1 //===-- Nios2InstrFormats.td - Nios2 Instruction Formats ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 //===----------------------------------------------------------------------===//
11 // Describe NIOS2 instructions format
14 //===----------------------------------------------------------------------===//
16 // Format specifies the encoding used by the instruction. This is part of the
17 // ad-hoc solution used to emit machine instruction encodings by our machine
19 class Format<bits<6> val> {
23 def Pseudo : Format<0>;
24 // Nios2 R1 instr formats:
28 def FrmOther : Format<4>; // Instruction w/ a custom format
29 // Nios2 R2 instr 32-bit formats:
30 def FrmL26 : Format<5>; // corresponds to J format in R1
31 def FrmF2I16 : Format<6>; // corresponds to I format in R1
32 def FrmF2X4I12 : Format<7>;
33 def FrmF1X4I12 : Format<8>;
34 def FrmF1X4L17 : Format<9>;
35 def FrmF3X6L5 : Format<10>; // corresponds to R format in R1
36 def FrmF2X6L10 : Format<11>;
37 def FrmF3X6 : Format<12>; // corresponds to R format in R1
38 def FrmF3X8 : Format<13>; // corresponds to custom format in R1
39 // Nios2 R2 instr 16-bit formats:
40 def FrmI10 : Format<14>;
41 def FrmT1I7 : Format<15>;
42 def FrmT2I4 : Format<16>;
43 def FrmT1X1I6 : Format<17>;
44 def FrmX1I7 : Format<18>;
45 def FrmL5I4X1 : Format<19>;
46 def FrmT2X1L3 : Format<20>;
47 def FrmT2X1I3 : Format<21>;
48 def FrmT3X1 : Format<22>;
49 def FrmT2X3 : Format<23>;
50 def FrmF1X1 : Format<24>;
51 def FrmX2L5 : Format<25>;
52 def FrmF1I5 : Format<26>;
53 def FrmF2 : Format<27>;
55 //===----------------------------------------------------------------------===//
56 // Instruction Predicates:
57 //===----------------------------------------------------------------------===//
59 def isNios2r1 : Predicate<"Subtarget->isNios2r1()">;
60 def isNios2r2 : Predicate<"Subtarget->isNios2r2()">;
62 class PredicateControl {
63 // Predicates related to specific target CPU features
64 list<Predicate> FeaturePredicates = [];
65 // Predicates for the instruction group membership in given ISA
66 list<Predicate> InstrPredicates = [];
68 list<Predicate> Predicates = !listconcat(FeaturePredicates, InstrPredicates);
71 //===----------------------------------------------------------------------===//
72 // Base classes for 32-bit, 16-bit and pseudo instructions
73 //===----------------------------------------------------------------------===//
75 class Nios2Inst32<dag outs, dag ins, string asmstr, list<dag> pattern,
76 InstrItinClass itin, Format f>: Instruction,
81 let Namespace = "Nios2";
86 // Bottom 6 bits are the 'opcode' field
87 let Inst{5-0} = Opcode;
89 let OutOperandList = outs;
90 let InOperandList = ins;
92 let AsmString = asmstr;
93 let Pattern = pattern;
96 // Attributes specific to Nios2 instructions:
98 // TSFlags layout should be kept in sync with Nios2InstrInfo.h.
99 let TSFlags{5-0} = Form.Value;
100 let DecoderNamespace = "Nios2";
101 field bits<32> SoftFail = 0;
104 class Nios2Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern,
105 InstrItinClass Itin = IIPseudo>:
106 Nios2Inst32<outs, ins, asmstr, pattern, Itin, Pseudo> {
108 let isCodeGenOnly = 1;
112 //===----------------------------------------------------------------------===//
113 // Base classes for R1 and R2 instructions
114 //===----------------------------------------------------------------------===//
116 class Nios2R1Inst32<dag outs, dag ins, string asmstr, list<dag> pattern,
117 InstrItinClass itin, Format f>:
118 Nios2Inst32<outs, ins, asmstr, pattern, itin, f> {
119 let DecoderNamespace = "Nios2";
120 let InstrPredicates = [isNios2r1];
123 class Nios2R2Inst32<dag outs, dag ins, string asmstr, list<dag> pattern,
124 InstrItinClass itin, Format f>:
125 Nios2Inst32<outs, ins, asmstr, pattern, itin, f> {
126 let DecoderNamespace = "Nios2r2";
127 let InstrPredicates = [isNios2r2];
130 //===----------------------------------------------------------------------===//
131 // Format I instruction class in Nios2 : <|A|B|immediate|opcode|>
132 //===----------------------------------------------------------------------===//
134 class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
135 InstrItinClass itin>: Nios2R1Inst32<outs, ins, asmstr,
136 pattern, itin, FrmI> {
144 let Inst{31-27} = rA;
145 let Inst{26-22} = rB;
146 let Inst{21-6} = imm;
150 //===----------------------------------------------------------------------===//
151 // Format R instruction : <|A|B|C|opx|imm|opcode|>
152 //===----------------------------------------------------------------------===//
154 class FR<bits<6> opx, dag outs, dag ins, string asmstr, list<dag> pattern,
155 InstrItinClass itin>: Nios2R1Inst32<outs, ins, asmstr,
156 pattern, itin, FrmR> {
162 let Opcode = 0x3a; /* opcode is always 0x3a for R instr. */
164 let Inst{31-27} = rA;
165 let Inst{26-22} = rB;
166 let Inst{21-17} = rC;
167 let Inst{16-11} = opx; /* opx stands for opcode extension */
168 let Inst{10-6} = imm; /* optional 5-bit immediate value */
171 //===----------------------------------------------------------------------===//
172 // Format J instruction class in Nios2 : <|address|opcode|>
173 //===----------------------------------------------------------------------===//
175 class FJ<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
176 InstrItinClass itin>:
177 Nios2R1Inst32<outs, ins, asmstr, pattern, itin, FrmJ> {
180 let Inst{31-6} = addr;
183 //===----------------------------------------------------------------------===//
184 // Format F3X6 (R2) instruction : <|opx|RSV|C|B|A|opcode|>
185 //===----------------------------------------------------------------------===//
187 class F3X6<bits<6> opx, dag outs, dag ins, string asmstr, list<dag> pattern,
188 InstrItinClass itin>:
189 Nios2R2Inst32<outs, ins, asmstr, pattern, itin, FrmF3X6> {
195 let Opcode = 0x20; /* opcode is always 0x20 (OPX group) for F3X6 instr. */
197 let Inst{31-26} = opx; /* opx stands for opcode extension */
198 let Inst{25-21} = rsv;
199 let Inst{20-16} = rC;
200 let Inst{15-11} = rB;
204 //===----------------------------------------------------------------------===//
205 // Multiclasses for common instructions of both R1 and R2:
206 //===----------------------------------------------------------------------===//
208 // Multiclass for instructions that have R format in R1 and F3X6 format in R2
209 // and their opx values differ between R1 and R2
210 multiclass CommonInstr_R_F3X6_opx<bits<6> opxR1, bits<6> opxR2, dag outs,
211 dag ins, string asmstr, list<dag> pattern,
212 InstrItinClass itin> {
213 def NAME#_R1 : FR<opxR1, outs, ins, asmstr, pattern, itin>;
214 def NAME#_R2 : F3X6<opxR2, outs, ins, asmstr, pattern, itin>;
217 // Multiclass for instructions that have R format in R1 and F3X6 format in R2
218 // and their opx values are the same in R1 and R2
219 multiclass CommonInstr_R_F3X6<bits<6> opx, dag outs, dag ins, string asmstr,
220 list<dag> pattern, InstrItinClass itin> :
221 CommonInstr_R_F3X6_opx<opx, opx, outs, ins, asmstr, pattern, itin>;
223 // Multiclass for instructions that have I format in R1 and F2I16 format in R2
224 // and their op code values differ between R1 and R2
225 multiclass CommonInstr_I_F2I16_op<bits<6> opR1, bits<6> opR2, dag outs, dag ins,
226 string asmstr, list<dag> pattern,
227 InstrItinClass itin> {
228 def NAME#_R1 : FI<opR1, outs, ins, asmstr, pattern, itin>;
231 // Multiclass for instructions that have I format in R1 and F2I16 format in R2
232 // and their op code values are the same in R1 and R2
233 multiclass CommonInstr_I_F2I16<bits<6> op, dag outs, dag ins, string asmstr,
234 list<dag> pattern, InstrItinClass itin> :
235 CommonInstr_I_F2I16_op<op, op, outs, ins, asmstr, pattern, itin>;