Add support for ext and ins.
[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 // Generic Mips Format
25 class MipsInst<dag outs, dag ins, string asmstr, list<dag> pattern,
26                InstrItinClass itin>: Instruction
27 {
28   field bits<32> Inst;
29
30   let Namespace = "Mips";
31
32   bits<6> opcode;
33
34   // Top 5 bits are the 'opcode' field
35   let Inst{31-26} = opcode;
36
37   dag OutOperandList = outs;
38   dag InOperandList  = ins;
39
40   let AsmString   = asmstr;
41   let Pattern     = pattern;
42   let Itinerary   = itin;
43 }
44
45 // Mips Pseudo Instructions Format
46 class MipsPseudo<dag outs, dag ins, string asmstr, list<dag> pattern>:
47       MipsInst<outs, ins, asmstr, pattern, IIPseudo>;
48
49 //===----------------------------------------------------------------------===//
50 // Format R instruction class in Mips : <|opcode|rs|rt|rd|shamt|funct|>
51 //===----------------------------------------------------------------------===//
52
53 class FR<bits<6> op, bits<6> _funct, dag outs, dag ins, string asmstr,
54          list<dag> pattern, InstrItinClass itin>:
55       MipsInst<outs, ins, asmstr, pattern, itin>
56 {
57   bits<5>  rd;
58   bits<5>  rs;
59   bits<5>  rt;
60   bits<5>  shamt;
61   bits<6>  funct;
62
63   let opcode = op;
64   let funct  = _funct;
65
66   let Inst{25-21} = rs;
67   let Inst{20-16} = rt;
68   let Inst{15-11} = rd;
69   let Inst{10-6}  = shamt;
70   let Inst{5-0}   = funct;
71 }
72
73 //===----------------------------------------------------------------------===//
74 // Format I instruction class in Mips : <|opcode|rs|rt|immediate|>
75 //===----------------------------------------------------------------------===//
76
77 class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
78          InstrItinClass itin>: MipsInst<outs, ins, asmstr, pattern, itin>
79 {
80   bits<5>  rt;
81   bits<5>  rs;
82   bits<16> imm16;
83
84   let opcode = op;
85
86   let Inst{25-21} = rs;
87   let Inst{20-16} = rt;
88   let Inst{15-0}  = imm16;
89 }
90
91 //===----------------------------------------------------------------------===//
92 // Format J instruction class in Mips : <|opcode|address|>
93 //===----------------------------------------------------------------------===//
94
95 class FJ<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
96          InstrItinClass itin>: MipsInst<outs, ins, asmstr, pattern, itin>
97 {
98   bits<26> addr;
99
100   let opcode = op;
101
102   let Inst{25-0} = addr;
103 }
104
105 // Ext and Ins
106 class ExtIns<bits<6> _funct, string instr_asm, dag Outs, dag Ins,
107              list<dag> pattern, InstrItinClass itin>:
108   MipsInst<Outs, Ins, !strconcat(instr_asm, "\t$dst, $src, $pos, $size"),
109            pattern, itin>
110 {
111   bits<5>  rt;
112   bits<5>  rs;
113   bits<5>  sz;
114   bits<5>  pos;
115   bits<6>  funct;
116
117   let opcode = 0x1f;
118   let funct  = _funct;
119
120   let Inst{25-21} = rs;
121   let Inst{20-16} = rt;
122   let Inst{15-11} = sz;
123   let Inst{10-6}  = pos;
124   let Inst{5-0}   = funct;
125 }
126
127 //===----------------------------------------------------------------------===//
128 //
129 //  FLOATING POINT INSTRUCTION FORMATS
130 //
131 //  opcode  - operation code.
132 //  fs      - src reg.
133 //  ft      - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
134 //  fd      - dst reg, only used on 3 regs instr.
135 //  fmt     - double or single precision.
136 //  funct   - combined with opcode field give us an operation code.
137 //
138 //===----------------------------------------------------------------------===//
139
140 //===----------------------------------------------------------------------===//
141 // Format FR instruction class in Mips : <|opcode|fmt|ft|fs|fd|funct|>
142 //===----------------------------------------------------------------------===//
143
144 class FFR<bits<6> op, bits<6> _funct, bits<5> _fmt, dag outs, dag ins,
145           string asmstr, list<dag> pattern> :
146           MipsInst<outs, ins, asmstr, pattern, NoItinerary>
147 {
148   bits<5>  fd;
149   bits<5>  fs;
150   bits<5>  ft;
151   bits<5>  fmt;
152   bits<6>  funct;
153
154   let opcode = op;
155   let funct  = _funct;
156   let fmt    = _fmt;
157
158   let Inst{25-21} = fmt;
159   let Inst{20-16} = ft;
160   let Inst{15-11} = fs;
161   let Inst{10-6}  = fd;
162   let Inst{5-0}   = funct;
163 }
164
165 //===----------------------------------------------------------------------===//
166 // Format FI instruction class in Mips : <|opcode|base|ft|immediate|>
167 //===----------------------------------------------------------------------===//
168
169 class FFI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>:
170           MipsInst<outs, ins, asmstr, pattern, NoItinerary>
171 {
172   bits<5>  ft;
173   bits<5>  base;
174   bits<16> imm16;
175
176   let opcode = op;
177
178   let Inst{25-21} = base;
179   let Inst{20-16} = ft;
180   let Inst{15-0}  = imm16;
181 }
182
183 //===----------------------------------------------------------------------===//
184 // Compare instruction class in Mips : <|010001|fmt|ft|fs|0000011|condcode|>
185 //===----------------------------------------------------------------------===//
186
187 class FCC<bits<5> _fmt, dag outs, dag ins, string asmstr, list<dag> pattern> :
188           MipsInst<outs, ins, asmstr, pattern, NoItinerary>
189 {
190   bits<5>  fs;
191   bits<5>  ft;
192   bits<4>  cc;
193   bits<5>  fmt;
194
195   let opcode = 0x11;
196   let fmt    = _fmt;
197
198   let Inst{25-21} = fmt;
199   let Inst{20-16} = ft;
200   let Inst{15-11} = fs;
201   let Inst{10-6}  = 0;
202   let Inst{5-4}   = 0b11;
203   let Inst{3-0}   = cc;
204 }
205
206
207 class FCMOV<bits<1> _tf, dag outs, dag ins, string asmstr,
208             list<dag> pattern> :
209   MipsInst<outs, ins, asmstr, pattern, NoItinerary>
210 {
211   bits<5>  rd;
212   bits<5>  rs;
213   bits<3>  N;
214   bits<1>  tf;
215
216   let opcode = 0;
217   let tf = _tf;
218
219   let Inst{25-21} = rs;
220   let Inst{20-18} = N;
221   let Inst{17} = 0;
222   let Inst{16} = tf;
223   let Inst{15-11} = rd;
224   let Inst{10-6}  = 0;
225   let Inst{5-0}   = 1;
226 }
227
228 class FFCMOV<bits<5> _fmt, bits<1> _tf, dag outs, dag ins, string asmstr,
229              list<dag> pattern> :
230   MipsInst<outs, ins, asmstr, pattern, NoItinerary>
231 {
232   bits<5>  fd;
233   bits<5>  fs;
234   bits<3>  N;
235   bits<5>  fmt;
236   bits<1>  tf;
237
238   let opcode = 17;
239   let fmt = _fmt;
240   let tf = _tf;
241
242   let Inst{25-21} = fmt;
243   let Inst{20-18} = N;
244   let Inst{17} = 0;
245   let Inst{16} = tf;
246   let Inst{15-11} = fs;
247   let Inst{10-6}  = fd;
248   let Inst{5-0}   = 17;
249 }