1 //===-- SparcInstrFormats.td - Sparc Instruction Formats ---*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 class InstSP<dag outs, dag ins, string asmstr, list<dag> pattern,
10 InstrItinClass itin = NoItinerary>
18 let Inst{31-30} = op; // Top two bits are the 'op' field
20 dag OutOperandList = outs;
21 dag InOperandList = ins;
22 let AsmString = asmstr;
23 let Pattern = pattern;
25 let DecoderNamespace = "Sparc";
26 field bits<32> SoftFail = 0;
31 //===----------------------------------------------------------------------===//
32 // Format #2 instruction classes in the Sparc
33 //===----------------------------------------------------------------------===//
35 // Format 2 instructions
36 class F2<dag outs, dag ins, string asmstr, list<dag> pattern,
37 InstrItinClass itin = NoItinerary>
38 : InstSP<outs, ins, asmstr, pattern, itin> {
42 let Inst{24-22} = op2;
43 let Inst{21-0} = imm22;
46 // Specific F2 classes: SparcV8 manual, page 44
48 class F2_1<bits<3> op2Val, dag outs, dag ins, string asmstr, list<dag> pattern,
49 InstrItinClass itin = NoItinerary>
50 : F2<outs, ins, asmstr, pattern, itin> {
58 class F2_2<bits<3> op2Val, bit annul, dag outs, dag ins, string asmstr,
59 list<dag> pattern, InstrItinClass itin = NoItinerary>
60 : F2<outs, ins, asmstr, pattern, itin> {
65 let Inst{28-25} = cond;
68 class F2_3<bits<3> op2Val, bit annul, bit pred,
69 dag outs, dag ins, string asmstr, list<dag> pattern,
70 InstrItinClass itin = NoItinerary>
71 : InstSP<outs, ins, asmstr, pattern, itin> {
79 let Inst{28-25} = cond;
80 let Inst{24-22} = op2Val;
83 let Inst{18-0} = imm19;
86 class F2_4<bit annul, bit pred, dag outs, dag ins,
87 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
88 : InstSP<outs, ins, asmstr, pattern, itin> {
97 let Inst{27-25} = rcond;
98 let Inst{24-22} = 0b011;
99 let Inst{21-20} = imm16{15-14};
101 let Inst{18-14} = rs1;
102 let Inst{13-0} = imm16{13-0};
106 //===----------------------------------------------------------------------===//
107 // Format #3 instruction classes in the Sparc
108 //===----------------------------------------------------------------------===//
110 class F3<dag outs, dag ins, string asmstr, list<dag> pattern,
111 InstrItinClass itin = NoItinerary>
112 : InstSP<outs, ins, asmstr, pattern, itin> {
116 let op{1} = 1; // Op = 2 or 3
117 let Inst{29-25} = rd;
118 let Inst{24-19} = op3;
119 let Inst{18-14} = rs1;
122 // Specific F3 classes: SparcV8 manual, page 44
124 class F3_1_asi<bits<2> opVal, bits<6> op3val, dag outs, dag ins,
125 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
126 : F3<outs, ins, asmstr, pattern, itin> {
133 let Inst{13} = 0; // i field = 0
134 let Inst{12-5} = asi; // address space identifier
138 // CAS instructions does not use an immediate even when i=1
139 class F3_1_cas_asi<bits<2> opVal, bits<6> op3val, dag outs, dag ins,
140 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
141 : F3_1_asi<opVal, op3val, outs, ins, asmstr, pattern, itin> {
143 let Inst{13} = 1; // i field = 1
146 class F3_1<bits<2> opVal, bits<6> op3val, dag outs, dag ins, string asmstr,
147 list<dag> pattern, InstrItinClass itin = IIC_iu_instr>
148 : F3_1_asi<opVal, op3val, outs, ins, asmstr, pattern, itin> {
152 class F3_2<bits<2> opVal, bits<6> op3val, dag outs, dag ins,
153 string asmstr, list<dag> pattern, InstrItinClass itin = IIC_iu_instr>
154 : F3<outs, ins, asmstr, pattern, itin> {
160 let Inst{13} = 1; // i field = 1
161 let Inst{12-0} = simm13;
165 class F3_3<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
166 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
167 : F3<outs, ins, asmstr, pattern, itin> {
173 let Inst{13-5} = opfval; // fp opcode
177 // floating-point unary operations.
178 class F3_3u<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
179 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
180 : F3<outs, ins, asmstr, pattern, itin> {
187 let Inst{13-5} = opfval; // fp opcode
191 // floating-point compares.
192 class F3_3c<bits<2> opVal, bits<6> op3val, bits<9> opfval, dag outs, dag ins,
193 string asmstr, list<dag> pattern, InstrItinClass itin = NoItinerary>
194 : F3<outs, ins, asmstr, pattern, itin> {
200 let Inst{13-5} = opfval; // fp opcode
204 // Shift by register rs2.
205 class F3_Sr<bits<2> opVal, bits<6> op3val, bit xVal, dag outs, dag ins,
206 string asmstr, list<dag> pattern, InstrItinClass itin = IIC_iu_instr>
207 : F3<outs, ins, asmstr, pattern, itin> {
208 bit x = xVal; // 1 for 64-bit shifts.
214 let Inst{13} = 0; // i field = 0
215 let Inst{12} = x; // extended registers.
219 // Shift by immediate.
220 class F3_Si<bits<2> opVal, bits<6> op3val, bit xVal, dag outs, dag ins,
221 string asmstr, list<dag> pattern, InstrItinClass itin = IIC_iu_instr>
222 : F3<outs, ins, asmstr, pattern, itin> {
223 bit x = xVal; // 1 for 64-bit shifts.
224 bits<6> shcnt; // shcnt32 / shcnt64.
229 let Inst{13} = 1; // i field = 1
230 let Inst{12} = x; // extended registers.
231 let Inst{5-0} = shcnt;
234 // Define rr and ri shift instructions with patterns.
235 multiclass F3_S<string OpcStr, bits<6> Op3Val, bit XVal, SDNode OpNode,
236 ValueType VT, Operand SIT, RegisterClass RC,
237 InstrItinClass itin = IIC_iu_instr> {
238 def rr : F3_Sr<2, Op3Val, XVal, (outs RC:$rd), (ins RC:$rs1, IntRegs:$rs2),
239 !strconcat(OpcStr, " $rs1, $rs2, $rd"),
240 [(set VT:$rd, (OpNode VT:$rs1, i32:$rs2))],
242 def ri : F3_Si<2, Op3Val, XVal, (outs RC:$rd), (ins RC:$rs1, SIT:$shcnt),
243 !strconcat(OpcStr, " $rs1, $shcnt, $rd"),
244 [(set VT:$rd, (OpNode VT:$rs1, (i32 imm:$shcnt)))],
248 class F4<bits<6> op3, dag outs, dag ins, string asmstr, list<dag> pattern,
249 InstrItinClass itin = NoItinerary>
250 : InstSP<outs, ins, asmstr, pattern, itin> {
254 let Inst{29-25} = rd;
255 let Inst{24-19} = op3;
259 class F4_1<bits<6> op3, dag outs, dag ins,
260 string asmstr, list<dag> pattern,
261 InstrItinClass itin = NoItinerary>
262 : F4<op3, outs, ins, asmstr, pattern, itin> {
269 let Inst{12-11} = cc;
271 let Inst{17-14} = cond;
272 let Inst{18} = intcc;
275 class F4_2<bits<6> op3, dag outs, dag ins,
276 string asmstr, list<dag> pattern,
277 InstrItinClass itin = NoItinerary>
278 : F4<op3, outs, ins, asmstr, pattern, itin> {
284 let Inst{10-0} = simm11;
285 let Inst{12-11} = cc;
287 let Inst{17-14} = cond;
288 let Inst{18} = intcc;
291 class F4_3<bits<6> op3, bits<6> opf_low, dag outs, dag ins,
292 string asmstr, list<dag> pattern,
293 InstrItinClass itin = NoItinerary>
294 : F4<op3, outs, ins, asmstr, pattern, itin> {
301 let Inst{17-14} = cond;
302 let Inst{13} = intcc;
303 let Inst{12-11} = opf_cc;
304 let Inst{10-5} = opf_low;
308 class F4_4r<bits<6> op3, bits<5> opf_low, dag outs, dag ins,
309 string asmstr, list<dag> pattern,
310 InstrItinClass itin = NoItinerary>
311 : F4<op3, outs, ins, asmstr, pattern, itin> {
315 let Inst{18-14} = rs1;
316 let Inst{13} = 0; // IsImm
317 let Inst{12-10} = rcond;
318 let Inst{9-5} = opf_low;
323 class F4_4i<bits<6> op3, dag outs, dag ins,
324 string asmstr, list<dag> pattern,
325 InstrItinClass itin = NoItinerary>
326 : F4<op3, outs, ins, asmstr, pattern, itin> {
330 let Inst{18-14} = rs1;
331 let Inst{13} = 1; // IsImm
332 let Inst{12-10} = rcond;
333 let Inst{9-0} = simm10;
337 class TRAPSP<bits<6> op3Val, bit isimm, dag outs, dag ins,
338 string asmstr, list<dag> pattern,
339 InstrItinClass itin = NoItinerary>
340 : F3<outs, ins, asmstr, pattern, itin> {
348 let Inst{13} = isimm;
349 let Inst{12-11} = cc;
353 class TRAPSPrr<bits<6> op3Val, dag outs, dag ins,
354 string asmstr, list<dag> pattern,
355 InstrItinClass itin = NoItinerary>
356 : TRAPSP<op3Val, 0, outs, ins, asmstr, pattern, itin> {
363 class TRAPSPri<bits<6> op3Val, dag outs, dag ins,
364 string asmstr, list<dag> pattern,
365 InstrItinClass itin = NoItinerary>
366 : TRAPSP<op3Val, 1, outs, ins, asmstr, pattern, itin> {
373 // Pseudo-instructions for alternate assembly syntax (never used by codegen).
374 // These are aliases that require C++ handling to convert to the target
375 // instruction, while InstAliases can be handled directly by tblgen.
376 class AsmPseudoInst<dag outs, dag ins, string asm>
377 : InstSP<outs, ins, asm, []> {