blob: f1d08867180890986071777404a923b79219973d [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
Scott Michela59d4692008-02-23 18:41:37 +00001471multiclass BitwiseOr
1472{
1473 def v16i8: ORVecInst<v16i8>;
1474 def v8i16: ORVecInst<v8i16>;
1475 def v4i32: ORVecInst<v4i32>;
1476 def v2i64: ORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001477
Scott Michela59d4692008-02-23 18:41:37 +00001478 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1479 [(set (v4f32 VECREG:$rT),
1480 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1481 (v4i32 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001482
Scott Michela59d4692008-02-23 18:41:37 +00001483 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michelf0569be2008-12-27 04:51:36 +00001484 [(set (v2f64 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00001485 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1486 (v2i64 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001487
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001488 def r128: ORRegInst<GPRC>;
1489 def r64: ORRegInst<R64C>;
1490 def r32: ORRegInst<R32C>;
1491 def r16: ORRegInst<R16C>;
1492 def r8: ORRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001493
Scott Michela59d4692008-02-23 18:41:37 +00001494 // OR instructions used to copy f32 and f64 registers.
1495 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1496 [/* no pattern */]>;
Scott Michel504c3692007-12-17 22:32:34 +00001497
Scott Michela59d4692008-02-23 18:41:37 +00001498 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1499 [/* no pattern */]>;
Scott Michel86c041f2007-12-20 00:44:13 +00001500
Scott Michel02d711b2008-12-30 23:28:25 +00001501 // scalar->vector promotion, prefslot2vec:
Scott Michela59d4692008-02-23 18:41:37 +00001502 def v16i8_i8: ORPromoteScalar<R8C>;
1503 def v8i16_i16: ORPromoteScalar<R16C>;
1504 def v4i32_i32: ORPromoteScalar<R32C>;
1505 def v2i64_i64: ORPromoteScalar<R64C>;
1506 def v4f32_f32: ORPromoteScalar<R32FP>;
1507 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel86c041f2007-12-20 00:44:13 +00001508
Scott Michel02d711b2008-12-30 23:28:25 +00001509 // vector->scalar demotion, vec2prefslot:
Scott Michela59d4692008-02-23 18:41:37 +00001510 def i8_v16i8: ORExtractElt<R8C>;
1511 def i16_v8i16: ORExtractElt<R16C>;
1512 def i32_v4i32: ORExtractElt<R32C>;
1513 def i64_v2i64: ORExtractElt<R64C>;
1514 def f32_v4f32: ORExtractElt<R32FP>;
1515 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00001516
Scott Michel6e1d1472009-03-16 18:47:25 +00001517 // Conversion from vector to GPRC
1518 def i128_vec: ORCvtVecGPRC;
1519
1520 // Conversion from GPRC to vector
1521 def vec_i128: ORCvtGPRCVec;
1522
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001523/*
Scott Michel6e1d1472009-03-16 18:47:25 +00001524 // Conversion from register to GPRC
Scott Michelf0569be2008-12-27 04:51:36 +00001525 def i128_r64: ORCvtRegGPRC<R64C>;
1526 def i128_f64: ORCvtRegGPRC<R64FP>;
1527 def i128_r32: ORCvtRegGPRC<R32C>;
1528 def i128_f32: ORCvtRegGPRC<R32FP>;
1529 def i128_r16: ORCvtRegGPRC<R16C>;
1530 def i128_r8: ORCvtRegGPRC<R8C>;
1531
Scott Michel6e1d1472009-03-16 18:47:25 +00001532 // Conversion from GPRC to register
Scott Michelf0569be2008-12-27 04:51:36 +00001533 def r64_i128: ORCvtGPRCReg<R64C>;
1534 def f64_i128: ORCvtGPRCReg<R64FP>;
1535 def r32_i128: ORCvtGPRCReg<R32C>;
1536 def f32_i128: ORCvtGPRCReg<R32FP>;
1537 def r16_i128: ORCvtGPRCReg<R16C>;
1538 def r8_i128: ORCvtGPRCReg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001539*/
1540/*
Scott Micheldd950092009-01-06 03:36:14 +00001541 // Conversion from register to R32C:
Scott Michel6e1d1472009-03-16 18:47:25 +00001542 def r32_r16: ORCvtFormRegR32<R16C>;
1543 def r32_r8: ORCvtFormRegR32<R8C>;
Scott Micheldd950092009-01-06 03:36:14 +00001544
1545 // Conversion from R32C to register
1546 def r32_r16: ORCvtFormR32Reg<R16C>;
1547 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001548*/
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001549
Scott Michel6e1d1472009-03-16 18:47:25 +00001550 // Conversion from R64C to register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001551 def r32_r64: ORCvtFormR64Reg<R32C>;
1552 // def r16_r64: ORCvtFormR64Reg<R16C>;
1553 // def r8_r64: ORCvtFormR64Reg<R8C>;
1554
Scott Michel6e1d1472009-03-16 18:47:25 +00001555 // Conversion to R64C from register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001556 def r64_r32: ORCvtFormRegR64<R32C>;
1557 // def r64_r16: ORCvtFormRegR64<R16C>;
1558 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001559
1560 // bitconvert patterns:
1561 def r32_f32: ORCvtFormR32Reg<R32FP,
1562 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1563 def f32_r32: ORCvtFormRegR32<R32FP,
1564 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1565
1566 def r64_f64: ORCvtFormR64Reg<R64FP,
1567 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1568 def f64_r64: ORCvtFormRegR64<R64FP,
1569 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michela59d4692008-02-23 18:41:37 +00001570}
Scott Michel504c3692007-12-17 22:32:34 +00001571
Scott Michela59d4692008-02-23 18:41:37 +00001572defm OR : BitwiseOr;
1573
Scott Michelf0569be2008-12-27 04:51:36 +00001574// scalar->vector promotion patterns (preferred slot to vector):
1575def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1576 (ORv16i8_i8 R8C:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001577
Scott Michelf0569be2008-12-27 04:51:36 +00001578def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1579 (ORv8i16_i16 R16C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001580
Scott Michelf0569be2008-12-27 04:51:36 +00001581def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1582 (ORv4i32_i32 R32C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001583
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001584def : Pat<(v2i32 (SPUprefslot2vec R32C:$rA)),
1585 (ORv4i32_i32 R32C:$rA)>;
1586
Scott Michelf0569be2008-12-27 04:51:36 +00001587def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1588 (ORv2i64_i64 R64C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001589
Scott Michelf0569be2008-12-27 04:51:36 +00001590def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1591 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001592
Kalle Raiskilae1c91592010-08-02 11:22:10 +00001593def : Pat<(v2f32 (SPUprefslot2vec R32FP:$rA)),
1594 (ORv4f32_f32 R32FP:$rA)>;
1595
Scott Michelf0569be2008-12-27 04:51:36 +00001596def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1597 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001598
Scott Michelf0569be2008-12-27 04:51:36 +00001599// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1600// known as converting the vector back to its preferred slot
Scott Michel504c3692007-12-17 22:32:34 +00001601
Scott Michel104de432008-11-24 17:11:17 +00001602def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001603 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001604
Scott Michel104de432008-11-24 17:11:17 +00001605def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001606 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001607
Scott Michel104de432008-11-24 17:11:17 +00001608def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001609 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001610
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001611def : Pat<(SPUvec2prefslot (v2i32 VECREG:$rA)),
1612 (ORi32_v4i32 VECREG:$rA)>;
1613
Scott Michel104de432008-11-24 17:11:17 +00001614def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001615 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001616
Scott Michel104de432008-11-24 17:11:17 +00001617def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001618 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001619
Kalle Raiskilae1c91592010-08-02 11:22:10 +00001620def : Pat<(SPUvec2prefslot (v2f32 VECREG:$rA)),
1621 (ORf32_v4f32 VECREG:$rA)>;
1622
Scott Michel104de432008-11-24 17:11:17 +00001623def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001624 (ORf64_v2f64 VECREG:$rA)>;
1625
1626// Load Register: This is an assembler alias for a bitwise OR of a register
1627// against itself. It's here because it brings some clarity to assembly
1628// language output.
1629
1630let hasCtrlDep = 1 in {
1631 class LRInst<dag OOL, dag IOL>
1632 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1633 bits<7> RA;
1634 bits<7> RT;
1635
1636 let Pattern = [/*no pattern*/];
1637
1638 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1639 let Inst{11-17} = RA;
1640 let Inst{18-24} = RA;
1641 let Inst{25-31} = RT;
1642 }
1643
1644 class LRVecInst<ValueType vectype>:
1645 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1646
1647 class LRRegInst<RegisterClass rclass>:
1648 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1649
1650 multiclass LoadRegister {
1651 def v2i64: LRVecInst<v2i64>;
1652 def v2f64: LRVecInst<v2f64>;
1653 def v4i32: LRVecInst<v4i32>;
1654 def v4f32: LRVecInst<v4f32>;
1655 def v8i16: LRVecInst<v8i16>;
1656 def v16i8: LRVecInst<v16i8>;
1657
1658 def r128: LRRegInst<GPRC>;
1659 def r64: LRRegInst<R64C>;
1660 def f64: LRRegInst<R64FP>;
1661 def r32: LRRegInst<R32C>;
1662 def f32: LRRegInst<R32FP>;
1663 def r16: LRRegInst<R16C>;
1664 def r8: LRRegInst<R8C>;
1665 }
1666
1667 defm LR: LoadRegister;
1668}
Scott Michel66377522007-12-04 22:35:58 +00001669
Scott Michela59d4692008-02-23 18:41:37 +00001670// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel66377522007-12-04 22:35:58 +00001671
Scott Michela59d4692008-02-23 18:41:37 +00001672class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1673 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1674 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001675
Scott Michela59d4692008-02-23 18:41:37 +00001676class ORCVecInst<ValueType vectype>:
1677 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1678 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1679 (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001680
Scott Michela59d4692008-02-23 18:41:37 +00001681class ORCRegInst<RegisterClass rclass>:
1682 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1683 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001684
Scott Michela59d4692008-02-23 18:41:37 +00001685multiclass BitwiseOrComplement
1686{
1687 def v16i8: ORCVecInst<v16i8>;
1688 def v8i16: ORCVecInst<v8i16>;
1689 def v4i32: ORCVecInst<v4i32>;
1690 def v2i64: ORCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001691
Scott Michel6e1d1472009-03-16 18:47:25 +00001692 def r128: ORCRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00001693 def r64: ORCRegInst<R64C>;
1694 def r32: ORCRegInst<R32C>;
1695 def r16: ORCRegInst<R16C>;
1696 def r8: ORCRegInst<R8C>;
1697}
1698
1699defm ORC : BitwiseOrComplement;
Scott Michel504c3692007-12-17 22:32:34 +00001700
Scott Michel66377522007-12-04 22:35:58 +00001701// OR byte immediate
Scott Michela59d4692008-02-23 18:41:37 +00001702class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1703 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1704 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001705
Scott Michela59d4692008-02-23 18:41:37 +00001706class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1707 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1708 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1709 (vectype immpred:$val)))]>;
1710
1711multiclass BitwiseOrByteImm
1712{
1713 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1714
1715 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1716 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1717}
1718
1719defm ORBI : BitwiseOrByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001720
Scott Michel66377522007-12-04 22:35:58 +00001721// OR halfword immediate
Scott Michela59d4692008-02-23 18:41:37 +00001722class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1723 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1724 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001725
Scott Michela59d4692008-02-23 18:41:37 +00001726class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1727 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1728 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1729 immpred:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001730
Scott Michela59d4692008-02-23 18:41:37 +00001731multiclass BitwiseOrHalfwordImm
1732{
1733 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1734
1735 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1736 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1737
1738 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1739 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1740 [(set R16C:$rT, (or (anyext R8C:$rA),
1741 i16ImmSExt10:$val))]>;
1742}
1743
1744defm ORHI : BitwiseOrHalfwordImm;
1745
1746class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1747 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1748 IntegerOp, pattern>;
1749
1750class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1751 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1752 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1753 immpred:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001754
1755// Bitwise "or" with immediate
Scott Michela59d4692008-02-23 18:41:37 +00001756multiclass BitwiseOrImm
1757{
1758 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel66377522007-12-04 22:35:58 +00001759
Scott Michela59d4692008-02-23 18:41:37 +00001760 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1761 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001762
Scott Michela59d4692008-02-23 18:41:37 +00001763 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1764 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1765 // infra "anyext 16->32" pattern.)
1766 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1767 [(set R32C:$rT, (or (anyext R16C:$rA),
1768 i32ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001769
Scott Michela59d4692008-02-23 18:41:37 +00001770 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1771 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1772 // infra "anyext 16->32" pattern.)
1773 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1774 [(set R32C:$rT, (or (anyext R8C:$rA),
1775 i32ImmSExt10:$val))]>;
1776}
Scott Michel66377522007-12-04 22:35:58 +00001777
Scott Michela59d4692008-02-23 18:41:37 +00001778defm ORI : BitwiseOrImm;
Scott Michel504c3692007-12-17 22:32:34 +00001779
Scott Michel66377522007-12-04 22:35:58 +00001780// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1781// $rT[0], slots 1-3 are zeroed.
1782//
Scott Michel504c3692007-12-17 22:32:34 +00001783// FIXME: Needs to match an intrinsic pattern.
Scott Michel66377522007-12-04 22:35:58 +00001784def ORXv4i32:
1785 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1786 "orx\t$rT, $rA, $rB", IntegerOp,
1787 []>;
1788
Scott Michel504c3692007-12-17 22:32:34 +00001789// XOR:
Scott Michel66377522007-12-04 22:35:58 +00001790
Scott Michelad2715e2008-03-05 23:02:02 +00001791class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1792 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1793 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001794
Scott Michelad2715e2008-03-05 23:02:02 +00001795class XORVecInst<ValueType vectype>:
1796 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1797 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1798 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001799
Scott Michelad2715e2008-03-05 23:02:02 +00001800class XORRegInst<RegisterClass rclass>:
1801 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1802 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1803
1804multiclass BitwiseExclusiveOr
1805{
1806 def v16i8: XORVecInst<v16i8>;
1807 def v8i16: XORVecInst<v8i16>;
1808 def v4i32: XORVecInst<v4i32>;
1809 def v2i64: XORVecInst<v2i64>;
1810
1811 def r128: XORRegInst<GPRC>;
1812 def r64: XORRegInst<R64C>;
1813 def r32: XORRegInst<R32C>;
1814 def r16: XORRegInst<R16C>;
1815 def r8: XORRegInst<R8C>;
Scott Michela82d3f72009-03-17 16:45:16 +00001816
1817 // XOR instructions used to negate f32 and f64 quantities.
1818
1819 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1820 [/* no pattern */]>;
1821
1822 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1823 [/* no pattern */]>;
1824
1825 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1826 [/* no pattern, see fneg{32,64} */]>;
Scott Michelad2715e2008-03-05 23:02:02 +00001827}
1828
1829defm XOR : BitwiseExclusiveOr;
Scott Michel66377522007-12-04 22:35:58 +00001830
1831//==----------------------------------------------------------
Scott Michel504c3692007-12-17 22:32:34 +00001832
Scott Michela59d4692008-02-23 18:41:37 +00001833class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1834 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1835 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001836
Scott Michela59d4692008-02-23 18:41:37 +00001837multiclass XorByteImm
1838{
1839 def v16i8:
1840 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1841 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1842
1843 def r8:
1844 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1845 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1846}
1847
1848defm XORBI : XorByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001849
Scott Michel66377522007-12-04 22:35:58 +00001850def XORHIv8i16:
Scott Michela59d4692008-02-23 18:41:37 +00001851 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel66377522007-12-04 22:35:58 +00001852 "xorhi\t$rT, $rA, $val", IntegerOp,
1853 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1854 v8i16SExt10Imm:$val))]>;
1855
1856def XORHIr16:
1857 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1858 "xorhi\t$rT, $rA, $val", IntegerOp,
1859 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1860
1861def XORIv4i32:
Scott Michel78c47fa2008-03-10 16:58:52 +00001862 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel66377522007-12-04 22:35:58 +00001863 "xori\t$rT, $rA, $val", IntegerOp,
1864 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1865 v4i32SExt10Imm:$val))]>;
1866
1867def XORIr32:
1868 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1869 "xori\t$rT, $rA, $val", IntegerOp,
1870 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1871
1872// NAND:
Scott Michel66377522007-12-04 22:35:58 +00001873
Scott Michel6e1d1472009-03-16 18:47:25 +00001874class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1875 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1876 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001877
Scott Michel6e1d1472009-03-16 18:47:25 +00001878class NANDVecInst<ValueType vectype>:
1879 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1880 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1881 (vectype VECREG:$rB))))]>;
1882class NANDRegInst<RegisterClass rclass>:
1883 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1884 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001885
Scott Michel6e1d1472009-03-16 18:47:25 +00001886multiclass BitwiseNand
1887{
1888 def v16i8: NANDVecInst<v16i8>;
1889 def v8i16: NANDVecInst<v8i16>;
1890 def v4i32: NANDVecInst<v4i32>;
1891 def v2i64: NANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001892
Scott Michel6e1d1472009-03-16 18:47:25 +00001893 def r128: NANDRegInst<GPRC>;
1894 def r64: NANDRegInst<R64C>;
1895 def r32: NANDRegInst<R32C>;
1896 def r16: NANDRegInst<R16C>;
1897 def r8: NANDRegInst<R8C>;
1898}
Scott Michel66377522007-12-04 22:35:58 +00001899
Scott Michel6e1d1472009-03-16 18:47:25 +00001900defm NAND : BitwiseNand;
Scott Michel504c3692007-12-17 22:32:34 +00001901
Scott Michel66377522007-12-04 22:35:58 +00001902// NOR:
Scott Michel66377522007-12-04 22:35:58 +00001903
Scott Michel6e1d1472009-03-16 18:47:25 +00001904class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1905 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1906 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001907
Scott Michel6e1d1472009-03-16 18:47:25 +00001908class NORVecInst<ValueType vectype>:
1909 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1910 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1911 (vectype VECREG:$rB))))]>;
1912class NORRegInst<RegisterClass rclass>:
1913 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1914 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001915
Scott Michel6e1d1472009-03-16 18:47:25 +00001916multiclass BitwiseNor
1917{
1918 def v16i8: NORVecInst<v16i8>;
1919 def v8i16: NORVecInst<v8i16>;
1920 def v4i32: NORVecInst<v4i32>;
1921 def v2i64: NORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001922
Scott Michel6e1d1472009-03-16 18:47:25 +00001923 def r128: NORRegInst<GPRC>;
1924 def r64: NORRegInst<R64C>;
1925 def r32: NORRegInst<R32C>;
1926 def r16: NORRegInst<R16C>;
1927 def r8: NORRegInst<R8C>;
1928}
Scott Michel66377522007-12-04 22:35:58 +00001929
Scott Michel6e1d1472009-03-16 18:47:25 +00001930defm NOR : BitwiseNor;
Scott Michel504c3692007-12-17 22:32:34 +00001931
Scott Michel66377522007-12-04 22:35:58 +00001932// Select bits:
Scott Michelad2715e2008-03-05 23:02:02 +00001933class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1934 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1935 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001936
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001937class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michelad2715e2008-03-05 23:02:02 +00001938 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1939 [(set (vectype VECREG:$rT),
1940 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001941 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michelad2715e2008-03-05 23:02:02 +00001942 (vectype VECREG:$rA))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001943
Scott Michel02d711b2008-12-30 23:28:25 +00001944class SELBVecVCondInst<ValueType vectype>:
1945 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1946 [(set (vectype VECREG:$rT),
1947 (select (vectype VECREG:$rC),
1948 (vectype VECREG:$rB),
1949 (vectype VECREG:$rA)))]>;
1950
Scott Michelf0569be2008-12-27 04:51:36 +00001951class SELBVecCondInst<ValueType vectype>:
1952 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1953 [(set (vectype VECREG:$rT),
1954 (select R32C:$rC,
1955 (vectype VECREG:$rB),
1956 (vectype VECREG:$rA)))]>;
1957
Scott Michelad2715e2008-03-05 23:02:02 +00001958class SELBRegInst<RegisterClass rclass>:
1959 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1960 [(set rclass:$rT,
Scott Michel1df30c42008-12-29 03:23:36 +00001961 (or (and rclass:$rB, rclass:$rC),
1962 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001963
Scott Michelf0569be2008-12-27 04:51:36 +00001964class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1965 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1966 [(set rclass:$rT,
1967 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1968
Scott Michelad2715e2008-03-05 23:02:02 +00001969multiclass SelectBits
1970{
1971 def v16i8: SELBVecInst<v16i8>;
1972 def v8i16: SELBVecInst<v8i16>;
1973 def v4i32: SELBVecInst<v4i32>;
Chris Lattner918472a2010-03-28 07:48:17 +00001974 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel66377522007-12-04 22:35:58 +00001975
Scott Michelad2715e2008-03-05 23:02:02 +00001976 def r128: SELBRegInst<GPRC>;
1977 def r64: SELBRegInst<R64C>;
1978 def r32: SELBRegInst<R32C>;
1979 def r16: SELBRegInst<R16C>;
1980 def r8: SELBRegInst<R8C>;
Scott Michelf0569be2008-12-27 04:51:36 +00001981
1982 def v16i8_cond: SELBVecCondInst<v16i8>;
1983 def v8i16_cond: SELBVecCondInst<v8i16>;
1984 def v4i32_cond: SELBVecCondInst<v4i32>;
1985 def v2i64_cond: SELBVecCondInst<v2i64>;
1986
Scott Michel02d711b2008-12-30 23:28:25 +00001987 def v16i8_vcond: SELBVecCondInst<v16i8>;
1988 def v8i16_vcond: SELBVecCondInst<v8i16>;
1989 def v4i32_vcond: SELBVecCondInst<v4i32>;
1990 def v2i64_vcond: SELBVecCondInst<v2i64>;
1991
1992 def v4f32_cond:
Scott Michel19c10e62009-01-26 03:37:41 +00001993 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1994 [(set (v4f32 VECREG:$rT),
1995 (select (v4i32 VECREG:$rC),
1996 (v4f32 VECREG:$rB),
1997 (v4f32 VECREG:$rA)))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00001998
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001999 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michelf0569be2008-12-27 04:51:36 +00002000 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel02d711b2008-12-30 23:28:25 +00002001 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00002002 def r16_cond: SELBRegCondInst<R16C, R16C>;
2003 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michelad2715e2008-03-05 23:02:02 +00002004}
Scott Michel66377522007-12-04 22:35:58 +00002005
Scott Michelad2715e2008-03-05 23:02:02 +00002006defm SELB : SelectBits;
Scott Michel66377522007-12-04 22:35:58 +00002007
Scott Michel7a1c9e92008-11-22 23:50:42 +00002008class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michelad2715e2008-03-05 23:02:02 +00002009 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
2010 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel66377522007-12-04 22:35:58 +00002011
Scott Michel7a1c9e92008-11-22 23:50:42 +00002012def : SPUselbPatVec<v16i8, SELBv16i8>;
2013def : SPUselbPatVec<v8i16, SELBv8i16>;
2014def : SPUselbPatVec<v4i32, SELBv4i32>;
2015def : SPUselbPatVec<v2i64, SELBv2i64>;
2016
2017class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
2018 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
2019 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
2020
2021def : SPUselbPatReg<R8C, SELBr8>;
2022def : SPUselbPatReg<R16C, SELBr16>;
2023def : SPUselbPatReg<R32C, SELBr32>;
2024def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel66377522007-12-04 22:35:58 +00002025
Scott Michelad2715e2008-03-05 23:02:02 +00002026// EQV: Equivalence (1 for each same bit, otherwise 0)
2027//
2028// Note: There are a lot of ways to match this bit operator and these patterns
2029// attempt to be as exhaustive as possible.
Scott Michel66377522007-12-04 22:35:58 +00002030
Scott Michelad2715e2008-03-05 23:02:02 +00002031class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2032 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2033 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002034
Scott Michelad2715e2008-03-05 23:02:02 +00002035class EQVVecInst<ValueType vectype>:
2036 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2037 [(set (vectype VECREG:$rT),
2038 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2039 (and (vnot (vectype VECREG:$rA)),
2040 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002041
Scott Michelad2715e2008-03-05 23:02:02 +00002042class EQVRegInst<RegisterClass rclass>:
2043 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2044 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2045 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002046
Scott Michelad2715e2008-03-05 23:02:02 +00002047class EQVVecPattern1<ValueType vectype>:
2048 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2049 [(set (vectype VECREG:$rT),
2050 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002051
Scott Michelad2715e2008-03-05 23:02:02 +00002052class EQVRegPattern1<RegisterClass rclass>:
2053 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2054 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002055
Scott Michelad2715e2008-03-05 23:02:02 +00002056class EQVVecPattern2<ValueType vectype>:
2057 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2058 [(set (vectype VECREG:$rT),
2059 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2060 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002061
Scott Michelad2715e2008-03-05 23:02:02 +00002062class EQVRegPattern2<RegisterClass rclass>:
2063 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2064 [(set rclass:$rT,
2065 (or (and rclass:$rA, rclass:$rB),
2066 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002067
Scott Michelad2715e2008-03-05 23:02:02 +00002068class EQVVecPattern3<ValueType vectype>:
2069 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2070 [(set (vectype VECREG:$rT),
2071 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002072
Scott Michelad2715e2008-03-05 23:02:02 +00002073class EQVRegPattern3<RegisterClass rclass>:
2074 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2075 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002076
Scott Michelad2715e2008-03-05 23:02:02 +00002077multiclass BitEquivalence
2078{
2079 def v16i8: EQVVecInst<v16i8>;
2080 def v8i16: EQVVecInst<v8i16>;
2081 def v4i32: EQVVecInst<v4i32>;
2082 def v2i64: EQVVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002083
Scott Michelad2715e2008-03-05 23:02:02 +00002084 def v16i8_1: EQVVecPattern1<v16i8>;
2085 def v8i16_1: EQVVecPattern1<v8i16>;
2086 def v4i32_1: EQVVecPattern1<v4i32>;
2087 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002088
Scott Michelad2715e2008-03-05 23:02:02 +00002089 def v16i8_2: EQVVecPattern2<v16i8>;
2090 def v8i16_2: EQVVecPattern2<v8i16>;
2091 def v4i32_2: EQVVecPattern2<v4i32>;
2092 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002093
Scott Michelad2715e2008-03-05 23:02:02 +00002094 def v16i8_3: EQVVecPattern3<v16i8>;
2095 def v8i16_3: EQVVecPattern3<v8i16>;
2096 def v4i32_3: EQVVecPattern3<v4i32>;
2097 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002098
Scott Michelad2715e2008-03-05 23:02:02 +00002099 def r128: EQVRegInst<GPRC>;
2100 def r64: EQVRegInst<R64C>;
2101 def r32: EQVRegInst<R32C>;
2102 def r16: EQVRegInst<R16C>;
2103 def r8: EQVRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002104
Scott Michelad2715e2008-03-05 23:02:02 +00002105 def r128_1: EQVRegPattern1<GPRC>;
2106 def r64_1: EQVRegPattern1<R64C>;
2107 def r32_1: EQVRegPattern1<R32C>;
2108 def r16_1: EQVRegPattern1<R16C>;
2109 def r8_1: EQVRegPattern1<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002110
Scott Michelad2715e2008-03-05 23:02:02 +00002111 def r128_2: EQVRegPattern2<GPRC>;
2112 def r64_2: EQVRegPattern2<R64C>;
2113 def r32_2: EQVRegPattern2<R32C>;
2114 def r16_2: EQVRegPattern2<R16C>;
2115 def r8_2: EQVRegPattern2<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002116
Scott Michelad2715e2008-03-05 23:02:02 +00002117 def r128_3: EQVRegPattern3<GPRC>;
2118 def r64_3: EQVRegPattern3<R64C>;
2119 def r32_3: EQVRegPattern3<R32C>;
2120 def r16_3: EQVRegPattern3<R16C>;
2121 def r8_3: EQVRegPattern3<R8C>;
2122}
Scott Michel504c3692007-12-17 22:32:34 +00002123
Scott Michelad2715e2008-03-05 23:02:02 +00002124defm EQV: BitEquivalence;
Scott Michel66377522007-12-04 22:35:58 +00002125
2126//===----------------------------------------------------------------------===//
2127// Vector shuffle...
2128//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002129// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2130// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2131// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2132// the SPUISD::SHUFB opcode.
Scott Michela59d4692008-02-23 18:41:37 +00002133//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002134
Scott Michela59d4692008-02-23 18:41:37 +00002135class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2136 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2137 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002138
Scott Michel1a6cdb62008-12-01 17:56:02 +00002139class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michela59d4692008-02-23 18:41:37 +00002140 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel1a6cdb62008-12-01 17:56:02 +00002141 [(set (resultvec VECREG:$rT),
2142 (SPUshuffle (resultvec VECREG:$rA),
2143 (resultvec VECREG:$rB),
2144 (maskvec VECREG:$rC)))]>;
Scott Michel86c041f2007-12-20 00:44:13 +00002145
Scott Michelf0569be2008-12-27 04:51:36 +00002146class SHUFBGPRCInst:
2147 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2148 [/* no pattern */]>;
2149
Scott Michela59d4692008-02-23 18:41:37 +00002150multiclass ShuffleBytes
2151{
Scott Michel1a6cdb62008-12-01 17:56:02 +00002152 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2153 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2154 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2155 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2156 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2157 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
Kalle Raiskila82fe4672010-08-02 08:54:39 +00002158 def v2i32 : SHUFBVecInst<v2i32, v16i8>;
2159 def v2i32_m32 : SHUFBVecInst<v2i32, v4i32>;
Scott Michel1a6cdb62008-12-01 17:56:02 +00002160 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2161 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel66377522007-12-04 22:35:58 +00002162
Scott Michel1a6cdb62008-12-01 17:56:02 +00002163 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2164 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
Kalle Raiskilae1c91592010-08-02 11:22:10 +00002165 def v2f32 : SHUFBVecInst<v2f32, v16i8>;
2166 def v2f32_m32 : SHUFBVecInst<v2f32, v4i32>;
Scott Michel1a6cdb62008-12-01 17:56:02 +00002167
2168 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2169 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michelf0569be2008-12-27 04:51:36 +00002170
2171 def gprc : SHUFBGPRCInst;
Scott Michela59d4692008-02-23 18:41:37 +00002172}
2173
2174defm SHUFB : ShuffleBytes;
2175
Scott Michel66377522007-12-04 22:35:58 +00002176//===----------------------------------------------------------------------===//
2177// Shift and rotate group:
2178//===----------------------------------------------------------------------===//
2179
Scott Michela59d4692008-02-23 18:41:37 +00002180class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2181 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2182 RotateShift, pattern>;
2183
2184class SHLHVecInst<ValueType vectype>:
2185 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2186 [(set (vectype VECREG:$rT),
2187 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002188
Scott Michela59d4692008-02-23 18:41:37 +00002189multiclass ShiftLeftHalfword
2190{
2191 def v8i16: SHLHVecInst<v8i16>;
2192 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2193 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2194 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2195 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2196}
Scott Michel66377522007-12-04 22:35:58 +00002197
Scott Michela59d4692008-02-23 18:41:37 +00002198defm SHLH : ShiftLeftHalfword;
Scott Michel66377522007-12-04 22:35:58 +00002199
Scott Michela59d4692008-02-23 18:41:37 +00002200//===----------------------------------------------------------------------===//
Scott Michel504c3692007-12-17 22:32:34 +00002201
Scott Michela59d4692008-02-23 18:41:37 +00002202class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2203 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2204 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002205
Scott Michela59d4692008-02-23 18:41:37 +00002206class SHLHIVecInst<ValueType vectype>:
2207 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2208 [(set (vectype VECREG:$rT),
2209 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002210
Scott Michela59d4692008-02-23 18:41:37 +00002211multiclass ShiftLeftHalfwordImm
2212{
2213 def v8i16: SHLHIVecInst<v8i16>;
2214 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2215 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2216}
2217
2218defm SHLHI : ShiftLeftHalfwordImm;
2219
2220def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002221 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michela59d4692008-02-23 18:41:37 +00002222
2223def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002224 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002225
Scott Michela59d4692008-02-23 18:41:37 +00002226//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002227
Scott Michela59d4692008-02-23 18:41:37 +00002228class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2229 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2230 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002231
Scott Michela59d4692008-02-23 18:41:37 +00002232multiclass ShiftLeftWord
2233{
2234 def v4i32:
2235 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2236 [(set (v4i32 VECREG:$rT),
2237 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2238 def r32:
2239 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2240 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2241}
Scott Michel66377522007-12-04 22:35:58 +00002242
Scott Michela59d4692008-02-23 18:41:37 +00002243defm SHL: ShiftLeftWord;
Scott Michel504c3692007-12-17 22:32:34 +00002244
Scott Michela59d4692008-02-23 18:41:37 +00002245//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002246
Scott Michela59d4692008-02-23 18:41:37 +00002247class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2248 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2249 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002250
Scott Michela59d4692008-02-23 18:41:37 +00002251multiclass ShiftLeftWordImm
2252{
2253 def v4i32:
2254 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2255 [(set (v4i32 VECREG:$rT),
2256 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002257
Scott Michela59d4692008-02-23 18:41:37 +00002258 def r32:
2259 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2260 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2261}
Scott Michel66377522007-12-04 22:35:58 +00002262
Scott Michela59d4692008-02-23 18:41:37 +00002263defm SHLI : ShiftLeftWordImm;
Scott Michel504c3692007-12-17 22:32:34 +00002264
Scott Michela59d4692008-02-23 18:41:37 +00002265//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002266// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2267// register) to the left. Vector form is here to ensure type correctness.
Scott Michela59d4692008-02-23 18:41:37 +00002268//
2269// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2270// of 7 bits is actually possible.
2271//
2272// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2273// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2274// bytes with SHLQBY.
Scott Michel66377522007-12-04 22:35:58 +00002275
Scott Michela59d4692008-02-23 18:41:37 +00002276class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2277 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2278 RotateShift, pattern>;
2279
2280class SHLQBIVecInst<ValueType vectype>:
2281 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2282 [(set (vectype VECREG:$rT),
2283 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2284
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002285class SHLQBIRegInst<RegisterClass rclass>:
2286 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2287 [/* no pattern */]>;
2288
Scott Michela59d4692008-02-23 18:41:37 +00002289multiclass ShiftLeftQuadByBits
2290{
2291 def v16i8: SHLQBIVecInst<v16i8>;
2292 def v8i16: SHLQBIVecInst<v8i16>;
2293 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002294 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002295 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002296 def v2f64: SHLQBIVecInst<v2f64>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002297
2298 def r128: SHLQBIRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00002299}
2300
2301defm SHLQBI : ShiftLeftQuadByBits;
2302
2303// See note above on SHLQBI. In this case, the predicate actually does then
2304// enforcement, whereas with SHLQBI, we have to "take it on faith."
2305class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2306 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2307 RotateShift, pattern>;
2308
2309class SHLQBIIVecInst<ValueType vectype>:
2310 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2311 [(set (vectype VECREG:$rT),
2312 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2313
2314multiclass ShiftLeftQuadByBitsImm
2315{
2316 def v16i8 : SHLQBIIVecInst<v16i8>;
2317 def v8i16 : SHLQBIIVecInst<v8i16>;
2318 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002319 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002320 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002321 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002322}
2323
2324defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel66377522007-12-04 22:35:58 +00002325
2326// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michela59d4692008-02-23 18:41:37 +00002327// not by bits. See notes above on SHLQBI.
Scott Michel66377522007-12-04 22:35:58 +00002328
Scott Michela59d4692008-02-23 18:41:37 +00002329class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel662165d2008-11-25 00:23:16 +00002330 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00002331 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002332
Scott Michela59d4692008-02-23 18:41:37 +00002333class SHLQBYVecInst<ValueType vectype>:
2334 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2335 [(set (vectype VECREG:$rT),
2336 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002337
Scott Michela59d4692008-02-23 18:41:37 +00002338multiclass ShiftLeftQuadBytes
2339{
2340 def v16i8: SHLQBYVecInst<v16i8>;
2341 def v8i16: SHLQBYVecInst<v8i16>;
2342 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002343 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002344 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002345 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002346 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2347 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2348}
Scott Michel66377522007-12-04 22:35:58 +00002349
Scott Michela59d4692008-02-23 18:41:37 +00002350defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel66377522007-12-04 22:35:58 +00002351
Scott Michela59d4692008-02-23 18:41:37 +00002352class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2353 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2354 RotateShift, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00002355
Scott Michela59d4692008-02-23 18:41:37 +00002356class SHLQBYIVecInst<ValueType vectype>:
2357 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2358 [(set (vectype VECREG:$rT),
2359 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002360
Scott Michela59d4692008-02-23 18:41:37 +00002361multiclass ShiftLeftQuadBytesImm
2362{
2363 def v16i8: SHLQBYIVecInst<v16i8>;
2364 def v8i16: SHLQBYIVecInst<v8i16>;
2365 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002366 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002367 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002368 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002369 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2370 [(set GPRC:$rT,
2371 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2372}
Scott Michel504c3692007-12-17 22:32:34 +00002373
Scott Michela59d4692008-02-23 18:41:37 +00002374defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel504c3692007-12-17 22:32:34 +00002375
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002376class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2377 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2378 RotateShift, pattern>;
2379
2380class SHLQBYBIVecInst<ValueType vectype>:
2381 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2382 [/* no pattern */]>;
2383
2384class SHLQBYBIRegInst<RegisterClass rclass>:
2385 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2386 [/* no pattern */]>;
2387
2388multiclass ShiftLeftQuadBytesBitCount
2389{
2390 def v16i8: SHLQBYBIVecInst<v16i8>;
2391 def v8i16: SHLQBYBIVecInst<v8i16>;
2392 def v4i32: SHLQBYBIVecInst<v4i32>;
2393 def v4f32: SHLQBYBIVecInst<v4f32>;
2394 def v2i64: SHLQBYBIVecInst<v2i64>;
2395 def v2f64: SHLQBYBIVecInst<v2f64>;
2396
2397 def r128: SHLQBYBIRegInst<GPRC>;
2398}
2399
2400defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2401
Scott Michela59d4692008-02-23 18:41:37 +00002402//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2403// Rotate halfword:
2404//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2405class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2406 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2407 RotateShift, pattern>;
2408
2409class ROTHVecInst<ValueType vectype>:
2410 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2411 [(set (vectype VECREG:$rT),
Chris Lattnerdd6fbd12010-03-08 18:59:49 +00002412 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michela59d4692008-02-23 18:41:37 +00002413
2414class ROTHRegInst<RegisterClass rclass>:
2415 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2416 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2417
2418multiclass RotateLeftHalfword
2419{
2420 def v8i16: ROTHVecInst<v8i16>;
2421 def r16: ROTHRegInst<R16C>;
2422}
2423
2424defm ROTH: RotateLeftHalfword;
2425
2426def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2427 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2428
2429//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2430// Rotate halfword, immediate:
2431//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2432class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2433 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2434 RotateShift, pattern>;
2435
2436class ROTHIVecInst<ValueType vectype>:
2437 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2438 [(set (vectype VECREG:$rT),
2439 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2440
2441multiclass RotateLeftHalfwordImm
2442{
2443 def v8i16: ROTHIVecInst<v8i16>;
2444 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2445 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2446 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2447 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2448}
2449
2450defm ROTHI: RotateLeftHalfwordImm;
2451
Chris Lattner420c69d2010-03-15 05:53:47 +00002452def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2453 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002454
Scott Michela59d4692008-02-23 18:41:37 +00002455//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2456// Rotate word:
2457//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002458
Scott Michela59d4692008-02-23 18:41:37 +00002459class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2460 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2461 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002462
Scott Michela59d4692008-02-23 18:41:37 +00002463class ROTVecInst<ValueType vectype>:
2464 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2465 [(set (vectype VECREG:$rT),
2466 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002467
Scott Michela59d4692008-02-23 18:41:37 +00002468class ROTRegInst<RegisterClass rclass>:
2469 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2470 [(set rclass:$rT,
2471 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002472
Scott Michela59d4692008-02-23 18:41:37 +00002473multiclass RotateLeftWord
2474{
2475 def v4i32: ROTVecInst<v4i32>;
2476 def r32: ROTRegInst<R32C>;
2477}
2478
2479defm ROT: RotateLeftWord;
Scott Michel66377522007-12-04 22:35:58 +00002480
Scott Michel504c3692007-12-17 22:32:34 +00002481// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2482// 32-bit register
2483def ROTr32_r16_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002484 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2485 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002486
2487def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2488 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2489
2490def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2491 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2492
2493def ROTr32_r8_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002494 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2495 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002496
2497def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2498 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2499
2500def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2501 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2502
Scott Michela59d4692008-02-23 18:41:37 +00002503//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2504// Rotate word, immediate
2505//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002506
Scott Michela59d4692008-02-23 18:41:37 +00002507class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2508 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2509 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002510
Scott Michela59d4692008-02-23 18:41:37 +00002511class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2512 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2513 [(set (vectype VECREG:$rT),
2514 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002515
Scott Michela59d4692008-02-23 18:41:37 +00002516class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2517 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2518 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002519
Scott Michela59d4692008-02-23 18:41:37 +00002520multiclass RotateLeftWordImm
2521{
2522 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2523 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2524 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel66377522007-12-04 22:35:58 +00002525
Scott Michela59d4692008-02-23 18:41:37 +00002526 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2527 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2528 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2529}
Scott Michel504c3692007-12-17 22:32:34 +00002530
Scott Michela59d4692008-02-23 18:41:37 +00002531defm ROTI : RotateLeftWordImm;
2532
2533//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2534// Rotate quad by byte (count)
2535//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2536
2537class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2538 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2539 RotateShift, pattern>;
2540
2541class ROTQBYVecInst<ValueType vectype>:
2542 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2543 [(set (vectype VECREG:$rT),
2544 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2545
2546multiclass RotateQuadLeftByBytes
2547{
2548 def v16i8: ROTQBYVecInst<v16i8>;
2549 def v8i16: ROTQBYVecInst<v8i16>;
2550 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002551 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002552 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002553 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002554}
2555
2556defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel66377522007-12-04 22:35:58 +00002557
Scott Michela59d4692008-02-23 18:41:37 +00002558//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2559// Rotate quad by byte (count), immediate
2560//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2561
2562class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2563 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2564 RotateShift, pattern>;
2565
2566class ROTQBYIVecInst<ValueType vectype>:
2567 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2568 [(set (vectype VECREG:$rT),
2569 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2570
2571multiclass RotateQuadByBytesImm
2572{
2573 def v16i8: ROTQBYIVecInst<v16i8>;
2574 def v8i16: ROTQBYIVecInst<v8i16>;
2575 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002576 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002577 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002578 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002579}
2580
2581defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel66377522007-12-04 22:35:58 +00002582
Scott Michel66377522007-12-04 22:35:58 +00002583// See ROTQBY note above.
Scott Michel8bf61e82008-06-02 22:18:03 +00002584class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2585 RI7Form<0b00110011100, OOL, IOL,
2586 "rotqbybi\t$rT, $rA, $shift",
2587 RotateShift, pattern>;
2588
2589class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2590 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2591 [(set (vectype VECREG:$rT),
2592 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2593
2594multiclass RotateQuadByBytesByBitshift {
2595 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2596 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2597 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2598 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2599}
2600
2601defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel66377522007-12-04 22:35:58 +00002602
Scott Michela59d4692008-02-23 18:41:37 +00002603//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002604// See ROTQBY note above.
2605//
2606// Assume that the user of this instruction knows to shift the rotate count
2607// into bit 29
Scott Michela59d4692008-02-23 18:41:37 +00002608//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002609
Scott Michela59d4692008-02-23 18:41:37 +00002610class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2611 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2612 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002613
Scott Michela59d4692008-02-23 18:41:37 +00002614class ROTQBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002615 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002616 [/* no pattern yet */]>;
2617
2618class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel02d711b2008-12-30 23:28:25 +00002619 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002620 [/* no pattern yet */]>;
2621
2622multiclass RotateQuadByBitCount
2623{
2624 def v16i8: ROTQBIVecInst<v16i8>;
2625 def v8i16: ROTQBIVecInst<v8i16>;
2626 def v4i32: ROTQBIVecInst<v4i32>;
2627 def v2i64: ROTQBIVecInst<v2i64>;
2628
2629 def r128: ROTQBIRegInst<GPRC>;
2630 def r64: ROTQBIRegInst<R64C>;
2631}
2632
2633defm ROTQBI: RotateQuadByBitCount;
Scott Michelf0569be2008-12-27 04:51:36 +00002634
Scott Michela59d4692008-02-23 18:41:37 +00002635class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2636 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2637 RotateShift, pattern>;
2638
2639class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2640 PatLeaf pred>:
2641 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2642 [/* no pattern yet */]>;
2643
2644class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2645 PatLeaf pred>:
2646 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2647 [/* no pattern yet */]>;
2648
2649multiclass RotateQuadByBitCountImm
2650{
2651 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2652 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2653 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2654 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2655
2656 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2657 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2658}
2659
2660defm ROTQBII : RotateQuadByBitCountImm;
2661
2662//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002663// ROTHM v8i16 form:
2664// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2665// so this only matches a synthetically generated/lowered code
2666// fragment.
2667// NOTE(2): $rB must be negated before the right rotate!
Scott Michela59d4692008-02-23 18:41:37 +00002668//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002669
Scott Michela59d4692008-02-23 18:41:37 +00002670class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2671 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2672 RotateShift, pattern>;
2673
2674def ROTHMv8i16:
2675 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2676 [/* see patterns below - $rB must be negated */]>;
2677
2678def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002679 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2680
Scott Michela59d4692008-02-23 18:41:37 +00002681def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002682 (ROTHMv8i16 VECREG:$rA,
2683 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2684
Scott Michela59d4692008-02-23 18:41:37 +00002685def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002686 (ROTHMv8i16 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002687 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002688
2689// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2690// Note: This instruction doesn't match a pattern because rB must be negated
2691// for the instruction to work. Thus, the pattern below the instruction!
Scott Michela59d4692008-02-23 18:41:37 +00002692
Scott Michel66377522007-12-04 22:35:58 +00002693def ROTHMr16:
Scott Michela59d4692008-02-23 18:41:37 +00002694 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2695 [/* see patterns below - $rB must be negated! */]>;
Scott Michel66377522007-12-04 22:35:58 +00002696
2697def : Pat<(srl R16C:$rA, R32C:$rB),
2698 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2699
2700def : Pat<(srl R16C:$rA, R16C:$rB),
2701 (ROTHMr16 R16C:$rA,
2702 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2703
Scott Michel504c3692007-12-17 22:32:34 +00002704def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002705 (ROTHMr16 R16C:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002706 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002707
2708// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2709// that the immediate can be complemented, so that the user doesn't have to
2710// worry about it.
Scott Michel66377522007-12-04 22:35:58 +00002711
Scott Michela59d4692008-02-23 18:41:37 +00002712class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2713 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2714 RotateShift, pattern>;
2715
2716def ROTHMIv8i16:
2717 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2718 [/* no pattern */]>;
2719
2720def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2721 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2722
2723def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002724 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002725
Scott Michela59d4692008-02-23 18:41:37 +00002726def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002727 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002728
2729def ROTHMIr16:
Scott Michela59d4692008-02-23 18:41:37 +00002730 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2731 [/* no pattern */]>;
2732
2733def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2734 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel66377522007-12-04 22:35:58 +00002735
2736def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002737 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002738
Scott Michel504c3692007-12-17 22:32:34 +00002739def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002740 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002741
Scott Michel66377522007-12-04 22:35:58 +00002742// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michela59d4692008-02-23 18:41:37 +00002743class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2744 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2745 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002746
Scott Michela59d4692008-02-23 18:41:37 +00002747def ROTMv4i32:
2748 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2749 [/* see patterns below - $rB must be negated */]>;
2750
Chris Lattner420c69d2010-03-15 05:53:47 +00002751def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002752 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2753
Chris Lattner420c69d2010-03-15 05:53:47 +00002754def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002755 (ROTMv4i32 VECREG:$rA,
2756 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2757
Chris Lattner420c69d2010-03-15 05:53:47 +00002758def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002759 (ROTMv4i32 VECREG:$rA,
Scott Michela59d4692008-02-23 18:41:37 +00002760 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002761
2762def ROTMr32:
Scott Michela59d4692008-02-23 18:41:37 +00002763 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2764 [/* see patterns below - $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002765
2766def : Pat<(srl R32C:$rA, R32C:$rB),
2767 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2768
2769def : Pat<(srl R32C:$rA, R16C:$rB),
2770 (ROTMr32 R32C:$rA,
2771 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2772
Scott Michel504c3692007-12-17 22:32:34 +00002773def : Pat<(srl R32C:$rA, R8C:$rB),
2774 (ROTMr32 R32C:$rA,
2775 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2776
Scott Michel66377522007-12-04 22:35:58 +00002777// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2778def ROTMIv4i32:
2779 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2780 "rotmi\t$rT, $rA, $val", RotateShift,
2781 [(set (v4i32 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002782 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002783
Chris Lattner420c69d2010-03-15 05:53:47 +00002784def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2785 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002786
Chris Lattner420c69d2010-03-15 05:53:47 +00002787def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2788 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002789
2790// ROTMI r32 form: know how to complement the immediate value.
2791def ROTMIr32:
2792 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2793 "rotmi\t$rT, $rA, $val", RotateShift,
2794 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2795
2796def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002797 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002798
Scott Michel504c3692007-12-17 22:32:34 +00002799def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002800 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002801
Scott Michela59d4692008-02-23 18:41:37 +00002802//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Micheldd950092009-01-06 03:36:14 +00002803// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel66377522007-12-04 22:35:58 +00002804// instruction pattern, type checking will succeed. This instruction assumes
Scott Michela59d4692008-02-23 18:41:37 +00002805// that the user knew to negate $rB.
Scott Michela59d4692008-02-23 18:41:37 +00002806//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002807
Scott Michela59d4692008-02-23 18:41:37 +00002808class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2809 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2810 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002811
Scott Michela59d4692008-02-23 18:41:37 +00002812class ROTQMBYVecInst<ValueType vectype>:
2813 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2814 [/* no pattern, $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002815
Scott Michela59d4692008-02-23 18:41:37 +00002816class ROTQMBYRegInst<RegisterClass rclass>:
2817 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00002818 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00002819
Scott Michela59d4692008-02-23 18:41:37 +00002820multiclass RotateQuadBytes
2821{
2822 def v16i8: ROTQMBYVecInst<v16i8>;
2823 def v8i16: ROTQMBYVecInst<v8i16>;
2824 def v4i32: ROTQMBYVecInst<v4i32>;
2825 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002826
Scott Michela59d4692008-02-23 18:41:37 +00002827 def r128: ROTQMBYRegInst<GPRC>;
2828 def r64: ROTQMBYRegInst<R64C>;
2829}
2830
2831defm ROTQMBY : RotateQuadBytes;
2832
Scott Michela59d4692008-02-23 18:41:37 +00002833class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2834 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2835 RotateShift, pattern>;
2836
2837class ROTQMBYIVecInst<ValueType vectype>:
2838 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002839 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002840
Scott Micheldd950092009-01-06 03:36:14 +00002841class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2842 PatLeaf pred>:
Scott Michela59d4692008-02-23 18:41:37 +00002843 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002844 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002845
Scott Micheldd950092009-01-06 03:36:14 +00002846// 128-bit zero extension form:
2847class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2848 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2849 [/* no pattern */]>;
2850
Scott Michela59d4692008-02-23 18:41:37 +00002851multiclass RotateQuadBytesImm
2852{
2853 def v16i8: ROTQMBYIVecInst<v16i8>;
2854 def v8i16: ROTQMBYIVecInst<v8i16>;
2855 def v4i32: ROTQMBYIVecInst<v4i32>;
2856 def v2i64: ROTQMBYIVecInst<v2i64>;
2857
2858 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2859 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Micheldd950092009-01-06 03:36:14 +00002860
2861 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2862 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2863 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2864 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michela59d4692008-02-23 18:41:37 +00002865}
2866
2867defm ROTQMBYI : RotateQuadBytesImm;
2868
Scott Michela59d4692008-02-23 18:41:37 +00002869//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2870// Rotate right and mask by bit count
2871//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2872
2873class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2874 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2875 RotateShift, pattern>;
2876
2877class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002878 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2879 [/* no pattern, */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002880
2881multiclass RotateMaskQuadByBitCount
2882{
2883 def v16i8: ROTQMBYBIVecInst<v16i8>;
2884 def v8i16: ROTQMBYBIVecInst<v8i16>;
2885 def v4i32: ROTQMBYBIVecInst<v4i32>;
2886 def v2i64: ROTQMBYBIVecInst<v2i64>;
2887}
2888
2889defm ROTQMBYBI: RotateMaskQuadByBitCount;
2890
2891//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2892// Rotate quad and mask by bits
2893// Note that the rotate amount has to be negated
2894//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2895
2896class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2897 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2898 RotateShift, pattern>;
2899
2900class ROTQMBIVecInst<ValueType vectype>:
2901 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2902 [/* no pattern */]>;
2903
2904class ROTQMBIRegInst<RegisterClass rclass>:
2905 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2906 [/* no pattern */]>;
2907
2908multiclass RotateMaskQuadByBits
2909{
2910 def v16i8: ROTQMBIVecInst<v16i8>;
2911 def v8i16: ROTQMBIVecInst<v8i16>;
2912 def v4i32: ROTQMBIVecInst<v4i32>;
2913 def v2i64: ROTQMBIVecInst<v2i64>;
2914
2915 def r128: ROTQMBIRegInst<GPRC>;
2916 def r64: ROTQMBIRegInst<R64C>;
2917}
2918
2919defm ROTQMBI: RotateMaskQuadByBits;
2920
Scott Michela59d4692008-02-23 18:41:37 +00002921//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2922// Rotate quad and mask by bits, immediate
2923//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2924
2925class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2926 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2927 RotateShift, pattern>;
2928
2929class ROTQMBIIVecInst<ValueType vectype>:
2930 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002931 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002932
2933class ROTQMBIIRegInst<RegisterClass rclass>:
2934 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002935 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002936
2937multiclass RotateMaskQuadByBitsImm
2938{
2939 def v16i8: ROTQMBIIVecInst<v16i8>;
2940 def v8i16: ROTQMBIIVecInst<v8i16>;
2941 def v4i32: ROTQMBIIVecInst<v4i32>;
2942 def v2i64: ROTQMBIIVecInst<v2i64>;
2943
2944 def r128: ROTQMBIIRegInst<GPRC>;
2945 def r64: ROTQMBIIRegInst<R64C>;
2946}
2947
2948defm ROTQMBII: RotateMaskQuadByBitsImm;
2949
2950//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2951//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002952
2953def ROTMAHv8i16:
2954 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2955 "rotmah\t$rT, $rA, $rB", RotateShift,
2956 [/* see patterns below - $rB must be negated */]>;
2957
Chris Lattner420c69d2010-03-15 05:53:47 +00002958def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002959 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2960
Chris Lattner420c69d2010-03-15 05:53:47 +00002961def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002962 (ROTMAHv8i16 VECREG:$rA,
2963 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2964
Chris Lattner420c69d2010-03-15 05:53:47 +00002965def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel504c3692007-12-17 22:32:34 +00002966 (ROTMAHv8i16 VECREG:$rA,
2967 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2968
Scott Michel66377522007-12-04 22:35:58 +00002969def ROTMAHr16:
2970 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2971 "rotmah\t$rT, $rA, $rB", RotateShift,
2972 [/* see patterns below - $rB must be negated */]>;
2973
2974def : Pat<(sra R16C:$rA, R32C:$rB),
2975 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2976
2977def : Pat<(sra R16C:$rA, R16C:$rB),
2978 (ROTMAHr16 R16C:$rA,
2979 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2980
Scott Michel504c3692007-12-17 22:32:34 +00002981def : Pat<(sra R16C:$rA, R8C:$rB),
2982 (ROTMAHr16 R16C:$rA,
2983 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2984
Scott Michel66377522007-12-04 22:35:58 +00002985def ROTMAHIv8i16:
2986 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2987 "rotmahi\t$rT, $rA, $val", RotateShift,
2988 [(set (v8i16 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002989 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002990
Scott Michela59d4692008-02-23 18:41:37 +00002991def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002992 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002993
Scott Michela59d4692008-02-23 18:41:37 +00002994def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002995 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002996
Scott Michel66377522007-12-04 22:35:58 +00002997def ROTMAHIr16:
2998 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2999 "rotmahi\t$rT, $rA, $val", RotateShift,
3000 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
3001
3002def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003003 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00003004
Scott Michel504c3692007-12-17 22:32:34 +00003005def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00003006 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00003007
Scott Michel66377522007-12-04 22:35:58 +00003008def ROTMAv4i32:
3009 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
3010 "rotma\t$rT, $rA, $rB", RotateShift,
3011 [/* see patterns below - $rB must be negated */]>;
3012
Chris Lattner420c69d2010-03-15 05:53:47 +00003013def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
3014 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel66377522007-12-04 22:35:58 +00003015
Chris Lattner420c69d2010-03-15 05:53:47 +00003016def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
3017 (ROTMAv4i32 VECREG:$rA,
Scott Michel66377522007-12-04 22:35:58 +00003018 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3019
Chris Lattner420c69d2010-03-15 05:53:47 +00003020def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
3021 (ROTMAv4i32 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00003022 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3023
Scott Michel66377522007-12-04 22:35:58 +00003024def ROTMAr32:
3025 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3026 "rotma\t$rT, $rA, $rB", RotateShift,
3027 [/* see patterns below - $rB must be negated */]>;
3028
3029def : Pat<(sra R32C:$rA, R32C:$rB),
3030 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3031
3032def : Pat<(sra R32C:$rA, R16C:$rB),
3033 (ROTMAr32 R32C:$rA,
3034 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3035
Scott Michel504c3692007-12-17 22:32:34 +00003036def : Pat<(sra R32C:$rA, R8C:$rB),
3037 (ROTMAr32 R32C:$rA,
3038 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3039
Scott Michel8bf61e82008-06-02 22:18:03 +00003040class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3041 RRForm<0b01011110000, OOL, IOL,
3042 "rotmai\t$rT, $rA, $val",
3043 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003044
Scott Michel8bf61e82008-06-02 22:18:03 +00003045class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3046 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3047 [(set (vectype VECREG:$rT),
3048 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003049
Scott Michel8bf61e82008-06-02 22:18:03 +00003050class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3051 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3052 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003053
Scott Michel8bf61e82008-06-02 22:18:03 +00003054multiclass RotateMaskAlgebraicImm {
3055 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3056 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3057 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3058 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3059}
Scott Michel66377522007-12-04 22:35:58 +00003060
Scott Michel8bf61e82008-06-02 22:18:03 +00003061defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel504c3692007-12-17 22:32:34 +00003062
Scott Michel66377522007-12-04 22:35:58 +00003063//===----------------------------------------------------------------------===//
3064// Branch and conditionals:
3065//===----------------------------------------------------------------------===//
3066
3067let isTerminator = 1, isBarrier = 1 in {
3068 // Halt If Equal (r32 preferred slot only, no vector form)
3069 def HEQr32:
3070 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3071 "heq\t$rA, $rB", BranchResolv,
3072 [/* no pattern to match */]>;
3073
3074 def HEQIr32 :
3075 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3076 "heqi\t$rA, $val", BranchResolv,
3077 [/* no pattern to match */]>;
3078
3079 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3080 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3081 def HGTr32:
3082 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3083 "hgt\t$rA, $rB", BranchResolv,
3084 [/* no pattern to match */]>;
3085
Scott Michelf0569be2008-12-27 04:51:36 +00003086 def HGTIr32:
Scott Michel66377522007-12-04 22:35:58 +00003087 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3088 "hgti\t$rA, $val", BranchResolv,
3089 [/* no pattern to match */]>;
3090
3091 def HLGTr32:
3092 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3093 "hlgt\t$rA, $rB", BranchResolv,
3094 [/* no pattern to match */]>;
3095
3096 def HLGTIr32:
3097 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3098 "hlgti\t$rA, $val", BranchResolv,
3099 [/* no pattern to match */]>;
3100}
3101
Scott Michelf0569be2008-12-27 04:51:36 +00003102//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3103// Comparison operators for i8, i16 and i32:
3104//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003105
Scott Michela59d4692008-02-23 18:41:37 +00003106class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3107 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3108 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003109
Scott Michela59d4692008-02-23 18:41:37 +00003110multiclass CmpEqualByte
3111{
3112 def v16i8 :
3113 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3114 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3115 (v8i16 VECREG:$rB)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00003116
Scott Michela59d4692008-02-23 18:41:37 +00003117 def r8 :
3118 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3119 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3120}
Scott Michel66377522007-12-04 22:35:58 +00003121
Scott Michela59d4692008-02-23 18:41:37 +00003122class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3123 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3124 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003125
Scott Michela59d4692008-02-23 18:41:37 +00003126multiclass CmpEqualByteImm
3127{
3128 def v16i8 :
3129 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3130 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3131 v16i8SExt8Imm:$val))]>;
3132 def r8:
3133 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3134 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3135}
Scott Michel66377522007-12-04 22:35:58 +00003136
Scott Michela59d4692008-02-23 18:41:37 +00003137class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3138 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3139 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003140
Scott Michela59d4692008-02-23 18:41:37 +00003141multiclass CmpEqualHalfword
3142{
3143 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3144 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3145 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003146
Scott Michela59d4692008-02-23 18:41:37 +00003147 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3148 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3149}
Scott Michel66377522007-12-04 22:35:58 +00003150
Scott Michela59d4692008-02-23 18:41:37 +00003151class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3152 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3153 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003154
Scott Michela59d4692008-02-23 18:41:37 +00003155multiclass CmpEqualHalfwordImm
3156{
3157 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3158 [(set (v8i16 VECREG:$rT),
3159 (seteq (v8i16 VECREG:$rA),
3160 (v8i16 v8i16SExt10Imm:$val)))]>;
3161 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3162 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3163}
Scott Michel66377522007-12-04 22:35:58 +00003164
Scott Michela59d4692008-02-23 18:41:37 +00003165class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3166 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3167 ByteOp, pattern>;
3168
3169multiclass CmpEqualWord
3170{
3171 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3172 [(set (v4i32 VECREG:$rT),
3173 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3174
3175 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3176 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3177}
3178
3179class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3180 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3181 ByteOp, pattern>;
3182
3183multiclass CmpEqualWordImm
3184{
3185 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3186 [(set (v4i32 VECREG:$rT),
3187 (seteq (v4i32 VECREG:$rA),
3188 (v4i32 v4i32SExt16Imm:$val)))]>;
3189
3190 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3191 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3192}
3193
3194class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3195 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3196 ByteOp, pattern>;
3197
3198multiclass CmpGtrByte
3199{
3200 def v16i8 :
3201 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3202 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3203 (v8i16 VECREG:$rB)))]>;
3204
3205 def r8 :
3206 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3207 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3208}
3209
3210class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3211 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3212 ByteOp, pattern>;
3213
3214multiclass CmpGtrByteImm
3215{
3216 def v16i8 :
3217 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3218 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3219 v16i8SExt8Imm:$val))]>;
3220 def r8:
3221 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel79698f62008-03-20 00:51:36 +00003222 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003223}
3224
3225class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3226 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3227 ByteOp, pattern>;
3228
3229multiclass CmpGtrHalfword
3230{
3231 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3232 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3233 (v8i16 VECREG:$rB)))]>;
3234
3235 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3236 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3237}
3238
3239class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3240 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3241 ByteOp, pattern>;
3242
3243multiclass CmpGtrHalfwordImm
3244{
3245 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3246 [(set (v8i16 VECREG:$rT),
3247 (setgt (v8i16 VECREG:$rA),
3248 (v8i16 v8i16SExt10Imm:$val)))]>;
3249 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3250 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3251}
3252
3253class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3254 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3255 ByteOp, pattern>;
3256
3257multiclass CmpGtrWord
3258{
3259 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3260 [(set (v4i32 VECREG:$rT),
3261 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3262
3263 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3264 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3265}
3266
3267class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3268 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3269 ByteOp, pattern>;
3270
3271multiclass CmpGtrWordImm
3272{
3273 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3274 [(set (v4i32 VECREG:$rT),
3275 (setgt (v4i32 VECREG:$rA),
3276 (v4i32 v4i32SExt16Imm:$val)))]>;
3277
3278 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3279 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00003280
3281 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3282 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3283 [(set (v4i32 VECREG:$rT),
3284 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3285 (v4i32 v4i32SExt16Imm:$val)))]>;
3286
3287 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +00003288 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00003289}
3290
3291class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003292 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003293 ByteOp, pattern>;
3294
3295multiclass CmpLGtrByte
3296{
3297 def v16i8 :
3298 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3299 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3300 (v8i16 VECREG:$rB)))]>;
3301
3302 def r8 :
3303 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3304 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3305}
3306
3307class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003308 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003309 ByteOp, pattern>;
3310
3311multiclass CmpLGtrByteImm
3312{
3313 def v16i8 :
3314 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3315 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3316 v16i8SExt8Imm:$val))]>;
3317 def r8:
3318 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3319 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3320}
3321
3322class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003323 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003324 ByteOp, pattern>;
3325
3326multiclass CmpLGtrHalfword
3327{
3328 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3329 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3330 (v8i16 VECREG:$rB)))]>;
3331
3332 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3333 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3334}
3335
3336class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003337 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003338 ByteOp, pattern>;
3339
3340multiclass CmpLGtrHalfwordImm
3341{
3342 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3343 [(set (v8i16 VECREG:$rT),
3344 (setugt (v8i16 VECREG:$rA),
3345 (v8i16 v8i16SExt10Imm:$val)))]>;
3346 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3347 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3348}
3349
3350class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003351 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003352 ByteOp, pattern>;
3353
3354multiclass CmpLGtrWord
3355{
3356 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3357 [(set (v4i32 VECREG:$rT),
3358 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3359
3360 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3361 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3362}
3363
3364class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003365 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003366 ByteOp, pattern>;
3367
3368multiclass CmpLGtrWordImm
3369{
3370 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3371 [(set (v4i32 VECREG:$rT),
3372 (setugt (v4i32 VECREG:$rA),
3373 (v4i32 v4i32SExt16Imm:$val)))]>;
3374
3375 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michelad2715e2008-03-05 23:02:02 +00003376 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003377}
3378
3379defm CEQB : CmpEqualByte;
3380defm CEQBI : CmpEqualByteImm;
3381defm CEQH : CmpEqualHalfword;
3382defm CEQHI : CmpEqualHalfwordImm;
3383defm CEQ : CmpEqualWord;
3384defm CEQI : CmpEqualWordImm;
3385defm CGTB : CmpGtrByte;
3386defm CGTBI : CmpGtrByteImm;
3387defm CGTH : CmpGtrHalfword;
3388defm CGTHI : CmpGtrHalfwordImm;
3389defm CGT : CmpGtrWord;
3390defm CGTI : CmpGtrWordImm;
3391defm CLGTB : CmpLGtrByte;
3392defm CLGTBI : CmpLGtrByteImm;
3393defm CLGTH : CmpLGtrHalfword;
3394defm CLGTHI : CmpLGtrHalfwordImm;
3395defm CLGT : CmpLGtrWord;
3396defm CLGTI : CmpLGtrWordImm;
3397
Scott Michel78c47fa2008-03-10 16:58:52 +00003398//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003399// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3400// define a pattern to generate the right code, as a binary operator
3401// (in a manner of speaking.)
Scott Michel78c47fa2008-03-10 16:58:52 +00003402//
Scott Michelf0569be2008-12-27 04:51:36 +00003403// Notes:
3404// 1. This only matches the setcc set of conditionals. Special pattern
3405// matching is used for select conditionals.
3406//
3407// 2. The "DAG" versions of these classes is almost exclusively used for
3408// i64 comparisons. See the tblgen fundamentals documentation for what
3409// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3410// class for where ResultInstrs originates.
Scott Michel78c47fa2008-03-10 16:58:52 +00003411//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003412
Scott Michel78c47fa2008-03-10 16:58:52 +00003413class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3414 SPUInstr xorinst, SPUInstr cmpare>:
3415 Pat<(cond rclass:$rA, rclass:$rB),
3416 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3417
3418class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3419 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3420 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3421 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3422
Scott Michelf0569be2008-12-27 04:51:36 +00003423def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003424def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3425
Scott Michelf0569be2008-12-27 04:51:36 +00003426def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003427def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3428
3429def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3430def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003431
3432class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3433 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3434 Pat<(cond rclass:$rA, rclass:$rB),
3435 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3436 (cmpOp2 rclass:$rA, rclass:$rB))>;
3437
3438class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3439 ValueType immtype,
3440 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3441 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3442 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3443 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3444
Scott Michel78c47fa2008-03-10 16:58:52 +00003445def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3446def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3447def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3448def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3449def : Pat<(setle R8C:$rA, R8C:$rB),
3450 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3451def : Pat<(setle R8C:$rA, immU8:$imm),
3452 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003453
Scott Michel78c47fa2008-03-10 16:58:52 +00003454def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3455def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3456 ORr16, CGTHIr16, CEQHIr16>;
3457def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3458def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3459def : Pat<(setle R16C:$rA, R16C:$rB),
3460 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3461def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3462 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003463
Scott Michel78c47fa2008-03-10 16:58:52 +00003464def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3465def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3466 ORr32, CGTIr32, CEQIr32>;
3467def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3468def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3469def : Pat<(setle R32C:$rA, R32C:$rB),
3470 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3471def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3472 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003473
Scott Michel78c47fa2008-03-10 16:58:52 +00003474def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3475def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3476def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3477def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3478def : Pat<(setule R8C:$rA, R8C:$rB),
3479 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3480def : Pat<(setule R8C:$rA, immU8:$imm),
3481 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003482
Scott Michel78c47fa2008-03-10 16:58:52 +00003483def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3484def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3485 ORr16, CLGTHIr16, CEQHIr16>;
3486def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3487def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3488 CLGTHIr16, CEQHIr16>;
3489def : Pat<(setule R16C:$rA, R16C:$rB),
3490 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel79698f62008-03-20 00:51:36 +00003491def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel78c47fa2008-03-10 16:58:52 +00003492 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003493
Scott Michel78c47fa2008-03-10 16:58:52 +00003494def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003495def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel78c47fa2008-03-10 16:58:52 +00003496 ORr32, CLGTIr32, CEQIr32>;
3497def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003498def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003499def : Pat<(setule R32C:$rA, R32C:$rB),
3500 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3501def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3502 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003503
Scott Michel78c47fa2008-03-10 16:58:52 +00003504//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3505// select conditional patterns:
3506//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3507
3508class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3509 SPUInstr selinstr, SPUInstr cmpare>:
3510 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3511 rclass:$rTrue, rclass:$rFalse),
3512 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003513 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003514
3515class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3516 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3517 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003518 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003519 (selinstr rclass:$rTrue, rclass:$rFalse,
3520 (cmpare rclass:$rA, immpred:$imm))>;
3521
3522def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3523def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3524def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3525def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3526def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3527def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3528
3529def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3530def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3531def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3532def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3533def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3534def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3535
3536def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3537def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3538def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3539def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3540def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3541def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3542
3543class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3544 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3545 SPUInstr cmpOp2>:
3546 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michelf0569be2008-12-27 04:51:36 +00003547 rclass:$rTrue, rclass:$rFalse),
3548 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel78c47fa2008-03-10 16:58:52 +00003549 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3550 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3551
3552class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3553 ValueType inttype,
3554 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3555 SPUInstr cmpOp2>:
3556 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003557 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003558 (selinstr rclass:$rFalse, rclass:$rTrue,
3559 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3560 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3561
3562def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3563def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3564 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3565
3566def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3567def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3568 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3569
3570def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3571def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3572 SELBr32, ORr32, CGTIr32, CEQIr32>;
3573
3574def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3575def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3576 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3577
3578def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3579def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3580 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3581
3582def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3583def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3584 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003585
3586//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003587
3588let isCall = 1,
3589 // All calls clobber the non-callee-saved registers:
3590 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3591 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3592 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3593 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3594 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3595 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3596 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3597 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3598 // All of these instructions use $lr (aka $0)
3599 Uses = [R0] in {
3600 // Branch relative and set link: Used if we actually know that the target
3601 // is within [-32768, 32767] bytes of the target
3602 def BRSL:
3603 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3604 "brsl\t$$lr, $func",
3605 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3606
3607 // Branch absolute and set link: Used if we actually know that the target
3608 // is an absolute address
3609 def BRASL:
3610 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3611 "brasl\t$$lr, $func",
Scott Michel9de5d0d2008-01-11 02:53:15 +00003612 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel66377522007-12-04 22:35:58 +00003613
3614 // Branch indirect and set link if external data. These instructions are not
3615 // actually generated, matched by an intrinsic:
3616 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3617 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3618 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3619 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3620
3621 // Branch indirect and set link. This is the "X-form" address version of a
3622 // function call
3623 def BISL:
3624 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3625}
3626
Scott Michel1df30c42008-12-29 03:23:36 +00003627// Support calls to external symbols:
3628def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3629 (BRSL texternalsym:$func)>;
3630
3631def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3632 (BRASL texternalsym:$func)>;
3633
Scott Michel66377522007-12-04 22:35:58 +00003634// Unconditional branches:
Dan Gohman5b37fba2009-11-10 22:16:57 +00003635let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3636 let isBarrier = 1 in {
3637 def BR :
3638 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3639 "br\t$dest",
3640 [(br bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003641
Dan Gohman5b37fba2009-11-10 22:16:57 +00003642 // Unconditional, absolute address branch
3643 def BRA:
3644 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3645 "bra\t$dest",
3646 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003647
Dan Gohman5b37fba2009-11-10 22:16:57 +00003648 // Indirect branch
3649 def BI:
3650 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3651 }
Scott Michel66377522007-12-04 22:35:58 +00003652
Scott Micheled741dd2009-01-05 01:34:35 +00003653 // Conditional branches:
Scott Michelf0569be2008-12-27 04:51:36 +00003654 class BRNZInst<dag IOL, list<dag> pattern>:
3655 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3656 BranchResolv, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003657
Scott Michelf0569be2008-12-27 04:51:36 +00003658 class BRNZRegInst<RegisterClass rclass>:
3659 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3660 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003661
Scott Michelf0569be2008-12-27 04:51:36 +00003662 class BRNZVecInst<ValueType vectype>:
3663 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3664 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003665
Scott Michelf0569be2008-12-27 04:51:36 +00003666 multiclass BranchNotZero {
3667 def v4i32 : BRNZVecInst<v4i32>;
3668 def r32 : BRNZRegInst<R32C>;
3669 }
Scott Michel66377522007-12-04 22:35:58 +00003670
Scott Michelf0569be2008-12-27 04:51:36 +00003671 defm BRNZ : BranchNotZero;
3672
3673 class BRZInst<dag IOL, list<dag> pattern>:
3674 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3675 BranchResolv, pattern>;
3676
3677 class BRZRegInst<RegisterClass rclass>:
3678 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3679
3680 class BRZVecInst<ValueType vectype>:
3681 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3682
3683 multiclass BranchZero {
3684 def v4i32: BRZVecInst<v4i32>;
3685 def r32: BRZRegInst<R32C>;
3686 }
3687
3688 defm BRZ: BranchZero;
3689
3690 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3691 // be useful:
3692 /*
3693 class BINZInst<dag IOL, list<dag> pattern>:
3694 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3695
3696 class BINZRegInst<RegisterClass rclass>:
3697 BINZInst<(ins rclass:$rA, brtarget:$dest),
3698 [(brcond rclass:$rA, R32C:$dest)]>;
3699
3700 class BINZVecInst<ValueType vectype>:
3701 BINZInst<(ins VECREG:$rA, R32C:$dest),
3702 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3703
3704 multiclass BranchNotZeroIndirect {
3705 def v4i32: BINZVecInst<v4i32>;
3706 def r32: BINZRegInst<R32C>;
3707 }
3708
3709 defm BINZ: BranchNotZeroIndirect;
3710
3711 class BIZInst<dag IOL, list<dag> pattern>:
3712 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3713
3714 class BIZRegInst<RegisterClass rclass>:
3715 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3716
3717 class BIZVecInst<ValueType vectype>:
3718 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3719
3720 multiclass BranchZeroIndirect {
3721 def v4i32: BIZVecInst<v4i32>;
3722 def r32: BIZRegInst<R32C>;
3723 }
3724
3725 defm BIZ: BranchZeroIndirect;
3726 */
3727
3728 class BRHNZInst<dag IOL, list<dag> pattern>:
3729 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3730 pattern>;
3731
3732 class BRHNZRegInst<RegisterClass rclass>:
3733 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3734 [(brcond rclass:$rCond, bb:$dest)]>;
3735
3736 class BRHNZVecInst<ValueType vectype>:
3737 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3738
3739 multiclass BranchNotZeroHalfword {
3740 def v8i16: BRHNZVecInst<v8i16>;
3741 def r16: BRHNZRegInst<R16C>;
3742 }
3743
3744 defm BRHNZ: BranchNotZeroHalfword;
3745
3746 class BRHZInst<dag IOL, list<dag> pattern>:
3747 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3748 pattern>;
3749
3750 class BRHZRegInst<RegisterClass rclass>:
3751 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3752
3753 class BRHZVecInst<ValueType vectype>:
3754 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3755
3756 multiclass BranchZeroHalfword {
3757 def v8i16: BRHZVecInst<v8i16>;
3758 def r16: BRHZRegInst<R16C>;
3759 }
3760
3761 defm BRHZ: BranchZeroHalfword;
Scott Michel66377522007-12-04 22:35:58 +00003762}
3763
Scott Michel58c58182008-01-17 20:38:41 +00003764//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003765// setcc and brcond patterns:
Scott Michel58c58182008-01-17 20:38:41 +00003766//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003767
Scott Michelf0569be2008-12-27 04:51:36 +00003768def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3769 (BRHZr16 R16C:$rA, bb:$dest)>;
3770def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3771 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michela59d4692008-02-23 18:41:37 +00003772
Scott Michelf0569be2008-12-27 04:51:36 +00003773def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3774 (BRZr32 R32C:$rA, bb:$dest)>;
3775def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3776 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel66377522007-12-04 22:35:58 +00003777
Scott Michela59d4692008-02-23 18:41:37 +00003778multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3779{
3780 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3781 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michel053c1da2008-01-29 02:16:57 +00003782
Scott Michela59d4692008-02-23 18:41:37 +00003783 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3784 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3785
3786 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3787 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3788
3789 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3790 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3791}
3792
Scott Micheled741dd2009-01-05 01:34:35 +00003793defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3794defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003795
3796multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3797{
3798 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3799 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3800
3801 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3802 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3803
3804 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3805 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3806
3807 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3808 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3809}
3810
Scott Michelf0569be2008-12-27 04:51:36 +00003811defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3812defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003813
3814multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3815 SPUInstr orinst32, SPUInstr brinst32>
3816{
3817 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3818 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3819 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3820 bb:$dest)>;
3821
3822 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3823 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3824 (CEQHr16 R16C:$rA, R16:$rB)),
3825 bb:$dest)>;
3826
3827 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3828 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3829 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3830 bb:$dest)>;
3831
3832 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3833 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3834 (CEQr32 R32C:$rA, R32C:$rB)),
3835 bb:$dest)>;
3836}
3837
Scott Michelf0569be2008-12-27 04:51:36 +00003838defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3839defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003840
3841multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3842{
3843 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3844 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3845
3846 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3847 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3848
3849 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3850 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3851
3852 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3853 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3854}
3855
Scott Michelf0569be2008-12-27 04:51:36 +00003856defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3857defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003858
3859multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3860 SPUInstr orinst32, SPUInstr brinst32>
3861{
3862 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3863 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3864 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3865 bb:$dest)>;
3866
3867 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3868 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3869 (CEQHr16 R16C:$rA, R16:$rB)),
3870 bb:$dest)>;
3871
3872 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3873 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3874 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3875 bb:$dest)>;
3876
3877 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3878 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3879 (CEQr32 R32C:$rA, R32C:$rB)),
3880 bb:$dest)>;
3881}
3882
Scott Michelf0569be2008-12-27 04:51:36 +00003883defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3884defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel053c1da2008-01-29 02:16:57 +00003885
Scott Michel66377522007-12-04 22:35:58 +00003886let isTerminator = 1, isBarrier = 1 in {
3887 let isReturn = 1 in {
3888 def RET:
3889 RETForm<"bi\t$$lr", [(retflag)]>;
3890 }
3891}
3892
3893//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00003894// Single precision floating point instructions
3895//===----------------------------------------------------------------------===//
3896
Scott Michelaedc6372008-12-10 00:15:19 +00003897class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3898 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003899 SPrecFP, pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00003900
Scott Michelaedc6372008-12-10 00:15:19 +00003901class FAVecInst<ValueType vectype>:
3902 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3903 [(set (vectype VECREG:$rT),
Scott Michel02d711b2008-12-30 23:28:25 +00003904 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00003905
Scott Michelaedc6372008-12-10 00:15:19 +00003906multiclass SFPAdd
3907{
3908 def v4f32: FAVecInst<v4f32>;
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003909 def v2f32: FAVecInst<v2f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003910 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3911 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003912}
Scott Michel66377522007-12-04 22:35:58 +00003913
Scott Michelaedc6372008-12-10 00:15:19 +00003914defm FA : SFPAdd;
Scott Michel66377522007-12-04 22:35:58 +00003915
Scott Michelaedc6372008-12-10 00:15:19 +00003916class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3917 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003918 SPrecFP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003919
Scott Michelaedc6372008-12-10 00:15:19 +00003920class FSVecInst<ValueType vectype>:
3921 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00003922 [(set (vectype VECREG:$rT),
3923 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003924
3925multiclass SFPSub
3926{
3927 def v4f32: FSVecInst<v4f32>;
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003928 def v2f32: FSVecInst<v2f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003929 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3930 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003931}
3932
3933defm FS : SFPSub;
Scott Michel66377522007-12-04 22:35:58 +00003934
Kalle Raiskilac9fda992010-08-02 10:25:47 +00003935class FMInst<dag OOL, dag IOL, list<dag> pattern>:
3936 RRForm<0b01100011010, OOL, IOL,
3937 "fm\t$rT, $rA, $rB", SPrecFP,
3938 pattern>;
3939
3940class FMVecInst<ValueType type>:
3941 FMInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3942 [(set (type VECREG:$rT),
3943 (fmul (type VECREG:$rA), (type VECREG:$rB)))]>;
3944
3945multiclass SFPMul
3946{
3947 def v4f32: FMVecInst<v4f32>;
3948 def v2f32: FMVecInst<v2f32>;
3949 def f32: FMInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3950 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3951}
3952
3953defm FM : SFPMul;
3954
3955// Floating point multiply and add
3956// e.g. d = c + (a * b)
3957def FMAv4f32:
3958 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3959 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3960 [(set (v4f32 VECREG:$rT),
3961 (fadd (v4f32 VECREG:$rC),
3962 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3963
3964def FMAf32:
3965 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3966 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3967 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3968
3969// FP multiply and subtract
3970// Subtracts value in rC from product
3971// res = a * b - c
3972def FMSv4f32 :
3973 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3974 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3975 [(set (v4f32 VECREG:$rT),
3976 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3977 (v4f32 VECREG:$rC)))]>;
3978
3979def FMSf32 :
3980 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3981 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3982 [(set R32FP:$rT,
3983 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3984
3985// Floating Negative Mulitply and Subtract
3986// Subtracts product from value in rC
3987// res = fneg(fms a b c)
3988// = - (a * b - c)
3989// = c - a * b
3990// NOTE: subtraction order
3991// fsub a b = a - b
3992// fs a b = b - a?
3993def FNMSf32 :
3994 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3995 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3996 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3997
3998def FNMSv4f32 :
3999 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4000 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4001 [(set (v4f32 VECREG:$rT),
4002 (fsub (v4f32 VECREG:$rC),
4003 (fmul (v4f32 VECREG:$rA),
4004 (v4f32 VECREG:$rB))))]>;
4005
4006
4007
4008
Scott Michel66377522007-12-04 22:35:58 +00004009// Floating point reciprocal estimate
Scott Michel66377522007-12-04 22:35:58 +00004010
Scott Michel02d711b2008-12-30 23:28:25 +00004011class FRESTInst<dag OOL, dag IOL>:
4012 RRForm_1<0b00110111000, OOL, IOL,
4013 "frest\t$rT, $rA", SPrecFP,
4014 [/* no pattern */]>;
4015
4016def FRESTv4f32 :
4017 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
4018
4019def FRESTf32 :
4020 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00004021
4022// Floating point interpolate (used in conjunction with reciprocal estimate)
4023def FIv4f32 :
4024 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4025 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00004026 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00004027
4028def FIf32 :
4029 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4030 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00004031 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00004032
Scott Michel9c0c6b22008-11-21 02:56:16 +00004033//--------------------------------------------------------------------------
4034// Basic single precision floating point comparisons:
4035//
4036// Note: There is no support on SPU for single precision NaN. Consequently,
4037// ordered and unordered comparisons are the same.
4038//--------------------------------------------------------------------------
4039
Scott Michel66377522007-12-04 22:35:58 +00004040def FCEQf32 :
4041 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4042 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004043 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
4044
4045def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
4046 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004047
4048def FCMEQf32 :
4049 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4050 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004051 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4052
4053def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
4054 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004055
4056def FCGTf32 :
4057 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4058 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004059 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
4060
4061def : Pat<(setugt R32FP:$rA, R32FP:$rB),
4062 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00004063
4064def FCMGTf32 :
4065 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
4066 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00004067 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
4068
4069def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
4070 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
4071
4072//--------------------------------------------------------------------------
4073// Single precision floating point comparisons and SETCC equivalents:
4074//--------------------------------------------------------------------------
4075
4076def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
4077def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
4078
4079def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
4080def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
4081
4082def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
4083def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
4084
4085def : Pat<(setule R32FP:$rA, R32FP:$rB),
4086 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
4087def : Pat<(setole R32FP:$rA, R32FP:$rB),
4088 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel66377522007-12-04 22:35:58 +00004089
4090// FP Status and Control Register Write
4091// Why isn't rT a don't care in the ISA?
4092// Should we create a special RRForm_3 for this guy and zero out the rT?
4093def FSCRWf32 :
4094 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
4095 "fscrwr\t$rA", SPrecFP,
4096 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
4097
4098// FP Status and Control Register Read
4099def FSCRRf32 :
4100 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
4101 "fscrrd\t$rT", SPrecFP,
4102 [/* This instruction requires an intrinsic */]>;
4103
4104// llvm instruction space
4105// How do these map onto cell instructions?
4106// fdiv rA rB
4107// frest rC rB # c = 1/b (both lines)
4108// fi rC rB rC
4109// fm rD rA rC # d = a * 1/b
4110// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4111// fma rB rB rC rD # b = b * c + d
4112// = -(d *b -a) * c + d
4113// = a * c - c ( a *b *c - a)
4114
4115// fcopysign (???)
4116
4117// Library calls:
4118// These llvm instructions will actually map to library calls.
4119// All that's needed, then, is to check that the appropriate library is
4120// imported and do a brsl to the proper function name.
4121// frem # fmod(x, y): x - (x/y) * y
4122// (Note: fmod(double, double), fmodf(float,float)
4123// fsqrt?
4124// fsin?
4125// fcos?
4126// Unimplemented SPU instruction space
4127// floating reciprocal absolute square root estimate (frsqest)
4128
4129// The following are probably just intrinsics
Scott Michelf0569be2008-12-27 04:51:36 +00004130// status and control register write
Scott Michel66377522007-12-04 22:35:58 +00004131// status and control register read
4132
4133//--------------------------------------
Scott Michel66377522007-12-04 22:35:58 +00004134// Floating Point Conversions
4135// Signed conversions:
4136def CSiFv4f32:
4137 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4138 "csflt\t$rT, $rA, 0", SPrecFP,
4139 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4140
Scott Michelf0569be2008-12-27 04:51:36 +00004141// Convert signed integer to floating point
Scott Michel66377522007-12-04 22:35:58 +00004142def CSiFf32 :
4143 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4144 "csflt\t$rT, $rA, 0", SPrecFP,
4145 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4146
4147// Convert unsigned into to float
4148def CUiFv4f32 :
4149 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4150 "cuflt\t$rT, $rA, 0", SPrecFP,
4151 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4152
4153def CUiFf32 :
4154 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4155 "cuflt\t$rT, $rA, 0", SPrecFP,
4156 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4157
Scott Michelf0569be2008-12-27 04:51:36 +00004158// Convert float to unsigned int
Scott Michel66377522007-12-04 22:35:58 +00004159// Assume that scale = 0
4160
4161def CFUiv4f32 :
4162 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4163 "cfltu\t$rT, $rA, 0", SPrecFP,
4164 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4165
4166def CFUif32 :
4167 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4168 "cfltu\t$rT, $rA, 0", SPrecFP,
4169 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4170
Scott Michelf0569be2008-12-27 04:51:36 +00004171// Convert float to signed int
Scott Michel66377522007-12-04 22:35:58 +00004172// Assume that scale = 0
4173
4174def CFSiv4f32 :
4175 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4176 "cflts\t$rT, $rA, 0", SPrecFP,
4177 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4178
4179def CFSif32 :
4180 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4181 "cflts\t$rT, $rA, 0", SPrecFP,
4182 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4183
4184//===----------------------------------------------------------------------==//
4185// Single<->Double precision conversions
4186//===----------------------------------------------------------------------==//
4187
4188// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4189// v4f32, output is v2f64--which goes in the name?)
4190
4191// Floating point extend single to double
4192// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4193// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4194// are ignored).
4195def FESDvec :
4196 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4197 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnere9eda0f2010-03-19 04:53:47 +00004198 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel66377522007-12-04 22:35:58 +00004199
4200def FESDf32 :
4201 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4202 "fesd\t$rT, $rA", SPrecFP,
4203 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4204
4205// Floating point round double to single
4206//def FRDSvec :
4207// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4208// "frds\t$rT, $rA,", SPrecFP,
4209// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4210
4211def FRDSf64 :
4212 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4213 "frds\t$rT, $rA", SPrecFP,
4214 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4215
4216//ToDo include anyextend?
4217
4218//===----------------------------------------------------------------------==//
4219// Double precision floating point instructions
4220//===----------------------------------------------------------------------==//
4221def FAf64 :
4222 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4223 "dfa\t$rT, $rA, $rB", DPrecFP,
4224 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4225
4226def FAv2f64 :
4227 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4228 "dfa\t$rT, $rA, $rB", DPrecFP,
4229 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4230
4231def FSf64 :
4232 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4233 "dfs\t$rT, $rA, $rB", DPrecFP,
4234 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4235
4236def FSv2f64 :
4237 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4238 "dfs\t$rT, $rA, $rB", DPrecFP,
4239 [(set (v2f64 VECREG:$rT),
4240 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4241
4242def FMf64 :
4243 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4244 "dfm\t$rT, $rA, $rB", DPrecFP,
4245 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4246
4247def FMv2f64:
4248 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4249 "dfm\t$rT, $rA, $rB", DPrecFP,
4250 [(set (v2f64 VECREG:$rT),
4251 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4252
4253def FMAf64:
4254 RRForm<0b00111010110, (outs R64FP:$rT),
4255 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4256 "dfma\t$rT, $rA, $rB", DPrecFP,
4257 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4258 RegConstraint<"$rC = $rT">,
4259 NoEncode<"$rC">;
4260
4261def FMAv2f64:
4262 RRForm<0b00111010110, (outs VECREG:$rT),
4263 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4264 "dfma\t$rT, $rA, $rB", DPrecFP,
4265 [(set (v2f64 VECREG:$rT),
4266 (fadd (v2f64 VECREG:$rC),
4267 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4268 RegConstraint<"$rC = $rT">,
4269 NoEncode<"$rC">;
4270
4271def FMSf64 :
4272 RRForm<0b10111010110, (outs R64FP:$rT),
4273 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4274 "dfms\t$rT, $rA, $rB", DPrecFP,
4275 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4276 RegConstraint<"$rC = $rT">,
4277 NoEncode<"$rC">;
4278
4279def FMSv2f64 :
4280 RRForm<0b10111010110, (outs VECREG:$rT),
4281 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4282 "dfms\t$rT, $rA, $rB", DPrecFP,
4283 [(set (v2f64 VECREG:$rT),
4284 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4285 (v2f64 VECREG:$rC)))]>;
4286
Scott Michel7ea02ff2009-03-17 01:15:45 +00004287// DFNMS: - (a * b - c)
Scott Michel66377522007-12-04 22:35:58 +00004288// - (a * b) + c => c - (a * b)
Scott Michel7ea02ff2009-03-17 01:15:45 +00004289
4290class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4291 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4292 DPrecFP, pattern>,
Scott Michel66377522007-12-04 22:35:58 +00004293 RegConstraint<"$rC = $rT">,
4294 NoEncode<"$rC">;
4295
Scott Michel7ea02ff2009-03-17 01:15:45 +00004296class DFNMSVecInst<list<dag> pattern>:
4297 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4298 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004299
Scott Michel7ea02ff2009-03-17 01:15:45 +00004300class DFNMSRegInst<list<dag> pattern>:
4301 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4302 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004303
Scott Michel7ea02ff2009-03-17 01:15:45 +00004304multiclass DFMultiplySubtract
4305{
4306 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4307 (fsub (v2f64 VECREG:$rC),
4308 (fmul (v2f64 VECREG:$rA),
4309 (v2f64 VECREG:$rB))))]>;
4310
4311 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4312 (fsub R64FP:$rC,
4313 (fmul R64FP:$rA, R64FP:$rB)))]>;
4314}
4315
4316defm DFNMS : DFMultiplySubtract;
Scott Michel66377522007-12-04 22:35:58 +00004317
4318// - (a * b + c)
4319// - (a * b) - c
4320def FNMAf64 :
4321 RRForm<0b11111010110, (outs R64FP:$rT),
4322 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4323 "dfnma\t$rT, $rA, $rB", DPrecFP,
4324 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4325 RegConstraint<"$rC = $rT">,
4326 NoEncode<"$rC">;
4327
4328def FNMAv2f64 :
4329 RRForm<0b11111010110, (outs VECREG:$rT),
4330 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4331 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michelf0569be2008-12-27 04:51:36 +00004332 [(set (v2f64 VECREG:$rT),
4333 (fneg (fadd (v2f64 VECREG:$rC),
4334 (fmul (v2f64 VECREG:$rA),
Scott Michel66377522007-12-04 22:35:58 +00004335 (v2f64 VECREG:$rB)))))]>,
4336 RegConstraint<"$rC = $rT">,
4337 NoEncode<"$rC">;
4338
4339//===----------------------------------------------------------------------==//
4340// Floating point negation and absolute value
4341//===----------------------------------------------------------------------==//
4342
4343def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michela82d3f72009-03-17 16:45:16 +00004344 (XORfnegvec (v4f32 VECREG:$rA),
4345 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel66377522007-12-04 22:35:58 +00004346
4347def : Pat<(fneg R32FP:$rA),
Scott Michela82d3f72009-03-17 16:45:16 +00004348 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel66377522007-12-04 22:35:58 +00004349
4350// Floating point absolute value
Scott Michel7ea02ff2009-03-17 01:15:45 +00004351// Note: f64 fabs is custom-selected.
Scott Michel66377522007-12-04 22:35:58 +00004352
4353def : Pat<(fabs R32FP:$rA),
4354 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4355
4356def : Pat<(fabs (v4f32 VECREG:$rA)),
4357 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel7ea02ff2009-03-17 01:15:45 +00004358 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
Scott Michelc9c8b2a2009-01-26 03:31:40 +00004359
Scott Michel66377522007-12-04 22:35:58 +00004360//===----------------------------------------------------------------------===//
Scott Michelaedc6372008-12-10 00:15:19 +00004361// Hint for branch instructions:
4362//===----------------------------------------------------------------------===//
4363
4364/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4365
4366//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004367// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4368// in the odd pipeline)
4369//===----------------------------------------------------------------------===//
4370
Scott Michela59d4692008-02-23 18:41:37 +00004371def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004372 let Pattern = [];
4373
4374 let Inst{0-10} = 0b10000000010;
4375 let Inst{11-17} = 0;
4376 let Inst{18-24} = 0;
4377 let Inst{25-31} = 0;
4378}
4379
Scott Michela59d4692008-02-23 18:41:37 +00004380def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004381 let Pattern = [];
4382
4383 let Inst{0-10} = 0b10000000000;
4384 let Inst{11-17} = 0;
4385 let Inst{18-24} = 0;
4386 let Inst{25-31} = 0;
4387}
4388
4389//===----------------------------------------------------------------------===//
4390// Bit conversions (type conversions between vector/packed types)
Scott Michel6e1d1472009-03-16 18:47:25 +00004391// NOTE: Promotions are handled using the XS* instructions.
Scott Michel66377522007-12-04 22:35:58 +00004392//===----------------------------------------------------------------------===//
4393def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4394def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4395def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4396def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4397def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4398
4399def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4400def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4401def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4402def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4403def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4404
4405def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4406def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4407def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4408def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4409def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4410
4411def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4412def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4413def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4414def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4415def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4416
4417def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4418def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4419def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4420def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4421def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4422
4423def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4424def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4425def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4426def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattnere82f3362010-03-28 08:36:45 +00004427def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel66377522007-12-04 22:35:58 +00004428
Scott Michel6e1d1472009-03-16 18:47:25 +00004429def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4430 (ORi128_vec VECREG:$src)>;
4431def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4432 (ORi128_vec VECREG:$src)>;
4433def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4434 (ORi128_vec VECREG:$src)>;
4435def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4436 (ORi128_vec VECREG:$src)>;
4437def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4438 (ORi128_vec VECREG:$src)>;
4439def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4440 (ORi128_vec VECREG:$src)>;
4441
4442def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4443 (v16i8 (ORvec_i128 GPRC:$src))>;
4444def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4445 (v8i16 (ORvec_i128 GPRC:$src))>;
4446def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4447 (v4i32 (ORvec_i128 GPRC:$src))>;
4448def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4449 (v2i64 (ORvec_i128 GPRC:$src))>;
4450def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4451 (v4f32 (ORvec_i128 GPRC:$src))>;
4452def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4453 (v2f64 (ORvec_i128 GPRC:$src))>;
Scott Michel66377522007-12-04 22:35:58 +00004454
4455//===----------------------------------------------------------------------===//
4456// Instruction patterns:
4457//===----------------------------------------------------------------------===//
4458
4459// General 32-bit constants:
4460def : Pat<(i32 imm:$imm),
4461 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4462
4463// Single precision float constants:
Nate Begemanccef5802008-02-14 18:43:04 +00004464def : Pat<(f32 fpimm:$imm),
Scott Michel66377522007-12-04 22:35:58 +00004465 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4466
4467// General constant 32-bit vectors
4468def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michelad2715e2008-03-05 23:02:02 +00004469 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4470 (LO16_vec v4i32Imm:$imm))>;
Scott Michelf0569be2008-12-27 04:51:36 +00004471
Scott Michel504c3692007-12-17 22:32:34 +00004472// 8-bit constants
4473def : Pat<(i8 imm:$imm),
4474 (ILHr8 imm:$imm)>;
Scott Michel66377522007-12-04 22:35:58 +00004475
4476//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004477// Zero/Any/Sign extensions
4478//===----------------------------------------------------------------------===//
4479
Scott Michel66377522007-12-04 22:35:58 +00004480// sext 8->32: Sign extend bytes to words
4481def : Pat<(sext_inreg R32C:$rSrc, i8),
4482 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4483
Scott Michel504c3692007-12-17 22:32:34 +00004484def : Pat<(i32 (sext R8C:$rSrc)),
4485 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4486
Scott Micheldd950092009-01-06 03:36:14 +00004487// sext 8->64: Sign extend bytes to double word
4488def : Pat<(sext_inreg R64C:$rSrc, i8),
4489 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4490
4491def : Pat<(i64 (sext R8C:$rSrc)),
4492 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4493
Scott Michel504c3692007-12-17 22:32:34 +00004494// zext 8->16: Zero extend bytes to halfwords
4495def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004496 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004497
Scott Michel504c3692007-12-17 22:32:34 +00004498// zext 8->32: Zero extend bytes to words
4499def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004500 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004501
Scott Micheldd950092009-01-06 03:36:14 +00004502// zext 8->64: Zero extend bytes to double words
4503def : Pat<(i64 (zext R8C:$rSrc)),
4504 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4505 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4506 0x4),
4507 (ILv4i32 0x0),
4508 (FSMBIv4i32 0x0f0f)))>;
4509
4510// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004511def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004512 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004513
Scott Micheldd950092009-01-06 03:36:14 +00004514// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004515def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004516 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004517
Scott Micheldd950092009-01-06 03:36:14 +00004518// sext 16->64: Sign extend halfword to double word
4519def : Pat<(sext_inreg R64C:$rSrc, i16),
4520 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4521
4522def : Pat<(sext R16C:$rSrc),
4523 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4524
Scott Michela59d4692008-02-23 18:41:37 +00004525// zext 16->32: Zero extend halfwords to words
Scott Michel66377522007-12-04 22:35:58 +00004526def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004527 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel66377522007-12-04 22:35:58 +00004528
4529def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michela59d4692008-02-23 18:41:37 +00004530 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel66377522007-12-04 22:35:58 +00004531
4532def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michela59d4692008-02-23 18:41:37 +00004533 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel66377522007-12-04 22:35:58 +00004534
4535def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michela59d4692008-02-23 18:41:37 +00004536 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel66377522007-12-04 22:35:58 +00004537
4538// anyext 16->32: Extend 16->32 bits, irrespective of sign
4539def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004540 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel66377522007-12-04 22:35:58 +00004541
4542//===----------------------------------------------------------------------===//
Scott Michelf0569be2008-12-27 04:51:36 +00004543// Truncates:
4544// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4545// above are custom lowered.
4546//===----------------------------------------------------------------------===//
4547
4548def : Pat<(i8 (trunc GPRC:$src)),
4549 (ORi8_v16i8
4550 (SHUFBgprc GPRC:$src, GPRC:$src,
4551 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4552
4553def : Pat<(i8 (trunc R64C:$src)),
4554 (ORi8_v16i8
4555 (SHUFBv2i64_m32
4556 (ORv2i64_i64 R64C:$src),
4557 (ORv2i64_i64 R64C:$src),
4558 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4559
4560def : Pat<(i8 (trunc R32C:$src)),
4561 (ORi8_v16i8
4562 (SHUFBv4i32_m32
4563 (ORv4i32_i32 R32C:$src),
4564 (ORv4i32_i32 R32C:$src),
4565 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4566
4567def : Pat<(i8 (trunc R16C:$src)),
4568 (ORi8_v16i8
4569 (SHUFBv4i32_m32
4570 (ORv8i16_i16 R16C:$src),
4571 (ORv8i16_i16 R16C:$src),
4572 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4573
4574def : Pat<(i16 (trunc GPRC:$src)),
4575 (ORi16_v8i16
4576 (SHUFBgprc GPRC:$src, GPRC:$src,
4577 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4578
4579def : Pat<(i16 (trunc R64C:$src)),
4580 (ORi16_v8i16
4581 (SHUFBv2i64_m32
4582 (ORv2i64_i64 R64C:$src),
4583 (ORv2i64_i64 R64C:$src),
4584 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4585
4586def : Pat<(i16 (trunc R32C:$src)),
4587 (ORi16_v8i16
4588 (SHUFBv4i32_m32
4589 (ORv4i32_i32 R32C:$src),
4590 (ORv4i32_i32 R32C:$src),
4591 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4592
4593def : Pat<(i32 (trunc GPRC:$src)),
4594 (ORi32_v4i32
4595 (SHUFBgprc GPRC:$src, GPRC:$src,
4596 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4597
4598def : Pat<(i32 (trunc R64C:$src)),
4599 (ORi32_v4i32
4600 (SHUFBv2i64_m32
4601 (ORv2i64_i64 R64C:$src),
4602 (ORv2i64_i64 R64C:$src),
4603 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4604
4605//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00004606// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel66377522007-12-04 22:35:58 +00004607// low parts in order to load them into a register.
4608//===----------------------------------------------------------------------===//
4609
Scott Michel053c1da2008-01-29 02:16:57 +00004610def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4611def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4612def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4613def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4614
4615def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4616 (SPUlo tglobaladdr:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004617 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004618
Scott Michel053c1da2008-01-29 02:16:57 +00004619def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4620 (SPUlo texternalsym:$in, 0)),
4621 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4622
4623def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4624 (SPUlo tjumptable:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004625 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004626
Scott Michel053c1da2008-01-29 02:16:57 +00004627def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4628 (SPUlo tconstpool:$in, 0)),
4629 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4630
4631def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4632 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4633
4634def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4635 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4636
4637def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4638 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4639
4640def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4641 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel66377522007-12-04 22:35:58 +00004642
Scott Michel6e1d1472009-03-16 18:47:25 +00004643// Intrinsics:
Scott Michel66377522007-12-04 22:35:58 +00004644include "CellSDKIntrinsics.td"
Scott Michel02d711b2008-12-30 23:28:25 +00004645// Various math operator instruction sequences
4646include "SPUMathInstr.td"
Scott Michelf0569be2008-12-27 04:51:36 +00004647// 64-bit "instructions"/support
4648include "SPU64InstrInfo.td"
Scott Micheldd950092009-01-06 03:36:14 +00004649// 128-bit "instructions"/support
4650include "SPU128InstrInfo.td"