From: David Chase Date: Fri, 24 Oct 2025 21:25:46 +0000 (-0400) Subject: [dev.simd] test: add some trickier cases to ternary-boolean simd test X-Git-Tag: go1.26rc1~147^2~32 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ca1264ac50;p=gostls13.git [dev.simd] test: add some trickier cases to ternary-boolean simd test These new tests check a hypothesis about interactions between CPU features and common subexpressions. Happily, they hypothesis was not (yet) correct and the test did not fail. These are probably good to have in the corpus in case we decide to tinker with the rewrite in the future, or if someone wants to write a fuzzer and needs a little inspiration. Change-Id: I8ea6e1655a293c22e39bf53e4d2c5afd3dcb2510 Reviewed-on: https://go-review.googlesource.com/c/go/+/714803 Reviewed-by: Junyang Shao LUCI-TryBot-Result: Go LUCI --- diff --git a/test/simd.go b/test/simd.go index 32ed70d39a..307e98e0e7 100644 --- a/test/simd.go +++ b/test/simd.go @@ -105,3 +105,41 @@ func ternRewrite(m, w, x, y, z simd.Int32x16) (t0, t1, t2 simd.Int32x16) { t2 = x.Xor(y).Xor(z).And(x.Xor(y).Xor(z.Not())) // ERROR "Rewriting.*ternInt" return // ERROR "has features avx[+]avx2[+]avx512$" } + +func ternTricky1(x, y, z simd.Int32x8) simd.Int32x8 { + // Int32x8 is a 256-bit vector and does not guarantee AVX-512 + // a is a 3-variable logical expression occurring outside AVX-512 feature check + a := x.Xor(y).Xor(z) + var w simd.Int32x8 + if !simd.HasAVX512() { // ERROR "has features avx$" + // do nothing + } else { + w = y.AndNot(a) // ERROR "has features avx[+]avx2[+]avx512" "Rewriting.*ternInt" + } + // a is a common subexpression + return a.Or(w) // ERROR "has features avx$" +} + +func ternTricky2(x, y, z simd.Int32x8) simd.Int32x8 { + // Int32x8 is a 256-bit vector and does not guarantee AVX-512 + var a, w simd.Int32x8 + if !simd.HasAVX512() { // ERROR "has features avx$" + // do nothing + } else { + a = x.Xor(y).Xor(z) + w = y.AndNot(a) // ERROR "has features avx[+]avx2[+]avx512" "Rewriting.*ternInt" + } + // a is a common subexpression + return a.Or(w) // ERROR "has features avx$" +} + +func ternTricky3(x, y, z simd.Int32x8) simd.Int32x8 { + // Int32x8 is a 256-bit vector and does not guarantee AVX-512 + a := x.Xor(y).Xor(z) + w := y.AndNot(a) + if !simd.HasAVX512() { // ERROR "has features avx$" + return a // ERROR "has features avx$" + } + // a is a common subexpression + return a.Or(w) // ERROR "has features avx[+]avx2[+]avx512" // This does not rewrite, do we want it to? +}