GH-138245: Perform boolean guards by testing a single bit, rather than a full pointer comparison. (GH-143810)

This commit is contained in:
Mark Shannon 2026-01-21 15:58:27 +00:00 committed by GitHub
parent f52af86cba
commit 9eab67d507
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 2478 additions and 1027 deletions

View file

@ -1136,15 +1136,6 @@ dummy_func(void) {
}
}
op(_GUARD_IS_TRUE_POP, (flag -- )) {
if (sym_is_const(ctx, flag)) {
PyObject *value = sym_get_const(ctx, flag);
assert(value != NULL);
eliminate_pop_guard(this_instr, ctx, value != Py_True);
}
sym_set_const(flag, Py_True);
}
op(_CALL_LIST_APPEND, (callable, self, arg -- none, c, s)) {
(void)(arg);
c = callable;
@ -1181,12 +1172,39 @@ dummy_func(void) {
}
}
op(_GUARD_IS_TRUE_POP, (flag -- )) {
if (sym_is_const(ctx, flag)) {
PyObject *value = sym_get_const(ctx, flag);
assert(value != NULL);
eliminate_pop_guard(this_instr, ctx, value != Py_True);
}
else {
int bit = get_test_bit_for_bools();
if (bit) {
REPLACE_OP(this_instr,
test_bit_set_in_true(bit) ?
_GUARD_BIT_IS_SET_POP :
_GUARD_BIT_IS_UNSET_POP, bit, 0);
}
}
sym_set_const(flag, Py_True);
}
op(_GUARD_IS_FALSE_POP, (flag -- )) {
if (sym_is_const(ctx, flag)) {
PyObject *value = sym_get_const(ctx, flag);
assert(value != NULL);
eliminate_pop_guard(this_instr, ctx, value != Py_False);
}
else {
int bit = get_test_bit_for_bools();
if (bit) {
REPLACE_OP(this_instr,
test_bit_set_in_true(bit) ?
_GUARD_BIT_IS_UNSET_POP :
_GUARD_BIT_IS_SET_POP, bit, 0);
}
}
sym_set_const(flag, Py_False);
}