-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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-115999: Add free-threaded specialization for COMPARE_OP #126410
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2382,8 +2382,9 @@ _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. | ||
|
@@ -2393,12 +2394,12 @@ _Py_Specialize_CompareOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *i | |
goto failure; | ||
} | ||
if (PyFloat_CheckExact(lhs)) { | ||
instr->op.code = COMPARE_OP_FLOAT; | ||
specialized_op = COMPARE_OP_FLOAT; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now you can use helpers to write it, like |
||
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 { | ||
|
@@ -2413,18 +2414,19 @@ _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; | ||
SET_OPCODE_OR_RETURN(instr, COMPARE_OP); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same applies to that piece of code, you can remove both of failure and success blocks, now you just need to do Also don't forget to remove the |
||
cache->counter = adaptive_counter_backoff(cache->counter); | ||
return; | ||
success: | ||
STAT_INC(COMPARE_OP, success); | ||
SET_OPCODE_OR_RETURN(instr, specialized_op); | ||
cache->counter = adaptive_counter_cooldown(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this test to a more appropriate location, like
test_opcache
?Also, can we avoid hardcoding sequences of instructions into the tests and use a behavioral approach: testing that the behavior is the same with and without specialization.
We should already have tests for specialization of
COMPARE_OP
somewhere.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Behavioural tests specifically for specialization sound like a great idea regardless of whether we're free-threaded or not. They should still make sure that actual specialization happened, and not just exercise some code. As far as I can tell we don't have any of those right now. I assume that was on purpose.
I agree we should already have tests for specialization of COMPARE_OP, but we don't. That's why I added the new test, similar to the existing test for specialization of BINARY_OP, which Matt adapted for free-threaded specialization in #123926. That test existed here, in test_dis. I assume they were added here on purpose. Should all those tests be moved to a more appropriate location?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look: #126498,
even I am not sure Mark intended these kinds of tests.
(If I add COMPARE_OP tests, it is properly failed.)