8000 use stwodigits for lshift · python/cpython@0085021 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0085021

Browse files
committed
use stwodigits for lshift
1 parent 32c68ae commit 0085021

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Python/specialize.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,9 +2475,18 @@ shift_guard(PyObject *lhs, PyObject *rhs)
24752475

24762476
// rshift with value larger the the number of bits is undefined in C
24772477
// for lshift we do not want to overflow, but we always have at least 16 bits available
2478-
return (is_compactlong(lhs) && is_compactnonnegativelong(rhs) && (_PyLong_CompactValue((PyLongObject *)rhs) <= 12) );
2478+
return (is_compactlong(lhs) && is_compactnonnegativelong(rhs) && (_PyLong_CompactValue((PyLongObject *)rhs) <= 16) );
24792479
}
24802480

2481+
#define BITWISE_LONGS_ACTION_STWODIGITS(NAME, OP) \
2482+
static PyObject * \
2483+
(NAME)(PyObject *lhs, PyObject *rhs) \
2484+
{ \
2485+
stwodigits rhs_val = (stwodigits)_PyLong_CompactValue((PyLongObject *)rhs); \
2486+
stwodigits lhs_val = (stwodigits) _PyLong_CompactValue((PyLongObject *)lhs); \
2487+
return PyLong_FromLongLong(lhs_val OP rhs_val); \
2488+
}
2489+
24812490
#define BITWISE_LONGS_ACTION(NAME, OP) \
24822491
static PyObject * \
24832492
(NAME)(PyObject *lhs, PyObject *rhs) \
@@ -2489,7 +2498,7 @@ shift_guard(PyObject *lhs, PyObject *rhs)
24892498
BITWISE_LONGS_ACTION(compactlongs_or, |)
24902499
BITWISE_LONGS_ACTION(compactlongs_and, &)
24912500
BITWISE_LONGS_ACTION(compactlongs_xor, ^)
2492-
BITWISE_LONGS_ACTION(compactlongs_lshift, <<)
2501+
BITWISE_LONGS_ACTION_STWODIGITS(compactlongs_lshift, <<)
24932502
BITWISE_LONGS_ACTION(compactlongs_rshift, >>)
24942503
#undef BITWISE_LONGS_ACTION
24952504

0 commit comments

Comments
 (0)
0