blob: ff776fbe231569e84930b35fb97c28381ac650c6 [file] [log] [blame]
Scott Michel66377522007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
Scott Michelf0569be2008-12-27 04:51:36 +00002//
Scott Michel66377522007-12-04 22:35:58 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Scott Michelf0569be2008-12-27 04:51:36 +00007//
Scott Michel66377522007-12-04 22:35:58 +00008//===----------------------------------------------------------------------===//
9// Cell SPU Instructions:
10//===----------------------------------------------------------------------===//
11
12//===----------------------------------------------------------------------===//
13// TODO Items (not urgent today, but would be nice, low priority)
14//
15// ANDBI, ORBI: SPU constructs a 4-byte constant for these instructions by
16// concatenating the byte argument b as "bbbb". Could recognize this bit pattern
17// in 16-bit and 32-bit constants and reduce instruction count.
18//===----------------------------------------------------------------------===//
19
20//===----------------------------------------------------------------------===//
21// Pseudo instructions:
22//===----------------------------------------------------------------------===//
23
24let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
Scott Michel203b2d62008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel66377522007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
Chris Lattnere563bbc2008-10-11 22:08:30 +000027 [(callseq_start timm:$amt)]>;
Scott Michel203b2d62008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel66377522007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
Chris Lattnere563bbc2008-10-11 22:08:30 +000030 [(callseq_end timm:$amt)]>;
Scott Michel66377522007-12-04 22:35:58 +000031}
32
33//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +000034// Loads:
35// NB: The ordering is actually important, since the instruction selection
36// will try each of the instructions in sequence, i.e., the D-form first with
37// the 10-bit displacement, then the A-form with the 16 bit displacement, and
38// finally the X-form with the register-register.
39//===----------------------------------------------------------------------===//
40
Dan Gohman15511cf2008-12-03 18:15:48 +000041let canFoldAsLoad = 1 in {
Scott Michel053c1da2008-01-29 02:16:57 +000042 class LoadDFormVec<ValueType vectype>
Scott Michelf0569be2008-12-27 04:51:36 +000043 : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +000044 "lqd\t$rT, $src",
45 LoadStore,
46 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
47 { }
Scott Michel66377522007-12-04 22:35:58 +000048
Scott Michel053c1da2008-01-29 02:16:57 +000049 class LoadDForm<RegisterClass rclass>
Scott Michelf0569be2008-12-27 04:51:36 +000050 : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +000051 "lqd\t$rT, $src",
52 LoadStore,
53 [(set rclass:$rT, (load dform_addr:$src))]>
54 { }
Scott Michel66377522007-12-04 22:35:58 +000055
Scott Michel053c1da2008-01-29 02:16:57 +000056 multiclass LoadDForms
57 {
58 def v16i8: LoadDFormVec<v16i8>;
59 def v8i16: LoadDFormVec<v8i16>;
60 def v4i32: LoadDFormVec<v4i32>;
61 def v2i64: LoadDFormVec<v2i64>;
62 def v4f32: LoadDFormVec<v4f32>;
63 def v2f64: LoadDFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +000064
Scott Michel21213e72009-01-06 23:10:38 +000065 def v2i32: LoadDFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +000066 def v2f32: LoadDFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +000067
Scott Michel053c1da2008-01-29 02:16:57 +000068 def r128: LoadDForm<GPRC>;
69 def r64: LoadDForm<R64C>;
70 def r32: LoadDForm<R32C>;
71 def f32: LoadDForm<R32FP>;
72 def f64: LoadDForm<R64FP>;
73 def r16: LoadDForm<R16C>;
74 def r8: LoadDForm<R8C>;
75 }
Scott Michel66377522007-12-04 22:35:58 +000076
Scott Michel053c1da2008-01-29 02:16:57 +000077 class LoadAFormVec<ValueType vectype>
78 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
79 "lqa\t$rT, $src",
80 LoadStore,
81 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
82 { }
Scott Michel66377522007-12-04 22:35:58 +000083
Scott Michel053c1da2008-01-29 02:16:57 +000084 class LoadAForm<RegisterClass rclass>
85 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
86 "lqa\t$rT, $src",
87 LoadStore,
88 [(set rclass:$rT, (load aform_addr:$src))]>
89 { }
Scott Michel66377522007-12-04 22:35:58 +000090
Scott Michel053c1da2008-01-29 02:16:57 +000091 multiclass LoadAForms
92 {
93 def v16i8: LoadAFormVec<v16i8>;
94 def v8i16: LoadAFormVec<v8i16>;
95 def v4i32: LoadAFormVec<v4i32>;
96 def v2i64: LoadAFormVec<v2i64>;
97 def v4f32: LoadAFormVec<v4f32>;
98 def v2f64: LoadAFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +000099
Scott Michel21213e72009-01-06 23:10:38 +0000100 def v2i32: LoadAFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +0000101 def v2f32: LoadAFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +0000102
Scott Michel053c1da2008-01-29 02:16:57 +0000103 def r128: LoadAForm<GPRC>;
104 def r64: LoadAForm<R64C>;
105 def r32: LoadAForm<R32C>;
106 def f32: LoadAForm<R32FP>;
107 def f64: LoadAForm<R64FP>;
108 def r16: LoadAForm<R16C>;
109 def r8: LoadAForm<R8C>;
110 }
Scott Michel66377522007-12-04 22:35:58 +0000111
Scott Michel053c1da2008-01-29 02:16:57 +0000112 class LoadXFormVec<ValueType vectype>
113 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
114 "lqx\t$rT, $src",
115 LoadStore,
116 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
117 { }
Scott Michel66377522007-12-04 22:35:58 +0000118
Scott Michel053c1da2008-01-29 02:16:57 +0000119 class LoadXForm<RegisterClass rclass>
120 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
121 "lqx\t$rT, $src",
122 LoadStore,
123 [(set rclass:$rT, (load xform_addr:$src))]>
124 { }
Scott Michel66377522007-12-04 22:35:58 +0000125
Scott Michel053c1da2008-01-29 02:16:57 +0000126 multiclass LoadXForms
127 {
128 def v16i8: LoadXFormVec<v16i8>;
129 def v8i16: LoadXFormVec<v8i16>;
130 def v4i32: LoadXFormVec<v4i32>;
131 def v2i64: LoadXFormVec<v2i64>;
132 def v4f32: LoadXFormVec<v4f32>;
133 def v2f64: LoadXFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000134
Scott Michel21213e72009-01-06 23:10:38 +0000135 def v2i32: LoadXFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +0000136 def v2f32: LoadXFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +0000137
Scott Michel053c1da2008-01-29 02:16:57 +0000138 def r128: LoadXForm<GPRC>;
139 def r64: LoadXForm<R64C>;
140 def r32: LoadXForm<R32C>;
141 def f32: LoadXForm<R32FP>;
142 def f64: LoadXForm<R64FP>;
143 def r16: LoadXForm<R16C>;
144 def r8: LoadXForm<R8C>;
145 }
Scott Michel66377522007-12-04 22:35:58 +0000146
Scott Michel053c1da2008-01-29 02:16:57 +0000147 defm LQA : LoadAForms;
148 defm LQD : LoadDForms;
149 defm LQX : LoadXForms;
Scott Michel504c3692007-12-17 22:32:34 +0000150
Scott Michel66377522007-12-04 22:35:58 +0000151/* Load quadword, PC relative: Not much use at this point in time.
Scott Michel053c1da2008-01-29 02:16:57 +0000152 Might be of use later for relocatable code. It's effectively the
153 same as LQA, but uses PC-relative addressing.
Scott Michel66377522007-12-04 22:35:58 +0000154 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
155 "lqr\t$rT, $disp", LoadStore,
156 [(set VECREG:$rT, (load iaddr:$disp))]>;
157 */
Scott Michel66377522007-12-04 22:35:58 +0000158}
159
160//===----------------------------------------------------------------------===//
161// Stores:
162//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +0000163class StoreDFormVec<ValueType vectype>
Scott Michelf0569be2008-12-27 04:51:36 +0000164 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000165 "stqd\t$rT, $src",
166 LoadStore,
167 [(store (vectype VECREG:$rT), dform_addr:$src)]>
168{ }
Scott Michel66377522007-12-04 22:35:58 +0000169
Scott Michel053c1da2008-01-29 02:16:57 +0000170class StoreDForm<RegisterClass rclass>
Scott Michelf0569be2008-12-27 04:51:36 +0000171 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000172 "stqd\t$rT, $src",
173 LoadStore,
174 [(store rclass:$rT, dform_addr:$src)]>
175{ }
Scott Michel66377522007-12-04 22:35:58 +0000176
Scott Michel053c1da2008-01-29 02:16:57 +0000177multiclass StoreDForms
178{
179 def v16i8: StoreDFormVec<v16i8>;
180 def v8i16: StoreDFormVec<v8i16>;
181 def v4i32: StoreDFormVec<v4i32>;
182 def v2i64: StoreDFormVec<v2i64>;
183 def v4f32: StoreDFormVec<v4f32>;
184 def v2f64: StoreDFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000185
Scott Michel21213e72009-01-06 23:10:38 +0000186 def v2i32: StoreDFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +0000187 def v2f32: StoreDFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +0000188
Scott Michel053c1da2008-01-29 02:16:57 +0000189 def r128: StoreDForm<GPRC>;
190 def r64: StoreDForm<R64C>;
191 def r32: StoreDForm<R32C>;
192 def f32: StoreDForm<R32FP>;
193 def f64: StoreDForm<R64FP>;
194 def r16: StoreDForm<R16C>;
195 def r8: StoreDForm<R8C>;
196}
Scott Michel66377522007-12-04 22:35:58 +0000197
Scott Michel053c1da2008-01-29 02:16:57 +0000198class StoreAFormVec<ValueType vectype>
199 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000200 "stqa\t$rT, $src",
201 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000202 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000203
Scott Michel053c1da2008-01-29 02:16:57 +0000204class StoreAForm<RegisterClass rclass>
205 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000206 "stqa\t$rT, $src",
207 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000208 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000209
Scott Michel053c1da2008-01-29 02:16:57 +0000210multiclass StoreAForms
211{
212 def v16i8: StoreAFormVec<v16i8>;
213 def v8i16: StoreAFormVec<v8i16>;
214 def v4i32: StoreAFormVec<v4i32>;
215 def v2i64: StoreAFormVec<v2i64>;
216 def v4f32: StoreAFormVec<v4f32>;
217 def v2f64: StoreAFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000218
Scott Michel21213e72009-01-06 23:10:38 +0000219 def v2i32: StoreAFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +0000220 def v2f32: StoreAFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +0000221
Scott Michel053c1da2008-01-29 02:16:57 +0000222 def r128: StoreAForm<GPRC>;
223 def r64: StoreAForm<R64C>;
224 def r32: StoreAForm<R32C>;
225 def f32: StoreAForm<R32FP>;
226 def f64: StoreAForm<R64FP>;
227 def r16: StoreAForm<R16C>;
228 def r8: StoreAForm<R8C>;
229}
Scott Michel66377522007-12-04 22:35:58 +0000230
Scott Michel053c1da2008-01-29 02:16:57 +0000231class StoreXFormVec<ValueType vectype>
232 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000233 "stqx\t$rT, $src",
234 LoadStore,
235 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000236{ }
Scott Michel66377522007-12-04 22:35:58 +0000237
Scott Michel053c1da2008-01-29 02:16:57 +0000238class StoreXForm<RegisterClass rclass>
239 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000240 "stqx\t$rT, $src",
241 LoadStore,
242 [(store rclass:$rT, xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000243{ }
Scott Michel66377522007-12-04 22:35:58 +0000244
Scott Michel053c1da2008-01-29 02:16:57 +0000245multiclass StoreXForms
246{
247 def v16i8: StoreXFormVec<v16i8>;
248 def v8i16: StoreXFormVec<v8i16>;
249 def v4i32: StoreXFormVec<v4i32>;
250 def v2i64: StoreXFormVec<v2i64>;
251 def v4f32: StoreXFormVec<v4f32>;
252 def v2f64: StoreXFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000253
Scott Michel21213e72009-01-06 23:10:38 +0000254 def v2i32: StoreXFormVec<v2i32>;
Kalle Raiskilabc2697c2010-08-04 13:59:48 +0000255 def v2f32: StoreXFormVec<v2f32>;
Scott Michel21213e72009-01-06 23:10:38 +0000256
Scott Michel053c1da2008-01-29 02:16:57 +0000257 def r128: StoreXForm<GPRC>;
258 def r64: StoreXForm<R64C>;
259 def r32: StoreXForm<R32C>;
260 def f32: StoreXForm<R32FP>;
261 def f64: StoreXForm<R64FP>;
262 def r16: StoreXForm<R16C>;
263 def r8: StoreXForm<R8C>;
264}
Scott Michel66377522007-12-04 22:35:58 +0000265
Scott Michel053c1da2008-01-29 02:16:57 +0000266defm STQD : StoreDForms;
267defm STQA : StoreAForms;
268defm STQX : StoreXForms;
Scott Michel66377522007-12-04 22:35:58 +0000269
270/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michel053c1da2008-01-29 02:16:57 +0000271 be useful for relocatable code.
Chris Lattnerc8478d82008-01-06 06:44:58 +0000272def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
273 "stqr\t$rT, $disp", LoadStore,
274 [(store VECREG:$rT, iaddr:$disp)]>;
275*/
Scott Michel66377522007-12-04 22:35:58 +0000276
277//===----------------------------------------------------------------------===//
278// Generate Controls for Insertion:
279//===----------------------------------------------------------------------===//
280
Scott Michelf0569be2008-12-27 04:51:36 +0000281def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000282 "cbd\t$rT, $src", ShuffleOp,
283 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000284
Scott Michel1a6cdb62008-12-01 17:56:02 +0000285def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000286 "cbx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000287 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000288
Scott Michelf0569be2008-12-27 04:51:36 +0000289def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000290 "chd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000291 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000292
Scott Michel1a6cdb62008-12-01 17:56:02 +0000293def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000294 "chx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000295 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000296
Scott Michelf0569be2008-12-27 04:51:36 +0000297def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000298 "cwd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000299 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000300
Scott Michel1a6cdb62008-12-01 17:56:02 +0000301def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000302 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000303 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000304
Scott Michelf0569be2008-12-27 04:51:36 +0000305def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000306 "cwd\t$rT, $src", ShuffleOp,
307 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
308
309def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel203b2d62008-04-30 00:30:08 +0000310 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000311 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000312
Scott Michelf0569be2008-12-27 04:51:36 +0000313def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000314 "cdd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000315 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000316
Scott Michel1a6cdb62008-12-01 17:56:02 +0000317def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000318 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000319 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000320
Scott Michelf0569be2008-12-27 04:51:36 +0000321def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000322 "cdd\t$rT, $src", ShuffleOp,
323 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
324
325def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel203b2d62008-04-30 00:30:08 +0000326 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000327 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000328
Scott Michel66377522007-12-04 22:35:58 +0000329//===----------------------------------------------------------------------===//
330// Constant formation:
331//===----------------------------------------------------------------------===//
332
333def ILHv8i16:
334 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
335 "ilh\t$rT, $val", ImmLoad,
336 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
337
338def ILHr16:
339 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
340 "ilh\t$rT, $val", ImmLoad,
341 [(set R16C:$rT, immSExt16:$val)]>;
342
Scott Michel504c3692007-12-17 22:32:34 +0000343// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
344// the right constant")
345def ILHr8:
346 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
347 "ilh\t$rT, $val", ImmLoad,
348 [(set R8C:$rT, immSExt8:$val)]>;
349
Scott Michel66377522007-12-04 22:35:58 +0000350// IL does sign extension!
Scott Michel66377522007-12-04 22:35:58 +0000351
Scott Michelad2715e2008-03-05 23:02:02 +0000352class ILInst<dag OOL, dag IOL, list<dag> pattern>:
353 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
354 ImmLoad, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000355
Scott Michelad2715e2008-03-05 23:02:02 +0000356class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
357 ILInst<(outs VECREG:$rT), (ins immtype:$val),
358 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000359
Scott Michelad2715e2008-03-05 23:02:02 +0000360class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
361 ILInst<(outs rclass:$rT), (ins immtype:$val),
362 [(set rclass:$rT, xform:$val)]>;
Scott Michel66377522007-12-04 22:35:58 +0000363
Scott Michelad2715e2008-03-05 23:02:02 +0000364multiclass ImmediateLoad
365{
366 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
367 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel66377522007-12-04 22:35:58 +0000368
Scott Michelad2715e2008-03-05 23:02:02 +0000369 // TODO: Need v2f64, v4f32
Scott Michel66377522007-12-04 22:35:58 +0000370
Scott Michelad2715e2008-03-05 23:02:02 +0000371 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
372 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
373 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
374 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
375}
Scott Michel66377522007-12-04 22:35:58 +0000376
Scott Michelad2715e2008-03-05 23:02:02 +0000377defm IL : ImmediateLoad;
Scott Michel66377522007-12-04 22:35:58 +0000378
Scott Michelad2715e2008-03-05 23:02:02 +0000379class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
380 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
381 ImmLoad, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000382
Scott Michelad2715e2008-03-05 23:02:02 +0000383class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
384 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
385 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
386
387class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
388 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
389 [(set rclass:$rT, xform:$val)]>;
390
391multiclass ImmLoadHalfwordUpper
392{
393 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michel203b2d62008-04-30 00:30:08 +0000394 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michelad2715e2008-03-05 23:02:02 +0000395
396 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michel203b2d62008-04-30 00:30:08 +0000397 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michelad2715e2008-03-05 23:02:02 +0000398
399 // Loads the high portion of an address
400 def hi: ILHURegInst<R32C, symbolHi, hi16>;
401
402 // Used in custom lowering constant SFP loads:
403 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
404}
405
406defm ILHU : ImmLoadHalfwordUpper;
Scott Michel66377522007-12-04 22:35:58 +0000407
408// Immediate load address (can also be used to load 18-bit unsigned constants,
409// see the zext 16->32 pattern)
Scott Michelad2715e2008-03-05 23:02:02 +0000410
Scott Michela59d4692008-02-23 18:41:37 +0000411class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
412 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
413 LoadNOP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000414
Scott Michelad2715e2008-03-05 23:02:02 +0000415class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
416 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
417 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
418
419class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
420 ILAInst<(outs rclass:$rT), (ins immtype:$val),
421 [(set rclass:$rT, xform:$val)]>;
422
Scott Michela59d4692008-02-23 18:41:37 +0000423multiclass ImmLoadAddress
424{
Scott Michelad2715e2008-03-05 23:02:02 +0000425 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
426 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel66377522007-12-04 22:35:58 +0000427
Scott Michelad2715e2008-03-05 23:02:02 +0000428 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
429 def r32: ILARegInst<R32C, u18imm, imm18>;
430 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
431 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel66377522007-12-04 22:35:58 +0000432
Scott Michelf0569be2008-12-27 04:51:36 +0000433 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michelad2715e2008-03-05 23:02:02 +0000434 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel66377522007-12-04 22:35:58 +0000435
Scott Michela59d4692008-02-23 18:41:37 +0000436 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
437 [/* no pattern */]>;
438}
439
440defm ILA : ImmLoadAddress;
Scott Michel66377522007-12-04 22:35:58 +0000441
442// Immediate OR, Halfword Lower: The "other" part of loading large constants
443// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
444// Note that these are really two operand instructions, but they're encoded
445// as three operands with the first two arguments tied-to each other.
446
Scott Michelad2715e2008-03-05 23:02:02 +0000447class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
448 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
449 ImmLoad, pattern>,
450 RegConstraint<"$rS = $rT">,
451 NoEncode<"$rS">;
Scott Michel66377522007-12-04 22:35:58 +0000452
Scott Michelad2715e2008-03-05 23:02:02 +0000453class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
454 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
455 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000456
Scott Michelad2715e2008-03-05 23:02:02 +0000457class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
458 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
459 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000460
Scott Michelad2715e2008-03-05 23:02:02 +0000461multiclass ImmOrHalfwordLower
462{
463 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michel203b2d62008-04-30 00:30:08 +0000464 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michelad2715e2008-03-05 23:02:02 +0000465
466 def r32: IOHLRegInst<R32C, i32imm>;
467 def f32: IOHLRegInst<R32FP, f32imm>;
468
469 def lo: IOHLRegInst<R32C, symbolLo>;
470}
471
472defm IOHL: ImmOrHalfwordLower;
Scott Michel9de5d0d2008-01-11 02:53:15 +0000473
Scott Michel66377522007-12-04 22:35:58 +0000474// Form select mask for bytes using immediate, used in conjunction with the
475// SELB instruction:
476
Scott Michelad2715e2008-03-05 23:02:02 +0000477class FSMBIVec<ValueType vectype>:
478 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
479 "fsmbi\t$rT, $val",
480 SelectOp,
Scott Michel8bf61e82008-06-02 22:18:03 +0000481 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000482
Scott Michela59d4692008-02-23 18:41:37 +0000483multiclass FormSelectMaskBytesImm
Scott Michel053c1da2008-01-29 02:16:57 +0000484{
485 def v16i8: FSMBIVec<v16i8>;
486 def v8i16: FSMBIVec<v8i16>;
487 def v4i32: FSMBIVec<v4i32>;
488 def v2i64: FSMBIVec<v2i64>;
489}
Scott Michel66377522007-12-04 22:35:58 +0000490
Scott Michela59d4692008-02-23 18:41:37 +0000491defm FSMBI : FormSelectMaskBytesImm;
492
493// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michelf0569be2008-12-27 04:51:36 +0000494class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
495 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
496 pattern>;
497
498class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
499 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
500 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
501
502class FSMBVecInst<ValueType vectype>:
503 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
504 [(set (vectype VECREG:$rT),
505 (SPUselmask (vectype VECREG:$rA)))]>;
506
507multiclass FormSelectMaskBits {
508 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
509 def v16i8: FSMBVecInst<v16i8>;
510}
511
512defm FSMB: FormSelectMaskBits;
Scott Michela59d4692008-02-23 18:41:37 +0000513
514// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
515// only 8-bits wide (even though it's input as 16-bits here)
Scott Michelf0569be2008-12-27 04:51:36 +0000516
517class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
518 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
519 pattern>;
520
521class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
522 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
523 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
524
525class FSMHVecInst<ValueType vectype>:
526 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
527 [(set (vectype VECREG:$rT),
528 (SPUselmask (vectype VECREG:$rA)))]>;
529
530multiclass FormSelectMaskHalfword {
531 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
532 def v8i16: FSMHVecInst<v8i16>;
533}
534
535defm FSMH: FormSelectMaskHalfword;
Scott Michela59d4692008-02-23 18:41:37 +0000536
537// fsm: Form select mask for words. Like the other fsm* instructions,
538// only the lower 4 bits of $rA are significant.
Scott Michelf0569be2008-12-27 04:51:36 +0000539
540class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
541 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
542 pattern>;
543
544class FSMRegInst<ValueType vectype, RegisterClass rclass>:
545 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
546 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
547
548class FSMVecInst<ValueType vectype>:
549 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
550 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000551
552multiclass FormSelectMaskWord {
Scott Michelf0569be2008-12-27 04:51:36 +0000553 def v4i32: FSMVecInst<v4i32>;
554
555 def r32 : FSMRegInst<v4i32, R32C>;
556 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000557}
558
559defm FSM : FormSelectMaskWord;
560
561// Special case when used for i64 math operations
562multiclass FormSelectMaskWord64 {
Scott Michelf0569be2008-12-27 04:51:36 +0000563 def r32 : FSMRegInst<v2i64, R32C>;
564 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000565}
566
567defm FSM64 : FormSelectMaskWord64;
Scott Michel66377522007-12-04 22:35:58 +0000568
569//===----------------------------------------------------------------------===//
570// Integer and Logical Operations:
571//===----------------------------------------------------------------------===//
572
573def AHv8i16:
574 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
575 "ah\t$rT, $rA, $rB", IntegerOp,
576 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
577
578def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
579 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
580
Scott Michel66377522007-12-04 22:35:58 +0000581def AHr16:
582 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
583 "ah\t$rT, $rA, $rB", IntegerOp,
584 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
585
586def AHIvec:
587 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
588 "ahi\t$rT, $rA, $val", IntegerOp,
589 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
590 v8i16SExt10Imm:$val))]>;
591
Scott Michela59d4692008-02-23 18:41:37 +0000592def AHIr16:
593 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
594 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel02d711b2008-12-30 23:28:25 +0000595 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
596
597// v4i32, i32 add instruction:
Scott Michel66377522007-12-04 22:35:58 +0000598
Scott Michel1df30c42008-12-29 03:23:36 +0000599class AInst<dag OOL, dag IOL, list<dag> pattern>:
600 RRForm<0b00000011000, OOL, IOL,
601 "a\t$rT, $rA, $rB", IntegerOp,
602 pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000603
Scott Michel1df30c42008-12-29 03:23:36 +0000604class AVecInst<ValueType vectype>:
605 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
606 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
607 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000608
Scott Michel1df30c42008-12-29 03:23:36 +0000609class ARegInst<RegisterClass rclass>:
610 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
611 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
612
613multiclass AddInstruction {
614 def v4i32: AVecInst<v4i32>;
615 def v16i8: AVecInst<v16i8>;
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000616 def v2i32: AVecInst<v2i32>;
Scott Michel1df30c42008-12-29 03:23:36 +0000617 def r32: ARegInst<R32C>;
Scott Michel1df30c42008-12-29 03:23:36 +0000618}
Scott Michel66377522007-12-04 22:35:58 +0000619
Scott Michel1df30c42008-12-29 03:23:36 +0000620defm A : AddInstruction;
Scott Michel504c3692007-12-17 22:32:34 +0000621
Scott Michel02d711b2008-12-30 23:28:25 +0000622class AIInst<dag OOL, dag IOL, list<dag> pattern>:
623 RI10Form<0b00111000, OOL, IOL,
Scott Michel19c10e62009-01-26 03:37:41 +0000624 "ai\t$rT, $rA, $val", IntegerOp,
625 pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000626
Scott Michel02d711b2008-12-30 23:28:25 +0000627class AIVecInst<ValueType vectype, PatLeaf immpred>:
628 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000629 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000630
631class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
632 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000633 [/* no pattern */]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000634
635class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
636 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000637 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000638
639// This is used to add epsilons to floating point numbers in the f32 fdiv code:
640class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
641 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000642 [/* no pattern */]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000643
644multiclass AddImmediate {
645 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
646
647 def r32: AIRegInst<R32C, i32ImmSExt10>;
648
649 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
650 def f32: AIFPInst<R32FP, i32ImmSExt10>;
651}
652
653defm AI : AddImmediate;
Scott Michel66377522007-12-04 22:35:58 +0000654
Scott Michel504c3692007-12-17 22:32:34 +0000655def SFHvec:
656 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
657 "sfh\t$rT, $rA, $rB", IntegerOp,
658 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
659 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000660
Scott Michel504c3692007-12-17 22:32:34 +0000661def SFHr16:
662 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
663 "sfh\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000664 [(set R16C:$rT, (sub R16C:$rB, R16C:$rA))]>;
Scott Michel66377522007-12-04 22:35:58 +0000665
666def SFHIvec:
667 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
668 "sfhi\t$rT, $rA, $val", IntegerOp,
669 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
670 (v8i16 VECREG:$rA)))]>;
671
672def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
673 "sfhi\t$rT, $rA, $val", IntegerOp,
674 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
675
676def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
677 (ins VECREG:$rA, VECREG:$rB),
678 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000679 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rB), (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000680
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000681def SF2vec : RRForm<0b00000010000, (outs VECREG:$rT),
682 (ins VECREG:$rA, VECREG:$rB),
683 "sf\t$rT, $rA, $rB", IntegerOp,
684 [(set (v2i32 VECREG:$rT), (sub (v2i32 VECREG:$rB), (v2i32 VECREG:$rA)))]>;
685
686
Scott Michel66377522007-12-04 22:35:58 +0000687def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
688 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000689 [(set R32C:$rT, (sub R32C:$rB, R32C:$rA))]>;
Scott Michel66377522007-12-04 22:35:58 +0000690
691def SFIvec:
692 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
693 "sfi\t$rT, $rA, $val", IntegerOp,
694 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
695 (v4i32 VECREG:$rA)))]>;
696
697def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
698 (ins R32C:$rA, s10imm_i32:$val),
699 "sfi\t$rT, $rA, $val", IntegerOp,
700 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
701
702// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel8bf61e82008-06-02 22:18:03 +0000703class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
704 RRForm<0b00000010110, OOL, IOL,
705 "addx\t$rT, $rA, $rB",
706 IntegerOp, pattern>;
707
708class ADDXVecInst<ValueType vectype>:
709 ADDXInst<(outs VECREG:$rT),
710 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000711 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000712 RegConstraint<"$rCarry = $rT">,
713 NoEncode<"$rCarry">;
714
Scott Michel8bf61e82008-06-02 22:18:03 +0000715class ADDXRegInst<RegisterClass rclass>:
716 ADDXInst<(outs rclass:$rT),
717 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000718 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000719 RegConstraint<"$rCarry = $rT">,
720 NoEncode<"$rCarry">;
721
Scott Michel8bf61e82008-06-02 22:18:03 +0000722multiclass AddExtended {
723 def v2i64 : ADDXVecInst<v2i64>;
724 def v4i32 : ADDXVecInst<v4i32>;
725 def r64 : ADDXRegInst<R64C>;
726 def r32 : ADDXRegInst<R32C>;
727}
728
729defm ADDX : AddExtended;
730
731// CG: Generate carry for add
732class CGInst<dag OOL, dag IOL, list<dag> pattern>:
733 RRForm<0b01000011000, OOL, IOL,
734 "cg\t$rT, $rA, $rB",
735 IntegerOp, pattern>;
736
737class CGVecInst<ValueType vectype>:
738 CGInst<(outs VECREG:$rT),
739 (ins VECREG:$rA, VECREG:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000740 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000741
742class CGRegInst<RegisterClass rclass>:
743 CGInst<(outs rclass:$rT),
744 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000745 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000746
747multiclass CarryGenerate {
748 def v2i64 : CGVecInst<v2i64>;
749 def v4i32 : CGVecInst<v4i32>;
750 def r64 : CGRegInst<R64C>;
751 def r32 : CGRegInst<R32C>;
752}
753
754defm CG : CarryGenerate;
755
756// SFX: Subract from, extended. This is used in conjunction with BG to subtract
757// with carry (borrow, in this case)
758class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
759 RRForm<0b10000010110, OOL, IOL,
760 "sfx\t$rT, $rA, $rB",
761 IntegerOp, pattern>;
762
763class SFXVecInst<ValueType vectype>:
764 SFXInst<(outs VECREG:$rT),
765 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000766 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000767 RegConstraint<"$rCarry = $rT">,
768 NoEncode<"$rCarry">;
769
Scott Michel8bf61e82008-06-02 22:18:03 +0000770class SFXRegInst<RegisterClass rclass>:
771 SFXInst<(outs rclass:$rT),
772 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000773 [/* no pattern */]>,
Scott Michel8bf61e82008-06-02 22:18:03 +0000774 RegConstraint<"$rCarry = $rT">,
775 NoEncode<"$rCarry">;
776
777multiclass SubtractExtended {
778 def v2i64 : SFXVecInst<v2i64>;
779 def v4i32 : SFXVecInst<v4i32>;
780 def r64 : SFXRegInst<R64C>;
781 def r32 : SFXRegInst<R32C>;
782}
783
784defm SFX : SubtractExtended;
785
Scott Michel66377522007-12-04 22:35:58 +0000786// BG: only available in vector form, doesn't match a pattern.
Scott Michel8bf61e82008-06-02 22:18:03 +0000787class BGInst<dag OOL, dag IOL, list<dag> pattern>:
788 RRForm<0b01000010000, OOL, IOL,
789 "bg\t$rT, $rA, $rB",
790 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000791
Scott Michel8bf61e82008-06-02 22:18:03 +0000792class BGVecInst<ValueType vectype>:
793 BGInst<(outs VECREG:$rT),
794 (ins VECREG:$rA, VECREG:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000795 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000796
797class BGRegInst<RegisterClass rclass>:
798 BGInst<(outs rclass:$rT),
799 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000800 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000801
802multiclass BorrowGenerate {
803 def v4i32 : BGVecInst<v4i32>;
804 def v2i64 : BGVecInst<v2i64>;
805 def r64 : BGRegInst<R64C>;
806 def r32 : BGRegInst<R32C>;
807}
808
809defm BG : BorrowGenerate;
810
811// BGX: Borrow generate, extended.
Scott Michel66377522007-12-04 22:35:58 +0000812def BGXvec:
813 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michelf0569be2008-12-27 04:51:36 +0000814 VECREG:$rCarry),
Scott Michel66377522007-12-04 22:35:58 +0000815 "bgx\t$rT, $rA, $rB", IntegerOp,
816 []>,
817 RegConstraint<"$rCarry = $rT">,
818 NoEncode<"$rCarry">;
819
820// Halfword multiply variants:
821// N.B: These can be used to build up larger quantities (16x16 -> 32)
822
823def MPYv8i16:
824 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
825 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000826 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000827
828def MPYr16:
829 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
830 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
831 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
832
Scott Michel1df30c42008-12-29 03:23:36 +0000833// Unsigned 16-bit multiply:
834
835class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
836 RRForm<0b00110011110, OOL, IOL,
837 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
838 pattern>;
839
Scott Michel66377522007-12-04 22:35:58 +0000840def MPYUv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000841 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000842 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000843
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000844def MPYUv2i32:
845 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
846 [/* no pattern */]>;
847
Scott Michel66377522007-12-04 22:35:58 +0000848def MPYUr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000849 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
850 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000851
852def MPYUr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000853 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000854 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000855
Scott Michel1df30c42008-12-29 03:23:36 +0000856// mpyi: multiply 16 x s10imm -> 32 result.
857
858class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
859 RI10Form<0b00101110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000860 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michel1df30c42008-12-29 03:23:36 +0000861 pattern>;
862
863def MPYIvec:
864 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
865 [(set (v8i16 VECREG:$rT),
866 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000867
868def MPYIr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000869 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
870 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000871
872// mpyui: same issues as other multiplies, plus, this doesn't match a
873// pattern... but may be used during target DAG selection or lowering
Scott Michel1df30c42008-12-29 03:23:36 +0000874
875class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
876 RI10Form<0b10101110, OOL, IOL,
877 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
878 pattern>;
879
Scott Michel66377522007-12-04 22:35:58 +0000880def MPYUIvec:
Scott Michel1df30c42008-12-29 03:23:36 +0000881 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
882 []>;
Scott Michel66377522007-12-04 22:35:58 +0000883
884def MPYUIr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000885 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
886 []>;
Scott Michel66377522007-12-04 22:35:58 +0000887
888// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michel1df30c42008-12-29 03:23:36 +0000889class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
890 RRRForm<0b0011, OOL, IOL,
891 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
892 pattern>;
893
Scott Michel94bd57e2009-01-15 04:41:47 +0000894def MPYAv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000895 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
896 [(set (v4i32 VECREG:$rT),
897 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
898 (v8i16 VECREG:$rB)))),
899 (v4i32 VECREG:$rC)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000900
901def MPYAr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000902 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
903 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
904 R32C:$rC))]>;
905
906def MPYAr32_sext:
907 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
908 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
909 R32C:$rC))]>;
Scott Michel66377522007-12-04 22:35:58 +0000910
911def MPYAr32_sextinreg:
Scott Michel1df30c42008-12-29 03:23:36 +0000912 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
913 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
914 (sext_inreg R32C:$rB, i16)),
915 R32C:$rC))]>;
Scott Michel66377522007-12-04 22:35:58 +0000916
917// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michel1df30c42008-12-29 03:23:36 +0000918class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
919 RRForm<0b10100011110, OOL, IOL,
920 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
921 pattern>;
922
Scott Michel66377522007-12-04 22:35:58 +0000923def MPYHv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000924 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000925 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000926
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000927def MPYHv2i32:
928 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
929 [/* no pattern */]>;
930
Scott Michel66377522007-12-04 22:35:58 +0000931def MPYHr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000932 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000933 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000934
935// mpys: multiply high and shift right (returns the top half of
936// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel66377522007-12-04 22:35:58 +0000937
Scott Michel02d711b2008-12-30 23:28:25 +0000938class MPYSInst<dag OOL, dag IOL>:
939 RRForm<0b11100011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000940 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000941 [/* no pattern */]>;
942
Scott Michel94bd57e2009-01-15 04:41:47 +0000943def MPYSv4i32:
Scott Michel02d711b2008-12-30 23:28:25 +0000944 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
945
946def MPYSr16:
947 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000948
949// mpyhh: multiply high-high (returns the 32-bit result from multiplying
950// the top 16 bits of the $rA, $rB)
Scott Michel02d711b2008-12-30 23:28:25 +0000951
952class MPYHHInst<dag OOL, dag IOL>:
953 RRForm<0b01100011110, OOL, IOL,
954 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
955 [/* no pattern */]>;
956
Scott Michel66377522007-12-04 22:35:58 +0000957def MPYHHv8i16:
Scott Michel02d711b2008-12-30 23:28:25 +0000958 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000959
960def MPYHHr32:
Scott Michel02d711b2008-12-30 23:28:25 +0000961 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000962
963// mpyhha: Multiply high-high, add to $rT:
Scott Michel66377522007-12-04 22:35:58 +0000964
Scott Michel02d711b2008-12-30 23:28:25 +0000965class MPYHHAInst<dag OOL, dag IOL>:
966 RRForm<0b01100010110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000967 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000968 [/* no pattern */]>;
969
970def MPYHHAvec:
971 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
972
973def MPYHHAr32:
974 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000975
Scott Michel94bd57e2009-01-15 04:41:47 +0000976// mpyhhu: Multiply high-high, unsigned, e.g.:
977//
978// +-------+-------+ +-------+-------+ +---------+
979// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
980// +-------+-------+ +-------+-------+ +---------+
981//
982// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel66377522007-12-04 22:35:58 +0000983
Scott Michel02d711b2008-12-30 23:28:25 +0000984class MPYHHUInst<dag OOL, dag IOL>:
985 RRForm<0b01110011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000986 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000987 [/* no pattern */]>;
988
Scott Michel94bd57e2009-01-15 04:41:47 +0000989def MPYHHUv4i32:
Scott Michel02d711b2008-12-30 23:28:25 +0000990 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
991
992def MPYHHUr32:
993 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000994
995// mpyhhau: Multiply high-high, unsigned
Scott Michel02d711b2008-12-30 23:28:25 +0000996
997class MPYHHAUInst<dag OOL, dag IOL>:
998 RRForm<0b01110010110, OOL, IOL,
999 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
1000 [/* no pattern */]>;
1001
Scott Michel66377522007-12-04 22:35:58 +00001002def MPYHHAUvec:
Scott Michel02d711b2008-12-30 23:28:25 +00001003 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
1004
Scott Michel66377522007-12-04 22:35:58 +00001005def MPYHHAUr32:
Scott Michel02d711b2008-12-30 23:28:25 +00001006 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel1df30c42008-12-29 03:23:36 +00001007
1008//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00001009// clz: Count leading zeroes
Scott Michel1df30c42008-12-29 03:23:36 +00001010//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michelf0569be2008-12-27 04:51:36 +00001011class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1012 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1013 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001014
Scott Michelf0569be2008-12-27 04:51:36 +00001015class CLZRegInst<RegisterClass rclass>:
1016 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel02d711b2008-12-30 23:28:25 +00001017 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001018
1019class CLZVecInst<ValueType vectype>:
1020 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1021 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1022
1023multiclass CountLeadingZeroes {
1024 def v4i32 : CLZVecInst<v4i32>;
1025 def r32 : CLZRegInst<R32C>;
1026}
1027
1028defm CLZ : CountLeadingZeroes;
Scott Michel66377522007-12-04 22:35:58 +00001029
1030// cntb: Count ones in bytes (aka "population count")
Scott Michelf0569be2008-12-27 04:51:36 +00001031//
Scott Michel66377522007-12-04 22:35:58 +00001032// NOTE: This instruction is really a vector instruction, but the custom
1033// lowering code uses it in unorthodox ways to support CTPOP for other
1034// data types!
Scott Michelf0569be2008-12-27 04:51:36 +00001035
Scott Michel66377522007-12-04 22:35:58 +00001036def CNTBv16i8:
1037 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1038 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001039 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001040
1041def CNTBv8i16 :
1042 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1043 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001044 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001045
1046def CNTBv4i32 :
1047 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1048 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001049 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001050
Scott Michelf0569be2008-12-27 04:51:36 +00001051// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1052// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1053// slots 1-3.
1054//
1055// Note: This instruction "pairs" with the fsmb instruction for all of the
1056// various types defined here.
1057//
1058// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1059// a vector or register.
1060
1061class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1062 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1063
1064class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1065 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001066 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001067
1068class GBBVecInst<ValueType vectype>:
1069 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001070 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001071
1072multiclass GatherBitsFromBytes {
1073 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1074 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1075 def v16i8: GBBVecInst<v16i8>;
1076}
1077
1078defm GBB: GatherBitsFromBytes;
Scott Michel66377522007-12-04 22:35:58 +00001079
1080// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michelf0569be2008-12-27 04:51:36 +00001081// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1082// and slots 1-3 also set to 0.
1083//
1084// See notes for GBBInst, above.
1085
1086class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1087 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1088 pattern>;
1089
1090class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1091 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001092 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001093
1094class GBHVecInst<ValueType vectype>:
1095 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001096 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001097
1098multiclass GatherBitsHalfword {
1099 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1100 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1101 def v8i16: GBHVecInst<v8i16>;
1102}
1103
1104defm GBH: GatherBitsHalfword;
Scott Michel66377522007-12-04 22:35:58 +00001105
1106// gb: Gather all low order bits from each word in $rA into a single
Scott Michelf0569be2008-12-27 04:51:36 +00001107// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1108// as well as slots 1-3.
1109//
1110// See notes for gbb, above.
1111
1112class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1113 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1114 pattern>;
1115
1116class GBRegInst<RegisterClass rclass, ValueType vectype>:
1117 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001118 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001119
1120class GBVecInst<ValueType vectype>:
1121 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001122 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001123
1124multiclass GatherBitsWord {
1125 def v4i32_r32: GBRegInst<R32C, v4i32>;
1126 def v4i32_r16: GBRegInst<R16C, v4i32>;
1127 def v4i32: GBVecInst<v4i32>;
1128}
1129
1130defm GB: GatherBitsWord;
Scott Michel66377522007-12-04 22:35:58 +00001131
1132// avgb: average bytes
1133def AVGB:
1134 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1135 "avgb\t$rT, $rA, $rB", ByteOp,
1136 []>;
1137
1138// absdb: absolute difference of bytes
1139def ABSDB:
1140 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1141 "absdb\t$rT, $rA, $rB", ByteOp,
1142 []>;
1143
1144// sumb: sum bytes into halfwords
1145def SUMB:
1146 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1147 "sumb\t$rT, $rA, $rB", ByteOp,
1148 []>;
1149
1150// Sign extension operations:
Scott Michel8bf61e82008-06-02 22:18:03 +00001151class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1152 RRForm_1<0b01101101010, OOL, IOL,
1153 "xsbh\t$rDst, $rSrc",
1154 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001155
Scott Micheldd950092009-01-06 03:36:14 +00001156class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel8bf61e82008-06-02 22:18:03 +00001157 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Micheldd950092009-01-06 03:36:14 +00001158 pattern>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001159
1160multiclass ExtendByteHalfword {
Chris Lattnere9eda0f2010-03-19 04:53:47 +00001161 def v16i8: XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1162 [
1163 /*(set (v8i16 VECREG:$rDst), (sext (v8i16 VECREG:$rSrc)))*/]>;
Scott Micheldd950092009-01-06 03:36:14 +00001164 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1165 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1166 def r16: XSBHInRegInst<R16C,
1167 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001168
1169 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1170 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1171 // pattern below). Intentionally doesn't match a pattern because we want the
1172 // sext 8->32 pattern to do the work for us, namely because we need the extra
1173 // XSHWr32.
Scott Micheldd950092009-01-06 03:36:14 +00001174 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1175
1176 // Same as the 32-bit version, but for i64
1177 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001178}
1179
1180defm XSBH : ExtendByteHalfword;
1181
Scott Michel66377522007-12-04 22:35:58 +00001182// Sign extend halfwords to words:
Scott Michel66377522007-12-04 22:35:58 +00001183
Scott Micheldd950092009-01-06 03:36:14 +00001184class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1185 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1186 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001187
Scott Micheldd950092009-01-06 03:36:14 +00001188class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1189 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1190 [(set (out_vectype VECREG:$rDest),
1191 (sext (in_vectype VECREG:$rSrc)))]>;
1192
1193class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1194 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1195 pattern>;
1196
1197class XSHWRegInst<RegisterClass rclass>:
1198 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1199 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1200
1201multiclass ExtendHalfwordWord {
1202 def v4i32: XSHWVecInst<v4i32, v8i16>;
1203
1204 def r16: XSHWRegInst<R32C>;
1205
1206 def r32: XSHWInRegInst<R32C,
1207 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1208 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1209}
1210
1211defm XSHW : ExtendHalfwordWord;
Scott Michel66377522007-12-04 22:35:58 +00001212
Scott Micheled741dd2009-01-05 01:34:35 +00001213// Sign-extend words to doublewords (32->64 bits)
Scott Michel66377522007-12-04 22:35:58 +00001214
Scott Micheled741dd2009-01-05 01:34:35 +00001215class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Micheldd950092009-01-06 03:36:14 +00001216 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1217 IntegerOp, pattern>;
Scott Micheled741dd2009-01-05 01:34:35 +00001218
1219class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1220 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
Chris Lattnere9eda0f2010-03-19 04:53:47 +00001221 [/*(set (out_vectype VECREG:$rDst),
1222 (sext (out_vectype VECREG:$rSrc)))*/]>;
Scott Micheled741dd2009-01-05 01:34:35 +00001223
1224class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1225 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1226 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1227
1228multiclass ExtendWordToDoubleWord {
1229 def v2i64: XSWDVecInst<v4i32, v2i64>;
1230 def r64: XSWDRegInst<R32C, R64C>;
1231
1232 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1233 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1234}
Scott Michel66377522007-12-04 22:35:58 +00001235
Scott Micheled741dd2009-01-05 01:34:35 +00001236defm XSWD : ExtendWordToDoubleWord;
Scott Michel66377522007-12-04 22:35:58 +00001237
1238// AND operations
Scott Michel66377522007-12-04 22:35:58 +00001239
Scott Michela59d4692008-02-23 18:41:37 +00001240class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1241 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1242 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001243
Scott Michela59d4692008-02-23 18:41:37 +00001244class ANDVecInst<ValueType vectype>:
1245 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1246 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1247 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001248
Scott Michelad2715e2008-03-05 23:02:02 +00001249class ANDRegInst<RegisterClass rclass>:
1250 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1251 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1252
Scott Michela59d4692008-02-23 18:41:37 +00001253multiclass BitwiseAnd
1254{
1255 def v16i8: ANDVecInst<v16i8>;
1256 def v8i16: ANDVecInst<v8i16>;
1257 def v4i32: ANDVecInst<v4i32>;
1258 def v2i64: ANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001259
Scott Michelad2715e2008-03-05 23:02:02 +00001260 def r128: ANDRegInst<GPRC>;
1261 def r64: ANDRegInst<R64C>;
1262 def r32: ANDRegInst<R32C>;
1263 def r16: ANDRegInst<R16C>;
1264 def r8: ANDRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001265
Scott Michela59d4692008-02-23 18:41:37 +00001266 //===---------------------------------------------
1267 // Special instructions to perform the fabs instruction
1268 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1269 [/* Intentionally does not match a pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00001270
Scott Michel7ea02ff2009-03-17 01:15:45 +00001271 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001272 [/* Intentionally does not match a pattern */]>;
1273
Scott Michela59d4692008-02-23 18:41:37 +00001274 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1275 [/* Intentionally does not match a pattern */]>;
1276
1277 //===---------------------------------------------
1278
1279 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1280 // quantities -- see 16->32 zext pattern.
1281 //
1282 // This pattern is somewhat artificial, since it might match some
1283 // compiler generated pattern but it is unlikely to do so.
1284
1285 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1286 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1287}
1288
1289defm AND : BitwiseAnd;
Scott Michel66377522007-12-04 22:35:58 +00001290
Chris Lattner918472a2010-03-28 07:48:17 +00001291
1292def vnot_cell_conv : PatFrag<(ops node:$in),
1293 (xor node:$in, (bitconvert (v4i32 immAllOnesV)))>;
1294
1295// N.B.: vnot_cell_conv is one of those special target selection pattern
1296// fragments,
Scott Michel66377522007-12-04 22:35:58 +00001297// in which we expect there to be a bit_convert on the constant. Bear in mind
1298// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1299// constant -1 vector.)
Scott Michel66377522007-12-04 22:35:58 +00001300
Scott Michela59d4692008-02-23 18:41:37 +00001301class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1302 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1303 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001304
Scott Michel7ea02ff2009-03-17 01:15:45 +00001305class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michela59d4692008-02-23 18:41:37 +00001306 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel7ea02ff2009-03-17 01:15:45 +00001307 [(set (vectype VECREG:$rT),
1308 (and (vectype VECREG:$rA),
1309 (vnot_frag (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001310
Scott Michela59d4692008-02-23 18:41:37 +00001311class ANDCRegInst<RegisterClass rclass>:
1312 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1313 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001314
Scott Michela59d4692008-02-23 18:41:37 +00001315multiclass AndComplement
1316{
1317 def v16i8: ANDCVecInst<v16i8>;
1318 def v8i16: ANDCVecInst<v8i16>;
1319 def v4i32: ANDCVecInst<v4i32>;
1320 def v2i64: ANDCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001321
Scott Michela59d4692008-02-23 18:41:37 +00001322 def r128: ANDCRegInst<GPRC>;
1323 def r64: ANDCRegInst<R64C>;
1324 def r32: ANDCRegInst<R32C>;
1325 def r16: ANDCRegInst<R16C>;
1326 def r8: ANDCRegInst<R8C>;
Scott Michel7ea02ff2009-03-17 01:15:45 +00001327
1328 // Sometimes, the xor pattern has a bitcast constant:
Chris Lattner918472a2010-03-28 07:48:17 +00001329 def v16i8_conv: ANDCVecInst<v16i8, vnot_cell_conv>;
Scott Michela59d4692008-02-23 18:41:37 +00001330}
Scott Michel504c3692007-12-17 22:32:34 +00001331
Scott Michela59d4692008-02-23 18:41:37 +00001332defm ANDC : AndComplement;
Scott Michel66377522007-12-04 22:35:58 +00001333
Scott Michela59d4692008-02-23 18:41:37 +00001334class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1335 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michelaedc6372008-12-10 00:15:19 +00001336 ByteOp, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00001337
Scott Michela59d4692008-02-23 18:41:37 +00001338multiclass AndByteImm
1339{
1340 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1341 [(set (v16i8 VECREG:$rT),
1342 (and (v16i8 VECREG:$rA),
1343 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001344
Scott Michela59d4692008-02-23 18:41:37 +00001345 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1346 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1347}
Scott Michel504c3692007-12-17 22:32:34 +00001348
Scott Michela59d4692008-02-23 18:41:37 +00001349defm ANDBI : AndByteImm;
Scott Michel66377522007-12-04 22:35:58 +00001350
Scott Michela59d4692008-02-23 18:41:37 +00001351class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1352 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michelaedc6372008-12-10 00:15:19 +00001353 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001354
Scott Michela59d4692008-02-23 18:41:37 +00001355multiclass AndHalfwordImm
1356{
1357 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1358 [(set (v8i16 VECREG:$rT),
1359 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001360
Scott Michela59d4692008-02-23 18:41:37 +00001361 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1362 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001363
Scott Michela59d4692008-02-23 18:41:37 +00001364 // Zero-extend i8 to i16:
1365 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1366 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1367}
Scott Michel66377522007-12-04 22:35:58 +00001368
Scott Michela59d4692008-02-23 18:41:37 +00001369defm ANDHI : AndHalfwordImm;
1370
1371class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1372 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1373 IntegerOp, pattern>;
1374
1375multiclass AndWordImm
1376{
1377 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1378 [(set (v4i32 VECREG:$rT),
1379 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1380
1381 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1382 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1383
1384 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1385 // pattern below.
1386 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1387 [(set R32C:$rT,
1388 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1389
1390 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1391 // zext 16->32 pattern below.
1392 //
1393 // Note that this pattern is somewhat artificial, since it might match
1394 // something the compiler generates but is unlikely to occur in practice.
1395 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1396 [(set R32C:$rT,
1397 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1398}
1399
1400defm ANDI : AndWordImm;
1401
1402//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00001403// Bitwise OR group:
Scott Michela59d4692008-02-23 18:41:37 +00001404//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1405
Scott Michel66377522007-12-04 22:35:58 +00001406// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michela59d4692008-02-23 18:41:37 +00001407class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1408 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1409 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001410
Scott Michela59d4692008-02-23 18:41:37 +00001411class ORVecInst<ValueType vectype>:
1412 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1413 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1414 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001415
Scott Michela59d4692008-02-23 18:41:37 +00001416class ORRegInst<RegisterClass rclass>:
1417 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1418 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00001419
Scott Michelf0569be2008-12-27 04:51:36 +00001420// ORCvtForm: OR conversion form
1421//
1422// This is used to "convert" the preferred slot to its vector equivalent, as
1423// well as convert a vector back to its preferred slot.
1424//
1425// These are effectively no-ops, but need to exist for proper type conversion
1426// and type coercion.
1427
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001428class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michelf0569be2008-12-27 04:51:36 +00001429 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1430 bits<7> RA;
1431 bits<7> RT;
1432
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001433 let Pattern = pattern;
Scott Michelf0569be2008-12-27 04:51:36 +00001434
1435 let Inst{0-10} = 0b10000010000;
1436 let Inst{11-17} = RA;
1437 let Inst{18-24} = RA;
1438 let Inst{25-31} = RT;
1439}
1440
Scott Michela59d4692008-02-23 18:41:37 +00001441class ORPromoteScalar<RegisterClass rclass>:
Scott Michelf0569be2008-12-27 04:51:36 +00001442 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001443
Scott Michela59d4692008-02-23 18:41:37 +00001444class ORExtractElt<RegisterClass rclass>:
Scott Michelf0569be2008-12-27 04:51:36 +00001445 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1446
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001447/* class ORCvtRegGPRC<RegisterClass rclass>:
1448 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michelf0569be2008-12-27 04:51:36 +00001449
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001450/* class ORCvtGPRCReg<RegisterClass rclass>:
1451 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Micheldd950092009-01-06 03:36:14 +00001452
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001453class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1454 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001455
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001456class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1457 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001458
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001459class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1460 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001461
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001462class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1463 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00001464
Scott Michel6e1d1472009-03-16 18:47:25 +00001465class ORCvtGPRCVec:
1466 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1467
1468class ORCvtVecGPRC:
1469 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001470
Kalle Raiskila99534bb2010-08-09 16:33:00 +00001471class ORCvtVecVec:
1472 ORCvtForm<(outs VECREG:$rT), (ins VECREG:$rA)>;
1473
Scott Michela59d4692008-02-23 18:41:37 +00001474multiclass BitwiseOr
1475{
1476 def v16i8: ORVecInst<v16i8>;
1477 def v8i16: ORVecInst<v8i16>;
1478 def v4i32: ORVecInst<v4i32>;
1479 def v2i64: ORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001480
Scott Michela59d4692008-02-23 18:41:37 +00001481 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1482 [(set (v4f32 VECREG:$rT),
1483 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1484 (v4i32 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001485
Scott Michela59d4692008-02-23 18:41:37 +00001486 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michelf0569be2008-12-27 04:51:36 +00001487 [(set (v2f64 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00001488 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1489 (v2i64 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001490
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001491 def r128: ORRegInst<GPRC>;
1492 def r64: ORRegInst<R64C>;
1493 def r32: ORRegInst<R32C>;
1494 def r16: ORRegInst<R16C>;
1495 def r8: ORRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001496
Scott Michela59d4692008-02-23 18:41:37 +00001497 // OR instructions used to copy f32 and f64 registers.
1498 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1499 [/* no pattern */]>;
Scott Michel504c3692007-12-17 22:32:34 +00001500
Scott Michela59d4692008-02-23 18:41:37 +00001501 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1502 [/* no pattern */]>;
Scott Michel86c041f2007-12-20 00:44:13 +00001503
Scott Michel02d711b2008-12-30 23:28:25 +00001504 // scalar->vector promotion, prefslot2vec:
Scott Michela59d4692008-02-23 18:41:37 +00001505 def v16i8_i8: ORPromoteScalar<R8C>;
1506 def v8i16_i16: ORPromoteScalar<R16C>;
1507 def v4i32_i32: ORPromoteScalar<R32C>;
1508 def v2i64_i64: ORPromoteScalar<R64C>;
1509 def v4f32_f32: ORPromoteScalar<R32FP>;
1510 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel86c041f2007-12-20 00:44:13 +00001511
Scott Michel02d711b2008-12-30 23:28:25 +00001512 // vector->scalar demotion, vec2prefslot:
Scott Michela59d4692008-02-23 18:41:37 +00001513 def i8_v16i8: ORExtractElt<R8C>;
1514 def i16_v8i16: ORExtractElt<R16C>;
1515 def i32_v4i32: ORExtractElt<R32C>;
1516 def i64_v2i64: ORExtractElt<R64C>;
1517 def f32_v4f32: ORExtractElt<R32FP>;
1518 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00001519
Kalle Raiskila99534bb2010-08-09 16:33:00 +00001520 // half <-> full vector mappings
1521 def v2i32_v4i32: ORCvtVecVec;
1522 def v4i32_v2i32: ORCvtVecVec;
1523 def v2f32_v4f32: ORCvtVecVec;
1524 def v4f32_v2f32: ORCvtVecVec;
1525
1526
Scott Michel6e1d1472009-03-16 18:47:25 +00001527 // Conversion from vector to GPRC
1528 def i128_vec: ORCvtVecGPRC;
1529
1530 // Conversion from GPRC to vector
1531 def vec_i128: ORCvtGPRCVec;
1532
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001533/*
Scott Michel6e1d1472009-03-16 18:47:25 +00001534 // Conversion from register to GPRC
Scott Michelf0569be2008-12-27 04:51:36 +00001535 def i128_r64: ORCvtRegGPRC<R64C>;
1536 def i128_f64: ORCvtRegGPRC<R64FP>;
1537 def i128_r32: ORCvtRegGPRC<R32C>;
1538 def i128_f32: ORCvtRegGPRC<R32FP>;
1539 def i128_r16: ORCvtRegGPRC<R16C>;
1540 def i128_r8: ORCvtRegGPRC<R8C>;
1541
Scott Michel6e1d1472009-03-16 18:47:25 +00001542 // Conversion from GPRC to register
Scott Michelf0569be2008-12-27 04:51:36 +00001543 def r64_i128: ORCvtGPRCReg<R64C>;
1544 def f64_i128: ORCvtGPRCReg<R64FP>;
1545 def r32_i128: ORCvtGPRCReg<R32C>;
1546 def f32_i128: ORCvtGPRCReg<R32FP>;
1547 def r16_i128: ORCvtGPRCReg<R16C>;
1548 def r8_i128: ORCvtGPRCReg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001549*/
1550/*
Scott Micheldd950092009-01-06 03:36:14 +00001551 // Conversion from register to R32C:
Scott Michel6e1d1472009-03-16 18:47:25 +00001552 def r32_r16: ORCvtFormRegR32<R16C>;
1553 def r32_r8: ORCvtFormRegR32<R8C>;
Scott Micheldd950092009-01-06 03:36:14 +00001554
1555 // Conversion from R32C to register
1556 def r32_r16: ORCvtFormR32Reg<R16C>;
1557 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001558*/
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001559
Scott Michel6e1d1472009-03-16 18:47:25 +00001560 // Conversion from R64C to register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001561 def r32_r64: ORCvtFormR64Reg<R32C>;
1562 // def r16_r64: ORCvtFormR64Reg<R16C>;
1563 // def r8_r64: ORCvtFormR64Reg<R8C>;
1564
Scott Michel6e1d1472009-03-16 18:47:25 +00001565 // Conversion to R64C from register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001566 def r64_r32: ORCvtFormRegR64<R32C>;
1567 // def r64_r16: ORCvtFormRegR64<R16C>;
1568 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001569
1570 // bitconvert patterns:
1571 def r32_f32: ORCvtFormR32Reg<R32FP,
1572 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1573 def f32_r32: ORCvtFormRegR32<R32FP,
1574 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1575
1576 def r64_f64: ORCvtFormR64Reg<R64FP,
1577 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1578 def f64_r64: ORCvtFormRegR64<R64FP,
1579 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michela59d4692008-02-23 18:41:37 +00001580}
Scott Michel504c3692007-12-17 22:32:34 +00001581
Scott Michela59d4692008-02-23 18:41:37 +00001582defm OR : BitwiseOr;
1583
Scott Michelf0569be2008-12-27 04:51:36 +00001584// scalar->vector promotion patterns (preferred slot to vector):
1585def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1586 (ORv16i8_i8 R8C:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001587
Scott Michelf0569be2008-12-27 04:51:36 +00001588def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1589 (ORv8i16_i16 R16C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001590
Scott Michelf0569be2008-12-27 04:51:36 +00001591def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1592 (ORv4i32_i32 R32C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001593
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001594def : Pat<(v2i32 (SPUprefslot2vec R32C:$rA)),
1595 (ORv4i32_i32 R32C:$rA)>;
1596
Scott Michelf0569be2008-12-27 04:51:36 +00001597def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1598 (ORv2i64_i64 R64C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001599
Scott Michelf0569be2008-12-27 04:51:36 +00001600def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1601 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001602
Kalle Raiskilae1c91592010-08-02 11:22:10 +00001603def : Pat<(v2f32 (SPUprefslot2vec R32FP:$rA)),
1604 (ORv4f32_f32 R32FP:$rA)>;
1605
Scott Michelf0569be2008-12-27 04:51:36 +00001606def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1607 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001608
Scott Michelf0569be2008-12-27 04:51:36 +00001609// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1610// known as converting the vector back to its preferred slot
Scott Michel504c3692007-12-17 22:32:34 +00001611
Scott Michel104de432008-11-24 17:11:17 +00001612def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001613 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001614
Scott Michel104de432008-11-24 17:11:17 +00001615def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001616 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001617
Scott Michel104de432008-11-24 17:11:17 +00001618def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001619 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001620
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001621def : Pat<(SPUvec2prefslot (v2i32 VECREG:$rA)),
1622 (ORi32_v4i32 VECREG:$rA)>;
1623
Scott Michel104de432008-11-24 17:11:17 +00001624def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001625 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001626
Scott Michel104de432008-11-24 17:11:17 +00001627def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001628 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001629
Kalle Raiskilae1c91592010-08-02 11:22:10 +00001630def : Pat<(SPUvec2prefslot (v2f32 VECREG:$rA)),
1631 (ORf32_v4f32 VECREG:$rA)>;
1632
Scott Michel104de432008-11-24 17:11:17 +00001633def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001634 (ORf64_v2f64 VECREG:$rA)>;
1635
Kalle Raiskila99534bb2010-08-09 16:33:00 +00001636// Conversions between 64 bit and 128 bit vectors.
1637
1638def : Pat<(v4i32 (SPUhalf2vec (v2i32 VECREG:$rA))),
1639 (ORv4i32_v2i32 (v2i32 VECREG:$rA))>;
1640def : Pat<(v4f32 (SPUhalf2vec (v2f32 VECREG:$rA))),
1641 (ORv4f32_v2f32 (v2f32 VECREG:$rA))>;
1642
1643def : Pat<(v2i32 (SPUvec2half (v4i32 VECREG:$rA))),
1644 (ORv2i32_v4i32 VECREG:$rA)>;
1645def : Pat<(v2f32 (SPUvec2half (v4f32 VECREG:$rA))),
1646 (ORv2f32_v4f32 VECREG:$rA)>;
1647
Scott Michelf0569be2008-12-27 04:51:36 +00001648// Load Register: This is an assembler alias for a bitwise OR of a register
1649// against itself. It's here because it brings some clarity to assembly
1650// language output.
1651
1652let hasCtrlDep = 1 in {
1653 class LRInst<dag OOL, dag IOL>
1654 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1655 bits<7> RA;
1656 bits<7> RT;
1657
1658 let Pattern = [/*no pattern*/];
1659
1660 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1661 let Inst{11-17} = RA;
1662 let Inst{18-24} = RA;
1663 let Inst{25-31} = RT;
1664 }
1665
1666 class LRVecInst<ValueType vectype>:
1667 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1668
1669 class LRRegInst<RegisterClass rclass>:
1670 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1671
1672 multiclass LoadRegister {
1673 def v2i64: LRVecInst<v2i64>;
1674 def v2f64: LRVecInst<v2f64>;
1675 def v4i32: LRVecInst<v4i32>;
1676 def v4f32: LRVecInst<v4f32>;
1677 def v8i16: LRVecInst<v8i16>;
1678 def v16i8: LRVecInst<v16i8>;
1679
1680 def r128: LRRegInst<GPRC>;
1681 def r64: LRRegInst<R64C>;
1682 def f64: LRRegInst<R64FP>;
1683 def r32: LRRegInst<R32C>;
1684 def f32: LRRegInst<R32FP>;
1685 def r16: LRRegInst<R16C>;
1686 def r8: LRRegInst<R8C>;
1687 }
1688
1689 defm LR: LoadRegister;
1690}
Scott Michel66377522007-12-04 22:35:58 +00001691
Scott Michela59d4692008-02-23 18:41:37 +00001692// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel66377522007-12-04 22:35:58 +00001693
Scott Michela59d4692008-02-23 18:41:37 +00001694class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1695 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1696 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001697
Scott Michela59d4692008-02-23 18:41:37 +00001698class ORCVecInst<ValueType vectype>:
1699 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1700 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1701 (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001702
Scott Michela59d4692008-02-23 18:41:37 +00001703class ORCRegInst<RegisterClass rclass>:
1704 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1705 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001706
Scott Michela59d4692008-02-23 18:41:37 +00001707multiclass BitwiseOrComplement
1708{
1709 def v16i8: ORCVecInst<v16i8>;
1710 def v8i16: ORCVecInst<v8i16>;
1711 def v4i32: ORCVecInst<v4i32>;
1712 def v2i64: ORCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001713
Scott Michel6e1d1472009-03-16 18:47:25 +00001714 def r128: ORCRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00001715 def r64: ORCRegInst<R64C>;
1716 def r32: ORCRegInst<R32C>;
1717 def r16: ORCRegInst<R16C>;
1718 def r8: ORCRegInst<R8C>;
1719}
1720
1721defm ORC : BitwiseOrComplement;
Scott Michel504c3692007-12-17 22:32:34 +00001722
Scott Michel66377522007-12-04 22:35:58 +00001723// OR byte immediate
Scott Michela59d4692008-02-23 18:41:37 +00001724class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1725 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1726 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001727
Scott Michela59d4692008-02-23 18:41:37 +00001728class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1729 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1730 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1731 (vectype immpred:$val)))]>;
1732
1733multiclass BitwiseOrByteImm
1734{
1735 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1736
1737 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1738 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1739}
1740
1741defm ORBI : BitwiseOrByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001742
Scott Michel66377522007-12-04 22:35:58 +00001743// OR halfword immediate
Scott Michela59d4692008-02-23 18:41:37 +00001744class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1745 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1746 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001747
Scott Michela59d4692008-02-23 18:41:37 +00001748class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1749 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1750 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1751 immpred:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001752
Scott Michela59d4692008-02-23 18:41:37 +00001753multiclass BitwiseOrHalfwordImm
1754{
1755 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1756
1757 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1758 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1759
1760 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1761 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1762 [(set R16C:$rT, (or (anyext R8C:$rA),
1763 i16ImmSExt10:$val))]>;
1764}
1765
1766defm ORHI : BitwiseOrHalfwordImm;
1767
1768class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1769 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1770 IntegerOp, pattern>;
1771
1772class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1773 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1774 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1775 immpred:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001776
1777// Bitwise "or" with immediate
Scott Michela59d4692008-02-23 18:41:37 +00001778multiclass BitwiseOrImm
1779{
1780 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel66377522007-12-04 22:35:58 +00001781
Scott Michela59d4692008-02-23 18:41:37 +00001782 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1783 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001784
Scott Michela59d4692008-02-23 18:41:37 +00001785 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1786 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1787 // infra "anyext 16->32" pattern.)
1788 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1789 [(set R32C:$rT, (or (anyext R16C:$rA),
1790 i32ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001791
Scott Michela59d4692008-02-23 18:41:37 +00001792 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1793 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1794 // infra "anyext 16->32" pattern.)
1795 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1796 [(set R32C:$rT, (or (anyext R8C:$rA),
1797 i32ImmSExt10:$val))]>;
1798}
Scott Michel66377522007-12-04 22:35:58 +00001799
Scott Michela59d4692008-02-23 18:41:37 +00001800defm ORI : BitwiseOrImm;
Scott Michel504c3692007-12-17 22:32:34 +00001801
Scott Michel66377522007-12-04 22:35:58 +00001802// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1803// $rT[0], slots 1-3 are zeroed.
1804//
Scott Michel504c3692007-12-17 22:32:34 +00001805// FIXME: Needs to match an intrinsic pattern.
Scott Michel66377522007-12-04 22:35:58 +00001806def ORXv4i32:
1807 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1808 "orx\t$rT, $rA, $rB", IntegerOp,
1809 []>;
1810
Scott Michel504c3692007-12-17 22:32:34 +00001811// XOR:
Scott Michel66377522007-12-04 22:35:58 +00001812
Scott Michelad2715e2008-03-05 23:02:02 +00001813class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1814 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1815 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001816
Scott Michelad2715e2008-03-05 23:02:02 +00001817class XORVecInst<ValueType vectype>:
1818 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1819 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1820 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001821
Scott Michelad2715e2008-03-05 23:02:02 +00001822class XORRegInst<RegisterClass rclass>:
1823 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1824 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1825
1826multiclass BitwiseExclusiveOr
1827{
1828 def v16i8: XORVecInst<v16i8>;
1829 def v8i16: XORVecInst<v8i16>;
1830 def v4i32: XORVecInst<v4i32>;
1831 def v2i64: XORVecInst<v2i64>;
1832
1833 def r128: XORRegInst<GPRC>;
1834 def r64: XORRegInst<R64C>;
1835 def r32: XORRegInst<R32C>;
1836 def r16: XORRegInst<R16C>;
1837 def r8: XORRegInst<R8C>;
Scott Michela82d3f72009-03-17 16:45:16 +00001838
1839 // XOR instructions used to negate f32 and f64 quantities.
1840
1841 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1842 [/* no pattern */]>;
1843
1844 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1845 [/* no pattern */]>;
1846
1847 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1848 [/* no pattern, see fneg{32,64} */]>;
Scott Michelad2715e2008-03-05 23:02:02 +00001849}
1850
1851defm XOR : BitwiseExclusiveOr;
Scott Michel66377522007-12-04 22:35:58 +00001852
1853//==----------------------------------------------------------
Scott Michel504c3692007-12-17 22:32:34 +00001854
Scott Michela59d4692008-02-23 18:41:37 +00001855class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1856 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1857 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001858
Scott Michela59d4692008-02-23 18:41:37 +00001859multiclass XorByteImm
1860{
1861 def v16i8:
1862 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1863 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1864
1865 def r8:
1866 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1867 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1868}
1869
1870defm XORBI : XorByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001871
Scott Michel66377522007-12-04 22:35:58 +00001872def XORHIv8i16:
Scott Michela59d4692008-02-23 18:41:37 +00001873 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel66377522007-12-04 22:35:58 +00001874 "xorhi\t$rT, $rA, $val", IntegerOp,
1875 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1876 v8i16SExt10Imm:$val))]>;
1877
1878def XORHIr16:
1879 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1880 "xorhi\t$rT, $rA, $val", IntegerOp,
1881 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1882
1883def XORIv4i32:
Scott Michel78c47fa2008-03-10 16:58:52 +00001884 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel66377522007-12-04 22:35:58 +00001885 "xori\t$rT, $rA, $val", IntegerOp,
1886 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1887 v4i32SExt10Imm:$val))]>;
1888
1889def XORIr32:
1890 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1891 "xori\t$rT, $rA, $val", IntegerOp,
1892 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1893
1894// NAND:
Scott Michel66377522007-12-04 22:35:58 +00001895
Scott Michel6e1d1472009-03-16 18:47:25 +00001896class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1897 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1898 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001899
Scott Michel6e1d1472009-03-16 18:47:25 +00001900class NANDVecInst<ValueType vectype>:
1901 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1902 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1903 (vectype VECREG:$rB))))]>;
1904class NANDRegInst<RegisterClass rclass>:
1905 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1906 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001907
Scott Michel6e1d1472009-03-16 18:47:25 +00001908multiclass BitwiseNand
1909{
1910 def v16i8: NANDVecInst<v16i8>;
1911 def v8i16: NANDVecInst<v8i16>;
1912 def v4i32: NANDVecInst<v4i32>;
1913 def v2i64: NANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001914
Scott Michel6e1d1472009-03-16 18:47:25 +00001915 def r128: NANDRegInst<GPRC>;
1916 def r64: NANDRegInst<R64C>;
1917 def r32: NANDRegInst<R32C>;
1918 def r16: NANDRegInst<R16C>;
1919 def r8: NANDRegInst<R8C>;
1920}
Scott Michel66377522007-12-04 22:35:58 +00001921
Scott Michel6e1d1472009-03-16 18:47:25 +00001922defm NAND : BitwiseNand;
Scott Michel504c3692007-12-17 22:32:34 +00001923
Scott Michel66377522007-12-04 22:35:58 +00001924// NOR:
Scott Michel66377522007-12-04 22:35:58 +00001925
Scott Michel6e1d1472009-03-16 18:47:25 +00001926class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1927 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1928 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001929
Scott Michel6e1d1472009-03-16 18:47:25 +00001930class NORVecInst<ValueType vectype>:
1931 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1932 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1933 (vectype VECREG:$rB))))]>;
1934class NORRegInst<RegisterClass rclass>:
1935 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1936 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001937
Scott Michel6e1d1472009-03-16 18:47:25 +00001938multiclass BitwiseNor
1939{
1940 def v16i8: NORVecInst<v16i8>;
1941 def v8i16: NORVecInst<v8i16>;
1942 def v4i32: NORVecInst<v4i32>;
1943 def v2i64: NORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001944
Scott Michel6e1d1472009-03-16 18:47:25 +00001945 def r128: NORRegInst<GPRC>;
1946 def r64: NORRegInst<R64C>;
1947 def r32: NORRegInst<R32C>;
1948 def r16: NORRegInst<R16C>;
1949 def r8: NORRegInst<R8C>;
1950}
Scott Michel66377522007-12-04 22:35:58 +00001951
Scott Michel6e1d1472009-03-16 18:47:25 +00001952defm NOR : BitwiseNor;
Scott Michel504c3692007-12-17 22:32:34 +00001953
Scott Michel66377522007-12-04 22:35:58 +00001954// Select bits:
Scott Michelad2715e2008-03-05 23:02:02 +00001955class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1956 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1957 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001958
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001959class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michelad2715e2008-03-05 23:02:02 +00001960 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1961 [(set (vectype VECREG:$rT),
1962 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001963 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michelad2715e2008-03-05 23:02:02 +00001964 (vectype VECREG:$rA))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001965
Scott Michel02d711b2008-12-30 23:28:25 +00001966class SELBVecVCondInst<ValueType vectype>:
1967 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1968 [(set (vectype VECREG:$rT),
1969 (select (vectype VECREG:$rC),
1970 (vectype VECREG:$rB),
1971 (vectype VECREG:$rA)))]>;
1972
Scott Michelf0569be2008-12-27 04:51:36 +00001973class SELBVecCondInst<ValueType vectype>:
1974 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1975 [(set (vectype VECREG:$rT),
1976 (select R32C:$rC,
1977 (vectype VECREG:$rB),
1978 (vectype VECREG:$rA)))]>;
1979
Scott Michelad2715e2008-03-05 23:02:02 +00001980class SELBRegInst<RegisterClass rclass>:
1981 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1982 [(set rclass:$rT,
Scott Michel1df30c42008-12-29 03:23:36 +00001983 (or (and rclass:$rB, rclass:$rC),
1984 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001985
Scott Michelf0569be2008-12-27 04:51:36 +00001986class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1987 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1988 [(set rclass:$rT,
1989 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1990
Scott Michelad2715e2008-03-05 23:02:02 +00001991multiclass SelectBits
1992{
1993 def v16i8: SELBVecInst<v16i8>;
1994 def v8i16: SELBVecInst<v8i16>;
1995 def v4i32: SELBVecInst<v4i32>;
Chris Lattner918472a2010-03-28 07:48:17 +00001996 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel66377522007-12-04 22:35:58 +00001997
Scott Michelad2715e2008-03-05 23:02:02 +00001998 def r128: SELBRegInst<GPRC>;
1999 def r64: SELBRegInst<R64C>;
2000 def r32: SELBRegInst<R32C>;
2001 def r16: SELBRegInst<R16C>;
2002 def r8: SELBRegInst<R8C>;
Scott Michelf0569be2008-12-27 04:51:36 +00002003
2004 def v16i8_cond: SELBVecCondInst<v16i8>;
2005 def v8i16_cond: SELBVecCondInst<v8i16>;
2006 def v4i32_cond: SELBVecCondInst<v4i32>;
2007 def v2i64_cond: SELBVecCondInst<v2i64>;
2008
Scott Michel02d711b2008-12-30 23:28:25 +00002009 def v16i8_vcond: SELBVecCondInst<v16i8>;
2010 def v8i16_vcond: SELBVecCondInst<v8i16>;
2011 def v4i32_vcond: SELBVecCondInst<v4i32>;
2012 def v2i64_vcond: SELBVecCondInst<v2i64>;
2013
2014 def v4f32_cond:
Scott Michel19c10e62009-01-26 03:37:41 +00002015 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
2016 [(set (v4f32 VECREG:$rT),
2017 (select (v4i32 VECREG:$rC),
2018 (v4f32 VECREG:$rB),
2019 (v4f32 VECREG:$rA)))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00002020
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002021 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michelf0569be2008-12-27 04:51:36 +00002022 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel02d711b2008-12-30 23:28:25 +00002023 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00002024 def r16_cond: SELBRegCondInst<R16C, R16C>;
2025 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michelad2715e2008-03-05 23:02:02 +00002026}
Scott Michel66377522007-12-04 22:35:58 +00002027
Scott Michelad2715e2008-03-05 23:02:02 +00002028defm SELB : SelectBits;
Scott Michel66377522007-12-04 22:35:58 +00002029
Scott Michel7a1c9e92008-11-22 23:50:42 +00002030class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michelad2715e2008-03-05 23:02:02 +00002031 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
2032 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel66377522007-12-04 22:35:58 +00002033
Scott Michel7a1c9e92008-11-22 23:50:42 +00002034def : SPUselbPatVec<v16i8, SELBv16i8>;
2035def : SPUselbPatVec<v8i16, SELBv8i16>;
2036def : SPUselbPatVec<v4i32, SELBv4i32>;
2037def : SPUselbPatVec<v2i64, SELBv2i64>;
2038
2039class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
2040 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
2041 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
2042
2043def : SPUselbPatReg<R8C, SELBr8>;
2044def : SPUselbPatReg<R16C, SELBr16>;
2045def : SPUselbPatReg<R32C, SELBr32>;
2046def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel66377522007-12-04 22:35:58 +00002047
Scott Michelad2715e2008-03-05 23:02:02 +00002048// EQV: Equivalence (1 for each same bit, otherwise 0)
2049//
2050// Note: There are a lot of ways to match this bit operator and these patterns
2051// attempt to be as exhaustive as possible.
Scott Michel66377522007-12-04 22:35:58 +00002052
Scott Michelad2715e2008-03-05 23:02:02 +00002053class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2054 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2055 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002056
Scott Michelad2715e2008-03-05 23:02:02 +00002057class EQVVecInst<ValueType vectype>:
2058 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2059 [(set (vectype VECREG:$rT),
2060 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2061 (and (vnot (vectype VECREG:$rA)),
2062 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002063
Scott Michelad2715e2008-03-05 23:02:02 +00002064class EQVRegInst<RegisterClass rclass>:
2065 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2066 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2067 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002068
Scott Michelad2715e2008-03-05 23:02:02 +00002069class EQVVecPattern1<ValueType vectype>:
2070 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2071 [(set (vectype VECREG:$rT),
2072 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002073
Scott Michelad2715e2008-03-05 23:02:02 +00002074class EQVRegPattern1<RegisterClass rclass>:
2075 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2076 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002077
Scott Michelad2715e2008-03-05 23:02:02 +00002078class EQVVecPattern2<ValueType vectype>:
2079 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2080 [(set (vectype VECREG:$rT),
2081 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2082 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002083
Scott Michelad2715e2008-03-05 23:02:02 +00002084class EQVRegPattern2<RegisterClass rclass>:
2085 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2086 [(set rclass:$rT,
2087 (or (and rclass:$rA, rclass:$rB),
2088 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002089
Scott Michelad2715e2008-03-05 23:02:02 +00002090class EQVVecPattern3<ValueType vectype>:
2091 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2092 [(set (vectype VECREG:$rT),
2093 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002094
Scott Michelad2715e2008-03-05 23:02:02 +00002095class EQVRegPattern3<RegisterClass rclass>:
2096 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2097 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002098
Scott Michelad2715e2008-03-05 23:02:02 +00002099multiclass BitEquivalence
2100{
2101 def v16i8: EQVVecInst<v16i8>;
2102 def v8i16: EQVVecInst<v8i16>;
2103 def v4i32: EQVVecInst<v4i32>;
2104 def v2i64: EQVVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002105
Scott Michelad2715e2008-03-05 23:02:02 +00002106 def v16i8_1: EQVVecPattern1<v16i8>;
2107 def v8i16_1: EQVVecPattern1<v8i16>;
2108 def v4i32_1: EQVVecPattern1<v4i32>;
2109 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002110
Scott Michelad2715e2008-03-05 23:02:02 +00002111 def v16i8_2: EQVVecPattern2<v16i8>;
2112 def v8i16_2: EQVVecPattern2<v8i16>;
2113 def v4i32_2: EQVVecPattern2<v4i32>;
2114 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002115
Scott Michelad2715e2008-03-05 23:02:02 +00002116 def v16i8_3: EQVVecPattern3<v16i8>;
2117 def v8i16_3: EQVVecPattern3<v8i16>;
2118 def v4i32_3: EQVVecPattern3<v4i32>;
2119 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002120
Scott Michelad2715e2008-03-05 23:02:02 +00002121 def r128: EQVRegInst<GPRC>;
2122 def r64: EQVRegInst<R64C>;
2123 def r32: EQVRegInst<R32C>;
2124 def r16: EQVRegInst<R16C>;
2125 def r8: EQVRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002126
Scott Michelad2715e2008-03-05 23:02:02 +00002127 def r128_1: EQVRegPattern1<GPRC>;
2128 def r64_1: EQVRegPattern1<R64C>;
2129 def r32_1: EQVRegPattern1<R32C>;
2130 def r16_1: EQVRegPattern1<R16C>;
2131 def r8_1: EQVRegPattern1<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002132
Scott Michelad2715e2008-03-05 23:02:02 +00002133 def r128_2: EQVRegPattern2<GPRC>;
2134 def r64_2: EQVRegPattern2<R64C>;
2135 def r32_2: EQVRegPattern2<R32C>;
2136 def r16_2: EQVRegPattern2<R16C>;
2137 def r8_2: EQVRegPattern2<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002138
Scott Michelad2715e2008-03-05 23:02:02 +00002139 def r128_3: EQVRegPattern3<GPRC>;
2140 def r64_3: EQVRegPattern3<R64C>;
2141 def r32_3: EQVRegPattern3<R32C>;
2142 def r16_3: EQVRegPattern3<R16C>;
2143 def r8_3: EQVRegPattern3<R8C>;
2144}
Scott Michel504c3692007-12-17 22:32:34 +00002145
Scott Michelad2715e2008-03-05 23:02:02 +00002146defm EQV: BitEquivalence;
Scott Michel66377522007-12-04 22:35:58 +00002147
2148//===----------------------------------------------------------------------===//
2149// Vector shuffle...
2150//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002151// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2152// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2153// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2154// the SPUISD::SHUFB opcode.
Scott Michela59d4692008-02-23 18:41:37 +00002155//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002156
Scott Michela59d4692008-02-23 18:41:37 +00002157class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2158 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2159 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002160
Scott Michel1a6cdb62008-12-01 17:56:02 +00002161class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michela59d4692008-02-23 18:41:37 +00002162 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel1a6cdb62008-12-01 17:56:02 +00002163 [(set (resultvec VECREG:$rT),
2164 (SPUshuffle (resultvec VECREG:$rA),
2165 (resultvec VECREG:$rB),
2166 (maskvec VECREG:$rC)))]>;
Scott Michel86c041f2007-12-20 00:44:13 +00002167
Scott Michelf0569be2008-12-27 04:51:36 +00002168class SHUFBGPRCInst:
2169 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2170 [/* no pattern */]>;
2171
Scott Michela59d4692008-02-23 18:41:37 +00002172multiclass ShuffleBytes
2173{
Scott Michel1a6cdb62008-12-01 17:56:02 +00002174 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2175 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2176 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2177 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2178 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2179 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
Kalle Raiskila82fe4672010-08-02 08:54:39 +00002180 def v2i32 : SHUFBVecInst<v2i32, v16i8>;
2181 def v2i32_m32 : SHUFBVecInst<v2i32, v4i32>;
Scott Michel1a6cdb62008-12-01 17:56:02 +00002182 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2183 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel66377522007-12-04 22:35:58 +00002184
Scott Michel1a6cdb62008-12-01 17:56:02 +00002185 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2186 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
Kalle Raiskilae1c91592010-08-02 11:22:10 +00002187 def v2f32 : SHUFBVecInst<v2f32, v16i8>;
2188 def v2f32_m32 : SHUFBVecInst<v2f32, v4i32>;
Scott Michel1a6cdb62008-12-01 17:56:02 +00002189
2190 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2191 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michelf0569be2008-12-27 04:51:36 +00002192
2193 def gprc : SHUFBGPRCInst;
Scott Michela59d4692008-02-23 18:41:37 +00002194}
2195
2196defm SHUFB : ShuffleBytes;
2197
Scott Michel66377522007-12-04 22:35:58 +00002198//===----------------------------------------------------------------------===//
2199// Shift and rotate group:
2200//===----------------------------------------------------------------------===//
2201
Scott Michela59d4692008-02-23 18:41:37 +00002202class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2203 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2204 RotateShift, pattern>;
2205
2206class SHLHVecInst<ValueType vectype>:
2207 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2208 [(set (vectype VECREG:$rT),
2209 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002210
Scott Michela59d4692008-02-23 18:41:37 +00002211multiclass ShiftLeftHalfword
2212{
2213 def v8i16: SHLHVecInst<v8i16>;
2214 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2215 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2216 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2217 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2218}
Scott Michel66377522007-12-04 22:35:58 +00002219
Scott Michela59d4692008-02-23 18:41:37 +00002220defm SHLH : ShiftLeftHalfword;
Scott Michel66377522007-12-04 22:35:58 +00002221
Scott Michela59d4692008-02-23 18:41:37 +00002222//===----------------------------------------------------------------------===//
Scott Michel504c3692007-12-17 22:32:34 +00002223
Scott Michela59d4692008-02-23 18:41:37 +00002224class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2225 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2226 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002227
Scott Michela59d4692008-02-23 18:41:37 +00002228class SHLHIVecInst<ValueType vectype>:
2229 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2230 [(set (vectype VECREG:$rT),
2231 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002232
Scott Michela59d4692008-02-23 18:41:37 +00002233multiclass ShiftLeftHalfwordImm
2234{
2235 def v8i16: SHLHIVecInst<v8i16>;
2236 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2237 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2238}
2239
2240defm SHLHI : ShiftLeftHalfwordImm;
2241
2242def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002243 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michela59d4692008-02-23 18:41:37 +00002244
2245def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002246 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002247
Scott Michela59d4692008-02-23 18:41:37 +00002248//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002249
Scott Michela59d4692008-02-23 18:41:37 +00002250class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2251 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2252 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002253
Scott Michela59d4692008-02-23 18:41:37 +00002254multiclass ShiftLeftWord
2255{
2256 def v4i32:
2257 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2258 [(set (v4i32 VECREG:$rT),
2259 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2260 def r32:
2261 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2262 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2263}
Scott Michel66377522007-12-04 22:35:58 +00002264
Scott Michela59d4692008-02-23 18:41:37 +00002265defm SHL: ShiftLeftWord;
Scott Michel504c3692007-12-17 22:32:34 +00002266
Scott Michela59d4692008-02-23 18:41:37 +00002267//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002268
Scott Michela59d4692008-02-23 18:41:37 +00002269class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2270 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2271 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002272
Scott Michela59d4692008-02-23 18:41:37 +00002273multiclass ShiftLeftWordImm
2274{
2275 def v4i32:
2276 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2277 [(set (v4i32 VECREG:$rT),
2278 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002279
Scott Michela59d4692008-02-23 18:41:37 +00002280 def r32:
2281 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2282 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2283}
Scott Michel66377522007-12-04 22:35:58 +00002284
Scott Michela59d4692008-02-23 18:41:37 +00002285defm SHLI : ShiftLeftWordImm;
Scott Michel504c3692007-12-17 22:32:34 +00002286
Scott Michela59d4692008-02-23 18:41:37 +00002287//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002288// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2289// register) to the left. Vector form is here to ensure type correctness.
Scott Michela59d4692008-02-23 18:41:37 +00002290//
2291// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2292// of 7 bits is actually possible.
2293//
2294// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2295// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2296// bytes with SHLQBY.
Scott Michel66377522007-12-04 22:35:58 +00002297
Scott Michela59d4692008-02-23 18:41:37 +00002298class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2299 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2300 RotateShift, pattern>;
2301
2302class SHLQBIVecInst<ValueType vectype>:
2303 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2304 [(set (vectype VECREG:$rT),
2305 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2306
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002307class SHLQBIRegInst<RegisterClass rclass>:
2308 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2309 [/* no pattern */]>;
2310
Scott Michela59d4692008-02-23 18:41:37 +00002311multiclass ShiftLeftQuadByBits
2312{
2313 def v16i8: SHLQBIVecInst<v16i8>;
2314 def v8i16: SHLQBIVecInst<v8i16>;
2315 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002316 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002317 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002318 def v2f64: SHLQBIVecInst<v2f64>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002319
2320 def r128: SHLQBIRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00002321}
2322
2323defm SHLQBI : ShiftLeftQuadByBits;
2324
2325// See note above on SHLQBI. In this case, the predicate actually does then
2326// enforcement, whereas with SHLQBI, we have to "take it on faith."
2327class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2328 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2329 RotateShift, pattern>;
2330
2331class SHLQBIIVecInst<ValueType vectype>:
2332 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2333 [(set (vectype VECREG:$rT),
2334 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2335
2336multiclass ShiftLeftQuadByBitsImm
2337{
2338 def v16i8 : SHLQBIIVecInst<v16i8>;
2339 def v8i16 : SHLQBIIVecInst<v8i16>;
2340 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002341 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002342 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002343 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002344}
2345
2346defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel66377522007-12-04 22:35:58 +00002347
2348// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michela59d4692008-02-23 18:41:37 +00002349// not by bits. See notes above on SHLQBI.
Scott Michel66377522007-12-04 22:35:58 +00002350
Scott Michela59d4692008-02-23 18:41:37 +00002351class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel662165d2008-11-25 00:23:16 +00002352 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00002353 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002354
Scott Michela59d4692008-02-23 18:41:37 +00002355class SHLQBYVecInst<ValueType vectype>:
2356 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2357 [(set (vectype VECREG:$rT),
2358 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002359
Scott Michela59d4692008-02-23 18:41:37 +00002360multiclass ShiftLeftQuadBytes
2361{
2362 def v16i8: SHLQBYVecInst<v16i8>;
2363 def v8i16: SHLQBYVecInst<v8i16>;
2364 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002365 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002366 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002367 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002368 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2369 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2370}
Scott Michel66377522007-12-04 22:35:58 +00002371
Scott Michela59d4692008-02-23 18:41:37 +00002372defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel66377522007-12-04 22:35:58 +00002373
Scott Michela59d4692008-02-23 18:41:37 +00002374class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2375 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2376 RotateShift, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00002377
Scott Michela59d4692008-02-23 18:41:37 +00002378class SHLQBYIVecInst<ValueType vectype>:
2379 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2380 [(set (vectype VECREG:$rT),
2381 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002382
Scott Michela59d4692008-02-23 18:41:37 +00002383multiclass ShiftLeftQuadBytesImm
2384{
2385 def v16i8: SHLQBYIVecInst<v16i8>;
2386 def v8i16: SHLQBYIVecInst<v8i16>;
2387 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002388 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002389 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002390 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002391 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2392 [(set GPRC:$rT,
2393 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2394}
Scott Michel504c3692007-12-17 22:32:34 +00002395
Scott Michela59d4692008-02-23 18:41:37 +00002396defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel504c3692007-12-17 22:32:34 +00002397
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002398class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2399 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2400 RotateShift, pattern>;
2401
2402class SHLQBYBIVecInst<ValueType vectype>:
2403 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2404 [/* no pattern */]>;
2405
2406class SHLQBYBIRegInst<RegisterClass rclass>:
2407 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2408 [/* no pattern */]>;
2409
2410multiclass ShiftLeftQuadBytesBitCount
2411{
2412 def v16i8: SHLQBYBIVecInst<v16i8>;
2413 def v8i16: SHLQBYBIVecInst<v8i16>;
2414 def v4i32: SHLQBYBIVecInst<v4i32>;
2415 def v4f32: SHLQBYBIVecInst<v4f32>;
2416 def v2i64: SHLQBYBIVecInst<v2i64>;
2417 def v2f64: SHLQBYBIVecInst<v2f64>;
2418
2419 def r128: SHLQBYBIRegInst<GPRC>;
2420}
2421
2422defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2423
Scott Michela59d4692008-02-23 18:41:37 +00002424//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2425// Rotate halfword:
2426//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2427class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2428 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2429 RotateShift, pattern>;
2430
2431class ROTHVecInst<ValueType vectype>:
2432 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2433 [(set (vectype VECREG:$rT),
Chris Lattnerdd6fbd12010-03-08 18:59:49 +00002434 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michela59d4692008-02-23 18:41:37 +00002435
2436class ROTHRegInst<RegisterClass rclass>:
2437 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2438 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2439
2440multiclass RotateLeftHalfword
2441{
2442 def v8i16: ROTHVecInst<v8i16>;
2443 def r16: ROTHRegInst<R16C>;
2444}
2445
2446defm ROTH: RotateLeftHalfword;
2447
2448def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2449 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2450
2451//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2452// Rotate halfword, immediate:
2453//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2454class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2455 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2456 RotateShift, pattern>;
2457
2458class ROTHIVecInst<ValueType vectype>:
2459 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2460 [(set (vectype VECREG:$rT),
2461 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2462
2463multiclass RotateLeftHalfwordImm
2464{
2465 def v8i16: ROTHIVecInst<v8i16>;
2466 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2467 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2468 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2469 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2470}
2471
2472defm ROTHI: RotateLeftHalfwordImm;
2473
Chris Lattner420c69d2010-03-15 05:53:47 +00002474def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2475 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002476
Scott Michela59d4692008-02-23 18:41:37 +00002477//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2478// Rotate word:
2479//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002480
Scott Michela59d4692008-02-23 18:41:37 +00002481class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2482 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2483 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002484
Scott Michela59d4692008-02-23 18:41:37 +00002485class ROTVecInst<ValueType vectype>:
2486 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2487 [(set (vectype VECREG:$rT),
2488 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002489
Scott Michela59d4692008-02-23 18:41:37 +00002490class ROTRegInst<RegisterClass rclass>:
2491 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2492 [(set rclass:$rT,
2493 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002494
Scott Michela59d4692008-02-23 18:41:37 +00002495multiclass RotateLeftWord
2496{
2497 def v4i32: ROTVecInst<v4i32>;
2498 def r32: ROTRegInst<R32C>;
2499}
2500
2501defm ROT: RotateLeftWord;
Scott Michel66377522007-12-04 22:35:58 +00002502
Scott Michel504c3692007-12-17 22:32:34 +00002503// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2504// 32-bit register
2505def ROTr32_r16_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002506 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2507 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002508
2509def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2510 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2511
2512def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2513 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2514
2515def ROTr32_r8_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002516 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2517 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002518
2519def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2520 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2521
2522def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2523 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2524
Scott Michela59d4692008-02-23 18:41:37 +00002525//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2526// Rotate word, immediate
2527//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002528
Scott Michela59d4692008-02-23 18:41:37 +00002529class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2530 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2531 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002532
Scott Michela59d4692008-02-23 18:41:37 +00002533class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2534 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2535 [(set (vectype VECREG:$rT),
2536 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002537
Scott Michela59d4692008-02-23 18:41:37 +00002538class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2539 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2540 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002541
Scott Michela59d4692008-02-23 18:41:37 +00002542multiclass RotateLeftWordImm
2543{
2544 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2545 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2546 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel66377522007-12-04 22:35:58 +00002547
Scott Michela59d4692008-02-23 18:41:37 +00002548 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2549 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2550 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2551}
Scott Michel504c3692007-12-17 22:32:34 +00002552
Scott Michela59d4692008-02-23 18:41:37 +00002553defm ROTI : RotateLeftWordImm;
2554
2555//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2556// Rotate quad by byte (count)
2557//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2558
2559class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2560 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2561 RotateShift, pattern>;
2562
2563class ROTQBYVecInst<ValueType vectype>:
2564 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2565 [(set (vectype VECREG:$rT),
2566 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2567
2568multiclass RotateQuadLeftByBytes
2569{
2570 def v16i8: ROTQBYVecInst<v16i8>;
2571 def v8i16: ROTQBYVecInst<v8i16>;
2572 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002573 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002574 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002575 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002576}
2577
2578defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel66377522007-12-04 22:35:58 +00002579
Scott Michela59d4692008-02-23 18:41:37 +00002580//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2581// Rotate quad by byte (count), immediate
2582//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2583
2584class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2585 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2586 RotateShift, pattern>;
2587
2588class ROTQBYIVecInst<ValueType vectype>:
2589 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2590 [(set (vectype VECREG:$rT),
2591 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2592
2593multiclass RotateQuadByBytesImm
2594{
2595 def v16i8: ROTQBYIVecInst<v16i8>;
2596 def v8i16: ROTQBYIVecInst<v8i16>;
2597 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002598 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002599 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002600 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002601}
2602
2603defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel66377522007-12-04 22:35:58 +00002604
Scott Michel66377522007-12-04 22:35:58 +00002605// See ROTQBY note above.
Scott Michel8bf61e82008-06-02 22:18:03 +00002606class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2607 RI7Form<0b00110011100, OOL, IOL,
2608 "rotqbybi\t$rT, $rA, $shift",
2609 RotateShift, pattern>;
2610
2611class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2612 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2613 [(set (vectype VECREG:$rT),
2614 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2615
2616multiclass RotateQuadByBytesByBitshift {
2617 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2618 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2619 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2620 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2621}
2622
2623defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel66377522007-12-04 22:35:58 +00002624
Scott Michela59d4692008-02-23 18:41:37 +00002625//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002626// See ROTQBY note above.
2627//
2628// Assume that the user of this instruction knows to shift the rotate count
2629// into bit 29
Scott Michela59d4692008-02-23 18:41:37 +00002630//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002631
Scott Michela59d4692008-02-23 18:41:37 +00002632class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2633 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2634 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002635
Scott Michela59d4692008-02-23 18:41:37 +00002636class ROTQBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002637 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002638 [/* no pattern yet */]>;
2639
2640class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel02d711b2008-12-30 23:28:25 +00002641 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002642 [/* no pattern yet */]>;
2643
2644multiclass RotateQuadByBitCount
2645{
2646 def v16i8: ROTQBIVecInst<v16i8>;
2647 def v8i16: ROTQBIVecInst<v8i16>;
2648 def v4i32: ROTQBIVecInst<v4i32>;
2649 def v2i64: ROTQBIVecInst<v2i64>;
2650
2651 def r128: ROTQBIRegInst<GPRC>;
2652 def r64: ROTQBIRegInst<R64C>;
2653}
2654
2655defm ROTQBI: RotateQuadByBitCount;
Scott Michelf0569be2008-12-27 04:51:36 +00002656
Scott Michela59d4692008-02-23 18:41:37 +00002657class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2658 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2659 RotateShift, pattern>;
2660
2661class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2662 PatLeaf pred>:
2663 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2664 [/* no pattern yet */]>;
2665
2666class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2667 PatLeaf pred>:
2668 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2669 [/* no pattern yet */]>;
2670
2671multiclass RotateQuadByBitCountImm
2672{
2673 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2674 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2675 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2676 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2677
2678 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2679 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2680}
2681
2682defm ROTQBII : RotateQuadByBitCountImm;
2683
2684//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002685// ROTHM v8i16 form:
2686// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2687// so this only matches a synthetically generated/lowered code
2688// fragment.
2689// NOTE(2): $rB must be negated before the right rotate!
Scott Michela59d4692008-02-23 18:41:37 +00002690//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002691
Scott Michela59d4692008-02-23 18:41:37 +00002692class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2693 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2694 RotateShift, pattern>;
2695
2696def ROTHMv8i16:
2697 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2698 [/* see patterns below - $rB must be negated */]>;
2699
2700def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002701 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2702
Scott Michela59d4692008-02-23 18:41:37 +00002703def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002704 (ROTHMv8i16 VECREG:$rA,
2705 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2706
Scott Michela59d4692008-02-23 18:41:37 +00002707def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002708 (ROTHMv8i16 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002709 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002710
2711// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2712// Note: This instruction doesn't match a pattern because rB must be negated
2713// for the instruction to work. Thus, the pattern below the instruction!
Scott Michela59d4692008-02-23 18:41:37 +00002714
Scott Michel66377522007-12-04 22:35:58 +00002715def ROTHMr16:
Scott Michela59d4692008-02-23 18:41:37 +00002716 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2717 [/* see patterns below - $rB must be negated! */]>;
Scott Michel66377522007-12-04 22:35:58 +00002718
2719def : Pat<(srl R16C:$rA, R32C:$rB),
2720 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2721
2722def : Pat<(srl R16C:$rA, R16C:$rB),
2723 (ROTHMr16 R16C:$rA,
2724 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2725
Scott Michel504c3692007-12-17 22:32:34 +00002726def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002727 (ROTHMr16 R16C:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002728 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002729
2730// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2731// that the immediate can be complemented, so that the user doesn't have to
2732// worry about it.
Scott Michel66377522007-12-04 22:35:58 +00002733
Scott Michela59d4692008-02-23 18:41:37 +00002734class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2735 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2736 RotateShift, pattern>;
2737
2738def ROTHMIv8i16:
2739 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2740 [/* no pattern */]>;
2741
2742def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2743 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2744
2745def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002746 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002747
Scott Michela59d4692008-02-23 18:41:37 +00002748def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002749 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002750
2751def ROTHMIr16:
Scott Michela59d4692008-02-23 18:41:37 +00002752 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2753 [/* no pattern */]>;
2754
2755def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2756 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel66377522007-12-04 22:35:58 +00002757
2758def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002759 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002760
Scott Michel504c3692007-12-17 22:32:34 +00002761def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002762 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002763
Scott Michel66377522007-12-04 22:35:58 +00002764// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michela59d4692008-02-23 18:41:37 +00002765class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2766 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2767 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002768
Scott Michela59d4692008-02-23 18:41:37 +00002769def ROTMv4i32:
2770 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2771 [/* see patterns below - $rB must be negated */]>;
2772
Chris Lattner420c69d2010-03-15 05:53:47 +00002773def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002774 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2775
Chris Lattner420c69d2010-03-15 05:53:47 +00002776def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002777 (ROTMv4i32 VECREG:$rA,
2778 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2779
Chris Lattner420c69d2010-03-15 05:53:47 +00002780def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002781 (ROTMv4i32 VECREG:$rA,
Scott Michela59d4692008-02-23 18:41:37 +00002782 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002783
2784def ROTMr32:
Scott Michela59d4692008-02-23 18:41:37 +00002785 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2786 [/* see patterns below - $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002787
2788def : Pat<(srl R32C:$rA, R32C:$rB),
2789 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2790
2791def : Pat<(srl R32C:$rA, R16C:$rB),
2792 (ROTMr32 R32C:$rA,
2793 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2794
Scott Michel504c3692007-12-17 22:32:34 +00002795def : Pat<(srl R32C:$rA, R8C:$rB),
2796 (ROTMr32 R32C:$rA,
2797 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2798
Scott Michel66377522007-12-04 22:35:58 +00002799// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2800def ROTMIv4i32:
2801 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2802 "rotmi\t$rT, $rA, $val", RotateShift,
2803 [(set (v4i32 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002804 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002805
Chris Lattner420c69d2010-03-15 05:53:47 +00002806def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2807 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002808
Chris Lattner420c69d2010-03-15 05:53:47 +00002809def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2810 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002811
2812// ROTMI r32 form: know how to complement the immediate value.
2813def ROTMIr32:
2814 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2815 "rotmi\t$rT, $rA, $val", RotateShift,
2816 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2817
2818def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002819 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002820
Scott Michel504c3692007-12-17 22:32:34 +00002821def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002822 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002823
Scott Michela59d4692008-02-23 18:41:37 +00002824//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Micheldd950092009-01-06 03:36:14 +00002825// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel66377522007-12-04 22:35:58 +00002826// instruction pattern, type checking will succeed. This instruction assumes
Scott Michela59d4692008-02-23 18:41:37 +00002827// that the user knew to negate $rB.
Scott Michela59d4692008-02-23 18:41:37 +00002828//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002829
Scott Michela59d4692008-02-23 18:41:37 +00002830class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2831 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2832 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002833
Scott Michela59d4692008-02-23 18:41:37 +00002834class ROTQMBYVecInst<ValueType vectype>:
2835 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2836 [/* no pattern, $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002837
Scott Michela59d4692008-02-23 18:41:37 +00002838class ROTQMBYRegInst<RegisterClass rclass>:
2839 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00002840 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00002841
Scott Michela59d4692008-02-23 18:41:37 +00002842multiclass RotateQuadBytes
2843{
2844 def v16i8: ROTQMBYVecInst<v16i8>;
2845 def v8i16: ROTQMBYVecInst<v8i16>;
2846 def v4i32: ROTQMBYVecInst<v4i32>;
2847 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002848
Scott Michela59d4692008-02-23 18:41:37 +00002849 def r128: ROTQMBYRegInst<GPRC>;
2850 def r64: ROTQMBYRegInst<R64C>;
2851}
2852
2853defm ROTQMBY : RotateQuadBytes;
2854
Scott Michela59d4692008-02-23 18:41:37 +00002855class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2856 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2857 RotateShift, pattern>;
2858
2859class ROTQMBYIVecInst<ValueType vectype>:
2860 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002861 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002862
Scott Micheldd950092009-01-06 03:36:14 +00002863class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2864 PatLeaf pred>:
Scott Michela59d4692008-02-23 18:41:37 +00002865 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002866 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002867
Scott Micheldd950092009-01-06 03:36:14 +00002868// 128-bit zero extension form:
2869class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2870 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2871 [/* no pattern */]>;
2872
Scott Michela59d4692008-02-23 18:41:37 +00002873multiclass RotateQuadBytesImm
2874{
2875 def v16i8: ROTQMBYIVecInst<v16i8>;
2876 def v8i16: ROTQMBYIVecInst<v8i16>;
2877 def v4i32: ROTQMBYIVecInst<v4i32>;
2878 def v2i64: ROTQMBYIVecInst<v2i64>;
2879
2880 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2881 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Micheldd950092009-01-06 03:36:14 +00002882
2883 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2884 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2885 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2886 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michela59d4692008-02-23 18:41:37 +00002887}
2888
2889defm ROTQMBYI : RotateQuadBytesImm;
2890
Scott Michela59d4692008-02-23 18:41:37 +00002891//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2892// Rotate right and mask by bit count
2893//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2894
2895class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2896 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2897 RotateShift, pattern>;
2898
2899class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002900 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2901 [/* no pattern, */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002902
2903multiclass RotateMaskQuadByBitCount
2904{
2905 def v16i8: ROTQMBYBIVecInst<v16i8>;
2906 def v8i16: ROTQMBYBIVecInst<v8i16>;
2907 def v4i32: ROTQMBYBIVecInst<v4i32>;
2908 def v2i64: ROTQMBYBIVecInst<v2i64>;
2909}
2910
2911defm ROTQMBYBI: RotateMaskQuadByBitCount;
2912
2913//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2914// Rotate quad and mask by bits
2915// Note that the rotate amount has to be negated
2916//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2917
2918class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2919 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2920 RotateShift, pattern>;
2921
2922class ROTQMBIVecInst<ValueType vectype>:
2923 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2924 [/* no pattern */]>;
2925
2926class ROTQMBIRegInst<RegisterClass rclass>:
2927 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2928 [/* no pattern */]>;
2929
2930multiclass RotateMaskQuadByBits
2931{
2932 def v16i8: ROTQMBIVecInst<v16i8>;
2933 def v8i16: ROTQMBIVecInst<v8i16>;
2934 def v4i32: ROTQMBIVecInst<v4i32>;
2935 def v2i64: ROTQMBIVecInst<v2i64>;
2936
2937 def r128: ROTQMBIRegInst<GPRC>;
2938 def r64: ROTQMBIRegInst<R64C>;
2939}
2940
2941defm ROTQMBI: RotateMaskQuadByBits;
2942
Scott Michela59d4692008-02-23 18:41:37 +00002943//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2944// Rotate quad and mask by bits, immediate
2945//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2946
2947class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2948 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2949 RotateShift, pattern>;
2950
2951class ROTQMBIIVecInst<ValueType vectype>:
2952 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002953 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002954
2955class ROTQMBIIRegInst<RegisterClass rclass>:
2956 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002957 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002958
2959multiclass RotateMaskQuadByBitsImm
2960{
2961 def v16i8: ROTQMBIIVecInst<v16i8>;
2962 def v8i16: ROTQMBIIVecInst<v8i16>;
2963 def v4i32: ROTQMBIIVecInst<v4i32>;
2964 def v2i64: ROTQMBIIVecInst<v2i64>;
2965
2966 def r128: ROTQMBIIRegInst<GPRC>;
2967 def r64: ROTQMBIIRegInst<R64C>;
2968}
2969
2970defm ROTQMBII: RotateMaskQuadByBitsImm;
2971
2972//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2973//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002974
2975def ROTMAHv8i16:
2976 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2977 "rotmah\t$rT, $rA, $rB", RotateShift,
2978 [/* see patterns below - $rB must be negated */]>;
2979
Chris Lattner420c69d2010-03-15 05:53:47 +00002980def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002981 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2982
Chris Lattner420c69d2010-03-15 05:53:47 +00002983def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002984 (ROTMAHv8i16 VECREG:$rA,
2985 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2986
Chris Lattner420c69d2010-03-15 05:53:47 +00002987def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel504c3692007-12-17 22:32:34 +00002988 (ROTMAHv8i16 VECREG:$rA,
2989 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2990
Scott Michel66377522007-12-04 22:35:58 +00002991def ROTMAHr16:
2992 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2993 "rotmah\t$rT, $rA, $rB", RotateShift,
2994 [/* see patterns below - $rB must be negated */]>;
2995
2996def : Pat<(sra R16C:$rA, R32C:$rB),
2997 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2998
2999def : Pat<(sra R16C:$rA, R16C:$rB),
3000 (ROTMAHr16 R16C:$rA,
3001 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3002
Scott Michel504c3692007-12-17 22:32:34 +00003003def : Pat<(sra R16C:$rA, R8C:$rB),
3004 (ROTMAHr16 R16C:$rA,
3005 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3006
Scott Michel66377522007-12-04 22:35:58 +00003007def ROTMAHIv8i16:
3008 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
3009 "rotmahi\t$rT, $rA, $val", RotateShift,
3010 [(set (v8i16 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00003011 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003012
Scott Michela59d4692008-02-23 18:41:37 +00003013def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003014 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00003015
Scott Michela59d4692008-02-23 18:41:37 +00003016def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003017 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00003018
Scott Michel66377522007-12-04 22:35:58 +00003019def ROTMAHIr16:
3020 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
3021 "rotmahi\t$rT, $rA, $val", RotateShift,
3022 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
3023
3024def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003025 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00003026
Scott Michel504c3692007-12-17 22:32:34 +00003027def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003028 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00003029
Scott Michel66377522007-12-04 22:35:58 +00003030def ROTMAv4i32:
3031 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
3032 "rotma\t$rT, $rA, $rB", RotateShift,
3033 [/* see patterns below - $rB must be negated */]>;
3034
Chris Lattner420c69d2010-03-15 05:53:47 +00003035def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
3036 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel66377522007-12-04 22:35:58 +00003037
Chris Lattner420c69d2010-03-15 05:53:47 +00003038def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
3039 (ROTMAv4i32 VECREG:$rA,
Scott Michel66377522007-12-04 22:35:58 +00003040 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3041
Chris Lattner420c69d2010-03-15 05:53:47 +00003042def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
3043 (ROTMAv4i32 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00003044 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3045
Scott Michel66377522007-12-04 22:35:58 +00003046def ROTMAr32:
3047 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3048 "rotma\t$rT, $rA, $rB", RotateShift,
3049 [/* see patterns below - $rB must be negated */]>;
3050
3051def : Pat<(sra R32C:$rA, R32C:$rB),
3052 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3053
3054def : Pat<(sra R32C:$rA, R16C:$rB),
3055 (ROTMAr32 R32C:$rA,
3056 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3057
Scott Michel504c3692007-12-17 22:32:34 +00003058def : Pat<(sra R32C:$rA, R8C:$rB),
3059 (ROTMAr32 R32C:$rA,
3060 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3061
Scott Michel8bf61e82008-06-02 22:18:03 +00003062class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3063 RRForm<0b01011110000, OOL, IOL,
3064 "rotmai\t$rT, $rA, $val",
3065 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003066
Scott Michel8bf61e82008-06-02 22:18:03 +00003067class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3068 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3069 [(set (vectype VECREG:$rT),
3070 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003071
Scott Michel8bf61e82008-06-02 22:18:03 +00003072class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3073 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3074 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003075
Scott Michel8bf61e82008-06-02 22:18:03 +00003076multiclass RotateMaskAlgebraicImm {
3077 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3078 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3079 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3080 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3081}
Scott Michel66377522007-12-04 22:35:58 +00003082
Scott Michel8bf61e82008-06-02 22:18:03 +00003083defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel504c3692007-12-17 22:32:34 +00003084
Scott Michel66377522007-12-04 22:35:58 +00003085//===----------------------------------------------------------------------===//
3086// Branch and conditionals:
3087//===----------------------------------------------------------------------===//
3088
3089let isTerminator = 1, isBarrier = 1 in {
3090 // Halt If Equal (r32 preferred slot only, no vector form)
3091 def HEQr32:
3092 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3093 "heq\t$rA, $rB", BranchResolv,
3094 [/* no pattern to match */]>;
3095
3096 def HEQIr32 :
3097 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3098 "heqi\t$rA, $val", BranchResolv,
3099 [/* no pattern to match */]>;
3100
3101 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3102 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3103 def HGTr32:
3104 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3105 "hgt\t$rA, $rB", BranchResolv,
3106 [/* no pattern to match */]>;
3107
Scott Michelf0569be2008-12-27 04:51:36 +00003108 def HGTIr32:
Scott Michel66377522007-12-04 22:35:58 +00003109 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3110 "hgti\t$rA, $val", BranchResolv,
3111 [/* no pattern to match */]>;
3112
3113 def HLGTr32:
3114 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3115 "hlgt\t$rA, $rB", BranchResolv,
3116 [/* no pattern to match */]>;
3117
3118 def HLGTIr32:
3119 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3120 "hlgti\t$rA, $val", BranchResolv,
3121 [/* no pattern to match */]>;
3122}
3123
Scott Michelf0569be2008-12-27 04:51:36 +00003124//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3125// Comparison operators for i8, i16 and i32:
3126//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003127
Scott Michela59d4692008-02-23 18:41:37 +00003128class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3129 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3130 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003131
Scott Michela59d4692008-02-23 18:41:37 +00003132multiclass CmpEqualByte
3133{
3134 def v16i8 :
3135 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3136 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3137 (v8i16 VECREG:$rB)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00003138
Scott Michela59d4692008-02-23 18:41:37 +00003139 def r8 :
3140 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3141 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3142}
Scott Michel66377522007-12-04 22:35:58 +00003143
Scott Michela59d4692008-02-23 18:41:37 +00003144class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3145 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3146 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003147
Scott Michela59d4692008-02-23 18:41:37 +00003148multiclass CmpEqualByteImm
3149{
3150 def v16i8 :
3151 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3152 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3153 v16i8SExt8Imm:$val))]>;
3154 def r8:
3155 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3156 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3157}
Scott Michel66377522007-12-04 22:35:58 +00003158
Scott Michela59d4692008-02-23 18:41:37 +00003159class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3160 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3161 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003162
Scott Michela59d4692008-02-23 18:41:37 +00003163multiclass CmpEqualHalfword
3164{
3165 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3166 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3167 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003168
Scott Michela59d4692008-02-23 18:41:37 +00003169 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3170 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3171}
Scott Michel66377522007-12-04 22:35:58 +00003172
Scott Michela59d4692008-02-23 18:41:37 +00003173class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3174 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3175 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003176
Scott Michela59d4692008-02-23 18:41:37 +00003177multiclass CmpEqualHalfwordImm
3178{
3179 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3180 [(set (v8i16 VECREG:$rT),
3181 (seteq (v8i16 VECREG:$rA),
3182 (v8i16 v8i16SExt10Imm:$val)))]>;
3183 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3184 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3185}
Scott Michel66377522007-12-04 22:35:58 +00003186
Scott Michela59d4692008-02-23 18:41:37 +00003187class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3188 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3189 ByteOp, pattern>;
3190
3191multiclass CmpEqualWord
3192{
3193 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3194 [(set (v4i32 VECREG:$rT),
3195 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3196
3197 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3198 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3199}
3200
3201class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3202 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3203 ByteOp, pattern>;
3204
3205multiclass CmpEqualWordImm
3206{
3207 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3208 [(set (v4i32 VECREG:$rT),
3209 (seteq (v4i32 VECREG:$rA),
3210 (v4i32 v4i32SExt16Imm:$val)))]>;
3211
3212 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3213 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3214}
3215
3216class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3217 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3218 ByteOp, pattern>;
3219
3220multiclass CmpGtrByte
3221{
3222 def v16i8 :
3223 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3224 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3225 (v8i16 VECREG:$rB)))]>;
3226
3227 def r8 :
3228 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3229 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3230}
3231
3232class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3233 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3234 ByteOp, pattern>;
3235
3236multiclass CmpGtrByteImm
3237{
3238 def v16i8 :
3239 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3240 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3241 v16i8SExt8Imm:$val))]>;
3242 def r8:
3243 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel79698f62008-03-20 00:51:36 +00003244 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003245}
3246
3247class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3248 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3249 ByteOp, pattern>;
3250
3251multiclass CmpGtrHalfword
3252{
3253 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3254 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3255 (v8i16 VECREG:$rB)))]>;
3256
3257 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3258 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3259}
3260
3261class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3262 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3263 ByteOp, pattern>;
3264
3265multiclass CmpGtrHalfwordImm
3266{
3267 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3268 [(set (v8i16 VECREG:$rT),
3269 (setgt (v8i16 VECREG:$rA),
3270 (v8i16 v8i16SExt10Imm:$val)))]>;
3271 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3272 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3273}
3274
3275class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3276 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3277 ByteOp, pattern>;
3278
3279multiclass CmpGtrWord
3280{
3281 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3282 [(set (v4i32 VECREG:$rT),
3283 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3284
3285 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3286 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3287}
3288
3289class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3290 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3291 ByteOp, pattern>;
3292
3293multiclass CmpGtrWordImm
3294{
3295 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3296 [(set (v4i32 VECREG:$rT),
3297 (setgt (v4i32 VECREG:$rA),
3298 (v4i32 v4i32SExt16Imm:$val)))]>;
3299
3300 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3301 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00003302
3303 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3304 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3305 [(set (v4i32 VECREG:$rT),
3306 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3307 (v4i32 v4i32SExt16Imm:$val)))]>;
3308
3309 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +00003310 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00003311}
3312
3313class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003314 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003315 ByteOp, pattern>;
3316
3317multiclass CmpLGtrByte
3318{
3319 def v16i8 :
3320 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3321 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3322 (v8i16 VECREG:$rB)))]>;
3323
3324 def r8 :
3325 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3326 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3327}
3328
3329class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003330 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003331 ByteOp, pattern>;
3332
3333multiclass CmpLGtrByteImm
3334{
3335 def v16i8 :
3336 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3337 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3338 v16i8SExt8Imm:$val))]>;
3339 def r8:
3340 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3341 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3342}
3343
3344class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003345 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003346 ByteOp, pattern>;
3347
3348multiclass CmpLGtrHalfword
3349{
3350 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3351 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3352 (v8i16 VECREG:$rB)))]>;
3353
3354 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3355 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3356}
3357
3358class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003359 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003360 ByteOp, pattern>;
3361
3362multiclass CmpLGtrHalfwordImm
3363{
3364 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3365 [(set (v8i16 VECREG:$rT),
3366 (setugt (v8i16 VECREG:$rA),
3367 (v8i16 v8i16SExt10Imm:$val)))]>;
3368 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3369 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3370}
3371
3372class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003373 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003374 ByteOp, pattern>;
3375
3376multiclass CmpLGtrWord
3377{
3378 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3379 [(set (v4i32 VECREG:$rT),
3380 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3381
3382 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3383 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3384}
3385
3386class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003387 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003388 ByteOp, pattern>;
3389
3390multiclass CmpLGtrWordImm
3391{
3392 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3393 [(set (v4i32 VECREG:$rT),
3394 (setugt (v4i32 VECREG:$rA),
3395 (v4i32 v4i32SExt16Imm:$val)))]>;
3396
3397 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michelad2715e2008-03-05 23:02:02 +00003398 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003399}
3400
3401defm CEQB : CmpEqualByte;
3402defm CEQBI : CmpEqualByteImm;
3403defm CEQH : CmpEqualHalfword;
3404defm CEQHI : CmpEqualHalfwordImm;
3405defm CEQ : CmpEqualWord;
3406defm CEQI : CmpEqualWordImm;
3407defm CGTB : CmpGtrByte;
3408defm CGTBI : CmpGtrByteImm;
3409defm CGTH : CmpGtrHalfword;
3410defm CGTHI : CmpGtrHalfwordImm;
3411defm CGT : CmpGtrWord;
3412defm CGTI : CmpGtrWordImm;
3413defm CLGTB : CmpLGtrByte;
3414defm CLGTBI : CmpLGtrByteImm;
3415defm CLGTH : CmpLGtrHalfword;
3416defm CLGTHI : CmpLGtrHalfwordImm;
3417defm CLGT : CmpLGtrWord;
3418defm CLGTI : CmpLGtrWordImm;
3419
Scott Michel78c47fa2008-03-10 16:58:52 +00003420//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003421// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3422// define a pattern to generate the right code, as a binary operator
3423// (in a manner of speaking.)
Scott Michel78c47fa2008-03-10 16:58:52 +00003424//
Scott Michelf0569be2008-12-27 04:51:36 +00003425// Notes:
3426// 1. This only matches the setcc set of conditionals. Special pattern
3427// matching is used for select conditionals.
3428//
3429// 2. The "DAG" versions of these classes is almost exclusively used for
3430// i64 comparisons. See the tblgen fundamentals documentation for what
3431// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3432// class for where ResultInstrs originates.
Scott Michel78c47fa2008-03-10 16:58:52 +00003433//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003434
Scott Michel78c47fa2008-03-10 16:58:52 +00003435class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3436 SPUInstr xorinst, SPUInstr cmpare>:
3437 Pat<(cond rclass:$rA, rclass:$rB),
3438 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3439
3440class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3441 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3442 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3443 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3444
Scott Michelf0569be2008-12-27 04:51:36 +00003445def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003446def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3447
Scott Michelf0569be2008-12-27 04:51:36 +00003448def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003449def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3450
3451def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3452def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003453
3454class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3455 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3456 Pat<(cond rclass:$rA, rclass:$rB),
3457 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3458 (cmpOp2 rclass:$rA, rclass:$rB))>;
3459
3460class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3461 ValueType immtype,
3462 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3463 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3464 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3465 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3466
Scott Michel78c47fa2008-03-10 16:58:52 +00003467def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3468def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3469def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3470def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3471def : Pat<(setle R8C:$rA, R8C:$rB),
3472 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3473def : Pat<(setle R8C:$rA, immU8:$imm),
3474 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003475
Scott Michel78c47fa2008-03-10 16:58:52 +00003476def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3477def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3478 ORr16, CGTHIr16, CEQHIr16>;
3479def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3480def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3481def : Pat<(setle R16C:$rA, R16C:$rB),
3482 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3483def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3484 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003485
Scott Michel78c47fa2008-03-10 16:58:52 +00003486def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3487def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3488 ORr32, CGTIr32, CEQIr32>;
3489def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3490def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3491def : Pat<(setle R32C:$rA, R32C:$rB),
3492 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3493def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3494 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003495
Scott Michel78c47fa2008-03-10 16:58:52 +00003496def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3497def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3498def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3499def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3500def : Pat<(setule R8C:$rA, R8C:$rB),
3501 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3502def : Pat<(setule R8C:$rA, immU8:$imm),
3503 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003504
Scott Michel78c47fa2008-03-10 16:58:52 +00003505def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3506def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3507 ORr16, CLGTHIr16, CEQHIr16>;
3508def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3509def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3510 CLGTHIr16, CEQHIr16>;
3511def : Pat<(setule R16C:$rA, R16C:$rB),
3512 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel79698f62008-03-20 00:51:36 +00003513def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel78c47fa2008-03-10 16:58:52 +00003514 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003515
Scott Michel78c47fa2008-03-10 16:58:52 +00003516def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003517def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel78c47fa2008-03-10 16:58:52 +00003518 ORr32, CLGTIr32, CEQIr32>;
3519def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003520def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003521def : Pat<(setule R32C:$rA, R32C:$rB),
3522 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3523def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3524 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003525
Scott Michel78c47fa2008-03-10 16:58:52 +00003526//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3527// select conditional patterns:
3528//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3529
3530class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3531 SPUInstr selinstr, SPUInstr cmpare>:
3532 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3533 rclass:$rTrue, rclass:$rFalse),
3534 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003535 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003536
3537class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3538 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3539 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003540 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003541 (selinstr rclass:$rTrue, rclass:$rFalse,
3542 (cmpare rclass:$rA, immpred:$imm))>;
3543
3544def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3545def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3546def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3547def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3548def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3549def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3550
3551def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3552def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3553def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3554def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3555def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3556def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3557
3558def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3559def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3560def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3561def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3562def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3563def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3564
3565class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3566 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3567 SPUInstr cmpOp2>:
3568 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michelf0569be2008-12-27 04:51:36 +00003569 rclass:$rTrue, rclass:$rFalse),
3570 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel78c47fa2008-03-10 16:58:52 +00003571 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3572 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3573
3574class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3575 ValueType inttype,
3576 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3577 SPUInstr cmpOp2>:
3578 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003579 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003580 (selinstr rclass:$rFalse, rclass:$rTrue,
3581 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3582 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3583
3584def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3585def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3586 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3587
3588def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3589def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3590 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3591
3592def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3593def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3594 SELBr32, ORr32, CGTIr32, CEQIr32>;
3595
3596def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3597def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3598 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3599
3600def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3601def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3602 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3603
3604def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3605def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3606 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003607
3608//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003609
3610let isCall = 1,
3611 // All calls clobber the non-callee-saved registers:
3612 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3613 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3614 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3615 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3616 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3617 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3618 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3619 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3620 // All of these instructions use $lr (aka $0)
3621 Uses = [R0] in {
3622 // Branch relative and set link: Used if we actually know that the target
3623 // is within [-32768, 32767] bytes of the target
3624 def BRSL:
3625 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3626 "brsl\t$$lr, $func",
3627 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3628
3629 // Branch absolute and set link: Used if we actually know that the target
3630 // is an absolute address
3631 def BRASL:
3632 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3633 "brasl\t$$lr, $func",
Scott Michel9de5d0d2008-01-11 02:53:15 +00003634 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel66377522007-12-04 22:35:58 +00003635
3636 // Branch indirect and set link if external data. These instructions are not
3637 // actually generated, matched by an intrinsic:
3638 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3639 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3640 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3641 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3642
3643 // Branch indirect and set link. This is the "X-form" address version of a
3644 // function call
3645 def BISL:
3646 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3647}
3648
Scott Michel1df30c42008-12-29 03:23:36 +00003649// Support calls to external symbols:
3650def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3651 (BRSL texternalsym:$func)>;
3652
3653def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3654 (BRASL texternalsym:$func)>;
3655
Scott Michel66377522007-12-04 22:35:58 +00003656// Unconditional branches:
Dan Gohman5b37fba2009-11-10 22:16:57 +00003657let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3658 let isBarrier = 1 in {
3659 def BR :
3660 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3661 "br\t$dest",
3662 [(br bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003663
Dan Gohman5b37fba2009-11-10 22:16:57 +00003664 // Unconditional, absolute address branch
3665 def BRA:
3666 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3667 "bra\t$dest",
3668 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003669
Dan Gohman5b37fba2009-11-10 22:16:57 +00003670 // Indirect branch
3671 def BI:
3672 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3673 }
Scott Michel66377522007-12-04 22:35:58 +00003674
Scott Micheled741dd2009-01-05 01:34:35 +00003675 // Conditional branches:
Scott Michelf0569be2008-12-27 04:51:36 +00003676 class BRNZInst<dag IOL, list<dag> pattern>:
3677 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3678 BranchResolv, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003679
Scott Michelf0569be2008-12-27 04:51:36 +00003680 class BRNZRegInst<RegisterClass rclass>:
3681 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3682 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003683
Scott Michelf0569be2008-12-27 04:51:36 +00003684 class BRNZVecInst<ValueType vectype>:
3685 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3686 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003687
Scott Michelf0569be2008-12-27 04:51:36 +00003688 multiclass BranchNotZero {
3689 def v4i32 : BRNZVecInst<v4i32>;
3690 def r32 : BRNZRegInst<R32C>;
3691 }
Scott Michel66377522007-12-04 22:35:58 +00003692
Scott Michelf0569be2008-12-27 04:51:36 +00003693 defm BRNZ : BranchNotZero;
3694
3695 class BRZInst<dag IOL, list<dag> pattern>:
3696 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3697 BranchResolv, pattern>;
3698
3699 class BRZRegInst<RegisterClass rclass>:
3700 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3701
3702 class BRZVecInst<ValueType vectype>:
3703 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3704
3705 multiclass BranchZero {
3706 def v4i32: BRZVecInst<v4i32>;
3707 def r32: BRZRegInst<R32C>;
3708 }
3709
3710 defm BRZ: BranchZero;
3711
3712 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3713 // be useful:
3714 /*
3715 class BINZInst<dag IOL, list<dag> pattern>:
3716 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3717
3718 class BINZRegInst<RegisterClass rclass>:
3719 BINZInst<(ins rclass:$rA, brtarget:$dest),
3720 [(brcond rclass:$rA, R32C:$dest)]>;
3721
3722 class BINZVecInst<ValueType vectype>:
3723 BINZInst<(ins VECREG:$rA, R32C:$dest),
3724 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3725
3726 multiclass BranchNotZeroIndirect {
3727 def v4i32: BINZVecInst<v4i32>;
3728 def r32: BINZRegInst<R32C>;
3729 }
3730
3731 defm BINZ: BranchNotZeroIndirect;
3732
3733 class BIZInst<dag IOL, list<dag> pattern>:
3734 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3735
3736 class BIZRegInst<RegisterClass rclass>:
3737 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3738
3739 class BIZVecInst<ValueType vectype>:
3740 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3741
3742 multiclass BranchZeroIndirect {
3743 def v4i32: BIZVecInst<v4i32>;
3744 def r32: BIZRegInst<R32C>;
3745 }
3746
3747 defm BIZ: BranchZeroIndirect;
3748 */
3749
3750 class BRHNZInst<dag IOL, list<dag> pattern>:
3751 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3752 pattern>;
3753
3754 class BRHNZRegInst<RegisterClass rclass>:
3755 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3756 [(brcond rclass:$rCond, bb:$dest)]>;
3757
3758 class BRHNZVecInst<ValueType vectype>:
3759 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3760
3761 multiclass BranchNotZeroHalfword {
3762 def v8i16: BRHNZVecInst<v8i16>;
3763 def r16: BRHNZRegInst<R16C>;
3764 }
3765
3766 defm BRHNZ: BranchNotZeroHalfword;
3767
3768 class BRHZInst<dag IOL, list<dag> pattern>:
3769 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3770 pattern>;
3771
3772 class BRHZRegInst<RegisterClass rclass>:
3773 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3774
3775 class BRHZVecInst<ValueType vectype>:
3776 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3777
3778 multiclass BranchZeroHalfword {
3779 def v8i16: BRHZVecInst<v8i16>;
3780 def r16: BRHZRegInst<R16C>;
3781 }
3782
3783 defm BRHZ: BranchZeroHalfword;
Scott Michel66377522007-12-04 22:35:58 +00003784}
3785
Scott Michel58c58182008-01-17 20:38:41 +00003786//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003787// setcc and brcond patterns:
Scott Michel58c58182008-01-17 20:38:41 +00003788//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003789
Scott Michelf0569be2008-12-27 04:51:36 +00003790def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3791 (BRHZr16 R16C:$rA, bb:$dest)>;
3792def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3793 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michela59d4692008-02-23 18:41:37 +00003794
Scott Michelf0569be2008-12-27 04:51:36 +00003795def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3796 (BRZr32 R32C:$rA, bb:$dest)>;
3797def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3798 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel66377522007-12-04 22:35:58 +00003799
Scott Michela59d4692008-02-23 18:41:37 +00003800multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3801{
3802 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3803 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michel053c1da2008-01-29 02:16:57 +00003804
Scott Michela59d4692008-02-23 18:41:37 +00003805 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3806 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3807
3808 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3809 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3810
3811 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3812 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3813}
3814
Scott Micheled741dd2009-01-05 01:34:35 +00003815defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3816defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003817
3818multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3819{
3820 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3821 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3822
3823 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3824 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3825
3826 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3827 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3828
3829 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3830 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3831}
3832
Scott Michelf0569be2008-12-27 04:51:36 +00003833defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3834defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003835
3836multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3837 SPUInstr orinst32, SPUInstr brinst32>
3838{
3839 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3840 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3841 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3842 bb:$dest)>;
3843
3844 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3845 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3846 (CEQHr16 R16C:$rA, R16:$rB)),
3847 bb:$dest)>;
3848
3849 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3850 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3851 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3852 bb:$dest)>;
3853
3854 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3855 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3856 (CEQr32 R32C:$rA, R32C:$rB)),
3857 bb:$dest)>;
3858}
3859
Scott Michelf0569be2008-12-27 04:51:36 +00003860defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3861defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003862
3863multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3864{
3865 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3866 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3867
3868 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3869 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3870
3871 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3872 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3873
3874 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3875 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3876}
3877
Scott Michelf0569be2008-12-27 04:51:36 +00003878defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3879defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003880
3881multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3882 SPUInstr orinst32, SPUInstr brinst32>
3883{
3884 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3885 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3886 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3887 bb:$dest)>;
3888
3889 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3890 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3891 (CEQHr16 R16C:$rA, R16:$rB)),
3892 bb:$dest)>;
3893
3894 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3895 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3896 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3897 bb:$dest)>;
3898
3899 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3900 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3901 (CEQr32 R32C:$rA, R32C:$rB)),
3902 bb:$dest)>;
3903}
3904
Scott Michelf0569be2008-12-27 04:51:36 +00003905defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3906defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel053c1da2008-01-29 02:16:57 +00003907
Scott Michel66377522007-12-04 22:35:58 +00003908let isTerminator = 1, isBarrier = 1 in {
3909 let isReturn = 1 in {
3910 def RET:
3911 RETForm<"bi\t$$lr", [(retflag)]>;
3912 }
3913}
3914
3915//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00003916// Single precision floating point instructions
3917//===----------------------------------------------------------------------===//
3918
Scott Michelaedc6372008-12-10 00:15:19 +00003919class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3920 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003921 SPrecFP, pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00003922
Scott Michelaedc6372008-12-10 00:15:19 +00003923class FAVecInst<ValueType vectype>:
3924 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3925 [(set (vectype VECREG:$rT),
Scott Michel02d711b2008-12-30 23:28:25 +00003926 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00003927
Scott Michelaedc6372008-12-10 00:15:19 +00003928multiclass SFPAdd
3929{
3930 def v4f32: FAVecInst<v4f32>;
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003931 def v2f32: FAVecInst<v2f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003932 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3933 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003934}
Scott Michel66377522007-12-04 22:35:58 +00003935
Scott Michelaedc6372008-12-10 00:15:19 +00003936defm FA : SFPAdd;
Scott Michel66377522007-12-04 22:35:58 +00003937
Scott Michelaedc6372008-12-10 00:15:19 +00003938class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3939 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003940 SPrecFP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003941
Scott Michelaedc6372008-12-10 00:15:19 +00003942class FSVecInst<ValueType vectype>:
3943 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00003944 [(set (vectype VECREG:$rT),
3945 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003946
3947multiclass SFPSub
3948{
3949 def v4f32: FSVecInst<v4f32>;
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003950 def v2f32: FSVecInst<v2f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003951 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3952 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003953}
3954
3955defm FS : SFPSub;
Scott Michel66377522007-12-04 22:35:58 +00003956
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003957class FMInst<dag OOL, dag IOL, list<dag> pattern>:
3958 RRForm<0b01100011010, OOL, IOL,
3959 "fm\t$rT, $rA, $rB", SPrecFP,
3960 pattern>;
3961
3962class FMVecInst<ValueType type>:
3963 FMInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3964 [(set (type VECREG:$rT),
3965 (fmul (type VECREG:$rA), (type VECREG:$rB)))]>;
3966
3967multiclass SFPMul
3968{
3969 def v4f32: FMVecInst<v4f32>;
3970 def v2f32: FMVecInst<v2f32>;
3971 def f32: FMInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3972 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3973}
3974
3975defm FM : SFPMul;
3976
3977// Floating point multiply and add
3978// e.g. d = c + (a * b)
3979def FMAv4f32:
3980 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3981 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3982 [(set (v4f32 VECREG:$rT),
3983 (fadd (v4f32 VECREG:$rC),
3984 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3985
3986def FMAf32:
3987 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3988 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3989 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3990
3991// FP multiply and subtract
3992// Subtracts value in rC from product
3993// res = a * b - c
3994def FMSv4f32 :
3995 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3996 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3997 [(set (v4f32 VECREG:$rT),
3998 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3999 (v4f32 VECREG:$rC)))]>;
4000
4001def FMSf32 :
4002 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4003 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4004 [(set R32FP:$rT,
4005 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4006
4007// Floating Negative Mulitply and Subtract
4008// Subtracts product from value in rC
4009// res = fneg(fms a b c)
4010// = - (a * b - c)
4011// = c - a * b
4012// NOTE: subtraction order
4013// fsub a b = a - b
4014// fs a b = b - a?
4015def FNMSf32 :
4016 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4017 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4018 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4019
4020def FNMSv4f32 :
4021 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4022 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4023 [(set (v4f32 VECREG:$rT),
4024 (fsub (v4f32 VECREG:$rC),
4025 (fmul (v4f32 VECREG:$rA),
4026 (v4f32 VECREG:$rB))))]>;
4027
4028
4029
4030
Scott Michel66377522007-12-04 22:35:58 +00004031// Floating point reciprocal estimate
Scott Michel66377522007-12-04 22:35:58 +00004032
Scott Michel02d711b2008-12-30 23:28:25 +00004033class FRESTInst<dag OOL, dag IOL>:
4034 RRForm_1<0b00110111000, OOL, IOL,
4035 "frest\t$rT, $rA", SPrecFP,
4036 [/* no pattern */]>;
4037
4038def FRESTv4f32 :
4039 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
4040
4041def FRESTf32 :
4042 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00004043
4044// Floating point interpolate (used in conjunction with reciprocal estimate)
4045def FIv4f32 :
4046 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4047 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00004048 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00004049
4050def FIf32 :
4051 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4052 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00004053 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00004054
Scott Michel9c0c6b22008-11-21 02:56:16 +00004055//--------------------------------------------------------------------------
4056// Basic single precision floating point comparisons:
4057//
4058// Note: There is no support on SPU for single precision NaN. Consequently,
4059// ordered and unordered comparisons are the same.
4060//--------------------------------------------------------------------------
4061
Scott Michel66377522007-12-04 22:35:58 +00004062def FCEQf32 :
4063 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4064 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004065 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
4066
4067def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
4068 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004069
4070def FCMEQf32 :
4071 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4072 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004073 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4074
4075def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
4076 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004077
4078def FCGTf32 :
4079 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4080 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004081 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
4082
4083def : Pat<(setugt R32FP:$rA, R32FP:$rB),
4084 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004085
4086def FCMGTf32 :
4087 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4088 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004089 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4090
4091def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
4092 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
4093
4094//--------------------------------------------------------------------------
4095// Single precision floating point comparisons and SETCC equivalents:
4096//--------------------------------------------------------------------------
4097
4098def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
4099def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
4100
4101def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
4102def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
4103
4104def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
4105def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
4106
4107def : Pat<(setule R32FP:$rA, R32FP:$rB),
4108 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
4109def : Pat<(setole R32FP:$rA, R32FP:$rB),
4110 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel66377522007-12-04 22:35:58 +00004111
4112// FP Status and Control Register Write
4113// Why isn't rT a don't care in the ISA?
4114// Should we create a special RRForm_3 for this guy and zero out the rT?
4115def FSCRWf32 :
4116 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
4117 "fscrwr\t$rA", SPrecFP,
4118 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
4119
4120// FP Status and Control Register Read
4121def FSCRRf32 :
4122 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
4123 "fscrrd\t$rT", SPrecFP,
4124 [/* This instruction requires an intrinsic */]>;
4125
4126// llvm instruction space
4127// How do these map onto cell instructions?
4128// fdiv rA rB
4129// frest rC rB # c = 1/b (both lines)
4130// fi rC rB rC
4131// fm rD rA rC # d = a * 1/b
4132// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4133// fma rB rB rC rD # b = b * c + d
4134// = -(d *b -a) * c + d
4135// = a * c - c ( a *b *c - a)
4136
4137// fcopysign (???)
4138
4139// Library calls:
4140// These llvm instructions will actually map to library calls.
4141// All that's needed, then, is to check that the appropriate library is
4142// imported and do a brsl to the proper function name.
4143// frem # fmod(x, y): x - (x/y) * y
4144// (Note: fmod(double, double), fmodf(float,float)
4145// fsqrt?
4146// fsin?
4147// fcos?
4148// Unimplemented SPU instruction space
4149// floating reciprocal absolute square root estimate (frsqest)
4150
4151// The following are probably just intrinsics
Scott Michelf0569be2008-12-27 04:51:36 +00004152// status and control register write
Scott Michel66377522007-12-04 22:35:58 +00004153// status and control register read
4154
4155//--------------------------------------
Scott Michel66377522007-12-04 22:35:58 +00004156// Floating Point Conversions
4157// Signed conversions:
4158def CSiFv4f32:
4159 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4160 "csflt\t$rT, $rA, 0", SPrecFP,
4161 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4162
Scott Michelf0569be2008-12-27 04:51:36 +00004163// Convert signed integer to floating point
Scott Michel66377522007-12-04 22:35:58 +00004164def CSiFf32 :
4165 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4166 "csflt\t$rT, $rA, 0", SPrecFP,
4167 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4168
4169// Convert unsigned into to float
4170def CUiFv4f32 :
4171 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4172 "cuflt\t$rT, $rA, 0", SPrecFP,
4173 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4174
4175def CUiFf32 :
4176 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4177 "cuflt\t$rT, $rA, 0", SPrecFP,
4178 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4179
Scott Michelf0569be2008-12-27 04:51:36 +00004180// Convert float to unsigned int
Scott Michel66377522007-12-04 22:35:58 +00004181// Assume that scale = 0
4182
4183def CFUiv4f32 :
4184 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4185 "cfltu\t$rT, $rA, 0", SPrecFP,
4186 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4187
4188def CFUif32 :
4189 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4190 "cfltu\t$rT, $rA, 0", SPrecFP,
4191 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4192
Scott Michelf0569be2008-12-27 04:51:36 +00004193// Convert float to signed int
Scott Michel66377522007-12-04 22:35:58 +00004194// Assume that scale = 0
4195
4196def CFSiv4f32 :
4197 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4198 "cflts\t$rT, $rA, 0", SPrecFP,
4199 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4200
4201def CFSif32 :
4202 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4203 "cflts\t$rT, $rA, 0", SPrecFP,
4204 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4205
4206//===----------------------------------------------------------------------==//
4207// Single<->Double precision conversions
4208//===----------------------------------------------------------------------==//
4209
4210// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4211// v4f32, output is v2f64--which goes in the name?)
4212
4213// Floating point extend single to double
4214// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4215// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4216// are ignored).
4217def FESDvec :
4218 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4219 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnere9eda0f2010-03-19 04:53:47 +00004220 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel66377522007-12-04 22:35:58 +00004221
4222def FESDf32 :
4223 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4224 "fesd\t$rT, $rA", SPrecFP,
4225 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4226
4227// Floating point round double to single
4228//def FRDSvec :
4229// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4230// "frds\t$rT, $rA,", SPrecFP,
4231// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4232
4233def FRDSf64 :
4234 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4235 "frds\t$rT, $rA", SPrecFP,
4236 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4237
4238//ToDo include anyextend?
4239
4240//===----------------------------------------------------------------------==//
4241// Double precision floating point instructions
4242//===----------------------------------------------------------------------==//
4243def FAf64 :
4244 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4245 "dfa\t$rT, $rA, $rB", DPrecFP,
4246 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4247
4248def FAv2f64 :
4249 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4250 "dfa\t$rT, $rA, $rB", DPrecFP,
4251 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4252
4253def FSf64 :
4254 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4255 "dfs\t$rT, $rA, $rB", DPrecFP,
4256 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4257
4258def FSv2f64 :
4259 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4260 "dfs\t$rT, $rA, $rB", DPrecFP,
4261 [(set (v2f64 VECREG:$rT),
4262 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4263
4264def FMf64 :
4265 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4266 "dfm\t$rT, $rA, $rB", DPrecFP,
4267 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4268
4269def FMv2f64:
4270 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4271 "dfm\t$rT, $rA, $rB", DPrecFP,
4272 [(set (v2f64 VECREG:$rT),
4273 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4274
4275def FMAf64:
4276 RRForm<0b00111010110, (outs R64FP:$rT),
4277 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4278 "dfma\t$rT, $rA, $rB", DPrecFP,
4279 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4280 RegConstraint<"$rC = $rT">,
4281 NoEncode<"$rC">;
4282
4283def FMAv2f64:
4284 RRForm<0b00111010110, (outs VECREG:$rT),
4285 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4286 "dfma\t$rT, $rA, $rB", DPrecFP,
4287 [(set (v2f64 VECREG:$rT),
4288 (fadd (v2f64 VECREG:$rC),
4289 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4290 RegConstraint<"$rC = $rT">,
4291 NoEncode<"$rC">;
4292
4293def FMSf64 :
4294 RRForm<0b10111010110, (outs R64FP:$rT),
4295 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4296 "dfms\t$rT, $rA, $rB", DPrecFP,
4297 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4298 RegConstraint<"$rC = $rT">,
4299 NoEncode<"$rC">;
4300
4301def FMSv2f64 :
4302 RRForm<0b10111010110, (outs VECREG:$rT),
4303 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4304 "dfms\t$rT, $rA, $rB", DPrecFP,
4305 [(set (v2f64 VECREG:$rT),
4306 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4307 (v2f64 VECREG:$rC)))]>;
4308
Scott Michel7ea02ff2009-03-17 01:15:45 +00004309// DFNMS: - (a * b - c)
Scott Michel66377522007-12-04 22:35:58 +00004310// - (a * b) + c => c - (a * b)
Scott Michel7ea02ff2009-03-17 01:15:45 +00004311
4312class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4313 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4314 DPrecFP, pattern>,
Scott Michel66377522007-12-04 22:35:58 +00004315 RegConstraint<"$rC = $rT">,
4316 NoEncode<"$rC">;
4317
Scott Michel7ea02ff2009-03-17 01:15:45 +00004318class DFNMSVecInst<list<dag> pattern>:
4319 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4320 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004321
Scott Michel7ea02ff2009-03-17 01:15:45 +00004322class DFNMSRegInst<list<dag> pattern>:
4323 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4324 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004325
Scott Michel7ea02ff2009-03-17 01:15:45 +00004326multiclass DFMultiplySubtract
4327{
4328 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4329 (fsub (v2f64 VECREG:$rC),
4330 (fmul (v2f64 VECREG:$rA),
4331 (v2f64 VECREG:$rB))))]>;
4332
4333 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4334 (fsub R64FP:$rC,
4335 (fmul R64FP:$rA, R64FP:$rB)))]>;
4336}
4337
4338defm DFNMS : DFMultiplySubtract;
Scott Michel66377522007-12-04 22:35:58 +00004339
4340// - (a * b + c)
4341// - (a * b) - c
4342def FNMAf64 :
4343 RRForm<0b11111010110, (outs R64FP:$rT),
4344 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4345 "dfnma\t$rT, $rA, $rB", DPrecFP,
4346 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4347 RegConstraint<"$rC = $rT">,
4348 NoEncode<"$rC">;
4349
4350def FNMAv2f64 :
4351 RRForm<0b11111010110, (outs VECREG:$rT),
4352 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4353 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michelf0569be2008-12-27 04:51:36 +00004354 [(set (v2f64 VECREG:$rT),
4355 (fneg (fadd (v2f64 VECREG:$rC),
4356 (fmul (v2f64 VECREG:$rA),
Scott Michel66377522007-12-04 22:35:58 +00004357 (v2f64 VECREG:$rB)))))]>,
4358 RegConstraint<"$rC = $rT">,
4359 NoEncode<"$rC">;
4360
4361//===----------------------------------------------------------------------==//
4362// Floating point negation and absolute value
4363//===----------------------------------------------------------------------==//
4364
4365def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michela82d3f72009-03-17 16:45:16 +00004366 (XORfnegvec (v4f32 VECREG:$rA),
4367 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel66377522007-12-04 22:35:58 +00004368
4369def : Pat<(fneg R32FP:$rA),
Scott Michela82d3f72009-03-17 16:45:16 +00004370 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel66377522007-12-04 22:35:58 +00004371
4372// Floating point absolute value
Scott Michel7ea02ff2009-03-17 01:15:45 +00004373// Note: f64 fabs is custom-selected.
Scott Michel66377522007-12-04 22:35:58 +00004374
4375def : Pat<(fabs R32FP:$rA),
4376 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4377
4378def : Pat<(fabs (v4f32 VECREG:$rA)),
4379 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel7ea02ff2009-03-17 01:15:45 +00004380 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
Scott Michelc9c8b2a2009-01-26 03:31:40 +00004381
Scott Michel66377522007-12-04 22:35:58 +00004382//===----------------------------------------------------------------------===//
Scott Michelaedc6372008-12-10 00:15:19 +00004383// Hint for branch instructions:
4384//===----------------------------------------------------------------------===//
4385
4386/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4387
4388//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004389// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4390// in the odd pipeline)
4391//===----------------------------------------------------------------------===//
4392
Scott Michela59d4692008-02-23 18:41:37 +00004393def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004394 let Pattern = [];
4395
4396 let Inst{0-10} = 0b10000000010;
4397 let Inst{11-17} = 0;
4398 let Inst{18-24} = 0;
4399 let Inst{25-31} = 0;
4400}
4401
Scott Michela59d4692008-02-23 18:41:37 +00004402def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004403 let Pattern = [];
4404
4405 let Inst{0-10} = 0b10000000000;
4406 let Inst{11-17} = 0;
4407 let Inst{18-24} = 0;
4408 let Inst{25-31} = 0;
4409}
4410
4411//===----------------------------------------------------------------------===//
4412// Bit conversions (type conversions between vector/packed types)
Scott Michel6e1d1472009-03-16 18:47:25 +00004413// NOTE: Promotions are handled using the XS* instructions.
Scott Michel66377522007-12-04 22:35:58 +00004414//===----------------------------------------------------------------------===//
4415def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4416def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4417def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4418def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4419def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4420
4421def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4422def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4423def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4424def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4425def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4426
4427def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4428def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4429def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4430def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4431def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4432
4433def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4434def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4435def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4436def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4437def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4438
4439def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4440def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4441def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4442def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4443def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4444
4445def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4446def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4447def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4448def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattnere82f3362010-03-28 08:36:45 +00004449def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel66377522007-12-04 22:35:58 +00004450
Scott Michel6e1d1472009-03-16 18:47:25 +00004451def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4452 (ORi128_vec VECREG:$src)>;
4453def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4454 (ORi128_vec VECREG:$src)>;
4455def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4456 (ORi128_vec VECREG:$src)>;
4457def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4458 (ORi128_vec VECREG:$src)>;
4459def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4460 (ORi128_vec VECREG:$src)>;
4461def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4462 (ORi128_vec VECREG:$src)>;
4463
4464def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4465 (v16i8 (ORvec_i128 GPRC:$src))>;
4466def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4467 (v8i16 (ORvec_i128 GPRC:$src))>;
4468def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4469 (v4i32 (ORvec_i128 GPRC:$src))>;
4470def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4471 (v2i64 (ORvec_i128 GPRC:$src))>;
4472def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4473 (v4f32 (ORvec_i128 GPRC:$src))>;
4474def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4475 (v2f64 (ORvec_i128 GPRC:$src))>;
Scott Michel66377522007-12-04 22:35:58 +00004476
4477//===----------------------------------------------------------------------===//
4478// Instruction patterns:
4479//===----------------------------------------------------------------------===//
4480
4481// General 32-bit constants:
4482def : Pat<(i32 imm:$imm),
4483 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4484
4485// Single precision float constants:
Nate Begemanccef5802008-02-14 18:43:04 +00004486def : Pat<(f32 fpimm:$imm),
Scott Michel66377522007-12-04 22:35:58 +00004487 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4488
4489// General constant 32-bit vectors
4490def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michelad2715e2008-03-05 23:02:02 +00004491 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4492 (LO16_vec v4i32Imm:$imm))>;
Scott Michelf0569be2008-12-27 04:51:36 +00004493
Scott Michel504c3692007-12-17 22:32:34 +00004494// 8-bit constants
4495def : Pat<(i8 imm:$imm),
4496 (ILHr8 imm:$imm)>;
Scott Michel66377522007-12-04 22:35:58 +00004497
4498//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004499// Zero/Any/Sign extensions
4500//===----------------------------------------------------------------------===//
4501
Scott Michel66377522007-12-04 22:35:58 +00004502// sext 8->32: Sign extend bytes to words
4503def : Pat<(sext_inreg R32C:$rSrc, i8),
4504 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4505
Scott Michel504c3692007-12-17 22:32:34 +00004506def : Pat<(i32 (sext R8C:$rSrc)),
4507 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4508
Scott Micheldd950092009-01-06 03:36:14 +00004509// sext 8->64: Sign extend bytes to double word
4510def : Pat<(sext_inreg R64C:$rSrc, i8),
4511 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4512
4513def : Pat<(i64 (sext R8C:$rSrc)),
4514 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4515
Scott Michel504c3692007-12-17 22:32:34 +00004516// zext 8->16: Zero extend bytes to halfwords
4517def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004518 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004519
Scott Michel504c3692007-12-17 22:32:34 +00004520// zext 8->32: Zero extend bytes to words
4521def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004522 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004523
Scott Micheldd950092009-01-06 03:36:14 +00004524// zext 8->64: Zero extend bytes to double words
4525def : Pat<(i64 (zext R8C:$rSrc)),
4526 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4527 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4528 0x4),
4529 (ILv4i32 0x0),
4530 (FSMBIv4i32 0x0f0f)))>;
4531
4532// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004533def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004534 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004535
Scott Micheldd950092009-01-06 03:36:14 +00004536// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004537def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004538 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004539
Scott Micheldd950092009-01-06 03:36:14 +00004540// sext 16->64: Sign extend halfword to double word
4541def : Pat<(sext_inreg R64C:$rSrc, i16),
4542 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4543
4544def : Pat<(sext R16C:$rSrc),
4545 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4546
Scott Michela59d4692008-02-23 18:41:37 +00004547// zext 16->32: Zero extend halfwords to words
Scott Michel66377522007-12-04 22:35:58 +00004548def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004549 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel66377522007-12-04 22:35:58 +00004550
4551def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michela59d4692008-02-23 18:41:37 +00004552 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel66377522007-12-04 22:35:58 +00004553
4554def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michela59d4692008-02-23 18:41:37 +00004555 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel66377522007-12-04 22:35:58 +00004556
4557def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michela59d4692008-02-23 18:41:37 +00004558 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel66377522007-12-04 22:35:58 +00004559
4560// anyext 16->32: Extend 16->32 bits, irrespective of sign
4561def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004562 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel66377522007-12-04 22:35:58 +00004563
4564//===----------------------------------------------------------------------===//
Scott Michelf0569be2008-12-27 04:51:36 +00004565// Truncates:
4566// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4567// above are custom lowered.
4568//===----------------------------------------------------------------------===//
4569
4570def : Pat<(i8 (trunc GPRC:$src)),
4571 (ORi8_v16i8
4572 (SHUFBgprc GPRC:$src, GPRC:$src,
4573 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4574
4575def : Pat<(i8 (trunc R64C:$src)),
4576 (ORi8_v16i8
4577 (SHUFBv2i64_m32
4578 (ORv2i64_i64 R64C:$src),
4579 (ORv2i64_i64 R64C:$src),
4580 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4581
4582def : Pat<(i8 (trunc R32C:$src)),
4583 (ORi8_v16i8
4584 (SHUFBv4i32_m32
4585 (ORv4i32_i32 R32C:$src),
4586 (ORv4i32_i32 R32C:$src),
4587 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4588
4589def : Pat<(i8 (trunc R16C:$src)),
4590 (ORi8_v16i8
4591 (SHUFBv4i32_m32
4592 (ORv8i16_i16 R16C:$src),
4593 (ORv8i16_i16 R16C:$src),
4594 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4595
4596def : Pat<(i16 (trunc GPRC:$src)),
4597 (ORi16_v8i16
4598 (SHUFBgprc GPRC:$src, GPRC:$src,
4599 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4600
4601def : Pat<(i16 (trunc R64C:$src)),
4602 (ORi16_v8i16
4603 (SHUFBv2i64_m32
4604 (ORv2i64_i64 R64C:$src),
4605 (ORv2i64_i64 R64C:$src),
4606 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4607
4608def : Pat<(i16 (trunc R32C:$src)),
4609 (ORi16_v8i16
4610 (SHUFBv4i32_m32
4611 (ORv4i32_i32 R32C:$src),
4612 (ORv4i32_i32 R32C:$src),
4613 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4614
4615def : Pat<(i32 (trunc GPRC:$src)),
4616 (ORi32_v4i32
4617 (SHUFBgprc GPRC:$src, GPRC:$src,
4618 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4619
4620def : Pat<(i32 (trunc R64C:$src)),
4621 (ORi32_v4i32
4622 (SHUFBv2i64_m32
4623 (ORv2i64_i64 R64C:$src),
4624 (ORv2i64_i64 R64C:$src),
4625 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4626
4627//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00004628// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel66377522007-12-04 22:35:58 +00004629// low parts in order to load them into a register.
4630//===----------------------------------------------------------------------===//
4631
Scott Michel053c1da2008-01-29 02:16:57 +00004632def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4633def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4634def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4635def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4636
4637def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4638 (SPUlo tglobaladdr:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004639 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004640
Scott Michel053c1da2008-01-29 02:16:57 +00004641def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4642 (SPUlo texternalsym:$in, 0)),
4643 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4644
4645def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4646 (SPUlo tjumptable:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004647 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004648
Scott Michel053c1da2008-01-29 02:16:57 +00004649def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4650 (SPUlo tconstpool:$in, 0)),
4651 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4652
4653def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4654 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4655
4656def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4657 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4658
4659def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4660 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4661
4662def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4663 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel66377522007-12-04 22:35:58 +00004664
Scott Michel6e1d1472009-03-16 18:47:25 +00004665// Intrinsics:
Scott Michel66377522007-12-04 22:35:58 +00004666include "CellSDKIntrinsics.td"
Scott Michel02d711b2008-12-30 23:28:25 +00004667// Various math operator instruction sequences
4668include "SPUMathInstr.td"
Scott Michelf0569be2008-12-27 04:51:36 +00004669// 64-bit "instructions"/support
4670include "SPU64InstrInfo.td"
Scott Micheldd950092009-01-06 03:36:14 +00004671// 128-bit "instructions"/support
4672include "SPU128InstrInfo.td"