Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7dc5221

Browse files
committed
Eliminate data dependency in predict macro.
Added two predictions: GET_ITER --> FOR_ITER FOR_ITER --> STORE_FAST or UNPACK_SEQUENCE Improves timings on pybench and timeit.py. Pystone results are neutral.
1 parent ac20729 commit 7dc5221

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Python/ceval.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ eval_frame(PyFrameObject *f)
620620

621621
#define PREDICT(op) if (*next_instr == op) goto PRED_##op
622622
#define PREDICTED(op) PRED_##op: next_instr++
623-
#define PREDICTED_WITH_ARG(op) PRED_##op: oparg = (next_instr += 3, \
624-
(next_instr[-1]<<8) + next_instr[-2])
623+
#define PREDICTED_WITH_ARG(op) PRED_##op: oparg = (next_instr[2]<<8) + \
624+
next_instr[1]; next_instr += 3
625625

626626
/* Stack manipulation macros */
627627

@@ -889,6 +889,7 @@ eval_frame(PyFrameObject *f)
889889
PUSH(x);
890890
goto fast_next_opcode;
891891

892+
PREDICTED_WITH_ARG(STORE_FAST);
892893
case STORE_FAST:
893894
v = POP();
894895
SETLOCAL(oparg, v);
@@ -1675,6 +1676,7 @@ eval_frame(PyFrameObject *f)
16751676
NAME_ERROR_MSG ,w);
16761677
break;
16771678

1679+
PREDICTED_WITH_ARG(UNPACK_SEQUENCE);
16781680
case UNPACK_SEQUENCE:
16791681
v = POP();
16801682
if (PyTuple_CheckExact(v)) {
@@ -2051,17 +2053,21 @@ eval_frame(PyFrameObject *f)
20512053
Py_DECREF(v);
20522054
if (x != NULL) {
20532055
SET_TOP(x);
2056+
PREDICT(FOR_ITER);
20542057
continue;
20552058
}
20562059
STACKADJ(-1);
20572060
break;
20582061

2062+
PREDICTED_WITH_ARG(FOR_ITER);
20592063
case FOR_ITER:
20602064
/* before: [iter]; after: [iter, iter()] *or* [] */
20612065
v = TOP();
20622066
x = PyIter_Next(v);
20632067
if (x != NULL) {
20642068
PUSH(x);
2069+
PREDICT(STORE_FAST);
2070+
PREDICT(UNPACK_SEQUENCE);
20652071
continue;
20662072
}
20672073
if (!PyErr_Occurred()) {

0 commit comments

Comments
 (0)