Skip to content

Commit 74ea0a2

Browse files
committed
COMPARE_OP_STR_JUMP
1 parent d3ece03 commit 74ea0a2

File tree

2 files changed

+44
-50
lines changed

2 files changed

+44
-50
lines changed

Python/bytecodes.c

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,14 @@ static PyObject *list, *tuple, *dict;
8585
static PyObject *exit_func, *lasti, *val;
8686
static PyObject *jump;
8787
// Dummy variables for stack effects
88-
static int when_to_jump_mask;
88+
static _Py_CODEUNIT when_to_jump_mask, invert;
8989
// Dummy opcode names for 'op' opcodes
9090
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_1 1001
9191
#define _BINARY_OP_INPLACE_ADD_UNICODE_PART_2 1002
9292
#define _COMPARE_OP_FLOAT 1003
9393
#define _COMPARE_OP_INT 1004
94-
#define _JUMP_ON_SIGN 1005
94+
#define _COMPARE_OP_STR 1005
95+
#define _JUMP_ON_SIGN 1006
9596

9697
static PyObject *
9798
dummy_func(
@@ -2065,7 +2066,7 @@ dummy_func(
20652066
COMPARE_OP,
20662067
_COMPARE_OP_FLOAT,
20672068
_COMPARE_OP_INT,
2068-
// COMPARE_OP_STR_JUMP,
2069+
_COMPARE_OP_STR,
20692070
};
20702071

20712072
inst(COMPARE_OP, (unused/1, left, right, unused/1 -- res)) {
@@ -2132,35 +2133,22 @@ dummy_func(
21322133
}
21332134
super(COMPARE_OP_INT_JUMP) = _COMPARE_OP_INT + _JUMP_ON_SIGN;
21342135

2135-
// stack effect: (__0 -- )
2136-
inst(COMPARE_OP_STR_JUMP) {
2136+
// Similar to COMPARE_OP_FLOAT, but for ==, != only
2137+
op(_COMPARE_OP_STR, (unused/1, left, right, invert/1 -- jump)) {
21372138
assert(cframe.use_tracing == 0);
21382139
// Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_IF_(true/false)
2139-
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
2140-
int invert = cache->mask;
2141-
PyObject *right = TOP();
2142-
PyObject *left = SECOND();
21432140
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
21442141
DEOPT_IF(!PyUnicode_CheckExact(right), COMPARE_OP);
21452142
STAT_INC(COMPARE_OP, hit);
21462143
int res = _PyUnicode_Equal(left, right);
21472144
assert(oparg == Py_EQ || oparg == Py_NE);
2148-
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
2149-
NEXTOPARG();
2150-
assert(opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_TRUE);
2151-
STACK_SHRINK(2);
21522145
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
21532146
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
21542147
assert(res == 0 || res == 1);
21552148
assert(invert == 0 || invert == 1);
2156-
int jump = res ^ invert;
2157-
if (!jump) {
2158-
next_instr++;
2159-
}
2160-
else {
2161-
JUMPBY(1 + oparg);
2162-
}
2149+
jump = (PyObject *)(size_t)(res ^ invert);
21632150
}
2151+
super(COMPARE_OP_STR_JUMP) = _COMPARE_OP_STR + _JUMP_ON_SIGN;
21642152

21652153
// stack effect: (__0 -- )
21662154
inst(IS_OP) {

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)