8000 feat: bigger CACHE entries for everything, CACHE for JUMP_BACKWARD (#51) · oraluben/cpython@7210772 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7210772

Browse files
feat: bigger CACHE entries for everything, CACHE for JUMP_BACKWARD (python#51)
* feat: store bb_test flag in frame to reload during resume * feat: bigger CACHE entries for everything, CACHE for JUMP_BACKWARD * nit: increase overallocate factor even more * feat: remove bb_flag/bb_test and use only the frame's
1 parent 022997a commit 7210772

File tree

12 files changed

+153
-133
lines changed

12 files changed

+153
-133
lines changed

Include/internal/pycore_code.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,17 @@ typedef struct {
1212
// The LSB indicates whether the bb branch is a type guard or not.
1313
// To get the actual BB ID, do a right bit shift by one.
1414
uint16_t bb_id_tagged;
15+
// Forward jump if required since not all successor BBs are fall-through.
1516
uint16_t successor_jumpby;
17+
// Function pointers to trace.
18+
uint16_t consequent_trace[4];
19+
uint16_t alternative_trace[4];
1620
} _PyBBBranchCache;
1721

1822
#define INLINE_CACHE_ENTRIES_BB_BRANCH CACHE_ENTRIES(_PyBBBranchCache)
1923

24+
#define INLINE_CACHE_ENTRIES_JUMP_BACKWARD CACHE_ENTRIES(_PyBBBranchCache)
25+
2026
/* PEP 659
2127
* Specialization and quickening structs and helper functions
2228
*/
@@ -103,6 +109,7 @@ typedef struct {
103109

104110
#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)
105111

112+
106113
typedef struct {
107114
uint16_t counter;
108115
} _PySendCache;
@@ -269,8 +276,8 @@ extern int _PyStaticCode_Init(PyCodeObject *co);
269276
// requires a stack element to be popped.
270277
#define BB_TEST(gen_bb_is_successor, gen_bb_requires_pop) \
271278
(((gen_bb_is_successor) << 4) | (gen_bb_requires_pop))
272-
#define BB_TEST_IS_SUCCESSOR(bb_test) ((bb_test) >> 4)
273-
#define BB_TEST_GET_N_REQUIRES_POP(bb_test) ((bb_test) & 0b1111)
279+
#define BB_TEST_IS_SUCCESSOR(frame) ((frame->bb_test) >> 4)
280+
#define BB_TEST_GET_N_REQUIRES_POP(bb_flag) ((bb_flag) & 0b1111)
274281

275282
extern _Py_CODEUNIT *_PyCode_Tier2Warmup(struct _PyInterpreterFrame *,
276283
_Py_CODEUNIT *);

Include/internal/pycore_frame.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ typedef struct _PyInterpreterFrame {
6363
uint16_t yield_offset;
6464
char owner;
6565
bool is_tier2;
66+
// For restoring state after entering the JIT code.
67+
char bb_test;
6668
/* Locals and stack and unboxed bit mask */
6769
PyObject *localsplus[1];
6870
} _PyInterpreterFrame;
@@ -138,6 +140,7 @@ _PyFrame_Initialize(
138140
frame->is_tier2 = false;
139141
frame->prev_instr = _PyCode_CODE(code) - 1;
140142
}
143+
frame->bb_test = BB_TEST(0, 0);
141144
frame->yield_offset = 0;
142145
frame->owner = FRAME_OWNED_BY_THREAD;
143146

Include/internal/pycore_opcode.h

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/dis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
if uop.startswith('BB_BRANCH') or uop.startswith('BB_JUMP'):
6363
if uop.startswith('BB_JUMP'):
6464
_bb_jumps.append(uop_opcode)
65-
_inline_cache_entries[uop_opcode] = 2
65+
_inline_cache_entries[uop_opcode] = sum(_cache_format['BB_BRANCH'].values())
6666
_uop_hasoparg.append(uop_opcode)
6767
if uop.startswith('BB_TEST_ITER'):
68-
_inline_cache_entries[uop_opcode] = 1
68+
_inline_cache_entries[uop_opcode] = 1
6969

7070
deoptmap = {
7171
specialized: base for base, family in _specializations.items() for specialized in family

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ def _write_atomic(path, data, mode=0o666):
436436
# Python 3.12a6 3520 (Remove PREP_RERAISE_STAR, add CALL_INTRINSIC_2)
437437
# Python 3.12a7 3521 (Shrink the LOAD_GLOBAL caches)
438438
# Python 3.12a7 3523 (Convert COMPARE_AND_BRANCH back to COMPARE_OP)
439+
# Python 3.12a7 3524 (pylbbv: Add support for tier 2 JIT)
439440

440441
# Python 3.13 will start with 3550
441442

@@ -452,7 +453,7 @@ def _write_atomic(path, data, mode=0o666):
452453
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
453454
# in PC/launcher.c must also be updated.
454455

455-
MAGIC_NUMBER = (3523).to_bytes(2, 'little') + b'\r\n'
456+
MAGIC_NUMBER = (3524).to_bytes(2, 'little') + b'\r\n'
456457

457458
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
458459

Lib/opcode.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,8 +446,17 @@ def pseudo_op(name, op, real_ops):
446446
},
447447
"BB_BRANCH" : {
448448
"bb_id": 1,
449-
"forward_jumpby": 1
449+
"forward_jumpby": 1,
450+
"consequent_trace": 4,
451+
"alternative_trace": 4,
450452
},
453+
# Keep in sync with BB_BRANCH for simplicity's sake
454+
"JUMP_BACKWARD": {
455+
"bb_id": 1,
456+
"forward_jumpby": 1,
457+
"consequent_trace": 4,
458+
"alternative_trace": 4,
459+
}
451460
}
452461

453462
_inline_cache_entries = [

Programs/test_frozenmain.h

Lines changed: 27 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0