RFR: 8265491: Math Signum optimization for x86 [v11]

Jatin Bhateja jbhateja at openjdk.java.net
Wed Apr 28 05:43:53 UTC 2021


On Wed, 28 Apr 2021 01:39:23 GMT, Marcus G K Williams <github.com+168222+mgkwill at openjdk.org> wrote:

>> x86 Math.Signum() uses two floating point compares and a copy sign operation involving data movement to gpr and XMM.
>> 
>> We can optimize to one floating point compare and sign computation in XMM. We observe ~25% performance improvement with this optimization.
>> 
>> Base:
>> 
>> Benchmark                       Mode Cnt Score Error Units
>> Signum._1_signumFloatTest avgt 5 4.660 ? 0.040 ns/op
>> Signum._2_overheadFloat avgt 5 3.314 ? 0.023 ns/op
>> Signum._3_signumDoubleTest avgt 5 4.809 ? 0.043 ns/op
>> Signum._4_overheadDouble avgt 5 3.313 ? 0.015 ns/op
>> 
>>  
>> Optimized:
>> signum intrinsic patch
>> 
>> Benchmark                       Mode  Cnt  Score   Error  Units
>> Signum._1_signumFloatTest       avgt    5  3.769 ? 0.015  ns/op
>> Signum._2_overheadFloat         avgt    5  3.312 ? 0.025  ns/op
>> Signum._3_signumDoubleTest      avgt    5  3.765 ? 0.005  ns/op
>> Signum._4_overheadDouble        avgt    5  3.309 ? 0.010  ns/op
>> 
>> 
>> Signed-off-by: Marcus G K Williams <marcus.williams at intel.com>
>
> Marcus G K Williams has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Revert to vector _sign_flip
>   
>   Signed-off-by: Marcus G K Williams <marcus.williams at intel.com>

src/hotspot/cpu/x86/c2_MacroAssembler_x86.cpp line 1067:

> 1065:   jcc(Assembler::parity, DONE_LABEL);   // handle special case NaN, if argument NaN, return NaN
> 1066: 
> 1067:   if (opcode == Op_SignumF){

Too many if/else, can you kindly club the instruction for SignumF and SignumD in one conditional(if/else) block.

src/hotspot/cpu/x86/x86.ad line 5791:

> 5789: 
> 5790: instruct signumF_reg(regF dst, regF zero, regF one, rRegP scratch, rFlagsReg cr) %{
> 5791:   predicate(UseSSE>=1);

Predicate looks redundant since you already added a check in match_rule_supported

src/hotspot/cpu/x86/x86.ad line 5803:

> 5801: 
> 5802: instruct signumD_reg(regD dst, regD zero, regD one, rRegP scratch, rFlagsReg cr) %{
> 5803:   predicate(UseSSE>=2);

Same as above

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

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


More information about the hotspot-compiler-dev mailing list