Skip to content
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

GH-98686: Get rid of "adaptive" and "quick" instructions #99182

Merged
merged 25 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2dc5e71
Combine all unquickened and adaptive instructions
brandtbucher Oct 20, 2022
15c806f
Merge EXTENDED_ARG and EXTENDED_ARG_QUICK
brandtbucher Oct 20, 2022
7c164d2
Add back BINARY_OP_GENERIC and COMPARE_OP_GENERIC
brandtbucher Oct 20, 2022
2eda520
Merge the miss and backoff counters
brandtbucher Oct 20, 2022
e36c5d7
make regen-cases
brandtbucher Oct 20, 2022
3caa5d4
Try inlining the miss label everywhere
brandtbucher Oct 20, 2022
db558f1
Update adaptive.md
brandtbucher Oct 21, 2022
b8796e6
Remove branching from EXTENDED_ARG
brandtbucher Oct 21, 2022
a7a451b
fixup
brandtbucher Oct 21, 2022
6fdf5ad
Remove tracing branches in adaptive instructions
brandtbucher Oct 21, 2022
e69e254
Remove error checking from many specializations
brandtbucher Oct 21, 2022
513aaab
Fix macro
brandtbucher Oct 21, 2022
a5c6cab
Catch up with main
brandtbucher Oct 21, 2022
1cd6d66
Make sure stats overhead is disabled be default
brandtbucher Oct 21, 2022
ea175fc
Use a single direct jump for misses
brandtbucher Nov 5, 2022
4dbff4d
Catch up with main
brandtbucher Nov 5, 2022
553ebab
Revert some unrelated changes
brandtbucher Nov 5, 2022
dc545bd
Clean up the diff
brandtbucher Nov 5, 2022
3639b66
Clarify the reasoning behind each counter value
brandtbucher Nov 5, 2022
84bc481
Merge EXTENDED_ARG and EXTENDED_ARG_QUICK
brandtbucher Nov 5, 2022
6e60694
Catch up with main
brandtbucher Nov 5, 2022
f885e6c
Fix stats
brandtbucher Nov 5, 2022
f33d882
fixup
brandtbucher Nov 5, 2022
cf98d4a
blurb add
brandtbucher Nov 6, 2022
58698db
Catch up with main
brandtbucher Oct 21, 2022
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
45 changes: 33 additions & 12 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ typedef struct {

#define INLINE_CACHE_ENTRIES_FOR_ITER CACHE_ENTRIES(_PyForIterCache)

extern uint8_t _PyOpcode_Adaptive[256];

// Borrowed references to common callables:
struct callable_cache {
PyObject *isinstance;
Expand Down Expand Up @@ -219,11 +217,14 @@ extern int _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
PyObject *name);
extern int _Py_Specialize_StoreAttr(PyObject *owner, _Py_CODEUNIT *instr,
PyObject *name);
extern int _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins, _Py_CODEUNIT *instr, PyObject *name);
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);
extern void _Py_Specialize_LoadGlobal(PyObject *globals, PyObject *builtins,
_Py_CODEUNIT *instr, PyObject *name);
extern void _Py_Specialize_BinarySubscr(PyObject *sub, PyObject *container,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_StoreSubscr(PyObject *container, PyObject *sub,
_Py_CODEUNIT *instr);
extern void _Py_Specialize_Call(PyObject *callable, _Py_CODEUNIT *instr,
int nargs, PyObject *kwnames);
extern void _Py_Specialize_BinaryOp(PyObject *lhs, PyObject *rhs, _Py_CODEUNIT *instr,
int oparg, PyObject **locals);
extern void _Py_Specialize_CompareOp(PyObject *lhs, PyObject *rhs,
Expand Down Expand Up @@ -377,8 +378,22 @@ write_location_entry_start(uint8_t *ptr, int code, int length)

/* With a 16-bit counter, we have 12 bits for the counter value, and 4 bits for the backoff */
#define ADAPTIVE_BACKOFF_BITS 4
/* The initial counter value is 1 == 2**ADAPTIVE_BACKOFF_START - 1 */
#define ADAPTIVE_BACKOFF_START 1

// A value of 1 means that we attempt to specialize the *second* time each
// instruction is executed. Executing twice is a much better indicator of
// "hotness" than executing once, but additional warmup delays only prevent
// specialization. Most types stabilize by the second execution, too:
#define ADAPTIVE_WARMUP_VALUE 1
#define ADAPTIVE_WARMUP_BACKOFF 1

// A value of 52 means that we attempt to re-specialize after 53 misses (a prime
// number, useful for avoiding artifacts if every nth value is a different type
// or something). Setting the backoff to 0 means that the counter is reset to
// the same state as a warming-up instruction (value == 1, backoff == 1) after
// deoptimization. This isn't strictly necessary, but it is bit easier to reason
// about when thinking about the opcode transitions as a state machine:
#define ADAPTIVE_COOLDOWN_VALUE 52
#define ADAPTIVE_COOLDOWN_BACKOFF 0

#define MAX_BACKOFF_VALUE (16 - ADAPTIVE_BACKOFF_BITS)

Expand All @@ -390,9 +405,15 @@ adaptive_counter_bits(int value, int backoff) {
}

static inline uint16_t
adaptive_counter_start(void) {
unsigned int value = (1 << ADAPTIVE_BACKOFF_START) - 1;
return adaptive_counter_bits(value, ADAPTIVE_BACKOFF_START);
adaptive_counter_warmup(void) {
return adaptive_counter_bits(ADAPTIVE_WARMUP_VALUE,
ADAPTIVE_WARMUP_BACKOFF);
}

static inline uint16_t
adaptive_counter_cooldown(void) {
return adaptive_counter_bits(ADAPTIVE_COOLDOWN_VALUE,
ADAPTIVE_COOLDOWN_BACKOFF);
}

static inline uint16_t
Expand Down
114 changes: 57 additions & 57 deletions Include/internal/pycore_opcode.h

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

Loading