[pypy-issue] [issue1701] a / b with integers could be faster in the JIT

Armin Rigo tracker at bugs.pypy.org
Fri Mar 7 17:36:07 CET 2014


Armin Rigo <armin.rigo at gmail.com> added the comment:

Sorry, I said something wrong in that IRC extract: we can't just use one xor,
it's a bit more complicated.

The branch is the "cheapest" I could reasonably come up with.  A way to use the
combined div-and-mod x86 operation would be to recognize, in the x86 backend, a
combination of two resoperations, INT_TRUNCDIV followed by INT_TRUNCMOD.  It
could be written by using this kind of logic in rtyper/rint.py:

d = int_truncdiv(a, b)
m = int_truncmod(a, b)
if b > 0:
    d += (a&m)>>INT_BITS_1
else:
    d += ((-m)&(-a)) >>INT_BITS_1

Or without any branch:

d = int_truncdiv(a, b)
m = int_truncmod(a, b)
d += ((a^b)&(m|-m))>>INT_BITS_1

It goes far into the land of obscurity if you ask me...

----------
nosy: +arigo
status: unread -> chatting

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1701>
________________________________________


More information about the pypy-issue mailing list