1
2
3
4
5
6
7
8
9
10 package simd_test
11
12 import (
13 "simd/archsimd"
14 "testing"
15 )
16
17 const sveMaskUint16s = sveMaxBytes / 8
18
19
20
21
22 func testSVECompare[T number, V, M any](t *testing.T, pool []T, elemBytes, active int,
23 load func([]T) V, cmp func(V, V) M, store func(M, []uint16), want func(T, T) bool) {
24 t.Helper()
25 count := sveMaxBytes / elemBytes
26 forSlicePair(t, pool, count, func(x, y []T) bool {
27 t.Helper()
28 bits := make([]uint16, sveMaskUint16s)
29 store(cmp(load(x), load(y)), bits)
30 for i := 0; i < active; i++ {
31 b := i * elemBytes
32 got := bits[b/16]>>uint(b%16)&1 == 1
33 if got != want(x[i], y[i]) {
34 t.Errorf("lane %d: got %v, want %v (x=%v y=%v)", i, got, want(x[i], y[i]), x[i], y[i])
35 return false
36 }
37 }
38 return true
39 })
40 }
41
42 func testInt8sCompare(t *testing.T, cmp func(_, _ archsimd.Int8s) archsimd.Mask8s, want func(_, _ int8) bool) {
43 var z archsimd.Int8s
44 testSVECompare(t, int8s, 1, z.Len(), archsimd.LoadInt8s, cmp, archsimd.Mask8s.Store, want)
45 }
46
47 func testInt16sCompare(t *testing.T, cmp func(_, _ archsimd.Int16s) archsimd.Mask16s, want func(_, _ int16) bool) {
48 var z archsimd.Int16s
49 testSVECompare(t, int16s, 2, z.Len(), archsimd.LoadInt16s, cmp, archsimd.Mask16s.Store, want)
50 }
51
52 func testInt32sCompare(t *testing.T, cmp func(_, _ archsimd.Int32s) archsimd.Mask32s, want func(_, _ int32) bool) {
53 var z archsimd.Int32s
54 testSVECompare(t, int32s, 4, z.Len(), archsimd.LoadInt32s, cmp, archsimd.Mask32s.Store, want)
55 }
56
57 func testInt64sCompare(t *testing.T, cmp func(_, _ archsimd.Int64s) archsimd.Mask64s, want func(_, _ int64) bool) {
58 var z archsimd.Int64s
59 testSVECompare(t, int64s, 8, z.Len(), archsimd.LoadInt64s, cmp, archsimd.Mask64s.Store, want)
60 }
61
62 func TestGreaterSVE(t *testing.T) {
63 if !archsimd.ARM64.SVE() {
64 t.Skip("no sve")
65 }
66 testInt8sCompare(t, archsimd.Int8s.Greater, func(a, b int8) bool { return a > b })
67 testInt16sCompare(t, archsimd.Int16s.Greater, func(a, b int16) bool { return a > b })
68 testInt32sCompare(t, archsimd.Int32s.Greater, func(a, b int32) bool { return a > b })
69 testInt64sCompare(t, archsimd.Int64s.Greater, func(a, b int64) bool { return a > b })
70 }
71
72
73
74 func TestMaskStoreLoadPanicSVE(t *testing.T) {
75 if !archsimd.ARM64.SVE() {
76 t.Skip("no sve")
77 }
78 var z archsimd.Int8s
79 m := z.Greater(z)
80 mustPanic(t, "Store short", func() { m.Store(nil) })
81 mustPanic(t, "LoadMask8s short", func() { archsimd.LoadMask8s(nil) })
82
83 bits := make([]uint16, sveMaskUint16s)
84 m.Store(bits)
85 archsimd.LoadMask8s(bits)
86 }
87
View as plain text