97b6498c9473a282a23c77ddf180fb1ede1d19f8
[oota-llvm.git] / lib / Target / Sparc / SparcInstrFormats.td
1 //===-- SparcInstrFormats.td - Sparc 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 class InstSP<dag outs, dag ins, string asmstr, list<dag> pattern>
11           : Instruction {
12   field bits<32> Inst;
13
14   let Namespace = "SP";
15   let Size = 4;
16
17   bits<2> op;
18   let Inst{31-30} = op;               // Top two bits are the 'op' field
19
20   dag OutOperandList = outs;
21   dag InOperandList = ins;
22   let AsmString   = asmstr;
23   let Pattern = pattern;
24
25   let DecoderNamespace = "Sparc";
26   field bits<32> SoftFail = 0;
27 }
28
29 //===----------------------------------------------------------------------===//
30 // Format #2 instruction classes in the Sparc
31 //===----------------------------------------------------------------------===//
32
33 // Format 2 instructions
34 class F2<dag outs, dag ins, string asmstr, list<dag> pattern>
35    : InstSP<outs, ins, asmstr, pattern> {
36   bits<3>  op2;
37   bits<22> imm22;
38   let op          = 0;    // op = 0
39   let Inst{24-22} = op2;
40   let Inst{21-0}  = imm22;
41 }
42
43 // Specific F2 classes: SparcV8 manual, page 44
44 //
45 class F2_1<bits<3> op2Val, dag outs, dag ins, string asmstr, list<dag> pattern>
46    : F2<outs, ins, asmstr, pattern> {
47   bits<5>  rd;
48
49   let op2         = op2Val;
50
51   let Inst{29-25} = rd;
52 }
53
54 class F2_2<bits<3> op2Val, bit annul, dag outs, dag ins, string asmstr,
55            list<dag> pattern> : F2<outs, ins, asmstr, pattern> {
56   bits<4>   cond;
57   let op2         = op2Val;
58
59   let Inst{29}    = annul;
60   let Inst{28-25} = cond;
61 }
62
63 class F2_3<bits<3> op2Val, bits<2> ccVal, dag outs, dag ins, string asmstr,
64            list<dag> pattern>
65    : InstSP<outs, ins, asmstr, pattern> {
66   bit      annul;
67   bits<4>  cond;
68   bit      pred;
69   bits<19> imm19;
70
71   let op          = 0;    // op = 0
72
73   bit annul       = 0;    // currently unused
74   let pred        = 1;    // default is predict taken
75
76   let Inst{29}    = annul;
77   let Inst{28-25} = cond;
78   let Inst{24-22} = op2Val;
79   let Inst{21-20} = ccVal;
80   let Inst{19}    = pred;
81   let Inst{18-0}  = imm19;
82 }
83
84 //===----------------------------------------------------------------------===//
85 // Format #3 instruction classes in the Sparc
86 //===----------------------------------------------------------------------===//
87
88 class F3<dag outs, dag ins, string asmstr, list<dag> pattern>
89     : InstSP<outs, ins, asmstr, pattern> {
90   bits<5> rd;
91   bits<6> op3;
92   bits<5> rs1;
93   let op{1} = 1;   // Op = 2 or 3
94   let Inst{29-25} = rd;
95   let Inst{24-19} = op3;
96   let Inst{18-14} = rs1;
97 }
98
99 // Specific F3 classes: SparcV8 manual, page 44
100 //
101 class F3_1_asi<bits<2> opVal, bits<6> op3val, bits<8> asi, dag outs, dag ins,
102            string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
103   bits<5> rs2;
104
105   let op         = opVal;
106   let op3        = op3val;
107
108   let Inst{13}   = 0;     // i field = 0
109   let Inst{12-5} = asi;   // address space identifier
110   let Inst{4-0}  = rs2;
111 }
112
113 class F3_1<bits<2> opVal, bits<6> op3val, dag outs, dag ins, string asmstr,
114        list<dag> pattern> : F3_1_asi<opVal, op3val, 0, outs, ins,
115                                                      asmstr, pattern>;
116
117 class F3_2<bits<2> opVal, bits<6> op3val, dag outs, dag ins,
118            string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
119   bits<13> simm13;
120
121   let op         = opVal;
122   let op3        = op3val;
123
124   let Inst{13}   = 1;     // i field = 1
125   let Inst{12-0} = simm13;
126 }
127
128 // floating-point
129 class F3_3<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
130            string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
131   bits<5> rs2;
132
133   let op         = opVal;
134   let op3        = op3val;
135
136   let Inst{13-5} = opfval;   // fp opcode
137   let Inst{4-0}  = rs2;
138 }
139
140 // floating-point unary operations.
141 class F3_3u<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
142            string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
143   bits<5> rs2;
144
145   let op         = opVal;
146   let op3        = op3val;
147   let rs1        = 0;
148
149   let Inst{13-5} = opfval;   // fp opcode
150   let Inst{4-0}  = rs2;
151 }
152
153 // floating-point compares.
154 class F3_3c<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
155            string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
156   bits<5> rs2;
157
158   let op         = opVal;
159   let op3        = op3val;
160   let rd         = 0;
161
162   let Inst{13-5} = opfval;   // fp opcode
163   let Inst{4-0}  = rs2;
164 }
165
166 // Shift by register rs2.
167 class F3_Sr<bits<2> opVal, bits<6> op3val, bit xVal, dag outs, dag ins,
168             string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
169   bit x = xVal;           // 1 for 64-bit shifts.
170   bits<5> rs2;
171
172   let op         = opVal;
173   let op3        = op3val;
174
175   let Inst{13}   = 0;     // i field = 0
176   let Inst{12}   = x;     // extended registers.
177   let Inst{4-0}  = rs2;
178 }
179
180 // Shift by immediate.
181 class F3_Si<bits<2> opVal, bits<6> op3val, bit xVal, dag outs, dag ins,
182             string asmstr, list<dag> pattern> : F3<outs, ins, asmstr, pattern> {
183   bit x = xVal;           // 1 for 64-bit shifts.
184   bits<6> shcnt;          // shcnt32 / shcnt64.
185
186   let op         = opVal;
187   let op3        = op3val;
188
189   let Inst{13}   = 1;     // i field = 1
190   let Inst{12}   = x;     // extended registers.
191   let Inst{5-0}  = shcnt;
192 }
193
194 // Define rr and ri shift instructions with patterns.
195 multiclass F3_S<string OpcStr, bits<6> Op3Val, bit XVal, SDNode OpNode,
196                 ValueType VT, RegisterClass RC> {
197   def rr : F3_Sr<2, Op3Val, XVal, (outs RC:$rd), (ins RC:$rs1, IntRegs:$rs2),
198                  !strconcat(OpcStr, " $rs1, $rs2, $rd"),
199                  [(set VT:$rd, (OpNode VT:$rs1, i32:$rs2))]>;
200   def ri : F3_Si<2, Op3Val, XVal, (outs RC:$rd), (ins RC:$rs1, i32imm:$shcnt),
201                  !strconcat(OpcStr, " $rs1, $shcnt, $rd"),
202                  [(set VT:$rd, (OpNode VT:$rs1, (i32 imm:$shcnt)))]>;
203 }
204
205 class F4<bits<6> op3, dag outs, dag ins, string asmstr, list<dag> pattern>
206       : InstSP<outs, ins, asmstr, pattern> {
207   bits<5> rd;
208
209   let op          = 2;
210   let Inst{29-25} = rd;
211   let Inst{24-19} = op3;
212 }
213
214
215 class F4_1<bits<6> op3, dag outs, dag ins,
216             string asmstr, list<dag> pattern>
217       : F4<op3, outs, ins, asmstr, pattern> {
218
219   bits<3> cc;
220   bits<4> cond;
221   bits<5> rs2;
222
223   let Inst{4-0}   = rs2;
224   let Inst{11}    = cc{0};
225   let Inst{12}    = cc{1};
226   let Inst{13}    = 0;
227   let Inst{17-14} = cond;
228   let Inst{18}    = cc{2};
229
230 }
231
232 class F4_2<bits<6> op3, dag outs, dag ins,
233             string asmstr, list<dag> pattern>
234       : F4<op3, outs, ins, asmstr, pattern> {
235   bits<3>  cc;
236   bits<4>  cond;
237   bits<11> simm11;
238
239   let Inst{10-0}  = simm11;
240   let Inst{11}    = cc{0};
241   let Inst{12}    = cc{1};
242   let Inst{13}    = 1;
243   let Inst{17-14} = cond;
244   let Inst{18}    = cc{2};
245 }
246
247 class F4_3<bits<6> op3, bits<6> opf_low, dag outs, dag ins,
248            string asmstr, list<dag> pattern>
249       : F4<op3, outs, ins, asmstr, pattern> {
250   bits<4> cond;
251   bits<3> opf_cc;
252   bits<5> rs2;
253
254   let Inst{18}     = 0;
255   let Inst{17-14}  = cond;
256   let Inst{13-11}  = opf_cc;
257   let Inst{10-5}   = opf_low;
258   let Inst{4-0}    = rs2;
259 }