gh-93554: Conditional jump opcodes only jump forward (GH-96318)

This commit is contained in:
Irit Katriel 2022-09-01 21:36:47 +01:00 committed by GitHub
parent a91f25577c
commit 4c72517cad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 298 additions and 448 deletions

View file

@ -3307,7 +3307,7 @@ handle_eval_breaker:
TARGET(COMPARE_OP_FLOAT_JUMP) {
assert(cframe.use_tracing == 0);
// Combined: COMPARE_OP (float ? float) + POP_JUMP_(direction)_IF_(true/false)
// Combined: COMPARE_OP (float ? float) + POP_JUMP_IF_(true/false)
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
int when_to_jump_mask = cache->mask;
PyObject *right = TOP();
@ -3325,23 +3325,12 @@ handle_eval_breaker:
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, _PyFloat_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyFloat_ExactDealloc);
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
int jump = (9 << (sign + 1)) & when_to_jump_mask;
assert(opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_TRUE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
next_instr++;
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
@ -3349,7 +3338,7 @@ handle_eval_breaker:
TARGET(COMPARE_OP_INT_JUMP) {
assert(cframe.use_tracing == 0);
// Combined: COMPARE_OP (int ? int) + POP_JUMP_(direction)_IF_(true/false)
// Combined: COMPARE_OP (int ? int) + POP_JUMP_IF_(true/false)
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
int when_to_jump_mask = cache->mask;
PyObject *right = TOP();
@ -3368,23 +3357,12 @@ handle_eval_breaker:
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, (destructor)PyObject_Free);
_Py_DECREF_SPECIALIZED(right, (destructor)PyObject_Free);
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
int jump = (9 << (sign + 1)) & when_to_jump_mask;
assert(opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_TRUE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
next_instr++;
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
@ -3392,9 +3370,9 @@ handle_eval_breaker:
TARGET(COMPARE_OP_STR_JUMP) {
assert(cframe.use_tracing == 0);
// Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_(direction)_IF_(true/false)
// Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_IF_(true/false)
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
int when_to_jump_mask = cache->mask;
int invert = cache->mask;
PyObject *right = TOP();
PyObject *left = SECOND();
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
@ -3407,28 +3385,17 @@ handle_eval_breaker:
assert(oparg == Py_EQ || oparg == Py_NE);
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
NEXTOPARG();
assert(opcode == POP_JUMP_FORWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
assert(opcode == POP_JUMP_IF_FALSE || opcode == POP_JUMP_IF_TRUE);
STACK_SHRINK(2);
_Py_DECREF_SPECIALIZED(left, _PyUnicode_ExactDealloc);
_Py_DECREF_SPECIALIZED(right, _PyUnicode_ExactDealloc);
assert(res == 0 || res == 1);
int sign = 1 - res;
int jump = (9 << (sign + 1)) & when_to_jump_mask;
assert(invert == 0 || invert == 1);
int jump = res ^ invert;
if (!jump) {
next_instr++;
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
@ -3575,34 +3542,8 @@ handle_eval_breaker:
JUMP_TO_INSTRUCTION(JUMP_BACKWARD_QUICK);
}
TARGET(POP_JUMP_BACKWARD_IF_FALSE) {
PREDICTED(POP_JUMP_BACKWARD_IF_FALSE);
PyObject *cond = POP();
if (Py_IsTrue(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsFalse(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
}
int err = PyObject_IsTrue(cond);
Py_DECREF(cond);
if (err > 0)
;
else if (err == 0) {
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
}
else
goto error;
DISPATCH();
}
TARGET(POP_JUMP_FORWARD_IF_FALSE) {
PREDICTED(POP_JUMP_FORWARD_IF_FALSE);
TARGET(POP_JUMP_IF_FALSE) {
PREDICTED(POP_JUMP_IF_FALSE);
PyObject *cond = POP();
if (Py_IsTrue(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
@ -3625,32 +3566,7 @@ handle_eval_breaker:
DISPATCH();
}
TARGET(POP_JUMP_BACKWARD_IF_TRUE) {
PyObject *cond = POP();
if (Py_IsFalse(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
DISPATCH();
}
if (Py_IsTrue(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
}
int err = PyObject_IsTrue(cond);
Py_DECREF(cond);
if (err > 0) {
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
}
else if (err == 0)
;
else
goto error;
DISPATCH();
}
TARGET(POP_JUMP_FORWARD_IF_TRUE) {
TARGET(POP_JUMP_IF_TRUE) {
PyObject *cond = POP();
if (Py_IsFalse(cond)) {
_Py_DECREF_NO_DEALLOC(cond);
@ -3673,19 +3589,7 @@ handle_eval_breaker:
DISPATCH();
}
TARGET(POP_JUMP_BACKWARD_IF_NOT_NONE) {
PyObject *value = POP();
if (!Py_IsNone(value)) {
Py_DECREF(value);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
DISPATCH();
}
_Py_DECREF_NO_DEALLOC(value);
DISPATCH();
}
TARGET(POP_JUMP_FORWARD_IF_NOT_NONE) {
TARGET(POP_JUMP_IF_NOT_NONE) {
PyObject *value = POP();
if (!Py_IsNone(value)) {
JUMPBY(oparg);
@ -3694,20 +3598,7 @@ handle_eval_breaker:
DISPATCH();
}
TARGET(POP_JUMP_BACKWARD_IF_NONE) {
PyObject *value = POP();
if (Py_IsNone(value)) {
_Py_DECREF_NO_DEALLOC(value);
JUMPBY(-oparg);
CHECK_EVAL_BREAKER();
}
else {
Py_DECREF(value);
}
DISPATCH();
}
TARGET(POP_JUMP_FORWARD_IF_NONE) {
TARGET(POP_JUMP_IF_NONE) {
PyObject *value = POP();
if (Py_IsNone(value)) {
_Py_DECREF_NO_DEALLOC(value);
@ -3834,8 +3725,7 @@ handle_eval_breaker:
PyObject *res = match ? Py_True : Py_False;
Py_INCREF(res);
PUSH(res);
PREDICT(POP_JUMP_FORWARD_IF_FALSE);
PREDICT(POP_JUMP_BACKWARD_IF_FALSE);
PREDICT(POP_JUMP_IF_FALSE);
DISPATCH();
}
@ -3845,8 +3735,7 @@ handle_eval_breaker:
PyObject *res = match ? Py_True : Py_False;
Py_INCREF(res);
PUSH(res);
PREDICT(POP_JUMP_FORWARD_IF_FALSE);
PREDICT(POP_JUMP_BACKWARD_IF_FALSE);
PREDICT(POP_JUMP_IF_FALSE);
DISPATCH();
}