On 4 July 2014 18:13, Edward Nevill <edward.nev...@linaro.org> wrote: > Hi, > > Does anyone know of a nice way to detect 64 x 64 -> 64 multiply overflow on > aarch64? > > On x86 you can just use the V flag, but aarch64 seems to have no option to > set the flags after a MUL instruction which I find very odd. > > The only solution I can think of is to do the equivalent of > > r = a * b; > if (r/a != b) overflow(); > > There is some short circuiting you can do to avoid the div if you know there > is no possibility it could have overflowed. > > Eg. > > if (clz(labs(a)) + clz(labs(b)) < 32) { > r = a * b; > if (r/a != b) overflow(); > } > > Then there is the special case of a = 0x8000000000000000 and b == -1. > > All in all its a mess just to detect overflow. >
If you are saying AArch64, I am assuming you can use inline asm and umulh, no? -- Ard. _______________________________________________ linaro-dev mailing list linaro-dev@lists.linaro.org http://lists.linaro.org/mailman/listinfo/linaro-dev