1
2
3
4
5
6
7
8
9 package simd_test
10
11 import (
12 "simd/archsimd"
13 "testing"
14 )
15
16
17 func testInt8x32Ternary(t *testing.T, f func(_, _, _ archsimd.Int8x32) archsimd.Int8x32, want func(_, _, _ []int8) []int8) {
18 n := 32
19 t.Helper()
20 forSliceTriple(t, int8s, n, func(x, y, z []int8) bool {
21 t.Helper()
22 a := archsimd.LoadInt8x32(x)
23 b := archsimd.LoadInt8x32(y)
24 c := archsimd.LoadInt8x32(z)
25 g := make([]int8, n)
26 f(a, b, c).Store(g)
27 w := want(x, y, z)
28 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
29 })
30 }
31
32
33 func testInt16x16Ternary(t *testing.T, f func(_, _, _ archsimd.Int16x16) archsimd.Int16x16, want func(_, _, _ []int16) []int16) {
34 n := 16
35 t.Helper()
36 forSliceTriple(t, int16s, n, func(x, y, z []int16) bool {
37 t.Helper()
38 a := archsimd.LoadInt16x16(x)
39 b := archsimd.LoadInt16x16(y)
40 c := archsimd.LoadInt16x16(z)
41 g := make([]int16, n)
42 f(a, b, c).Store(g)
43 w := want(x, y, z)
44 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
45 })
46 }
47
48
49 func testInt32x8Ternary(t *testing.T, f func(_, _, _ archsimd.Int32x8) archsimd.Int32x8, want func(_, _, _ []int32) []int32) {
50 n := 8
51 t.Helper()
52 forSliceTriple(t, int32s, n, func(x, y, z []int32) bool {
53 t.Helper()
54 a := archsimd.LoadInt32x8(x)
55 b := archsimd.LoadInt32x8(y)
56 c := archsimd.LoadInt32x8(z)
57 g := make([]int32, n)
58 f(a, b, c).Store(g)
59 w := want(x, y, z)
60 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
61 })
62 }
63
64
65 func testInt64x4Ternary(t *testing.T, f func(_, _, _ archsimd.Int64x4) archsimd.Int64x4, want func(_, _, _ []int64) []int64) {
66 n := 4
67 t.Helper()
68 forSliceTriple(t, int64s, n, func(x, y, z []int64) bool {
69 t.Helper()
70 a := archsimd.LoadInt64x4(x)
71 b := archsimd.LoadInt64x4(y)
72 c := archsimd.LoadInt64x4(z)
73 g := make([]int64, n)
74 f(a, b, c).Store(g)
75 w := want(x, y, z)
76 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
77 })
78 }
79
80
81 func testUint8x32Ternary(t *testing.T, f func(_, _, _ archsimd.Uint8x32) archsimd.Uint8x32, want func(_, _, _ []uint8) []uint8) {
82 n := 32
83 t.Helper()
84 forSliceTriple(t, uint8s, n, func(x, y, z []uint8) bool {
85 t.Helper()
86 a := archsimd.LoadUint8x32(x)
87 b := archsimd.LoadUint8x32(y)
88 c := archsimd.LoadUint8x32(z)
89 g := make([]uint8, n)
90 f(a, b, c).Store(g)
91 w := want(x, y, z)
92 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
93 })
94 }
95
96
97 func testUint16x16Ternary(t *testing.T, f func(_, _, _ archsimd.Uint16x16) archsimd.Uint16x16, want func(_, _, _ []uint16) []uint16) {
98 n := 16
99 t.Helper()
100 forSliceTriple(t, uint16s, n, func(x, y, z []uint16) bool {
101 t.Helper()
102 a := archsimd.LoadUint16x16(x)
103 b := archsimd.LoadUint16x16(y)
104 c := archsimd.LoadUint16x16(z)
105 g := make([]uint16, n)
106 f(a, b, c).Store(g)
107 w := want(x, y, z)
108 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
109 })
110 }
111
112
113 func testUint32x8Ternary(t *testing.T, f func(_, _, _ archsimd.Uint32x8) archsimd.Uint32x8, want func(_, _, _ []uint32) []uint32) {
114 n := 8
115 t.Helper()
116 forSliceTriple(t, uint32s, n, func(x, y, z []uint32) bool {
117 t.Helper()
118 a := archsimd.LoadUint32x8(x)
119 b := archsimd.LoadUint32x8(y)
120 c := archsimd.LoadUint32x8(z)
121 g := make([]uint32, n)
122 f(a, b, c).Store(g)
123 w := want(x, y, z)
124 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
125 })
126 }
127
128
129 func testUint64x4Ternary(t *testing.T, f func(_, _, _ archsimd.Uint64x4) archsimd.Uint64x4, want func(_, _, _ []uint64) []uint64) {
130 n := 4
131 t.Helper()
132 forSliceTriple(t, uint64s, n, func(x, y, z []uint64) bool {
133 t.Helper()
134 a := archsimd.LoadUint64x4(x)
135 b := archsimd.LoadUint64x4(y)
136 c := archsimd.LoadUint64x4(z)
137 g := make([]uint64, n)
138 f(a, b, c).Store(g)
139 w := want(x, y, z)
140 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
141 })
142 }
143
144
145 func testFloat32x8Ternary(t *testing.T, f func(_, _, _ archsimd.Float32x8) archsimd.Float32x8, want func(_, _, _ []float32) []float32) {
146 n := 8
147 t.Helper()
148 forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
149 t.Helper()
150 a := archsimd.LoadFloat32x8(x)
151 b := archsimd.LoadFloat32x8(y)
152 c := archsimd.LoadFloat32x8(z)
153 g := make([]float32, n)
154 f(a, b, c).Store(g)
155 w := want(x, y, z)
156 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
157 })
158 }
159
160
161 func testFloat64x4Ternary(t *testing.T, f func(_, _, _ archsimd.Float64x4) archsimd.Float64x4, want func(_, _, _ []float64) []float64) {
162 n := 4
163 t.Helper()
164 forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
165 t.Helper()
166 a := archsimd.LoadFloat64x4(x)
167 b := archsimd.LoadFloat64x4(y)
168 c := archsimd.LoadFloat64x4(z)
169 g := make([]float64, n)
170 f(a, b, c).Store(g)
171 w := want(x, y, z)
172 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
173 })
174 }
175
176
177 func testInt8x64Ternary(t *testing.T, f func(_, _, _ archsimd.Int8x64) archsimd.Int8x64, want func(_, _, _ []int8) []int8) {
178 n := 64
179 t.Helper()
180 forSliceTriple(t, int8s, n, func(x, y, z []int8) bool {
181 t.Helper()
182 a := archsimd.LoadInt8x64(x)
183 b := archsimd.LoadInt8x64(y)
184 c := archsimd.LoadInt8x64(z)
185 g := make([]int8, n)
186 f(a, b, c).Store(g)
187 w := want(x, y, z)
188 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
189 })
190 }
191
192
193 func testInt16x32Ternary(t *testing.T, f func(_, _, _ archsimd.Int16x32) archsimd.Int16x32, want func(_, _, _ []int16) []int16) {
194 n := 32
195 t.Helper()
196 forSliceTriple(t, int16s, n, func(x, y, z []int16) bool {
197 t.Helper()
198 a := archsimd.LoadInt16x32(x)
199 b := archsimd.LoadInt16x32(y)
200 c := archsimd.LoadInt16x32(z)
201 g := make([]int16, n)
202 f(a, b, c).Store(g)
203 w := want(x, y, z)
204 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
205 })
206 }
207
208
209 func testInt32x16Ternary(t *testing.T, f func(_, _, _ archsimd.Int32x16) archsimd.Int32x16, want func(_, _, _ []int32) []int32) {
210 n := 16
211 t.Helper()
212 forSliceTriple(t, int32s, n, func(x, y, z []int32) bool {
213 t.Helper()
214 a := archsimd.LoadInt32x16(x)
215 b := archsimd.LoadInt32x16(y)
216 c := archsimd.LoadInt32x16(z)
217 g := make([]int32, n)
218 f(a, b, c).Store(g)
219 w := want(x, y, z)
220 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
221 })
222 }
223
224
225 func testInt64x8Ternary(t *testing.T, f func(_, _, _ archsimd.Int64x8) archsimd.Int64x8, want func(_, _, _ []int64) []int64) {
226 n := 8
227 t.Helper()
228 forSliceTriple(t, int64s, n, func(x, y, z []int64) bool {
229 t.Helper()
230 a := archsimd.LoadInt64x8(x)
231 b := archsimd.LoadInt64x8(y)
232 c := archsimd.LoadInt64x8(z)
233 g := make([]int64, n)
234 f(a, b, c).Store(g)
235 w := want(x, y, z)
236 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
237 })
238 }
239
240
241 func testUint8x64Ternary(t *testing.T, f func(_, _, _ archsimd.Uint8x64) archsimd.Uint8x64, want func(_, _, _ []uint8) []uint8) {
242 n := 64
243 t.Helper()
244 forSliceTriple(t, uint8s, n, func(x, y, z []uint8) bool {
245 t.Helper()
246 a := archsimd.LoadUint8x64(x)
247 b := archsimd.LoadUint8x64(y)
248 c := archsimd.LoadUint8x64(z)
249 g := make([]uint8, n)
250 f(a, b, c).Store(g)
251 w := want(x, y, z)
252 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
253 })
254 }
255
256
257 func testUint16x32Ternary(t *testing.T, f func(_, _, _ archsimd.Uint16x32) archsimd.Uint16x32, want func(_, _, _ []uint16) []uint16) {
258 n := 32
259 t.Helper()
260 forSliceTriple(t, uint16s, n, func(x, y, z []uint16) bool {
261 t.Helper()
262 a := archsimd.LoadUint16x32(x)
263 b := archsimd.LoadUint16x32(y)
264 c := archsimd.LoadUint16x32(z)
265 g := make([]uint16, n)
266 f(a, b, c).Store(g)
267 w := want(x, y, z)
268 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
269 })
270 }
271
272
273 func testUint32x16Ternary(t *testing.T, f func(_, _, _ archsimd.Uint32x16) archsimd.Uint32x16, want func(_, _, _ []uint32) []uint32) {
274 n := 16
275 t.Helper()
276 forSliceTriple(t, uint32s, n, func(x, y, z []uint32) bool {
277 t.Helper()
278 a := archsimd.LoadUint32x16(x)
279 b := archsimd.LoadUint32x16(y)
280 c := archsimd.LoadUint32x16(z)
281 g := make([]uint32, n)
282 f(a, b, c).Store(g)
283 w := want(x, y, z)
284 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
285 })
286 }
287
288
289 func testUint64x8Ternary(t *testing.T, f func(_, _, _ archsimd.Uint64x8) archsimd.Uint64x8, want func(_, _, _ []uint64) []uint64) {
290 n := 8
291 t.Helper()
292 forSliceTriple(t, uint64s, n, func(x, y, z []uint64) bool {
293 t.Helper()
294 a := archsimd.LoadUint64x8(x)
295 b := archsimd.LoadUint64x8(y)
296 c := archsimd.LoadUint64x8(z)
297 g := make([]uint64, n)
298 f(a, b, c).Store(g)
299 w := want(x, y, z)
300 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
301 })
302 }
303
304
305 func testFloat32x16Ternary(t *testing.T, f func(_, _, _ archsimd.Float32x16) archsimd.Float32x16, want func(_, _, _ []float32) []float32) {
306 n := 16
307 t.Helper()
308 forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
309 t.Helper()
310 a := archsimd.LoadFloat32x16(x)
311 b := archsimd.LoadFloat32x16(y)
312 c := archsimd.LoadFloat32x16(z)
313 g := make([]float32, n)
314 f(a, b, c).Store(g)
315 w := want(x, y, z)
316 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
317 })
318 }
319
320
321 func testFloat64x8Ternary(t *testing.T, f func(_, _, _ archsimd.Float64x8) archsimd.Float64x8, want func(_, _, _ []float64) []float64) {
322 n := 8
323 t.Helper()
324 forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
325 t.Helper()
326 a := archsimd.LoadFloat64x8(x)
327 b := archsimd.LoadFloat64x8(y)
328 c := archsimd.LoadFloat64x8(z)
329 g := make([]float64, n)
330 f(a, b, c).Store(g)
331 w := want(x, y, z)
332 return checkSlicesLogInput(t, g, w, 0.0, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
333 })
334 }
335
336
337
338 func testFloat32x8TernaryFlaky(t *testing.T, f func(x, y, z archsimd.Float32x8) archsimd.Float32x8, want func(x, y, z []float32) []float32, flakiness float64) {
339 n := 8
340 t.Helper()
341 forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
342 t.Helper()
343 a := archsimd.LoadFloat32x8(x)
344 b := archsimd.LoadFloat32x8(y)
345 c := archsimd.LoadFloat32x8(z)
346 g := make([]float32, n)
347 f(a, b, c).Store(g)
348 w := want(x, y, z)
349 return checkSlicesLogInput(t, g, w, flakiness, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
350 })
351 }
352
353
354
355 func testFloat64x4TernaryFlaky(t *testing.T, f func(x, y, z archsimd.Float64x4) archsimd.Float64x4, want func(x, y, z []float64) []float64, flakiness float64) {
356 n := 4
357 t.Helper()
358 forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
359 t.Helper()
360 a := archsimd.LoadFloat64x4(x)
361 b := archsimd.LoadFloat64x4(y)
362 c := archsimd.LoadFloat64x4(z)
363 g := make([]float64, n)
364 f(a, b, c).Store(g)
365 w := want(x, y, z)
366 return checkSlicesLogInput(t, g, w, flakiness, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
367 })
368 }
369
370
371
372 func testFloat32x16TernaryFlaky(t *testing.T, f func(x, y, z archsimd.Float32x16) archsimd.Float32x16, want func(x, y, z []float32) []float32, flakiness float64) {
373 n := 16
374 t.Helper()
375 forSliceTriple(t, float32s, n, func(x, y, z []float32) bool {
376 t.Helper()
377 a := archsimd.LoadFloat32x16(x)
378 b := archsimd.LoadFloat32x16(y)
379 c := archsimd.LoadFloat32x16(z)
380 g := make([]float32, n)
381 f(a, b, c).Store(g)
382 w := want(x, y, z)
383 return checkSlicesLogInput(t, g, w, flakiness, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
384 })
385 }
386
387
388
389 func testFloat64x8TernaryFlaky(t *testing.T, f func(x, y, z archsimd.Float64x8) archsimd.Float64x8, want func(x, y, z []float64) []float64, flakiness float64) {
390 n := 8
391 t.Helper()
392 forSliceTriple(t, float64s, n, func(x, y, z []float64) bool {
393 t.Helper()
394 a := archsimd.LoadFloat64x8(x)
395 b := archsimd.LoadFloat64x8(y)
396 c := archsimd.LoadFloat64x8(z)
397 g := make([]float64, n)
398 f(a, b, c).Store(g)
399 w := want(x, y, z)
400 return checkSlicesLogInput(t, g, w, flakiness, func() { t.Helper(); t.Logf("x=%v", x); t.Logf("y=%v", y); t.Logf("z=%v", z) })
401 })
402 }
403
View as plain text