mirror of
https://github.com/python/cpython.git
synced 2025-12-31 04:23:37 +00:00
gh-138302: Specialize int ops only if ints are compact (GH-138347)
This commit is contained in:
parent
6528cf47a0
commit
ea77feecbb
3 changed files with 21 additions and 3 deletions
|
|
@ -1333,6 +1333,21 @@ def binary_op_add_int():
|
|||
self.assert_specialized(binary_op_add_int, "BINARY_OP_ADD_INT")
|
||||
self.assert_no_opcode(binary_op_add_int, "BINARY_OP")
|
||||
|
||||
def binary_op_int_non_compact():
|
||||
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
|
||||
a, b = 10000000000, 1
|
||||
c = a + b
|
||||
self.assertEqual(c, 10000000001)
|
||||
c = a - b
|
||||
self.assertEqual(c, 9999999999)
|
||||
c = a * b
|
||||
self.assertEqual(c, 10000000000)
|
||||
|
||||
binary_op_int_non_compact()
|
||||
self.assert_no_opcode(binary_op_int_non_compact, "BINARY_OP_ADD_INT")
|
||||
self.assert_no_opcode(binary_op_int_non_compact, "BINARY_OP_SUBTRACT_INT")
|
||||
self.assert_no_opcode(binary_op_int_non_compact, "BINARY_OP_MULTIPLY_INT")
|
||||
|
||||
def binary_op_add_unicode():
|
||||
for _ in range(_testinternalcapi.SPECIALIZATION_THRESHOLD):
|
||||
a, b = "foo", "bar"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
``BINARY_OP`` now specializes to ``BINARY_OP_ADD_INT``,
|
||||
``BINARY_OP_SUBTRACT_INT`` or ``BINARY_OP_MULTIPLY_INT`` if operands
|
||||
are compact ints.
|
||||
|
|
@ -2595,7 +2595,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
|
|||
specialize(instr, BINARY_OP_ADD_UNICODE);
|
||||
return;
|
||||
}
|
||||
if (PyLong_CheckExact(lhs)) {
|
||||
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
|
||||
specialize(instr, BINARY_OP_ADD_INT);
|
||||
return;
|
||||
}
|
||||
|
|
@ -2609,7 +2609,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
|
|||
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
|
||||
break;
|
||||
}
|
||||
if (PyLong_CheckExact(lhs)) {
|
||||
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
|
||||
specialize(instr, BINARY_OP_MULTIPLY_INT);
|
||||
return;
|
||||
}
|
||||
|
|
@ -2623,7 +2623,7 @@ _Py_Specialize_BinaryOp(_PyStackRef lhs_st, _PyStackRef rhs_st, _Py_CODEUNIT *in
|
|||
if (!Py_IS_TYPE(lhs, Py_TYPE(rhs))) {
|
||||
break;
|
||||
}
|
||||
if (PyLong_CheckExact(lhs)) {
|
||||
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {
|
||||
specialize(instr, BINARY_OP_SUBTRACT_INT);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue