Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Catch up with main
  • Loading branch information
brandtbucher committed Jan 28, 2022
commit 37fab55bd8f8fcd679d2fa9cc9b481b0ada03e56
5 changes: 3 additions & 2 deletions Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand All @@ -871,15 +872,15 @@ static const binaryfunc binary_ops[] = {
STACK_SHRINK(1); \
if (Py_REFCNT(lhs) == 1) { \
Copy link
Copy Markdown
Member

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+1 rather than return 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), writing return 2*x is more likely than return x*2. And of course for asymmetric operations you may not have a choice, like return 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Yeah, those are my main motivations for sticking with the LHS here.

PyFloat_AS_DOUBLE(lhs) = d; \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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); \
Comment thread
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)


Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.