Lowering multiplyExact
Andrew Haley
aph at redhat.com
Thu Dec 1 13:55:26 UTC 2016
Graal assumes that multiplies set the overflow flag, and relies on
this for multiplyExact. AArch64 doesn't set the overlfow flag for
multiply, and as far as I can see neither does SPARC, so we have to do
some backward somersaults to get it to work.
Right now we do this:
0x0000007fa8baec54: smull x8, w1, w2
0x0000007fa8baec58: add w0, w8, #0x0
0x0000007fa8baec5c: cmp x8, w8, sxtw
0x0000007fa8baec60: orr x8, xzr, #0x80000000
0x0000007fa8baec64: csel w8, w8, wzr, ne
0x0000007fa8baec68: cmp w8, #0x1
0x0000007fa8baec6c: b.vs 0x0000007fa8baec8c
which is
x8 = i2l(w1) * i2l(w2)
result = l2i(x8)
flags = compare(x8, result)
x8 = 0x80000000
w8 = flags.ne ? w8 : 0
flags = compare(w8, 1)
...
if (flags.vs) goto overflow
But it could be simply
x8 = i2l(w1) * i2l(w2)
result = l2i(x8)
flags = compare(x8, result)
...
if (flags.ne) goto overflow
if we had a lowering for multiplyExact that didn't assume that
multiplies set the overflow flag.
It's really not an important thing, but it's kinda irksome. :-)
Andrew.
More information about the graal-dev
mailing list