1
2
3
4
5 package main
6
7 import (
8 "simd/archsimd/_gen/simdgen/types"
9 "slices"
10 "testing"
11 )
12
13 func TestCombineCPUFeatures(t *testing.T) {
14 cases := []struct {
15 a, b []string
16 want []string
17 }{
18 {[]string{"AVX"}, []string{"AVX512"}, []string{"AVX512"}},
19 {[]string{"AVX2"}, []string{"AVX512"}, []string{"AVX512"}},
20 {[]string{"AVX512"}, []string{"AVX512"}, []string{"AVX512"}},
21 {[]string{"AVX512VBMI"}, []string{"AVX512"}, []string{"AVX512VBMI"}},
22 {[]string{"AVX512"}, []string{"AVX512VBMI"}, []string{"AVX512VBMI"}},
23 {[]string{"FMA"}, []string{"AVX512"}, []string{"FMA", "AVX512"}},
24 {[]string{"FMA", "AVX"}, []string{"AVX512"}, []string{"FMA", "AVX512"}},
25 {nil, []string{"AVX512"}, []string{"AVX512"}},
26 }
27 for _, tc := range cases {
28 if got := combineCPUFeatures("amd64", tc.a, tc.b); !slices.Equal(got, tc.want) {
29 t.Errorf("combineCPUFeatures(%v, %v) = %v, want %v", tc.a, tc.b, got, tc.want)
30 }
31 }
32 }
33
34 func TestAddOperandCPUFeatures(t *testing.T) {
35 vreg := func(bits, goBits int) types.Operand {
36 return types.Operand{
37 Class: "vreg",
38 Bits: types.VectorSize{NRaw: bits},
39 GoBits: &goBits,
40 }
41 }
42 ops := []Operation{
43 {
44 rawOperation: types.RawOperation{
45 GOARCH: "amd64",
46 CPUFeature: "AVX",
47 Out: []types.Operand{vreg(128, 256)},
48 },
49 In: []types.Operand{vreg(128, 128)},
50 CPUFeature: "AVX",
51 },
52 {
53 rawOperation: types.RawOperation{
54 GOARCH: "amd64",
55 CPUFeature: "AVX",
56 Out: []types.Operand{vreg(256, 512)},
57 },
58 In: []types.Operand{vreg(256, 256)},
59 CPUFeature: "AVX",
60 },
61 }
62 addOperandCPUFeatures(ops)
63
64 if got := ops[0].CPUFeature; got != "AVX" {
65 t.Errorf("128->256 CPUFeature = %q, want AVX", got)
66 }
67 if got := ops[1].CPUFeature; got != "AVX512" {
68 t.Errorf("256->512 CPUFeature = %q, want AVX512", got)
69 }
70 if got := ops[1].rawOperation.CPUFeature; got != "AVX" {
71 t.Errorf("256->512 rawOperation.CPUFeature = %q, want AVX", got)
72 }
73 }
74
View as plain text