mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
GH-100222: Redefine _Py_CODEUNIT as a union to clarify structure of code unit. (GH-100223)
This commit is contained in:
parent
985a71032b
commit
6997e77bdf
9 changed files with 150 additions and 134 deletions
|
|
@ -16,21 +16,24 @@ extern "C" {
|
|||
* 2**32 - 1, rather than INT_MAX.
|
||||
*/
|
||||
|
||||
typedef uint16_t _Py_CODEUNIT;
|
||||
typedef union {
|
||||
uint16_t cache;
|
||||
struct {
|
||||
uint8_t opcode;
|
||||
uint8_t oparg;
|
||||
};
|
||||
} _Py_CODEUNIT;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
# define _Py_OPCODE(word) ((word) >> 8)
|
||||
# define _Py_OPARG(word) ((word) & 255)
|
||||
# define _Py_MAKECODEUNIT(opcode, oparg) (((opcode)<<8)|(oparg))
|
||||
#else
|
||||
# define _Py_OPCODE(word) ((word) & 255)
|
||||
# define _Py_OPARG(word) ((word) >> 8)
|
||||
# define _Py_MAKECODEUNIT(opcode, oparg) ((opcode)|((oparg)<<8))
|
||||
#endif
|
||||
#define _Py_OPCODE(word) ((word).opcode)
|
||||
#define _Py_OPARG(word) ((word).oparg)
|
||||
|
||||
// Use "unsigned char" instead of "uint8_t" here to avoid illegal aliasing:
|
||||
#define _Py_SET_OPCODE(word, opcode) \
|
||||
do { ((unsigned char *)&(word))[0] = (opcode); } while (0)
|
||||
static inline void
|
||||
_py_set_opocde(_Py_CODEUNIT *word, uint8_t opcode)
|
||||
{
|
||||
word->opcode = opcode;
|
||||
}
|
||||
|
||||
#define _Py_SET_OPCODE(word, opcode) _py_set_opocde(&(word), opcode)
|
||||
|
||||
typedef struct {
|
||||
PyObject *_co_code;
|
||||
|
|
|
|||
|
|
@ -18,53 +18,53 @@ extern "C" {
|
|||
#define CACHE_ENTRIES(cache) (sizeof(cache)/sizeof(_Py_CODEUNIT))
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT index;
|
||||
_Py_CODEUNIT module_keys_version[2];
|
||||
_Py_CODEUNIT builtin_keys_version;
|
||||
uint16_t counter;
|
||||
uint16_t index;
|
||||
uint16_t module_keys_version[2];
|
||||
uint16_t builtin_keys_version;
|
||||
} _PyLoadGlobalCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_LOAD_GLOBAL CACHE_ENTRIES(_PyLoadGlobalCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
uint16_t counter;
|
||||
} _PyBinaryOpCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
uint16_t counter;
|
||||
} _PyUnpackSequenceCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE \
|
||||
CACHE_ENTRIES(_PyUnpackSequenceCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT mask;
|
||||
uint16_t counter;
|
||||
uint16_t mask;
|
||||
} _PyCompareOpCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_COMPARE_OP CACHE_ENTRIES(_PyCompareOpCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT type_version[2];
|
||||
_Py_CODEUNIT func_version;
|
||||
uint16_t counter;
|
||||
uint16_t type_version[2];
|
||||
uint16_t func_version;
|
||||
} _PyBinarySubscrCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_BINARY_SUBSCR CACHE_ENTRIES(_PyBinarySubscrCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT version[2];
|
||||
_Py_CODEUNIT index;
|
||||
uint16_t counter;
|
||||
uint16_t version[2];
|
||||
uint16_t index;
|
||||
} _PyAttrCache;
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT type_version[2];
|
||||
_Py_CODEUNIT keys_version[2];
|
||||
_Py_CODEUNIT descr[4];
|
||||
uint16_t counter;
|
||||
uint16_t type_version[2];
|
||||
uint16_t keys_version[2];
|
||||
uint16_t descr[4];
|
||||
} _PyLoadMethodCache;
|
||||
|
||||
|
||||
|
|
@ -74,21 +74,21 @@ typedef struct {
|
|||
#define INLINE_CACHE_ENTRIES_STORE_ATTR CACHE_ENTRIES(_PyAttrCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT func_version[2];
|
||||
_Py_CODEUNIT min_args;
|
||||
uint16_t counter;
|
||||
uint16_t func_version[2];
|
||||
uint16_t min_args;
|
||||
} _PyCallCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_CALL CACHE_ENTRIES(_PyCallCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
uint16_t counter;
|
||||
} _PyStoreSubscrCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_STORE_SUBSCR CACHE_ENTRIES(_PyStoreSubscrCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
uint16_t counter;
|
||||
} _PyForIterCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)
|
||||
|
|
@ -409,7 +409,7 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
|
|||
static inline uint16_t
|
||||
adaptive_counter_bits(int value, int backoff) {
|
||||
return (value << ADAPTIVE_BACKOFF_BITS) |
|
||||
(backoff & ((1<<ADAPTIVE_BACKOFF_BITS)-1));
|
||||
(backoff & ((1<<ADAPTIVE_BACKOFF_BITS)-1));
|
||||
}
|
||||
|
||||
static inline uint16_t
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue