[dev.simd] simd: modify test generation to make it more flexible

This is to support conversions, which are not T -> T.

Change-Id: I323887b116eee8133770a899ed82363bba38a9c4
Reviewed-on: https://go-review.googlesource.com/c/go/+/689717
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
David Chase 2025-07-22 15:34:55 -04:00
parent ec5c20ba5a
commit a24ffe3379
7 changed files with 919 additions and 860 deletions

View file

@ -28,21 +28,6 @@ func testInt8x16Compare(t *testing.T, f func(_, _ simd.Int8x16) simd.Mask8x16, w
})
}
// testUint8x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x16Compare(t *testing.T, f func(_, _ simd.Uint8x16) simd.Mask8x16, want func(_, _ []uint8) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x16Slice(x)
b := simd.LoadUint8x16Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt16x8Compare tests the simd comparison method f against the expected behavior generated by want
func testInt16x8Compare(t *testing.T, f func(_, _ simd.Int16x8) simd.Mask16x8, want func(_, _ []int16) []int64) {
n := 8
@ -58,21 +43,6 @@ func testInt16x8Compare(t *testing.T, f func(_, _ simd.Int16x8) simd.Mask16x8, w
})
}
// testUint16x8Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x8Compare(t *testing.T, f func(_, _ simd.Uint16x8) simd.Mask16x8, want func(_, _ []uint16) []int64) {
n := 8
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x8Slice(x)
b := simd.LoadUint16x8Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x8().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt32x4Compare tests the simd comparison method f against the expected behavior generated by want
func testInt32x4Compare(t *testing.T, f func(_, _ simd.Int32x4) simd.Mask32x4, want func(_, _ []int32) []int64) {
n := 4
@ -88,21 +58,6 @@ func testInt32x4Compare(t *testing.T, f func(_, _ simd.Int32x4) simd.Mask32x4, w
})
}
// testUint32x4Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x4Compare(t *testing.T, f func(_, _ simd.Uint32x4) simd.Mask32x4, want func(_, _ []uint32) []int64) {
n := 4
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x4Slice(x)
b := simd.LoadUint32x4Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x4().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt64x2Compare tests the simd comparison method f against the expected behavior generated by want
func testInt64x2Compare(t *testing.T, f func(_, _ simd.Int64x2) simd.Mask64x2, want func(_, _ []int64) []int64) {
n := 2
@ -118,6 +73,51 @@ func testInt64x2Compare(t *testing.T, f func(_, _ simd.Int64x2) simd.Mask64x2, w
})
}
// testUint8x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x16Compare(t *testing.T, f func(_, _ simd.Uint8x16) simd.Mask8x16, want func(_, _ []uint8) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x16Slice(x)
b := simd.LoadUint8x16Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint16x8Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x8Compare(t *testing.T, f func(_, _ simd.Uint16x8) simd.Mask16x8, want func(_, _ []uint16) []int64) {
n := 8
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x8Slice(x)
b := simd.LoadUint16x8Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x8().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint32x4Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x4Compare(t *testing.T, f func(_, _ simd.Uint32x4) simd.Mask32x4, want func(_, _ []uint32) []int64) {
n := 4
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x4Slice(x)
b := simd.LoadUint32x4Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x4().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint64x2Compare tests the simd comparison method f against the expected behavior generated by want
func testUint64x2Compare(t *testing.T, f func(_, _ simd.Uint64x2) simd.Mask64x2, want func(_, _ []uint64) []int64) {
n := 2
@ -178,21 +178,6 @@ func testInt8x32Compare(t *testing.T, f func(_, _ simd.Int8x32) simd.Mask8x32, w
})
}
// testUint8x32Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x32Compare(t *testing.T, f func(_, _ simd.Uint8x32) simd.Mask8x32, want func(_, _ []uint8) []int64) {
n := 32
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x32Slice(x)
b := simd.LoadUint8x32Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x32().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt16x16Compare tests the simd comparison method f against the expected behavior generated by want
func testInt16x16Compare(t *testing.T, f func(_, _ simd.Int16x16) simd.Mask16x16, want func(_, _ []int16) []int64) {
n := 16
@ -208,21 +193,6 @@ func testInt16x16Compare(t *testing.T, f func(_, _ simd.Int16x16) simd.Mask16x16
})
}
// testUint16x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x16Compare(t *testing.T, f func(_, _ simd.Uint16x16) simd.Mask16x16, want func(_, _ []uint16) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x16Slice(x)
b := simd.LoadUint16x16Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt32x8Compare tests the simd comparison method f against the expected behavior generated by want
func testInt32x8Compare(t *testing.T, f func(_, _ simd.Int32x8) simd.Mask32x8, want func(_, _ []int32) []int64) {
n := 8
@ -238,21 +208,6 @@ func testInt32x8Compare(t *testing.T, f func(_, _ simd.Int32x8) simd.Mask32x8, w
})
}
// testUint32x8Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x8Compare(t *testing.T, f func(_, _ simd.Uint32x8) simd.Mask32x8, want func(_, _ []uint32) []int64) {
n := 8
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x8Slice(x)
b := simd.LoadUint32x8Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x8().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt64x4Compare tests the simd comparison method f against the expected behavior generated by want
func testInt64x4Compare(t *testing.T, f func(_, _ simd.Int64x4) simd.Mask64x4, want func(_, _ []int64) []int64) {
n := 4
@ -268,6 +223,51 @@ func testInt64x4Compare(t *testing.T, f func(_, _ simd.Int64x4) simd.Mask64x4, w
})
}
// testUint8x32Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x32Compare(t *testing.T, f func(_, _ simd.Uint8x32) simd.Mask8x32, want func(_, _ []uint8) []int64) {
n := 32
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x32Slice(x)
b := simd.LoadUint8x32Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x32().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint16x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x16Compare(t *testing.T, f func(_, _ simd.Uint16x16) simd.Mask16x16, want func(_, _ []uint16) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x16Slice(x)
b := simd.LoadUint16x16Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint32x8Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x8Compare(t *testing.T, f func(_, _ simd.Uint32x8) simd.Mask32x8, want func(_, _ []uint32) []int64) {
n := 8
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x8Slice(x)
b := simd.LoadUint32x8Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x8().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint64x4Compare tests the simd comparison method f against the expected behavior generated by want
func testUint64x4Compare(t *testing.T, f func(_, _ simd.Uint64x4) simd.Mask64x4, want func(_, _ []uint64) []int64) {
n := 4
@ -328,21 +328,6 @@ func testInt8x64Compare(t *testing.T, f func(_, _ simd.Int8x64) simd.Mask8x64, w
})
}
// testUint8x64Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x64Compare(t *testing.T, f func(_, _ simd.Uint8x64) simd.Mask8x64, want func(_, _ []uint8) []int64) {
n := 64
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x64Slice(x)
b := simd.LoadUint8x64Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x64().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt16x32Compare tests the simd comparison method f against the expected behavior generated by want
func testInt16x32Compare(t *testing.T, f func(_, _ simd.Int16x32) simd.Mask16x32, want func(_, _ []int16) []int64) {
n := 32
@ -358,21 +343,6 @@ func testInt16x32Compare(t *testing.T, f func(_, _ simd.Int16x32) simd.Mask16x32
})
}
// testUint16x32Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x32Compare(t *testing.T, f func(_, _ simd.Uint16x32) simd.Mask16x32, want func(_, _ []uint16) []int64) {
n := 32
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x32Slice(x)
b := simd.LoadUint16x32Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x32().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt32x16Compare tests the simd comparison method f against the expected behavior generated by want
func testInt32x16Compare(t *testing.T, f func(_, _ simd.Int32x16) simd.Mask32x16, want func(_, _ []int32) []int64) {
n := 16
@ -388,21 +358,6 @@ func testInt32x16Compare(t *testing.T, f func(_, _ simd.Int32x16) simd.Mask32x16
})
}
// testUint32x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x16Compare(t *testing.T, f func(_, _ simd.Uint32x16) simd.Mask32x16, want func(_, _ []uint32) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x16Slice(x)
b := simd.LoadUint32x16Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testInt64x8Compare tests the simd comparison method f against the expected behavior generated by want
func testInt64x8Compare(t *testing.T, f func(_, _ simd.Int64x8) simd.Mask64x8, want func(_, _ []int64) []int64) {
n := 8
@ -418,6 +373,51 @@ func testInt64x8Compare(t *testing.T, f func(_, _ simd.Int64x8) simd.Mask64x8, w
})
}
// testUint8x64Compare tests the simd comparison method f against the expected behavior generated by want
func testUint8x64Compare(t *testing.T, f func(_, _ simd.Uint8x64) simd.Mask8x64, want func(_, _ []uint8) []int64) {
n := 64
t.Helper()
forSlicePair(t, uint8s, n, func(x, y []uint8) bool {
t.Helper()
a := simd.LoadUint8x64Slice(x)
b := simd.LoadUint8x64Slice(y)
g := make([]int8, n)
f(a, b).AsInt8x64().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint16x32Compare tests the simd comparison method f against the expected behavior generated by want
func testUint16x32Compare(t *testing.T, f func(_, _ simd.Uint16x32) simd.Mask16x32, want func(_, _ []uint16) []int64) {
n := 32
t.Helper()
forSlicePair(t, uint16s, n, func(x, y []uint16) bool {
t.Helper()
a := simd.LoadUint16x32Slice(x)
b := simd.LoadUint16x32Slice(y)
g := make([]int16, n)
f(a, b).AsInt16x32().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint32x16Compare tests the simd comparison method f against the expected behavior generated by want
func testUint32x16Compare(t *testing.T, f func(_, _ simd.Uint32x16) simd.Mask32x16, want func(_, _ []uint32) []int64) {
n := 16
t.Helper()
forSlicePair(t, uint32s, n, func(x, y []uint32) bool {
t.Helper()
a := simd.LoadUint32x16Slice(x)
b := simd.LoadUint32x16Slice(y)
g := make([]int32, n)
f(a, b).AsInt32x16().StoreSlice(g)
w := want(x, y)
return checkSlicesLogInput(t, s64(g), w, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) })
})
}
// testUint64x8Compare tests the simd comparison method f against the expected behavior generated by want
func testUint64x8Compare(t *testing.T, f func(_, _ simd.Uint64x8) simd.Mask64x8, want func(_, _ []uint64) []int64) {
n := 8