blob: ad017a7c548a51648f1c611d493bd2e460faa411 [file] [log] [blame]
Anton Korobeynikovd4022c32009-05-29 23:41:08 +00001//===- ARMInstrThumb2.td - Thumb2 support for ARM -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file describes the Thumb2 instruction set.
11//
12//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +000013
Evan Cheng06e16582009-07-10 01:54:42 +000014// IT block predicate field
15def it_pred : Operand<i32> {
Johnny Chen9d3acaa2010-03-02 17:57:15 +000016 let PrintMethod = "printMandatoryPredicateOperand";
Evan Cheng06e16582009-07-10 01:54:42 +000017}
18
19// IT block condition mask
20def it_mask : Operand<i32> {
21 let PrintMethod = "printThumbITMask";
22}
23
Evan Cheng5657c012009-07-29 02:18:14 +000024// Table branch address
25def tb_addrmode : Operand<i32> {
26 let PrintMethod = "printTBAddrMode";
27}
28
Anton Korobeynikov52237112009-06-17 18:13:58 +000029// Shifted operands. No register controlled shifts for Thumb2.
30// Note: We do not support rrx shifted operands yet.
31def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000032 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000033 [shl,srl,sra,rotr]> {
Owen Anderson5de6d842010-11-12 21:12:40 +000034 string EncoderMethod = "getT2SORegOpValue";
Evan Cheng9cb9e672009-06-27 02:26:13 +000035 let PrintMethod = "printT2SOOperand";
Jim Grosbach6ccfc502010-07-30 02:41:01 +000036 let MIOperandInfo = (ops rGPR, i32imm);
Anton Korobeynikov52237112009-06-17 18:13:58 +000037}
38
Evan Chengf49810c2009-06-23 17:48:47 +000039// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
40def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000041 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000042}]>;
43
Evan Chengf49810c2009-06-23 17:48:47 +000044// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
45def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000046 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000047}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000048
Evan Chengf49810c2009-06-23 17:48:47 +000049// t2_so_imm - Match a 32-bit immediate operand, which is an
50// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
51// immediate splatted into multiple bytes of the word. t2_so_imm values are
52// represented in the imm field in the same 12-bit form that they are encoded
Jim Grosbach6935efc2009-11-24 00:20:27 +000053// into t2_so_imm instructions: the 8-bit immediate is the least significant
54// bits [bits 0-7], the 4-bit shift/splat amount is the next 4 bits [bits 8-11].
Owen Anderson5de6d842010-11-12 21:12:40 +000055def t2_so_imm : Operand<i32>, PatLeaf<(imm), [{ return Pred_t2_so_imm(N); }]> {
56 string EncoderMethod = "getT2SOImmOpValue";
57}
Anton Korobeynikov52237112009-06-17 18:13:58 +000058
Jim Grosbach64171712010-02-16 21:07:46 +000059// t2_so_imm_not - Match an immediate that is a complement
Evan Chengf49810c2009-06-23 17:48:47 +000060// of a t2_so_imm.
61def t2_so_imm_not : Operand<i32>,
62 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000063 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
64}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000065
66// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
67def t2_so_imm_neg : Operand<i32>,
68 PatLeaf<(imm), [{
Evan Cheng875a6ac2010-11-12 22:42:47 +000069 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
Evan Chenge7cbe412009-07-08 21:03:57 +000070}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000071
Jim Grosbach65b7f3a2009-10-21 20:44:34 +000072// Break t2_so_imm's up into two pieces. This handles immediates with up to 16
73// bits set in them. This uses t2_so_imm2part to match and t2_so_imm2part_[12]
74// to get the first/second pieces.
75def t2_so_imm2part : Operand<i32>,
76 PatLeaf<(imm), [{
77 return ARM_AM::isT2SOImmTwoPartVal((unsigned)N->getZExtValue());
78 }]> {
79}
80
81def t2_so_imm2part_1 : SDNodeXForm<imm, [{
82 unsigned V = ARM_AM::getT2SOImmTwoPartFirst((unsigned)N->getZExtValue());
83 return CurDAG->getTargetConstant(V, MVT::i32);
84}]>;
85
86def t2_so_imm2part_2 : SDNodeXForm<imm, [{
87 unsigned V = ARM_AM::getT2SOImmTwoPartSecond((unsigned)N->getZExtValue());
88 return CurDAG->getTargetConstant(V, MVT::i32);
89}]>;
90
Jim Grosbach15e6ef82009-11-23 20:35:53 +000091def t2_so_neg_imm2part : Operand<i32>, PatLeaf<(imm), [{
92 return ARM_AM::isT2SOImmTwoPartVal(-(int)N->getZExtValue());
93 }]> {
94}
95
96def t2_so_neg_imm2part_1 : SDNodeXForm<imm, [{
97 unsigned V = ARM_AM::getT2SOImmTwoPartFirst(-(int)N->getZExtValue());
98 return CurDAG->getTargetConstant(V, MVT::i32);
99}]>;
100
101def t2_so_neg_imm2part_2 : SDNodeXForm<imm, [{
102 unsigned V = ARM_AM::getT2SOImmTwoPartSecond(-(int)N->getZExtValue());
103 return CurDAG->getTargetConstant(V, MVT::i32);
104}]>;
105
Evan Chenga67efd12009-06-23 19:39:13 +0000106/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
107def imm1_31 : PatLeaf<(i32 imm), [{
108 return (int32_t)N->getZExtValue() >= 1 && (int32_t)N->getZExtValue() < 32;
109}]>;
110
Evan Chengf49810c2009-06-23 17:48:47 +0000111/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
Evan Cheng86198642009-08-07 00:34:42 +0000112def imm0_4095 : Operand<i32>,
113 PatLeaf<(i32 imm), [{
Evan Chengf49810c2009-06-23 17:48:47 +0000114 return (uint32_t)N->getZExtValue() < 4096;
115}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000116
Jim Grosbach64171712010-02-16 21:07:46 +0000117def imm0_4095_neg : PatLeaf<(i32 imm), [{
118 return (uint32_t)(-N->getZExtValue()) < 4096;
119}], imm_neg_XFORM>;
Anton Korobeynikov52237112009-06-17 18:13:58 +0000120
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000121def imm0_255_neg : PatLeaf<(i32 imm), [{
122 return (uint32_t)(-N->getZExtValue()) < 255;
Jim Grosbach64171712010-02-16 21:07:46 +0000123}], imm_neg_XFORM>;
Evan Chengfa2ea1a2009-08-04 01:41:15 +0000124
Jim Grosbach502e0aa2010-07-14 17:45:16 +0000125def imm0_255_not : PatLeaf<(i32 imm), [{
126 return (uint32_t)(~N->getZExtValue()) < 255;
127}], imm_comp_XFORM>;
128
Evan Cheng055b0312009-06-29 07:51:04 +0000129// Define Thumb2 specific addressing modes.
130
131// t2addrmode_imm12 := reg + imm12
132def t2addrmode_imm12 : Operand<i32>,
133 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000134 let PrintMethod = "printAddrModeImm12Operand";
Evan Cheng055b0312009-06-29 07:51:04 +0000135 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
136}
137
Johnny Chen0635fc52010-03-04 17:40:44 +0000138// t2addrmode_imm8 := reg +/- imm8
Evan Cheng055b0312009-06-29 07:51:04 +0000139def t2addrmode_imm8 : Operand<i32>,
140 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
141 let PrintMethod = "printT2AddrModeImm8Operand";
142 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
143}
144
Evan Cheng6d94f112009-07-03 00:06:39 +0000145def t2am_imm8_offset : Operand<i32>,
Chris Lattner52a261b2010-09-21 20:31:19 +0000146 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
147 [], [SDNPWantRoot]> {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000148 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
149}
150
Evan Cheng5c874172009-07-09 22:21:59 +0000151// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
Chris Lattner979b0612010-09-05 22:51:11 +0000152def t2addrmode_imm8s4 : Operand<i32> {
Evan Cheng5c874172009-07-09 22:21:59 +0000153 let PrintMethod = "printT2AddrModeImm8s4Operand";
David Goodwin6647cea2009-06-30 22:50:01 +0000154 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
155}
156
Johnny Chenae1757b2010-03-11 01:13:36 +0000157def t2am_imm8s4_offset : Operand<i32> {
158 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
159}
160
Evan Chengcba962d2009-07-09 20:40:44 +0000161// t2addrmode_so_reg := reg + (reg << imm2)
Evan Cheng055b0312009-06-29 07:51:04 +0000162def t2addrmode_so_reg : Operand<i32>,
163 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
164 let PrintMethod = "printT2AddrModeSoRegOperand";
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000165 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
Evan Cheng055b0312009-06-29 07:51:04 +0000166}
167
168
Anton Korobeynikov52237112009-06-17 18:13:58 +0000169//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000170// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000171//
172
Owen Anderson83da6cd2010-11-14 05:37:38 +0000173class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
174 string opc, string asm, list<dag> pattern>
175 : T2I<oops, iops, itin, opc, asm, pattern> {
176 bits<4> Rd;
177 bits<4> Rn;
178 bits<12> imm;
179
180 let Inst{11-8} = Rd{3-0};
181 let Inst{19-16} = Rn{3-0};
182 let Inst{26} = imm{11};
183 let Inst{14-12} = imm{10-8};
184 let Inst{7-0} = imm{7-0};
185}
186
187class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson5de6d842010-11-12 21:12:40 +0000188 string opc, string asm, list<dag> pattern>
189 : T2sI<oops, iops, itin, opc, asm, pattern> {
190 bits<4> Rd;
191 bits<4> Rn;
192 bits<12> imm;
193
194 let Inst{11-8} = Rd{3-0};
195 let Inst{19-16} = Rn{3-0};
196 let Inst{26} = imm{11};
197 let Inst{14-12} = imm{10-8};
198 let Inst{7-0} = imm{7-0};
199}
200
201class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
202 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000203 : T2I<oops, iops, itin, opc, asm, pattern> {
204 bits<4> Rd;
205 bits<4> Rn;
206 bits<4> Rm;
207
208 let Inst{11-8} = Rd{3-0};
209 let Inst{19-16} = Rn{3-0};
210 let Inst{3-0} = Rm{3-0};
211}
212
213class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
214 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000215 : T2sI<oops, iops, itin, opc, asm, pattern> {
216 bits<4> Rd;
217 bits<4> Rn;
218 bits<4> Rm;
219
220 let Inst{11-8} = Rd{3-0};
221 let Inst{19-16} = Rn{3-0};
222 let Inst{3-0} = Rm{3-0};
223}
224
225class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
226 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000227 : T2I<oops, iops, itin, opc, asm, pattern> {
228 bits<4> Rd;
229 bits<4> Rn;
230 bits<12> ShiftedRm;
231
232 let Inst{11-8} = Rd{3-0};
233 let Inst{19-16} = Rn{3-0};
234 let Inst{3-0} = ShiftedRm{3-0};
235 let Inst{5-4} = ShiftedRm{6-5};
236 let Inst{14-12} = ShiftedRm{11-9};
237 let Inst{7-6} = ShiftedRm{8-7};
238}
239
240class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
241 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000242 : T2sI<oops, iops, itin, opc, asm, pattern> {
243 bits<4> Rd;
244 bits<4> Rn;
245 bits<12> ShiftedRm;
246
247 let Inst{11-8} = Rd{3-0};
248 let Inst{19-16} = Rn{3-0};
249 let Inst{3-0} = ShiftedRm{3-0};
250 let Inst{5-4} = ShiftedRm{6-5};
251 let Inst{14-12} = ShiftedRm{11-9};
252 let Inst{7-6} = ShiftedRm{8-7};
253}
254
Evan Chenga67efd12009-06-23 19:39:13 +0000255/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000256/// unary operation that produces a value. These are predicable and can be
257/// changed to modify CPSR.
Evan Cheng5d42c562010-09-29 00:49:25 +0000258multiclass T2I_un_irs<bits<4> opcod, string opc,
259 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
260 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
Evan Chenga67efd12009-06-23 19:39:13 +0000261 // shifted imm
Evan Cheng5d42c562010-09-29 00:49:25 +0000262 def i : T2sI<(outs rGPR:$dst), (ins t2_so_imm:$src), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000263 opc, "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000264 [(set rGPR:$dst, (opnode t2_so_imm:$src))]> {
Evan Chenga67efd12009-06-23 19:39:13 +0000265 let isAsCheapAsAMove = Cheap;
266 let isReMaterializable = ReMat;
Johnny Chend68e1192009-12-15 17:24:14 +0000267 let Inst{31-27} = 0b11110;
268 let Inst{25} = 0;
269 let Inst{24-21} = opcod;
270 let Inst{20} = ?; // The S bit.
271 let Inst{19-16} = 0b1111; // Rn
272 let Inst{15} = 0;
Evan Chenga67efd12009-06-23 19:39:13 +0000273 }
274 // register
Evan Cheng5d42c562010-09-29 00:49:25 +0000275 def r : T2sI<(outs rGPR:$dst), (ins rGPR:$src), iir,
Bob Wilsonc21763f2010-05-24 22:41:19 +0000276 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000277 [(set rGPR:$dst, (opnode rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000278 let Inst{31-27} = 0b11101;
279 let Inst{26-25} = 0b01;
280 let Inst{24-21} = opcod;
281 let Inst{20} = ?; // The S bit.
282 let Inst{19-16} = 0b1111; // Rn
283 let Inst{14-12} = 0b000; // imm3
284 let Inst{7-6} = 0b00; // imm2
285 let Inst{5-4} = 0b00; // type
286 }
Evan Chenga67efd12009-06-23 19:39:13 +0000287 // shifted register
Evan Cheng5d42c562010-09-29 00:49:25 +0000288 def s : T2sI<(outs rGPR:$dst), (ins t2_so_reg:$src), iis,
Bob Wilsonc21763f2010-05-24 22:41:19 +0000289 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000290 [(set rGPR:$dst, (opnode t2_so_reg:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000291 let Inst{31-27} = 0b11101;
292 let Inst{26-25} = 0b01;
293 let Inst{24-21} = opcod;
294 let Inst{20} = ?; // The S bit.
295 let Inst{19-16} = 0b1111; // Rn
296 }
Evan Chenga67efd12009-06-23 19:39:13 +0000297}
298
299/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Bob Wilson4876bdb2010-05-25 04:43:08 +0000300/// binary operation that produces a value. These are predicable and can be
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000301/// changed to modify CPSR.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000302multiclass T2I_bin_irs<bits<4> opcod, string opc,
303 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
304 PatFrag opnode, bit Commutable = 0, string wide = ""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000305 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000306 def ri : T2sTwoRegImm<
307 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
308 opc, "\t$Rd, $Rn, $imm",
309 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000310 let Inst{31-27} = 0b11110;
311 let Inst{25} = 0;
312 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000313 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000314 let Inst{15} = 0;
315 }
Evan Chenga67efd12009-06-23 19:39:13 +0000316 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000317 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
318 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
319 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000320 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000321 let Inst{31-27} = 0b11101;
322 let Inst{26-25} = 0b01;
323 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000324 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000325 let Inst{14-12} = 0b000; // imm3
326 let Inst{7-6} = 0b00; // imm2
327 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000328 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000329 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000330 def rs : T2sTwoRegShiftedReg<
331 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
332 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
333 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000334 let Inst{31-27} = 0b11101;
335 let Inst{26-25} = 0b01;
336 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000337 let Inst{20} = ?; // The S bit.
338 }
339}
340
David Goodwin1f096272009-07-27 23:34:12 +0000341/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
342// the ".w" prefix to indicate that they are wide.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000343multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
344 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
345 PatFrag opnode, bit Commutable = 0> :
346 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, Commutable, ".w">;
Bill Wendling1f7bf0e2010-08-29 03:55:31 +0000347
Evan Cheng1e249e32009-06-25 20:59:23 +0000348/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000349/// reversed. The 'rr' form is only defined for the disassembler; for codegen
350/// it is equivalent to the T2I_bin_irs counterpart.
351multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000352 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000353 def ri : T2sTwoRegImm<
354 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
355 opc, ".w\t$Rd, $Rn, $imm",
356 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000357 let Inst{31-27} = 0b11110;
358 let Inst{25} = 0;
359 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000360 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000361 let Inst{15} = 0;
362 }
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000363 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000364 def rr : T2sThreeReg<
365 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
366 opc, "\t$Rd, $Rn, $Rm",
Bob Wilson136e4912010-08-14 03:18:29 +0000367 [/* For disassembly only; pattern left blank */]> {
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000368 let Inst{31-27} = 0b11101;
369 let Inst{26-25} = 0b01;
370 let Inst{24-21} = opcod;
371 let Inst{20} = ?; // The S bit.
372 let Inst{14-12} = 0b000; // imm3
373 let Inst{7-6} = 0b00; // imm2
374 let Inst{5-4} = 0b00; // type
375 }
Evan Chengf49810c2009-06-23 17:48:47 +0000376 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000377 def rs : T2sTwoRegShiftedReg<
378 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
379 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
380 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000381 let Inst{31-27} = 0b11101;
382 let Inst{26-25} = 0b01;
383 let Inst{24-21} = opcod;
Bob Wilson4876bdb2010-05-25 04:43:08 +0000384 let Inst{20} = ?; // The S bit.
Johnny Chend68e1192009-12-15 17:24:14 +0000385 }
Evan Chengf49810c2009-06-23 17:48:47 +0000386}
387
Evan Chenga67efd12009-06-23 19:39:13 +0000388/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000389/// instruction modifies the CPSR register.
390let Defs = [CPSR] in {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000391multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
392 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
393 PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000394 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000395 def ri : T2TwoRegImm<
396 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
397 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
398 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000399 let Inst{31-27} = 0b11110;
400 let Inst{25} = 0;
401 let Inst{24-21} = opcod;
402 let Inst{20} = 1; // The S bit.
403 let Inst{15} = 0;
404 }
Evan Chenga67efd12009-06-23 19:39:13 +0000405 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000406 def rr : T2ThreeReg<
407 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
408 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm",
409 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000410 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000411 let Inst{31-27} = 0b11101;
412 let Inst{26-25} = 0b01;
413 let Inst{24-21} = opcod;
414 let Inst{20} = 1; // The S bit.
415 let Inst{14-12} = 0b000; // imm3
416 let Inst{7-6} = 0b00; // imm2
417 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000418 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000419 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000420 def rs : T2TwoRegShiftedReg<
421 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
422 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm",
423 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000424 let Inst{31-27} = 0b11101;
425 let Inst{26-25} = 0b01;
426 let Inst{24-21} = opcod;
427 let Inst{20} = 1; // The S bit.
428 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000429}
430}
431
Evan Chenga67efd12009-06-23 19:39:13 +0000432/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
433/// patterns for a binary operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000434multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
435 bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000436 // shifted imm
Jim Grosbach663e3392010-08-30 19:49:58 +0000437 // The register-immediate version is re-materializable. This is useful
438 // in particular for taking the address of a local.
439 let isReMaterializable = 1 in {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000440 def ri : T2sTwoRegImm<
441 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
442 opc, ".w\t$Rd, $Rn, $imm",
443 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000444 let Inst{31-27} = 0b11110;
445 let Inst{25} = 0;
446 let Inst{24} = 1;
447 let Inst{23-21} = op23_21;
448 let Inst{20} = 0; // The S bit.
449 let Inst{15} = 0;
450 }
Jim Grosbach663e3392010-08-30 19:49:58 +0000451 }
Evan Chengf49810c2009-06-23 17:48:47 +0000452 // 12-bit imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000453 def ri12 : T2TwoRegImm<
454 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
455 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
456 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000457 let Inst{31-27} = 0b11110;
458 let Inst{25} = 1;
459 let Inst{24} = 0;
460 let Inst{23-21} = op23_21;
461 let Inst{20} = 0; // The S bit.
462 let Inst{15} = 0;
463 }
Evan Chenga67efd12009-06-23 19:39:13 +0000464 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000465 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr,
466 opc, ".w\t$Rd, $Rn, $Rm",
467 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000468 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000469 let Inst{31-27} = 0b11101;
470 let Inst{26-25} = 0b01;
471 let Inst{24} = 1;
472 let Inst{23-21} = op23_21;
473 let Inst{20} = 0; // The S bit.
474 let Inst{14-12} = 0b000; // imm3
475 let Inst{7-6} = 0b00; // imm2
476 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000477 }
Evan Chengf49810c2009-06-23 17:48:47 +0000478 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000479 def rs : T2sTwoRegShiftedReg<
480 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
481 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
482 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000483 let Inst{31-27} = 0b11101;
Johnny Chend68e1192009-12-15 17:24:14 +0000484 let Inst{26-25} = 0b01;
Johnny Chend248ffb2010-01-08 17:41:33 +0000485 let Inst{24} = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000486 let Inst{23-21} = op23_21;
487 let Inst{20} = 0; // The S bit.
488 }
Evan Chengf49810c2009-06-23 17:48:47 +0000489}
490
Jim Grosbach6935efc2009-11-24 00:20:27 +0000491/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000492/// for a binary operation that produces a value and use the carry
Jim Grosbach6935efc2009-11-24 00:20:27 +0000493/// bit. It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000494let Uses = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000495multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
496 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000497 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000498 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000499 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
500 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000501 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000502 let Inst{31-27} = 0b11110;
503 let Inst{25} = 0;
504 let Inst{24-21} = opcod;
505 let Inst{20} = 0; // The S bit.
506 let Inst{15} = 0;
507 }
Evan Chenga67efd12009-06-23 19:39:13 +0000508 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000509 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000510 opc, ".w\t$Rd, $Rn, $Rm",
511 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000512 Requires<[IsThumb2]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000513 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000514 let Inst{31-27} = 0b11101;
515 let Inst{26-25} = 0b01;
516 let Inst{24-21} = opcod;
517 let Inst{20} = 0; // The S bit.
518 let Inst{14-12} = 0b000; // imm3
519 let Inst{7-6} = 0b00; // imm2
520 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000521 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000522 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000523 def rs : T2sTwoRegShiftedReg<
Owen Anderson5de6d842010-11-12 21:12:40 +0000524 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
525 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
526 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000527 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000528 let Inst{31-27} = 0b11101;
529 let Inst{26-25} = 0b01;
530 let Inst{24-21} = opcod;
531 let Inst{20} = 0; // The S bit.
532 }
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000533}
534
535// Carry setting variants
536let Defs = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000537multiclass T2I_adde_sube_s_irs<bits<4> opcod, string opc, PatFrag opnode,
538 bit Commutable = 0> {
Evan Cheng62674222009-06-25 23:34:10 +0000539 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000540 def ri : T2sTwoRegImm<
Owen Anderson5de6d842010-11-12 21:12:40 +0000541 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
542 opc, "\t$Rd, $Rn, $imm",
543 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000544 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000545 let Inst{31-27} = 0b11110;
546 let Inst{25} = 0;
547 let Inst{24-21} = opcod;
548 let Inst{20} = 1; // The S bit.
549 let Inst{15} = 0;
550 }
Evan Cheng62674222009-06-25 23:34:10 +0000551 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000552 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000553 opc, ".w\t$Rd, $Rn, $Rm",
554 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000555 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000556 let isCommutable = Commutable;
557 let Inst{31-27} = 0b11101;
558 let Inst{26-25} = 0b01;
559 let Inst{24-21} = opcod;
560 let Inst{20} = 1; // The S bit.
561 let Inst{14-12} = 0b000; // imm3
562 let Inst{7-6} = 0b00; // imm2
563 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000564 }
Evan Cheng62674222009-06-25 23:34:10 +0000565 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000566 def rs : T2sTwoRegShiftedReg<
Owen Anderson5de6d842010-11-12 21:12:40 +0000567 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
568 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
569 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Johnny Chenb5031ad2010-03-02 19:38:59 +0000570 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000571 let Inst{31-27} = 0b11101;
572 let Inst{26-25} = 0b01;
573 let Inst{24-21} = opcod;
574 let Inst{20} = 1; // The S bit.
Evan Cheng8de898a2009-06-26 00:19:44 +0000575 }
Evan Chengf49810c2009-06-23 17:48:47 +0000576}
577}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000578}
Evan Chengf49810c2009-06-23 17:48:47 +0000579
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000580/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
581/// version is not needed since this is only for codegen.
Evan Cheng1e249e32009-06-25 20:59:23 +0000582let Defs = [CPSR] in {
Johnny Chend68e1192009-12-15 17:24:14 +0000583multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000584 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000585 def ri : T2TwoRegImm<
586 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
587 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
588 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000589 let Inst{31-27} = 0b11110;
590 let Inst{25} = 0;
591 let Inst{24-21} = opcod;
592 let Inst{20} = 1; // The S bit.
593 let Inst{15} = 0;
594 }
Evan Chengf49810c2009-06-23 17:48:47 +0000595 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000596 def rs : T2TwoRegShiftedReg<
597 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
598 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm",
599 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000600 let Inst{31-27} = 0b11101;
601 let Inst{26-25} = 0b01;
602 let Inst{24-21} = opcod;
603 let Inst{20} = 1; // The S bit.
604 }
Evan Chengf49810c2009-06-23 17:48:47 +0000605}
606}
607
Evan Chenga67efd12009-06-23 19:39:13 +0000608/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
609// rotate operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000610multiclass T2I_sh_ir<bits<2> opcod, string opc, PatFrag opnode> {
Evan Chenga67efd12009-06-23 19:39:13 +0000611 // 5-bit imm
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000612 def ri : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, i32imm:$rhs), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +0000613 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000614 [(set rGPR:$dst, (opnode rGPR:$lhs, imm1_31:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000615 let Inst{31-27} = 0b11101;
616 let Inst{26-21} = 0b010010;
617 let Inst{19-16} = 0b1111; // Rn
618 let Inst{5-4} = opcod;
619 }
Evan Chenga67efd12009-06-23 19:39:13 +0000620 // register
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000621 def rr : T2sI<(outs rGPR:$dst), (ins rGPR:$lhs, rGPR:$rhs), IIC_iMOVsr,
Evan Cheng699beba2009-10-27 00:08:59 +0000622 opc, ".w\t$dst, $lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000623 [(set rGPR:$dst, (opnode rGPR:$lhs, rGPR:$rhs))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000624 let Inst{31-27} = 0b11111;
625 let Inst{26-23} = 0b0100;
626 let Inst{22-21} = opcod;
627 let Inst{15-12} = 0b1111;
628 let Inst{7-4} = 0b0000;
629 }
Evan Chenga67efd12009-06-23 19:39:13 +0000630}
Evan Chengf49810c2009-06-23 17:48:47 +0000631
Johnny Chend68e1192009-12-15 17:24:14 +0000632/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
Evan Chenga67efd12009-06-23 19:39:13 +0000633/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000634/// a explicit result, only implicitly set CPSR.
Bill Wendlingf0e132c2010-08-19 00:05:48 +0000635let isCompare = 1, Defs = [CPSR] in {
Evan Cheng5d42c562010-09-29 00:49:25 +0000636multiclass T2I_cmp_irs<bits<4> opcod, string opc,
637 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
638 PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000639 // shifted imm
Evan Cheng5d42c562010-09-29 00:49:25 +0000640 def ri : T2I<(outs), (ins GPR:$lhs, t2_so_imm:$rhs), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000641 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000642 [(opnode GPR:$lhs, t2_so_imm:$rhs)]> {
643 let Inst{31-27} = 0b11110;
644 let Inst{25} = 0;
645 let Inst{24-21} = opcod;
646 let Inst{20} = 1; // The S bit.
647 let Inst{15} = 0;
648 let Inst{11-8} = 0b1111; // Rd
649 }
Evan Chenga67efd12009-06-23 19:39:13 +0000650 // register
Evan Cheng5d42c562010-09-29 00:49:25 +0000651 def rr : T2I<(outs), (ins GPR:$lhs, rGPR:$rhs), iir,
Evan Cheng699beba2009-10-27 00:08:59 +0000652 opc, ".w\t$lhs, $rhs",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000653 [(opnode GPR:$lhs, rGPR:$rhs)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000654 let Inst{31-27} = 0b11101;
655 let Inst{26-25} = 0b01;
656 let Inst{24-21} = opcod;
657 let Inst{20} = 1; // The S bit.
658 let Inst{14-12} = 0b000; // imm3
659 let Inst{11-8} = 0b1111; // Rd
660 let Inst{7-6} = 0b00; // imm2
661 let Inst{5-4} = 0b00; // type
662 }
Evan Chengf49810c2009-06-23 17:48:47 +0000663 // shifted register
Evan Cheng5d42c562010-09-29 00:49:25 +0000664 def rs : T2I<(outs), (ins GPR:$lhs, t2_so_reg:$rhs), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000665 opc, ".w\t$lhs, $rhs",
Johnny Chend68e1192009-12-15 17:24:14 +0000666 [(opnode GPR:$lhs, t2_so_reg:$rhs)]> {
667 let Inst{31-27} = 0b11101;
668 let Inst{26-25} = 0b01;
669 let Inst{24-21} = opcod;
670 let Inst{20} = 1; // The S bit.
671 let Inst{11-8} = 0b1111; // Rd
672 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000673}
674}
675
Evan Chengf3c21b82009-06-30 02:15:48 +0000676/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000677multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000678 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000679 def i12 : T2Ii12<(outs GPR:$dst), (ins t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000680 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000681 [(set GPR:$dst, (opnode t2addrmode_imm12:$addr))]> {
682 let Inst{31-27} = 0b11111;
683 let Inst{26-25} = 0b00;
684 let Inst{24} = signed;
685 let Inst{23} = 1;
686 let Inst{22-21} = opcod;
687 let Inst{20} = 1; // load
688 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000689 def i8 : T2Ii8 <(outs GPR:$dst), (ins t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000690 opc, "\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000691 [(set GPR:$dst, (opnode t2addrmode_imm8:$addr))]> {
692 let Inst{31-27} = 0b11111;
693 let Inst{26-25} = 0b00;
694 let Inst{24} = signed;
695 let Inst{23} = 0;
696 let Inst{22-21} = opcod;
697 let Inst{20} = 1; // load
698 let Inst{11} = 1;
699 // Offset: index==TRUE, wback==FALSE
700 let Inst{10} = 1; // The P bit.
701 let Inst{8} = 0; // The W bit.
702 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000703 def s : T2Iso <(outs GPR:$dst), (ins t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000704 opc, ".w\t$dst, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000705 [(set GPR:$dst, (opnode t2addrmode_so_reg:$addr))]> {
706 let Inst{31-27} = 0b11111;
707 let Inst{26-25} = 0b00;
708 let Inst{24} = signed;
709 let Inst{23} = 0;
710 let Inst{22-21} = opcod;
711 let Inst{20} = 1; // load
712 let Inst{11-6} = 0b000000;
713 }
Evan Chengbc7deb02010-11-03 05:14:24 +0000714
715 // FIXME: Is the pci variant actually needed?
Evan Cheng0e55fd62010-09-30 01:08:25 +0000716 def pci : T2Ipc <(outs GPR:$dst), (ins i32imm:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000717 opc, ".w\t$dst, $addr",
Evan Cheng9eda6892009-10-31 03:39:36 +0000718 [(set GPR:$dst, (opnode (ARMWrapper tconstpool:$addr)))]> {
719 let isReMaterializable = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000720 let Inst{31-27} = 0b11111;
721 let Inst{26-25} = 0b00;
722 let Inst{24} = signed;
723 let Inst{23} = ?; // add = (U == '1')
724 let Inst{22-21} = opcod;
725 let Inst{20} = 1; // load
726 let Inst{19-16} = 0b1111; // Rn
Evan Cheng9eda6892009-10-31 03:39:36 +0000727 }
Evan Chengf3c21b82009-06-30 02:15:48 +0000728}
729
David Goodwin73b8f162009-06-30 22:11:34 +0000730/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000731multiclass T2I_st<bits<2> opcod, string opc,
Evan Cheng7e2fe912010-10-28 06:47:08 +0000732 InstrItinClass iii, InstrItinClass iis, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +0000733 def i12 : T2Ii12<(outs), (ins GPR:$src, t2addrmode_imm12:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000734 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000735 [(opnode GPR:$src, t2addrmode_imm12:$addr)]> {
736 let Inst{31-27} = 0b11111;
737 let Inst{26-23} = 0b0001;
738 let Inst{22-21} = opcod;
739 let Inst{20} = 0; // !load
740 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000741 def i8 : T2Ii8 <(outs), (ins GPR:$src, t2addrmode_imm8:$addr), iii,
Evan Cheng699beba2009-10-27 00:08:59 +0000742 opc, "\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000743 [(opnode GPR:$src, t2addrmode_imm8:$addr)]> {
744 let Inst{31-27} = 0b11111;
745 let Inst{26-23} = 0b0000;
746 let Inst{22-21} = opcod;
747 let Inst{20} = 0; // !load
748 let Inst{11} = 1;
749 // Offset: index==TRUE, wback==FALSE
750 let Inst{10} = 1; // The P bit.
751 let Inst{8} = 0; // The W bit.
752 }
Evan Cheng7e2fe912010-10-28 06:47:08 +0000753 def s : T2Iso <(outs), (ins GPR:$src, t2addrmode_so_reg:$addr), iis,
Evan Cheng699beba2009-10-27 00:08:59 +0000754 opc, ".w\t$src, $addr",
Johnny Chend68e1192009-12-15 17:24:14 +0000755 [(opnode GPR:$src, t2addrmode_so_reg:$addr)]> {
756 let Inst{31-27} = 0b11111;
757 let Inst{26-23} = 0b0000;
758 let Inst{22-21} = opcod;
759 let Inst{20} = 0; // !load
760 let Inst{11-6} = 0b000000;
761 }
David Goodwin73b8f162009-06-30 22:11:34 +0000762}
763
Evan Cheng0e55fd62010-09-30 01:08:25 +0000764/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000765/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000766multiclass T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode> {
767 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000768 opc, ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000769 [(set rGPR:$dst, (opnode rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000770 let Inst{31-27} = 0b11111;
771 let Inst{26-23} = 0b0100;
772 let Inst{22-20} = opcod;
773 let Inst{19-16} = 0b1111; // Rn
774 let Inst{15-12} = 0b1111;
775 let Inst{7} = 1;
776 let Inst{5-4} = 0b00; // rotate
777 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000778 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Evan Cheng699beba2009-10-27 00:08:59 +0000779 opc, ".w\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000780 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000781 let Inst{31-27} = 0b11111;
782 let Inst{26-23} = 0b0100;
783 let Inst{22-20} = opcod;
784 let Inst{19-16} = 0b1111; // Rn
785 let Inst{15-12} = 0b1111;
786 let Inst{7} = 1;
787 let Inst{5-4} = {?,?}; // rotate
788 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000789}
790
Eli Friedman761fa7a2010-06-24 18:20:04 +0000791// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000792multiclass T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode> {
793 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000794 opc, "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000795 [(set rGPR:$dst, (opnode rGPR:$src))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000796 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000797 let Inst{31-27} = 0b11111;
798 let Inst{26-23} = 0b0100;
799 let Inst{22-20} = opcod;
800 let Inst{19-16} = 0b1111; // Rn
801 let Inst{15-12} = 0b1111;
802 let Inst{7} = 1;
803 let Inst{5-4} = 0b00; // rotate
804 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000805 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen267124c2010-03-04 22:24:41 +0000806 opc, "\t$dst, $src, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000807 [(set rGPR:$dst, (opnode (rotr rGPR:$src, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000808 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chen267124c2010-03-04 22:24:41 +0000809 let Inst{31-27} = 0b11111;
810 let Inst{26-23} = 0b0100;
811 let Inst{22-20} = opcod;
812 let Inst{19-16} = 0b1111; // Rn
813 let Inst{15-12} = 0b1111;
814 let Inst{7} = 1;
815 let Inst{5-4} = {?,?}; // rotate
816 }
817}
818
Eli Friedman761fa7a2010-06-24 18:20:04 +0000819// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
820// supported yet.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000821multiclass T2I_ext_rrot_sxtb16<bits<3> opcod, string opc> {
822 def r : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000823 opc, "\t$dst, $src", []> {
824 let Inst{31-27} = 0b11111;
825 let Inst{26-23} = 0b0100;
826 let Inst{22-20} = opcod;
827 let Inst{19-16} = 0b1111; // Rn
828 let Inst{15-12} = 0b1111;
829 let Inst{7} = 1;
830 let Inst{5-4} = 0b00; // rotate
831 }
Evan Cheng0e55fd62010-09-30 01:08:25 +0000832 def r_rot : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$rot), IIC_iEXTr,
Johnny Chen93042d12010-03-02 18:14:57 +0000833 opc, "\t$dst, $src, ror $rot", []> {
834 let Inst{31-27} = 0b11111;
835 let Inst{26-23} = 0b0100;
836 let Inst{22-20} = opcod;
837 let Inst{19-16} = 0b1111; // Rn
838 let Inst{15-12} = 0b1111;
839 let Inst{7} = 1;
840 let Inst{5-4} = {?,?}; // rotate
841 }
842}
843
Evan Cheng0e55fd62010-09-30 01:08:25 +0000844/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000845/// register and one whose operand is a register rotated by 8/16/24.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000846multiclass T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode> {
847 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Evan Cheng699beba2009-10-27 00:08:59 +0000848 opc, "\t$dst, $LHS, $RHS",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000849 [(set rGPR:$dst, (opnode rGPR:$LHS, rGPR:$RHS))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000850 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000851 let Inst{31-27} = 0b11111;
852 let Inst{26-23} = 0b0100;
853 let Inst{22-20} = opcod;
854 let Inst{15-12} = 0b1111;
855 let Inst{7} = 1;
856 let Inst{5-4} = 0b00; // rotate
857 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000858 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng0e55fd62010-09-30 01:08:25 +0000859 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000860 [(set rGPR:$dst, (opnode rGPR:$LHS,
861 (rotr rGPR:$RHS, rot_imm:$rot)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +0000862 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000863 let Inst{31-27} = 0b11111;
864 let Inst{26-23} = 0b0100;
865 let Inst{22-20} = opcod;
866 let Inst{15-12} = 0b1111;
867 let Inst{7} = 1;
868 let Inst{5-4} = {?,?}; // rotate
869 }
Evan Chengd27c9fc2009-07-03 01:43:10 +0000870}
871
Johnny Chen93042d12010-03-02 18:14:57 +0000872// DO variant - disassembly only, no pattern
873
Evan Cheng0e55fd62010-09-30 01:08:25 +0000874multiclass T2I_exta_rrot_DO<bits<3> opcod, string opc> {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000875 def rr : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS), IIC_iEXTAr,
Johnny Chen93042d12010-03-02 18:14:57 +0000876 opc, "\t$dst, $LHS, $RHS", []> {
877 let Inst{31-27} = 0b11111;
878 let Inst{26-23} = 0b0100;
879 let Inst{22-20} = opcod;
880 let Inst{15-12} = 0b1111;
881 let Inst{7} = 1;
882 let Inst{5-4} = 0b00; // rotate
883 }
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000884 def rr_rot : T2I<(outs rGPR:$dst), (ins rGPR:$LHS, rGPR:$RHS, i32imm:$rot),
Evan Cheng7e1bf302010-09-29 00:27:46 +0000885 IIC_iEXTAsr, opc, "\t$dst, $LHS, $RHS, ror $rot", []> {
Johnny Chen93042d12010-03-02 18:14:57 +0000886 let Inst{31-27} = 0b11111;
887 let Inst{26-23} = 0b0100;
888 let Inst{22-20} = opcod;
889 let Inst{15-12} = 0b1111;
890 let Inst{7} = 1;
891 let Inst{5-4} = {?,?}; // rotate
892 }
893}
894
Anton Korobeynikov52237112009-06-17 18:13:58 +0000895//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000896// Instructions
897//===----------------------------------------------------------------------===//
898
899//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +0000900// Miscellaneous Instructions.
901//
902
Evan Chenga09b9ca2009-06-24 23:47:58 +0000903// LEApcrel - Load a pc-relative address into a register without offending the
904// assembler.
Evan Chengea420b22010-05-19 01:52:25 +0000905let neverHasSideEffects = 1 in {
Evan Cheng9085f982010-05-19 07:28:01 +0000906let isReMaterializable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000907def t2LEApcrel : T2XI<(outs rGPR:$dst), (ins i32imm:$label, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000908 "adr${p}.w\t$dst, #$label", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000909 let Inst{31-27} = 0b11110;
910 let Inst{25-24} = 0b10;
911 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
912 let Inst{22} = 0;
913 let Inst{20} = 0;
914 let Inst{19-16} = 0b1111; // Rn
915 let Inst{15} = 0;
916}
Jim Grosbacha967d112010-06-21 21:27:27 +0000917} // neverHasSideEffects
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000918def t2LEApcrelJT : T2XI<(outs rGPR:$dst),
Bob Wilson4f38b382009-08-21 21:58:55 +0000919 (ins i32imm:$label, nohash_imm:$id, pred:$p), IIC_iALUi,
Daniel Dunbar9db683b2010-08-11 04:46:10 +0000920 "adr${p}.w\t$dst, #${label}_${id}", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000921 let Inst{31-27} = 0b11110;
922 let Inst{25-24} = 0b10;
923 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
924 let Inst{22} = 0;
925 let Inst{20} = 0;
926 let Inst{19-16} = 0b1111; // Rn
927 let Inst{15} = 0;
928}
Evan Chenga09b9ca2009-06-24 23:47:58 +0000929
Evan Cheng86198642009-08-07 00:34:42 +0000930// ADD r, sp, {so_imm|i12}
Owen Andersonb9a643e2010-11-12 23:36:03 +0000931def t2ADDrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
932 IIC_iALUi, "add", ".w\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000933 let Inst{31-27} = 0b11110;
934 let Inst{25} = 0;
935 let Inst{24-21} = 0b1000;
936 let Inst{20} = ?; // The S bit.
Owen Andersonb9a643e2010-11-12 23:36:03 +0000937 let Inst{19-16} = 0b1101; // Rn = sp
Johnny Chend68e1192009-12-15 17:24:14 +0000938 let Inst{15} = 0;
939}
Owen Andersonb9a643e2010-11-12 23:36:03 +0000940def t2ADDrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
941 IIC_iALUi, "addw", "\t$dst, $sp, $imm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +0000942 let Inst{31-27} = 0b11110;
943 let Inst{25} = 1;
944 let Inst{24-21} = 0b0000;
945 let Inst{20} = 0; // The S bit.
946 let Inst{19-16} = 0b1101; // Rn = sp
947 let Inst{15} = 0;
948}
Evan Cheng86198642009-08-07 00:34:42 +0000949
950// ADD r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +0000951def t2ADDrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +0000952 IIC_iALUsi, "add", ".w\t$dst, $sp, $rhs", []> {
953 let Inst{31-27} = 0b11101;
954 let Inst{26-25} = 0b01;
955 let Inst{24-21} = 0b1000;
956 let Inst{20} = ?; // The S bit.
957 let Inst{19-16} = 0b1101; // Rn = sp
958 let Inst{15} = 0;
959}
Evan Cheng86198642009-08-07 00:34:42 +0000960
961// SUB r, sp, {so_imm|i12}
David Goodwin5d598aa2009-08-19 18:00:44 +0000962def t2SUBrSPi : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_imm:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +0000963 IIC_iALUi, "sub", ".w\t$dst, $sp, $imm", []> {
964 let Inst{31-27} = 0b11110;
965 let Inst{25} = 0;
966 let Inst{24-21} = 0b1101;
967 let Inst{20} = ?; // The S bit.
968 let Inst{19-16} = 0b1101; // Rn = sp
969 let Inst{15} = 0;
970}
David Goodwin5d598aa2009-08-19 18:00:44 +0000971def t2SUBrSPi12 : T2I<(outs GPR:$dst), (ins GPR:$sp, imm0_4095:$imm),
Johnny Chend68e1192009-12-15 17:24:14 +0000972 IIC_iALUi, "subw", "\t$dst, $sp, $imm", []> {
973 let Inst{31-27} = 0b11110;
974 let Inst{25} = 1;
975 let Inst{24-21} = 0b0101;
976 let Inst{20} = 0; // The S bit.
977 let Inst{19-16} = 0b1101; // Rn = sp
978 let Inst{15} = 0;
979}
Evan Cheng86198642009-08-07 00:34:42 +0000980
981// SUB r, sp, so_reg
David Goodwin5d598aa2009-08-19 18:00:44 +0000982def t2SUBrSPs : T2sI<(outs GPR:$dst), (ins GPR:$sp, t2_so_reg:$rhs),
983 IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +0000984 "sub", "\t$dst, $sp, $rhs", []> {
985 let Inst{31-27} = 0b11101;
986 let Inst{26-25} = 0b01;
987 let Inst{24-21} = 0b1101;
988 let Inst{20} = ?; // The S bit.
989 let Inst{19-16} = 0b1101; // Rn = sp
990 let Inst{15} = 0;
991}
Evan Cheng86198642009-08-07 00:34:42 +0000992
Jim Grosbachb1dc3932010-05-05 20:44:35 +0000993// Signed and unsigned division on v7-M
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000994def t2SDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +0000995 "sdiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000996 [(set rGPR:$dst, (sdiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +0000997 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +0000998 let Inst{31-27} = 0b11111;
999 let Inst{26-21} = 0b011100;
1000 let Inst{20} = 0b1;
1001 let Inst{15-12} = 0b1111;
1002 let Inst{7-4} = 0b1111;
1003}
1004
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001005def t2UDIV : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iALUi,
Jim Grosbachb1dc3932010-05-05 20:44:35 +00001006 "udiv", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001007 [(set rGPR:$dst, (udiv rGPR:$a, rGPR:$b))]>,
Jim Grosbach29402132010-05-05 23:44:43 +00001008 Requires<[HasDivide]> {
Johnny Chen93042d12010-03-02 18:14:57 +00001009 let Inst{31-27} = 0b11111;
1010 let Inst{26-21} = 0b011101;
1011 let Inst{20} = 0b1;
1012 let Inst{15-12} = 0b1111;
1013 let Inst{7-4} = 0b1111;
1014}
1015
Evan Chenga09b9ca2009-06-24 23:47:58 +00001016//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001017// Load / store Instructions.
1018//
1019
Evan Cheng055b0312009-06-29 07:51:04 +00001020// Load
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001021let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng7e2fe912010-10-28 06:47:08 +00001022defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001023 UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001024
Evan Chengf3c21b82009-06-30 02:15:48 +00001025// Loads with zero extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001026defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001027 UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001028defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001029 UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001030
Evan Chengf3c21b82009-06-30 02:15:48 +00001031// Loads with sign extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001032defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001033 UnOpFrag<(sextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001034defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001035 UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001036
Chris Lattnera1ca91a2010-11-02 23:40:41 +00001037let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
1038 isCodeGenOnly = 1 in { // $dst doesn't exist in asmstring?
Evan Chengf3c21b82009-06-30 02:15:48 +00001039// Load doubleword
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001040def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Chenge298ab22009-09-27 09:46:04 +00001041 (ins t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001042 IIC_iLoad_d_i, "ldrd", "\t$dst1, $addr", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001043def t2LDRDpci : T2Ii8s4<1, 0, 1, (outs rGPR:$dst1, rGPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001044 (ins i32imm:$addr), IIC_iLoad_d_i,
Johnny Chen83142992010-01-05 22:37:28 +00001045 "ldrd", "\t$dst1, $addr", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001046 let Inst{19-16} = 0b1111; // Rn
1047}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001048} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
Evan Chengf3c21b82009-06-30 02:15:48 +00001049
1050// zextload i1 -> zextload i8
1051def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1052 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1053def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1054 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1055def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1056 (t2LDRBs t2addrmode_so_reg:$addr)>;
1057def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1058 (t2LDRBpci tconstpool:$addr)>;
1059
1060// extload -> zextload
1061// FIXME: Reduce the number of patterns by legalizing extload to zextload
1062// earlier?
1063def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1064 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1065def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1066 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1067def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1068 (t2LDRBs t2addrmode_so_reg:$addr)>;
1069def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1070 (t2LDRBpci tconstpool:$addr)>;
1071
1072def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1073 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1074def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1075 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1076def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1077 (t2LDRBs t2addrmode_so_reg:$addr)>;
1078def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1079 (t2LDRBpci tconstpool:$addr)>;
1080
1081def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1082 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1083def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1084 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1085def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1086 (t2LDRHs t2addrmode_so_reg:$addr)>;
1087def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1088 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +00001089
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001090// FIXME: The destination register of the loads and stores can't be PC, but
1091// can be SP. We need another regclass (similar to rGPR) to represent
1092// that. Not a pressing issue since these are selected manually,
1093// not via pattern.
1094
Evan Chenge88d5ce2009-07-02 07:28:31 +00001095// Indexed loads
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001096let mayLoad = 1, neverHasSideEffects = 1 in {
Johnny Chend68e1192009-12-15 17:24:14 +00001097def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001098 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001099 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001100 "ldr", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001101 []>;
1102
Johnny Chend68e1192009-12-15 17:24:14 +00001103def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001104 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001105 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001106 "ldr", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001107 []>;
1108
Johnny Chend68e1192009-12-15 17:24:14 +00001109def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001110 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001111 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001112 "ldrb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001113 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001114def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001115 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001116 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001117 "ldrb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001118 []>;
1119
Johnny Chend68e1192009-12-15 17:24:14 +00001120def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001121 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001122 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001123 "ldrh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001124 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001125def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001126 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001127 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001128 "ldrh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001129 []>;
1130
Johnny Chend68e1192009-12-15 17:24:14 +00001131def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001132 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001133 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001134 "ldrsb", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001135 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001136def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001137 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001138 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001139 "ldrsb", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001140 []>;
1141
Johnny Chend68e1192009-12-15 17:24:14 +00001142def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001143 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001144 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001145 "ldrsh", "\t$dst, $addr!", "$addr.base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001146 []>;
Johnny Chend68e1192009-12-15 17:24:14 +00001147def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$dst, GPR:$base_wb),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001148 (ins GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001149 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001150 "ldrsh", "\t$dst, [$base], $offset", "$base = $base_wb",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001151 []>;
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001152} // mayLoad = 1, neverHasSideEffects = 1
Evan Cheng4fbb9962009-07-02 23:16:11 +00001153
Johnny Chene54a3ef2010-03-03 18:45:36 +00001154// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1155// for disassembly only.
1156// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001157class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
1158 : T2Ii8<(outs GPR:$dst), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001159 "\t$dst, $addr", []> {
1160 let Inst{31-27} = 0b11111;
1161 let Inst{26-25} = 0b00;
1162 let Inst{24} = signed;
1163 let Inst{23} = 0;
1164 let Inst{22-21} = type;
1165 let Inst{20} = 1; // load
1166 let Inst{11} = 1;
1167 let Inst{10-8} = 0b110; // PUW.
1168}
1169
Evan Cheng0e55fd62010-09-30 01:08:25 +00001170def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1171def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1172def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1173def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1174def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001175
David Goodwin73b8f162009-06-30 22:11:34 +00001176// Store
Evan Cheng7e2fe912010-10-28 06:47:08 +00001177defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001178 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001179defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001180 BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001181defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001182 BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +00001183
David Goodwin6647cea2009-06-30 22:50:01 +00001184// Store doubleword
Chris Lattnera1ca91a2010-11-02 23:40:41 +00001185let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1186 isCodeGenOnly = 1 in // $src2 doesn't exist in asm string
Johnny Chend68e1192009-12-15 17:24:14 +00001187def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
Evan Chenge298ab22009-09-27 09:46:04 +00001188 (ins GPR:$src1, GPR:$src2, t2addrmode_imm8s4:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001189 IIC_iStore_d_r, "strd", "\t$src1, $addr", []>;
David Goodwin6647cea2009-06-30 22:50:01 +00001190
Evan Cheng6d94f112009-07-03 00:06:39 +00001191// Indexed stores
Johnny Chend68e1192009-12-15 17:24:14 +00001192def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001193 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001194 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001195 "str", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001196 [(set GPR:$base_wb,
1197 (pre_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1198
Johnny Chend68e1192009-12-15 17:24:14 +00001199def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001200 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001201 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001202 "str", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001203 [(set GPR:$base_wb,
Jim Grosbach6935efc2009-11-24 00:20:27 +00001204 (post_store GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001205
Johnny Chend68e1192009-12-15 17:24:14 +00001206def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001207 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001208 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001209 "strh", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001210 [(set GPR:$base_wb,
1211 (pre_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1212
Johnny Chend68e1192009-12-15 17:24:14 +00001213def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001214 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001215 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001216 "strh", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001217 [(set GPR:$base_wb,
1218 (post_truncsti16 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1219
Johnny Chend68e1192009-12-15 17:24:14 +00001220def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001221 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001222 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001223 "strb", "\t$src, [$base, $offset]!", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001224 [(set GPR:$base_wb,
1225 (pre_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1226
Johnny Chend68e1192009-12-15 17:24:14 +00001227def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPR:$base_wb),
Evan Cheng6d94f112009-07-03 00:06:39 +00001228 (ins GPR:$src, GPR:$base, t2am_imm8_offset:$offset),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001229 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Evan Cheng699beba2009-10-27 00:08:59 +00001230 "strb", "\t$src, [$base], $offset", "$base = $base_wb",
Evan Cheng6d94f112009-07-03 00:06:39 +00001231 [(set GPR:$base_wb,
1232 (post_truncsti8 GPR:$src, GPR:$base, t2am_imm8_offset:$offset))]>;
1233
Johnny Chene54a3ef2010-03-03 18:45:36 +00001234// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1235// only.
1236// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001237class T2IstT<bits<2> type, string opc, InstrItinClass ii>
1238 : T2Ii8<(outs GPR:$src), (ins t2addrmode_imm8:$addr), ii, opc,
Johnny Chene54a3ef2010-03-03 18:45:36 +00001239 "\t$src, $addr", []> {
1240 let Inst{31-27} = 0b11111;
1241 let Inst{26-25} = 0b00;
1242 let Inst{24} = 0; // not signed
1243 let Inst{23} = 0;
1244 let Inst{22-21} = type;
1245 let Inst{20} = 0; // store
1246 let Inst{11} = 1;
1247 let Inst{10-8} = 0b110; // PUW
1248}
1249
Evan Cheng0e55fd62010-09-30 01:08:25 +00001250def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1251def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1252def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
David Goodwind1fa1202009-07-01 00:01:13 +00001253
Johnny Chenae1757b2010-03-11 01:13:36 +00001254// ldrd / strd pre / post variants
1255// For disassembly only.
1256
1257def t2LDRD_PRE : T2Ii8s4<1, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001258 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001259 "ldrd", "\t$dst1, $dst2, [$base, $imm]!", []>;
1260
1261def t2LDRD_POST : T2Ii8s4<0, 1, 1, (outs GPR:$dst1, GPR:$dst2),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001262 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Johnny Chenae1757b2010-03-11 01:13:36 +00001263 "ldrd", "\t$dst1, $dst2, [$base], $imm", []>;
1264
1265def t2STRD_PRE : T2Ii8s4<1, 1, 0, (outs),
1266 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001267 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base, $imm]!", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001268
1269def t2STRD_POST : T2Ii8s4<0, 1, 0, (outs),
1270 (ins GPR:$src1, GPR:$src2, GPR:$base, t2am_imm8s4_offset:$imm),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001271 IIC_iStore_d_ru, "strd", "\t$src1, $src2, [$base], $imm", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +00001272
Johnny Chen0635fc52010-03-04 17:40:44 +00001273// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1274// data/instruction access. These are for disassembly only.
Evan Chengdfed19f2010-11-03 06:34:55 +00001275// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1276// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
Evan Cheng416941d2010-11-04 05:19:35 +00001277multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001278
Evan Chengdfed19f2010-11-03 06:34:55 +00001279 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001280 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001281 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001282 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001283 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001284 let Inst{23} = 1; // U = 1
1285 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001286 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001287 let Inst{20} = 1;
1288 let Inst{15-12} = 0b1111;
1289 }
1290
Evan Chengdfed19f2010-11-03 06:34:55 +00001291 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001292 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001293 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001294 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001295 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001296 let Inst{23} = 0; // U = 0
1297 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001298 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001299 let Inst{20} = 1;
1300 let Inst{15-12} = 0b1111;
1301 let Inst{11-8} = 0b1100;
1302 }
1303
Evan Chengdfed19f2010-11-03 06:34:55 +00001304 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001305 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001306 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
Evan Chengbc7deb02010-11-03 05:14:24 +00001307 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001308 let Inst{24} = instr;
Evan Chengbc7deb02010-11-03 05:14:24 +00001309 let Inst{23} = 0; // add = TRUE for T1
1310 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001311 let Inst{21} = write;
Evan Chengbc7deb02010-11-03 05:14:24 +00001312 let Inst{20} = 1;
1313 let Inst{15-12} = 0b1111;
1314 let Inst{11-6} = 0000000;
1315 }
1316
1317 let isCodeGenOnly = 1 in
Evan Chengdfed19f2010-11-03 06:34:55 +00001318 def pci : T2Ipc<(outs), (ins i32imm:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001319 "\t$addr",
1320 []> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001321 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001322 let Inst{24} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001323 let Inst{23} = ?; // add = (U == 1)
1324 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001325 let Inst{21} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001326 let Inst{20} = 1;
1327 let Inst{19-16} = 0b1111; // Rn = 0b1111
1328 let Inst{15-12} = 0b1111;
1329 }
Johnny Chen0635fc52010-03-04 17:40:44 +00001330}
1331
Evan Cheng416941d2010-11-04 05:19:35 +00001332defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1333defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1334defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
Johnny Chen0635fc52010-03-04 17:40:44 +00001335
Evan Cheng2889cce2009-07-03 00:18:36 +00001336//===----------------------------------------------------------------------===//
1337// Load / store multiple Instructions.
1338//
1339
Bill Wendling6c470b82010-11-13 09:09:38 +00001340multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1341 InstrItinClass itin_upd, bit L_bit> {
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001342 def ia :
Bill Wendling6c470b82010-11-13 09:09:38 +00001343 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1344 itin, !strconcat(asm, "${p}.w\t$Rn, $regs"), []> {
1345 bits<4> Rn;
1346 bits<16> regs;
1347
1348 let Inst{31-27} = 0b11101;
1349 let Inst{26-25} = 0b00;
1350 let Inst{24-23} = 0b01; // Increment After
1351 let Inst{22} = 0;
1352 let Inst{21} = 0; // No writeback
1353 let Inst{20} = L_bit;
1354 let Inst{19-16} = Rn;
1355 let Inst{15-0} = regs;
1356 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001357 def ia_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001358 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1359 itin_upd, !strconcat(asm, "${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
1360 bits<4> Rn;
1361 bits<16> regs;
1362
1363 let Inst{31-27} = 0b11101;
1364 let Inst{26-25} = 0b00;
1365 let Inst{24-23} = 0b01; // Increment After
1366 let Inst{22} = 0;
1367 let Inst{21} = 1; // Writeback
1368 let Inst{20} = L_bit;
1369 let Inst{19-16} = Rn;
1370 let Inst{15-0} = regs;
1371 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001372 def db :
Bill Wendling6c470b82010-11-13 09:09:38 +00001373 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1374 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1375 bits<4> Rn;
1376 bits<16> regs;
1377
1378 let Inst{31-27} = 0b11101;
1379 let Inst{26-25} = 0b00;
1380 let Inst{24-23} = 0b10; // Decrement Before
1381 let Inst{22} = 0;
1382 let Inst{21} = 0; // No writeback
1383 let Inst{20} = L_bit;
1384 let Inst{19-16} = Rn;
1385 let Inst{15-0} = regs;
1386 }
Bill Wendling1f4abcf2010-11-13 10:43:34 +00001387 def db_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001388 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1389 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1390 bits<4> Rn;
1391 bits<16> regs;
1392
1393 let Inst{31-27} = 0b11101;
1394 let Inst{26-25} = 0b00;
1395 let Inst{24-23} = 0b10; // Decrement Before
1396 let Inst{22} = 0;
1397 let Inst{21} = 1; // Writeback
1398 let Inst{20} = L_bit;
1399 let Inst{19-16} = Rn;
1400 let Inst{15-0} = regs;
1401 }
1402}
1403
Bill Wendlingc93989a2010-11-13 11:20:05 +00001404/* TODO:
1405let neverHasSideEffects = 1 in {
Bill Wendlingddc918b2010-11-13 10:57:02 +00001406
1407let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1408defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1409
1410let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1411defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1412
1413} // neverHasSideEffects
Bill Wendlingc93989a2010-11-13 11:20:05 +00001414*/
Bill Wendlingddc918b2010-11-13 10:57:02 +00001415
Chris Lattner39ee0362010-10-31 19:10:56 +00001416let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1,
1417 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001418def t2LDM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001419 reglist:$dsts, variable_ops), IIC_iLoad_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001420 "ldm${amode}${p}.w\t$Rn, $dsts", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001421 let Inst{31-27} = 0b11101;
1422 let Inst{26-25} = 0b00;
1423 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1424 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001425 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001426 let Inst{20} = 1; // Load
1427}
Evan Cheng2889cce2009-07-03 00:18:36 +00001428
Jim Grosbache6913602010-11-03 01:01:43 +00001429def t2LDM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001430 reglist:$dsts, variable_ops),
1431 IIC_iLoad_mu,
Jim Grosbache6913602010-11-03 01:01:43 +00001432 "ldm${amode}${p}.w\t$Rn!, $dsts",
1433 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001434 let Inst{31-27} = 0b11101;
1435 let Inst{26-25} = 0b00;
1436 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1437 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00001438 let Inst{21} = 1; // The W bit.
1439 let Inst{20} = 1; // Load
1440}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001441} // mayLoad, neverHasSideEffects, hasExtraDefRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001442
Chris Lattner39ee0362010-10-31 19:10:56 +00001443let mayStore = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1,
1444 isCodeGenOnly = 1 in {
Jim Grosbache6913602010-11-03 01:01:43 +00001445def t2STM : T2XI<(outs), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Evan Chenga0792de2010-10-06 06:27:31 +00001446 reglist:$srcs, variable_ops), IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001447 "stm${amode}${p}.w\t$Rn, $srcs", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001448 let Inst{31-27} = 0b11101;
1449 let Inst{26-25} = 0b00;
1450 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1451 let Inst{22} = 0;
1452 let Inst{21} = 0; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00001453 let Inst{20} = 0; // Store
1454}
Evan Cheng2889cce2009-07-03 00:18:36 +00001455
Jim Grosbache6913602010-11-03 01:01:43 +00001456def t2STM_UPD : T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
Bob Wilson815baeb2010-03-13 01:08:20 +00001457 reglist:$srcs, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00001458 IIC_iStore_m,
Jim Grosbache6913602010-11-03 01:01:43 +00001459 "stm${amode}${p}.w\t$Rn!, $srcs",
1460 "$Rn = $wb", []> {
Bob Wilson815baeb2010-03-13 01:08:20 +00001461 let Inst{31-27} = 0b11101;
1462 let Inst{26-25} = 0b00;
1463 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
1464 let Inst{22} = 0;
1465 let Inst{21} = 1; // The W bit.
1466 let Inst{20} = 0; // Store
1467}
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001468} // mayStore, neverHasSideEffects, hasExtraSrcRegAllocReq
Bob Wilson815baeb2010-03-13 01:08:20 +00001469
Evan Cheng9cb9e672009-06-27 02:26:13 +00001470//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001471// Move Instructions.
1472//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001473
Evan Chengf49810c2009-06-23 17:48:47 +00001474let neverHasSideEffects = 1 in
David Goodwin5d598aa2009-08-19 18:00:44 +00001475def t2MOVr : T2sI<(outs GPR:$dst), (ins GPR:$src), IIC_iMOVr,
Johnny Chend68e1192009-12-15 17:24:14 +00001476 "mov", ".w\t$dst, $src", []> {
1477 let Inst{31-27} = 0b11101;
1478 let Inst{26-25} = 0b01;
1479 let Inst{24-21} = 0b0010;
1480 let Inst{20} = ?; // The S bit.
1481 let Inst{19-16} = 0b1111; // Rn
1482 let Inst{14-12} = 0b000;
1483 let Inst{7-4} = 0b0000;
1484}
Evan Chengf49810c2009-06-23 17:48:47 +00001485
Evan Cheng5adb66a2009-09-28 09:14:39 +00001486// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
1487let isReMaterializable = 1, isAsCheapAsAMove = 1, AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001488def t2MOVi : T2sI<(outs rGPR:$dst), (ins t2_so_imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001489 "mov", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001490 [(set rGPR:$dst, t2_so_imm:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001491 let Inst{31-27} = 0b11110;
1492 let Inst{25} = 0;
1493 let Inst{24-21} = 0b0010;
1494 let Inst{20} = ?; // The S bit.
1495 let Inst{19-16} = 0b1111; // Rn
1496 let Inst{15} = 0;
1497}
David Goodwin83b35932009-06-26 16:10:07 +00001498
1499let isReMaterializable = 1, isAsCheapAsAMove = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001500def t2MOVi16 : T2I<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001501 "movw", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001502 [(set rGPR:$dst, imm0_65535:$src)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001503 let Inst{31-27} = 0b11110;
1504 let Inst{25} = 1;
1505 let Inst{24-21} = 0b0010;
1506 let Inst{20} = 0; // The S bit.
1507 let Inst{15} = 0;
1508}
Evan Chengf49810c2009-06-23 17:48:47 +00001509
Evan Cheng3850a6a2009-06-23 05:23:49 +00001510let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001511def t2MOVTi16 : T2I<(outs rGPR:$dst), (ins rGPR:$src, i32imm:$imm), IIC_iMOVi,
Evan Cheng699beba2009-10-27 00:08:59 +00001512 "movt", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001513 [(set rGPR:$dst,
1514 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001515 let Inst{31-27} = 0b11110;
1516 let Inst{25} = 1;
1517 let Inst{24-21} = 0b0110;
1518 let Inst{20} = 0; // The S bit.
1519 let Inst{15} = 0;
1520}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001521
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001522def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
Evan Cheng20956592009-10-21 08:15:52 +00001523
Anton Korobeynikov52237112009-06-17 18:13:58 +00001524//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +00001525// Extend Instructions.
1526//
1527
1528// Sign extenders
1529
Evan Cheng0e55fd62010-09-30 01:08:25 +00001530defm t2SXTB : T2I_ext_rrot<0b100, "sxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001531 UnOpFrag<(sext_inreg node:$Src, i8)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001532defm t2SXTH : T2I_ext_rrot<0b000, "sxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001533 UnOpFrag<(sext_inreg node:$Src, i16)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001534defm t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001535
Evan Cheng0e55fd62010-09-30 01:08:25 +00001536defm t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001537 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001538defm t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001539 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001540defm t2SXTAB16 : T2I_exta_rrot_DO<0b010, "sxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001541
Johnny Chen93042d12010-03-02 18:14:57 +00001542// TODO: SXT(A){B|H}16 - done for disassembly only
Evan Chengd27c9fc2009-07-03 01:43:10 +00001543
1544// Zero extenders
1545
1546let AddedComplexity = 16 in {
Evan Cheng0e55fd62010-09-30 01:08:25 +00001547defm t2UXTB : T2I_ext_rrot<0b101, "uxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001548 UnOpFrag<(and node:$Src, 0x000000FF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001549defm t2UXTH : T2I_ext_rrot<0b001, "uxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001550 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001551defm t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
Johnny Chend68e1192009-12-15 17:24:14 +00001552 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001553
Jim Grosbach79464942010-07-28 23:17:45 +00001554// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1555// The transformation should probably be done as a combiner action
1556// instead so we can include a check for masking back in the upper
1557// eight bits of the source into the lower eight bits of the result.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001558//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001559// (t2UXTB16r_rot rGPR:$Src, 24)>,
1560// Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001561def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001562 (t2UXTB16r_rot rGPR:$Src, 8)>,
1563 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001564
Evan Cheng0e55fd62010-09-30 01:08:25 +00001565defm t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001566 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001567defm t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001568 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Evan Cheng0e55fd62010-09-30 01:08:25 +00001569defm t2UXTAB16 : T2I_exta_rrot_DO<0b011, "uxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001570}
1571
1572//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001573// Arithmetic Instructions.
1574//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001575
Johnny Chend68e1192009-12-15 17:24:14 +00001576defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1577 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1578defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1579 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001580
Evan Chengf49810c2009-06-23 17:48:47 +00001581// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Johnny Chend68e1192009-12-15 17:24:14 +00001582defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001583 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001584 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1585defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001586 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001587 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001588
Johnny Chend68e1192009-12-15 17:24:14 +00001589defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001590 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001591defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001592 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001593defm t2ADCS : T2I_adde_sube_s_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001594 BinOpFrag<(adde_live_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chenb5031ad2010-03-02 19:38:59 +00001595defm t2SBCS : T2I_adde_sube_s_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001596 BinOpFrag<(sube_live_carry node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001597
David Goodwin752aa7d2009-07-27 16:39:05 +00001598// RSB
Bob Wilson20d8e4e2010-08-13 23:24:25 +00001599defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
Johnny Chend68e1192009-12-15 17:24:14 +00001600 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1601defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1602 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001603
1604// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001605// The assume-no-carry-in form uses the negation of the input since add/sub
1606// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1607// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1608// details.
1609// The AddedComplexity preferences the first variant over the others since
1610// it can be shrunk to a 16-bit wide encoding, while the others cannot.
Evan Chengfa2ea1a2009-08-04 01:41:15 +00001611let AddedComplexity = 1 in
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001612def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1613 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1614def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1615 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1616def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1617 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1618let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001619def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1620 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1621def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1622 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001623// The with-carry-in form matches bitwise not instead of the negation.
1624// Effectively, the inverse interpretation of the carry flag already accounts
1625// for part of the negation.
1626let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001627def : T2Pat<(adde rGPR:$src, imm0_255_not:$imm),
1628 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
1629def : T2Pat<(adde rGPR:$src, t2_so_imm_not:$imm),
1630 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001631
Johnny Chen93042d12010-03-02 18:14:57 +00001632// Select Bytes -- for disassembly only
1633
1634def t2SEL : T2I<(outs GPR:$dst), (ins GPR:$a, GPR:$b), NoItinerary, "sel",
1635 "\t$dst, $a, $b", []> {
1636 let Inst{31-27} = 0b11111;
1637 let Inst{26-24} = 0b010;
1638 let Inst{23} = 0b1;
1639 let Inst{22-20} = 0b010;
1640 let Inst{15-12} = 0b1111;
1641 let Inst{7} = 0b1;
1642 let Inst{6-4} = 0b000;
1643}
1644
Johnny Chenadc77332010-02-26 22:04:29 +00001645// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1646// And Miscellaneous operations -- for disassembly only
Nate Begeman692433b2010-07-29 17:56:55 +00001647class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
1648 list<dag> pat = [/* For disassembly only; pattern left blank */]>
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001649 : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), NoItinerary, opc,
Nate Begeman692433b2010-07-29 17:56:55 +00001650 "\t$dst, $a, $b", pat> {
Johnny Chenadc77332010-02-26 22:04:29 +00001651 let Inst{31-27} = 0b11111;
1652 let Inst{26-23} = 0b0101;
1653 let Inst{22-20} = op22_20;
1654 let Inst{15-12} = 0b1111;
1655 let Inst{7-4} = op7_4;
1656}
1657
1658// Saturating add/subtract -- for disassembly only
1659
Nate Begeman692433b2010-07-29 17:56:55 +00001660def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001661 [(set rGPR:$dst, (int_arm_qadd rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001662def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1663def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1664def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
1665def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd">;
1666def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub">;
1667def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
Nate Begeman692433b2010-07-29 17:56:55 +00001668def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001669 [(set rGPR:$dst, (int_arm_qsub rGPR:$a, rGPR:$b))]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001670def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1671def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1672def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1673def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1674def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1675def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1676def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1677def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1678
1679// Signed/Unsigned add/subtract -- for disassembly only
1680
1681def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1682def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1683def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1684def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1685def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1686def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1687def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1688def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1689def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1690def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1691def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1692def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1693
1694// Signed/Unsigned halving add/subtract -- for disassembly only
1695
1696def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1697def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1698def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1699def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1700def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1701def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1702def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1703def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1704def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1705def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1706def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1707def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1708
1709// Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1710
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001711def t2USAD8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1712 (ins rGPR:$a, rGPR:$b),
Johnny Chenadc77332010-02-26 22:04:29 +00001713 NoItinerary, "usad8", "\t$dst, $a, $b", []> {
1714 let Inst{15-12} = 0b1111;
1715}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001716def t2USADA8 : T2I_mac<0, 0b111, 0b0000, (outs rGPR:$dst),
1717 (ins rGPR:$a, rGPR:$b, rGPR:$acc), NoItinerary, "usada8",
Johnny Chenadc77332010-02-26 22:04:29 +00001718 "\t$dst, $a, $b, $acc", []>;
1719
1720// Signed/Unsigned saturate -- for disassembly only
1721
Bob Wilson22f5dc72010-08-16 18:27:34 +00001722def t2SSAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001723 NoItinerary, "ssat", "\t$dst, $bit_pos, $a$sh",
1724 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001725 let Inst{31-27} = 0b11110;
1726 let Inst{25-22} = 0b1100;
1727 let Inst{20} = 0;
1728 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001729}
1730
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001731def t2SSAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001732 "ssat16", "\t$dst, $bit_pos, $a",
1733 [/* For disassembly only; pattern left blank */]> {
1734 let Inst{31-27} = 0b11110;
1735 let Inst{25-22} = 0b1100;
1736 let Inst{20} = 0;
1737 let Inst{15} = 0;
1738 let Inst{21} = 1; // sh = '1'
1739 let Inst{14-12} = 0b000; // imm3 = '000'
1740 let Inst{7-6} = 0b00; // imm2 = '00'
1741}
1742
Bob Wilson22f5dc72010-08-16 18:27:34 +00001743def t2USAT: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a, shift_imm:$sh),
Bob Wilson38aa2872010-08-13 21:48:10 +00001744 NoItinerary, "usat", "\t$dst, $bit_pos, $a$sh",
1745 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001746 let Inst{31-27} = 0b11110;
1747 let Inst{25-22} = 0b1110;
1748 let Inst{20} = 0;
1749 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001750}
1751
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001752def t2USAT16: T2I<(outs rGPR:$dst), (ins i32imm:$bit_pos, rGPR:$a), NoItinerary,
Johnny Chenadc77332010-02-26 22:04:29 +00001753 "usat16", "\t$dst, $bit_pos, $a",
1754 [/* For disassembly only; pattern left blank */]> {
1755 let Inst{31-27} = 0b11110;
1756 let Inst{25-22} = 0b1110;
1757 let Inst{20} = 0;
1758 let Inst{15} = 0;
1759 let Inst{21} = 1; // sh = '1'
1760 let Inst{14-12} = 0b000; // imm3 = '000'
1761 let Inst{7-6} = 0b00; // imm2 = '00'
1762}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001763
Bob Wilson38aa2872010-08-13 21:48:10 +00001764def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
1765def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
Nate Begeman0e0a20e2010-07-29 22:48:09 +00001766
Evan Chengf49810c2009-06-23 17:48:47 +00001767//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +00001768// Shift and rotate Instructions.
1769//
1770
Johnny Chend68e1192009-12-15 17:24:14 +00001771defm t2LSL : T2I_sh_ir<0b00, "lsl", BinOpFrag<(shl node:$LHS, node:$RHS)>>;
1772defm t2LSR : T2I_sh_ir<0b01, "lsr", BinOpFrag<(srl node:$LHS, node:$RHS)>>;
1773defm t2ASR : T2I_sh_ir<0b10, "asr", BinOpFrag<(sra node:$LHS, node:$RHS)>>;
1774defm t2ROR : T2I_sh_ir<0b11, "ror", BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
Evan Chenga67efd12009-06-23 19:39:13 +00001775
David Goodwinca01a8d2009-09-01 18:32:09 +00001776let Uses = [CPSR] in {
Jim Grosbach792e9792010-10-14 20:43:44 +00001777def t2RRX : T2sI<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Evan Cheng699beba2009-10-27 00:08:59 +00001778 "rrx", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001779 [(set rGPR:$dst, (ARMrrx rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001780 let Inst{31-27} = 0b11101;
1781 let Inst{26-25} = 0b01;
1782 let Inst{24-21} = 0b0010;
1783 let Inst{20} = ?; // The S bit.
1784 let Inst{19-16} = 0b1111; // Rn
1785 let Inst{14-12} = 0b000;
1786 let Inst{7-4} = 0b0011;
1787}
David Goodwinca01a8d2009-09-01 18:32:09 +00001788}
Evan Chenga67efd12009-06-23 19:39:13 +00001789
David Goodwin3583df72009-07-28 17:06:49 +00001790let Defs = [CPSR] in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001791def t2MOVsrl_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001792 "lsrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001793 [(set rGPR:$dst, (ARMsrl_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001794 let Inst{31-27} = 0b11101;
1795 let Inst{26-25} = 0b01;
1796 let Inst{24-21} = 0b0010;
1797 let Inst{20} = 1; // The S bit.
1798 let Inst{19-16} = 0b1111; // Rn
1799 let Inst{5-4} = 0b01; // Shift type.
1800 // Shift amount = Inst{14-12:7-6} = 1.
1801 let Inst{14-12} = 0b000;
1802 let Inst{7-6} = 0b01;
1803}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001804def t2MOVsra_flag : T2I<(outs rGPR:$dst), (ins rGPR:$src), IIC_iMOVsi,
Bob Wilsona85df802010-05-25 04:51:47 +00001805 "asrs", ".w\t$dst, $src, #1",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001806 [(set rGPR:$dst, (ARMsra_flag rGPR:$src))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001807 let Inst{31-27} = 0b11101;
1808 let Inst{26-25} = 0b01;
1809 let Inst{24-21} = 0b0010;
1810 let Inst{20} = 1; // The S bit.
1811 let Inst{19-16} = 0b1111; // Rn
1812 let Inst{5-4} = 0b10; // Shift type.
1813 // Shift amount = Inst{14-12:7-6} = 1.
1814 let Inst{14-12} = 0b000;
1815 let Inst{7-6} = 0b01;
1816}
David Goodwin3583df72009-07-28 17:06:49 +00001817}
1818
Evan Chenga67efd12009-06-23 19:39:13 +00001819//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00001820// Bitwise Instructions.
1821//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001822
Johnny Chend68e1192009-12-15 17:24:14 +00001823defm t2AND : T2I_bin_w_irs<0b0000, "and",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001824 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001825 BinOpFrag<(and node:$LHS, node:$RHS)>, 1>;
1826defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001827 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001828 BinOpFrag<(or node:$LHS, node:$RHS)>, 1>;
1829defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001830 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001831 BinOpFrag<(xor node:$LHS, node:$RHS)>, 1>;
Evan Chengf49810c2009-06-23 17:48:47 +00001832
Johnny Chend68e1192009-12-15 17:24:14 +00001833defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001834 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001835 BinOpFrag<(and node:$LHS, (not node:$RHS))>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001836
Evan Chengf49810c2009-06-23 17:48:47 +00001837let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001838def t2BFC : T2I<(outs rGPR:$dst), (ins rGPR:$src, bf_inv_mask_imm:$imm),
David Goodwin2f54a2f2009-11-02 17:28:36 +00001839 IIC_iUNAsi, "bfc", "\t$dst, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001840 [(set rGPR:$dst, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001841 let Inst{31-27} = 0b11110;
1842 let Inst{25} = 1;
1843 let Inst{24-20} = 0b10110;
1844 let Inst{19-16} = 0b1111; // Rn
1845 let Inst{15} = 0;
1846}
Evan Chengf49810c2009-06-23 17:48:47 +00001847
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001848def t2SBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001849 IIC_iUNAsi, "sbfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001850 let Inst{31-27} = 0b11110;
1851 let Inst{25} = 1;
1852 let Inst{24-20} = 0b10100;
1853 let Inst{15} = 0;
1854}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001855
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001856def t2UBFX: T2I<(outs rGPR:$dst), (ins rGPR:$src, imm0_31:$lsb, imm0_31:$width),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001857 IIC_iUNAsi, "ubfx", "\t$dst, $src, $lsb, $width", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001858 let Inst{31-27} = 0b11110;
1859 let Inst{25} = 1;
1860 let Inst{24-20} = 0b11100;
1861 let Inst{15} = 0;
1862}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00001863
Johnny Chen9474d552010-02-02 19:31:58 +00001864// A8.6.18 BFI - Bitfield insert (Encoding T1)
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001865let Constraints = "$src = $dst" in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001866def t2BFI : T2I<(outs rGPR:$dst),
1867 (ins rGPR:$src, rGPR:$val, bf_inv_mask_imm:$imm),
Evan Cheng7e1bf302010-09-29 00:27:46 +00001868 IIC_iBITi, "bfi", "\t$dst, $val, $imm",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001869 [(set rGPR:$dst, (ARMbfi rGPR:$src, rGPR:$val,
Jim Grosbach469bbdb2010-07-16 23:05:05 +00001870 bf_inv_mask_imm:$imm))]> {
Johnny Chen9474d552010-02-02 19:31:58 +00001871 let Inst{31-27} = 0b11110;
1872 let Inst{25} = 1;
1873 let Inst{24-20} = 0b10110;
1874 let Inst{15} = 0;
1875}
Evan Chengf49810c2009-06-23 17:48:47 +00001876
Evan Cheng7e1bf302010-09-29 00:27:46 +00001877defm t2ORN : T2I_bin_irs<0b0011, "orn",
1878 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
1879 BinOpFrag<(or node:$LHS, (not node:$RHS))>, 0, "">;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001880
1881// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
1882let AddedComplexity = 1 in
Evan Cheng5d42c562010-09-29 00:49:25 +00001883defm t2MVN : T2I_un_irs <0b0011, "mvn",
Evan Cheng3881cb72010-09-29 22:42:35 +00001884 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
Evan Cheng5d42c562010-09-29 00:49:25 +00001885 UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001886
1887
Jim Grosbachf084a5e2010-07-20 16:07:04 +00001888let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001889def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
1890 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001891
Evan Cheng25f7cfc2009-08-01 06:13:52 +00001892// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001893def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
1894 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
Evan Chengea253b92009-08-12 01:56:42 +00001895 Requires<[IsThumb2]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00001896
1897def : T2Pat<(t2_so_imm_not:$src),
1898 (t2MVNi t2_so_imm_not:$src)>;
1899
Evan Chengf49810c2009-06-23 17:48:47 +00001900//===----------------------------------------------------------------------===//
1901// Multiply Instructions.
1902//
Evan Cheng8de898a2009-06-26 00:19:44 +00001903let isCommutable = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001904def t2MUL: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00001905 "mul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001906 [(set rGPR:$dst, (mul rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001907 let Inst{31-27} = 0b11111;
1908 let Inst{26-23} = 0b0110;
1909 let Inst{22-20} = 0b000;
1910 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1911 let Inst{7-4} = 0b0000; // Multiply
1912}
Evan Chengf49810c2009-06-23 17:48:47 +00001913
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001914def t2MLA: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001915 "mla", "\t$dst, $a, $b, $c",
1916 [(set rGPR:$dst, (add (mul rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001917 let Inst{31-27} = 0b11111;
1918 let Inst{26-23} = 0b0110;
1919 let Inst{22-20} = 0b000;
1920 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1921 let Inst{7-4} = 0b0000; // Multiply
1922}
Evan Chengf49810c2009-06-23 17:48:47 +00001923
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001924def t2MLS: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Jim Grosbachf38bfd12010-10-29 23:23:15 +00001925 "mls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001926 [(set rGPR:$dst, (sub rGPR:$c, (mul rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001927 let Inst{31-27} = 0b11111;
1928 let Inst{26-23} = 0b0110;
1929 let Inst{22-20} = 0b000;
1930 let Inst{15-12} = {?, ?, ?, ?}; // Ra
1931 let Inst{7-4} = 0b0001; // Multiply and Subtract
1932}
Evan Chengf49810c2009-06-23 17:48:47 +00001933
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001934// Extra precision multiplies with low / high results
1935let neverHasSideEffects = 1 in {
1936let isCommutable = 1 in {
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001937def t2SMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1938 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00001939 "smull", "\t$ldst, $hdst, $a, $b", []> {
1940 let Inst{31-27} = 0b11111;
1941 let Inst{26-23} = 0b0111;
1942 let Inst{22-20} = 0b000;
1943 let Inst{7-4} = 0b0000;
1944}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001945
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001946def t2UMULL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1947 (ins rGPR:$a, rGPR:$b), IIC_iMUL64,
Johnny Chend68e1192009-12-15 17:24:14 +00001948 "umull", "\t$ldst, $hdst, $a, $b", []> {
1949 let Inst{31-27} = 0b11111;
1950 let Inst{26-23} = 0b0111;
1951 let Inst{22-20} = 0b010;
1952 let Inst{7-4} = 0b0000;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001953}
Johnny Chend68e1192009-12-15 17:24:14 +00001954} // isCommutable
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001955
1956// Multiply + accumulate
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001957def t2SMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1958 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001959 "smlal", "\t$ldst, $hdst, $a, $b", []>{
1960 let Inst{31-27} = 0b11111;
1961 let Inst{26-23} = 0b0111;
1962 let Inst{22-20} = 0b100;
1963 let Inst{7-4} = 0b0000;
1964}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001965
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001966def t2UMLAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1967 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001968 "umlal", "\t$ldst, $hdst, $a, $b", []>{
1969 let Inst{31-27} = 0b11111;
1970 let Inst{26-23} = 0b0111;
1971 let Inst{22-20} = 0b110;
1972 let Inst{7-4} = 0b0000;
1973}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001974
Jim Grosbachc5ed0132010-08-17 18:39:16 +00001975def t2UMAAL : T2I<(outs rGPR:$ldst, rGPR:$hdst),
1976 (ins rGPR:$a, rGPR:$b), IIC_iMAC64,
Johnny Chend68e1192009-12-15 17:24:14 +00001977 "umaal", "\t$ldst, $hdst, $a, $b", []>{
1978 let Inst{31-27} = 0b11111;
1979 let Inst{26-23} = 0b0111;
1980 let Inst{22-20} = 0b110;
1981 let Inst{7-4} = 0b0110;
1982}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001983} // neverHasSideEffects
1984
Johnny Chen93042d12010-03-02 18:14:57 +00001985// Rounding variants of the below included for disassembly only
1986
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001987// Most significant word multiply
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001988def t2SMMUL : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Evan Cheng699beba2009-10-27 00:08:59 +00001989 "smmul", "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001990 [(set rGPR:$dst, (mulhs rGPR:$a, rGPR:$b))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001991 let Inst{31-27} = 0b11111;
1992 let Inst{26-23} = 0b0110;
1993 let Inst{22-20} = 0b101;
1994 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
1995 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
1996}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00001997
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001998def t2SMMULR : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL32,
Johnny Chen93042d12010-03-02 18:14:57 +00001999 "smmulr", "\t$dst, $a, $b", []> {
2000 let Inst{31-27} = 0b11111;
2001 let Inst{26-23} = 0b0110;
2002 let Inst{22-20} = 0b101;
2003 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2004 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2005}
2006
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002007def t2SMMLA : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00002008 "smmla", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002009 [(set rGPR:$dst, (add (mulhs rGPR:$a, rGPR:$b), rGPR:$c))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002010 let Inst{31-27} = 0b11111;
2011 let Inst{26-23} = 0b0110;
2012 let Inst{22-20} = 0b101;
2013 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2014 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2015}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002016
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002017def t2SMMLAR: T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00002018 "smmlar", "\t$dst, $a, $b, $c", []> {
2019 let Inst{31-27} = 0b11111;
2020 let Inst{26-23} = 0b0110;
2021 let Inst{22-20} = 0b101;
2022 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2023 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2024}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002025
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002026def t2SMMLS: T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Evan Cheng699beba2009-10-27 00:08:59 +00002027 "smmls", "\t$dst, $a, $b, $c",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002028 [(set rGPR:$dst, (sub rGPR:$c, (mulhs rGPR:$a, rGPR:$b)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002029 let Inst{31-27} = 0b11111;
2030 let Inst{26-23} = 0b0110;
2031 let Inst{22-20} = 0b110;
2032 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2033 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2034}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002035
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002036def t2SMMLSR:T2I <(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$c), IIC_iMAC32,
Johnny Chen93042d12010-03-02 18:14:57 +00002037 "smmlsr", "\t$dst, $a, $b, $c", []> {
2038 let Inst{31-27} = 0b11111;
2039 let Inst{26-23} = 0b0110;
2040 let Inst{22-20} = 0b110;
2041 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2042 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2043}
2044
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002045multiclass T2I_smul<string opc, PatFrag opnode> {
Evan Cheng0e55fd62010-09-30 01:08:25 +00002046 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002047 !strconcat(opc, "bb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002048 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
2049 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002050 let Inst{31-27} = 0b11111;
2051 let Inst{26-23} = 0b0110;
2052 let Inst{22-20} = 0b001;
2053 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2054 let Inst{7-6} = 0b00;
2055 let Inst{5-4} = 0b00;
2056 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002057
Evan Cheng0e55fd62010-09-30 01:08:25 +00002058 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002059 !strconcat(opc, "bt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002060 [(set rGPR:$dst, (opnode (sext_inreg rGPR:$a, i16),
2061 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002062 let Inst{31-27} = 0b11111;
2063 let Inst{26-23} = 0b0110;
2064 let Inst{22-20} = 0b001;
2065 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2066 let Inst{7-6} = 0b00;
2067 let Inst{5-4} = 0b01;
2068 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002069
Evan Cheng0e55fd62010-09-30 01:08:25 +00002070 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002071 !strconcat(opc, "tb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002072 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2073 (sext_inreg rGPR:$b, i16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002074 let Inst{31-27} = 0b11111;
2075 let Inst{26-23} = 0b0110;
2076 let Inst{22-20} = 0b001;
2077 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2078 let Inst{7-6} = 0b00;
2079 let Inst{5-4} = 0b10;
2080 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002081
Evan Cheng0e55fd62010-09-30 01:08:25 +00002082 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002083 !strconcat(opc, "tt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002084 [(set rGPR:$dst, (opnode (sra rGPR:$a, (i32 16)),
2085 (sra rGPR:$b, (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002086 let Inst{31-27} = 0b11111;
2087 let Inst{26-23} = 0b0110;
2088 let Inst{22-20} = 0b001;
2089 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2090 let Inst{7-6} = 0b00;
2091 let Inst{5-4} = 0b11;
2092 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002093
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002094 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002095 !strconcat(opc, "wb"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002096 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2097 (sext_inreg rGPR:$b, i16)), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002098 let Inst{31-27} = 0b11111;
2099 let Inst{26-23} = 0b0110;
2100 let Inst{22-20} = 0b011;
2101 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2102 let Inst{7-6} = 0b00;
2103 let Inst{5-4} = 0b00;
2104 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002105
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002106 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b), IIC_iMUL16,
Evan Cheng699beba2009-10-27 00:08:59 +00002107 !strconcat(opc, "wt"), "\t$dst, $a, $b",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002108 [(set rGPR:$dst, (sra (opnode rGPR:$a,
2109 (sra rGPR:$b, (i32 16))), (i32 16)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002110 let Inst{31-27} = 0b11111;
2111 let Inst{26-23} = 0b0110;
2112 let Inst{22-20} = 0b011;
2113 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2114 let Inst{7-6} = 0b00;
2115 let Inst{5-4} = 0b01;
2116 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002117}
2118
2119
2120multiclass T2I_smla<string opc, PatFrag opnode> {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002121 def BB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002122 !strconcat(opc, "bb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002123 [(set rGPR:$dst, (add rGPR:$acc,
2124 (opnode (sext_inreg rGPR:$a, i16),
2125 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002126 let Inst{31-27} = 0b11111;
2127 let Inst{26-23} = 0b0110;
2128 let Inst{22-20} = 0b001;
2129 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2130 let Inst{7-6} = 0b00;
2131 let Inst{5-4} = 0b00;
2132 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002133
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002134 def BT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002135 !strconcat(opc, "bt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002136 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sext_inreg rGPR:$a, i16),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002137 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002138 let Inst{31-27} = 0b11111;
2139 let Inst{26-23} = 0b0110;
2140 let Inst{22-20} = 0b001;
2141 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2142 let Inst{7-6} = 0b00;
2143 let Inst{5-4} = 0b01;
2144 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002145
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002146 def TB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002147 !strconcat(opc, "tb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002148 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002149 (sext_inreg rGPR:$b, i16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002150 let Inst{31-27} = 0b11111;
2151 let Inst{26-23} = 0b0110;
2152 let Inst{22-20} = 0b001;
2153 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2154 let Inst{7-6} = 0b00;
2155 let Inst{5-4} = 0b10;
2156 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002157
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002158 def TT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002159 !strconcat(opc, "tt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002160 [(set rGPR:$dst, (add rGPR:$acc, (opnode (sra rGPR:$a, (i32 16)),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002161 (sra rGPR:$b, (i32 16)))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002162 let Inst{31-27} = 0b11111;
2163 let Inst{26-23} = 0b0110;
2164 let Inst{22-20} = 0b001;
2165 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2166 let Inst{7-6} = 0b00;
2167 let Inst{5-4} = 0b11;
2168 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002169
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002170 def WB : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002171 !strconcat(opc, "wb"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002172 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002173 (sext_inreg rGPR:$b, i16)), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002174 let Inst{31-27} = 0b11111;
2175 let Inst{26-23} = 0b0110;
2176 let Inst{22-20} = 0b011;
2177 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2178 let Inst{7-6} = 0b00;
2179 let Inst{5-4} = 0b00;
2180 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002181
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002182 def WT : T2I<(outs rGPR:$dst), (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC16,
Evan Cheng699beba2009-10-27 00:08:59 +00002183 !strconcat(opc, "wt"), "\t$dst, $a, $b, $acc",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002184 [(set rGPR:$dst, (add rGPR:$acc, (sra (opnode rGPR:$a,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002185 (sra rGPR:$b, (i32 16))), (i32 16))))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002186 let Inst{31-27} = 0b11111;
2187 let Inst{26-23} = 0b0110;
2188 let Inst{22-20} = 0b011;
2189 let Inst{15-12} = {?, ?, ?, ?}; // Ra
2190 let Inst{7-6} = 0b00;
2191 let Inst{5-4} = 0b01;
2192 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002193}
2194
2195defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2196defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2197
Johnny Chenadc77332010-02-26 22:04:29 +00002198// Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002199def t2SMLALBB : T2I_mac<1, 0b100, 0b1000, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002200 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002201 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002202def t2SMLALBT : T2I_mac<1, 0b100, 0b1001, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002203 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlalbt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002204 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002205def t2SMLALTB : T2I_mac<1, 0b100, 0b1010, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002206 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltb", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002207 [/* For disassembly only; pattern left blank */]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002208def t2SMLALTT : T2I_mac<1, 0b100, 0b1011, (outs rGPR:$ldst,rGPR:$hdst),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002209 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaltt", "\t$ldst, $hdst, $a, $b",
Johnny Chenadc77332010-02-26 22:04:29 +00002210 [/* For disassembly only; pattern left blank */]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002211
Johnny Chenadc77332010-02-26 22:04:29 +00002212// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2213// These are for disassembly only.
2214
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002215def t2SMUAD: T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2216 IIC_iMAC32, "smuad", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002217 let Inst{15-12} = 0b1111;
2218}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002219def t2SMUADX:T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2220 IIC_iMAC32, "smuadx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002221 let Inst{15-12} = 0b1111;
2222}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002223def t2SMUSD: T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2224 IIC_iMAC32, "smusd", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002225 let Inst{15-12} = 0b1111;
2226}
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002227def t2SMUSDX:T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst), (ins rGPR:$a, rGPR:$b),
2228 IIC_iMAC32, "smusdx", "\t$dst, $a, $b", []> {
Johnny Chenadc77332010-02-26 22:04:29 +00002229 let Inst{15-12} = 0b1111;
2230}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002231def t2SMLAD : T2I_mac<0, 0b010, 0b0000, (outs rGPR:$dst),
2232 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlad",
Johnny Chenadc77332010-02-26 22:04:29 +00002233 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002234def t2SMLADX : T2I_mac<0, 0b010, 0b0001, (outs rGPR:$dst),
2235 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smladx",
Johnny Chenadc77332010-02-26 22:04:29 +00002236 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002237def t2SMLSD : T2I_mac<0, 0b100, 0b0000, (outs rGPR:$dst),
2238 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsd",
Johnny Chenadc77332010-02-26 22:04:29 +00002239 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002240def t2SMLSDX : T2I_mac<0, 0b100, 0b0001, (outs rGPR:$dst),
2241 (ins rGPR:$a, rGPR:$b, rGPR:$acc), IIC_iMAC32, "smlsdx",
Johnny Chenadc77332010-02-26 22:04:29 +00002242 "\t$dst, $a, $b, $acc", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002243def t2SMLALD : T2I_mac<1, 0b100, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2244 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlald",
Johnny Chenadc77332010-02-26 22:04:29 +00002245 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002246def t2SMLALDX : T2I_mac<1, 0b100, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2247 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlaldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002248 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002249def t2SMLSLD : T2I_mac<1, 0b101, 0b1100, (outs rGPR:$ldst,rGPR:$hdst),
2250 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsld",
Johnny Chenadc77332010-02-26 22:04:29 +00002251 "\t$ldst, $hdst, $a, $b", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002252def t2SMLSLDX : T2I_mac<1, 0b101, 0b1101, (outs rGPR:$ldst,rGPR:$hdst),
2253 (ins rGPR:$a,rGPR:$b), IIC_iMAC64, "smlsldx",
Johnny Chenadc77332010-02-26 22:04:29 +00002254 "\t$ldst, $hdst, $a, $b", []>;
Evan Chengf49810c2009-06-23 17:48:47 +00002255
2256//===----------------------------------------------------------------------===//
2257// Misc. Arithmetic Instructions.
2258//
2259
Jim Grosbach80dc1162010-02-16 21:23:02 +00002260class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2261 InstrItinClass itin, string opc, string asm, list<dag> pattern>
Johnny Chend68e1192009-12-15 17:24:14 +00002262 : T2I<oops, iops, itin, opc, asm, pattern> {
2263 let Inst{31-27} = 0b11111;
2264 let Inst{26-22} = 0b01010;
2265 let Inst{21-20} = op1;
2266 let Inst{15-12} = 0b1111;
2267 let Inst{7-6} = 0b10;
2268 let Inst{5-4} = op2;
2269}
Evan Chengf49810c2009-06-23 17:48:47 +00002270
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002271def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
2272 "clz", "\t$dst, $src", [(set rGPR:$dst, (ctlz rGPR:$src))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002273
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002274def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Evan Chengf609bb82010-01-19 00:44:15 +00002275 "rbit", "\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002276 [(set rGPR:$dst, (ARMrbit rGPR:$src))]>;
Jim Grosbach3482c802010-01-18 19:58:49 +00002277
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002278def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002279 "rev", ".w\t$dst, $src", [(set rGPR:$dst, (bswap rGPR:$src))]>;
Johnny Chend68e1192009-12-15 17:24:14 +00002280
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002281def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002282 "rev16", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002283 [(set rGPR:$dst,
2284 (or (and (srl rGPR:$src, (i32 8)), 0xFF),
2285 (or (and (shl rGPR:$src, (i32 8)), 0xFF00),
2286 (or (and (srl rGPR:$src, (i32 8)), 0xFF0000),
Jim Grosbachc5ed0132010-08-17 18:39:16 +00002287 (and (shl rGPR:$src, (i32 8)), 0xFF000000)))))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002288
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002289def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$dst), (ins rGPR:$src), IIC_iUNAr,
Johnny Chend68e1192009-12-15 17:24:14 +00002290 "revsh", ".w\t$dst, $src",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002291 [(set rGPR:$dst,
Evan Chengf49810c2009-06-23 17:48:47 +00002292 (sext_inreg
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002293 (or (srl (and rGPR:$src, 0xFF00), (i32 8)),
2294 (shl rGPR:$src, (i32 8))), i16))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002295
Bob Wilsonf955f292010-08-17 17:23:19 +00002296def t2PKHBT : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002297 IIC_iBITsi, "pkhbt", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002298 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF),
Bob Wilsonf955f292010-08-17 17:23:19 +00002299 (and (shl rGPR:$src2, lsl_amt:$sh),
Jim Grosbachb1dc3932010-05-05 20:44:35 +00002300 0xFFFF0000)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002301 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002302 let Inst{31-27} = 0b11101;
2303 let Inst{26-25} = 0b01;
2304 let Inst{24-20} = 0b01100;
2305 let Inst{5} = 0; // BT form
2306 let Inst{4} = 0;
2307}
Evan Cheng40289b02009-07-07 05:35:52 +00002308
2309// Alternate cases for PKHBT where identities eliminate some nodes.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002310def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2311 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002312 Requires<[HasT2ExtractPack, IsThumb2]>;
Bob Wilsonf955f292010-08-17 17:23:19 +00002313def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
2314 (t2PKHBT rGPR:$src1, rGPR:$src2, (lsl_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002315 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Cheng40289b02009-07-07 05:35:52 +00002316
Bob Wilsondc66eda2010-08-16 22:26:55 +00002317// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2318// will match the pattern below.
Bob Wilsonf955f292010-08-17 17:23:19 +00002319def t2PKHTB : T2I<(outs rGPR:$dst), (ins rGPR:$src1, rGPR:$src2, shift_imm:$sh),
Evan Cheng7e1bf302010-09-29 00:27:46 +00002320 IIC_iBITsi, "pkhtb", "\t$dst, $src1, $src2$sh",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002321 [(set rGPR:$dst, (or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002322 (and (sra rGPR:$src2, asr_amt:$sh),
2323 0xFFFF)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002324 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002325 let Inst{31-27} = 0b11101;
2326 let Inst{26-25} = 0b01;
2327 let Inst{24-20} = 0b01100;
2328 let Inst{5} = 1; // TB form
2329 let Inst{4} = 0;
2330}
Evan Cheng40289b02009-07-07 05:35:52 +00002331
2332// Alternate cases for PKHTB where identities eliminate some nodes. Note that
2333// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilsondc66eda2010-08-16 22:26:55 +00002334def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
Bob Wilsonf955f292010-08-17 17:23:19 +00002335 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm16_31:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002336 Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002337def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002338 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
2339 (t2PKHTB rGPR:$src1, rGPR:$src2, (asr_shift_imm imm1_15:$sh))>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002340 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002341
2342//===----------------------------------------------------------------------===//
2343// Comparison Instructions...
2344//
Johnny Chend68e1192009-12-15 17:24:14 +00002345defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002346 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002347 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
2348defm t2CMPz : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002349 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002350 BinOpFrag<(ARMcmpZ node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002351
Dan Gohman4b7dff92010-08-26 15:50:25 +00002352//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2353// Compare-to-zero still works out, just not the relationals
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002354//defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2355// BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002356defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
Evan Cheng5d42c562010-09-29 00:49:25 +00002357 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Dan Gohman4b7dff92010-08-26 15:50:25 +00002358 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2359
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002360//def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2361// (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002362
2363def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2364 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002365
Johnny Chend68e1192009-12-15 17:24:14 +00002366defm t2TST : T2I_cmp_irs<0b0000, "tst",
Evan Cheng5d42c562010-09-29 00:49:25 +00002367 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002368 BinOpFrag<(ARMcmpZ (and node:$LHS, node:$RHS), 0)>>;
2369defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
Evan Cheng5d42c562010-09-29 00:49:25 +00002370 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002371 BinOpFrag<(ARMcmpZ (xor node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002372
Evan Chenge253c952009-07-07 20:39:03 +00002373// Conditional moves
2374// FIXME: should be able to write a pattern for ARMcmov, but can't use
Jim Grosbach64171712010-02-16 21:07:46 +00002375// a two-value operand where a dag node expects two operands. :(
Evan Cheng63f35442010-11-13 02:25:14 +00002376let neverHasSideEffects = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002377def t2MOVCCr : T2I<(outs rGPR:$dst), (ins rGPR:$false, rGPR:$true), IIC_iCMOVr,
Evan Cheng699beba2009-10-27 00:08:59 +00002378 "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002379 [/*(set rGPR:$dst, (ARMcmov rGPR:$false, rGPR:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002380 RegConstraint<"$false = $dst"> {
2381 let Inst{31-27} = 0b11101;
2382 let Inst{26-25} = 0b01;
2383 let Inst{24-21} = 0b0010;
2384 let Inst{20} = 0; // The S bit.
2385 let Inst{19-16} = 0b1111; // Rn
2386 let Inst{14-12} = 0b000;
2387 let Inst{7-4} = 0b0000;
2388}
Evan Chenge253c952009-07-07 20:39:03 +00002389
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002390def t2MOVCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
Evan Cheng699beba2009-10-27 00:08:59 +00002391 IIC_iCMOVi, "mov", ".w\t$dst, $true",
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002392[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm:$true, imm:$cc, CCR:$ccr))*/]>,
Johnny Chend68e1192009-12-15 17:24:14 +00002393 RegConstraint<"$false = $dst"> {
2394 let Inst{31-27} = 0b11110;
2395 let Inst{25} = 0;
2396 let Inst{24-21} = 0b0010;
2397 let Inst{20} = 0; // The S bit.
2398 let Inst{19-16} = 0b1111; // Rn
2399 let Inst{15} = 0;
2400}
Evan Chengf49810c2009-06-23 17:48:47 +00002401
Jim Grosbacha4257162010-10-07 00:53:56 +00002402def t2MOVCCi16 : T2I<(outs rGPR:$dst), (ins rGPR:$false, i32imm:$src),
Evan Cheng875a6ac2010-11-12 22:42:47 +00002403 IIC_iCMOVi,
Jim Grosbacha4257162010-10-07 00:53:56 +00002404 "movw", "\t$dst, $src", []>,
2405 RegConstraint<"$false = $dst"> {
2406 let Inst{31-27} = 0b11110;
2407 let Inst{25} = 1;
2408 let Inst{24-21} = 0b0010;
2409 let Inst{20} = 0; // The S bit.
2410 let Inst{15} = 0;
2411}
2412
Evan Cheng63f35442010-11-13 02:25:14 +00002413def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2414 (ins rGPR:$false, i32imm:$src, pred:$p),
Evan Chengc47f7d62010-11-13 05:14:20 +00002415 IIC_iCMOVix2, "", []>, RegConstraint<"$false = $dst">;
Evan Cheng63f35442010-11-13 02:25:14 +00002416
Evan Cheng875a6ac2010-11-12 22:42:47 +00002417def t2MVNCCi : T2I<(outs rGPR:$dst), (ins rGPR:$false, t2_so_imm:$true),
2418 IIC_iCMOVi, "mvn", ".w\t$dst, $true",
2419[/*(set rGPR:$dst,(ARMcmov rGPR:$false,t2_so_imm_not:$true,
2420 imm:$cc, CCR:$ccr))*/]>,
2421 RegConstraint<"$false = $dst"> {
2422 let Inst{31-27} = 0b11110;
2423 let Inst{25} = 0;
2424 let Inst{24-21} = 0b0011;
2425 let Inst{20} = 0; // The S bit.
2426 let Inst{19-16} = 0b1111; // Rn
2427 let Inst{15} = 0;
2428}
2429
Johnny Chend68e1192009-12-15 17:24:14 +00002430class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2431 string opc, string asm, list<dag> pattern>
2432 : T2I<oops, iops, itin, opc, asm, pattern> {
2433 let Inst{31-27} = 0b11101;
2434 let Inst{26-25} = 0b01;
2435 let Inst{24-21} = 0b0010;
2436 let Inst{20} = 0; // The S bit.
2437 let Inst{19-16} = 0b1111; // Rn
2438 let Inst{5-4} = opcod; // Shift type.
2439}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002440def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$dst),
2441 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002442 IIC_iCMOVsi, "lsl", ".w\t$dst, $true, $rhs", []>,
2443 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002444def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$dst),
2445 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002446 IIC_iCMOVsi, "lsr", ".w\t$dst, $true, $rhs", []>,
2447 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002448def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$dst),
2449 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002450 IIC_iCMOVsi, "asr", ".w\t$dst, $true, $rhs", []>,
2451 RegConstraint<"$false = $dst">;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002452def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$dst),
2453 (ins rGPR:$false, rGPR:$true, i32imm:$rhs),
Johnny Chend68e1192009-12-15 17:24:14 +00002454 IIC_iCMOVsi, "ror", ".w\t$dst, $true, $rhs", []>,
2455 RegConstraint<"$false = $dst">;
Owen Andersonf523e472010-09-23 23:45:25 +00002456} // neverHasSideEffects
Evan Cheng13f8b362009-08-01 01:43:45 +00002457
David Goodwin5e47a9a2009-06-30 18:04:13 +00002458//===----------------------------------------------------------------------===//
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002459// Atomic operations intrinsics
2460//
2461
2462// memory barriers protect the atomic sequences
2463let hasSideEffects = 1 in {
Bob Wilsonf74a4292010-10-30 00:54:37 +00002464def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2465 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2466 Requires<[IsThumb, HasDB]> {
2467 bits<4> opt;
2468 let Inst{31-4} = 0xf3bf8f5;
2469 let Inst{3-0} = opt;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002470}
2471}
2472
Bob Wilsonf74a4292010-10-30 00:54:37 +00002473def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2474 "dsb", "\t$opt",
2475 [/* For disassembly only; pattern left blank */]>,
2476 Requires<[IsThumb, HasDB]> {
2477 bits<4> opt;
2478 let Inst{31-4} = 0xf3bf8f4;
2479 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00002480}
2481
Johnny Chena4339822010-03-03 00:16:28 +00002482// ISB has only full system option -- for disassembly only
Bob Wilsonf74a4292010-10-30 00:54:37 +00002483def t2ISB : T2I<(outs), (ins), NoItinerary, "isb", "",
2484 [/* For disassembly only; pattern left blank */]>,
2485 Requires<[IsThumb2, HasV7]> {
2486 let Inst{31-4} = 0xf3bf8f6;
Johnny Chena4339822010-03-03 00:16:28 +00002487 let Inst{3-0} = 0b1111;
2488}
2489
Johnny Chend68e1192009-12-15 17:24:14 +00002490class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2491 InstrItinClass itin, string opc, string asm, string cstr,
2492 list<dag> pattern, bits<4> rt2 = 0b1111>
2493 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2494 let Inst{31-27} = 0b11101;
2495 let Inst{26-20} = 0b0001101;
2496 let Inst{11-8} = rt2;
2497 let Inst{7-6} = 0b01;
2498 let Inst{5-4} = opcod;
2499 let Inst{3-0} = 0b1111;
2500}
2501class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, SizeFlagVal sz,
2502 InstrItinClass itin, string opc, string asm, string cstr,
2503 list<dag> pattern, bits<4> rt2 = 0b1111>
2504 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2505 let Inst{31-27} = 0b11101;
2506 let Inst{26-20} = 0b0001100;
2507 let Inst{11-8} = rt2;
2508 let Inst{7-6} = 0b01;
2509 let Inst{5-4} = opcod;
2510}
2511
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002512let mayLoad = 1 in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002513def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002514 Size4Bytes, NoItinerary, "ldrexb", "\t$dest, [$ptr]",
2515 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002516def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002517 Size4Bytes, NoItinerary, "ldrexh", "\t$dest, [$ptr]",
2518 "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002519def t2LDREX : Thumb2I<(outs rGPR:$dest), (ins rGPR:$ptr), AddrModeNone,
Johnny Chend68e1192009-12-15 17:24:14 +00002520 Size4Bytes, NoItinerary,
2521 "ldrex", "\t$dest, [$ptr]", "",
2522 []> {
2523 let Inst{31-27} = 0b11101;
2524 let Inst{26-20} = 0b0000101;
2525 let Inst{11-8} = 0b1111;
2526 let Inst{7-0} = 0b00000000; // imm8 = 0
2527}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002528def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$dest, rGPR:$dest2), (ins rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002529 AddrModeNone, Size4Bytes, NoItinerary,
2530 "ldrexd", "\t$dest, $dest2, [$ptr]", "",
2531 [], {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002532}
2533
Jim Grosbach587b0722009-12-16 19:44:06 +00002534let mayStore = 1, Constraints = "@earlyclobber $success" in {
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002535def t2STREXB : T2I_strex<0b00, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002536 AddrModeNone, Size4Bytes, NoItinerary,
2537 "strexb", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002538def t2STREXH : T2I_strex<0b01, (outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002539 AddrModeNone, Size4Bytes, NoItinerary,
2540 "strexh", "\t$success, $src, [$ptr]", "", []>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002541def t2STREX : Thumb2I<(outs rGPR:$success), (ins rGPR:$src, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002542 AddrModeNone, Size4Bytes, NoItinerary,
2543 "strex", "\t$success, $src, [$ptr]", "",
2544 []> {
2545 let Inst{31-27} = 0b11101;
2546 let Inst{26-20} = 0b0000100;
2547 let Inst{7-0} = 0b00000000; // imm8 = 0
2548}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002549def t2STREXD : T2I_strex<0b11, (outs rGPR:$success),
2550 (ins rGPR:$src, rGPR:$src2, rGPR:$ptr),
Johnny Chend68e1192009-12-15 17:24:14 +00002551 AddrModeNone, Size4Bytes, NoItinerary,
2552 "strexd", "\t$success, $src, $src2, [$ptr]", "", [],
2553 {?, ?, ?, ?}>;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002554}
2555
Johnny Chen10a77e12010-03-02 22:11:06 +00002556// Clear-Exclusive is for disassembly only.
2557def t2CLREX : T2I<(outs), (ins), NoItinerary, "clrex", "",
2558 [/* For disassembly only; pattern left blank */]>,
2559 Requires<[IsARM, HasV7]> {
2560 let Inst{31-20} = 0xf3b;
2561 let Inst{15-14} = 0b10;
2562 let Inst{12} = 0;
2563 let Inst{7-4} = 0b0010;
2564}
2565
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002566//===----------------------------------------------------------------------===//
David Goodwin334c2642009-07-08 16:09:28 +00002567// TLS Instructions
2568//
2569
2570// __aeabi_read_tp preserves the registers r1-r3.
2571let isCall = 1,
2572 Defs = [R0, R12, LR, CPSR] in {
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002573 def t2TPsoft : T2XI<(outs), (ins), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002574 "bl\t__aeabi_read_tp",
Johnny Chend68e1192009-12-15 17:24:14 +00002575 [(set R0, ARMthread_pointer)]> {
2576 let Inst{31-27} = 0b11110;
2577 let Inst{15-14} = 0b11;
2578 let Inst{12} = 1;
2579 }
David Goodwin334c2642009-07-08 16:09:28 +00002580}
2581
2582//===----------------------------------------------------------------------===//
Jim Grosbach5aa16842009-08-11 19:42:21 +00002583// SJLJ Exception handling intrinsics
Jim Grosbach1add6592009-08-13 15:11:43 +00002584// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach5aa16842009-08-11 19:42:21 +00002585// address and save #0 in R0 for the non-longjmp case.
2586// Since by its nature we may be coming from some other function to get
2587// here, and we're using the stack frame for the containing function to
2588// save/restore registers, we can't keep anything live in regs across
2589// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
2590// when we get here from a longjmp(). We force everthing out of registers
2591// except for our own input by listing the relevant registers in Defs. By
2592// doing so, we also cause the prologue/epilogue code to actively preserve
2593// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbach0798edd2010-05-27 23:49:24 +00002594// $val is a scratch register for our use.
Jim Grosbacha87ded22010-02-08 23:22:00 +00002595let Defs =
Jim Grosbachf35d2162009-08-13 16:59:44 +00002596 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, D0,
2597 D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11, D12, D13, D14, D15,
Jim Grosbach5aa16842009-08-11 19:42:21 +00002598 D16, D17, D18, D19, D20, D21, D22, D23, D24, D25, D26, D27, D28, D29, D30,
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002599 D31 ], hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002600 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002601 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002602 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002603 Requires<[IsThumb2, HasVFP2]>;
Jim Grosbach5aa16842009-08-11 19:42:21 +00002604}
2605
Bob Wilsonec80e262010-04-09 20:41:18 +00002606let Defs =
Jim Grosbach5caeff52010-05-28 17:37:40 +00002607 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR ],
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002608 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002609 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Jim Grosbach71d933a2010-09-30 16:56:53 +00002610 AddrModeNone, SizeSpecial, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002611 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002612 Requires<[IsThumb2, NoVFP]>;
2613}
Jim Grosbach5aa16842009-08-11 19:42:21 +00002614
2615
2616//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00002617// Control-Flow Instructions
2618//
2619
Evan Chengc50a1cb2009-07-09 22:58:39 +00002620// FIXME: remove when we have a way to marking a MI with these properties.
2621// FIXME: $dst1 should be a def. But the extra ops must be in the end of the
2622// operand list.
2623// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng0d92f5f2009-10-01 08:22:27 +00002624let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
Chris Lattner39ee0362010-10-31 19:10:56 +00002625 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
Jim Grosbache6913602010-11-03 01:01:43 +00002626 def t2LDM_RET: T2XIt<(outs GPR:$wb), (ins GPR:$Rn, ldstm_mode:$amode, pred:$p,
2627 reglist:$dsts, variable_ops),
Evan Chenga0792de2010-10-06 06:27:31 +00002628 IIC_iLoad_mBr,
Jim Grosbache6913602010-11-03 01:01:43 +00002629 "ldm${amode}${p}.w\t$Rn!, $dsts",
2630 "$Rn = $wb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002631 let Inst{31-27} = 0b11101;
2632 let Inst{26-25} = 0b00;
2633 let Inst{24-23} = {?, ?}; // IA: '01', DB: '10'
2634 let Inst{22} = 0;
Bob Wilson815baeb2010-03-13 01:08:20 +00002635 let Inst{21} = 1; // The W bit.
Johnny Chend68e1192009-12-15 17:24:14 +00002636 let Inst{20} = 1; // Load
2637}
Evan Chengc50a1cb2009-07-09 22:58:39 +00002638
David Goodwin5e47a9a2009-06-30 18:04:13 +00002639let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
2640let isPredicable = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002641def t2B : T2XI<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002642 "b.w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002643 [(br bb:$target)]> {
2644 let Inst{31-27} = 0b11110;
2645 let Inst{15-14} = 0b10;
2646 let Inst{12} = 1;
2647}
David Goodwin5e47a9a2009-06-30 18:04:13 +00002648
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002649let isNotDuplicable = 1, isIndirectBranch = 1,
2650 isCodeGenOnly = 1 in { // $id doesn't exist in asmstring, should be lowered.
Evan Cheng66ac5312009-07-25 00:33:29 +00002651def t2BR_JT :
Evan Cheng5657c012009-07-29 02:18:14 +00002652 T2JTI<(outs),
2653 (ins GPR:$target, GPR:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002654 IIC_Br, "mov\tpc, $target$jt",
Johnny Chend68e1192009-12-15 17:24:14 +00002655 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]> {
2656 let Inst{31-27} = 0b11101;
2657 let Inst{26-20} = 0b0100100;
2658 let Inst{19-16} = 0b1111;
2659 let Inst{14-12} = 0b000;
2660 let Inst{11-8} = 0b1111; // Rd = pc
2661 let Inst{7-4} = 0b0000;
2662}
Evan Cheng5657c012009-07-29 02:18:14 +00002663
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002664// FIXME: Add a non-pc based case that can be predicated.
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002665let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002666def t2TBB :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002667 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002668 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002669 IIC_Br, "tbb\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002670 let Inst{31-27} = 0b11101;
2671 let Inst{26-20} = 0b0001101;
2672 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2673 let Inst{15-8} = 0b11110000;
2674 let Inst{7-4} = 0b0000; // B form
2675}
Evan Cheng5657c012009-07-29 02:18:14 +00002676
Chris Lattnera1ca91a2010-11-02 23:40:41 +00002677let isCodeGenOnly = 1 in // $id doesn't exist in asm string, should be lowered.
Evan Cheng5657c012009-07-29 02:18:14 +00002678def t2TBH :
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002679 T2JTI<(outs),
Evan Cheng5657c012009-07-29 02:18:14 +00002680 (ins tb_addrmode:$index, jt2block_operand:$jt, i32imm:$id),
Bob Wilsond4d188e2010-07-31 06:28:10 +00002681 IIC_Br, "tbh\t$index$jt", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002682 let Inst{31-27} = 0b11101;
2683 let Inst{26-20} = 0b0001101;
2684 let Inst{19-16} = 0b1111; // Rn = pc (table follows this instruction)
2685 let Inst{15-8} = 0b11110000;
2686 let Inst{7-4} = 0b0001; // H form
2687}
Johnny Chen93042d12010-03-02 18:14:57 +00002688
2689// Generic versions of the above two instructions, for disassembly only
2690
2691def t2TBBgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2692 "tbb", "\t[$a, $b]", []>{
2693 let Inst{31-27} = 0b11101;
2694 let Inst{26-20} = 0b0001101;
2695 let Inst{15-8} = 0b11110000;
2696 let Inst{7-4} = 0b0000; // B form
2697}
2698
2699def t2TBHgen : T2I<(outs), (ins GPR:$a, GPR:$b), IIC_Br,
2700 "tbh", "\t[$a, $b, lsl #1]", []> {
2701 let Inst{31-27} = 0b11101;
2702 let Inst{26-20} = 0b0001101;
2703 let Inst{15-8} = 0b11110000;
2704 let Inst{7-4} = 0b0001; // H form
2705}
Evan Cheng5657c012009-07-29 02:18:14 +00002706} // isNotDuplicable, isIndirectBranch
2707
David Goodwinc9a59b52009-06-30 19:50:22 +00002708} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00002709
2710// FIXME: should be able to write a pattern for ARMBrcond, but can't use
2711// a two-value operand where a dag node expects two operands. :(
2712let isBranch = 1, isTerminator = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002713def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002714 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002715 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
2716 let Inst{31-27} = 0b11110;
2717 let Inst{15-14} = 0b10;
2718 let Inst{12} = 0;
2719}
Evan Chengf49810c2009-06-23 17:48:47 +00002720
Evan Cheng06e16582009-07-10 01:54:42 +00002721
2722// IT block
Evan Cheng86050dc2010-06-18 23:09:54 +00002723let Defs = [ITSTATE] in
Evan Cheng06e16582009-07-10 01:54:42 +00002724def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
David Goodwin5d598aa2009-08-19 18:00:44 +00002725 AddrModeNone, Size2Bytes, IIC_iALUx,
Johnny Chend68e1192009-12-15 17:24:14 +00002726 "it$mask\t$cc", "", []> {
2727 // 16-bit instruction.
Johnny Chenbbc71b22009-12-16 02:32:54 +00002728 let Inst{31-16} = 0x0000;
Johnny Chend68e1192009-12-15 17:24:14 +00002729 let Inst{15-8} = 0b10111111;
2730}
Evan Cheng06e16582009-07-10 01:54:42 +00002731
Johnny Chence6275f2010-02-25 19:05:29 +00002732// Branch and Exchange Jazelle -- for disassembly only
2733// Rm = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002734def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
Johnny Chence6275f2010-02-25 19:05:29 +00002735 [/* For disassembly only; pattern left blank */]> {
2736 let Inst{31-27} = 0b11110;
2737 let Inst{26} = 0;
2738 let Inst{25-20} = 0b111100;
2739 let Inst{15-14} = 0b10;
2740 let Inst{12} = 0;
2741}
2742
Johnny Chen93042d12010-03-02 18:14:57 +00002743// Change Processor State is a system instruction -- for disassembly only.
2744// The singleton $opt operand contains the following information:
2745// opt{4-0} = mode from Inst{4-0}
2746// opt{5} = changemode from Inst{17}
2747// opt{8-6} = AIF from Inst{8-6}
2748// opt{10-9} = imod from Inst{19-18} with 0b10 as enable and 0b11 as disable
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002749def t2CPS : T2XI<(outs),(ins cps_opt:$opt), NoItinerary, "cps$opt",
Johnny Chen93042d12010-03-02 18:14:57 +00002750 [/* For disassembly only; pattern left blank */]> {
2751 let Inst{31-27} = 0b11110;
2752 let Inst{26} = 0;
2753 let Inst{25-20} = 0b111010;
2754 let Inst{15-14} = 0b10;
2755 let Inst{12} = 0;
2756}
2757
Johnny Chen0f7866e2010-03-03 02:09:43 +00002758// A6.3.4 Branches and miscellaneous control
2759// Table A6-14 Change Processor State, and hint instructions
2760// Helper class for disassembly only.
2761class T2I_hint<bits<8> op7_0, string opc, string asm>
2762 : T2I<(outs), (ins), NoItinerary, opc, asm,
2763 [/* For disassembly only; pattern left blank */]> {
2764 let Inst{31-20} = 0xf3a;
2765 let Inst{15-14} = 0b10;
2766 let Inst{12} = 0;
2767 let Inst{10-8} = 0b000;
2768 let Inst{7-0} = op7_0;
2769}
2770
2771def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
2772def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
2773def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
2774def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
2775def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
2776
2777def t2DBG : T2I<(outs),(ins i32imm:$opt), NoItinerary, "dbg", "\t$opt",
2778 [/* For disassembly only; pattern left blank */]> {
2779 let Inst{31-20} = 0xf3a;
2780 let Inst{15-14} = 0b10;
2781 let Inst{12} = 0;
2782 let Inst{10-8} = 0b000;
2783 let Inst{7-4} = 0b1111;
2784}
2785
Johnny Chen6341c5a2010-02-25 20:25:24 +00002786// Secure Monitor Call is a system instruction -- for disassembly only
2787// Option = Inst{19-16}
2788def t2SMC : T2I<(outs), (ins i32imm:$opt), NoItinerary, "smc", "\t$opt",
2789 [/* For disassembly only; pattern left blank */]> {
2790 let Inst{31-27} = 0b11110;
2791 let Inst{26-20} = 0b1111111;
2792 let Inst{15-12} = 0b1000;
2793}
2794
2795// Store Return State is a system instruction -- for disassembly only
2796def t2SRSDBW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
2797 [/* For disassembly only; pattern left blank */]> {
2798 let Inst{31-27} = 0b11101;
2799 let Inst{26-20} = 0b0000010; // W = 1
2800}
2801
2802def t2SRSDB : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
2803 [/* For disassembly only; pattern left blank */]> {
2804 let Inst{31-27} = 0b11101;
2805 let Inst{26-20} = 0b0000000; // W = 0
2806}
2807
2808def t2SRSIAW : T2I<(outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
2809 [/* For disassembly only; pattern left blank */]> {
2810 let Inst{31-27} = 0b11101;
2811 let Inst{26-20} = 0b0011010; // W = 1
2812}
2813
2814def t2SRSIA : T2I<(outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
2815 [/* For disassembly only; pattern left blank */]> {
2816 let Inst{31-27} = 0b11101;
2817 let Inst{26-20} = 0b0011000; // W = 0
2818}
2819
2820// Return From Exception is a system instruction -- for disassembly only
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002821def t2RFEDBW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfedb", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002822 [/* For disassembly only; pattern left blank */]> {
2823 let Inst{31-27} = 0b11101;
2824 let Inst{26-20} = 0b0000011; // W = 1
2825}
2826
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002827def t2RFEDB : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeab", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002828 [/* For disassembly only; pattern left blank */]> {
2829 let Inst{31-27} = 0b11101;
2830 let Inst{26-20} = 0b0000001; // W = 0
2831}
2832
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002833def t2RFEIAW : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base!",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002834 [/* For disassembly only; pattern left blank */]> {
2835 let Inst{31-27} = 0b11101;
2836 let Inst{26-20} = 0b0011011; // W = 1
2837}
2838
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002839def t2RFEIA : T2I<(outs), (ins rGPR:$base), NoItinerary, "rfeia", "\t$base",
Johnny Chen6341c5a2010-02-25 20:25:24 +00002840 [/* For disassembly only; pattern left blank */]> {
2841 let Inst{31-27} = 0b11101;
2842 let Inst{26-20} = 0b0011001; // W = 0
2843}
2844
Evan Chengf49810c2009-06-23 17:48:47 +00002845//===----------------------------------------------------------------------===//
2846// Non-Instruction Patterns
2847//
2848
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002849// Two piece so_imms.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002850def : T2Pat<(or rGPR:$LHS, t2_so_imm2part:$RHS),
2851 (t2ORRri (t2ORRri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002852 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002853def : T2Pat<(xor rGPR:$LHS, t2_so_imm2part:$RHS),
2854 (t2EORri (t2EORri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002855 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002856def : T2Pat<(add rGPR:$LHS, t2_so_imm2part:$RHS),
2857 (t2ADDri (t2ADDri rGPR:$LHS, (t2_so_imm2part_1 imm:$RHS)),
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002858 (t2_so_imm2part_2 imm:$RHS))>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002859def : T2Pat<(add rGPR:$LHS, t2_so_neg_imm2part:$RHS),
2860 (t2SUBri (t2SUBri rGPR:$LHS, (t2_so_neg_imm2part_1 imm:$RHS)),
Jim Grosbach15e6ef82009-11-23 20:35:53 +00002861 (t2_so_neg_imm2part_2 imm:$RHS))>;
Jim Grosbach65b7f3a2009-10-21 20:44:34 +00002862
Evan Cheng5adb66a2009-09-28 09:14:39 +00002863// 32-bit immediate using movw + movt.
Evan Cheng5be39222010-09-24 22:03:46 +00002864// This is a single pseudo instruction to make it re-materializable.
2865// FIXME: Remove this when we can do generalized remat.
Evan Cheng5adb66a2009-09-28 09:14:39 +00002866let isReMaterializable = 1 in
Jim Grosbach3c38f962010-10-06 22:01:26 +00002867def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
2868 "", [(set rGPR:$dst, (i32 imm:$src))]>,
2869 Requires<[IsThumb, HasV6T2]>;
Evan Chengb9803a82009-11-06 23:52:48 +00002870
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00002871// ConstantPool, GlobalAddress, and JumpTable
2872def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
2873 Requires<[IsThumb2, DontUseMovt]>;
2874def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
2875def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
2876 Requires<[IsThumb2, UseMovt]>;
2877
2878def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
2879 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
2880
Evan Chengb9803a82009-11-06 23:52:48 +00002881// Pseudo instruction that combines ldr from constpool and add pc. This should
2882// be expanded into two instructions late to allow if-conversion and
2883// scheduling.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00002884let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Chengb9803a82009-11-06 23:52:48 +00002885def t2LDRpci_pic : PseudoInst<(outs GPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Jim Grosbach78890f42010-10-01 23:21:38 +00002886 IIC_iLoadiALU, "",
Evan Chengb9803a82009-11-06 23:52:48 +00002887 [(set GPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
2888 imm:$cp))]>,
2889 Requires<[IsThumb2]>;
Johnny Chen23336552010-02-25 18:46:43 +00002890
2891//===----------------------------------------------------------------------===//
2892// Move between special register and ARM core register -- for disassembly only
2893//
2894
2895// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002896def t2MRS : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, cpsr",
Johnny Chen23336552010-02-25 18:46:43 +00002897 [/* For disassembly only; pattern left blank */]> {
2898 let Inst{31-27} = 0b11110;
2899 let Inst{26} = 0;
2900 let Inst{25-21} = 0b11111;
2901 let Inst{20} = 0; // The R bit.
2902 let Inst{15-14} = 0b10;
2903 let Inst{12} = 0;
2904}
2905
2906// Rd = Instr{11-8}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002907def t2MRSsys : T2I<(outs rGPR:$dst), (ins), NoItinerary, "mrs", "\t$dst, spsr",
Johnny Chen23336552010-02-25 18:46:43 +00002908 [/* For disassembly only; pattern left blank */]> {
2909 let Inst{31-27} = 0b11110;
2910 let Inst{26} = 0;
2911 let Inst{25-21} = 0b11111;
2912 let Inst{20} = 1; // The R bit.
2913 let Inst{15-14} = 0b10;
2914 let Inst{12} = 0;
2915}
2916
Johnny Chen23336552010-02-25 18:46:43 +00002917// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002918def t2MSR : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002919 "\tcpsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00002920 [/* For disassembly only; pattern left blank */]> {
2921 let Inst{31-27} = 0b11110;
2922 let Inst{26} = 0;
2923 let Inst{25-21} = 0b11100;
2924 let Inst{20} = 0; // The R bit.
2925 let Inst{15-14} = 0b10;
2926 let Inst{12} = 0;
2927}
2928
Johnny Chen23336552010-02-25 18:46:43 +00002929// Rn = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002930def t2MSRsys : T2I<(outs), (ins rGPR:$src, msr_mask:$mask), NoItinerary, "msr",
Johnny Chendd0f3cf2010-03-10 18:59:38 +00002931 "\tspsr$mask, $src",
Johnny Chen23336552010-02-25 18:46:43 +00002932 [/* For disassembly only; pattern left blank */]> {
2933 let Inst{31-27} = 0b11110;
2934 let Inst{26} = 0;
2935 let Inst{25-21} = 0b11100;
2936 let Inst{20} = 1; // The R bit.
2937 let Inst{15-14} = 0b10;
2938 let Inst{12} = 0;
2939}