mirror of
https://github.com/python/cpython.git
synced 2025-11-01 06:01:29 +00:00
GH-100923: Embed jump mask in COMPARE_OP oparg (GH-100924)
This commit is contained in:
parent
61f12b8ff7
commit
6e4e14d98f
12 changed files with 200 additions and 177 deletions
34
Python/generated_cases.c.h
generated
34
Python/generated_cases.c.h
generated
|
|
@ -2090,14 +2090,14 @@
|
|||
}
|
||||
STAT_INC(COMPARE_OP, deferred);
|
||||
DECREMENT_ADAPTIVE_COUNTER(cache->counter);
|
||||
assert(oparg <= Py_GE);
|
||||
res = PyObject_RichCompare(left, right, oparg);
|
||||
assert((oparg >> 4) <= Py_GE);
|
||||
res = PyObject_RichCompare(left, right, oparg>>4);
|
||||
Py_DECREF(left);
|
||||
Py_DECREF(right);
|
||||
if (res == NULL) goto pop_2_error;
|
||||
STACK_SHRINK(1);
|
||||
POKE(1, res);
|
||||
JUMPBY(2);
|
||||
JUMPBY(1);
|
||||
DISPATCH();
|
||||
}
|
||||
|
||||
|
|
@ -2108,7 +2108,6 @@
|
|||
PyObject *right = _tmp_1;
|
||||
PyObject *left = _tmp_2;
|
||||
size_t jump;
|
||||
uint16_t when_to_jump_mask = read_u16(&next_instr[1].cache);
|
||||
assert(cframe.use_tracing == 0);
|
||||
// Combined: COMPARE_OP (float ? float) + POP_JUMP_IF_(true/false)
|
||||
DEOPT_IF(!PyFloat_CheckExact(left), COMPARE_OP);
|
||||
|
|
@ -2116,14 +2115,14 @@
|
|||
STAT_INC(COMPARE_OP, hit);
|
||||
double dleft = PyFloat_AS_DOUBLE(left);
|
||||
double dright = PyFloat_AS_DOUBLE(right);
|
||||
// 1 if NaN, 2 if <, 4 if >, 8 if ==; this matches when_to_jump_mask
|
||||
int sign_ish = 1 << (2 * (dleft >= dright) + (dleft <= dright));
|
||||
// 1 if NaN, 2 if <, 4 if >, 8 if ==; this matches low four bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(dleft, dright);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
|
||||
jump = sign_ish & when_to_jump_mask;
|
||||
jump = sign_ish & oparg;
|
||||
_tmp_2 = (PyObject *)jump;
|
||||
}
|
||||
JUMPBY(2);
|
||||
JUMPBY(1);
|
||||
NEXTOPARG();
|
||||
JUMPBY(1);
|
||||
{
|
||||
|
|
@ -2144,7 +2143,6 @@
|
|||
PyObject *right = _tmp_1;
|
||||
PyObject *left = _tmp_2;
|
||||
size_t jump;
|
||||
uint16_t when_to_jump_mask = read_u16(&next_instr[1].cache);
|
||||
assert(cframe.use_tracing == 0);
|
||||
// Combined: COMPARE_OP (int ? int) + POP_JUMP_IF_(true/false)
|
||||
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
|
||||
|
|
@ -2155,14 +2153,14 @@
|
|||
assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
|
||||
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->ob_digit[0];
|
||||
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->ob_digit[0];
|
||||
// 2 if <, 4 if >, 8 if ==; this matches when_to_jump_mask
|
||||
int sign_ish = 1 << (2 * (ileft >= iright) + (ileft <= iright));
|
||||
// 2 if <, 4 if >, 8 if ==; this matches the low 4 bits of the oparg
|
||||
int sign_ish = COMPARISON_BIT(ileft, iright);
|
||||
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
|
||||
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
|
||||
jump = sign_ish & when_to_jump_mask;
|
||||
jump = sign_ish & oparg;
|
||||
_tmp_2 = (PyObject *)jump;
|
||||
}
|
||||
JUMPBY(2);
|
||||
JUMPBY(1);
|
||||
NEXTOPARG();
|
||||
JUMPBY(1);
|
||||
{
|
||||
|
|
@ -2183,22 +2181,22 @@
|
|||
PyObject *right = _tmp_1;
|
||||
PyObject *left = _tmp_2;
|
||||
size_t jump;
|
||||
uint16_t invert = read_u16(&next_instr[1].cache);
|
||||
assert(cframe.use_tracing == 0);
|
||||
// Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_IF_(true/false)
|
||||
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
|
||||
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
|
||||
STAT_INC(COMPARE_OP, hit);
|
||||
int res = _PyUnicode_Equal(left, right);
|
||||
assert(oparg == Py_EQ || oparg == Py_NE);
|
||||
assert((oparg >>4) == Py_EQ || (oparg >>4) == Py_NE);
|
||||
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
|
||||
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
|
||||
assert(res == 0 || res == 1);
|
||||
assert(invert == 0 || invert == 1);
|
||||
jump = res ^ invert;
|
||||
assert((oparg & 0xf) == COMPARISON_NOT_EQUALS || (oparg & 0xf) == COMPARISON_EQUALS);
|
||||
assert(COMPARISON_NOT_EQUALS + 1 == COMPARISON_EQUALS);
|
||||
jump = (res + COMPARISON_NOT_EQUALS) & oparg;
|
||||
_tmp_2 = (PyObject *)jump;
|
||||
}
|
||||
JUMPBY(2);
|
||||
JUMPBY(1);
|
||||
NEXTOPARG();
|
||||
JUMPBY(1);
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue