mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-46841: Use inline cache for BINARY_SUBSCR
. (GH-31618)
This commit is contained in:
parent
e91b0a7139
commit
3b0f1c5a71
11 changed files with 76 additions and 39 deletions
|
@ -229,6 +229,13 @@ struct _typeobject {
|
|||
vectorcallfunc tp_vectorcall;
|
||||
};
|
||||
|
||||
/* This struct is used by the specializer
|
||||
* It should should be treated as an opaque blob
|
||||
* by code other than the specializer and interpreter. */
|
||||
struct _specialization_cache {
|
||||
PyObject *getitem;
|
||||
};
|
||||
|
||||
/* The *real* layout of a type object when allocated on the heap */
|
||||
typedef struct _heaptypeobject {
|
||||
/* Note: there's a dependency on the order of these members
|
||||
|
@ -247,6 +254,7 @@ typedef struct _heaptypeobject {
|
|||
struct _dictkeysobject *ht_cached_keys;
|
||||
PyObject *ht_module;
|
||||
char *_ht_tpname; // Storage for "tp_name"; see PyType_FromModuleAndSpec
|
||||
struct _specialization_cache _spec_cache; // For use by the specializer.
|
||||
/* here are optional user slots, followed by the members. */
|
||||
} PyHeapTypeObject;
|
||||
|
||||
|
|
|
@ -92,6 +92,15 @@ typedef struct {
|
|||
|
||||
#define INLINE_CACHE_ENTRIES_COMPARE_OP CACHE_ENTRIES(_PyCompareOpCache)
|
||||
|
||||
typedef struct {
|
||||
_Py_CODEUNIT counter;
|
||||
_Py_CODEUNIT type_version;
|
||||
_Py_CODEUNIT _t1;
|
||||
_Py_CODEUNIT func_version;
|
||||
} _PyBinarySubscrCache;
|
||||
|
||||
#define INLINE_CACHE_ENTRIES_BINARY_SUBSCR CACHE_ENTRIES(_PyBinarySubscrCache)
|
||||
|
||||
/* Maximum size of code to quicken, in code units. */
|
||||
#define MAX_SIZE_TO_QUICKEN 5000
|
||||
|
||||
|
@ -323,7 +332,7 @@ extern int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObjec
|
|||
extern int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
|
||||
extern int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name);
|
||||
extern int _Py_Specialize_LoadMethod(PyObject *owner, _Py_CODEUNIT *instr, PyObject *name, SpecializedCacheEntry *cache);
|
||||
extern int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr, SpecializedCacheEntry *cache);
|
||||
extern int _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container, _Py_CODEUNIT *instr);
|
||||
extern int _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub, _Py_CODEUNIT *instr);
|
||||
extern int _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr, int nargs,
|
||||
PyObject *kwnames, SpecializedCacheEntry *cache);
|
||||
|
|
1
Include/opcode.h
generated
1
Include/opcode.h
generated
|
@ -211,6 +211,7 @@ static const uint32_t _PyOpcode_Jump[8] = {
|
|||
};
|
||||
|
||||
const uint8_t _PyOpcode_InlineCacheEntries[256] = {
|
||||
[BINARY_SUBSCR] = 4,
|
||||
[UNPACK_SEQUENCE] = 1,
|
||||
[COMPARE_OP] = 2,
|
||||
[LOAD_GLOBAL] = 5,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue