Add support for 64-bit divide instructions.
[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 // Mips64 Instruction Predicate Definitions.
16 //===----------------------------------------------------------------------===//
17 def HasMips64    : Predicate<"Subtarget.hasMips64()">;
18 def HasMips64r2  : Predicate<"Subtarget.hasMips64r2()">;
19
20 //===----------------------------------------------------------------------===//
21 // Mips Operand, Complex Patterns and Transformations Definitions.
22 //===----------------------------------------------------------------------===//
23
24 // Instruction operand types
25 def simm16_64      : Operand<i64>;
26 def shamt_64       : Operand<i64>;
27
28 // Unsigned Operand
29 def uimm16_64      : Operand<i64> {
30   let PrintMethod = "printUnsignedImm";
31 }
32
33 // Transformation Function - get Imm - 32.
34 def Subtract32 : SDNodeXForm<imm, [{
35   return getI32Imm((unsigned)N->getZExtValue() - 32);
36 }]>;
37
38 // imm32_63 predicate - True if imm is in range [32, 63].
39 def imm32_63 : ImmLeaf<i64,
40                        [{return (int32_t)Imm >= 32 && (int32_t)Imm < 64;}],
41                        Subtract32>;
42
43 //===----------------------------------------------------------------------===//
44 // Instructions specific format
45 //===----------------------------------------------------------------------===//
46
47 // Arithmetic 3 register operands
48 class ArithR64<bits<6> op, bits<6> func, string instr_asm, SDNode OpNode,
49                InstrItinClass itin, bit isComm = 0>:
50   FR<op, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
51      !strconcat(instr_asm, "\t$dst, $b, $c"),
52      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], itin> {
53   let isCommutable = isComm;
54 }
55
56 // Arithmetic 2 register operands
57 class ArithI64<bits<6> op, string instr_asm, SDNode OpNode,
58                Operand Od, PatLeaf imm_type> :
59   FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, Od:$c),
60      !strconcat(instr_asm, "\t$dst, $b, $c"),
61      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, imm_type:$c))], IIAlu>;
62
63 //  Logical
64 let isCommutable = 1 in
65 class LogicR64<bits<6> func, string instr_asm, SDNode OpNode>:
66   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, CPU64Regs:$c),
67      !strconcat(instr_asm, "\t$dst, $b, $c"),
68      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu>;
69
70 class LogicI64<bits<6> op, string instr_asm, SDNode OpNode>:
71   FI<op, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, uimm16_64:$c),
72      !strconcat(instr_asm, "\t$dst, $b, $c"),
73      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, immZExt16:$c))], IIAlu>;
74
75 // Shifts
76 class LogicR_shift_rotate_imm64<bits<6> func, bits<5> _rs, string instr_asm,
77                                 SDNode OpNode, PatFrag PF>:
78   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$b, shamt_64:$c),
79      !strconcat(instr_asm, "\t$dst, $b, $c"),
80      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, (i64 PF:$c)))],
81      IIAlu> {
82   let rs = _rs;
83 }
84
85 class LogicR_shift_rotate_reg64<bits<6> func, bits<5> _shamt, string instr_asm,
86                                 SDNode OpNode>:
87   FR<0x00, func, (outs CPU64Regs:$dst), (ins CPU64Regs:$c, CPU64Regs:$b),
88      !strconcat(instr_asm, "\t$dst, $b, $c"),
89      [(set CPU64Regs:$dst, (OpNode CPU64Regs:$b, CPU64Regs:$c))], IIAlu> {
90   let shamt = _shamt;
91 }
92
93 // Mul, Div
94 let Defs = [HI64, LO64] in {
95   let isCommutable = 1 in
96   class Mul64<bits<6> func, string instr_asm, InstrItinClass itin>:
97     FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
98        !strconcat(instr_asm, "\t$a, $b"), [], itin>;
99
100   class Div64<SDNode op, bits<6> func, string instr_asm, InstrItinClass itin>:
101               FR<0x00, func, (outs), (ins CPU64Regs:$a, CPU64Regs:$b),
102               !strconcat(instr_asm, "\t$$zero, $a, $b"),
103               [(op CPU64Regs:$a, CPU64Regs:$b)], itin>;
104 }
105
106 // Move from Hi/Lo
107 let shamt = 0 in {
108 let rs = 0, rt = 0 in
109 class MoveFromLOHI64<bits<6> func, string instr_asm>:
110   FR<0x00, func, (outs CPU64Regs:$dst), (ins),
111      !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
112
113 let rt = 0, rd = 0 in
114 class MoveToLOHI64<bits<6> func, string instr_asm>:
115   FR<0x00, func, (outs), (ins CPU64Regs:$src),
116      !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
117 }
118
119 //===----------------------------------------------------------------------===//
120 // Instruction definition
121 //===----------------------------------------------------------------------===//
122
123 /// Arithmetic Instructions (ALU Immediate)
124 def DADDiu   : ArithI64<0x19, "daddiu", add, simm16_64, immSExt16>;
125 def DANDi    : LogicI64<0x0c, "andi", and>;
126 def DORi     : LogicI64<0x0d, "ori",  or>;
127 def DXORi    : LogicI64<0x0e, "xori",  xor>;
128
129 /// Arithmetic Instructions (3-Operand, R-Type)
130 def DADDu    : ArithR64<0x00, 0x2d, "daddu", add, IIAlu, 1>;
131 def DSUBu    : ArithR64<0x00, 0x2f, "dsubu", sub, IIAlu>;
132 def DAND     : LogicR64<0x24, "and", and>;
133 def DOR      : LogicR64<0x25, "or", or>;
134 def DXOR     : LogicR64<0x26, "xor", xor>;
135
136 /// Shift Instructions
137 def DSLL     : LogicR_shift_rotate_imm64<0x38, 0x00, "dsll", shl, immZExt5>;
138 def DSRL     : LogicR_shift_rotate_imm64<0x3a, 0x00, "dsrl", srl, immZExt5>;
139 def DSRA     : LogicR_shift_rotate_imm64<0x3b, 0x00, "dsra", sra, immZExt5>;
140 def DSLL32   : LogicR_shift_rotate_imm64<0x3c, 0x00, "dsll32", shl, imm32_63>;
141 def DSRL32   : LogicR_shift_rotate_imm64<0x3e, 0x00, "dsrl32", srl, imm32_63>;
142 def DSRA32   : LogicR_shift_rotate_imm64<0x3f, 0x00, "dsra32", sra, imm32_63>;
143 def DSLLV    : LogicR_shift_rotate_reg64<0x24, 0x00, "dsllv", shl>;
144 def DSRLV    : LogicR_shift_rotate_reg64<0x26, 0x00, "dsrlv", srl>;
145 def DSRAV    : LogicR_shift_rotate_reg64<0x27, 0x00, "dsrav", sra>;
146
147 // Rotate Instructions
148 let Predicates = [HasMips64r2] in {
149   def DROTR    : LogicR_shift_rotate_imm64<0x3a, 0x01, "drotr", rotr, immZExt5>;
150   def DROTR32  : LogicR_shift_rotate_imm64<0x3e, 0x01, "drotr32", rotr,
151                                            imm32_63>;
152   def DROTRV   : LogicR_shift_rotate_reg64<0x16, 0x01, "drotrv", rotr>;
153 }
154
155 /// Multiply and Divide Instructions.
156 def DMULT    : Mul64<0x1c, "dmult", IIImul>;
157 def DMULTu   : Mul64<0x1d, "dmultu", IIImul>;
158 def DSDIV    : Div64<MipsDivRem, 0x1e, "ddiv", IIIdiv>;
159 def DUDIV    : Div64<MipsDivRemU, 0x1f, "ddivu", IIIdiv>;
160
161 let Defs = [HI64] in
162   def MTHI64  : MoveToLOHI64<0x11, "mthi">;
163 let Defs = [LO64] in
164   def MTLO64  : MoveToLOHI64<0x13, "mtlo">;
165
166 let Uses = [HI64] in
167   def MFHI64  : MoveFromLOHI64<0x10, "mfhi">;
168 let Uses = [LO64] in
169   def MFLO64  : MoveFromLOHI64<0x12, "mflo">;
170
171 //===----------------------------------------------------------------------===//
172 //  Arbitrary patterns that map to one or more instructions
173 //===----------------------------------------------------------------------===//
174
175 // Small immediates
176 def : Pat<(i64 immSExt16:$in),
177           (DADDiu ZERO_64, imm:$in)>;
178 def : Pat<(i64 immZExt16:$in),
179           (DORi ZERO_64, imm:$in)>;