gh-133395: add option for extension modules to specialize BINARY_OP/SUBSCR, apply to arrays (#133396)

This commit is contained in:
Irit Katriel 2025-05-05 17:46:56 +01:00 committed by GitHub
parent 07f416a3f0
commit 082dbf7788
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 172 additions and 45 deletions

View file

@ -1147,26 +1147,7 @@
break;
}
case _GUARD_BINARY_OP_EXTEND: {
_PyStackRef right;
_PyStackRef left;
right = stack_pointer[-1];
left = stack_pointer[-2];
PyObject *descr = (PyObject *)CURRENT_OPERAND0();
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
_PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
assert(d && d->guard);
_PyFrame_SetStackPointer(frame, stack_pointer);
int res = d->guard(left_o, right_o);
stack_pointer = _PyFrame_GetStackPointer(frame);
if (!res) {
UOP_STAT_INC(uopcode, miss);
JUMP_TO_JUMP_TARGET();
}
break;
}
/* _GUARD_BINARY_OP_EXTEND is not a viable micro-op for tier 2 because it uses the 'this_instr' variable */
case _BINARY_OP_EXTEND: {
_PyStackRef right;
@ -1193,6 +1174,9 @@
stack_pointer = _PyFrame_GetStackPointer(frame);
stack_pointer += -2;
assert(WITHIN_STACK_BOUNDS());
if (res_o == NULL) {
JUMP_TO_ERROR();
}
res = PyStackRef_FromPyObjectSteal(res_o);
stack_pointer[0] = res;
stack_pointer += 1;