8000 bpo-46841: Use inline caching for calls by brandtbucher · Pull Request #31709 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-46841: Use inline caching for calls #31709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean things up
  • Loading branch information
brandtbucher committed Mar 5, 2022
comm 8000 it ba214fc555bd6d49d3f82bb492c556c4ea41b315
11 changes: 6 additions & 5 deletions Include/internal/pycore_code.h
8000
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ extern "C" {
*/


/* Inline caches */
// Inline caches. If you change the number of cache entries for an instruction,
// you must *also* bump the magic number in Lib/importlib/_bootstap_external.py!

#define CACHE_ENTRIES(cache) (sizeof(cache)/sizeof(_Py_CODEUNIT))

Expand Down Expand Up @@ -70,20 +71,16 @@ typedef struct {

#define INLINE_CACHE_ENTRIES_LOAD_METHOD CACHE_ENTRIES(_PyLoadMethodCache)

// XXX: These members can definitely shrink:
typedef struct {
_Py_CODEUNIT counter;
_Py_CODEUNIT func_version[2];
_Py_CODEUNIT min_args;
_Py_CODEUNIT defaults_len;
} _PyCallCache;

#define INLINE_CACHE_ENTRIES_CALL CACHE_ENTRIES(_PyCallCache)

// XXX: Combine with _PyCallCache?
typedef struct {
_Py_CODEUNIT counter;
_Py_CODEUNIT callable[4];
} _PyPrecallCache;

#define INLINE_CACHE_ENTRIES_PRECALL CACHE_ENTRIES(_PyPrecallCache)
Expand Down Expand Up @@ -116,6 +113,10 @@ _Py_IncrementCountAndMaybeQuicken(PyCodeObject *code)

extern Py_ssize_t _Py_QuickenedCount;

extern PyObject *builtin_isinstance;
extern PyObject *builtin_len;
extern PyObject *builtin_list_append;

/* "Locals plus" for a code object is the set of locals + cell vars +
* free vars. This relates to variable names as well as offsets into
* the "fast locals" storage array of execution frames. The compiler
Expand Down
144 changes: 72 additions & 72 deletions Include/opcode.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Lib/importlib/_bootstrap_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def _write_atomic(path, data, mode=0o666):
# Python 3.11a5 3484 (Use inline caching for LOAD_ATTR, LOAD_METHOD, and
# STORE_ATTR)
# Python 3.11a5 3485 (Add an oparg to GET_AWAITABLE)
# Python 3.11a6 3486 (Use inline caching for PRECALL and CALL)

# Python 3.12 will start with magic number 3500

Expand All @@ -407,7 +408,7 @@ def _write_atomic(path, data, mode=0o666):
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
# in PC/launcher.c must also be updated.

MAGIC_NUMBER = (3485).to_bytes(2, 'little') + b'\r\n'
MAGIC_NUMBER = (3486).to_bytes(2, 'little') + b'\r\n'
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c

_PYCACHE = '__pycache__'
Expand Down
6 changes: 3 additions & 3 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def jabs_op(name, op, entries=0):
# Instruction opcodes for compiled code
# Blank lines correspond to available opcodes

def_op('CACHE', 0)
def_op('POP_TOP', 1)
def_op('PUSH_NULL', 2)
def_op('CACHE', 3)

def_op('NOP', 9)
def_op('UNARY_POSITIVE', 10)
Expand Down Expand Up @@ -191,9 +191,9 @@ def jabs_op(name, op, entries=0):
def_op('SET_UPDATE', 163)
def_op('DICT_MERGE', 164)
def_op('DICT_UPDATE', 165)
def_op('PRECALL', 166, 5)
def_op('PRECALL', 166, 1)

def_op('CALL', 171, 5)
def_op('CALL', 171, 4)
def_op('KW_NAMES', 172)
hasconst.append(172)

Expand Down
Loading
0