simd/archsimd: deduplicate tests Put tests that can run on all supported architectures (AMD64, ARM64, and Wasm) in common files. Only use architecture-specific files for architecture-specific operations. Change-Id: I7be5dd6afd1f3186fb3fff3dc2817024b67c6fa9 Reviewed-on: https://go-review.googlesource.com/c/go/+/792161 Reviewed-by: Junyang Shao <shaojunyang@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/src/simd/archsimd/_gen/tmplgen/main.go b/src/simd/archsimd/_gen/tmplgen/main.go index 24ca72a..692aebe 100644 --- a/src/simd/archsimd/_gen/tmplgen/main.go +++ b/src/simd/archsimd/_gen/tmplgen/main.go
@@ -1449,14 +1449,12 @@ ch := flag.String("ch", TD+"compare_helpers_%W_test.go", "file name for compare test helpers") cmh := flag.String("cmh", TD+"comparemasked_helpers_test.go", "file name for compare-masked test helpers") // ARM64-specific - bhArm64 := flag.String("bhArm64", TD+"arm64_binary_helpers_test.go", "file name for ARM64 binary test helpers") slArm64 := flag.String("slArm64", SIMD+"slice_gen_arm64.go", "file name for ARM64 slice operations") opArm64 := flag.String("opArm64", SIMD+"other_gen_arm64.go", "file name for ARM64 other operations") shArm64 := flag.String("shArm64", TD+"arm64_shift_helpers_test.go", "file name for ARM64 shift test helpers") uhArm64 := flag.String("uhArm64", TD+"arm64_unary_helpers_test.go", "file name for ARM64 unary test helpers") cmArm64 := flag.String("cmArm64", SIMD+"compare_gen_arm64.go", "file name for ARM64 comparison operations") mmArm64 := flag.String("mmArm64", SIMD+"maskmerge_gen_arm64.go", "file name for ARM64 mask/merge operations") - chArm64 := flag.String("chArm64", TD+"arm64_compare_helpers_test.go", "file name for ARM64 compare test helpers") thArm64 := flag.String("thArm64", TD+"ternary_arm64_helpers_test.go", "file name for ARM64 ternary test helpers") rhArm64 := flag.String("rhArm64", TD+"reduce_arm64_helpers_test.go", "file name for ARM64 reduce test helpers") flag.Parse() @@ -1529,9 +1527,6 @@ if *slArm64 != "" { one(*slArm64, prologue, sliceTemplateArm64) } - if *bhArm64 != "" { - oneArch(*bhArm64, "arm64", curryTestPrologue("binary simd methods"), binaryTemplateArm64) - } if *opArm64 != "" { one(*opArm64, prologue, broadcastTemplateArm64, @@ -1557,7 +1552,6 @@ arm64ToInt32, arm64ToUint32, arm64ToInt64, arm64ToUint64, arm64ToFloat32, arm64ToFloat64, - unaryTemplateArm64, ) } if *cmArm64 != "" { @@ -1573,9 +1567,6 @@ arm64MaskToString, ) } - if *chArm64 != "" { - oneArch(*chArm64, "arm64", curryTestPrologue("simd methods that compare two operands"), compareTemplateArm64) - } if *thArm64 != "" { oneArch(*thArm64, "arm64", curryTestPrologue("ternary simd methods"), ternaryTemplateArm64, ternaryFlakyTemplateArm64) } @@ -1750,7 +1741,7 @@ if strings.Contains(filename, "%W") { smallFile := strings.ReplaceAll(filename, "%W", "128") largeFile := strings.ReplaceAll(filename, "%W", "wider") - oneArch(smallFile, "(amd64 || wasm)", prologue, Map(smallSAT, sats)...) + oneArch(smallFile, "(amd64 || wasm || arm64)", prologue, Map(smallSAT, sats)...) oneArch(largeFile, "amd64", prologue, Map(largeSAT, sats)...) return }
diff --git a/src/simd/archsimd/internal/simd_test/arm64_binary_helpers_test.go b/src/simd/archsimd/internal/simd_test/arm64_binary_helpers_test.go deleted file mode 100644 index 6f537c2..0000000 --- a/src/simd/archsimd/internal/simd_test/arm64_binary_helpers_test.go +++ /dev/null
@@ -1,164 +0,0 @@ -// Code generated by 'tmplgen'; DO NOT EDIT. - -//go:build goexperiment.simd && arm64 - -// This file contains functions testing binary simd methods. -// Each function in this file is specialized for a -// particular simd type <BaseType><Width>x<Count>. - -package simd_test - -import ( - "simd/archsimd" - "testing" -) - -// testInt8x16Binary tests the simd binary method f against the expected behavior generated by want -func testInt8x16Binary(t *testing.T, f func(_, _ archsimd.Int8x16) archsimd.Int8x16, want func(_, _ []int8) []int8) { - n := 16 - t.Helper() - forSlicePair(t, int8s, n, func(x, y []int8) bool { - t.Helper() - a := archsimd.LoadInt8x16(x) - b := archsimd.LoadInt8x16(y) - g := make([]int8, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testInt16x8Binary tests the simd binary method f against the expected behavior generated by want -func testInt16x8Binary(t *testing.T, f func(_, _ archsimd.Int16x8) archsimd.Int16x8, want func(_, _ []int16) []int16) { - n := 8 - t.Helper() - forSlicePair(t, int16s, n, func(x, y []int16) bool { - t.Helper() - a := archsimd.LoadInt16x8(x) - b := archsimd.LoadInt16x8(y) - g := make([]int16, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testInt32x4Binary tests the simd binary method f against the expected behavior generated by want -func testInt32x4Binary(t *testing.T, f func(_, _ archsimd.Int32x4) archsimd.Int32x4, want func(_, _ []int32) []int32) { - n := 4 - t.Helper() - forSlicePair(t, int32s, n, func(x, y []int32) bool { - t.Helper() - a := archsimd.LoadInt32x4(x) - b := archsimd.LoadInt32x4(y) - g := make([]int32, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testInt64x2Binary tests the simd binary method f against the expected behavior generated by want -func testInt64x2Binary(t *testing.T, f func(_, _ archsimd.Int64x2) archsimd.Int64x2, want func(_, _ []int64) []int64) { - n := 2 - t.Helper() - forSlicePair(t, int64s, n, func(x, y []int64) bool { - t.Helper() - a := archsimd.LoadInt64x2(x) - b := archsimd.LoadInt64x2(y) - g := make([]int64, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testUint8x16Binary tests the simd binary method f against the expected behavior generated by want -func testUint8x16Binary(t *testing.T, f func(_, _ archsimd.Uint8x16) archsimd.Uint8x16, want func(_, _ []uint8) []uint8) { - n := 16 - t.Helper() - forSlicePair(t, uint8s, n, func(x, y []uint8) bool { - t.Helper() - a := archsimd.LoadUint8x16(x) - b := archsimd.LoadUint8x16(y) - g := make([]uint8, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testUint16x8Binary tests the simd binary method f against the expected behavior generated by want -func testUint16x8Binary(t *testing.T, f func(_, _ archsimd.Uint16x8) archsimd.Uint16x8, want func(_, _ []uint16) []uint16) { - n := 8 - t.Helper() - forSlicePair(t, uint16s, n, func(x, y []uint16) bool { - t.Helper() - a := archsimd.LoadUint16x8(x) - b := archsimd.LoadUint16x8(y) - g := make([]uint16, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testUint32x4Binary tests the simd binary method f against the expected behavior generated by want -func testUint32x4Binary(t *testing.T, f func(_, _ archsimd.Uint32x4) archsimd.Uint32x4, want func(_, _ []uint32) []uint32) { - n := 4 - t.Helper() - forSlicePair(t, uint32s, n, func(x, y []uint32) bool { - t.Helper() - a := archsimd.LoadUint32x4(x) - b := archsimd.LoadUint32x4(y) - g := make([]uint32, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testUint64x2Binary tests the simd binary method f against the expected behavior generated by want -func testUint64x2Binary(t *testing.T, f func(_, _ archsimd.Uint64x2) archsimd.Uint64x2, want func(_, _ []uint64) []uint64) { - n := 2 - t.Helper() - forSlicePair(t, uint64s, n, func(x, y []uint64) bool { - t.Helper() - a := archsimd.LoadUint64x2(x) - b := archsimd.LoadUint64x2(y) - g := make([]uint64, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testFloat32x4Binary tests the simd binary method f against the expected behavior generated by want -func testFloat32x4Binary(t *testing.T, f func(_, _ archsimd.Float32x4) archsimd.Float32x4, want func(_, _ []float32) []float32) { - n := 4 - t.Helper() - forSlicePair(t, float32s, n, func(x, y []float32) bool { - t.Helper() - a := archsimd.LoadFloat32x4(x) - b := archsimd.LoadFloat32x4(y) - g := make([]float32, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testFloat64x2Binary tests the simd binary method f against the expected behavior generated by want -func testFloat64x2Binary(t *testing.T, f func(_, _ archsimd.Float64x2) archsimd.Float64x2, want func(_, _ []float64) []float64) { - n := 2 - t.Helper() - forSlicePair(t, float64s, n, func(x, y []float64) bool { - t.Helper() - a := archsimd.LoadFloat64x2(x) - b := archsimd.LoadFloat64x2(y) - g := make([]float64, n) - f(a, b).Store(g) - w := want(x, y) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -}
diff --git a/src/simd/archsimd/internal/simd_test/arm64_binary_test.go b/src/simd/archsimd/internal/simd_test/arm64_binary_test.go index a1d2c55..83a1182 100644 --- a/src/simd/archsimd/internal/simd_test/arm64_binary_test.go +++ b/src/simd/archsimd/internal/simd_test/arm64_binary_test.go
@@ -11,78 +11,6 @@ "testing" ) -func TestAdd(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Add, addSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Add, addSlice[float64]) - - testInt8x16Binary(t, archsimd.Int8x16.Add, addSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Add, addSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Add, addSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Add, addSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Add, addSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Add, addSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Add, addSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Add, addSlice[uint64]) -} - -func TestMul(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Mul, mulSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Mul, mulSlice[float64]) - - testInt8x16Binary(t, archsimd.Int8x16.Mul, mulSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Mul, mulSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Mul, mulSlice[int32]) - - testUint8x16Binary(t, archsimd.Uint8x16.Mul, mulSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Mul, mulSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Mul, mulSlice[uint32]) -} - -func TestSub(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Sub, subSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Sub, subSlice[float64]) - - testInt8x16Binary(t, archsimd.Int8x16.Sub, subSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Sub, subSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Sub, subSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Sub, subSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Sub, subSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Sub, subSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Sub, subSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Sub, subSlice[uint64]) -} - -func TestDiv(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Div, divSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Div, divSlice[float64]) -} - -func TestMax(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Max, maxSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Max, maxSlice[float64]) - - testInt8x16Binary(t, archsimd.Int8x16.Max, maxSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Max, maxSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Max, maxSlice[int32]) - testUint8x16Binary(t, archsimd.Uint8x16.Max, maxSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Max, maxSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Max, maxSlice[uint32]) -} - -func TestMin(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Min, minSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Min, minSlice[float64]) - - testInt8x16Binary(t, archsimd.Int8x16.Min, minSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Min, minSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Min, minSlice[int32]) - testUint8x16Binary(t, archsimd.Uint8x16.Min, minSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Min, minSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Min, minSlice[uint32]) -} - func TestConcatEven(t *testing.T) { testInt8x16Binary(t, archsimd.Int8x16.ConcatEven, deinterleaveSlice[int8](128, false)) testInt16x8Binary(t, archsimd.Int16x8.ConcatEven, deinterleaveSlice[int16](128, false)) @@ -148,189 +76,3 @@ testUint32x4Binary(t, archsimd.Uint32x4.InterleaveHi, interleaveSlice[uint32](128, true)) testUint64x2Binary(t, archsimd.Uint64x2.InterleaveHi, interleaveSlice[uint64](128, true)) } - -func TestGetElem(t *testing.T) { - // Int8x16 - { - a := []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - v := archsimd.LoadInt8x16(a) - if e := v.GetElem(2); e != a[2] { - t.Errorf("Int8x16.GetElem(2) = %d, want %d", e, a[2]) - } - } - // Int16x8 - { - a := []int16{10, 20, 30, 40, 50, 60, 70, 80} - v := archsimd.LoadInt16x8(a) - if e := v.GetElem(3); e != a[3] { - t.Errorf("Int16x8.GetElem(3) = %d, want %d", e, a[3]) - } - } - // Int32x4 - { - a := []int32{100, 200, 300, 400} - v := archsimd.LoadInt32x4(a) - if e := v.GetElem(1); e != a[1] { - t.Errorf("Int32x4.GetElem(1) = %d, want %d", e, a[1]) - } - } - // Int64x2 - { - a := []int64{1000, 2000} - v := archsimd.LoadInt64x2(a) - if e := v.GetElem(0); e != a[0] { - t.Errorf("Int64x2.GetElem(0) = %d, want %d", e, a[0]) - } - } - // Uint8x16 - { - a := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - v := archsimd.LoadUint8x16(a) - if e := v.GetElem(5); e != a[5] { - t.Errorf("Uint8x16.GetElem(5) = %d, want %d", e, a[5]) - } - } - // Uint16x8 - { - a := []uint16{100, 200, 300, 400, 500, 600, 700, 800} - v := archsimd.LoadUint16x8(a) - if e := v.GetElem(7); e != a[7] { - t.Errorf("Uint16x8.GetElem(7) = %d, want %d", e, a[7]) - } - } - // Uint32x4 - { - a := []uint32{1000, 2000, 3000, 4000} - v := archsimd.LoadUint32x4(a) - if e := v.GetElem(2); e != a[2] { - t.Errorf("Uint32x4.GetElem(2) = %d, want %d", e, a[2]) - } - } - // Uint64x2 - { - a := []uint64{10000, 20000} - v := archsimd.LoadUint64x2(a) - if e := v.GetElem(1); e != a[1] { - t.Errorf("Uint64x2.GetElem(1) = %d, want %d", e, a[1]) - } - } - // Float32x4 - { - a := []float32{1.0, 2.0, 3.0, 4.0} - v := archsimd.LoadFloat32x4(a) - if e := v.GetElem(3); e != a[3] { - t.Errorf("Float32x4.GetElem(3) = %f, want %f", e, a[3]) - } - } - // Float64x2 - { - a := []float64{10.5, 20.5} - v := archsimd.LoadFloat64x2(a) - if e := v.GetElem(0); e != a[0] { - t.Errorf("Float64x2.GetElem(0) = %f, want %f", e, a[0]) - } - } -} - -func TestSetElem(t *testing.T) { - // Int8x16 - { - a := []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - v := archsimd.LoadInt8x16(a) - v = v.SetElem(3, int8(99)) - a[3] = 99 - b := make([]int8, 16) - v.Store(b) - checkSlices(t, b, a) - } - // Int16x8 - { - a := []int16{10, 20, 30, 40, 50, 60, 70, 80} - v := archsimd.LoadInt16x8(a) - v = v.SetElem(5, int16(123)) - a[5] = 123 - b := make([]int16, 8) - v.Store(b) - checkSlices(t, b, a) - } - // Int32x4 - { - a := []int32{100, 200, 300, 400} - v := archsimd.LoadInt32x4(a) - v = v.SetElem(2, int32(999)) - a[2] = 999 - b := make([]int32, 4) - v.Store(b) - checkSlices(t, b, a) - } - // Int64x2 - { - a := []int64{1000, 2000} - v := archsimd.LoadInt64x2(a) - v = v.SetElem(1, int64(5555)) - a[1] = 5555 - b := make([]int64, 2) - v.Store(b) - checkSlices(t, b, a) - } - // Uint8x16 - { - a := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} - v := archsimd.LoadUint8x16(a) - v = v.SetElem(7, uint8(200)) - a[7] = 200 - b := make([]uint8, 16) - v.Store(b) - checkSlices(t, b, a) - } - // Uint16x8 - { - a := []uint16{100, 200, 300, 400, 500, 600, 700, 800} - v := archsimd.LoadUint16x8(a) - v = v.SetElem(0, uint16(1111)) - a[0] = 1111 - b := make([]uint16, 8) - v.Store(b) - checkSlices(t, b, a) - } - // Uint32x4 - { - a := []uint32{1000, 2000, 3000, 4000} - v := archsimd.LoadUint32x4(a) - v = v.SetElem(3, uint32(9999)) - a[3] = 9999 - b := make([]uint32, 4) - v.Store(b) - checkSlices(t, b, a) - } - // Uint64x2 - { - a := []uint64{10000, 20000} - v := archsimd.LoadUint64x2(a) - v = v.SetElem(0, uint64(55555)) - a[0] = 55555 - b := make([]uint64, 2) - v.Store(b) - checkSlices(t, b, a) - } - // Float32x4 - { - a := []float32{1.0, 2.0, 3.0, 4.0} - v := archsimd.LoadFloat32x4(a) - v = v.SetElem(1, float32(42.5)) - a[1] = 42.5 - b := make([]float32, 4) - v.Store(b) - checkSlices(t, b, a) - } - // Float64x2 - { - a := []float64{10.5, 20.5} - v := archsimd.LoadFloat64x2(a) - v = v.SetElem(0, float64(99.9)) - a[0] = 99.9 - b := make([]float64, 2) - v.Store(b) - checkSlices(t, b, a) - } -}
diff --git a/src/simd/archsimd/internal/simd_test/arm64_bitwise_test.go b/src/simd/archsimd/internal/simd_test/arm64_bitwise_test.go index c0b5522..f431c10 100644 --- a/src/simd/archsimd/internal/simd_test/arm64_bitwise_test.go +++ b/src/simd/archsimd/internal/simd_test/arm64_bitwise_test.go
@@ -11,54 +11,6 @@ "testing" ) -func TestAnd(t *testing.T) { - testInt8x16Binary(t, archsimd.Int8x16.And, andSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.And, andSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.And, andSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.And, andSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.And, andSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.And, andSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.And, andSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.And, andSlice[uint64]) -} - -func TestOr(t *testing.T) { - testInt8x16Binary(t, archsimd.Int8x16.Or, orSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Or, orSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Or, orSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Or, orSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Or, orSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Or, orSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Or, orSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Or, orSlice[uint64]) -} - -func TestXor(t *testing.T) { - testInt8x16Binary(t, archsimd.Int8x16.Xor, xorSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.Xor, xorSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Xor, xorSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Xor, xorSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Xor, xorSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.Xor, xorSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Xor, xorSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Xor, xorSlice[uint64]) -} - -func TestAndNot(t *testing.T) { - testInt8x16Binary(t, archsimd.Int8x16.AndNot, andNotSlice[int8]) - testInt16x8Binary(t, archsimd.Int16x8.AndNot, andNotSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.AndNot, andNotSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.AndNot, andNotSlice[int64]) - - testUint8x16Binary(t, archsimd.Uint8x16.AndNot, andNotSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.AndNot, andNotSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.AndNot, andNotSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.AndNot, andNotSlice[uint64]) -} - func TestOrNot(t *testing.T) { testInt8x16Binary(t, archsimd.Int8x16.OrNot, orNotSlice[int8]) testInt16x8Binary(t, archsimd.Int16x8.OrNot, orNotSlice[int16]) @@ -70,15 +22,3 @@ testUint32x4Binary(t, archsimd.Uint32x4.OrNot, orNotSlice[uint32]) testUint64x2Binary(t, archsimd.Uint64x2.OrNot, orNotSlice[uint64]) } - -func TestNot(t *testing.T) { - testInt8x16Unary(t, archsimd.Int8x16.Not, notSlice[int8]) - testInt16x8Unary(t, archsimd.Int16x8.Not, notSlice[int16]) - testInt32x4Unary(t, archsimd.Int32x4.Not, notSlice[int32]) - testInt64x2Unary(t, archsimd.Int64x2.Not, notSlice[int64]) - - testUint8x16Unary(t, archsimd.Uint8x16.Not, notSlice[uint8]) - testUint16x8Unary(t, archsimd.Uint16x8.Not, notSlice[uint16]) - testUint32x4Unary(t, archsimd.Uint32x4.Not, notSlice[uint32]) - testUint64x2Unary(t, archsimd.Uint64x2.Not, notSlice[uint64]) -}
diff --git a/src/simd/archsimd/internal/simd_test/arm64_compare_helpers_test.go b/src/simd/archsimd/internal/simd_test/arm64_compare_helpers_test.go deleted file mode 100644 index a7a90b7..0000000 --- a/src/simd/archsimd/internal/simd_test/arm64_compare_helpers_test.go +++ /dev/null
@@ -1,164 +0,0 @@ -// Code generated by 'tmplgen'; DO NOT EDIT. - -//go:build goexperiment.simd && arm64 - -// This file contains functions testing simd methods that compare two operands. -// Each function in this file is specialized for a -// particular simd type <BaseType><Width>x<Count>. - -package simd_test - -import ( - "simd/archsimd" - "testing" -) - -// testInt8x16Compare tests the simd comparison method f against the expected behavior generated by want -func testInt8x16Compare(t *testing.T, f func(_, _ archsimd.Int8x16) archsimd.Mask8x16, want func(_, _ []int8) []int64) { - n := 16 - t.Helper() - forSlicePair(t, int8s, n, func(x, y []int8) bool { - t.Helper() - a := archsimd.LoadInt8x16(x) - b := archsimd.LoadInt8x16(y) - g := make([]int8, n) - f(a, b).ToInt8x16().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Int16x8) archsimd.Mask16x8, want func(_, _ []int16) []int64) { - n := 8 - t.Helper() - forSlicePair(t, int16s, n, func(x, y []int16) bool { - t.Helper() - a := archsimd.LoadInt16x8(x) - b := archsimd.LoadInt16x8(y) - g := make([]int16, n) - f(a, b).ToInt16x8().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Int32x4) archsimd.Mask32x4, want func(_, _ []int32) []int64) { - n := 4 - t.Helper() - forSlicePair(t, int32s, n, func(x, y []int32) bool { - t.Helper() - a := archsimd.LoadInt32x4(x) - b := archsimd.LoadInt32x4(y) - g := make([]int32, n) - f(a, b).ToInt32x4().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Int64x2) archsimd.Mask64x2, want func(_, _ []int64) []int64) { - n := 2 - t.Helper() - forSlicePair(t, int64s, n, func(x, y []int64) bool { - t.Helper() - a := archsimd.LoadInt64x2(x) - b := archsimd.LoadInt64x2(y) - g := make([]int64, n) - f(a, b).ToInt64x2().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testUint8x16Compare tests the simd comparison method f against the expected behavior generated by want -func testUint8x16Compare(t *testing.T, f func(_, _ archsimd.Uint8x16) archsimd.Mask8x16, want func(_, _ []uint8) []int64) { - n := 16 - t.Helper() - forSlicePair(t, uint8s, n, func(x, y []uint8) bool { - t.Helper() - a := archsimd.LoadUint8x16(x) - b := archsimd.LoadUint8x16(y) - g := make([]int8, n) - f(a, b).ToInt8x16().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Uint16x8) archsimd.Mask16x8, want func(_, _ []uint16) []int64) { - n := 8 - t.Helper() - forSlicePair(t, uint16s, n, func(x, y []uint16) bool { - t.Helper() - a := archsimd.LoadUint16x8(x) - b := archsimd.LoadUint16x8(y) - g := make([]int16, n) - f(a, b).ToInt16x8().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Uint32x4) archsimd.Mask32x4, want func(_, _ []uint32) []int64) { - n := 4 - t.Helper() - forSlicePair(t, uint32s, n, func(x, y []uint32) bool { - t.Helper() - a := archsimd.LoadUint32x4(x) - b := archsimd.LoadUint32x4(y) - g := make([]int32, n) - f(a, b).ToInt32x4().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, 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(_, _ archsimd.Uint64x2) archsimd.Mask64x2, want func(_, _ []uint64) []int64) { - n := 2 - t.Helper() - forSlicePair(t, uint64s, n, func(x, y []uint64) bool { - t.Helper() - a := archsimd.LoadUint64x2(x) - b := archsimd.LoadUint64x2(y) - g := make([]int64, n) - f(a, b).ToInt64x2().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testFloat32x4Compare tests the simd comparison method f against the expected behavior generated by want -func testFloat32x4Compare(t *testing.T, f func(_, _ archsimd.Float32x4) archsimd.Mask32x4, want func(_, _ []float32) []int64) { - n := 4 - t.Helper() - forSlicePair(t, float32s, n, func(x, y []float32) bool { - t.Helper() - a := archsimd.LoadFloat32x4(x) - b := archsimd.LoadFloat32x4(y) - g := make([]int32, n) - f(a, b).ToInt32x4().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -} - -// testFloat64x2Compare tests the simd comparison method f against the expected behavior generated by want -func testFloat64x2Compare(t *testing.T, f func(_, _ archsimd.Float64x2) archsimd.Mask64x2, want func(_, _ []float64) []int64) { - n := 2 - t.Helper() - forSlicePair(t, float64s, n, func(x, y []float64) bool { - t.Helper() - a := archsimd.LoadFloat64x2(x) - b := archsimd.LoadFloat64x2(y) - g := make([]int64, n) - f(a, b).ToInt64x2().Store(g) - w := want(x, y) - return checkSlicesLogInput(t, s64(g), w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y) }) - }) -}
diff --git a/src/simd/archsimd/internal/simd_test/arm64_compare_test.go b/src/simd/archsimd/internal/simd_test/arm64_compare_test.go index e9a9eff..ad1c55b 100644 --- a/src/simd/archsimd/internal/simd_test/arm64_compare_test.go +++ b/src/simd/archsimd/internal/simd_test/arm64_compare_test.go
@@ -11,108 +11,6 @@ "testing" ) -// --- Equal (hardware: CMEQ / FCMEQ) --- - -func TestEqual(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.Equal, equalSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.Equal, equalSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Equal, equalSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Equal, equalSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.Equal, equalSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.Equal, equalSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Equal, equalSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Equal, equalSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.Equal, equalSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Equal, equalSlice[float64]) -} - -// --- Greater (hardware: CMGT/CMHI for signed/unsigned, FCMGT for float) --- - -func TestGreater(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.Greater, greaterSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.Greater, greaterSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Greater, greaterSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Greater, greaterSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.Greater, greaterSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.Greater, greaterSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Greater, greaterSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Greater, greaterSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.Greater, greaterSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Greater, greaterSlice[float64]) -} - -// --- GreaterEqual (hardware: CMGE/CMHS for signed/unsigned, FCMGE for float) --- - -func TestGreaterEqual(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.GreaterEqual, greaterEqualSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.GreaterEqual, greaterEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.GreaterEqual, greaterEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.GreaterEqual, greaterEqualSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.GreaterEqual, greaterEqualSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.GreaterEqual, greaterEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.GreaterEqual, greaterEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.GreaterEqual, greaterEqualSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.GreaterEqual, greaterEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.GreaterEqual, greaterEqualSlice[float64]) -} - -// --- Less (derived: y.Greater(x)) --- - -func TestLess(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.Less, lessSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.Less, lessSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Less, lessSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Less, lessSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.Less, lessSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.Less, lessSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Less, lessSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Less, lessSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.Less, lessSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Less, lessSlice[float64]) -} - -// --- LessEqual (derived: y.GreaterEqual(x)) --- - -func TestLessEqual(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.LessEqual, lessEqualSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.LessEqual, lessEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.LessEqual, lessEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.LessEqual, lessEqualSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.LessEqual, lessEqualSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.LessEqual, lessEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.LessEqual, lessEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.LessEqual, lessEqualSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.LessEqual, lessEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.LessEqual, lessEqualSlice[float64]) -} - -// --- NotEqual (derived: Equal().Not()) --- - -func TestNotEqual(t *testing.T) { - testInt8x16Compare(t, archsimd.Int8x16.NotEqual, notEqualSlice[int8]) - testInt16x8Compare(t, archsimd.Int16x8.NotEqual, notEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.NotEqual, notEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.NotEqual, notEqualSlice[int64]) - - testUint8x16Compare(t, archsimd.Uint8x16.NotEqual, notEqualSlice[uint8]) - testUint16x8Compare(t, archsimd.Uint16x8.NotEqual, notEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.NotEqual, notEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.NotEqual, notEqualSlice[uint64]) - - testFloat32x4Compare(t, archsimd.Float32x4.NotEqual, notEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.NotEqual, notEqualSlice[float64]) -} - // --- Masked: zero elements where mask is false --- func TestMasked(t *testing.T) {
diff --git a/src/simd/archsimd/internal/simd_test/arm64_unary_helpers_test.go b/src/simd/archsimd/internal/simd_test/arm64_unary_helpers_test.go index 78d1db9..648d1d9 100644 --- a/src/simd/archsimd/internal/simd_test/arm64_unary_helpers_test.go +++ b/src/simd/archsimd/internal/simd_test/arm64_unary_helpers_test.go
@@ -1412,143 +1412,3 @@ return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) }) } - -// testInt8x16Unary tests the simd unary method f against the expected behavior generated by want -func testInt8x16Unary(t *testing.T, f func(_ archsimd.Int8x16) archsimd.Int8x16, want func(_ []int8) []int8) { - n := 16 - t.Helper() - forSlice(t, int8s, n, func(x []int8) bool { - t.Helper() - a := archsimd.LoadInt8x16(x) - g := make([]int8, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testInt16x8Unary tests the simd unary method f against the expected behavior generated by want -func testInt16x8Unary(t *testing.T, f func(_ archsimd.Int16x8) archsimd.Int16x8, want func(_ []int16) []int16) { - n := 8 - t.Helper() - forSlice(t, int16s, n, func(x []int16) bool { - t.Helper() - a := archsimd.LoadInt16x8(x) - g := make([]int16, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testInt32x4Unary tests the simd unary method f against the expected behavior generated by want -func testInt32x4Unary(t *testing.T, f func(_ archsimd.Int32x4) archsimd.Int32x4, want func(_ []int32) []int32) { - n := 4 - t.Helper() - forSlice(t, int32s, n, func(x []int32) bool { - t.Helper() - a := archsimd.LoadInt32x4(x) - g := make([]int32, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testInt64x2Unary tests the simd unary method f against the expected behavior generated by want -func testInt64x2Unary(t *testing.T, f func(_ archsimd.Int64x2) archsimd.Int64x2, want func(_ []int64) []int64) { - n := 2 - t.Helper() - forSlice(t, int64s, n, func(x []int64) bool { - t.Helper() - a := archsimd.LoadInt64x2(x) - g := make([]int64, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testUint8x16Unary tests the simd unary method f against the expected behavior generated by want -func testUint8x16Unary(t *testing.T, f func(_ archsimd.Uint8x16) archsimd.Uint8x16, want func(_ []uint8) []uint8) { - n := 16 - t.Helper() - forSlice(t, uint8s, n, func(x []uint8) bool { - t.Helper() - a := archsimd.LoadUint8x16(x) - g := make([]uint8, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testUint16x8Unary tests the simd unary method f against the expected behavior generated by want -func testUint16x8Unary(t *testing.T, f func(_ archsimd.Uint16x8) archsimd.Uint16x8, want func(_ []uint16) []uint16) { - n := 8 - t.Helper() - forSlice(t, uint16s, n, func(x []uint16) bool { - t.Helper() - a := archsimd.LoadUint16x8(x) - g := make([]uint16, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testUint32x4Unary tests the simd unary method f against the expected behavior generated by want -func testUint32x4Unary(t *testing.T, f func(_ archsimd.Uint32x4) archsimd.Uint32x4, want func(_ []uint32) []uint32) { - n := 4 - t.Helper() - forSlice(t, uint32s, n, func(x []uint32) bool { - t.Helper() - a := archsimd.LoadUint32x4(x) - g := make([]uint32, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testUint64x2Unary tests the simd unary method f against the expected behavior generated by want -func testUint64x2Unary(t *testing.T, f func(_ archsimd.Uint64x2) archsimd.Uint64x2, want func(_ []uint64) []uint64) { - n := 2 - t.Helper() - forSlice(t, uint64s, n, func(x []uint64) bool { - t.Helper() - a := archsimd.LoadUint64x2(x) - g := make([]uint64, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testFloat32x4Unary tests the simd unary method f against the expected behavior generated by want -func testFloat32x4Unary(t *testing.T, f func(_ archsimd.Float32x4) archsimd.Float32x4, want func(_ []float32) []float32) { - n := 4 - t.Helper() - forSlice(t, float32s, n, func(x []float32) bool { - t.Helper() - a := archsimd.LoadFloat32x4(x) - g := make([]float32, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -} - -// testFloat64x2Unary tests the simd unary method f against the expected behavior generated by want -func testFloat64x2Unary(t *testing.T, f func(_ archsimd.Float64x2) archsimd.Float64x2, want func(_ []float64) []float64) { - n := 2 - t.Helper() - forSlice(t, float64s, n, func(x []float64) bool { - t.Helper() - a := archsimd.LoadFloat64x2(x) - g := make([]float64, n) - f(a).Store(g) - w := want(x) - return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x) }) - }) -}
diff --git a/src/simd/archsimd/internal/simd_test/arm64_unary_test.go b/src/simd/archsimd/internal/simd_test/arm64_unary_test.go deleted file mode 100644 index ec1c809..0000000 --- a/src/simd/archsimd/internal/simd_test/arm64_unary_test.go +++ /dev/null
@@ -1,37 +0,0 @@ -// Copyright 2026 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build goexperiment.simd && arm64 - -package simd_test - -import ( - "simd/archsimd" - "testing" -) - -func TestSqrt(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Sqrt, sqrtSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Sqrt, sqrtSlice[float64]) -} - -func TestRound(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Round, roundSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Round, roundSlice[float64]) -} - -func TestFloor(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Floor, floorSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Floor, floorSlice[float64]) -} - -func TestCeil(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Ceil, ceilSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Ceil, ceilSlice[float64]) -} - -func TestTrunc(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Trunc, truncSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Trunc, truncSlice[float64]) -}
diff --git a/src/simd/archsimd/internal/simd_test/binary_128_test.go b/src/simd/archsimd/internal/simd_test/binary_128_test.go index 79360e6..e5c4984 100644 --- a/src/simd/archsimd/internal/simd_test/binary_128_test.go +++ b/src/simd/archsimd/internal/simd_test/binary_128_test.go
@@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.simd && wasm +//go:build goexperiment.simd && (amd64 || wasm || arm64) package simd_test import ( + "runtime" "simd/archsimd" "testing" ) @@ -42,35 +43,33 @@ } func TestMax(t *testing.T) { + if runtime.GOARCH != "amd64" { + // skip in AMD64 as NaN behavior is different + testFloat32x4Binary(t, archsimd.Float32x4.Max, maxSlice[float32]) + testFloat64x2Binary(t, archsimd.Float64x2.Max, maxSlice[float64]) + } + testInt8x16Binary(t, archsimd.Int8x16.Max, maxSlice[int8]) testInt16x8Binary(t, archsimd.Int16x8.Max, maxSlice[int16]) testInt32x4Binary(t, archsimd.Int32x4.Max, maxSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Max, maxSlice[int64]) - - testInt8x16Binary(t, archsimd.Int8x16.Max, maxSlice[int8]) - + testUint8x16Binary(t, archsimd.Uint8x16.Max, maxSlice[uint8]) testUint16x8Binary(t, archsimd.Uint16x8.Max, maxSlice[uint16]) testUint32x4Binary(t, archsimd.Uint32x4.Max, maxSlice[uint32]) - - testUint64x2Binary(t, archsimd.Uint64x2.Max, maxSlice[uint64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Max, maxSlice[uint8]) } func TestMin(t *testing.T) { + if runtime.GOARCH != "amd64" { + // skip in AMD64 as NaN behavior is different + testFloat32x4Binary(t, archsimd.Float32x4.Min, minSlice[float32]) + testFloat64x2Binary(t, archsimd.Float64x2.Min, minSlice[float64]) + } + testInt8x16Binary(t, archsimd.Int8x16.Min, minSlice[int8]) testInt16x8Binary(t, archsimd.Int16x8.Min, minSlice[int16]) testInt32x4Binary(t, archsimd.Int32x4.Min, minSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Min, minSlice[int64]) - - testInt8x16Binary(t, archsimd.Int8x16.Min, minSlice[int8]) - + testUint8x16Binary(t, archsimd.Uint8x16.Min, minSlice[uint8]) testUint16x8Binary(t, archsimd.Uint16x8.Min, minSlice[uint16]) testUint32x4Binary(t, archsimd.Uint32x4.Min, minSlice[uint32]) - - testUint64x2Binary(t, archsimd.Uint64x2.Min, minSlice[uint64]) - - testUint8x16Binary(t, archsimd.Uint8x16.Min, minSlice[uint8]) } func TestAnd(t *testing.T) { @@ -129,13 +128,195 @@ testUint8x16Binary(t, archsimd.Uint8x16.Mul, mulSlice[uint8]) testInt16x8Binary(t, archsimd.Int16x8.Mul, mulSlice[int16]) testInt32x4Binary(t, archsimd.Int32x4.Mul, mulSlice[int32]) - - if archsimd.X86.AVX512() { - testInt64x2Binary(t, archsimd.Int64x2.Mul, mulSlice[int64]) - } } func TestDiv(t *testing.T) { testFloat32x4Binary(t, archsimd.Float32x4.Div, divSlice[float32]) testFloat64x2Binary(t, archsimd.Float64x2.Div, divSlice[float64]) } + +func TestGetElem(t *testing.T) { + // Int8x16 + { + a := []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + v := archsimd.LoadInt8x16(a) + if e := v.GetElem(2); e != a[2] { + t.Errorf("Int8x16.GetElem(2) = %d, want %d", e, a[2]) + } + } + // Int16x8 + { + a := []int16{10, 20, 30, 40, 50, 60, 70, 80} + v := archsimd.LoadInt16x8(a) + if e := v.GetElem(3); e != a[3] { + t.Errorf("Int16x8.GetElem(3) = %d, want %d", e, a[3]) + } + } + // Int32x4 + { + a := []int32{100, 200, 300, 400} + v := archsimd.LoadInt32x4(a) + if e := v.GetElem(1); e != a[1] { + t.Errorf("Int32x4.GetElem(1) = %d, want %d", e, a[1]) + } + } + // Int64x2 + { + a := []int64{1000, 2000} + v := archsimd.LoadInt64x2(a) + if e := v.GetElem(0); e != a[0] { + t.Errorf("Int64x2.GetElem(0) = %d, want %d", e, a[0]) + } + } + // Uint8x16 + { + a := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + v := archsimd.LoadUint8x16(a) + if e := v.GetElem(5); e != a[5] { + t.Errorf("Uint8x16.GetElem(5) = %d, want %d", e, a[5]) + } + } + // Uint16x8 + { + a := []uint16{100, 200, 300, 400, 500, 600, 700, 800} + v := archsimd.LoadUint16x8(a) + if e := v.GetElem(7); e != a[7] { + t.Errorf("Uint16x8.GetElem(7) = %d, want %d", e, a[7]) + } + } + // Uint32x4 + { + a := []uint32{1000, 2000, 3000, 4000} + v := archsimd.LoadUint32x4(a) + if e := v.GetElem(2); e != a[2] { + t.Errorf("Uint32x4.GetElem(2) = %d, want %d", e, a[2]) + } + } + // Uint64x2 + { + a := []uint64{10000, 20000} + v := archsimd.LoadUint64x2(a) + if e := v.GetElem(1); e != a[1] { + t.Errorf("Uint64x2.GetElem(1) = %d, want %d", e, a[1]) + } + } + // Float32x4 + { + a := []float32{1.0, 2.0, 3.0, 4.0} + v := archsimd.LoadFloat32x4(a) + if e := v.GetElem(3); e != a[3] { + t.Errorf("Float32x4.GetElem(3) = %f, want %f", e, a[3]) + } + } + // Float64x2 + { + a := []float64{10.5, 20.5} + v := archsimd.LoadFloat64x2(a) + if e := v.GetElem(0); e != a[0] { + t.Errorf("Float64x2.GetElem(0) = %f, want %f", e, a[0]) + } + } +} + +func TestSetElem(t *testing.T) { + // Int8x16 + { + a := []int8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + v := archsimd.LoadInt8x16(a) + v = v.SetElem(3, int8(99)) + a[3] = 99 + b := make([]int8, 16) + v.Store(b) + checkSlices(t, b, a) + } + // Int16x8 + { + a := []int16{10, 20, 30, 40, 50, 60, 70, 80} + v := archsimd.LoadInt16x8(a) + v = v.SetElem(5, int16(123)) + a[5] = 123 + b := make([]int16, 8) + v.Store(b) + checkSlices(t, b, a) + } + // Int32x4 + { + a := []int32{100, 200, 300, 400} + v := archsimd.LoadInt32x4(a) + v = v.SetElem(2, int32(999)) + a[2] = 999 + b := make([]int32, 4) + v.Store(b) + checkSlices(t, b, a) + } + // Int64x2 + { + a := []int64{1000, 2000} + v := archsimd.LoadInt64x2(a) + v = v.SetElem(1, int64(5555)) + a[1] = 5555 + b := make([]int64, 2) + v.Store(b) + checkSlices(t, b, a) + } + // Uint8x16 + { + a := []uint8{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + v := archsimd.LoadUint8x16(a) + v = v.SetElem(7, uint8(200)) + a[7] = 200 + b := make([]uint8, 16) + v.Store(b) + checkSlices(t, b, a) + } + // Uint16x8 + { + a := []uint16{100, 200, 300, 400, 500, 600, 700, 800} + v := archsimd.LoadUint16x8(a) + v = v.SetElem(0, uint16(1111)) + a[0] = 1111 + b := make([]uint16, 8) + v.Store(b) + checkSlices(t, b, a) + } + // Uint32x4 + { + a := []uint32{1000, 2000, 3000, 4000} + v := archsimd.LoadUint32x4(a) + v = v.SetElem(3, uint32(9999)) + a[3] = 9999 + b := make([]uint32, 4) + v.Store(b) + checkSlices(t, b, a) + } + // Uint64x2 + { + a := []uint64{10000, 20000} + v := archsimd.LoadUint64x2(a) + v = v.SetElem(0, uint64(55555)) + a[0] = 55555 + b := make([]uint64, 2) + v.Store(b) + checkSlices(t, b, a) + } + // Float32x4 + { + a := []float32{1.0, 2.0, 3.0, 4.0} + v := archsimd.LoadFloat32x4(a) + v = v.SetElem(1, float32(42.5)) + a[1] = 42.5 + b := make([]float32, 4) + v.Store(b) + checkSlices(t, b, a) + } + // Float64x2 + { + a := []float64{10.5, 20.5} + v := archsimd.LoadFloat64x2(a) + v = v.SetElem(0, float64(99.9)) + a[0] = 99.9 + b := make([]float64, 2) + v.Store(b) + checkSlices(t, b, a) + } +}
diff --git a/src/simd/archsimd/internal/simd_test/binary_test.go b/src/simd/archsimd/internal/simd_test/binary_amd64_test.go similarity index 70% rename from src/simd/archsimd/internal/simd_test/binary_test.go rename to src/simd/archsimd/internal/simd_test/binary_amd64_test.go index 797a7af..412f7a3 100644 --- a/src/simd/archsimd/internal/simd_test/binary_test.go +++ b/src/simd/archsimd/internal/simd_test/binary_amd64_test.go
@@ -11,22 +11,10 @@ "testing" ) -func TestAdd(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Add, addSlice[float32]) +func TestAddAMD64(t *testing.T) { testFloat32x8Binary(t, archsimd.Float32x8.Add, addSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Add, addSlice[float64]) testFloat64x4Binary(t, archsimd.Float64x4.Add, addSlice[float64]) - testInt16x8Binary(t, archsimd.Int16x8.Add, addSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Add, addSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Add, addSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.Add, addSlice[int8]) - - testUint32x4Binary(t, archsimd.Uint32x4.Add, addSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Add, addSlice[uint64]) - testUint16x8Binary(t, archsimd.Uint16x8.Add, addSlice[uint16]) - testUint8x16Binary(t, archsimd.Uint8x16.Add, addSlice[uint8]) - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Add, addSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Add, addSlice[uint32]) @@ -55,17 +43,10 @@ } } -func TestSub(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Sub, subSlice[float32]) +func TestSubAMD64(t *testing.T) { testFloat32x8Binary(t, archsimd.Float32x8.Sub, subSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Sub, subSlice[float64]) testFloat64x4Binary(t, archsimd.Float64x4.Sub, subSlice[float64]) - testInt32x4Binary(t, archsimd.Int32x4.Sub, subSlice[int32]) - testInt16x8Binary(t, archsimd.Int16x8.Sub, subSlice[int16]) - testInt64x2Binary(t, archsimd.Int64x2.Sub, subSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.Sub, subSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Sub, subSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Sub, subSlice[int32]) @@ -73,11 +54,6 @@ testInt8x32Binary(t, archsimd.Int8x32.Sub, subSlice[int8]) } - testUint32x4Binary(t, archsimd.Uint32x4.Sub, subSlice[uint32]) - testUint16x8Binary(t, archsimd.Uint16x8.Sub, subSlice[uint16]) - testUint64x2Binary(t, archsimd.Uint64x2.Sub, subSlice[uint64]) - testUint8x16Binary(t, archsimd.Uint8x16.Sub, subSlice[uint8]) - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Sub, subSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Sub, subSlice[uint32]) @@ -99,53 +75,26 @@ } } -func TestMax(t *testing.T) { - // testFloat32x4Binary(t, archsimd.Float32x4.Max, maxSlice[float32]) // nan is wrong +func TestMaxAMD64(t *testing.T) { // testFloat32x8Binary(t, archsimd.Float32x8.Max, maxSlice[float32]) // nan is wrong - // testFloat64x2Binary(t, archsimd.Float64x2.Max, maxSlice[float64]) // nan is wrong // testFloat64x4Binary(t, archsimd.Float64x4.Max, maxSlice[float64]) // nan is wrong - testInt16x8Binary(t, archsimd.Int16x8.Max, maxSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Max, maxSlice[int32]) - if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Max, maxSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Max, maxSlice[int32]) - } - - if archsimd.X86.AVX512() { - testInt64x2Binary(t, archsimd.Int64x2.Max, maxSlice[int64]) - testInt64x4Binary(t, archsimd.Int64x4.Max, maxSlice[int64]) - } - - testInt8x16Binary(t, archsimd.Int8x16.Max, maxSlice[int8]) - - if archsimd.X86.AVX2() { testInt8x32Binary(t, archsimd.Int8x32.Max, maxSlice[int8]) - } - - testUint16x8Binary(t, archsimd.Uint16x8.Max, maxSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Max, maxSlice[uint32]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Max, maxSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Max, maxSlice[uint32]) - } - - if archsimd.X86.AVX512() { - testUint64x2Binary(t, archsimd.Uint64x2.Max, maxSlice[uint64]) - testUint64x4Binary(t, archsimd.Uint64x4.Max, maxSlice[uint64]) - } - - testUint8x16Binary(t, archsimd.Uint8x16.Max, maxSlice[uint8]) - - if archsimd.X86.AVX2() { testUint8x32Binary(t, archsimd.Uint8x32.Max, maxSlice[uint8]) } if archsimd.X86.AVX512() { // testFloat32x16Binary(t, archsimd.Float32x16.Max, maxSlice[float32]) // nan is wrong // testFloat64x8Binary(t, archsimd.Float64x8.Max, maxSlice[float64]) // nan is wrong + testInt64x2Binary(t, archsimd.Int64x2.Max, maxSlice[int64]) + testInt64x4Binary(t, archsimd.Int64x4.Max, maxSlice[int64]) + testUint64x2Binary(t, archsimd.Uint64x2.Max, maxSlice[uint64]) + testUint64x4Binary(t, archsimd.Uint64x4.Max, maxSlice[uint64]) testInt8x64Binary(t, archsimd.Int8x64.Max, maxSlice[int8]) testInt16x32Binary(t, archsimd.Int16x32.Max, maxSlice[int16]) testInt32x16Binary(t, archsimd.Int32x16.Max, maxSlice[int32]) @@ -157,53 +106,26 @@ } } -func TestMin(t *testing.T) { - // testFloat32x4Binary(t, archsimd.Float32x4.Min, minSlice[float32]) // nan is wrong +func TestMinAMD64(t *testing.T) { // testFloat32x8Binary(t, archsimd.Float32x8.Min, minSlice[float32]) // nan is wrong - // testFloat64x2Binary(t, archsimd.Float64x2.Min, minSlice[float64]) // nan is wrong // testFloat64x4Binary(t, archsimd.Float64x4.Min, minSlice[float64]) // nan is wrong - testInt16x8Binary(t, archsimd.Int16x8.Min, minSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Min, minSlice[int32]) - if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Min, minSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Min, minSlice[int32]) - } - - if archsimd.X86.AVX512() { - testInt64x2Binary(t, archsimd.Int64x2.Min, minSlice[int64]) - testInt64x4Binary(t, archsimd.Int64x4.Min, minSlice[int64]) - } - - testInt8x16Binary(t, archsimd.Int8x16.Min, minSlice[int8]) - - if archsimd.X86.AVX2() { testInt8x32Binary(t, archsimd.Int8x32.Min, minSlice[int8]) - } - - testUint16x8Binary(t, archsimd.Uint16x8.Min, minSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Min, minSlice[uint32]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Min, minSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Min, minSlice[uint32]) - } - - if archsimd.X86.AVX512() { - testUint64x2Binary(t, archsimd.Uint64x2.Min, minSlice[uint64]) - testUint64x4Binary(t, archsimd.Uint64x4.Min, minSlice[uint64]) - } - - testUint8x16Binary(t, archsimd.Uint8x16.Min, minSlice[uint8]) - - if archsimd.X86.AVX2() { testUint8x32Binary(t, archsimd.Uint8x32.Min, minSlice[uint8]) } if archsimd.X86.AVX512() { // testFloat32x16Binary(t, archsimd.Float32x16.Min, minSlice[float32]) // nan is wrong // testFloat64x8Binary(t, archsimd.Float64x8.Min, minSlice[float64]) // nan is wrong + testInt64x2Binary(t, archsimd.Int64x2.Min, minSlice[int64]) + testInt64x4Binary(t, archsimd.Int64x4.Min, minSlice[int64]) + testUint64x2Binary(t, archsimd.Uint64x2.Min, minSlice[uint64]) + testUint64x4Binary(t, archsimd.Uint64x4.Min, minSlice[uint64]) testInt8x64Binary(t, archsimd.Int8x64.Min, minSlice[int8]) testInt16x32Binary(t, archsimd.Int16x32.Min, minSlice[int16]) testInt32x16Binary(t, archsimd.Int32x16.Min, minSlice[int32]) @@ -215,25 +137,13 @@ } } -func TestAnd(t *testing.T) { - testInt16x8Binary(t, archsimd.Int16x8.And, andSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.And, andSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.And, andSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.And, andSlice[int8]) - +func TestAndAMD64(t *testing.T) { if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.And, andSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.And, andSlice[int32]) testInt64x4Binary(t, archsimd.Int64x4.And, andSlice[int64]) testInt8x32Binary(t, archsimd.Int8x32.And, andSlice[int8]) - } - testUint16x8Binary(t, archsimd.Uint16x8.And, andSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.And, andSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.And, andSlice[uint64]) - testUint8x16Binary(t, archsimd.Uint8x16.And, andSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.And, andSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.And, andSlice[uint32]) testUint64x4Binary(t, archsimd.Uint64x4.And, andSlice[uint64]) @@ -241,36 +151,24 @@ } if archsimd.X86.AVX512() { - // testInt8x64Binary(t, archsimd.Int8x64.And, andISlice[int8]) // missing - // testInt16x32Binary(t, archsimd.Int16x32.And, andISlice[int16]) // missing + testInt8x64Binary(t, archsimd.Int8x64.And, andSlice[int8]) + testInt16x32Binary(t, archsimd.Int16x32.And, andSlice[int16]) testInt32x16Binary(t, archsimd.Int32x16.And, andSlice[int32]) testInt64x8Binary(t, archsimd.Int64x8.And, andSlice[int64]) - // testUint8x64Binary(t, archsimd.Uint8x64.And, andISlice[uint8]) // missing - // testUint16x32Binary(t, archsimd.Uint16x32.And, andISlice[uint16]) // missing + testUint8x64Binary(t, archsimd.Uint8x64.And, andSlice[uint8]) + testUint16x32Binary(t, archsimd.Uint16x32.And, andSlice[uint16]) testUint32x16Binary(t, archsimd.Uint32x16.And, andSlice[uint32]) testUint64x8Binary(t, archsimd.Uint64x8.And, andSlice[uint64]) } } -func TestAndNot(t *testing.T) { - testInt16x8Binary(t, archsimd.Int16x8.AndNot, andNotSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.AndNot, andNotSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.AndNot, andNotSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.AndNot, andNotSlice[int8]) - +func TestAndNotAMD64(t *testing.T) { if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.AndNot, andNotSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.AndNot, andNotSlice[int32]) testInt64x4Binary(t, archsimd.Int64x4.AndNot, andNotSlice[int64]) testInt8x32Binary(t, archsimd.Int8x32.AndNot, andNotSlice[int8]) - } - testUint8x16Binary(t, archsimd.Uint8x16.AndNot, andNotSlice[uint8]) - testUint16x8Binary(t, archsimd.Uint16x8.AndNot, andNotSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.AndNot, andNotSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.AndNot, andNotSlice[uint64]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.AndNot, andNotSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.AndNot, andNotSlice[uint32]) testUint64x4Binary(t, archsimd.Uint64x4.AndNot, andNotSlice[uint64]) @@ -289,25 +187,13 @@ } } -func TestXor(t *testing.T) { - testInt16x8Binary(t, archsimd.Int16x8.Xor, xorSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Xor, xorSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Xor, xorSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.Xor, xorSlice[int8]) - +func TestXorAMD64(t *testing.T) { if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Xor, xorSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Xor, xorSlice[int32]) testInt64x4Binary(t, archsimd.Int64x4.Xor, xorSlice[int64]) testInt8x32Binary(t, archsimd.Int8x32.Xor, xorSlice[int8]) - } - testUint16x8Binary(t, archsimd.Uint16x8.Xor, xorSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Xor, xorSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Xor, xorSlice[uint64]) - testUint8x16Binary(t, archsimd.Uint8x16.Xor, xorSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Xor, xorSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Xor, xorSlice[uint32]) testUint64x4Binary(t, archsimd.Uint64x4.Xor, xorSlice[uint64]) @@ -315,36 +201,24 @@ } if archsimd.X86.AVX512() { - // testInt8x64Binary(t, archsimd.Int8x64.Xor, andISlice[int8]) // missing - // testInt16x32Binary(t, archsimd.Int16x32.Xor, andISlice[int16]) // missing + testInt8x64Binary(t, archsimd.Int8x64.Xor, xorSlice[int8]) + testInt16x32Binary(t, archsimd.Int16x32.Xor, xorSlice[int16]) testInt32x16Binary(t, archsimd.Int32x16.Xor, xorSlice[int32]) testInt64x8Binary(t, archsimd.Int64x8.Xor, xorSlice[int64]) - // testUint8x64Binary(t, archsimd.Uint8x64.Xor, andISlice[uint8]) // missing - // testUint16x32Binary(t, archsimd.Uint16x32.Xor, andISlice[uint16]) // missing + testUint8x64Binary(t, archsimd.Uint8x64.Xor, xorSlice[uint8]) + testUint16x32Binary(t, archsimd.Uint16x32.Xor, xorSlice[uint16]) testUint32x16Binary(t, archsimd.Uint32x16.Xor, xorSlice[uint32]) testUint64x8Binary(t, archsimd.Uint64x8.Xor, xorSlice[uint64]) } } -func TestOr(t *testing.T) { - testInt16x8Binary(t, archsimd.Int16x8.Or, orSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Or, orSlice[int32]) - testInt64x2Binary(t, archsimd.Int64x2.Or, orSlice[int64]) - testInt8x16Binary(t, archsimd.Int8x16.Or, orSlice[int8]) - +func TestOrAMD64(t *testing.T) { if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Or, orSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Or, orSlice[int32]) testInt64x4Binary(t, archsimd.Int64x4.Or, orSlice[int64]) testInt8x32Binary(t, archsimd.Int8x32.Or, orSlice[int8]) - } - testUint16x8Binary(t, archsimd.Uint16x8.Or, orSlice[uint16]) - testUint32x4Binary(t, archsimd.Uint32x4.Or, orSlice[uint32]) - testUint64x2Binary(t, archsimd.Uint64x2.Or, orSlice[uint64]) - testUint8x16Binary(t, archsimd.Uint8x16.Or, orSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Binary(t, archsimd.Uint16x16.Or, orSlice[uint16]) testUint32x8Binary(t, archsimd.Uint32x8.Or, orSlice[uint32]) testUint64x4Binary(t, archsimd.Uint64x4.Or, orSlice[uint64]) @@ -352,26 +226,21 @@ } if archsimd.X86.AVX512() { - // testInt8x64Binary(t, archsimd.Int8x64.Or, andISlice[int8]) // missing - // testInt16x32Binary(t, archsimd.Int16x32.Or, andISlice[int16]) // missing + testInt8x64Binary(t, archsimd.Int8x64.Or, orSlice[int8]) + testInt16x32Binary(t, archsimd.Int16x32.Or, orSlice[int16]) testInt32x16Binary(t, archsimd.Int32x16.Or, orSlice[int32]) testInt64x8Binary(t, archsimd.Int64x8.Or, orSlice[int64]) - // testUint8x64Binary(t, archsimd.Uint8x64.Or, andISlice[uint8]) // missing - // testUint16x32Binary(t, archsimd.Uint16x32.Or, andISlice[uint16]) // missing + testUint8x64Binary(t, archsimd.Uint8x64.Or, orSlice[uint8]) + testUint16x32Binary(t, archsimd.Uint16x32.Or, orSlice[uint16]) testUint32x16Binary(t, archsimd.Uint32x16.Or, orSlice[uint32]) testUint64x8Binary(t, archsimd.Uint64x8.Or, orSlice[uint64]) } } -func TestMul(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Mul, mulSlice[float32]) +func TestMulAMD64(t *testing.T) { testFloat32x8Binary(t, archsimd.Float32x8.Mul, mulSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Mul, mulSlice[float64]) testFloat64x4Binary(t, archsimd.Float64x4.Mul, mulSlice[float64]) - testInt16x8Binary(t, archsimd.Int16x8.Mul, mulSlice[int16]) - testInt32x4Binary(t, archsimd.Int32x4.Mul, mulSlice[int32]) - if archsimd.X86.AVX2() { testInt16x16Binary(t, archsimd.Int16x16.Mul, mulSlice[int16]) testInt32x8Binary(t, archsimd.Int32x8.Mul, mulSlice[int32]) @@ -379,9 +248,6 @@ testUint8x32Binary(t, archsimd.Uint8x32.Mul, mulSlice[uint8]) } - testInt8x16Binary(t, archsimd.Int8x16.Mul, mulSlice[int8]) - testUint8x16Binary(t, archsimd.Uint8x16.Mul, mulSlice[uint8]) - // TODO we should be able to do these, there's no difference between signed/unsigned Mul // testUint16x16Binary(t, archsimd.Uint16x16.Mul, mulSlice[uint16]) // testUint16x8Binary(t, archsimd.Uint16x8.Mul, mulSlice[uint16]) @@ -413,10 +279,8 @@ } } -func TestDiv(t *testing.T) { - testFloat32x4Binary(t, archsimd.Float32x4.Div, divSlice[float32]) +func TestDivAMD64(t *testing.T) { testFloat32x8Binary(t, archsimd.Float32x8.Div, divSlice[float32]) - testFloat64x2Binary(t, archsimd.Float64x2.Div, divSlice[float64]) testFloat64x4Binary(t, archsimd.Float64x4.Div, divSlice[float64]) if archsimd.X86.AVX512() {
diff --git a/src/simd/archsimd/internal/simd_test/binary_helpers_128_test.go b/src/simd/archsimd/internal/simd_test/binary_helpers_128_test.go index be1aee9..f3bf87e 100644 --- a/src/simd/archsimd/internal/simd_test/binary_helpers_128_test.go +++ b/src/simd/archsimd/internal/simd_test/binary_helpers_128_test.go
@@ -1,6 +1,6 @@ // Code generated by 'tmplgen'; DO NOT EDIT. -//go:build goexperiment.simd && (amd64 || wasm) +//go:build goexperiment.simd && (amd64 || wasm || arm64) // This file contains functions testing binary simd methods. // Each function in this file is specialized for a
diff --git a/src/simd/archsimd/internal/simd_test/binary_wasm_test.go b/src/simd/archsimd/internal/simd_test/binary_wasm_test.go new file mode 100644 index 0000000..cbae26a --- /dev/null +++ b/src/simd/archsimd/internal/simd_test/binary_wasm_test.go
@@ -0,0 +1,27 @@ +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build goexperiment.simd && wasm + +package simd_test + +import ( + "simd/archsimd" + "testing" +) + +func TestMaxWasm(t *testing.T) { + testInt64x2Binary(t, archsimd.Int64x2.Max, maxSlice[int64]) + testUint64x2Binary(t, archsimd.Uint64x2.Max, maxSlice[uint64]) +} + +func TestMinWasm(t *testing.T) { + testInt64x2Binary(t, archsimd.Int64x2.Min, minSlice[int64]) + testUint64x2Binary(t, archsimd.Uint64x2.Min, minSlice[uint64]) +} + +func TestMulWasm(t *testing.T) { + testInt64x2Binary(t, archsimd.Int64x2.Mul, mulSlice[int64]) + testUint64x2Binary(t, archsimd.Uint64x2.Mul, mulSlice[uint64]) +}
diff --git a/src/simd/archsimd/internal/simd_test/compare_128_test.go b/src/simd/archsimd/internal/simd_test/compare_128_test.go index 2fa1dc8..98ade49 100644 --- a/src/simd/archsimd/internal/simd_test/compare_128_test.go +++ b/src/simd/archsimd/internal/simd_test/compare_128_test.go
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.simd && wasm +//go:build goexperiment.simd && (amd64 || wasm || arm64) package simd_test
diff --git a/src/simd/archsimd/internal/simd_test/compare_test.go b/src/simd/archsimd/internal/simd_test/compare_amd64_test.go similarity index 68% rename from src/simd/archsimd/internal/simd_test/compare_test.go rename to src/simd/archsimd/internal/simd_test/compare_amd64_test.go index 3ce0d54..f264be8 100644 --- a/src/simd/archsimd/internal/simd_test/compare_test.go +++ b/src/simd/archsimd/internal/simd_test/compare_amd64_test.go
@@ -11,40 +11,16 @@ "testing" ) -func TestLess(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.Less, lessSlice[float32]) +func TestLessAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.Less, lessSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Less, lessSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.Less, lessSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.Less, lessSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Less, lessSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Less, lessSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.Less, lessSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.Less, lessSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.Less, lessSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.Less, lessSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.Less, lessSlice[int8]) - testInt16x16Compare(t, archsimd.Int16x16.Less, lessSlice[int16]) - testInt32x8Compare(t, archsimd.Int32x8.Less, lessSlice[int32]) - testInt64x4Compare(t, archsimd.Int64x4.Less, lessSlice[int64]) - testInt8x32Compare(t, archsimd.Int8x32.Less, lessSlice[int8]) - } - - testInt16x8Compare(t, archsimd.Int16x8.Less, lessSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Less, lessSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Less, lessSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.Less, lessSlice[int8]) - - testUint16x8Compare(t, archsimd.Uint16x8.Less, lessSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Less, lessSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Less, lessSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.Less, lessSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.Less, lessSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.Less, lessSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.Less, lessSlice[uint64]) @@ -74,30 +50,16 @@ } } -func TestLessEqual(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.LessEqual, lessEqualSlice[float32]) +func TestLessEqualAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.LessEqual, lessEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.LessEqual, lessEqualSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.LessEqual, lessEqualSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.LessEqual, lessEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.LessEqual, lessEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.LessEqual, lessEqualSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.LessEqual, lessEqualSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.LessEqual, lessEqualSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.LessEqual, lessEqualSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.LessEqual, lessEqualSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.LessEqual, lessEqualSlice[int8]) - } - testUint16x8Compare(t, archsimd.Uint16x8.LessEqual, lessEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.LessEqual, lessEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.LessEqual, lessEqualSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.LessEqual, lessEqualSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.LessEqual, lessEqualSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.LessEqual, lessEqualSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.LessEqual, lessEqualSlice[uint64]) @@ -118,30 +80,16 @@ } } -func TestGreater(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.Greater, greaterSlice[float32]) +func TestGreaterAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.Greater, greaterSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Greater, greaterSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.Greater, greaterSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.Greater, greaterSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Greater, greaterSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Greater, greaterSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.Greater, greaterSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.Greater, greaterSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.Greater, greaterSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.Greater, greaterSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.Greater, greaterSlice[int8]) - } - testUint16x8Compare(t, archsimd.Uint16x8.Greater, greaterSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Greater, greaterSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Greater, greaterSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.Greater, greaterSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.Greater, greaterSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.Greater, greaterSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.Greater, greaterSlice[uint64]) @@ -163,30 +111,16 @@ } } -func TestGreaterEqual(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.GreaterEqual, greaterEqualSlice[float32]) +func TestGreaterEqualAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.GreaterEqual, greaterEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.GreaterEqual, greaterEqualSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.GreaterEqual, greaterEqualSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.GreaterEqual, greaterEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.GreaterEqual, greaterEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.GreaterEqual, greaterEqualSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.GreaterEqual, greaterEqualSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.GreaterEqual, greaterEqualSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.GreaterEqual, greaterEqualSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.GreaterEqual, greaterEqualSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.GreaterEqual, greaterEqualSlice[int8]) - } - testUint16x8Compare(t, archsimd.Uint16x8.GreaterEqual, greaterEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.GreaterEqual, greaterEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.GreaterEqual, greaterEqualSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.GreaterEqual, greaterEqualSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.GreaterEqual, greaterEqualSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.GreaterEqual, greaterEqualSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.GreaterEqual, greaterEqualSlice[uint64]) @@ -207,30 +141,16 @@ } } -func TestEqual(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.Equal, equalSlice[float32]) +func TestEqualAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.Equal, equalSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.Equal, equalSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.Equal, equalSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.Equal, equalSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.Equal, equalSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.Equal, equalSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.Equal, equalSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.Equal, equalSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.Equal, equalSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.Equal, equalSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.Equal, equalSlice[int8]) - } - testUint16x8Compare(t, archsimd.Uint16x8.Equal, equalSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.Equal, equalSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.Equal, equalSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.Equal, equalSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.Equal, equalSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.Equal, equalSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.Equal, equalSlice[uint64]) @@ -251,30 +171,16 @@ } } -func TestNotEqual(t *testing.T) { - testFloat32x4Compare(t, archsimd.Float32x4.NotEqual, notEqualSlice[float32]) +func TestNotEqualAMD64(t *testing.T) { testFloat32x8Compare(t, archsimd.Float32x8.NotEqual, notEqualSlice[float32]) - testFloat64x2Compare(t, archsimd.Float64x2.NotEqual, notEqualSlice[float64]) testFloat64x4Compare(t, archsimd.Float64x4.NotEqual, notEqualSlice[float64]) - testInt16x8Compare(t, archsimd.Int16x8.NotEqual, notEqualSlice[int16]) - testInt32x4Compare(t, archsimd.Int32x4.NotEqual, notEqualSlice[int32]) - testInt64x2Compare(t, archsimd.Int64x2.NotEqual, notEqualSlice[int64]) - testInt8x16Compare(t, archsimd.Int8x16.NotEqual, notEqualSlice[int8]) - if archsimd.X86.AVX2() { testInt16x16Compare(t, archsimd.Int16x16.NotEqual, notEqualSlice[int16]) testInt32x8Compare(t, archsimd.Int32x8.NotEqual, notEqualSlice[int32]) testInt64x4Compare(t, archsimd.Int64x4.NotEqual, notEqualSlice[int64]) testInt8x32Compare(t, archsimd.Int8x32.NotEqual, notEqualSlice[int8]) - } - testUint16x8Compare(t, archsimd.Uint16x8.NotEqual, notEqualSlice[uint16]) - testUint32x4Compare(t, archsimd.Uint32x4.NotEqual, notEqualSlice[uint32]) - testUint64x2Compare(t, archsimd.Uint64x2.NotEqual, notEqualSlice[uint64]) - testUint8x16Compare(t, archsimd.Uint8x16.NotEqual, notEqualSlice[uint8]) - - if archsimd.X86.AVX2() { testUint16x16Compare(t, archsimd.Uint16x16.NotEqual, notEqualSlice[uint16]) testUint32x8Compare(t, archsimd.Uint32x8.NotEqual, notEqualSlice[uint32]) testUint64x4Compare(t, archsimd.Uint64x4.NotEqual, notEqualSlice[uint64])
diff --git a/src/simd/archsimd/internal/simd_test/compare_helpers_128_test.go b/src/simd/archsimd/internal/simd_test/compare_helpers_128_test.go index 44819ba..c217440 100644 --- a/src/simd/archsimd/internal/simd_test/compare_helpers_128_test.go +++ b/src/simd/archsimd/internal/simd_test/compare_helpers_128_test.go
@@ -1,6 +1,6 @@ // Code generated by 'tmplgen'; DO NOT EDIT. -//go:build goexperiment.simd && (amd64 || wasm) +//go:build goexperiment.simd && (amd64 || wasm || arm64) // This file contains functions testing simd methods that compare two operands. // Each function in this file is specialized for a
diff --git a/src/simd/archsimd/internal/simd_test/shift_128_test.go b/src/simd/archsimd/internal/simd_test/shift_128_test.go index 7da9ad1..61b55c6 100644 --- a/src/simd/archsimd/internal/simd_test/shift_128_test.go +++ b/src/simd/archsimd/internal/simd_test/shift_128_test.go
@@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.simd && wasm +//go:build goexperiment.simd && (amd64 || wasm || arm64) package simd_test
diff --git a/src/simd/archsimd/internal/simd_test/shift_test.go b/src/simd/archsimd/internal/simd_test/shift_amd64_test.go similarity index 89% rename from src/simd/archsimd/internal/simd_test/shift_test.go rename to src/simd/archsimd/internal/simd_test/shift_amd64_test.go index 18cc206..31ff375 100644 --- a/src/simd/archsimd/internal/simd_test/shift_test.go +++ b/src/simd/archsimd/internal/simd_test/shift_amd64_test.go
@@ -11,7 +11,7 @@ "testing" ) -func TestRotateAllLeft(t *testing.T) { +func TestRotateAllLeftAMD64(t *testing.T) { x := uint8(0x81) if y := rotl(x, 1); y != 3 { t.Errorf("Expected 3, got 0x%x", y) @@ -24,12 +24,6 @@ } for i := uint64(0); i < 65; i++ { - testUint64x2Unary(t, curry2(archsimd.Uint64x2.RotateAllLeft, i), rotlOfSlice[uint64](i)) - testUint32x4Unary(t, curry2(archsimd.Uint32x4.RotateAllLeft, i), rotlOfSlice[uint32](i)) - // testUint16x8Unary(t, curry2(archsimd.Uint16x8.RotateAllLeft, i), rotlOfSlice[uint16](i)) - // testUint8x16Unary(t, curry2(archsimd.Uint8x16.RotateAllLeft, i), rotlOfSlice[uint8](i)) - } - for i := uint64(0); i < 65; i++ { testUint64x4Unary(t, curry2(archsimd.Uint64x4.RotateAllLeft, i), rotlOfSlice[uint64](i)) testUint32x8Unary(t, curry2(archsimd.Uint32x8.RotateAllLeft, i), rotlOfSlice[uint32](i)) // testUint16x16Unary(t, curry2(archsimd.Uint16x16.RotateAllLeft, i), rotlOfSlice[uint16](i)) @@ -38,7 +32,7 @@ } -func TestRotateAllRight(t *testing.T) { +func TestRotateAllRightAMD64(t *testing.T) { x := uint8(0x81) if y := rotr(x, 1); y != 0xc0 { t.Errorf("Expected 0xc0, got 0x%x", y) @@ -51,12 +45,6 @@ } for i := uint64(0); i < 65; i++ { - testUint64x2Unary(t, curry2(archsimd.Uint64x2.RotateAllRight, i), rotrOfSlice[uint64](i)) - testUint32x4Unary(t, curry2(archsimd.Uint32x4.RotateAllRight, i), rotrOfSlice[uint32](i)) - // testUint16x8Unary(t, curry2(archsimd.Uint16x8.RotateAllLeft, i), rotlOfSlice[uint16](i)) - // testUint8x16Unary(t, curry2(archsimd.Uint8x16.RotateAllLeft, i), rotlOfSlice[uint8](i)) - } - for i := uint64(0); i < 65; i++ { testUint64x4Unary(t, curry2(archsimd.Uint64x4.RotateAllRight, i), rotrOfSlice[uint64](i)) testUint32x8Unary(t, curry2(archsimd.Uint32x8.RotateAllRight, i), rotrOfSlice[uint32](i)) // testUint16x16Unary(t, curry2(archsimd.Uint16x16.RotateAllLeft, i), rotlOfSlice[uint16](i))
diff --git a/src/simd/archsimd/internal/simd_test/unary_128_test.go b/src/simd/archsimd/internal/simd_test/unary_128_test.go index 416978d..afad266 100644 --- a/src/simd/archsimd/internal/simd_test/unary_128_test.go +++ b/src/simd/archsimd/internal/simd_test/unary_128_test.go
@@ -2,11 +2,12 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build goexperiment.simd && wasm +//go:build goexperiment.simd && (amd64 || wasm || arm64) package simd_test import ( + "runtime" "simd/archsimd" "testing" ) @@ -46,25 +47,30 @@ testInt64x2Unary(t, archsimd.Int64x2.Not, map1[int64](not)) } -func TestAbsolute(t *testing.T) { +func TestAbs(t *testing.T) { + testFloat32x4Unary(t, archsimd.Float32x4.Abs, map1[float32](abs)) + testFloat64x2Unary(t, archsimd.Float64x2.Abs, map1[float64](abs)) testInt8x16Unary(t, archsimd.Int8x16.Abs, map1[int8](abs)) testInt16x8Unary(t, archsimd.Int16x8.Abs, map1[int16](abs)) testInt32x4Unary(t, archsimd.Int32x4.Abs, map1[int32](abs)) + if runtime.GOARCH != "amd64" || archsimd.X86.AVX512() { + testInt64x2Unary(t, archsimd.Int64x2.Abs, map1[int64](abs)) + } +} + +func TestNeg(t *testing.T) { + testFloat32x4Unary(t, archsimd.Float32x4.Neg, map1[float32](neg)) + testFloat64x2Unary(t, archsimd.Float64x2.Neg, map1[float64](neg)) + testInt8x16Unary(t, archsimd.Int8x16.Neg, map1[int8](neg)) + testInt16x8Unary(t, archsimd.Int16x8.Neg, map1[int16](neg)) + testInt32x4Unary(t, archsimd.Int32x4.Neg, map1[int32](neg)) + testInt64x2Unary(t, archsimd.Int64x2.Neg, map1[int64](neg)) } func TestOnesCount(t *testing.T) { + if runtime.GOARCH == "amd64" && !archsimd.X86.AVX512BITALG() { + t.Skip("OnesCount on 128-bit 8-bit vectors on amd64 requires AVX512BITALG") + } testInt8x16Unary(t, archsimd.Int8x16.OnesCount, map1[int8](onesCount)) - testInt16x8Unary(t, archsimd.Int16x8.OnesCount, map1[int16](onesCount)) - testInt32x4Unary(t, archsimd.Int32x4.OnesCount, map1[int32](onesCount)) + testUint8x16Unary(t, archsimd.Uint8x16.OnesCount, map1[uint8](onesCount)) } - -// func TestConvert(t *testing.T) { -// testFloat64x2ConvertToFloat32(t, archsimd.Float64x2.ConvertToFloat32, map1n[float64](toFloat32, 4)) -// testFloat32x4ConvertToFloat64(t, archsimd.Float32x4.ConvertToFloat64, map1[float32](toFloat64)) - -// testFloat32x4ConvertToInt32(t, archsimd.Float32x4.ConvertToInt32, map1[float32](floatToInt32_x86)) -// testFloat64x2ConvertToInt32(t, archsimd.Float64x2.ConvertToInt32, map1n[float64](floatToInt32_x86, 4)) - -// testInt32x4ConvertToFloat32(t, archsimd.Int32x4.ConvertToFloat32, map1[int32](toFloat32)) -// testInt32x4ConvertToFloat64(t, archsimd.Int32x4.ConvertToFloat64, map1[int32](toFloat64)) -// }
diff --git a/src/simd/archsimd/internal/simd_test/unary_test.go b/src/simd/archsimd/internal/simd_test/unary_amd64_test.go similarity index 87% rename from src/simd/archsimd/internal/simd_test/unary_test.go rename to src/simd/archsimd/internal/simd_test/unary_amd64_test.go index 8d390f0..734e21d 100644 --- a/src/simd/archsimd/internal/simd_test/unary_test.go +++ b/src/simd/archsimd/internal/simd_test/unary_amd64_test.go
@@ -12,32 +12,46 @@ "testing" ) -func TestAbsFP(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Abs, map1[float32](abs)) +func TestAbsAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Abs, map1[float32](abs)) - testFloat64x2Unary(t, archsimd.Float64x2.Abs, map1[float64](abs)) testFloat64x4Unary(t, archsimd.Float64x4.Abs, map1[float64](abs)) + if archsimd.X86.AVX2() { + testInt8x32Unary(t, archsimd.Int8x32.Abs, map1[int8](abs)) + testInt16x16Unary(t, archsimd.Int16x16.Abs, map1[int16](abs)) + testInt32x8Unary(t, archsimd.Int32x8.Abs, map1[int32](abs)) + } if archsimd.X86.AVX512() { - testFloat32x16Unary(t, archsimd.Float32x16.Abs, map1[float32](abs)) // missing - testFloat64x8Unary(t, archsimd.Float64x8.Abs, map1[float64](abs)) // missing + testInt8x64Unary(t, archsimd.Int8x64.Abs, map1[int8](abs)) + testInt16x32Unary(t, archsimd.Int16x32.Abs, map1[int16](abs)) + testInt32x16Unary(t, archsimd.Int32x16.Abs, map1[int32](abs)) + testInt64x4Unary(t, archsimd.Int64x4.Abs, map1[int64](abs)) + testInt64x8Unary(t, archsimd.Int64x8.Abs, map1[int64](abs)) + testFloat32x16Unary(t, archsimd.Float32x16.Abs, map1[float32](abs)) + testFloat64x8Unary(t, archsimd.Float64x8.Abs, map1[float64](abs)) } } -func TestNegFP(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Neg, map1[float32](neg)) +func TestNegAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Neg, map1[float32](neg)) - testFloat64x2Unary(t, archsimd.Float64x2.Neg, map1[float64](neg)) testFloat64x4Unary(t, archsimd.Float64x4.Neg, map1[float64](neg)) + if archsimd.X86.AVX2() { + testInt8x32Unary(t, archsimd.Int8x32.Neg, map1[int8](neg)) + testInt16x16Unary(t, archsimd.Int16x16.Neg, map1[int16](neg)) + testInt32x8Unary(t, archsimd.Int32x8.Neg, map1[int32](neg)) + testInt64x4Unary(t, archsimd.Int64x4.Neg, map1[int64](neg)) + } if archsimd.X86.AVX512() { - testFloat32x16Unary(t, archsimd.Float32x16.Neg, map1[float32](neg)) // missing - testFloat64x8Unary(t, archsimd.Float64x8.Neg, map1[float64](neg)) // missing + testFloat32x16Unary(t, archsimd.Float32x16.Neg, map1[float32](neg)) + testFloat64x8Unary(t, archsimd.Float64x8.Neg, map1[float64](neg)) + testInt8x64Unary(t, archsimd.Int8x64.Neg, map1[int8](neg)) + testInt16x32Unary(t, archsimd.Int16x32.Neg, map1[int16](neg)) + testInt32x16Unary(t, archsimd.Int32x16.Neg, map1[int32](neg)) + testInt64x8Unary(t, archsimd.Int64x8.Neg, map1[int64](neg)) } } -func TestCeil(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Ceil, ceilSlice[float32]) +func TestCeilAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Ceil, ceilSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Ceil, ceilSlice[float64]) testFloat64x4Unary(t, archsimd.Float64x4.Ceil, ceilSlice[float64]) if archsimd.X86.AVX512() { // testFloat32x16Unary(t, archsimd.Float32x16.Ceil, ceilSlice[float32]) // missing @@ -45,10 +59,8 @@ } } -func TestFloor(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Floor, floorSlice[float32]) +func TestFloorAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Floor, floorSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Floor, floorSlice[float64]) testFloat64x4Unary(t, archsimd.Float64x4.Floor, floorSlice[float64]) if archsimd.X86.AVX512() { // testFloat32x16Unary(t, archsimd.Float32x16.Floor, floorSlice[float32]) // missing @@ -56,10 +68,8 @@ } } -func TestTrunc(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Trunc, truncSlice[float32]) +func TestTruncAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Trunc, truncSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Trunc, truncSlice[float64]) testFloat64x4Unary(t, archsimd.Float64x4.Trunc, truncSlice[float64]) if archsimd.X86.AVX512() { // testFloat32x16Unary(t, archsimd.Float32x16.Trunc, truncSlice[float32]) // missing @@ -67,10 +77,8 @@ } } -func TestRound(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Round, roundSlice[float32]) +func TestRoundAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Round, roundSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Round, roundSlice[float64]) testFloat64x4Unary(t, archsimd.Float64x4.Round, roundSlice[float64]) if archsimd.X86.AVX512() { // testFloat32x16Unary(t, archsimd.Float32x16.Round, roundSlice[float32]) // missing @@ -78,10 +86,8 @@ } } -func TestSqrt(t *testing.T) { - testFloat32x4Unary(t, archsimd.Float32x4.Sqrt, sqrtSlice[float32]) +func TestSqrtAMD64(t *testing.T) { testFloat32x8Unary(t, archsimd.Float32x8.Sqrt, sqrtSlice[float32]) - testFloat64x2Unary(t, archsimd.Float64x2.Sqrt, sqrtSlice[float64]) testFloat64x4Unary(t, archsimd.Float64x4.Sqrt, sqrtSlice[float64]) if archsimd.X86.AVX512() { testFloat32x16Unary(t, archsimd.Float32x16.Sqrt, sqrtSlice[float32]) @@ -89,10 +95,8 @@ } } -func TestNot(t *testing.T) { - testInt8x16Unary(t, archsimd.Int8x16.Not, map1[int8](not)) +func TestNotAMD64(t *testing.T) { testInt16x8Unary(t, archsimd.Int16x8.Not, map1[int16](not)) - testInt32x4Unary(t, archsimd.Int32x4.Not, map1[int32](not)) if archsimd.X86.AVX2() { testInt8x32Unary(t, archsimd.Int8x32.Not, map1[int8](not)) @@ -101,32 +105,6 @@ } } -func TestAbsolute(t *testing.T) { - testInt8x16Unary(t, archsimd.Int8x16.Abs, map1[int8](abs)) - testInt16x8Unary(t, archsimd.Int16x8.Abs, map1[int16](abs)) - testInt32x4Unary(t, archsimd.Int32x4.Abs, map1[int32](abs)) - testFloat32x4Unary(t, archsimd.Float32x4.Abs, map1[float32](abs)) - testFloat64x2Unary(t, archsimd.Float64x2.Abs, map1[float64](abs)) - - if archsimd.X86.AVX2() { - testInt8x32Unary(t, archsimd.Int8x32.Abs, map1[int8](abs)) - testInt16x16Unary(t, archsimd.Int16x16.Abs, map1[int16](abs)) - testInt32x8Unary(t, archsimd.Int32x8.Abs, map1[int32](abs)) - testFloat32x8Unary(t, archsimd.Float32x8.Abs, map1[float32](abs)) - testFloat64x4Unary(t, archsimd.Float64x4.Abs, map1[float64](abs)) - } - if archsimd.X86.AVX512() { - testInt8x64Unary(t, archsimd.Int8x64.Abs, map1[int8](abs)) - testInt16x32Unary(t, archsimd.Int16x32.Abs, map1[int16](abs)) - testInt32x16Unary(t, archsimd.Int32x16.Abs, map1[int32](abs)) - testInt64x2Unary(t, archsimd.Int64x2.Abs, map1[int64](abs)) - testInt64x4Unary(t, archsimd.Int64x4.Abs, map1[int64](abs)) - testInt64x8Unary(t, archsimd.Int64x8.Abs, map1[int64](abs)) - testFloat32x16Unary(t, archsimd.Float32x16.Abs, map1[float32](abs)) - testFloat64x8Unary(t, archsimd.Float64x8.Abs, map1[float64](abs)) - } -} - func TestCeilScaledResidue(t *testing.T) { if !archsimd.X86.AVX512() { t.Skip("Needs AVX512") @@ -340,3 +318,43 @@ testUint64x8ConvertToUint32(t, archsimd.Uint64x8.SaturateToUint32, map1[uint64](satToUint32)) } } + +func TestOnesCountAMD64(t *testing.T) { + if archsimd.X86.AVX512BITALG() { + // 128-bit + testInt16x8Unary(t, archsimd.Int16x8.OnesCount, map1[int16](onesCount)) + testUint16x8Unary(t, archsimd.Uint16x8.OnesCount, map1[uint16](onesCount)) + + // 256-bit + testInt8x32Unary(t, archsimd.Int8x32.OnesCount, map1[int8](onesCount)) + testUint8x32Unary(t, archsimd.Uint8x32.OnesCount, map1[uint8](onesCount)) + testInt16x16Unary(t, archsimd.Int16x16.OnesCount, map1[int16](onesCount)) + testUint16x16Unary(t, archsimd.Uint16x16.OnesCount, map1[uint16](onesCount)) + + // 512-bit + testInt8x64Unary(t, archsimd.Int8x64.OnesCount, map1[int8](onesCount)) + testUint8x64Unary(t, archsimd.Uint8x64.OnesCount, map1[uint8](onesCount)) + testInt16x32Unary(t, archsimd.Int16x32.OnesCount, map1[int16](onesCount)) + testUint16x32Unary(t, archsimd.Uint16x32.OnesCount, map1[uint16](onesCount)) + } + + if archsimd.X86.AVX512VPOPCNTDQ() { + // 128-bit + testInt32x4Unary(t, archsimd.Int32x4.OnesCount, map1[int32](onesCount)) + testUint32x4Unary(t, archsimd.Uint32x4.OnesCount, map1[uint32](onesCount)) + testInt64x2Unary(t, archsimd.Int64x2.OnesCount, map1[int64](onesCount)) + testUint64x2Unary(t, archsimd.Uint64x2.OnesCount, map1[uint64](onesCount)) + + // 256-bit + testInt32x8Unary(t, archsimd.Int32x8.OnesCount, map1[int32](onesCount)) + testUint32x8Unary(t, archsimd.Uint32x8.OnesCount, map1[uint32](onesCount)) + testInt64x4Unary(t, archsimd.Int64x4.OnesCount, map1[int64](onesCount)) + testUint64x4Unary(t, archsimd.Uint64x4.OnesCount, map1[uint64](onesCount)) + + // 512-bit + testInt32x16Unary(t, archsimd.Int32x16.OnesCount, map1[int32](onesCount)) + testUint32x16Unary(t, archsimd.Uint32x16.OnesCount, map1[uint32](onesCount)) + testInt64x8Unary(t, archsimd.Int64x8.OnesCount, map1[int64](onesCount)) + testUint64x8Unary(t, archsimd.Uint64x8.OnesCount, map1[uint64](onesCount)) + } +}
diff --git a/src/simd/archsimd/internal/simd_test/unary_helpers_128_test.go b/src/simd/archsimd/internal/simd_test/unary_helpers_128_test.go index dee8c3a..dc6bf82 100644 --- a/src/simd/archsimd/internal/simd_test/unary_helpers_128_test.go +++ b/src/simd/archsimd/internal/simd_test/unary_helpers_128_test.go
@@ -1,6 +1,6 @@ // Code generated by 'tmplgen'; DO NOT EDIT. -//go:build goexperiment.simd && (amd64 || wasm) +//go:build goexperiment.simd && (amd64 || wasm || arm64) // This file contains functions testing unary simd methods. // Each function in this file is specialized for a
diff --git a/src/simd/archsimd/internal/simd_test/unary_wasm_test.go b/src/simd/archsimd/internal/simd_test/unary_wasm_test.go new file mode 100644 index 0000000..3275030 --- /dev/null +++ b/src/simd/archsimd/internal/simd_test/unary_wasm_test.go
@@ -0,0 +1,21 @@ +// Copyright 2026 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build goexperiment.simd && wasm + +package simd_test + +import ( + "simd/archsimd" + "testing" +) + +func TestOnesCountWasm(t *testing.T) { + testInt16x8Unary(t, archsimd.Int16x8.OnesCount, map1[int16](onesCount)) + testUint16x8Unary(t, archsimd.Uint16x8.OnesCount, map1[uint16](onesCount)) + testInt32x4Unary(t, archsimd.Int32x4.OnesCount, map1[int32](onesCount)) + testUint32x4Unary(t, archsimd.Uint32x4.OnesCount, map1[uint32](onesCount)) + testInt64x2Unary(t, archsimd.Int64x2.OnesCount, map1[int64](onesCount)) + testUint64x2Unary(t, archsimd.Uint64x2.OnesCount, map1[uint64](onesCount)) +}