summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorT. Wouters <thomas@python.org>2025-01-07 14:41:01 (GMT)
committerGitHub <noreply@github.com>2025-01-07 14:41:01 (GMT)
commit8f93dd8a8f237b277abad20d566df90c5cbd7f1e (patch)
treea7eed0c4de60ef38b80a6929521c8f387e51fc74 /Python
parenta734c1e304ab459fb34a88f6dd2dbd944a1b57c9 (diff)
downloadcpython-8f93dd8a8f237b277abad20d566df90c5cbd7f1e.zip
cpython-8f93dd8a8f237b277abad20d566df90c5cbd7f1e.tar.gz
cpython-8f93dd8a8f237b277abad20d566df90c5cbd7f1e.tar.bz2
gh-115999: Add free-threaded specialization for COMPARE_OP (#126410)
Add free-threaded specialization for COMPARE_OP, and tests for COMPARE_OP specialization in general. Co-authored-by: Donghee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r--Python/bytecodes.c2
-rw-r--r--Python/generated_cases.c.h2
-rw-r--r--Python/specialize.c17
3 files changed, 9 insertions, 12 deletions
diff --git a/Python/bytecodes.c b/Python/bytecodes.c
index 4961693..ec1cd00 100644
--- a/Python/bytecodes.c
+++ b/Python/bytecodes.c
@@ -2464,7 +2464,7 @@ dummy_func(
};
specializing op(_SPECIALIZE_COMPARE_OP, (counter/1, left, right -- left, right)) {
- #if ENABLE_SPECIALIZATION
+ #if ENABLE_SPECIALIZATION_FT
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
next_instr = this_instr;
_Py_Specialize_CompareOp(left, right, next_instr, oparg);
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index b73844c..eaa8a56 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -3229,7 +3229,7 @@
left = stack_pointer[-2];
uint16_t counter = read_u16(&this_instr[1].cache);
(void)counter;
- #if ENABLE_SPECIALIZATION
+ #if ENABLE_SPECIALIZATION_FT
if (ADAPTIVE_COUNTER_TRIGGERS(counter)) {
next_instr = this_instr;
_PyFrame_SetStackPointer(frame, stack_pointer);
diff --git a/Python/specialize.c b/Python/specialize.c
index c918c77..c9325c3 100644
--- a/Python/specialize.c
+++ b/Python/specialize.c
@@ -2480,23 +2480,23 @@ _Py_Specialize_CompareOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *i
{
PyObject *lhs = PyStackRef_AsPyObjectBorrow(lhs_st);
PyObject *rhs = PyStackRef_AsPyObjectBorrow(rhs_st);
+ uint8_t specialized_op;
- assert(ENABLE_SPECIALIZATION);
+ assert(ENABLE_SPECIALIZATION_FT);
assert(_PyOpcode_Caches[COMPARE_OP] == INLINE_CACHE_ENTRIES_COMPARE_OP);
// All of these specializations compute boolean values, so they're all valid
// regardless of the fifth-lowest oparg bit.
- _PyCompareOpCache *cache = (_PyCompareOpCache *)(instr + 1);
if (Py_TYPE(lhs) != Py_TYPE(rhs)) {
SPECIALIZATION_FAIL(COMPARE_OP, compare_op_fail_kind(lhs, rhs));
goto failure;
}
if (PyFloat_CheckExact(lhs)) {
- instr->op.code = COMPARE_OP_FLOAT;
+ specialized_op = COMPARE_OP_FLOAT;
goto success;
}
if (PyLong_CheckExact(lhs)) {
if (_PyLong_IsCompact((PyLongObject *)lhs) && _PyLong_IsCompact((PyLongObject *)rhs)) {
- instr->op.code = COMPARE_OP_INT;
+ specialized_op = COMPARE_OP_INT;
goto success;
}
else {
@@ -2511,19 +2511,16 @@ _Py_Specialize_CompareOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *i
goto failure;
}
else {
- instr->op.code = COMPARE_OP_STR;
+ specialized_op = COMPARE_OP_STR;
goto success;
}
}
SPECIALIZATION_FAIL(COMPARE_OP, compare_op_fail_kind(lhs, rhs));
failure:
- STAT_INC(COMPARE_OP, failure);
- instr->op.code = COMPARE_OP;
- cache->counter = adaptive_counter_backoff(cache->counter);
+ unspecialize(instr);
return;
success:
- STAT_INC(COMPARE_OP, success);
- cache->counter = adaptive_counter_cooldown();
+ specialize(instr, specialized_op);
}
#ifdef Py_STATS