-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-45367: Specialize BINARY_MULTIPLY #28727
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
Changes from all commits
3c85756
300a0ca
d266912
c64540a
5a44ecc
aea424e
37d3716
903ff9c
7aecc97
31c3bb9
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
Specialized the ``BINARY_MULTIPLY`` opcode to ``BINARY_MULTIPLY_INT`` and ``BINARY_MULTIPLY_FLOAT`` using the PEP 659 machinery. |
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 |
---|---|---|
|
@@ -124,6 +124,7 @@ _Py_GetSpecializationStats(void) { | |
err += add_stat_dict(stats, LOAD_GLOBAL, "load_global"); | ||
err += add_stat_dict(stats, LOAD_METHOD, "load_method"); | ||
err += add_stat_dict(stats, BINARY_ADD, "binary_add"); | ||
err += add_stat_dict(stats, BINARY_MULTIPLY, "binary_multiply"); | ||
err += add_stat_dict(stats, BINARY_SUBSCR, "binary_subscr"); | ||
err += add_stat_dict(stats, STORE_ATTR, "store_attr"); | ||
if (err < 0) { | ||
|
@@ -180,6 +181,7 @@ _Py_PrintSpecializationStats(void) | |
print_stats(out, &_specialization_stats[LOAD_GLOBAL], "load_global"); | ||
print_stats(out, &_specialization_stats[LOAD_METHOD], "load_method"); | ||
print_stats(out, &_specialization_stats[BINARY_ADD], "binary_add"); | ||
print_stats(out, &_specialization_stats[BINARY_MULTIPLY], "binary_multiply"); | ||
print_stats(out, &_specialization_stats[BINARY_SUBSCR], "binary_subscr"); | ||
print_stats(out, &_specialization_stats[STORE_ATTR], "store_attr"); | ||
if (out != stderr) { | ||
|
@@ -230,6 +232,7 @@ static uint8_t adaptive_opcodes[256] = { | |
[LOAD_GLOBAL] = LOAD_GLOBAL_ADAPTIVE, | ||
[LOAD_METHOD] = LOAD_METHOD_ADAPTIVE, | ||
[BINARY_ADD] = BINARY_ADD_ADAPTIVE, | ||
[BINARY_MULTIPLY] = BINARY_MULTIPLY_ADAPTIVE, | ||
[BINARY_SUBSCR] = BINARY_SUBSCR_ADAPTIVE, | ||
[STORE_ATTR] = STORE_ATTR_ADAPTIVE, | ||
}; | ||
|
@@ -240,6 +243,7 @@ static uint8_t cache_requirements[256] = { | |
[LOAD_GLOBAL] = 2, /* _PyAdaptiveEntry and _PyLoadGlobalCache */ | ||
[LOAD_METHOD] = 3, /* _PyAdaptiveEntry, _PyAttrCache and _PyObjectCache */ | ||
[BINARY_ADD] = 0, | ||
[BINARY_MULTIPLY] = 0, | ||
[BINARY_SUBSCR] = 0, | ||
[STORE_ATTR] = 2, /* _PyAdaptiveEntry and _PyAttrCache */ | ||
}; | ||
|
@@ -1188,3 +1192,32 @@ _Py_Specialize_BinaryAdd(PyObject *left, PyObject *right, _Py_CODEUNIT *instr) | |
assert(!PyErr_Occurred()); | ||
return 0; | ||
} | ||
|
||
int | ||
_Py_Specialize_BinaryMultiply(PyObject *left, PyObject *right, _Py_CODEUNIT *instr) | ||
{ | ||
if (!Py_IS_TYPE(left, Py_TYPE(right))) { | ||
SPECIALIZATION_FAIL(BINARY_MULTIPLY, SPEC_FAIL_DIFFERENT_TYPES); | ||
goto fail; | ||
} | ||
if (PyLong_CheckExact(left)) { | ||
*instr = _Py_MAKECODEUNIT(BINARY_MULTIPLY_INT, saturating_start()); | ||
goto success; | ||
} | ||
else if (PyFloat_CheckExact(left)) { | ||
*instr = _Py_MAKECODEUNIT(BINARY_MULTIPLY_FLOAT, saturating_start()); | ||
goto success; | ||
} | ||
else { | ||
SPECIALIZATION_FAIL(BINARY_MULTIPLY, SPEC_FAIL_OTHER); | ||
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. Maybe this should be refined further. In another PR, though. 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. I agree. I don't think it will touch pyperformance, but it seems that in our own test suite almost 10% aren't hits #28727 (comment).
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. Most of the non-hits are deferred, not specialization failure, so I think that's because the nature of a lot of test code is to only be run once, without many tight loops. 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. Thanks for pointing that out Dennis. I can't believe I missed that :). That means nearly 100% actual specialization on hot code. Hooray! Off-topic: I've recently wondered if 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. "deferred" means that the Look at the numbers. |
||
} | ||
fail: | ||
STAT_INC(BINARY_MULTIPLY, specialization_failure); | ||
assert(!PyErr_Occurred()); | ||
*instr = _Py_MAKECODEUNIT(_Py_OPCODE(*instr), ADAPTIVE_CACHE_BACKOFF); | ||
return 0; | ||
success: | ||
STAT_INC(BINARY_MULTIPLY, specialization_success); | ||
assert(!PyErr_Occurred()); | ||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.