Skip to content

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Jan 13, 2026

This reduces the overhead of performing boolean guards in jitted code.

On Aarch64 reduces the size of the stencil from 5 to 2 instructions.

GUARD_IS_FALSE_POP_r10:

  adrp    x8, 0x0   // _Py_FalseStruct
  ldr     x8, [x8]   // _Py_FalseStruct
  orr     x8, x8, #0x1
  cmp     x24, x8
  b.ne    jump_target

_GUARD_BIT_IS_SET_POP_4_r10:

  tbnz    w24, #0x4, next
  b    jump_target
next:
    // 0000000000000004:  R_AARCH64_JUMP26     _JIT_JUMP_TARGET

Comment on lines +156 to +167
d = id(True) ^ id(False)
bit = 0
for i in range(4, 8):
if d & (1 << i):
bit = i
break
if bit == 0:
return "_GUARD_IS_FALSE_POP", "_GUARD_IS_TRUE_POP"
if id(True) & (1 << bit):
return f"_GUARD_BIT_IS_UNSET_POP_{bit}", f"_GUARD_BIT_IS_SET_POP_{bit}"
else:
return f"_GUARD_BIT_IS_SET_POP_{bit}", f"_GUARD_BIT_IS_UNSET_POP_{bit}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be dedented one.

int bit = get_test_bit_for_bools();
if (bit) {
REPLACE_OP(this_instr,
test_bit_set_in_true(bit) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check this once at the context initialization and set it in the context, then fetch the corresponding op to use from the context.

int bit = get_test_bit_for_bools();
if (bit) {
REPLACE_OP(this_instr,
test_bit_set_in_true(bit) ?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

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.

2 participants