[Python-checkins] python/dist/src/Python ceval.c, 2.400,
2.401 compile.c, 2.303, 2.304
rhettinger at users.sourceforge.net
rhettinger at users.sourceforge.net
Mon Jun 21 12:31:19 EDT 2004
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26471/Python
Modified Files:
ceval.c compile.c
Log Message:
Install two code generation optimizations that depend on NOP.
Reduces the cost of "not" to almost zero.
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.400
retrieving revision 2.401
diff -C2 -d -r2.400 -r2.401
*** ceval.c 17 Jun 2004 10:22:40 -0000 2.400
--- ceval.c 21 Jun 2004 16:31:14 -0000 2.401
***************
*** 850,853 ****
--- 850,856 ----
/* case STOP_CODE: this is an error! */
+ case NOP:
+ goto fast_next_opcode;
+
case LOAD_FAST:
x = GETLOCAL(oparg);
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.303
retrieving revision 2.304
diff -C2 -d -r2.303 -r2.304
*** compile.c 8 Jun 2004 18:52:54 -0000 2.303
--- compile.c 21 Jun 2004 16:31:15 -0000 2.304
***************
*** 393,396 ****
--- 393,423 ----
switch (opcode) {
+ /* Replace UNARY_NOT JUMP_IF_FALSE with NOP JUMP_IF_TRUE */
+ case UNARY_NOT:
+ if (codestr[i+1] != JUMP_IF_FALSE ||
+ codestr[i+4] != POP_TOP ||
+ !ISBASICBLOCK(blocks,i,5))
+ continue;
+ tgt = GETJUMPTGT(codestr, (i+1));
+ if (codestr[tgt] != POP_TOP)
+ continue;
+ codestr[i] = NOP;
+ codestr[i+1] = JUMP_IF_TRUE;
+ break;
+
+ /* not a is b --> a is not b
+ not a in b --> a not in b
+ not a is not b --> a is b
+ not a not in b --> a in b */
+ case COMPARE_OP:
+ j = GETARG(codestr, i);
+ if (j < 6 || j > 9 ||
+ codestr[i+3] != UNARY_NOT ||
+ !ISBASICBLOCK(blocks,i,4))
+ continue;
+ SETARG(codestr, i, (j^1));
+ codestr[i+3] = NOP;
+ break;
+
/* Skip over LOAD_CONST trueconst JUMP_IF_FALSE xx POP_TOP.
Note, only the first opcode is changed, the others still
***************
*** 419,424 ****
codestr[i+1] = JUMP_FORWARD;
SETARG(codestr, i+1, 2);
! codestr[i+4] = DUP_TOP; /* Filler codes used as NOPs */
! codestr[i+5] = POP_TOP;
continue;
}
--- 446,451 ----
codestr[i+1] = JUMP_FORWARD;
SETARG(codestr, i+1, 2);
! codestr[i+4] = NOP;
! codestr[i+5] = NOP;
continue;
}
***************
*** 429,433 ****
codestr[i+2] = JUMP_FORWARD;
SETARG(codestr, i+2, 1);
! codestr[i+5] = DUP_TOP;
}
break;
--- 456,460 ----
codestr[i+2] = JUMP_FORWARD;
SETARG(codestr, i+2, 1);
! codestr[i+5] = NOP;
}
break;
More information about the Python-checkins
mailing list