blob: 6e91f863dbff4dc6ba60479bf1bf3f3d0e151440 [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]> {
Chris Lattner2ac19022010-11-15 05:19:05 +000034 let 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); }]> {
Chris Lattner2ac19022010-11-15 05:19:05 +000056 let EncoderMethod = "getT2SOImmOpValue";
Owen Anderson5de6d842010-11-12 21:12:40 +000057}
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 Andersona99e7782010-11-15 18:45:17 +0000173
174class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson83da6cd2010-11-14 05:37:38 +0000175 string opc, string asm, list<dag> pattern>
176 : T2I<oops, iops, itin, opc, asm, pattern> {
177 bits<4> Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000178 bits<12> imm;
179
180 let Inst{11-8} = Rd{3-0};
181 let Inst{26} = imm{11};
182 let Inst{14-12} = imm{10-8};
183 let Inst{7-0} = imm{7-0};
184}
185
186class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
187 string opc, string asm, list<dag> pattern>
188 : T2sI<oops, iops, itin, opc, asm, pattern> {
189 bits<4> Rd;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000190 bits<4> Rn;
191 bits<12> imm;
192
193 let Inst{11-8} = Rd{3-0};
Owen Anderson83da6cd2010-11-14 05:37:38 +0000194 let Inst{26} = imm{11};
195 let Inst{14-12} = imm{10-8};
196 let Inst{7-0} = imm{7-0};
197}
198
Owen Andersona99e7782010-11-15 18:45:17 +0000199class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
200 string opc, string asm, list<dag> pattern>
201 : T2I<oops, iops, itin, opc, asm, pattern> {
202 bits<4> Rd;
203 bits<12> ShiftedRm;
204
205 let Inst{11-8} = Rd{3-0};
206 let Inst{3-0} = ShiftedRm{3-0};
207 let Inst{5-4} = ShiftedRm{6-5};
208 let Inst{14-12} = ShiftedRm{11-9};
209 let Inst{7-6} = ShiftedRm{8-7};
210}
211
212class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
213 string opc, string asm, list<dag> pattern>
214 : T2I<oops, iops, itin, opc, asm, pattern> {
215 bits<4> Rd;
216 bits<12> ShiftedRm;
217
218 let Inst{11-8} = Rd{3-0};
219 let Inst{3-0} = ShiftedRm{3-0};
220 let Inst{5-4} = ShiftedRm{6-5};
221 let Inst{14-12} = ShiftedRm{11-9};
222 let Inst{7-6} = ShiftedRm{8-7};
223}
224
225class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
226 string opc, string asm, list<dag> pattern>
227 : T2I<oops, iops, itin, opc, asm, pattern> {
228 bits<4> Rd;
229 bits<4> Rm;
230
231 let Inst{11-8} = Rd{3-0};
232 let Inst{3-0} = Rm{3-0};
233}
234
235class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
236 string opc, string asm, list<dag> pattern>
237 : T2sI<oops, iops, itin, opc, asm, pattern> {
238 bits<4> Rd;
239 bits<4> Rm;
240
241 let Inst{11-8} = Rd{3-0};
242 let Inst{3-0} = Rm{3-0};
243}
244
245
246class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
247 string opc, string asm, list<dag> pattern>
248 : T2I<oops, iops, itin, opc, asm, pattern> {
249 bits<4> Rd;
250 bits<4> Rm;
251
252 let Inst{11-8} = Rd{3-0};
253 let Inst{3-0} = Rm{3-0};
254}
255
Owen Anderson83da6cd2010-11-14 05:37:38 +0000256class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson5de6d842010-11-12 21:12:40 +0000257 string opc, string asm, list<dag> pattern>
258 : T2sI<oops, iops, itin, opc, asm, pattern> {
259 bits<4> Rd;
260 bits<4> Rn;
261 bits<12> imm;
262
263 let Inst{11-8} = Rd{3-0};
264 let Inst{19-16} = Rn{3-0};
265 let Inst{26} = imm{11};
266 let Inst{14-12} = imm{10-8};
267 let Inst{7-0} = imm{7-0};
268}
269
270class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
271 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000272 : T2I<oops, iops, itin, opc, asm, pattern> {
273 bits<4> Rd;
274 bits<4> Rn;
275 bits<4> Rm;
276
277 let Inst{11-8} = Rd{3-0};
278 let Inst{19-16} = Rn{3-0};
279 let Inst{3-0} = Rm{3-0};
280}
281
282class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
283 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000284 : T2sI<oops, iops, itin, opc, asm, pattern> {
285 bits<4> Rd;
286 bits<4> Rn;
287 bits<4> Rm;
288
289 let Inst{11-8} = Rd{3-0};
290 let Inst{19-16} = Rn{3-0};
291 let Inst{3-0} = Rm{3-0};
292}
293
294class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
295 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000296 : T2I<oops, iops, itin, opc, asm, pattern> {
297 bits<4> Rd;
298 bits<4> Rn;
299 bits<12> ShiftedRm;
300
301 let Inst{11-8} = Rd{3-0};
302 let Inst{19-16} = Rn{3-0};
303 let Inst{3-0} = ShiftedRm{3-0};
304 let Inst{5-4} = ShiftedRm{6-5};
305 let Inst{14-12} = ShiftedRm{11-9};
306 let Inst{7-6} = ShiftedRm{8-7};
307}
308
309class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
310 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000311 : T2sI<oops, iops, itin, opc, asm, pattern> {
312 bits<4> Rd;
313 bits<4> Rn;
314 bits<12> ShiftedRm;
315
316 let Inst{11-8} = Rd{3-0};
317 let Inst{19-16} = Rn{3-0};
318 let Inst{3-0} = ShiftedRm{3-0};
319 let Inst{5-4} = ShiftedRm{6-5};
320 let Inst{14-12} = ShiftedRm{11-9};
321 let Inst{7-6} = ShiftedRm{8-7};
322}
323
Evan Chenga67efd12009-06-23 19:39:13 +0000324/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000325/// unary operation that produces a value. These are predicable and can be
326/// changed to modify CPSR.
Evan Cheng5d42c562010-09-29 00:49:25 +0000327multiclass T2I_un_irs<bits<4> opcod, string opc,
328 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
329 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
Evan Chenga67efd12009-06-23 19:39:13 +0000330 // shifted imm
Owen Andersona99e7782010-11-15 18:45:17 +0000331 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
332 opc, "\t$Rd, $imm",
333 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
Evan Chenga67efd12009-06-23 19:39:13 +0000334 let isAsCheapAsAMove = Cheap;
335 let isReMaterializable = ReMat;
Johnny Chend68e1192009-12-15 17:24:14 +0000336 let Inst{31-27} = 0b11110;
337 let Inst{25} = 0;
338 let Inst{24-21} = opcod;
339 let Inst{20} = ?; // The S bit.
340 let Inst{19-16} = 0b1111; // Rn
341 let Inst{15} = 0;
Evan Chenga67efd12009-06-23 19:39:13 +0000342 }
343 // register
Owen Andersona99e7782010-11-15 18:45:17 +0000344 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
345 opc, ".w\t$Rd, $Rm",
346 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000347 let Inst{31-27} = 0b11101;
348 let Inst{26-25} = 0b01;
349 let Inst{24-21} = opcod;
350 let Inst{20} = ?; // The S bit.
351 let Inst{19-16} = 0b1111; // Rn
352 let Inst{14-12} = 0b000; // imm3
353 let Inst{7-6} = 0b00; // imm2
354 let Inst{5-4} = 0b00; // type
355 }
Evan Chenga67efd12009-06-23 19:39:13 +0000356 // shifted register
Owen Andersona99e7782010-11-15 18:45:17 +0000357 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
358 opc, ".w\t$Rd, $ShiftedRm",
359 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000360 let Inst{31-27} = 0b11101;
361 let Inst{26-25} = 0b01;
362 let Inst{24-21} = opcod;
363 let Inst{20} = ?; // The S bit.
364 let Inst{19-16} = 0b1111; // Rn
365 }
Evan Chenga67efd12009-06-23 19:39:13 +0000366}
367
368/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Bob Wilson4876bdb2010-05-25 04:43:08 +0000369/// binary operation that produces a value. These are predicable and can be
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000370/// changed to modify CPSR.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000371multiclass T2I_bin_irs<bits<4> opcod, string opc,
372 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
373 PatFrag opnode, bit Commutable = 0, string wide = ""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000374 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000375 def ri : T2sTwoRegImm<
376 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
377 opc, "\t$Rd, $Rn, $imm",
378 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000379 let Inst{31-27} = 0b11110;
380 let Inst{25} = 0;
381 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000382 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000383 let Inst{15} = 0;
384 }
Evan Chenga67efd12009-06-23 19:39:13 +0000385 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000386 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
387 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
388 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000389 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000390 let Inst{31-27} = 0b11101;
391 let Inst{26-25} = 0b01;
392 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000393 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000394 let Inst{14-12} = 0b000; // imm3
395 let Inst{7-6} = 0b00; // imm2
396 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000397 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000398 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000399 def rs : T2sTwoRegShiftedReg<
400 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
401 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
402 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000403 let Inst{31-27} = 0b11101;
404 let Inst{26-25} = 0b01;
405 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000406 let Inst{20} = ?; // The S bit.
407 }
408}
409
David Goodwin1f096272009-07-27 23:34:12 +0000410/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
411// the ".w" prefix to indicate that they are wide.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000412multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
413 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
414 PatFrag opnode, bit Commutable = 0> :
415 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w">;
Bill Wendling1f7bf0e2010-08-29 03:55:31 +0000416
Evan Cheng1e249e32009-06-25 20:59:23 +0000417/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000418/// reversed. The 'rr' form is only defined for the disassembler; for codegen
419/// it is equivalent to the T2I_bin_irs counterpart.
420multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000421 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000422 def ri : T2sTwoRegImm<
423 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
424 opc, ".w\t$Rd, $Rn, $imm",
425 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000426 let Inst{31-27} = 0b11110;
427 let Inst{25} = 0;
428 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000429 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000430 let Inst{15} = 0;
431 }
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000432 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000433 def rr : T2sThreeReg<
434 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
435 opc, "\t$Rd, $Rn, $Rm",
Bob Wilson136e4912010-08-14 03:18:29 +0000436 [/* For disassembly only; pattern left blank */]> {
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000437 let Inst{31-27} = 0b11101;
438 let Inst{26-25} = 0b01;
439 let Inst{24-21} = opcod;
440 let Inst{20} = ?; // The S bit.
441 let Inst{14-12} = 0b000; // imm3
442 let Inst{7-6} = 0b00; // imm2
443 let Inst{5-4} = 0b00; // type
444 }
Evan Chengf49810c2009-06-23 17:48:47 +0000445 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000446 def rs : T2sTwoRegShiftedReg<
447 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
448 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
449 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000450 let Inst{31-27} = 0b11101;
451 let Inst{26-25} = 0b01;
452 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000453 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000454 }
Evan Chengf49810c2009-06-23 17:48:47 +0000455}
456
Evan Chenga67efd12009-06-23 19:39:13 +0000457/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000458/// instruction modifies the CPSR register.
459let Defs = [CPSR] in {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000460multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
461 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
462 PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000463 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000464 def ri : T2TwoRegImm<
465 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
466 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
467 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000468 let Inst{31-27} = 0b11110;
469 let Inst{25} = 0;
470 let Inst{24-21} = opcod;
471 let Inst{20} = 1; // The S bit.
472 let Inst{15} = 0;
473 }
Evan Chenga67efd12009-06-23 19:39:13 +0000474 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000475 def rr : T2ThreeReg<
476 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
477 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm",
478 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000479 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000480 let Inst{31-27} = 0b11101;
481 let Inst{26-25} = 0b01;
482 let Inst{24-21} = opcod;
483 let Inst{20} = 1; // The S bit.
484 let Inst{14-12} = 0b000; // imm3
485 let Inst{7-6} = 0b00; // imm2
486 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000487 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000488 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000489 def rs : T2TwoRegShiftedReg<
490 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
491 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm",
492 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000493 let Inst{31-27} = 0b11101;
494 let Inst{26-25} = 0b01;
495 let Inst{24-21} = opcod;
496 let Inst{20} = 1; // The S bit.
497 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000498}
499}
500
Evan Chenga67efd12009-06-23 19:39:13 +0000501/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
502/// patterns for a binary operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000503multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
504 bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000505 // shifted imm
Jim Grosbach663e3392010-08-30 19:49:58 +0000506 // The register-immediate version is re-materializable. This is useful
507 // in particular for taking the address of a local.
508 let isReMaterializable = 1 in {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000509 def ri : T2sTwoRegImm<
510 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
511 opc, ".w\t$Rd, $Rn, $imm",
512 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000513 let Inst{31-27} = 0b11110;
514 let Inst{25} = 0;
515 let Inst{24} = 1;
516 let Inst{23-21} = op23_21;
517 let Inst{20} = 0; // The S bit.
518 let Inst{15} = 0;
519 }
Jim Grosbach663e3392010-08-30 19:49:58 +0000520 }
Evan Chengf49810c2009-06-23 17:48:47 +0000521 // 12-bit imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000522 def ri12 : T2TwoRegImm<
523 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
524 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
525 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000526 let Inst{31-27} = 0b11110;
527 let Inst{25} = 1;
528 let Inst{24} = 0;
529 let Inst{23-21} = op23_21;
530 let Inst{20} = 0; // The S bit.
531 let Inst{15} = 0;
532 }
Evan Chenga67efd12009-06-23 19:39:13 +0000533 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000534 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr,
535 opc, ".w\t$Rd, $Rn, $Rm",
536 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000537 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000538 let Inst{31-27} = 0b11101;
539 let Inst{26-25} = 0b01;
540 let Inst{24} = 1;
541 let Inst{23-21} = op23_21;
542 let Inst{20} = 0; // The S bit.
543 let Inst{14-12} = 0b000; // imm3
544 let Inst{7-6} = 0b00; // imm2
545 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000546 }
Evan Chengf49810c2009-06-23 17:48:47 +0000547 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000548 def rs : T2sTwoRegShiftedReg<
549 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
550 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
551 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000552 let Inst{31-27} = 0b11101;
Johnny Chend68e1192009-12-15 17:24:14 +0000553 let Inst{26-25} = 0b01;
Johnny Chend248ffb2010-01-08 17:41:33 +0000554 let Inst{24} = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000555 let Inst{23-21} = op23_21;
556 let Inst{20} = 0; // The S bit.
557 }
Evan Chengf49810c2009-06-23 17:48:47 +0000558}
559
Jim Grosbach6935efc2009-11-24 00:20:27 +0000560/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000561/// for a binary operation that produces a value and use the carry
Jim Grosbach6935efc2009-11-24 00:20:27 +0000562/// bit. It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000563let Uses = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000564multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
565 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000566 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000567 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000568 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
569 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000570 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000571 let Inst{31-27} = 0b11110;
572 let Inst{25} = 0;
573 let Inst{24-21} = opcod;
574 let Inst{20} = 0; // The S bit.
575 let Inst{15} = 0;
576 }
Evan Chenga67efd12009-06-23 19:39:13 +0000577 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000578 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000579 opc, ".w\t$Rd, $Rn, $Rm",
580 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000581 Requires<[IsThumb2]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000582 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000583 let Inst{31-27} = 0b11101;
584 let Inst{26-25} = 0b01;
585 let Inst{24-21} = opcod;
586 let Inst{20} = 0; // The S bit.
587 let Inst{14-12} = 0b000; // imm3
588 let Inst{7-6} = 0b00; // imm2
589 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000590 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000591 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000592 def rs : T2sTwoRegShiftedReg<
Owen Anderson5de6d842010-11-12 21:12:40 +0000593 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
594 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
595 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000596 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000597 let Inst{31-27} = 0b11101;
598 let Inst{26-25} = 0b01;
599 let Inst{24-21} = opcod;
600 let Inst{20} = 0; // The S bit.
601 }
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000602}
603
604// Carry setting variants
605let Defs = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000606multiclass T2I_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
607 bit Commutable = 0> {
Evan Cheng62674222009-06-25 23:34:10 +0000608 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000609 def ri : T2sTwoRegImm<
Owen Anderson5de6d842010-11-12 21:12:40 +0000610 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
611 opc, "\t$Rd, $Rn, $imm",
612 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000613 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000614 let Inst{31-27} = 0b11110;
615 let Inst{25} = 0;
616 let Inst{24-21} = opcod;
617 let Inst{20} = 1; // The S bit.
618 let Inst{15} = 0;
619 }
Evan Cheng62674222009-06-25 23:34:10 +0000620 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000621 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000622 opc, ".w\t$Rd, $Rn, $Rm",
623 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000624 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000625 let isCommutable = Commutable;
626 let Inst{31-27} = 0b11101;
627 let Inst{26-25} = 0b01;
628 let Inst{24-21} = opcod;
629 let Inst{20} = 1; // The S bit.
630 let Inst{14-12} = 0b000; // imm3
631 let Inst{7-6} = 0b00; // imm2
632 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000633 }
Evan Cheng62674222009-06-25 23:34:10 +0000634 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000635 def rs : T2sTwoRegShiftedReg<
Owen Anderson5de6d842010-11-12 21:12:40 +0000636 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
637 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
638 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000639 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000640 let Inst{31-27} = 0b11101;
641 let Inst{26-25} = 0b01;
642 let Inst{24-21} = opcod;
643 let Inst{20} = 1; // The S bit.
Evan Cheng8de898a2009-06-26 00:19:44 +0000644 }
Evan Chengf49810c2009-06-23 17:48:47 +0000645}
646}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000647}
Evan Chengf49810c2009-06-23 17:48:47 +0000648
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000649/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
650/// version is not needed since this is only for codegen.
Evan Cheng1e249e32009-06-25 20:59:23 +0000651let Defs = [CPSR] in {
Johnny Chend68e1192009-12-15 17:24:14 +0000652multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000653 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000654 def ri : T2TwoRegImm<
655 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
656 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
657 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000658 let Inst{31-27} = 0b11110;
659 let Inst{25} = 0;
660 let Inst{24-21} = opcod;
661 let Inst{20} = 1; // The S bit.
662 let Inst{15} = 0;
663 }
Evan Chengf49810c2009-06-23 17:48:47 +0000664 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000665 def rs : T2TwoRegShiftedReg<
666 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
667 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm",
668 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000669 let Inst{31-27} = 0b11101;
670 let Inst{26-25} = 0b01;
671 let Inst{24-21} = opcod;
672 let Inst{20} = 1; // The S bit.
673 }
Evan Chengf49810c2009-06-23 17:48:47 +0000674}
675}
676
Evan Chenga67efd12009-06-23 19:39:13 +0000677/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
678// rotate operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000679multiclass T2I_sh_ir<bits<2> opcod, string opc, PatFrag opnode> {
Evan Chenga67efd12009-06-23 19:39:13 +0000680 // 5-bit imm
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000681 def ri : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +0000682 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000683 [(set rGPR:$dst, (opnode rGPR:$lhs, imm1_31:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000684 let Inst{31-27} = 0b11101;
685 let Inst{26-21} = 0b010010;
686 let Inst{19-16} = 0b1111; // Rn
687 let Inst{5-4} = opcod;
688 }
Evan Chenga67efd12009-06-23 19:39:13 +0000689 // register
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000690 def rr : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, rGPR:$rhs), IIC_iMOVsr,
Evan Cheng699beba2009-10-27 00:08:59 +0000691 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000692 [(set rGPR:$dst, (opnode rGPR:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000693 let Inst{31-27} = 0b11111;
694 let Inst{26-23} = 0b0100;
695 let Inst{22-21} = opcod;
696 let Inst{15-12} = 0b1111;
697 let Inst{7-4} = 0b0000;
698 }
Evan Chenga67efd12009-06-23 19:39:13 +0000699}
Evan Chengf49810c2009-06-23 17:48:47 +0000700
Johnny Chend68e1192009-12-15 17:24:14 +0000701/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
Evan Chenga67efd12009-06-23 19:39:13 +0000702/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000703/// a explicit result, only implicitly set CPSR.
Bill Wendlingf0e132c2010-08-19 00:05:48 +0000704let isCompare = 1, Defs = [CPSR] in {
Evan Cheng5d42c562010-09-29 00:49:25 +0000705multiclass T2I_cmp_irs<bits<4> opcod, string opc,
706 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
707 PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000708 // shifted imm
Evan Cheng5d42c562010-09-29 00:49:25 +0000709 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000710 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000711 [(opnode GPR:$lhs, t2_so_imm:$rhs)]> {
712 let Inst{31-27} = 0b11110;
713 let Inst{25} = 0;
714 let Inst{24-21} = opcod;
715 let Inst{20} = 1; // The S bit.
716 let Inst{15} = 0;
717 let Inst{11-8} = 0b1111; // Rd
718 }
Evan Chenga67efd12009-06-23 19:39:13 +0000719 // register
Evan Cheng5d42c562010-09-29 00:49:25 +0000720 def rr : T2I<(outs), (ins GPR:$lhs, rGPR:$rhs), iir,
Evan Cheng699beba2009-10-27 00:08:59 +0000721 opc, ".w\t$lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000722 [(opnode GPR:$lhs, rGPR:$rhs)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000723 let Inst{31-27} = 0b11101;
724 let Inst{26-25} = 0b01;
725 let Inst{24-21} = opcod;
726 let Inst{20} = 1; // The S bit.
727 let Inst{14-12} = 0b000; // imm3
728 let Inst{11-8} = 0b1111; // Rd
729 let Inst{7-6} = 0b00; // imm2
730 let Inst{5-4} = 0b00; // type
731 }
Evan Chengf49810c2009-06-23 17:48:47 +0000732 // shifted register
Evan Cheng5d42c562010-09-29 00:49:25 +0000733 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000734 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000735 [(opnode GPR:$lhs, t2_so_reg:$rhs)]> {
736 let Inst{31-27} = 0b11101;
737 let Inst{26-25} = 0b01;
738 let Inst{24-21} = opcod;
739 let Inst{20} = 1; // The S bit.
740 let Inst{11-8} = 0b1111; // Rd
741 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000742}
743}
744
Evan Chengf3c21b82009-06-30 02:15:48 +0000745/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000746multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000747 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000748 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000749 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000750 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]> {
751 let Inst{31-27} = 0b11111;
752 let Inst{26-25} = 0b00;
753 let Inst{24} = signed;
754 let Inst{23} = 1;
755 let Inst{22-21} = opcod;
756 let Inst{20} = 1; // load
757 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000758 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000759 opc, "\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000760 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]> {
761 let Inst{31-27} = 0b11111;
762 let Inst{26-25} = 0b00;
763 let Inst{24} = signed;
764 let Inst{23} = 0;
765 let Inst{22-21} = opcod;
766 let Inst{20} = 1; // load
767 let Inst{11} = 1;
768 // Offset: index==TRUE, wback==FALSE
769 let Inst{10} = 1; // The P bit.
770 let Inst{8} = 0; // The W bit.
771 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000772 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000773 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000774 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]> {
775 let Inst{31-27} = 0b11111;
776 let Inst{26-25} = 0b00;
777 let Inst{24} = signed;
778 let Inst{23} = 0;
779 let Inst{22-21} = opcod;
780 let Inst{20} = 1; // load
781 let Inst{11-6} = 0b000000;
782 }
Evan Chengbc7deb02010-11-03 05:14:24 +0000783
784 // FIXME: Is the pci variant actually needed?
Evan Cheng0e55fd62010-09-30 01:08:25 +0000785 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000786 opc, ".w\t$dst, $addr",
Evan Cheng9eda6892009-10-31 03:39:36 +0000787 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]> {
788 let isReMaterializable = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000789 let Inst{31-27} = 0b11111;
790 let Inst{26-25} = 0b00;
791 let Inst{24} = signed;
792 let Inst{23} = ?; // add = (U == '1')
793 let Inst{22-21} = opcod;
794 let Inst{20} = 1; // load
795 let Inst{19-16} = 0b1111; // Rn
Evan Cheng9eda6892009-10-31 03:39:36 +0000796 }
Evan Chengf3c21b82009-06-30 02:15:48 +0000797}
798
David Goodwin73b8f162009-06-30 22:11:34 +0000799/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000800multiclass T2I_st<bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000801 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000802 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000803 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000804 [(opnode GPR:$src, t2addrmode_imm12:$addr)]> {
805 let Inst{31-27} = 0b11111;
806 let Inst{26-23} = 0b0001;
807 let Inst{22-21} = opcod;
808 let Inst{20} = 0; // !load
809 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000810 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000811 opc, "\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000812 [(opnode GPR:$src, t2addrmode_imm8:$addr)]> {
813 let Inst{31-27} = 0b11111;
814 let Inst{26-23} = 0b0000;
815 let Inst{22-21} = opcod;
816 let Inst{20} = 0; // !load
817 let Inst{11} = 1;
818 // Offset: index==TRUE, wback==FALSE
819 let Inst{10} = 1; // The P bit.
820 let Inst{8} = 0; // The W bit.
821 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000822 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000823 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000824 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]> {
825 let Inst{31-27} = 0b11111;
826 let Inst{26-23} = 0b0000;
827 let Inst{22-21} = opcod;
828 let Inst{20} = 0; // !load
829 let Inst{11-6} = 0b000000;
830 }
David Goodwin73b8f162009-06-30 22:11:34 +0000831}
832
Evan Cheng0e55fd62010-09-30 01:08:25 +0000833/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000834/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000835multiclass T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> {
836 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000837 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000838 [(set rGPR:$dst, (opnode rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000839 let Inst{31-27} = 0b11111;
840 let Inst{26-23} = 0b0100;
841 let Inst{22-20} = opcod;
842 let Inst{19-16} = 0b1111; // Rn
843 let Inst{15-12} = 0b1111;
844 let Inst{7} = 1;
845 let Inst{5-4} = 0b00; // rotate
846 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000847 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000848 opc, ".w\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000849 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000850 let Inst{31-27} = 0b11111;
851 let Inst{26-23} = 0b0100;
852 let Inst{22-20} = opcod;
853 let Inst{19-16} = 0b1111; // Rn
854 let Inst{15-12} = 0b1111;
855 let Inst{7} = 1;
856 let Inst{5-4} = {?,?}; // rotate
857 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000858}
859
Eli Friedman761fa7a2010-06-24 18:20:04 +0000860// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000861multiclass T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> {
862 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000863 opc, "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000864 [(set rGPR:$dst, (opnode rGPR:$src))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000865 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000866 let Inst{31-27} = 0b11111;
867 let Inst{26-23} = 0b0100;
868 let Inst{22-20} = opcod;
869 let Inst{19-16} = 0b1111; // Rn
870 let Inst{15-12} = 0b1111;
871 let Inst{7} = 1;
872 let Inst{5-4} = 0b00; // rotate
873 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000874 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000875 opc, "\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000876 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000877 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000878 let Inst{31-27} = 0b11111;
879 let Inst{26-23} = 0b0100;
880 let Inst{22-20} = opcod;
881 let Inst{19-16} = 0b1111; // Rn
882 let Inst{15-12} = 0b1111;
883 let Inst{7} = 1;
884 let Inst{5-4} = {?,?}; // rotate
885 }
886}
887
Eli Friedman761fa7a2010-06-24 18:20:04 +0000888// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
889// supported yet.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000890multiclass T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> {
891 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000892 opc, "\t$dst, $src", []> {
893 let Inst{31-27} = 0b11111;
894 let Inst{26-23} = 0b0100;
895 let Inst{22-20} = opcod;
896 let Inst{19-16} = 0b1111; // Rn
897 let Inst{15-12} = 0b1111;
898 let Inst{7} = 1;
899 let Inst{5-4} = 0b00; // rotate
900 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000901 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000902 opc, "\t$dst, $src, ror $rot", []> {
903 let Inst{31-27} = 0b11111;
904 let Inst{26-23} = 0b0100;
905 let Inst{22-20} = opcod;
906 let Inst{19-16} = 0b1111; // Rn
907 let Inst{15-12} = 0b1111;
908 let Inst{7} = 1;
909 let Inst{5-4} = {?,?}; // rotate
910 }
911}
912
Evan Cheng0e55fd62010-09-30 01:08:25 +0000913/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000914/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000915multiclass T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> {
916 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Evan Cheng699beba2009-10-27 00:08:59 +0000917 opc, "\t$dst, $LHS, $RHS",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000918 [(set rGPR:$dst, (opnode rGPR:$LHS, rGPR:$RHS))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000919 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000920 let Inst{31-27} = 0b11111;
921 let Inst{26-23} = 0b0100;
922 let Inst{22-20} = opcod;
923 let Inst{15-12} = 0b1111;
924 let Inst{7} = 1;
925 let Inst{5-4} = 0b00; // rotate
926 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000927 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng0e55fd62010-09-30 01:08:25 +0000928 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000929 [(set rGPR:$dst, (opnode rGPR:$LHS,
930 (rotr rGPR:$RHS, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000931 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000932 let Inst{31-27} = 0b11111;
933 let Inst{26-23} = 0b0100;
934 let Inst{22-20} = opcod;
935 let Inst{15-12} = 0b1111;
936 let Inst{7} = 1;
937 let Inst{5-4} = {?,?}; // rotate
938 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000939}
940
Johnny Chen93042d12010-03-02 18:14:57 +0000941// DO variant - disassembly only, no pattern
942
Evan Cheng0e55fd62010-09-30 01:08:25 +0000943multiclass T2I_exta_rrot_DO<bits<3> opcod, string opc> {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000944 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Johnny Chen93042d12010-03-02 18:14:57 +0000945 opc, "\t$dst, $LHS, $RHS", []> {
946 let Inst{31-27} = 0b11111;
947 let Inst{26-23} = 0b0100;
948 let Inst{22-20} = opcod;
949 let Inst{15-12} = 0b1111;
950 let Inst{7} = 1;
951 let Inst{5-4} = 0b00; // rotate
952 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000953 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng7e1bf302010-09-29 00:27:46 +0000954 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot", []> {
Johnny Chen93042d12010-03-02 18:14:57 +0000955 let Inst{31-27} = 0b11111;
956 let Inst{26-23} = 0b0100;
957 let Inst{22-20} = opcod;
958 let Inst{15-12} = 0b1111;
959 let Inst{7} = 1;
960 let Inst{5-4} = {?,?}; // rotate
961 }
962}
963
Anton Korobeynikov52237112009-06-17 18:13:58 +0000964//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000965// Instructions
966//===----------------------------------------------------------------------===//
967
968//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000969// Miscellaneous Instructions.
970//
971
Evan Chenga09b9ca2009-06-24 23:47:58 +0000972// LEApcrel - Load a pc-relative address into a register without offending the
973// assembler.
Evan Chengea420b22010-05-19 01:52:25 +0000974let neverHasSideEffects = 1 in {
Evan Cheng9085f982010-05-19 07:28:01 +0000975let isReMaterializable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000976def t2LEApcrel : T2XI<(outs rGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000977 "adr${p}.w\t$dst, #$label", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000978 let Inst{31-27} = 0b11110;
979 let Inst{25-24} = 0b10;
980 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
981 let Inst{22} = 0;
982 let Inst{20} = 0;
983 let Inst{19-16} = 0b1111; // Rn
984 let Inst{15} = 0;
985}
Jim Grosbacha967d112010-06-21 21:27:27 +0000986} // neverHasSideEffects
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000987def t2LEApcrelJT : T2XI<(outs rGPR:$dst),
Bob Wilson4f38b382009-08-21 21:58:55 +0000988 (ins i32imm:$label, nohash_imm:$id, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000989 "adr${p}.w\t$dst, #${label}_${id}", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000990 let Inst{31-27} = 0b11110;
991 let Inst{25-24} = 0b10;
992 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
993 let Inst{22} = 0;
994 let Inst{20} = 0;
995 let Inst{19-16} = 0b1111; // Rn
996 let Inst{15} = 0;
997}
Evan Chenga09b9ca2009-06-24 23:47:58 +0000998
Evan Cheng86198642009-08-07 00:34:42 +0000999// ADD r, sp, {so_imm|i12}
Owen Andersonb9a643e2010-11-12 23:36:03 +00001000def t2ADDrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
1001 IIC_iALUi, "add", ".w\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001002 let Inst{31-27} = 0b11110;
1003 let Inst{25} = 0;
1004 let Inst{24-21} = 0b1000;
1005 let Inst{20} = ?; // The S bit.
Owen Andersonb9a643e2010-11-12 23:36:03 +00001006 let Inst{19-16} = 0b1101; // Rn = sp
Johnny Chend68e1192009-12-15 17:24:14 +00001007 let Inst{15} = 0;
1008}
Owen Andersonb9a643e2010-11-12 23:36:03 +00001009def t2ADDrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
1010 IIC_iALUi, "addw", "\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001011 let Inst{31-27} = 0b11110;
1012 let Inst{25} = 1;
1013 let Inst{24-21} = 0b0000;
1014 let Inst{20} = 0; // The S bit.
1015 let Inst{19-16} = 0b1101; // Rn = sp
1016 let Inst{15} = 0;
1017}
Evan Cheng86198642009-08-07 00:34:42 +00001018
1019// ADD r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +00001020def t2ADDrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00001021 IIC_iALUsi, "add", ".w\t$dst, $sp, $rhs", []> {
1022 let Inst{31-27} = 0b11101;
1023 let Inst{26-25} = 0b01;
1024 let Inst{24-21} = 0b1000;
1025 let Inst{20} = ?; // The S bit.
1026 let Inst{19-16} = 0b1101; // Rn = sp
1027 let Inst{15} = 0;
1028}
Evan Cheng86198642009-08-07 00:34:42 +00001029
1030// SUB r, sp, {so_imm|i12}
David Goodwin5d598aa2009-08-19 18:00:44 +00001031def t2SUBrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +00001032 IIC_iALUi, "sub", ".w\t$dst, $sp, $imm", []> {
1033 let Inst{31-27} = 0b11110;
1034 let Inst{25} = 0;
1035 let Inst{24-21} = 0b1101;
1036 let Inst{20} = ?; // The S bit.
1037 let Inst{19-16} = 0b1101; // Rn = sp
1038 let Inst{15} = 0;
1039}
David Goodwin5d598aa2009-08-19 18:00:44 +00001040def t2SUBrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +00001041 IIC_iALUi, "subw", "\t$dst, $sp, $imm", []> {
1042 let Inst{31-27} = 0b11110;
1043 let Inst{25} = 1;
1044 let Inst{24-21} = 0b0101;
1045 let Inst{20} = 0; // The S bit.
1046 let Inst{19-16} = 0b1101; // Rn = sp
1047 let Inst{15} = 0;
1048}
Evan Cheng86198642009-08-07 00:34:42 +00001049
1050// SUB r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +00001051def t2SUBrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
1052 IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001053 "sub", "\t$dst, $sp, $rhs", []> {
1054 let Inst{31-27} = 0b11101;
1055 let Inst{26-25} = 0b01;
1056 let Inst{24-21} = 0b1101;
1057 let Inst{20} = ?; // The S bit.
1058 let Inst{19-16} = 0b1101; // Rn = sp
1059 let Inst{15} = 0;
1060}
Evan Cheng86198642009-08-07 00:34:42 +00001061
Jim Grosbachb1dc3932010-05-05 20:44:35 +00001062// Signed and unsigned division on v7-M
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001063def t2SDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +00001064 "sdiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001065 [(set rGPR:$dst, (sdiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +00001066 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +00001067 let Inst{31-27} = 0b11111;
1068 let Inst{26-21} = 0b011100;
1069 let Inst{20} = 0b1;
1070 let Inst{15-12} = 0b1111;
1071 let Inst{7-4} = 0b1111;
1072}
1073
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001074def t2UDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +00001075 "udiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001076 [(set rGPR:$dst, (udiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +00001077 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +00001078 let Inst{31-27} = 0b11111;
1079 let Inst{26-21} = 0b011101;
1080 let Inst{20} = 0b1;
1081 let Inst{15-12} = 0b1111;
1082 let Inst{7-4} = 0b1111;
1083}
1084
Evan Chenga09b9ca2009-06-24 23:47:58 +00001085//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001086// Load / store Instructions.
1087//
1088
Evan Cheng055b0312009-06-29 07:51:04 +00001089// Load
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001090let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng7e2fe912010-10-28 06:47:08 +00001091defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001092 UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001093
Evan Chengf3c21b82009-06-30 02:15:48 +00001094// Loads with zero extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001095defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001096 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001097defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001098 UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001099
Evan Chengf3c21b82009-06-30 02:15:48 +00001100// Loads with sign extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001101defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001102 UnOpFrag<(sextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001103defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001104 UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001105
Chris Lattnera1ca91a2010-11-02 23:40:41 +00001106let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
1107 isCodeGenOnly = 1 in { // $dst doesn't exist in asmstring?
Evan Chengf3c21b82009-06-30 02:15:48 +00001108// Load doubleword
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001109def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Chenge298ab22009-09-27 09:46:04 +00001110 (ins t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001111 IIC_iLoad_d_i, "ldrd", "\t$dst1, $addr", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001112def t2LDRDpci : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001113 (ins i32imm:$addr), IIC_iLoad_d_i,
Johnny Chen83142992010-01-05 22:37:28 +00001114 "ldrd", "\t$dst1, $addr", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001115 let Inst{19-16} = 0b1111; // Rn
1116}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001117} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
Evan Chengf3c21b82009-06-30 02:15:48 +00001118
1119// zextload i1 -> zextload i8
1120def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1121 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1122def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1123 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1124def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1125 (t2LDRBs t2addrmode_so_reg:$addr)>;
1126def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1127 (t2LDRBpci tconstpool:$addr)>;
1128
1129// extload -> zextload
1130// FIXME: Reduce the number of patterns by legalizing extload to zextload
1131// earlier?
1132def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1133 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1134def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1135 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1136def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1137 (t2LDRBs t2addrmode_so_reg:$addr)>;
1138def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1139 (t2LDRBpci tconstpool:$addr)>;
1140
1141def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1142 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1143def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1144 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1145def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1146 (t2LDRBs t2addrmode_so_reg:$addr)>;
1147def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1148 (t2LDRBpci tconstpool:$addr)>;
1149
1150def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1151 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1152def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1153 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1154def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1155 (t2LDRHs t2addrmode_so_reg:$addr)>;
1156def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1157 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +00001158
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001159// FIXME: The destination register of the loads and stores can't be PC, but
1160// can be SP. We need another regclass (similar to rGPR) to represent
1161// that. Not a pressing issue since these are selected manually,
1162// not via pattern.
1163
Evan Chenge88d5ce2009-07-02 07:28:31 +00001164// Indexed loads
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001165let mayLoad = 1, neverHasSideEffects = 1 in {
Johnny Chend68e1192009-12-15 17:24:14 +00001166def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001167 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001168 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001169 "ldr", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001170 []>;
1171
Johnny Chend68e1192009-12-15 17:24:14 +00001172def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001173 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001174 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001175 "ldr", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001176 []>;
1177
Johnny Chend68e1192009-12-15 17:24:14 +00001178def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001179 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001180 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001181 "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001182 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001183def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001184 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001185 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001186 "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001187 []>;
1188
Johnny Chend68e1192009-12-15 17:24:14 +00001189def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001190 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001191 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001192 "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001193 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001194def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001195 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001196 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001197 "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001198 []>;
1199
Johnny Chend68e1192009-12-15 17:24:14 +00001200def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001201 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001202 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001203 "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001204 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001205def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001206 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001207 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001208 "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001209 []>;
1210
Johnny Chend68e1192009-12-15 17:24:14 +00001211def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001212 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001213 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001214 "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001215 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001216def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001217 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001218 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001219 "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001220 []>;
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001221} // mayLoad = 1, neverHasSideEffects = 1
Evan Cheng4fbb9962009-07-02 23:16:11 +00001222
Johnny Chene54a3ef2010-03-03 18:45:36 +00001223// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1224// for disassembly only.
1225// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001226class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1227 : T2Ii8<(outs GPR:$dst), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001228 "\t$dst, $addr", []> {
1229 let Inst{31-27} = 0b11111;
1230 let Inst{26-25} = 0b00;
1231 let Inst{24} = signed;
1232 let Inst{23} = 0;
1233 let Inst{22-21} = type;
1234 let Inst{20} = 1; // load
1235 let Inst{11} = 1;
1236 let Inst{10-8} = 0b110; // PUW.
1237}
1238
Evan Cheng0e55fd62010-09-30 01:08:25 +00001239def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1240def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1241def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1242def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1243def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001244
David Goodwin73b8f162009-06-30 22:11:34 +00001245// Store
Evan Cheng7e2fe912010-10-28 06:47:08 +00001246defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001247 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001248defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001249 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001250defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001251 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +00001252
David Goodwin6647cea2009-06-30 22:50:01 +00001253// Store doubleword
Chris Lattnera1ca91a2010-11-02 23:40:41 +00001254let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1255 isCodeGenOnly = 1 in // $src2 doesn't exist in asm string
Johnny Chend68e1192009-12-15 17:24:14 +00001256def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
Evan Chenge298ab22009-09-27 09:46:04 +00001257 (ins GPR:$src1, GPR:$src2, t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001258 IIC_iStore_d_r, "strd", "\t$src1, $addr", []>;
David Goodwin6647cea2009-06-30 22:50:01 +00001259
Evan Cheng6d94f112009-07-03 00:06:39 +00001260// Indexed stores
Johnny Chend68e1192009-12-15 17:24:14 +00001261def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001262 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001263 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001264 "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001265 [(set GPR:$base_wb,
1266 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1267
Johnny Chend68e1192009-12-15 17:24:14 +00001268def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001269 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001270 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001271 "str", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001272 [(set GPR:$base_wb,
Jim Grosbach6935efc2009-11-24 00:20:27 +00001273 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001274
Johnny Chend68e1192009-12-15 17:24:14 +00001275def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001276 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001277 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001278 "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001279 [(set GPR:$base_wb,
1280 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1281
Johnny Chend68e1192009-12-15 17:24:14 +00001282def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001283 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001284 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001285 "strh", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001286 [(set GPR:$base_wb,
1287 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1288
Johnny Chend68e1192009-12-15 17:24:14 +00001289def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001290 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001291 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001292 "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001293 [(set GPR:$base_wb,
1294 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1295
Johnny Chend68e1192009-12-15 17:24:14 +00001296def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001297 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001298 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001299 "strb", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001300 [(set GPR:$base_wb,
1301 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1302
Johnny Chene54a3ef2010-03-03 18:45:36 +00001303// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1304// only.
1305// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001306class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1307 : T2Ii8<(outs GPR:$src), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001308 "\t$src, $addr", []> {
1309 let Inst{31-27} = 0b11111;
1310 let Inst{26-25} = 0b00;
1311 let Inst{24} = 0; // not signed
1312 let Inst{23} = 0;
1313 let Inst{22-21} = type;
1314 let Inst{20} = 0; // store
1315 let Inst{11} = 1;
1316 let Inst{10-8} = 0b110; // PUW
1317}
1318
Evan Cheng0e55fd62010-09-30 01:08:25 +00001319def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1320def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1321def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
David Goodwind1fa1202009-07-01 00:01:13 +00001322
Johnny Chenae1757b2010-03-11 01:13:36 +00001323// ldrd / strd pre / post variants
1324// For disassembly only.
1325
1326def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001327 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001328 "ldrd", "\t$dst1, $dst2, [$base, $imm]!", []>;
1329
1330def t2LDRD_POST : T2Ii8s4<0, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001331 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001332 "ldrd", "\t$dst1, $dst2, [$base], $imm", []>;
1333
1334def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs),
1335 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001336 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base, $imm]!", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001337
1338def t2STRD_POST : T2Ii8s4<0, 1, 0, (outs),
1339 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001340 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base], $imm", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +00001341
Johnny Chen0635fc52010-03-04 17:40:44 +00001342// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1343// data/instruction access. These are for disassembly only.
Evan Chengdfed19f2010-11-03 06:34:55 +00001344// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1345// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
Evan Cheng416941d2010-11-04 05:19:35 +00001346multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001347
Evan Chengdfed19f2010-11-03 06:34:55 +00001348 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001349 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001350 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001351 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001352 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001353 let Inst{23} = 1; // U = 1
1354 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001355 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001356 let Inst{20} = 1;
1357 let Inst{15-12} = 0b1111;
1358 }
1359
Evan Chengdfed19f2010-11-03 06:34:55 +00001360 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001361 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001362 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001363 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001364 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001365 let Inst{23} = 0; // U = 0
1366 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001367 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001368 let Inst{20} = 1;
1369 let Inst{15-12} = 0b1111;
1370 let Inst{11-8} = 0b1100;
1371 }
1372
Evan Chengdfed19f2010-11-03 06:34:55 +00001373 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001374 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001375 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
Evan Chengbc7deb02010-11-03 05:14:24 +00001376 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001377 let Inst{24} = instr;
Evan Chengbc7deb02010-11-03 05:14:24 +00001378 let Inst{23} = 0; // add = TRUE for T1
1379 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001380 let Inst{21} = write;
Evan Chengbc7deb02010-11-03 05:14:24 +00001381 let Inst{20} = 1;
1382 let Inst{15-12} = 0b1111;
1383 let Inst{11-6} = 0000000;
1384 }
1385
1386 let isCodeGenOnly = 1 in
Evan Chengdfed19f2010-11-03 06:34:55 +00001387 def pci : T2Ipc<(outs), (ins i32imm:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001388 "\t$addr",
1389 []> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001390 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001391 let Inst{24} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001392 let Inst{23} = ?; // add = (U == 1)
1393 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001394 let Inst{21} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001395 let Inst{20} = 1;
1396 let Inst{19-16} = 0b1111; // Rn = 0b1111
1397 let Inst{15-12} = 0b1111;
1398 }
Johnny Chen0635fc52010-03-04 17:40:44 +00001399}
1400
Evan Cheng416941d2010-11-04 05:19:35 +00001401defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1402defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1403defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
Johnny Chen0635fc52010-03-04 17:40:44 +00001404
Evan Cheng2889cce2009-07-03 00:18:36 +00001405//===----------------------------------------------------------------------===//
1406// Load / store multiple Instructions.
1407//
1408
Bill Wendling6c470b82010-11-13 09:09:38 +00001409multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1410 InstrItinClass itin_upd, bit L_bit> {
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001411 def ia :
Bill Wendling6c470b82010-11-13 09:09:38 +00001412 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1413 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1414 bits<4> Rn;
1415 bits<16> regs;
1416
1417 let Inst{31-27} = 0b11101;
1418 let Inst{26-25} = 0b00;
1419 let Inst{24-23} = 0b01; // Increment After
1420 let Inst{22} = 0;
1421 let Inst{21} = 0; // No writeback
1422 let Inst{20} = L_bit;
1423 let Inst{19-16} = Rn;
1424 let Inst{15-0} = regs;
1425 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001426 def ia_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001427 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1428 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1429 bits<4> Rn;
1430 bits<16> regs;
1431
1432 let Inst{31-27} = 0b11101;
1433 let Inst{26-25} = 0b00;
1434 let Inst{24-23} = 0b01; // Increment After
1435 let Inst{22} = 0;
1436 let Inst{21} = 1; // Writeback
1437 let Inst{20} = L_bit;
1438 let Inst{19-16} = Rn;
1439 let Inst{15-0} = regs;
1440 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001441 def db :
Bill Wendling6c470b82010-11-13 09:09:38 +00001442 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1443 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1444 bits<4> Rn;
1445 bits<16> regs;
1446
1447 let Inst{31-27} = 0b11101;
1448 let Inst{26-25} = 0b00;
1449 let Inst{24-23} = 0b10; // Decrement Before
1450 let Inst{22} = 0;
1451 let Inst{21} = 0; // No writeback
1452 let Inst{20} = L_bit;
1453 let Inst{19-16} = Rn;
1454 let Inst{15-0} = regs;
1455 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001456 def db_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001457 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1458 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1459 bits<4> Rn;
1460 bits<16> regs;
1461
1462 let Inst{31-27} = 0b11101;
1463 let Inst{26-25} = 0b00;
1464 let Inst{24-23} = 0b10; // Decrement Before
1465 let Inst{22} = 0;
1466 let Inst{21} = 1; // Writeback
1467 let Inst{20} = L_bit;
1468 let Inst{19-16} = Rn;
1469 let Inst{15-0} = regs;
1470 }
1471}
1472
Bill Wendlingc93989a2010-11-13 11:20:05 +00001473/* TODO:
1474let neverHasSideEffects = 1 in {
Bill Wendlingddc918b2010-11-13 10:57:02 +00001475
1476let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1477defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1478
1479let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1480defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1481
1482} // neverHasSideEffects
Bill Wendlingc93989a2010-11-13 11:20:05 +00001483*/
Bill Wendlingddc918b2010-11-13 10:57:02 +00001484
Chris Lattner39ee0362010-10-31 19:10:56 +00001485let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
1486 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001487def t2LDM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001488 reglist:$dsts, variable_ops), IIC_iLoad_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001489 "ldm${amode}${p}.w\t$Rn, $dsts", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001490 let Inst{31-27} = 0b11101;
1491 let Inst{26-25} = 0b00;
1492 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1493 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001494 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001495 let Inst{20} = 1; // Load
1496}
Evan Cheng2889cce2009-07-03 00:18:36 +00001497
Jim Grosbache6913602010-11-03 01:01:43 +00001498def t2LDM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001499 reglist:$dsts, variable_ops),
1500 IIC_iLoad_mu,
Jim Grosbache6913602010-11-03 01:01:43 +00001501 "ldm${amode}${p}.w\t$Rn!, $dsts",
1502 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001503 let Inst{31-27} = 0b11101;
1504 let Inst{26-25} = 0b00;
1505 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1506 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001507 let Inst{21} = 1; // The W bit.
1508 let Inst{20} = 1; // Load
1509}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001510} // mayLoad, neverHasSideEffects, hasExtraDefRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001511
Chris Lattner39ee0362010-10-31 19:10:56 +00001512let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1513 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001514def t2STM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001515 reglist:$srcs, variable_ops), IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001516 "stm${amode}${p}.w\t$Rn, $srcs", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001517 let Inst{31-27} = 0b11101;
1518 let Inst{26-25} = 0b00;
1519 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1520 let Inst{22} = 0;
1521 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001522 let Inst{20} = 0; // Store
1523}
Evan Cheng2889cce2009-07-03 00:18:36 +00001524
Jim Grosbache6913602010-11-03 01:01:43 +00001525def t2STM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Bob Wilson815baeb2010-03-13 01:08:20 +00001526 reglist:$srcs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00001527 IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001528 "stm${amode}${p}.w\t$Rn!, $srcs",
1529 "$Rn = $wb", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001530 let Inst{31-27} = 0b11101;
1531 let Inst{26-25} = 0b00;
1532 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1533 let Inst{22} = 0;
1534 let Inst{21} = 1; // The W bit.
1535 let Inst{20} = 0; // Store
1536}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001537} // mayStore, neverHasSideEffects, hasExtraSrcRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001538
Evan Cheng9cb9e672009-06-27 02:26:13 +00001539//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001540// Move Instructions.
1541//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001542
Evan Chengf49810c2009-06-23 17:48:47 +00001543let neverHasSideEffects = 1 in
David Goodwin5d598aa2009-08-19 18:00:44 +00001544def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
Johnny Chend68e1192009-12-15 17:24:14 +00001545 "mov", ".w\t$dst, $src", []> {
1546 let Inst{31-27} = 0b11101;
1547 let Inst{26-25} = 0b01;
1548 let Inst{24-21} = 0b0010;
1549 let Inst{20} = ?; // The S bit.
1550 let Inst{19-16} = 0b1111; // Rn
1551 let Inst{14-12} = 0b000;
1552 let Inst{7-4} = 0b0000;
1553}
Evan Chengf49810c2009-06-23 17:48:47 +00001554
Evan Cheng5adb66a2009-09-28 09:14:39 +00001555// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1556let isReMaterializable = 1, isAsCheapAsAMove = 1, AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001557def t2MOVi : T2sI<(outs rGPR:$dst), (ins t2_so_imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001558 "mov", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001559 [(set rGPR:$dst, t2_so_imm:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001560 let Inst{31-27} = 0b11110;
1561 let Inst{25} = 0;
1562 let Inst{24-21} = 0b0010;
1563 let Inst{20} = ?; // The S bit.
1564 let Inst{19-16} = 0b1111; // Rn
1565 let Inst{15} = 0;
1566}
David Goodwin83b35932009-06-26 16:10:07 +00001567
1568let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001569def t2MOVi16 : T2I<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001570 "movw", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001571 [(set rGPR:$dst, imm0_65535:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001572 let Inst{31-27} = 0b11110;
1573 let Inst{25} = 1;
1574 let Inst{24-21} = 0b0010;
1575 let Inst{20} = 0; // The S bit.
1576 let Inst{15} = 0;
1577}
Evan Chengf49810c2009-06-23 17:48:47 +00001578
Evan Cheng3850a6a2009-06-23 05:23:49 +00001579let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001580def t2MOVTi16 : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$imm), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001581 "movt", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001582 [(set rGPR:$dst,
1583 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001584 let Inst{31-27} = 0b11110;
1585 let Inst{25} = 1;
1586 let Inst{24-21} = 0b0110;
1587 let Inst{20} = 0; // The S bit.
1588 let Inst{15} = 0;
1589}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001590
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001591def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
Evan Cheng20956592009-10-21 08:15:52 +00001592
Anton Korobeynikov52237112009-06-17 18:13:58 +00001593//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +00001594// Extend Instructions.
1595//
1596
1597// Sign extenders
1598
Evan Cheng0e55fd62010-09-30 01:08:25 +00001599defm t2SXTB : T2I_ext_rrot<0b100, "sxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001600 UnOpFrag<(sext_inreg node:$Src, i8)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001601defm t2SXTH : T2I_ext_rrot<0b000, "sxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001602 UnOpFrag<(sext_inreg node:$Src, i16)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001603defm t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001604
Evan Cheng0e55fd62010-09-30 01:08:25 +00001605defm t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001606 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001607defm t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001608 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001609defm t2SXTAB16 : T2I_exta_rrot_DO<0b010, "sxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001610
Johnny Chen93042d12010-03-02 18:14:57 +00001611// TODO: SXT(A){B|H}16 - done for disassembly only
Evan Chengd27c9fc2009-07-03 01:43:10 +00001612
1613// Zero extenders
1614
1615let AddedComplexity = 16 in {
Evan Cheng0e55fd62010-09-30 01:08:25 +00001616defm t2UXTB : T2I_ext_rrot<0b101, "uxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001617 UnOpFrag<(and node:$Src, 0x000000FF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001618defm t2UXTH : T2I_ext_rrot<0b001, "uxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001619 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001620defm t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
Johnny Chend68e1192009-12-15 17:24:14 +00001621 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001622
Jim Grosbach79464942010-07-28 23:17:45 +00001623// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1624// The transformation should probably be done as a combiner action
1625// instead so we can include a check for masking back in the upper
1626// eight bits of the source into the lower eight bits of the result.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001627//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001628// (t2UXTB16r_rot rGPR:$Src, 24)>,
1629// Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001630def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001631 (t2UXTB16r_rot rGPR:$Src, 8)>,
1632 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001633
Evan Cheng0e55fd62010-09-30 01:08:25 +00001634defm t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001635 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001636defm t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001637 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001638defm t2UXTAB16 : T2I_exta_rrot_DO<0b011, "uxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001639}
1640
1641//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001642// Arithmetic Instructions.
1643//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001644
Johnny Chend68e1192009-12-15 17:24:14 +00001645defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1646 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1647defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1648 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001649
Evan Chengf49810c2009-06-23 17:48:47 +00001650// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Johnny Chend68e1192009-12-15 17:24:14 +00001651defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001652 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001653 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1654defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001655 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001656 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001657
Johnny Chend68e1192009-12-15 17:24:14 +00001658defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001659 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001660defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001661 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001662defm t2ADCS : T2I_adde_sube_s_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001663 BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001664defm t2SBCS : T2I_adde_sube_s_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001665 BinOpFrag<(sube_live_carry node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001666
David Goodwin752aa7d2009-07-27 16:39:05 +00001667// RSB
Bob Wilson20d8e4e2010-08-13 23:24:25 +00001668defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
Johnny Chend68e1192009-12-15 17:24:14 +00001669 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1670defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1671 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001672
1673// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001674// The assume-no-carry-in form uses the negation of the input since add/sub
1675// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1676// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1677// details.
1678// The AddedComplexity preferences the first variant over the others since
1679// it can be shrunk to a 16-bit wide encoding, while the others cannot.
Evan Chengfa2ea1a2009-08-04 01:41:15 +00001680let AddedComplexity = 1 in
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001681def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1682 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1683def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1684 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1685def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1686 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1687let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001688def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1689 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1690def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1691 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001692// The with-carry-in form matches bitwise not instead of the negation.
1693// Effectively, the inverse interpretation of the carry flag already accounts
1694// for part of the negation.
1695let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001696def : T2Pat<(adde rGPR:$src, imm0_255_not:$imm),
1697 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
1698def : T2Pat<(adde rGPR:$src, t2_so_imm_not:$imm),
1699 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001700
Johnny Chen93042d12010-03-02 18:14:57 +00001701// Select Bytes -- for disassembly only
1702
1703def t2SEL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), NoItinerary, "sel",
1704 "\t$dst, $a, $b", []> {
1705 let Inst{31-27} = 0b11111;
1706 let Inst{26-24} = 0b010;
1707 let Inst{23} = 0b1;
1708 let Inst{22-20} = 0b010;
1709 let Inst{15-12} = 0b1111;
1710 let Inst{7} = 0b1;
1711 let Inst{6-4} = 0b000;
1712}
1713
Johnny Chenadc77332010-02-26 22:04:29 +00001714// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1715// And Miscellaneous operations -- for disassembly only
Nate Begeman692433b2010-07-29 17:56:55 +00001716class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1717 list<dag> pat = [/* For disassembly only; pattern left blank */]>
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001718 : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), NoItinerary, opc,
Nate Begeman692433b2010-07-29 17:56:55 +00001719 "\t$dst, $a, $b", pat> {
Johnny Chenadc77332010-02-26 22:04:29 +00001720 let Inst{31-27} = 0b11111;
1721 let Inst{26-23} = 0b0101;
1722 let Inst{22-20} = op22_20;
1723 let Inst{15-12} = 0b1111;
1724 let Inst{7-4} = op7_4;
1725}
1726
1727// Saturating add/subtract -- for disassembly only
1728
Nate Begeman692433b2010-07-29 17:56:55 +00001729def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001730 [(set rGPR:$dst, (int_arm_qadd rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001731def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1732def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1733def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
1734def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd">;
1735def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub">;
1736def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
Nate Begeman692433b2010-07-29 17:56:55 +00001737def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001738 [(set rGPR:$dst, (int_arm_qsub rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001739def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1740def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1741def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1742def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1743def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1744def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1745def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1746def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1747
1748// Signed/Unsigned add/subtract -- for disassembly only
1749
1750def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1751def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1752def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1753def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1754def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1755def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1756def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1757def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1758def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1759def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1760def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1761def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1762
1763// Signed/Unsigned halving add/subtract -- for disassembly only
1764
1765def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1766def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1767def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1768def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1769def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1770def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1771def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1772def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1773def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1774def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1775def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1776def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1777
1778// Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1779
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001780def t2USAD8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1781 (ins rGPR:$a, rGPR:$b),
Johnny Chenadc77332010-02-26 22:04:29 +00001782 NoItinerary, "usad8", "\t$dst, $a, $b", []> {
1783 let Inst{15-12} = 0b1111;
1784}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001785def t2USADA8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1786 (ins rGPR:$a, rGPR:$b, rGPR:$acc), NoItinerary, "usada8",
Johnny Chenadc77332010-02-26 22:04:29 +00001787 "\t$dst, $a, $b, $acc", []>;
1788
1789// Signed/Unsigned saturate -- for disassembly only
1790
Bob Wilson22f5dc72010-08-16 18:27:34 +00001791def t2SSAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001792 NoItinerary, "ssat", "\t$dst, $bit_pos, $a$sh",
1793 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001794 let Inst{31-27} = 0b11110;
1795 let Inst{25-22} = 0b1100;
1796 let Inst{20} = 0;
1797 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001798}
1799
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001800def t2SSAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001801 "ssat16", "\t$dst, $bit_pos, $a",
1802 [/* For disassembly only; pattern left blank */]> {
1803 let Inst{31-27} = 0b11110;
1804 let Inst{25-22} = 0b1100;
1805 let Inst{20} = 0;
1806 let Inst{15} = 0;
1807 let Inst{21} = 1; // sh = '1'
1808 let Inst{14-12} = 0b000; // imm3 = '000'
1809 let Inst{7-6} = 0b00; // imm2 = '00'
1810}
1811
Bob Wilson22f5dc72010-08-16 18:27:34 +00001812def t2USAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001813 NoItinerary, "usat", "\t$dst, $bit_pos, $a$sh",
1814 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001815 let Inst{31-27} = 0b11110;
1816 let Inst{25-22} = 0b1110;
1817 let Inst{20} = 0;
1818 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001819}
1820
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001821def t2USAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001822 "usat16", "\t$dst, $bit_pos, $a",
1823 [/* For disassembly only; pattern left blank */]> {
1824 let Inst{31-27} = 0b11110;
1825 let Inst{25-22} = 0b1110;
1826 let Inst{20} = 0;
1827 let Inst{15} = 0;
1828 let Inst{21} = 1; // sh = '1'
1829 let Inst{14-12} = 0b000; // imm3 = '000'
1830 let Inst{7-6} = 0b00; // imm2 = '00'
1831}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001832
Bob Wilson38aa2872010-08-13 21:48:10 +00001833def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
1834def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
Nate Begeman0e0a20e2010-07-29 22:48:09 +00001835
Evan Chengf49810c2009-06-23 17:48:47 +00001836//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +00001837// Shift and rotate Instructions.
1838//
1839
Johnny Chend68e1192009-12-15 17:24:14 +00001840defm t2LSL : T2I_sh_ir<0b00, "lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
1841defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
1842defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
1843defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
Evan Chenga67efd12009-06-23 19:39:13 +00001844
David Goodwinca01a8d2009-09-01 18:32:09 +00001845let Uses = [CPSR] in {
Jim Grosbach792e9792010-10-14 20:43:44 +00001846def t2RRX : T2sI<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +00001847 "rrx", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001848 [(set rGPR:$dst, (ARMrrx rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001849 let Inst{31-27} = 0b11101;
1850 let Inst{26-25} = 0b01;
1851 let Inst{24-21} = 0b0010;
1852 let Inst{20} = ?; // The S bit.
1853 let Inst{19-16} = 0b1111; // Rn
1854 let Inst{14-12} = 0b000;
1855 let Inst{7-4} = 0b0011;
1856}
David Goodwinca01a8d2009-09-01 18:32:09 +00001857}
Evan Chenga67efd12009-06-23 19:39:13 +00001858
David Goodwin3583df72009-07-28 17:06:49 +00001859let Defs = [CPSR] in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001860def t2MOVsrl_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001861 "lsrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001862 [(set rGPR:$dst, (ARMsrl_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001863 let Inst{31-27} = 0b11101;
1864 let Inst{26-25} = 0b01;
1865 let Inst{24-21} = 0b0010;
1866 let Inst{20} = 1; // The S bit.
1867 let Inst{19-16} = 0b1111; // Rn
1868 let Inst{5-4} = 0b01; // Shift type.
1869 // Shift amount = Inst{14-12:7-6} = 1.
1870 let Inst{14-12} = 0b000;
1871 let Inst{7-6} = 0b01;
1872}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001873def t2MOVsra_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001874 "asrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001875 [(set rGPR:$dst, (ARMsra_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001876 let Inst{31-27} = 0b11101;
1877 let Inst{26-25} = 0b01;
1878 let Inst{24-21} = 0b0010;
1879 let Inst{20} = 1; // The S bit.
1880 let Inst{19-16} = 0b1111; // Rn
1881 let Inst{5-4} = 0b10; // Shift type.
1882 // Shift amount = Inst{14-12:7-6} = 1.
1883 let Inst{14-12} = 0b000;
1884 let Inst{7-6} = 0b01;
1885}
David Goodwin3583df72009-07-28 17:06:49 +00001886}
1887
Evan Chenga67efd12009-06-23 19:39:13 +00001888//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00001889// Bitwise Instructions.
1890//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001891
Johnny Chend68e1192009-12-15 17:24:14 +00001892defm t2AND : T2I_bin_w_irs<0b0000, "and",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001893 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001894 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
1895defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001896 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001897 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
1898defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001899 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001900 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +00001901
Johnny Chend68e1192009-12-15 17:24:14 +00001902defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001903 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001904 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001905
Evan Chengf49810c2009-06-23 17:48:47 +00001906let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001907def t2BFC : T2I<(outs rGPR:$dst), (ins rGPR:$src, bf_inv_mask_imm:$imm),
David Goodwin2f54a2f2009-11-02 17:28:36 +00001908 IIC_iUNAsi, "bfc", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001909 [(set rGPR:$dst, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001910 let Inst{31-27} = 0b11110;
1911 let Inst{25} = 1;
1912 let Inst{24-20} = 0b10110;
1913 let Inst{19-16} = 0b1111; // Rn
1914 let Inst{15} = 0;
1915}
Evan Chengf49810c2009-06-23 17:48:47 +00001916
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001917def t2SBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001918 IIC_iUNAsi, "sbfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001919 let Inst{31-27} = 0b11110;
1920 let Inst{25} = 1;
1921 let Inst{24-20} = 0b10100;
1922 let Inst{15} = 0;
1923}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001924
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001925def t2UBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001926 IIC_iUNAsi, "ubfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001927 let Inst{31-27} = 0b11110;
1928 let Inst{25} = 1;
1929 let Inst{24-20} = 0b11100;
1930 let Inst{15} = 0;
1931}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001932
Johnny Chen9474d552010-02-02 19:31:58 +00001933// A8.6.18 BFI - Bitfield insert (Encoding T1)
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001934let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001935def t2BFI : T2I<(outs rGPR:$dst),
1936 (ins rGPR:$src, rGPR:$val, bf_inv_mask_imm:$imm),
Evan Cheng7e1bf302010-09-29 00:27:46 +00001937 IIC_iBITi, "bfi", "\t$dst, $val, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001938 [(set rGPR:$dst, (ARMbfi rGPR:$src, rGPR:$val,
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001939 bf_inv_mask_imm:$imm))]> {
Johnny Chen9474d552010-02-02 19:31:58 +00001940 let Inst{31-27} = 0b11110;
1941 let Inst{25} = 1;
1942 let Inst{24-20} = 0b10110;
1943 let Inst{15} = 0;
1944}
Evan Chengf49810c2009-06-23 17:48:47 +00001945
Evan Cheng7e1bf302010-09-29 00:27:46 +00001946defm t2ORN : T2I_bin_irs<0b0011, "orn",
1947 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
1948 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001949
1950// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
1951let AddedComplexity = 1 in
Evan Cheng5d42c562010-09-29 00:49:25 +00001952defm t2MVN : T2I_un_irs <0b0011, "mvn",
Evan Cheng3881cb72010-09-29 22:42:35 +00001953 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
Evan Cheng5d42c562010-09-29 00:49:25 +00001954 UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001955
1956
Jim Grosbachf084a5e2010-07-20 16:07:04 +00001957let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001958def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
1959 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001960
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001961// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001962def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
1963 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
Evan Chengea253b92009-08-12 01:56:42 +00001964 Requires<[IsThumb2]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001965
1966def : T2Pat<(t2_so_imm_not:$src),
1967 (t2MVNi t2_so_imm_not:$src)>;
1968
Evan Chengf49810c2009-06-23 17:48:47 +00001969//===----------------------------------------------------------------------===//
1970// Multiply Instructions.
1971//
Evan Cheng8de898a2009-06-26 00:19:44 +00001972let isCommutable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001973def t2MUL: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00001974 "mul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001975 [(set rGPR:$dst, (mul rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001976 let Inst{31-27} = 0b11111;
1977 let Inst{26-23} = 0b0110;
1978 let Inst{22-20} = 0b000;
1979 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1980 let Inst{7-4} = 0b0000; // Multiply
1981}
Evan Chengf49810c2009-06-23 17:48:47 +00001982
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001983def t2MLA: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001984 "mla", "\t$dst, $a, $b, $c",
1985 [(set rGPR:$dst, (add (mul rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001986 let Inst{31-27} = 0b11111;
1987 let Inst{26-23} = 0b0110;
1988 let Inst{22-20} = 0b000;
1989 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1990 let Inst{7-4} = 0b0000; // Multiply
1991}
Evan Chengf49810c2009-06-23 17:48:47 +00001992
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001993def t2MLS: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001994 "mls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001995 [(set rGPR:$dst, (sub rGPR:$c, (mul rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001996 let Inst{31-27} = 0b11111;
1997 let Inst{26-23} = 0b0110;
1998 let Inst{22-20} = 0b000;
1999 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2000 let Inst{7-4} = 0b0001; // Multiply and Subtract
2001}
Evan Chengf49810c2009-06-23 17:48:47 +00002002
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002003// Extra precision multiplies with low / high results
2004let neverHasSideEffects = 1 in {
2005let isCommutable = 1 in {
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002006def t2SMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
2007 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00002008 "smull", "\t$ldst, $hdst, $a, $b", []> {
2009 let Inst{31-27} = 0b11111;
2010 let Inst{26-23} = 0b0111;
2011 let Inst{22-20} = 0b000;
2012 let Inst{7-4} = 0b0000;
2013}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002014
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002015def t2UMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
2016 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00002017 "umull", "\t$ldst, $hdst, $a, $b", []> {
2018 let Inst{31-27} = 0b11111;
2019 let Inst{26-23} = 0b0111;
2020 let Inst{22-20} = 0b010;
2021 let Inst{7-4} = 0b0000;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002022}
Johnny Chend68e1192009-12-15 17:24:14 +00002023} // isCommutable
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002024
2025// Multiply + accumulate
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002026def t2SMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
2027 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00002028 "smlal", "\t$ldst, $hdst, $a, $b", []>{
2029 let Inst{31-27} = 0b11111;
2030 let Inst{26-23} = 0b0111;
2031 let Inst{22-20} = 0b100;
2032 let Inst{7-4} = 0b0000;
2033}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002034
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002035def t2UMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
2036 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00002037 "umlal", "\t$ldst, $hdst, $a, $b", []>{
2038 let Inst{31-27} = 0b11111;
2039 let Inst{26-23} = 0b0111;
2040 let Inst{22-20} = 0b110;
2041 let Inst{7-4} = 0b0000;
2042}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002043
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002044def t2UMAAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
2045 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00002046 "umaal", "\t$ldst, $hdst, $a, $b", []>{
2047 let Inst{31-27} = 0b11111;
2048 let Inst{26-23} = 0b0111;
2049 let Inst{22-20} = 0b110;
2050 let Inst{7-4} = 0b0110;
2051}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002052} // neverHasSideEffects
2053
Johnny Chen93042d12010-03-02 18:14:57 +00002054// Rounding variants of the below included for disassembly only
2055
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002056// Most significant word multiply
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002057def t2SMMUL : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00002058 "smmul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002059 [(set rGPR:$dst, (mulhs rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002060 let Inst{31-27} = 0b11111;
2061 let Inst{26-23} = 0b0110;
2062 let Inst{22-20} = 0b101;
2063 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2064 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2065}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002066
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002067def t2SMMULR : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Johnny Chen93042d12010-03-02 18:14:57 +00002068 "smmulr", "\t$dst, $a, $b", []> {
2069 let Inst{31-27} = 0b11111;
2070 let Inst{26-23} = 0b0110;
2071 let Inst{22-20} = 0b101;
2072 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2073 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2074}
2075
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002076def t2SMMLA : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00002077 "smmla", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002078 [(set rGPR:$dst, (add (mulhs rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002079 let Inst{31-27} = 0b11111;
2080 let Inst{26-23} = 0b0110;
2081 let Inst{22-20} = 0b101;
2082 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2083 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2084}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002085
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002086def t2SMMLAR: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00002087 "smmlar", "\t$dst, $a, $b, $c", []> {
2088 let Inst{31-27} = 0b11111;
2089 let Inst{26-23} = 0b0110;
2090 let Inst{22-20} = 0b101;
2091 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2092 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2093}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002094
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002095def t2SMMLS: T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00002096 "smmls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002097 [(set rGPR:$dst, (sub rGPR:$c, (mulhs rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002098 let Inst{31-27} = 0b11111;
2099 let Inst{26-23} = 0b0110;
2100 let Inst{22-20} = 0b110;
2101 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2102 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2103}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002104
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002105def t2SMMLSR:T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00002106 "smmlsr", "\t$dst, $a, $b, $c", []> {
2107 let Inst{31-27} = 0b11111;
2108 let Inst{26-23} = 0b0110;
2109 let Inst{22-20} = 0b110;
2110 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2111 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2112}
2113
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002114multiclass T2I_smul<string opc, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +00002115 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002116 !strconcat(opc, "bb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002117 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
2118 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002119 let Inst{31-27} = 0b11111;
2120 let Inst{26-23} = 0b0110;
2121 let Inst{22-20} = 0b001;
2122 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2123 let Inst{7-6} = 0b00;
2124 let Inst{5-4} = 0b00;
2125 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002126
Evan Cheng0e55fd62010-09-30 01:08:25 +00002127 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002128 !strconcat(opc, "bt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002129 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
2130 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002131 let Inst{31-27} = 0b11111;
2132 let Inst{26-23} = 0b0110;
2133 let Inst{22-20} = 0b001;
2134 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2135 let Inst{7-6} = 0b00;
2136 let Inst{5-4} = 0b01;
2137 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002138
Evan Cheng0e55fd62010-09-30 01:08:25 +00002139 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002140 !strconcat(opc, "tb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002141 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2142 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002143 let Inst{31-27} = 0b11111;
2144 let Inst{26-23} = 0b0110;
2145 let Inst{22-20} = 0b001;
2146 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2147 let Inst{7-6} = 0b00;
2148 let Inst{5-4} = 0b10;
2149 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002150
Evan Cheng0e55fd62010-09-30 01:08:25 +00002151 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002152 !strconcat(opc, "tt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002153 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2154 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002155 let Inst{31-27} = 0b11111;
2156 let Inst{26-23} = 0b0110;
2157 let Inst{22-20} = 0b001;
2158 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2159 let Inst{7-6} = 0b00;
2160 let Inst{5-4} = 0b11;
2161 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002162
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002163 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002164 !strconcat(opc, "wb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002165 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2166 (sext_inreg rGPR:$b, i16)), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002167 let Inst{31-27} = 0b11111;
2168 let Inst{26-23} = 0b0110;
2169 let Inst{22-20} = 0b011;
2170 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2171 let Inst{7-6} = 0b00;
2172 let Inst{5-4} = 0b00;
2173 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002174
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002175 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002176 !strconcat(opc, "wt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002177 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2178 (sra rGPR:$b, (i32 16))), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002179 let Inst{31-27} = 0b11111;
2180 let Inst{26-23} = 0b0110;
2181 let Inst{22-20} = 0b011;
2182 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2183 let Inst{7-6} = 0b00;
2184 let Inst{5-4} = 0b01;
2185 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002186}
2187
2188
2189multiclass T2I_smla<string opc, PatFrag opnode> {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002190 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002191 !strconcat(opc, "bb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002192 [(set rGPR:$dst, (add rGPR:$acc,
2193 (opnode (sext_inreg rGPR:$a, i16),
2194 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002195 let Inst{31-27} = 0b11111;
2196 let Inst{26-23} = 0b0110;
2197 let Inst{22-20} = 0b001;
2198 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2199 let Inst{7-6} = 0b00;
2200 let Inst{5-4} = 0b00;
2201 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002202
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002203 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002204 !strconcat(opc, "bt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002205 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sext_inreg rGPR:$a, i16),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002206 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002207 let Inst{31-27} = 0b11111;
2208 let Inst{26-23} = 0b0110;
2209 let Inst{22-20} = 0b001;
2210 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2211 let Inst{7-6} = 0b00;
2212 let Inst{5-4} = 0b01;
2213 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002214
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002215 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002216 !strconcat(opc, "tb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002217 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002218 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002219 let Inst{31-27} = 0b11111;
2220 let Inst{26-23} = 0b0110;
2221 let Inst{22-20} = 0b001;
2222 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2223 let Inst{7-6} = 0b00;
2224 let Inst{5-4} = 0b10;
2225 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002226
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002227 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002228 !strconcat(opc, "tt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002229 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002230 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002231 let Inst{31-27} = 0b11111;
2232 let Inst{26-23} = 0b0110;
2233 let Inst{22-20} = 0b001;
2234 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2235 let Inst{7-6} = 0b00;
2236 let Inst{5-4} = 0b11;
2237 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002238
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002239 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002240 !strconcat(opc, "wb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002241 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002242 (sext_inreg rGPR:$b, i16)), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002243 let Inst{31-27} = 0b11111;
2244 let Inst{26-23} = 0b0110;
2245 let Inst{22-20} = 0b011;
2246 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2247 let Inst{7-6} = 0b00;
2248 let Inst{5-4} = 0b00;
2249 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002250
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002251 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002252 !strconcat(opc, "wt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002253 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002254 (sra rGPR:$b, (i32 16))), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002255 let Inst{31-27} = 0b11111;
2256 let Inst{26-23} = 0b0110;
2257 let Inst{22-20} = 0b011;
2258 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2259 let Inst{7-6} = 0b00;
2260 let Inst{5-4} = 0b01;
2261 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002262}
2263
2264defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2265defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2266
Johnny Chenadc77332010-02-26 22:04:29 +00002267// Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002268def t2SMLALBB : T2I_mac<1, 0b100, 0b1000, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002269 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002270 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002271def t2SMLALBT : T2I_mac<1, 0b100, 0b1001, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002272 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002273 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002274def t2SMLALTB : T2I_mac<1, 0b100, 0b1010, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002275 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002276 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002277def t2SMLALTT : T2I_mac<1, 0b100, 0b1011, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002278 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002279 [/* For disassembly only; pattern left blank */]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002280
Johnny Chenadc77332010-02-26 22:04:29 +00002281// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2282// These are for disassembly only.
2283
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002284def t2SMUAD: T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2285 IIC_iMAC32, "smuad", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002286 let Inst{15-12} = 0b1111;
2287}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002288def t2SMUADX:T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2289 IIC_iMAC32, "smuadx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002290 let Inst{15-12} = 0b1111;
2291}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002292def t2SMUSD: T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2293 IIC_iMAC32, "smusd", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002294 let Inst{15-12} = 0b1111;
2295}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002296def t2SMUSDX:T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2297 IIC_iMAC32, "smusdx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002298 let Inst{15-12} = 0b1111;
2299}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002300def t2SMLAD : T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst),
2301 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlad",
Johnny Chenadc77332010-02-26 22:04:29 +00002302 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002303def t2SMLADX : T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst),
2304 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smladx",
Johnny Chenadc77332010-02-26 22:04:29 +00002305 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002306def t2SMLSD : T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst),
2307 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsd",
Johnny Chenadc77332010-02-26 22:04:29 +00002308 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002309def t2SMLSDX : T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst),
2310 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsdx",
Johnny Chenadc77332010-02-26 22:04:29 +00002311 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002312def t2SMLALD : T2I_mac<1, 0b100, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2313 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlald",
Johnny Chenadc77332010-02-26 22:04:29 +00002314 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002315def t2SMLALDX : T2I_mac<1, 0b100, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2316 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002317 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002318def t2SMLSLD : T2I_mac<1, 0b101, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2319 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsld",
Johnny Chenadc77332010-02-26 22:04:29 +00002320 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002321def t2SMLSLDX : T2I_mac<1, 0b101, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2322 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002323 "\t$ldst, $hdst, $a, $b", []>;
Evan Chengf49810c2009-06-23 17:48:47 +00002324
2325//===----------------------------------------------------------------------===//
2326// Misc. Arithmetic Instructions.
2327//
2328
Jim Grosbach80dc1162010-02-16 21:23:02 +00002329class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2330 InstrItinClass itin, string opc, string asm, list<dag> pattern>
Johnny Chend68e1192009-12-15 17:24:14 +00002331 : T2I<oops, iops, itin, opc, asm, pattern> {
2332 let Inst{31-27} = 0b11111;
2333 let Inst{26-22} = 0b01010;
2334 let Inst{21-20} = op1;
2335 let Inst{15-12} = 0b1111;
2336 let Inst{7-6} = 0b10;
2337 let Inst{5-4} = op2;
2338}
Evan Chengf49810c2009-06-23 17:48:47 +00002339
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002340def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
2341 "clz", "\t$dst, $src", [(set rGPR:$dst, (ctlz rGPR:$src))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002342
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002343def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Evan Chengf609bb82010-01-19 00:44:15 +00002344 "rbit", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002345 [(set rGPR:$dst, (ARMrbit rGPR:$src))]>;
Jim Grosbach3482c802010-01-18 19:58:49 +00002346
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002347def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002348 "rev", ".w\t$dst, $src", [(set rGPR:$dst, (bswap rGPR:$src))]>;
Johnny Chend68e1192009-12-15 17:24:14 +00002349
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002350def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002351 "rev16", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002352 [(set rGPR:$dst,
2353 (or (and (srl rGPR:$src, (i32 8)), 0xFF),
2354 (or (and (shl rGPR:$src, (i32 8)), 0xFF00),
2355 (or (and (srl rGPR:$src, (i32 8)), 0xFF0000),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002356 (and (shl rGPR:$src, (i32 8)), 0xFF000000)))))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002357
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002358def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002359 "revsh", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002360 [(set rGPR:$dst,
Evan Chengf49810c2009-06-23 17:48:47 +00002361 (sext_inreg
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002362 (or (srl (and rGPR:$src, 0xFF00), (i32 8)),
2363 (shl rGPR:$src, (i32 8))), i16))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002364
Bob Wilsonf955f292010-08-17 17:23:19 +00002365def t2PKHBT : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002366 IIC_iBITsi, "pkhbt", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002367 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF),
Bob Wilsonf955f292010-08-17 17:23:19 +00002368 (and (shl rGPR:$src2, lsl_amt:$sh),
Jim Grosbachb1dc3932010-05-05 20:44:35 +00002369 0xFFFF0000)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002370 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002371 let Inst{31-27} = 0b11101;
2372 let Inst{26-25} = 0b01;
2373 let Inst{24-20} = 0b01100;
2374 let Inst{5} = 0; // BT form
2375 let Inst{4} = 0;
2376}
Evan Cheng40289b02009-07-07 05:35:52 +00002377
2378// Alternate cases for PKHBT where identities eliminate some nodes.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002379def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2380 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002381 Requires<[HasT2ExtractPack, IsThumb2]>;
Bob Wilsonf955f292010-08-17 17:23:19 +00002382def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2383 (t2PKHBT rGPR:$src1, rGPR:$src2, (lsl_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002384 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Cheng40289b02009-07-07 05:35:52 +00002385
Bob Wilsondc66eda2010-08-16 22:26:55 +00002386// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2387// will match the pattern below.
Bob Wilsonf955f292010-08-17 17:23:19 +00002388def t2PKHTB : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002389 IIC_iBITsi, "pkhtb", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002390 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002391 (and (sra rGPR:$src2, asr_amt:$sh),
2392 0xFFFF)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002393 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002394 let Inst{31-27} = 0b11101;
2395 let Inst{26-25} = 0b01;
2396 let Inst{24-20} = 0b01100;
2397 let Inst{5} = 1; // TB form
2398 let Inst{4} = 0;
2399}
Evan Cheng40289b02009-07-07 05:35:52 +00002400
2401// Alternate cases for PKHTB where identities eliminate some nodes. Note that
2402// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilsondc66eda2010-08-16 22:26:55 +00002403def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
Bob Wilsonf955f292010-08-17 17:23:19 +00002404 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002405 Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002406def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002407 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2408 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm1_15:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002409 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002410
2411//===----------------------------------------------------------------------===//
2412// Comparison Instructions...
2413//
Johnny Chend68e1192009-12-15 17:24:14 +00002414defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002415 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002416 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2417defm t2CMPz : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002418 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002419 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002420
Dan Gohman4b7dff92010-08-26 15:50:25 +00002421//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2422// Compare-to-zero still works out, just not the relationals
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002423//defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2424// BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002425defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
Evan Cheng5d42c562010-09-29 00:49:25 +00002426 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Dan Gohman4b7dff92010-08-26 15:50:25 +00002427 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2428
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002429//def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2430// (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002431
2432def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2433 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002434
Johnny Chend68e1192009-12-15 17:24:14 +00002435defm t2TST : T2I_cmp_irs<0b0000, "tst",
Evan Cheng5d42c562010-09-29 00:49:25 +00002436 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002437 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
2438defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
Evan Cheng5d42c562010-09-29 00:49:25 +00002439 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002440 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002441
Evan Chenge253c952009-07-07 20:39:03 +00002442// Conditional moves
2443// FIXME: should be able to write a pattern for ARMcmov, but can't use
Jim Grosbach64171712010-02-16 21:07:46 +00002444// a two-value operand where a dag node expects two operands. :(
Evan Cheng63f35442010-11-13 02:25:14 +00002445let neverHasSideEffects = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002446def t2MOVCCr : T2I<(outs rGPR:$dst), (ins rGPR:$false, rGPR:$true), IIC_iCMOVr,
Evan Cheng699beba2009-10-27 00:08:59 +00002447 "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002448 [/*(set rGPR:$dst, (ARMcmov rGPR:$false, rGPR:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002449 RegConstraint<"$false = $dst"> {
2450 let Inst{31-27} = 0b11101;
2451 let Inst{26-25} = 0b01;
2452 let Inst{24-21} = 0b0010;
2453 let Inst{20} = 0; // The S bit.
2454 let Inst{19-16} = 0b1111; // Rn
2455 let Inst{14-12} = 0b000;
2456 let Inst{7-4} = 0b0000;
2457}
Evan Chenge253c952009-07-07 20:39:03 +00002458
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002459def t2MOVCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
Evan Cheng699beba2009-10-27 00:08:59 +00002460 IIC_iCMOVi, "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002461[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002462 RegConstraint<"$false = $dst"> {
2463 let Inst{31-27} = 0b11110;
2464 let Inst{25} = 0;
2465 let Inst{24-21} = 0b0010;
2466 let Inst{20} = 0; // The S bit.
2467 let Inst{19-16} = 0b1111; // Rn
2468 let Inst{15} = 0;
2469}
Evan Chengf49810c2009-06-23 17:48:47 +00002470
Jim Grosbacha4257162010-10-07 00:53:56 +00002471def t2MOVCCi16 : T2I<(outs rGPR:$dst), (ins rGPR:$false, i32imm:$src),
Evan Cheng875a6ac2010-11-12 22:42:47 +00002472 IIC_iCMOVi,
Jim Grosbacha4257162010-10-07 00:53:56 +00002473 "movw", "\t$dst, $src", []>,
2474 RegConstraint<"$false = $dst"> {
2475 let Inst{31-27} = 0b11110;
2476 let Inst{25} = 1;
2477 let Inst{24-21} = 0b0010;
2478 let Inst{20} = 0; // The S bit.
2479 let Inst{15} = 0;
2480}
2481
Evan Cheng63f35442010-11-13 02:25:14 +00002482def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2483 (ins rGPR:$false, i32imm:$src, pred:$p),
Evan Chengc47f7d62010-11-13 05:14:20 +00002484 IIC_iCMOVix2, "", []>, RegConstraint<"$false = $dst">;
Evan Cheng63f35442010-11-13 02:25:14 +00002485
Evan Cheng875a6ac2010-11-12 22:42:47 +00002486def t2MVNCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
2487 IIC_iCMOVi, "mvn", ".w\t$dst, $true",
2488[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm_not:$true,
2489 imm:$cc, CCR:$ccr))*/]>,
2490 RegConstraint<"$false = $dst"> {
2491 let Inst{31-27} = 0b11110;
2492 let Inst{25} = 0;
2493 let Inst{24-21} = 0b0011;
2494 let Inst{20} = 0; // The S bit.
2495 let Inst{19-16} = 0b1111; // Rn
2496 let Inst{15} = 0;
2497}
2498
Johnny Chend68e1192009-12-15 17:24:14 +00002499class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2500 string opc, string asm, list<dag> pattern>
2501 : T2I<oops, iops, itin, opc, asm, pattern> {
2502 let Inst{31-27} = 0b11101;
2503 let Inst{26-25} = 0b01;
2504 let Inst{24-21} = 0b0010;
2505 let Inst{20} = 0; // The S bit.
2506 let Inst{19-16} = 0b1111; // Rn
2507 let Inst{5-4} = opcod; // Shift type.
2508}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002509def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$dst),
2510 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002511 IIC_iCMOVsi, "lsl", ".w\t$dst, $true, $rhs", []>,
2512 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002513def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$dst),
2514 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002515 IIC_iCMOVsi, "lsr", ".w\t$dst, $true, $rhs", []>,
2516 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002517def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$dst),
2518 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002519 IIC_iCMOVsi, "asr", ".w\t$dst, $true, $rhs", []>,
2520 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002521def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$dst),
2522 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002523 IIC_iCMOVsi, "ror", ".w\t$dst, $true, $rhs", []>,
2524 RegConstraint<"$false = $dst">;
Owen Andersonf523e472010-09-23 23:45:25 +00002525} // neverHasSideEffects
Evan Cheng13f8b362009-08-01 01:43:45 +00002526
David Goodwin5e47a9a2009-06-30 18:04:13 +00002527//===----------------------------------------------------------------------===//
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002528// Atomic operations intrinsics
2529//
2530
2531// memory barriers protect the atomic sequences
2532let hasSideEffects = 1 in {
Bob Wilsonf74a4292010-10-30 00:54:37 +00002533def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2534 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2535 Requires<[IsThumb, HasDB]> {
2536 bits<4> opt;
2537 let Inst{31-4} = 0xf3bf8f5;
2538 let Inst{3-0} = opt;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002539}
2540}
2541
Bob Wilsonf74a4292010-10-30 00:54:37 +00002542def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2543 "dsb", "\t$opt",
2544 [/* For disassembly only; pattern left blank */]>,
2545 Requires<[IsThumb, HasDB]> {
2546 bits<4> opt;
2547 let Inst{31-4} = 0xf3bf8f4;
2548 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00002549}
2550
Johnny Chena4339822010-03-03 00:16:28 +00002551// ISB has only full system option -- for disassembly only
Bob Wilsonf74a4292010-10-30 00:54:37 +00002552def t2ISB : T2I<(outs), (ins), NoItinerary, "isb", "",
2553 [/* For disassembly only; pattern left blank */]>,
2554 Requires<[IsThumb2, HasV7]> {
2555 let Inst{31-4} = 0xf3bf8f6;
Johnny Chena4339822010-03-03 00:16:28 +00002556 let Inst{3-0} = 0b1111;
2557}
2558
Johnny Chend68e1192009-12-15 17:24:14 +00002559class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2560 InstrItinClass itin, string opc, string asm, string cstr,
2561 list<dag> pattern, bits<4> rt2 = 0b1111>
2562 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2563 let Inst{31-27} = 0b11101;
2564 let Inst{26-20} = 0b0001101;
2565 let Inst{11-8} = rt2;
2566 let Inst{7-6} = 0b01;
2567 let Inst{5-4} = opcod;
2568 let Inst{3-0} = 0b1111;
2569}
2570class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2571 InstrItinClass itin, string opc, string asm, string cstr,
2572 list<dag> pattern, bits<4> rt2 = 0b1111>
2573 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2574 let Inst{31-27} = 0b11101;
2575 let Inst{26-20} = 0b0001100;
2576 let Inst{11-8} = rt2;
2577 let Inst{7-6} = 0b01;
2578 let Inst{5-4} = opcod;
2579}
2580
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002581let mayLoad = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002582def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002583 Size4Bytes, NoItinerary, "ldrexb", "\t$dest, [$ptr]",
2584 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002585def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002586 Size4Bytes, NoItinerary, "ldrexh", "\t$dest, [$ptr]",
2587 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002588def t2LDREX : Thumb2I<(outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002589 Size4Bytes, NoItinerary,
2590 "ldrex", "\t$dest, [$ptr]", "",
2591 []> {
2592 let Inst{31-27} = 0b11101;
2593 let Inst{26-20} = 0b0000101;
2594 let Inst{11-8} = 0b1111;
2595 let Inst{7-0} = 0b00000000; // imm8 = 0
2596}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002597def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$dest, rGPR:$dest2), (ins rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002598 AddrModeNone, Size4Bytes, NoItinerary,
2599 "ldrexd", "\t$dest, $dest2, [$ptr]", "",
2600 [], {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002601}
2602
Jim Grosbach587b0722009-12-16 19:44:06 +00002603let mayStore = 1, Constraints = "@earlyclobber $success" in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002604def t2STREXB : T2I_strex<0b00, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002605 AddrModeNone, Size4Bytes, NoItinerary,
2606 "strexb", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002607def t2STREXH : T2I_strex<0b01, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002608 AddrModeNone, Size4Bytes, NoItinerary,
2609 "strexh", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002610def t2STREX : Thumb2I<(outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002611 AddrModeNone, Size4Bytes, NoItinerary,
2612 "strex", "\t$success, $src, [$ptr]", "",
2613 []> {
2614 let Inst{31-27} = 0b11101;
2615 let Inst{26-20} = 0b0000100;
2616 let Inst{7-0} = 0b00000000; // imm8 = 0
2617}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002618def t2STREXD : T2I_strex<0b11, (outs rGPR:$success),
2619 (ins rGPR:$src, rGPR:$src2, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002620 AddrModeNone, Size4Bytes, NoItinerary,
2621 "strexd", "\t$success, $src, $src2, [$ptr]", "", [],
2622 {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002623}
2624
Johnny Chen10a77e12010-03-02 22:11:06 +00002625// Clear-Exclusive is for disassembly only.
2626def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "",
2627 [/* For disassembly only; pattern left blank */]>,
2628 Requires<[IsARM, HasV7]> {
2629 let Inst{31-20} = 0xf3b;
2630 let Inst{15-14} = 0b10;
2631 let Inst{12} = 0;
2632 let Inst{7-4} = 0b0010;
2633}
2634
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002635//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00002636// TLS Instructions
2637//
2638
2639// __aeabi_read_tp preserves the registers r1-r3.
2640let isCall = 1,
2641 Defs = [R0, R12, LR, CPSR] in {
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002642 def t2TPsoft : T2XI<(outs), (ins), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002643 "bl\t__aeabi_read_tp",
Johnny Chend68e1192009-12-15 17:24:14 +00002644 [(set R0, ARMthread_pointer)]> {
2645 let Inst{31-27} = 0b11110;
2646 let Inst{15-14} = 0b11;
2647 let Inst{12} = 1;
2648 }
David Goodwin334c2642009-07-08 16:09:28 +00002649}
2650
2651//===----------------------------------------------------------------------===//
Jim Grosbach5aa16842009-08-11 19:42:21 +00002652// SJLJ Exception handling intrinsics
Jim Grosbach1add6592009-08-13 15:11:43 +00002653// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach5aa16842009-08-11 19:42:21 +00002654// address and save #0 in R0 for the non-longjmp case.
2655// Since by its nature we may be coming from some other function to get
2656// here, and we're using the stack frame for the containing function to
2657// save/restore registers, we can't keep anything live in regs across
2658// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
2659// when we get here from a longjmp(). We force everthing out of registers
2660// except for our own input by listing the relevant registers in Defs. By
2661// doing so, we also cause the prologue/epilogue code to actively preserve
2662// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbach0798edd2010-05-27 23:49:24 +00002663// $val is a scratch register for our use.
Jim Grosbacha87ded22010-02-08 23:22:00 +00002664let Defs =
Jim Grosbachf35d2162009-08-13 16:59:44 +00002665 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
2666 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Jim Grosbach5aa16842009-08-11 19:42:21 +00002667 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002668 D31 ], hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002669 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002670 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002671 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002672 Requires<[IsThumb2, HasVFP2]>;
Jim Grosbach5aa16842009-08-11 19:42:21 +00002673}
2674
Bob Wilsonec80e262010-04-09 20:41:18 +00002675let Defs =
Jim Grosbach5caeff52010-05-28 17:37:40 +00002676 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR ],
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002677 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002678 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002679 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002680 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002681 Requires<[IsThumb2, NoVFP]>;
2682}
Jim Grosbach5aa16842009-08-11 19:42:21 +00002683
2684
2685//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00002686// Control-Flow Instructions
2687//
2688
Evan Chengc50a1cb2009-07-09 22:58:39 +00002689// FIXME: remove when we have a way to marking a MI with these properties.
2690// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
2691// operand list.
2692// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng0d92f5f2009-10-01 08:22:27 +00002693let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
Chris Lattner39ee0362010-10-31 19:10:56 +00002694 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
Jim Grosbache6913602010-11-03 01:01:43 +00002695 def t2LDM_RET: T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
2696 reglist:$dsts, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00002697 IIC_iLoad_mBr,
Jim Grosbache6913602010-11-03 01:01:43 +00002698 "ldm${amode}${p}.w\t$Rn!, $dsts",
2699 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002700 let Inst{31-27} = 0b11101;
2701 let Inst{26-25} = 0b00;
2702 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
2703 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00002704 let Inst{21} = 1; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00002705 let Inst{20} = 1; // Load
2706}
Evan Chengc50a1cb2009-07-09 22:58:39 +00002707
David Goodwin5e47a9a2009-06-30 18:04:13 +00002708let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
2709let isPredicable = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002710def t2B : T2XI<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002711 "b.w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002712 [(br bb:$target)]> {
2713 let Inst{31-27} = 0b11110;
2714 let Inst{15-14} = 0b10;
2715 let Inst{12} = 1;
2716}
David Goodwin5e47a9a2009-06-30 18:04:13 +00002717
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002718let isNotDuplicable = 1, isIndirectBranch = 1,
2719 isCodeGenOnly = 1 in { // $id doesn't exist in asmstring, should be lowered.
Evan Cheng66ac5312009-07-25 00:33:29 +00002720def t2BR_JT :
Evan Cheng5657c012009-07-29 02:18:14 +00002721 T2JTI<(outs),
2722 (ins GPR:$target, GPR:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002723 IIC_Br, "mov\tpc, $target$jt",
Johnny Chend68e1192009-12-15 17:24:14 +00002724 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]> {
2725 let Inst{31-27} = 0b11101;
2726 let Inst{26-20} = 0b0100100;
2727 let Inst{19-16} = 0b1111;
2728 let Inst{14-12} = 0b000;
2729 let Inst{11-8} = 0b1111; // Rd = pc
2730 let Inst{7-4} = 0b0000;
2731}
Evan Cheng5657c012009-07-29 02:18:14 +00002732
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002733// FIXME: Add a non-pc based case that can be predicated.
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002734let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002735def t2TBB :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002736 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002737 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002738 IIC_Br, "tbb\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002739 let Inst{31-27} = 0b11101;
2740 let Inst{26-20} = 0b0001101;
2741 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2742 let Inst{15-8} = 0b11110000;
2743 let Inst{7-4} = 0b0000; // B form
2744}
Evan Cheng5657c012009-07-29 02:18:14 +00002745
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002746let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002747def t2TBH :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002748 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002749 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002750 IIC_Br, "tbh\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002751 let Inst{31-27} = 0b11101;
2752 let Inst{26-20} = 0b0001101;
2753 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2754 let Inst{15-8} = 0b11110000;
2755 let Inst{7-4} = 0b0001; // H form
2756}
Johnny Chen93042d12010-03-02 18:14:57 +00002757
2758// Generic versions of the above two instructions, for disassembly only
2759
2760def t2TBBgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2761 "tbb", "\t[$a, $b]", []>{
2762 let Inst{31-27} = 0b11101;
2763 let Inst{26-20} = 0b0001101;
2764 let Inst{15-8} = 0b11110000;
2765 let Inst{7-4} = 0b0000; // B form
2766}
2767
2768def t2TBHgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2769 "tbh", "\t[$a, $b, lsl #1]", []> {
2770 let Inst{31-27} = 0b11101;
2771 let Inst{26-20} = 0b0001101;
2772 let Inst{15-8} = 0b11110000;
2773 let Inst{7-4} = 0b0001; // H form
2774}
Evan Cheng5657c012009-07-29 02:18:14 +00002775} // isNotDuplicable, isIndirectBranch
2776
David Goodwinc9a59b52009-06-30 19:50:22 +00002777} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00002778
2779// FIXME: should be able to write a pattern for ARMBrcond, but can't use
2780// a two-value operand where a dag node expects two operands. :(
2781let isBranch = 1, isTerminator = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002782def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002783 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002784 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
2785 let Inst{31-27} = 0b11110;
2786 let Inst{15-14} = 0b10;
2787 let Inst{12} = 0;
2788}
Evan Chengf49810c2009-06-23 17:48:47 +00002789
Evan Cheng06e16582009-07-10 01:54:42 +00002790
2791// IT block
Evan Cheng86050dc2010-06-18 23:09:54 +00002792let Defs = [ITSTATE] in
Evan Cheng06e16582009-07-10 01:54:42 +00002793def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
David Goodwin5d598aa2009-08-19 18:00:44 +00002794 AddrModeNone, Size2Bytes, IIC_iALUx,
Johnny Chend68e1192009-12-15 17:24:14 +00002795 "it$mask\t$cc", "", []> {
2796 // 16-bit instruction.
Johnny Chenbbc71b22009-12-16 02:32:54 +00002797 let Inst{31-16} = 0x0000;
Johnny Chend68e1192009-12-15 17:24:14 +00002798 let Inst{15-8} = 0b10111111;
2799}
Evan Cheng06e16582009-07-10 01:54:42 +00002800
Johnny Chence6275f2010-02-25 19:05:29 +00002801// Branch and Exchange Jazelle -- for disassembly only
2802// Rm = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002803def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
Johnny Chence6275f2010-02-25 19:05:29 +00002804 [/* For disassembly only; pattern left blank */]> {
2805 let Inst{31-27} = 0b11110;
2806 let Inst{26} = 0;
2807 let Inst{25-20} = 0b111100;
2808 let Inst{15-14} = 0b10;
2809 let Inst{12} = 0;
2810}
2811
Johnny Chen93042d12010-03-02 18:14:57 +00002812// Change Processor State is a system instruction -- for disassembly only.
2813// The singleton $opt operand contains the following information:
2814// opt{4-0} = mode from Inst{4-0}
2815// opt{5} = changemode from Inst{17}
2816// opt{8-6} = AIF from Inst{8-6}
2817// opt{10-9} = imod from Inst{19-18} with 0b10 as enable and 0b11 as disable
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002818def t2CPS : T2XI<(outs),(ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +00002819 [/* For disassembly only; pattern left blank */]> {
2820 let Inst{31-27} = 0b11110;
2821 let Inst{26} = 0;
2822 let Inst{25-20} = 0b111010;
2823 let Inst{15-14} = 0b10;
2824 let Inst{12} = 0;
2825}
2826
Johnny Chen0f7866e2010-03-03 02:09:43 +00002827// A6.3.4 Branches and miscellaneous control
2828// Table A6-14 Change Processor State, and hint instructions
2829// Helper class for disassembly only.
2830class T2I_hint<bits<8> op7_0, string opc, string asm>
2831 : T2I<(outs), (ins), NoItinerary, opc, asm,
2832 [/* For disassembly only; pattern left blank */]> {
2833 let Inst{31-20} = 0xf3a;
2834 let Inst{15-14} = 0b10;
2835 let Inst{12} = 0;
2836 let Inst{10-8} = 0b000;
2837 let Inst{7-0} = op7_0;
2838}
2839
2840def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
2841def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
2842def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
2843def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
2844def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
2845
2846def t2DBG : T2I<(outs),(ins i32imm:$opt), NoItinerary, "dbg", "\t$opt",
2847 [/* For disassembly only; pattern left blank */]> {
2848 let Inst{31-20} = 0xf3a;
2849 let Inst{15-14} = 0b10;
2850 let Inst{12} = 0;
2851 let Inst{10-8} = 0b000;
2852 let Inst{7-4} = 0b1111;
2853}
2854
Johnny Chen6341c5a2010-02-25 20:25:24 +00002855// Secure Monitor Call is a system instruction -- for disassembly only
2856// Option = Inst{19-16}
2857def t2SMC : T2I<(outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
2858 [/* For disassembly only; pattern left blank */]> {
2859 let Inst{31-27} = 0b11110;
2860 let Inst{26-20} = 0b1111111;
2861 let Inst{15-12} = 0b1000;
2862}
2863
2864// Store Return State is a system instruction -- for disassembly only
2865def t2SRSDBW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
2866 [/* For disassembly only; pattern left blank */]> {
2867 let Inst{31-27} = 0b11101;
2868 let Inst{26-20} = 0b0000010; // W = 1
2869}
2870
2871def t2SRSDB : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
2872 [/* For disassembly only; pattern left blank */]> {
2873 let Inst{31-27} = 0b11101;
2874 let Inst{26-20} = 0b0000000; // W = 0
2875}
2876
2877def t2SRSIAW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
2878 [/* For disassembly only; pattern left blank */]> {
2879 let Inst{31-27} = 0b11101;
2880 let Inst{26-20} = 0b0011010; // W = 1
2881}
2882
2883def t2SRSIA : T2I<(outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
2884 [/* For disassembly only; pattern left blank */]> {
2885 let Inst{31-27} = 0b11101;
2886 let Inst{26-20} = 0b0011000; // W = 0
2887}
2888
2889// Return From Exception is a system instruction -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002890def t2RFEDBW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfedb", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002891 [/* For disassembly only; pattern left blank */]> {
2892 let Inst{31-27} = 0b11101;
2893 let Inst{26-20} = 0b0000011; // W = 1
2894}
2895
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002896def t2RFEDB : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeab", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002897 [/* For disassembly only; pattern left blank */]> {
2898 let Inst{31-27} = 0b11101;
2899 let Inst{26-20} = 0b0000001; // W = 0
2900}
2901
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002902def t2RFEIAW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002903 [/* For disassembly only; pattern left blank */]> {
2904 let Inst{31-27} = 0b11101;
2905 let Inst{26-20} = 0b0011011; // W = 1
2906}
2907
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002908def t2RFEIA : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002909 [/* For disassembly only; pattern left blank */]> {
2910 let Inst{31-27} = 0b11101;
2911 let Inst{26-20} = 0b0011001; // W = 0
2912}
2913
Evan Chengf49810c2009-06-23 17:48:47 +00002914//===----------------------------------------------------------------------===//
2915// Non-Instruction Patterns
2916//
2917
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002918// Two piece so_imms.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002919def : T2Pat<(or rGPR:$LHS, t2_so_imm2part:$RHS),
2920 (t2ORRri (t2ORRri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002921 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002922def : T2Pat<(xor rGPR:$LHS, t2_so_imm2part:$RHS),
2923 (t2EORri (t2EORri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002924 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002925def : T2Pat<(add rGPR:$LHS, t2_so_imm2part:$RHS),
2926 (t2ADDri (t2ADDri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002927 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002928def : T2Pat<(add rGPR:$LHS, t2_so_neg_imm2part:$RHS),
2929 (t2SUBri (t2SUBri rGPR:$LHS, (t2_so_neg_imm2part_1 imm:$RHS)),
Jim Grosbach15e6ef82009-11-23 20:35:53 +00002930 (t2_so_neg_imm2part_2 imm:$RHS))>;
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002931
Evan Cheng5adb66a2009-09-28 09:14:39 +00002932// 32-bit immediate using movw + movt.
Evan Cheng5be39222010-09-24 22:03:46 +00002933// This is a single pseudo instruction to make it re-materializable.
2934// FIXME: Remove this when we can do generalized remat.
Evan Cheng5adb66a2009-09-28 09:14:39 +00002935let isReMaterializable = 1 in
Jim Grosbach3c38f962010-10-06 22:01:26 +00002936def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
2937 "", [(set rGPR:$dst, (i32 imm:$src))]>,
2938 Requires<[IsThumb, HasV6T2]>;
Evan Chengb9803a82009-11-06 23:52:48 +00002939
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00002940// ConstantPool, GlobalAddress, and JumpTable
2941def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
2942 Requires<[IsThumb2, DontUseMovt]>;
2943def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
2944def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
2945 Requires<[IsThumb2, UseMovt]>;
2946
2947def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
2948 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
2949
Evan Chengb9803a82009-11-06 23:52:48 +00002950// Pseudo instruction that combines ldr from constpool and add pc. This should
2951// be expanded into two instructions late to allow if-conversion and
2952// scheduling.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00002953let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Chengb9803a82009-11-06 23:52:48 +00002954def t2LDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Jim Grosbach78890f42010-10-01 23:21:38 +00002955 IIC_iLoadiALU, "",
Evan Chengb9803a82009-11-06 23:52:48 +00002956 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
2957 imm:$cp))]>,
2958 Requires<[IsThumb2]>;
Johnny Chen23336552010-02-25 18:46:43 +00002959
2960//===----------------------------------------------------------------------===//
2961// Move between special register and ARM core register -- for disassembly only
2962//
2963
2964// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002965def t2MRS : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, cpsr",
Johnny Chen23336552010-02-25 18:46:43 +00002966 [/* For disassembly only; pattern left blank */]> {
2967 let Inst{31-27} = 0b11110;
2968 let Inst{26} = 0;
2969 let Inst{25-21} = 0b11111;
2970 let Inst{20} = 0; // The R bit.
2971 let Inst{15-14} = 0b10;
2972 let Inst{12} = 0;
2973}
2974
2975// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002976def t2MRSsys : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, spsr",
Johnny Chen23336552010-02-25 18:46:43 +00002977 [/* For disassembly only; pattern left blank */]> {
2978 let Inst{31-27} = 0b11110;
2979 let Inst{26} = 0;
2980 let Inst{25-21} = 0b11111;
2981 let Inst{20} = 1; // The R bit.
2982 let Inst{15-14} = 0b10;
2983 let Inst{12} = 0;
2984}
2985
Johnny Chen23336552010-02-25 18:46:43 +00002986// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002987def t2MSR : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002988 "\tcpsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00002989 [/* For disassembly only; pattern left blank */]> {
2990 let Inst{31-27} = 0b11110;
2991 let Inst{26} = 0;
2992 let Inst{25-21} = 0b11100;
2993 let Inst{20} = 0; // The R bit.
2994 let Inst{15-14} = 0b10;
2995 let Inst{12} = 0;
2996}
2997
Johnny Chen23336552010-02-25 18:46:43 +00002998// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002999def t2MSRsys : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00003000 "\tspsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00003001 [/* For disassembly only; pattern left blank */]> {
3002 let Inst{31-27} = 0b11110;
3003 let Inst{26} = 0;
3004 let Inst{25-21} = 0b11100;
3005 let Inst{20} = 1; // The R bit.
3006 let Inst{15-14} = 0b10;
3007 let Inst{12} = 0;
3008}