Fast long overflow detection?
Per Bothner
per at bothner.com
Tue Feb 7 15:11:47 PST 2012
On 02/07/2012 03:04 PM, Vitaly Davidovich wrote:
> Can't the overflow test be (value ^ result) & (otherValue ^ result) < 0?
> I think that's what hacker's delight suggests and you don't need the
> negation and the sign bit mask in that case.
In gnu.math the "fixnums" are int, so I do long addition like this:
long r = (long) value + (long) otherValue;
int ri = (int) r;
if ((int) ri == r) return makeFix(ri);
else return makeBig(r);
This is probably slower on older 32-bit CPUs.
But with modern CPUs I doubt it matters what computation
you do: what really matters are cache misses.
--
--Per Bothner
per at bothner.com http://per.bothner.com/
More information about the mlvm-dev
mailing list