Skip to content

Commit d3ece03

Browse files
committed
COMPARE_OP_INT_JUMP
1 parent a35904d commit d3ece03

File tree

2 files changed

+51
-55
lines changed

2 files changed

+51
-55
lines changed

Python/bytecodes.c

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,11 @@ static PyObject *jump;
8787
// Dummy variables for stack effects
8888
static int when_to_jump_mask;
8989
// Dummy opcode names for 'op' opcodes
90-
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_1 1
91-
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_2 2
92-
#define _COMPARE_OP_FLOAT 3
93-
#define _JUMP_ON_SIGN 4
90+
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_1 1001
91+
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_2 1002
92+
#define _COMPARE_OP_FLOAT 1003
93+
#define _COMPARE_OP_INT 1004
94+
#define _JUMP_ON_SIGN 1005
9495

9596
static PyObject *
9697
dummy_func(
@@ -2063,7 +2064,7 @@ dummy_func(
20632064
family(compare_op) = {
20642065
COMPARE_OP,
20652066
_COMPARE_OP_FLOAT,
2066-
// COMPARE_OP_INT_JUMP,
2067+
_COMPARE_OP_INT,
20672068
// COMPARE_OP_STR_JUMP,
20682069
};
20692070

@@ -2111,14 +2112,10 @@ dummy_func(
21112112
// We're praying that the compiler optimizes the flags manipuations.
21122113
super(COMPARE_OP_FLOAT_JUMP) = _COMPARE_OP_FLOAT + _JUMP_ON_SIGN;
21132114

2114-
// stack effect: (__0 -- )
2115-
inst(COMPARE_OP_INT_JUMP) {
2115+
// Similar to COMPARE_OP_FLOAT
2116+
op(_COMPARE_OP_INT, (unused/1, left, right, when_to_jump_mask/1 -- jump)) {
21162117
assert(cframe.use_tracing == 0);
21172118
// Combined: COMPARE_OP (int ? int) + POP_JUMP_IF_(true/false)
2118-
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
2119-
int when_to_jump_mask = cache->mask;
2120-
PyObject *right = TOP();
2121-
PyObject *left = SECOND();
21222119
DEOPT_IF(!PyLong_CheckExact(left), COMPARE_OP);
21232120
DEOPT_IF(!PyLong_CheckExact(right), COMPARE_OP);
21242121
DEOPT_IF((size_t)(Py_SIZE(left) + 1) > 2, COMPARE_OP);
@@ -2127,21 +2124,13 @@ dummy_func(
21272124
assert(Py_ABS(Py_SIZE(left)) <= 1 && Py_ABS(Py_SIZE(right)) <= 1);
21282125
Py_ssize_t ileft = Py_SIZE(left) * ((PyLongObject *)left)->ob_digit[0];
21292126
Py_ssize_t iright = Py_SIZE(right) * ((PyLongObject *)right)->ob_digit[0];
2130-
int sign = (ileft > iright) - (ileft < iright);
2131-
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
2132-
NEXTOPARG();
2133-
STACK_SHRINK(2);
2127+
// 1 if <, 2 if ==, 4 if >; this matches when _to_jump_mask
2128+
int sign_ish = 2*(ileft > iright) + 2 - (ileft < iright);
21342129
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
21352130
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
2136-
assert(opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_TRUE);
2137-
int jump = (1 << (sign + 1)) & when_to_jump_mask;
2138-
if (!jump) {
2139-
next_instr++;
2140-
}
2141-
else {
2142-
JUMPBY(1 + oparg);
2143-
}
2131+
jump = (PyObject *)(size_t)(sign_ish & when_to_jump_mask);
21442132
}
2133+
super(COMPARE_OP_INT_JUMP) = _COMPARE_OP_INT + _JUMP_ON_SIGN;
21452134

21462135
// stack effect: (__0 -- )
21472136
inst(COMPARE_OP_STR_JUMP) {

Python/generated_cases.c.h

Lines changed: 39 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)