Math.Signum() currently uses two floating point compares and a copy sign operation which involves data movement to gpr and XMM.
It can be optimized to use only 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._3_signumDoubleTest avgt 5 4.809 ? 0.043 ns/op
Optimized:
signum intrinsic patch
Benchmark Mode Cnt Score Error Units
Signum._1_signumFloatTest avgt 5 3.782 ? 0.019 ns/op
Signum._3_signumDoubleTest avgt 5 3.782 ? 0.017 ns/op
It can be optimized to use only 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._3_signumDoubleTest avgt 5 4.809 ? 0.043 ns/op
Optimized:
signum intrinsic patch
Benchmark Mode Cnt Score Error Units
Signum._1_signumFloatTest avgt 5 3.782 ? 0.019 ns/op
Signum._3_signumDoubleTest avgt 5 3.782 ? 0.017 ns/op
- relates to
-
JDK-8271883 Math CopySign optimization for x86
-
- Resolved
-
-
JDK-8251525 AArch64: Faster Math.signum(fp)
-
- Resolved
-