-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-41902: Add fast path for long_div if the divisor is one #22480
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,7 +204,10 @@ def test_division(self): | |
| self.check_division(710031681576388032, 26769404391308) | ||
| self.check_division(1933622614268221, 30212853348836) | ||
|
|
||
|
|
||
| @support.cpython_only | ||
| def test_division_with_one(self): | ||
| for n in range(10000000): | ||
|
Member
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. Well, I don't think that it's worth it to test 10000000 numbers. Just test a bunch of various numbers made of a single digit. Like: |
||
| self.assertEqual(n, n // 1) | ||
|
Member
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 suggest to test assertIs(). |
||
|
|
||
|
Member
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. Test also that assertEqual(type(x//1), int) where x is an int subclass. |
||
| def test_karatsuba(self): | ||
| digits = list(range(1, 5)) + list(range(KARATSUBA_CUTOFF, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add fast path for long_div if the divisor is one. Patch by Dong-hee Na. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3695,6 +3695,10 @@ static PyObject * | |
| long_div(PyObject *a, PyObject *b) | ||
| { | ||
| PyLongObject *div; | ||
| if (b == _PyLong_One && PyLong_CheckExact(a)) { | ||
|
Member
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. This branch may impact the normal path, we certainly should benchmark this with PGO and cpu isolation. |
||
| Py_INCREF(a); | ||
| return a; | ||
| } | ||
|
|
||
| CHECK_BINOP(a, b); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you test assertIs(), please add a comment mentioning bpo-41902 and explain that it's a micro-optimization which returns x for x//1 if x is an int made of a single digit.