xref: /freebsd/contrib/llvm-project/llvm/lib/Target/ARC/ARCInstrFormats.td (revision 13ec1e3155c7e9bf037b12af186351b7fa9b9450)
1//===- ARCInstrFormats.td - ARC Instruction Formats --------*- tablegen -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9//===----------------------------------------------------------------------===//
10// Instruction format superclass
11//===----------------------------------------------------------------------===//
12
13class Encoding64 {
14  field bits<64> Inst;
15  field bits<64> SoftFail = 0;
16}
17
18// Address operands
19
20class immU<int BSz> : Operand<i32>, PatLeaf<(imm),
21    "\n    return isUInt<"#BSz#">(N->getSExtValue());"> {
22}
23
24def immU6 : immU<6>;
25
26class immS<int BSz> : Operand<i32>, PatLeaf<(imm),
27    "\n    return isInt<"#BSz#">(N->getSExtValue());"> {
28  let DecoderMethod = "DecodeSignedOperand<"#BSz#">";
29}
30
31// e.g. s3 field may encode the signed integers values -1 .. 6
32// using binary codes 111, 000, 001, 010, 011, 100, 101, and 110, respectively
33class immC<int BSz> : Operand<i32>, PatLeaf<(imm),
34    "\n    return isInt<"#BSz#">(N->getSExtValue());"> {
35  let DecoderMethod = "DecodeFromCyclicRange<"#BSz#">";
36}
37
38def MEMii : Operand<i32> {
39  let MIOperandInfo = (ops i32imm, i32imm);
40}
41
42def MEMrs9 : Operand<iAny> {
43  let MIOperandInfo = (ops GPR32:$B, immS<9>:$S9);
44  let PrintMethod = "printMemOperandRI";
45  let DecoderMethod = "DecodeMEMrs9";
46}
47
48def MEMrlimm : Operand<iAny> {
49  let MIOperandInfo = (ops GPR32:$B, i32imm:$LImm);
50  let PrintMethod = "printMemOperandRI";
51  let DecoderMethod = "DecodeMEMrlimm";
52}
53
54def GPR32Reduced : Operand<iAny> {
55  let DecoderMethod = "DecodeGBR32ShortRegister";
56}
57
58// Helper classes for load/store instructions
59class DataSizeMode<bits<2> mode, string instSfx, string asmSfx> {
60  bits<2> Value = mode;
61  string  InstSuffix = instSfx;
62  string  AsmSuffix  = asmSfx;
63}
64class ExtMode<bit mode, string instSfx, string asmSfx> {
65  bit     Value = mode;
66  string  InstSuffix = instSfx;
67  string  AsmSuffix  = asmSfx;
68}
69
70class AddrMode<bits<2> mode, string instSfx, string asmSfx> {
71  bits<2> Value = mode;
72  string  InstSuffix = instSfx;
73  string  AsmSuffix  = asmSfx;
74}
75
76class CacheMode<bit mode, string instSfx, string asmSfx> {
77  bit     Value = mode;
78  string  InstSuffix = instSfx;
79  string  AsmSuffix  = asmSfx;
80}
81
82def ByteSM : DataSizeMode<0b01, "B", "b">;
83def HalfSM : DataSizeMode<0b10, "H", "h">;
84def WordSM : DataSizeMode<0b00,  "",  "">;
85
86def NoEM      : ExtMode<0,   "",   "">;
87def SignedEM  : ExtMode<1, "_X", ".x">;
88
89def NoAM      : AddrMode<0b00, "", "">;
90def PreIncAM  : AddrMode<0b01, "_AW", ".aw">;
91def PostIncAM : AddrMode<0b10, "_AB", ".ab">;
92
93def NoCC       : CacheMode<0b0,    "",    "">;
94def UncachedCC : CacheMode<0b1, "_DI", ".di">;
95
96class InstARC<int sz, dag outs, dag ins, string asmstr, list<dag> pattern>
97    : Instruction, Encoding64 {
98
99  let Namespace = "ARC";
100  dag OutOperandList = outs;
101  dag InOperandList = ins;
102  let AsmString = asmstr;
103  let Pattern = pattern;
104  let Size = sz;
105
106  // Load/Store instruction properties
107  DataSizeMode ZZ = WordSM;
108  ExtMode X = NoEM;
109  AddrMode AA = NoAM;
110  CacheMode DI = NoCC;
111
112  // Field used for relation models
113  string BaseOpcode = "";
114
115  //TSFlags
116  let TSFlags{1-0} = AA.Value;
117}
118
119// ARC pseudo instructions format
120class PseudoInstARC<dag outs, dag ins, string asmstr, list<dag> pattern>
121   : InstARC<0, outs, ins, asmstr, pattern> {
122  let isPseudo = 1;
123}
124
125//===----------------------------------------------------------------------===//
126// Instruction formats
127//===----------------------------------------------------------------------===//
128
129// All 32-bit ARC instructions have a 5-bit "major" opcode class designator
130// in bits 27-31.
131//
132// Some general naming conventions:
133// N  - Delay Slot bit.  ARC v2 branch instructions have an optional delay slot
134//      which is encoded with this bit.  When set, a delay slot exists.
135// cc - Condition code.
136// SX - Signed X-bit immediate.
137// UX - Unsigned X-bit immediate.
138//
139// [ABC] - 32-bit register operand.  These are 6-bit fields.  This encodes the
140//         standard 32 general purpose registers, and allows use of additional
141//         (extension) registers.  This also encodes an instruction that uses
142//         a 32-bit Long Immediate (LImm), using 0x3e==62 as the field value.
143//         This makes 32-bit format instructions with Long Immediates
144//         64-bit instructions, with the Long Immediate in bits 32-63.
145// A - Inst[5-0] = A[5-0], when the format has A.  A is always a register.
146// B - Inst[14-12] = B[5-3], Inst[26-24] = B[2-0], when the format has B.
147//     B is always a register.
148// C - Inst[11-6] = C[5-0], when the format has C.  C can either be a register,
149//     or a 6-bit unsigned immediate (immU6), depending on the format.
150// F - Many instructions specify a flag bit. When set, the result of these
151//     instructions will set the ZNCV flags of the STATUS32 register
152//     (Zero/Negative/Carry/oVerflow).
153
154// Branch Instructions.
155class F32_BR<bits<5> major, dag outs, dag ins, bit b16, string asmstr,
156             list<dag> pattern> :
157  InstARC<4, outs, ins, asmstr, pattern> {
158  bit N;
159
160  let Inst{31-27} = major;
161  let Inst{16} = b16;
162  let Inst{5} = N;
163}
164
165class F32_BR_COND<bits<5> major, dag outs, dag ins, bit b16, string asmstr,
166                  list<dag> pattern> :
167  F32_BR<major, outs, ins, b16, asmstr, pattern> {
168  bits<21> S21; // 2-byte aligned 21-bit byte-offset.
169  bits<5> cc;
170  let Inst{26-18} = S21{10-2};
171  let Inst{15-6} = S21{20-11};
172  let Inst{4-0} = cc;
173}
174
175class F32_BR_UCOND_FAR<bits<5> major, dag outs, dag ins, bit b16, string asmstr,
176                       list<dag> pattern> :
177  F32_BR<major, outs, ins, b16, asmstr, pattern> {
178  bits<25> S25; // 2-byte aligned 25-bit byte-offset.
179  let Inst{26-18} = S25{10-2};
180  let Inst{15-6} = S25{20-11};
181  let Inst{4} = 0;
182  let Inst{3-0} = S25{24-21};
183}
184
185class F32_BR0_COND<dag outs, dag ins, string asmstr, list<dag> pat> :
186  F32_BR_COND<0b00000, outs, ins, 0, asmstr, pat> {
187  let Inst{17} = S21{1};
188}
189
190// Branch targets are 2-byte aligned, so S25[0] is implied 0.
191// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0   |
192// |S25[10-1]                    | 1|S25[20-11]               |N|0|S25[24-21]|
193class F32_BR0_UCOND_FAR<dag outs, dag ins, string asmstr, list<dag> pat> :
194  F32_BR_UCOND_FAR<0b00000, outs, ins, 1, asmstr, pat> {
195  let Inst{17} = S25{1};
196}
197
198// BL targets (functions) are 4-byte aligned, so S25[1-0] = 0b00
199// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0   |
200// |S25[10-2]                 | 1| 0|S25[20-11]               |N|0|S25[24-21]|
201class F32_BR1_BL_UCOND_FAR<dag outs, dag ins, string asmstr, list<dag> pat> :
202  F32_BR_UCOND_FAR<0b00001, outs, ins, 0, asmstr, pat> {
203  let Inst{17} = 1;
204}
205
206// BLcc targets have 21 bit range, and are 4-byte aligned.
207// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
208// |S25[10-2]                 | 0| 0|S25[20-11]               |N|0|cc     |
209class F32_BR1_BL_COND<dag outs, dag ins, string asmstr, list<dag> pat> :
210  F32_BR_COND<0b00001, outs, ins, 0, asmstr, pat> {
211  let Inst{17} = 0;
212}
213
214// BRcc targets have limited 9-bit range.  These are for compare and branch
215// in single instruction.  Their targets are 2-byte aligned.  They also use
216// a different (3-bit) set of condition codes.
217// |26|25|24|23|22|21|20|19|18|17|16|15   |14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
218// |B[2-0]  |S9[7-1]             | 1|S9[8]|B[5-3]  |C            |N|u|0|cc   |
219class F32_BR1_BCC<dag outs, dag ins, string asmstr, bit IsU6,
220                  list<dag> pattern> :
221  InstARC<4, outs, ins, asmstr, pattern> {
222
223  bits<3> cc;
224  bits<6> B;
225  bits<6> C;
226  bit N;
227  bits<9> S9; // 2-byte aligned 9-bit byte-offset.
228
229  let Inst{31-27} = 0b00001;
230  let Inst{26-24} = B{2-0};
231  let Inst{23-17} = S9{7-1};
232  let Inst{16} = 1;
233  let Inst{15} = S9{8};
234  let Inst{14-12} = B{5-3};
235  let Inst{11-6} = C;
236  let Inst{5} = N;
237  let Inst{4} = IsU6;
238  let Inst{3} = 0;
239  let Inst{2-0} = cc;
240}
241
242// General operations instructions.
243// Single Operand Instructions.  Inst[5-0] specifies the specific operation
244// for this format.
245// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
246// |B[2-0]  | 0| 0| 1| 0| 1| 1| 1| 1| F|B[5-3]  |C            |subop      |
247class F32_SOP_RR<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
248                 string asmstr, list<dag> pattern> :
249  InstARC<4, outs, ins, asmstr, pattern> {
250
251  bits<6> C;
252  bits<6> B;
253
254  let Inst{31-27} = major;
255  let Inst{26-24} = B{2-0};
256  let Inst{23-22} = 0b00;
257  let Inst{21-16} = 0b101111;
258  let Inst{15} = F;
259  let Inst{14-12} = B{5-3};
260  let Inst{11-6} = C;
261  let Inst{5-0} = subop;
262}
263
264// Single Operand Immediate Instructions.
265// 1-register, unsigned 6-bit immediate Single Operand instruction with
266// condition code.
267// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
268// |B[2-0]  | 1| 1|            subop| F|B[5-3]  |U6           |1|cc       |
269class F32_SOP_CC_RU6<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
270                     string asmstr, list<dag> pattern> :
271  InstARC<4, outs, ins, asmstr, pattern> {
272
273  bits<5> cc;
274  bits<6> U6;
275  bits<6> B;
276
277  let Inst{31-27} = major;
278  let Inst{26-24} = B{2-0};
279  let Inst{23-22} = 0b11;
280  let Inst{21-16} = subop;
281  let Inst{15} = F;
282  let Inst{14-12} = B{5-3};
283  let Inst{11-6} = U6;
284  let Inst{5} = 1;
285  let Inst{4-0} = cc;
286
287  let DecoderMethod = "DecodeCCRU6Instruction";
288}
289
290// Dual Operand Instructions.  Inst[21-16] specifies the specific operation
291// for this format.
292
293// 3-register Dual Operand instruction.
294// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
295// |B[2-0]  | 0| 0|            subop| F|B[5-3]  |C            |A          |
296class F32_DOP_RR<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
297                 string asmstr, list<dag> pattern> :
298  InstARC<4, outs, ins, asmstr, pattern> {
299  bits<6> C;
300  bits<6> B;
301  bits<6> A;
302
303  let Inst{31-27} = major;
304  let Inst{26-24} = B{2-0};
305  let Inst{23-22} = 0b00;
306  let Inst{21-16} = subop;
307  let Inst{15} = F;
308  let Inst{14-12} = B{5-3};
309  let Inst{11-6} = C;
310  let Inst{5-0} = A;
311}
312
313// Conditional Dual Operand instruction.  This instruction uses B as the
314// first 2 operands (i.e, add.cc B, B, C).
315// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
316// |B[2-0]  | 1| 1|            subop| F|B[5-3]  |C            |A          |
317class F32_DOP_CC_RR<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
318                    string asmstr, list<dag> pattern> :
319  InstARC<4, outs, ins, asmstr, pattern> {
320  bits<5> cc;
321  bits<6> C;
322  bits<6> B;
323
324  let Inst{31-27} = major;
325  let Inst{26-24} = B{2-0};
326  let Inst{23-22} = 0b11;
327  let Inst{21-16} = subop;
328  let Inst{15} = F;
329  let Inst{14-12} = B{5-3};
330  let Inst{11-6} = C;
331  let Inst{5} = 0;
332  let Inst{4-0} = cc;
333}
334
335
336// 2-register, unsigned 6-bit immediate Dual Operand instruction.
337// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
338// |B[2-0]  | 0| 1|            subop| F|B[5-3]  |U6           |A          |
339class F32_DOP_RU6<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
340                  string asmstr, list<dag> pattern> :
341  InstARC<4, outs, ins, asmstr, pattern> {
342  bits<6> U6;
343  bits<6> B;
344  bits<6> A;
345
346  let Inst{31-27} = major;
347  let Inst{26-24} = B{2-0};
348  let Inst{23-22} = 0b01;
349  let Inst{21-16} = subop;
350  let Inst{15} = F;
351  let Inst{14-12} = B{5-3};
352  let Inst{11-6} = U6;
353  let Inst{5-0} = A;
354}
355
356// 2-register, unsigned 6-bit immediate Dual Operand instruction with
357// condition code. This instruction uses B as the first 2 operands
358// (i.e, add.cc B, B, u6).
359// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
360// |B[2-0]  | 1| 1|            subop| F|B[5-3]  |U6           |1|cc       |
361class F32_DOP_CC_RRU6<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
362                      string asmstr, list<dag> pattern> :
363  InstARC<4, outs, ins, asmstr, pattern> {
364  bits<5> cc;
365  bits<6> U6;
366  bits<6> B;
367  bits<6> A;
368
369  let Inst{31-27} = major;
370  let Inst{26-24} = B{2-0};
371  let Inst{23-22} = 0b11;
372  let Inst{21-16} = subop;
373  let Inst{15} = F;
374  let Inst{14-12} = B{5-3};
375  let Inst{11-6} = U6;
376  let Inst{5} = 1;
377  let Inst{4-0} = cc;
378}
379
380// 2-register, signed 12-bit immediate Dual Operand instruction.
381// This instruction uses B as the first 2 operands (i.e., add B, B, -128).
382// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
383// |B[2-0]  | 1| 0|            subop| F|B[5-3]  |S12[5-0]     |S12[11-6]  |
384class F32_DOP_RS12<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
385                   string asmstr, list<dag> pattern> :
386  InstARC<4, outs, ins, asmstr, pattern> {
387  bits<6> B;
388  bits<12> S12;
389
390  let Inst{31-27} = major;
391  let Inst{26-24} = B{2-0};
392  let Inst{23-22} = 0b10;
393  let Inst{21-16} = subop;
394  let Inst{15} = F;
395  let Inst{14-12} = B{5-3};
396  let Inst{11-6} = S12{5-0};
397  let Inst{5-0} = S12{11-6};
398}
399
400// 2-register, 32-bit immediate (LImm) Dual Operand instruction.
401// This instruction has the 32-bit immediate in bits 32-63, and
402// 62 in the C register operand slot, but is otherwise F32_DOP_RR.
403class F32_DOP_RLIMM<bits<5> major, bits<6> subop, bit F, dag outs, dag ins,
404                    string asmstr, list<dag> pattern> :
405  InstARC<8, outs, ins, asmstr, pattern> {
406  bits<6> B;
407  bits<6> A;
408  bits<32> LImm;
409
410  let Inst{63-32} = LImm;
411  let Inst{31-27} = major;
412  let Inst{26-24} = B{2-0};
413  let Inst{23-22} = 0b00;
414  let Inst{21-16} = subop;
415  let Inst{15} = F;
416  let Inst{14-12} = B{5-3};
417  let Inst{11-6} = 0b111110;
418  let Inst{5-0} = A;
419}
420
421
422// Load and store instructions.
423// In addition to the previous naming conventions, load and store instructions
424// have:
425// di - Uncached bit.  When set, loads/stores bypass the cache and access
426//      memory directly.
427// aa - Incrementing mode.  Loads and stores can write-back address pre- or
428//      post- memory operation.
429// zz - Memory size (can be 8/16/32 bit load/store).
430//  x - Sign-extending.  When set, short loads can be sign-extended to 32-bits.
431// Loads and Stores support different memory addressing modes:
432// Base Register + Signed 9-bit Immediate: Both Load/Store.
433// LImm: Both Load/Store (Load/Store from a fixed 32-bit address).
434// Register + Register: Load Only.
435// Register + LImm: Load Only.
436
437// Register + S9 Load. (B + S9)
438// |26|25|24|23|22|21|20|19|18|17|16|15   |14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
439// |B[2-0]  |S9[7-0]                |S9[8]|B[5-3]  |di|aa  |zz |x|A          |
440class F32_LD_RS9<bit x, bits<2> aa, bit di, bits<2> zz, dag outs, dag ins,
441                 string asmstr, list<dag> pattern> :
442  InstARC<4, outs, ins, asmstr, pattern> {
443  bits<6> B;
444  bits<6> A;
445  bits<9> S9;
446
447  let Inst{31-27} = 0b00010;
448  let Inst{26-24} = B{2-0};
449  let Inst{23-16} = S9{7-0};
450  let Inst{15} = S9{8};
451  let Inst{14-12} = B{5-3};
452  let Inst{11} = di;
453  let Inst{10-9} = aa;
454  let Inst{8-7} = zz;
455  let Inst{6} = x;
456  let Inst{5-0} = A;
457
458  let BaseOpcode = "ld_rs9";
459}
460
461class F32_LD_ADDR<bit x, bits<2> aa, bit di, bits<2> zz, dag outs, dag ins,
462                  string asmstr, list<dag> pattern> :
463  F32_LD_RS9<x, aa, di, zz, outs, ins, asmstr, pattern> {
464  bits<15> addr;
465
466  let B = addr{14-9};
467  let S9 = addr{8-0};
468
469  let BaseOpcode = "ld_rs9";
470}
471
472
473// LImm Load.  The 32-bit immediate address is in Inst[63-32].
474// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
475// | 1| 1| 0| 0                        | 1| 1| 1|di| 0|0|zz |x|A          |
476class F32_LD_LIMM<bit x, bit di, bits<2> zz, dag outs, dag ins,
477                  string asmstr, list<dag> pattern> :
478  InstARC<8, outs, ins, asmstr, pattern> {
479  bits<6> LImmReg = 0b111110;
480  bits<6> A;
481  bits<32> LImm;
482
483  let Inst{63-32} = LImm;
484  let Inst{31-27} = 0b00010;
485  let Inst{26-24} = LImmReg{2-0};
486  let Inst{23-15} = 0;
487  let Inst{14-12} = LImmReg{5-3};
488  let Inst{11} = di;
489  let Inst{10-9} = 0;
490  let Inst{8-7} = zz;
491  let Inst{6} = x;
492  let Inst{5-0} = A;
493  let DecoderMethod = "DecodeLdLImmInstruction";
494
495  let BaseOpcode = "ld_limm";
496}
497
498// Register + LImm load.  The 32-bit immediate address is in Inst[63-32].
499// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5|4|3|2|1|0|
500// |B[2-0]  |aa   | 1| 1| 0|zz   | x|di|B[5-3]  | 1| 1|1|1|1|0|A          |
501class F32_LD_RLIMM<bit x, bits<2> aa, bit di, bits<2> zz, dag outs, dag ins,
502                   string asmstr, list<dag> pattern> :
503  InstARC<8, outs, ins, asmstr, pattern> {
504  bits<6> LImmReg = 0b111110;
505  bits<32> LImm;
506  bits<6> B;
507  bits<6> A;
508  bits<38> addr;
509  let B = addr{37-32};
510  let LImm = addr{31-0};
511
512  let Inst{63-32} = LImm;
513  let Inst{31-27} = 0b00100;
514  let Inst{26-24} = B{2-0};
515  let Inst{23-22} = aa;
516  let Inst{21-19} = 0b110;
517  let Inst{18-17} = zz;
518  let Inst{16} = x;
519  let Inst{15} = di;
520  let Inst{14-12} = B{5-3};
521  let Inst{11-6} = LImmReg;
522  let Inst{5-0} = A;
523  let DecoderMethod = "DecodeLdRLImmInstruction";
524
525  let BaseOpcode = "ld_rlimm";
526}
527
528// Register + S9 Store. (B + S9)
529// |26|25|24|23|22|21|20|19|18|17|16|15   |14|13|12|11|10|9|8|7|6|5 |4|3|2|1|0|
530// |B[2-0]  |S9[7-0]                |S9[8]|B[5-3]  |C            |di|aa |zz |0|
531class F32_ST_RS9<bits<2> aa, bit di, bits<2> zz, dag outs, dag ins,
532                 string asmstr, list<dag> pattern> :
533  InstARC<4, outs, ins, asmstr, pattern> {
534  bits<6> B;
535  bits<6> C;
536  bits<9> S9;
537
538  let Inst{31-27} = 0b00011;
539  let Inst{26-24} = B{2-0};
540  let Inst{23-16} = S9{7-0};
541  let Inst{15} = S9{8};
542  let Inst{14-12} = B{5-3};
543  let Inst{11-6} = C;
544  let Inst{5} = di;
545  let Inst{4-3} = aa;
546  let Inst{2-1} = zz;
547  let Inst{0} = 0;
548
549  let BaseOpcode = "st_rs9";
550}
551
552class F32_ST_ADDR<bits<2> aa, bit di, bits<2> zz, dag outs, dag ins,
553                  string asmstr, list<dag> pattern> :
554  F32_ST_RS9<aa, di, zz, outs, ins, asmstr, pattern> {
555  bits<15> addr;
556
557  let B = addr{14-9};
558  let S9 = addr{8-0};
559
560  let BaseOpcode = "st_rs9";
561}
562
563// LImm Store.
564// |26|25|24|23|22|21|20|19|18|17|16|15|14|13|12|11|10|9|8|7|6|5 |4|3|2|1|0|
565// | 1| 1| 0| 0                        | 1| 1| 1|C            |di|0|0|zz |0|
566class F32_ST_LIMM<bit di, bits<2> zz, dag outs, dag ins,
567                  string asmstr, list<dag> pattern> :
568  InstARC<8, outs, ins, asmstr, pattern> {
569  bits<6> LImmReg = 0b111110;
570  bits<6> C;
571  bits<32> LImm;
572
573  let Inst{63-32} = LImm;
574  let Inst{31-27} = 0b00011;
575  let Inst{26-24} = LImmReg{2-0};
576  let Inst{23-15} = 0;
577  let Inst{14-12} = LImmReg{5-3};
578  let Inst{11-6} = C;
579  let Inst{5} = di;
580  let Inst{4-3} = 0;
581  let Inst{2-1} = zz;
582  let Inst{0} = 0;
583  let DecoderMethod = "DecodeStLImmInstruction";
584
585  let BaseOpcode = "st_limm";
586}
587
588// Compact Move/Load.
589// |10|9|8|7|6|5|4|3|2|1|0|
590// |      |h    |   |i|H  |
591class F16_COMPACT<bits<1> i, dag outs, dag ins,
592                 string asmstr> :
593  InstARC<2, outs, ins, asmstr, []> {
594
595  bits<5> h;
596
597  let Inst{15-11} = 0b01000;
598  let Inst{7-5} = h{2-0};
599  let Inst{2} = i;
600  let Inst{1-0} = h{4-3};
601}
602
603// Compact Load/Add/Sub.
604class F16_LD_ADD_SUB<dag outs, dag ins, string asmstr> :
605  InstARC<2, outs, ins, asmstr, []> {
606
607  bits<3> b;
608  let Inst{15-11} = 0b01001;
609  let Inst{10-8} = b;
610}
611
612class F16_LD_SUB<bit i, string asmstr> :
613  F16_LD_ADD_SUB<(outs GPR32:$a), (ins GPR32:$b, GPR32:$c),
614  asmstr> {
615
616  bits<3> a;
617  bits<3> c;
618
619  let Inst{7-5} = c;
620  let Inst{4} = i;
621  let Inst{3} = 0;
622  let Inst{2-0} = a;
623}
624
625class F16_ADD :
626  F16_LD_ADD_SUB<(outs GPR32:$r), (ins GPR32:$b, immU<6>:$u6),
627  "add_s\t$r, $b, $u6"> {
628
629  bit r;
630  bits<6> u6;
631
632  let Inst{7} = r;
633  let Inst{6-4} = u6{5-3};
634  let Inst{3} = 1;
635  let Inst{2-0} = u6{2-0};
636}
637
638// Compact Load/Store.
639class F16_LD_ST_1<dag outs, dag ins, string asmstr> :
640  InstARC<2, outs, ins, asmstr, []> {
641
642  let Inst{15-11} = 0b01010;
643}
644
645class F16_LD_ST_s11<bit i, string asmstr> :
646  F16_LD_ST_1<(outs), (ins immS<11>:$s11), asmstr> {
647
648  bits<11> s11;
649
650  let Inst{10-5} = s11{10-5};
651  let Inst{4} = i;
652  let Inst{3} = 0;
653  let Inst{2-0} = s11{4-2};
654  let s11{1-0} = 0b00;
655}
656
657class F16_LDI_u7 :
658  F16_LD_ST_1<(outs GPR32:$b), (ins immU<7>:$u7),
659  "ldi_s\t$b, [$u7]"> {
660
661  bits<3> b;
662  bits<7> u7;
663
664  let Inst{10-8} = b;
665  let Inst{7-4} = u7{6-3};
666  let Inst{3} = 1;
667  let Inst{2-0} = u7{2-0};
668}
669
670// Indexed Jump or Execute.
671class F16_JLI_EI<bit i, string asmstr> :
672  InstARC<2, (outs), (ins immU<10>:$u10),
673  !strconcat(asmstr, "\t$u10"), []> {
674
675  bits<10> u10;
676
677  let Inst{15-11} = 0b01011;
678  let Inst{10} = i;
679  let Inst{9-0} = u10;
680}
681
682// Load/Add Register-Register.
683class F16_LD_ADD_RR<bits<2> i, string asmstr> :
684  InstARC<2, (outs GPR32:$a), (ins GPR32:$b, GPR32:$c),
685  asmstr, []> {
686
687  bits<3> a;
688  bits<3> b;
689  bits<3> c;
690
691  let Inst{15-11} = 0b01100;
692  let Inst{10-8} = b;
693  let Inst{7-5} = c;
694  let Inst{4-3} = i;
695  let Inst{2-0} = a;
696}
697
698// Load/Add GP-Relative.
699class F16_GP_LD_ADD<bits<2> i, dag ins, string asmstr> :
700  InstARC<2, (outs), ins, asmstr, []> {
701
702  let Inst{15-11} = 0b11001;
703  let Inst{10-9} = i;
704}
705
706// Add/Sub/Shift Register-Immediate.
707// |10|9|8|7|6|5|4|3|2|1|0|
708// |b     |c    |i  |u    |
709class F16_ADD_IMM<bits<2> i, string asmstr> :
710  InstARC<2, (outs GPR32:$c), (ins GPR32:$b, immU<3>:$u3),
711  !strconcat(asmstr, "\t$c, $b, $u3"), []> {
712
713  bits<3> b;
714  bits<3> c;
715  bits<3> u3;
716
717  let Inst{15-11} = 0b01101;
718  let Inst{10-8} = b;
719  let Inst{7-5} = c;
720  let Inst{4-3} = i;
721  let Inst{2-0} = u3;
722}
723
724// Dual Register Operations.
725// |10|9|8|7|6|5|4|3|2|1|0|
726// |b/s   |h    |i    |H  |
727class F16_OP_HREG<bits<3> i, dag outs, dag ins, string asmstr> :
728  InstARC<2, outs, ins, asmstr, []> {
729
730  bits<3> b_s3;
731  bits<5> h;
732
733  let Inst{15-11} = 0b01110;
734  let Inst{10-8} = b_s3;
735  let Inst{7-5} = h{2-0};
736  let Inst{4-2} = i;
737  let Inst{1-0} = h{4-3};
738}
739
740class F16_OP_HREG30<bits<3> i, dag outs, dag ins, string asmstr> :
741  F16_OP_HREG<i, outs, ins, asmstr> {
742
743  bits<5> LImmReg = 0b11110;
744  let Inst{7-5} = LImmReg{2-0};
745  let Inst{1-0} = LImmReg{4-3};
746}
747
748class F16_OP_HREG_LIMM<bits<3> i, dag outs, dag ins, string asmstr> :
749  F16_OP_HREG30<i, outs, ins, asmstr> {
750
751  bits<32> LImm;
752  let Inst{47-16} = LImm;
753  let Size = 6;
754}
755
756// General compact DOP format.
757class F16_GEN_DOP_BASE<bits<5> i, dag outs, dag ins, string asmstr> :
758  InstARC<2, outs, ins, asmstr, []> {
759
760  bits<3> b;
761  bits<3> c;
762  let Inst{15-11} = 0b01111;
763  let Inst{10-8} = b;
764  let Inst{7-5} = c;
765  let Inst{4-0} = i;
766}
767
768class F16_GEN_DOP<bits<5> i, string asmstr> :
769  F16_GEN_DOP_BASE<i, (outs GPR32:$b), (ins GPR32:$c),
770  !strconcat(asmstr, "\t$b, $b, $c")>;
771
772class F16_GEN_DOP_NODST<bits<5> i, string asmstr> :
773  F16_GEN_DOP_BASE<i, (outs), (ins GPR32:$b, GPR32:$c),
774  !strconcat(asmstr, "\t$b, $c")>;
775
776class F16_GEN_DOP_SINGLESRC<bits<5> i, string asmstr> :
777  F16_GEN_DOP_BASE<i, (outs GPR32:$b), (ins GPR32:$c),
778  !strconcat(asmstr, "\t$b, $c")>;
779
780class F16_GEN_SOP_BASE<bits<3> i, dag outs, dag ins, string asmstr> :
781  F16_GEN_DOP_BASE<0b00000, outs, ins, asmstr> {
782
783  let c = i;
784}
785
786class F16_GEN_SOP<bits<3> i, string asmstr> :
787  F16_GEN_SOP_BASE<i, (outs), (ins GPR32:$b), asmstr>;
788
789class F16_GEN_ZOP<bits<3> i, string asmstr> :
790  F16_GEN_SOP_BASE<0b111, (outs), (ins), asmstr> {
791
792  let b = i;
793}
794
795// Compact Load/Store with Offset Format.
796class F16_LD_ST_OFF<bits<5> opc, dag outs, dag ins, string asmstr> :
797  InstARC<2, outs, ins, !strconcat(asmstr, "\t$c, [$b, $off]"), []> {
798
799  bits<3> b;
800  bits<3> c;
801  let Inst{15-11} = opc;
802  let Inst{10-8} = b;
803  let Inst{7-5} = c;
804}
805
806class F16_LD_ST_WORD_OFF<bits<5> opc, dag outs, dag ins, string asmstr> :
807  F16_LD_ST_OFF<opc, outs, ins, asmstr> {
808
809  bits<7> off;
810  let Inst{4-0} = off{6-2};
811  let off{1-0} = 0b00;
812}
813
814class F16_LD_ST_HALF_OFF<bits<5> opc, dag outs, dag ins, string asmstr> :
815  F16_LD_ST_OFF<opc, outs, ins, asmstr> {
816
817  bits<6> off;
818  let Inst{4-0} = off{5-1};
819  let off{0} = 0b0;
820}
821
822class F16_LD_ST_BYTE_OFF<bits<5> opc, dag outs, dag ins, string asmstr> :
823  F16_LD_ST_OFF<opc, outs, ins, asmstr> {
824
825  bits<5> off;
826  let Inst{4-0} = off;
827}
828
829// Shift/Subtract/Bit Immediate.
830// |10|9|8|7|6|5|4|3|2|1|0|
831// |b     |i    |u        |
832class F16_SH_SUB_BIT<bits<3> i, string asmstr> :
833  InstARC<2, (outs), (ins GPR32:$b, immU<5>:$u5), asmstr, []> {
834
835  bits<3> b;
836  bits<5> u5;
837
838  let Inst{15-11} = 0b10111;
839  let Inst{10-8} = b;
840  let Inst{7-5} = i;
841  let Inst{4-0} = u5;
842}
843
844class F16_SH_SUB_BIT_DST<bits<3> i, string asmstr> :
845  F16_SH_SUB_BIT<i, !strconcat(asmstr, "\t$b, $b, $u5")>;
846
847// 16-bit stack-based operations.
848// |10|9|8|7|6|5|4|3|2|1|0|
849// |b     |i    |u        |
850class F16_SP_OPS<bits<3> i,
851  dag outs, dag ins, string asmstr> :
852  InstARC<2, outs, ins, asmstr, []> {
853
854  bits<3> fieldB;
855  bits<5> fieldU;
856
857  let Inst{15-11} = 0b11000;
858  let Inst{10-8} = fieldB;
859  let Inst{7-5} = i;
860  let Inst{4-0} = fieldU;
861}
862
863class F16_SP_OPS_u7_aligned<bits<3> i,
864  dag outs, dag ins, string asmstr> :
865  F16_SP_OPS<i, outs, ins, asmstr> {
866
867  bits<3> b3;
868  bits<7> u7;
869
870  let fieldB = b3;
871  let fieldU = u7{6-2};
872  let u7{1-0} = 0b00;
873}
874
875class F16_SP_OPS_bconst<bits<3> b, string asmop> :
876  F16_SP_OPS_u7_aligned<0b101,
877  (outs), (ins immU<7>:$u7),
878  !strconcat(asmop, "\t%sp, %sp, $u7")> {
879
880  let fieldB = b;
881}
882
883class F16_SP_OPS_uconst<bits<3> i,
884  dag outs, dag ins, string asmop> :
885  F16_SP_OPS_u7_aligned<i, outs, ins,
886  !strconcat(asmop, "\t$b3")> {
887
888  let fieldU = 0b00001;
889}
890
891class F16_SP_OPS_buconst<bits<3> i, string asmop> :
892  F16_SP_OPS_u7_aligned<i, (outs), (ins),
893    !strconcat(asmop, "\t%blink")> {
894
895  let fieldB = 0x000;
896  let fieldU = 0b10001;
897}
898
899class F16_SP_LD<bits<3> i, string asmop> : F16_SP_OPS_u7_aligned<i,
900                         (outs GPR32Reduced:$b3), (ins immU<7>:$u7),
901                         !strconcat(asmop, "\t$b3, [%sp, $u7]")>;
902
903class F16_SP_ST<bits<3> i, string asmop> : F16_SP_OPS_u7_aligned<i,
904                         (outs), (ins GPR32Reduced:$b3, immU<7>:$u7),
905                         !strconcat(asmop, "\t$b3, [%sp, $u7]")>;
906
907// Compact MOV/ADD/CMP Immediate Format.
908class F16_OP_IMM<bits<5> opc, dag outs, dag ins, string asmstr> :
909  InstARC<2, outs, ins, asmstr, []> {
910
911  bits<3> b;
912  let Inst{15-11} = opc;
913  let Inst{10-8} = b;
914}
915
916class F16_OP_U7<bit i, string asmstr> :
917  F16_OP_IMM<0b11100, (outs GPR32:$b), (ins immU<7>:$u7), asmstr> {
918
919  bits<7> u7;
920  let Inst{7} = i;
921  let Inst{6-0} = u7;
922}
923
924// Special types for different instruction operands.
925def cmovpred : Operand<i32>, PredicateOp,
926               ComplexPattern<i32, 2, "SelectCMOVPred"> {
927  let MIOperandInfo = (ops i32imm, i32imm);
928  let PrintMethod = "printPredicateOperand";
929}
930
931def ccond : Operand<i32> {
932  let MIOperandInfo = (ops i32imm);
933  let PrintMethod = "printPredicateOperand";
934}
935
936def brccond : Operand<i32> {
937  let MIOperandInfo = (ops i32imm);
938  let PrintMethod = "printBRCCPredicateOperand";
939}
940
941// Branch/call targets of different offset sizes.
942class BCTarget<ValueType vt> : Operand<vt> {
943  let OperandType = "OPERAND_PCREL";
944}
945
946def btarget : BCTarget<OtherVT>;
947
948class BCTargetSigned<ValueType vt, int BSz> : BCTarget<vt> {
949  let DecoderMethod = "DecodeBranchTargetS<"#BSz#">";
950}
951
952class BranchTargetS<int BSz> : BCTargetSigned<OtherVT, BSz>;
953def btargetS7 : BranchTargetS<7>;
954def btargetS8 : BranchTargetS<8>;
955def btargetS9 : BranchTargetS<9>;
956def btargetS10 : BranchTargetS<10>;
957def btargetS13 : BranchTargetS<13>;
958def btargetS21 : BranchTargetS<21>;
959def btargetS25 : BranchTargetS<25>;
960
961class CallTargetS<int BSz> : BCTargetSigned<i32, BSz>;
962def calltargetS25: CallTargetS<25>;
963
964// Compact Branch on Compare Register with Zero.
965class F16_BCC_REG<bit i, string asmstr> :
966  InstARC<2, (outs), (ins GPR32:$b, btargetS8:$s8),
967  !strconcat(asmstr, "\t$b, 0, $s8"), []> {
968
969  bits<3> b;
970  bits<8> s8;
971
972  let Inst{15-11} = 0b11101;
973  let Inst{10-8} = b;
974  let Inst{7} = i;
975  let Inst{6-0} = s8{7-1};
976  let s8{0} = 0b0;
977}
978
979// Compact Branch Conditionally Format.
980class F16_BCC<bits<2> i, dag ins, string asmstr> :
981  InstARC<2, (outs), ins, asmstr, []> {
982
983  let Inst{15-11} = 0b11110;
984  let Inst{10-9} = i;
985}
986
987class F16_BCC_s10<bits<2> i, string asmstr> :
988  F16_BCC<i, (ins btargetS10:$s),
989  !strconcat(asmstr, "\t$s")> {
990
991  bits<10> s;
992  let Inst{8-0} = s{9-1};
993  let s{0} = 0b0;
994}
995
996class F16_BCC_s7<bits<3> i, string asmstr> :
997  F16_BCC<0b11, (ins btargetS7:$s),
998  !strconcat(asmstr, "\t$s")> {
999
1000  bits<7> s;
1001  let Inst{8-6} = i;
1002  let Inst{5-0} = s{6-1};
1003  let s{0} = 0b0;
1004}
1005