Add definitions of instructions which move values between 64-bit integer
[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 // Move from Hi/Lo
94 let shamt = 0 in {
95 let rs = 0, rt = 0 in
96 class MoveFromLOHI64<bits<6> func, string instr_asm>:
97   FR<0x00, func, (outs CPU64Regs:$dst), (ins),
98      !strconcat(instr_asm, "\t$dst"), [], IIHiLo>;
99
100 let rt = 0, rd = 0 in
101 class MoveToLOHI64<bits<6> func, string instr_asm>:
102   FR<0x00, func, (outs), (ins CPU64Regs:$src),
103      !strconcat(instr_asm, "\t$src"), [], IIHiLo>;
104 }
105
106 //===----------------------------------------------------------------------===//
107 // Instruction definition
108 //===----------------------------------------------------------------------===//
109
110 /// Arithmetic Instructions (ALU Immediate)
111 def DADDiu   : ArithI64<0x19, "daddiu", add, simm16_64, immSExt16>;
112 def DANDi    : LogicI64<0x0c, "andi", and>;
113 def DORi     : LogicI64<0x0d, "ori",  or>;
114 def DXORi    : LogicI64<0x0e, "xori",  xor>;
115
116 /// Arithmetic Instructions (3-Operand, R-Type)
117 def DADDu    : ArithR64<0x00, 0x2d, "daddu", add, IIAlu, 1>;
118 def DSUBu    : ArithR64<0x00, 0x2f, "dsubu", sub, IIAlu>;
119 def DAND     : LogicR64<0x24, "and", and>;
120 def DOR      : LogicR64<0x25, "or", or>;
121 def DXOR     : LogicR64<0x26, "xor", xor>;
122
123 /// Shift Instructions
124 def DSLL     : LogicR_shift_rotate_imm64<0x38, 0x00, "dsll", shl, immZExt5>;
125 def DSRL     : LogicR_shift_rotate_imm64<0x3a, 0x00, "dsrl", srl, immZExt5>;
126 def DSRA     : LogicR_shift_rotate_imm64<0x3b, 0x00, "dsra", sra, immZExt5>;
127 def DSLL32   : LogicR_shift_rotate_imm64<0x3c, 0x00, "dsll32", shl, imm32_63>;
128 def DSRL32   : LogicR_shift_rotate_imm64<0x3e, 0x00, "dsrl32", srl, imm32_63>;
129 def DSRA32   : LogicR_shift_rotate_imm64<0x3f, 0x00, "dsra32", sra, imm32_63>;
130 def DSLLV    : LogicR_shift_rotate_reg64<0x24, 0x00, "dsllv", shl>;
131 def DSRLV    : LogicR_shift_rotate_reg64<0x26, 0x00, "dsrlv", srl>;
132 def DSRAV    : LogicR_shift_rotate_reg64<0x27, 0x00, "dsrav", sra>;
133
134 // Rotate Instructions
135 let Predicates = [HasMips64r2] in {
136   def DROTR    : LogicR_shift_rotate_imm64<0x3a, 0x01, "drotr", rotr, immZExt5>;
137   def DROTR32  : LogicR_shift_rotate_imm64<0x3e, 0x01, "drotr32", rotr,
138                                            imm32_63>;
139   def DROTRV   : LogicR_shift_rotate_reg64<0x16, 0x01, "drotrv", rotr>;
140 }
141
142 let Defs = [HI64] in
143   def MTHI64  : MoveToLOHI64<0x11, "mthi">;
144 let Defs = [LO64] in
145   def MTLO64  : MoveToLOHI64<0x13, "mtlo">;
146
147 let Uses = [HI64] in
148   def MFHI64  : MoveFromLOHI64<0x10, "mfhi">;
149 let Uses = [LO64] in
150   def MFLO64  : MoveFromLOHI64<0x12, "mflo">;
151
152 //===----------------------------------------------------------------------===//
153 //  Arbitrary patterns that map to one or more instructions
154 //===----------------------------------------------------------------------===//
155
156 // Small immediates
157 def : Pat<(i64 immSExt16:$in),
158           (DADDiu ZERO_64, imm:$in)>;
159 def : Pat<(i64 immZExt16:$in),
160           (DORi ZERO_64, imm:$in)>;