1 //===-- MipsInstrFormats.td - Mips 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 MIPS instructions format
13 // CPU INSTRUCTION FORMATS
15 // opcode - operation code.
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.
22 //===----------------------------------------------------------------------===//
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
27 class Format<bits<4> val> {
31 def Pseudo : Format<0>;
35 def FrmFR : Format<4>;
36 def FrmFI : Format<5>;
37 def FrmOther : Format<6>; // Instruction w/ a custom format
39 // Generic Mips Format
40 class MipsInst<dag outs, dag ins, string asmstr, list<dag> pattern,
41 InstrItinClass itin, Format f>: Instruction
46 let Namespace = "Mips";
52 // Top 6 bits are the 'opcode' field
53 let Inst{31-26} = Opcode;
55 let OutOperandList = outs;
56 let InOperandList = ins;
58 let AsmString = asmstr;
59 let Pattern = pattern;
63 // Attributes specific to Mips instructions...
65 bits<4> FormBits = Form.Value;
67 // TSFlags layout should be kept in sync with MipsInstrInfo.h.
68 let TSFlags{3-0} = FormBits;
70 let DecoderNamespace = "Mips";
72 field bits<32> SoftFail = 0;
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 = [HasStdEnc];
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;
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 = [HasStdEnc];
95 // Pseudo-instructions for alternate assembly syntax (never used by codegen).
96 // These are aliases that require C++ handling to convert to the target
97 // instruction, while InstAliases can be handled directly by tblgen.
98 class MipsAsmPseudoInst<dag outs, dag ins, string asmstr>:
99 MipsInst<outs, ins, asmstr, [], IIPseudo, Pseudo> {
103 //===----------------------------------------------------------------------===//
104 // Format R instruction class in Mips : <|opcode|rs|rt|rd|shamt|funct|>
105 //===----------------------------------------------------------------------===//
107 class FR<bits<6> op, bits<6> _funct, dag outs, dag ins, string asmstr,
108 list<dag> pattern, InstrItinClass itin>:
109 InstSE<outs, ins, asmstr, pattern, itin, FrmR>
120 let Inst{25-21} = rs;
121 let Inst{20-16} = rt;
122 let Inst{15-11} = rd;
123 let Inst{10-6} = shamt;
124 let Inst{5-0} = funct;
127 //===----------------------------------------------------------------------===//
128 // Format I instruction class in Mips : <|opcode|rs|rt|immediate|>
129 //===----------------------------------------------------------------------===//
131 class FI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
132 InstrItinClass itin>: InstSE<outs, ins, asmstr, pattern, itin, FrmI>
140 let Inst{25-21} = rs;
141 let Inst{20-16} = rt;
142 let Inst{15-0} = imm16;
145 class BranchBase<bits<6> op, dag outs, dag ins, string asmstr,
146 list<dag> pattern, InstrItinClass itin>:
147 InstSE<outs, ins, asmstr, pattern, itin, FrmI>
155 let Inst{25-21} = rs;
156 let Inst{20-16} = rt;
157 let Inst{15-0} = imm16;
160 //===----------------------------------------------------------------------===//
161 // Format J instruction class in Mips : <|opcode|address|>
162 //===----------------------------------------------------------------------===//
164 class FJ<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern,
165 InstrItinClass itin>: InstSE<outs, ins, asmstr, pattern, itin, FrmJ>
171 let Inst{25-0} = addr;
174 //===----------------------------------------------------------------------===//
175 // MFC instruction class in Mips : <|op|mf|rt|rd|0000000|sel|>
176 //===----------------------------------------------------------------------===//
177 class MFC3OP<bits<6> op, bits<5> _mfmt, dag outs, dag ins, string asmstr>:
178 InstSE<outs, ins, asmstr, [], NoItinerary, FrmFR>
188 let Inst{25-21} = mfmt;
189 let Inst{20-16} = rt;
190 let Inst{15-11} = rd;
195 //===----------------------------------------------------------------------===//
197 // FLOATING POINT INSTRUCTION FORMATS
199 // opcode - operation code.
201 // ft - dst reg (on a 2 regs instr) or src reg (on a 3 reg instr).
202 // fd - dst reg, only used on 3 regs instr.
203 // fmt - double or single precision.
204 // funct - combined with opcode field give us an operation code.
206 //===----------------------------------------------------------------------===//
208 //===----------------------------------------------------------------------===//
209 // Format FR instruction class in Mips : <|opcode|fmt|ft|fs|fd|funct|>
210 //===----------------------------------------------------------------------===//
212 class FFR<bits<6> op, bits<6> _funct, bits<5> _fmt, dag outs, dag ins,
213 string asmstr, list<dag> pattern> :
214 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmFR>
226 let Inst{25-21} = fmt;
227 let Inst{20-16} = ft;
228 let Inst{15-11} = fs;
230 let Inst{5-0} = funct;
233 //===----------------------------------------------------------------------===//
234 // Format FI instruction class in Mips : <|opcode|base|ft|immediate|>
235 //===----------------------------------------------------------------------===//
237 class FFI<bits<6> op, dag outs, dag ins, string asmstr, list<dag> pattern>:
238 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmFI>
246 let Inst{25-21} = base;
247 let Inst{20-16} = ft;
248 let Inst{15-0} = imm16;
251 //===----------------------------------------------------------------------===//
252 // Compare instruction class in Mips : <|010001|fmt|ft|fs|0000011|condcode|>
253 //===----------------------------------------------------------------------===//
255 class FCC<bits<5> _fmt, dag outs, dag ins, string asmstr, list<dag> pattern> :
256 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
266 let Inst{25-21} = fmt;
267 let Inst{20-16} = ft;
268 let Inst{15-11} = fs;
270 let Inst{5-4} = 0b11;
275 class FCMOV<bits<1> _tf, dag outs, dag ins, string asmstr,
277 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
287 let Inst{25-21} = rs;
288 let Inst{20-18} = cc;
291 let Inst{15-11} = rd;
296 class FFCMOV<bits<5> _fmt, bits<1> _tf, dag outs, dag ins, string asmstr,
298 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
310 let Inst{25-21} = fmt;
311 let Inst{20-18} = cc;
314 let Inst{15-11} = fs;
319 // Floating point madd/msub/nmadd/nmsub.
320 class FFMADDSUB<bits<3> funct, bits<3> fmt, dag outs, dag ins, string asmstr,
322 : InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther> {
329 let Inst{25-21} = fr;
330 let Inst{20-16} = ft;
331 let Inst{15-11} = fs;
333 let Inst{5-3} = funct;
337 // FP indexed load/store instructions.
338 class FFMemIdx<bits<6> funct, dag outs, dag ins, string asmstr,
340 InstSE<outs, ins, asmstr, pattern, NoItinerary, FrmOther>
349 let Inst{25-21} = base;
350 let Inst{20-16} = index;
351 let Inst{15-11} = fs;
353 let Inst{5-0} = funct;
356 class ADDS_FM<bits<6> funct, bits<5> fmt> {
363 let Inst{31-26} = 0x11;
364 let Inst{25-21} = fmt;
365 let Inst{20-16} = ft;
366 let Inst{15-11} = fs;
368 let Inst{5-0} = funct;
371 class ABSS_FM<bits<6> funct, bits<5> fmt> {
377 let Inst{31-26} = 0x11;
378 let Inst{25-21} = fmt;
380 let Inst{15-11} = fs;
382 let Inst{5-0} = funct;
385 class MFC1_FM<bits<5> funct> {
391 let Inst{31-26} = 0x11;
392 let Inst{25-21} = funct;
393 let Inst{20-16} = rt;
394 let Inst{15-11} = fs;
398 class LW_FM<bits<6> op> {
404 let Inst{31-26} = op;
405 let Inst{25-21} = addr{20-16};
406 let Inst{20-16} = rt;
407 let Inst{15-0} = addr{15-0};
410 class MADDS_FM<bits<3> funct, bits<3> fmt> {
418 let Inst{31-26} = 0x13;
419 let Inst{25-21} = fr;
420 let Inst{20-16} = ft;
421 let Inst{15-11} = fs;
423 let Inst{5-3} = funct;
427 class LWXC1_FM<bits<6> funct> {
434 let Inst{31-26} = 0x13;
435 let Inst{25-21} = base;
436 let Inst{20-16} = index;
439 let Inst{5-0} = funct;
442 class SWXC1_FM<bits<6> funct> {
449 let Inst{31-26} = 0x13;
450 let Inst{25-21} = base;
451 let Inst{20-16} = index;
452 let Inst{15-11} = fs;
454 let Inst{5-0} = funct;
457 class BC1F_FM<bit nd, bit tf> {
462 let Inst{31-26} = 0x11;
463 let Inst{25-21} = 0x8;
464 let Inst{20-18} = 0; // cc
467 let Inst{15-0} = offset;
470 class CEQS_FM<bits<5> fmt> {
477 let Inst{31-26} = 0x11;
478 let Inst{25-21} = fmt;
479 let Inst{20-16} = ft;
480 let Inst{15-11} = fs;
481 let Inst{10-8} = 0; // cc
483 let Inst{3-0} = cond;