FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-100239: use PyFloat_AS_DOUBLE and _PyLong_IsZero in the float / compactlong specializations by chris-eibl · Pull Request #144826 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
@@ -0,0 +1,2 @@
Speedup ``BINARY_OP_EXTEND`` for exact floats and medium-size integers by up

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Compact ints are an implementation detail and the term medium-size integers has been chosen in news entries in the past for them.

to 15%. Patch by Chris Eibl.
12 changes: 6 additions & 6 deletions Python/specialize.c
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
Expand Up @@ -2100,7 +2100,7 @@ float_compactlong_guard(PyObject *lhs, PyObject *rhs)
{
return (
PyFloat_CheckExact(lhs) &&
!isnan(PyFloat_AsDouble(lhs)) &&
!isnan(PyFloat_AS_DOUBLE(lhs)) &&
PyLong_CheckExact(rhs) &&
_PyLong_IsCompact((PyLongObject *)rhs)
);
Expand All @@ -2110,15 +2110,15 @@ static inline int
nonzero_float_compactlong_guard(PyObject *lhs, PyObject *rhs)
{
return (
float_compactlong_guard(lhs, rhs) && !PyLong_IsZero(rhs)
float_compactlong_guard(lhs, rhs) && !_PyLong_IsZero((PyLongObject*)rhs)
);
}

#define FLOAT_LONG_ACTION(NAME, OP) \
static PyObject * \
(NAME)(PyObject *lhs, PyObject *rhs) \
{ \
double lhs_val = PyFloat_AsDouble(lhs); \
double lhs_val = PyFloat_AS_DOUBLE(lhs); \
Py_ssize_t rhs_val = _PyLong_CompactValue((PyLongObject *)rhs); \
return PyFloat_FromDouble(lhs_val OP rhs_val); \
}
Expand All @@ -2137,23 +2137,23 @@ compactlong_float_guard(PyObject *lhs, PyObject *rhs)
PyLong_CheckExact(lhs) &&
_PyLong_IsCompact((PyLongObject *)lhs) &&
PyFloat_CheckExact(rhs) &&
!isnan(PyFloat_AsDouble(rhs))
!isnan(PyFloat_AS_DOUBLE(rhs))
);
}

static inline int
nonzero_compactlong_float_guard(PyObject *lhs, PyObject *rhs)
{
return (
compactlong_float_guard(lhs, rhs) && PyFloat_AsDouble(rhs) != 0.0
compactlong_float_guard(lhs, rhs) && PyFloat_AS_DOUBLE(rhs) != 0.0
);
}

#define LONG_FLOAT_ACTION(NAME, OP) \
static PyObject * \
(NAME)(PyObject *lhs, PyObject *rhs) \
{ \
double rhs_val = PyFloat_AsDouble(rhs); \
double rhs_val = PyFloat_AS_DOUBLE(rhs); \
Py_ssize_t lhs_val = _PyLong_CompactValue((PyLongObject *)lhs); \
return PyFloat_FromDouble(lhs_val OP rhs_val); \
}
Expand Down
Loading

Back | FazBrowse Home | New Git URL