Add comment, clean up code. No functional change.
[oota-llvm.git] / lib / Target / Mips / MipsInstrFormats.td
1 //===-- MipsInstrFormats.td - Mips Instruction Formats -----*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 //===----------------------------------------------------------------------===//
11 //  Describe MIPS instructions format
12 //
13 //  CPU INSTRUCTION FORMATS
14 //
15 //  opcode  - operation code.
16 //  rs      - src reg.
17 //  rt      - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
18 //  rd      - dst reg, only used on 3 regs instr.
19 //  shamt   - only used on shift instructions, contains the shift amount.
20 //  funct   - combined with opcode field give us an operation code.
21 //
22 //===----------------------------------------------------------------------===//
23
24 // Format specifies the encoding used by the instruction.  This is part of the
25 // ad-hoc solution used to emit machine instruction encodings by our machine
26 // code emitter.
27 class Format<bits<4> val> {
28   bits<4> Value = val;
29 }
30
31 def Pseudo    : Format<0>;
32 def FrmR      : Format<1>;
33 def FrmI      : Format<2>;
34 def FrmJ      : Format<3>;
35 def FrmFR     : Format<4>;
36 def FrmFI     : Format<5>;
37 def FrmOther  : Format<6>; // Instruction w/ a custom format
38
39 // Generic Mips Format
40 class MipsInst<dag outs, dag ins, string asmstr, list<dag> pattern,
41                InstrItinClass itin, Format f>: Instruction
42 {
43   field bits<32> Inst;
44   Format Form = f;
45
46   let Namespace = "Mips";
47
48   let Size = 4;
49
50   bits<6> Opcode = 0;
51
52   // Top 6 bits are the 'opcode' field
53   let Inst{31-26} = Opcode;
54
55   let OutOperandList = outs;
56   let InOperandList  = ins;
57
58   let AsmString   = asmstr;
59   let Pattern     = pattern;
60   let Itinerary   = itin;
61
62   //
63   // Attributes specific to Mips instructions...
64   //
65   bits<4> FormBits = Form.Value;
66
67   // TSFlags layout should be kept in sync with MipsInstrInfo.h.
68   let TSFlags{3-0}   = FormBits;
69
70   let DecoderNamespace = "Mips";
71
72   field bits<32> SoftFail = 0;
73 }
74
75 // Mips32/64 Instruction Format
76 class InstSE<dag outs, dag ins, string asmstr, list<dag> pattern,
77              InstrItinClass itin, Format f>:
78   MipsInst<outs, ins, asmstr, pattern, itin, f> {
79   let Predicates = [HasStandardEncoding];
80 }
81
82 // Mips Pseudo Instructions Format
83 class MipsPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>:
84   MipsInst<outs, ins, asmstr, pattern, IIPseudo, Pseudo> {
85   let isCodeGenOnly = 1;
86   let isPseudo = 1;
87 }
88
89 // Mips32/64 Pseudo Instruction Format
90 class PseudoSE<dag outs, dag ins, string asmstr, list<dag> pattern>:
91   MipsPseudo<outs, ins, asmstr, pattern> {
92   let Predicates = [HasStandardEncoding];
93 }
94
95 //===----------------------------------------------------------------------===//
96 // Format R instruction class in Mips : <|opcode|rs|rt|rd|shamt|funct|>
97 //===----------------------------------------------------------------------===//
98
99 class FR<bits<6> op, bits<6> _funct, dag outs, dag ins, string asmstr,
100          list<dag> pattern, InstrItinClass itin>:
101   InstSE<outs, ins, asmstr, pattern, itin, FrmR>
102 {
103   bits<5>  rd;
104   bits<5>  rs;
105   bits<5>  rt;
106   bits<5>  shamt;
107   bits<6>  funct;
108
109   let Opcode = op;
110   let funct  = _funct;
111
112   let Inst{25-21} = rs;
113   let Inst{20-16} = rt;
114   let Inst{15-11} = rd;
115   let Inst{10-6}  = shamt;
116   let Inst{5-0}   = funct;
117 }
118
119 //===----------------------------------------------------------------------===//
120 // Format I instruction class in Mips : <|opcode|rs|rt|immediate|>
121 //===----------------------------------------------------------------------===//
122
123 class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
124          InstrItinClass itin>: InstSE<outs, ins, asmstr, pattern, itin, FrmI>
125 {
126   bits<5>  rt;
127   bits<5>  rs;
128   bits<16> imm16;
129
130   let Opcode = op;
131
132   let Inst{25-21} = rs;
133   let Inst{20-16} = rt;
134   let Inst{15-0}  = imm16;
135 }
136
137 class BranchBase<bits<6> op, dag outs, dag ins, string asmstr,
138                   list<dag> pattern, InstrItinClass itin>:
139   InstSE<outs, ins, asmstr, pattern, itin, FrmI>
140 {
141   bits<5>  rs;
142   bits<5>  rt;
143   bits<16> imm16;
144
145   let Opcode = op;
146
147   let Inst{25-21} = rs;
148   let Inst{20-16} = rt;
149   let Inst{15-0}  = imm16;
150 }
151
152 //===----------------------------------------------------------------------===//
153 // Format J instruction class in Mips : <|opcode|address|>
154 //===----------------------------------------------------------------------===//
155
156 class FJ<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
157          InstrItinClass itin>: InstSE<outs, ins, asmstr, pattern, itin, FrmJ>
158 {
159   bits<26> addr;
160
161   let Opcode = op;
162
163   let Inst{25-0} = addr;
164 }
165
166 //===----------------------------------------------------------------------===//
167 //
168 //  FLOATING POINT INSTRUCTION FORMATS
169 //
170 //  opcode  - operation code.
171 //  fs      - src reg.
172 //  ft      - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
173 //  fd      - dst reg, only used on 3 regs instr.
174 //  fmt     - double or single precision.
175 //  funct   - combined with opcode field give us an operation code.
176 //
177 //===----------------------------------------------------------------------===//
178
179 //===----------------------------------------------------------------------===//
180 // Format FR instruction class in Mips : <|opcode|fmt|ft|fs|fd|funct|>
181 //===----------------------------------------------------------------------===//
182
183 class FFR<bits<6> op, bits<6> _funct, bits<5> _fmt, dag outs, dag ins,
184           string asmstr, list<dag> pattern> :
185   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmFR>
186 {
187   bits<5>  fd;
188   bits<5>  fs;
189   bits<5>  ft;
190   bits<5>  fmt;
191   bits<6>  funct;
192
193   let Opcode = op;
194   let funct  = _funct;
195   let fmt    = _fmt;
196
197   let Inst{25-21} = fmt;
198   let Inst{20-16} = ft;
199   let Inst{15-11} = fs;
200   let Inst{10-6}  = fd;
201   let Inst{5-0}   = funct;
202 }
203
204 //===----------------------------------------------------------------------===//
205 // Format FI instruction class in Mips : <|opcode|base|ft|immediate|>
206 //===----------------------------------------------------------------------===//
207
208 class FFI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>:
209   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmFI>
210 {
211   bits<5>  ft;
212   bits<5>  base;
213   bits<16> imm16;
214
215   let Opcode = op;
216
217   let Inst{25-21} = base;
218   let Inst{20-16} = ft;
219   let Inst{15-0}  = imm16;
220 }
221
222 //===----------------------------------------------------------------------===//
223 // Compare instruction class in Mips : <|010001|fmt|ft|fs|0000011|condcode|>
224 //===----------------------------------------------------------------------===//
225
226 class FCC<bits<5> _fmt, dag outs, dag ins, string asmstr, list<dag> pattern> :
227   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
228 {
229   bits<5>  fs;
230   bits<5>  ft;
231   bits<4>  cc;
232   bits<5>  fmt;
233
234   let Opcode = 0x11;
235   let fmt    = _fmt;
236
237   let Inst{25-21} = fmt;
238   let Inst{20-16} = ft;
239   let Inst{15-11} = fs;
240   let Inst{10-6}  = 0;
241   let Inst{5-4}   = 0b11;
242   let Inst{3-0}   = cc;
243 }
244
245
246 class FCMOV<bits<1> _tf, dag outs, dag ins, string asmstr,
247             list<dag> pattern> :
248   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
249 {
250   bits<5>  rd;
251   bits<5>  rs;
252   bits<3>  cc;
253   bits<1>  tf;
254
255   let Opcode = 0;
256   let tf = _tf;
257
258   let Inst{25-21} = rs;
259   let Inst{20-18} = cc;
260   let Inst{17} = 0;
261   let Inst{16} = tf;
262   let Inst{15-11} = rd;
263   let Inst{10-6}  = 0;
264   let Inst{5-0}   = 1;
265 }
266
267 class FFCMOV<bits<5> _fmt, bits<1> _tf, dag outs, dag ins, string asmstr,
268              list<dag> pattern> :
269   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
270 {
271   bits<5>  fd;
272   bits<5>  fs;
273   bits<3>  cc;
274   bits<5>  fmt;
275   bits<1>  tf;
276
277   let Opcode = 17;
278   let fmt = _fmt;
279   let tf = _tf;
280
281   let Inst{25-21} = fmt;
282   let Inst{20-18} = cc;
283   let Inst{17} = 0;
284   let Inst{16} = tf;
285   let Inst{15-11} = fs;
286   let Inst{10-6}  = fd;
287   let Inst{5-0}   = 17;
288 }
289
290 // FP unary instructions without patterns.
291 class FFR1<bits<6> funct, bits<5> fmt, string opstr, string fmtstr,
292            RegisterClass DstRC, RegisterClass SrcRC> :
293   FFR<0x11, funct, fmt, (outs DstRC:$fd), (ins SrcRC:$fs),
294       !strconcat(opstr, ".", fmtstr, "\t$fd, $fs"), []> {
295   let ft = 0;
296 }
297
298 // FP unary instructions with patterns.
299 class FFR1P<bits<6> funct, bits<5> fmt, string opstr, string fmtstr,
300             RegisterClass DstRC, RegisterClass SrcRC, SDNode OpNode> :
301   FFR<0x11, funct, fmt, (outs DstRC:$fd), (ins SrcRC:$fs),
302       !strconcat(opstr, ".", fmtstr, "\t$fd, $fs"),
303       [(set DstRC:$fd, (OpNode SrcRC:$fs))]> {
304   let ft = 0;
305 }
306
307 class FFR2P<bits<6> funct, bits<5> fmt, string opstr,
308             string fmtstr, RegisterClass RC, SDNode OpNode> :
309   FFR<0x11, funct, fmt, (outs RC:$fd), (ins RC:$fs, RC:$ft),
310       !strconcat(opstr, ".", fmtstr, "\t$fd, $fs, $ft"),
311       [(set RC:$fd, (OpNode RC:$fs, RC:$ft))]>;
312
313 // Floating point madd/msub/nmadd/nmsub.
314 class FFMADDSUB<bits<3> funct, bits<3> fmt, dag outs, dag ins, string asmstr,
315                 list<dag> pattern>
316   : InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther> {
317   bits<5> fd;
318   bits<5> fr;
319   bits<5> fs;
320   bits<5> ft;
321
322   let Opcode = 0x13;
323   let Inst{25-21} = fr;
324   let Inst{20-16} = ft;
325   let Inst{15-11} = fs;
326   let Inst{10-6} = fd;
327   let Inst{5-3} = funct;
328   let Inst{2-0} = fmt;
329 }
330
331 // FP indexed load/store instructions.
332 class FFMemIdx<bits<6> funct, dag outs, dag ins, string asmstr,
333                list<dag> pattern> :
334   InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
335 {
336   bits<5>  base;
337   bits<5>  index;
338   bits<5>  fs;
339   bits<5>  fd;
340
341   let Opcode = 0x13;
342
343   let Inst{25-21} = base;
344   let Inst{20-16} = index;
345   let Inst{15-11} = fs;
346   let Inst{10-6} = fd;
347   let Inst{5-0} = funct;
348 }