Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-47120: make POP_JUMP_IF_TRUE/FALSE/NONE/NOT_NONE relative #32400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
shift jump mask for backwards jumps
  • Loading branch information
iritkatriel committed Apr 8, 2022
commit 3f5626c00ef0e27a7a7310bda1f199f4c7cdb8e4
70 changes: 35 additions & 35 deletions 70 Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -3697,22 +3697,22 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
int jump = (9 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
next_instr++;
NOTRACE_DISPATCH();
}
else {
if (opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE) {
JUMPBY(1 - oparg);
}
else {
JUMPBY(1 + oparg);
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
NOTRACE_DISPATCH();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
}

TARGET(COMPARE_OP_INT_JUMP) {
Expand Down Expand Up @@ -3740,29 +3740,29 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE);
int jump = (1 << (sign + 1)) & when_to_jump_mask;
int jump = (9 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
next_instr++;
NOTRACE_DISPATCH();
}
else {
if (opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE) {
JUMPBY(1 - oparg);
}
else {
JUMPBY(1 + oparg);
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
NOTRACE_DISPATCH();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
}

TARGET(COMPARE_OP_STR_JUMP) {
assert(cframe.use_tracing == 0);
// Combined: COMPARE_OP (str == str or str != str) + POP_JUMP_(direction)_IF_(true/false)
_PyCompareOpCache *cache = (_PyCompareOpCache *)next_instr;
int invert = cache->mask;
int when_to_jump_mask = cache->mask;
PyObject *right = TOP();
PyObject *left = SECOND();
DEOPT_IF(!PyUnicode_CheckExact(left), COMPARE_OP);
Expand All @@ -3783,23 +3783,23 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, _PyInterpreterFrame *frame, int
Py_DECREF(left);
Py_DECREF(right);
assert(res == 0 || res == 1);
assert(invert == 0 || invert == 1);
int jump = res ^ invert;
int sign = 1 - res;
int jump = (9 << (sign + 1)) & when_to_jump_mask;
if (!jump) {
next_instr++;
NOTRACE_DISPATCH();
}
else {
if (opcode == POP_JUMP_BACKWARD_IF_FALSE ||
opcode == POP_JUMP_BACKWARD_IF_TRUE) {
JUMPBY(1 - oparg);
}
else {
JUMPBY(1 + oparg);
}
else if (jump >= 8) {
assert(opcode == POP_JUMP_BACKWARD_IF_TRUE ||
opcode == POP_JUMP_BACKWARD_IF_FALSE);
JUMPBY(1 - oparg);
CHECK_EVAL_BREAKER();
NOTRACE_DISPATCH();
}
else {
assert(opcode == POP_JUMP_FORWARD_IF_TRUE ||
opcode == POP_JUMP_FORWARD_IF_FALSE);
JUMPBY(1 + oparg);
}
NOTRACE_DISPATCH();
}

TARGET(IS_OP) {
Expand Down
6 changes: 5 additions & 1 deletion 6 Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,10 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
next_opcode == POP_JUMP_BACKWARD_IF_FALSE) {
when_to_jump_mask = (1 | 2 | 4) & ~when_to_jump_mask;
}
if (next_opcode == POP_JUMP_BACKWARD_IF_TRUE ||
next_opcode == POP_JUMP_BACKWARD_IF_FALSE) {
when_to_jump_mask <<= 3;
}
if (Py_TYPE(lhs) != Py_TYPE(rhs)) {
SPECIALIZATION_FAIL(COMPARE_OP, compare_op_fail_kind(lhs, rhs));
goto failure;
Expand Down Expand Up @@ -1935,7 +1939,7 @@ _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
}
else {
_Py_SET_OPCODE(*instr, COMPARE_OP_STR_JUMP);
cache->mask = (when_to_jump_mask & 2) == 0;
cache->mask = when_to_jump_mask;
goto success;
}
}
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.