Debian Codegraph @

reg/x86.go

raw symbols SCIP
1 package reg
2
3 // Register kinds.
4 const (
5 KindPseudo Kind = iota
6 KindGP
7 KindVector
8 KindOpmask
9 )
10
11 // Declare register families.
12 var (
13 Pseudo = &Family{Kind: KindPseudo}
14 GeneralPurpose = &Family{Kind: KindGP}
15 Vector = &Family{Kind: KindVector}
16 Opmask = &Family{Kind: KindOpmask}
17
18 Families = []*Family{
19 Pseudo,
20 GeneralPurpose,
21 Vector,
22 Opmask,
23 }
24 )
25
26 var familiesByKind = map[Kind]*Family{}
27
28 func init() {
29 for _, f := range Families {
30 familiesByKind[f.Kind] = f
31 }
32 }
33
34 // FamilyOfKind returns the Family of registers of the given kind, or nil if not found.
35 func FamilyOfKind(k Kind) *Family {
36 return familiesByKind[k]
37 }
38
39 // Pseudo registers.
40 var (
41 FramePointer = Pseudo.define(S0, 0, "FP")
42 ProgramCounter = Pseudo.define(S0, 0, "PC")
43 StaticBase = Pseudo.define(S0, 0, "SB")
44 StackPointer = Pseudo.define(S0, 0, "SP")
45 )
46
47 // GP provides additional methods for general purpose registers.
48 type GP interface {
49 As8() Register
50 As8L() Register
51 As8H() Register
52 As16() Register
53 As32() Register
54 As64() Register
55 }
56
57 // GPPhysical is a general-purpose physical register.
58 type GPPhysical interface {
59 Physical
60 GP
61 }
62
63 type gpp struct {
64 Physical
65 }
66
67 func newgpp(r Physical) GPPhysical { return gpp{Physical: r} }
68
69 func (p gpp) As8() Register { return newgpp(p.as(S8).(Physical)) }
70 func (p gpp) As8L() Register { return newgpp(p.as(S8L).(Physical)) }
71 func (p gpp) As8H() Register { return newgpp(p.as(S8H).(Physical)) }
72 func (p gpp) As16() Register { return newgpp(p.as(S16).(Physical)) }
73 func (p gpp) As32() Register { return newgpp(p.as(S32).(Physical)) }
74 func (p gpp) As64() Register { return newgpp(p.as(S64).(Physical)) }
75
76 // GPVirtual is a general-purpose virtual register.
77 type GPVirtual interface {
78 Virtual
79 GP
80 }
81
82 type gpv struct {
83 Virtual
84 }
85
86 func newgpv(v Virtual) GPVirtual { return gpv{Virtual: v} }
87
88 func (v gpv) As8() Register { return newgpv(v.as(S8).(Virtual)) }
89 func (v gpv) As8L() Register { return newgpv(v.as(S8L).(Virtual)) }
90 func (v gpv) As8H() Register { return newgpv(v.as(S8H).(Virtual)) }
91 func (v gpv) As16() Register { return newgpv(v.as(S16).(Virtual)) }
92 func (v gpv) As32() Register { return newgpv(v.as(S32).(Virtual)) }
93 func (v gpv) As64() Register { return newgpv(v.as(S64).(Virtual)) }
94
95 func gp(s Spec, id Index, name string, flags ...Info) GPPhysical {
96 r := newgpp(newregister(GeneralPurpose, s, id, name, flags...))
97 GeneralPurpose.add(r)
98 return r
99 }
100
101 // General purpose registers.
102 var (
103 // Low byte.
104 AL = gp(S8L, 0, "AL")
105 CL = gp(S8L, 1, "CL")
106 DL = gp(S8L, 2, "DL")
107 BL = gp(S8L, 3, "BL")
108
109 // High byte.
110 AH = gp(S8H, 0, "AH")
111 CH = gp(S8H, 1, "CH")
112 DH = gp(S8H, 2, "DH")
113 BH = gp(S8H, 3, "BH")
114
115 // 8-bit.
116 SPB = gp(S8, 4, "SP", Restricted)
117 BPB = gp(S8, 5, "BP", BasePointer)
118 SIB = gp(S8, 6, "SI")
119 DIB = gp(S8, 7, "DI")
120 R8B = gp(S8, 8, "R8")
121 R9B = gp(S8, 9, "R9")
122 R10B = gp(S8, 10, "R10")
123 R11B = gp(S8, 11, "R11")
124 R12B = gp(S8, 12, "R12")
125 R13B = gp(S8, 13, "R13")
126 R14B = gp(S8, 14, "R14")
127 R15B = gp(S8, 15, "R15")
128
129 // 16-bit.
130 AX = gp(S16, 0, "AX")
131 CX = gp(S16, 1, "CX")
132 DX = gp(S16, 2, "DX")
133 BX = gp(S16, 3, "BX")
134 SP = gp(S16, 4, "SP", Restricted)
135 BP = gp(S16, 5, "BP", BasePointer)
136 SI = gp(S16, 6, "SI")
137 DI = gp(S16, 7, "DI")
138 R8W = gp(S16, 8, "R8")
139 R9W = gp(S16, 9, "R9")
140 R10W = gp(S16, 10, "R10")
141 R11W = gp(S16, 11, "R11")
142 R12W = gp(S16, 12, "R12")
143 R13W = gp(S16, 13, "R13")
144 R14W = gp(S16, 14, "R14")
145 R15W = gp(S16, 15, "R15")
146
147 // 32-bit.
148 EAX = gp(S32, 0, "AX")
149 ECX = gp(S32, 1, "CX")
150 EDX = gp(S32, 2, "DX")
151 EBX = gp(S32, 3, "BX")
152 ESP = gp(S32, 4, "SP", Restricted)
153 EBP = gp(S32, 5, "BP", BasePointer)
154 ESI = gp(S32, 6, "SI")
155 EDI = gp(S32, 7, "DI")
156 R8L = gp(S32, 8, "R8")
157 R9L = gp(S32, 9, "R9")
158 R10L = gp(S32, 10, "R10")
159 R11L = gp(S32, 11, "R11")
160 R12L = gp(S32, 12, "R12")
161 R13L = gp(S32, 13, "R13")
162 R14L = gp(S32, 14, "R14")
163 R15L = gp(S32, 15, "R15")
164
165 // 64-bit.
166 RAX = gp(S64, 0, "AX")
167 RCX = gp(S64, 1, "CX")
168 RDX = gp(S64, 2, "DX")
169 RBX = gp(S64, 3, "BX")
170 RSP = gp(S64, 4, "SP", Restricted)
171 RBP = gp(S64, 5, "BP", BasePointer)
172 RSI = gp(S64, 6, "SI")
173 RDI = gp(S64, 7, "DI")
174 R8 = gp(S64, 8, "R8")
175 R9 = gp(S64, 9, "R9")
176 R10 = gp(S64, 10, "R10")
177 R11 = gp(S64, 11, "R11")
178 R12 = gp(S64, 12, "R12")
179 R13 = gp(S64, 13, "R13")
180 R14 = gp(S64, 14, "R14")
181 R15 = gp(S64, 15, "R15")
182 )
183
184 // Vec provides methods for vector registers.
185 type Vec interface {
186 AsX() Register
187 AsY() Register
188 AsZ() Register
189 }
190
191 // VecPhysical is a physical vector register.
192 type VecPhysical interface {
193 Physical
194 Vec
195 }
196
197 type vecp struct {
198 Physical
199 Vec
200 }
201
202 func newvecp(r Physical) VecPhysical { return vecp{Physical: r} }
203
204 func (p vecp) AsX() Register { return newvecp(p.as(S128).(Physical)) }
205 func (p vecp) AsY() Register { return newvecp(p.as(S256).(Physical)) }
206 func (p vecp) AsZ() Register { return newvecp(p.as(S512).(Physical)) }
207
208 // VecVirtual is a virtual vector register.
209 type VecVirtual interface {
210 Virtual
211 Vec
212 }
213
214 type vecv struct {
215 Virtual
216 Vec
217 }
218
219 func newvecv(v Virtual) VecVirtual { return vecv{Virtual: v} }
220
221 func (v vecv) AsX() Register { return newvecv(v.as(S128).(Virtual)) }
222 func (v vecv) AsY() Register { return newvecv(v.as(S256).(Virtual)) }
223 func (v vecv) AsZ() Register { return newvecv(v.as(S512).(Virtual)) }
224
225 func vec(s Spec, id Index, name string, flags ...Info) VecPhysical {
226 r := newvecp(newregister(Vector, s, id, name, flags...))
227 Vector.add(r)
228 return r
229 }
230
231 // Vector registers.
232 var (
233 // 128-bit.
234 X0 = vec(S128, 0, "X0")
235 X1 = vec(S128, 1, "X1")
236 X2 = vec(S128, 2, "X2")
237 X3 = vec(S128, 3, "X3")
238 X4 = vec(S128, 4, "X4")
239 X5 = vec(S128, 5, "X5")
240 X6 = vec(S128, 6, "X6")
241 X7 = vec(S128, 7, "X7")
242 X8 = vec(S128, 8, "X8")
243 X9 = vec(S128, 9, "X9")
244 X10 = vec(S128, 10, "X10")
245 X11 = vec(S128, 11, "X11")
246 X12 = vec(S128, 12, "X12")
247 X13 = vec(S128, 13, "X13")
248 X14 = vec(S128, 14, "X14")
249 X15 = vec(S128, 15, "X15")
250 X16 = vec(S128, 16, "X16")
251 X17 = vec(S128, 17, "X17")
252 X18 = vec(S128, 18, "X18")
253 X19 = vec(S128, 19, "X19")
254 X20 = vec(S128, 20, "X20")
255 X21 = vec(S128, 21, "X21")
256 X22 = vec(S128, 22, "X22")
257 X23 = vec(S128, 23, "X23")
258 X24 = vec(S128, 24, "X24")
259 X25 = vec(S128, 25, "X25")
260 X26 = vec(S128, 26, "X26")
261 X27 = vec(S128, 27, "X27")
262 X28 = vec(S128, 28, "X28")
263 X29 = vec(S128, 29, "X29")
264 X30 = vec(S128, 30, "X30")
265 X31 = vec(S128, 31, "X31")
266
267 // 256-bit.
268 Y0 = vec(S256, 0, "Y0")
269 Y1 = vec(S256, 1, "Y1")
270 Y2 = vec(S256, 2, "Y2")
271 Y3 = vec(S256, 3, "Y3")
272 Y4 = vec(S256, 4, "Y4")
273 Y5 = vec(S256, 5, "Y5")
274 Y6 = vec(S256, 6, "Y6")
275 Y7 = vec(S256, 7, "Y7")
276 Y8 = vec(S256, 8, "Y8")
277 Y9 = vec(S256, 9, "Y9")
278 Y10 = vec(S256, 10, "Y10")
279 Y11 = vec(S256, 11, "Y11")
280 Y12 = vec(S256, 12, "Y12")
281 Y13 = vec(S256, 13, "Y13")
282 Y14 = vec(S256, 14, "Y14")
283 Y15 = vec(S256, 15, "Y15")
284 Y16 = vec(S256, 16, "Y16")
285 Y17 = vec(S256, 17, "Y17")
286 Y18 = vec(S256, 18, "Y18")
287 Y19 = vec(S256, 19, "Y19")
288 Y20 = vec(S256, 20, "Y20")
289 Y21 = vec(S256, 21, "Y21")
290 Y22 = vec(S256, 22, "Y22")
291 Y23 = vec(S256, 23, "Y23")
292 Y24 = vec(S256, 24, "Y24")
293 Y25 = vec(S256, 25, "Y25")
294 Y26 = vec(S256, 26, "Y26")
295 Y27 = vec(S256, 27, "Y27")
296 Y28 = vec(S256, 28, "Y28")
297 Y29 = vec(S256, 29, "Y29")
298 Y30 = vec(S256, 30, "Y30")
299 Y31 = vec(S256, 31, "Y31")
300
301 // 512-bit.
302 Z0 = vec(S512, 0, "Z0")
303 Z1 = vec(S512, 1, "Z1")
304 Z2 = vec(S512, 2, "Z2")
305 Z3 = vec(S512, 3, "Z3")
306 Z4 = vec(S512, 4, "Z4")
307 Z5 = vec(S512, 5, "Z5")
308 Z6 = vec(S512, 6, "Z6")
309 Z7 = vec(S512, 7, "Z7")
310 Z8 = vec(S512, 8, "Z8")
311 Z9 = vec(S512, 9, "Z9")
312 Z10 = vec(S512, 10, "Z10")
313 Z11 = vec(S512, 11, "Z11")
314 Z12 = vec(S512, 12, "Z12")
315 Z13 = vec(S512, 13, "Z13")
316 Z14 = vec(S512, 14, "Z14")
317 Z15 = vec(S512, 15, "Z15")
318 Z16 = vec(S512, 16, "Z16")
319 Z17 = vec(S512, 17, "Z17")
320 Z18 = vec(S512, 18, "Z18")
321 Z19 = vec(S512, 19, "Z19")
322 Z20 = vec(S512, 20, "Z20")
323 Z21 = vec(S512, 21, "Z21")
324 Z22 = vec(S512, 22, "Z22")
325 Z23 = vec(S512, 23, "Z23")
326 Z24 = vec(S512, 24, "Z24")
327 Z25 = vec(S512, 25, "Z25")
328 Z26 = vec(S512, 26, "Z26")
329 Z27 = vec(S512, 27, "Z27")
330 Z28 = vec(S512, 28, "Z28")
331 Z29 = vec(S512, 29, "Z29")
332 Z30 = vec(S512, 30, "Z30")
333 Z31 = vec(S512, 31, "Z31")
334 )
335
336 // OpmaskPhysical is a opmask physical register.
337 type OpmaskPhysical interface {
338 Physical
339 }
340
341 type opmaskp struct {
342 Physical
343 }
344
345 func newopmaskp(r Physical) OpmaskPhysical { return opmaskp{Physical: r} }
346
347 // OpmaskVirtual is a virtual opmask register.
348 type OpmaskVirtual interface {
349 Virtual
350 }
351
352 type opmaskv struct {
353 Virtual
354 }
355
356 func newopmaskv(v Virtual) OpmaskVirtual { return opmaskv{Virtual: v} }
357
358 func opmask(s Spec, id Index, name string, flags ...Info) OpmaskPhysical {
359 r := newopmaskp(newregister(Opmask, s, id, name, flags...))
360 Opmask.add(r)
361 return r
362 }
363
364 // Opmask registers.
365 //
366 // Note that while K0 is a physical opmask register (it is a valid opmask source
367 // and destination operand), it cannot be used as an opmask predicate value
368 // because in that context K0 means "all true" or "no mask" regardless of the
369 // actual contents of the physical register. For that reason, K0 should never be
370 // assigned as a "general purpose" opmask register. However, it can be
371 // explicitly operated upon by name as non-predicate operand, for example to
372 // hold a constant or temporary value during calculations on other opmask
373 // registers.
374 var (
375 K0 = opmask(S64, 0, "K0", Restricted)
376 K1 = opmask(S64, 1, "K1")
377 K2 = opmask(S64, 2, "K2")
378 K3 = opmask(S64, 3, "K3")
379 K4 = opmask(S64, 4, "K4")
380 K5 = opmask(S64, 5, "K5")
381 K6 = opmask(S64, 6, "K6")
382 K7 = opmask(S64, 7, "K7")
383 )