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.
This commit is contained in:
parent
ef0e6c3b04
commit
74a69fa662
|
@ -184,17 +184,17 @@ The Python compiler currently generates the following bytecode instructions.
|
||||||
three.
|
three.
|
||||||
|
|
||||||
|
|
||||||
.. opcode:: ROT_FOUR
|
|
||||||
|
|
||||||
Lifts second, third and forth stack item one position up, moves top down to
|
|
||||||
position four.
|
|
||||||
|
|
||||||
|
|
||||||
.. opcode:: DUP_TOP
|
.. opcode:: DUP_TOP
|
||||||
|
|
||||||
Duplicates the reference on top of the stack.
|
Duplicates the reference on top of the stack.
|
||||||
|
|
||||||
|
|
||||||
|
.. opcode:: DUP_TOP_TWO
|
||||||
|
|
||||||
|
Duplicates the two references on top of the stack, leaving them in the
|
||||||
|
same order.
|
||||||
|
|
||||||
|
|
||||||
**Unary operations**
|
**Unary operations**
|
||||||
|
|
||||||
Unary operations take the top of the stack, apply the operation, and push the
|
Unary operations take the top of the stack, apply the operation, and push the
|
||||||
|
@ -531,12 +531,6 @@ the more significant byte last.
|
||||||
are put onto the stack right-to-left.
|
are put onto the stack right-to-left.
|
||||||
|
|
||||||
|
|
||||||
.. opcode:: DUP_TOPX (count)
|
|
||||||
|
|
||||||
Duplicate *count* items, keeping them in the same order. Due to implementation
|
|
||||||
limits, *count* should be between 1 and 5 inclusive.
|
|
||||||
|
|
||||||
|
|
||||||
.. opcode:: STORE_ATTR (namei)
|
.. opcode:: STORE_ATTR (namei)
|
||||||
|
|
||||||
Implements ``TOS.name = TOS1``, where *namei* is the index of name in
|
Implements ``TOS.name = TOS1``, where *namei* is the index of name in
|
||||||
|
|
|
@ -12,7 +12,7 @@ extern "C" {
|
||||||
#define ROT_TWO 2
|
#define ROT_TWO 2
|
||||||
#define ROT_THREE 3
|
#define ROT_THREE 3
|
||||||
#define DUP_TOP 4
|
#define DUP_TOP 4
|
||||||
#define ROT_FOUR 5
|
#define DUP_TOP_TWO 5
|
||||||
#define NOP 9
|
#define NOP 9
|
||||||
|
|
||||||
#define UNARY_POSITIVE 10
|
#define UNARY_POSITIVE 10
|
||||||
|
@ -83,7 +83,7 @@ extern "C" {
|
||||||
#define DELETE_ATTR 96 /* "" */
|
#define DELETE_ATTR 96 /* "" */
|
||||||
#define STORE_GLOBAL 97 /* "" */
|
#define STORE_GLOBAL 97 /* "" */
|
||||||
#define DELETE_GLOBAL 98 /* "" */
|
#define DELETE_GLOBAL 98 /* "" */
|
||||||
#define DUP_TOPX 99 /* number of items to duplicate */
|
|
||||||
#define LOAD_CONST 100 /* Index in const list */
|
#define LOAD_CONST 100 /* Index in const list */
|
||||||
#define LOAD_NAME 101 /* Index in name list */
|
#define LOAD_NAME 101 /* Index in name list */
|
||||||
#define BUILD_TUPLE 102 /* Number of tuple items */
|
#define BUILD_TUPLE 102 /* Number of tuple items */
|
||||||
|
|
|
@ -48,7 +48,7 @@ def_op('POP_TOP', 1)
|
||||||
def_op('ROT_TWO', 2)
|
def_op('ROT_TWO', 2)
|
||||||
def_op('ROT_THREE', 3)
|
def_op('ROT_THREE', 3)
|
||||||
def_op('DUP_TOP', 4)
|
def_op('DUP_TOP', 4)
|
||||||
def_op('ROT_FOUR', 5)
|
def_op('DUP_TOP_TWO', 5)
|
||||||
|
|
||||||
def_op('NOP', 9)
|
def_op('NOP', 9)
|
||||||
def_op('UNARY_POSITIVE', 10)
|
def_op('UNARY_POSITIVE', 10)
|
||||||
|
@ -116,7 +116,6 @@ name_op('STORE_ATTR', 95) # Index in name list
|
||||||
name_op('DELETE_ATTR', 96) # ""
|
name_op('DELETE_ATTR', 96) # ""
|
||||||
name_op('STORE_GLOBAL', 97) # ""
|
name_op('STORE_GLOBAL', 97) # ""
|
||||||
name_op('DELETE_GLOBAL', 98) # ""
|
name_op('DELETE_GLOBAL', 98) # ""
|
||||||
def_op('DUP_TOPX', 99) # number of items to duplicate
|
|
||||||
def_op('LOAD_CONST', 100) # Index in const list
|
def_op('LOAD_CONST', 100) # Index in const list
|
||||||
hasconst.append(100)
|
hasconst.append(100)
|
||||||
name_op('LOAD_NAME', 101) # Index in name list
|
name_op('LOAD_NAME', 101) # Index in name list
|
||||||
|
|
|
@ -700,6 +700,7 @@ Craig Rowland
|
||||||
Clinton Roy
|
Clinton Roy
|
||||||
Paul Rubin
|
Paul Rubin
|
||||||
Sam Ruby
|
Sam Ruby
|
||||||
|
Demur Rumed
|
||||||
Audun S. Runde
|
Audun S. Runde
|
||||||
Rauli Ruohonen
|
Rauli Ruohonen
|
||||||
Jeff Rush
|
Jeff Rush
|
||||||
|
|
|
@ -12,6 +12,10 @@ What's New in Python 3.2 Alpha 2?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- 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.
|
||||||
|
|
||||||
- Issue #9766: Rename poorly named variables exposed by _warnings to prevent
|
- Issue #9766: Rename poorly named variables exposed by _warnings to prevent
|
||||||
confusion with the proper variables names from 'warnings' itself.
|
confusion with the proper variables names from 'warnings' itself.
|
||||||
|
|
||||||
|
|
|
@ -1420,50 +1420,21 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
SET_THIRD(v);
|
SET_THIRD(v);
|
||||||
FAST_DISPATCH();
|
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)
|
TARGET(DUP_TOP)
|
||||||
v = TOP();
|
v = TOP();
|
||||||
Py_INCREF(v);
|
Py_INCREF(v);
|
||||||
PUSH(v);
|
PUSH(v);
|
||||||
FAST_DISPATCH();
|
FAST_DISPATCH();
|
||||||
|
|
||||||
TARGET(DUP_TOPX)
|
TARGET(DUP_TOP_TWO)
|
||||||
if (oparg == 2) {
|
x = TOP();
|
||||||
x = TOP();
|
Py_INCREF(x);
|
||||||
Py_INCREF(x);
|
w = SECOND();
|
||||||
w = SECOND();
|
Py_INCREF(w);
|
||||||
Py_INCREF(w);
|
STACKADJ(2);
|
||||||
STACKADJ(2);
|
SET_TOP(x);
|
||||||
SET_TOP(x);
|
SET_SECOND(w);
|
||||||
SET_SECOND(w);
|
FAST_DISPATCH();
|
||||||
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(UNARY_POSITIVE)
|
TARGET(UNARY_POSITIVE)
|
||||||
v = TOP();
|
v = TOP();
|
||||||
|
|
|
@ -680,8 +680,8 @@ opcode_stack_effect(int opcode, int oparg)
|
||||||
return 0;
|
return 0;
|
||||||
case DUP_TOP:
|
case DUP_TOP:
|
||||||
return 1;
|
return 1;
|
||||||
case ROT_FOUR:
|
case DUP_TOP_TWO:
|
||||||
return 0;
|
return 2;
|
||||||
|
|
||||||
case UNARY_POSITIVE:
|
case UNARY_POSITIVE:
|
||||||
case UNARY_NEGATIVE:
|
case UNARY_NEGATIVE:
|
||||||
|
@ -782,8 +782,6 @@ opcode_stack_effect(int opcode, int oparg)
|
||||||
return -1;
|
return -1;
|
||||||
case DELETE_GLOBAL:
|
case DELETE_GLOBAL:
|
||||||
return 0;
|
return 0;
|
||||||
case DUP_TOPX:
|
|
||||||
return oparg;
|
|
||||||
case LOAD_CONST:
|
case LOAD_CONST:
|
||||||
return 1;
|
return 1;
|
||||||
case LOAD_NAME:
|
case LOAD_NAME:
|
||||||
|
@ -3404,7 +3402,7 @@ compiler_handle_subscr(struct compiler *c, const char *kind,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (ctx == AugLoad) {
|
if (ctx == AugLoad) {
|
||||||
ADDOP_I(c, DUP_TOPX, 2);
|
ADDOP(c, DUP_TOP_TWO);
|
||||||
}
|
}
|
||||||
else if (ctx == AugStore) {
|
else if (ctx == AugStore) {
|
||||||
ADDOP(c, ROT_THREE);
|
ADDOP(c, ROT_THREE);
|
||||||
|
|
|
@ -101,12 +101,14 @@ typedef unsigned short mode_t;
|
||||||
introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)
|
introduce POP_JUMP_IF_FALSE and POP_JUMP_IF_TRUE)
|
||||||
Python 3.2a0: 3160 (add SETUP_WITH)
|
Python 3.2a0: 3160 (add SETUP_WITH)
|
||||||
tag: cpython-32
|
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
|
/* If you change MAGIC, you must change TAG and you must insert the old value
|
||||||
into _PyMagicNumberTags below.
|
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 TAG "cpython-32"
|
||||||
#define CACHEDIR "__pycache__"
|
#define CACHEDIR "__pycache__"
|
||||||
/* Current magic word and string tag as globals. */
|
/* Current magic word and string tag as globals. */
|
||||||
|
|
|
@ -4,7 +4,7 @@ static void *opcode_targets[256] = {
|
||||||
&&TARGET_ROT_TWO,
|
&&TARGET_ROT_TWO,
|
||||||
&&TARGET_ROT_THREE,
|
&&TARGET_ROT_THREE,
|
||||||
&&TARGET_DUP_TOP,
|
&&TARGET_DUP_TOP,
|
||||||
&&TARGET_ROT_FOUR,
|
&&TARGET_DUP_TOP_TWO,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
&&_unknown_opcode,
|
&&_unknown_opcode,
|
||||||
|
@ -98,7 +98,7 @@ static void *opcode_targets[256] = {
|
||||||
&&TARGET_DELETE_ATTR,
|
&&TARGET_DELETE_ATTR,
|
||||||
&&TARGET_STORE_GLOBAL,
|
&&TARGET_STORE_GLOBAL,
|
||||||
&&TARGET_DELETE_GLOBAL,
|
&&TARGET_DELETE_GLOBAL,
|
||||||
&&TARGET_DUP_TOPX,
|
&&_unknown_opcode,
|
||||||
&&TARGET_LOAD_CONST,
|
&&TARGET_LOAD_CONST,
|
||||||
&&TARGET_LOAD_NAME,
|
&&TARGET_LOAD_NAME,
|
||||||
&&TARGET_BUILD_TUPLE,
|
&&TARGET_BUILD_TUPLE,
|
||||||
|
|
Loading…
Reference in New Issue