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