RFR: 8285868: x86_64 intrinsics for floating point methods isNaN, isFinite and isInfinite [v4]

Srinivas Vamsi Parasa duke at openjdk.java.net
Wed May 18 04:30:53 UTC 2022


On Wed, 18 May 2022 02:23:10 GMT, Quan Anh Mai <duke at openjdk.java.net> wrote:

> Hi, I'm working on #8525 which also improves the performance of these methods. With that patch, `isNaN` is reduced to the optimal sequence `ucomiss x, x; jp label`. This patch still benefits the performance of `isFinite` and `isInfinite` for float cases. For double cases without `vfpclass`, I'm not sure due to the materialisation of long constants, though.
> 
> Also, can we output the result of the intrinsics directly in the flag registers? Thanks.

Thank you for the review! The main bottleneck for the performance of `isNan()` comes from popfq instruction used for fixing up the bits in flags register. Is your patch #8525 fixing that?

> Also, for non `vfpclass` cases, it would be simpler and more efficient to implement in the Java side instead
> 
> ```
> static Float::isFinite(float f) {
>     return (floatToRawIntBits(f) & SIGN_ELIMINATION) < POS_INFINITY_BITS;
> }
> ```

True, but that needs changes to java.lang.Float. Will that be approved?

> src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 4753:
> 
>> 4751:   switch (opcode) {
>> 4752:     case Op_IsFiniteF:
>> 4753:       setb(Assembler::below, dst);
> 
> This partial write may stall later reads on `dst`, you could emit a `xor dst, dst` before doing the comparison.

Will try the `xor dst, dst` and see the performance changes.

> src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 4785:
> 
>> 4783:   kmovbl(dst, tmp);
>> 4784:   if (opcode == Op_IsFiniteF) {
>> 4785:     xorl(dst, 0x00000001);
> 
> `notl(dst)`?

I can't recall why `notl(dst)` didn't work. Will try it and let you know.

> src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 4800:
> 
>> 4798:   mov64(temp1, KILL_SIGN_MASK);
>> 4799:   andq(temp, temp1);
>> 4800:   mov64(temp2, POS_INF);
> 
> Can we use `temp1` for this, too?

Sure, will make the change

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

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


More information about the hotspot-compiler-dev mailing list