Skip to content

Commit cd51e7d

Browse files
committed
gh-151289: reduce subtract specialization uop churn
1 parent 06d0a8c commit cd51e7d

8 files changed

Lines changed: 112 additions & 299 deletions

File tree

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 0 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_testinternalcapi/test_cases.c.h

Lines changed: 23 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/bytecodes.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -643,16 +643,6 @@ dummy_func(
643643
EXIT_IF(!_PyLong_CheckExactAndCompact(value_o));
644644
}
645645

646-
op(_GUARD_NOS_EXACT_INT, (left, unused -- left, unused)) {
647-
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
648-
EXIT_IF(!PyLong_CheckExact(left_o));
649-
}
650-
651-
op(_GUARD_TOS_EXACT_INT, (value -- value)) {
652-
PyObject *value_o = PyStackRef_AsPyObjectBorrow(value);
653-
EXIT_IF(!PyLong_CheckExact(value_o));
654-
}
655-
656646
op(_GUARD_NOS_OVERFLOWED, (left, unused -- left, unused)) {
657647
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
658648
assert(Py_TYPE(left_o) == &PyLong_Type);
@@ -698,11 +688,17 @@ dummy_func(
698688
pure op(_BINARY_OP_SUBTRACT_INT, (left, right -- res, l, r)) {
699689
PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
700690
PyObject *right_o = PyStackRef_AsPyObjectBorrow(right);
701-
assert(PyLong_CheckExact(left_o));
702-
assert(PyLong_CheckExact(right_o));
691+
EXIT_IF(!PyLong_CheckExact(left_o));
692+
EXIT_IF(!PyLong_CheckExact(right_o));
693+
bool both_compact = _PyLong_BothAreCompact((PyLongObject *)left_o, (PyLongObject *)right_o);
694+
bool shrink_pair = false;
695+
if (!both_compact) {
696+
shrink_pair = _PyLong_IsShrinkSubtractPair((PyLongObject *)left_o, (PyLongObject *)right_o);
697+
}
698+
EXIT_IF(!(both_compact || shrink_pair));
703699

704700
STAT_INC(BINARY_OP, hit);
705-
if (_PyLong_BothAreCompact((PyLongObject *)left_o, (PyLongObject *)right_o)) {
701+
if (both_compact) {
706702
res = _PyCompactLong_Subtract((PyLongObject *)left_o, (PyLongObject *)right_o);
707703
}
708704
else {
@@ -721,7 +717,7 @@ dummy_func(
721717
_GUARD_TOS_INT + _GUARD_NOS_INT + unused/5 + _BINARY_OP_ADD_INT + _POP_TOP_INT + _POP_TOP_INT;
722718

723719
macro(BINARY_OP_SUBTRACT_INT) =
724-
_GUARD_TOS_EXACT_INT + _GUARD_NOS_EXACT_INT + unused/5 + _BINARY_OP_SUBTRACT_INT + _POP_TOP_INT + _POP_TOP_INT;
720+
unused/5 + _BINARY_OP_SUBTRACT_INT + _POP_TOP_INT + _POP_TOP_INT;
725721

726722
// Inplace compact int ops: mutate the uniquely-referenced operand
727723
// when possible. The op handles decref of TARGET internally so

0 commit comments

Comments
 (0)