RFR: 8349138: Optimize Math.copySign API for Intel e-core targets [v2]
Tobias Hartmann
thartmann at openjdk.org
Wed Feb 5 07:40:13 UTC 2025
On Mon, 3 Feb 2025 14:21:31 GMT, Jatin Bhateja <jbhateja at openjdk.org> wrote:
>> Math.copySign is only intrinsified on x86 targets supporting the AVX512 feature.
>> Intel E-core Xeons support only the AVX2 feature set and still compile Java implementation which is composed of logical operations.
>>
>> Since there is a 3-cycle penalty for copying incoming float/double values to GPRs before being operated upon by logical operation there is an opportunity to optimize this using an efficient instruction sequence.
>>
>> Patch uses ANDPS and ANDPD logical instruction to generate efficient instruction sequences to absorb domain copy over penalty. Also, performs minor tuning for existing AVX512 instruction sequence based on VPTERNLOG instruction.
>>
>> Following are the performance numbers of the following existing microbenchmark
>> https://github.com/openjdk/jdk/blob/master/test/micro/org/openjdk/bench/vm/compiler/Signum.java
>>
>> Patch passes following validation test
>> [test/jdk/java/lang/Math/IeeeRecommendedTests.java
>> ](https://github.com/openjdk/jdk/blob/master/test/jdk/java/lang/Math/IeeeRecommendedTests.java)
>>
>>
>> Granite Rapids-AP (P-core Xeon)
>> Baseline AVX512:
>> Benchmark Mode Cnt Score Error Units
>> Signum._5_copySignFloatTest thrpt 2 1296.141 ops/ns
>> Signum._7_copySignDoubleTest thrpt 2 838.954 ops/ns
>>
>> Withopt :
>> Benchmark Mode Cnt Score Error Units
>> Signum._5_copySignFloatTest thrpt 2 940.240 ops/ns
>> Signum._7_copySignDoubleTest thrpt 2 967.370 ops/ns
>>
>> Baseline AVX2:
>> Benchmark Mode Cnt Score Error Units
>> Signum._5_copySignFloatTest thrpt 2 63.673 ops/ns
>> Signum._7_copySignDoubleTest thrpt 2 26.898 ops/ns
>>
>> Withopt :
>> Benchmark Mode Cnt Score Error Units
>> Signum._5_copySignFloatTest thrpt 2 785.801 ops/ns
>> Signum._7_copySignDoubleTest thrpt 2 558.710 ops/ns
>>
>> Sierra Forest (E-core Xeon)
>> Baseline:
>> Benchmark (seed) Mode Cnt Score Error Units
>> o.o.b.vm.compiler.Signum._5_copySignFloatTest N/A thrpt 2 40.528 ops/ns
>> o.o.b.vm.compiler.Signum._7_copySignDoubleTest N/A thrpt 2 25.101 ops/ns
>>
>> Withopt:
>> Benchmark (seed) Mode Cnt Score Error Units
>> o.o.b.vm.compiler.Signum._5_copySignFloatTest N/A thrpt 2 676....
>
> Jatin Bhateja has updated the pull request incrementally with one additional commit since the last revision:
>
> Adding IR framework verification test
`compiler/intrinsics/math/TestCopySignIntrinsic.java` fails with `-ea -esa -XX:CompileThreshold=100 -XX:+UnlockExperimentalVMOptions -server -XX:+TieredCompilation` on Mac x64:
1) Method "public void compiler.intrinsics.math.TestCopySignIntrinsic.testCopySignD()" - [Failed IR rules: 1]:
* @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#COPYSIGN_D#_", " >0 "}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={"avx", "true"}, applyIfAnd={}, applyIfNot={})"
> Phase "PrintIdeal":
- counts: Graph contains wrong number of nodes:
* Constraint 1: "(\\d+(\\s){2}(CopySignD.*)+(\\s){2}===.*)"
- Failed comparison: [found] 0 > 0 [given]
- No nodes matched!
2) Method "public void compiler.intrinsics.math.TestCopySignIntrinsic.testCopySignF()" - [Failed IR rules: 1]:
* @IR rule 1: "@compiler.lib.ir_framework.IR(phase={DEFAULT}, applyIfPlatformAnd={}, applyIfCPUFeatureOr={}, counts={"_#COPYSIGN_F#_", " >0 "}, applyIfPlatform={}, applyIfPlatformOr={}, failOn={}, applyIfOr={}, applyIfCPUFeatureAnd={}, applyIf={}, applyIfCPUFeature={"avx", "true"}, applyIfAnd={}, applyIfNot={})"
> Phase "PrintIdeal":
- counts: Graph contains wrong number of nodes:
* Constraint 1: "(\\d+(\\s){2}(CopySignF.*)+(\\s){2}===.*)"
- Failed comparison: [found] 0 > 0 [given]
- No nodes matched!
-------------
PR Comment: https://git.openjdk.org/jdk/pull/23386#issuecomment-2635945209
More information about the hotspot-compiler-dev
mailing list