summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-04 18:43:52 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-04 18:43:52 (GMT)
commit74a69fa662fb844ad3c60eb27b09e5fa1e577305 (patch)
tree251ba06cc429ab62a204e28bece4f382e179c7bf /Python
parentef0e6c3b0485e83444b15c07f9cb1d905203791a (diff)
downloadcpython-74a69fa662fb844ad3c60eb27b09e5fa1e577305.zip
cpython-74a69fa662fb844ad3c60eb27b09e5fa1e577305.tar.gz
cpython-74a69fa662fb844ad3c60eb27b09e5fa1e577305.tar.bz2
Issue #9225: Remove the ROT_FOUR and DUP_TOPX opcode, the latter replaced
by the new (and simpler) DUP_TOP_TWO. Performance isn't changed, but our bytecode is a bit simplified. Patch by Demur Rumed.
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c47
-rw-r--r--Python/compile.c8
-rw-r--r--Python/import.c4
-rw-r--r--Python/opcode_targets.h4
4 files changed, 17 insertions, 46 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 4d583a5..1f78f95 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -1420,50 +1420,21 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
SET_THIRD(v);
FAST_DISPATCH();
- TARGET(ROT_FOUR)
- u = TOP();
- v = SECOND();
- w = THIRD();
- x = FOURTH();
- SET_TOP(v);
- SET_SECOND(w);
- SET_THIRD(x);
- SET_FOURTH(u);
- FAST_DISPATCH();
-
TARGET(DUP_TOP)
v = TOP();
Py_INCREF(v);
PUSH(v);
FAST_DISPATCH();
- TARGET(DUP_TOPX)
- if (oparg == 2) {
- x = TOP();
- Py_INCREF(x);
- w = SECOND();
- Py_INCREF(w);
- STACKADJ(2);
- SET_TOP(x);
- SET_SECOND(w);
- FAST_DISPATCH();
- } else if (oparg == 3) {
- x = TOP();
- Py_INCREF(x);
- w = SECOND();
- Py_INCREF(w);
- v = THIRD();
- Py_INCREF(v);
- STACKADJ(3);
- SET_TOP(x);
- SET_SECOND(w);
- SET_THIRD(v);
- FAST_DISPATCH();
- }
- Py_FatalError("invalid argument to DUP_TOPX"
- " (bytecode corruption?)");
- /* Never returns, so don't bother to set why. */
- break;
+ TARGET(DUP_TOP_TWO)
+ x = TOP();
+ Py_INCREF(x);
+ w = SECOND();
+ Py_INCREF(w);
+ STACKADJ(2);
+ SET_TOP(x);
+ SET_SECOND(w);
+ FAST_DISPATCH();
TARGET(UNARY_POSITIVE)
v = TOP();
diff --git a/Python/compile.c b/Python/compile.c
index aae0339..6963a15 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -680,8 +680,8 @@ opcode_stack_effect(int opcode, int oparg)
return 0;
case DUP_TOP:
return 1;
- case ROT_FOUR:
- return 0;
+ case DUP_TOP_TWO:
+ return 2;
case UNARY_POSITIVE:
case UNARY_NEGATIVE:
@@ -782,8 +782,6 @@ opcode_stack_effect(int opcode, int oparg)
return -1;
case DELETE_GLOBAL:
return 0;
- case DUP_TOPX:
- return oparg;
case LOAD_CONST:
return 1;
case LOAD_NAME:
@@ -3404,7 +3402,7 @@ compiler_handle_subscr(struct compiler *c, const char *kind,
return 0;
}
if (ctx == AugLoad) {
- ADDOP_I(c, DUP_TOPX, 2);
+ ADDOP(c, DUP_TOP_TWO);
}
else if (ctx == AugStore) {
ADDOP(c, ROT_THREE);
diff --git a/Python/import.c b/Python/import.c
index a5277af..d6b19e8 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -101,12 +101,14 @@ typedef unsigned short mode_t;
introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)
Python 3.2a0: 3160 (add SETUP_WITH)
tag: cpython-32
+ Python 3.2a1: 3170 (add DUP_TOP_TWO, remove DUP_TOPX and ROT_FOUR)
+ tag: cpython-32
*/
/* If you change MAGIC, you must change TAG and you must insert the old value
into _PyMagicNumberTags below.
*/
-#define MAGIC (3160 | ((long)'\r'<<16) | ((long)'\n'<<24))
+#define MAGIC (3170 | ((long)'\r'<<16) | ((long)'\n'<<24))
#define TAG "cpython-32"
#define CACHEDIR "__pycache__"
/* Current magic word and string tag as globals. */
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index 20c9f25..8b59c2d 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -4,7 +4,7 @@ static void *opcode_targets[256] = {
&&TARGET_ROT_TWO,
&&TARGET_ROT_THREE,
&&TARGET_DUP_TOP,
- &&TARGET_ROT_FOUR,
+ &&TARGET_DUP_TOP_TWO,
&&_unknown_opcode,
&&_unknown_opcode,
&&_unknown_opcode,
@@ -98,7 +98,7 @@ static void *opcode_targets[256] = {
&&TARGET_DELETE_ATTR,
&&TARGET_STORE_GLOBAL,
&&TARGET_DELETE_GLOBAL,
- &&TARGET_DUP_TOPX,
+ &&_unknown_opcode,
&&TARGET_LOAD_CONST,
&&TARGET_LOAD_NAME,
&&TARGET_BUILD_TUPLE,