[aarch64-port-dev ] RFR(M): 8212043: Add floating-point Math.min/max intrinsics

Pengfei Li (Arm Technology China) Pengfei.Li at arm.com
Tue Dec 18 10:21:58 UTC 2018


Hi,

> On 12/17/18 4:08 PM, Andrew Dinn wrote:
> > I think you need to construct the required float and double values
> > using an appropriate int or long bit pattern. I have just pushed a
> > patch to the submit repo that uses these definitions:
> >
> >   static long pos_dinf_bits = 0x7ff0000000000000L;
> >   static int pos_finf_bits = 0x7f800000;
> >
> >   static double pos_dinf() { return *(double*)&pos_dinf_bits; }
> >   static float pos_finf() { return *(double*)&pos_finf_bits; }
> >   static double neg_dinf() { return -pos_finf(); }
> >   static float neg_dinf() { return -pos_finf(); }
> 
> Hmm. In C++ that cast
> 
> *(double*)&pos_dinf_bits
> 
> is undefined behaviour. While there is UB in HotSpot already, I don't think
> we should be introducing it.
> 
> This is the pattern we already use in HotSpot:
> 
>     union { intptr_t p; double d; } value;
>     value.p = (intptr_t) CONST64(0xDEADDEAFDEADDEAF);
>     use value.d ...

I found another simpler approach of using "std::numeric_limits<float>::infinity()" to represent float +inf, other infinities are similar. The cppreference website[1] said this method is available to be used before C++11 (and the previous INFINITY macro is not). I also see that hotspot shared code in "src/hotspot/share/metaprogramming" uses std::numeric_limits. 

http://cr.openjdk.java.net/~pli/rfr/8212043/webrev.04/
Today I tested this webrev on Linux/x86_64, Linux/AArch64, macOS and Windows10. All the builds completed with no failure. So do you like this solution?

[1] https://en.cppreference.com/w/cpp/types/numeric_limits/infinity

--
Thanks,
Pengfei



More information about the aarch64-port-dev mailing list