RFR: 6506405: Math.abs(float) is slow

Joe Darcy darcy at openjdk.java.net
Thu Jul 8 00:43:49 UTC 2021


On Wed, 7 Jul 2021 20:28:37 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Please consider this change to make the `float` and `double` versions of `java.lang.Math.abs()` branch-free.

src/java.base/share/classes/java/lang/Math.java line 1530:

> 1528:     @IntrinsicCandidate
> 1529:     public static float abs(float a) {
> 1530:         return Float.intBitsToFloat(Float.floatToRawIntBits(a) & 0x7fffffff);

I'd like to see a brief comment on these methods along the lines of "zero out sign bit in the representation." Using underscores in the literal to better group the digits or using the constants in jdk.internal.math.DoubleConsts.

-------------

PR: https://git.openjdk.java.net/jdk/pull/4711


More information about the core-libs-dev mailing list