Skip to content
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
Next Next commit
Add FT specialization
  • Loading branch information
Eclips4 committed Nov 8, 2024
commit 5e0d8753f3272b8f1ff23f1677a42e3292a8e59d
2 changes: 1 addition & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ dummy_func(
};

specializing op(_SPECIALIZE_UNPACK_SEQUENCE, (counter/1, seq -- seq)) {
#if ENABLE_SPECIALIZATION
#if ENABLE_SPECIALIZATION_FT
Comment thread
mpage marked this conversation as resolved.
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
next_instr = this_instr;
_Py_Specialize_UnpackSequence(seq, next_instr, oparg);
Expand Down
2 changes: 1 addition & 1 deletion Python/generated_cases.c.h

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

35 changes: 12 additions & 23 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,6 @@ _Py_Specialize_CompareOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *i
cache->counter = adaptive_counter_cooldown();
}

#ifdef Py_STATS
static int
unpack_sequence_fail_kind(PyObject *seq)
{
Expand All @@ -2476,46 +2475,36 @@ unpack_sequence_fail_kind(PyObject *seq)
}
return SPEC_FAIL_OTHER;
}
#endif // Py_STATS

void
_Py_Specialize_UnpackSequence(_PyStackRef seq_st, _Py_CODEUNIT *instr, int oparg)
{
PyObject *seq = PyStackRef_AsPyObjectBorrow(seq_st);

assert(ENABLE_SPECIALIZATION);
assert(ENABLE_SPECIALIZATION_FT);
assert(_PyOpcode_Caches[UNPACK_SEQUENCE] ==
INLINE_CACHE_ENTRIES_UNPACK_SEQUENCE);
_PyUnpackSequenceCache *cache = (_PyUnpackSequenceCache *)(instr + 1);
if (PyTuple_CheckExact(seq)) {
if (PyTuple_GET_SIZE(seq) != oparg) {
SPECIALIZATION_FAIL(UNPACK_SEQUENCE, SPEC_FAIL_EXPECTED_ERROR);
goto failure;
unspecialize(instr, SPEC_FAIL_EXPECTED_ERROR);
return;
}
if (PyTuple_GET_SIZE(seq) == 2) {
instr->op.code = UNPACK_SEQUENCE_TWO_TUPLE;
goto success;
specialize(instr, UNPACK_SEQUENCE_TWO_TUPLE);
return;
}
instr->op.code = UNPACK_SEQUENCE_TUPLE;
goto success;
specialize(instr, UNPACK_SEQUENCE_TUPLE);
return;
}
if (PyList_CheckExact(seq)) {
if (PyList_GET_SIZE(seq) != oparg) {
SPECIALIZATION_FAIL(UNPACK_SEQUENCE, SPEC_FAIL_EXPECTED_ERROR);
goto failure;
unspecialize(instr, SPEC_FAIL_EXPECTED_ERROR);
return;
}
instr->op.code = UNPACK_SEQUENCE_LIST;
goto success;
specialize(instr, UNPACK_SEQUENCE_LIST);
return;
}
SPECIALIZATION_FAIL(UNPACK_SEQUENCE, unpack_sequence_fail_kind(seq));
failure:
STAT_INC(UNPACK_SEQUENCE, failure);
instr->op.code = UNPACK_SEQUENCE;
cache->counter = adaptive_counter_backoff(cache->counter);
return;
success:
STAT_INC(UNPACK_SEQUENCE, success);
cache->counter = adaptive_counter_cooldown();
unspecialize(instr, unpack_sequence_fail_kind(seq));
}

#ifdef Py_STATS
Expand Down