RFR(S): 8249198: Faster Math.signum(fp) for positive and negative numbers

Joe Darcy joe.darcy at oracle.com
Fri Jul 10 19:06:41 UTC 2020


Hello,

The comment

+        // NaN is here by JLS 15.20.1

is not correct; either NaN or (signed) zero is present at that point in 
the code.

-Joe

On 7/10/2020 11:11 AM, Dmitry Chuyko wrote:
> Hello,
>
> Please review a small change in Math.signum(double d) and 
> Math.signum(float f) that improves performance for positive and 
> negative numbers.
>
> Current version first checks if the number is NaN or zero, and for all 
> other numbers it extracts sign bit and constructs fp result. That 
> makes all regular numbers case ~1.2-1.5x slower than two special 
> number cases.
>
> Improved version checks for regular number cases first, and does not 
> use bit extraction. For positive and negative double numbers 
> improvement is ~1.31-1.47x, for floats it is 1.06-1.46x. 
> Micro-benchmark results are provided for tiered C2 on x86_64 and 
> aarch64. For NaN and zero we see ~1.00-1.26x slowdown in same conditions.
>
> Please find benchmarks and results in the webrev.
>
> rfe: https://bugs.openjdk.java.net/browse/JDK-8249198
>
> webrev: http://cr.openjdk.java.net/~dchuyko/8249198/webrev.00/
>
> results: 
> http://cr.openjdk.java.net/~dchuyko/8249198/webrev.00/results.txt
>
> testing: JCK tests, jtreg tests on different platforms.
>
> -Dmitry
>


More information about the core-libs-dev mailing list