simd/archsimd: add more tests for Extend operations

The operations that extend only low elements, ExtendLoNTo..., are
not yet included.

Change-Id: I93168889b92c56720344b443c1cff238f8cc096a
Reviewed-on: https://go-review.googlesource.com/c/go/+/732661
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Cherry Mui
2025-12-26 11:53:19 -05:00
parent 7971fcdf53
commit 037c047f2c
4 changed files with 1939 additions and 159 deletions

View File

@@ -372,9 +372,21 @@ func test{{.VType}}ConvertTo{{.OEType}}(t *testing.T, f func(x archsimd.{{.VType
}
`)
var unaryToInt32 = convertTemplate.target("int", 32)
var unaryToUint32 = convertTemplate.target("uint", 32)
var unaryToUint16 = convertTemplate.target("uint", 16)
var (
// templates and shapes for conversion.
// TODO: this includes shapes where in and out have the same element type,
// which are not needed.
unaryToInt8 = convertTemplate.target("int", 8)
unaryToUint8 = convertTemplate.target("uint", 8)
unaryToInt16 = convertTemplate.target("int", 16)
unaryToUint16 = convertTemplate.target("uint", 16)
unaryToInt32 = convertTemplate.target("int", 32)
unaryToUint32 = convertTemplate.target("uint", 32)
unaryToInt64 = convertTemplate.target("int", 64)
unaryToUint64 = convertTemplate.target("uint", 64)
unaryToFloat32 = convertTemplate.target("float", 32)
unaryToFloat64 = convertTemplate.target("float", 64)
)
var binaryTemplate = templateOf("binary_helpers", `
// test{{.VType}}Binary tests the simd binary method f against the expected behavior generated by want
@@ -862,7 +874,7 @@ func main() {
one(*ush, unsafePrologue, unsafePATemplate)
}
if *uh != "" {
one(*uh, curryTestPrologue("unary simd methods"), unaryTemplate, unaryToInt32, unaryToUint32, unaryToUint16, unaryFlakyTemplate)
one(*uh, curryTestPrologue("unary simd methods"), unaryTemplate, unaryToInt8, unaryToUint8, unaryToInt16, unaryToUint16, unaryToInt32, unaryToUint32, unaryToInt64, unaryToUint64, unaryToFloat32, unaryToFloat64, unaryFlakyTemplate)
}
if *bh != "" {
one(*bh, curryTestPrologue("binary simd methods"), binaryTemplate)

View File

@@ -126,8 +126,9 @@ func map1[T, U any](elem func(x T) U) func(x []T) []U {
}
}
// map1 returns a function that returns the slice of the results of applying
// comparison function elem to the respective elements of its two slice inputs.
// mapCompare returns a function that returns the slice of the results of applying
// comparison function elem to the respective elements of its two slice inputs,
// and returns -1 if the comparison is true, 0 otherwise.
func mapCompare[T number](elem func(x, y T) bool) func(x, y []T) []int64 {
return func(x, y []T) []int64 {
s := make([]int64, len(x))

File diff suppressed because it is too large Load Diff

View File

@@ -130,14 +130,26 @@ func TestToInt32(t *testing.T) {
testFloat32x8ConvertToInt32(t, archsimd.Float32x8.ConvertToInt32, map1[float32](toInt32))
}
func TestConverts(t *testing.T) {
testUint8x16ConvertToUint16(t, archsimd.Uint8x16.ExtendToUint16, map1[uint8](toUint16))
testUint16x8ConvertToUint32(t, archsimd.Uint16x8.ExtendToUint32, map1[uint16](toUint32))
}
func TestConvertsAVX512(t *testing.T) {
if !archsimd.X86.AVX512() {
t.Skip("Needs AVX512")
func TestExtend(t *testing.T) {
if archsimd.X86.AVX2() {
testInt8x16ConvertToInt16(t, archsimd.Int8x16.ExtendToInt16, map1[int8](toInt16))
testInt16x8ConvertToInt32(t, archsimd.Int16x8.ExtendToInt32, map1[int16](toInt32))
testInt32x4ConvertToInt64(t, archsimd.Int32x4.ExtendToInt64, map1[int32](toInt64))
testUint8x16ConvertToUint16(t, archsimd.Uint8x16.ExtendToUint16, map1[uint8](toUint16))
testUint16x8ConvertToUint32(t, archsimd.Uint16x8.ExtendToUint32, map1[uint16](toUint32))
testUint32x4ConvertToUint64(t, archsimd.Uint32x4.ExtendToUint64, map1[uint32](toUint64))
}
if archsimd.X86.AVX512() {
testInt8x32ConvertToInt16(t, archsimd.Int8x32.ExtendToInt16, map1[int8](toInt16))
testInt8x16ConvertToInt32(t, archsimd.Int8x16.ExtendToInt32, map1[int8](toInt32))
testInt16x16ConvertToInt32(t, archsimd.Int16x16.ExtendToInt32, map1[int16](toInt32))
testInt16x8ConvertToInt64(t, archsimd.Int16x8.ExtendToInt64, map1[int16](toInt64))
testInt32x8ConvertToInt64(t, archsimd.Int32x8.ExtendToInt64, map1[int32](toInt64))
testUint8x32ConvertToUint16(t, archsimd.Uint8x32.ExtendToUint16, map1[uint8](toUint16))
testUint8x16ConvertToUint32(t, archsimd.Uint8x16.ExtendToUint32, map1[uint8](toUint32))
testUint16x16ConvertToUint32(t, archsimd.Uint16x16.ExtendToUint32, map1[uint16](toUint32))
testUint16x8ConvertToUint64(t, archsimd.Uint16x8.ExtendToUint64, map1[uint16](toUint64))
testUint32x8ConvertToUint64(t, archsimd.Uint32x8.ExtendToUint64, map1[uint32](toUint64))
}
testUint8x32ConvertToUint16(t, archsimd.Uint8x32.ExtendToUint16, map1[uint8](toUint16))
}