mirror of
https://github.com/python/cpython.git
synced 2025-07-23 19:25:40 +00:00
gh-115999: Enable free-threaded specialization of LOAD_CONST (#129365)
Enable free-threaded specialization of LOAD_CONST.
This commit is contained in:
parent
789390872b
commit
5c930a26fb
4 changed files with 39 additions and 4 deletions
|
@ -294,10 +294,20 @@ dummy_func(
|
|||
* marshalling can intern strings and make them immortal. */
|
||||
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||
value = PyStackRef_FromPyObjectNew(obj);
|
||||
#if ENABLE_SPECIALIZATION
|
||||
#if ENABLE_SPECIALIZATION_FT
|
||||
#ifdef Py_GIL_DISABLED
|
||||
uint8_t expected = LOAD_CONST;
|
||||
if (!_Py_atomic_compare_exchange_uint8(
|
||||
&this_instr->op.code, &expected,
|
||||
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL)) {
|
||||
// We might lose a race with instrumentation, which we don't care about.
|
||||
assert(expected >= MIN_INSTRUMENTED_OPCODE);
|
||||
}
|
||||
#else
|
||||
if (this_instr->op.code == LOAD_CONST) {
|
||||
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -2558,7 +2568,7 @@ dummy_func(
|
|||
}
|
||||
OPCODE_DEFERRED_INC(COMPARE_OP);
|
||||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
|
||||
op(_COMPARE_OP, (left, right -- res)) {
|
||||
|
|
14
Python/generated_cases.c.h
generated
14
Python/generated_cases.c.h
generated
|
@ -3318,7 +3318,7 @@
|
|||
}
|
||||
OPCODE_DEFERRED_INC(COMPARE_OP);
|
||||
ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter);
|
||||
#endif /* ENABLE_SPECIALIZATION */
|
||||
#endif /* ENABLE_SPECIALIZATION_FT */
|
||||
}
|
||||
// _COMPARE_OP
|
||||
{
|
||||
|
@ -6035,11 +6035,21 @@
|
|||
* marshalling can intern strings and make them immortal. */
|
||||
PyObject *obj = GETITEM(FRAME_CO_CONSTS, oparg);
|
||||
value = PyStackRef_FromPyObjectNew(obj);
|
||||
#if ENABLE_SPECIALIZATION
|
||||
#if ENABLE_SPECIALIZATION_FT
|
||||
#ifdef Py_GIL_DISABLED
|
||||
uint8_t expected = LOAD_CONST;
|
||||
if (!_Py_atomic_compare_exchange_uint8(
|
||||
&this_instr->op.code, &expected,
|
||||
_Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL)) {
|
||||
// We might lose a race with instrumentation, which we don't care about.
|
||||
assert(expected >= MIN_INSTRUMENTED_OPCODE);
|
||||
}
|
||||
#else
|
||||
if (this_instr->op.code == LOAD_CONST) {
|
||||
this_instr->op.code = _Py_IsImmortal(obj) ? LOAD_CONST_IMMORTAL : LOAD_CONST_MORTAL;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
stack_pointer[0] = value;
|
||||
stack_pointer += 1;
|
||||
assert(WITHIN_STACK_BOUNDS());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue