[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
// Copyright 2025 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 && amd64
|
|
|
|
|
|
|
|
|
|
package simd_test
|
|
|
|
|
|
|
|
|
|
import (
|
2025-07-25 15:18:11 -04:00
|
|
|
"math"
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
"simd"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCeil(t *testing.T) {
|
|
|
|
|
testFloat32x4Unary(t, simd.Float32x4.Ceil, ceilSlice[float32])
|
|
|
|
|
testFloat32x8Unary(t, simd.Float32x8.Ceil, ceilSlice[float32])
|
|
|
|
|
testFloat64x2Unary(t, simd.Float64x2.Ceil, ceilSlice[float64])
|
|
|
|
|
testFloat64x4Unary(t, simd.Float64x4.Ceil, ceilSlice[float64])
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
// testFloat32x16Unary(t, simd.Float32x16.Ceil, ceilSlice[float32]) // missing
|
|
|
|
|
// testFloat64x8Unary(t, simd.Float64x8.Ceil, ceilSlice[float64]) // missing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestFloor(t *testing.T) {
|
|
|
|
|
testFloat32x4Unary(t, simd.Float32x4.Floor, floorSlice[float32])
|
|
|
|
|
testFloat32x8Unary(t, simd.Float32x8.Floor, floorSlice[float32])
|
|
|
|
|
testFloat64x2Unary(t, simd.Float64x2.Floor, floorSlice[float64])
|
|
|
|
|
testFloat64x4Unary(t, simd.Float64x4.Floor, floorSlice[float64])
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
// testFloat32x16Unary(t, simd.Float32x16.Floor, floorSlice[float32]) // missing
|
|
|
|
|
// testFloat64x8Unary(t, simd.Float64x8.Floor, floorSlice[float64]) // missing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTrunc(t *testing.T) {
|
|
|
|
|
testFloat32x4Unary(t, simd.Float32x4.Trunc, truncSlice[float32])
|
|
|
|
|
testFloat32x8Unary(t, simd.Float32x8.Trunc, truncSlice[float32])
|
|
|
|
|
testFloat64x2Unary(t, simd.Float64x2.Trunc, truncSlice[float64])
|
|
|
|
|
testFloat64x4Unary(t, simd.Float64x4.Trunc, truncSlice[float64])
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
// testFloat32x16Unary(t, simd.Float32x16.Trunc, truncSlice[float32]) // missing
|
|
|
|
|
// testFloat64x8Unary(t, simd.Float64x8.Trunc, truncSlice[float64]) // missing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestRound(t *testing.T) {
|
2025-08-07 17:05:50 +00:00
|
|
|
testFloat32x4Unary(t, simd.Float32x4.RoundToEven, roundSlice[float32])
|
|
|
|
|
testFloat32x8Unary(t, simd.Float32x8.RoundToEven, roundSlice[float32])
|
|
|
|
|
testFloat64x2Unary(t, simd.Float64x2.RoundToEven, roundSlice[float64])
|
|
|
|
|
testFloat64x4Unary(t, simd.Float64x4.RoundToEven, roundSlice[float64])
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
// testFloat32x16Unary(t, simd.Float32x16.Round, roundSlice[float32]) // missing
|
|
|
|
|
// testFloat64x8Unary(t, simd.Float64x8.Round, roundSlice[float64]) // missing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestSqrt(t *testing.T) {
|
|
|
|
|
testFloat32x4Unary(t, simd.Float32x4.Sqrt, sqrtSlice[float32])
|
|
|
|
|
testFloat32x8Unary(t, simd.Float32x8.Sqrt, sqrtSlice[float32])
|
|
|
|
|
testFloat64x2Unary(t, simd.Float64x2.Sqrt, sqrtSlice[float64])
|
|
|
|
|
testFloat64x4Unary(t, simd.Float64x4.Sqrt, sqrtSlice[float64])
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
testFloat32x16Unary(t, simd.Float32x16.Sqrt, sqrtSlice[float32])
|
|
|
|
|
testFloat64x8Unary(t, simd.Float64x8.Sqrt, sqrtSlice[float64])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-09 14:44:25 -04:00
|
|
|
func TestNot(t *testing.T) {
|
|
|
|
|
testInt8x16Unary(t, simd.Int8x16.Not, map1[int8](not))
|
|
|
|
|
testInt8x32Unary(t, simd.Int8x32.Not, map1[int8](not))
|
|
|
|
|
testInt16x8Unary(t, simd.Int16x8.Not, map1[int16](not))
|
|
|
|
|
testInt16x16Unary(t, simd.Int16x16.Not, map1[int16](not))
|
|
|
|
|
testInt32x4Unary(t, simd.Int32x4.Not, map1[int32](not))
|
|
|
|
|
testInt32x8Unary(t, simd.Int32x8.Not, map1[int32](not))
|
|
|
|
|
}
|
|
|
|
|
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
func TestAbsolute(t *testing.T) {
|
2025-08-07 17:05:50 +00:00
|
|
|
testInt8x16Unary(t, simd.Int8x16.Abs, map1[int8](abs))
|
|
|
|
|
testInt8x32Unary(t, simd.Int8x32.Abs, map1[int8](abs))
|
|
|
|
|
testInt16x8Unary(t, simd.Int16x8.Abs, map1[int16](abs))
|
|
|
|
|
testInt16x16Unary(t, simd.Int16x16.Abs, map1[int16](abs))
|
|
|
|
|
testInt32x4Unary(t, simd.Int32x4.Abs, map1[int32](abs))
|
|
|
|
|
testInt32x8Unary(t, simd.Int32x8.Abs, map1[int32](abs))
|
2025-11-12 19:56:09 +00:00
|
|
|
if simd.X86.AVX512() {
|
2025-08-07 17:05:50 +00:00
|
|
|
testInt8x64Unary(t, simd.Int8x64.Abs, map1[int8](abs))
|
|
|
|
|
testInt16x32Unary(t, simd.Int16x32.Abs, map1[int16](abs))
|
|
|
|
|
testInt32x16Unary(t, simd.Int32x16.Abs, map1[int32](abs))
|
|
|
|
|
testInt64x2Unary(t, simd.Int64x2.Abs, map1[int64](abs))
|
|
|
|
|
testInt64x4Unary(t, simd.Int64x4.Abs, map1[int64](abs))
|
|
|
|
|
testInt64x8Unary(t, simd.Int64x8.Abs, map1[int64](abs))
|
[dev.simd] simd: move test generation into Go repo
This pairs with CL 689275 which removes test generation from simdgen
This uses generics and attempts to encode the tests as compactly as
possible.
Some files, *_helpers_test.go, are generated.
Use t.Helper() to get the line number right for a failure.
Adds helper error return values and early exits to only report a
single test failure per operations and vector shape, for the
generated test failures.
Include the entire got and wanted vectors for that failure.
Provide an option to include the input vectors to failures, also
report the type of the test.
Sample failure test output (obtained by intentionally breaking
the "want" value for AndNot):
=== RUN TestAndNot
binary_test.go:214: For int16 vector elements:
binary_test.go:214: got =[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
binary_test.go:214: want=[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:214: x=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: y=[1 -1 0 2 4 8 1024 3 5 7 11 13 3000 5555 7777 11111]
binary_test.go:214: at index 0, got=0, want=-1
binary_test.go:215: For int16 vector elements:
binary_test.go:215: got =[0 0 0 0 0 0 0 0]
binary_test.go:215: want=[-1 -1 -1 -1 -1 -1 -1 -1]
binary_test.go:215: x=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: y=[1 -1 0 2 4 8 1024 3]
binary_test.go:215: at index 0, got=0, want=-1
binary_test.go:216: For int32 vector elements:
binary_test.go:216: got =[0 0 0 0]
binary_test.go:216: want=[-1 -1 -1 -1]
binary_test.go:216: x=[1 -1 0 2]
binary_test.go:216: y=[1 -1 0 2]
binary_test.go:216: at index 0, got=0, want=-1
(etc)
Change-Id: I0f6ee8390ebe7a2333002e9415b4d71527fa3c38
Reviewed-on: https://go-review.googlesource.com/c/go/+/686057
Reviewed-by: Junyang Shao <shaojunyang@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-07-07 17:48:24 -04:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-22 16:39:42 -04:00
|
|
|
|
2025-08-01 15:58:29 -04:00
|
|
|
func TestCeilScaledResidue(t *testing.T) {
|
2025-11-12 19:56:09 +00:00
|
|
|
if !simd.X86.AVX512() {
|
2025-07-25 15:18:11 -04:00
|
|
|
t.Skip("Needs AVX512")
|
|
|
|
|
}
|
|
|
|
|
testFloat64x8UnaryFlaky(t,
|
2025-08-01 15:58:29 -04:00
|
|
|
func(x simd.Float64x8) simd.Float64x8 { return x.CeilScaledResidue(0) },
|
2025-07-25 15:18:11 -04:00
|
|
|
map1(ceilResidueForPrecision[float64](0)),
|
|
|
|
|
0.001)
|
|
|
|
|
testFloat64x8UnaryFlaky(t,
|
2025-08-01 15:58:29 -04:00
|
|
|
func(x simd.Float64x8) simd.Float64x8 { return x.CeilScaledResidue(1) },
|
2025-07-25 15:18:11 -04:00
|
|
|
map1(ceilResidueForPrecision[float64](1)),
|
|
|
|
|
0.001)
|
|
|
|
|
testFloat64x8Unary(t,
|
2025-08-01 15:58:29 -04:00
|
|
|
func(x simd.Float64x8) simd.Float64x8 { return x.Sub(x.CeilScaled(0)) },
|
2025-07-25 15:18:11 -04:00
|
|
|
map1[float64](func(x float64) float64 { return x - math.Ceil(x) }))
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-22 16:39:42 -04:00
|
|
|
func TestToUint32(t *testing.T) {
|
2025-11-12 19:56:09 +00:00
|
|
|
if !simd.X86.AVX512() {
|
2025-07-22 16:39:42 -04:00
|
|
|
t.Skip("Needs AVX512")
|
|
|
|
|
}
|
2025-08-19 15:26:19 -04:00
|
|
|
testFloat32x4ConvertToUint32(t, simd.Float32x4.ConvertToUint32, map1[float32](toUint32))
|
|
|
|
|
testFloat32x8ConvertToUint32(t, simd.Float32x8.ConvertToUint32, map1[float32](toUint32))
|
|
|
|
|
testFloat32x16ConvertToUint32(t, simd.Float32x16.ConvertToUint32, map1[float32](toUint32))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestToInt32(t *testing.T) {
|
|
|
|
|
testFloat32x4ConvertToInt32(t, simd.Float32x4.ConvertToInt32, map1[float32](toInt32))
|
|
|
|
|
testFloat32x8ConvertToInt32(t, simd.Float32x8.ConvertToInt32, map1[float32](toInt32))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestConverts(t *testing.T) {
|
|
|
|
|
testUint8x16ConvertToUint16(t, simd.Uint8x16.ConvertToUint16, map1[uint8](toUint16))
|
|
|
|
|
testUint16x8ConvertToUint32(t, simd.Uint16x8.ConvertToUint32, map1[uint16](toUint32))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestConvertsAVX512(t *testing.T) {
|
2025-11-12 19:56:09 +00:00
|
|
|
if !simd.X86.AVX512() {
|
2025-08-19 15:26:19 -04:00
|
|
|
t.Skip("Needs AVX512")
|
|
|
|
|
}
|
|
|
|
|
testUint8x32ConvertToUint16(t, simd.Uint8x32.ConvertToUint16, map1[uint8](toUint16))
|
2025-07-22 16:39:42 -04:00
|
|
|
}
|