Need reviewer: JDK 8 CR for Support Integer overflow (original) (raw)

Joe Darcy joe.darcy at oracle.com
Fri Feb 3 17:07:59 UTC 2012


On 02/03/2012 06:44 AM, Florian Weimer wrote:

* Roger Riggs:

The boolean expression can be refactored. (Only bit-31 is significant). But it becomes pretty inscrutable.

(x ^ r)< 0&& (x ^ y)>= 0 becomes (x ^ r)< 0&& (~(x ^ y))< 0 becomes ((x ^ r)& ~(x ^ y))< 0 That's what I got in my second attempt, too. It doesn't result in a longer dependency chain because the left side of the& is two operations deep, too. Therefore, this version should be faster (at least after compilation), independent of the input arguments.

These sorts of concerns and lovingly (and laboriously!) detailed to Hank Warren's bit-twiddling tome "Hacker's Delight" (http://www.hackersdelight.org/).

Roger's initial code used one of the recommend idioms from that source.
We should stick with those idioms unless there is a good reason not to.

-Joe



More information about the core-libs-dev mailing list