aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/generated_cases.c.h
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2025-01-16 15:22:13 +0000
committerGitHub <noreply@github.com>2025-01-16 15:22:13 +0000
commit3893a92d956363fa2443bc5e47d4bae3deddacef (patch)
treee87b4c94dfa6cc47ba4610d93db82dd15791a2fa /Python/generated_cases.c.h
parente81fe940c9bd092f6de558fa965100502b78da0f (diff)
downloadcpython-3893a92d956363fa2443bc5e47d4bae3deddacef.tar.gz
cpython-3893a92d956363fa2443bc5e47d4bae3deddacef.zip
gh-100239: specialize long tail of binary operations (#128722)
Diffstat (limited to 'Python/generated_cases.c.h')
-rw-r--r--Python/generated_cases.c.h99
1 files changed, 73 insertions, 26 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h
index 81408380d6b..dc90f75f264 100644
--- a/Python/generated_cases.c.h
+++ b/Python/generated_cases.c.h
@@ -11,10 +11,10 @@
TARGET(BINARY_OP) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP);
PREDICTED(BINARY_OP);
- _Py_CODEUNIT* const this_instr = next_instr - 2;
+ _Py_CODEUNIT* const this_instr = next_instr - 6;
(void)this_instr;
_PyStackRef lhs;
_PyStackRef rhs;
@@ -39,6 +39,7 @@
assert(NB_ADD <= oparg);
assert(oparg <= NB_INPLACE_XOR);
}
+ /* Skip 4 cache entries */
// _BINARY_OP
{
PyObject *lhs_o = PyStackRef_AsPyObjectBorrow(lhs);
@@ -60,9 +61,9 @@
TARGET(BINARY_OP_ADD_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -75,7 +76,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -98,9 +99,9 @@
TARGET(BINARY_OP_ADD_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -113,7 +114,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -135,9 +136,9 @@
TARGET(BINARY_OP_ADD_UNICODE) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_ADD_UNICODE);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -150,7 +151,7 @@
DEOPT_IF(!PyUnicode_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_ADD_UNICODE
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -170,11 +171,57 @@
DISPATCH();
}
+ TARGET(BINARY_OP_EXTEND) {
+ _Py_CODEUNIT* const this_instr = frame->instr_ptr = next_instr;
+ next_instr += 6;
+ INSTRUCTION_STATS(BINARY_OP_EXTEND);
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
+ _PyStackRef left;
+ _PyStackRef right;
+ _PyStackRef res;
+ /* Skip 1 cache entry */
+ // _GUARD_BINARY_OP_EXTEND
+ {
+ right = stack_pointer[-1];
+ left = stack_pointer[-2];
+ PyObject *descr = read_obj(&this_instr[2].cache);
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ assert(d && d->guard);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ int res = d->guard(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ DEOPT_IF(!res, BINARY_OP);
+ }
+ /* Skip -4 cache entry */
+ // _BINARY_OP_EXTEND
+ {
+ PyObject *descr = read_obj(&this_instr[2].cache);
+ PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
+ PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
+ assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5);
+ _PyBinaryOpSpecializationDescr *d = (_PyBinaryOpSpecializationDescr*)descr;
+ STAT_INC(BINARY_OP, hit);
+ _PyFrame_SetStackPointer(frame, stack_pointer);
+ PyObject *res_o = d->action(left_o, right_o);
+ stack_pointer = _PyFrame_GetStackPointer(frame);
+ PyStackRef_CLOSE(left);
+ PyStackRef_CLOSE(right);
+ res = PyStackRef_FromPyObjectSteal(res_o);
+ }
+ stack_pointer[-2] = res;
+ stack_pointer += -1;
+ assert(WITHIN_STACK_BOUNDS());
+ DISPATCH();
+ }
+
TARGET(BINARY_OP_INPLACE_ADD_UNICODE) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_INPLACE_ADD_UNICODE);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
// _GUARD_BOTH_UNICODE
@@ -186,7 +233,7 @@
DEOPT_IF(!PyUnicode_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyUnicode_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_INPLACE_ADD_UNICODE
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -235,9 +282,9 @@
TARGET(BINARY_OP_MULTIPLY_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_MULTIPLY_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -250,7 +297,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_MULTIPLY_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -273,9 +320,9 @@
TARGET(BINARY_OP_MULTIPLY_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_MULTIPLY_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -288,7 +335,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_MULTIPLY_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -310,9 +357,9 @@
TARGET(BINARY_OP_SUBTRACT_FLOAT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_SUBTRACT_FLOAT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -325,7 +372,7 @@
DEOPT_IF(!PyFloat_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyFloat_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_SUBTRACT_FLOAT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
@@ -348,9 +395,9 @@
TARGET(BINARY_OP_SUBTRACT_INT) {
frame->instr_ptr = next_instr;
- next_instr += 2;
+ next_instr += 6;
INSTRUCTION_STATS(BINARY_OP_SUBTRACT_INT);
- static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 1, "incorrect cache size");
+ static_assert(INLINE_CACHE_ENTRIES_BINARY_OP == 5, "incorrect cache size");
_PyStackRef left;
_PyStackRef right;
_PyStackRef res;
@@ -363,7 +410,7 @@
DEOPT_IF(!PyLong_CheckExact(left_o), BINARY_OP);
DEOPT_IF(!PyLong_CheckExact(right_o), BINARY_OP);
}
- /* Skip 1 cache entry */
+ /* Skip 5 cache entries */
// _BINARY_OP_SUBTRACT_INT
{
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);