blob: 62229c33b6de6da3eeba5a8f88a4fa9050ccd8c8 [file] [log] [blame]
Anton Korobeynikovd4022c32009-05-29 23:41:08 +00001//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
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 the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +000013
Evan Cheng06e16582009-07-10 01:54:42 +000014// IT block predicate field
15def it_pred : Operand<i32> {
Johnny Chen9d3acaa2010-03-02 17:57:15 +000016 let PrintMethod = "printMandatoryPredicateOperand";
Evan Cheng06e16582009-07-10 01:54:42 +000017}
18
19// IT block condition mask
20def it_mask : Operand<i32> {
21 let PrintMethod = "printThumbITMask";
22}
23
Evan Cheng5657c012009-07-29 02:18:14 +000024// Table branch address
25def tb_addrmode : Operand<i32> {
26 let PrintMethod = "printTBAddrMode";
27}
28
Anton Korobeynikov52237112009-06-17 18:13:58 +000029// Shifted operands. No register controlled shifts for Thumb2.
30// Note: We do not support rrx shifted operands yet.
31def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000032 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000033 [shl,srl,sra,rotr]> {
Owen Anderson5de6d842010-11-12 21:12:40 +000034 string EncoderMethod = "getT2SORegOpValue";
Evan Cheng9cb9e672009-06-27 02:26:13 +000035 let PrintMethod = "printT2SOOperand";
Jim Grosbach6ccfc502010-07-30 02:41:01 +000036 let MIOperandInfo = (ops rGPR, i32imm);
Anton Korobeynikov52237112009-06-17 18:13:58 +000037}
38
Evan Chengf49810c2009-06-23 17:48:47 +000039// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
40def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000041 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000042}]>;
43
Evan Chengf49810c2009-06-23 17:48:47 +000044// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
45def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000046 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000047}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000048
Evan Chengf49810c2009-06-23 17:48:47 +000049// t2_so_imm - Match a 32-bit immediate operand, which is an
50// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
51// immediate splatted into multiple bytes of the word. t2_so_imm values are
52// represented in the imm field in the same 12-bit form that they are encoded
Jim Grosbach6935efc2009-11-24 00:20:27 +000053// into t2_so_imm instructions: the 8-bit immediate is the least significant
54// bits [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
Owen Anderson5de6d842010-11-12 21:12:40 +000055def t2_so_imm : Operand<i32>, PatLeaf<(imm), [{ return Pred_t2_so_imm(N); }]> {
56 string EncoderMethod = "getT2SOImmOpValue";
57}
Anton Korobeynikov52237112009-06-17 18:13:58 +000058
Jim Grosbach64171712010-02-16 21:07:46 +000059// t2_so_imm_not - Match an immediate that is a complement
Evan Chengf49810c2009-06-23 17:48:47 +000060// of a t2_so_imm.
61def t2_so_imm_not : Operand<i32>,
62 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000063 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
64}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000065
66// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
67def t2_so_imm_neg : Operand<i32>,
68 PatLeaf<(imm), [{
Evan Cheng875a6ac2010-11-12 22:42:47 +000069 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
Evan Chenge7cbe412009-07-08 21:03:57 +000070}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000071
Jim Grosbach65b7f3a2009-10-21 20:44:34 +000072// Break t2_so_imm's up into two pieces. This handles immediates with up to 16
73// bits set in them. This uses t2_so_imm2part to match and t2_so_imm2part_[12]
74// to get the first/second pieces.
75def t2_so_imm2part : Operand<i32>,
76 PatLeaf<(imm), [{
77 return ARM_AM::isT2SOImmTwoPartVal((unsigned)N->getZExtValue());
78 }]> {
79}
80
81def t2_so_imm2part_1 : SDNodeXForm<imm, [{
82 unsigned V = ARM_AM::getT2SOImmTwoPartFirst((unsigned)N->getZExtValue());
83 return CurDAG->getTargetConstant(V, MVT::i32);
84}]>;
85
86def t2_so_imm2part_2 : SDNodeXForm<imm, [{
87 unsigned V = ARM_AM::getT2SOImmTwoPartSecond((unsigned)N->getZExtValue());
88 return CurDAG->getTargetConstant(V, MVT::i32);
89}]>;
90
Jim Grosbach15e6ef82009-11-23 20:35:53 +000091def t2_so_neg_imm2part : Operand<i32>, PatLeaf<(imm), [{
92 return ARM_AM::isT2SOImmTwoPartVal(-(int)N->getZExtValue());
93 }]> {
94}
95
96def t2_so_neg_imm2part_1 : SDNodeXForm<imm, [{
97 unsigned V = ARM_AM::getT2SOImmTwoPartFirst(-(int)N->getZExtValue());
98 return CurDAG->getTargetConstant(V, MVT::i32);
99}]>;
100
101def t2_so_neg_imm2part_2 : SDNodeXForm<imm, [{
102 unsigned V = ARM_AM::getT2SOImmTwoPartSecond(-(int)N->getZExtValue());
103 return CurDAG->getTargetConstant(V, MVT::i32);
104}]>;
105
Evan Chenga67efd12009-06-23 19:39:13 +0000106/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
107def imm1_31 : PatLeaf<(i32 imm), [{
108 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
109}]>;
110
Evan Chengf49810c2009-06-23 17:48:47 +0000111/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
Evan Cheng86198642009-08-07 00:34:42 +0000112def imm0_4095 : Operand<i32>,
113 PatLeaf<(i32 imm), [{
Evan Chengf49810c2009-06-23 17:48:47 +0000114 return (uint32_t)N->getZExtValue() < 4096;
115}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000116
Jim Grosbach64171712010-02-16 21:07:46 +0000117def imm0_4095_neg : PatLeaf<(i32 imm), [{
118 return (uint32_t)(-N->getZExtValue()) < 4096;
119}], imm_neg_XFORM>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000120
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000121def imm0_255_neg : PatLeaf<(i32 imm), [{
122 return (uint32_t)(-N->getZExtValue()) < 255;
Jim Grosbach64171712010-02-16 21:07:46 +0000123}], imm_neg_XFORM>;
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000124
Jim Grosbach502e0aa2010-07-14 17:45:16 +0000125def imm0_255_not : PatLeaf<(i32 imm), [{
126 return (uint32_t)(~N->getZExtValue()) < 255;
127}], imm_comp_XFORM>;
128
Evan Cheng055b0312009-06-29 07:51:04 +0000129// Define Thumb2 specific addressing modes.
130
131// t2addrmode_imm12 := reg + imm12
132def t2addrmode_imm12 : Operand<i32>,
133 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000134 let PrintMethod = "printAddrModeImm12Operand";
Evan Cheng055b0312009-06-29 07:51:04 +0000135 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
136}
137
Johnny Chen0635fc52010-03-04 17:40:44 +0000138// t2addrmode_imm8 := reg +/- imm8
Evan Cheng055b0312009-06-29 07:51:04 +0000139def t2addrmode_imm8 : Operand<i32>,
140 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
141 let PrintMethod = "printT2AddrModeImm8Operand";
142 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
143}
144
Evan Cheng6d94f112009-07-03 00:06:39 +0000145def t2am_imm8_offset : Operand<i32>,
Chris Lattner52a261b2010-09-21 20:31:19 +0000146 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
147 [], [SDNPWantRoot]> {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000148 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
149}
150
Evan Cheng5c874172009-07-09 22:21:59 +0000151// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
Chris Lattner979b0612010-09-05 22:51:11 +0000152def t2addrmode_imm8s4 : Operand<i32> {
Evan Cheng5c874172009-07-09 22:21:59 +0000153 let PrintMethod = "printT2AddrModeImm8s4Operand";
David Goodwin6647cea2009-06-30 22:50:01 +0000154 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
155}
156
Johnny Chenae1757b2010-03-11 01:13:36 +0000157def t2am_imm8s4_offset : Operand<i32> {
158 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
159}
160
Evan Chengcba962d2009-07-09 20:40:44 +0000161// t2addrmode_so_reg := reg + (reg << imm2)
Evan Cheng055b0312009-06-29 07:51:04 +0000162def t2addrmode_so_reg : Operand<i32>,
163 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
164 let PrintMethod = "printT2AddrModeSoRegOperand";
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000165 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
Evan Cheng055b0312009-06-29 07:51:04 +0000166}
167
168
Anton Korobeynikov52237112009-06-17 18:13:58 +0000169//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000170// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000171//
172
Owen Andersonb9a643e2010-11-12 23:36:03 +0000173class T2TwoRegShiftedImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson5de6d842010-11-12 21:12:40 +0000174 string opc, string asm, list<dag> pattern>
175 : T2sI<oops, iops, itin, opc, asm, pattern> {
176 bits<4> Rd;
177 bits<4> Rn;
178 bits<12> imm;
179
180 let Inst{11-8} = Rd{3-0};
181 let Inst{19-16} = Rn{3-0};
182 let Inst{26} = imm{11};
183 let Inst{14-12} = imm{10-8};
184 let Inst{7-0} = imm{7-0};
185}
186
187class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
188 string opc, string asm, list<dag> pattern>
189 : T2sI<oops, iops, itin, opc, asm, pattern> {
190 bits<4> Rd;
191 bits<4> Rn;
192 bits<4> Rm;
193
194 let Inst{11-8} = Rd{3-0};
195 let Inst{19-16} = Rn{3-0};
196 let Inst{3-0} = Rm{3-0};
197}
198
199class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
200 string opc, string asm, list<dag> pattern>
201 : T2sI<oops, iops, itin, opc, asm, pattern> {
202 bits<4> Rd;
203 bits<4> Rn;
204 bits<12> ShiftedRm;
205
206 let Inst{11-8} = Rd{3-0};
207 let Inst{19-16} = Rn{3-0};
208 let Inst{3-0} = ShiftedRm{3-0};
209 let Inst{5-4} = ShiftedRm{6-5};
210 let Inst{14-12} = ShiftedRm{11-9};
211 let Inst{7-6} = ShiftedRm{8-7};
212}
213
Evan Chenga67efd12009-06-23 19:39:13 +0000214/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000215/// unary operation that produces a value. These are predicable and can be
216/// changed to modify CPSR.
Evan Cheng5d42c562010-09-29 00:49:25 +0000217multiclass T2I_un_irs<bits<4> opcod, string opc,
218 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
219 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
Evan Chenga67efd12009-06-23 19:39:13 +0000220 // shifted imm
Evan Cheng5d42c562010-09-29 00:49:25 +0000221 def i : T2sI<(outs rGPR:$dst), (ins t2_so_imm:$src), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000222 opc, "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000223 [(set rGPR:$dst, (opnode t2_so_imm:$src))]> {
Evan Chenga67efd12009-06-23 19:39:13 +0000224 let isAsCheapAsAMove = Cheap;
225 let isReMaterializable = ReMat;
Johnny Chend68e1192009-12-15 17:24:14 +0000226 let Inst{31-27} = 0b11110;
227 let Inst{25} = 0;
228 let Inst{24-21} = opcod;
229 let Inst{20} = ?; // The S bit.
230 let Inst{19-16} = 0b1111; // Rn
231 let Inst{15} = 0;
Evan Chenga67efd12009-06-23 19:39:13 +0000232 }
233 // register
Evan Cheng5d42c562010-09-29 00:49:25 +0000234 def r : T2sI<(outs rGPR:$dst), (ins rGPR:$src), iir,
Bob Wilsonc21763f2010-05-24 22:41:19 +0000235 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000236 [(set rGPR:$dst, (opnode rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000237 let Inst{31-27} = 0b11101;
238 let Inst{26-25} = 0b01;
239 let Inst{24-21} = opcod;
240 let Inst{20} = ?; // The S bit.
241 let Inst{19-16} = 0b1111; // Rn
242 let Inst{14-12} = 0b000; // imm3
243 let Inst{7-6} = 0b00; // imm2
244 let Inst{5-4} = 0b00; // type
245 }
Evan Chenga67efd12009-06-23 19:39:13 +0000246 // shifted register
Evan Cheng5d42c562010-09-29 00:49:25 +0000247 def s : T2sI<(outs rGPR:$dst), (ins t2_so_reg:$src), iis,
Bob Wilsonc21763f2010-05-24 22:41:19 +0000248 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000249 [(set rGPR:$dst, (opnode t2_so_reg:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000250 let Inst{31-27} = 0b11101;
251 let Inst{26-25} = 0b01;
252 let Inst{24-21} = opcod;
253 let Inst{20} = ?; // The S bit.
254 let Inst{19-16} = 0b1111; // Rn
255 }
Evan Chenga67efd12009-06-23 19:39:13 +0000256}
257
258/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Bob Wilson4876bdb2010-05-25 04:43:08 +0000259/// binary operation that produces a value. These are predicable and can be
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000260/// changed to modify CPSR.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000261multiclass T2I_bin_irs<bits<4> opcod, string opc,
262 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
263 PatFrag opnode, bit Commutable = 0, string wide = ""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000264 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000265 def ri : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, t2_so_imm:$rhs), iii,
266 opc, "\t$dst, $lhs, $rhs",
267 [(set rGPR:$dst, (opnode rGPR:$lhs, t2_so_imm:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000268 let Inst{31-27} = 0b11110;
269 let Inst{25} = 0;
270 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000271 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000272 let Inst{15} = 0;
273 }
Evan Chenga67efd12009-06-23 19:39:13 +0000274 // register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000275 def rr : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, rGPR:$rhs), iir,
276 opc, !strconcat(wide, "\t$dst, $lhs, $rhs"),
277 [(set rGPR:$dst, (opnode rGPR:$lhs, rGPR:$rhs))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000278 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000279 let Inst{31-27} = 0b11101;
280 let Inst{26-25} = 0b01;
281 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000282 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000283 let Inst{14-12} = 0b000; // imm3
284 let Inst{7-6} = 0b00; // imm2
285 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000286 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000287 // shifted register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000288 def rs : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, t2_so_reg:$rhs), iis,
289 opc, !strconcat(wide, "\t$dst, $lhs, $rhs"),
290 [(set rGPR:$dst, (opnode rGPR:$lhs, t2_so_reg:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000291 let Inst{31-27} = 0b11101;
292 let Inst{26-25} = 0b01;
293 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000294 let Inst{20} = ?; // The S bit.
295 }
296}
297
David Goodwin1f096272009-07-27 23:34:12 +0000298/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
299// the ".w" prefix to indicate that they are wide.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000300multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
301 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
302 PatFrag opnode, bit Commutable = 0> :
303 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w">;
Bill Wendling1f7bf0e2010-08-29 03:55:31 +0000304
Evan Cheng1e249e32009-06-25 20:59:23 +0000305/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000306/// reversed. The 'rr' form is only defined for the disassembler; for codegen
307/// it is equivalent to the T2I_bin_irs counterpart.
308multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000309 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000310 def ri : T2sI<(outs rGPR:$dst), (ins rGPR:$rhs, t2_so_imm:$lhs), IIC_iALUi,
311 opc, ".w\t$dst, $rhs, $lhs",
312 [(set rGPR:$dst, (opnode t2_so_imm:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000313 let Inst{31-27} = 0b11110;
314 let Inst{25} = 0;
315 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000316 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000317 let Inst{15} = 0;
318 }
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000319 // register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000320 def rr : T2sI<(outs rGPR:$dst), (ins rGPR:$rhs, rGPR:$lhs), IIC_iALUr,
321 opc, "\t$dst, $rhs, $lhs",
Bob Wilson136e4912010-08-14 03:18:29 +0000322 [/* For disassembly only; pattern left blank */]> {
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000323 let Inst{31-27} = 0b11101;
324 let Inst{26-25} = 0b01;
325 let Inst{24-21} = opcod;
326 let Inst{20} = ?; // The S bit.
327 let Inst{14-12} = 0b000; // imm3
328 let Inst{7-6} = 0b00; // imm2
329 let Inst{5-4} = 0b00; // type
330 }
Evan Chengf49810c2009-06-23 17:48:47 +0000331 // shifted register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000332 def rs : T2sI<(outs rGPR:$dst), (ins rGPR:$rhs, t2_so_reg:$lhs), IIC_iALUsir,
333 opc, "\t$dst, $rhs, $lhs",
334 [(set rGPR:$dst, (opnode t2_so_reg:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000335 let Inst{31-27} = 0b11101;
336 let Inst{26-25} = 0b01;
337 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000338 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000339 }
Evan Chengf49810c2009-06-23 17:48:47 +0000340}
341
Evan Chenga67efd12009-06-23 19:39:13 +0000342/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000343/// instruction modifies the CPSR register.
344let Defs = [CPSR] in {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000345multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
346 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
347 PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000348 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000349 def ri : T2I<(outs rGPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs), iii,
350 !strconcat(opc, "s"), ".w\t$dst, $lhs, $rhs",
351 [(set rGPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000352 let Inst{31-27} = 0b11110;
353 let Inst{25} = 0;
354 let Inst{24-21} = opcod;
355 let Inst{20} = 1; // The S bit.
356 let Inst{15} = 0;
357 }
Evan Chenga67efd12009-06-23 19:39:13 +0000358 // register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000359 def rr : T2I<(outs rGPR:$dst), (ins GPR:$lhs, rGPR:$rhs), iir,
360 !strconcat(opc, "s"), ".w\t$dst, $lhs, $rhs",
361 [(set rGPR:$dst, (opnode GPR:$lhs, rGPR:$rhs))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000362 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000363 let Inst{31-27} = 0b11101;
364 let Inst{26-25} = 0b01;
365 let Inst{24-21} = opcod;
366 let Inst{20} = 1; // The S bit.
367 let Inst{14-12} = 0b000; // imm3
368 let Inst{7-6} = 0b00; // imm2
369 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000370 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000371 // shifted register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000372 def rs : T2I<(outs rGPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs), iis,
373 !strconcat(opc, "s"), ".w\t$dst, $lhs, $rhs",
374 [(set rGPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000375 let Inst{31-27} = 0b11101;
376 let Inst{26-25} = 0b01;
377 let Inst{24-21} = opcod;
378 let Inst{20} = 1; // The S bit.
379 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000380}
381}
382
Evan Chenga67efd12009-06-23 19:39:13 +0000383/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
384/// patterns for a binary operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000385multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
386 bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000387 // shifted imm
Jim Grosbach663e3392010-08-30 19:49:58 +0000388 // The register-immediate version is re-materializable. This is useful
389 // in particular for taking the address of a local.
390 let isReMaterializable = 1 in {
Owen Andersonb9a643e2010-11-12 23:36:03 +0000391 def ri : T2sI<(outs rGPR:$dst), (ins GPR:$lhs, t2_so_imm:$rhs), IIC_iALUi,
392 opc, ".w\t$dst, $lhs, $rhs",
393 [(set rGPR:$dst, (opnode GPR:$lhs, t2_so_imm:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000394 let Inst{31-27} = 0b11110;
395 let Inst{25} = 0;
396 let Inst{24} = 1;
397 let Inst{23-21} = op23_21;
398 let Inst{20} = 0; // The S bit.
399 let Inst{15} = 0;
400 }
Jim Grosbach663e3392010-08-30 19:49:58 +0000401 }
Evan Chengf49810c2009-06-23 17:48:47 +0000402 // 12-bit imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000403 def ri12 : T2I<(outs rGPR:$dst), (ins GPR:$lhs, imm0_4095:$rhs), IIC_iALUi,
404 !strconcat(opc, "w"), "\t$dst, $lhs, $rhs",
405 [(set rGPR:$dst, (opnode GPR:$lhs, imm0_4095:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000406 let Inst{31-27} = 0b11110;
407 let Inst{25} = 1;
408 let Inst{24} = 0;
409 let Inst{23-21} = op23_21;
410 let Inst{20} = 0; // The S bit.
411 let Inst{15} = 0;
412 }
Evan Chenga67efd12009-06-23 19:39:13 +0000413 // register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000414 def rr : T2sI<(outs rGPR:$dst), (ins GPR:$lhs, rGPR:$rhs), IIC_iALUr,
415 opc, ".w\t$dst, $lhs, $rhs",
416 [(set rGPR:$dst, (opnode GPR:$lhs, rGPR:$rhs))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000417 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000418 let Inst{31-27} = 0b11101;
419 let Inst{26-25} = 0b01;
420 let Inst{24} = 1;
421 let Inst{23-21} = op23_21;
422 let Inst{20} = 0; // The S bit.
423 let Inst{14-12} = 0b000; // imm3
424 let Inst{7-6} = 0b00; // imm2
425 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000426 }
Evan Chengf49810c2009-06-23 17:48:47 +0000427 // shifted register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000428 def rs : T2sI<(outs rGPR:$dst), (ins GPR:$lhs, t2_so_reg:$rhs), IIC_iALUsi,
429 opc, ".w\t$dst, $lhs, $rhs",
430 [(set rGPR:$dst, (opnode GPR:$lhs, t2_so_reg:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000431 let Inst{31-27} = 0b11101;
Johnny Chend68e1192009-12-15 17:24:14 +0000432 let Inst{26-25} = 0b01;
Johnny Chend248ffb2010-01-08 17:41:33 +0000433 let Inst{24} = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000434 let Inst{23-21} = op23_21;
435 let Inst{20} = 0; // The S bit.
436 }
Evan Chengf49810c2009-06-23 17:48:47 +0000437}
438
Jim Grosbach6935efc2009-11-24 00:20:27 +0000439/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000440/// for a binary operation that produces a value and use the carry
Jim Grosbach6935efc2009-11-24 00:20:27 +0000441/// bit. It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000442let Uses = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000443multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
444 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000445 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000446 def ri : T2TwoRegShiftedImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000447 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
448 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000449 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000450 let Inst{31-27} = 0b11110;
451 let Inst{25} = 0;
452 let Inst{24-21} = opcod;
453 let Inst{20} = 0; // The S bit.
454 let Inst{15} = 0;
455 }
Evan Chenga67efd12009-06-23 19:39:13 +0000456 // register
Owen Anderson5de6d842010-11-12 21:12:40 +0000457 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
458 opc, ".w\t$Rd, $Rn, $Rm",
459 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000460 Requires<[IsThumb2]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000461 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000462 let Inst{31-27} = 0b11101;
463 let Inst{26-25} = 0b01;
464 let Inst{24-21} = opcod;
465 let Inst{20} = 0; // The S bit.
466 let Inst{14-12} = 0b000; // imm3
467 let Inst{7-6} = 0b00; // imm2
468 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000469 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000470 // shifted register
Owen Anderson5de6d842010-11-12 21:12:40 +0000471 def rs : T2TwoRegShiftedReg<
472 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
473 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
474 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000475 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000476 let Inst{31-27} = 0b11101;
477 let Inst{26-25} = 0b01;
478 let Inst{24-21} = opcod;
479 let Inst{20} = 0; // The S bit.
480 }
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000481}
482
483// Carry setting variants
484let Defs = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000485multiclass T2I_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
486 bit Commutable = 0> {
Evan Cheng62674222009-06-25 23:34:10 +0000487 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000488 def ri : T2TwoRegShiftedImm<
Owen Anderson5de6d842010-11-12 21:12:40 +0000489 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
490 opc, "\t$Rd, $Rn, $imm",
491 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000492 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000493 let Inst{31-27} = 0b11110;
494 let Inst{25} = 0;
495 let Inst{24-21} = opcod;
496 let Inst{20} = 1; // The S bit.
497 let Inst{15} = 0;
498 }
Evan Cheng62674222009-06-25 23:34:10 +0000499 // register
Owen Anderson5de6d842010-11-12 21:12:40 +0000500 def rr : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
501 opc, ".w\t$Rd, $Rn, $Rm",
502 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000503 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000504 let isCommutable = Commutable;
505 let Inst{31-27} = 0b11101;
506 let Inst{26-25} = 0b01;
507 let Inst{24-21} = opcod;
508 let Inst{20} = 1; // The S bit.
509 let Inst{14-12} = 0b000; // imm3
510 let Inst{7-6} = 0b00; // imm2
511 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000512 }
Evan Cheng62674222009-06-25 23:34:10 +0000513 // shifted register
Owen Anderson5de6d842010-11-12 21:12:40 +0000514 def rs : T2TwoRegShiftedReg<
515 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
516 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
517 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000518 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000519 let Inst{31-27} = 0b11101;
520 let Inst{26-25} = 0b01;
521 let Inst{24-21} = opcod;
522 let Inst{20} = 1; // The S bit.
Evan Cheng8de898a2009-06-26 00:19:44 +0000523 }
Evan Chengf49810c2009-06-23 17:48:47 +0000524}
525}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000526}
Evan Chengf49810c2009-06-23 17:48:47 +0000527
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000528/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
529/// version is not needed since this is only for codegen.
Evan Cheng1e249e32009-06-25 20:59:23 +0000530let Defs = [CPSR] in {
Johnny Chend68e1192009-12-15 17:24:14 +0000531multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000532 // shifted imm
Owen Andersonb9a643e2010-11-12 23:36:03 +0000533 def ri : T2I<(outs rGPR:$dst), (ins rGPR:$rhs, t2_so_imm:$lhs), IIC_iALUi,
534 !strconcat(opc, "s"), ".w\t$dst, $rhs, $lhs",
535 [(set rGPR:$dst, (opnode t2_so_imm:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000536 let Inst{31-27} = 0b11110;
537 let Inst{25} = 0;
538 let Inst{24-21} = opcod;
539 let Inst{20} = 1; // The S bit.
540 let Inst{15} = 0;
541 }
Evan Chengf49810c2009-06-23 17:48:47 +0000542 // shifted register
Owen Andersonb9a643e2010-11-12 23:36:03 +0000543 def rs : T2I<(outs rGPR:$dst), (ins rGPR:$rhs, t2_so_reg:$lhs), IIC_iALUsi,
544 !strconcat(opc, "s"), "\t$dst, $rhs, $lhs",
545 [(set rGPR:$dst, (opnode t2_so_reg:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000546 let Inst{31-27} = 0b11101;
547 let Inst{26-25} = 0b01;
548 let Inst{24-21} = opcod;
549 let Inst{20} = 1; // The S bit.
550 }
Evan Chengf49810c2009-06-23 17:48:47 +0000551}
552}
553
Evan Chenga67efd12009-06-23 19:39:13 +0000554/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
555// rotate operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000556multiclass T2I_sh_ir<bits<2> opcod, string opc, PatFrag opnode> {
Evan Chenga67efd12009-06-23 19:39:13 +0000557 // 5-bit imm
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000558 def ri : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +0000559 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000560 [(set rGPR:$dst, (opnode rGPR:$lhs, imm1_31:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000561 let Inst{31-27} = 0b11101;
562 let Inst{26-21} = 0b010010;
563 let Inst{19-16} = 0b1111; // Rn
564 let Inst{5-4} = opcod;
565 }
Evan Chenga67efd12009-06-23 19:39:13 +0000566 // register
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000567 def rr : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, rGPR:$rhs), IIC_iMOVsr,
Evan Cheng699beba2009-10-27 00:08:59 +0000568 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000569 [(set rGPR:$dst, (opnode rGPR:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000570 let Inst{31-27} = 0b11111;
571 let Inst{26-23} = 0b0100;
572 let Inst{22-21} = opcod;
573 let Inst{15-12} = 0b1111;
574 let Inst{7-4} = 0b0000;
575 }
Evan Chenga67efd12009-06-23 19:39:13 +0000576}
Evan Chengf49810c2009-06-23 17:48:47 +0000577
Johnny Chend68e1192009-12-15 17:24:14 +0000578/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
Evan Chenga67efd12009-06-23 19:39:13 +0000579/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000580/// a explicit result, only implicitly set CPSR.
Bill Wendlingf0e132c2010-08-19 00:05:48 +0000581let isCompare = 1, Defs = [CPSR] in {
Evan Cheng5d42c562010-09-29 00:49:25 +0000582multiclass T2I_cmp_irs<bits<4> opcod, string opc,
583 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
584 PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000585 // shifted imm
Evan Cheng5d42c562010-09-29 00:49:25 +0000586 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000587 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000588 [(opnode GPR:$lhs, t2_so_imm:$rhs)]> {
589 let Inst{31-27} = 0b11110;
590 let Inst{25} = 0;
591 let Inst{24-21} = opcod;
592 let Inst{20} = 1; // The S bit.
593 let Inst{15} = 0;
594 let Inst{11-8} = 0b1111; // Rd
595 }
Evan Chenga67efd12009-06-23 19:39:13 +0000596 // register
Evan Cheng5d42c562010-09-29 00:49:25 +0000597 def rr : T2I<(outs), (ins GPR:$lhs, rGPR:$rhs), iir,
Evan Cheng699beba2009-10-27 00:08:59 +0000598 opc, ".w\t$lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000599 [(opnode GPR:$lhs, rGPR:$rhs)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000600 let Inst{31-27} = 0b11101;
601 let Inst{26-25} = 0b01;
602 let Inst{24-21} = opcod;
603 let Inst{20} = 1; // The S bit.
604 let Inst{14-12} = 0b000; // imm3
605 let Inst{11-8} = 0b1111; // Rd
606 let Inst{7-6} = 0b00; // imm2
607 let Inst{5-4} = 0b00; // type
608 }
Evan Chengf49810c2009-06-23 17:48:47 +0000609 // shifted register
Evan Cheng5d42c562010-09-29 00:49:25 +0000610 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000611 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000612 [(opnode GPR:$lhs, t2_so_reg:$rhs)]> {
613 let Inst{31-27} = 0b11101;
614 let Inst{26-25} = 0b01;
615 let Inst{24-21} = opcod;
616 let Inst{20} = 1; // The S bit.
617 let Inst{11-8} = 0b1111; // Rd
618 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000619}
620}
621
Evan Chengf3c21b82009-06-30 02:15:48 +0000622/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000623multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000624 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000625 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000626 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000627 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]> {
628 let Inst{31-27} = 0b11111;
629 let Inst{26-25} = 0b00;
630 let Inst{24} = signed;
631 let Inst{23} = 1;
632 let Inst{22-21} = opcod;
633 let Inst{20} = 1; // load
634 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000635 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000636 opc, "\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000637 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]> {
638 let Inst{31-27} = 0b11111;
639 let Inst{26-25} = 0b00;
640 let Inst{24} = signed;
641 let Inst{23} = 0;
642 let Inst{22-21} = opcod;
643 let Inst{20} = 1; // load
644 let Inst{11} = 1;
645 // Offset: index==TRUE, wback==FALSE
646 let Inst{10} = 1; // The P bit.
647 let Inst{8} = 0; // The W bit.
648 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000649 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000650 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000651 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]> {
652 let Inst{31-27} = 0b11111;
653 let Inst{26-25} = 0b00;
654 let Inst{24} = signed;
655 let Inst{23} = 0;
656 let Inst{22-21} = opcod;
657 let Inst{20} = 1; // load
658 let Inst{11-6} = 0b000000;
659 }
Evan Chengbc7deb02010-11-03 05:14:24 +0000660
661 // FIXME: Is the pci variant actually needed?
Evan Cheng0e55fd62010-09-30 01:08:25 +0000662 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000663 opc, ".w\t$dst, $addr",
Evan Cheng9eda6892009-10-31 03:39:36 +0000664 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]> {
665 let isReMaterializable = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000666 let Inst{31-27} = 0b11111;
667 let Inst{26-25} = 0b00;
668 let Inst{24} = signed;
669 let Inst{23} = ?; // add = (U == '1')
670 let Inst{22-21} = opcod;
671 let Inst{20} = 1; // load
672 let Inst{19-16} = 0b1111; // Rn
Evan Cheng9eda6892009-10-31 03:39:36 +0000673 }
Evan Chengf3c21b82009-06-30 02:15:48 +0000674}
675
David Goodwin73b8f162009-06-30 22:11:34 +0000676/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000677multiclass T2I_st<bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000678 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000679 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000680 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000681 [(opnode GPR:$src, t2addrmode_imm12:$addr)]> {
682 let Inst{31-27} = 0b11111;
683 let Inst{26-23} = 0b0001;
684 let Inst{22-21} = opcod;
685 let Inst{20} = 0; // !load
686 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000687 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000688 opc, "\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000689 [(opnode GPR:$src, t2addrmode_imm8:$addr)]> {
690 let Inst{31-27} = 0b11111;
691 let Inst{26-23} = 0b0000;
692 let Inst{22-21} = opcod;
693 let Inst{20} = 0; // !load
694 let Inst{11} = 1;
695 // Offset: index==TRUE, wback==FALSE
696 let Inst{10} = 1; // The P bit.
697 let Inst{8} = 0; // The W bit.
698 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000699 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000700 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000701 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]> {
702 let Inst{31-27} = 0b11111;
703 let Inst{26-23} = 0b0000;
704 let Inst{22-21} = opcod;
705 let Inst{20} = 0; // !load
706 let Inst{11-6} = 0b000000;
707 }
David Goodwin73b8f162009-06-30 22:11:34 +0000708}
709
Evan Cheng0e55fd62010-09-30 01:08:25 +0000710/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000711/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000712multiclass T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> {
713 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000714 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000715 [(set rGPR:$dst, (opnode rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000716 let Inst{31-27} = 0b11111;
717 let Inst{26-23} = 0b0100;
718 let Inst{22-20} = opcod;
719 let Inst{19-16} = 0b1111; // Rn
720 let Inst{15-12} = 0b1111;
721 let Inst{7} = 1;
722 let Inst{5-4} = 0b00; // rotate
723 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000724 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000725 opc, ".w\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000726 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000727 let Inst{31-27} = 0b11111;
728 let Inst{26-23} = 0b0100;
729 let Inst{22-20} = opcod;
730 let Inst{19-16} = 0b1111; // Rn
731 let Inst{15-12} = 0b1111;
732 let Inst{7} = 1;
733 let Inst{5-4} = {?,?}; // rotate
734 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000735}
736
Eli Friedman761fa7a2010-06-24 18:20:04 +0000737// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000738multiclass T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> {
739 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000740 opc, "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000741 [(set rGPR:$dst, (opnode rGPR:$src))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000742 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000743 let Inst{31-27} = 0b11111;
744 let Inst{26-23} = 0b0100;
745 let Inst{22-20} = opcod;
746 let Inst{19-16} = 0b1111; // Rn
747 let Inst{15-12} = 0b1111;
748 let Inst{7} = 1;
749 let Inst{5-4} = 0b00; // rotate
750 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000751 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000752 opc, "\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000753 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000754 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000755 let Inst{31-27} = 0b11111;
756 let Inst{26-23} = 0b0100;
757 let Inst{22-20} = opcod;
758 let Inst{19-16} = 0b1111; // Rn
759 let Inst{15-12} = 0b1111;
760 let Inst{7} = 1;
761 let Inst{5-4} = {?,?}; // rotate
762 }
763}
764
Eli Friedman761fa7a2010-06-24 18:20:04 +0000765// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
766// supported yet.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000767multiclass T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> {
768 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000769 opc, "\t$dst, $src", []> {
770 let Inst{31-27} = 0b11111;
771 let Inst{26-23} = 0b0100;
772 let Inst{22-20} = opcod;
773 let Inst{19-16} = 0b1111; // Rn
774 let Inst{15-12} = 0b1111;
775 let Inst{7} = 1;
776 let Inst{5-4} = 0b00; // rotate
777 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000778 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000779 opc, "\t$dst, $src, ror $rot", []> {
780 let Inst{31-27} = 0b11111;
781 let Inst{26-23} = 0b0100;
782 let Inst{22-20} = opcod;
783 let Inst{19-16} = 0b1111; // Rn
784 let Inst{15-12} = 0b1111;
785 let Inst{7} = 1;
786 let Inst{5-4} = {?,?}; // rotate
787 }
788}
789
Evan Cheng0e55fd62010-09-30 01:08:25 +0000790/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000791/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000792multiclass T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> {
793 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Evan Cheng699beba2009-10-27 00:08:59 +0000794 opc, "\t$dst, $LHS, $RHS",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000795 [(set rGPR:$dst, (opnode rGPR:$LHS, rGPR:$RHS))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000796 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000797 let Inst{31-27} = 0b11111;
798 let Inst{26-23} = 0b0100;
799 let Inst{22-20} = opcod;
800 let Inst{15-12} = 0b1111;
801 let Inst{7} = 1;
802 let Inst{5-4} = 0b00; // rotate
803 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000804 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng0e55fd62010-09-30 01:08:25 +0000805 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000806 [(set rGPR:$dst, (opnode rGPR:$LHS,
807 (rotr rGPR:$RHS, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000808 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000809 let Inst{31-27} = 0b11111;
810 let Inst{26-23} = 0b0100;
811 let Inst{22-20} = opcod;
812 let Inst{15-12} = 0b1111;
813 let Inst{7} = 1;
814 let Inst{5-4} = {?,?}; // rotate
815 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000816}
817
Johnny Chen93042d12010-03-02 18:14:57 +0000818// DO variant - disassembly only, no pattern
819
Evan Cheng0e55fd62010-09-30 01:08:25 +0000820multiclass T2I_exta_rrot_DO<bits<3> opcod, string opc> {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000821 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Johnny Chen93042d12010-03-02 18:14:57 +0000822 opc, "\t$dst, $LHS, $RHS", []> {
823 let Inst{31-27} = 0b11111;
824 let Inst{26-23} = 0b0100;
825 let Inst{22-20} = opcod;
826 let Inst{15-12} = 0b1111;
827 let Inst{7} = 1;
828 let Inst{5-4} = 0b00; // rotate
829 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000830 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng7e1bf302010-09-29 00:27:46 +0000831 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot", []> {
Johnny Chen93042d12010-03-02 18:14:57 +0000832 let Inst{31-27} = 0b11111;
833 let Inst{26-23} = 0b0100;
834 let Inst{22-20} = opcod;
835 let Inst{15-12} = 0b1111;
836 let Inst{7} = 1;
837 let Inst{5-4} = {?,?}; // rotate
838 }
839}
840
Anton Korobeynikov52237112009-06-17 18:13:58 +0000841//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000842// Instructions
843//===----------------------------------------------------------------------===//
844
845//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000846// Miscellaneous Instructions.
847//
848
Evan Chenga09b9ca2009-06-24 23:47:58 +0000849// LEApcrel - Load a pc-relative address into a register without offending the
850// assembler.
Evan Chengea420b22010-05-19 01:52:25 +0000851let neverHasSideEffects = 1 in {
Evan Cheng9085f982010-05-19 07:28:01 +0000852let isReMaterializable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000853def t2LEApcrel : T2XI<(outs rGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000854 "adr${p}.w\t$dst, #$label", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000855 let Inst{31-27} = 0b11110;
856 let Inst{25-24} = 0b10;
857 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
858 let Inst{22} = 0;
859 let Inst{20} = 0;
860 let Inst{19-16} = 0b1111; // Rn
861 let Inst{15} = 0;
862}
Jim Grosbacha967d112010-06-21 21:27:27 +0000863} // neverHasSideEffects
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000864def t2LEApcrelJT : T2XI<(outs rGPR:$dst),
Bob Wilson4f38b382009-08-21 21:58:55 +0000865 (ins i32imm:$label, nohash_imm:$id, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000866 "adr${p}.w\t$dst, #${label}_${id}", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000867 let Inst{31-27} = 0b11110;
868 let Inst{25-24} = 0b10;
869 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
870 let Inst{22} = 0;
871 let Inst{20} = 0;
872 let Inst{19-16} = 0b1111; // Rn
873 let Inst{15} = 0;
874}
Evan Chenga09b9ca2009-06-24 23:47:58 +0000875
Evan Cheng86198642009-08-07 00:34:42 +0000876// ADD r, sp, {so_imm|i12}
Owen Andersonb9a643e2010-11-12 23:36:03 +0000877def t2ADDrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
878 IIC_iALUi, "add", ".w\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000879 let Inst{31-27} = 0b11110;
880 let Inst{25} = 0;
881 let Inst{24-21} = 0b1000;
882 let Inst{20} = ?; // The S bit.
Owen Andersonb9a643e2010-11-12 23:36:03 +0000883 let Inst{19-16} = 0b1101; // Rn = sp
Johnny Chend68e1192009-12-15 17:24:14 +0000884 let Inst{15} = 0;
885}
Owen Andersonb9a643e2010-11-12 23:36:03 +0000886def t2ADDrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
887 IIC_iALUi, "addw", "\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000888 let Inst{31-27} = 0b11110;
889 let Inst{25} = 1;
890 let Inst{24-21} = 0b0000;
891 let Inst{20} = 0; // The S bit.
892 let Inst{19-16} = 0b1101; // Rn = sp
893 let Inst{15} = 0;
894}
Evan Cheng86198642009-08-07 00:34:42 +0000895
896// ADD r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +0000897def t2ADDrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +0000898 IIC_iALUsi, "add", ".w\t$dst, $sp, $rhs", []> {
899 let Inst{31-27} = 0b11101;
900 let Inst{26-25} = 0b01;
901 let Inst{24-21} = 0b1000;
902 let Inst{20} = ?; // The S bit.
903 let Inst{19-16} = 0b1101; // Rn = sp
904 let Inst{15} = 0;
905}
Evan Cheng86198642009-08-07 00:34:42 +0000906
907// SUB r, sp, {so_imm|i12}
David Goodwin5d598aa2009-08-19 18:00:44 +0000908def t2SUBrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +0000909 IIC_iALUi, "sub", ".w\t$dst, $sp, $imm", []> {
910 let Inst{31-27} = 0b11110;
911 let Inst{25} = 0;
912 let Inst{24-21} = 0b1101;
913 let Inst{20} = ?; // The S bit.
914 let Inst{19-16} = 0b1101; // Rn = sp
915 let Inst{15} = 0;
916}
David Goodwin5d598aa2009-08-19 18:00:44 +0000917def t2SUBrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +0000918 IIC_iALUi, "subw", "\t$dst, $sp, $imm", []> {
919 let Inst{31-27} = 0b11110;
920 let Inst{25} = 1;
921 let Inst{24-21} = 0b0101;
922 let Inst{20} = 0; // The S bit.
923 let Inst{19-16} = 0b1101; // Rn = sp
924 let Inst{15} = 0;
925}
Evan Cheng86198642009-08-07 00:34:42 +0000926
927// SUB r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +0000928def t2SUBrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
929 IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +0000930 "sub", "\t$dst, $sp, $rhs", []> {
931 let Inst{31-27} = 0b11101;
932 let Inst{26-25} = 0b01;
933 let Inst{24-21} = 0b1101;
934 let Inst{20} = ?; // The S bit.
935 let Inst{19-16} = 0b1101; // Rn = sp
936 let Inst{15} = 0;
937}
Evan Cheng86198642009-08-07 00:34:42 +0000938
Jim Grosbachb1dc3932010-05-05 20:44:35 +0000939// Signed and unsigned division on v7-M
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000940def t2SDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +0000941 "sdiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000942 [(set rGPR:$dst, (sdiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +0000943 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +0000944 let Inst{31-27} = 0b11111;
945 let Inst{26-21} = 0b011100;
946 let Inst{20} = 0b1;
947 let Inst{15-12} = 0b1111;
948 let Inst{7-4} = 0b1111;
949}
950
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000951def t2UDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +0000952 "udiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000953 [(set rGPR:$dst, (udiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +0000954 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +0000955 let Inst{31-27} = 0b11111;
956 let Inst{26-21} = 0b011101;
957 let Inst{20} = 0b1;
958 let Inst{15-12} = 0b1111;
959 let Inst{7-4} = 0b1111;
960}
961
Evan Chenga09b9ca2009-06-24 23:47:58 +0000962//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000963// Load / store Instructions.
964//
965
Evan Cheng055b0312009-06-29 07:51:04 +0000966// Load
Dan Gohmanbc9d98b2010-02-27 23:47:46 +0000967let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng7e2fe912010-10-28 06:47:08 +0000968defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +0000969 UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000970
Evan Chengf3c21b82009-06-30 02:15:48 +0000971// Loads with zero extension
Evan Cheng7e2fe912010-10-28 06:47:08 +0000972defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +0000973 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +0000974defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +0000975 UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000976
Evan Chengf3c21b82009-06-30 02:15:48 +0000977// Loads with sign extension
Evan Cheng7e2fe912010-10-28 06:47:08 +0000978defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +0000979 UnOpFrag<(sextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +0000980defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +0000981 UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +0000982
Chris Lattnera1ca91a2010-11-02 23:40:41 +0000983let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
984 isCodeGenOnly = 1 in { // $dst doesn't exist in asmstring?
Evan Chengf3c21b82009-06-30 02:15:48 +0000985// Load doubleword
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000986def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Chenge298ab22009-09-27 09:46:04 +0000987 (ins t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +0000988 IIC_iLoad_d_i, "ldrd", "\t$dst1, $addr", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000989def t2LDRDpci : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +0000990 (ins i32imm:$addr), IIC_iLoad_d_i,
Johnny Chen83142992010-01-05 22:37:28 +0000991 "ldrd", "\t$dst1, $addr", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000992 let Inst{19-16} = 0b1111; // Rn
993}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +0000994} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
Evan Chengf3c21b82009-06-30 02:15:48 +0000995
996// zextload i1 -> zextload i8
997def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
998 (t2LDRBi12 t2addrmode_imm12:$addr)>;
999def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1000 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1001def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1002 (t2LDRBs t2addrmode_so_reg:$addr)>;
1003def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1004 (t2LDRBpci tconstpool:$addr)>;
1005
1006// extload -> zextload
1007// FIXME: Reduce the number of patterns by legalizing extload to zextload
1008// earlier?
1009def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1010 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1011def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1012 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1013def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1014 (t2LDRBs t2addrmode_so_reg:$addr)>;
1015def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1016 (t2LDRBpci tconstpool:$addr)>;
1017
1018def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1019 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1020def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1021 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1022def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1023 (t2LDRBs t2addrmode_so_reg:$addr)>;
1024def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1025 (t2LDRBpci tconstpool:$addr)>;
1026
1027def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1028 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1029def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1030 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1031def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1032 (t2LDRHs t2addrmode_so_reg:$addr)>;
1033def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1034 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +00001035
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001036// FIXME: The destination register of the loads and stores can't be PC, but
1037// can be SP. We need another regclass (similar to rGPR) to represent
1038// that. Not a pressing issue since these are selected manually,
1039// not via pattern.
1040
Evan Chenge88d5ce2009-07-02 07:28:31 +00001041// Indexed loads
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001042let mayLoad = 1, neverHasSideEffects = 1 in {
Johnny Chend68e1192009-12-15 17:24:14 +00001043def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001044 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001045 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001046 "ldr", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001047 []>;
1048
Johnny Chend68e1192009-12-15 17:24:14 +00001049def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001050 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001051 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001052 "ldr", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001053 []>;
1054
Johnny Chend68e1192009-12-15 17:24:14 +00001055def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001056 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001057 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001058 "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001059 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001060def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001061 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001062 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001063 "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001064 []>;
1065
Johnny Chend68e1192009-12-15 17:24:14 +00001066def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001067 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001068 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001069 "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001070 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001071def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001072 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001073 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001074 "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001075 []>;
1076
Johnny Chend68e1192009-12-15 17:24:14 +00001077def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001078 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001079 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001080 "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001081 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001082def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001083 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001084 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001085 "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001086 []>;
1087
Johnny Chend68e1192009-12-15 17:24:14 +00001088def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001089 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001090 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001091 "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001092 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001093def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001094 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001095 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001096 "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001097 []>;
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001098} // mayLoad = 1, neverHasSideEffects = 1
Evan Cheng4fbb9962009-07-02 23:16:11 +00001099
Johnny Chene54a3ef2010-03-03 18:45:36 +00001100// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1101// for disassembly only.
1102// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001103class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1104 : T2Ii8<(outs GPR:$dst), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001105 "\t$dst, $addr", []> {
1106 let Inst{31-27} = 0b11111;
1107 let Inst{26-25} = 0b00;
1108 let Inst{24} = signed;
1109 let Inst{23} = 0;
1110 let Inst{22-21} = type;
1111 let Inst{20} = 1; // load
1112 let Inst{11} = 1;
1113 let Inst{10-8} = 0b110; // PUW.
1114}
1115
Evan Cheng0e55fd62010-09-30 01:08:25 +00001116def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1117def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1118def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1119def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1120def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001121
David Goodwin73b8f162009-06-30 22:11:34 +00001122// Store
Evan Cheng7e2fe912010-10-28 06:47:08 +00001123defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001124 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001125defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001126 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001127defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001128 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +00001129
David Goodwin6647cea2009-06-30 22:50:01 +00001130// Store doubleword
Chris Lattnera1ca91a2010-11-02 23:40:41 +00001131let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1132 isCodeGenOnly = 1 in // $src2 doesn't exist in asm string
Johnny Chend68e1192009-12-15 17:24:14 +00001133def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
Evan Chenge298ab22009-09-27 09:46:04 +00001134 (ins GPR:$src1, GPR:$src2, t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001135 IIC_iStore_d_r, "strd", "\t$src1, $addr", []>;
David Goodwin6647cea2009-06-30 22:50:01 +00001136
Evan Cheng6d94f112009-07-03 00:06:39 +00001137// Indexed stores
Johnny Chend68e1192009-12-15 17:24:14 +00001138def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001139 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001140 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001141 "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001142 [(set GPR:$base_wb,
1143 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1144
Johnny Chend68e1192009-12-15 17:24:14 +00001145def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001146 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001147 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001148 "str", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001149 [(set GPR:$base_wb,
Jim Grosbach6935efc2009-11-24 00:20:27 +00001150 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001151
Johnny Chend68e1192009-12-15 17:24:14 +00001152def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001153 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001154 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001155 "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001156 [(set GPR:$base_wb,
1157 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1158
Johnny Chend68e1192009-12-15 17:24:14 +00001159def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001160 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001161 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001162 "strh", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001163 [(set GPR:$base_wb,
1164 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1165
Johnny Chend68e1192009-12-15 17:24:14 +00001166def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001167 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001168 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001169 "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001170 [(set GPR:$base_wb,
1171 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1172
Johnny Chend68e1192009-12-15 17:24:14 +00001173def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001174 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001175 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001176 "strb", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001177 [(set GPR:$base_wb,
1178 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1179
Johnny Chene54a3ef2010-03-03 18:45:36 +00001180// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1181// only.
1182// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001183class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1184 : T2Ii8<(outs GPR:$src), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001185 "\t$src, $addr", []> {
1186 let Inst{31-27} = 0b11111;
1187 let Inst{26-25} = 0b00;
1188 let Inst{24} = 0; // not signed
1189 let Inst{23} = 0;
1190 let Inst{22-21} = type;
1191 let Inst{20} = 0; // store
1192 let Inst{11} = 1;
1193 let Inst{10-8} = 0b110; // PUW
1194}
1195
Evan Cheng0e55fd62010-09-30 01:08:25 +00001196def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1197def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1198def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
David Goodwind1fa1202009-07-01 00:01:13 +00001199
Johnny Chenae1757b2010-03-11 01:13:36 +00001200// ldrd / strd pre / post variants
1201// For disassembly only.
1202
1203def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001204 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001205 "ldrd", "\t$dst1, $dst2, [$base, $imm]!", []>;
1206
1207def t2LDRD_POST : T2Ii8s4<0, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001208 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001209 "ldrd", "\t$dst1, $dst2, [$base], $imm", []>;
1210
1211def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs),
1212 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001213 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base, $imm]!", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001214
1215def t2STRD_POST : T2Ii8s4<0, 1, 0, (outs),
1216 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001217 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base], $imm", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +00001218
Johnny Chen0635fc52010-03-04 17:40:44 +00001219// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1220// data/instruction access. These are for disassembly only.
Evan Chengdfed19f2010-11-03 06:34:55 +00001221// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1222// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
Evan Cheng416941d2010-11-04 05:19:35 +00001223multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001224
Evan Chengdfed19f2010-11-03 06:34:55 +00001225 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001226 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001227 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001228 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001229 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001230 let Inst{23} = 1; // U = 1
1231 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001232 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001233 let Inst{20} = 1;
1234 let Inst{15-12} = 0b1111;
1235 }
1236
Evan Chengdfed19f2010-11-03 06:34:55 +00001237 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001238 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001239 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001240 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001241 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001242 let Inst{23} = 0; // U = 0
1243 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001244 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001245 let Inst{20} = 1;
1246 let Inst{15-12} = 0b1111;
1247 let Inst{11-8} = 0b1100;
1248 }
1249
Evan Chengdfed19f2010-11-03 06:34:55 +00001250 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001251 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001252 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
Evan Chengbc7deb02010-11-03 05:14:24 +00001253 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001254 let Inst{24} = instr;
Evan Chengbc7deb02010-11-03 05:14:24 +00001255 let Inst{23} = 0; // add = TRUE for T1
1256 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001257 let Inst{21} = write;
Evan Chengbc7deb02010-11-03 05:14:24 +00001258 let Inst{20} = 1;
1259 let Inst{15-12} = 0b1111;
1260 let Inst{11-6} = 0000000;
1261 }
1262
1263 let isCodeGenOnly = 1 in
Evan Chengdfed19f2010-11-03 06:34:55 +00001264 def pci : T2Ipc<(outs), (ins i32imm:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001265 "\t$addr",
1266 []> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001267 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001268 let Inst{24} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001269 let Inst{23} = ?; // add = (U == 1)
1270 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001271 let Inst{21} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001272 let Inst{20} = 1;
1273 let Inst{19-16} = 0b1111; // Rn = 0b1111
1274 let Inst{15-12} = 0b1111;
1275 }
Johnny Chen0635fc52010-03-04 17:40:44 +00001276}
1277
Evan Cheng416941d2010-11-04 05:19:35 +00001278defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1279defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1280defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
Johnny Chen0635fc52010-03-04 17:40:44 +00001281
Evan Cheng2889cce2009-07-03 00:18:36 +00001282//===----------------------------------------------------------------------===//
1283// Load / store multiple Instructions.
1284//
1285
Bill Wendling6c470b82010-11-13 09:09:38 +00001286multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1287 InstrItinClass itin_upd, bit L_bit> {
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001288 def ia :
Bill Wendling6c470b82010-11-13 09:09:38 +00001289 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1290 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1291 bits<4> Rn;
1292 bits<16> regs;
1293
1294 let Inst{31-27} = 0b11101;
1295 let Inst{26-25} = 0b00;
1296 let Inst{24-23} = 0b01; // Increment After
1297 let Inst{22} = 0;
1298 let Inst{21} = 0; // No writeback
1299 let Inst{20} = L_bit;
1300 let Inst{19-16} = Rn;
1301 let Inst{15-0} = regs;
1302 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001303 def ia_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001304 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1305 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1306 bits<4> Rn;
1307 bits<16> regs;
1308
1309 let Inst{31-27} = 0b11101;
1310 let Inst{26-25} = 0b00;
1311 let Inst{24-23} = 0b01; // Increment After
1312 let Inst{22} = 0;
1313 let Inst{21} = 1; // Writeback
1314 let Inst{20} = L_bit;
1315 let Inst{19-16} = Rn;
1316 let Inst{15-0} = regs;
1317 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001318 def db :
Bill Wendling6c470b82010-11-13 09:09:38 +00001319 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1320 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1321 bits<4> Rn;
1322 bits<16> regs;
1323
1324 let Inst{31-27} = 0b11101;
1325 let Inst{26-25} = 0b00;
1326 let Inst{24-23} = 0b10; // Decrement Before
1327 let Inst{22} = 0;
1328 let Inst{21} = 0; // No writeback
1329 let Inst{20} = L_bit;
1330 let Inst{19-16} = Rn;
1331 let Inst{15-0} = regs;
1332 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001333 def db_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001334 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1335 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1336 bits<4> Rn;
1337 bits<16> regs;
1338
1339 let Inst{31-27} = 0b11101;
1340 let Inst{26-25} = 0b00;
1341 let Inst{24-23} = 0b10; // Decrement Before
1342 let Inst{22} = 0;
1343 let Inst{21} = 1; // Writeback
1344 let Inst{20} = L_bit;
1345 let Inst{19-16} = Rn;
1346 let Inst{15-0} = regs;
1347 }
1348}
1349
Bill Wendlingc93989a2010-11-13 11:20:05 +00001350/* TODO:
1351let neverHasSideEffects = 1 in {
Bill Wendlingddc918b2010-11-13 10:57:02 +00001352
1353let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1354defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1355
1356let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1357defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1358
1359} // neverHasSideEffects
Bill Wendlingc93989a2010-11-13 11:20:05 +00001360*/
Bill Wendlingddc918b2010-11-13 10:57:02 +00001361
Chris Lattner39ee0362010-10-31 19:10:56 +00001362let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
1363 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001364def t2LDM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001365 reglist:$dsts, variable_ops), IIC_iLoad_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001366 "ldm${amode}${p}.w\t$Rn, $dsts", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001367 let Inst{31-27} = 0b11101;
1368 let Inst{26-25} = 0b00;
1369 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1370 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001371 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001372 let Inst{20} = 1; // Load
1373}
Evan Cheng2889cce2009-07-03 00:18:36 +00001374
Jim Grosbache6913602010-11-03 01:01:43 +00001375def t2LDM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001376 reglist:$dsts, variable_ops),
1377 IIC_iLoad_mu,
Jim Grosbache6913602010-11-03 01:01:43 +00001378 "ldm${amode}${p}.w\t$Rn!, $dsts",
1379 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001380 let Inst{31-27} = 0b11101;
1381 let Inst{26-25} = 0b00;
1382 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1383 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001384 let Inst{21} = 1; // The W bit.
1385 let Inst{20} = 1; // Load
1386}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001387} // mayLoad, neverHasSideEffects, hasExtraDefRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001388
Chris Lattner39ee0362010-10-31 19:10:56 +00001389let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1390 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001391def t2STM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001392 reglist:$srcs, variable_ops), IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001393 "stm${amode}${p}.w\t$Rn, $srcs", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001394 let Inst{31-27} = 0b11101;
1395 let Inst{26-25} = 0b00;
1396 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1397 let Inst{22} = 0;
1398 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001399 let Inst{20} = 0; // Store
1400}
Evan Cheng2889cce2009-07-03 00:18:36 +00001401
Jim Grosbache6913602010-11-03 01:01:43 +00001402def t2STM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Bob Wilson815baeb2010-03-13 01:08:20 +00001403 reglist:$srcs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00001404 IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001405 "stm${amode}${p}.w\t$Rn!, $srcs",
1406 "$Rn = $wb", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001407 let Inst{31-27} = 0b11101;
1408 let Inst{26-25} = 0b00;
1409 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1410 let Inst{22} = 0;
1411 let Inst{21} = 1; // The W bit.
1412 let Inst{20} = 0; // Store
1413}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001414} // mayStore, neverHasSideEffects, hasExtraSrcRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001415
Evan Cheng9cb9e672009-06-27 02:26:13 +00001416//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001417// Move Instructions.
1418//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001419
Evan Chengf49810c2009-06-23 17:48:47 +00001420let neverHasSideEffects = 1 in
David Goodwin5d598aa2009-08-19 18:00:44 +00001421def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
Johnny Chend68e1192009-12-15 17:24:14 +00001422 "mov", ".w\t$dst, $src", []> {
1423 let Inst{31-27} = 0b11101;
1424 let Inst{26-25} = 0b01;
1425 let Inst{24-21} = 0b0010;
1426 let Inst{20} = ?; // The S bit.
1427 let Inst{19-16} = 0b1111; // Rn
1428 let Inst{14-12} = 0b000;
1429 let Inst{7-4} = 0b0000;
1430}
Evan Chengf49810c2009-06-23 17:48:47 +00001431
Evan Cheng5adb66a2009-09-28 09:14:39 +00001432// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1433let isReMaterializable = 1, isAsCheapAsAMove = 1, AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001434def t2MOVi : T2sI<(outs rGPR:$dst), (ins t2_so_imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001435 "mov", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001436 [(set rGPR:$dst, t2_so_imm:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001437 let Inst{31-27} = 0b11110;
1438 let Inst{25} = 0;
1439 let Inst{24-21} = 0b0010;
1440 let Inst{20} = ?; // The S bit.
1441 let Inst{19-16} = 0b1111; // Rn
1442 let Inst{15} = 0;
1443}
David Goodwin83b35932009-06-26 16:10:07 +00001444
1445let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001446def t2MOVi16 : T2I<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001447 "movw", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001448 [(set rGPR:$dst, imm0_65535:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001449 let Inst{31-27} = 0b11110;
1450 let Inst{25} = 1;
1451 let Inst{24-21} = 0b0010;
1452 let Inst{20} = 0; // The S bit.
1453 let Inst{15} = 0;
1454}
Evan Chengf49810c2009-06-23 17:48:47 +00001455
Evan Cheng3850a6a2009-06-23 05:23:49 +00001456let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001457def t2MOVTi16 : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$imm), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001458 "movt", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001459 [(set rGPR:$dst,
1460 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001461 let Inst{31-27} = 0b11110;
1462 let Inst{25} = 1;
1463 let Inst{24-21} = 0b0110;
1464 let Inst{20} = 0; // The S bit.
1465 let Inst{15} = 0;
1466}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001467
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001468def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
Evan Cheng20956592009-10-21 08:15:52 +00001469
Anton Korobeynikov52237112009-06-17 18:13:58 +00001470//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +00001471// Extend Instructions.
1472//
1473
1474// Sign extenders
1475
Evan Cheng0e55fd62010-09-30 01:08:25 +00001476defm t2SXTB : T2I_ext_rrot<0b100, "sxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001477 UnOpFrag<(sext_inreg node:$Src, i8)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001478defm t2SXTH : T2I_ext_rrot<0b000, "sxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001479 UnOpFrag<(sext_inreg node:$Src, i16)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001480defm t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001481
Evan Cheng0e55fd62010-09-30 01:08:25 +00001482defm t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001483 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001484defm t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001485 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001486defm t2SXTAB16 : T2I_exta_rrot_DO<0b010, "sxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001487
Johnny Chen93042d12010-03-02 18:14:57 +00001488// TODO: SXT(A){B|H}16 - done for disassembly only
Evan Chengd27c9fc2009-07-03 01:43:10 +00001489
1490// Zero extenders
1491
1492let AddedComplexity = 16 in {
Evan Cheng0e55fd62010-09-30 01:08:25 +00001493defm t2UXTB : T2I_ext_rrot<0b101, "uxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001494 UnOpFrag<(and node:$Src, 0x000000FF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001495defm t2UXTH : T2I_ext_rrot<0b001, "uxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001496 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001497defm t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
Johnny Chend68e1192009-12-15 17:24:14 +00001498 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001499
Jim Grosbach79464942010-07-28 23:17:45 +00001500// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1501// The transformation should probably be done as a combiner action
1502// instead so we can include a check for masking back in the upper
1503// eight bits of the source into the lower eight bits of the result.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001504//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001505// (t2UXTB16r_rot rGPR:$Src, 24)>,
1506// Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001507def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001508 (t2UXTB16r_rot rGPR:$Src, 8)>,
1509 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001510
Evan Cheng0e55fd62010-09-30 01:08:25 +00001511defm t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001512 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001513defm t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001514 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001515defm t2UXTAB16 : T2I_exta_rrot_DO<0b011, "uxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001516}
1517
1518//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001519// Arithmetic Instructions.
1520//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001521
Johnny Chend68e1192009-12-15 17:24:14 +00001522defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1523 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1524defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1525 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001526
Evan Chengf49810c2009-06-23 17:48:47 +00001527// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Johnny Chend68e1192009-12-15 17:24:14 +00001528defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001529 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001530 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1531defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001532 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001533 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001534
Johnny Chend68e1192009-12-15 17:24:14 +00001535defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001536 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001537defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001538 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001539defm t2ADCS : T2I_adde_sube_s_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001540 BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001541defm t2SBCS : T2I_adde_sube_s_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001542 BinOpFrag<(sube_live_carry node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001543
David Goodwin752aa7d2009-07-27 16:39:05 +00001544// RSB
Bob Wilson20d8e4e2010-08-13 23:24:25 +00001545defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
Johnny Chend68e1192009-12-15 17:24:14 +00001546 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1547defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1548 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001549
1550// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001551// The assume-no-carry-in form uses the negation of the input since add/sub
1552// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1553// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1554// details.
1555// The AddedComplexity preferences the first variant over the others since
1556// it can be shrunk to a 16-bit wide encoding, while the others cannot.
Evan Chengfa2ea1a2009-08-04 01:41:15 +00001557let AddedComplexity = 1 in
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001558def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1559 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1560def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1561 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1562def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1563 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1564let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001565def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1566 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1567def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1568 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001569// The with-carry-in form matches bitwise not instead of the negation.
1570// Effectively, the inverse interpretation of the carry flag already accounts
1571// for part of the negation.
1572let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001573def : T2Pat<(adde rGPR:$src, imm0_255_not:$imm),
1574 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
1575def : T2Pat<(adde rGPR:$src, t2_so_imm_not:$imm),
1576 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001577
Johnny Chen93042d12010-03-02 18:14:57 +00001578// Select Bytes -- for disassembly only
1579
1580def t2SEL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), NoItinerary, "sel",
1581 "\t$dst, $a, $b", []> {
1582 let Inst{31-27} = 0b11111;
1583 let Inst{26-24} = 0b010;
1584 let Inst{23} = 0b1;
1585 let Inst{22-20} = 0b010;
1586 let Inst{15-12} = 0b1111;
1587 let Inst{7} = 0b1;
1588 let Inst{6-4} = 0b000;
1589}
1590
Johnny Chenadc77332010-02-26 22:04:29 +00001591// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1592// And Miscellaneous operations -- for disassembly only
Nate Begeman692433b2010-07-29 17:56:55 +00001593class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1594 list<dag> pat = [/* For disassembly only; pattern left blank */]>
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001595 : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), NoItinerary, opc,
Nate Begeman692433b2010-07-29 17:56:55 +00001596 "\t$dst, $a, $b", pat> {
Johnny Chenadc77332010-02-26 22:04:29 +00001597 let Inst{31-27} = 0b11111;
1598 let Inst{26-23} = 0b0101;
1599 let Inst{22-20} = op22_20;
1600 let Inst{15-12} = 0b1111;
1601 let Inst{7-4} = op7_4;
1602}
1603
1604// Saturating add/subtract -- for disassembly only
1605
Nate Begeman692433b2010-07-29 17:56:55 +00001606def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001607 [(set rGPR:$dst, (int_arm_qadd rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001608def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1609def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1610def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
1611def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd">;
1612def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub">;
1613def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
Nate Begeman692433b2010-07-29 17:56:55 +00001614def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001615 [(set rGPR:$dst, (int_arm_qsub rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001616def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1617def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1618def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1619def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1620def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1621def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1622def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1623def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1624
1625// Signed/Unsigned add/subtract -- for disassembly only
1626
1627def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1628def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1629def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1630def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1631def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1632def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1633def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1634def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1635def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1636def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1637def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1638def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1639
1640// Signed/Unsigned halving add/subtract -- for disassembly only
1641
1642def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1643def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1644def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1645def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1646def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1647def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1648def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1649def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1650def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1651def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1652def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1653def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1654
1655// Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1656
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001657def t2USAD8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1658 (ins rGPR:$a, rGPR:$b),
Johnny Chenadc77332010-02-26 22:04:29 +00001659 NoItinerary, "usad8", "\t$dst, $a, $b", []> {
1660 let Inst{15-12} = 0b1111;
1661}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001662def t2USADA8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1663 (ins rGPR:$a, rGPR:$b, rGPR:$acc), NoItinerary, "usada8",
Johnny Chenadc77332010-02-26 22:04:29 +00001664 "\t$dst, $a, $b, $acc", []>;
1665
1666// Signed/Unsigned saturate -- for disassembly only
1667
Bob Wilson22f5dc72010-08-16 18:27:34 +00001668def t2SSAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001669 NoItinerary, "ssat", "\t$dst, $bit_pos, $a$sh",
1670 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001671 let Inst{31-27} = 0b11110;
1672 let Inst{25-22} = 0b1100;
1673 let Inst{20} = 0;
1674 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001675}
1676
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001677def t2SSAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001678 "ssat16", "\t$dst, $bit_pos, $a",
1679 [/* For disassembly only; pattern left blank */]> {
1680 let Inst{31-27} = 0b11110;
1681 let Inst{25-22} = 0b1100;
1682 let Inst{20} = 0;
1683 let Inst{15} = 0;
1684 let Inst{21} = 1; // sh = '1'
1685 let Inst{14-12} = 0b000; // imm3 = '000'
1686 let Inst{7-6} = 0b00; // imm2 = '00'
1687}
1688
Bob Wilson22f5dc72010-08-16 18:27:34 +00001689def t2USAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001690 NoItinerary, "usat", "\t$dst, $bit_pos, $a$sh",
1691 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001692 let Inst{31-27} = 0b11110;
1693 let Inst{25-22} = 0b1110;
1694 let Inst{20} = 0;
1695 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001696}
1697
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001698def t2USAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001699 "usat16", "\t$dst, $bit_pos, $a",
1700 [/* For disassembly only; pattern left blank */]> {
1701 let Inst{31-27} = 0b11110;
1702 let Inst{25-22} = 0b1110;
1703 let Inst{20} = 0;
1704 let Inst{15} = 0;
1705 let Inst{21} = 1; // sh = '1'
1706 let Inst{14-12} = 0b000; // imm3 = '000'
1707 let Inst{7-6} = 0b00; // imm2 = '00'
1708}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001709
Bob Wilson38aa2872010-08-13 21:48:10 +00001710def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
1711def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
Nate Begeman0e0a20e2010-07-29 22:48:09 +00001712
Evan Chengf49810c2009-06-23 17:48:47 +00001713//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +00001714// Shift and rotate Instructions.
1715//
1716
Johnny Chend68e1192009-12-15 17:24:14 +00001717defm t2LSL : T2I_sh_ir<0b00, "lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
1718defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
1719defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
1720defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
Evan Chenga67efd12009-06-23 19:39:13 +00001721
David Goodwinca01a8d2009-09-01 18:32:09 +00001722let Uses = [CPSR] in {
Jim Grosbach792e9792010-10-14 20:43:44 +00001723def t2RRX : T2sI<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +00001724 "rrx", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001725 [(set rGPR:$dst, (ARMrrx rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001726 let Inst{31-27} = 0b11101;
1727 let Inst{26-25} = 0b01;
1728 let Inst{24-21} = 0b0010;
1729 let Inst{20} = ?; // The S bit.
1730 let Inst{19-16} = 0b1111; // Rn
1731 let Inst{14-12} = 0b000;
1732 let Inst{7-4} = 0b0011;
1733}
David Goodwinca01a8d2009-09-01 18:32:09 +00001734}
Evan Chenga67efd12009-06-23 19:39:13 +00001735
David Goodwin3583df72009-07-28 17:06:49 +00001736let Defs = [CPSR] in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001737def t2MOVsrl_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001738 "lsrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001739 [(set rGPR:$dst, (ARMsrl_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001740 let Inst{31-27} = 0b11101;
1741 let Inst{26-25} = 0b01;
1742 let Inst{24-21} = 0b0010;
1743 let Inst{20} = 1; // The S bit.
1744 let Inst{19-16} = 0b1111; // Rn
1745 let Inst{5-4} = 0b01; // Shift type.
1746 // Shift amount = Inst{14-12:7-6} = 1.
1747 let Inst{14-12} = 0b000;
1748 let Inst{7-6} = 0b01;
1749}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001750def t2MOVsra_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001751 "asrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001752 [(set rGPR:$dst, (ARMsra_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001753 let Inst{31-27} = 0b11101;
1754 let Inst{26-25} = 0b01;
1755 let Inst{24-21} = 0b0010;
1756 let Inst{20} = 1; // The S bit.
1757 let Inst{19-16} = 0b1111; // Rn
1758 let Inst{5-4} = 0b10; // Shift type.
1759 // Shift amount = Inst{14-12:7-6} = 1.
1760 let Inst{14-12} = 0b000;
1761 let Inst{7-6} = 0b01;
1762}
David Goodwin3583df72009-07-28 17:06:49 +00001763}
1764
Evan Chenga67efd12009-06-23 19:39:13 +00001765//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00001766// Bitwise Instructions.
1767//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001768
Johnny Chend68e1192009-12-15 17:24:14 +00001769defm t2AND : T2I_bin_w_irs<0b0000, "and",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001770 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001771 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
1772defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001773 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001774 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
1775defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001776 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001777 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +00001778
Johnny Chend68e1192009-12-15 17:24:14 +00001779defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001780 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001781 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001782
Evan Chengf49810c2009-06-23 17:48:47 +00001783let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001784def t2BFC : T2I<(outs rGPR:$dst), (ins rGPR:$src, bf_inv_mask_imm:$imm),
David Goodwin2f54a2f2009-11-02 17:28:36 +00001785 IIC_iUNAsi, "bfc", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001786 [(set rGPR:$dst, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001787 let Inst{31-27} = 0b11110;
1788 let Inst{25} = 1;
1789 let Inst{24-20} = 0b10110;
1790 let Inst{19-16} = 0b1111; // Rn
1791 let Inst{15} = 0;
1792}
Evan Chengf49810c2009-06-23 17:48:47 +00001793
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001794def t2SBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001795 IIC_iUNAsi, "sbfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001796 let Inst{31-27} = 0b11110;
1797 let Inst{25} = 1;
1798 let Inst{24-20} = 0b10100;
1799 let Inst{15} = 0;
1800}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001801
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001802def t2UBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001803 IIC_iUNAsi, "ubfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001804 let Inst{31-27} = 0b11110;
1805 let Inst{25} = 1;
1806 let Inst{24-20} = 0b11100;
1807 let Inst{15} = 0;
1808}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001809
Johnny Chen9474d552010-02-02 19:31:58 +00001810// A8.6.18 BFI - Bitfield insert (Encoding T1)
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001811let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001812def t2BFI : T2I<(outs rGPR:$dst),
1813 (ins rGPR:$src, rGPR:$val, bf_inv_mask_imm:$imm),
Evan Cheng7e1bf302010-09-29 00:27:46 +00001814 IIC_iBITi, "bfi", "\t$dst, $val, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001815 [(set rGPR:$dst, (ARMbfi rGPR:$src, rGPR:$val,
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001816 bf_inv_mask_imm:$imm))]> {
Johnny Chen9474d552010-02-02 19:31:58 +00001817 let Inst{31-27} = 0b11110;
1818 let Inst{25} = 1;
1819 let Inst{24-20} = 0b10110;
1820 let Inst{15} = 0;
1821}
Evan Chengf49810c2009-06-23 17:48:47 +00001822
Evan Cheng7e1bf302010-09-29 00:27:46 +00001823defm t2ORN : T2I_bin_irs<0b0011, "orn",
1824 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
1825 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001826
1827// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
1828let AddedComplexity = 1 in
Evan Cheng5d42c562010-09-29 00:49:25 +00001829defm t2MVN : T2I_un_irs <0b0011, "mvn",
Evan Cheng3881cb72010-09-29 22:42:35 +00001830 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
Evan Cheng5d42c562010-09-29 00:49:25 +00001831 UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001832
1833
Jim Grosbachf084a5e2010-07-20 16:07:04 +00001834let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001835def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
1836 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001837
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001838// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001839def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
1840 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
Evan Chengea253b92009-08-12 01:56:42 +00001841 Requires<[IsThumb2]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001842
1843def : T2Pat<(t2_so_imm_not:$src),
1844 (t2MVNi t2_so_imm_not:$src)>;
1845
Evan Chengf49810c2009-06-23 17:48:47 +00001846//===----------------------------------------------------------------------===//
1847// Multiply Instructions.
1848//
Evan Cheng8de898a2009-06-26 00:19:44 +00001849let isCommutable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001850def t2MUL: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00001851 "mul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001852 [(set rGPR:$dst, (mul rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001853 let Inst{31-27} = 0b11111;
1854 let Inst{26-23} = 0b0110;
1855 let Inst{22-20} = 0b000;
1856 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1857 let Inst{7-4} = 0b0000; // Multiply
1858}
Evan Chengf49810c2009-06-23 17:48:47 +00001859
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001860def t2MLA: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001861 "mla", "\t$dst, $a, $b, $c",
1862 [(set rGPR:$dst, (add (mul rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001863 let Inst{31-27} = 0b11111;
1864 let Inst{26-23} = 0b0110;
1865 let Inst{22-20} = 0b000;
1866 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1867 let Inst{7-4} = 0b0000; // Multiply
1868}
Evan Chengf49810c2009-06-23 17:48:47 +00001869
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001870def t2MLS: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001871 "mls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001872 [(set rGPR:$dst, (sub rGPR:$c, (mul rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001873 let Inst{31-27} = 0b11111;
1874 let Inst{26-23} = 0b0110;
1875 let Inst{22-20} = 0b000;
1876 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1877 let Inst{7-4} = 0b0001; // Multiply and Subtract
1878}
Evan Chengf49810c2009-06-23 17:48:47 +00001879
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001880// Extra precision multiplies with low / high results
1881let neverHasSideEffects = 1 in {
1882let isCommutable = 1 in {
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001883def t2SMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1884 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00001885 "smull", "\t$ldst, $hdst, $a, $b", []> {
1886 let Inst{31-27} = 0b11111;
1887 let Inst{26-23} = 0b0111;
1888 let Inst{22-20} = 0b000;
1889 let Inst{7-4} = 0b0000;
1890}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001891
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001892def t2UMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1893 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00001894 "umull", "\t$ldst, $hdst, $a, $b", []> {
1895 let Inst{31-27} = 0b11111;
1896 let Inst{26-23} = 0b0111;
1897 let Inst{22-20} = 0b010;
1898 let Inst{7-4} = 0b0000;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001899}
Johnny Chend68e1192009-12-15 17:24:14 +00001900} // isCommutable
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001901
1902// Multiply + accumulate
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001903def t2SMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1904 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001905 "smlal", "\t$ldst, $hdst, $a, $b", []>{
1906 let Inst{31-27} = 0b11111;
1907 let Inst{26-23} = 0b0111;
1908 let Inst{22-20} = 0b100;
1909 let Inst{7-4} = 0b0000;
1910}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001911
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001912def t2UMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1913 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001914 "umlal", "\t$ldst, $hdst, $a, $b", []>{
1915 let Inst{31-27} = 0b11111;
1916 let Inst{26-23} = 0b0111;
1917 let Inst{22-20} = 0b110;
1918 let Inst{7-4} = 0b0000;
1919}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001920
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001921def t2UMAAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1922 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001923 "umaal", "\t$ldst, $hdst, $a, $b", []>{
1924 let Inst{31-27} = 0b11111;
1925 let Inst{26-23} = 0b0111;
1926 let Inst{22-20} = 0b110;
1927 let Inst{7-4} = 0b0110;
1928}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001929} // neverHasSideEffects
1930
Johnny Chen93042d12010-03-02 18:14:57 +00001931// Rounding variants of the below included for disassembly only
1932
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001933// Most significant word multiply
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001934def t2SMMUL : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00001935 "smmul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001936 [(set rGPR:$dst, (mulhs rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001937 let Inst{31-27} = 0b11111;
1938 let Inst{26-23} = 0b0110;
1939 let Inst{22-20} = 0b101;
1940 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1941 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
1942}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001943
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001944def t2SMMULR : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Johnny Chen93042d12010-03-02 18:14:57 +00001945 "smmulr", "\t$dst, $a, $b", []> {
1946 let Inst{31-27} = 0b11111;
1947 let Inst{26-23} = 0b0110;
1948 let Inst{22-20} = 0b101;
1949 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1950 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
1951}
1952
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001953def t2SMMLA : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00001954 "smmla", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001955 [(set rGPR:$dst, (add (mulhs rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001956 let Inst{31-27} = 0b11111;
1957 let Inst{26-23} = 0b0110;
1958 let Inst{22-20} = 0b101;
1959 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1960 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
1961}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001962
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001963def t2SMMLAR: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00001964 "smmlar", "\t$dst, $a, $b, $c", []> {
1965 let Inst{31-27} = 0b11111;
1966 let Inst{26-23} = 0b0110;
1967 let Inst{22-20} = 0b101;
1968 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1969 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
1970}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001971
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001972def t2SMMLS: T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00001973 "smmls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001974 [(set rGPR:$dst, (sub rGPR:$c, (mulhs rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001975 let Inst{31-27} = 0b11111;
1976 let Inst{26-23} = 0b0110;
1977 let Inst{22-20} = 0b110;
1978 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1979 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
1980}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001981
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001982def t2SMMLSR:T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00001983 "smmlsr", "\t$dst, $a, $b, $c", []> {
1984 let Inst{31-27} = 0b11111;
1985 let Inst{26-23} = 0b0110;
1986 let Inst{22-20} = 0b110;
1987 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1988 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
1989}
1990
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001991multiclass T2I_smul<string opc, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +00001992 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00001993 !strconcat(opc, "bb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001994 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
1995 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001996 let Inst{31-27} = 0b11111;
1997 let Inst{26-23} = 0b0110;
1998 let Inst{22-20} = 0b001;
1999 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2000 let Inst{7-6} = 0b00;
2001 let Inst{5-4} = 0b00;
2002 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002003
Evan Cheng0e55fd62010-09-30 01:08:25 +00002004 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002005 !strconcat(opc, "bt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002006 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
2007 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002008 let Inst{31-27} = 0b11111;
2009 let Inst{26-23} = 0b0110;
2010 let Inst{22-20} = 0b001;
2011 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2012 let Inst{7-6} = 0b00;
2013 let Inst{5-4} = 0b01;
2014 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002015
Evan Cheng0e55fd62010-09-30 01:08:25 +00002016 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002017 !strconcat(opc, "tb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002018 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2019 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002020 let Inst{31-27} = 0b11111;
2021 let Inst{26-23} = 0b0110;
2022 let Inst{22-20} = 0b001;
2023 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2024 let Inst{7-6} = 0b00;
2025 let Inst{5-4} = 0b10;
2026 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002027
Evan Cheng0e55fd62010-09-30 01:08:25 +00002028 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002029 !strconcat(opc, "tt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002030 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2031 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002032 let Inst{31-27} = 0b11111;
2033 let Inst{26-23} = 0b0110;
2034 let Inst{22-20} = 0b001;
2035 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2036 let Inst{7-6} = 0b00;
2037 let Inst{5-4} = 0b11;
2038 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002039
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002040 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002041 !strconcat(opc, "wb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002042 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2043 (sext_inreg rGPR:$b, i16)), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002044 let Inst{31-27} = 0b11111;
2045 let Inst{26-23} = 0b0110;
2046 let Inst{22-20} = 0b011;
2047 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2048 let Inst{7-6} = 0b00;
2049 let Inst{5-4} = 0b00;
2050 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002051
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002052 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002053 !strconcat(opc, "wt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002054 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2055 (sra rGPR:$b, (i32 16))), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002056 let Inst{31-27} = 0b11111;
2057 let Inst{26-23} = 0b0110;
2058 let Inst{22-20} = 0b011;
2059 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2060 let Inst{7-6} = 0b00;
2061 let Inst{5-4} = 0b01;
2062 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002063}
2064
2065
2066multiclass T2I_smla<string opc, PatFrag opnode> {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002067 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002068 !strconcat(opc, "bb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002069 [(set rGPR:$dst, (add rGPR:$acc,
2070 (opnode (sext_inreg rGPR:$a, i16),
2071 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002072 let Inst{31-27} = 0b11111;
2073 let Inst{26-23} = 0b0110;
2074 let Inst{22-20} = 0b001;
2075 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2076 let Inst{7-6} = 0b00;
2077 let Inst{5-4} = 0b00;
2078 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002079
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002080 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002081 !strconcat(opc, "bt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002082 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sext_inreg rGPR:$a, i16),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002083 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002084 let Inst{31-27} = 0b11111;
2085 let Inst{26-23} = 0b0110;
2086 let Inst{22-20} = 0b001;
2087 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2088 let Inst{7-6} = 0b00;
2089 let Inst{5-4} = 0b01;
2090 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002091
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002092 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002093 !strconcat(opc, "tb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002094 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002095 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002096 let Inst{31-27} = 0b11111;
2097 let Inst{26-23} = 0b0110;
2098 let Inst{22-20} = 0b001;
2099 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2100 let Inst{7-6} = 0b00;
2101 let Inst{5-4} = 0b10;
2102 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002103
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002104 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002105 !strconcat(opc, "tt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002106 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002107 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002108 let Inst{31-27} = 0b11111;
2109 let Inst{26-23} = 0b0110;
2110 let Inst{22-20} = 0b001;
2111 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2112 let Inst{7-6} = 0b00;
2113 let Inst{5-4} = 0b11;
2114 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002115
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002116 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002117 !strconcat(opc, "wb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002118 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002119 (sext_inreg rGPR:$b, i16)), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002120 let Inst{31-27} = 0b11111;
2121 let Inst{26-23} = 0b0110;
2122 let Inst{22-20} = 0b011;
2123 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2124 let Inst{7-6} = 0b00;
2125 let Inst{5-4} = 0b00;
2126 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002127
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002128 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002129 !strconcat(opc, "wt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002130 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002131 (sra rGPR:$b, (i32 16))), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002132 let Inst{31-27} = 0b11111;
2133 let Inst{26-23} = 0b0110;
2134 let Inst{22-20} = 0b011;
2135 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2136 let Inst{7-6} = 0b00;
2137 let Inst{5-4} = 0b01;
2138 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002139}
2140
2141defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2142defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2143
Johnny Chenadc77332010-02-26 22:04:29 +00002144// Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002145def t2SMLALBB : T2I_mac<1, 0b100, 0b1000, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002146 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002147 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002148def t2SMLALBT : T2I_mac<1, 0b100, 0b1001, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002149 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002150 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002151def t2SMLALTB : T2I_mac<1, 0b100, 0b1010, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002152 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002153 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002154def t2SMLALTT : T2I_mac<1, 0b100, 0b1011, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002155 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002156 [/* For disassembly only; pattern left blank */]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002157
Johnny Chenadc77332010-02-26 22:04:29 +00002158// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2159// These are for disassembly only.
2160
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002161def t2SMUAD: T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2162 IIC_iMAC32, "smuad", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002163 let Inst{15-12} = 0b1111;
2164}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002165def t2SMUADX:T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2166 IIC_iMAC32, "smuadx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002167 let Inst{15-12} = 0b1111;
2168}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002169def t2SMUSD: T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2170 IIC_iMAC32, "smusd", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002171 let Inst{15-12} = 0b1111;
2172}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002173def t2SMUSDX:T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2174 IIC_iMAC32, "smusdx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002175 let Inst{15-12} = 0b1111;
2176}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002177def t2SMLAD : T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst),
2178 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlad",
Johnny Chenadc77332010-02-26 22:04:29 +00002179 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002180def t2SMLADX : T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst),
2181 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smladx",
Johnny Chenadc77332010-02-26 22:04:29 +00002182 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002183def t2SMLSD : T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst),
2184 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsd",
Johnny Chenadc77332010-02-26 22:04:29 +00002185 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002186def t2SMLSDX : T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst),
2187 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsdx",
Johnny Chenadc77332010-02-26 22:04:29 +00002188 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002189def t2SMLALD : T2I_mac<1, 0b100, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2190 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlald",
Johnny Chenadc77332010-02-26 22:04:29 +00002191 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002192def t2SMLALDX : T2I_mac<1, 0b100, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2193 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002194 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002195def t2SMLSLD : T2I_mac<1, 0b101, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2196 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsld",
Johnny Chenadc77332010-02-26 22:04:29 +00002197 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002198def t2SMLSLDX : T2I_mac<1, 0b101, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2199 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002200 "\t$ldst, $hdst, $a, $b", []>;
Evan Chengf49810c2009-06-23 17:48:47 +00002201
2202//===----------------------------------------------------------------------===//
2203// Misc. Arithmetic Instructions.
2204//
2205
Jim Grosbach80dc1162010-02-16 21:23:02 +00002206class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2207 InstrItinClass itin, string opc, string asm, list<dag> pattern>
Johnny Chend68e1192009-12-15 17:24:14 +00002208 : T2I<oops, iops, itin, opc, asm, pattern> {
2209 let Inst{31-27} = 0b11111;
2210 let Inst{26-22} = 0b01010;
2211 let Inst{21-20} = op1;
2212 let Inst{15-12} = 0b1111;
2213 let Inst{7-6} = 0b10;
2214 let Inst{5-4} = op2;
2215}
Evan Chengf49810c2009-06-23 17:48:47 +00002216
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002217def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
2218 "clz", "\t$dst, $src", [(set rGPR:$dst, (ctlz rGPR:$src))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002219
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002220def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Evan Chengf609bb82010-01-19 00:44:15 +00002221 "rbit", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002222 [(set rGPR:$dst, (ARMrbit rGPR:$src))]>;
Jim Grosbach3482c802010-01-18 19:58:49 +00002223
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002224def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002225 "rev", ".w\t$dst, $src", [(set rGPR:$dst, (bswap rGPR:$src))]>;
Johnny Chend68e1192009-12-15 17:24:14 +00002226
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002227def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002228 "rev16", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002229 [(set rGPR:$dst,
2230 (or (and (srl rGPR:$src, (i32 8)), 0xFF),
2231 (or (and (shl rGPR:$src, (i32 8)), 0xFF00),
2232 (or (and (srl rGPR:$src, (i32 8)), 0xFF0000),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002233 (and (shl rGPR:$src, (i32 8)), 0xFF000000)))))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002234
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002235def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002236 "revsh", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002237 [(set rGPR:$dst,
Evan Chengf49810c2009-06-23 17:48:47 +00002238 (sext_inreg
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002239 (or (srl (and rGPR:$src, 0xFF00), (i32 8)),
2240 (shl rGPR:$src, (i32 8))), i16))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002241
Bob Wilsonf955f292010-08-17 17:23:19 +00002242def t2PKHBT : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002243 IIC_iBITsi, "pkhbt", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002244 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF),
Bob Wilsonf955f292010-08-17 17:23:19 +00002245 (and (shl rGPR:$src2, lsl_amt:$sh),
Jim Grosbachb1dc3932010-05-05 20:44:35 +00002246 0xFFFF0000)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002247 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002248 let Inst{31-27} = 0b11101;
2249 let Inst{26-25} = 0b01;
2250 let Inst{24-20} = 0b01100;
2251 let Inst{5} = 0; // BT form
2252 let Inst{4} = 0;
2253}
Evan Cheng40289b02009-07-07 05:35:52 +00002254
2255// Alternate cases for PKHBT where identities eliminate some nodes.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002256def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2257 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002258 Requires<[HasT2ExtractPack, IsThumb2]>;
Bob Wilsonf955f292010-08-17 17:23:19 +00002259def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2260 (t2PKHBT rGPR:$src1, rGPR:$src2, (lsl_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002261 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Cheng40289b02009-07-07 05:35:52 +00002262
Bob Wilsondc66eda2010-08-16 22:26:55 +00002263// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2264// will match the pattern below.
Bob Wilsonf955f292010-08-17 17:23:19 +00002265def t2PKHTB : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002266 IIC_iBITsi, "pkhtb", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002267 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002268 (and (sra rGPR:$src2, asr_amt:$sh),
2269 0xFFFF)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002270 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002271 let Inst{31-27} = 0b11101;
2272 let Inst{26-25} = 0b01;
2273 let Inst{24-20} = 0b01100;
2274 let Inst{5} = 1; // TB form
2275 let Inst{4} = 0;
2276}
Evan Cheng40289b02009-07-07 05:35:52 +00002277
2278// Alternate cases for PKHTB where identities eliminate some nodes. Note that
2279// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilsondc66eda2010-08-16 22:26:55 +00002280def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
Bob Wilsonf955f292010-08-17 17:23:19 +00002281 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002282 Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002283def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002284 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2285 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm1_15:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002286 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002287
2288//===----------------------------------------------------------------------===//
2289// Comparison Instructions...
2290//
Johnny Chend68e1192009-12-15 17:24:14 +00002291defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002292 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002293 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2294defm t2CMPz : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002295 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002296 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002297
Dan Gohman4b7dff92010-08-26 15:50:25 +00002298//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2299// Compare-to-zero still works out, just not the relationals
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002300//defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2301// BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002302defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
Evan Cheng5d42c562010-09-29 00:49:25 +00002303 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Dan Gohman4b7dff92010-08-26 15:50:25 +00002304 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2305
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002306//def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2307// (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002308
2309def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2310 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002311
Johnny Chend68e1192009-12-15 17:24:14 +00002312defm t2TST : T2I_cmp_irs<0b0000, "tst",
Evan Cheng5d42c562010-09-29 00:49:25 +00002313 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002314 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
2315defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
Evan Cheng5d42c562010-09-29 00:49:25 +00002316 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002317 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002318
Evan Chenge253c952009-07-07 20:39:03 +00002319// Conditional moves
2320// FIXME: should be able to write a pattern for ARMcmov, but can't use
Jim Grosbach64171712010-02-16 21:07:46 +00002321// a two-value operand where a dag node expects two operands. :(
Evan Cheng63f35442010-11-13 02:25:14 +00002322let neverHasSideEffects = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002323def t2MOVCCr : T2I<(outs rGPR:$dst), (ins rGPR:$false, rGPR:$true), IIC_iCMOVr,
Evan Cheng699beba2009-10-27 00:08:59 +00002324 "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002325 [/*(set rGPR:$dst, (ARMcmov rGPR:$false, rGPR:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002326 RegConstraint<"$false = $dst"> {
2327 let Inst{31-27} = 0b11101;
2328 let Inst{26-25} = 0b01;
2329 let Inst{24-21} = 0b0010;
2330 let Inst{20} = 0; // The S bit.
2331 let Inst{19-16} = 0b1111; // Rn
2332 let Inst{14-12} = 0b000;
2333 let Inst{7-4} = 0b0000;
2334}
Evan Chenge253c952009-07-07 20:39:03 +00002335
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002336def t2MOVCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
Evan Cheng699beba2009-10-27 00:08:59 +00002337 IIC_iCMOVi, "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002338[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002339 RegConstraint<"$false = $dst"> {
2340 let Inst{31-27} = 0b11110;
2341 let Inst{25} = 0;
2342 let Inst{24-21} = 0b0010;
2343 let Inst{20} = 0; // The S bit.
2344 let Inst{19-16} = 0b1111; // Rn
2345 let Inst{15} = 0;
2346}
Evan Chengf49810c2009-06-23 17:48:47 +00002347
Jim Grosbacha4257162010-10-07 00:53:56 +00002348def t2MOVCCi16 : T2I<(outs rGPR:$dst), (ins rGPR:$false, i32imm:$src),
Evan Cheng875a6ac2010-11-12 22:42:47 +00002349 IIC_iCMOVi,
Jim Grosbacha4257162010-10-07 00:53:56 +00002350 "movw", "\t$dst, $src", []>,
2351 RegConstraint<"$false = $dst"> {
2352 let Inst{31-27} = 0b11110;
2353 let Inst{25} = 1;
2354 let Inst{24-21} = 0b0010;
2355 let Inst{20} = 0; // The S bit.
2356 let Inst{15} = 0;
2357}
2358
Evan Cheng63f35442010-11-13 02:25:14 +00002359def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2360 (ins rGPR:$false, i32imm:$src, pred:$p),
Evan Chengc47f7d62010-11-13 05:14:20 +00002361 IIC_iCMOVix2, "", []>, RegConstraint<"$false = $dst">;
Evan Cheng63f35442010-11-13 02:25:14 +00002362
Evan Cheng875a6ac2010-11-12 22:42:47 +00002363def t2MVNCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
2364 IIC_iCMOVi, "mvn", ".w\t$dst, $true",
2365[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm_not:$true,
2366 imm:$cc, CCR:$ccr))*/]>,
2367 RegConstraint<"$false = $dst"> {
2368 let Inst{31-27} = 0b11110;
2369 let Inst{25} = 0;
2370 let Inst{24-21} = 0b0011;
2371 let Inst{20} = 0; // The S bit.
2372 let Inst{19-16} = 0b1111; // Rn
2373 let Inst{15} = 0;
2374}
2375
Johnny Chend68e1192009-12-15 17:24:14 +00002376class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2377 string opc, string asm, list<dag> pattern>
2378 : T2I<oops, iops, itin, opc, asm, pattern> {
2379 let Inst{31-27} = 0b11101;
2380 let Inst{26-25} = 0b01;
2381 let Inst{24-21} = 0b0010;
2382 let Inst{20} = 0; // The S bit.
2383 let Inst{19-16} = 0b1111; // Rn
2384 let Inst{5-4} = opcod; // Shift type.
2385}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002386def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$dst),
2387 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002388 IIC_iCMOVsi, "lsl", ".w\t$dst, $true, $rhs", []>,
2389 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002390def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$dst),
2391 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002392 IIC_iCMOVsi, "lsr", ".w\t$dst, $true, $rhs", []>,
2393 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002394def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$dst),
2395 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002396 IIC_iCMOVsi, "asr", ".w\t$dst, $true, $rhs", []>,
2397 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002398def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$dst),
2399 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002400 IIC_iCMOVsi, "ror", ".w\t$dst, $true, $rhs", []>,
2401 RegConstraint<"$false = $dst">;
Owen Andersonf523e472010-09-23 23:45:25 +00002402} // neverHasSideEffects
Evan Cheng13f8b362009-08-01 01:43:45 +00002403
David Goodwin5e47a9a2009-06-30 18:04:13 +00002404//===----------------------------------------------------------------------===//
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002405// Atomic operations intrinsics
2406//
2407
2408// memory barriers protect the atomic sequences
2409let hasSideEffects = 1 in {
Bob Wilsonf74a4292010-10-30 00:54:37 +00002410def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2411 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2412 Requires<[IsThumb, HasDB]> {
2413 bits<4> opt;
2414 let Inst{31-4} = 0xf3bf8f5;
2415 let Inst{3-0} = opt;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002416}
2417}
2418
Bob Wilsonf74a4292010-10-30 00:54:37 +00002419def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2420 "dsb", "\t$opt",
2421 [/* For disassembly only; pattern left blank */]>,
2422 Requires<[IsThumb, HasDB]> {
2423 bits<4> opt;
2424 let Inst{31-4} = 0xf3bf8f4;
2425 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00002426}
2427
Johnny Chena4339822010-03-03 00:16:28 +00002428// ISB has only full system option -- for disassembly only
Bob Wilsonf74a4292010-10-30 00:54:37 +00002429def t2ISB : T2I<(outs), (ins), NoItinerary, "isb", "",
2430 [/* For disassembly only; pattern left blank */]>,
2431 Requires<[IsThumb2, HasV7]> {
2432 let Inst{31-4} = 0xf3bf8f6;
Johnny Chena4339822010-03-03 00:16:28 +00002433 let Inst{3-0} = 0b1111;
2434}
2435
Johnny Chend68e1192009-12-15 17:24:14 +00002436class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2437 InstrItinClass itin, string opc, string asm, string cstr,
2438 list<dag> pattern, bits<4> rt2 = 0b1111>
2439 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2440 let Inst{31-27} = 0b11101;
2441 let Inst{26-20} = 0b0001101;
2442 let Inst{11-8} = rt2;
2443 let Inst{7-6} = 0b01;
2444 let Inst{5-4} = opcod;
2445 let Inst{3-0} = 0b1111;
2446}
2447class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2448 InstrItinClass itin, string opc, string asm, string cstr,
2449 list<dag> pattern, bits<4> rt2 = 0b1111>
2450 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2451 let Inst{31-27} = 0b11101;
2452 let Inst{26-20} = 0b0001100;
2453 let Inst{11-8} = rt2;
2454 let Inst{7-6} = 0b01;
2455 let Inst{5-4} = opcod;
2456}
2457
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002458let mayLoad = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002459def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002460 Size4Bytes, NoItinerary, "ldrexb", "\t$dest, [$ptr]",
2461 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002462def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002463 Size4Bytes, NoItinerary, "ldrexh", "\t$dest, [$ptr]",
2464 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002465def t2LDREX : Thumb2I<(outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002466 Size4Bytes, NoItinerary,
2467 "ldrex", "\t$dest, [$ptr]", "",
2468 []> {
2469 let Inst{31-27} = 0b11101;
2470 let Inst{26-20} = 0b0000101;
2471 let Inst{11-8} = 0b1111;
2472 let Inst{7-0} = 0b00000000; // imm8 = 0
2473}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002474def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$dest, rGPR:$dest2), (ins rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002475 AddrModeNone, Size4Bytes, NoItinerary,
2476 "ldrexd", "\t$dest, $dest2, [$ptr]", "",
2477 [], {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002478}
2479
Jim Grosbach587b0722009-12-16 19:44:06 +00002480let mayStore = 1, Constraints = "@earlyclobber $success" in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002481def t2STREXB : T2I_strex<0b00, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002482 AddrModeNone, Size4Bytes, NoItinerary,
2483 "strexb", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002484def t2STREXH : T2I_strex<0b01, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002485 AddrModeNone, Size4Bytes, NoItinerary,
2486 "strexh", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002487def t2STREX : Thumb2I<(outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002488 AddrModeNone, Size4Bytes, NoItinerary,
2489 "strex", "\t$success, $src, [$ptr]", "",
2490 []> {
2491 let Inst{31-27} = 0b11101;
2492 let Inst{26-20} = 0b0000100;
2493 let Inst{7-0} = 0b00000000; // imm8 = 0
2494}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002495def t2STREXD : T2I_strex<0b11, (outs rGPR:$success),
2496 (ins rGPR:$src, rGPR:$src2, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002497 AddrModeNone, Size4Bytes, NoItinerary,
2498 "strexd", "\t$success, $src, $src2, [$ptr]", "", [],
2499 {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002500}
2501
Johnny Chen10a77e12010-03-02 22:11:06 +00002502// Clear-Exclusive is for disassembly only.
2503def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "",
2504 [/* For disassembly only; pattern left blank */]>,
2505 Requires<[IsARM, HasV7]> {
2506 let Inst{31-20} = 0xf3b;
2507 let Inst{15-14} = 0b10;
2508 let Inst{12} = 0;
2509 let Inst{7-4} = 0b0010;
2510}
2511
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002512//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00002513// TLS Instructions
2514//
2515
2516// __aeabi_read_tp preserves the registers r1-r3.
2517let isCall = 1,
2518 Defs = [R0, R12, LR, CPSR] in {
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002519 def t2TPsoft : T2XI<(outs), (ins), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002520 "bl\t__aeabi_read_tp",
Johnny Chend68e1192009-12-15 17:24:14 +00002521 [(set R0, ARMthread_pointer)]> {
2522 let Inst{31-27} = 0b11110;
2523 let Inst{15-14} = 0b11;
2524 let Inst{12} = 1;
2525 }
David Goodwin334c2642009-07-08 16:09:28 +00002526}
2527
2528//===----------------------------------------------------------------------===//
Jim Grosbach5aa16842009-08-11 19:42:21 +00002529// SJLJ Exception handling intrinsics
Jim Grosbach1add6592009-08-13 15:11:43 +00002530// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach5aa16842009-08-11 19:42:21 +00002531// address and save #0 in R0 for the non-longjmp case.
2532// Since by its nature we may be coming from some other function to get
2533// here, and we're using the stack frame for the containing function to
2534// save/restore registers, we can't keep anything live in regs across
2535// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
2536// when we get here from a longjmp(). We force everthing out of registers
2537// except for our own input by listing the relevant registers in Defs. By
2538// doing so, we also cause the prologue/epilogue code to actively preserve
2539// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbach0798edd2010-05-27 23:49:24 +00002540// $val is a scratch register for our use.
Jim Grosbacha87ded22010-02-08 23:22:00 +00002541let Defs =
Jim Grosbachf35d2162009-08-13 16:59:44 +00002542 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
2543 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Jim Grosbach5aa16842009-08-11 19:42:21 +00002544 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002545 D31 ], hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002546 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002547 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002548 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002549 Requires<[IsThumb2, HasVFP2]>;
Jim Grosbach5aa16842009-08-11 19:42:21 +00002550}
2551
Bob Wilsonec80e262010-04-09 20:41:18 +00002552let Defs =
Jim Grosbach5caeff52010-05-28 17:37:40 +00002553 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR ],
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002554 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002555 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002556 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002557 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002558 Requires<[IsThumb2, NoVFP]>;
2559}
Jim Grosbach5aa16842009-08-11 19:42:21 +00002560
2561
2562//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00002563// Control-Flow Instructions
2564//
2565
Evan Chengc50a1cb2009-07-09 22:58:39 +00002566// FIXME: remove when we have a way to marking a MI with these properties.
2567// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
2568// operand list.
2569// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng0d92f5f2009-10-01 08:22:27 +00002570let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
Chris Lattner39ee0362010-10-31 19:10:56 +00002571 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
Jim Grosbache6913602010-11-03 01:01:43 +00002572 def t2LDM_RET: T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
2573 reglist:$dsts, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00002574 IIC_iLoad_mBr,
Jim Grosbache6913602010-11-03 01:01:43 +00002575 "ldm${amode}${p}.w\t$Rn!, $dsts",
2576 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002577 let Inst{31-27} = 0b11101;
2578 let Inst{26-25} = 0b00;
2579 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
2580 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00002581 let Inst{21} = 1; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00002582 let Inst{20} = 1; // Load
2583}
Evan Chengc50a1cb2009-07-09 22:58:39 +00002584
David Goodwin5e47a9a2009-06-30 18:04:13 +00002585let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
2586let isPredicable = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002587def t2B : T2XI<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002588 "b.w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002589 [(br bb:$target)]> {
2590 let Inst{31-27} = 0b11110;
2591 let Inst{15-14} = 0b10;
2592 let Inst{12} = 1;
2593}
David Goodwin5e47a9a2009-06-30 18:04:13 +00002594
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002595let isNotDuplicable = 1, isIndirectBranch = 1,
2596 isCodeGenOnly = 1 in { // $id doesn't exist in asmstring, should be lowered.
Evan Cheng66ac5312009-07-25 00:33:29 +00002597def t2BR_JT :
Evan Cheng5657c012009-07-29 02:18:14 +00002598 T2JTI<(outs),
2599 (ins GPR:$target, GPR:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002600 IIC_Br, "mov\tpc, $target$jt",
Johnny Chend68e1192009-12-15 17:24:14 +00002601 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]> {
2602 let Inst{31-27} = 0b11101;
2603 let Inst{26-20} = 0b0100100;
2604 let Inst{19-16} = 0b1111;
2605 let Inst{14-12} = 0b000;
2606 let Inst{11-8} = 0b1111; // Rd = pc
2607 let Inst{7-4} = 0b0000;
2608}
Evan Cheng5657c012009-07-29 02:18:14 +00002609
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002610// FIXME: Add a non-pc based case that can be predicated.
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002611let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002612def t2TBB :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002613 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002614 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002615 IIC_Br, "tbb\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002616 let Inst{31-27} = 0b11101;
2617 let Inst{26-20} = 0b0001101;
2618 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2619 let Inst{15-8} = 0b11110000;
2620 let Inst{7-4} = 0b0000; // B form
2621}
Evan Cheng5657c012009-07-29 02:18:14 +00002622
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002623let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002624def t2TBH :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002625 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002626 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002627 IIC_Br, "tbh\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002628 let Inst{31-27} = 0b11101;
2629 let Inst{26-20} = 0b0001101;
2630 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2631 let Inst{15-8} = 0b11110000;
2632 let Inst{7-4} = 0b0001; // H form
2633}
Johnny Chen93042d12010-03-02 18:14:57 +00002634
2635// Generic versions of the above two instructions, for disassembly only
2636
2637def t2TBBgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2638 "tbb", "\t[$a, $b]", []>{
2639 let Inst{31-27} = 0b11101;
2640 let Inst{26-20} = 0b0001101;
2641 let Inst{15-8} = 0b11110000;
2642 let Inst{7-4} = 0b0000; // B form
2643}
2644
2645def t2TBHgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2646 "tbh", "\t[$a, $b, lsl #1]", []> {
2647 let Inst{31-27} = 0b11101;
2648 let Inst{26-20} = 0b0001101;
2649 let Inst{15-8} = 0b11110000;
2650 let Inst{7-4} = 0b0001; // H form
2651}
Evan Cheng5657c012009-07-29 02:18:14 +00002652} // isNotDuplicable, isIndirectBranch
2653
David Goodwinc9a59b52009-06-30 19:50:22 +00002654} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00002655
2656// FIXME: should be able to write a pattern for ARMBrcond, but can't use
2657// a two-value operand where a dag node expects two operands. :(
2658let isBranch = 1, isTerminator = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002659def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002660 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002661 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
2662 let Inst{31-27} = 0b11110;
2663 let Inst{15-14} = 0b10;
2664 let Inst{12} = 0;
2665}
Evan Chengf49810c2009-06-23 17:48:47 +00002666
Evan Cheng06e16582009-07-10 01:54:42 +00002667
2668// IT block
Evan Cheng86050dc2010-06-18 23:09:54 +00002669let Defs = [ITSTATE] in
Evan Cheng06e16582009-07-10 01:54:42 +00002670def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
David Goodwin5d598aa2009-08-19 18:00:44 +00002671 AddrModeNone, Size2Bytes, IIC_iALUx,
Johnny Chend68e1192009-12-15 17:24:14 +00002672 "it$mask\t$cc", "", []> {
2673 // 16-bit instruction.
Johnny Chenbbc71b22009-12-16 02:32:54 +00002674 let Inst{31-16} = 0x0000;
Johnny Chend68e1192009-12-15 17:24:14 +00002675 let Inst{15-8} = 0b10111111;
2676}
Evan Cheng06e16582009-07-10 01:54:42 +00002677
Johnny Chence6275f2010-02-25 19:05:29 +00002678// Branch and Exchange Jazelle -- for disassembly only
2679// Rm = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002680def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
Johnny Chence6275f2010-02-25 19:05:29 +00002681 [/* For disassembly only; pattern left blank */]> {
2682 let Inst{31-27} = 0b11110;
2683 let Inst{26} = 0;
2684 let Inst{25-20} = 0b111100;
2685 let Inst{15-14} = 0b10;
2686 let Inst{12} = 0;
2687}
2688
Johnny Chen93042d12010-03-02 18:14:57 +00002689// Change Processor State is a system instruction -- for disassembly only.
2690// The singleton $opt operand contains the following information:
2691// opt{4-0} = mode from Inst{4-0}
2692// opt{5} = changemode from Inst{17}
2693// opt{8-6} = AIF from Inst{8-6}
2694// opt{10-9} = imod from Inst{19-18} with 0b10 as enable and 0b11 as disable
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002695def t2CPS : T2XI<(outs),(ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +00002696 [/* For disassembly only; pattern left blank */]> {
2697 let Inst{31-27} = 0b11110;
2698 let Inst{26} = 0;
2699 let Inst{25-20} = 0b111010;
2700 let Inst{15-14} = 0b10;
2701 let Inst{12} = 0;
2702}
2703
Johnny Chen0f7866e2010-03-03 02:09:43 +00002704// A6.3.4 Branches and miscellaneous control
2705// Table A6-14 Change Processor State, and hint instructions
2706// Helper class for disassembly only.
2707class T2I_hint<bits<8> op7_0, string opc, string asm>
2708 : T2I<(outs), (ins), NoItinerary, opc, asm,
2709 [/* For disassembly only; pattern left blank */]> {
2710 let Inst{31-20} = 0xf3a;
2711 let Inst{15-14} = 0b10;
2712 let Inst{12} = 0;
2713 let Inst{10-8} = 0b000;
2714 let Inst{7-0} = op7_0;
2715}
2716
2717def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
2718def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
2719def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
2720def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
2721def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
2722
2723def t2DBG : T2I<(outs),(ins i32imm:$opt), NoItinerary, "dbg", "\t$opt",
2724 [/* For disassembly only; pattern left blank */]> {
2725 let Inst{31-20} = 0xf3a;
2726 let Inst{15-14} = 0b10;
2727 let Inst{12} = 0;
2728 let Inst{10-8} = 0b000;
2729 let Inst{7-4} = 0b1111;
2730}
2731
Johnny Chen6341c5a2010-02-25 20:25:24 +00002732// Secure Monitor Call is a system instruction -- for disassembly only
2733// Option = Inst{19-16}
2734def t2SMC : T2I<(outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
2735 [/* For disassembly only; pattern left blank */]> {
2736 let Inst{31-27} = 0b11110;
2737 let Inst{26-20} = 0b1111111;
2738 let Inst{15-12} = 0b1000;
2739}
2740
2741// Store Return State is a system instruction -- for disassembly only
2742def t2SRSDBW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
2743 [/* For disassembly only; pattern left blank */]> {
2744 let Inst{31-27} = 0b11101;
2745 let Inst{26-20} = 0b0000010; // W = 1
2746}
2747
2748def t2SRSDB : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
2749 [/* For disassembly only; pattern left blank */]> {
2750 let Inst{31-27} = 0b11101;
2751 let Inst{26-20} = 0b0000000; // W = 0
2752}
2753
2754def t2SRSIAW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
2755 [/* For disassembly only; pattern left blank */]> {
2756 let Inst{31-27} = 0b11101;
2757 let Inst{26-20} = 0b0011010; // W = 1
2758}
2759
2760def t2SRSIA : T2I<(outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
2761 [/* For disassembly only; pattern left blank */]> {
2762 let Inst{31-27} = 0b11101;
2763 let Inst{26-20} = 0b0011000; // W = 0
2764}
2765
2766// Return From Exception is a system instruction -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002767def t2RFEDBW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfedb", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002768 [/* For disassembly only; pattern left blank */]> {
2769 let Inst{31-27} = 0b11101;
2770 let Inst{26-20} = 0b0000011; // W = 1
2771}
2772
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002773def t2RFEDB : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeab", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002774 [/* For disassembly only; pattern left blank */]> {
2775 let Inst{31-27} = 0b11101;
2776 let Inst{26-20} = 0b0000001; // W = 0
2777}
2778
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002779def t2RFEIAW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002780 [/* For disassembly only; pattern left blank */]> {
2781 let Inst{31-27} = 0b11101;
2782 let Inst{26-20} = 0b0011011; // W = 1
2783}
2784
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002785def t2RFEIA : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002786 [/* For disassembly only; pattern left blank */]> {
2787 let Inst{31-27} = 0b11101;
2788 let Inst{26-20} = 0b0011001; // W = 0
2789}
2790
Evan Chengf49810c2009-06-23 17:48:47 +00002791//===----------------------------------------------------------------------===//
2792// Non-Instruction Patterns
2793//
2794
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002795// Two piece so_imms.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002796def : T2Pat<(or rGPR:$LHS, t2_so_imm2part:$RHS),
2797 (t2ORRri (t2ORRri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002798 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002799def : T2Pat<(xor rGPR:$LHS, t2_so_imm2part:$RHS),
2800 (t2EORri (t2EORri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002801 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002802def : T2Pat<(add rGPR:$LHS, t2_so_imm2part:$RHS),
2803 (t2ADDri (t2ADDri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002804 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002805def : T2Pat<(add rGPR:$LHS, t2_so_neg_imm2part:$RHS),
2806 (t2SUBri (t2SUBri rGPR:$LHS, (t2_so_neg_imm2part_1 imm:$RHS)),
Jim Grosbach15e6ef82009-11-23 20:35:53 +00002807 (t2_so_neg_imm2part_2 imm:$RHS))>;
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002808
Evan Cheng5adb66a2009-09-28 09:14:39 +00002809// 32-bit immediate using movw + movt.
Evan Cheng5be39222010-09-24 22:03:46 +00002810// This is a single pseudo instruction to make it re-materializable.
2811// FIXME: Remove this when we can do generalized remat.
Evan Cheng5adb66a2009-09-28 09:14:39 +00002812let isReMaterializable = 1 in
Jim Grosbach3c38f962010-10-06 22:01:26 +00002813def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
2814 "", [(set rGPR:$dst, (i32 imm:$src))]>,
2815 Requires<[IsThumb, HasV6T2]>;
Evan Chengb9803a82009-11-06 23:52:48 +00002816
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00002817// ConstantPool, GlobalAddress, and JumpTable
2818def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
2819 Requires<[IsThumb2, DontUseMovt]>;
2820def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
2821def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
2822 Requires<[IsThumb2, UseMovt]>;
2823
2824def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
2825 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
2826
Evan Chengb9803a82009-11-06 23:52:48 +00002827// Pseudo instruction that combines ldr from constpool and add pc. This should
2828// be expanded into two instructions late to allow if-conversion and
2829// scheduling.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00002830let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Chengb9803a82009-11-06 23:52:48 +00002831def t2LDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Jim Grosbach78890f42010-10-01 23:21:38 +00002832 IIC_iLoadiALU, "",
Evan Chengb9803a82009-11-06 23:52:48 +00002833 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
2834 imm:$cp))]>,
2835 Requires<[IsThumb2]>;
Johnny Chen23336552010-02-25 18:46:43 +00002836
2837//===----------------------------------------------------------------------===//
2838// Move between special register and ARM core register -- for disassembly only
2839//
2840
2841// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002842def t2MRS : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, cpsr",
Johnny Chen23336552010-02-25 18:46:43 +00002843 [/* For disassembly only; pattern left blank */]> {
2844 let Inst{31-27} = 0b11110;
2845 let Inst{26} = 0;
2846 let Inst{25-21} = 0b11111;
2847 let Inst{20} = 0; // The R bit.
2848 let Inst{15-14} = 0b10;
2849 let Inst{12} = 0;
2850}
2851
2852// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002853def t2MRSsys : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, spsr",
Johnny Chen23336552010-02-25 18:46:43 +00002854 [/* For disassembly only; pattern left blank */]> {
2855 let Inst{31-27} = 0b11110;
2856 let Inst{26} = 0;
2857 let Inst{25-21} = 0b11111;
2858 let Inst{20} = 1; // The R bit.
2859 let Inst{15-14} = 0b10;
2860 let Inst{12} = 0;
2861}
2862
Johnny Chen23336552010-02-25 18:46:43 +00002863// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002864def t2MSR : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002865 "\tcpsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00002866 [/* For disassembly only; pattern left blank */]> {
2867 let Inst{31-27} = 0b11110;
2868 let Inst{26} = 0;
2869 let Inst{25-21} = 0b11100;
2870 let Inst{20} = 0; // The R bit.
2871 let Inst{15-14} = 0b10;
2872 let Inst{12} = 0;
2873}
2874
Johnny Chen23336552010-02-25 18:46:43 +00002875// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002876def t2MSRsys : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002877 "\tspsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00002878 [/* For disassembly only; pattern left blank */]> {
2879 let Inst{31-27} = 0b11110;
2880 let Inst{26} = 0;
2881 let Inst{25-21} = 0b11100;
2882 let Inst{20} = 1; // The R bit.
2883 let Inst{15-14} = 0b10;
2884 let Inst{12} = 0;
2885}