-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-46372: Try to mutate the LHS during fast float ops
#30594
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
cf64e13
Perform specialized ops in-place when possible
brandtbucher 5e49a13
Break out common logic
brandtbucher f7187d9
Clean things up a bit
brandtbucher dd19cec
Clean up macro
brandtbucher 78cc5c4
Simplify the "small" int case
brandtbucher 218b10b
blurb add
brandtbucher 505fd8e
Catch up with main
brandtbucher 6b4cc6d
Apply first round of code revew comments
brandtbucher f21a813
Fix 32-bit Windows errrors
brandtbucher d6a69d5
Perform the inplace checks when specializing
brandtbucher f11cf6d
Remove duplicate code
brandtbucher b6f041a
Simplify things further
brandtbucher eb586b1
Remove int and refcount == 2 optimizations
brandtbucher def9c64
Catch up with main
brandtbucher 6e262ba
Revert int changes
brandtbucher 37fab55
Catch up with main
brandtbucher 04f186c
Add the "adaptive superinstructions" back
brandtbucher e0d0042
Catch up with main
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Catch up with main
- Loading branch information
commit 37fab55bd8f8fcd679d2fa9cc9b481b0ada03e56
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -859,6 +859,7 @@ static const binaryfunc binary_ops[] = { | |
|
|
||
| #define BINARY_OP_FAST_FLOAT(OP) \ | ||
| do { \ | ||
| assert(cframe.use_tracing == 0); \ | ||
| PyObject *lhs = SECOND(); \ | ||
| PyObject *rhs = TOP(); \ | ||
| DEOPT_IF(!PyFloat_CheckExact(lhs), BINARY_OP); \ | ||
|
|
@@ -871,15 +872,15 @@ static const binaryfunc binary_ops[] = { | |
| STACK_SHRINK(1); \ | ||
| if (Py_REFCNT(lhs) == 1) { \ | ||
| PyFloat_AS_DOUBLE(lhs) = d; \ | ||
|
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. Presumably (see PEP 674) Victor won't like this use of a macro as a target. :-) Nevertheless, this whole macro is so nice and straightforward compared to ints! |
||
| DISPATCH(); \ | ||
| NOTRACE_DISPATCH(); \ | ||
| } \ | ||
| Py_DECREF(lhs); \ | ||
|
brandtbucher marked this conversation as resolved.
Outdated
|
||
| PyObject *res = PyFloat_FromDouble(d); \ | ||
| SET_TOP(res); \ | ||
| if (res == NULL) { \ | ||
| goto error; \ | ||
| } \ | ||
| DISPATCH(); \ | ||
| NOTRACE_DISPATCH(); \ | ||
| } while (0) | ||
|
|
||
|
|
||
|
|
||
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Would there be any benefit in checking whether perhaps rhs has a refcount of 1, in case lhs doesn't? While people are probably more likely to write
return x+1rather thanreturn 1+x(though even I could sometimes see a reason to do that, from "rhyming" with some other operations or just how the textbook presents the formula), writingreturn 2*xis more likely thanreturn x*2. And of course for asymmetric operations you may not have a choice, likereturn 1/x.Of course, there's a cost (more code, more branches). There's also the fact that
+=and friends steer this in the direction you're taking here.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.
Yeah, those are my main motivations for sticking with the LHS here.