RFR: 8266028: C2 computes -0.0 for Math.pow(-0.0, 0.5)

Jie Fu jiefu at openjdk.java.net
Tue Apr 27 23:37:55 UTC 2021


On Tue, 27 Apr 2021 16:45:15 GMT, Vladimir Kozlov <kvn at openjdk.org> wrote:

> I am fine with your fix - it is rare case so we can skip 0 case. But we need to verify that Interpreter and stubs (and Java) give the same result for -0.0 in 32- and 64-bit VMs.
> 
> C code uses `if(hx>=0)` so what result will it give for `-0.0`? :
> https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/sharedRuntimeTrans.cpp#L497
> 
> 64-bit stub code use Integer compare which should be fine I think:
> https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/macroAssembler_x86_pow.cpp#L839
> 
> Java code adds `+0.0` to get correct result (would be nice to see what code C2 generates when it see such bytecode):
> https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/FdLibm.java#L364

Hi @vnkozlov ,

Thanks for your review.

The C code actually uses integer compare.
So I think it's fine otherwise non-x86 platforms would report errors.


As for the Java code, C2 will emit a `vaddsd` instruction.

Java method

  public static double test(double d) {
    return d + 0.0;
  }


Generated code by C2

000     B1: #   out( N1 ) <- BLOCK HEAD IS JUNK  Freq: 1
000     # stack bang (96 bytes)
        pushq   rbp     # Save rbp
        subq    rsp, #16        # Create frame

00c     # MachConstantBaseNode (empty encoding)
00c     vaddsd  XMM0, XMM0, [constant table base + #0]  # load from constant table: double=#0.000000
014     addq    rsp, 16 # Destroy frame
        popq    rbp
        cmpq     rsp, poll_offset[r15_thread]
        ja       #safepoint_stub        # Safepoint: poll for GC

026     ret

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

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


More information about the hotspot-compiler-dev mailing list