Commit f1e85caf authored by Stefan Behnel's avatar Stefan Behnel

Repair and simplify unrolled PyLong comparison loop that used PyLong_BASE...

Repair and simplify unrolled PyLong comparison loop that used PyLong_BASE incorrectly (it's an exponential base, not a factor).
parent b6a5a34b
...@@ -757,23 +757,16 @@ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyInt_{{'' if ret_type.is_pyobject els ...@@ -757,23 +757,16 @@ static CYTHON_INLINE {{c_ret_type}} __Pyx_PyInt_{{'' if ret_type.is_pyobject els
// After checking that the sign is the same (and excluding 0), now compare the absolute values. // After checking that the sign is the same (and excluding 0), now compare the absolute values.
// When inlining, the C compiler should select exactly one line from this unrolled loop. // When inlining, the C compiler should select exactly one line from this unrolled loop.
uintval = (unsigned long) intval; uintval = (unsigned long) intval;
if ((0)); {{for _size in range(4, 0, -1)}}
{{for _size in range(4, 1, -1)}}
#if PyLong_SHIFT * {{_size}} < SIZEOF_LONG*8 #if PyLong_SHIFT * {{_size}} < SIZEOF_LONG*8
else if (uintval >= {{_size-1}}UL * (unsigned long) PyLong_BASE) { if (uintval >> (PyLong_SHIFT * {{_size}})) {
if (uintval >= {{_size}}UL * (unsigned long) PyLong_BASE) { // C integer value is between the maximum multiple digits that fit into a long completely and the maximum long value
// C integer value is between the maximum multiple digits that fit into a long completely and the maximum long value unequal = (size != {{_size+1}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
unequal = (size != {{_size+1}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)) {{for _i in range(1, _size+1)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}};
{{for _i in range(1, _size+1)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}}; } else
} else {
// C integer value is within the maximum multiple digits that fit into a long completely
unequal = (size != {{_size}}) || (digits[0] != (uintval & (unsigned long) PyLong_MASK))
{{for _i in range(1, _size)}} | (digits[{{_i}}] != ((uintval >> ({{_i}} * PyLong_SHIFT)) & (unsigned long) PyLong_MASK)){{endfor}};
}
}
#endif #endif
{{endfor}} {{endfor}}
else unequal = (size != 1) || (digits[0] != (uintval & (unsigned long) PyLong_MASK)); unequal = (size != 1) || (((unsigned long) digits[0]) != (uintval & (unsigned long) PyLong_MASK));
{{return_compare('unequal', '0', c_op)}} {{return_compare('unequal', '0', c_op)}}
} }
......
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