Skip to content

JIT: add ZEND_BW_NOT handler for integer operands - #24179

Draft
adapik wants to merge 1 commit into
php:masterfrom
adapik:jit-bw-not
Draft

adapik wants to merge 1 commit into
php:masterfrom
adapik:jit-bw-not

Conversation

@adapik

@adapik adapik commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

ZEND_BW_NOT is currently the only bitwise opcode without a JIT handler: BW_OR, BW_AND, BW_XOR, SL and SR are all compiled. As a result, an expression such as ~$a & $b breaks the compiled code with a call into the VM handler, and values kept in registers have to be spilled around it. This and-not combination shows up in bit-manipulation code such as hash functions, checksums and other algorithms.

This PR adds a handler for the case where the operand is known to be int. Any other operand type (string, float, bool, null, array, object, undefined, constant) is not handled and keeps going through the VM handler, so behaviour,
warnings and TypeError messages are unchanged.

Release build (-O2), x86-64, best of several runs, 20M iterations of
$s ^= (~$a & $b) ^ ($i << 3):

JIT before after
tracing 0.037s 0.011s
function 0.036s 0.025s

This is a micro-benchmark that isolates the affected pattern.

@adapik
adapik marked this pull request as draft October 7, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant