diff options
author | Eric Snow <ericsnowcurrently@gmail.com> | 2021-06-07 22:52:00 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-07 22:52:00 (GMT) |
commit | 631f9938b1604d4f893417ec339b9e0fa9196fb1 (patch) | |
tree | 6a72bf35dafb42ad3d00e153e244538db4a646ee /Include | |
parent | e915db3e9e512249a6f494c0b331db2d021e1f56 (diff) | |
download | cpython-631f9938b1604d4f893417ec339b9e0fa9196fb1.zip cpython-631f9938b1604d4f893417ec339b9e0fa9196fb1.tar.gz cpython-631f9938b1604d4f893417ec339b9e0fa9196fb1.tar.bz2 |
bpo-43693: Add the MAKE_CELL opcode and interleave fast locals offsets. (gh-26396)
This moves logic out of the frame initialization code and into the compiler and eval loop. Doing so simplifies the runtime code and allows us to optimize it better.
https://bugs.python.org/issue43693
Diffstat (limited to 'Include')
-rw-r--r-- | Include/cpython/code.h | 11 | ||||
-rw-r--r-- | Include/internal/pycore_frame.h | 2 | ||||
-rw-r--r-- | Include/opcode.h | 9 |
3 files changed, 16 insertions, 6 deletions
diff --git a/Include/cpython/code.h b/Include/cpython/code.h index c81f9f3..a338374 100644 --- a/Include/cpython/code.h +++ b/Include/cpython/code.h @@ -2,9 +2,16 @@ # error "this header file must not be included directly" #endif +/* Each instruction in a code object is a fixed-width value, + * currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG + * opcode allows for larger values but the current limit is 3 uses + * of EXTENDED_ARG (see Python/wordcode_helpers.h), for a maximum + * 32-bit value. This aligns with the note in Python/compile.c + * (compiler_addop_i_line) indicating that the max oparg value is + * 2**32 - 1, rather than INT_MAX. + */ + typedef uint16_t _Py_CODEUNIT; -// Each oparg must fit in the second half of _Py_CODEUNIT, hence 8 bits. -#define _Py_MAX_OPARG 255 #ifdef WORDS_BIGENDIAN # define _Py_OPCODE(word) ((word) >> 8) diff --git a/Include/internal/pycore_frame.h b/Include/internal/pycore_frame.h index 44f58fb..11c3a2c 100644 --- a/Include/internal/pycore_frame.h +++ b/Include/internal/pycore_frame.h @@ -32,6 +32,8 @@ _PyFrame_GetBuiltins(PyFrameObject *f) int _PyFrame_TakeLocals(PyFrameObject *f); +PyAPI_FUNC(int) _PyFrame_OpAlreadyRan(PyFrameObject *f, int opcode, int oparg); + #ifdef __cplusplus } #endif diff --git a/Include/opcode.h b/Include/opcode.h index a3a8b2a..c65e2f4 100644 --- a/Include/opcode.h +++ b/Include/opcode.h @@ -113,10 +113,11 @@ extern "C" { #define CALL_FUNCTION 131 #define MAKE_FUNCTION 132 #define BUILD_SLICE 133 -#define LOAD_CLOSURE 135 -#define LOAD_DEREF 136 -#define STORE_DEREF 137 -#define DELETE_DEREF 138 +#define MAKE_CELL 135 +#define LOAD_CLOSURE 136 +#define LOAD_DEREF 137 +#define STORE_DEREF 138 +#define DELETE_DEREF 139 #define CALL_FUNCTION_KW 141 #define CALL_FUNCTION_EX 142 #define EXTENDED_ARG 144 |