1 //===- Mips64InstrInfo.td - Mips64 Instruction Information -*- 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 // This file describes Mips64 instructions.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // Mips64 Instruction Predicate Definitions.
16 //===----------------------------------------------------------------------===//
17 def HasMips64 : Predicate<"Subtarget.hasMips64()">;
18 def HasMips64r2 : Predicate<"Subtarget.hasMips64r2()">;
20 //===----------------------------------------------------------------------===//
21 // Mips Operand, Complex Patterns and Transformations Definitions.
22 //===----------------------------------------------------------------------===//
24 // Instruction operand types
25 def shamt_64 : Operand<i64>;
28 def uimm16_64 : Operand<i64> {
29 let PrintMethod = "printUnsignedImm";
32 // Transformation Function - get Imm - 32.
33 def Subtract32 : SDNodeXForm<imm, [{
34 return getI32Imm((unsigned)N->getZExtValue() - 32);
37 // imm32_63 predicate - True if imm is in range [32, 63].
38 def imm32_63 : ImmLeaf<i64,
39 [{return (int32_t)Imm >= 32 && (int32_t)Imm < 64;}],
42 //===----------------------------------------------------------------------===//
43 // Instructions specific format
44 //===----------------------------------------------------------------------===//
46 // Arithmetic 3 register operands
47 class ArithR64<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
48 InstrItinClass itin, bit isComm = 0>:
49 FR<op, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
50 !strconcat(instr_asm, "\t$dst, $b, $c"),
51 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], itin> {
52 let isCommutable = isComm;
55 // Arithmetic 2 register operands
56 class ArithI64<bits<6> op, string instr_asm, SDNode OpNode,
57 Operand Od, PatLeaf imm_type> :
58 FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, Od:$c),
59 !strconcat(instr_asm, "\t$dst, $b, $c"),
60 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, imm_type:$c))], IIAlu>;
63 let isCommutable = 1 in
64 class LogicR64<bits<6> func, string instr_asm, SDNode OpNode>:
65 FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
66 !strconcat(instr_asm, "\t$dst, $b, $c"),
67 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu>;
69 class LogicI64<bits<6> op, string instr_asm, SDNode OpNode>:
70 FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, uimm16_64:$c),
71 !strconcat(instr_asm, "\t$dst, $b, $c"),
72 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, immZExt16:$c))], IIAlu>;
74 let isCommutable = 1 in
75 class LogicNOR64<bits<6> op, bits<6> func, string instr_asm>:
76 FR<op, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
77 !strconcat(instr_asm, "\t$dst, $b, $c"),
78 [(set CPU64Regs:$dst, (not (or CPU64Regs:$b, CPU64Regs:$c)))], IIAlu>;
81 class LogicR_shift_rotate_imm64<bits<6> func, bits<5> _rs, string instr_asm,
82 SDNode OpNode, PatFrag PF>:
83 FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, shamt_64:$c),
84 !strconcat(instr_asm, "\t$dst, $b, $c"),
85 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, (i64 PF:$c)))],
90 class LogicR_shift_rotate_reg64<bits<6> func, bits<5> _shamt, string instr_asm,
92 FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$c, CPU64Regs:$b),
93 !strconcat(instr_asm, "\t$dst, $b, $c"),
94 [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu> {
99 let Defs = [HI64, LO64] in {
100 let isCommutable = 1 in
101 class Mul64<bits<6> func, string instr_asm, InstrItinClass itin>:
102 FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
103 !strconcat(instr_asm, "\t$a, $b"), [], itin>;
105 class Div64<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
106 FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
107 !strconcat(instr_asm, "\t$$zero, $a, $b"),
108 [(op CPU64Regs:$a, CPU64Regs:$b)], itin>;
113 let rs = 0, rt = 0 in
114 class MoveFromLOHI64<bits<6> func, string instr_asm>:
115 FR<0x00, func, (outs CPU64Regs:$dst), (ins),
116 !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
118 let rt = 0, rd = 0 in
119 class MoveToLOHI64<bits<6> func, string instr_asm>:
120 FR<0x00, func, (outs), (ins CPU64Regs:$src),
121 !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
124 // Count Leading Ones/Zeros in Word
125 class CountLeading64<bits<6> func, string instr_asm, list<dag> pattern>:
126 FR<0x1c, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$src),
127 !strconcat(instr_asm, "\t$dst, $src"), pattern, IIAlu>,
128 Requires<[HasBitCount]> {
133 //===----------------------------------------------------------------------===//
134 // Instruction definition
135 //===----------------------------------------------------------------------===//
137 /// Arithmetic Instructions (ALU Immediate)
138 def DADDiu : ArithI64<0x19, "daddiu", add, simm16_64, immSExt16>;
139 def DANDi : LogicI64<0x0c, "andi", and>;
140 def DORi : LogicI64<0x0d, "ori", or>;
141 def DXORi : LogicI64<0x0e, "xori", xor>;
143 /// Arithmetic Instructions (3-Operand, R-Type)
144 def DADDu : ArithR64<0x00, 0x2d, "daddu", add, IIAlu, 1>;
145 def DSUBu : ArithR64<0x00, 0x2f, "dsubu", sub, IIAlu>;
146 def DAND : LogicR64<0x24, "and", and>;
147 def DOR : LogicR64<0x25, "or", or>;
148 def DXOR : LogicR64<0x26, "xor", xor>;
149 def DNOR : LogicNOR64<0x00, 0x27, "nor">;
151 /// Shift Instructions
152 def DSLL : LogicR_shift_rotate_imm64<0x38, 0x00, "dsll", shl, immZExt5>;
153 def DSRL : LogicR_shift_rotate_imm64<0x3a, 0x00, "dsrl", srl, immZExt5>;
154 def DSRA : LogicR_shift_rotate_imm64<0x3b, 0x00, "dsra", sra, immZExt5>;
155 def DSLL32 : LogicR_shift_rotate_imm64<0x3c, 0x00, "dsll32", shl, imm32_63>;
156 def DSRL32 : LogicR_shift_rotate_imm64<0x3e, 0x00, "dsrl32", srl, imm32_63>;
157 def DSRA32 : LogicR_shift_rotate_imm64<0x3f, 0x00, "dsra32", sra, imm32_63>;
158 def DSLLV : LogicR_shift_rotate_reg64<0x24, 0x00, "dsllv", shl>;
159 def DSRLV : LogicR_shift_rotate_reg64<0x26, 0x00, "dsrlv", srl>;
160 def DSRAV : LogicR_shift_rotate_reg64<0x27, 0x00, "dsrav", sra>;
162 // Rotate Instructions
163 let Predicates = [HasMips64r2] in {
164 def DROTR : LogicR_shift_rotate_imm64<0x3a, 0x01, "drotr", rotr, immZExt5>;
165 def DROTR32 : LogicR_shift_rotate_imm64<0x3e, 0x01, "drotr32", rotr,
167 def DROTRV : LogicR_shift_rotate_reg64<0x16, 0x01, "drotrv", rotr>;
170 /// Load and Store Instructions
172 defm LB64 : LoadM64<0x20, "lb", sextloadi8>;
173 defm LBu64 : LoadM64<0x24, "lbu", zextloadi8>;
174 defm LH64 : LoadM64<0x21, "lh", sextloadi16_a>;
175 defm LHu64 : LoadM64<0x25, "lhu", zextloadi16_a>;
176 defm LW64 : LoadM64<0x23, "lw", sextloadi32_a>;
177 defm LWu64 : LoadM64<0x27, "lwu", zextloadi32_a>;
178 defm SB64 : StoreM64<0x28, "sb", truncstorei8>;
179 defm SH64 : StoreM64<0x29, "sh", truncstorei16_a>;
180 defm SW64 : StoreM64<0x2b, "sw", truncstorei32_a>;
181 defm LD : LoadM64<0x37, "ld", load_a>;
182 defm SD : StoreM64<0x3f, "sd", store_a>;
185 defm ULH64 : LoadM64<0x21, "ulh", sextloadi16_u, 1>;
186 defm ULHu64 : LoadM64<0x25, "ulhu", zextloadi16_u, 1>;
187 defm ULW64 : LoadM64<0x23, "ulw", sextloadi32_u, 1>;
188 defm USH64 : StoreM64<0x29, "ush", truncstorei16_u, 1>;
189 defm USW64 : StoreM64<0x2b, "usw", truncstorei32_u, 1>;
190 defm ULD : LoadM64<0x37, "uld", load_u, 1>;
191 defm USD : StoreM64<0x3f, "usd", store_u, 1>;
193 /// Multiply and Divide Instructions.
194 def DMULT : Mul64<0x1c, "dmult", IIImul>;
195 def DMULTu : Mul64<0x1d, "dmultu", IIImul>;
196 def DSDIV : Div64<MipsDivRem, 0x1e, "ddiv", IIIdiv>;
197 def DUDIV : Div64<MipsDivRemU, 0x1f, "ddivu", IIIdiv>;
200 def MTHI64 : MoveToLOHI64<0x11, "mthi">;
202 def MTLO64 : MoveToLOHI64<0x13, "mtlo">;
205 def MFHI64 : MoveFromLOHI64<0x10, "mfhi">;
207 def MFLO64 : MoveFromLOHI64<0x12, "mflo">;
210 def DCLZ : CountLeading64<0x24, "dclz",
211 [(set CPU64Regs:$dst, (ctlz CPU64Regs:$src))]>;
212 def DCLO : CountLeading64<0x25, "dclo",
213 [(set CPU64Regs:$dst, (ctlz (not CPU64Regs:$src)))]>;
215 //===----------------------------------------------------------------------===//
216 // Arbitrary patterns that map to one or more instructions
217 //===----------------------------------------------------------------------===//
220 def : Pat<(i64 immSExt16:$in),
221 (DADDiu ZERO_64, imm:$in)>;
222 def : Pat<(i64 immZExt16:$in),
223 (DORi ZERO_64, imm:$in)>;
226 def : Pat<(zextloadi32_u addr:$a), (DSRL (DSLL (ULW64_P8 addr:$a), 32), 32)>,
228 def : Pat<(zextloadi32_u addr:$a), (DSRL (DSLL (ULW64 addr:$a), 32), 32)>,
232 def : Pat<(i64 (MipsLo tglobaladdr:$in)), (DADDiu ZERO_64, tglobaladdr:$in)>;