1
2
3
4
5 package cpu
6
7 const cacheLineSize = 256
8
9 func initOptions() {
10 options = []option{
11 {Name: "zarch", Feature: &S390X.HasZARCH, Required: true},
12 {Name: "stfle", Feature: &S390X.HasSTFLE, Required: true},
13 {Name: "ldisp", Feature: &S390X.HasLDISP, Required: true},
14 {Name: "eimm", Feature: &S390X.HasEIMM, Required: true},
15 {Name: "dfp", Feature: &S390X.HasDFP},
16 {Name: "etf3eh", Feature: &S390X.HasETF3EH},
17 {Name: "msa", Feature: &S390X.HasMSA},
18 {Name: "aes", Feature: &S390X.HasAES},
19 {Name: "aescbc", Feature: &S390X.HasAESCBC},
20 {Name: "aesctr", Feature: &S390X.HasAESCTR},
21 {Name: "aesgcm", Feature: &S390X.HasAESGCM},
22 {Name: "ghash", Feature: &S390X.HasGHASH},
23 {Name: "sha1", Feature: &S390X.HasSHA1},
24 {Name: "sha256", Feature: &S390X.HasSHA256},
25 {Name: "sha3", Feature: &S390X.HasSHA3},
26 {Name: "sha512", Feature: &S390X.HasSHA512},
27 {Name: "vx", Feature: &S390X.HasVX},
28 {Name: "vxe", Feature: &S390X.HasVXE},
29 }
30 }
31
32
33
34 func bitIsSet(bits []uint64, index uint) bool {
35 return bits[index/64]&((1<<63)>>(index%64)) != 0
36 }
37
38
39 type facility uint8
40
41 const (
42
43 zarch facility = 1
44 stflef facility = 7
45 ldisp facility = 18
46 eimm facility = 21
47
48
49 dfp facility = 42
50 etf3eh facility = 30
51
52
53 msa facility = 17
54 msa3 facility = 76
55 msa4 facility = 77
56 msa5 facility = 57
57 msa8 facility = 146
58 msa9 facility = 155
59
60
61 vx facility = 129
62 vxe facility = 135
63 vxe2 facility = 148
64 )
65
66
67
68
69 type facilityList struct {
70 bits [4]uint64
71 }
72
73
74 func (s *facilityList) Has(fs ...facility) bool {
75 if len(fs) == 0 {
76 panic("no facility bits provided")
77 }
78 for _, f := range fs {
79 if !bitIsSet(s.bits[:], uint(f)) {
80 return false
81 }
82 }
83 return true
84 }
85
86
87 type function uint8
88
89 const (
90
91 aes128 function = 18
92 aes192 function = 19
93 aes256 function = 20
94
95
96 sha1 function = 1
97 sha256 function = 2
98 sha512 function = 3
99 sha3_224 function = 32
100 sha3_256 function = 33
101 sha3_384 function = 34
102 sha3_512 function = 35
103 shake128 function = 36
104 shake256 function = 37
105
106
107 ghash function = 65
108 )
109
110
111
112
113 type queryResult struct {
114 bits [2]uint64
115 }
116
117
118 func (q *queryResult) Has(fns ...function) bool {
119 if len(fns) == 0 {
120 panic("no function codes provided")
121 }
122 for _, f := range fns {
123 if !bitIsSet(q.bits[:], uint(f)) {
124 return false
125 }
126 }
127 return true
128 }
129
130 func doinit() {
131 initS390Xbase()
132
133
134
135 if !haveAsmFunctions() {
136 return
137 }
138
139
140 if S390X.HasMSA {
141 aes := []function{aes128, aes192, aes256}
142
143
144 km, kmc := kmQuery(), kmcQuery()
145 S390X.HasAES = km.Has(aes...)
146 S390X.HasAESCBC = kmc.Has(aes...)
147 if S390X.HasSTFLE {
148 facilities := stfle()
149 if facilities.Has(msa4) {
150 kmctr := kmctrQuery()
151 S390X.HasAESCTR = kmctr.Has(aes...)
152 }
153 if facilities.Has(msa8) {
154 kma := kmaQuery()
155 S390X.HasAESGCM = kma.Has(aes...)
156 }
157 }
158
159
160 kimd := kimdQuery()
161 klmd := klmdQuery()
162 S390X.HasSHA1 = kimd.Has(sha1) && klmd.Has(sha1)
163 S390X.HasSHA256 = kimd.Has(sha256) && klmd.Has(sha256)
164 S390X.HasSHA512 = kimd.Has(sha512) && klmd.Has(sha512)
165 S390X.HasGHASH = kimd.Has(ghash)
166 sha3 := []function{
167 sha3_224, sha3_256, sha3_384, sha3_512,
168 shake128, shake256,
169 }
170 S390X.HasSHA3 = kimd.Has(sha3...) && klmd.Has(sha3...)
171 }
172 }
173
View as plain text