Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Revert some unrelated changes
  • Loading branch information
brandtbucher committed Nov 5, 2022
commit 553ebabc98ff7c7bb88392d6af7541f76d40e331
4 changes: 2 additions & 2 deletions Include/internal/pycore_code.h
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ write_location_entry_start(uint8_t *ptr, int code, int length)
#define ADAPTIVE_BACKOFF_BITS 4

#define ADAPTIVE_BACKOFF_START_VALUE 1
#define ADAPTIVE_BACKOFF_START_BACKOFF 1 // 2**0 <= 1 < 2**1
#define ADAPTIVE_BACKOFF_START_BACKOFF 1

#define ADAPTIVE_BACKOFF_RESTART_VALUE 52
#define ADAPTIVE_BACKOFF_RESTART_BACKOFF 6 // 2**5 <= 53 < 2**6
#define ADAPTIVE_BACKOFF_RESTART_BACKOFF 0

#define MAX_BACKOFF_VALUE (16 - ADAPTIVE_BACKOFF_BITS)

Expand Down
26 changes: 13 additions & 13 deletions Include/internal/pycore_opcode.h

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

57 changes: 29 additions & 28 deletions Include/opcode.h

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

3 changes: 3 additions & 0 deletions Lib/opcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ def pseudo_op(name, op, real_ops):
"COMPARE_OP_INT_JUMP",
"COMPARE_OP_STR_JUMP",
],
"EXTENDED_ARG": [
"EXTENDED_ARG_QUICK",
],
"FOR_ITER": [
"FOR_ITER_LIST",
"FOR_ITER_RANGE",
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,8 @@ def is_specialized(f):
opname in opcode._specialized_instructions
# Exclude superinstructions:
and "__" not in opname
# Exclude "quick" instructions:
and not opname.endswith("_QUICK")
):
return True
return False
Expand Down
77 changes: 41 additions & 36 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,17 @@ dummy_func(
}

inst(COMPARE_OP_GENERIC) {
goto compare_op;
assert(oparg <= Py_GE);
PyObject *right = POP();
PyObject *left = TOP();
PyObject *res = PyObject_RichCompare(left, right, oparg);
SET_TOP(res);
Py_DECREF(left);
Py_DECREF(right);
if (res == NULL) {
goto error;
}
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
}

// stack effect: (__0 -- )
Expand All @@ -2285,18 +2295,7 @@ dummy_func(
STAT_INC(COMPARE_OP, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache);
}
compare_op:
assert(oparg <= Py_GE);
PyObject *right = POP();
PyObject *left = TOP();
PyObject *res = PyObject_RichCompare(left, right, oparg);
SET_TOP(res);
Py_DECREF(left);
Py_DECREF(right);
if (res == NULL) {
goto error;
}
JUMPBY(INLINE_CACHE_ENTRIES_COMPARE_OP);
GO_TO_INSTRUCTION(COMPARE_OP_GENERIC);
}

// stack effect: (__0 -- )
Expand Down Expand Up @@ -3886,7 +3885,19 @@ dummy_func(
}

inst(BINARY_OP_GENERIC) {
goto binary_op;
PyObject *rhs = POP();
PyObject *lhs = TOP();
assert(0 <= oparg);
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
PyObject *res = binary_ops[oparg](lhs, rhs);
Py_DECREF(lhs);
Py_DECREF(rhs);
SET_TOP(res);
if (res == NULL) {
goto error;
}
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
}

// stack effect: (__0 -- )
Expand All @@ -3903,21 +3914,7 @@ dummy_func(
STAT_INC(BINARY_OP, deferred);
DECREMENT_ADAPTIVE_COUNTER(cache);
}
binary_op:
; // Why is this still a thing in 2022?
PyObject *rhs = POP();
PyObject *lhs = TOP();
assert(0 <= oparg);
assert((unsigned)oparg < Py_ARRAY_LENGTH(binary_ops));
assert(binary_ops[oparg]);
PyObject *res = binary_ops[oparg](lhs, rhs);
Py_DECREF(lhs);
Py_DECREF(rhs);
SET_TOP(res);
if (res == NULL) {
goto error;
}
JUMPBY(INLINE_CACHE_ENTRIES_BINARY_OP);
GO_TO_INSTRUCTION(BINARY_OP_GENERIC);
}

// stack effect: ( -- )
Expand All @@ -3931,15 +3928,12 @@ dummy_func(
// stack effect: ( -- )
inst(EXTENDED_ARG) {
assert(oparg);
opcode = _Py_OPCODE(*next_instr);
if (cframe.use_tracing) {
// Deoptimize the next opcode to avoid breaking tracing
// guarantees in quickened instructions:
opcode = _PyOpcode_Deopt[opcode];
PRE_DISPATCH_GOTO();
}
oparg <<= 8;
oparg |= _Py_OPARG(*next_instr);
// We might be tracing. To avoid breaking tracing guarantees in
// quickened instructions, always deoptimize the next opcode:
opcode = _PyOpcode_Deopt[_Py_OPCODE(*next_instr)];
PRE_DISPATCH_GOTO();
// CPython hasn't traced the following instruction historically
// (DO_TRACING would clobber our extended oparg anyways), so just
// skip our usual cframe.use_tracing check before dispatch. Also,
Expand All @@ -3949,6 +3943,16 @@ dummy_func(
DISPATCH_GOTO();
}

// stack effect: ( -- )
inst(EXTENDED_ARG_QUICK) {
assert(cframe.use_tracing == 0);
assert(oparg);
int oldoparg = oparg;
NEXTOPARG();
oparg |= oldoparg << 8;
DISPATCH_GOTO();
}

// stack effect: ( -- )
inst(CACHE) {
Py_UNREACHABLE();
Expand Down Expand Up @@ -3989,6 +3993,7 @@ family(call) = {
family(compare_op) = {
COMPARE_OP, COMPARE_OP_FLOAT_JUMP, COMPARE_OP_GENERIC,
COMPARE_OP_INT_JUMP, COMPARE_OP_STR_JUMP };
family(extended_arg) = { EXTENDED_ARG, EXTENDED_ARG_QUICK };
family(for_iter) = {
FOR_ITER, FOR_ITER_LIST,
FOR_ITER_RANGE };
Expand Down
3 changes: 3 additions & 0 deletions Python/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -8062,6 +8062,7 @@ scan_block_for_locals(basicblock *b, basicblock ***sp)
for (int i = 0; i < b->b_iused; i++) {
struct instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG);
assert(instr->i_opcode != EXTENDED_ARG_QUICK);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
if (instr->i_except != NULL) {
maybe_push(instr->i_except, unsafe_mask, sp);
Expand Down Expand Up @@ -8118,6 +8119,7 @@ fast_scan_many_locals(basicblock *entryblock, int nlocals)
for (int i = 0; i < b->b_iused; i++) {
struct instr *instr = &b->b_instr[i];
assert(instr->i_opcode != EXTENDED_ARG);
assert(instr->i_opcode != EXTENDED_ARG_QUICK);
assert(!IS_SUPERINSTRUCTION_OPCODE(instr->i_opcode));
int arg = instr->i_oparg;
if (arg < 64) {
Expand Down Expand Up @@ -8665,6 +8667,7 @@ fix_cell_offsets(struct compiler *c, basicblock *entryblock, int *fixedmap)
struct instr *inst = &b->b_instr[i];
// This is called before extended args are generated.
assert(inst->i_opcode != EXTENDED_ARG);
assert(inst->i_opcode != EXTENDED_ARG_QUICK);
int oldoffset = inst->i_oparg;
switch(inst->i_opcode) {
case MAKE_CELL:
Expand Down
Loading