RFR: 6506405: Math.abs(float) is slow
Brian Burkhalter
bpb at openjdk.java.net
Thu Jul 8 00:43:49 UTC 2021
On Thu, 8 Jul 2021 00:38:45 GMT, Joe Darcy <darcy 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.
There is no specific constant in `{Float,Double}Consts` to mask all but the sign bit, but I had thought it might be good to add one there.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4711
More information about the core-libs-dev
mailing list