Commit 6d9daa08 authored by Stefan Behnel's avatar Stefan Behnel

Speed up &-ing multi-digit PyLongs with known single digit integers, e.g....

Speed up &-ing multi-digit PyLongs with known single digit integers, e.g. "bigx & 255" or "bigx & 1".
parent 81c44b70
...@@ -887,6 +887,12 @@ static {{c_ret_type}} __Pyx_PyInt_{{'' if ret_type.is_pyobject else 'Bool'}}{{op ...@@ -887,6 +887,12 @@ static {{c_ret_type}} __Pyx_PyInt_{{'' if ret_type.is_pyobject else 'Bool'}}{{op
{{endif}} {{endif}}
const digit* digits = ((PyLongObject*){{pyval}})->ob_digit; const digit* digits = ((PyLongObject*){{pyval}})->ob_digit;
const Py_ssize_t size = Py_SIZE({{pyval}}); const Py_ssize_t size = Py_SIZE({{pyval}});
{{if c_op == '&'}}
// special case for &-ing arbitrarily large numbers with known single digit operands
if ((intval & PyLong_MASK) == intval) {
return PyLong_FromLong(likely(size) ? digits[0] & intval : 0);
} else
{{endif}}
// handle most common case first to avoid indirect branch and optimise branch prediction // handle most common case first to avoid indirect branch and optimise branch prediction
if (likely(__Pyx_sst_abs(size) <= 1)) { if (likely(__Pyx_sst_abs(size) <= 1)) {
{{ival}} = likely(size) ? digits[0] : 0; {{ival}} = likely(size) ? digits[0] : 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment