Skip to content

Commit

Permalink
FOR_ITER__STORE_FAST
Browse files Browse the repository at this point in the history
  • Loading branch information
Fidget-Spinner committed Jul 25, 2021
1 parent d98e594 commit c8a1338
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 105 deletions.
6 changes: 1 addition & 5 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,5 @@ def jabs_op(name, op):
"LOAD_GLOBAL_MODULE",
"LOAD_GLOBAL_BUILTIN",
# Super instructions
"LOAD_FAST__LOAD_FAST",
"STORE_FAST__LOAD_FAST",
"LOAD_FAST__LOAD_CONST",
"LOAD_CONST__LOAD_FAST",
"STORE_FAST__STORE_FAST",
"FOR_ITER__STORE_FAST",
]
92 changes: 25 additions & 67 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1683,73 +1683,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
DISPATCH();
}

case TARGET(LOAD_FAST__LOAD_FAST): {
PyObject *value = GETLOCAL(oparg);
if (value == NULL) {
goto unbound_local_error;
}
NEXTOPARG();
Py_INCREF(value);
PUSH(value);
value = GETLOCAL(oparg);
if (value == NULL) {
goto unbound_local_error;
}
Py_INCREF(value);
PUSH(value);
NOTRACE_DISPATCH();
}

case TARGET(LOAD_FAST__LOAD_CONST): {
PyObject *value = GETLOCAL(oparg);
if (value == NULL) {
goto unbound_local_error;
}
NEXTOPARG();
Py_INCREF(value);
PUSH(value);
value = GETITEM(consts, oparg);
Py_INCREF(value);
PUSH(value);
NOTRACE_DISPATCH();
}

case TARGET(STORE_FAST__LOAD_FAST): {
PyObject *value = POP();
SETLOCAL(oparg, value);
NEXTOPARG();
value = GETLOCAL(oparg);
if (value == NULL) {
goto unbound_local_error;
}
Py_INCREF(value);
PUSH(value);
NOTRACE_DISPATCH();
}

case TARGET(STORE_FAST__STORE_FAST): {
PyObject *value = POP();
SETLOCAL(oparg, value);
NEXTOPARG();
value = POP();
SETLOCAL(oparg, value);
NOTRACE_DISPATCH();
}

case TARGET(LOAD_CONST__LOAD_FAST): {
PyObject *value = GETITEM(consts, oparg);
NEXTOPARG();
Py_INCREF(value);
PUSH(value);
value = GETLOCAL(oparg);
if (value == NULL) {
goto unbound_local_error;
}
Py_INCREF(value);
PUSH(value);
NOTRACE_DISPATCH();
}

case TARGET(POP_TOP): {
PyObject *value = POP();
Py_DECREF(value);
Expand Down Expand Up @@ -3997,6 +3930,31 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
DISPATCH();
}

case TARGET(FOR_ITER__STORE_FAST): {
/* before: [iter]; after: [iter] *or* [] */
PyObject *iter = TOP();
PyObject *next = (*Py_TYPE(iter)->tp_iternext)(iter);
if (next != NULL) {
NEXTOPARG();
SETLOCAL(oparg, next);
NOTRACE_DISPATCH();
}
if (_PyErr_Occurred(tstate)) {
if (!_PyErr_ExceptionMatches(tstate, PyExc_StopIteration)) {
goto error;
}
else if (tstate->c_tracefunc != NULL) {
call_exc_trace(tstate->c_tracefunc, tstate->c_traceobj, tstate, f);
}
_PyErr_Clear(tstate);
}
/* iterator ended normally */
STACK_SHRINK(1);
Py_DECREF(iter);
JUMPBY(oparg);
NOTRACE_DISPATCH();
}

case TARGET(BEFORE_ASYNC_WITH): {
_Py_IDENTIFIER(__aenter__);
_Py_IDENTIFIER(__aexit__);
Expand Down
10 changes: 5 additions & 5 deletions Python/opcode_targets.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 2 additions & 23 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,9 @@ optimize(SpecializedCacheOrInstruction *quickened, int len)
/* Super instructions don't use the cache,
* so no need to update the offset. */
switch (opcode) {
case JUMP_ABSOLUTE:
instructions[i] = _Py_MAKECODEUNIT(JUMP_ABSOLUTE_QUICK, oparg);
break;
case LOAD_FAST:
switch(previous_opcode) {
case LOAD_FAST:
instructions[i-1] = _Py_MAKECODEUNIT(LOAD_FAST__LOAD_FAST, previous_oparg);
break;
case STORE_FAST:
instructions[i-1] = _Py_MAKECODEUNIT(STORE_FAST__LOAD_FAST, previous_oparg);
break;
case LOAD_CONST:
instructions[i-1] = _Py_MAKECODEUNIT(LOAD_CONST__LOAD_FAST, previous_oparg);
break;
}
break;
case STORE_FAST:
if (previous_opcode == STORE_FAST) {
instructions[i-1] = _Py_MAKECODEUNIT(STORE_FAST__STORE_FAST, previous_oparg);
}
break;
case LOAD_CONST:
if (previous_opcode == LOAD_FAST) {
instructions[i-1] = _Py_MAKECODEUNIT(LOAD_FAST__LOAD_CONST, previous_oparg);
if (previous_opcode == FOR_ITER) {
instructions[i-1] = _Py_MAKECODEUNIT(FOR_ITER__STORE_FAST, previous_oparg);
}
break;
}
Expand Down

0 comments on commit c8a1338

Please sign in to comment.