summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-02-06 22:45:18 (GMT)
committerGitHub <noreply@github.com>2023-02-06 22:45:18 (GMT)
commit38752760c91c87dd67af16d2cee611a22e647567 (patch)
tree824cac44876b08b47e878044d215357581d74343 /Python
parent949c58f945b93af5b7bb70c6448e940da669065d (diff)
downloadcpython-38752760c91c87dd67af16d2cee611a22e647567.zip
cpython-38752760c91c87dd67af16d2cee611a22e647567.tar.gz
cpython-38752760c91c87dd67af16d2cee611a22e647567.tar.bz2
gh-98831: rewrite COPY and SWAP in the instruction definition DSL (#101620)
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c17
-rw-r--r--Python/generated_cases.c.h18
-rw-r--r--Python/opcode_metadata.h8
3 files changed, 21 insertions, 22 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 8993567..0fc0b3b 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -3098,11 +3098,9 @@ dummy_func(
PUSH(result);
}
- // stack effect: ( -- __0)
- inst(COPY) {
- assert(oparg != 0);
- PyObject *peek = PEEK(oparg);
- PUSH(Py_NewRef(peek));
+ inst(COPY, (bottom, unused[oparg-1] -- bottom, unused[oparg-1], top)) {
+ assert(oparg > 0);
+ top = Py_NewRef(bottom);
}
inst(BINARY_OP, (unused/1, lhs, rhs -- res)) {
@@ -3126,12 +3124,9 @@ dummy_func(
ERROR_IF(res == NULL, error);
}
- // stack effect: ( -- )
- inst(SWAP) {
- assert(oparg != 0);
- PyObject *top = TOP();
- SET_TOP(PEEK(oparg));
- PEEK(oparg) = top;
+ inst(SWAP, (bottom, unused[oparg-2], top --
+ top, unused[oparg-2], bottom)) {
+ assert(oparg >= 2);
}
inst(EXTENDED_ARG, (--)) {
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index e524bfc..f0f314a 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3723,9 +3723,12 @@
}
TARGET(COPY) {
- assert(oparg != 0);
- PyObject *peek = PEEK(oparg);
- PUSH(Py_NewRef(peek));
+ PyObject *bottom = PEEK(1 + (oparg-1));
+ PyObject *top;
+ assert(oparg > 0);
+ top = Py_NewRef(bottom);
+ STACK_GROW(1);
+ POKE(1, top);
DISPATCH();
}
@@ -3760,10 +3763,11 @@
}
TARGET(SWAP) {
- assert(oparg != 0);
- PyObject *top = TOP();
- SET_TOP(PEEK(oparg));
- PEEK(oparg) = top;
+ PyObject *top = PEEK(1);
+ PyObject *bottom = PEEK(2 + (oparg-2));
+ assert(oparg >= 2);
+ POKE(1, bottom);
+ POKE(2 + (oparg-2), top);
DISPATCH();
}
diff --git a/Python/opcode_metadata.h b/Python/opcode_metadata.h
index 857526c..948d175 100644
--- a/Python/opcode_metadata.h
+++ b/Python/opcode_metadata.h
@@ -333,11 +333,11 @@ _PyOpcode_num_popped(int opcode, int oparg, bool jump) {
case FORMAT_VALUE:
return -1;
case COPY:
- return -1;
+ return (oparg-1) + 1;
case BINARY_OP:
return 2;
case SWAP:
- return -1;
+ return (oparg-2) + 2;
case EXTENDED_ARG:
return 0;
case CACHE:
@@ -679,11 +679,11 @@ _PyOpcode_num_pushed(int opcode, int oparg, bool jump) {
case FORMAT_VALUE:
return -1;
case COPY:
- return -1;
+ return (oparg-1) + 2;
case BINARY_OP:
return 1;
case SWAP:
- return -1;
+ return (oparg-2) + 2;
case EXTENDED_ARG:
return 0;
case CACHE: