go/src/simd/ternary_helpers_test.go

495 lines
18 KiB
Go
Raw Normal View History

[dev.simd] simd: move test generation into Go repo This pairs with CL 689275 which removes test generation from simdgen This uses generics and attempts to encode the tests as compactly as possible. Some files, *_helpers_test.go, are generated. Use t.Helper() to get the line number right for a failure. Adds helper error return values and early exits to only report a single test failure per operations and vector shape, for the generated test failures. Include the entire got and wanted vectors for that failure. Provide an option to include the input vectors to failures, also report the type of the test. Sample failure test output (obtained by intentionally breaking the "want" value for AndNot): === RUN TestAndNot binary_test.go:214: For int16 vector elements: binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: at index 0, got=0, want=-1 binary_test.go:215: For int16 vector elements: binary_test.go:215: got =[0 0 0 0 0 0 0 0] binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:215: x=[1 -1 0 2 4 8 1024 3] binary_test.go:215: y=[1 -1 0 2 4 8 1024 3] binary_test.go:215: at index 0, got=0, want=-1 binary_test.go:216: For int32 vector elements: binary_test.go:216: got =[0 0 0 0] binary_test.go:216: want=[-1 -1 -1 -1] binary_test.go:216: x=[1 -1 0 2] binary_test.go:216: y=[1 -1 0 2] binary_test.go:216: at index 0, got=0, want=-1 (etc) Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38 Reviewed-on: https://go-review.googlesource.com/c/go/+/686057 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
// Code generated by 'go run genfiles.go'; DO NOT EDIT.
//go:build goexperiment.simd
// This file contains functions testing ternary simd methods.
// Each function in this file is specialized for a
// particular simd type <BaseType><Width>x<Count>.
package simd_test
import (
"simd"
"testing"
)
// testInt8x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt8x16Ternary(t *testing.T, f func(_, _, _ simd.Int8x16) simd.Int8x16, want func(_, _, _ []int8) []int8) {
n := 16
t.Helper()
forSliceTriple(t, int8s, n, func(x, y, z []int8) bool {
t.Helper()
a := simd.LoadInt8x16Slice(x)
b := simd.LoadInt8x16Slice(y)
c := simd.LoadInt8x16Slice(z)
g := make([]int8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt16x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt16x8Ternary(t *testing.T, f func(_, _, _ simd.Int16x8) simd.Int16x8, want func(_, _, _ []int16) []int16) {
n := 8
t.Helper()
forSliceTriple(t, int16s, n, func(x, y, z []int16) bool {
t.Helper()
a := simd.LoadInt16x8Slice(x)
b := simd.LoadInt16x8Slice(y)
c := simd.LoadInt16x8Slice(z)
g := make([]int16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt32x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt32x4Ternary(t *testing.T, f func(_, _, _ simd.Int32x4) simd.Int32x4, want func(_, _, _ []int32) []int32) {
n := 4
t.Helper()
forSliceTriple(t, int32s, n, func(x, y, z []int32) bool {
t.Helper()
a := simd.LoadInt32x4Slice(x)
b := simd.LoadInt32x4Slice(y)
c := simd.LoadInt32x4Slice(z)
g := make([]int32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt64x2Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt64x2Ternary(t *testing.T, f func(_, _, _ simd.Int64x2) simd.Int64x2, want func(_, _, _ []int64) []int64) {
n := 2
t.Helper()
forSliceTriple(t, int64s, n, func(x, y, z []int64) bool {
t.Helper()
a := simd.LoadInt64x2Slice(x)
b := simd.LoadInt64x2Slice(y)
c := simd.LoadInt64x2Slice(z)
g := make([]int64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint8x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint8x16Ternary(t *testing.T, f func(_, _, _ simd.Uint8x16) simd.Uint8x16, want func(_, _, _ []uint8) []uint8) {
n := 16
t.Helper()
forSliceTriple(t, uint8s, n, func(x, y, z []uint8) bool {
t.Helper()
a := simd.LoadUint8x16Slice(x)
b := simd.LoadUint8x16Slice(y)
c := simd.LoadUint8x16Slice(z)
g := make([]uint8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint16x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint16x8Ternary(t *testing.T, f func(_, _, _ simd.Uint16x8) simd.Uint16x8, want func(_, _, _ []uint16) []uint16) {
n := 8
t.Helper()
forSliceTriple(t, uint16s, n, func(x, y, z []uint16) bool {
t.Helper()
a := simd.LoadUint16x8Slice(x)
b := simd.LoadUint16x8Slice(y)
c := simd.LoadUint16x8Slice(z)
g := make([]uint16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint32x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint32x4Ternary(t *testing.T, f func(_, _, _ simd.Uint32x4) simd.Uint32x4, want func(_, _, _ []uint32) []uint32) {
n := 4
t.Helper()
forSliceTriple(t, uint32s, n, func(x, y, z []uint32) bool {
t.Helper()
a := simd.LoadUint32x4Slice(x)
b := simd.LoadUint32x4Slice(y)
c := simd.LoadUint32x4Slice(z)
g := make([]uint32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
[dev.simd] simd: move test generation into Go repo This pairs with CL 689275 which removes test generation from simdgen This uses generics and attempts to encode the tests as compactly as possible. Some files, *_helpers_test.go, are generated. Use t.Helper() to get the line number right for a failure. Adds helper error return values and early exits to only report a single test failure per operations and vector shape, for the generated test failures. Include the entire got and wanted vectors for that failure. Provide an option to include the input vectors to failures, also report the type of the test. Sample failure test output (obtained by intentionally breaking the "want" value for AndNot): === RUN TestAndNot binary_test.go:214: For int16 vector elements: binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: at index 0, got=0, want=-1 binary_test.go:215: For int16 vector elements: binary_test.go:215: got =[0 0 0 0 0 0 0 0] binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:215: x=[1 -1 0 2 4 8 1024 3] binary_test.go:215: y=[1 -1 0 2 4 8 1024 3] binary_test.go:215: at index 0, got=0, want=-1 binary_test.go:216: For int32 vector elements: binary_test.go:216: got =[0 0 0 0] binary_test.go:216: want=[-1 -1 -1 -1] binary_test.go:216: x=[1 -1 0 2] binary_test.go:216: y=[1 -1 0 2] binary_test.go:216: at index 0, got=0, want=-1 (etc) Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38 Reviewed-on: https://go-review.googlesource.com/c/go/+/686057 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
// testUint64x2Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint64x2Ternary(t *testing.T, f func(_, _, _ simd.Uint64x2) simd.Uint64x2, want func(_, _, _ []uint64) []uint64) {
n := 2
t.Helper()
forSliceTriple(t, uint64s, n, func(x, y, z []uint64) bool {
t.Helper()
a := simd.LoadUint64x2Slice(x)
b := simd.LoadUint64x2Slice(y)
c := simd.LoadUint64x2Slice(z)
g := make([]uint64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat32x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat32x4Ternary(t *testing.T, f func(_, _, _ simd.Float32x4) simd.Float32x4, want func(_, _, _ []float32) []float32) {
n := 4
t.Helper()
forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
t.Helper()
a := simd.LoadFloat32x4Slice(x)
b := simd.LoadFloat32x4Slice(y)
c := simd.LoadFloat32x4Slice(z)
g := make([]float32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat64x2Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat64x2Ternary(t *testing.T, f func(_, _, _ simd.Float64x2) simd.Float64x2, want func(_, _, _ []float64) []float64) {
n := 2
t.Helper()
forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
t.Helper()
a := simd.LoadFloat64x2Slice(x)
b := simd.LoadFloat64x2Slice(y)
c := simd.LoadFloat64x2Slice(z)
g := make([]float64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt8x32Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt8x32Ternary(t *testing.T, f func(_, _, _ simd.Int8x32) simd.Int8x32, want func(_, _, _ []int8) []int8) {
n := 32
t.Helper()
forSliceTriple(t, int8s, n, func(x, y, z []int8) bool {
t.Helper()
a := simd.LoadInt8x32Slice(x)
b := simd.LoadInt8x32Slice(y)
c := simd.LoadInt8x32Slice(z)
g := make([]int8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt16x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt16x16Ternary(t *testing.T, f func(_, _, _ simd.Int16x16) simd.Int16x16, want func(_, _, _ []int16) []int16) {
n := 16
t.Helper()
forSliceTriple(t, int16s, n, func(x, y, z []int16) bool {
t.Helper()
a := simd.LoadInt16x16Slice(x)
b := simd.LoadInt16x16Slice(y)
c := simd.LoadInt16x16Slice(z)
g := make([]int16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt32x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt32x8Ternary(t *testing.T, f func(_, _, _ simd.Int32x8) simd.Int32x8, want func(_, _, _ []int32) []int32) {
n := 8
t.Helper()
forSliceTriple(t, int32s, n, func(x, y, z []int32) bool {
t.Helper()
a := simd.LoadInt32x8Slice(x)
b := simd.LoadInt32x8Slice(y)
c := simd.LoadInt32x8Slice(z)
g := make([]int32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt64x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt64x4Ternary(t *testing.T, f func(_, _, _ simd.Int64x4) simd.Int64x4, want func(_, _, _ []int64) []int64) {
n := 4
t.Helper()
forSliceTriple(t, int64s, n, func(x, y, z []int64) bool {
t.Helper()
a := simd.LoadInt64x4Slice(x)
b := simd.LoadInt64x4Slice(y)
c := simd.LoadInt64x4Slice(z)
g := make([]int64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint8x32Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint8x32Ternary(t *testing.T, f func(_, _, _ simd.Uint8x32) simd.Uint8x32, want func(_, _, _ []uint8) []uint8) {
n := 32
t.Helper()
forSliceTriple(t, uint8s, n, func(x, y, z []uint8) bool {
t.Helper()
a := simd.LoadUint8x32Slice(x)
b := simd.LoadUint8x32Slice(y)
c := simd.LoadUint8x32Slice(z)
g := make([]uint8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint16x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint16x16Ternary(t *testing.T, f func(_, _, _ simd.Uint16x16) simd.Uint16x16, want func(_, _, _ []uint16) []uint16) {
n := 16
t.Helper()
forSliceTriple(t, uint16s, n, func(x, y, z []uint16) bool {
t.Helper()
a := simd.LoadUint16x16Slice(x)
b := simd.LoadUint16x16Slice(y)
c := simd.LoadUint16x16Slice(z)
g := make([]uint16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint32x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint32x8Ternary(t *testing.T, f func(_, _, _ simd.Uint32x8) simd.Uint32x8, want func(_, _, _ []uint32) []uint32) {
n := 8
t.Helper()
forSliceTriple(t, uint32s, n, func(x, y, z []uint32) bool {
t.Helper()
a := simd.LoadUint32x8Slice(x)
b := simd.LoadUint32x8Slice(y)
c := simd.LoadUint32x8Slice(z)
g := make([]uint32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
[dev.simd] simd: move test generation into Go repo This pairs with CL 689275 which removes test generation from simdgen This uses generics and attempts to encode the tests as compactly as possible. Some files, *_helpers_test.go, are generated. Use t.Helper() to get the line number right for a failure. Adds helper error return values and early exits to only report a single test failure per operations and vector shape, for the generated test failures. Include the entire got and wanted vectors for that failure. Provide an option to include the input vectors to failures, also report the type of the test. Sample failure test output (obtained by intentionally breaking the "want" value for AndNot): === RUN TestAndNot binary_test.go:214: For int16 vector elements: binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: at index 0, got=0, want=-1 binary_test.go:215: For int16 vector elements: binary_test.go:215: got =[0 0 0 0 0 0 0 0] binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:215: x=[1 -1 0 2 4 8 1024 3] binary_test.go:215: y=[1 -1 0 2 4 8 1024 3] binary_test.go:215: at index 0, got=0, want=-1 binary_test.go:216: For int32 vector elements: binary_test.go:216: got =[0 0 0 0] binary_test.go:216: want=[-1 -1 -1 -1] binary_test.go:216: x=[1 -1 0 2] binary_test.go:216: y=[1 -1 0 2] binary_test.go:216: at index 0, got=0, want=-1 (etc) Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38 Reviewed-on: https://go-review.googlesource.com/c/go/+/686057 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
// testUint64x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint64x4Ternary(t *testing.T, f func(_, _, _ simd.Uint64x4) simd.Uint64x4, want func(_, _, _ []uint64) []uint64) {
n := 4
t.Helper()
forSliceTriple(t, uint64s, n, func(x, y, z []uint64) bool {
t.Helper()
a := simd.LoadUint64x4Slice(x)
b := simd.LoadUint64x4Slice(y)
c := simd.LoadUint64x4Slice(z)
g := make([]uint64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat32x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat32x8Ternary(t *testing.T, f func(_, _, _ simd.Float32x8) simd.Float32x8, want func(_, _, _ []float32) []float32) {
n := 8
t.Helper()
forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
t.Helper()
a := simd.LoadFloat32x8Slice(x)
b := simd.LoadFloat32x8Slice(y)
c := simd.LoadFloat32x8Slice(z)
g := make([]float32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat64x4Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat64x4Ternary(t *testing.T, f func(_, _, _ simd.Float64x4) simd.Float64x4, want func(_, _, _ []float64) []float64) {
n := 4
t.Helper()
forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
t.Helper()
a := simd.LoadFloat64x4Slice(x)
b := simd.LoadFloat64x4Slice(y)
c := simd.LoadFloat64x4Slice(z)
g := make([]float64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt8x64Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt8x64Ternary(t *testing.T, f func(_, _, _ simd.Int8x64) simd.Int8x64, want func(_, _, _ []int8) []int8) {
n := 64
t.Helper()
forSliceTriple(t, int8s, n, func(x, y, z []int8) bool {
t.Helper()
a := simd.LoadInt8x64Slice(x)
b := simd.LoadInt8x64Slice(y)
c := simd.LoadInt8x64Slice(z)
g := make([]int8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt16x32Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt16x32Ternary(t *testing.T, f func(_, _, _ simd.Int16x32) simd.Int16x32, want func(_, _, _ []int16) []int16) {
n := 32
t.Helper()
forSliceTriple(t, int16s, n, func(x, y, z []int16) bool {
t.Helper()
a := simd.LoadInt16x32Slice(x)
b := simd.LoadInt16x32Slice(y)
c := simd.LoadInt16x32Slice(z)
g := make([]int16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt32x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt32x16Ternary(t *testing.T, f func(_, _, _ simd.Int32x16) simd.Int32x16, want func(_, _, _ []int32) []int32) {
n := 16
t.Helper()
forSliceTriple(t, int32s, n, func(x, y, z []int32) bool {
t.Helper()
a := simd.LoadInt32x16Slice(x)
b := simd.LoadInt32x16Slice(y)
c := simd.LoadInt32x16Slice(z)
g := make([]int32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testInt64x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testInt64x8Ternary(t *testing.T, f func(_, _, _ simd.Int64x8) simd.Int64x8, want func(_, _, _ []int64) []int64) {
n := 8
t.Helper()
forSliceTriple(t, int64s, n, func(x, y, z []int64) bool {
t.Helper()
a := simd.LoadInt64x8Slice(x)
b := simd.LoadInt64x8Slice(y)
c := simd.LoadInt64x8Slice(z)
g := make([]int64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint8x64Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint8x64Ternary(t *testing.T, f func(_, _, _ simd.Uint8x64) simd.Uint8x64, want func(_, _, _ []uint8) []uint8) {
n := 64
t.Helper()
forSliceTriple(t, uint8s, n, func(x, y, z []uint8) bool {
t.Helper()
a := simd.LoadUint8x64Slice(x)
b := simd.LoadUint8x64Slice(y)
c := simd.LoadUint8x64Slice(z)
g := make([]uint8, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint16x32Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint16x32Ternary(t *testing.T, f func(_, _, _ simd.Uint16x32) simd.Uint16x32, want func(_, _, _ []uint16) []uint16) {
n := 32
t.Helper()
forSliceTriple(t, uint16s, n, func(x, y, z []uint16) bool {
t.Helper()
a := simd.LoadUint16x32Slice(x)
b := simd.LoadUint16x32Slice(y)
c := simd.LoadUint16x32Slice(z)
g := make([]uint16, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint32x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint32x16Ternary(t *testing.T, f func(_, _, _ simd.Uint32x16) simd.Uint32x16, want func(_, _, _ []uint32) []uint32) {
n := 16
t.Helper()
forSliceTriple(t, uint32s, n, func(x, y, z []uint32) bool {
t.Helper()
a := simd.LoadUint32x16Slice(x)
b := simd.LoadUint32x16Slice(y)
c := simd.LoadUint32x16Slice(z)
g := make([]uint32, n)
f(a, b, c).StoreSlice(g)
[dev.simd] simd: move test generation into Go repo This pairs with CL 689275 which removes test generation from simdgen This uses generics and attempts to encode the tests as compactly as possible. Some files, *_helpers_test.go, are generated. Use t.Helper() to get the line number right for a failure. Adds helper error return values and early exits to only report a single test failure per operations and vector shape, for the generated test failures. Include the entire got and wanted vectors for that failure. Provide an option to include the input vectors to failures, also report the type of the test. Sample failure test output (obtained by intentionally breaking the "want" value for AndNot): === RUN TestAndNot binary_test.go:214: For int16 vector elements: binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111] binary_test.go:214: at index 0, got=0, want=-1 binary_test.go:215: For int16 vector elements: binary_test.go:215: got =[0 0 0 0 0 0 0 0] binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1] binary_test.go:215: x=[1 -1 0 2 4 8 1024 3] binary_test.go:215: y=[1 -1 0 2 4 8 1024 3] binary_test.go:215: at index 0, got=0, want=-1 binary_test.go:216: For int32 vector elements: binary_test.go:216: got =[0 0 0 0] binary_test.go:216: want=[-1 -1 -1 -1] binary_test.go:216: x=[1 -1 0 2] binary_test.go:216: y=[1 -1 0 2] binary_test.go:216: at index 0, got=0, want=-1 (etc) Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38 Reviewed-on: https://go-review.googlesource.com/c/go/+/686057 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testUint64x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testUint64x8Ternary(t *testing.T, f func(_, _, _ simd.Uint64x8) simd.Uint64x8, want func(_, _, _ []uint64) []uint64) {
n := 8
t.Helper()
forSliceTriple(t, uint64s, n, func(x, y, z []uint64) bool {
t.Helper()
a := simd.LoadUint64x8Slice(x)
b := simd.LoadUint64x8Slice(y)
c := simd.LoadUint64x8Slice(z)
g := make([]uint64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat32x16Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat32x16Ternary(t *testing.T, f func(_, _, _ simd.Float32x16) simd.Float32x16, want func(_, _, _ []float32) []float32) {
n := 16
t.Helper()
forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
t.Helper()
a := simd.LoadFloat32x16Slice(x)
b := simd.LoadFloat32x16Slice(y)
c := simd.LoadFloat32x16Slice(z)
g := make([]float32, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}
// testFloat64x8Ternary tests the simd ternary method f against the expected behavior generated by want
func testFloat64x8Ternary(t *testing.T, f func(_, _, _ simd.Float64x8) simd.Float64x8, want func(_, _, _ []float64) []float64) {
n := 8
t.Helper()
forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
t.Helper()
a := simd.LoadFloat64x8Slice(x)
b := simd.LoadFloat64x8Slice(y)
c := simd.LoadFloat64x8Slice(z)
g := make([]float64, n)
f(a, b, c).StoreSlice(g)
w := want(x, y, z)
return checkSlicesLogInput(t, g, w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
})
}