Extend SF patch #707257: Improve code generation
to cover the case for: "x,y,z=1,2,3". Gives a 30% speed-up. Also, added FOR_ITER to the list of opcodes that can jump.
This commit is contained in:
parent
8b7a9a38c6
commit
255a3d08a1
|
@ -364,23 +364,35 @@ optimize_code(PyObject *code, PyObject* consts)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2 JMP+2.
|
/* Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2 JMP+2.
|
||||||
|
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2 JMP+1.
|
||||||
Note, these opcodes occur together only in assignment
|
Note, these opcodes occur together only in assignment
|
||||||
statements. Accordingly, the unpack opcode is never
|
statements. Accordingly, the unpack opcode is never
|
||||||
a jump target. */
|
a jump target. */
|
||||||
case BUILD_TUPLE:
|
case BUILD_TUPLE:
|
||||||
case BUILD_LIST:
|
case BUILD_LIST:
|
||||||
if (codestr[i+3] != UNPACK_SEQUENCE ||
|
if (codestr[i+3] != UNPACK_SEQUENCE)
|
||||||
GETARG(codestr, i) != 2 ||
|
|
||||||
GETARG(codestr, i+3) != 2)
|
|
||||||
continue;
|
continue;
|
||||||
codestr[i] = ROT_TWO;
|
if (GETARG(codestr, i) == 2 && \
|
||||||
codestr[i+1] = JUMP_FORWARD;
|
GETARG(codestr, i+3) == 2) {
|
||||||
SETARG(codestr, i+1, 2);
|
codestr[i] = ROT_TWO;
|
||||||
codestr[i+4] = DUP_TOP; /* Filler codes used as NOPs */
|
codestr[i+1] = JUMP_FORWARD;
|
||||||
codestr[i+5] = POP_TOP;
|
SETARG(codestr, i+1, 2);
|
||||||
|
codestr[i+4] = DUP_TOP; /* Filler codes used as NOPs */
|
||||||
|
codestr[i+5] = POP_TOP;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (GETARG(codestr, i) == 3 && \
|
||||||
|
GETARG(codestr, i+3) == 3) {
|
||||||
|
codestr[i] = ROT_THREE;
|
||||||
|
codestr[i+1] = ROT_TWO;
|
||||||
|
codestr[i+2] = JUMP_FORWARD;
|
||||||
|
SETARG(codestr, i+2, 1);
|
||||||
|
codestr[i+5] = DUP_TOP;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Replace jumps to unconditional jumps */
|
/* Replace jumps to unconditional jumps */
|
||||||
|
case FOR_ITER:
|
||||||
case JUMP_FORWARD:
|
case JUMP_FORWARD:
|
||||||
case JUMP_IF_FALSE:
|
case JUMP_IF_FALSE:
|
||||||
case JUMP_IF_TRUE:
|
case JUMP_IF_TRUE:
|
||||||
|
|
Loading…
Reference in New Issue