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

Marcus G K Williams github.com+168222+mgkwill at openjdk.java.net
Thu Apr 22 18:58:32 UTC 2021


On Thu, 22 Apr 2021 18:44:58 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 two additional commits since the last revision:
> 
>  - Implement Default UseSignumIntrinsic suggestion
>    
>    Signed-off-by: Marcus G K Williams <marcus.williams at intel.com>
>  - Use three operand xorps/d
>    
>    Signed-off-by: Marcus G K Williams <marcus.williams at intel.com>

- Switched to 3 operand xorps/d on colleague suggestion to insure I don't introduce a hard to find register bug. 

- Implemented @DamonFool suggestion for Default Enable of UseSignumIntrinsic on x86. Slightly worried about `!has_match_rule(opcode)` for aarch64. But as long as it doesn't hit this I think it will work.

 src/hotspot/cpu/aarch64/aarch64.ad:

const bool Matcher::match_rule_supported(int opcode) {
  if (!has_match_rule(opcode))
    return false;


Also moved matcher checks in src/hotspot/cpu/x86/x86.ad outside of 

#ifndef _LP64
#endif // !LP64


Thanks for the review @DamonFool @dholmes-ora @jatin-bhateja.

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

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


More information about the hotspot-compiler-dev mailing list