Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lib/test/test_opcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@
specialize(instr, BINARY_OP_ADD_UNICODE);
return;
}
if (PyLong_CheckExact(lhs)) {
if (_PyLong_CheckExactAndCompact(lhs) && _PyLong_CheckExactAndCompact(rhs)) {

Check warning on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (x64)

'_PyLong_CheckExactAndCompact' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (x64)

'_PyLong_CheckExactAndCompact' undefined; assuming extern returning int [D:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check warning on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Windows / Build and test (arm64)

'_PyLong_CheckExactAndCompact' undefined; assuming extern returning int [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Hypothesis tests on Ubuntu

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check warning on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Windows (free-threading) / Build and test (arm64)

'_PyLong_CheckExactAndCompact' undefined; assuming extern returning int [C:\a\cpython\cpython\PCbuild\_freeze_module.vcxproj]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Cross build Linux

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04-arm)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Ubuntu / build and test (ubuntu-24.04)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Ubuntu (free-threading) / build and test (ubuntu-24.04-arm)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]

Check failure on line 2605 in Python/specialize.c

View workflow job for this annotation

GitHub Actions / Ubuntu (bolt) / build and test (ubuntu-24.04)

implicit declaration of function ‘_PyLong_CheckExactAndCompact’ [-Werror=implicit-function-declaration]
specialize(instr, BINARY_OP_ADD_INT);
return;
}
Expand All @@ -2616,7 +2616,7 @@
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;
}
Expand All @@ -2630,7 +2630,7 @@
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;
}
Expand Down
Loading