blob: d7e92db89df5595c3a63ef496d258fe4ee797419 [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";
Owen Andersone234d022011-08-24 17:21:43 +000017 let DecoderMethod = "DecodeITCond";
Evan Cheng06e16582009-07-10 01:54:42 +000018}
19
20// IT block condition mask
21def it_mask : Operand<i32> {
22 let PrintMethod = "printThumbITMask";
23}
24
Anton Korobeynikov52237112009-06-17 18:13:58 +000025// Shifted operands. No register controlled shifts for Thumb2.
26// Note: We do not support rrx shifted operands yet.
27def t2_so_reg : Operand<i32>, // reg imm
Evan Cheng9cb9e672009-06-27 02:26:13 +000028 ComplexPattern<i32, 2, "SelectT2ShifterOperandReg",
Anton Korobeynikov52237112009-06-17 18:13:58 +000029 [shl,srl,sra,rotr]> {
Chris Lattner2ac19022010-11-15 05:19:05 +000030 let EncoderMethod = "getT2SORegOpValue";
Evan Cheng9cb9e672009-06-27 02:26:13 +000031 let PrintMethod = "printT2SOOperand";
Jim Grosbach6ccfc502010-07-30 02:41:01 +000032 let MIOperandInfo = (ops rGPR, i32imm);
Owen Anderson2c9f8352011-08-22 23:10:16 +000033 let DecoderMethod = "DecodeSORegImmOperand";
Anton Korobeynikov52237112009-06-17 18:13:58 +000034}
35
Evan Chengf49810c2009-06-23 17:48:47 +000036// t2_so_imm_not_XFORM - Return the complement of a t2_so_imm value
37def t2_so_imm_not_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000038 return CurDAG->getTargetConstant(~((uint32_t)N->getZExtValue()), MVT::i32);
Anton Korobeynikov52237112009-06-17 18:13:58 +000039}]>;
40
Evan Chengf49810c2009-06-23 17:48:47 +000041// t2_so_imm_neg_XFORM - Return the negation of a t2_so_imm value
42def t2_so_imm_neg_XFORM : SDNodeXForm<imm, [{
Owen Anderson825b72b2009-08-11 20:47:22 +000043 return CurDAG->getTargetConstant(-((int)N->getZExtValue()), MVT::i32);
Evan Chengf49810c2009-06-23 17:48:47 +000044}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000045
Evan Chengf49810c2009-06-23 17:48:47 +000046// t2_so_imm - Match a 32-bit immediate operand, which is an
47// 8-bit immediate rotated by an arbitrary number of bits, or an 8-bit
Bob Wilson09989942011-02-07 17:43:06 +000048// immediate splatted into multiple bytes of the word.
Jim Grosbach6b8f1e32011-06-27 23:54:06 +000049def t2_so_imm_asmoperand : AsmOperandClass { let Name = "T2SOImm"; }
Eli Friedmanc573e2c2011-04-29 22:48:03 +000050def t2_so_imm : Operand<i32>, ImmLeaf<i32, [{
51 return ARM_AM::getT2SOImmVal(Imm) != -1;
52 }]> {
Jim Grosbach6b8f1e32011-06-27 23:54:06 +000053 let ParserMatchClass = t2_so_imm_asmoperand;
Chris Lattner2ac19022010-11-15 05:19:05 +000054 let EncoderMethod = "getT2SOImmOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +000055 let DecoderMethod = "DecodeT2SOImm";
Owen Anderson5de6d842010-11-12 21:12:40 +000056}
Anton Korobeynikov52237112009-06-17 18:13:58 +000057
Jim Grosbach64171712010-02-16 21:07:46 +000058// t2_so_imm_not - Match an immediate that is a complement
Evan Chengf49810c2009-06-23 17:48:47 +000059// of a t2_so_imm.
60def t2_so_imm_not : Operand<i32>,
61 PatLeaf<(imm), [{
Evan Chenge7cbe412009-07-08 21:03:57 +000062 return ARM_AM::getT2SOImmVal(~((uint32_t)N->getZExtValue())) != -1;
63}], t2_so_imm_not_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000064
65// t2_so_imm_neg - Match an immediate that is a negation of a t2_so_imm.
66def t2_so_imm_neg : Operand<i32>,
67 PatLeaf<(imm), [{
Evan Cheng875a6ac2010-11-12 22:42:47 +000068 return ARM_AM::getT2SOImmVal(-((uint32_t)N->getZExtValue())) != -1;
Evan Chenge7cbe412009-07-08 21:03:57 +000069}], t2_so_imm_neg_XFORM>;
Evan Chengf49810c2009-06-23 17:48:47 +000070
Evan Chenga67efd12009-06-23 19:39:13 +000071/// imm1_31 predicate - True if the 32-bit immediate is in the range [1,31].
Owen Anderson6d746312011-08-08 20:42:17 +000072def imm1_31 : Operand<i32>, ImmLeaf<i32, [{
Eric Christopher8f232d32011-04-28 05:49:04 +000073 return (int32_t)Imm >= 1 && (int32_t)Imm < 32;
Evan Chenga67efd12009-06-23 19:39:13 +000074}]>;
75
Evan Chengf49810c2009-06-23 17:48:47 +000076/// imm0_4095 predicate - True if the 32-bit immediate is in the range [0.4095].
Evan Cheng86198642009-08-07 00:34:42 +000077def imm0_4095 : Operand<i32>,
Eric Christopher8f232d32011-04-28 05:49:04 +000078 ImmLeaf<i32, [{
79 return Imm >= 0 && Imm < 4096;
Evan Chengf49810c2009-06-23 17:48:47 +000080}]>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000081
Jim Grosbach64171712010-02-16 21:07:46 +000082def imm0_4095_neg : PatLeaf<(i32 imm), [{
83 return (uint32_t)(-N->getZExtValue()) < 4096;
84}], imm_neg_XFORM>;
Anton Korobeynikov52237112009-06-17 18:13:58 +000085
Evan Chengfa2ea1a2009-08-04 01:41:15 +000086def imm0_255_neg : PatLeaf<(i32 imm), [{
87 return (uint32_t)(-N->getZExtValue()) < 255;
Jim Grosbach64171712010-02-16 21:07:46 +000088}], imm_neg_XFORM>;
Evan Chengfa2ea1a2009-08-04 01:41:15 +000089
Jim Grosbach502e0aa2010-07-14 17:45:16 +000090def imm0_255_not : PatLeaf<(i32 imm), [{
91 return (uint32_t)(~N->getZExtValue()) < 255;
92}], imm_comp_XFORM>;
93
Andrew Trickd49ffe82011-04-29 14:18:15 +000094def lo5AllOne : PatLeaf<(i32 imm), [{
95 // Returns true if all low 5-bits are 1.
96 return (((uint32_t)N->getZExtValue()) & 0x1FUL) == 0x1FUL;
97}]>;
98
Evan Cheng055b0312009-06-29 07:51:04 +000099// Define Thumb2 specific addressing modes.
100
101// t2addrmode_imm12 := reg + imm12
102def t2addrmode_imm12 : Operand<i32>,
103 ComplexPattern<i32, 2, "SelectT2AddrModeImm12", []> {
Jim Grosbach458f2dc2010-10-25 20:00:01 +0000104 let PrintMethod = "printAddrModeImm12Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000105 let EncoderMethod = "getAddrModeImm12OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000106 let DecoderMethod = "DecodeT2AddrModeImm12";
Evan Cheng055b0312009-06-29 07:51:04 +0000107 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
108}
109
Owen Andersonc9bd4962011-03-18 17:42:55 +0000110// t2ldrlabel := imm12
111def t2ldrlabel : Operand<i32> {
112 let EncoderMethod = "getAddrModeImm12OpValue";
113}
114
115
Owen Andersona838a252010-12-14 00:36:49 +0000116// ADR instruction labels.
117def t2adrlabel : Operand<i32> {
118 let EncoderMethod = "getT2AdrLabelOpValue";
119}
120
121
Johnny Chen0635fc52010-03-04 17:40:44 +0000122// t2addrmode_imm8 := reg +/- imm8
Jim Grosbach7ce05792011-08-03 23:50:40 +0000123def MemImm8OffsetAsmOperand : AsmOperandClass { let Name = "MemImm8Offset"; }
Evan Cheng055b0312009-06-29 07:51:04 +0000124def t2addrmode_imm8 : Operand<i32>,
125 ComplexPattern<i32, 2, "SelectT2AddrModeImm8", []> {
126 let PrintMethod = "printT2AddrModeImm8Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000127 let EncoderMethod = "getT2AddrModeImm8OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000128 let DecoderMethod = "DecodeT2AddrModeImm8";
Jim Grosbach7ce05792011-08-03 23:50:40 +0000129 let ParserMatchClass = MemImm8OffsetAsmOperand;
Evan Cheng055b0312009-06-29 07:51:04 +0000130 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
131}
132
Evan Cheng6d94f112009-07-03 00:06:39 +0000133def t2am_imm8_offset : Operand<i32>,
Chris Lattner52a261b2010-09-21 20:31:19 +0000134 ComplexPattern<i32, 1, "SelectT2AddrModeImm8Offset",
135 [], [SDNPWantRoot]> {
Evan Chenge88d5ce2009-07-02 07:28:31 +0000136 let PrintMethod = "printT2AddrModeImm8OffsetOperand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000137 let EncoderMethod = "getT2AddrModeImm8OffsetOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000138 let DecoderMethod = "DecodeT2Imm8";
Evan Chenge88d5ce2009-07-02 07:28:31 +0000139}
140
Evan Cheng5c874172009-07-09 22:21:59 +0000141// t2addrmode_imm8s4 := reg +/- (imm8 << 2)
Chris Lattner979b0612010-09-05 22:51:11 +0000142def t2addrmode_imm8s4 : Operand<i32> {
Evan Cheng5c874172009-07-09 22:21:59 +0000143 let PrintMethod = "printT2AddrModeImm8s4Operand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000144 let EncoderMethod = "getT2AddrModeImm8s4OpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000145 let DecoderMethod = "DecodeT2AddrModeImm8s4";
David Goodwin6647cea2009-06-30 22:50:01 +0000146 let MIOperandInfo = (ops GPR:$base, i32imm:$offsimm);
147}
148
Johnny Chenae1757b2010-03-11 01:13:36 +0000149def t2am_imm8s4_offset : Operand<i32> {
150 let PrintMethod = "printT2AddrModeImm8s4OffsetOperand";
Owen Anderson14c903a2011-08-04 23:18:05 +0000151 let DecoderMethod = "DecodeT2Imm8S4";
Johnny Chenae1757b2010-03-11 01:13:36 +0000152}
153
Evan Chengcba962d2009-07-09 20:40:44 +0000154// t2addrmode_so_reg := reg + (reg << imm2)
Evan Cheng055b0312009-06-29 07:51:04 +0000155def t2addrmode_so_reg : Operand<i32>,
156 ComplexPattern<i32, 3, "SelectT2AddrModeSoReg", []> {
157 let PrintMethod = "printT2AddrModeSoRegOperand";
Jim Grosbach683fc3e2010-12-10 20:53:44 +0000158 let EncoderMethod = "getT2AddrModeSORegOpValue";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000159 let DecoderMethod = "DecodeT2AddrModeSOReg";
Jim Grosbach6ccfc502010-07-30 02:41:01 +0000160 let MIOperandInfo = (ops GPR:$base, rGPR:$offsreg, i32imm:$offsimm);
Evan Cheng055b0312009-06-29 07:51:04 +0000161}
162
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000163// t2addrmode_reg := reg
164// Used by load/store exclusive instructions. Useful to enable right assembly
165// parsing and printing. Not used for any codegen matching.
166//
167def t2addrmode_reg : Operand<i32> {
168 let PrintMethod = "printAddrMode7Operand";
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000169 let DecoderMethod = "DecodeGPRRegisterClass";
Cameron Zwarichd6ffcd82011-05-17 23:26:20 +0000170 let MIOperandInfo = (ops GPR);
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +0000171}
Evan Cheng055b0312009-06-29 07:51:04 +0000172
Anton Korobeynikov52237112009-06-17 18:13:58 +0000173//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +0000174// Multiclass helpers...
Anton Korobeynikov52237112009-06-17 18:13:58 +0000175//
176
Owen Andersona99e7782010-11-15 18:45:17 +0000177
178class T2OneRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson83da6cd2010-11-14 05:37:38 +0000179 string opc, string asm, list<dag> pattern>
180 : T2I<oops, iops, itin, opc, asm, pattern> {
181 bits<4> Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000182 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000183
Jim Grosbach86386922010-12-08 22:10:43 +0000184 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000185 let Inst{26} = imm{11};
186 let Inst{14-12} = imm{10-8};
187 let Inst{7-0} = imm{7-0};
188}
189
Owen Andersonbb6315d2010-11-15 19:58:36 +0000190
Owen Andersona99e7782010-11-15 18:45:17 +0000191class T2sOneRegImm<dag oops, dag iops, InstrItinClass itin,
192 string opc, string asm, list<dag> pattern>
193 : T2sI<oops, iops, itin, opc, asm, pattern> {
194 bits<4> Rd;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000195 bits<4> Rn;
196 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000197
Jim Grosbach86386922010-12-08 22:10:43 +0000198 let Inst{11-8} = Rd;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000199 let Inst{26} = imm{11};
200 let Inst{14-12} = imm{10-8};
201 let Inst{7-0} = imm{7-0};
202}
203
Owen Andersonbb6315d2010-11-15 19:58:36 +0000204class T2OneRegCmpImm<dag oops, dag iops, InstrItinClass itin,
205 string opc, string asm, list<dag> pattern>
206 : T2I<oops, iops, itin, opc, asm, pattern> {
207 bits<4> Rn;
208 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000209
Jim Grosbach86386922010-12-08 22:10:43 +0000210 let Inst{19-16} = Rn;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000211 let Inst{26} = imm{11};
212 let Inst{14-12} = imm{10-8};
213 let Inst{7-0} = imm{7-0};
214}
215
216
Owen Andersona99e7782010-11-15 18:45:17 +0000217class T2OneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
218 string opc, string asm, list<dag> pattern>
219 : T2I<oops, iops, itin, opc, asm, pattern> {
220 bits<4> Rd;
221 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000222
Jim Grosbach86386922010-12-08 22:10:43 +0000223 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000224 let Inst{3-0} = ShiftedRm{3-0};
225 let Inst{5-4} = ShiftedRm{6-5};
226 let Inst{14-12} = ShiftedRm{11-9};
227 let Inst{7-6} = ShiftedRm{8-7};
228}
229
230class T2sOneRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
231 string opc, string asm, list<dag> pattern>
Owen Andersonbdf71442010-12-07 20:50:15 +0000232 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000233 bits<4> Rd;
234 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000235
Jim Grosbach86386922010-12-08 22:10:43 +0000236 let Inst{11-8} = Rd;
Owen Andersona99e7782010-11-15 18:45:17 +0000237 let Inst{3-0} = ShiftedRm{3-0};
238 let Inst{5-4} = ShiftedRm{6-5};
239 let Inst{14-12} = ShiftedRm{11-9};
240 let Inst{7-6} = ShiftedRm{8-7};
241}
242
Owen Andersonbb6315d2010-11-15 19:58:36 +0000243class T2OneRegCmpShiftedReg<dag oops, dag iops, InstrItinClass itin,
244 string opc, string asm, list<dag> pattern>
245 : T2I<oops, iops, itin, opc, asm, pattern> {
246 bits<4> Rn;
247 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000248
Jim Grosbach86386922010-12-08 22:10:43 +0000249 let Inst{19-16} = Rn;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000250 let Inst{3-0} = ShiftedRm{3-0};
251 let Inst{5-4} = ShiftedRm{6-5};
252 let Inst{14-12} = ShiftedRm{11-9};
253 let Inst{7-6} = ShiftedRm{8-7};
254}
255
Owen Andersona99e7782010-11-15 18:45:17 +0000256class T2TwoReg<dag oops, dag iops, InstrItinClass itin,
257 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000258 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000259 bits<4> Rd;
260 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000261
Jim Grosbach86386922010-12-08 22:10:43 +0000262 let Inst{11-8} = Rd;
263 let Inst{3-0} = Rm;
Owen Andersona99e7782010-11-15 18:45:17 +0000264}
265
266class T2sTwoReg<dag oops, dag iops, InstrItinClass itin,
267 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000268 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Andersona99e7782010-11-15 18:45:17 +0000269 bits<4> Rd;
270 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000271
Jim Grosbach86386922010-12-08 22:10:43 +0000272 let Inst{11-8} = Rd;
273 let Inst{3-0} = Rm;
Owen Andersona99e7782010-11-15 18:45:17 +0000274}
275
Owen Andersonbb6315d2010-11-15 19:58:36 +0000276class T2TwoRegCmp<dag oops, dag iops, InstrItinClass itin,
277 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000278 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Andersonbb6315d2010-11-15 19:58:36 +0000279 bits<4> Rn;
280 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000281
Jim Grosbach86386922010-12-08 22:10:43 +0000282 let Inst{19-16} = Rn;
283 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000284}
285
Owen Andersona99e7782010-11-15 18:45:17 +0000286
287class T2TwoRegImm<dag oops, dag iops, InstrItinClass itin,
288 string opc, string asm, list<dag> pattern>
289 : T2I<oops, iops, itin, opc, asm, pattern> {
290 bits<4> Rd;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000291 bits<4> Rn;
Jim Grosbach20e0fa62010-12-08 23:24:29 +0000292 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000293
Jim Grosbach86386922010-12-08 22:10:43 +0000294 let Inst{11-8} = Rd;
Jim Grosbach20e0fa62010-12-08 23:24:29 +0000295 let Inst{19-16} = Rn;
296 let Inst{26} = imm{11};
297 let Inst{14-12} = imm{10-8};
298 let Inst{7-0} = imm{7-0};
Owen Andersona99e7782010-11-15 18:45:17 +0000299}
300
Owen Anderson83da6cd2010-11-14 05:37:38 +0000301class T2sTwoRegImm<dag oops, dag iops, InstrItinClass itin,
Owen Anderson5de6d842010-11-12 21:12:40 +0000302 string opc, string asm, list<dag> pattern>
303 : T2sI<oops, iops, itin, opc, asm, pattern> {
304 bits<4> Rd;
305 bits<4> Rn;
306 bits<12> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000307
Jim Grosbach86386922010-12-08 22:10:43 +0000308 let Inst{11-8} = Rd;
309 let Inst{19-16} = Rn;
Owen Anderson5de6d842010-11-12 21:12:40 +0000310 let Inst{26} = imm{11};
311 let Inst{14-12} = imm{10-8};
312 let Inst{7-0} = imm{7-0};
313}
314
Owen Andersonbb6315d2010-11-15 19:58:36 +0000315class T2TwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
316 string opc, string asm, list<dag> pattern>
317 : T2I<oops, iops, itin, opc, asm, pattern> {
318 bits<4> Rd;
319 bits<4> Rm;
320 bits<5> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000321
Jim Grosbach86386922010-12-08 22:10:43 +0000322 let Inst{11-8} = Rd;
323 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000324 let Inst{14-12} = imm{4-2};
325 let Inst{7-6} = imm{1-0};
326}
327
328class T2sTwoRegShiftImm<dag oops, dag iops, InstrItinClass itin,
329 string opc, string asm, list<dag> pattern>
330 : T2sI<oops, iops, itin, opc, asm, pattern> {
331 bits<4> Rd;
332 bits<4> Rm;
333 bits<5> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000334
Jim Grosbach86386922010-12-08 22:10:43 +0000335 let Inst{11-8} = Rd;
336 let Inst{3-0} = Rm;
Owen Andersonbb6315d2010-11-15 19:58:36 +0000337 let Inst{14-12} = imm{4-2};
338 let Inst{7-6} = imm{1-0};
339}
340
Owen Anderson5de6d842010-11-12 21:12:40 +0000341class T2ThreeReg<dag oops, dag iops, InstrItinClass itin,
342 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000343 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000344 bits<4> Rd;
345 bits<4> Rn;
346 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000347
Jim Grosbach86386922010-12-08 22:10:43 +0000348 let Inst{11-8} = Rd;
349 let Inst{19-16} = Rn;
350 let Inst{3-0} = Rm;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000351}
352
353class T2sThreeReg<dag oops, dag iops, InstrItinClass itin,
354 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000355 : T2sI<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5de6d842010-11-12 21:12:40 +0000356 bits<4> Rd;
357 bits<4> Rn;
358 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000359
Jim Grosbach86386922010-12-08 22:10:43 +0000360 let Inst{11-8} = Rd;
361 let Inst{19-16} = Rn;
362 let Inst{3-0} = Rm;
Owen Anderson5de6d842010-11-12 21:12:40 +0000363}
364
365class T2TwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
366 string opc, string asm, list<dag> pattern>
Owen Anderson83da6cd2010-11-14 05:37:38 +0000367 : T2I<oops, iops, itin, opc, asm, pattern> {
368 bits<4> Rd;
369 bits<4> Rn;
370 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000371
Jim Grosbach86386922010-12-08 22:10:43 +0000372 let Inst{11-8} = Rd;
373 let Inst{19-16} = Rn;
Owen Anderson83da6cd2010-11-14 05:37:38 +0000374 let Inst{3-0} = ShiftedRm{3-0};
375 let Inst{5-4} = ShiftedRm{6-5};
376 let Inst{14-12} = ShiftedRm{11-9};
377 let Inst{7-6} = ShiftedRm{8-7};
378}
379
380class T2sTwoRegShiftedReg<dag oops, dag iops, InstrItinClass itin,
381 string opc, string asm, list<dag> pattern>
Owen Anderson5de6d842010-11-12 21:12:40 +0000382 : T2sI<oops, iops, itin, opc, asm, pattern> {
383 bits<4> Rd;
384 bits<4> Rn;
385 bits<12> ShiftedRm;
Jim Grosbach7a088642010-11-19 17:11:02 +0000386
Jim Grosbach86386922010-12-08 22:10:43 +0000387 let Inst{11-8} = Rd;
388 let Inst{19-16} = Rn;
Owen Anderson5de6d842010-11-12 21:12:40 +0000389 let Inst{3-0} = ShiftedRm{3-0};
390 let Inst{5-4} = ShiftedRm{6-5};
391 let Inst{14-12} = ShiftedRm{11-9};
392 let Inst{7-6} = ShiftedRm{8-7};
393}
394
Owen Anderson35141a92010-11-18 01:08:42 +0000395class T2FourReg<dag oops, dag iops, InstrItinClass itin,
396 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +0000397 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson35141a92010-11-18 01:08:42 +0000398 bits<4> Rd;
399 bits<4> Rn;
400 bits<4> Rm;
401 bits<4> Ra;
Jim Grosbach7a088642010-11-19 17:11:02 +0000402
Jim Grosbach86386922010-12-08 22:10:43 +0000403 let Inst{19-16} = Rn;
404 let Inst{15-12} = Ra;
405 let Inst{11-8} = Rd;
406 let Inst{3-0} = Rm;
Owen Anderson35141a92010-11-18 01:08:42 +0000407}
408
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000409class T2MulLong<bits<3> opc22_20, bits<4> opc7_4,
410 dag oops, dag iops, InstrItinClass itin,
411 string opc, string asm, list<dag> pattern>
Jim Grosbach52082042010-12-08 22:29:28 +0000412 : T2I<oops, iops, itin, opc, asm, pattern> {
413 bits<4> RdLo;
414 bits<4> RdHi;
415 bits<4> Rn;
416 bits<4> Rm;
417
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000418 let Inst{31-23} = 0b111110111;
419 let Inst{22-20} = opc22_20;
Jim Grosbach52082042010-12-08 22:29:28 +0000420 let Inst{19-16} = Rn;
421 let Inst{15-12} = RdLo;
422 let Inst{11-8} = RdHi;
Jim Grosbach7c6d85a2010-12-08 22:38:41 +0000423 let Inst{7-4} = opc7_4;
Jim Grosbach52082042010-12-08 22:29:28 +0000424 let Inst{3-0} = Rm;
425}
426
Owen Anderson35141a92010-11-18 01:08:42 +0000427
Evan Chenga67efd12009-06-23 19:39:13 +0000428/// T2I_un_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000429/// unary operation that produces a value. These are predicable and can be
430/// changed to modify CPSR.
Evan Cheng5d42c562010-09-29 00:49:25 +0000431multiclass T2I_un_irs<bits<4> opcod, string opc,
432 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
433 PatFrag opnode, bit Cheap = 0, bit ReMat = 0> {
Evan Chenga67efd12009-06-23 19:39:13 +0000434 // shifted imm
Owen Andersona99e7782010-11-15 18:45:17 +0000435 def i : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), iii,
436 opc, "\t$Rd, $imm",
437 [(set rGPR:$Rd, (opnode t2_so_imm:$imm))]> {
Evan Chenga67efd12009-06-23 19:39:13 +0000438 let isAsCheapAsAMove = Cheap;
439 let isReMaterializable = ReMat;
Johnny Chend68e1192009-12-15 17:24:14 +0000440 let Inst{31-27} = 0b11110;
441 let Inst{25} = 0;
442 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000443 let Inst{19-16} = 0b1111; // Rn
444 let Inst{15} = 0;
Evan Chenga67efd12009-06-23 19:39:13 +0000445 }
446 // register
Owen Andersona99e7782010-11-15 18:45:17 +0000447 def r : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), iir,
448 opc, ".w\t$Rd, $Rm",
449 [(set rGPR:$Rd, (opnode rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000450 let Inst{31-27} = 0b11101;
451 let Inst{26-25} = 0b01;
452 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000453 let Inst{19-16} = 0b1111; // Rn
454 let Inst{14-12} = 0b000; // imm3
455 let Inst{7-6} = 0b00; // imm2
456 let Inst{5-4} = 0b00; // type
457 }
Evan Chenga67efd12009-06-23 19:39:13 +0000458 // shifted register
Owen Andersona99e7782010-11-15 18:45:17 +0000459 def s : T2sOneRegShiftedReg<(outs rGPR:$Rd), (ins t2_so_reg:$ShiftedRm), iis,
460 opc, ".w\t$Rd, $ShiftedRm",
461 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000462 let Inst{31-27} = 0b11101;
463 let Inst{26-25} = 0b01;
464 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000465 let Inst{19-16} = 0b1111; // Rn
466 }
Evan Chenga67efd12009-06-23 19:39:13 +0000467}
468
469/// T2I_bin_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns for a
Bob Wilson4876bdb2010-05-25 04:43:08 +0000470/// binary operation that produces a value. These are predicable and can be
Evan Cheng0aa1d8c2009-06-25 02:08:06 +0000471/// changed to modify CPSR.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000472multiclass T2I_bin_irs<bits<4> opcod, string opc,
473 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
Jim Grosbachadf73662011-06-28 00:19:13 +0000474 PatFrag opnode, string baseOpc, bit Commutable = 0,
475 string wide = ""> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000476 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000477 def ri : T2sTwoRegImm<
478 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), iii,
479 opc, "\t$Rd, $Rn, $imm",
480 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000481 let Inst{31-27} = 0b11110;
482 let Inst{25} = 0;
483 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000484 let Inst{15} = 0;
485 }
Evan Chenga67efd12009-06-23 19:39:13 +0000486 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000487 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), iir,
488 opc, !strconcat(wide, "\t$Rd, $Rn, $Rm"),
489 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000490 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000491 let Inst{31-27} = 0b11101;
492 let Inst{26-25} = 0b01;
493 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000494 let Inst{14-12} = 0b000; // imm3
495 let Inst{7-6} = 0b00; // imm2
496 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000497 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000498 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000499 def rs : T2sTwoRegShiftedReg<
500 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm), iis,
501 opc, !strconcat(wide, "\t$Rd, $Rn, $ShiftedRm"),
502 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000503 let Inst{31-27} = 0b11101;
504 let Inst{26-25} = 0b01;
505 let Inst{24-21} = opcod;
Bill Wendling4822bce2010-08-30 01:47:35 +0000506 }
Jim Grosbachadf73662011-06-28 00:19:13 +0000507 // Assembly aliases for optional destination operand when it's the same
508 // as the source operand.
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000509 def : t2InstAlias<!strconcat(opc, "${s}${p} $Rdn, $imm"),
Jim Grosbachadf73662011-06-28 00:19:13 +0000510 (!cast<Instruction>(!strconcat(baseOpc, "ri")) rGPR:$Rdn, rGPR:$Rdn,
511 t2_so_imm:$imm, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000512 cc_out:$s)>;
513 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $Rm"),
Jim Grosbachadf73662011-06-28 00:19:13 +0000514 (!cast<Instruction>(!strconcat(baseOpc, "rr")) rGPR:$Rdn, rGPR:$Rdn,
515 rGPR:$Rm, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000516 cc_out:$s)>;
517 def : t2InstAlias<!strconcat(opc, "${s}${p}", wide, " $Rdn, $shift"),
Jim Grosbachadf73662011-06-28 00:19:13 +0000518 (!cast<Instruction>(!strconcat(baseOpc, "rs")) rGPR:$Rdn, rGPR:$Rdn,
519 t2_so_reg:$shift, pred:$p,
Jim Grosbacha33b31b2011-08-22 18:04:24 +0000520 cc_out:$s)>;
Bill Wendling4822bce2010-08-30 01:47:35 +0000521}
522
David Goodwin1f096272009-07-27 23:34:12 +0000523/// T2I_bin_w_irs - Same as T2I_bin_irs except these operations need
Jim Grosbachadf73662011-06-28 00:19:13 +0000524// the ".w" suffix to indicate that they are wide.
Evan Cheng7e1bf302010-09-29 00:27:46 +0000525multiclass T2I_bin_w_irs<bits<4> opcod, string opc,
526 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
Jim Grosbachadf73662011-06-28 00:19:13 +0000527 PatFrag opnode, string baseOpc, bit Commutable = 0> :
528 T2I_bin_irs<opcod, opc, iii, iir, iis, opnode, baseOpc, Commutable, ".w">;
Bill Wendling1f7bf0e2010-08-29 03:55:31 +0000529
Evan Cheng1e249e32009-06-25 20:59:23 +0000530/// T2I_rbin_is - Same as T2I_bin_irs except the order of operands are
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000531/// reversed. The 'rr' form is only defined for the disassembler; for codegen
532/// it is equivalent to the T2I_bin_irs counterpart.
533multiclass T2I_rbin_irs<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000534 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000535 def ri : T2sTwoRegImm<
536 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
537 opc, ".w\t$Rd, $Rn, $imm",
538 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000539 let Inst{31-27} = 0b11110;
540 let Inst{25} = 0;
541 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000542 let Inst{15} = 0;
543 }
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000544 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000545 def rr : T2sThreeReg<
546 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
547 opc, "\t$Rd, $Rn, $Rm",
Bob Wilson136e4912010-08-14 03:18:29 +0000548 [/* For disassembly only; pattern left blank */]> {
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000549 let Inst{31-27} = 0b11101;
550 let Inst{26-25} = 0b01;
551 let Inst{24-21} = opcod;
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000552 let Inst{14-12} = 0b000; // imm3
553 let Inst{7-6} = 0b00; // imm2
554 let Inst{5-4} = 0b00; // type
555 }
Evan Chengf49810c2009-06-23 17:48:47 +0000556 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000557 def rs : T2sTwoRegShiftedReg<
558 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
559 IIC_iALUsir, opc, "\t$Rd, $Rn, $ShiftedRm",
560 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000561 let Inst{31-27} = 0b11101;
562 let Inst{26-25} = 0b01;
563 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000564 }
Evan Chengf49810c2009-06-23 17:48:47 +0000565}
566
Evan Chenga67efd12009-06-23 19:39:13 +0000567/// T2I_bin_s_irs - Similar to T2I_bin_irs except it sets the 's' bit so the
Anton Korobeynikov52237112009-06-17 18:13:58 +0000568/// instruction modifies the CPSR register.
Daniel Dunbar8d66b782011-01-10 15:26:39 +0000569let isCodeGenOnly = 1, Defs = [CPSR] in {
Evan Cheng7e1bf302010-09-29 00:27:46 +0000570multiclass T2I_bin_s_irs<bits<4> opcod, string opc,
571 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
572 PatFrag opnode, bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000573 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000574 def ri : T2TwoRegImm<
575 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), iii,
576 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
577 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000578 let Inst{31-27} = 0b11110;
579 let Inst{25} = 0;
580 let Inst{24-21} = opcod;
581 let Inst{20} = 1; // The S bit.
582 let Inst{15} = 0;
583 }
Evan Chenga67efd12009-06-23 19:39:13 +0000584 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000585 def rr : T2ThreeReg<
586 (outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), iir,
587 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $Rm",
588 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000589 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000590 let Inst{31-27} = 0b11101;
591 let Inst{26-25} = 0b01;
592 let Inst{24-21} = opcod;
593 let Inst{20} = 1; // The S bit.
594 let Inst{14-12} = 0b000; // imm3
595 let Inst{7-6} = 0b00; // imm2
596 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000597 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000598 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000599 def rs : T2TwoRegShiftedReg<
600 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
601 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $ShiftedRm",
602 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000603 let Inst{31-27} = 0b11101;
604 let Inst{26-25} = 0b01;
605 let Inst{24-21} = opcod;
606 let Inst{20} = 1; // The S bit.
607 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000608}
609}
610
Evan Chenga67efd12009-06-23 19:39:13 +0000611/// T2I_bin_ii12rs - Defines a set of (op reg, {so_imm|imm0_4095|r|so_reg})
612/// patterns for a binary operation that produces a value.
Johnny Chend68e1192009-12-15 17:24:14 +0000613multiclass T2I_bin_ii12rs<bits<3> op23_21, string opc, PatFrag opnode,
614 bit Commutable = 0> {
Evan Chengf49810c2009-06-23 17:48:47 +0000615 // shifted imm
Jim Grosbach663e3392010-08-30 19:49:58 +0000616 // The register-immediate version is re-materializable. This is useful
617 // in particular for taking the address of a local.
618 let isReMaterializable = 1 in {
Owen Anderson83da6cd2010-11-14 05:37:38 +0000619 def ri : T2sTwoRegImm<
620 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
621 opc, ".w\t$Rd, $Rn, $imm",
622 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000623 let Inst{31-27} = 0b11110;
624 let Inst{25} = 0;
625 let Inst{24} = 1;
626 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000627 let Inst{15} = 0;
628 }
Jim Grosbach663e3392010-08-30 19:49:58 +0000629 }
Evan Chengf49810c2009-06-23 17:48:47 +0000630 // 12-bit imm
Jim Grosbach07e9b262010-12-08 23:04:16 +0000631 def ri12 : T2I<
Owen Anderson83da6cd2010-11-14 05:37:38 +0000632 (outs rGPR:$Rd), (ins GPR:$Rn, imm0_4095:$imm), IIC_iALUi,
633 !strconcat(opc, "w"), "\t$Rd, $Rn, $imm",
634 [(set rGPR:$Rd, (opnode GPR:$Rn, imm0_4095:$imm))]> {
Jim Grosbach07e9b262010-12-08 23:04:16 +0000635 bits<4> Rd;
636 bits<4> Rn;
637 bits<12> imm;
Johnny Chend68e1192009-12-15 17:24:14 +0000638 let Inst{31-27} = 0b11110;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000639 let Inst{26} = imm{11};
640 let Inst{25-24} = 0b10;
Johnny Chend68e1192009-12-15 17:24:14 +0000641 let Inst{23-21} = op23_21;
642 let Inst{20} = 0; // The S bit.
Jim Grosbach07e9b262010-12-08 23:04:16 +0000643 let Inst{19-16} = Rn;
Johnny Chend68e1192009-12-15 17:24:14 +0000644 let Inst{15} = 0;
Jim Grosbach07e9b262010-12-08 23:04:16 +0000645 let Inst{14-12} = imm{10-8};
646 let Inst{11-8} = Rd;
647 let Inst{7-0} = imm{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +0000648 }
Evan Chenga67efd12009-06-23 19:39:13 +0000649 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000650 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins GPR:$Rn, rGPR:$Rm), IIC_iALUr,
651 opc, ".w\t$Rd, $Rn, $Rm",
652 [(set rGPR:$Rd, (opnode GPR:$Rn, rGPR:$Rm))]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000653 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000654 let Inst{31-27} = 0b11101;
655 let Inst{26-25} = 0b01;
656 let Inst{24} = 1;
657 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000658 let Inst{14-12} = 0b000; // imm3
659 let Inst{7-6} = 0b00; // imm2
660 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000661 }
Evan Chengf49810c2009-06-23 17:48:47 +0000662 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000663 def rs : T2sTwoRegShiftedReg<
Jim Grosbach7a088642010-11-19 17:11:02 +0000664 (outs rGPR:$Rd), (ins GPR:$Rn, t2_so_reg:$ShiftedRm),
Owen Anderson83da6cd2010-11-14 05:37:38 +0000665 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
666 [(set rGPR:$Rd, (opnode GPR:$Rn, t2_so_reg:$ShiftedRm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000667 let Inst{31-27} = 0b11101;
Johnny Chend68e1192009-12-15 17:24:14 +0000668 let Inst{26-25} = 0b01;
Johnny Chend248ffb2010-01-08 17:41:33 +0000669 let Inst{24} = 1;
Johnny Chend68e1192009-12-15 17:24:14 +0000670 let Inst{23-21} = op23_21;
Johnny Chend68e1192009-12-15 17:24:14 +0000671 }
Evan Chengf49810c2009-06-23 17:48:47 +0000672}
673
Jim Grosbach6935efc2009-11-24 00:20:27 +0000674/// T2I_adde_sube_irs - Defines a set of (op reg, {so_imm|r|so_reg}) patterns
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000675/// for a binary operation that produces a value and use the carry
Jim Grosbach6935efc2009-11-24 00:20:27 +0000676/// bit. It's not predicable.
Evan Cheng62674222009-06-25 23:34:10 +0000677let Uses = [CPSR] in {
Jim Grosbach80dc1162010-02-16 21:23:02 +0000678multiclass T2I_adde_sube_irs<bits<4> opcod, string opc, PatFrag opnode,
679 bit Commutable = 0> {
Anton Korobeynikov52237112009-06-17 18:13:58 +0000680 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000681 def ri : T2sTwoRegImm<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000682 IIC_iALUi, opc, "\t$Rd, $Rn, $imm",
683 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000684 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000685 let Inst{31-27} = 0b11110;
686 let Inst{25} = 0;
687 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000688 let Inst{15} = 0;
689 }
Evan Chenga67efd12009-06-23 19:39:13 +0000690 // register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000691 def rr : T2sThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUr,
Owen Anderson5de6d842010-11-12 21:12:40 +0000692 opc, ".w\t$Rd, $Rn, $Rm",
693 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000694 Requires<[IsThumb2]> {
Evan Cheng8de898a2009-06-26 00:19:44 +0000695 let isCommutable = Commutable;
Johnny Chend68e1192009-12-15 17:24:14 +0000696 let Inst{31-27} = 0b11101;
697 let Inst{26-25} = 0b01;
698 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000699 let Inst{14-12} = 0b000; // imm3
700 let Inst{7-6} = 0b00; // imm2
701 let Inst{5-4} = 0b00; // type
Evan Cheng8de898a2009-06-26 00:19:44 +0000702 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000703 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000704 def rs : T2sTwoRegShiftedReg<
Jim Grosbach7a088642010-11-19 17:11:02 +0000705 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
Owen Anderson5de6d842010-11-12 21:12:40 +0000706 IIC_iALUsi, opc, ".w\t$Rd, $Rn, $ShiftedRm",
707 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>,
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000708 Requires<[IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000709 let Inst{31-27} = 0b11101;
710 let Inst{26-25} = 0b01;
711 let Inst{24-21} = opcod;
Johnny Chend68e1192009-12-15 17:24:14 +0000712 }
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000713}
Andrew Trick1c3af772011-04-23 03:55:32 +0000714}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000715
716// Carry setting variants
Andrew Trick1c3af772011-04-23 03:55:32 +0000717// NOTE: CPSR def omitted because it will be handled by the custom inserter.
718let usesCustomInserter = 1 in {
719multiclass T2I_adde_sube_s_irs<PatFrag opnode, bit Commutable = 0> {
Evan Cheng62674222009-06-25 23:34:10 +0000720 // shifted imm
Andrew Trick1c3af772011-04-23 03:55:32 +0000721 def ri : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm),
Owen Anderson16884412011-07-13 23:22:26 +0000722 4, IIC_iALUi,
Andrew Trick1c3af772011-04-23 03:55:32 +0000723 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_imm:$imm))]>;
Evan Cheng62674222009-06-25 23:34:10 +0000724 // register
Andrew Trick1c3af772011-04-23 03:55:32 +0000725 def rr : t2PseudoInst<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Owen Anderson16884412011-07-13 23:22:26 +0000726 4, IIC_iALUr,
Andrew Trick1c3af772011-04-23 03:55:32 +0000727 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000728 let isCommutable = Commutable;
Evan Cheng8de898a2009-06-26 00:19:44 +0000729 }
Evan Cheng62674222009-06-25 23:34:10 +0000730 // shifted register
Andrew Trick1c3af772011-04-23 03:55:32 +0000731 def rs : t2PseudoInst<
732 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
Owen Anderson16884412011-07-13 23:22:26 +0000733 4, IIC_iALUsi,
Andrew Trick1c3af772011-04-23 03:55:32 +0000734 [(set rGPR:$Rd, (opnode rGPR:$Rn, t2_so_reg:$ShiftedRm))]>;
Evan Chengf49810c2009-06-23 17:48:47 +0000735}
Jim Grosbach39be8fc2010-02-16 20:42:29 +0000736}
Evan Chengf49810c2009-06-23 17:48:47 +0000737
Bob Wilson20d8e4e2010-08-13 23:24:25 +0000738/// T2I_rbin_s_is - Same as T2I_rbin_irs except sets 's' bit and the register
739/// version is not needed since this is only for codegen.
Daniel Dunbar8d66b782011-01-10 15:26:39 +0000740let isCodeGenOnly = 1, Defs = [CPSR] in {
Johnny Chend68e1192009-12-15 17:24:14 +0000741multiclass T2I_rbin_s_is<bits<4> opcod, string opc, PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000742 // shifted imm
Owen Anderson83da6cd2010-11-14 05:37:38 +0000743 def ri : T2TwoRegImm<
744 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_imm:$imm), IIC_iALUi,
745 !strconcat(opc, "s"), ".w\t$Rd, $Rn, $imm",
746 [(set rGPR:$Rd, (opnode t2_so_imm:$imm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000747 let Inst{31-27} = 0b11110;
748 let Inst{25} = 0;
749 let Inst{24-21} = opcod;
750 let Inst{20} = 1; // The S bit.
751 let Inst{15} = 0;
752 }
Evan Chengf49810c2009-06-23 17:48:47 +0000753 // shifted register
Owen Anderson83da6cd2010-11-14 05:37:38 +0000754 def rs : T2TwoRegShiftedReg<
755 (outs rGPR:$Rd), (ins rGPR:$Rn, t2_so_reg:$ShiftedRm),
756 IIC_iALUsi, !strconcat(opc, "s"), "\t$Rd, $Rn, $ShiftedRm",
757 [(set rGPR:$Rd, (opnode t2_so_reg:$ShiftedRm, rGPR:$Rn))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000758 let Inst{31-27} = 0b11101;
759 let Inst{26-25} = 0b01;
760 let Inst{24-21} = opcod;
761 let Inst{20} = 1; // The S bit.
762 }
Evan Chengf49810c2009-06-23 17:48:47 +0000763}
764}
765
Evan Chenga67efd12009-06-23 19:39:13 +0000766/// T2I_sh_ir - Defines a set of (op reg, {so_imm|r}) patterns for a shift /
767// rotate operation that produces a value.
Owen Anderson6d746312011-08-08 20:42:17 +0000768multiclass T2I_sh_ir<bits<2> opcod, string opc, Operand ty, PatFrag opnode> {
Evan Chenga67efd12009-06-23 19:39:13 +0000769 // 5-bit imm
Owen Andersonbb6315d2010-11-15 19:58:36 +0000770 def ri : T2sTwoRegShiftImm<
Owen Anderson6d746312011-08-08 20:42:17 +0000771 (outs rGPR:$Rd), (ins rGPR:$Rm, ty:$imm), IIC_iMOVsi,
Owen Andersonbb6315d2010-11-15 19:58:36 +0000772 opc, ".w\t$Rd, $Rm, $imm",
Jim Grosbach70939ee2011-08-17 21:51:27 +0000773 [(set rGPR:$Rd, (opnode rGPR:$Rm, (i32 ty:$imm)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000774 let Inst{31-27} = 0b11101;
775 let Inst{26-21} = 0b010010;
776 let Inst{19-16} = 0b1111; // Rn
777 let Inst{5-4} = opcod;
778 }
Evan Chenga67efd12009-06-23 19:39:13 +0000779 // register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000780 def rr : T2sThreeReg<
781 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMOVsr,
782 opc, ".w\t$Rd, $Rn, $Rm",
783 [(set rGPR:$Rd, (opnode rGPR:$Rn, rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000784 let Inst{31-27} = 0b11111;
785 let Inst{26-23} = 0b0100;
786 let Inst{22-21} = opcod;
787 let Inst{15-12} = 0b1111;
788 let Inst{7-4} = 0b0000;
789 }
Evan Chenga67efd12009-06-23 19:39:13 +0000790}
Evan Chengf49810c2009-06-23 17:48:47 +0000791
Johnny Chend68e1192009-12-15 17:24:14 +0000792/// T2I_cmp_irs - Defines a set of (op r, {so_imm|r|so_reg}) cmp / test
Evan Chenga67efd12009-06-23 19:39:13 +0000793/// patterns. Similar to T2I_bin_irs except the instruction does not produce
Evan Chengf49810c2009-06-23 17:48:47 +0000794/// a explicit result, only implicitly set CPSR.
Bill Wendlingf0e132c2010-08-19 00:05:48 +0000795let isCompare = 1, Defs = [CPSR] in {
Evan Cheng5d42c562010-09-29 00:49:25 +0000796multiclass T2I_cmp_irs<bits<4> opcod, string opc,
797 InstrItinClass iii, InstrItinClass iir, InstrItinClass iis,
798 PatFrag opnode> {
Evan Chengf49810c2009-06-23 17:48:47 +0000799 // shifted imm
Owen Andersonbb6315d2010-11-15 19:58:36 +0000800 def ri : T2OneRegCmpImm<
801 (outs), (ins GPR:$Rn, t2_so_imm:$imm), iii,
802 opc, ".w\t$Rn, $imm",
803 [(opnode GPR:$Rn, t2_so_imm:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000804 let Inst{31-27} = 0b11110;
805 let Inst{25} = 0;
806 let Inst{24-21} = opcod;
807 let Inst{20} = 1; // The S bit.
808 let Inst{15} = 0;
809 let Inst{11-8} = 0b1111; // Rd
810 }
Evan Chenga67efd12009-06-23 19:39:13 +0000811 // register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000812 def rr : T2TwoRegCmp<
Owen Andersone732cb02011-08-23 17:37:32 +0000813 (outs), (ins GPR:$Rn, rGPR:$Rm), iir,
814 opc, ".w\t$Rn, $Rm",
815 [(opnode GPR:$Rn, rGPR:$Rm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000816 let Inst{31-27} = 0b11101;
817 let Inst{26-25} = 0b01;
818 let Inst{24-21} = opcod;
819 let Inst{20} = 1; // The S bit.
820 let Inst{14-12} = 0b000; // imm3
821 let Inst{11-8} = 0b1111; // Rd
822 let Inst{7-6} = 0b00; // imm2
823 let Inst{5-4} = 0b00; // type
824 }
Evan Chengf49810c2009-06-23 17:48:47 +0000825 // shifted register
Owen Andersonbb6315d2010-11-15 19:58:36 +0000826 def rs : T2OneRegCmpShiftedReg<
827 (outs), (ins GPR:$Rn, t2_so_reg:$ShiftedRm), iis,
828 opc, ".w\t$Rn, $ShiftedRm",
829 [(opnode GPR:$Rn, t2_so_reg:$ShiftedRm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000830 let Inst{31-27} = 0b11101;
831 let Inst{26-25} = 0b01;
832 let Inst{24-21} = opcod;
833 let Inst{20} = 1; // The S bit.
834 let Inst{11-8} = 0b1111; // Rd
835 }
Anton Korobeynikov52237112009-06-17 18:13:58 +0000836}
837}
838
Evan Chengf3c21b82009-06-30 02:15:48 +0000839/// T2I_ld - Defines a set of (op r, {imm12|imm8|so_reg}) load patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000840multiclass T2I_ld<bit signed, bits<2> opcod, string opc,
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000841 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
842 PatFrag opnode> {
843 def i12 : T2Ii12<(outs target:$Rt), (ins t2addrmode_imm12:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000844 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000845 [(set target:$Rt, (opnode t2addrmode_imm12:$addr))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000846 let Inst{31-27} = 0b11111;
847 let Inst{26-25} = 0b00;
848 let Inst{24} = signed;
849 let Inst{23} = 1;
850 let Inst{22-21} = opcod;
851 let Inst{20} = 1; // load
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000852
Owen Anderson75579f72010-11-29 22:44:32 +0000853 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000854 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000855
Owen Anderson80dd3e02010-11-30 22:45:47 +0000856 bits<17> addr;
Johnny Chenf9ce2cb2011-04-12 18:48:00 +0000857 let addr{12} = 1; // add = TRUE
Owen Anderson80dd3e02010-11-30 22:45:47 +0000858 let Inst{19-16} = addr{16-13}; // Rn
859 let Inst{23} = addr{12}; // U
860 let Inst{11-0} = addr{11-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000861 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000862 def i8 : T2Ii8 <(outs target:$Rt), (ins t2addrmode_imm8:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000863 opc, "\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000864 [(set target:$Rt, (opnode t2addrmode_imm8:$addr))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000865 let Inst{31-27} = 0b11111;
866 let Inst{26-25} = 0b00;
867 let Inst{24} = signed;
868 let Inst{23} = 0;
869 let Inst{22-21} = opcod;
870 let Inst{20} = 1; // load
871 let Inst{11} = 1;
872 // Offset: index==TRUE, wback==FALSE
873 let Inst{10} = 1; // The P bit.
874 let Inst{8} = 0; // The W bit.
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000875
Owen Anderson75579f72010-11-29 22:44:32 +0000876 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000877 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000878
Owen Anderson75579f72010-11-29 22:44:32 +0000879 bits<13> addr;
880 let Inst{19-16} = addr{12-9}; // Rn
881 let Inst{9} = addr{8}; // U
882 let Inst{7-0} = addr{7-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000883 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000884 def s : T2Iso <(outs target:$Rt), (ins t2addrmode_so_reg:$addr), iis,
Owen Anderson75579f72010-11-29 22:44:32 +0000885 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000886 [(set target:$Rt, (opnode t2addrmode_so_reg:$addr))]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000887 let Inst{31-27} = 0b11111;
888 let Inst{26-25} = 0b00;
889 let Inst{24} = signed;
890 let Inst{23} = 0;
891 let Inst{22-21} = opcod;
892 let Inst{20} = 1; // load
893 let Inst{11-6} = 0b000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000894
Owen Anderson75579f72010-11-29 22:44:32 +0000895 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000896 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000897
Owen Anderson75579f72010-11-29 22:44:32 +0000898 bits<10> addr;
899 let Inst{19-16} = addr{9-6}; // Rn
900 let Inst{3-0} = addr{5-2}; // Rm
901 let Inst{5-4} = addr{1-0}; // imm
Owen Anderson8d7d2e12011-08-09 20:55:18 +0000902
903 let DecoderMethod = "DecodeT2LoadShift";
Johnny Chend68e1192009-12-15 17:24:14 +0000904 }
Evan Chengbc7deb02010-11-03 05:14:24 +0000905
Owen Anderson971b83b2011-02-08 22:39:40 +0000906 // FIXME: Is the pci variant actually needed?
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000907 def pci : T2Ipc <(outs target:$Rt), (ins t2ldrlabel:$addr), iii,
Owen Anderson971b83b2011-02-08 22:39:40 +0000908 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000909 [(set target:$Rt, (opnode (ARMWrapper tconstpool:$addr)))]> {
Owen Anderson971b83b2011-02-08 22:39:40 +0000910 let isReMaterializable = 1;
911 let Inst{31-27} = 0b11111;
912 let Inst{26-25} = 0b00;
913 let Inst{24} = signed;
914 let Inst{23} = ?; // add = (U == '1')
915 let Inst{22-21} = opcod;
916 let Inst{20} = 1; // load
917 let Inst{19-16} = 0b1111; // Rn
918 bits<4> Rt;
919 bits<12> addr;
920 let Inst{15-12} = Rt{3-0};
921 let Inst{11-0} = addr{11-0};
922 }
Evan Chengf3c21b82009-06-30 02:15:48 +0000923}
924
David Goodwin73b8f162009-06-30 22:11:34 +0000925/// T2I_st - Defines a set of (op r, {imm12|imm8|so_reg}) store patterns.
Evan Cheng0e55fd62010-09-30 01:08:25 +0000926multiclass T2I_st<bits<2> opcod, string opc,
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000927 InstrItinClass iii, InstrItinClass iis, RegisterClass target,
928 PatFrag opnode> {
929 def i12 : T2Ii12<(outs), (ins target:$Rt, t2addrmode_imm12:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000930 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000931 [(opnode target:$Rt, t2addrmode_imm12:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000932 let Inst{31-27} = 0b11111;
933 let Inst{26-23} = 0b0001;
934 let Inst{22-21} = opcod;
935 let Inst{20} = 0; // !load
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000936
Owen Anderson75579f72010-11-29 22:44:32 +0000937 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000938 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000939
Owen Anderson80dd3e02010-11-30 22:45:47 +0000940 bits<17> addr;
Johnny Chenf9ce2cb2011-04-12 18:48:00 +0000941 let addr{12} = 1; // add = TRUE
Owen Anderson80dd3e02010-11-30 22:45:47 +0000942 let Inst{19-16} = addr{16-13}; // Rn
943 let Inst{23} = addr{12}; // U
944 let Inst{11-0} = addr{11-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000945 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000946 def i8 : T2Ii8 <(outs), (ins target:$Rt, t2addrmode_imm8:$addr), iii,
Owen Anderson75579f72010-11-29 22:44:32 +0000947 opc, "\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000948 [(opnode target:$Rt, t2addrmode_imm8:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000949 let Inst{31-27} = 0b11111;
950 let Inst{26-23} = 0b0000;
951 let Inst{22-21} = opcod;
952 let Inst{20} = 0; // !load
953 let Inst{11} = 1;
954 // Offset: index==TRUE, wback==FALSE
955 let Inst{10} = 1; // The P bit.
956 let Inst{8} = 0; // The W bit.
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000957
Owen Anderson75579f72010-11-29 22:44:32 +0000958 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000959 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000960
Owen Anderson75579f72010-11-29 22:44:32 +0000961 bits<13> addr;
962 let Inst{19-16} = addr{12-9}; // Rn
963 let Inst{9} = addr{8}; // U
964 let Inst{7-0} = addr{7-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000965 }
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000966 def s : T2Iso <(outs), (ins target:$Rt, t2addrmode_so_reg:$addr), iis,
Owen Anderson75579f72010-11-29 22:44:32 +0000967 opc, ".w\t$Rt, $addr",
Owen Anderson9fe72bc2011-08-11 20:40:40 +0000968 [(opnode target:$Rt, t2addrmode_so_reg:$addr)]> {
Johnny Chend68e1192009-12-15 17:24:14 +0000969 let Inst{31-27} = 0b11111;
970 let Inst{26-23} = 0b0000;
971 let Inst{22-21} = opcod;
972 let Inst{20} = 0; // !load
973 let Inst{11-6} = 0b000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000974
Owen Anderson75579f72010-11-29 22:44:32 +0000975 bits<4> Rt;
Jim Grosbach86386922010-12-08 22:10:43 +0000976 let Inst{15-12} = Rt;
Jim Grosbach7721e7f2010-12-02 23:05:38 +0000977
Owen Anderson75579f72010-11-29 22:44:32 +0000978 bits<10> addr;
979 let Inst{19-16} = addr{9-6}; // Rn
980 let Inst{3-0} = addr{5-2}; // Rm
981 let Inst{5-4} = addr{1-0}; // imm
Johnny Chend68e1192009-12-15 17:24:14 +0000982 }
David Goodwin73b8f162009-06-30 22:11:34 +0000983}
984
Evan Cheng0e55fd62010-09-30 01:08:25 +0000985/// T2I_ext_rrot - A unary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +0000986/// register and one whose operand is a register rotated by 8/16/24.
Jim Grosbachc5a8c862011-07-27 16:47:19 +0000987class T2I_ext_rrot<bits<3> opcod, string opc, PatFrag opnode>
988 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
989 opc, ".w\t$Rd, $Rm$rot",
Eli Friedman2cb1dfa2011-08-08 19:49:37 +0000990 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
991 Requires<[IsThumb2]> {
Jim Grosbachc5a8c862011-07-27 16:47:19 +0000992 let Inst{31-27} = 0b11111;
993 let Inst{26-23} = 0b0100;
994 let Inst{22-20} = opcod;
995 let Inst{19-16} = 0b1111; // Rn
996 let Inst{15-12} = 0b1111;
997 let Inst{7} = 1;
Jim Grosbach7a088642010-11-19 17:11:02 +0000998
Jim Grosbachc5a8c862011-07-27 16:47:19 +0000999 bits<2> rot;
1000 let Inst{5-4} = rot{1-0}; // rotate
Evan Chengd27c9fc2009-07-03 01:43:10 +00001001}
1002
Eli Friedman761fa7a2010-06-24 18:20:04 +00001003// UXTB16 - Requres T2ExtractPack, does not need the .w qualifier.
Jim Grosbach70327412011-07-27 17:48:13 +00001004class T2I_ext_rrot_uxtb16<bits<3> opcod, string opc, PatFrag opnode>
Owen Andersone732cb02011-08-23 17:37:32 +00001005 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot),
1006 IIC_iEXTr, opc, "\t$Rd, $Rm$rot",
1007 [(set rGPR:$Rd, (opnode (rotr rGPR:$Rm, rot_imm:$rot)))]>,
Jim Grosbach70327412011-07-27 17:48:13 +00001008 Requires<[HasT2ExtractPack, IsThumb2]> {
1009 bits<2> rot;
1010 let Inst{31-27} = 0b11111;
1011 let Inst{26-23} = 0b0100;
1012 let Inst{22-20} = opcod;
1013 let Inst{19-16} = 0b1111; // Rn
1014 let Inst{15-12} = 0b1111;
1015 let Inst{7} = 1;
1016 let Inst{5-4} = rot;
Johnny Chen267124c2010-03-04 22:24:41 +00001017}
1018
Eli Friedman761fa7a2010-06-24 18:20:04 +00001019// SXTB16 - Requres T2ExtractPack, does not need the .w qualifier, no pattern
1020// supported yet.
Jim Grosbach70327412011-07-27 17:48:13 +00001021class T2I_ext_rrot_sxtb16<bits<3> opcod, string opc>
1022 : T2TwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm, rot_imm:$rot), IIC_iEXTr,
1023 opc, "\t$Rd, $Rm$rot", []>,
Jim Grosbacha7603982011-07-01 21:12:19 +00001024 Requires<[IsThumb2, HasT2ExtractPack]> {
Jim Grosbach70327412011-07-27 17:48:13 +00001025 bits<2> rot;
1026 let Inst{31-27} = 0b11111;
1027 let Inst{26-23} = 0b0100;
1028 let Inst{22-20} = opcod;
1029 let Inst{19-16} = 0b1111; // Rn
1030 let Inst{15-12} = 0b1111;
1031 let Inst{7} = 1;
1032 let Inst{5-4} = rot;
Johnny Chen93042d12010-03-02 18:14:57 +00001033}
1034
Evan Cheng0e55fd62010-09-30 01:08:25 +00001035/// T2I_exta_rrot - A binary operation with two forms: one whose operand is a
Evan Chengd27c9fc2009-07-03 01:43:10 +00001036/// register and one whose operand is a register rotated by 8/16/24.
Jim Grosbach70327412011-07-27 17:48:13 +00001037class T2I_exta_rrot<bits<3> opcod, string opc, PatFrag opnode>
1038 : T2ThreeReg<(outs rGPR:$Rd),
1039 (ins rGPR:$Rn, rGPR:$Rm, rot_imm:$rot),
1040 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot",
1041 [(set rGPR:$Rd, (opnode rGPR:$Rn, (rotr rGPR:$Rm,rot_imm:$rot)))]>,
1042 Requires<[HasT2ExtractPack, IsThumb2]> {
1043 bits<2> rot;
1044 let Inst{31-27} = 0b11111;
1045 let Inst{26-23} = 0b0100;
1046 let Inst{22-20} = opcod;
1047 let Inst{15-12} = 0b1111;
1048 let Inst{7} = 1;
1049 let Inst{5-4} = rot;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001050}
1051
Jim Grosbach70327412011-07-27 17:48:13 +00001052class T2I_exta_rrot_np<bits<3> opcod, string opc>
1053 : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm,rot_imm:$rot),
1054 IIC_iEXTAsr, opc, "\t$Rd, $Rn, $Rm$rot", []> {
1055 bits<2> rot;
1056 let Inst{31-27} = 0b11111;
1057 let Inst{26-23} = 0b0100;
1058 let Inst{22-20} = opcod;
1059 let Inst{15-12} = 0b1111;
1060 let Inst{7} = 1;
1061 let Inst{5-4} = rot;
Johnny Chen93042d12010-03-02 18:14:57 +00001062}
1063
Anton Korobeynikov52237112009-06-17 18:13:58 +00001064//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001065// Instructions
1066//===----------------------------------------------------------------------===//
1067
1068//===----------------------------------------------------------------------===//
Evan Chenga09b9ca2009-06-24 23:47:58 +00001069// Miscellaneous Instructions.
1070//
1071
Owen Andersonda663f72010-11-15 21:30:39 +00001072class T2PCOneRegImm<dag oops, dag iops, InstrItinClass itin,
1073 string asm, list<dag> pattern>
1074 : T2XI<oops, iops, itin, asm, pattern> {
1075 bits<4> Rd;
1076 bits<12> label;
Jim Grosbach7a088642010-11-19 17:11:02 +00001077
Jim Grosbach86386922010-12-08 22:10:43 +00001078 let Inst{11-8} = Rd;
Owen Andersonda663f72010-11-15 21:30:39 +00001079 let Inst{26} = label{11};
1080 let Inst{14-12} = label{10-8};
1081 let Inst{7-0} = label{7-0};
1082}
1083
Evan Chenga09b9ca2009-06-24 23:47:58 +00001084// LEApcrel - Load a pc-relative address into a register without offending the
1085// assembler.
Owen Andersona838a252010-12-14 00:36:49 +00001086def t2ADR : T2PCOneRegImm<(outs rGPR:$Rd),
1087 (ins t2adrlabel:$addr, pred:$p),
1088 IIC_iALUi, "adr{$p}.w\t$Rd, #$addr", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001089 let Inst{31-27} = 0b11110;
1090 let Inst{25-24} = 0b10;
1091 // Inst{23:21} = '11' (add = FALSE) or '00' (add = TRUE)
1092 let Inst{22} = 0;
1093 let Inst{20} = 0;
1094 let Inst{19-16} = 0b1111; // Rn
1095 let Inst{15} = 0;
Jim Grosbach00f25fa2010-12-14 20:46:39 +00001096
Owen Andersona838a252010-12-14 00:36:49 +00001097 bits<4> Rd;
1098 bits<13> addr;
1099 let Inst{11-8} = Rd;
1100 let Inst{23} = addr{12};
1101 let Inst{21} = addr{12};
1102 let Inst{26} = addr{11};
1103 let Inst{14-12} = addr{10-8};
1104 let Inst{7-0} = addr{7-0};
Owen Anderson6b8719f2010-12-13 22:51:08 +00001105}
Owen Andersona838a252010-12-14 00:36:49 +00001106
1107let neverHasSideEffects = 1, isReMaterializable = 1 in
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001108def t2LEApcrel : t2PseudoInst<(outs rGPR:$Rd), (ins i32imm:$label, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001109 4, IIC_iALUi, []>;
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001110def t2LEApcrelJT : t2PseudoInst<(outs rGPR:$Rd),
1111 (ins i32imm:$label, nohash_imm:$id, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00001112 4, IIC_iALUi,
Jim Grosbach41b1d4e2010-12-15 18:48:45 +00001113 []>;
Evan Chenga09b9ca2009-06-24 23:47:58 +00001114
Jim Grosbach60fc2ed2010-12-08 23:30:19 +00001115
Evan Chenga09b9ca2009-06-24 23:47:58 +00001116//===----------------------------------------------------------------------===//
Evan Cheng9cb9e672009-06-27 02:26:13 +00001117// Load / store Instructions.
1118//
1119
Evan Cheng055b0312009-06-29 07:51:04 +00001120// Load
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00001121let canFoldAsLoad = 1, isReMaterializable = 1 in
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001122defm t2LDR : T2I_ld<0, 0b10, "ldr", IIC_iLoad_i, IIC_iLoad_si, GPR,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001123 UnOpFrag<(load node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001124
Evan Chengf3c21b82009-06-30 02:15:48 +00001125// Loads with zero extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001126defm t2LDRH : T2I_ld<0, 0b01, "ldrh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001127 rGPR, UnOpFrag<(zextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001128defm t2LDRB : T2I_ld<0, 0b00, "ldrb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001129 rGPR, UnOpFrag<(zextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001130
Evan Chengf3c21b82009-06-30 02:15:48 +00001131// Loads with sign extension
Evan Cheng7e2fe912010-10-28 06:47:08 +00001132defm t2LDRSH : T2I_ld<1, 0b01, "ldrsh", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001133 rGPR, UnOpFrag<(sextloadi16 node:$Src)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001134defm t2LDRSB : T2I_ld<1, 0b00, "ldrsb", IIC_iLoad_bh_i, IIC_iLoad_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001135 rGPR, UnOpFrag<(sextloadi8 node:$Src)>>;
Evan Cheng055b0312009-06-29 07:51:04 +00001136
Owen Anderson9d63d902010-12-01 19:18:46 +00001137let mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1 in {
Evan Chengf3c21b82009-06-30 02:15:48 +00001138// Load doubleword
Owen Anderson9d63d902010-12-01 19:18:46 +00001139def t2LDRDi8 : T2Ii8s4<1, 0, 1, (outs rGPR:$Rt, rGPR:$Rt2),
Evan Chenge298ab22009-09-27 09:46:04 +00001140 (ins t2addrmode_imm8s4:$addr),
Owen Anderson9d63d902010-12-01 19:18:46 +00001141 IIC_iLoad_d_i, "ldrd", "\t$Rt, $Rt2, $addr", []>;
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001142} // mayLoad = 1, neverHasSideEffects = 1, hasExtraDefRegAllocReq = 1
Evan Chengf3c21b82009-06-30 02:15:48 +00001143
1144// zextload i1 -> zextload i8
1145def : T2Pat<(zextloadi1 t2addrmode_imm12:$addr),
1146 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1147def : T2Pat<(zextloadi1 t2addrmode_imm8:$addr),
1148 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1149def : T2Pat<(zextloadi1 t2addrmode_so_reg:$addr),
1150 (t2LDRBs t2addrmode_so_reg:$addr)>;
1151def : T2Pat<(zextloadi1 (ARMWrapper tconstpool:$addr)),
1152 (t2LDRBpci tconstpool:$addr)>;
1153
1154// extload -> zextload
1155// FIXME: Reduce the number of patterns by legalizing extload to zextload
1156// earlier?
1157def : T2Pat<(extloadi1 t2addrmode_imm12:$addr),
1158 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1159def : T2Pat<(extloadi1 t2addrmode_imm8:$addr),
1160 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1161def : T2Pat<(extloadi1 t2addrmode_so_reg:$addr),
1162 (t2LDRBs t2addrmode_so_reg:$addr)>;
1163def : T2Pat<(extloadi1 (ARMWrapper tconstpool:$addr)),
1164 (t2LDRBpci tconstpool:$addr)>;
1165
1166def : T2Pat<(extloadi8 t2addrmode_imm12:$addr),
1167 (t2LDRBi12 t2addrmode_imm12:$addr)>;
1168def : T2Pat<(extloadi8 t2addrmode_imm8:$addr),
1169 (t2LDRBi8 t2addrmode_imm8:$addr)>;
1170def : T2Pat<(extloadi8 t2addrmode_so_reg:$addr),
1171 (t2LDRBs t2addrmode_so_reg:$addr)>;
1172def : T2Pat<(extloadi8 (ARMWrapper tconstpool:$addr)),
1173 (t2LDRBpci tconstpool:$addr)>;
1174
1175def : T2Pat<(extloadi16 t2addrmode_imm12:$addr),
1176 (t2LDRHi12 t2addrmode_imm12:$addr)>;
1177def : T2Pat<(extloadi16 t2addrmode_imm8:$addr),
1178 (t2LDRHi8 t2addrmode_imm8:$addr)>;
1179def : T2Pat<(extloadi16 t2addrmode_so_reg:$addr),
1180 (t2LDRHs t2addrmode_so_reg:$addr)>;
1181def : T2Pat<(extloadi16 (ARMWrapper tconstpool:$addr)),
1182 (t2LDRHpci tconstpool:$addr)>;
Evan Cheng055b0312009-06-29 07:51:04 +00001183
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001184// FIXME: The destination register of the loads and stores can't be PC, but
1185// can be SP. We need another regclass (similar to rGPR) to represent
1186// that. Not a pressing issue since these are selected manually,
1187// not via pattern.
1188
Evan Chenge88d5ce2009-07-02 07:28:31 +00001189// Indexed loads
Owen Anderson6af50f72010-11-30 00:14:31 +00001190
Evan Cheng5fd1c9b2010-05-19 06:07:03 +00001191let mayLoad = 1, neverHasSideEffects = 1 in {
Owen Anderson6b0fa632010-12-09 02:56:12 +00001192def t2LDR_PRE : T2Iidxldst<0, 0b10, 1, 1, (outs GPR:$Rt, GPR:$Rn),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001193 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001194 AddrModeT2_i8, IndexModePre, IIC_iLoad_iu,
Owen Anderson6af50f72010-11-30 00:14:31 +00001195 "ldr", "\t$Rt, $addr!", "$addr.base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001196 []>;
1197
Owen Anderson6b0fa632010-12-09 02:56:12 +00001198def t2LDR_POST : T2Iidxldst<0, 0b10, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1199 (ins GPR:$base, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001200 AddrModeT2_i8, IndexModePost, IIC_iLoad_iu,
Owen Anderson6b0fa632010-12-09 02:56:12 +00001201 "ldr", "\t$Rt, [$Rn], $addr", "$base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001202 []>;
1203
Owen Anderson6b0fa632010-12-09 02:56:12 +00001204def t2LDRB_PRE : T2Iidxldst<0, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001205 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001206 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Owen Anderson6af50f72010-11-30 00:14:31 +00001207 "ldrb", "\t$Rt, $addr!", "$addr.base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001208 []>;
Owen Anderson6b0fa632010-12-09 02:56:12 +00001209def t2LDRB_POST : T2Iidxldst<0, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1210 (ins GPR:$base, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001211 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson6b0fa632010-12-09 02:56:12 +00001212 "ldrb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001213 []>;
1214
Owen Anderson6b0fa632010-12-09 02:56:12 +00001215def t2LDRH_PRE : T2Iidxldst<0, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
Evan Chenge88d5ce2009-07-02 07:28:31 +00001216 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001217 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Owen Anderson6af50f72010-11-30 00:14:31 +00001218 "ldrh", "\t$Rt, $addr!", "$addr.base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001219 []>;
Owen Anderson6b0fa632010-12-09 02:56:12 +00001220def t2LDRH_POST : T2Iidxldst<0, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1221 (ins GPR:$base, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001222 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson6b0fa632010-12-09 02:56:12 +00001223 "ldrh", "\t$Rt, [$Rn], $addr", "$base = $Rn",
Evan Chenge88d5ce2009-07-02 07:28:31 +00001224 []>;
1225
Owen Anderson6b0fa632010-12-09 02:56:12 +00001226def t2LDRSB_PRE : T2Iidxldst<1, 0b00, 1, 1, (outs GPR:$Rt, GPR:$Rn),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001227 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001228 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Owen Anderson6af50f72010-11-30 00:14:31 +00001229 "ldrsb", "\t$Rt, $addr!", "$addr.base = $Rn",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001230 []>;
Owen Anderson6b0fa632010-12-09 02:56:12 +00001231def t2LDRSB_POST : T2Iidxldst<1, 0b00, 1, 0, (outs GPR:$Rt, GPR:$Rn),
1232 (ins GPR:$base, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001233 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson6b0fa632010-12-09 02:56:12 +00001234 "ldrsb", "\t$Rt, [$Rn], $addr", "$base = $Rn",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001235 []>;
1236
Owen Anderson6b0fa632010-12-09 02:56:12 +00001237def t2LDRSH_PRE : T2Iidxldst<1, 0b01, 1, 1, (outs GPR:$Rt, GPR:$Rn),
Evan Cheng4fbb9962009-07-02 23:16:11 +00001238 (ins t2addrmode_imm8:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001239 AddrModeT2_i8, IndexModePre, IIC_iLoad_bh_iu,
Owen Anderson6af50f72010-11-30 00:14:31 +00001240 "ldrsh", "\t$Rt, $addr!", "$addr.base = $Rn",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001241 []>;
Owen Anderson2379fc22011-08-22 23:22:05 +00001242def t2LDRSH_POST : T2Iidxldst<1, 0b01, 1, 0, (outs GPR:$Rt, GPR:$Rn),
Owen Anderson6b0fa632010-12-09 02:56:12 +00001243 (ins GPR:$base, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001244 AddrModeT2_i8, IndexModePost, IIC_iLoad_bh_iu,
Owen Anderson2379fc22011-08-22 23:22:05 +00001245 "ldrsh", "\t$Rt, [$Rn], $addr", "$base = $Rn",
Evan Cheng4fbb9962009-07-02 23:16:11 +00001246 []>;
Jim Grosbach7a088642010-11-19 17:11:02 +00001247} // mayLoad = 1, neverHasSideEffects = 1
Evan Cheng4fbb9962009-07-02 23:16:11 +00001248
Johnny Chene54a3ef2010-03-03 18:45:36 +00001249// LDRT, LDRBT, LDRHT, LDRSBT, LDRSHT all have offset mode (PUW=0b110) and are
1250// for disassembly only.
1251// Ref: A8.6.57 LDR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001252class T2IldT<bit signed, bits<2> type, string opc, InstrItinClass ii>
Johnny Chen471d73d2011-04-13 21:04:32 +00001253 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001254 "\t$Rt, $addr", []> {
Johnny Chene54a3ef2010-03-03 18:45:36 +00001255 let Inst{31-27} = 0b11111;
1256 let Inst{26-25} = 0b00;
1257 let Inst{24} = signed;
1258 let Inst{23} = 0;
1259 let Inst{22-21} = type;
1260 let Inst{20} = 1; // load
1261 let Inst{11} = 1;
1262 let Inst{10-8} = 0b110; // PUW.
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001263
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001264 bits<4> Rt;
1265 bits<13> addr;
Jim Grosbach86386922010-12-08 22:10:43 +00001266 let Inst{15-12} = Rt;
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001267 let Inst{19-16} = addr{12-9};
1268 let Inst{7-0} = addr{7-0};
Johnny Chene54a3ef2010-03-03 18:45:36 +00001269}
1270
Evan Cheng0e55fd62010-09-30 01:08:25 +00001271def t2LDRT : T2IldT<0, 0b10, "ldrt", IIC_iLoad_i>;
1272def t2LDRBT : T2IldT<0, 0b00, "ldrbt", IIC_iLoad_bh_i>;
1273def t2LDRHT : T2IldT<0, 0b01, "ldrht", IIC_iLoad_bh_i>;
1274def t2LDRSBT : T2IldT<1, 0b00, "ldrsbt", IIC_iLoad_bh_i>;
1275def t2LDRSHT : T2IldT<1, 0b01, "ldrsht", IIC_iLoad_bh_i>;
Johnny Chene54a3ef2010-03-03 18:45:36 +00001276
David Goodwin73b8f162009-06-30 22:11:34 +00001277// Store
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001278defm t2STR :T2I_st<0b10,"str", IIC_iStore_i, IIC_iStore_si, GPR,
Evan Cheng0e55fd62010-09-30 01:08:25 +00001279 BinOpFrag<(store node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001280defm t2STRB:T2I_st<0b00,"strb", IIC_iStore_bh_i, IIC_iStore_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001281 rGPR, BinOpFrag<(truncstorei8 node:$LHS, node:$RHS)>>;
Evan Cheng7e2fe912010-10-28 06:47:08 +00001282defm t2STRH:T2I_st<0b01,"strh", IIC_iStore_bh_i, IIC_iStore_bh_si,
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001283 rGPR, BinOpFrag<(truncstorei16 node:$LHS, node:$RHS)>>;
David Goodwin73b8f162009-06-30 22:11:34 +00001284
David Goodwin6647cea2009-06-30 22:50:01 +00001285// Store doubleword
Owen Anderson9d63d902010-12-01 19:18:46 +00001286let mayLoad = 1, neverHasSideEffects = 1, hasExtraSrcRegAllocReq = 1 in
Johnny Chend68e1192009-12-15 17:24:14 +00001287def t2STRDi8 : T2Ii8s4<1, 0, 0, (outs),
Owen Anderson9d63d902010-12-01 19:18:46 +00001288 (ins GPR:$Rt, GPR:$Rt2, t2addrmode_imm8s4:$addr),
1289 IIC_iStore_d_r, "strd", "\t$Rt, $Rt2, $addr", []>;
David Goodwin6647cea2009-06-30 22:50:01 +00001290
Evan Cheng6d94f112009-07-03 00:06:39 +00001291// Indexed stores
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001292def t2STR_PRE : T2Iidxldst<0, 0b10, 0, 1, (outs GPRnopc:$base_wb),
1293 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001294 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001295 "str", "\t$Rt, [$Rn, $addr]!",
1296 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001297 [(set GPRnopc:$base_wb,
1298 (pre_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001299
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001300def t2STR_POST : T2Iidxldst<0, 0b10, 0, 0, (outs GPRnopc:$base_wb),
1301 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001302 AddrModeT2_i8, IndexModePost, IIC_iStore_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001303 "str", "\t$Rt, [$Rn], $addr",
1304 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001305 [(set GPRnopc:$base_wb,
1306 (post_store rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001307
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001308def t2STRH_PRE : T2Iidxldst<0, 0b01, 0, 1, (outs GPRnopc:$base_wb),
1309 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001310 AddrModeT2_i8, IndexModePre, IIC_iStore_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001311 "strh", "\t$Rt, [$Rn, $addr]!",
1312 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001313 [(set GPRnopc:$base_wb,
1314 (pre_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001315
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001316def t2STRH_POST : T2Iidxldst<0, 0b01, 0, 0, (outs GPRnopc:$base_wb),
1317 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001318 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001319 "strh", "\t$Rt, [$Rn], $addr",
1320 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001321 [(set GPRnopc:$base_wb,
1322 (post_truncsti16 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001323
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001324def t2STRB_PRE : T2Iidxldst<0, 0b00, 0, 1, (outs GPRnopc:$base_wb),
1325 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001326 AddrModeT2_i8, IndexModePre, IIC_iStore_bh_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001327 "strb", "\t$Rt, [$Rn, $addr]!",
1328 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001329 [(set GPRnopc:$base_wb,
1330 (pre_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001331
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001332def t2STRB_POST : T2Iidxldst<0, 0b00, 0, 0, (outs GPRnopc:$base_wb),
1333 (ins rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001334 AddrModeT2_i8, IndexModePost, IIC_iStore_bh_iu,
Jakob Stoklund Olesen836a7de2011-04-12 23:27:48 +00001335 "strb", "\t$Rt, [$Rn], $addr",
1336 "$Rn = $base_wb,@earlyclobber $base_wb",
Owen Anderson9fe72bc2011-08-11 20:40:40 +00001337 [(set GPRnopc:$base_wb,
1338 (post_truncsti8 rGPR:$Rt, GPRnopc:$Rn, t2am_imm8_offset:$addr))]>;
Evan Cheng6d94f112009-07-03 00:06:39 +00001339
Johnny Chene54a3ef2010-03-03 18:45:36 +00001340// STRT, STRBT, STRHT all have offset mode (PUW=0b110) and are for disassembly
1341// only.
1342// Ref: A8.6.193 STR (immediate, Thumb) Encoding T4
Evan Cheng0e55fd62010-09-30 01:08:25 +00001343class T2IstT<bits<2> type, string opc, InstrItinClass ii>
Johnny Chen471d73d2011-04-13 21:04:32 +00001344 : T2Ii8<(outs rGPR:$Rt), (ins t2addrmode_imm8:$addr), ii, opc,
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001345 "\t$Rt, $addr", []> {
Johnny Chene54a3ef2010-03-03 18:45:36 +00001346 let Inst{31-27} = 0b11111;
1347 let Inst{26-25} = 0b00;
1348 let Inst{24} = 0; // not signed
1349 let Inst{23} = 0;
1350 let Inst{22-21} = type;
1351 let Inst{20} = 0; // store
1352 let Inst{11} = 1;
1353 let Inst{10-8} = 0b110; // PUW
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001354
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001355 bits<4> Rt;
1356 bits<13> addr;
Jim Grosbach86386922010-12-08 22:10:43 +00001357 let Inst{15-12} = Rt;
Owen Andersoneb05a8d2010-11-30 18:38:28 +00001358 let Inst{19-16} = addr{12-9};
1359 let Inst{7-0} = addr{7-0};
Johnny Chene54a3ef2010-03-03 18:45:36 +00001360}
1361
Evan Cheng0e55fd62010-09-30 01:08:25 +00001362def t2STRT : T2IstT<0b10, "strt", IIC_iStore_i>;
1363def t2STRBT : T2IstT<0b00, "strbt", IIC_iStore_bh_i>;
1364def t2STRHT : T2IstT<0b01, "strht", IIC_iStore_bh_i>;
David Goodwind1fa1202009-07-01 00:01:13 +00001365
Johnny Chenae1757b2010-03-11 01:13:36 +00001366// ldrd / strd pre / post variants
1367// For disassembly only.
1368
Owen Anderson14c903a2011-08-04 23:18:05 +00001369def t2LDRD_PRE : T2Ii8s4Tied<1, 1, 1,
1370 (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001371 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Owen Anderson9d63d902010-12-01 19:18:46 +00001372 "ldrd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001373
Owen Anderson14c903a2011-08-04 23:18:05 +00001374def t2LDRD_POST : T2Ii8s4Tied<0, 1, 1,
1375 (outs rGPR:$Rt, rGPR:$Rt2, GPR:$wb),
Evan Cheng0e55fd62010-09-30 01:08:25 +00001376 (ins GPR:$base, t2am_imm8s4_offset:$imm), IIC_iLoad_d_ru,
Owen Anderson9d63d902010-12-01 19:18:46 +00001377 "ldrd", "\t$Rt, $Rt2, [$base], $imm", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001378
Owen Anderson14c903a2011-08-04 23:18:05 +00001379def t2STRD_PRE : T2Ii8s4Tied<1, 1, 0, (outs GPR:$wb),
Johnny Chen6e3ccc32011-04-13 16:56:08 +00001380 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
Owen Anderson9d63d902010-12-01 19:18:46 +00001381 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base, $imm]!", []>;
Johnny Chenae1757b2010-03-11 01:13:36 +00001382
Owen Anderson14c903a2011-08-04 23:18:05 +00001383def t2STRD_POST : T2Ii8s4Tied<0, 1, 0, (outs GPR:$wb),
Johnny Chen6e3ccc32011-04-13 16:56:08 +00001384 (ins rGPR:$Rt, rGPR:$Rt2, GPR:$base, t2am_imm8s4_offset:$imm),
Owen Anderson9d63d902010-12-01 19:18:46 +00001385 IIC_iStore_d_ru, "strd", "\t$Rt, $Rt2, [$base], $imm", []>;
Evan Cheng2889cce2009-07-03 00:18:36 +00001386
Johnny Chen0635fc52010-03-04 17:40:44 +00001387// T2Ipl (Preload Data/Instruction) signals the memory system of possible future
1388// data/instruction access. These are for disassembly only.
Evan Chengdfed19f2010-11-03 06:34:55 +00001389// instr_write is inverted for Thumb mode: (prefetch 3) -> (preload 0),
1390// (prefetch 1) -> (preload 2), (prefetch 2) -> (preload 1).
Evan Cheng416941d2010-11-04 05:19:35 +00001391multiclass T2Ipl<bits<1> write, bits<1> instr, string opc> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001392
Evan Chengdfed19f2010-11-03 06:34:55 +00001393 def i12 : T2Ii12<(outs), (ins t2addrmode_imm12:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001394 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001395 [(ARMPreload t2addrmode_imm12:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001396 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001397 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001398 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001399 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001400 let Inst{20} = 1;
1401 let Inst{15-12} = 0b1111;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001402
Owen Anderson80dd3e02010-11-30 22:45:47 +00001403 bits<17> addr;
Johnny Chenf9ce2cb2011-04-12 18:48:00 +00001404 let addr{12} = 1; // add = TRUE
Owen Anderson80dd3e02010-11-30 22:45:47 +00001405 let Inst{19-16} = addr{16-13}; // Rn
1406 let Inst{23} = addr{12}; // U
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001407 let Inst{11-0} = addr{11-0}; // imm12
Johnny Chen0635fc52010-03-04 17:40:44 +00001408 }
1409
Evan Chengdfed19f2010-11-03 06:34:55 +00001410 def i8 : T2Ii8<(outs), (ins t2addrmode_imm8:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001411 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001412 [(ARMPreload t2addrmode_imm8:$addr, (i32 write), (i32 instr))]> {
Johnny Chen0635fc52010-03-04 17:40:44 +00001413 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001414 let Inst{24} = instr;
Johnny Chen0635fc52010-03-04 17:40:44 +00001415 let Inst{23} = 0; // U = 0
1416 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001417 let Inst{21} = write;
Johnny Chen0635fc52010-03-04 17:40:44 +00001418 let Inst{20} = 1;
1419 let Inst{15-12} = 0b1111;
1420 let Inst{11-8} = 0b1100;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001421
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001422 bits<13> addr;
1423 let Inst{19-16} = addr{12-9}; // Rn
1424 let Inst{7-0} = addr{7-0}; // imm8
Johnny Chen0635fc52010-03-04 17:40:44 +00001425 }
1426
Evan Chengdfed19f2010-11-03 06:34:55 +00001427 def s : T2Iso<(outs), (ins t2addrmode_so_reg:$addr), IIC_Preload, opc,
Evan Chengbc7deb02010-11-03 05:14:24 +00001428 "\t$addr",
Evan Cheng416941d2010-11-04 05:19:35 +00001429 [(ARMPreload t2addrmode_so_reg:$addr, (i32 write), (i32 instr))]> {
Evan Chengbc7deb02010-11-03 05:14:24 +00001430 let Inst{31-25} = 0b1111100;
Evan Cheng416941d2010-11-04 05:19:35 +00001431 let Inst{24} = instr;
Evan Chengbc7deb02010-11-03 05:14:24 +00001432 let Inst{23} = 0; // add = TRUE for T1
1433 let Inst{22} = 0;
Evan Cheng416941d2010-11-04 05:19:35 +00001434 let Inst{21} = write;
Evan Chengbc7deb02010-11-03 05:14:24 +00001435 let Inst{20} = 1;
1436 let Inst{15-12} = 0b1111;
1437 let Inst{11-6} = 0000000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00001438
Owen Anderson0e1bcdf2010-11-30 19:19:31 +00001439 bits<10> addr;
1440 let Inst{19-16} = addr{9-6}; // Rn
1441 let Inst{3-0} = addr{5-2}; // Rm
1442 let Inst{5-4} = addr{1-0}; // imm2
Owen Anderson8d7d2e12011-08-09 20:55:18 +00001443
1444 let DecoderMethod = "DecodeT2LoadShift";
Evan Chengbc7deb02010-11-03 05:14:24 +00001445 }
Johnny Chen0635fc52010-03-04 17:40:44 +00001446}
1447
Evan Cheng416941d2010-11-04 05:19:35 +00001448defm t2PLD : T2Ipl<0, 0, "pld">, Requires<[IsThumb2]>;
1449defm t2PLDW : T2Ipl<1, 0, "pldw">, Requires<[IsThumb2,HasV7,HasMP]>;
1450defm t2PLI : T2Ipl<0, 1, "pli">, Requires<[IsThumb2,HasV7]>;
Johnny Chen0635fc52010-03-04 17:40:44 +00001451
Evan Cheng2889cce2009-07-03 00:18:36 +00001452//===----------------------------------------------------------------------===//
1453// Load / store multiple Instructions.
1454//
1455
Bill Wendling6c470b82010-11-13 09:09:38 +00001456multiclass thumb2_ldst_mult<string asm, InstrItinClass itin,
1457 InstrItinClass itin_upd, bit L_bit> {
Bill Wendling73fe34a2010-11-16 01:16:36 +00001458 def IA :
Bill Wendling6c470b82010-11-13 09:09:38 +00001459 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +00001460 itin, !strconcat(asm, "ia${p}.w\t$Rn, $regs"), []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001461 bits<4> Rn;
1462 bits<16> regs;
Jim Grosbach7a088642010-11-19 17:11:02 +00001463
Bill Wendling6c470b82010-11-13 09:09:38 +00001464 let Inst{31-27} = 0b11101;
1465 let Inst{26-25} = 0b00;
1466 let Inst{24-23} = 0b01; // Increment After
1467 let Inst{22} = 0;
1468 let Inst{21} = 0; // No writeback
1469 let Inst{20} = L_bit;
1470 let Inst{19-16} = Rn;
1471 let Inst{15-0} = regs;
1472 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001473 def IA_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001474 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
Bill Wendling73fe34a2010-11-16 01:16:36 +00001475 itin_upd, !strconcat(asm, "ia${p}.w\t$Rn!, $regs"), "$Rn = $wb", []> {
Bill Wendling6c470b82010-11-13 09:09:38 +00001476 bits<4> Rn;
1477 bits<16> regs;
Jim Grosbach7a088642010-11-19 17:11:02 +00001478
Bill Wendling6c470b82010-11-13 09:09:38 +00001479 let Inst{31-27} = 0b11101;
1480 let Inst{26-25} = 0b00;
1481 let Inst{24-23} = 0b01; // Increment After
1482 let Inst{22} = 0;
1483 let Inst{21} = 1; // Writeback
1484 let Inst{20} = L_bit;
1485 let Inst{19-16} = Rn;
1486 let Inst{15-0} = regs;
1487 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001488 def DB :
Bill Wendling6c470b82010-11-13 09:09:38 +00001489 T2XI<(outs), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1490 itin, !strconcat(asm, "db${p}.w\t$Rn, $regs"), []> {
1491 bits<4> Rn;
1492 bits<16> regs;
1493
1494 let Inst{31-27} = 0b11101;
1495 let Inst{26-25} = 0b00;
1496 let Inst{24-23} = 0b10; // Decrement Before
1497 let Inst{22} = 0;
1498 let Inst{21} = 0; // No writeback
1499 let Inst{20} = L_bit;
1500 let Inst{19-16} = Rn;
1501 let Inst{15-0} = regs;
1502 }
Bill Wendling73fe34a2010-11-16 01:16:36 +00001503 def DB_UPD :
Bill Wendling6c470b82010-11-13 09:09:38 +00001504 T2XIt<(outs GPR:$wb), (ins GPR:$Rn, pred:$p, reglist:$regs, variable_ops),
1505 itin_upd, !strconcat(asm, "db${p}.w\t$Rn, $regs"), "$Rn = $wb", []> {
1506 bits<4> Rn;
1507 bits<16> regs;
1508
1509 let Inst{31-27} = 0b11101;
1510 let Inst{26-25} = 0b00;
1511 let Inst{24-23} = 0b10; // Decrement Before
1512 let Inst{22} = 0;
1513 let Inst{21} = 1; // Writeback
1514 let Inst{20} = L_bit;
1515 let Inst{19-16} = Rn;
1516 let Inst{15-0} = regs;
1517 }
1518}
1519
Bill Wendlingc93989a2010-11-13 11:20:05 +00001520let neverHasSideEffects = 1 in {
Bill Wendlingddc918b2010-11-13 10:57:02 +00001521
1522let mayLoad = 1, hasExtraDefRegAllocReq = 1 in
1523defm t2LDM : thumb2_ldst_mult<"ldm", IIC_iLoad_m, IIC_iLoad_mu, 1>;
1524
1525let mayStore = 1, hasExtraSrcRegAllocReq = 1 in
1526defm t2STM : thumb2_ldst_mult<"stm", IIC_iStore_m, IIC_iStore_mu, 0>;
1527
1528} // neverHasSideEffects
1529
Bob Wilson815baeb2010-03-13 01:08:20 +00001530
Evan Cheng9cb9e672009-06-27 02:26:13 +00001531//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001532// Move Instructions.
1533//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001534
Evan Chengf49810c2009-06-23 17:48:47 +00001535let neverHasSideEffects = 1 in
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001536def t2MOVr : T2sTwoReg<(outs GPR:$Rd), (ins GPR:$Rm), IIC_iMOVr,
1537 "mov", ".w\t$Rd, $Rm", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00001538 let Inst{31-27} = 0b11101;
1539 let Inst{26-25} = 0b01;
1540 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00001541 let Inst{19-16} = 0b1111; // Rn
1542 let Inst{14-12} = 0b000;
1543 let Inst{7-4} = 0b0000;
1544}
Evan Chengf49810c2009-06-23 17:48:47 +00001545
Evan Cheng5adb66a2009-09-28 09:14:39 +00001546// AddedComplexity to ensure isel tries t2MOVi before t2MOVi16.
Evan Chengc4af4632010-11-17 20:13:28 +00001547let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1,
1548 AddedComplexity = 1 in
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001549def t2MOVi : T2sOneRegImm<(outs rGPR:$Rd), (ins t2_so_imm:$imm), IIC_iMOVi,
1550 "mov", ".w\t$Rd, $imm",
1551 [(set rGPR:$Rd, t2_so_imm:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001552 let Inst{31-27} = 0b11110;
1553 let Inst{25} = 0;
1554 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00001555 let Inst{19-16} = 0b1111; // Rn
1556 let Inst{15} = 0;
1557}
David Goodwin83b35932009-06-26 16:10:07 +00001558
Jim Grosbacha33b31b2011-08-22 18:04:24 +00001559def : t2InstAlias<"mov${s}${p} $Rd, $imm", (t2MOVi rGPR:$Rd, t2_so_imm:$imm,
1560 pred:$p, cc_out:$s)>;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00001561
Evan Chengc4af4632010-11-17 20:13:28 +00001562let isReMaterializable = 1, isAsCheapAsAMove = 1, isMoveImm = 1 in
Jim Grosbachffa32252011-07-19 19:13:28 +00001563def t2MOVi16 : T2I<(outs rGPR:$Rd), (ins imm0_65535_expr:$imm), IIC_iMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001564 "movw", "\t$Rd, $imm",
1565 [(set rGPR:$Rd, imm0_65535:$imm)]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001566 let Inst{31-27} = 0b11110;
1567 let Inst{25} = 1;
1568 let Inst{24-21} = 0b0010;
1569 let Inst{20} = 0; // The S bit.
1570 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00001571
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001572 bits<4> Rd;
1573 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001574
Jim Grosbach86386922010-12-08 22:10:43 +00001575 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001576 let Inst{19-16} = imm{15-12};
1577 let Inst{26} = imm{11};
1578 let Inst{14-12} = imm{10-8};
1579 let Inst{7-0} = imm{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +00001580}
Evan Chengf49810c2009-06-23 17:48:47 +00001581
Evan Cheng53519f02011-01-21 18:55:51 +00001582def t2MOVi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
Evan Cheng5de5d4b2011-01-17 08:03:18 +00001583 (ins i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1584
1585let Constraints = "$src = $Rd" in {
Evan Cheng75972122011-01-13 07:58:56 +00001586def t2MOVTi16 : T2I<(outs rGPR:$Rd),
Jim Grosbachffa32252011-07-19 19:13:28 +00001587 (ins rGPR:$src, imm0_65535_expr:$imm), IIC_iMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001588 "movt", "\t$Rd, $imm",
1589 [(set rGPR:$Rd,
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001590 (or (and rGPR:$src, 0xffff), lo16AllZero:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001591 let Inst{31-27} = 0b11110;
1592 let Inst{25} = 1;
1593 let Inst{24-21} = 0b0110;
1594 let Inst{20} = 0; // The S bit.
1595 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00001596
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001597 bits<4> Rd;
1598 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001599
Jim Grosbach86386922010-12-08 22:10:43 +00001600 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00001601 let Inst{19-16} = imm{15-12};
1602 let Inst{26} = imm{11};
1603 let Inst{14-12} = imm{10-8};
1604 let Inst{7-0} = imm{7-0};
Johnny Chend68e1192009-12-15 17:24:14 +00001605}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001606
Evan Cheng53519f02011-01-21 18:55:51 +00001607def t2MOVTi16_ga_pcrel : PseudoInst<(outs rGPR:$Rd),
Evan Cheng5de5d4b2011-01-17 08:03:18 +00001608 (ins rGPR:$src, i32imm:$addr, pclabel:$id), IIC_iMOVi, []>;
1609} // Constraints
1610
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001611def : T2Pat<(or rGPR:$src, 0xffff0000), (t2MOVTi16 rGPR:$src, 0xffff)>;
Evan Cheng20956592009-10-21 08:15:52 +00001612
Anton Korobeynikov52237112009-06-17 18:13:58 +00001613//===----------------------------------------------------------------------===//
Evan Chengd27c9fc2009-07-03 01:43:10 +00001614// Extend Instructions.
1615//
1616
1617// Sign extenders
1618
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001619def t2SXTB : T2I_ext_rrot<0b100, "sxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001620 UnOpFrag<(sext_inreg node:$Src, i8)>>;
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001621def t2SXTH : T2I_ext_rrot<0b000, "sxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001622 UnOpFrag<(sext_inreg node:$Src, i16)>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001623def t2SXTB16 : T2I_ext_rrot_sxtb16<0b010, "sxtb16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001624
Jim Grosbach70327412011-07-27 17:48:13 +00001625def t2SXTAB : T2I_exta_rrot<0b100, "sxtab",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001626 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS, i8))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001627def t2SXTAH : T2I_exta_rrot<0b000, "sxtah",
Evan Chengd27c9fc2009-07-03 01:43:10 +00001628 BinOpFrag<(add node:$LHS, (sext_inreg node:$RHS,i16))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001629def t2SXTAB16 : T2I_exta_rrot_np<0b010, "sxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001630
Jim Grosbach70327412011-07-27 17:48:13 +00001631// TODO: SXT(A){B|H}16
Evan Chengd27c9fc2009-07-03 01:43:10 +00001632
1633// Zero extenders
1634
1635let AddedComplexity = 16 in {
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001636def t2UXTB : T2I_ext_rrot<0b101, "uxtb",
Johnny Chend68e1192009-12-15 17:24:14 +00001637 UnOpFrag<(and node:$Src, 0x000000FF)>>;
Jim Grosbachc5a8c862011-07-27 16:47:19 +00001638def t2UXTH : T2I_ext_rrot<0b001, "uxth",
Johnny Chend68e1192009-12-15 17:24:14 +00001639 UnOpFrag<(and node:$Src, 0x0000FFFF)>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001640def t2UXTB16 : T2I_ext_rrot_uxtb16<0b011, "uxtb16",
Johnny Chend68e1192009-12-15 17:24:14 +00001641 UnOpFrag<(and node:$Src, 0x00FF00FF)>>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001642
Jim Grosbach79464942010-07-28 23:17:45 +00001643// FIXME: This pattern incorrectly assumes the shl operator is a rotate.
1644// The transformation should probably be done as a combiner action
1645// instead so we can include a check for masking back in the upper
1646// eight bits of the source into the lower eight bits of the result.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001647//def : T2Pat<(and (shl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach70327412011-07-27 17:48:13 +00001648// (t2UXTB16 rGPR:$Src, 3)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001649// Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001650def : T2Pat<(and (srl rGPR:$Src, (i32 8)), 0xFF00FF),
Jim Grosbach70327412011-07-27 17:48:13 +00001651 (t2UXTB16 rGPR:$Src, 1)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00001652 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001653
Jim Grosbach70327412011-07-27 17:48:13 +00001654def t2UXTAB : T2I_exta_rrot<0b101, "uxtab",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001655 BinOpFrag<(add node:$LHS, (and node:$RHS, 0x00FF))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001656def t2UXTAH : T2I_exta_rrot<0b001, "uxtah",
Jim Grosbach6935efc2009-11-24 00:20:27 +00001657 BinOpFrag<(add node:$LHS, (and node:$RHS, 0xFFFF))>>;
Jim Grosbach70327412011-07-27 17:48:13 +00001658def t2UXTAB16 : T2I_exta_rrot_np<0b011, "uxtab16">;
Evan Chengd27c9fc2009-07-03 01:43:10 +00001659}
1660
1661//===----------------------------------------------------------------------===//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001662// Arithmetic Instructions.
1663//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001664
Johnny Chend68e1192009-12-15 17:24:14 +00001665defm t2ADD : T2I_bin_ii12rs<0b000, "add",
1666 BinOpFrag<(add node:$LHS, node:$RHS)>, 1>;
1667defm t2SUB : T2I_bin_ii12rs<0b101, "sub",
1668 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001669
Evan Chengf49810c2009-06-23 17:48:47 +00001670// ADD and SUB with 's' bit set. No 12-bit immediate (T4) variants.
Johnny Chend68e1192009-12-15 17:24:14 +00001671defm t2ADDS : T2I_bin_s_irs <0b1000, "add",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001672 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001673 BinOpFrag<(addc node:$LHS, node:$RHS)>, 1>;
1674defm t2SUBS : T2I_bin_s_irs <0b1101, "sub",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001675 IIC_iALUi, IIC_iALUr, IIC_iALUsi,
Johnny Chend68e1192009-12-15 17:24:14 +00001676 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001677
Johnny Chend68e1192009-12-15 17:24:14 +00001678defm t2ADC : T2I_adde_sube_irs<0b1010, "adc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001679 BinOpFrag<(adde_dead_carry node:$LHS, node:$RHS)>, 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001680defm t2SBC : T2I_adde_sube_irs<0b1011, "sbc",
Jim Grosbach39be8fc2010-02-16 20:42:29 +00001681 BinOpFrag<(sube_dead_carry node:$LHS, node:$RHS)>>;
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00001682defm t2ADCS : T2I_adde_sube_s_irs<BinOpFrag<(adde_live_carry node:$LHS,
1683 node:$RHS)>, 1>;
1684defm t2SBCS : T2I_adde_sube_s_irs<BinOpFrag<(sube_live_carry node:$LHS,
1685 node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001686
David Goodwin752aa7d2009-07-27 16:39:05 +00001687// RSB
Bob Wilson20d8e4e2010-08-13 23:24:25 +00001688defm t2RSB : T2I_rbin_irs <0b1110, "rsb",
Johnny Chend68e1192009-12-15 17:24:14 +00001689 BinOpFrag<(sub node:$LHS, node:$RHS)>>;
1690defm t2RSBS : T2I_rbin_s_is <0b1110, "rsb",
1691 BinOpFrag<(subc node:$LHS, node:$RHS)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00001692
1693// (sub X, imm) gets canonicalized to (add X, -imm). Match this form.
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001694// The assume-no-carry-in form uses the negation of the input since add/sub
1695// assume opposite meanings of the carry flag (i.e., carry == !borrow).
1696// See the definition of AddWithCarry() in the ARM ARM A2.2.1 for the gory
1697// details.
1698// The AddedComplexity preferences the first variant over the others since
1699// it can be shrunk to a 16-bit wide encoding, while the others cannot.
Evan Chengfa2ea1a2009-08-04 01:41:15 +00001700let AddedComplexity = 1 in
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001701def : T2Pat<(add GPR:$src, imm0_255_neg:$imm),
1702 (t2SUBri GPR:$src, imm0_255_neg:$imm)>;
1703def : T2Pat<(add GPR:$src, t2_so_imm_neg:$imm),
1704 (t2SUBri GPR:$src, t2_so_imm_neg:$imm)>;
1705def : T2Pat<(add GPR:$src, imm0_4095_neg:$imm),
1706 (t2SUBri12 GPR:$src, imm0_4095_neg:$imm)>;
1707let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001708def : T2Pat<(addc rGPR:$src, imm0_255_neg:$imm),
1709 (t2SUBSri rGPR:$src, imm0_255_neg:$imm)>;
1710def : T2Pat<(addc rGPR:$src, t2_so_imm_neg:$imm),
1711 (t2SUBSri rGPR:$src, t2_so_imm_neg:$imm)>;
Jim Grosbach502e0aa2010-07-14 17:45:16 +00001712// The with-carry-in form matches bitwise not instead of the negation.
1713// Effectively, the inverse interpretation of the carry flag already accounts
1714// for part of the negation.
1715let AddedComplexity = 1 in
Andrew Trick1c3af772011-04-23 03:55:32 +00001716def : T2Pat<(adde_dead_carry rGPR:$src, imm0_255_not:$imm),
1717 (t2SBCri rGPR:$src, imm0_255_not:$imm)>;
1718def : T2Pat<(adde_dead_carry rGPR:$src, t2_so_imm_not:$imm),
1719 (t2SBCri rGPR:$src, t2_so_imm_not:$imm)>;
1720let AddedComplexity = 1 in
1721def : T2Pat<(adde_live_carry rGPR:$src, imm0_255_not:$imm),
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001722 (t2SBCSri rGPR:$src, imm0_255_not:$imm)>;
Andrew Trick1c3af772011-04-23 03:55:32 +00001723def : T2Pat<(adde_live_carry rGPR:$src, t2_so_imm_not:$imm),
Jim Grosbach6ccfc502010-07-30 02:41:01 +00001724 (t2SBCSri rGPR:$src, t2_so_imm_not:$imm)>;
Anton Korobeynikov52237112009-06-17 18:13:58 +00001725
Johnny Chen93042d12010-03-02 18:14:57 +00001726// Select Bytes -- for disassembly only
1727
Owen Andersonc7373f82010-11-30 20:00:01 +00001728def t2SEL : T2ThreeReg<(outs GPR:$Rd), (ins GPR:$Rn, GPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00001729 NoItinerary, "sel", "\t$Rd, $Rn, $Rm", []>,
1730 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00001731 let Inst{31-27} = 0b11111;
1732 let Inst{26-24} = 0b010;
1733 let Inst{23} = 0b1;
1734 let Inst{22-20} = 0b010;
1735 let Inst{15-12} = 0b1111;
1736 let Inst{7} = 0b1;
1737 let Inst{6-4} = 0b000;
1738}
1739
Johnny Chenadc77332010-02-26 22:04:29 +00001740// A6.3.13, A6.3.14, A6.3.15 Parallel addition and subtraction (signed/unsigned)
1741// And Miscellaneous operations -- for disassembly only
Nate Begeman692433b2010-07-29 17:56:55 +00001742class T2I_pam<bits<3> op22_20, bits<4> op7_4, string opc,
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001743 list<dag> pat = [/* For disassembly only; pattern left blank */],
1744 dag iops = (ins rGPR:$Rn, rGPR:$Rm),
1745 string asm = "\t$Rd, $Rn, $Rm">
Jim Grosbacha7603982011-07-01 21:12:19 +00001746 : T2I<(outs rGPR:$Rd), iops, NoItinerary, opc, asm, pat>,
1747 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001748 let Inst{31-27} = 0b11111;
1749 let Inst{26-23} = 0b0101;
1750 let Inst{22-20} = op22_20;
1751 let Inst{15-12} = 0b1111;
1752 let Inst{7-4} = op7_4;
Jim Grosbach7a088642010-11-19 17:11:02 +00001753
Owen Anderson46c478e2010-11-17 19:57:38 +00001754 bits<4> Rd;
1755 bits<4> Rn;
1756 bits<4> Rm;
Jim Grosbach7a088642010-11-19 17:11:02 +00001757
Jim Grosbach86386922010-12-08 22:10:43 +00001758 let Inst{11-8} = Rd;
1759 let Inst{19-16} = Rn;
1760 let Inst{3-0} = Rm;
Johnny Chenadc77332010-02-26 22:04:29 +00001761}
1762
1763// Saturating add/subtract -- for disassembly only
1764
Nate Begeman692433b2010-07-29 17:56:55 +00001765def t2QADD : T2I_pam<0b000, 0b1000, "qadd",
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001766 [(set rGPR:$Rd, (int_arm_qadd rGPR:$Rn, rGPR:$Rm))],
1767 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00001768def t2QADD16 : T2I_pam<0b001, 0b0001, "qadd16">;
1769def t2QADD8 : T2I_pam<0b000, 0b0001, "qadd8">;
1770def t2QASX : T2I_pam<0b010, 0b0001, "qasx">;
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001771def t2QDADD : T2I_pam<0b000, 0b1001, "qdadd", [],
1772 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
1773def t2QDSUB : T2I_pam<0b000, 0b1011, "qdsub", [],
1774 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00001775def t2QSAX : T2I_pam<0b110, 0b0001, "qsax">;
Nate Begeman692433b2010-07-29 17:56:55 +00001776def t2QSUB : T2I_pam<0b000, 0b1010, "qsub",
Bruno Cardoso Lopes03016002011-01-21 14:07:40 +00001777 [(set rGPR:$Rd, (int_arm_qsub rGPR:$Rn, rGPR:$Rm))],
1778 (ins rGPR:$Rm, rGPR:$Rn), "\t$Rd, $Rm, $Rn">;
Johnny Chenadc77332010-02-26 22:04:29 +00001779def t2QSUB16 : T2I_pam<0b101, 0b0001, "qsub16">;
1780def t2QSUB8 : T2I_pam<0b100, 0b0001, "qsub8">;
1781def t2UQADD16 : T2I_pam<0b001, 0b0101, "uqadd16">;
1782def t2UQADD8 : T2I_pam<0b000, 0b0101, "uqadd8">;
1783def t2UQASX : T2I_pam<0b010, 0b0101, "uqasx">;
1784def t2UQSAX : T2I_pam<0b110, 0b0101, "uqsax">;
1785def t2UQSUB16 : T2I_pam<0b101, 0b0101, "uqsub16">;
1786def t2UQSUB8 : T2I_pam<0b100, 0b0101, "uqsub8">;
1787
1788// Signed/Unsigned add/subtract -- for disassembly only
1789
1790def t2SASX : T2I_pam<0b010, 0b0000, "sasx">;
1791def t2SADD16 : T2I_pam<0b001, 0b0000, "sadd16">;
1792def t2SADD8 : T2I_pam<0b000, 0b0000, "sadd8">;
1793def t2SSAX : T2I_pam<0b110, 0b0000, "ssax">;
1794def t2SSUB16 : T2I_pam<0b101, 0b0000, "ssub16">;
1795def t2SSUB8 : T2I_pam<0b100, 0b0000, "ssub8">;
1796def t2UASX : T2I_pam<0b010, 0b0100, "uasx">;
1797def t2UADD16 : T2I_pam<0b001, 0b0100, "uadd16">;
1798def t2UADD8 : T2I_pam<0b000, 0b0100, "uadd8">;
1799def t2USAX : T2I_pam<0b110, 0b0100, "usax">;
1800def t2USUB16 : T2I_pam<0b101, 0b0100, "usub16">;
1801def t2USUB8 : T2I_pam<0b100, 0b0100, "usub8">;
1802
1803// Signed/Unsigned halving add/subtract -- for disassembly only
1804
1805def t2SHASX : T2I_pam<0b010, 0b0010, "shasx">;
1806def t2SHADD16 : T2I_pam<0b001, 0b0010, "shadd16">;
1807def t2SHADD8 : T2I_pam<0b000, 0b0010, "shadd8">;
1808def t2SHSAX : T2I_pam<0b110, 0b0010, "shsax">;
1809def t2SHSUB16 : T2I_pam<0b101, 0b0010, "shsub16">;
1810def t2SHSUB8 : T2I_pam<0b100, 0b0010, "shsub8">;
1811def t2UHASX : T2I_pam<0b010, 0b0110, "uhasx">;
1812def t2UHADD16 : T2I_pam<0b001, 0b0110, "uhadd16">;
1813def t2UHADD8 : T2I_pam<0b000, 0b0110, "uhadd8">;
1814def t2UHSAX : T2I_pam<0b110, 0b0110, "uhsax">;
1815def t2UHSUB16 : T2I_pam<0b101, 0b0110, "uhsub16">;
1816def t2UHSUB8 : T2I_pam<0b100, 0b0110, "uhsub8">;
1817
Owen Anderson821752e2010-11-18 20:32:18 +00001818// Helper class for disassembly only
1819// A6.3.16 & A6.3.17
1820// T2Imac - Thumb2 multiply [accumulate, and absolute difference] instructions.
1821class T2ThreeReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1822 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1823 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
1824 let Inst{31-27} = 0b11111;
1825 let Inst{26-24} = 0b011;
1826 let Inst{23} = long;
1827 let Inst{22-20} = op22_20;
1828 let Inst{7-4} = op7_4;
1829}
1830
1831class T2FourReg_mac<bit long, bits<3> op22_20, bits<4> op7_4, dag oops,
1832 dag iops, InstrItinClass itin, string opc, string asm, list<dag> pattern>
1833 : T2FourReg<oops, iops, itin, opc, asm, pattern> {
1834 let Inst{31-27} = 0b11111;
1835 let Inst{26-24} = 0b011;
1836 let Inst{23} = long;
1837 let Inst{22-20} = op22_20;
1838 let Inst{7-4} = op7_4;
1839}
1840
Johnny Chenadc77332010-02-26 22:04:29 +00001841// Unsigned Sum of Absolute Differences [and Accumulate] -- for disassembly only
1842
Owen Anderson821752e2010-11-18 20:32:18 +00001843def t2USAD8 : T2ThreeReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
1844 (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00001845 NoItinerary, "usad8", "\t$Rd, $Rn, $Rm", []>,
1846 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001847 let Inst{15-12} = 0b1111;
1848}
Owen Anderson821752e2010-11-18 20:32:18 +00001849def t2USADA8 : T2FourReg_mac<0, 0b111, 0b0000, (outs rGPR:$Rd),
Jim Grosbach7a088642010-11-19 17:11:02 +00001850 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), NoItinerary,
Jim Grosbacha7603982011-07-01 21:12:19 +00001851 "usada8", "\t$Rd, $Rn, $Rm, $Ra", []>,
1852 Requires<[IsThumb2, HasThumb2DSP]>;
Johnny Chenadc77332010-02-26 22:04:29 +00001853
1854// Signed/Unsigned saturate -- for disassembly only
1855
Owen Anderson46c478e2010-11-17 19:57:38 +00001856class T2SatI<dag oops, dag iops, InstrItinClass itin,
1857 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +00001858 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson46c478e2010-11-17 19:57:38 +00001859 bits<4> Rd;
1860 bits<4> Rn;
1861 bits<5> sat_imm;
1862 bits<7> sh;
Jim Grosbach7a088642010-11-19 17:11:02 +00001863
Jim Grosbach86386922010-12-08 22:10:43 +00001864 let Inst{11-8} = Rd;
1865 let Inst{19-16} = Rn;
Jim Grosbach580f4a92011-07-25 22:20:28 +00001866 let Inst{4-0} = sat_imm;
1867 let Inst{21} = sh{5};
Owen Anderson46c478e2010-11-17 19:57:38 +00001868 let Inst{14-12} = sh{4-2};
1869 let Inst{7-6} = sh{1-0};
1870}
1871
Owen Andersonc7373f82010-11-30 20:00:01 +00001872def t2SSAT: T2SatI<
Jim Grosbach4a5ffb32011-07-22 23:16:18 +00001873 (outs rGPR:$Rd), (ins imm1_32:$sat_imm, rGPR:$Rn, shift_imm:$sh),
Bruno Cardoso Lopes895c1e22011-05-31 03:33:27 +00001874 NoItinerary, "ssat", "\t$Rd, $sat_imm, $Rn$sh",
1875 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001876 let Inst{31-27} = 0b11110;
1877 let Inst{25-22} = 0b1100;
1878 let Inst{20} = 0;
1879 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001880}
1881
Owen Andersonc7373f82010-11-30 20:00:01 +00001882def t2SSAT16: T2SatI<
Jim Grosbachf4943352011-07-25 23:09:14 +00001883 (outs rGPR:$Rd), (ins imm1_16:$sat_imm, rGPR:$Rn), NoItinerary,
Bruno Cardoso Lopes895c1e22011-05-31 03:33:27 +00001884 "ssat16", "\t$Rd, $sat_imm, $Rn",
Jim Grosbacha7603982011-07-01 21:12:19 +00001885 [/* For disassembly only; pattern left blank */]>,
1886 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001887 let Inst{31-27} = 0b11110;
1888 let Inst{25-22} = 0b1100;
1889 let Inst{20} = 0;
1890 let Inst{15} = 0;
1891 let Inst{21} = 1; // sh = '1'
1892 let Inst{14-12} = 0b000; // imm3 = '000'
1893 let Inst{7-6} = 0b00; // imm2 = '00'
1894}
1895
Owen Andersonc7373f82010-11-30 20:00:01 +00001896def t2USAT: T2SatI<
1897 (outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn, shift_imm:$sh),
1898 NoItinerary, "usat", "\t$Rd, $sat_imm, $Rn$sh",
Bob Wilson38aa2872010-08-13 21:48:10 +00001899 [/* For disassembly only; pattern left blank */]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001900 let Inst{31-27} = 0b11110;
1901 let Inst{25-22} = 0b1110;
1902 let Inst{20} = 0;
1903 let Inst{15} = 0;
Johnny Chenadc77332010-02-26 22:04:29 +00001904}
1905
Owen Anderson22d35082011-08-22 23:27:47 +00001906def t2USAT16: T2SatI<(outs rGPR:$Rd), (ins i32imm:$sat_imm, rGPR:$Rn),
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00001907 NoItinerary,
Owen Anderson22d35082011-08-22 23:27:47 +00001908 "usat16", "\t$Rd, $sat_imm, $Rn",
Jim Grosbacha7603982011-07-01 21:12:19 +00001909 [/* For disassembly only; pattern left blank */]>,
1910 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00001911 let Inst{31-27} = 0b11110;
1912 let Inst{25-22} = 0b1110;
1913 let Inst{20} = 0;
1914 let Inst{15} = 0;
1915 let Inst{21} = 1; // sh = '1'
1916 let Inst{14-12} = 0b000; // imm3 = '000'
1917 let Inst{7-6} = 0b00; // imm2 = '00'
1918}
Anton Korobeynikov52237112009-06-17 18:13:58 +00001919
Bob Wilson38aa2872010-08-13 21:48:10 +00001920def : T2Pat<(int_arm_ssat GPR:$a, imm:$pos), (t2SSAT imm:$pos, GPR:$a, 0)>;
1921def : T2Pat<(int_arm_usat GPR:$a, imm:$pos), (t2USAT imm:$pos, GPR:$a, 0)>;
Nate Begeman0e0a20e2010-07-29 22:48:09 +00001922
Evan Chengf49810c2009-06-23 17:48:47 +00001923//===----------------------------------------------------------------------===//
Evan Chenga67efd12009-06-23 19:39:13 +00001924// Shift and rotate Instructions.
1925//
1926
Owen Anderson6d746312011-08-08 20:42:17 +00001927defm t2LSL : T2I_sh_ir<0b00, "lsl", imm1_31, BinOpFrag<(shl node:$LHS, node:$RHS)>>;
1928defm t2LSR : T2I_sh_ir<0b01, "lsr", imm_sr, BinOpFrag<(srl node:$LHS, node:$RHS)>>;
1929defm t2ASR : T2I_sh_ir<0b10, "asr", imm_sr, BinOpFrag<(sra node:$LHS, node:$RHS)>>;
1930defm t2ROR : T2I_sh_ir<0b11, "ror", imm1_31, BinOpFrag<(rotr node:$LHS, node:$RHS)>>;
Evan Chenga67efd12009-06-23 19:39:13 +00001931
Andrew Trickd49ffe82011-04-29 14:18:15 +00001932// (rotr x, (and y, 0x...1f)) ==> (ROR x, y)
1933def : Pat<(rotr rGPR:$lhs, (and rGPR:$rhs, lo5AllOne)),
1934 (t2RORrr rGPR:$lhs, rGPR:$rhs)>;
1935
David Goodwinca01a8d2009-09-01 18:32:09 +00001936let Uses = [CPSR] in {
Owen Anderson46c478e2010-11-17 19:57:38 +00001937def t2RRX : T2sTwoReg<(outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
1938 "rrx", "\t$Rd, $Rm",
1939 [(set rGPR:$Rd, (ARMrrx rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001940 let Inst{31-27} = 0b11101;
1941 let Inst{26-25} = 0b01;
1942 let Inst{24-21} = 0b0010;
Johnny Chend68e1192009-12-15 17:24:14 +00001943 let Inst{19-16} = 0b1111; // Rn
1944 let Inst{14-12} = 0b000;
1945 let Inst{7-4} = 0b0011;
1946}
David Goodwinca01a8d2009-09-01 18:32:09 +00001947}
Evan Chenga67efd12009-06-23 19:39:13 +00001948
Daniel Dunbar8d66b782011-01-10 15:26:39 +00001949let isCodeGenOnly = 1, Defs = [CPSR] in {
Owen Andersonbb6315d2010-11-15 19:58:36 +00001950def t2MOVsrl_flag : T2TwoRegShiftImm<
1951 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
1952 "lsrs", ".w\t$Rd, $Rm, #1",
1953 [(set rGPR:$Rd, (ARMsrl_flag rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001954 let Inst{31-27} = 0b11101;
1955 let Inst{26-25} = 0b01;
1956 let Inst{24-21} = 0b0010;
1957 let Inst{20} = 1; // The S bit.
1958 let Inst{19-16} = 0b1111; // Rn
1959 let Inst{5-4} = 0b01; // Shift type.
1960 // Shift amount = Inst{14-12:7-6} = 1.
1961 let Inst{14-12} = 0b000;
1962 let Inst{7-6} = 0b01;
1963}
Owen Andersonbb6315d2010-11-15 19:58:36 +00001964def t2MOVsra_flag : T2TwoRegShiftImm<
1965 (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iMOVsi,
1966 "asrs", ".w\t$Rd, $Rm, #1",
1967 [(set rGPR:$Rd, (ARMsra_flag rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00001968 let Inst{31-27} = 0b11101;
1969 let Inst{26-25} = 0b01;
1970 let Inst{24-21} = 0b0010;
1971 let Inst{20} = 1; // The S bit.
1972 let Inst{19-16} = 0b1111; // Rn
1973 let Inst{5-4} = 0b10; // Shift type.
1974 // Shift amount = Inst{14-12:7-6} = 1.
1975 let Inst{14-12} = 0b000;
1976 let Inst{7-6} = 0b01;
1977}
David Goodwin3583df72009-07-28 17:06:49 +00001978}
1979
Evan Chenga67efd12009-06-23 19:39:13 +00001980//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00001981// Bitwise Instructions.
1982//
Anton Korobeynikov52237112009-06-17 18:13:58 +00001983
Johnny Chend68e1192009-12-15 17:24:14 +00001984defm t2AND : T2I_bin_w_irs<0b0000, "and",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001985 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbachadf73662011-06-28 00:19:13 +00001986 BinOpFrag<(and node:$LHS, node:$RHS)>, "t2AND", 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001987defm t2ORR : T2I_bin_w_irs<0b0010, "orr",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001988 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbachadf73662011-06-28 00:19:13 +00001989 BinOpFrag<(or node:$LHS, node:$RHS)>, "t2ORR", 1>;
Johnny Chend68e1192009-12-15 17:24:14 +00001990defm t2EOR : T2I_bin_w_irs<0b0100, "eor",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001991 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbachadf73662011-06-28 00:19:13 +00001992 BinOpFrag<(xor node:$LHS, node:$RHS)>, "t2EOR", 1>;
Evan Chengf49810c2009-06-23 17:48:47 +00001993
Johnny Chend68e1192009-12-15 17:24:14 +00001994defm t2BIC : T2I_bin_w_irs<0b0001, "bic",
Evan Cheng7e1bf302010-09-29 00:27:46 +00001995 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbachadf73662011-06-28 00:19:13 +00001996 BinOpFrag<(and node:$LHS, (not node:$RHS))>,
1997 "t2BIC">;
Evan Chengf49810c2009-06-23 17:48:47 +00001998
Owen Anderson2f7aed32010-11-17 22:16:31 +00001999class T2BitFI<dag oops, dag iops, InstrItinClass itin,
2000 string opc, string asm, list<dag> pattern>
Jim Grosbach7a088642010-11-19 17:11:02 +00002001 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson2f7aed32010-11-17 22:16:31 +00002002 bits<4> Rd;
2003 bits<5> msb;
2004 bits<5> lsb;
Jim Grosbach7a088642010-11-19 17:11:02 +00002005
Jim Grosbach86386922010-12-08 22:10:43 +00002006 let Inst{11-8} = Rd;
Owen Anderson2f7aed32010-11-17 22:16:31 +00002007 let Inst{4-0} = msb{4-0};
2008 let Inst{14-12} = lsb{4-2};
2009 let Inst{7-6} = lsb{1-0};
2010}
2011
2012class T2TwoRegBitFI<dag oops, dag iops, InstrItinClass itin,
2013 string opc, string asm, list<dag> pattern>
2014 : T2BitFI<oops, iops, itin, opc, asm, pattern> {
2015 bits<4> Rn;
Jim Grosbach7a088642010-11-19 17:11:02 +00002016
Jim Grosbach86386922010-12-08 22:10:43 +00002017 let Inst{19-16} = Rn;
Owen Anderson2f7aed32010-11-17 22:16:31 +00002018}
2019
2020let Constraints = "$src = $Rd" in
2021def t2BFC : T2BitFI<(outs rGPR:$Rd), (ins rGPR:$src, bf_inv_mask_imm:$imm),
2022 IIC_iUNAsi, "bfc", "\t$Rd, $imm",
2023 [(set rGPR:$Rd, (and rGPR:$src, bf_inv_mask_imm:$imm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002024 let Inst{31-27} = 0b11110;
Johnny Chen3a961222011-04-15 22:52:15 +00002025 let Inst{26} = 0; // should be 0.
Johnny Chend68e1192009-12-15 17:24:14 +00002026 let Inst{25} = 1;
2027 let Inst{24-20} = 0b10110;
2028 let Inst{19-16} = 0b1111; // Rn
2029 let Inst{15} = 0;
Johnny Chen3a961222011-04-15 22:52:15 +00002030 let Inst{5} = 0; // should be 0.
Jim Grosbach7a088642010-11-19 17:11:02 +00002031
Owen Anderson2f7aed32010-11-17 22:16:31 +00002032 bits<10> imm;
2033 let msb{4-0} = imm{9-5};
2034 let lsb{4-0} = imm{4-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002035}
Evan Chengf49810c2009-06-23 17:48:47 +00002036
Owen Anderson2f7aed32010-11-17 22:16:31 +00002037def t2SBFX: T2TwoRegBitFI<
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002038 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
Owen Anderson2f7aed32010-11-17 22:16:31 +00002039 IIC_iUNAsi, "sbfx", "\t$Rd, $Rn, $lsb, $msb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002040 let Inst{31-27} = 0b11110;
2041 let Inst{25} = 1;
2042 let Inst{24-20} = 0b10100;
2043 let Inst{15} = 0;
2044}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002045
Owen Anderson2f7aed32010-11-17 22:16:31 +00002046def t2UBFX: T2TwoRegBitFI<
Jim Grosbachfb8989e2011-07-27 21:09:25 +00002047 (outs rGPR:$Rd), (ins rGPR:$Rn, imm0_31:$lsb, imm1_32:$msb),
Owen Anderson2f7aed32010-11-17 22:16:31 +00002048 IIC_iUNAsi, "ubfx", "\t$Rd, $Rn, $lsb, $msb", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002049 let Inst{31-27} = 0b11110;
2050 let Inst{25} = 1;
2051 let Inst{24-20} = 0b11100;
2052 let Inst{15} = 0;
2053}
Sandeep Patel47eedaa2009-10-13 18:59:48 +00002054
Johnny Chen9474d552010-02-02 19:31:58 +00002055// A8.6.18 BFI - Bitfield insert (Encoding T1)
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002056let Constraints = "$src = $Rd" in {
2057 def t2BFI : T2TwoRegBitFI<(outs rGPR:$Rd),
2058 (ins rGPR:$src, rGPR:$Rn, bf_inv_mask_imm:$imm),
2059 IIC_iBITi, "bfi", "\t$Rd, $Rn, $imm",
2060 [(set rGPR:$Rd, (ARMbfi rGPR:$src, rGPR:$Rn,
2061 bf_inv_mask_imm:$imm))]> {
2062 let Inst{31-27} = 0b11110;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002063 let Inst{26} = 0; // should be 0.
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002064 let Inst{25} = 1;
2065 let Inst{24-20} = 0b10110;
2066 let Inst{15} = 0;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002067 let Inst{5} = 0; // should be 0.
Jim Grosbach7a088642010-11-19 17:11:02 +00002068
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002069 bits<10> imm;
2070 let msb{4-0} = imm{9-5};
2071 let lsb{4-0} = imm{4-0};
2072 }
2073
2074 // GNU as only supports this form of bfi (w/ 4 arguments)
2075 let isAsmParserOnly = 1 in
2076 def t2BFI4p : T2TwoRegBitFI<(outs rGPR:$Rd),
2077 (ins rGPR:$src, rGPR:$Rn, lsb_pos_imm:$lsbit,
2078 width_imm:$width),
2079 IIC_iBITi, "bfi", "\t$Rd, $Rn, $lsbit, $width",
2080 []> {
2081 let Inst{31-27} = 0b11110;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002082 let Inst{26} = 0; // should be 0.
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002083 let Inst{25} = 1;
2084 let Inst{24-20} = 0b10110;
2085 let Inst{15} = 0;
Johnny Chen188ce9c2011-04-15 00:35:08 +00002086 let Inst{5} = 0; // should be 0.
Bruno Cardoso Lopesa461d422011-01-18 20:45:56 +00002087
2088 bits<5> lsbit;
2089 bits<5> width;
2090 let msb{4-0} = width; // Custom encoder => lsb+width-1
2091 let lsb{4-0} = lsbit;
2092 }
Johnny Chen9474d552010-02-02 19:31:58 +00002093}
Evan Chengf49810c2009-06-23 17:48:47 +00002094
Evan Cheng7e1bf302010-09-29 00:27:46 +00002095defm t2ORN : T2I_bin_irs<0b0011, "orn",
2096 IIC_iBITi, IIC_iBITr, IIC_iBITsi,
Jim Grosbachadf73662011-06-28 00:19:13 +00002097 BinOpFrag<(or node:$LHS, (not node:$RHS))>,
2098 "t2ORN", 0, "">;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002099
2100// Prefer over of t2EORri ra, rb, -1 because mvn has 16-bit version
2101let AddedComplexity = 1 in
Evan Cheng5d42c562010-09-29 00:49:25 +00002102defm t2MVN : T2I_un_irs <0b0011, "mvn",
Evan Cheng3881cb72010-09-29 22:42:35 +00002103 IIC_iMVNi, IIC_iMVNr, IIC_iMVNsi,
Evan Cheng5d42c562010-09-29 00:49:25 +00002104 UnOpFrag<(not node:$Src)>, 1, 1>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002105
2106
Jim Grosbachf084a5e2010-07-20 16:07:04 +00002107let AddedComplexity = 1 in
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002108def : T2Pat<(and rGPR:$src, t2_so_imm_not:$imm),
2109 (t2BICri rGPR:$src, t2_so_imm_not:$imm)>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002110
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002111// FIXME: Disable this pattern on Darwin to workaround an assembler bug.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002112def : T2Pat<(or rGPR:$src, t2_so_imm_not:$imm),
2113 (t2ORNri rGPR:$src, t2_so_imm_not:$imm)>,
Evan Chengea253b92009-08-12 01:56:42 +00002114 Requires<[IsThumb2]>;
Evan Cheng36a0aeb2009-07-06 22:23:46 +00002115
2116def : T2Pat<(t2_so_imm_not:$src),
2117 (t2MVNi t2_so_imm_not:$src)>;
2118
Evan Chengf49810c2009-06-23 17:48:47 +00002119//===----------------------------------------------------------------------===//
2120// Multiply Instructions.
2121//
Evan Cheng8de898a2009-06-26 00:19:44 +00002122let isCommutable = 1 in
Owen Anderson35141a92010-11-18 01:08:42 +00002123def t2MUL: T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2124 "mul", "\t$Rd, $Rn, $Rm",
2125 [(set rGPR:$Rd, (mul rGPR:$Rn, rGPR:$Rm))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002126 let Inst{31-27} = 0b11111;
2127 let Inst{26-23} = 0b0110;
2128 let Inst{22-20} = 0b000;
2129 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2130 let Inst{7-4} = 0b0000; // Multiply
2131}
Evan Chengf49810c2009-06-23 17:48:47 +00002132
Owen Anderson35141a92010-11-18 01:08:42 +00002133def t2MLA: T2FourReg<
2134 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2135 "mla", "\t$Rd, $Rn, $Rm, $Ra",
2136 [(set rGPR:$Rd, (add (mul rGPR:$Rn, rGPR:$Rm), rGPR:$Ra))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002137 let Inst{31-27} = 0b11111;
2138 let Inst{26-23} = 0b0110;
2139 let Inst{22-20} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +00002140 let Inst{7-4} = 0b0000; // Multiply
2141}
Evan Chengf49810c2009-06-23 17:48:47 +00002142
Owen Anderson35141a92010-11-18 01:08:42 +00002143def t2MLS: T2FourReg<
2144 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2145 "mls", "\t$Rd, $Rn, $Rm, $Ra",
2146 [(set rGPR:$Rd, (sub rGPR:$Ra, (mul rGPR:$Rn, rGPR:$Rm)))]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002147 let Inst{31-27} = 0b11111;
2148 let Inst{26-23} = 0b0110;
2149 let Inst{22-20} = 0b000;
Johnny Chend68e1192009-12-15 17:24:14 +00002150 let Inst{7-4} = 0b0001; // Multiply and Subtract
2151}
Evan Chengf49810c2009-06-23 17:48:47 +00002152
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002153// Extra precision multiplies with low / high results
2154let neverHasSideEffects = 1 in {
2155let isCommutable = 1 in {
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002156def t2SMULL : T2MulLong<0b000, 0b0000,
Owen Anderson796c3652011-08-22 23:16:48 +00002157 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002158 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
Owen Anderson796c3652011-08-22 23:16:48 +00002159 "smull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002160
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002161def t2UMULL : T2MulLong<0b010, 0b0000,
Jim Grosbach52082042010-12-08 22:29:28 +00002162 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002163 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL64,
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002164 "umull", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Johnny Chend68e1192009-12-15 17:24:14 +00002165} // isCommutable
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002166
2167// Multiply + accumulate
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002168def t2SMLAL : T2MulLong<0b100, 0b0000,
2169 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002170 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002171 "smlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002172
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002173def t2UMLAL : T2MulLong<0b110, 0b0000,
2174 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002175 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002176 "umlal", "\t$RdLo, $RdHi, $Rn, $Rm", []>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002177
Jim Grosbach7c6d85a2010-12-08 22:38:41 +00002178def t2UMAAL : T2MulLong<0b110, 0b0110,
2179 (outs rGPR:$RdLo, rGPR:$RdHi),
Owen Anderson35141a92010-11-18 01:08:42 +00002180 (ins rGPR:$Rn, rGPR:$Rm), IIC_iMAC64,
Jim Grosbacha7603982011-07-01 21:12:19 +00002181 "umaal", "\t$RdLo, $RdHi, $Rn, $Rm", []>,
2182 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002183} // neverHasSideEffects
2184
Johnny Chen93042d12010-03-02 18:14:57 +00002185// Rounding variants of the below included for disassembly only
2186
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002187// Most significant word multiply
Owen Anderson821752e2010-11-18 20:32:18 +00002188def t2SMMUL : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
2189 "smmul", "\t$Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002190 [(set rGPR:$Rd, (mulhs rGPR:$Rn, rGPR:$Rm))]>,
2191 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002192 let Inst{31-27} = 0b11111;
2193 let Inst{26-23} = 0b0110;
2194 let Inst{22-20} = 0b101;
2195 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2196 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2197}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002198
Owen Anderson821752e2010-11-18 20:32:18 +00002199def t2SMMULR : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002200 "smmulr", "\t$Rd, $Rn, $Rm", []>,
2201 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002202 let Inst{31-27} = 0b11111;
2203 let Inst{26-23} = 0b0110;
2204 let Inst{22-20} = 0b101;
2205 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2206 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2207}
2208
Owen Anderson821752e2010-11-18 20:32:18 +00002209def t2SMMLA : T2FourReg<
2210 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2211 "smmla", "\t$Rd, $Rn, $Rm, $Ra",
Jim Grosbacha7603982011-07-01 21:12:19 +00002212 [(set rGPR:$Rd, (add (mulhs rGPR:$Rm, rGPR:$Rn), rGPR:$Ra))]>,
2213 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002214 let Inst{31-27} = 0b11111;
2215 let Inst{26-23} = 0b0110;
2216 let Inst{22-20} = 0b101;
Johnny Chend68e1192009-12-15 17:24:14 +00002217 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2218}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002219
Owen Anderson821752e2010-11-18 20:32:18 +00002220def t2SMMLAR: T2FourReg<
2221 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002222 "smmlar", "\t$Rd, $Rn, $Rm, $Ra", []>,
2223 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002224 let Inst{31-27} = 0b11111;
2225 let Inst{26-23} = 0b0110;
2226 let Inst{22-20} = 0b101;
Johnny Chen93042d12010-03-02 18:14:57 +00002227 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2228}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002229
Owen Anderson821752e2010-11-18 20:32:18 +00002230def t2SMMLS: T2FourReg<
2231 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
2232 "smmls", "\t$Rd, $Rn, $Rm, $Ra",
Jim Grosbacha7603982011-07-01 21:12:19 +00002233 [(set rGPR:$Rd, (sub rGPR:$Ra, (mulhs rGPR:$Rn, rGPR:$Rm)))]>,
2234 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002235 let Inst{31-27} = 0b11111;
2236 let Inst{26-23} = 0b0110;
2237 let Inst{22-20} = 0b110;
Johnny Chend68e1192009-12-15 17:24:14 +00002238 let Inst{7-4} = 0b0000; // No Rounding (Inst{4} = 0)
2239}
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002240
Owen Anderson821752e2010-11-18 20:32:18 +00002241def t2SMMLSR:T2FourReg<
2242 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32,
Jim Grosbacha7603982011-07-01 21:12:19 +00002243 "smmlsr", "\t$Rd, $Rn, $Rm, $Ra", []>,
2244 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chen93042d12010-03-02 18:14:57 +00002245 let Inst{31-27} = 0b11111;
2246 let Inst{26-23} = 0b0110;
2247 let Inst{22-20} = 0b110;
Johnny Chen93042d12010-03-02 18:14:57 +00002248 let Inst{7-4} = 0b0001; // Rounding (Inst{4} = 1)
2249}
2250
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002251multiclass T2I_smul<string opc, PatFrag opnode> {
Owen Anderson821752e2010-11-18 20:32:18 +00002252 def BB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2253 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm",
2254 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002255 (sext_inreg rGPR:$Rm, i16)))]>,
2256 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002257 let Inst{31-27} = 0b11111;
2258 let Inst{26-23} = 0b0110;
2259 let Inst{22-20} = 0b001;
2260 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2261 let Inst{7-6} = 0b00;
2262 let Inst{5-4} = 0b00;
2263 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002264
Owen Anderson821752e2010-11-18 20:32:18 +00002265 def BT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2266 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm",
2267 [(set rGPR:$Rd, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002268 (sra rGPR:$Rm, (i32 16))))]>,
2269 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002270 let Inst{31-27} = 0b11111;
2271 let Inst{26-23} = 0b0110;
2272 let Inst{22-20} = 0b001;
2273 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2274 let Inst{7-6} = 0b00;
2275 let Inst{5-4} = 0b01;
2276 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002277
Owen Anderson821752e2010-11-18 20:32:18 +00002278 def TB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2279 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm",
2280 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002281 (sext_inreg rGPR:$Rm, i16)))]>,
2282 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002283 let Inst{31-27} = 0b11111;
2284 let Inst{26-23} = 0b0110;
2285 let Inst{22-20} = 0b001;
2286 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2287 let Inst{7-6} = 0b00;
2288 let Inst{5-4} = 0b10;
2289 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002290
Owen Anderson821752e2010-11-18 20:32:18 +00002291 def TT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2292 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm",
2293 [(set rGPR:$Rd, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002294 (sra rGPR:$Rm, (i32 16))))]>,
2295 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002296 let Inst{31-27} = 0b11111;
2297 let Inst{26-23} = 0b0110;
2298 let Inst{22-20} = 0b001;
2299 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2300 let Inst{7-6} = 0b00;
2301 let Inst{5-4} = 0b11;
2302 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002303
Owen Anderson821752e2010-11-18 20:32:18 +00002304 def WB : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2305 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm",
2306 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002307 (sext_inreg rGPR:$Rm, i16)), (i32 16)))]>,
2308 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002309 let Inst{31-27} = 0b11111;
2310 let Inst{26-23} = 0b0110;
2311 let Inst{22-20} = 0b011;
2312 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2313 let Inst{7-6} = 0b00;
2314 let Inst{5-4} = 0b00;
2315 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002316
Owen Anderson821752e2010-11-18 20:32:18 +00002317 def WT : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iMUL16,
2318 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm",
2319 [(set rGPR:$Rd, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002320 (sra rGPR:$Rm, (i32 16))), (i32 16)))]>,
2321 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002322 let Inst{31-27} = 0b11111;
2323 let Inst{26-23} = 0b0110;
2324 let Inst{22-20} = 0b011;
2325 let Inst{15-12} = 0b1111; // Ra = 0b1111 (no accumulate)
2326 let Inst{7-6} = 0b00;
2327 let Inst{5-4} = 0b01;
2328 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002329}
2330
2331
2332multiclass T2I_smla<string opc, PatFrag opnode> {
Owen Anderson821752e2010-11-18 20:32:18 +00002333 def BB : T2FourReg<
2334 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2335 !strconcat(opc, "bb"), "\t$Rd, $Rn, $Rm, $Ra",
2336 [(set rGPR:$Rd, (add rGPR:$Ra,
2337 (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002338 (sext_inreg rGPR:$Rm, i16))))]>,
2339 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002340 let Inst{31-27} = 0b11111;
2341 let Inst{26-23} = 0b0110;
2342 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002343 let Inst{7-6} = 0b00;
2344 let Inst{5-4} = 0b00;
2345 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002346
Owen Anderson821752e2010-11-18 20:32:18 +00002347 def BT : T2FourReg<
2348 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2349 !strconcat(opc, "bt"), "\t$Rd, $Rn, $Rm, $Ra",
2350 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sext_inreg rGPR:$Rn, i16),
Jim Grosbacha7603982011-07-01 21:12:19 +00002351 (sra rGPR:$Rm, (i32 16)))))]>,
2352 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002353 let Inst{31-27} = 0b11111;
2354 let Inst{26-23} = 0b0110;
2355 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002356 let Inst{7-6} = 0b00;
2357 let Inst{5-4} = 0b01;
2358 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002359
Owen Anderson821752e2010-11-18 20:32:18 +00002360 def TB : T2FourReg<
2361 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2362 !strconcat(opc, "tb"), "\t$Rd, $Rn, $Rm, $Ra",
2363 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002364 (sext_inreg rGPR:$Rm, i16))))]>,
2365 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002366 let Inst{31-27} = 0b11111;
2367 let Inst{26-23} = 0b0110;
2368 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002369 let Inst{7-6} = 0b00;
2370 let Inst{5-4} = 0b10;
2371 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002372
Owen Anderson821752e2010-11-18 20:32:18 +00002373 def TT : T2FourReg<
2374 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2375 !strconcat(opc, "tt"), "\t$Rd, $Rn, $Rm, $Ra",
2376 [(set rGPR:$Rd, (add rGPR:$Ra, (opnode (sra rGPR:$Rn, (i32 16)),
Jim Grosbacha7603982011-07-01 21:12:19 +00002377 (sra rGPR:$Rm, (i32 16)))))]>,
2378 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002379 let Inst{31-27} = 0b11111;
2380 let Inst{26-23} = 0b0110;
2381 let Inst{22-20} = 0b001;
Johnny Chend68e1192009-12-15 17:24:14 +00002382 let Inst{7-6} = 0b00;
2383 let Inst{5-4} = 0b11;
2384 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002385
Owen Anderson821752e2010-11-18 20:32:18 +00002386 def WB : T2FourReg<
2387 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2388 !strconcat(opc, "wb"), "\t$Rd, $Rn, $Rm, $Ra",
2389 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002390 (sext_inreg rGPR:$Rm, i16)), (i32 16))))]>,
2391 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002392 let Inst{31-27} = 0b11111;
2393 let Inst{26-23} = 0b0110;
2394 let Inst{22-20} = 0b011;
Johnny Chend68e1192009-12-15 17:24:14 +00002395 let Inst{7-6} = 0b00;
2396 let Inst{5-4} = 0b00;
2397 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002398
Owen Anderson821752e2010-11-18 20:32:18 +00002399 def WT : T2FourReg<
2400 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC16,
2401 !strconcat(opc, "wt"), "\t$Rd, $Rn, $Rm, $Ra",
2402 [(set rGPR:$Rd, (add rGPR:$Ra, (sra (opnode rGPR:$Rn,
Jim Grosbacha7603982011-07-01 21:12:19 +00002403 (sra rGPR:$Rm, (i32 16))), (i32 16))))]>,
2404 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002405 let Inst{31-27} = 0b11111;
2406 let Inst{26-23} = 0b0110;
2407 let Inst{22-20} = 0b011;
Johnny Chend68e1192009-12-15 17:24:14 +00002408 let Inst{7-6} = 0b00;
2409 let Inst{5-4} = 0b01;
2410 }
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002411}
2412
2413defm t2SMUL : T2I_smul<"smul", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2414defm t2SMLA : T2I_smla<"smla", BinOpFrag<(mul node:$LHS, node:$RHS)>>;
2415
Johnny Chenadc77332010-02-26 22:04:29 +00002416// Halfword multiple accumulate long: SMLAL<x><y> -- for disassembly only
Owen Anderson821752e2010-11-18 20:32:18 +00002417def t2SMLALBB : T2FourReg_mac<1, 0b100, 0b1000, (outs rGPR:$Ra,rGPR:$Rd),
2418 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbb", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002419 [/* For disassembly only; pattern left blank */]>,
2420 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002421def t2SMLALBT : T2FourReg_mac<1, 0b100, 0b1001, (outs rGPR:$Ra,rGPR:$Rd),
2422 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlalbt", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002423 [/* For disassembly only; pattern left blank */]>,
2424 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002425def t2SMLALTB : T2FourReg_mac<1, 0b100, 0b1010, (outs rGPR:$Ra,rGPR:$Rd),
2426 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltb", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002427 [/* For disassembly only; pattern left blank */]>,
2428 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002429def t2SMLALTT : T2FourReg_mac<1, 0b100, 0b1011, (outs rGPR:$Ra,rGPR:$Rd),
2430 (ins rGPR:$Rn,rGPR:$Rm), IIC_iMAC64, "smlaltt", "\t$Ra, $Rd, $Rn, $Rm",
Jim Grosbacha7603982011-07-01 21:12:19 +00002431 [/* For disassembly only; pattern left blank */]>,
2432 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Cheng5b9fcd12009-07-07 01:17:28 +00002433
Johnny Chenadc77332010-02-26 22:04:29 +00002434// Dual halfword multiple: SMUAD, SMUSD, SMLAD, SMLSD, SMLALD, SMLSLD
2435// These are for disassembly only.
Jim Grosbach7a088642010-11-19 17:11:02 +00002436
Owen Anderson821752e2010-11-18 20:32:18 +00002437def t2SMUAD: T2ThreeReg_mac<
2438 0, 0b010, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002439 IIC_iMAC32, "smuad", "\t$Rd, $Rn, $Rm", []>,
2440 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002441 let Inst{15-12} = 0b1111;
2442}
Owen Anderson821752e2010-11-18 20:32:18 +00002443def t2SMUADX:T2ThreeReg_mac<
2444 0, 0b010, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002445 IIC_iMAC32, "smuadx", "\t$Rd, $Rn, $Rm", []>,
2446 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002447 let Inst{15-12} = 0b1111;
2448}
Owen Anderson821752e2010-11-18 20:32:18 +00002449def t2SMUSD: T2ThreeReg_mac<
2450 0, 0b100, 0b0000, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002451 IIC_iMAC32, "smusd", "\t$Rd, $Rn, $Rm", []>,
2452 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002453 let Inst{15-12} = 0b1111;
2454}
Owen Anderson821752e2010-11-18 20:32:18 +00002455def t2SMUSDX:T2ThreeReg_mac<
2456 0, 0b100, 0b0001, (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm),
Jim Grosbacha7603982011-07-01 21:12:19 +00002457 IIC_iMAC32, "smusdx", "\t$Rd, $Rn, $Rm", []>,
2458 Requires<[IsThumb2, HasThumb2DSP]> {
Johnny Chenadc77332010-02-26 22:04:29 +00002459 let Inst{15-12} = 0b1111;
2460}
Owen Andersonc6788c82011-08-22 23:31:45 +00002461def t2SMLAD : T2FourReg_mac<
Owen Anderson821752e2010-11-18 20:32:18 +00002462 0, 0b010, 0b0000, (outs rGPR:$Rd),
2463 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlad",
Jim Grosbacha7603982011-07-01 21:12:19 +00002464 "\t$Rd, $Rn, $Rm, $Ra", []>,
2465 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002466def t2SMLADX : T2FourReg_mac<
2467 0, 0b010, 0b0001, (outs rGPR:$Rd),
2468 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smladx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002469 "\t$Rd, $Rn, $Rm, $Ra", []>,
2470 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002471def t2SMLSD : T2FourReg_mac<0, 0b100, 0b0000, (outs rGPR:$Rd),
2472 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsd",
Jim Grosbacha7603982011-07-01 21:12:19 +00002473 "\t$Rd, $Rn, $Rm, $Ra", []>,
2474 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002475def t2SMLSDX : T2FourReg_mac<0, 0b100, 0b0001, (outs rGPR:$Rd),
2476 (ins rGPR:$Rn, rGPR:$Rm, rGPR:$Ra), IIC_iMAC32, "smlsdx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002477 "\t$Rd, $Rn, $Rm, $Ra", []>,
2478 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002479def t2SMLALD : T2FourReg_mac<1, 0b100, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2480 (ins rGPR:$Rm, rGPR:$Rn), IIC_iMAC64, "smlald",
Jim Grosbacha7603982011-07-01 21:12:19 +00002481 "\t$Ra, $Rd, $Rm, $Rn", []>,
2482 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002483def t2SMLALDX : T2FourReg_mac<1, 0b100, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2484 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlaldx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002485 "\t$Ra, $Rd, $Rm, $Rn", []>,
2486 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002487def t2SMLSLD : T2FourReg_mac<1, 0b101, 0b1100, (outs rGPR:$Ra,rGPR:$Rd),
2488 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsld",
Jim Grosbacha7603982011-07-01 21:12:19 +00002489 "\t$Ra, $Rd, $Rm, $Rn", []>,
2490 Requires<[IsThumb2, HasThumb2DSP]>;
Owen Anderson821752e2010-11-18 20:32:18 +00002491def t2SMLSLDX : T2FourReg_mac<1, 0b101, 0b1101, (outs rGPR:$Ra,rGPR:$Rd),
2492 (ins rGPR:$Rm,rGPR:$Rn), IIC_iMAC64, "smlsldx",
Jim Grosbacha7603982011-07-01 21:12:19 +00002493 "\t$Ra, $Rd, $Rm, $Rn", []>,
2494 Requires<[IsThumb2, HasThumb2DSP]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002495
2496//===----------------------------------------------------------------------===//
Evan Cheng734f63b2011-06-21 19:00:54 +00002497// Division Instructions.
2498// Signed and unsigned division on v7-M
2499//
2500def t2SDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2501 "sdiv", "\t$Rd, $Rn, $Rm",
2502 [(set rGPR:$Rd, (sdiv rGPR:$Rn, rGPR:$Rm))]>,
2503 Requires<[HasDivide, IsThumb2]> {
2504 let Inst{31-27} = 0b11111;
2505 let Inst{26-21} = 0b011100;
2506 let Inst{20} = 0b1;
2507 let Inst{15-12} = 0b1111;
2508 let Inst{7-4} = 0b1111;
2509}
2510
2511def t2UDIV : T2ThreeReg<(outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm), IIC_iALUi,
2512 "udiv", "\t$Rd, $Rn, $Rm",
2513 [(set rGPR:$Rd, (udiv rGPR:$Rn, rGPR:$Rm))]>,
2514 Requires<[HasDivide, IsThumb2]> {
2515 let Inst{31-27} = 0b11111;
2516 let Inst{26-21} = 0b011101;
2517 let Inst{20} = 0b1;
2518 let Inst{15-12} = 0b1111;
2519 let Inst{7-4} = 0b1111;
2520}
2521
2522//===----------------------------------------------------------------------===//
Evan Chengf49810c2009-06-23 17:48:47 +00002523// Misc. Arithmetic Instructions.
2524//
2525
Jim Grosbach80dc1162010-02-16 21:23:02 +00002526class T2I_misc<bits<2> op1, bits<2> op2, dag oops, dag iops,
2527 InstrItinClass itin, string opc, string asm, list<dag> pattern>
Owen Anderson612fb5b2010-11-18 21:15:19 +00002528 : T2ThreeReg<oops, iops, itin, opc, asm, pattern> {
Johnny Chend68e1192009-12-15 17:24:14 +00002529 let Inst{31-27} = 0b11111;
2530 let Inst{26-22} = 0b01010;
2531 let Inst{21-20} = op1;
2532 let Inst{15-12} = 0b1111;
2533 let Inst{7-6} = 0b10;
2534 let Inst{5-4} = op2;
Jim Grosbach86386922010-12-08 22:10:43 +00002535 let Rn{3-0} = Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00002536}
Evan Chengf49810c2009-06-23 17:48:47 +00002537
Owen Anderson612fb5b2010-11-18 21:15:19 +00002538def t2CLZ : T2I_misc<0b11, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2539 "clz", "\t$Rd, $Rm", [(set rGPR:$Rd, (ctlz rGPR:$Rm))]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002540
Owen Anderson612fb5b2010-11-18 21:15:19 +00002541def t2RBIT : T2I_misc<0b01, 0b10, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2542 "rbit", "\t$Rd, $Rm",
2543 [(set rGPR:$Rd, (ARMrbit rGPR:$Rm))]>;
Jim Grosbach3482c802010-01-18 19:58:49 +00002544
Owen Anderson612fb5b2010-11-18 21:15:19 +00002545def t2REV : T2I_misc<0b01, 0b00, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2546 "rev", ".w\t$Rd, $Rm", [(set rGPR:$Rd, (bswap rGPR:$Rm))]>;
Johnny Chend68e1192009-12-15 17:24:14 +00002547
Owen Anderson612fb5b2010-11-18 21:15:19 +00002548def t2REV16 : T2I_misc<0b01, 0b01, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2549 "rev16", ".w\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00002550 [(set rGPR:$Rd, (rotr (bswap rGPR:$Rm), (i32 16)))]>;
Evan Cheng6d6c55b2011-06-17 20:47:21 +00002551
Owen Anderson612fb5b2010-11-18 21:15:19 +00002552def t2REVSH : T2I_misc<0b01, 0b11, (outs rGPR:$Rd), (ins rGPR:$Rm), IIC_iUNAr,
2553 "revsh", ".w\t$Rd, $Rm",
Evan Cheng9568e5c2011-06-21 06:01:08 +00002554 [(set rGPR:$Rd, (sra (bswap rGPR:$Rm), (i32 16)))]>;
Evan Cheng3f30af32011-03-18 21:52:42 +00002555
Evan Chengf60ceac2011-06-15 17:17:48 +00002556def : T2Pat<(or (sra (shl rGPR:$Rm, (i32 24)), (i32 16)),
Evan Cheng9568e5c2011-06-21 06:01:08 +00002557 (and (srl rGPR:$Rm, (i32 8)), 0xFF)),
Evan Chengf60ceac2011-06-15 17:17:48 +00002558 (t2REVSH rGPR:$Rm)>;
2559
Owen Anderson612fb5b2010-11-18 21:15:19 +00002560def t2PKHBT : T2ThreeReg<
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002561 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$sh),
2562 IIC_iBITsi, "pkhbt", "\t$Rd, $Rn, $Rm, lsl $sh",
Owen Anderson612fb5b2010-11-18 21:15:19 +00002563 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF),
Jim Grosbach1769a3d2011-07-20 20:49:03 +00002564 (and (shl rGPR:$Rm, pkh_lsl_amt:$sh),
Jim Grosbachb1dc3932010-05-05 20:44:35 +00002565 0xFFFF0000)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002566 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002567 let Inst{31-27} = 0b11101;
2568 let Inst{26-25} = 0b01;
2569 let Inst{24-20} = 0b01100;
2570 let Inst{5} = 0; // BT form
2571 let Inst{4} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002572
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002573 bits<5> sh;
2574 let Inst{14-12} = sh{4-2};
2575 let Inst{7-6} = sh{1-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002576}
Evan Cheng40289b02009-07-07 05:35:52 +00002577
2578// Alternate cases for PKHBT where identities eliminate some nodes.
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002579def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (and rGPR:$src2, 0xFFFF0000)),
2580 (t2PKHBT rGPR:$src1, rGPR:$src2, 0)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002581 Requires<[HasT2ExtractPack, IsThumb2]>;
Bob Wilsonf955f292010-08-17 17:23:19 +00002582def : T2Pat<(or (and rGPR:$src1, 0xFFFF), (shl rGPR:$src2, imm16_31:$sh)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002583 (t2PKHBT rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002584 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Cheng40289b02009-07-07 05:35:52 +00002585
Bob Wilsondc66eda2010-08-16 22:26:55 +00002586// Note: Shifts of 1-15 bits will be transformed to srl instead of sra and
2587// will match the pattern below.
Owen Anderson612fb5b2010-11-18 21:15:19 +00002588def t2PKHTB : T2ThreeReg<
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002589 (outs rGPR:$Rd), (ins rGPR:$Rn, rGPR:$Rm, i32imm:$sh),
2590 IIC_iBITsi, "pkhtb", "\t$Rd, $Rn, $Rm, asr $sh",
Owen Anderson612fb5b2010-11-18 21:15:19 +00002591 [(set rGPR:$Rd, (or (and rGPR:$Rn, 0xFFFF0000),
Jim Grosbach1769a3d2011-07-20 20:49:03 +00002592 (and (sra rGPR:$Rm, pkh_asr_amt:$sh),
Bob Wilsonf955f292010-08-17 17:23:19 +00002593 0xFFFF)))]>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002594 Requires<[HasT2ExtractPack, IsThumb2]> {
Johnny Chend68e1192009-12-15 17:24:14 +00002595 let Inst{31-27} = 0b11101;
2596 let Inst{26-25} = 0b01;
2597 let Inst{24-20} = 0b01100;
2598 let Inst{5} = 1; // TB form
2599 let Inst{4} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002600
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002601 bits<5> sh;
2602 let Inst{14-12} = sh{4-2};
2603 let Inst{7-6} = sh{1-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002604}
Evan Cheng40289b02009-07-07 05:35:52 +00002605
2606// Alternate cases for PKHTB where identities eliminate some nodes. Note that
2607// a shift amount of 0 is *not legal* here, it is PKHBT instead.
Bob Wilsondc66eda2010-08-16 22:26:55 +00002608def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000), (srl rGPR:$src2, imm16_31:$sh)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002609 (t2PKHTB rGPR:$src1, rGPR:$src2, imm16_31:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002610 Requires<[HasT2ExtractPack, IsThumb2]>;
Jim Grosbach6ccfc502010-07-30 02:41:01 +00002611def : T2Pat<(or (and rGPR:$src1, 0xFFFF0000),
Bob Wilsonf955f292010-08-17 17:23:19 +00002612 (and (srl rGPR:$src2, imm1_15:$sh), 0xFFFF)),
Jim Grosbacha0472dc2011-07-20 20:32:09 +00002613 (t2PKHTB rGPR:$src1, rGPR:$src2, imm1_15:$sh)>,
Jim Grosbach9729d2e2010-11-01 15:59:52 +00002614 Requires<[HasT2ExtractPack, IsThumb2]>;
Evan Chengf49810c2009-06-23 17:48:47 +00002615
2616//===----------------------------------------------------------------------===//
2617// Comparison Instructions...
2618//
Johnny Chend68e1192009-12-15 17:24:14 +00002619defm t2CMP : T2I_cmp_irs<0b1101, "cmp",
Evan Cheng5d42c562010-09-29 00:49:25 +00002620 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Johnny Chend68e1192009-12-15 17:24:14 +00002621 BinOpFrag<(ARMcmp node:$LHS, node:$RHS)>>;
Jim Grosbach97a884d2010-12-07 20:41:06 +00002622
2623def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_imm:$imm),
2624 (t2CMPri GPR:$lhs, t2_so_imm:$imm)>;
2625def : T2Pat<(ARMcmpZ GPR:$lhs, rGPR:$rhs),
2626 (t2CMPrr GPR:$lhs, rGPR:$rhs)>;
2627def : T2Pat<(ARMcmpZ GPR:$lhs, t2_so_reg:$rhs),
2628 (t2CMPrs GPR:$lhs, t2_so_reg:$rhs)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002629
Dan Gohman4b7dff92010-08-26 15:50:25 +00002630//FIXME: Disable CMN, as CCodes are backwards from compare expectations
2631// Compare-to-zero still works out, just not the relationals
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002632//defm t2CMN : T2I_cmp_irs<0b1000, "cmn",
2633// BinOpFrag<(ARMcmp node:$LHS,(ineg node:$RHS))>>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002634defm t2CMNz : T2I_cmp_irs<0b1000, "cmn",
Evan Cheng5d42c562010-09-29 00:49:25 +00002635 IIC_iCMPi, IIC_iCMPr, IIC_iCMPsi,
Dan Gohman4b7dff92010-08-26 15:50:25 +00002636 BinOpFrag<(ARMcmpZ node:$LHS,(ineg node:$RHS))>>;
2637
Jim Grosbachd5d2bae2010-01-22 00:08:13 +00002638//def : T2Pat<(ARMcmp GPR:$src, t2_so_imm_neg:$imm),
2639// (t2CMNri GPR:$src, t2_so_imm_neg:$imm)>;
Dan Gohman4b7dff92010-08-26 15:50:25 +00002640
2641def : T2Pat<(ARMcmpZ GPR:$src, t2_so_imm_neg:$imm),
2642 (t2CMNzri GPR:$src, t2_so_imm_neg:$imm)>;
Evan Chengf49810c2009-06-23 17:48:47 +00002643
Johnny Chend68e1192009-12-15 17:24:14 +00002644defm t2TST : T2I_cmp_irs<0b0000, "tst",
Evan Cheng5d42c562010-09-29 00:49:25 +00002645 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Evan Chengc4af4632010-11-17 20:13:28 +00002646 BinOpFrag<(ARMcmpZ (and_su node:$LHS, node:$RHS), 0)>>;
Johnny Chend68e1192009-12-15 17:24:14 +00002647defm t2TEQ : T2I_cmp_irs<0b0100, "teq",
Evan Cheng5d42c562010-09-29 00:49:25 +00002648 IIC_iTSTi, IIC_iTSTr, IIC_iTSTsi,
Evan Chengc4af4632010-11-17 20:13:28 +00002649 BinOpFrag<(ARMcmpZ (xor_su node:$LHS, node:$RHS), 0)>>;
Evan Chengf49810c2009-06-23 17:48:47 +00002650
Evan Chenge253c952009-07-07 20:39:03 +00002651// Conditional moves
2652// FIXME: should be able to write a pattern for ARMcmov, but can't use
Jim Grosbach64171712010-02-16 21:07:46 +00002653// a two-value operand where a dag node expects two operands. :(
Evan Cheng63f35442010-11-13 02:25:14 +00002654let neverHasSideEffects = 1 in {
Jim Grosbachefeedce2011-07-01 17:14:11 +00002655def t2MOVCCr : t2PseudoInst<(outs rGPR:$Rd),
2656 (ins rGPR:$false, rGPR:$Rm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00002657 4, IIC_iCMOVr,
Owen Anderson8ee97792010-11-18 21:46:31 +00002658 [/*(set rGPR:$Rd, (ARMcmov rGPR:$false, rGPR:$Rm, imm:$cc, CCR:$ccr))*/]>,
Jim Grosbachefeedce2011-07-01 17:14:11 +00002659 RegConstraint<"$false = $Rd">;
2660
2661let isMoveImm = 1 in
2662def t2MOVCCi : t2PseudoInst<(outs rGPR:$Rd),
2663 (ins rGPR:$false, t2_so_imm:$imm, pred:$p),
Owen Anderson16884412011-07-13 23:22:26 +00002664 4, IIC_iCMOVi,
Jim Grosbachefeedce2011-07-01 17:14:11 +00002665[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm:$imm, imm:$cc, CCR:$ccr))*/]>,
2666 RegConstraint<"$false = $Rd">;
Evan Chenge253c952009-07-07 20:39:03 +00002667
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00002668// FIXME: Pseudo-ize these. For now, just mark codegen only.
2669let isCodeGenOnly = 1 in {
Evan Chengc4af4632010-11-17 20:13:28 +00002670let isMoveImm = 1 in
Jim Grosbachffa32252011-07-19 19:13:28 +00002671def t2MOVCCi16 : T2I<(outs rGPR:$Rd), (ins rGPR:$false, imm0_65535_expr:$imm),
Evan Cheng875a6ac2010-11-12 22:42:47 +00002672 IIC_iCMOVi,
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002673 "movw", "\t$Rd, $imm", []>,
2674 RegConstraint<"$false = $Rd"> {
Jim Grosbacha4257162010-10-07 00:53:56 +00002675 let Inst{31-27} = 0b11110;
2676 let Inst{25} = 1;
2677 let Inst{24-21} = 0b0010;
2678 let Inst{20} = 0; // The S bit.
2679 let Inst{15} = 0;
Jim Grosbach7a088642010-11-19 17:11:02 +00002680
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002681 bits<4> Rd;
2682 bits<16> imm;
Jim Grosbach7a088642010-11-19 17:11:02 +00002683
Jim Grosbach86386922010-12-08 22:10:43 +00002684 let Inst{11-8} = Rd;
Owen Andersonc56dcbf2010-11-16 00:29:56 +00002685 let Inst{19-16} = imm{15-12};
2686 let Inst{26} = imm{11};
2687 let Inst{14-12} = imm{10-8};
2688 let Inst{7-0} = imm{7-0};
Jim Grosbacha4257162010-10-07 00:53:56 +00002689}
2690
Evan Chengc4af4632010-11-17 20:13:28 +00002691let isMoveImm = 1 in
Evan Cheng63f35442010-11-13 02:25:14 +00002692def t2MOVCCi32imm : PseudoInst<(outs rGPR:$dst),
2693 (ins rGPR:$false, i32imm:$src, pred:$p),
Jim Grosbach99594eb2010-11-18 01:38:26 +00002694 IIC_iCMOVix2, []>, RegConstraint<"$false = $dst">;
Evan Cheng63f35442010-11-13 02:25:14 +00002695
Evan Chengc4af4632010-11-17 20:13:28 +00002696let isMoveImm = 1 in
Owen Anderson8ee97792010-11-18 21:46:31 +00002697def t2MVNCCi : T2OneRegImm<(outs rGPR:$Rd), (ins rGPR:$false, t2_so_imm:$imm),
2698 IIC_iCMOVi, "mvn", ".w\t$Rd, $imm",
2699[/*(set rGPR:$Rd,(ARMcmov rGPR:$false,t2_so_imm_not:$imm,
Evan Cheng875a6ac2010-11-12 22:42:47 +00002700 imm:$cc, CCR:$ccr))*/]>,
Owen Anderson8ee97792010-11-18 21:46:31 +00002701 RegConstraint<"$false = $Rd"> {
Evan Cheng875a6ac2010-11-12 22:42:47 +00002702 let Inst{31-27} = 0b11110;
2703 let Inst{25} = 0;
2704 let Inst{24-21} = 0b0011;
2705 let Inst{20} = 0; // The S bit.
2706 let Inst{19-16} = 0b1111; // Rn
2707 let Inst{15} = 0;
2708}
2709
Johnny Chend68e1192009-12-15 17:24:14 +00002710class T2I_movcc_sh<bits<2> opcod, dag oops, dag iops, InstrItinClass itin,
2711 string opc, string asm, list<dag> pattern>
Owen Andersonbb6315d2010-11-15 19:58:36 +00002712 : T2TwoRegShiftImm<oops, iops, itin, opc, asm, pattern> {
Johnny Chend68e1192009-12-15 17:24:14 +00002713 let Inst{31-27} = 0b11101;
2714 let Inst{26-25} = 0b01;
2715 let Inst{24-21} = 0b0010;
2716 let Inst{20} = 0; // The S bit.
2717 let Inst{19-16} = 0b1111; // Rn
2718 let Inst{5-4} = opcod; // Shift type.
2719}
Owen Andersonbb6315d2010-11-15 19:58:36 +00002720def t2MOVCClsl : T2I_movcc_sh<0b00, (outs rGPR:$Rd),
2721 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2722 IIC_iCMOVsi, "lsl", ".w\t$Rd, $Rm, $imm", []>,
2723 RegConstraint<"$false = $Rd">;
2724def t2MOVCClsr : T2I_movcc_sh<0b01, (outs rGPR:$Rd),
2725 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2726 IIC_iCMOVsi, "lsr", ".w\t$Rd, $Rm, $imm", []>,
2727 RegConstraint<"$false = $Rd">;
2728def t2MOVCCasr : T2I_movcc_sh<0b10, (outs rGPR:$Rd),
2729 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2730 IIC_iCMOVsi, "asr", ".w\t$Rd, $Rm, $imm", []>,
2731 RegConstraint<"$false = $Rd">;
2732def t2MOVCCror : T2I_movcc_sh<0b11, (outs rGPR:$Rd),
2733 (ins rGPR:$false, rGPR:$Rm, i32imm:$imm),
2734 IIC_iCMOVsi, "ror", ".w\t$Rd, $Rm, $imm", []>,
2735 RegConstraint<"$false = $Rd">;
Jim Grosbach6b8f1e32011-06-27 23:54:06 +00002736} // isCodeGenOnly = 1
Jim Grosbachefeedce2011-07-01 17:14:11 +00002737} // neverHasSideEffects
Evan Cheng13f8b362009-08-01 01:43:45 +00002738
David Goodwin5e47a9a2009-06-30 18:04:13 +00002739//===----------------------------------------------------------------------===//
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002740// Atomic operations intrinsics
2741//
2742
2743// memory barriers protect the atomic sequences
2744let hasSideEffects = 1 in {
Bob Wilsonf74a4292010-10-30 00:54:37 +00002745def t2DMB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2746 "dmb", "\t$opt", [(ARMMemBarrier (i32 imm:$opt))]>,
2747 Requires<[IsThumb, HasDB]> {
2748 bits<4> opt;
2749 let Inst{31-4} = 0xf3bf8f5;
2750 let Inst{3-0} = opt;
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002751}
2752}
2753
Bob Wilsonf74a4292010-10-30 00:54:37 +00002754def t2DSB : AInoP<(outs), (ins memb_opt:$opt), ThumbFrm, NoItinerary,
2755 "dsb", "\t$opt",
2756 [/* For disassembly only; pattern left blank */]>,
2757 Requires<[IsThumb, HasDB]> {
2758 bits<4> opt;
2759 let Inst{31-4} = 0xf3bf8f4;
2760 let Inst{3-0} = opt;
Johnny Chena4339822010-03-03 00:16:28 +00002761}
2762
Johnny Chena4339822010-03-03 00:16:28 +00002763// ISB has only full system option -- for disassembly only
Bruno Cardoso Lopes892fc6d2011-01-18 21:17:09 +00002764def t2ISB : AInoP<(outs), (ins), ThumbFrm, NoItinerary, "isb", "",
Bob Wilsonf74a4292010-10-30 00:54:37 +00002765 [/* For disassembly only; pattern left blank */]>,
2766 Requires<[IsThumb2, HasV7]> {
2767 let Inst{31-4} = 0xf3bf8f6;
Johnny Chena4339822010-03-03 00:16:28 +00002768 let Inst{3-0} = 0b1111;
2769}
2770
Owen Anderson16884412011-07-13 23:22:26 +00002771class T2I_ldrex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
Johnny Chend68e1192009-12-15 17:24:14 +00002772 InstrItinClass itin, string opc, string asm, string cstr,
2773 list<dag> pattern, bits<4> rt2 = 0b1111>
2774 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2775 let Inst{31-27} = 0b11101;
2776 let Inst{26-20} = 0b0001101;
2777 let Inst{11-8} = rt2;
2778 let Inst{7-6} = 0b01;
2779 let Inst{5-4} = opcod;
2780 let Inst{3-0} = 0b1111;
Jim Grosbach7a088642010-11-19 17:11:02 +00002781
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002782 bits<4> addr;
Owen Anderson91a7c592010-11-19 00:28:38 +00002783 bits<4> Rt;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002784 let Inst{19-16} = addr;
Jim Grosbach86386922010-12-08 22:10:43 +00002785 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00002786}
Owen Anderson16884412011-07-13 23:22:26 +00002787class T2I_strex<bits<2> opcod, dag oops, dag iops, AddrMode am, int sz,
Johnny Chend68e1192009-12-15 17:24:14 +00002788 InstrItinClass itin, string opc, string asm, string cstr,
2789 list<dag> pattern, bits<4> rt2 = 0b1111>
2790 : Thumb2I<oops, iops, am, sz, itin, opc, asm, cstr, pattern> {
2791 let Inst{31-27} = 0b11101;
2792 let Inst{26-20} = 0b0001100;
2793 let Inst{11-8} = rt2;
2794 let Inst{7-6} = 0b01;
2795 let Inst{5-4} = opcod;
Jim Grosbach7a088642010-11-19 17:11:02 +00002796
Owen Anderson91a7c592010-11-19 00:28:38 +00002797 bits<4> Rd;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002798 bits<4> addr;
Owen Anderson91a7c592010-11-19 00:28:38 +00002799 bits<4> Rt;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002800 let Inst{3-0} = Rd;
2801 let Inst{19-16} = addr;
Jim Grosbach86386922010-12-08 22:10:43 +00002802 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00002803}
2804
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002805let mayLoad = 1 in {
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002806def t2LDREXB : T2I_ldrex<0b00, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002807 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002808 "ldrexb", "\t$Rt, $addr", "", []>;
2809def t2LDREXH : T2I_ldrex<0b01, (outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002810 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002811 "ldrexh", "\t$Rt, $addr", "", []>;
2812def t2LDREX : Thumb2I<(outs rGPR:$Rt), (ins t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002813 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002814 "ldrex", "\t$Rt, $addr", "", []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002815 let Inst{31-27} = 0b11101;
2816 let Inst{26-20} = 0b0000101;
2817 let Inst{11-8} = 0b1111;
2818 let Inst{7-0} = 0b00000000; // imm8 = 0
Jim Grosbach00f25fa2010-12-14 20:46:39 +00002819
Owen Anderson808c7d12010-12-10 21:52:38 +00002820 bits<4> Rt;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002821 bits<4> addr;
2822 let Inst{19-16} = addr;
Owen Anderson808c7d12010-12-10 21:52:38 +00002823 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00002824}
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002825let hasExtraDefRegAllocReq = 1 in
2826def t2LDREXD : T2I_ldrex<0b11, (outs rGPR:$Rt, rGPR:$Rt2),
2827 (ins t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002828 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002829 "ldrexd", "\t$Rt, $Rt2, $addr", "",
Owen Anderson91a7c592010-11-19 00:28:38 +00002830 [], {?, ?, ?, ?}> {
2831 bits<4> Rt2;
Jim Grosbach86386922010-12-08 22:10:43 +00002832 let Inst{11-8} = Rt2;
Owen Anderson91a7c592010-11-19 00:28:38 +00002833}
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002834}
2835
Owen Anderson91a7c592010-11-19 00:28:38 +00002836let mayStore = 1, Constraints = "@earlyclobber $Rd" in {
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002837def t2STREXB : T2I_strex<0b00, (outs rGPR:$Rd),
2838 (ins rGPR:$Rt, t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002839 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002840 "strexb", "\t$Rd, $Rt, $addr", "", []>;
2841def t2STREXH : T2I_strex<0b01, (outs rGPR:$Rd),
2842 (ins rGPR:$Rt, t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002843 AddrModeNone, 4, NoItinerary,
Jim Grosbachf921c0fe2011-06-13 22:54:22 +00002844 "strexh", "\t$Rd, $Rt, $addr", "", []>;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002845def t2STREX : Thumb2I<(outs rGPR:$Rd), (ins rGPR:$Rt, t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002846 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002847 "strex", "\t$Rd, $Rt, $addr", "",
2848 []> {
Johnny Chend68e1192009-12-15 17:24:14 +00002849 let Inst{31-27} = 0b11101;
2850 let Inst{26-20} = 0b0000100;
2851 let Inst{7-0} = 0b00000000; // imm8 = 0
Jim Grosbach00f25fa2010-12-14 20:46:39 +00002852
Owen Anderson808c7d12010-12-10 21:52:38 +00002853 bits<4> Rd;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002854 bits<4> addr;
Owen Anderson808c7d12010-12-10 21:52:38 +00002855 bits<4> Rt;
2856 let Inst{11-8} = Rd;
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002857 let Inst{19-16} = addr;
Owen Anderson808c7d12010-12-10 21:52:38 +00002858 let Inst{15-12} = Rt;
Johnny Chend68e1192009-12-15 17:24:14 +00002859}
Bruno Cardoso Lopesa0112d02011-05-28 04:07:29 +00002860}
2861
2862let hasExtraSrcRegAllocReq = 1, Constraints = "@earlyclobber $Rd" in
Owen Anderson91a7c592010-11-19 00:28:38 +00002863def t2STREXD : T2I_strex<0b11, (outs rGPR:$Rd),
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002864 (ins rGPR:$Rt, rGPR:$Rt2, t2addrmode_reg:$addr),
Owen Anderson16884412011-07-13 23:22:26 +00002865 AddrModeNone, 4, NoItinerary,
Bruno Cardoso Lopes505f3cd2011-03-24 21:04:58 +00002866 "strexd", "\t$Rd, $Rt, $Rt2, $addr", "", [],
Owen Anderson91a7c592010-11-19 00:28:38 +00002867 {?, ?, ?, ?}> {
2868 bits<4> Rt2;
Jim Grosbach86386922010-12-08 22:10:43 +00002869 let Inst{11-8} = Rt2;
Owen Anderson91a7c592010-11-19 00:28:38 +00002870}
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002871
Johnny Chen10a77e12010-03-02 22:11:06 +00002872// Clear-Exclusive is for disassembly only.
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00002873def t2CLREX : T2XI<(outs), (ins), NoItinerary, "clrex",
2874 [/* For disassembly only; pattern left blank */]>,
2875 Requires<[IsThumb2, HasV7]> {
2876 let Inst{31-16} = 0xf3bf;
Johnny Chen10a77e12010-03-02 22:11:06 +00002877 let Inst{15-14} = 0b10;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00002878 let Inst{13} = 0;
Johnny Chen10a77e12010-03-02 22:11:06 +00002879 let Inst{12} = 0;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00002880 let Inst{11-8} = 0b1111;
Johnny Chen10a77e12010-03-02 22:11:06 +00002881 let Inst{7-4} = 0b0010;
Bruno Cardoso Lopese47f3752011-01-20 19:18:32 +00002882 let Inst{3-0} = 0b1111;
Johnny Chen10a77e12010-03-02 22:11:06 +00002883}
2884
Jim Grosbachc219e4d2009-12-14 18:56:47 +00002885//===----------------------------------------------------------------------===//
Jim Grosbach5aa16842009-08-11 19:42:21 +00002886// SJLJ Exception handling intrinsics
Jim Grosbach1add6592009-08-13 15:11:43 +00002887// eh_sjlj_setjmp() is an instruction sequence to store the return
Jim Grosbach5aa16842009-08-11 19:42:21 +00002888// address and save #0 in R0 for the non-longjmp case.
2889// Since by its nature we may be coming from some other function to get
2890// here, and we're using the stack frame for the containing function to
2891// save/restore registers, we can't keep anything live in regs across
2892// the eh_sjlj_setjmp(), else it will almost certainly have been tromped upon
Chris Lattner7a2bdde2011-04-15 05:18:47 +00002893// when we get here from a longjmp(). We force everything out of registers
Jim Grosbach5aa16842009-08-11 19:42:21 +00002894// except for our own input by listing the relevant registers in Defs. By
2895// doing so, we also cause the prologue/epilogue code to actively preserve
2896// all of the callee-saved resgisters, which is exactly what we want.
Jim Grosbach0798edd2010-05-27 23:49:24 +00002897// $val is a scratch register for our use.
Jim Grosbacha87ded22010-02-08 23:22:00 +00002898let Defs =
Andrew Tricka1099f12011-06-07 00:08:49 +00002899 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR,
Jakob Stoklund Olesen2944b4f2011-05-03 22:31:24 +00002900 QQQQ0, QQQQ1, QQQQ2, QQQQ3 ],
2901 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002902 def t2Int_eh_sjlj_setjmp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00002903 AddrModeNone, 0, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002904 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002905 Requires<[IsThumb2, HasVFP2]>;
Jim Grosbach5aa16842009-08-11 19:42:21 +00002906}
2907
Bob Wilsonec80e262010-04-09 20:41:18 +00002908let Defs =
Andrew Tricka1099f12011-06-07 00:08:49 +00002909 [ R0, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, R12, LR, CPSR ],
Chris Lattnera4a3a5e2010-10-31 19:15:18 +00002910 hasSideEffects = 1, isBarrier = 1, isCodeGenOnly = 1 in {
Jim Grosbach9f134b52010-08-26 17:02:47 +00002911 def t2Int_eh_sjlj_setjmp_nofp : Thumb2XI<(outs), (ins tGPR:$src, tGPR:$val),
Owen Anderson16884412011-07-13 23:22:26 +00002912 AddrModeNone, 0, NoItinerary, "", "",
Jim Grosbach9f134b52010-08-26 17:02:47 +00002913 [(set R0, (ARMeh_sjlj_setjmp tGPR:$src, tGPR:$val))]>,
Bob Wilsonec80e262010-04-09 20:41:18 +00002914 Requires<[IsThumb2, NoVFP]>;
2915}
Jim Grosbach5aa16842009-08-11 19:42:21 +00002916
2917
2918//===----------------------------------------------------------------------===//
David Goodwin5e47a9a2009-06-30 18:04:13 +00002919// Control-Flow Instructions
2920//
2921
Evan Chengc50a1cb2009-07-09 22:58:39 +00002922// FIXME: remove when we have a way to marking a MI with these properties.
Evan Chengc50a1cb2009-07-09 22:58:39 +00002923// FIXME: Should pc be an implicit operand like PICADD, etc?
Evan Cheng0d92f5f2009-10-01 08:22:27 +00002924let isReturn = 1, isTerminator = 1, isBarrier = 1, mayLoad = 1,
Chris Lattner39ee0362010-10-31 19:10:56 +00002925 hasExtraDefRegAllocReq = 1, isCodeGenOnly = 1 in
Jim Grosbach53e3fc42011-07-08 17:40:42 +00002926def t2LDMIA_RET: t2PseudoExpand<(outs GPR:$wb), (ins GPR:$Rn, pred:$p,
Jim Grosbach16f99242011-06-30 18:25:42 +00002927 reglist:$regs, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00002928 4, IIC_iLoad_mBr, [],
Jim Grosbach53e3fc42011-07-08 17:40:42 +00002929 (t2LDMIA_UPD GPR:$wb, GPR:$Rn, pred:$p, reglist:$regs)>,
Jim Grosbach16f99242011-06-30 18:25:42 +00002930 RegConstraint<"$Rn = $wb">;
Evan Chengc50a1cb2009-07-09 22:58:39 +00002931
David Goodwin5e47a9a2009-06-30 18:04:13 +00002932let isBranch = 1, isTerminator = 1, isBarrier = 1 in {
2933let isPredicable = 1 in
Owen Andersonc2666002010-12-13 19:31:11 +00002934def t2B : T2XI<(outs), (ins uncondbrtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002935 "b.w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002936 [(br bb:$target)]> {
2937 let Inst{31-27} = 0b11110;
2938 let Inst{15-14} = 0b10;
2939 let Inst{12} = 1;
Owen Anderson05bf5952010-11-29 18:54:38 +00002940
2941 bits<20> target;
2942 let Inst{26} = target{19};
2943 let Inst{11} = target{18};
2944 let Inst{13} = target{17};
2945 let Inst{21-16} = target{16-11};
2946 let Inst{10-0} = target{10-0};
Johnny Chend68e1192009-12-15 17:24:14 +00002947}
David Goodwin5e47a9a2009-06-30 18:04:13 +00002948
Jim Grosbacha0bb2532010-11-29 22:40:58 +00002949let isNotDuplicable = 1, isIndirectBranch = 1 in {
Jim Grosbachd4811102010-12-15 19:03:16 +00002950def t2BR_JT : t2PseudoInst<(outs),
Jim Grosbach5ca66692010-11-29 22:37:40 +00002951 (ins GPR:$target, GPR:$index, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +00002952 0, IIC_Br,
Jim Grosbach5ca66692010-11-29 22:37:40 +00002953 [(ARMbr2jt GPR:$target, GPR:$index, tjumptable:$jt, imm:$id)]>;
Evan Cheng5657c012009-07-29 02:18:14 +00002954
Evan Cheng25f7cfc2009-08-01 06:13:52 +00002955// FIXME: Add a non-pc based case that can be predicated.
Jim Grosbachd4811102010-12-15 19:03:16 +00002956def t2TBB_JT : t2PseudoInst<(outs),
Jim Grosbach5ca66692010-11-29 22:37:40 +00002957 (ins GPR:$index, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +00002958 0, IIC_Br, []>;
Jim Grosbach5ca66692010-11-29 22:37:40 +00002959
Jim Grosbachd4811102010-12-15 19:03:16 +00002960def t2TBH_JT : t2PseudoInst<(outs),
Jim Grosbach5ca66692010-11-29 22:37:40 +00002961 (ins GPR:$index, i32imm:$jt, i32imm:$id),
Owen Anderson16884412011-07-13 23:22:26 +00002962 0, IIC_Br, []>;
Jim Grosbach5ca66692010-11-29 22:37:40 +00002963
2964def t2TBB : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
2965 "tbb", "\t[$Rn, $Rm]", []> {
2966 bits<4> Rn;
2967 bits<4> Rm;
Jim Grosbachf0db2612010-12-17 18:42:56 +00002968 let Inst{31-20} = 0b111010001101;
Jim Grosbach5ca66692010-11-29 22:37:40 +00002969 let Inst{19-16} = Rn;
2970 let Inst{15-5} = 0b11110000000;
2971 let Inst{4} = 0; // B form
2972 let Inst{3-0} = Rm;
Johnny Chend68e1192009-12-15 17:24:14 +00002973}
Evan Cheng5657c012009-07-29 02:18:14 +00002974
Jim Grosbach5ca66692010-11-29 22:37:40 +00002975def t2TBH : T2I<(outs), (ins GPR:$Rn, GPR:$Rm), IIC_Br,
2976 "tbh", "\t[$Rn, $Rm, lsl #1]", []> {
2977 bits<4> Rn;
2978 bits<4> Rm;
Jim Grosbachf0db2612010-12-17 18:42:56 +00002979 let Inst{31-20} = 0b111010001101;
Jim Grosbach5ca66692010-11-29 22:37:40 +00002980 let Inst{19-16} = Rn;
2981 let Inst{15-5} = 0b11110000000;
2982 let Inst{4} = 1; // H form
2983 let Inst{3-0} = Rm;
Johnny Chen93042d12010-03-02 18:14:57 +00002984}
Evan Cheng5657c012009-07-29 02:18:14 +00002985} // isNotDuplicable, isIndirectBranch
2986
David Goodwinc9a59b52009-06-30 19:50:22 +00002987} // isBranch, isTerminator, isBarrier
David Goodwin5e47a9a2009-06-30 18:04:13 +00002988
2989// FIXME: should be able to write a pattern for ARMBrcond, but can't use
2990// a two-value operand where a dag node expects two operands. :(
2991let isBranch = 1, isTerminator = 1 in
David Goodwin8b7d7ad2009-08-06 16:52:47 +00002992def t2Bcc : T2I<(outs), (ins brtarget:$target), IIC_Br,
Evan Cheng699beba2009-10-27 00:08:59 +00002993 "b", ".w\t$target",
Johnny Chend68e1192009-12-15 17:24:14 +00002994 [/*(ARMbrcond bb:$target, imm:$cc)*/]> {
2995 let Inst{31-27} = 0b11110;
2996 let Inst{15-14} = 0b10;
2997 let Inst{12} = 0;
Jim Grosbach00f25fa2010-12-14 20:46:39 +00002998
Owen Andersonfb20d892010-12-09 00:27:41 +00002999 bits<4> p;
3000 let Inst{25-22} = p;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003001
Owen Andersonfb20d892010-12-09 00:27:41 +00003002 bits<21> target;
3003 let Inst{26} = target{20};
3004 let Inst{11} = target{19};
3005 let Inst{13} = target{18};
3006 let Inst{21-16} = target{17-12};
3007 let Inst{10-0} = target{11-1};
Owen Anderson8d7d2e12011-08-09 20:55:18 +00003008
3009 let DecoderMethod = "DecodeThumb2BCCInstruction";
Johnny Chend68e1192009-12-15 17:24:14 +00003010}
Evan Chengf49810c2009-06-23 17:48:47 +00003011
Jim Grosbachaf7f2d62011-07-08 20:32:21 +00003012// Tail calls. The Darwin version of thumb tail calls uses a t2 branch, so
3013// it goes here.
3014let isCall = 1, isTerminator = 1, isReturn = 1, isBarrier = 1 in {
3015 // Darwin version.
3016 let Defs = [R0, R1, R2, R3, R9, R12, QQQQ0, QQQQ2, QQQQ3, PC],
3017 Uses = [SP] in
3018 def tTAILJMPd: tPseudoExpand<(outs), (ins uncondbrtarget:$dst, variable_ops),
Owen Anderson16884412011-07-13 23:22:26 +00003019 4, IIC_Br, [],
Jim Grosbachaf7f2d62011-07-08 20:32:21 +00003020 (t2B uncondbrtarget:$dst)>,
3021 Requires<[IsThumb2, IsDarwin]>;
3022}
Evan Cheng06e16582009-07-10 01:54:42 +00003023
3024// IT block
Evan Cheng86050dc2010-06-18 23:09:54 +00003025let Defs = [ITSTATE] in
Evan Cheng06e16582009-07-10 01:54:42 +00003026def t2IT : Thumb2XI<(outs), (ins it_pred:$cc, it_mask:$mask),
Owen Anderson16884412011-07-13 23:22:26 +00003027 AddrModeNone, 2, IIC_iALUx,
Johnny Chend68e1192009-12-15 17:24:14 +00003028 "it$mask\t$cc", "", []> {
3029 // 16-bit instruction.
Johnny Chenbbc71b22009-12-16 02:32:54 +00003030 let Inst{31-16} = 0x0000;
Johnny Chend68e1192009-12-15 17:24:14 +00003031 let Inst{15-8} = 0b10111111;
Owen Anderson05bf5952010-11-29 18:54:38 +00003032
3033 bits<4> cc;
3034 bits<4> mask;
Jim Grosbach86386922010-12-08 22:10:43 +00003035 let Inst{7-4} = cc;
3036 let Inst{3-0} = mask;
Johnny Chend68e1192009-12-15 17:24:14 +00003037}
Evan Cheng06e16582009-07-10 01:54:42 +00003038
Johnny Chence6275f2010-02-25 19:05:29 +00003039// Branch and Exchange Jazelle -- for disassembly only
3040// Rm = Inst{19-16}
Jim Grosbach6ccfc502010-07-30 02:41:01 +00003041def t2BXJ : T2I<(outs), (ins rGPR:$func), NoItinerary, "bxj", "\t$func",
Johnny Chence6275f2010-02-25 19:05:29 +00003042 [/* For disassembly only; pattern left blank */]> {
3043 let Inst{31-27} = 0b11110;
3044 let Inst{26} = 0;
3045 let Inst{25-20} = 0b111100;
3046 let Inst{15-14} = 0b10;
3047 let Inst{12} = 0;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003048
Owen Anderson05bf5952010-11-29 18:54:38 +00003049 bits<4> func;
Jim Grosbach86386922010-12-08 22:10:43 +00003050 let Inst{19-16} = func;
Johnny Chence6275f2010-02-25 19:05:29 +00003051}
3052
Jim Grosbach11cca7a2011-08-18 17:51:36 +00003053// Compare and branch on zero / non-zero
3054let isBranch = 1, isTerminator = 1 in {
3055 def tCBZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3056 "cbz\t$Rn, $target", []>,
3057 T1Misc<{0,0,?,1,?,?,?}>,
3058 Requires<[IsThumb2]> {
3059 // A8.6.27
3060 bits<6> target;
3061 bits<3> Rn;
3062 let Inst{9} = target{5};
3063 let Inst{7-3} = target{4-0};
3064 let Inst{2-0} = Rn;
3065 }
3066
3067 def tCBNZ : T1I<(outs), (ins tGPR:$Rn, t_cbtarget:$target), IIC_Br,
3068 "cbnz\t$Rn, $target", []>,
3069 T1Misc<{1,0,?,1,?,?,?}>,
3070 Requires<[IsThumb2]> {
3071 // A8.6.27
3072 bits<6> target;
3073 bits<3> Rn;
3074 let Inst{9} = target{5};
3075 let Inst{7-3} = target{4-0};
3076 let Inst{2-0} = Rn;
3077 }
3078}
3079
3080
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003081// Change Processor State is a system instruction -- for disassembly and
3082// parsing only.
3083// FIXME: Since the asm parser has currently no clean way to handle optional
3084// operands, create 3 versions of the same instruction. Once there's a clean
3085// framework to represent optional operands, change this behavior.
3086class t2CPS<dag iops, string asm_op> : T2XI<(outs), iops, NoItinerary,
3087 !strconcat("cps", asm_op),
3088 [/* For disassembly only; pattern left blank */]> {
3089 bits<2> imod;
3090 bits<3> iflags;
3091 bits<5> mode;
3092 bit M;
3093
Johnny Chen93042d12010-03-02 18:14:57 +00003094 let Inst{31-27} = 0b11110;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003095 let Inst{26} = 0;
Johnny Chen93042d12010-03-02 18:14:57 +00003096 let Inst{25-20} = 0b111010;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003097 let Inst{19-16} = 0b1111;
Johnny Chen93042d12010-03-02 18:14:57 +00003098 let Inst{15-14} = 0b10;
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003099 let Inst{12} = 0;
3100 let Inst{10-9} = imod;
3101 let Inst{8} = M;
3102 let Inst{7-5} = iflags;
3103 let Inst{4-0} = mode;
Owen Anderson6153a032011-08-23 17:45:18 +00003104 let DecoderMethod = "DecodeT2CPSInstruction";
Johnny Chen93042d12010-03-02 18:14:57 +00003105}
3106
Bruno Cardoso Lopesa2b6e412011-02-14 13:09:44 +00003107let M = 1 in
3108 def t2CPS3p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags, i32imm:$mode),
3109 "$imod.w\t$iflags, $mode">;
3110let mode = 0, M = 0 in
3111 def t2CPS2p : t2CPS<(ins imod_op:$imod, iflags_op:$iflags),
3112 "$imod.w\t$iflags">;
3113let imod = 0, iflags = 0, M = 1 in
3114 def t2CPS1p : t2CPS<(ins i32imm:$mode), "\t$mode">;
3115
Johnny Chen0f7866e2010-03-03 02:09:43 +00003116// A6.3.4 Branches and miscellaneous control
3117// Table A6-14 Change Processor State, and hint instructions
3118// Helper class for disassembly only.
3119class T2I_hint<bits<8> op7_0, string opc, string asm>
3120 : T2I<(outs), (ins), NoItinerary, opc, asm,
3121 [/* For disassembly only; pattern left blank */]> {
3122 let Inst{31-20} = 0xf3a;
Bruno Cardoso Lopes1b10d5b2011-01-26 13:28:14 +00003123 let Inst{19-16} = 0b1111;
Johnny Chen0f7866e2010-03-03 02:09:43 +00003124 let Inst{15-14} = 0b10;
3125 let Inst{12} = 0;
3126 let Inst{10-8} = 0b000;
3127 let Inst{7-0} = op7_0;
3128}
3129
3130def t2NOP : T2I_hint<0b00000000, "nop", ".w">;
3131def t2YIELD : T2I_hint<0b00000001, "yield", ".w">;
3132def t2WFE : T2I_hint<0b00000010, "wfe", ".w">;
3133def t2WFI : T2I_hint<0b00000011, "wfi", ".w">;
3134def t2SEV : T2I_hint<0b00000100, "sev", ".w">;
3135
Jim Grosbach6f9f8842011-07-13 22:59:38 +00003136def t2DBG : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "dbg", "\t$opt", []> {
Johnny Chen0f7866e2010-03-03 02:09:43 +00003137 let Inst{31-20} = 0xf3a;
3138 let Inst{15-14} = 0b10;
3139 let Inst{12} = 0;
3140 let Inst{10-8} = 0b000;
3141 let Inst{7-4} = 0b1111;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003142
Owen Andersonc7373f82010-11-30 20:00:01 +00003143 bits<4> opt;
Jim Grosbach86386922010-12-08 22:10:43 +00003144 let Inst{3-0} = opt;
Johnny Chen0f7866e2010-03-03 02:09:43 +00003145}
3146
Johnny Chen6341c5a2010-02-25 20:25:24 +00003147// Secure Monitor Call is a system instruction -- for disassembly only
3148// Option = Inst{19-16}
Jim Grosbach7c9fbc02011-07-22 18:13:31 +00003149def t2SMC : T2I<(outs), (ins imm0_15:$opt), NoItinerary, "smc", "\t$opt",
Johnny Chen6341c5a2010-02-25 20:25:24 +00003150 [/* For disassembly only; pattern left blank */]> {
3151 let Inst{31-27} = 0b11110;
3152 let Inst{26-20} = 0b1111111;
3153 let Inst{15-12} = 0b1000;
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003154
Owen Andersond18a9c92010-11-29 19:22:08 +00003155 bits<4> opt;
Jim Grosbach86386922010-12-08 22:10:43 +00003156 let Inst{19-16} = opt;
Owen Andersond18a9c92010-11-29 19:22:08 +00003157}
3158
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003159class T2SRS<bits<12> op31_20,
Owen Anderson5404c2b2010-11-29 20:38:48 +00003160 dag oops, dag iops, InstrItinClass itin,
Owen Andersond18a9c92010-11-29 19:22:08 +00003161 string opc, string asm, list<dag> pattern>
3162 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5404c2b2010-11-29 20:38:48 +00003163 let Inst{31-20} = op31_20{11-0};
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003164
Owen Andersond18a9c92010-11-29 19:22:08 +00003165 bits<5> mode;
3166 let Inst{4-0} = mode{4-0};
Johnny Chen6341c5a2010-02-25 20:25:24 +00003167}
3168
3169// Store Return State is a system instruction -- for disassembly only
Owen Anderson5404c2b2010-11-29 20:38:48 +00003170def t2SRSDBW : T2SRS<0b111010000010,
Owen Andersond18a9c92010-11-29 19:22:08 +00003171 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp!, $mode",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003172 [/* For disassembly only; pattern left blank */]>;
3173def t2SRSDB : T2SRS<0b111010000000,
Owen Andersond18a9c92010-11-29 19:22:08 +00003174 (outs),(ins i32imm:$mode),NoItinerary,"srsdb","\tsp, $mode",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003175 [/* For disassembly only; pattern left blank */]>;
3176def t2SRSIAW : T2SRS<0b111010011010,
Owen Andersond18a9c92010-11-29 19:22:08 +00003177 (outs),(ins i32imm:$mode),NoItinerary,"srsia","\tsp!, $mode",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003178 [/* For disassembly only; pattern left blank */]>;
3179def t2SRSIA : T2SRS<0b111010011000,
Owen Andersond18a9c92010-11-29 19:22:08 +00003180 (outs), (ins i32imm:$mode),NoItinerary,"srsia","\tsp, $mode",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003181 [/* For disassembly only; pattern left blank */]>;
Johnny Chen6341c5a2010-02-25 20:25:24 +00003182
3183// Return From Exception is a system instruction -- for disassembly only
Owen Andersond18a9c92010-11-29 19:22:08 +00003184
Owen Anderson5404c2b2010-11-29 20:38:48 +00003185class T2RFE<bits<12> op31_20, dag oops, dag iops, InstrItinClass itin,
Owen Andersond18a9c92010-11-29 19:22:08 +00003186 string opc, string asm, list<dag> pattern>
3187 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5404c2b2010-11-29 20:38:48 +00003188 let Inst{31-20} = op31_20{11-0};
Jim Grosbach7721e7f2010-12-02 23:05:38 +00003189
Owen Andersond18a9c92010-11-29 19:22:08 +00003190 bits<4> Rn;
Jim Grosbach86386922010-12-08 22:10:43 +00003191 let Inst{19-16} = Rn;
Johnny Chenec51a622011-04-12 21:41:51 +00003192 let Inst{15-0} = 0xc000;
Owen Andersond18a9c92010-11-29 19:22:08 +00003193}
3194
Owen Anderson5404c2b2010-11-29 20:38:48 +00003195def t2RFEDBW : T2RFE<0b111010000011,
Johnny Chenec51a622011-04-12 21:41:51 +00003196 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn!",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003197 [/* For disassembly only; pattern left blank */]>;
3198def t2RFEDB : T2RFE<0b111010000001,
Johnny Chenec51a622011-04-12 21:41:51 +00003199 (outs), (ins GPR:$Rn), NoItinerary, "rfedb", "\t$Rn",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003200 [/* For disassembly only; pattern left blank */]>;
3201def t2RFEIAW : T2RFE<0b111010011011,
Johnny Chenec51a622011-04-12 21:41:51 +00003202 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn!",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003203 [/* For disassembly only; pattern left blank */]>;
3204def t2RFEIA : T2RFE<0b111010011001,
Johnny Chenec51a622011-04-12 21:41:51 +00003205 (outs), (ins GPR:$Rn), NoItinerary, "rfeia", "\t$Rn",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003206 [/* For disassembly only; pattern left blank */]>;
Johnny Chen6341c5a2010-02-25 20:25:24 +00003207
Evan Chengf49810c2009-06-23 17:48:47 +00003208//===----------------------------------------------------------------------===//
3209// Non-Instruction Patterns
3210//
3211
Evan Cheng5adb66a2009-09-28 09:14:39 +00003212// 32-bit immediate using movw + movt.
Evan Cheng5be39222010-09-24 22:03:46 +00003213// This is a single pseudo instruction to make it re-materializable.
3214// FIXME: Remove this when we can do generalized remat.
Evan Chengfc8475b2011-01-19 02:16:49 +00003215let isReMaterializable = 1, isMoveImm = 1 in
Jim Grosbach3c38f962010-10-06 22:01:26 +00003216def t2MOVi32imm : PseudoInst<(outs rGPR:$dst), (ins i32imm:$src), IIC_iMOVix2,
Jim Grosbach99594eb2010-11-18 01:38:26 +00003217 [(set rGPR:$dst, (i32 imm:$src))]>,
Jim Grosbach3c38f962010-10-06 22:01:26 +00003218 Requires<[IsThumb, HasV6T2]>;
Evan Chengb9803a82009-11-06 23:52:48 +00003219
Evan Cheng53519f02011-01-21 18:55:51 +00003220// Pseudo instruction that combines movw + movt + add pc (if pic).
Evan Cheng9fe20092011-01-20 08:34:58 +00003221// It also makes it possible to rematerialize the instructions.
3222// FIXME: Remove this when we can do generalized remat and when machine licm
3223// can properly the instructions.
Evan Cheng53519f02011-01-21 18:55:51 +00003224let isReMaterializable = 1 in {
3225def t2MOV_ga_pcrel : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3226 IIC_iMOVix2addpc,
Evan Cheng9fe20092011-01-20 08:34:58 +00003227 [(set rGPR:$dst, (ARMWrapperPIC tglobaladdr:$addr))]>,
3228 Requires<[IsThumb2, UseMovt]>;
Evan Cheng5de5d4b2011-01-17 08:03:18 +00003229
Evan Cheng53519f02011-01-21 18:55:51 +00003230def t2MOV_ga_dyn : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr),
3231 IIC_iMOVix2,
3232 [(set rGPR:$dst, (ARMWrapperDYN tglobaladdr:$addr))]>,
3233 Requires<[IsThumb2, UseMovt]>;
3234}
3235
Anton Korobeynikov5cdc3a92009-11-24 00:44:37 +00003236// ConstantPool, GlobalAddress, and JumpTable
3237def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2LEApcrel tglobaladdr :$dst)>,
3238 Requires<[IsThumb2, DontUseMovt]>;
3239def : T2Pat<(ARMWrapper tconstpool :$dst), (t2LEApcrel tconstpool :$dst)>;
3240def : T2Pat<(ARMWrapper tglobaladdr :$dst), (t2MOVi32imm tglobaladdr :$dst)>,
3241 Requires<[IsThumb2, UseMovt]>;
3242
3243def : T2Pat<(ARMWrapperJT tjumptable:$dst, imm:$id),
3244 (t2LEApcrelJT tjumptable:$dst, imm:$id)>;
3245
Evan Chengb9803a82009-11-06 23:52:48 +00003246// Pseudo instruction that combines ldr from constpool and add pc. This should
3247// be expanded into two instructions late to allow if-conversion and
3248// scheduling.
Dan Gohmanbc9d98b2010-02-27 23:47:46 +00003249let canFoldAsLoad = 1, isReMaterializable = 1 in
Evan Cheng9fe20092011-01-20 08:34:58 +00003250def t2LDRpci_pic : PseudoInst<(outs rGPR:$dst), (ins i32imm:$addr, pclabel:$cp),
Jim Grosbach99594eb2010-11-18 01:38:26 +00003251 IIC_iLoadiALU,
Evan Cheng9fe20092011-01-20 08:34:58 +00003252 [(set rGPR:$dst, (ARMpic_add (load (ARMWrapper tconstpool:$addr)),
Evan Chengb9803a82009-11-06 23:52:48 +00003253 imm:$cp))]>,
3254 Requires<[IsThumb2]>;
Johnny Chen23336552010-02-25 18:46:43 +00003255
3256//===----------------------------------------------------------------------===//
3257// Move between special register and ARM core register -- for disassembly only
3258//
3259
Owen Anderson5404c2b2010-11-29 20:38:48 +00003260class T2SpecialReg<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3261 dag oops, dag iops, InstrItinClass itin,
Owen Anderson00a035f2010-11-29 19:29:15 +00003262 string opc, string asm, list<dag> pattern>
3263 : T2I<oops, iops, itin, opc, asm, pattern> {
Owen Anderson5404c2b2010-11-29 20:38:48 +00003264 let Inst{31-20} = op31_20{11-0};
3265 let Inst{15-14} = op15_14{1-0};
3266 let Inst{12} = op12{0};
3267}
3268
3269class T2MRS<bits<12> op31_20, bits<2> op15_14, bits<1> op12,
3270 dag oops, dag iops, InstrItinClass itin,
3271 string opc, string asm, list<dag> pattern>
3272 : T2SpecialReg<op31_20, op15_14, op12, oops, iops, itin, opc, asm, pattern> {
Owen Anderson00a035f2010-11-29 19:29:15 +00003273 bits<4> Rd;
Jim Grosbach86386922010-12-08 22:10:43 +00003274 let Inst{11-8} = Rd;
Bruno Cardoso Lopese7255a82011-01-18 21:31:35 +00003275 let Inst{19-16} = 0b1111;
Owen Anderson00a035f2010-11-29 19:29:15 +00003276}
3277
Owen Anderson5404c2b2010-11-29 20:38:48 +00003278def t2MRS : T2MRS<0b111100111110, 0b10, 0,
3279 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, cpsr",
3280 [/* For disassembly only; pattern left blank */]>;
3281def t2MRSsys : T2MRS<0b111100111111, 0b10, 0,
Owen Anderson00a035f2010-11-29 19:29:15 +00003282 (outs rGPR:$Rd), (ins), NoItinerary, "mrs", "\t$Rd, spsr",
Owen Anderson5404c2b2010-11-29 20:38:48 +00003283 [/* For disassembly only; pattern left blank */]>;
Johnny Chen23336552010-02-25 18:46:43 +00003284
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003285// Move from ARM core register to Special Register
3286//
3287// No need to have both system and application versions, the encodings are the
3288// same and the assembly parser has no way to distinguish between them. The mask
3289// operand contains the special register (R Bit) in bit 4 and bits 3-0 contains
3290// the mask with the fields to be accessed in the special register.
3291def t2MSR : T2SpecialReg<0b111100111000 /* op31-20 */, 0b10 /* op15-14 */,
3292 0 /* op12 */, (outs), (ins msr_mask:$mask, rGPR:$Rn),
3293 NoItinerary, "msr", "\t$mask, $Rn",
3294 [/* For disassembly only; pattern left blank */]> {
3295 bits<5> mask;
Owen Anderson00a035f2010-11-29 19:29:15 +00003296 bits<4> Rn;
Jim Grosbach86386922010-12-08 22:10:43 +00003297 let Inst{19-16} = Rn;
Bruno Cardoso Lopes584bf7b2011-02-18 19:45:59 +00003298 let Inst{20} = mask{4}; // R Bit
3299 let Inst{13} = 0b0;
3300 let Inst{11-8} = mask{3-0};
Owen Anderson00a035f2010-11-29 19:29:15 +00003301}
3302
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003303//===----------------------------------------------------------------------===//
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003304// Move between coprocessor and ARM core register
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003305//
3306
Jim Grosbache35c5e02011-07-13 21:35:10 +00003307class t2MovRCopro<bits<4> Op, string opc, bit direction, dag oops, dag iops,
3308 list<dag> pattern>
3309 : T2Cop<Op, oops, iops,
Jim Grosbach0d8dae22011-07-13 21:17:59 +00003310 !strconcat(opc, "\t$cop, $opc1, $Rt, $CRn, $CRm, $opc2"),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003311 pattern> {
3312 let Inst{27-24} = 0b1110;
3313 let Inst{20} = direction;
3314 let Inst{4} = 1;
3315
3316 bits<4> Rt;
3317 bits<4> cop;
3318 bits<3> opc1;
3319 bits<3> opc2;
3320 bits<4> CRm;
3321 bits<4> CRn;
3322
3323 let Inst{15-12} = Rt;
3324 let Inst{11-8} = cop;
3325 let Inst{23-21} = opc1;
3326 let Inst{7-5} = opc2;
3327 let Inst{3-0} = CRm;
3328 let Inst{19-16} = CRn;
3329}
3330
Jim Grosbache35c5e02011-07-13 21:35:10 +00003331class t2MovRRCopro<bits<4> Op, string opc, bit direction,
3332 list<dag> pattern = []>
3333 : T2Cop<Op, (outs),
Jim Grosbachc8ae39e2011-07-14 21:26:42 +00003334 (ins p_imm:$cop, imm0_15:$opc1, GPR:$Rt, GPR:$Rt2, c_imm:$CRm),
Jim Grosbache35c5e02011-07-13 21:35:10 +00003335 !strconcat(opc, "\t$cop, $opc1, $Rt, $Rt2, $CRm"), pattern> {
3336 let Inst{27-24} = 0b1100;
3337 let Inst{23-21} = 0b010;
3338 let Inst{20} = direction;
3339
3340 bits<4> Rt;
3341 bits<4> Rt2;
3342 bits<4> cop;
3343 bits<4> opc1;
3344 bits<4> CRm;
3345
3346 let Inst{15-12} = Rt;
3347 let Inst{19-16} = Rt2;
3348 let Inst{11-8} = cop;
3349 let Inst{7-4} = opc1;
3350 let Inst{3-0} = CRm;
3351}
3352
3353/* from ARM core register to coprocessor */
3354def t2MCR : t2MovRCopro<0b1110, "mcr", 0,
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003355 (outs),
Jim Grosbache540c742011-07-14 21:19:17 +00003356 (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3357 c_imm:$CRm, imm0_7:$opc2),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003358 [(int_arm_mcr imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3359 imm:$CRm, imm:$opc2)]>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003360def t2MCR2 : t2MovRCopro<0b1111, "mcr2", 0,
Jim Grosbache540c742011-07-14 21:19:17 +00003361 (outs), (ins p_imm:$cop, imm0_7:$opc1, GPR:$Rt, c_imm:$CRn,
3362 c_imm:$CRm, imm0_7:$opc2),
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003363 [(int_arm_mcr2 imm:$cop, imm:$opc1, GPR:$Rt, imm:$CRn,
3364 imm:$CRm, imm:$opc2)]>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003365
3366/* from coprocessor to ARM core register */
3367def t2MRC : t2MovRCopro<0b1110, "mrc", 1,
Jim Grosbachccfd9312011-07-19 20:35:35 +00003368 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3369 c_imm:$CRm, imm0_7:$opc2), []>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003370
3371def t2MRC2 : t2MovRCopro<0b1111, "mrc2", 1,
Jim Grosbachccfd9312011-07-19 20:35:35 +00003372 (outs GPR:$Rt), (ins p_imm:$cop, imm0_7:$opc1, c_imm:$CRn,
3373 c_imm:$CRm, imm0_7:$opc2), []>;
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003374
Jim Grosbache35c5e02011-07-13 21:35:10 +00003375def : T2v6Pat<(int_arm_mrc imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
3376 (t2MRC imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3377
3378def : T2v6Pat<(int_arm_mrc2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2),
Bruno Cardoso Lopes54ad87a2011-05-03 17:29:22 +00003379 (t2MRC2 imm:$cop, imm:$opc1, imm:$CRn, imm:$CRm, imm:$opc2)>;
3380
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003381
Jim Grosbache35c5e02011-07-13 21:35:10 +00003382/* from ARM core register to coprocessor */
3383def t2MCRR : t2MovRRCopro<0b1110, "mcrr", 0,
3384 [(int_arm_mcrr imm:$cop, imm:$opc1, GPR:$Rt, GPR:$Rt2,
3385 imm:$CRm)]>;
3386def t2MCRR2 : t2MovRRCopro<0b1111, "mcrr2", 0,
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003387 [(int_arm_mcrr2 imm:$cop, imm:$opc1, GPR:$Rt,
3388 GPR:$Rt2, imm:$CRm)]>;
Jim Grosbache35c5e02011-07-13 21:35:10 +00003389/* from coprocessor to ARM core register */
3390def t2MRRC : t2MovRRCopro<0b1110, "mrrc", 1>;
3391
3392def t2MRRC2 : t2MovRRCopro<0b1111, "mrrc2", 1>;
Bruno Cardoso Lopes6b3a9992011-01-20 16:58:48 +00003393
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003394//===----------------------------------------------------------------------===//
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003395// Other Coprocessor Instructions.
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003396//
3397
Jim Grosbach1cbb0c12011-07-13 22:06:11 +00003398def tCDP : T2Cop<0b1110, (outs), (ins p_imm:$cop, imm0_15:$opc1,
Jim Grosbach83ab0702011-07-13 22:01:08 +00003399 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
Jim Grosbach9bb098a2011-07-13 21:14:23 +00003400 "cdp\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
3401 [(int_arm_cdp imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3402 imm:$CRm, imm:$opc2)]> {
3403 let Inst{27-24} = 0b1110;
3404
3405 bits<4> opc1;
3406 bits<4> CRn;
3407 bits<4> CRd;
3408 bits<4> cop;
3409 bits<3> opc2;
3410 bits<4> CRm;
3411
3412 let Inst{3-0} = CRm;
3413 let Inst{4} = 0;
3414 let Inst{7-5} = opc2;
3415 let Inst{11-8} = cop;
3416 let Inst{15-12} = CRd;
3417 let Inst{19-16} = CRn;
3418 let Inst{23-20} = opc1;
3419}
3420
Jim Grosbach1cbb0c12011-07-13 22:06:11 +00003421def t2CDP2 : T2Cop<0b1111, (outs), (ins p_imm:$cop, imm0_15:$opc1,
Jim Grosbach83ab0702011-07-13 22:01:08 +00003422 c_imm:$CRd, c_imm:$CRn, c_imm:$CRm, imm0_7:$opc2),
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003423 "cdp2\t$cop, $opc1, $CRd, $CRn, $CRm, $opc2",
Bruno Cardoso Lopes0a69ba32011-05-03 17:29:29 +00003424 [(int_arm_cdp2 imm:$cop, imm:$opc1, imm:$CRd, imm:$CRn,
3425 imm:$CRm, imm:$opc2)]> {
Bruno Cardoso Lopes8dd37f72011-01-20 18:32:09 +00003426 let Inst{27-24} = 0b1110;
3427
3428 bits<4> opc1;
3429 bits<4> CRn;
3430 bits<4> CRd;
3431 bits<4> cop;
3432 bits<3> opc2;
3433 bits<4> CRm;
3434
3435 let Inst{3-0} = CRm;
3436 let Inst{4} = 0;
3437 let Inst{7-5} = opc2;
3438 let Inst{11-8} = cop;
3439 let Inst{15-12} = CRd;
3440 let Inst{19-16} = CRn;
3441 let Inst{23-20} = opc1;
3442}
Jim Grosbachc5a8c862011-07-27 16:47:19 +00003443
3444
3445
3446//===----------------------------------------------------------------------===//
3447// Non-Instruction Patterns
3448//
3449
3450// SXT/UXT with no rotate
Jim Grosbach70327412011-07-27 17:48:13 +00003451let AddedComplexity = 16 in {
3452def : T2Pat<(and rGPR:$Rm, 0x000000FF), (t2UXTB rGPR:$Rm, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003453 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003454def : T2Pat<(and rGPR:$Rm, 0x0000FFFF), (t2UXTH rGPR:$Rm, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003455 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003456def : T2Pat<(and rGPR:$Rm, 0x00FF00FF), (t2UXTB16 rGPR:$Rm, 0)>,
3457 Requires<[HasT2ExtractPack, IsThumb2]>;
3458def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0x00FF)),
3459 (t2UXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3460 Requires<[HasT2ExtractPack, IsThumb2]>;
3461def : T2Pat<(add rGPR:$Rn, (and rGPR:$Rm, 0xFFFF)),
3462 (t2UXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3463 Requires<[HasT2ExtractPack, IsThumb2]>;
3464}
Jim Grosbachc5a8c862011-07-27 16:47:19 +00003465
Jim Grosbach70327412011-07-27 17:48:13 +00003466def : T2Pat<(sext_inreg rGPR:$Src, i8), (t2SXTB rGPR:$Src, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003467 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003468def : T2Pat<(sext_inreg rGPR:$Src, i16), (t2SXTH rGPR:$Src, 0)>,
Eli Friedman2cb1dfa2011-08-08 19:49:37 +00003469 Requires<[IsThumb2]>;
Jim Grosbach70327412011-07-27 17:48:13 +00003470def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i8)),
3471 (t2SXTAB rGPR:$Rn, rGPR:$Rm, 0)>,
3472 Requires<[HasT2ExtractPack, IsThumb2]>;
3473def : T2Pat<(add rGPR:$Rn, (sext_inreg rGPR:$Rm, i16)),
3474 (t2SXTAH rGPR:$Rn, rGPR:$Rm, 0)>,
3475 Requires<[HasT2ExtractPack, IsThumb2]>;