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

Joe Darcy joe.darcy at oracle.com
Fri Jul 10 20:28:30 UTC 2020


Hi Dmitry,

On 7/10/2020 12:29 PM, Dmitry Chuyko wrote:
> Joe, thanks for taking a look on that.
>
> Would something like "Here d is either (signed) zero or NaN (JLS 
> 15.20.1)" make more sense?

That would be a correct statement. However, rather than referring to the 
JLS in this case, I suggesting stating the relevant information 
directly, something like:

return d; // Signed zeros and NaN are neither greater than zero nor less 
than zero.

Looking over the existing regression tests, I believe they are 
sufficient for the new implementation.

I'll leave it to others to review the benchmarks.

Thanks,

-Joe


>
> -Dmitry
>
> On 7/10/20 10:06 PM, Joe Darcy wrote:
>> 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