[Python-checkins] python/dist/src/Python ceval.c,2.360,2.361 compile.c,2.280,2.281
rhettinger@users.sourceforge.net
rhettinger@users.sourceforge.net
Wed, 23 Apr 2003 22:45:30 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv20255/Python
Modified Files:
ceval.c compile.c
Log Message:
Revert the previous enhancement to the bytecode optimizer.
The additional code complexity and new NOP opcode were not worth it.
Index: ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.360
retrieving revision 2.361
diff -C2 -d -r2.360 -r2.361
*** ceval.c 22 Apr 2003 06:49:09 -0000 2.360
--- ceval.c 24 Apr 2003 05:45:22 -0000 2.361
***************
*** 874,880 ****
/* case STOP_CODE: this is an error! */
- case NOP:
- goto fast_next_opcode;
-
case LOAD_FAST:
x = GETLOCAL(oparg);
--- 874,877 ----
Index: compile.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/compile.c,v
retrieving revision 2.280
retrieving revision 2.281
diff -C2 -d -r2.280 -r2.281
*** compile.c 22 Apr 2003 06:49:10 -0000 2.280
--- compile.c 24 Apr 2003 05:45:23 -0000 2.281
***************
*** 329,369 ****
#define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3))
#define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255
- #define CODESIZE(op) (HAS_ARG(op) ? 3 : 1)
- #define ISBASICBLOCK(blocks, start, bytes) (blocks[start]==blocks[start+bytes-1])
-
- static unsigned int *
- markblocks(unsigned char *code, int len)
- {
- unsigned int *blocks = PyMem_Malloc(len*sizeof(int));
- int i,j, opcode, oldblock, newblock, blockcnt = 0;
-
- if (blocks == NULL)
- return NULL;
- memset(blocks, 0, len*sizeof(int));
- for (i=0 ; i<len ; i+=CODESIZE(opcode)) {
- opcode = code[i];
- switch (opcode) {
- case FOR_ITER:
- case JUMP_FORWARD:
- case JUMP_IF_FALSE:
- case JUMP_IF_TRUE:
- case JUMP_ABSOLUTE:
- case CONTINUE_LOOP:
- case SETUP_LOOP:
- case SETUP_EXCEPT:
- case SETUP_FINALLY:
- j = GETJUMPTGT(code, i);
- oldblock = blocks[j];
- newblock = ++blockcnt;
- for (; j<len ; j++) {
- if (blocks[j] != (unsigned)oldblock)
- break;
- blocks[j] = newblock;
- }
- break;
- }
- }
- return blocks;
- }
static PyObject *
--- 329,332 ----
***************
*** 373,377 ****
int tgt, tgttgt, opcode;
unsigned char *codestr;
- unsigned int *blocks;
/* Make a modifiable copy of the code string */
--- 336,339 ----
***************
*** 380,394 ****
codelen = PyString_Size(code);
codestr = PyMem_Malloc(codelen);
! if (codestr == NULL)
goto exitUnchanged;
codestr = memcpy(codestr, PyString_AS_STRING(code), codelen);
- blocks = markblocks(codestr, codelen);
- if (blocks == NULL) {
- PyMem_Free(codestr);
- goto exitUnchanged;
- }
assert(PyTuple_Check(consts));
! for (i=0 ; i<codelen ; i += CODESIZE(codestr[i])) {
opcode = codestr[i];
switch (opcode) {
--- 342,351 ----
codelen = PyString_Size(code);
codestr = PyMem_Malloc(codelen);
! if (codestr == NULL)
goto exitUnchanged;
codestr = memcpy(codestr, PyString_AS_STRING(code), codelen);
assert(PyTuple_Check(consts));
! for (i=0 ; i<codelen-7 ; i += HAS_ARG(codestr[i]) ? 3 : 1) {
opcode = codestr[i];
switch (opcode) {
***************
*** 407,412 ****
break;
! /* Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2 JMP+2 NOP NOP.
! Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2 JMP+1 NOP.
Note, these opcodes occur together only in assignment
statements. Accordingly, the unpack opcode is never
--- 364,369 ----
break;
! /* 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
statements. Accordingly, the unpack opcode is never
***************
*** 421,426 ****
codestr[i+1] = JUMP_FORWARD;
SETARG(codestr, i+1, 2);
! codestr[i+4] = NOP;
! codestr[i+5] = NOP;
continue;
}
--- 378,383 ----
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;
}
***************
*** 430,468 ****
codestr[i+1] = ROT_TWO;
codestr[i+2] = JUMP_FORWARD;
! SETARG(codestr, i+2, 1);
! codestr[i+5] = NOP;
}
break;
- /* Simplify inverted tests.
- Must verify that sequence is a basic block because the jump
- can itself be a jump target. Also, must verify that *both*
- jump alternatives go to a POP_TOP. Otherwise, the code will
- expect the stack value to have been inverted. */
- 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 (codestr[i+3] != UNARY_NOT || j < 6 || \
- j > 9 || !ISBASICBLOCK(blocks,i,4))
- continue;
- SETARG(codestr, i, (j^1));
- codestr[i+3] = NOP;
- break;
-
/* Replace jumps to unconditional jumps */
case FOR_ITER:
--- 387,395 ----
codestr[i+1] = ROT_TWO;
codestr[i+2] = JUMP_FORWARD;
! SETARG(codestr, i+2, 1);
! codestr[i+5] = DUP_TOP;
}
break;
/* Replace jumps to unconditional jumps */
case FOR_ITER:
***************
*** 476,480 ****
case SETUP_FINALLY:
tgt = GETJUMPTGT(codestr, i);
! if (!UNCONDITIONAL_JUMP(codestr[tgt]))
continue;
tgttgt = GETJUMPTGT(codestr, tgt);
--- 403,407 ----
case SETUP_FINALLY:
tgt = GETJUMPTGT(codestr, i);
! if (!UNCONDITIONAL_JUMP(codestr[tgt]))
continue;
tgttgt = GETJUMPTGT(codestr, tgt);
***************
*** 496,500 ****
code = PyString_FromStringAndSize(codestr, codelen);
PyMem_Free(codestr);
- PyMem_Free(blocks);
return code;
--- 423,426 ----