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

Dmitry Chuyko dmitry.chuyko at bell-sw.com
Fri Jul 10 18:11:36 UTC 2020


Please review a small change in Math.signum(double d) and 
Math.signum(float f) that improves performance for positive and negative 

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.


More information about the core-libs-dev mailing list