overflows in SLDivNode
Raffaello Giulietti
raffaello.giulietti at supsi.ch
Mon Apr 27 12:17:53 UTC 2015
The following method (and the equivalent for int) might be added to
ExactMath to help implementing the division correctly.
public static long divExact(long x, long y) {
long r = x / y;
if ((x & y & r) < 0) {
throw new ArithmeticException("long overflow");
}
return r;
}
Since SL is meant to be an exemplary Truffle language, I feel it will be
surely imitated, so it is important to keep it as correct as possible.
Greetings
Raffaello
On 2015-04-26 17:51, Raffaello Giulietti wrote:
> Hi,
>
> I'm just studying the SL implementation in the last Graal/Truffle update.
>
> The long specialization of the division wrongly assumes that
> /* No overflow is possible on a division. */
>
> When left is Long.MIN_VALUE and right is -1 the division overflows.
>
> OK, OK, OK, this is the only case and has a ridiculous
> (cryptography-like) probability of 2^-128 to happen randomly. And, no,
> neither java.lang.Math nor ExactMath cover this rare case of overflow.
>
> Greetings
> Raffaello
More information about the graal-dev
mailing list