diff options
| author | Cherry Mui <cherryyz@google.com> | 2026-01-02 14:02:07 -0500 |
|---|---|---|
| committer | Cherry Mui <cherryyz@google.com> | 2026-01-02 12:16:34 -0800 |
| commit | e84983fa40a6e97d3e169f1f3549af889b1b1f22 (patch) | |
| tree | 782393e6b94f39a862623149faac9bad11fabaf1 /src/simd | |
| parent | 8244b8567704739d9d6fa69a0f4b50b3203d6504 (diff) | |
| download | go-e84983fa40a6e97d3e169f1f3549af889b1b1f22.tar.xz | |
cmd/compile: optimize SIMD IsNaN.Or(IsNaN)
IsNaN's underlying instruction, VCMPPS (or VCMPPD), takes two
inputs, and computes either of them is NaN. Optimize the Or
pattern to generate two-operand form.
This implements the optimization mentioned in CL 733660.
Change-Id: I13943b377ee384864c913eed320763f333a03e41
Reviewed-on: https://go-review.googlesource.com/c/go/+/733680
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/simd')
| -rw-r--r-- | src/simd/archsimd/internal/simd_test/compare_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/simd/archsimd/internal/simd_test/compare_test.go b/src/simd/archsimd/internal/simd_test/compare_test.go index e678676be0..ea8514ac93 100644 --- a/src/simd/archsimd/internal/simd_test/compare_test.go +++ b/src/simd/archsimd/internal/simd_test/compare_test.go @@ -309,4 +309,38 @@ func TestIsNaN(t *testing.T) { testFloat32x16UnaryCompare(t, archsimd.Float32x16.IsNaN, isNaNSlice[float32]) testFloat64x8UnaryCompare(t, archsimd.Float64x8.IsNaN, isNaNSlice[float64]) } + + // Test x.IsNaN().Or(y.IsNaN()), which is optimized to VCMPP(S|D) $3, x, y. + want32 := mapCompare(func(x, y float32) bool { return x != x || y != y }) + want64 := mapCompare(func(x, y float64) bool { return x != x || y != y }) + testFloat32x4Compare(t, + func(x, y archsimd.Float32x4) archsimd.Mask32x4 { + return x.IsNaN().Or(y.IsNaN()) + }, want32) + testFloat64x2Compare(t, + func(x, y archsimd.Float64x2) archsimd.Mask64x2 { + return x.IsNaN().Or(y.IsNaN()) + }, want64) + + if archsimd.X86.AVX2() { + testFloat32x8Compare(t, + func(x, y archsimd.Float32x8) archsimd.Mask32x8 { + return x.IsNaN().Or(y.IsNaN()) + }, want32) + testFloat64x4Compare(t, + func(x, y archsimd.Float64x4) archsimd.Mask64x4 { + return x.IsNaN().Or(y.IsNaN()) + }, want64) + } + + if archsimd.X86.AVX512() { + testFloat32x16Compare(t, + func(x, y archsimd.Float32x16) archsimd.Mask32x16 { + return x.IsNaN().Or(y.IsNaN()) + }, want32) + testFloat64x8Compare(t, + func(x, y archsimd.Float64x8) archsimd.Mask64x8 { + return x.IsNaN().Or(y.IsNaN()) + }, want64) + } } |
