@@ -26,11 +26,6 @@ typedef struct {
2626 uint32_t dk_version ;
2727} _PyAttrCache ;
2828
29- typedef struct {
30- uint32_t module_keys_version ;
31- uint32_t builtin_keys_version ;
32- } _PyLoadGlobalCache ;
33-
3429typedef struct {
3530 /* Borrowed ref in LOAD_METHOD */
3631 PyObject * obj ;
@@ -57,23 +52,35 @@ typedef union {
5752 _PyEntryZero zero ;
5853 _PyAdaptiveEntry adaptive ;
5954 _PyAttrCache attr ;
60- _PyLoadGlobalCache load_global ;
6155 _PyObjectCache obj ;
6256 _PyCallCache call ;
6357} SpecializedCacheEntry ;
6458
6559#define INSTRUCTIONS_PER_ENTRY (sizeof(SpecializedCacheEntry)/sizeof(_Py_CODEUNIT))
6660
61+ /* Inline caches */
62+
63+ #define CACHE_ENTRIES (cache ) (sizeof(cache)/sizeof(_Py_CODEUNIT))
64+
65+ typedef struct {
66+ _Py_CODEUNIT counter ;
67+ _Py_CODEUNIT index ;
68+ _Py_CODEUNIT module_keys_version ;
69+ _Py_CODEUNIT _m1 ;
70+ _Py_CODEUNIT builtin_keys_version ;
71+ } _PyLoadGlobalCache ;
72+
73+ #define INLINE_CACHE_ENTRIES_LOAD_GLOBAL CACHE_ENTRIES(_PyLoadGlobalCache)
74+
6775typedef struct {
6876 _Py_CODEUNIT counter ;
6977} _PyBinaryOpCache ;
7078
79+ #define INLINE_CACHE_ENTRIES_BINARY_OP CACHE_ENTRIES(_PyBinaryOpCache)
7180typedef struct {
7281 _Py_CODEUNIT counter ;
7382} _PyUnpackSequenceCache ;
7483
75- #define INLINE_CACHE_ENTRIES_BINARY_OP \
76- (sizeof(_PyBinaryOpCache) / sizeof(_Py_CODEUNIT))
7784
7885#define INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE \
7986 (sizeof(_PyUnpackSequenceCache) / sizeof(_Py_CODEUNIT))
@@ -307,7 +314,7 @@ cache_backoff(_PyAdaptiveEntry *entry) {
307314
308315extern int _Py_Specialize_LoadAttr (PyObject * owner , _Py_CODEUNIT * instr , PyObject * name , SpecializedCacheEntry * cache );
309316extern int _Py_Specialize_StoreAttr (PyObject * owner , _Py_CODEUNIT * instr , PyObject * name , SpecializedCacheEntry * cache );
310- extern int _Py_Specialize_LoadGlobal (PyObject * globals , PyObject * builtins , _Py_CODEUNIT * instr , PyObject * name , SpecializedCacheEntry * cache );
317+ extern int _Py_Specialize_LoadGlobal (PyObject * globals , PyObject * builtins , _Py_CODEUNIT * instr , PyObject * name );
311318extern int _Py_Specialize_LoadMethod (PyObject * owner , _Py_CODEUNIT * instr , PyObject * name , SpecializedCacheEntry * cache );
312319extern int _Py_Specialize_BinarySubscr (PyObject * sub , PyObject * container , _Py_CODEUNIT * instr , SpecializedCacheEntry * cache );
313320extern int _Py_Specialize_StoreSubscr (PyObject * container , PyObject * sub , _Py_CODEUNIT * instr );
@@ -388,6 +395,38 @@ extern PyObject* _Py_GetSpecializationStats(void);
388395#define OBJECT_STAT_INC (name ) ((void)0)
389396#endif
390397
398+ // Cache values are only valid in memory, so use native endianness.
399+ #ifdef WORDS_BIGENDIAN
400+
401+ static inline void
402+ write32 (uint16_t * p , uint32_t val )
403+ {
404+ p [0 ] = val >> 16 ;
405+ p [1 ] = (uint16_t )val ;
406+ }
407+
408+ static inline uint32_t
409+ read32 (uint16_t * p )
410+ {
411+ return (p [0 ] << 16 ) | p [1 ];
412+ }
413+
414+ #else
415+
416+ static inline void
417+ write32 (uint16_t * p , uint32_t val )
418+ {
419+ p [0 ] = (uint16_t )val ;
420+ p [1 ] = val >> 16 ;
421+ }
422+
423+ static inline uint32_t
424+ read32 (uint16_t * p )
425+ {
426+ return p [0 ] | (p [1 ] << 16 );
427+ }
428+
429+ #endif
391430
392431#ifdef __cplusplus
393432}
0 commit comments