blob: bc9668a8097e457b7797539f996074e9803cb4fc [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>;
66
Scott Michel053c1da2008-01-29 02:16:57 +000067 def r128: LoadDForm<GPRC>;
68 def r64: LoadDForm<R64C>;
69 def r32: LoadDForm<R32C>;
70 def f32: LoadDForm<R32FP>;
71 def f64: LoadDForm<R64FP>;
72 def r16: LoadDForm<R16C>;
73 def r8: LoadDForm<R8C>;
74 }
Scott Michel66377522007-12-04 22:35:58 +000075
Scott Michel053c1da2008-01-29 02:16:57 +000076 class LoadAFormVec<ValueType vectype>
77 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
78 "lqa\t$rT, $src",
79 LoadStore,
80 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
81 { }
Scott Michel66377522007-12-04 22:35:58 +000082
Scott Michel053c1da2008-01-29 02:16:57 +000083 class LoadAForm<RegisterClass rclass>
84 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
85 "lqa\t$rT, $src",
86 LoadStore,
87 [(set rclass:$rT, (load aform_addr:$src))]>
88 { }
Scott Michel66377522007-12-04 22:35:58 +000089
Scott Michel053c1da2008-01-29 02:16:57 +000090 multiclass LoadAForms
91 {
92 def v16i8: LoadAFormVec<v16i8>;
93 def v8i16: LoadAFormVec<v8i16>;
94 def v4i32: LoadAFormVec<v4i32>;
95 def v2i64: LoadAFormVec<v2i64>;
96 def v4f32: LoadAFormVec<v4f32>;
97 def v2f64: LoadAFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +000098
Scott Michel21213e72009-01-06 23:10:38 +000099 def v2i32: LoadAFormVec<v2i32>;
100
Scott Michel053c1da2008-01-29 02:16:57 +0000101 def r128: LoadAForm<GPRC>;
102 def r64: LoadAForm<R64C>;
103 def r32: LoadAForm<R32C>;
104 def f32: LoadAForm<R32FP>;
105 def f64: LoadAForm<R64FP>;
106 def r16: LoadAForm<R16C>;
107 def r8: LoadAForm<R8C>;
108 }
Scott Michel66377522007-12-04 22:35:58 +0000109
Scott Michel053c1da2008-01-29 02:16:57 +0000110 class LoadXFormVec<ValueType vectype>
111 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
112 "lqx\t$rT, $src",
113 LoadStore,
114 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
115 { }
Scott Michel66377522007-12-04 22:35:58 +0000116
Scott Michel053c1da2008-01-29 02:16:57 +0000117 class LoadXForm<RegisterClass rclass>
118 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
119 "lqx\t$rT, $src",
120 LoadStore,
121 [(set rclass:$rT, (load xform_addr:$src))]>
122 { }
Scott Michel66377522007-12-04 22:35:58 +0000123
Scott Michel053c1da2008-01-29 02:16:57 +0000124 multiclass LoadXForms
125 {
126 def v16i8: LoadXFormVec<v16i8>;
127 def v8i16: LoadXFormVec<v8i16>;
128 def v4i32: LoadXFormVec<v4i32>;
129 def v2i64: LoadXFormVec<v2i64>;
130 def v4f32: LoadXFormVec<v4f32>;
131 def v2f64: LoadXFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000132
Scott Michel21213e72009-01-06 23:10:38 +0000133 def v2i32: LoadXFormVec<v2i32>;
134
Scott Michel053c1da2008-01-29 02:16:57 +0000135 def r128: LoadXForm<GPRC>;
136 def r64: LoadXForm<R64C>;
137 def r32: LoadXForm<R32C>;
138 def f32: LoadXForm<R32FP>;
139 def f64: LoadXForm<R64FP>;
140 def r16: LoadXForm<R16C>;
141 def r8: LoadXForm<R8C>;
142 }
Scott Michel66377522007-12-04 22:35:58 +0000143
Scott Michel053c1da2008-01-29 02:16:57 +0000144 defm LQA : LoadAForms;
145 defm LQD : LoadDForms;
146 defm LQX : LoadXForms;
Scott Michel504c3692007-12-17 22:32:34 +0000147
Scott Michel66377522007-12-04 22:35:58 +0000148/* Load quadword, PC relative: Not much use at this point in time.
Scott Michel053c1da2008-01-29 02:16:57 +0000149 Might be of use later for relocatable code. It's effectively the
150 same as LQA, but uses PC-relative addressing.
Scott Michel66377522007-12-04 22:35:58 +0000151 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
152 "lqr\t$rT, $disp", LoadStore,
153 [(set VECREG:$rT, (load iaddr:$disp))]>;
154 */
Scott Michel66377522007-12-04 22:35:58 +0000155}
156
157//===----------------------------------------------------------------------===//
158// Stores:
159//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +0000160class StoreDFormVec<ValueType vectype>
Scott Michelf0569be2008-12-27 04:51:36 +0000161 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000162 "stqd\t$rT, $src",
163 LoadStore,
164 [(store (vectype VECREG:$rT), dform_addr:$src)]>
165{ }
Scott Michel66377522007-12-04 22:35:58 +0000166
Scott Michel053c1da2008-01-29 02:16:57 +0000167class StoreDForm<RegisterClass rclass>
Scott Michelf0569be2008-12-27 04:51:36 +0000168 : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
Scott Michel053c1da2008-01-29 02:16:57 +0000169 "stqd\t$rT, $src",
170 LoadStore,
171 [(store rclass:$rT, dform_addr:$src)]>
172{ }
Scott Michel66377522007-12-04 22:35:58 +0000173
Scott Michel053c1da2008-01-29 02:16:57 +0000174multiclass StoreDForms
175{
176 def v16i8: StoreDFormVec<v16i8>;
177 def v8i16: StoreDFormVec<v8i16>;
178 def v4i32: StoreDFormVec<v4i32>;
179 def v2i64: StoreDFormVec<v2i64>;
180 def v4f32: StoreDFormVec<v4f32>;
181 def v2f64: StoreDFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000182
Scott Michel21213e72009-01-06 23:10:38 +0000183 def v2i32: StoreDFormVec<v2i32>;
184
Scott Michel053c1da2008-01-29 02:16:57 +0000185 def r128: StoreDForm<GPRC>;
186 def r64: StoreDForm<R64C>;
187 def r32: StoreDForm<R32C>;
188 def f32: StoreDForm<R32FP>;
189 def f64: StoreDForm<R64FP>;
190 def r16: StoreDForm<R16C>;
191 def r8: StoreDForm<R8C>;
192}
Scott Michel66377522007-12-04 22:35:58 +0000193
Scott Michel053c1da2008-01-29 02:16:57 +0000194class StoreAFormVec<ValueType vectype>
195 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000196 "stqa\t$rT, $src",
197 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000198 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000199
Scott Michel053c1da2008-01-29 02:16:57 +0000200class StoreAForm<RegisterClass rclass>
201 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000202 "stqa\t$rT, $src",
203 LoadStore,
Scott Michelad2715e2008-03-05 23:02:02 +0000204 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel66377522007-12-04 22:35:58 +0000205
Scott Michel053c1da2008-01-29 02:16:57 +0000206multiclass StoreAForms
207{
208 def v16i8: StoreAFormVec<v16i8>;
209 def v8i16: StoreAFormVec<v8i16>;
210 def v4i32: StoreAFormVec<v4i32>;
211 def v2i64: StoreAFormVec<v2i64>;
212 def v4f32: StoreAFormVec<v4f32>;
213 def v2f64: StoreAFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000214
Scott Michel21213e72009-01-06 23:10:38 +0000215 def v2i32: StoreAFormVec<v2i32>;
216
Scott Michel053c1da2008-01-29 02:16:57 +0000217 def r128: StoreAForm<GPRC>;
218 def r64: StoreAForm<R64C>;
219 def r32: StoreAForm<R32C>;
220 def f32: StoreAForm<R32FP>;
221 def f64: StoreAForm<R64FP>;
222 def r16: StoreAForm<R16C>;
223 def r8: StoreAForm<R8C>;
224}
Scott Michel66377522007-12-04 22:35:58 +0000225
Scott Michel053c1da2008-01-29 02:16:57 +0000226class StoreXFormVec<ValueType vectype>
227 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000228 "stqx\t$rT, $src",
229 LoadStore,
230 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000231{ }
Scott Michel66377522007-12-04 22:35:58 +0000232
Scott Michel053c1da2008-01-29 02:16:57 +0000233class StoreXForm<RegisterClass rclass>
234 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel7f9ba9b2008-01-30 02:55:46 +0000235 "stqx\t$rT, $src",
236 LoadStore,
237 [(store rclass:$rT, xform_addr:$src)]>
Scott Michel053c1da2008-01-29 02:16:57 +0000238{ }
Scott Michel66377522007-12-04 22:35:58 +0000239
Scott Michel053c1da2008-01-29 02:16:57 +0000240multiclass StoreXForms
241{
242 def v16i8: StoreXFormVec<v16i8>;
243 def v8i16: StoreXFormVec<v8i16>;
244 def v4i32: StoreXFormVec<v4i32>;
245 def v2i64: StoreXFormVec<v2i64>;
246 def v4f32: StoreXFormVec<v4f32>;
247 def v2f64: StoreXFormVec<v2f64>;
Scott Michel66377522007-12-04 22:35:58 +0000248
Scott Michel21213e72009-01-06 23:10:38 +0000249 def v2i32: StoreXFormVec<v2i32>;
250
Scott Michel053c1da2008-01-29 02:16:57 +0000251 def r128: StoreXForm<GPRC>;
252 def r64: StoreXForm<R64C>;
253 def r32: StoreXForm<R32C>;
254 def f32: StoreXForm<R32FP>;
255 def f64: StoreXForm<R64FP>;
256 def r16: StoreXForm<R16C>;
257 def r8: StoreXForm<R8C>;
258}
Scott Michel66377522007-12-04 22:35:58 +0000259
Scott Michel053c1da2008-01-29 02:16:57 +0000260defm STQD : StoreDForms;
261defm STQA : StoreAForms;
262defm STQX : StoreXForms;
Scott Michel66377522007-12-04 22:35:58 +0000263
264/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michel053c1da2008-01-29 02:16:57 +0000265 be useful for relocatable code.
Chris Lattnerc8478d82008-01-06 06:44:58 +0000266def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
267 "stqr\t$rT, $disp", LoadStore,
268 [(store VECREG:$rT, iaddr:$disp)]>;
269*/
Scott Michel66377522007-12-04 22:35:58 +0000270
271//===----------------------------------------------------------------------===//
272// Generate Controls for Insertion:
273//===----------------------------------------------------------------------===//
274
Scott Michelf0569be2008-12-27 04:51:36 +0000275def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000276 "cbd\t$rT, $src", ShuffleOp,
277 [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000278
Scott Michel1a6cdb62008-12-01 17:56:02 +0000279def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000280 "cbx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000281 [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000282
Scott Michelf0569be2008-12-27 04:51:36 +0000283def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000284 "chd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000285 [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000286
Scott Michel1a6cdb62008-12-01 17:56:02 +0000287def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000288 "chx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000289 [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000290
Scott Michelf0569be2008-12-27 04:51:36 +0000291def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000292 "cwd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000293 [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000294
Scott Michel1a6cdb62008-12-01 17:56:02 +0000295def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000296 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000297 [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000298
Scott Michelf0569be2008-12-27 04:51:36 +0000299def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000300 "cwd\t$rT, $src", ShuffleOp,
301 [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
302
303def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel203b2d62008-04-30 00:30:08 +0000304 "cwx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000305 [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000306
Scott Michelf0569be2008-12-27 04:51:36 +0000307def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000308 "cdd\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000309 [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000310
Scott Michel1a6cdb62008-12-01 17:56:02 +0000311def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel66377522007-12-04 22:35:58 +0000312 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000313 [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel66377522007-12-04 22:35:58 +0000314
Scott Michelf0569be2008-12-27 04:51:36 +0000315def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
Scott Michel1a6cdb62008-12-01 17:56:02 +0000316 "cdd\t$rT, $src", ShuffleOp,
317 [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
318
319def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
Scott Michel203b2d62008-04-30 00:30:08 +0000320 "cdx\t$rT, $src", ShuffleOp,
Scott Michel7a1c9e92008-11-22 23:50:42 +0000321 [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
Scott Michel203b2d62008-04-30 00:30:08 +0000322
Scott Michel66377522007-12-04 22:35:58 +0000323//===----------------------------------------------------------------------===//
324// Constant formation:
325//===----------------------------------------------------------------------===//
326
327def ILHv8i16:
328 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
329 "ilh\t$rT, $val", ImmLoad,
330 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
331
332def ILHr16:
333 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
334 "ilh\t$rT, $val", ImmLoad,
335 [(set R16C:$rT, immSExt16:$val)]>;
336
Scott Michel504c3692007-12-17 22:32:34 +0000337// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
338// the right constant")
339def ILHr8:
340 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
341 "ilh\t$rT, $val", ImmLoad,
342 [(set R8C:$rT, immSExt8:$val)]>;
343
Scott Michel66377522007-12-04 22:35:58 +0000344// IL does sign extension!
Scott Michel66377522007-12-04 22:35:58 +0000345
Scott Michelad2715e2008-03-05 23:02:02 +0000346class ILInst<dag OOL, dag IOL, list<dag> pattern>:
347 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
348 ImmLoad, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000349
Scott Michelad2715e2008-03-05 23:02:02 +0000350class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
351 ILInst<(outs VECREG:$rT), (ins immtype:$val),
352 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000353
Scott Michelad2715e2008-03-05 23:02:02 +0000354class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
355 ILInst<(outs rclass:$rT), (ins immtype:$val),
356 [(set rclass:$rT, xform:$val)]>;
Scott Michel66377522007-12-04 22:35:58 +0000357
Scott Michelad2715e2008-03-05 23:02:02 +0000358multiclass ImmediateLoad
359{
360 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
361 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel66377522007-12-04 22:35:58 +0000362
Scott Michelad2715e2008-03-05 23:02:02 +0000363 // TODO: Need v2f64, v4f32
Scott Michel66377522007-12-04 22:35:58 +0000364
Scott Michelad2715e2008-03-05 23:02:02 +0000365 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
366 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
367 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
368 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
369}
Scott Michel66377522007-12-04 22:35:58 +0000370
Scott Michelad2715e2008-03-05 23:02:02 +0000371defm IL : ImmediateLoad;
Scott Michel66377522007-12-04 22:35:58 +0000372
Scott Michelad2715e2008-03-05 23:02:02 +0000373class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
374 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
375 ImmLoad, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000376
Scott Michelad2715e2008-03-05 23:02:02 +0000377class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
378 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
379 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
380
381class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
382 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
383 [(set rclass:$rT, xform:$val)]>;
384
385multiclass ImmLoadHalfwordUpper
386{
387 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michel203b2d62008-04-30 00:30:08 +0000388 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michelad2715e2008-03-05 23:02:02 +0000389
390 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michel203b2d62008-04-30 00:30:08 +0000391 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michelad2715e2008-03-05 23:02:02 +0000392
393 // Loads the high portion of an address
394 def hi: ILHURegInst<R32C, symbolHi, hi16>;
395
396 // Used in custom lowering constant SFP loads:
397 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
398}
399
400defm ILHU : ImmLoadHalfwordUpper;
Scott Michel66377522007-12-04 22:35:58 +0000401
402// Immediate load address (can also be used to load 18-bit unsigned constants,
403// see the zext 16->32 pattern)
Scott Michelad2715e2008-03-05 23:02:02 +0000404
Scott Michela59d4692008-02-23 18:41:37 +0000405class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
406 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
407 LoadNOP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000408
Scott Michelad2715e2008-03-05 23:02:02 +0000409class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
410 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
411 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
412
413class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
414 ILAInst<(outs rclass:$rT), (ins immtype:$val),
415 [(set rclass:$rT, xform:$val)]>;
416
Scott Michela59d4692008-02-23 18:41:37 +0000417multiclass ImmLoadAddress
418{
Scott Michelad2715e2008-03-05 23:02:02 +0000419 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
420 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel66377522007-12-04 22:35:58 +0000421
Scott Michelad2715e2008-03-05 23:02:02 +0000422 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
423 def r32: ILARegInst<R32C, u18imm, imm18>;
424 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
425 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel66377522007-12-04 22:35:58 +0000426
Scott Michelf0569be2008-12-27 04:51:36 +0000427 def hi: ILARegInst<R32C, symbolHi, imm18>;
Scott Michelad2715e2008-03-05 23:02:02 +0000428 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel66377522007-12-04 22:35:58 +0000429
Scott Michela59d4692008-02-23 18:41:37 +0000430 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
431 [/* no pattern */]>;
432}
433
434defm ILA : ImmLoadAddress;
Scott Michel66377522007-12-04 22:35:58 +0000435
436// Immediate OR, Halfword Lower: The "other" part of loading large constants
437// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
438// Note that these are really two operand instructions, but they're encoded
439// as three operands with the first two arguments tied-to each other.
440
Scott Michelad2715e2008-03-05 23:02:02 +0000441class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
442 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
443 ImmLoad, pattern>,
444 RegConstraint<"$rS = $rT">,
445 NoEncode<"$rS">;
Scott Michel66377522007-12-04 22:35:58 +0000446
Scott Michelad2715e2008-03-05 23:02:02 +0000447class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
448 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
449 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000450
Scott Michelad2715e2008-03-05 23:02:02 +0000451class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
452 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
453 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000454
Scott Michelad2715e2008-03-05 23:02:02 +0000455multiclass ImmOrHalfwordLower
456{
457 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michel203b2d62008-04-30 00:30:08 +0000458 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michelad2715e2008-03-05 23:02:02 +0000459
460 def r32: IOHLRegInst<R32C, i32imm>;
461 def f32: IOHLRegInst<R32FP, f32imm>;
462
463 def lo: IOHLRegInst<R32C, symbolLo>;
464}
465
466defm IOHL: ImmOrHalfwordLower;
Scott Michel9de5d0d2008-01-11 02:53:15 +0000467
Scott Michel66377522007-12-04 22:35:58 +0000468// Form select mask for bytes using immediate, used in conjunction with the
469// SELB instruction:
470
Scott Michelad2715e2008-03-05 23:02:02 +0000471class FSMBIVec<ValueType vectype>:
472 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
473 "fsmbi\t$rT, $val",
474 SelectOp,
Scott Michel8bf61e82008-06-02 22:18:03 +0000475 [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000476
Scott Michela59d4692008-02-23 18:41:37 +0000477multiclass FormSelectMaskBytesImm
Scott Michel053c1da2008-01-29 02:16:57 +0000478{
479 def v16i8: FSMBIVec<v16i8>;
480 def v8i16: FSMBIVec<v8i16>;
481 def v4i32: FSMBIVec<v4i32>;
482 def v2i64: FSMBIVec<v2i64>;
483}
Scott Michel66377522007-12-04 22:35:58 +0000484
Scott Michela59d4692008-02-23 18:41:37 +0000485defm FSMBI : FormSelectMaskBytesImm;
486
487// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
Scott Michelf0569be2008-12-27 04:51:36 +0000488class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
489 RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
490 pattern>;
491
492class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
493 FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
494 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
495
496class FSMBVecInst<ValueType vectype>:
497 FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
498 [(set (vectype VECREG:$rT),
499 (SPUselmask (vectype VECREG:$rA)))]>;
500
501multiclass FormSelectMaskBits {
502 def v16i8_r16: FSMBRegInst<R16C, v16i8>;
503 def v16i8: FSMBVecInst<v16i8>;
504}
505
506defm FSMB: FormSelectMaskBits;
Scott Michela59d4692008-02-23 18:41:37 +0000507
508// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
509// only 8-bits wide (even though it's input as 16-bits here)
Scott Michelf0569be2008-12-27 04:51:36 +0000510
511class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
512 RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
513 pattern>;
514
515class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
516 FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
517 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
518
519class FSMHVecInst<ValueType vectype>:
520 FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
521 [(set (vectype VECREG:$rT),
522 (SPUselmask (vectype VECREG:$rA)))]>;
523
524multiclass FormSelectMaskHalfword {
525 def v8i16_r16: FSMHRegInst<R16C, v8i16>;
526 def v8i16: FSMHVecInst<v8i16>;
527}
528
529defm FSMH: FormSelectMaskHalfword;
Scott Michela59d4692008-02-23 18:41:37 +0000530
531// fsm: Form select mask for words. Like the other fsm* instructions,
532// only the lower 4 bits of $rA are significant.
Scott Michelf0569be2008-12-27 04:51:36 +0000533
534class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
535 RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
536 pattern>;
537
538class FSMRegInst<ValueType vectype, RegisterClass rclass>:
539 FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
540 [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
541
542class FSMVecInst<ValueType vectype>:
543 FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
544 [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000545
546multiclass FormSelectMaskWord {
Scott Michelf0569be2008-12-27 04:51:36 +0000547 def v4i32: FSMVecInst<v4i32>;
548
549 def r32 : FSMRegInst<v4i32, R32C>;
550 def r16 : FSMRegInst<v4i32, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000551}
552
553defm FSM : FormSelectMaskWord;
554
555// Special case when used for i64 math operations
556multiclass FormSelectMaskWord64 {
Scott Michelf0569be2008-12-27 04:51:36 +0000557 def r32 : FSMRegInst<v2i64, R32C>;
558 def r16 : FSMRegInst<v2i64, R16C>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000559}
560
561defm FSM64 : FormSelectMaskWord64;
Scott Michel66377522007-12-04 22:35:58 +0000562
563//===----------------------------------------------------------------------===//
564// Integer and Logical Operations:
565//===----------------------------------------------------------------------===//
566
567def AHv8i16:
568 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
569 "ah\t$rT, $rA, $rB", IntegerOp,
570 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
571
572def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
573 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
574
Scott Michel66377522007-12-04 22:35:58 +0000575def AHr16:
576 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
577 "ah\t$rT, $rA, $rB", IntegerOp,
578 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
579
580def AHIvec:
581 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
582 "ahi\t$rT, $rA, $val", IntegerOp,
583 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
584 v8i16SExt10Imm:$val))]>;
585
Scott Michela59d4692008-02-23 18:41:37 +0000586def AHIr16:
587 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
588 "ahi\t$rT, $rA, $val", IntegerOp,
Scott Michel02d711b2008-12-30 23:28:25 +0000589 [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
590
591// v4i32, i32 add instruction:
Scott Michel66377522007-12-04 22:35:58 +0000592
Scott Michel1df30c42008-12-29 03:23:36 +0000593class AInst<dag OOL, dag IOL, list<dag> pattern>:
594 RRForm<0b00000011000, OOL, IOL,
595 "a\t$rT, $rA, $rB", IntegerOp,
596 pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000597
Scott Michel1df30c42008-12-29 03:23:36 +0000598class AVecInst<ValueType vectype>:
599 AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
600 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
601 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000602
Scott Michel1df30c42008-12-29 03:23:36 +0000603class ARegInst<RegisterClass rclass>:
604 AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
605 [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
606
607multiclass AddInstruction {
608 def v4i32: AVecInst<v4i32>;
609 def v16i8: AVecInst<v16i8>;
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000610 def v2i32: AVecInst<v2i32>;
Scott Michel1df30c42008-12-29 03:23:36 +0000611 def r32: ARegInst<R32C>;
Scott Michel1df30c42008-12-29 03:23:36 +0000612}
Scott Michel66377522007-12-04 22:35:58 +0000613
Scott Michel1df30c42008-12-29 03:23:36 +0000614defm A : AddInstruction;
Scott Michel504c3692007-12-17 22:32:34 +0000615
Scott Michel02d711b2008-12-30 23:28:25 +0000616class AIInst<dag OOL, dag IOL, list<dag> pattern>:
617 RI10Form<0b00111000, OOL, IOL,
Scott Michel19c10e62009-01-26 03:37:41 +0000618 "ai\t$rT, $rA, $val", IntegerOp,
619 pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000620
Scott Michel02d711b2008-12-30 23:28:25 +0000621class AIVecInst<ValueType vectype, PatLeaf immpred>:
622 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000623 [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000624
625class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
626 AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000627 [/* no pattern */]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000628
629class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
630 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000631 [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000632
633// This is used to add epsilons to floating point numbers in the f32 fdiv code:
634class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
635 AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +0000636 [/* no pattern */]>;
Scott Michel02d711b2008-12-30 23:28:25 +0000637
638multiclass AddImmediate {
639 def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
640
641 def r32: AIRegInst<R32C, i32ImmSExt10>;
642
643 def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
644 def f32: AIFPInst<R32FP, i32ImmSExt10>;
645}
646
647defm AI : AddImmediate;
Scott Michel66377522007-12-04 22:35:58 +0000648
Scott Michel504c3692007-12-17 22:32:34 +0000649def SFHvec:
650 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
651 "sfh\t$rT, $rA, $rB", IntegerOp,
652 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
653 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000654
Scott Michel504c3692007-12-17 22:32:34 +0000655def SFHr16:
656 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
657 "sfh\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000658 [(set R16C:$rT, (sub R16C:$rB, R16C:$rA))]>;
Scott Michel66377522007-12-04 22:35:58 +0000659
660def SFHIvec:
661 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
662 "sfhi\t$rT, $rA, $val", IntegerOp,
663 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
664 (v8i16 VECREG:$rA)))]>;
665
666def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
667 "sfhi\t$rT, $rA, $val", IntegerOp,
668 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
669
670def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
671 (ins VECREG:$rA, VECREG:$rB),
672 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000673 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rB), (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000674
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000675def SF2vec : RRForm<0b00000010000, (outs VECREG:$rT),
676 (ins VECREG:$rA, VECREG:$rB),
677 "sf\t$rT, $rA, $rB", IntegerOp,
678 [(set (v2i32 VECREG:$rT), (sub (v2i32 VECREG:$rB), (v2i32 VECREG:$rA)))]>;
679
680
Scott Michel66377522007-12-04 22:35:58 +0000681def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
682 "sf\t$rT, $rA, $rB", IntegerOp,
Kalle Raiskila26c4cf4c2010-05-10 08:13:49 +0000683 [(set R32C:$rT, (sub R32C:$rB, R32C:$rA))]>;
Scott Michel66377522007-12-04 22:35:58 +0000684
685def SFIvec:
686 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
687 "sfi\t$rT, $rA, $val", IntegerOp,
688 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
689 (v4i32 VECREG:$rA)))]>;
690
691def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
692 (ins R32C:$rA, s10imm_i32:$val),
693 "sfi\t$rT, $rA, $val", IntegerOp,
694 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
695
696// ADDX: only available in vector form, doesn't match a pattern.
Scott Michel8bf61e82008-06-02 22:18:03 +0000697class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
698 RRForm<0b00000010110, OOL, IOL,
699 "addx\t$rT, $rA, $rB",
700 IntegerOp, pattern>;
701
702class ADDXVecInst<ValueType vectype>:
703 ADDXInst<(outs VECREG:$rT),
704 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000705 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000706 RegConstraint<"$rCarry = $rT">,
707 NoEncode<"$rCarry">;
708
Scott Michel8bf61e82008-06-02 22:18:03 +0000709class ADDXRegInst<RegisterClass rclass>:
710 ADDXInst<(outs rclass:$rT),
711 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000712 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000713 RegConstraint<"$rCarry = $rT">,
714 NoEncode<"$rCarry">;
715
Scott Michel8bf61e82008-06-02 22:18:03 +0000716multiclass AddExtended {
717 def v2i64 : ADDXVecInst<v2i64>;
718 def v4i32 : ADDXVecInst<v4i32>;
719 def r64 : ADDXRegInst<R64C>;
720 def r32 : ADDXRegInst<R32C>;
721}
722
723defm ADDX : AddExtended;
724
725// CG: Generate carry for add
726class CGInst<dag OOL, dag IOL, list<dag> pattern>:
727 RRForm<0b01000011000, OOL, IOL,
728 "cg\t$rT, $rA, $rB",
729 IntegerOp, pattern>;
730
731class CGVecInst<ValueType vectype>:
732 CGInst<(outs VECREG:$rT),
733 (ins VECREG:$rA, VECREG:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000734 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000735
736class CGRegInst<RegisterClass rclass>:
737 CGInst<(outs rclass:$rT),
738 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000739 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000740
741multiclass CarryGenerate {
742 def v2i64 : CGVecInst<v2i64>;
743 def v4i32 : CGVecInst<v4i32>;
744 def r64 : CGRegInst<R64C>;
745 def r32 : CGRegInst<R32C>;
746}
747
748defm CG : CarryGenerate;
749
750// SFX: Subract from, extended. This is used in conjunction with BG to subtract
751// with carry (borrow, in this case)
752class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
753 RRForm<0b10000010110, OOL, IOL,
754 "sfx\t$rT, $rA, $rB",
755 IntegerOp, pattern>;
756
757class SFXVecInst<ValueType vectype>:
758 SFXInst<(outs VECREG:$rT),
759 (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000760 [/* no pattern */]>,
Scott Michel66377522007-12-04 22:35:58 +0000761 RegConstraint<"$rCarry = $rT">,
762 NoEncode<"$rCarry">;
763
Scott Michel8bf61e82008-06-02 22:18:03 +0000764class SFXRegInst<RegisterClass rclass>:
765 SFXInst<(outs rclass:$rT),
766 (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
Scott Michel94bd57e2009-01-15 04:41:47 +0000767 [/* no pattern */]>,
Scott Michel8bf61e82008-06-02 22:18:03 +0000768 RegConstraint<"$rCarry = $rT">,
769 NoEncode<"$rCarry">;
770
771multiclass SubtractExtended {
772 def v2i64 : SFXVecInst<v2i64>;
773 def v4i32 : SFXVecInst<v4i32>;
774 def r64 : SFXRegInst<R64C>;
775 def r32 : SFXRegInst<R32C>;
776}
777
778defm SFX : SubtractExtended;
779
Scott Michel66377522007-12-04 22:35:58 +0000780// BG: only available in vector form, doesn't match a pattern.
Scott Michel8bf61e82008-06-02 22:18:03 +0000781class BGInst<dag OOL, dag IOL, list<dag> pattern>:
782 RRForm<0b01000010000, OOL, IOL,
783 "bg\t$rT, $rA, $rB",
784 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +0000785
Scott Michel8bf61e82008-06-02 22:18:03 +0000786class BGVecInst<ValueType vectype>:
787 BGInst<(outs VECREG:$rT),
788 (ins VECREG:$rA, VECREG:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000789 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000790
791class BGRegInst<RegisterClass rclass>:
792 BGInst<(outs rclass:$rT),
793 (ins rclass:$rA, rclass:$rB),
Scott Michel94bd57e2009-01-15 04:41:47 +0000794 [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +0000795
796multiclass BorrowGenerate {
797 def v4i32 : BGVecInst<v4i32>;
798 def v2i64 : BGVecInst<v2i64>;
799 def r64 : BGRegInst<R64C>;
800 def r32 : BGRegInst<R32C>;
801}
802
803defm BG : BorrowGenerate;
804
805// BGX: Borrow generate, extended.
Scott Michel66377522007-12-04 22:35:58 +0000806def BGXvec:
807 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
Scott Michelf0569be2008-12-27 04:51:36 +0000808 VECREG:$rCarry),
Scott Michel66377522007-12-04 22:35:58 +0000809 "bgx\t$rT, $rA, $rB", IntegerOp,
810 []>,
811 RegConstraint<"$rCarry = $rT">,
812 NoEncode<"$rCarry">;
813
814// Halfword multiply variants:
815// N.B: These can be used to build up larger quantities (16x16 -> 32)
816
817def MPYv8i16:
818 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
819 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000820 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000821
822def MPYr16:
823 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
824 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
825 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
826
Scott Michel1df30c42008-12-29 03:23:36 +0000827// Unsigned 16-bit multiply:
828
829class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
830 RRForm<0b00110011110, OOL, IOL,
831 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
832 pattern>;
833
Scott Michel66377522007-12-04 22:35:58 +0000834def MPYUv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000835 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000836 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000837
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000838def MPYUv2i32:
839 MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
840 [/* no pattern */]>;
841
Scott Michel66377522007-12-04 22:35:58 +0000842def MPYUr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000843 MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
844 [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000845
846def MPYUr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000847 MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000848 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000849
Scott Michel1df30c42008-12-29 03:23:36 +0000850// mpyi: multiply 16 x s10imm -> 32 result.
851
852class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
853 RI10Form<0b00101110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000854 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
Scott Michel1df30c42008-12-29 03:23:36 +0000855 pattern>;
856
857def MPYIvec:
858 MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
859 [(set (v8i16 VECREG:$rT),
860 (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000861
862def MPYIr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000863 MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
864 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +0000865
866// mpyui: same issues as other multiplies, plus, this doesn't match a
867// pattern... but may be used during target DAG selection or lowering
Scott Michel1df30c42008-12-29 03:23:36 +0000868
869class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
870 RI10Form<0b10101110, OOL, IOL,
871 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
872 pattern>;
873
Scott Michel66377522007-12-04 22:35:58 +0000874def MPYUIvec:
Scott Michel1df30c42008-12-29 03:23:36 +0000875 MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
876 []>;
Scott Michel66377522007-12-04 22:35:58 +0000877
878def MPYUIr16:
Scott Michel1df30c42008-12-29 03:23:36 +0000879 MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
880 []>;
Scott Michel66377522007-12-04 22:35:58 +0000881
882// mpya: 16 x 16 + 16 -> 32 bit result
Scott Michel1df30c42008-12-29 03:23:36 +0000883class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
884 RRRForm<0b0011, OOL, IOL,
885 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
886 pattern>;
887
Scott Michel94bd57e2009-01-15 04:41:47 +0000888def MPYAv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000889 MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
890 [(set (v4i32 VECREG:$rT),
891 (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
892 (v8i16 VECREG:$rB)))),
893 (v4i32 VECREG:$rC)))]>;
Scott Michel66377522007-12-04 22:35:58 +0000894
895def MPYAr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000896 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
897 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
898 R32C:$rC))]>;
899
900def MPYAr32_sext:
901 MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
902 [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
903 R32C:$rC))]>;
Scott Michel66377522007-12-04 22:35:58 +0000904
905def MPYAr32_sextinreg:
Scott Michel1df30c42008-12-29 03:23:36 +0000906 MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
907 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
908 (sext_inreg R32C:$rB, i16)),
909 R32C:$rC))]>;
Scott Michel66377522007-12-04 22:35:58 +0000910
911// mpyh: multiply high, used to synthesize 32-bit multiplies
Scott Michel1df30c42008-12-29 03:23:36 +0000912class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
913 RRForm<0b10100011110, OOL, IOL,
914 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
915 pattern>;
916
Scott Michel66377522007-12-04 22:35:58 +0000917def MPYHv4i32:
Scott Michel1df30c42008-12-29 03:23:36 +0000918 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000919 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000920
Kalle Raiskila82fe4672010-08-02 08:54:39 +0000921def MPYHv2i32:
922 MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
923 [/* no pattern */]>;
924
Scott Michel66377522007-12-04 22:35:58 +0000925def MPYHr32:
Scott Michel1df30c42008-12-29 03:23:36 +0000926 MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +0000927 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +0000928
929// mpys: multiply high and shift right (returns the top half of
930// a 16-bit multiply, sign extended to 32 bits.)
Scott Michel66377522007-12-04 22:35:58 +0000931
Scott Michel02d711b2008-12-30 23:28:25 +0000932class MPYSInst<dag OOL, dag IOL>:
933 RRForm<0b11100011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000934 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000935 [/* no pattern */]>;
936
Scott Michel94bd57e2009-01-15 04:41:47 +0000937def MPYSv4i32:
Scott Michel02d711b2008-12-30 23:28:25 +0000938 MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
939
940def MPYSr16:
941 MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000942
943// mpyhh: multiply high-high (returns the 32-bit result from multiplying
944// the top 16 bits of the $rA, $rB)
Scott Michel02d711b2008-12-30 23:28:25 +0000945
946class MPYHHInst<dag OOL, dag IOL>:
947 RRForm<0b01100011110, OOL, IOL,
948 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
949 [/* no pattern */]>;
950
Scott Michel66377522007-12-04 22:35:58 +0000951def MPYHHv8i16:
Scott Michel02d711b2008-12-30 23:28:25 +0000952 MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000953
954def MPYHHr32:
Scott Michel02d711b2008-12-30 23:28:25 +0000955 MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000956
957// mpyhha: Multiply high-high, add to $rT:
Scott Michel66377522007-12-04 22:35:58 +0000958
Scott Michel02d711b2008-12-30 23:28:25 +0000959class MPYHHAInst<dag OOL, dag IOL>:
960 RRForm<0b01100010110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000961 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000962 [/* no pattern */]>;
963
964def MPYHHAvec:
965 MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
966
967def MPYHHAr32:
968 MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000969
Scott Michel94bd57e2009-01-15 04:41:47 +0000970// mpyhhu: Multiply high-high, unsigned, e.g.:
971//
972// +-------+-------+ +-------+-------+ +---------+
973// | a0 . a1 | x | b0 . b1 | = | a0 x b0 |
974// +-------+-------+ +-------+-------+ +---------+
975//
976// where a0, b0 are the upper 16 bits of the 32-bit word
Scott Michel66377522007-12-04 22:35:58 +0000977
Scott Michel02d711b2008-12-30 23:28:25 +0000978class MPYHHUInst<dag OOL, dag IOL>:
979 RRForm<0b01110011110, OOL, IOL,
Scott Michel66377522007-12-04 22:35:58 +0000980 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
Scott Michel02d711b2008-12-30 23:28:25 +0000981 [/* no pattern */]>;
982
Scott Michel94bd57e2009-01-15 04:41:47 +0000983def MPYHHUv4i32:
Scott Michel02d711b2008-12-30 23:28:25 +0000984 MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
985
986def MPYHHUr32:
987 MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +0000988
989// mpyhhau: Multiply high-high, unsigned
Scott Michel02d711b2008-12-30 23:28:25 +0000990
991class MPYHHAUInst<dag OOL, dag IOL>:
992 RRForm<0b01110010110, OOL, IOL,
993 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
994 [/* no pattern */]>;
995
Scott Michel66377522007-12-04 22:35:58 +0000996def MPYHHAUvec:
Scott Michel02d711b2008-12-30 23:28:25 +0000997 MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
998
Scott Michel66377522007-12-04 22:35:58 +0000999def MPYHHAUr32:
Scott Michel02d711b2008-12-30 23:28:25 +00001000 MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
Scott Michel1df30c42008-12-29 03:23:36 +00001001
1002//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00001003// clz: Count leading zeroes
Scott Michel1df30c42008-12-29 03:23:36 +00001004//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michelf0569be2008-12-27 04:51:36 +00001005class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1006 RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1007 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001008
Scott Michelf0569be2008-12-27 04:51:36 +00001009class CLZRegInst<RegisterClass rclass>:
1010 CLZInst<(outs rclass:$rT), (ins rclass:$rA),
Scott Michel02d711b2008-12-30 23:28:25 +00001011 [(set rclass:$rT, (ctlz rclass:$rA))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001012
1013class CLZVecInst<ValueType vectype>:
1014 CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1015 [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1016
1017multiclass CountLeadingZeroes {
1018 def v4i32 : CLZVecInst<v4i32>;
1019 def r32 : CLZRegInst<R32C>;
1020}
1021
1022defm CLZ : CountLeadingZeroes;
Scott Michel66377522007-12-04 22:35:58 +00001023
1024// cntb: Count ones in bytes (aka "population count")
Scott Michelf0569be2008-12-27 04:51:36 +00001025//
Scott Michel66377522007-12-04 22:35:58 +00001026// NOTE: This instruction is really a vector instruction, but the custom
1027// lowering code uses it in unorthodox ways to support CTPOP for other
1028// data types!
Scott Michelf0569be2008-12-27 04:51:36 +00001029
Scott Michel66377522007-12-04 22:35:58 +00001030def CNTBv16i8:
1031 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1032 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001033 [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001034
1035def CNTBv8i16 :
1036 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1037 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001038 [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001039
1040def CNTBv4i32 :
1041 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1042 "cntb\t$rT, $rA", IntegerOp,
Scott Michel8bf61e82008-06-02 22:18:03 +00001043 [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001044
Scott Michelf0569be2008-12-27 04:51:36 +00001045// gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1046// quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1047// slots 1-3.
1048//
1049// Note: This instruction "pairs" with the fsmb instruction for all of the
1050// various types defined here.
1051//
1052// Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1053// a vector or register.
1054
1055class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1056 RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1057
1058class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1059 GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001060 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001061
1062class GBBVecInst<ValueType vectype>:
1063 GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001064 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001065
1066multiclass GatherBitsFromBytes {
1067 def v16i8_r32: GBBRegInst<R32C, v16i8>;
1068 def v16i8_r16: GBBRegInst<R16C, v16i8>;
1069 def v16i8: GBBVecInst<v16i8>;
1070}
1071
1072defm GBB: GatherBitsFromBytes;
Scott Michel66377522007-12-04 22:35:58 +00001073
1074// gbh: Gather all low order bits from each halfword in $rA into a single
Scott Michelf0569be2008-12-27 04:51:36 +00001075// 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1076// and slots 1-3 also set to 0.
1077//
1078// See notes for GBBInst, above.
1079
1080class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1081 RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1082 pattern>;
1083
1084class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1085 GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001086 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001087
1088class GBHVecInst<ValueType vectype>:
1089 GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001090 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001091
1092multiclass GatherBitsHalfword {
1093 def v8i16_r32: GBHRegInst<R32C, v8i16>;
1094 def v8i16_r16: GBHRegInst<R16C, v8i16>;
1095 def v8i16: GBHVecInst<v8i16>;
1096}
1097
1098defm GBH: GatherBitsHalfword;
Scott Michel66377522007-12-04 22:35:58 +00001099
1100// gb: Gather all low order bits from each word in $rA into a single
Scott Michelf0569be2008-12-27 04:51:36 +00001101// 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1102// as well as slots 1-3.
1103//
1104// See notes for gbb, above.
1105
1106class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1107 RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1108 pattern>;
1109
1110class GBRegInst<RegisterClass rclass, ValueType vectype>:
1111 GBInst<(outs rclass:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001112 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001113
1114class GBVecInst<ValueType vectype>:
1115 GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
Scott Michel21213e72009-01-06 23:10:38 +00001116 [/* no pattern */]>;
Scott Michelf0569be2008-12-27 04:51:36 +00001117
1118multiclass GatherBitsWord {
1119 def v4i32_r32: GBRegInst<R32C, v4i32>;
1120 def v4i32_r16: GBRegInst<R16C, v4i32>;
1121 def v4i32: GBVecInst<v4i32>;
1122}
1123
1124defm GB: GatherBitsWord;
Scott Michel66377522007-12-04 22:35:58 +00001125
1126// avgb: average bytes
1127def AVGB:
1128 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1129 "avgb\t$rT, $rA, $rB", ByteOp,
1130 []>;
1131
1132// absdb: absolute difference of bytes
1133def ABSDB:
1134 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1135 "absdb\t$rT, $rA, $rB", ByteOp,
1136 []>;
1137
1138// sumb: sum bytes into halfwords
1139def SUMB:
1140 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1141 "sumb\t$rT, $rA, $rB", ByteOp,
1142 []>;
1143
1144// Sign extension operations:
Scott Michel8bf61e82008-06-02 22:18:03 +00001145class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1146 RRForm_1<0b01101101010, OOL, IOL,
1147 "xsbh\t$rDst, $rSrc",
1148 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001149
Scott Micheldd950092009-01-06 03:36:14 +00001150class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
Scott Michel8bf61e82008-06-02 22:18:03 +00001151 XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
Scott Micheldd950092009-01-06 03:36:14 +00001152 pattern>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001153
1154multiclass ExtendByteHalfword {
Chris Lattnere9eda0f2010-03-19 04:53:47 +00001155 def v16i8: XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1156 [
1157 /*(set (v8i16 VECREG:$rDst), (sext (v8i16 VECREG:$rSrc)))*/]>;
Scott Micheldd950092009-01-06 03:36:14 +00001158 def r8: XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1159 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1160 def r16: XSBHInRegInst<R16C,
1161 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001162
1163 // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1164 // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1165 // pattern below). Intentionally doesn't match a pattern because we want the
1166 // sext 8->32 pattern to do the work for us, namely because we need the extra
1167 // XSHWr32.
Scott Micheldd950092009-01-06 03:36:14 +00001168 def r32: XSBHInRegInst<R32C, [/* no pattern */]>;
1169
1170 // Same as the 32-bit version, but for i64
1171 def r64: XSBHInRegInst<R64C, [/* no pattern */]>;
Scott Michel8bf61e82008-06-02 22:18:03 +00001172}
1173
1174defm XSBH : ExtendByteHalfword;
1175
Scott Michel66377522007-12-04 22:35:58 +00001176// Sign extend halfwords to words:
Scott Michel66377522007-12-04 22:35:58 +00001177
Scott Micheldd950092009-01-06 03:36:14 +00001178class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1179 RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1180 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001181
Scott Micheldd950092009-01-06 03:36:14 +00001182class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1183 XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1184 [(set (out_vectype VECREG:$rDest),
1185 (sext (in_vectype VECREG:$rSrc)))]>;
1186
1187class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1188 XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1189 pattern>;
1190
1191class XSHWRegInst<RegisterClass rclass>:
1192 XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1193 [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1194
1195multiclass ExtendHalfwordWord {
1196 def v4i32: XSHWVecInst<v4i32, v8i16>;
1197
1198 def r16: XSHWRegInst<R32C>;
1199
1200 def r32: XSHWInRegInst<R32C,
1201 [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1202 def r64: XSHWInRegInst<R64C, [/* no pattern */]>;
1203}
1204
1205defm XSHW : ExtendHalfwordWord;
Scott Michel66377522007-12-04 22:35:58 +00001206
Scott Micheled741dd2009-01-05 01:34:35 +00001207// Sign-extend words to doublewords (32->64 bits)
Scott Michel66377522007-12-04 22:35:58 +00001208
Scott Micheled741dd2009-01-05 01:34:35 +00001209class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Micheldd950092009-01-06 03:36:14 +00001210 RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1211 IntegerOp, pattern>;
Scott Micheled741dd2009-01-05 01:34:35 +00001212
1213class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1214 XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
Chris Lattnere9eda0f2010-03-19 04:53:47 +00001215 [/*(set (out_vectype VECREG:$rDst),
1216 (sext (out_vectype VECREG:$rSrc)))*/]>;
Scott Micheled741dd2009-01-05 01:34:35 +00001217
1218class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1219 XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1220 [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1221
1222multiclass ExtendWordToDoubleWord {
1223 def v2i64: XSWDVecInst<v4i32, v2i64>;
1224 def r64: XSWDRegInst<R32C, R64C>;
1225
1226 def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1227 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1228}
Scott Michel66377522007-12-04 22:35:58 +00001229
Scott Micheled741dd2009-01-05 01:34:35 +00001230defm XSWD : ExtendWordToDoubleWord;
Scott Michel66377522007-12-04 22:35:58 +00001231
1232// AND operations
Scott Michel66377522007-12-04 22:35:58 +00001233
Scott Michela59d4692008-02-23 18:41:37 +00001234class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1235 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1236 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001237
Scott Michela59d4692008-02-23 18:41:37 +00001238class ANDVecInst<ValueType vectype>:
1239 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1240 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1241 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001242
Scott Michelad2715e2008-03-05 23:02:02 +00001243class ANDRegInst<RegisterClass rclass>:
1244 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1245 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1246
Scott Michela59d4692008-02-23 18:41:37 +00001247multiclass BitwiseAnd
1248{
1249 def v16i8: ANDVecInst<v16i8>;
1250 def v8i16: ANDVecInst<v8i16>;
1251 def v4i32: ANDVecInst<v4i32>;
1252 def v2i64: ANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001253
Scott Michelad2715e2008-03-05 23:02:02 +00001254 def r128: ANDRegInst<GPRC>;
1255 def r64: ANDRegInst<R64C>;
1256 def r32: ANDRegInst<R32C>;
1257 def r16: ANDRegInst<R16C>;
1258 def r8: ANDRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001259
Scott Michela59d4692008-02-23 18:41:37 +00001260 //===---------------------------------------------
1261 // Special instructions to perform the fabs instruction
1262 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1263 [/* Intentionally does not match a pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00001264
Scott Michel7ea02ff2009-03-17 01:15:45 +00001265 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001266 [/* Intentionally does not match a pattern */]>;
1267
Scott Michela59d4692008-02-23 18:41:37 +00001268 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1269 [/* Intentionally does not match a pattern */]>;
1270
1271 //===---------------------------------------------
1272
1273 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1274 // quantities -- see 16->32 zext pattern.
1275 //
1276 // This pattern is somewhat artificial, since it might match some
1277 // compiler generated pattern but it is unlikely to do so.
1278
1279 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1280 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1281}
1282
1283defm AND : BitwiseAnd;
Scott Michel66377522007-12-04 22:35:58 +00001284
Chris Lattner918472a2010-03-28 07:48:17 +00001285
1286def vnot_cell_conv : PatFrag<(ops node:$in),
1287 (xor node:$in, (bitconvert (v4i32 immAllOnesV)))>;
1288
1289// N.B.: vnot_cell_conv is one of those special target selection pattern
1290// fragments,
Scott Michel66377522007-12-04 22:35:58 +00001291// in which we expect there to be a bit_convert on the constant. Bear in mind
1292// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1293// constant -1 vector.)
Scott Michel66377522007-12-04 22:35:58 +00001294
Scott Michela59d4692008-02-23 18:41:37 +00001295class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1296 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1297 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001298
Scott Michel7ea02ff2009-03-17 01:15:45 +00001299class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michela59d4692008-02-23 18:41:37 +00001300 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel7ea02ff2009-03-17 01:15:45 +00001301 [(set (vectype VECREG:$rT),
1302 (and (vectype VECREG:$rA),
1303 (vnot_frag (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001304
Scott Michela59d4692008-02-23 18:41:37 +00001305class ANDCRegInst<RegisterClass rclass>:
1306 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1307 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001308
Scott Michela59d4692008-02-23 18:41:37 +00001309multiclass AndComplement
1310{
1311 def v16i8: ANDCVecInst<v16i8>;
1312 def v8i16: ANDCVecInst<v8i16>;
1313 def v4i32: ANDCVecInst<v4i32>;
1314 def v2i64: ANDCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001315
Scott Michela59d4692008-02-23 18:41:37 +00001316 def r128: ANDCRegInst<GPRC>;
1317 def r64: ANDCRegInst<R64C>;
1318 def r32: ANDCRegInst<R32C>;
1319 def r16: ANDCRegInst<R16C>;
1320 def r8: ANDCRegInst<R8C>;
Scott Michel7ea02ff2009-03-17 01:15:45 +00001321
1322 // Sometimes, the xor pattern has a bitcast constant:
Chris Lattner918472a2010-03-28 07:48:17 +00001323 def v16i8_conv: ANDCVecInst<v16i8, vnot_cell_conv>;
Scott Michela59d4692008-02-23 18:41:37 +00001324}
Scott Michel504c3692007-12-17 22:32:34 +00001325
Scott Michela59d4692008-02-23 18:41:37 +00001326defm ANDC : AndComplement;
Scott Michel66377522007-12-04 22:35:58 +00001327
Scott Michela59d4692008-02-23 18:41:37 +00001328class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1329 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
Scott Michelaedc6372008-12-10 00:15:19 +00001330 ByteOp, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00001331
Scott Michela59d4692008-02-23 18:41:37 +00001332multiclass AndByteImm
1333{
1334 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1335 [(set (v16i8 VECREG:$rT),
1336 (and (v16i8 VECREG:$rA),
1337 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001338
Scott Michela59d4692008-02-23 18:41:37 +00001339 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1340 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1341}
Scott Michel504c3692007-12-17 22:32:34 +00001342
Scott Michela59d4692008-02-23 18:41:37 +00001343defm ANDBI : AndByteImm;
Scott Michel66377522007-12-04 22:35:58 +00001344
Scott Michela59d4692008-02-23 18:41:37 +00001345class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1346 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
Scott Michelaedc6372008-12-10 00:15:19 +00001347 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001348
Scott Michela59d4692008-02-23 18:41:37 +00001349multiclass AndHalfwordImm
1350{
1351 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1352 [(set (v8i16 VECREG:$rT),
1353 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001354
Scott Michela59d4692008-02-23 18:41:37 +00001355 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1356 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001357
Scott Michela59d4692008-02-23 18:41:37 +00001358 // Zero-extend i8 to i16:
1359 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1360 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1361}
Scott Michel66377522007-12-04 22:35:58 +00001362
Scott Michela59d4692008-02-23 18:41:37 +00001363defm ANDHI : AndHalfwordImm;
1364
1365class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1366 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1367 IntegerOp, pattern>;
1368
1369multiclass AndWordImm
1370{
1371 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1372 [(set (v4i32 VECREG:$rT),
1373 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1374
1375 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1376 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1377
1378 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1379 // pattern below.
1380 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1381 [(set R32C:$rT,
1382 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1383
1384 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1385 // zext 16->32 pattern below.
1386 //
1387 // Note that this pattern is somewhat artificial, since it might match
1388 // something the compiler generates but is unlikely to occur in practice.
1389 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1390 [(set R32C:$rT,
1391 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1392}
1393
1394defm ANDI : AndWordImm;
1395
1396//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00001397// Bitwise OR group:
Scott Michela59d4692008-02-23 18:41:37 +00001398//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1399
Scott Michel66377522007-12-04 22:35:58 +00001400// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michela59d4692008-02-23 18:41:37 +00001401class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1402 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1403 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001404
Scott Michela59d4692008-02-23 18:41:37 +00001405class ORVecInst<ValueType vectype>:
1406 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1407 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1408 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001409
Scott Michela59d4692008-02-23 18:41:37 +00001410class ORRegInst<RegisterClass rclass>:
1411 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1412 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00001413
Scott Michelf0569be2008-12-27 04:51:36 +00001414// ORCvtForm: OR conversion form
1415//
1416// This is used to "convert" the preferred slot to its vector equivalent, as
1417// well as convert a vector back to its preferred slot.
1418//
1419// These are effectively no-ops, but need to exist for proper type conversion
1420// and type coercion.
1421
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001422class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
Scott Michelf0569be2008-12-27 04:51:36 +00001423 : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1424 bits<7> RA;
1425 bits<7> RT;
1426
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001427 let Pattern = pattern;
Scott Michelf0569be2008-12-27 04:51:36 +00001428
1429 let Inst{0-10} = 0b10000010000;
1430 let Inst{11-17} = RA;
1431 let Inst{18-24} = RA;
1432 let Inst{25-31} = RT;
1433}
1434
Scott Michela59d4692008-02-23 18:41:37 +00001435class ORPromoteScalar<RegisterClass rclass>:
Scott Michelf0569be2008-12-27 04:51:36 +00001436 ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001437
Scott Michela59d4692008-02-23 18:41:37 +00001438class ORExtractElt<RegisterClass rclass>:
Scott Michelf0569be2008-12-27 04:51:36 +00001439 ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1440
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001441/* class ORCvtRegGPRC<RegisterClass rclass>:
1442 ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
Scott Michelf0569be2008-12-27 04:51:36 +00001443
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001444/* class ORCvtGPRCReg<RegisterClass rclass>:
1445 ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
Scott Micheldd950092009-01-06 03:36:14 +00001446
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001447class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1448 ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001449
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001450class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1451 ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001452
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001453class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1454 ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
Scott Micheldd950092009-01-06 03:36:14 +00001455
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001456class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1457 ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00001458
Scott Michel6e1d1472009-03-16 18:47:25 +00001459class ORCvtGPRCVec:
1460 ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1461
1462class ORCvtVecGPRC:
1463 ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001464
Scott Michela59d4692008-02-23 18:41:37 +00001465multiclass BitwiseOr
1466{
1467 def v16i8: ORVecInst<v16i8>;
1468 def v8i16: ORVecInst<v8i16>;
1469 def v4i32: ORVecInst<v4i32>;
1470 def v2i64: ORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001471
Scott Michela59d4692008-02-23 18:41:37 +00001472 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1473 [(set (v4f32 VECREG:$rT),
1474 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1475 (v4i32 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001476
Scott Michela59d4692008-02-23 18:41:37 +00001477 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michelf0569be2008-12-27 04:51:36 +00001478 [(set (v2f64 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00001479 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1480 (v2i64 VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001481
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001482 def r128: ORRegInst<GPRC>;
1483 def r64: ORRegInst<R64C>;
1484 def r32: ORRegInst<R32C>;
1485 def r16: ORRegInst<R16C>;
1486 def r8: ORRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00001487
Scott Michela59d4692008-02-23 18:41:37 +00001488 // OR instructions used to copy f32 and f64 registers.
1489 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1490 [/* no pattern */]>;
Scott Michel504c3692007-12-17 22:32:34 +00001491
Scott Michela59d4692008-02-23 18:41:37 +00001492 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1493 [/* no pattern */]>;
Scott Michel86c041f2007-12-20 00:44:13 +00001494
Scott Michel02d711b2008-12-30 23:28:25 +00001495 // scalar->vector promotion, prefslot2vec:
Scott Michela59d4692008-02-23 18:41:37 +00001496 def v16i8_i8: ORPromoteScalar<R8C>;
1497 def v8i16_i16: ORPromoteScalar<R16C>;
1498 def v4i32_i32: ORPromoteScalar<R32C>;
1499 def v2i64_i64: ORPromoteScalar<R64C>;
1500 def v4f32_f32: ORPromoteScalar<R32FP>;
1501 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel86c041f2007-12-20 00:44:13 +00001502
Scott Michel02d711b2008-12-30 23:28:25 +00001503 // vector->scalar demotion, vec2prefslot:
Scott Michela59d4692008-02-23 18:41:37 +00001504 def i8_v16i8: ORExtractElt<R8C>;
1505 def i16_v8i16: ORExtractElt<R16C>;
1506 def i32_v4i32: ORExtractElt<R32C>;
1507 def i64_v2i64: ORExtractElt<R64C>;
1508 def f32_v4f32: ORExtractElt<R32FP>;
1509 def f64_v2f64: ORExtractElt<R64FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00001510
Scott Michel6e1d1472009-03-16 18:47:25 +00001511 // Conversion from vector to GPRC
1512 def i128_vec: ORCvtVecGPRC;
1513
1514 // Conversion from GPRC to vector
1515 def vec_i128: ORCvtGPRCVec;
1516
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001517/*
Scott Michel6e1d1472009-03-16 18:47:25 +00001518 // Conversion from register to GPRC
Scott Michelf0569be2008-12-27 04:51:36 +00001519 def i128_r64: ORCvtRegGPRC<R64C>;
1520 def i128_f64: ORCvtRegGPRC<R64FP>;
1521 def i128_r32: ORCvtRegGPRC<R32C>;
1522 def i128_f32: ORCvtRegGPRC<R32FP>;
1523 def i128_r16: ORCvtRegGPRC<R16C>;
1524 def i128_r8: ORCvtRegGPRC<R8C>;
1525
Scott Michel6e1d1472009-03-16 18:47:25 +00001526 // Conversion from GPRC to register
Scott Michelf0569be2008-12-27 04:51:36 +00001527 def r64_i128: ORCvtGPRCReg<R64C>;
1528 def f64_i128: ORCvtGPRCReg<R64FP>;
1529 def r32_i128: ORCvtGPRCReg<R32C>;
1530 def f32_i128: ORCvtGPRCReg<R32FP>;
1531 def r16_i128: ORCvtGPRCReg<R16C>;
1532 def r8_i128: ORCvtGPRCReg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001533*/
1534/*
Scott Micheldd950092009-01-06 03:36:14 +00001535 // Conversion from register to R32C:
Scott Michel6e1d1472009-03-16 18:47:25 +00001536 def r32_r16: ORCvtFormRegR32<R16C>;
1537 def r32_r8: ORCvtFormRegR32<R8C>;
Scott Micheldd950092009-01-06 03:36:14 +00001538
1539 // Conversion from R32C to register
1540 def r32_r16: ORCvtFormR32Reg<R16C>;
1541 def r32_r8: ORCvtFormR32Reg<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001542*/
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001543
Scott Michel6e1d1472009-03-16 18:47:25 +00001544 // Conversion from R64C to register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001545 def r32_r64: ORCvtFormR64Reg<R32C>;
1546 // def r16_r64: ORCvtFormR64Reg<R16C>;
1547 // def r8_r64: ORCvtFormR64Reg<R8C>;
1548
Scott Michel6e1d1472009-03-16 18:47:25 +00001549 // Conversion to R64C from register:
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001550 def r64_r32: ORCvtFormRegR64<R32C>;
1551 // def r64_r16: ORCvtFormRegR64<R16C>;
1552 // def r64_r8: ORCvtFormRegR64<R8C>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001553
1554 // bitconvert patterns:
1555 def r32_f32: ORCvtFormR32Reg<R32FP,
1556 [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1557 def f32_r32: ORCvtFormRegR32<R32FP,
1558 [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1559
1560 def r64_f64: ORCvtFormR64Reg<R64FP,
1561 [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1562 def f64_r64: ORCvtFormRegR64<R64FP,
1563 [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
Scott Michela59d4692008-02-23 18:41:37 +00001564}
Scott Michel504c3692007-12-17 22:32:34 +00001565
Scott Michela59d4692008-02-23 18:41:37 +00001566defm OR : BitwiseOr;
1567
Scott Michelf0569be2008-12-27 04:51:36 +00001568// scalar->vector promotion patterns (preferred slot to vector):
1569def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1570 (ORv16i8_i8 R8C:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001571
Scott Michelf0569be2008-12-27 04:51:36 +00001572def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1573 (ORv8i16_i16 R16C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001574
Scott Michelf0569be2008-12-27 04:51:36 +00001575def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1576 (ORv4i32_i32 R32C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001577
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001578def : Pat<(v2i32 (SPUprefslot2vec R32C:$rA)),
1579 (ORv4i32_i32 R32C:$rA)>;
1580
Scott Michelf0569be2008-12-27 04:51:36 +00001581def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1582 (ORv2i64_i64 R64C:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001583
Scott Michelf0569be2008-12-27 04:51:36 +00001584def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1585 (ORv4f32_f32 R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001586
Scott Michelf0569be2008-12-27 04:51:36 +00001587def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1588 (ORv2f64_f64 R64FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001589
Scott Michelf0569be2008-12-27 04:51:36 +00001590// ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1591// known as converting the vector back to its preferred slot
Scott Michel504c3692007-12-17 22:32:34 +00001592
Scott Michel104de432008-11-24 17:11:17 +00001593def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001594 (ORi8_v16i8 VECREG:$rA)>;
Scott Michel504c3692007-12-17 22:32:34 +00001595
Scott Michel104de432008-11-24 17:11:17 +00001596def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001597 (ORi16_v8i16 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001598
Scott Michel104de432008-11-24 17:11:17 +00001599def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001600 (ORi32_v4i32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001601
Kalle Raiskila82fe4672010-08-02 08:54:39 +00001602def : Pat<(SPUvec2prefslot (v2i32 VECREG:$rA)),
1603 (ORi32_v4i32 VECREG:$rA)>;
1604
Scott Michel104de432008-11-24 17:11:17 +00001605def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001606 (ORi64_v2i64 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001607
Scott Michel104de432008-11-24 17:11:17 +00001608def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001609 (ORf32_v4f32 VECREG:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00001610
Scott Michel104de432008-11-24 17:11:17 +00001611def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
Scott Michelf0569be2008-12-27 04:51:36 +00001612 (ORf64_v2f64 VECREG:$rA)>;
1613
1614// Load Register: This is an assembler alias for a bitwise OR of a register
1615// against itself. It's here because it brings some clarity to assembly
1616// language output.
1617
1618let hasCtrlDep = 1 in {
1619 class LRInst<dag OOL, dag IOL>
1620 : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1621 bits<7> RA;
1622 bits<7> RT;
1623
1624 let Pattern = [/*no pattern*/];
1625
1626 let Inst{0-10} = 0b10000010000; /* It's an OR operation */
1627 let Inst{11-17} = RA;
1628 let Inst{18-24} = RA;
1629 let Inst{25-31} = RT;
1630 }
1631
1632 class LRVecInst<ValueType vectype>:
1633 LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1634
1635 class LRRegInst<RegisterClass rclass>:
1636 LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1637
1638 multiclass LoadRegister {
1639 def v2i64: LRVecInst<v2i64>;
1640 def v2f64: LRVecInst<v2f64>;
1641 def v4i32: LRVecInst<v4i32>;
1642 def v4f32: LRVecInst<v4f32>;
1643 def v8i16: LRVecInst<v8i16>;
1644 def v16i8: LRVecInst<v16i8>;
1645
1646 def r128: LRRegInst<GPRC>;
1647 def r64: LRRegInst<R64C>;
1648 def f64: LRRegInst<R64FP>;
1649 def r32: LRRegInst<R32C>;
1650 def f32: LRRegInst<R32FP>;
1651 def r16: LRRegInst<R16C>;
1652 def r8: LRRegInst<R8C>;
1653 }
1654
1655 defm LR: LoadRegister;
1656}
Scott Michel66377522007-12-04 22:35:58 +00001657
Scott Michela59d4692008-02-23 18:41:37 +00001658// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel66377522007-12-04 22:35:58 +00001659
Scott Michela59d4692008-02-23 18:41:37 +00001660class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1661 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1662 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001663
Scott Michela59d4692008-02-23 18:41:37 +00001664class ORCVecInst<ValueType vectype>:
1665 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1666 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1667 (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001668
Scott Michela59d4692008-02-23 18:41:37 +00001669class ORCRegInst<RegisterClass rclass>:
1670 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1671 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001672
Scott Michela59d4692008-02-23 18:41:37 +00001673multiclass BitwiseOrComplement
1674{
1675 def v16i8: ORCVecInst<v16i8>;
1676 def v8i16: ORCVecInst<v8i16>;
1677 def v4i32: ORCVecInst<v4i32>;
1678 def v2i64: ORCVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001679
Scott Michel6e1d1472009-03-16 18:47:25 +00001680 def r128: ORCRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00001681 def r64: ORCRegInst<R64C>;
1682 def r32: ORCRegInst<R32C>;
1683 def r16: ORCRegInst<R16C>;
1684 def r8: ORCRegInst<R8C>;
1685}
1686
1687defm ORC : BitwiseOrComplement;
Scott Michel504c3692007-12-17 22:32:34 +00001688
Scott Michel66377522007-12-04 22:35:58 +00001689// OR byte immediate
Scott Michela59d4692008-02-23 18:41:37 +00001690class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1691 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1692 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001693
Scott Michela59d4692008-02-23 18:41:37 +00001694class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1695 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1696 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1697 (vectype immpred:$val)))]>;
1698
1699multiclass BitwiseOrByteImm
1700{
1701 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1702
1703 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1704 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1705}
1706
1707defm ORBI : BitwiseOrByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001708
Scott Michel66377522007-12-04 22:35:58 +00001709// OR halfword immediate
Scott Michela59d4692008-02-23 18:41:37 +00001710class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1711 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1712 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001713
Scott Michela59d4692008-02-23 18:41:37 +00001714class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1715 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1716 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1717 immpred:$val))]>;
Scott Michel504c3692007-12-17 22:32:34 +00001718
Scott Michela59d4692008-02-23 18:41:37 +00001719multiclass BitwiseOrHalfwordImm
1720{
1721 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1722
1723 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1724 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1725
1726 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1727 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1728 [(set R16C:$rT, (or (anyext R8C:$rA),
1729 i16ImmSExt10:$val))]>;
1730}
1731
1732defm ORHI : BitwiseOrHalfwordImm;
1733
1734class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1735 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1736 IntegerOp, pattern>;
1737
1738class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1739 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1740 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1741 immpred:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001742
1743// Bitwise "or" with immediate
Scott Michela59d4692008-02-23 18:41:37 +00001744multiclass BitwiseOrImm
1745{
1746 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel66377522007-12-04 22:35:58 +00001747
Scott Michela59d4692008-02-23 18:41:37 +00001748 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1749 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001750
Scott Michela59d4692008-02-23 18:41:37 +00001751 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1752 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1753 // infra "anyext 16->32" pattern.)
1754 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1755 [(set R32C:$rT, (or (anyext R16C:$rA),
1756 i32ImmSExt10:$val))]>;
Scott Michel66377522007-12-04 22:35:58 +00001757
Scott Michela59d4692008-02-23 18:41:37 +00001758 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1759 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1760 // infra "anyext 16->32" pattern.)
1761 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1762 [(set R32C:$rT, (or (anyext R8C:$rA),
1763 i32ImmSExt10:$val))]>;
1764}
Scott Michel66377522007-12-04 22:35:58 +00001765
Scott Michela59d4692008-02-23 18:41:37 +00001766defm ORI : BitwiseOrImm;
Scott Michel504c3692007-12-17 22:32:34 +00001767
Scott Michel66377522007-12-04 22:35:58 +00001768// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1769// $rT[0], slots 1-3 are zeroed.
1770//
Scott Michel504c3692007-12-17 22:32:34 +00001771// FIXME: Needs to match an intrinsic pattern.
Scott Michel66377522007-12-04 22:35:58 +00001772def ORXv4i32:
1773 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1774 "orx\t$rT, $rA, $rB", IntegerOp,
1775 []>;
1776
Scott Michel504c3692007-12-17 22:32:34 +00001777// XOR:
Scott Michel66377522007-12-04 22:35:58 +00001778
Scott Michelad2715e2008-03-05 23:02:02 +00001779class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1780 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1781 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001782
Scott Michelad2715e2008-03-05 23:02:02 +00001783class XORVecInst<ValueType vectype>:
1784 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1785 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1786 (vectype VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001787
Scott Michelad2715e2008-03-05 23:02:02 +00001788class XORRegInst<RegisterClass rclass>:
1789 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1790 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1791
1792multiclass BitwiseExclusiveOr
1793{
1794 def v16i8: XORVecInst<v16i8>;
1795 def v8i16: XORVecInst<v8i16>;
1796 def v4i32: XORVecInst<v4i32>;
1797 def v2i64: XORVecInst<v2i64>;
1798
1799 def r128: XORRegInst<GPRC>;
1800 def r64: XORRegInst<R64C>;
1801 def r32: XORRegInst<R32C>;
1802 def r16: XORRegInst<R16C>;
1803 def r8: XORRegInst<R8C>;
Scott Michela82d3f72009-03-17 16:45:16 +00001804
1805 // XOR instructions used to negate f32 and f64 quantities.
1806
1807 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1808 [/* no pattern */]>;
1809
1810 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1811 [/* no pattern */]>;
1812
1813 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1814 [/* no pattern, see fneg{32,64} */]>;
Scott Michelad2715e2008-03-05 23:02:02 +00001815}
1816
1817defm XOR : BitwiseExclusiveOr;
Scott Michel66377522007-12-04 22:35:58 +00001818
1819//==----------------------------------------------------------
Scott Michel504c3692007-12-17 22:32:34 +00001820
Scott Michela59d4692008-02-23 18:41:37 +00001821class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1822 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1823 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001824
Scott Michela59d4692008-02-23 18:41:37 +00001825multiclass XorByteImm
1826{
1827 def v16i8:
1828 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1829 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1830
1831 def r8:
1832 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1833 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1834}
1835
1836defm XORBI : XorByteImm;
Scott Michel504c3692007-12-17 22:32:34 +00001837
Scott Michel66377522007-12-04 22:35:58 +00001838def XORHIv8i16:
Scott Michela59d4692008-02-23 18:41:37 +00001839 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel66377522007-12-04 22:35:58 +00001840 "xorhi\t$rT, $rA, $val", IntegerOp,
1841 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1842 v8i16SExt10Imm:$val))]>;
1843
1844def XORHIr16:
1845 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1846 "xorhi\t$rT, $rA, $val", IntegerOp,
1847 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1848
1849def XORIv4i32:
Scott Michel78c47fa2008-03-10 16:58:52 +00001850 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel66377522007-12-04 22:35:58 +00001851 "xori\t$rT, $rA, $val", IntegerOp,
1852 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1853 v4i32SExt10Imm:$val))]>;
1854
1855def XORIr32:
1856 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1857 "xori\t$rT, $rA, $val", IntegerOp,
1858 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1859
1860// NAND:
Scott Michel66377522007-12-04 22:35:58 +00001861
Scott Michel6e1d1472009-03-16 18:47:25 +00001862class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1863 RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1864 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001865
Scott Michel6e1d1472009-03-16 18:47:25 +00001866class NANDVecInst<ValueType vectype>:
1867 NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1868 [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1869 (vectype VECREG:$rB))))]>;
1870class NANDRegInst<RegisterClass rclass>:
1871 NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1872 [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001873
Scott Michel6e1d1472009-03-16 18:47:25 +00001874multiclass BitwiseNand
1875{
1876 def v16i8: NANDVecInst<v16i8>;
1877 def v8i16: NANDVecInst<v8i16>;
1878 def v4i32: NANDVecInst<v4i32>;
1879 def v2i64: NANDVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001880
Scott Michel6e1d1472009-03-16 18:47:25 +00001881 def r128: NANDRegInst<GPRC>;
1882 def r64: NANDRegInst<R64C>;
1883 def r32: NANDRegInst<R32C>;
1884 def r16: NANDRegInst<R16C>;
1885 def r8: NANDRegInst<R8C>;
1886}
Scott Michel66377522007-12-04 22:35:58 +00001887
Scott Michel6e1d1472009-03-16 18:47:25 +00001888defm NAND : BitwiseNand;
Scott Michel504c3692007-12-17 22:32:34 +00001889
Scott Michel66377522007-12-04 22:35:58 +00001890// NOR:
Scott Michel66377522007-12-04 22:35:58 +00001891
Scott Michel6e1d1472009-03-16 18:47:25 +00001892class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1893 RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1894 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001895
Scott Michel6e1d1472009-03-16 18:47:25 +00001896class NORVecInst<ValueType vectype>:
1897 NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1898 [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1899 (vectype VECREG:$rB))))]>;
1900class NORRegInst<RegisterClass rclass>:
1901 NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1902 [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00001903
Scott Michel6e1d1472009-03-16 18:47:25 +00001904multiclass BitwiseNor
1905{
1906 def v16i8: NORVecInst<v16i8>;
1907 def v8i16: NORVecInst<v8i16>;
1908 def v4i32: NORVecInst<v4i32>;
1909 def v2i64: NORVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00001910
Scott Michel6e1d1472009-03-16 18:47:25 +00001911 def r128: NORRegInst<GPRC>;
1912 def r64: NORRegInst<R64C>;
1913 def r32: NORRegInst<R32C>;
1914 def r16: NORRegInst<R16C>;
1915 def r8: NORRegInst<R8C>;
1916}
Scott Michel66377522007-12-04 22:35:58 +00001917
Scott Michel6e1d1472009-03-16 18:47:25 +00001918defm NOR : BitwiseNor;
Scott Michel504c3692007-12-17 22:32:34 +00001919
Scott Michel66377522007-12-04 22:35:58 +00001920// Select bits:
Scott Michelad2715e2008-03-05 23:02:02 +00001921class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1922 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1923 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00001924
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001925class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
Scott Michelad2715e2008-03-05 23:02:02 +00001926 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1927 [(set (vectype VECREG:$rT),
1928 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
Scott Michelc9c8b2a2009-01-26 03:31:40 +00001929 (and (vnot_frag (vectype VECREG:$rC)),
Scott Michelad2715e2008-03-05 23:02:02 +00001930 (vectype VECREG:$rA))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001931
Scott Michel02d711b2008-12-30 23:28:25 +00001932class SELBVecVCondInst<ValueType vectype>:
1933 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1934 [(set (vectype VECREG:$rT),
1935 (select (vectype VECREG:$rC),
1936 (vectype VECREG:$rB),
1937 (vectype VECREG:$rA)))]>;
1938
Scott Michelf0569be2008-12-27 04:51:36 +00001939class SELBVecCondInst<ValueType vectype>:
1940 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1941 [(set (vectype VECREG:$rT),
1942 (select R32C:$rC,
1943 (vectype VECREG:$rB),
1944 (vectype VECREG:$rA)))]>;
1945
Scott Michelad2715e2008-03-05 23:02:02 +00001946class SELBRegInst<RegisterClass rclass>:
1947 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1948 [(set rclass:$rT,
Scott Michel1df30c42008-12-29 03:23:36 +00001949 (or (and rclass:$rB, rclass:$rC),
1950 (and rclass:$rA, (not rclass:$rC))))]>;
Scott Michel66377522007-12-04 22:35:58 +00001951
Scott Michelf0569be2008-12-27 04:51:36 +00001952class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1953 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1954 [(set rclass:$rT,
1955 (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1956
Scott Michelad2715e2008-03-05 23:02:02 +00001957multiclass SelectBits
1958{
1959 def v16i8: SELBVecInst<v16i8>;
1960 def v8i16: SELBVecInst<v8i16>;
1961 def v4i32: SELBVecInst<v4i32>;
Chris Lattner918472a2010-03-28 07:48:17 +00001962 def v2i64: SELBVecInst<v2i64, vnot_cell_conv>;
Scott Michel66377522007-12-04 22:35:58 +00001963
Scott Michelad2715e2008-03-05 23:02:02 +00001964 def r128: SELBRegInst<GPRC>;
1965 def r64: SELBRegInst<R64C>;
1966 def r32: SELBRegInst<R32C>;
1967 def r16: SELBRegInst<R16C>;
1968 def r8: SELBRegInst<R8C>;
Scott Michelf0569be2008-12-27 04:51:36 +00001969
1970 def v16i8_cond: SELBVecCondInst<v16i8>;
1971 def v8i16_cond: SELBVecCondInst<v8i16>;
1972 def v4i32_cond: SELBVecCondInst<v4i32>;
1973 def v2i64_cond: SELBVecCondInst<v2i64>;
1974
Scott Michel02d711b2008-12-30 23:28:25 +00001975 def v16i8_vcond: SELBVecCondInst<v16i8>;
1976 def v8i16_vcond: SELBVecCondInst<v8i16>;
1977 def v4i32_vcond: SELBVecCondInst<v4i32>;
1978 def v2i64_vcond: SELBVecCondInst<v2i64>;
1979
1980 def v4f32_cond:
Scott Michel19c10e62009-01-26 03:37:41 +00001981 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1982 [(set (v4f32 VECREG:$rT),
1983 (select (v4i32 VECREG:$rC),
1984 (v4f32 VECREG:$rB),
1985 (v4f32 VECREG:$rA)))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00001986
Scott Micheld1e8d9c2009-01-21 04:58:48 +00001987 // SELBr64_cond is defined in SPU64InstrInfo.td
Scott Michelf0569be2008-12-27 04:51:36 +00001988 def r32_cond: SELBRegCondInst<R32C, R32C>;
Scott Michel02d711b2008-12-30 23:28:25 +00001989 def f32_cond: SELBRegCondInst<R32C, R32FP>;
Scott Michelf0569be2008-12-27 04:51:36 +00001990 def r16_cond: SELBRegCondInst<R16C, R16C>;
1991 def r8_cond: SELBRegCondInst<R8C, R8C>;
Scott Michelad2715e2008-03-05 23:02:02 +00001992}
Scott Michel66377522007-12-04 22:35:58 +00001993
Scott Michelad2715e2008-03-05 23:02:02 +00001994defm SELB : SelectBits;
Scott Michel66377522007-12-04 22:35:58 +00001995
Scott Michel7a1c9e92008-11-22 23:50:42 +00001996class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
Scott Michelad2715e2008-03-05 23:02:02 +00001997 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1998 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel66377522007-12-04 22:35:58 +00001999
Scott Michel7a1c9e92008-11-22 23:50:42 +00002000def : SPUselbPatVec<v16i8, SELBv16i8>;
2001def : SPUselbPatVec<v8i16, SELBv8i16>;
2002def : SPUselbPatVec<v4i32, SELBv4i32>;
2003def : SPUselbPatVec<v2i64, SELBv2i64>;
2004
2005class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
2006 Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
2007 (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
2008
2009def : SPUselbPatReg<R8C, SELBr8>;
2010def : SPUselbPatReg<R16C, SELBr16>;
2011def : SPUselbPatReg<R32C, SELBr32>;
2012def : SPUselbPatReg<R64C, SELBr64>;
Scott Michel66377522007-12-04 22:35:58 +00002013
Scott Michelad2715e2008-03-05 23:02:02 +00002014// EQV: Equivalence (1 for each same bit, otherwise 0)
2015//
2016// Note: There are a lot of ways to match this bit operator and these patterns
2017// attempt to be as exhaustive as possible.
Scott Michel66377522007-12-04 22:35:58 +00002018
Scott Michelad2715e2008-03-05 23:02:02 +00002019class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2020 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2021 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002022
Scott Michelad2715e2008-03-05 23:02:02 +00002023class EQVVecInst<ValueType vectype>:
2024 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2025 [(set (vectype VECREG:$rT),
2026 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2027 (and (vnot (vectype VECREG:$rA)),
2028 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002029
Scott Michelad2715e2008-03-05 23:02:02 +00002030class EQVRegInst<RegisterClass rclass>:
2031 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2032 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2033 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002034
Scott Michelad2715e2008-03-05 23:02:02 +00002035class EQVVecPattern1<ValueType vectype>:
2036 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2037 [(set (vectype VECREG:$rT),
2038 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002039
Scott Michelad2715e2008-03-05 23:02:02 +00002040class EQVRegPattern1<RegisterClass rclass>:
2041 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2042 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002043
Scott Michelad2715e2008-03-05 23:02:02 +00002044class EQVVecPattern2<ValueType vectype>:
2045 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2046 [(set (vectype VECREG:$rT),
2047 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2048 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002049
Scott Michelad2715e2008-03-05 23:02:02 +00002050class EQVRegPattern2<RegisterClass rclass>:
2051 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2052 [(set rclass:$rT,
2053 (or (and rclass:$rA, rclass:$rB),
2054 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002055
Scott Michelad2715e2008-03-05 23:02:02 +00002056class EQVVecPattern3<ValueType vectype>:
2057 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2058 [(set (vectype VECREG:$rT),
2059 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel66377522007-12-04 22:35:58 +00002060
Scott Michelad2715e2008-03-05 23:02:02 +00002061class EQVRegPattern3<RegisterClass rclass>:
2062 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2063 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002064
Scott Michelad2715e2008-03-05 23:02:02 +00002065multiclass BitEquivalence
2066{
2067 def v16i8: EQVVecInst<v16i8>;
2068 def v8i16: EQVVecInst<v8i16>;
2069 def v4i32: EQVVecInst<v4i32>;
2070 def v2i64: EQVVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002071
Scott Michelad2715e2008-03-05 23:02:02 +00002072 def v16i8_1: EQVVecPattern1<v16i8>;
2073 def v8i16_1: EQVVecPattern1<v8i16>;
2074 def v4i32_1: EQVVecPattern1<v4i32>;
2075 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002076
Scott Michelad2715e2008-03-05 23:02:02 +00002077 def v16i8_2: EQVVecPattern2<v16i8>;
2078 def v8i16_2: EQVVecPattern2<v8i16>;
2079 def v4i32_2: EQVVecPattern2<v4i32>;
2080 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002081
Scott Michelad2715e2008-03-05 23:02:02 +00002082 def v16i8_3: EQVVecPattern3<v16i8>;
2083 def v8i16_3: EQVVecPattern3<v8i16>;
2084 def v4i32_3: EQVVecPattern3<v4i32>;
2085 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002086
Scott Michelad2715e2008-03-05 23:02:02 +00002087 def r128: EQVRegInst<GPRC>;
2088 def r64: EQVRegInst<R64C>;
2089 def r32: EQVRegInst<R32C>;
2090 def r16: EQVRegInst<R16C>;
2091 def r8: EQVRegInst<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002092
Scott Michelad2715e2008-03-05 23:02:02 +00002093 def r128_1: EQVRegPattern1<GPRC>;
2094 def r64_1: EQVRegPattern1<R64C>;
2095 def r32_1: EQVRegPattern1<R32C>;
2096 def r16_1: EQVRegPattern1<R16C>;
2097 def r8_1: EQVRegPattern1<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002098
Scott Michelad2715e2008-03-05 23:02:02 +00002099 def r128_2: EQVRegPattern2<GPRC>;
2100 def r64_2: EQVRegPattern2<R64C>;
2101 def r32_2: EQVRegPattern2<R32C>;
2102 def r16_2: EQVRegPattern2<R16C>;
2103 def r8_2: EQVRegPattern2<R8C>;
Scott Michel66377522007-12-04 22:35:58 +00002104
Scott Michelad2715e2008-03-05 23:02:02 +00002105 def r128_3: EQVRegPattern3<GPRC>;
2106 def r64_3: EQVRegPattern3<R64C>;
2107 def r32_3: EQVRegPattern3<R32C>;
2108 def r16_3: EQVRegPattern3<R16C>;
2109 def r8_3: EQVRegPattern3<R8C>;
2110}
Scott Michel504c3692007-12-17 22:32:34 +00002111
Scott Michelad2715e2008-03-05 23:02:02 +00002112defm EQV: BitEquivalence;
Scott Michel66377522007-12-04 22:35:58 +00002113
2114//===----------------------------------------------------------------------===//
2115// Vector shuffle...
2116//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002117// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2118// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2119// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2120// the SPUISD::SHUFB opcode.
Scott Michela59d4692008-02-23 18:41:37 +00002121//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002122
Scott Michela59d4692008-02-23 18:41:37 +00002123class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2124 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2125 IntegerOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002126
Scott Michel1a6cdb62008-12-01 17:56:02 +00002127class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
Scott Michela59d4692008-02-23 18:41:37 +00002128 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
Scott Michel1a6cdb62008-12-01 17:56:02 +00002129 [(set (resultvec VECREG:$rT),
2130 (SPUshuffle (resultvec VECREG:$rA),
2131 (resultvec VECREG:$rB),
2132 (maskvec VECREG:$rC)))]>;
Scott Michel86c041f2007-12-20 00:44:13 +00002133
Scott Michelf0569be2008-12-27 04:51:36 +00002134class SHUFBGPRCInst:
2135 SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2136 [/* no pattern */]>;
2137
Scott Michela59d4692008-02-23 18:41:37 +00002138multiclass ShuffleBytes
2139{
Scott Michel1a6cdb62008-12-01 17:56:02 +00002140 def v16i8 : SHUFBVecInst<v16i8, v16i8>;
2141 def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2142 def v8i16 : SHUFBVecInst<v8i16, v16i8>;
2143 def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2144 def v4i32 : SHUFBVecInst<v4i32, v16i8>;
2145 def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
Kalle Raiskila82fe4672010-08-02 08:54:39 +00002146 def v2i32 : SHUFBVecInst<v2i32, v16i8>;
2147 def v2i32_m32 : SHUFBVecInst<v2i32, v4i32>;
Scott Michel1a6cdb62008-12-01 17:56:02 +00002148 def v2i64 : SHUFBVecInst<v2i64, v16i8>;
2149 def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
Scott Michel66377522007-12-04 22:35:58 +00002150
Scott Michel1a6cdb62008-12-01 17:56:02 +00002151 def v4f32 : SHUFBVecInst<v4f32, v16i8>;
2152 def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2153
2154 def v2f64 : SHUFBVecInst<v2f64, v16i8>;
2155 def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
Scott Michelf0569be2008-12-27 04:51:36 +00002156
2157 def gprc : SHUFBGPRCInst;
Scott Michela59d4692008-02-23 18:41:37 +00002158}
2159
2160defm SHUFB : ShuffleBytes;
2161
Scott Michel66377522007-12-04 22:35:58 +00002162//===----------------------------------------------------------------------===//
2163// Shift and rotate group:
2164//===----------------------------------------------------------------------===//
2165
Scott Michela59d4692008-02-23 18:41:37 +00002166class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2167 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2168 RotateShift, pattern>;
2169
2170class SHLHVecInst<ValueType vectype>:
2171 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2172 [(set (vectype VECREG:$rT),
2173 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002174
Scott Michela59d4692008-02-23 18:41:37 +00002175multiclass ShiftLeftHalfword
2176{
2177 def v8i16: SHLHVecInst<v8i16>;
2178 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2179 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2180 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2181 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2182}
Scott Michel66377522007-12-04 22:35:58 +00002183
Scott Michela59d4692008-02-23 18:41:37 +00002184defm SHLH : ShiftLeftHalfword;
Scott Michel66377522007-12-04 22:35:58 +00002185
Scott Michela59d4692008-02-23 18:41:37 +00002186//===----------------------------------------------------------------------===//
Scott Michel504c3692007-12-17 22:32:34 +00002187
Scott Michela59d4692008-02-23 18:41:37 +00002188class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2189 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2190 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002191
Scott Michela59d4692008-02-23 18:41:37 +00002192class SHLHIVecInst<ValueType vectype>:
2193 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2194 [(set (vectype VECREG:$rT),
2195 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002196
Scott Michela59d4692008-02-23 18:41:37 +00002197multiclass ShiftLeftHalfwordImm
2198{
2199 def v8i16: SHLHIVecInst<v8i16>;
2200 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2201 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2202}
2203
2204defm SHLHI : ShiftLeftHalfwordImm;
2205
2206def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002207 (SHLHIv8i16 VECREG:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michela59d4692008-02-23 18:41:37 +00002208
2209def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002210 (SHLHIr16 R16C:$rA, (TO_IMM16 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002211
Scott Michela59d4692008-02-23 18:41:37 +00002212//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002213
Scott Michela59d4692008-02-23 18:41:37 +00002214class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2215 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2216 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002217
Scott Michela59d4692008-02-23 18:41:37 +00002218multiclass ShiftLeftWord
2219{
2220 def v4i32:
2221 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2222 [(set (v4i32 VECREG:$rT),
2223 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2224 def r32:
2225 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2226 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2227}
Scott Michel66377522007-12-04 22:35:58 +00002228
Scott Michela59d4692008-02-23 18:41:37 +00002229defm SHL: ShiftLeftWord;
Scott Michel504c3692007-12-17 22:32:34 +00002230
Scott Michela59d4692008-02-23 18:41:37 +00002231//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002232
Scott Michela59d4692008-02-23 18:41:37 +00002233class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2234 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2235 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002236
Scott Michela59d4692008-02-23 18:41:37 +00002237multiclass ShiftLeftWordImm
2238{
2239 def v4i32:
2240 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2241 [(set (v4i32 VECREG:$rT),
2242 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002243
Scott Michela59d4692008-02-23 18:41:37 +00002244 def r32:
2245 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2246 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2247}
Scott Michel66377522007-12-04 22:35:58 +00002248
Scott Michela59d4692008-02-23 18:41:37 +00002249defm SHLI : ShiftLeftWordImm;
Scott Michel504c3692007-12-17 22:32:34 +00002250
Scott Michela59d4692008-02-23 18:41:37 +00002251//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00002252// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2253// register) to the left. Vector form is here to ensure type correctness.
Scott Michela59d4692008-02-23 18:41:37 +00002254//
2255// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2256// of 7 bits is actually possible.
2257//
2258// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2259// to shift i64 and i128. SHLQBI is the residual left over after shifting by
2260// bytes with SHLQBY.
Scott Michel66377522007-12-04 22:35:58 +00002261
Scott Michela59d4692008-02-23 18:41:37 +00002262class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2263 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2264 RotateShift, pattern>;
2265
2266class SHLQBIVecInst<ValueType vectype>:
2267 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2268 [(set (vectype VECREG:$rT),
2269 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2270
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002271class SHLQBIRegInst<RegisterClass rclass>:
2272 SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2273 [/* no pattern */]>;
2274
Scott Michela59d4692008-02-23 18:41:37 +00002275multiclass ShiftLeftQuadByBits
2276{
2277 def v16i8: SHLQBIVecInst<v16i8>;
2278 def v8i16: SHLQBIVecInst<v8i16>;
2279 def v4i32: SHLQBIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002280 def v4f32: SHLQBIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002281 def v2i64: SHLQBIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002282 def v2f64: SHLQBIVecInst<v2f64>;
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002283
2284 def r128: SHLQBIRegInst<GPRC>;
Scott Michela59d4692008-02-23 18:41:37 +00002285}
2286
2287defm SHLQBI : ShiftLeftQuadByBits;
2288
2289// See note above on SHLQBI. In this case, the predicate actually does then
2290// enforcement, whereas with SHLQBI, we have to "take it on faith."
2291class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2292 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2293 RotateShift, pattern>;
2294
2295class SHLQBIIVecInst<ValueType vectype>:
2296 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2297 [(set (vectype VECREG:$rT),
2298 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2299
2300multiclass ShiftLeftQuadByBitsImm
2301{
2302 def v16i8 : SHLQBIIVecInst<v16i8>;
2303 def v8i16 : SHLQBIIVecInst<v8i16>;
2304 def v4i32 : SHLQBIIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002305 def v4f32 : SHLQBIIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002306 def v2i64 : SHLQBIIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002307 def v2f64 : SHLQBIIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002308}
2309
2310defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel66377522007-12-04 22:35:58 +00002311
2312// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michela59d4692008-02-23 18:41:37 +00002313// not by bits. See notes above on SHLQBI.
Scott Michel66377522007-12-04 22:35:58 +00002314
Scott Michela59d4692008-02-23 18:41:37 +00002315class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
Scott Michel662165d2008-11-25 00:23:16 +00002316 RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00002317 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002318
Scott Michela59d4692008-02-23 18:41:37 +00002319class SHLQBYVecInst<ValueType vectype>:
2320 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2321 [(set (vectype VECREG:$rT),
2322 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002323
Scott Michela59d4692008-02-23 18:41:37 +00002324multiclass ShiftLeftQuadBytes
2325{
2326 def v16i8: SHLQBYVecInst<v16i8>;
2327 def v8i16: SHLQBYVecInst<v8i16>;
2328 def v4i32: SHLQBYVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002329 def v4f32: SHLQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002330 def v2i64: SHLQBYVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002331 def v2f64: SHLQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002332 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2333 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2334}
Scott Michel66377522007-12-04 22:35:58 +00002335
Scott Michela59d4692008-02-23 18:41:37 +00002336defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel66377522007-12-04 22:35:58 +00002337
Scott Michela59d4692008-02-23 18:41:37 +00002338class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2339 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2340 RotateShift, pattern>;
Scott Michel504c3692007-12-17 22:32:34 +00002341
Scott Michela59d4692008-02-23 18:41:37 +00002342class SHLQBYIVecInst<ValueType vectype>:
2343 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2344 [(set (vectype VECREG:$rT),
2345 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002346
Scott Michela59d4692008-02-23 18:41:37 +00002347multiclass ShiftLeftQuadBytesImm
2348{
2349 def v16i8: SHLQBYIVecInst<v16i8>;
2350 def v8i16: SHLQBYIVecInst<v8i16>;
2351 def v4i32: SHLQBYIVecInst<v4i32>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002352 def v4f32: SHLQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002353 def v2i64: SHLQBYIVecInst<v2i64>;
Scott Michel7a1c9e92008-11-22 23:50:42 +00002354 def v2f64: SHLQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002355 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2356 [(set GPRC:$rT,
2357 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2358}
Scott Michel504c3692007-12-17 22:32:34 +00002359
Scott Michela59d4692008-02-23 18:41:37 +00002360defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel504c3692007-12-17 22:32:34 +00002361
Scott Micheld1e8d9c2009-01-21 04:58:48 +00002362class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2363 RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2364 RotateShift, pattern>;
2365
2366class SHLQBYBIVecInst<ValueType vectype>:
2367 SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2368 [/* no pattern */]>;
2369
2370class SHLQBYBIRegInst<RegisterClass rclass>:
2371 SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2372 [/* no pattern */]>;
2373
2374multiclass ShiftLeftQuadBytesBitCount
2375{
2376 def v16i8: SHLQBYBIVecInst<v16i8>;
2377 def v8i16: SHLQBYBIVecInst<v8i16>;
2378 def v4i32: SHLQBYBIVecInst<v4i32>;
2379 def v4f32: SHLQBYBIVecInst<v4f32>;
2380 def v2i64: SHLQBYBIVecInst<v2i64>;
2381 def v2f64: SHLQBYBIVecInst<v2f64>;
2382
2383 def r128: SHLQBYBIRegInst<GPRC>;
2384}
2385
2386defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2387
Scott Michela59d4692008-02-23 18:41:37 +00002388//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2389// Rotate halfword:
2390//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2391class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2392 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2393 RotateShift, pattern>;
2394
2395class ROTHVecInst<ValueType vectype>:
2396 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2397 [(set (vectype VECREG:$rT),
Chris Lattnerdd6fbd12010-03-08 18:59:49 +00002398 (SPUvec_rotl VECREG:$rA, (v8i16 VECREG:$rB)))]>;
Scott Michela59d4692008-02-23 18:41:37 +00002399
2400class ROTHRegInst<RegisterClass rclass>:
2401 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2402 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2403
2404multiclass RotateLeftHalfword
2405{
2406 def v8i16: ROTHVecInst<v8i16>;
2407 def r16: ROTHRegInst<R16C>;
2408}
2409
2410defm ROTH: RotateLeftHalfword;
2411
2412def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2413 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2414
2415//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2416// Rotate halfword, immediate:
2417//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2418class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2419 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2420 RotateShift, pattern>;
2421
2422class ROTHIVecInst<ValueType vectype>:
2423 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2424 [(set (vectype VECREG:$rT),
2425 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2426
2427multiclass RotateLeftHalfwordImm
2428{
2429 def v8i16: ROTHIVecInst<v8i16>;
2430 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2431 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2432 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2433 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2434}
2435
2436defm ROTHI: RotateLeftHalfwordImm;
2437
Chris Lattner420c69d2010-03-15 05:53:47 +00002438def : Pat<(SPUvec_rotl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2439 (ROTHIv8i16 VECREG:$rA, (TO_IMM16 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002440
Scott Michela59d4692008-02-23 18:41:37 +00002441//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2442// Rotate word:
2443//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002444
Scott Michela59d4692008-02-23 18:41:37 +00002445class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2446 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2447 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002448
Scott Michela59d4692008-02-23 18:41:37 +00002449class ROTVecInst<ValueType vectype>:
2450 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2451 [(set (vectype VECREG:$rT),
2452 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002453
Scott Michela59d4692008-02-23 18:41:37 +00002454class ROTRegInst<RegisterClass rclass>:
2455 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2456 [(set rclass:$rT,
2457 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel66377522007-12-04 22:35:58 +00002458
Scott Michela59d4692008-02-23 18:41:37 +00002459multiclass RotateLeftWord
2460{
2461 def v4i32: ROTVecInst<v4i32>;
2462 def r32: ROTRegInst<R32C>;
2463}
2464
2465defm ROT: RotateLeftWord;
Scott Michel66377522007-12-04 22:35:58 +00002466
Scott Michel504c3692007-12-17 22:32:34 +00002467// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2468// 32-bit register
2469def ROTr32_r16_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002470 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2471 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002472
2473def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2474 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2475
2476def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2477 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2478
2479def ROTr32_r8_anyext:
Scott Michela59d4692008-02-23 18:41:37 +00002480 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2481 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002482
2483def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2484 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2485
2486def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2487 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2488
Scott Michela59d4692008-02-23 18:41:37 +00002489//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2490// Rotate word, immediate
2491//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002492
Scott Michela59d4692008-02-23 18:41:37 +00002493class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2494 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2495 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002496
Scott Michela59d4692008-02-23 18:41:37 +00002497class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2498 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2499 [(set (vectype VECREG:$rT),
2500 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00002501
Scott Michela59d4692008-02-23 18:41:37 +00002502class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2503 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2504 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002505
Scott Michela59d4692008-02-23 18:41:37 +00002506multiclass RotateLeftWordImm
2507{
2508 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2509 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2510 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel66377522007-12-04 22:35:58 +00002511
Scott Michela59d4692008-02-23 18:41:37 +00002512 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2513 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2514 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2515}
Scott Michel504c3692007-12-17 22:32:34 +00002516
Scott Michela59d4692008-02-23 18:41:37 +00002517defm ROTI : RotateLeftWordImm;
2518
2519//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2520// Rotate quad by byte (count)
2521//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2522
2523class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2524 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2525 RotateShift, pattern>;
2526
2527class ROTQBYVecInst<ValueType vectype>:
2528 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2529 [(set (vectype VECREG:$rT),
2530 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2531
2532multiclass RotateQuadLeftByBytes
2533{
2534 def v16i8: ROTQBYVecInst<v16i8>;
2535 def v8i16: ROTQBYVecInst<v8i16>;
2536 def v4i32: ROTQBYVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002537 def v4f32: ROTQBYVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002538 def v2i64: ROTQBYVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002539 def v2f64: ROTQBYVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002540}
2541
2542defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel66377522007-12-04 22:35:58 +00002543
Scott Michela59d4692008-02-23 18:41:37 +00002544//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2545// Rotate quad by byte (count), immediate
2546//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2547
2548class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2549 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2550 RotateShift, pattern>;
2551
2552class ROTQBYIVecInst<ValueType vectype>:
2553 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2554 [(set (vectype VECREG:$rT),
2555 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2556
2557multiclass RotateQuadByBytesImm
2558{
2559 def v16i8: ROTQBYIVecInst<v16i8>;
2560 def v8i16: ROTQBYIVecInst<v8i16>;
2561 def v4i32: ROTQBYIVecInst<v4i32>;
Scott Michelcc188272008-12-04 21:01:44 +00002562 def v4f32: ROTQBYIVecInst<v4f32>;
Scott Michela59d4692008-02-23 18:41:37 +00002563 def v2i64: ROTQBYIVecInst<v2i64>;
Scott Michelcc188272008-12-04 21:01:44 +00002564 def vfi64: ROTQBYIVecInst<v2f64>;
Scott Michela59d4692008-02-23 18:41:37 +00002565}
2566
2567defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel66377522007-12-04 22:35:58 +00002568
Scott Michel66377522007-12-04 22:35:58 +00002569// See ROTQBY note above.
Scott Michel8bf61e82008-06-02 22:18:03 +00002570class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2571 RI7Form<0b00110011100, OOL, IOL,
2572 "rotqbybi\t$rT, $rA, $shift",
2573 RotateShift, pattern>;
2574
2575class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2576 ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2577 [(set (vectype VECREG:$rT),
2578 (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2579
2580multiclass RotateQuadByBytesByBitshift {
2581 def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2582 def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2583 def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2584 def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2585}
2586
2587defm ROTQBYBI : RotateQuadByBytesByBitshift;
Scott Michel66377522007-12-04 22:35:58 +00002588
Scott Michela59d4692008-02-23 18:41:37 +00002589//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002590// See ROTQBY note above.
2591//
2592// Assume that the user of this instruction knows to shift the rotate count
2593// into bit 29
Scott Michela59d4692008-02-23 18:41:37 +00002594//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002595
Scott Michela59d4692008-02-23 18:41:37 +00002596class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2597 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2598 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002599
Scott Michela59d4692008-02-23 18:41:37 +00002600class ROTQBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002601 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002602 [/* no pattern yet */]>;
2603
2604class ROTQBIRegInst<RegisterClass rclass>:
Scott Michel02d711b2008-12-30 23:28:25 +00002605 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michela59d4692008-02-23 18:41:37 +00002606 [/* no pattern yet */]>;
2607
2608multiclass RotateQuadByBitCount
2609{
2610 def v16i8: ROTQBIVecInst<v16i8>;
2611 def v8i16: ROTQBIVecInst<v8i16>;
2612 def v4i32: ROTQBIVecInst<v4i32>;
2613 def v2i64: ROTQBIVecInst<v2i64>;
2614
2615 def r128: ROTQBIRegInst<GPRC>;
2616 def r64: ROTQBIRegInst<R64C>;
2617}
2618
2619defm ROTQBI: RotateQuadByBitCount;
Scott Michelf0569be2008-12-27 04:51:36 +00002620
Scott Michela59d4692008-02-23 18:41:37 +00002621class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2622 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2623 RotateShift, pattern>;
2624
2625class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2626 PatLeaf pred>:
2627 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2628 [/* no pattern yet */]>;
2629
2630class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2631 PatLeaf pred>:
2632 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2633 [/* no pattern yet */]>;
2634
2635multiclass RotateQuadByBitCountImm
2636{
2637 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2638 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2639 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2640 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2641
2642 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2643 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2644}
2645
2646defm ROTQBII : RotateQuadByBitCountImm;
2647
2648//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002649// ROTHM v8i16 form:
2650// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2651// so this only matches a synthetically generated/lowered code
2652// fragment.
2653// NOTE(2): $rB must be negated before the right rotate!
Scott Michela59d4692008-02-23 18:41:37 +00002654//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002655
Scott Michela59d4692008-02-23 18:41:37 +00002656class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2657 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2658 RotateShift, pattern>;
2659
2660def ROTHMv8i16:
2661 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2662 [/* see patterns below - $rB must be negated */]>;
2663
2664def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002665 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2666
Scott Michela59d4692008-02-23 18:41:37 +00002667def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002668 (ROTHMv8i16 VECREG:$rA,
2669 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2670
Scott Michela59d4692008-02-23 18:41:37 +00002671def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002672 (ROTHMv8i16 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002673 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002674
2675// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2676// Note: This instruction doesn't match a pattern because rB must be negated
2677// for the instruction to work. Thus, the pattern below the instruction!
Scott Michela59d4692008-02-23 18:41:37 +00002678
Scott Michel66377522007-12-04 22:35:58 +00002679def ROTHMr16:
Scott Michela59d4692008-02-23 18:41:37 +00002680 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2681 [/* see patterns below - $rB must be negated! */]>;
Scott Michel66377522007-12-04 22:35:58 +00002682
2683def : Pat<(srl R16C:$rA, R32C:$rB),
2684 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2685
2686def : Pat<(srl R16C:$rA, R16C:$rB),
2687 (ROTHMr16 R16C:$rA,
2688 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2689
Scott Michel504c3692007-12-17 22:32:34 +00002690def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002691 (ROTHMr16 R16C:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00002692 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002693
2694// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2695// that the immediate can be complemented, so that the user doesn't have to
2696// worry about it.
Scott Michel66377522007-12-04 22:35:58 +00002697
Scott Michela59d4692008-02-23 18:41:37 +00002698class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2699 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2700 RotateShift, pattern>;
2701
2702def ROTHMIv8i16:
2703 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2704 [/* no pattern */]>;
2705
2706def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2707 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2708
2709def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002710 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002711
Scott Michela59d4692008-02-23 18:41:37 +00002712def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002713 (ROTHMIv8i16 VECREG:$rA, (TO_IMM32 imm:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002714
2715def ROTHMIr16:
Scott Michela59d4692008-02-23 18:41:37 +00002716 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2717 [/* no pattern */]>;
2718
2719def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2720 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel66377522007-12-04 22:35:58 +00002721
2722def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002723 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002724
Scott Michel504c3692007-12-17 22:32:34 +00002725def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002726 (ROTHMIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002727
Scott Michel66377522007-12-04 22:35:58 +00002728// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michela59d4692008-02-23 18:41:37 +00002729class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2730 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2731 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002732
Scott Michela59d4692008-02-23 18:41:37 +00002733def ROTMv4i32:
2734 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2735 [/* see patterns below - $rB must be negated */]>;
2736
Chris Lattner420c69d2010-03-15 05:53:47 +00002737def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002738 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2739
Chris Lattner420c69d2010-03-15 05:53:47 +00002740def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002741 (ROTMv4i32 VECREG:$rA,
2742 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2743
Chris Lattner420c69d2010-03-15 05:53:47 +00002744def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), R8C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002745 (ROTMv4i32 VECREG:$rA,
Scott Michela59d4692008-02-23 18:41:37 +00002746 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel66377522007-12-04 22:35:58 +00002747
2748def ROTMr32:
Scott Michela59d4692008-02-23 18:41:37 +00002749 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2750 [/* see patterns below - $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002751
2752def : Pat<(srl R32C:$rA, R32C:$rB),
2753 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2754
2755def : Pat<(srl R32C:$rA, R16C:$rB),
2756 (ROTMr32 R32C:$rA,
2757 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2758
Scott Michel504c3692007-12-17 22:32:34 +00002759def : Pat<(srl R32C:$rA, R8C:$rB),
2760 (ROTMr32 R32C:$rA,
2761 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2762
Scott Michel66377522007-12-04 22:35:58 +00002763// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2764def ROTMIv4i32:
2765 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2766 "rotmi\t$rT, $rA, $val", RotateShift,
2767 [(set (v4i32 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002768 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002769
Chris Lattner420c69d2010-03-15 05:53:47 +00002770def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2771 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michelf0569be2008-12-27 04:51:36 +00002772
Chris Lattner420c69d2010-03-15 05:53:47 +00002773def : Pat<(SPUvec_srl (v4i32 VECREG:$rA), (i8 uimm7:$val)),
2774 (ROTMIv4i32 VECREG:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002775
2776// ROTMI r32 form: know how to complement the immediate value.
2777def ROTMIr32:
2778 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2779 "rotmi\t$rT, $rA, $val", RotateShift,
2780 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2781
2782def : Pat<(srl R32C:$rA, (i16 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002783 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002784
Scott Michel504c3692007-12-17 22:32:34 +00002785def : Pat<(srl R32C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002786 (ROTMIr32 R32C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002787
Scott Michela59d4692008-02-23 18:41:37 +00002788//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Micheldd950092009-01-06 03:36:14 +00002789// ROTQMBY: This is a vector form merely so that when used in an
Scott Michel66377522007-12-04 22:35:58 +00002790// instruction pattern, type checking will succeed. This instruction assumes
Scott Michela59d4692008-02-23 18:41:37 +00002791// that the user knew to negate $rB.
Scott Michela59d4692008-02-23 18:41:37 +00002792//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002793
Scott Michela59d4692008-02-23 18:41:37 +00002794class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2795 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2796 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00002797
Scott Michela59d4692008-02-23 18:41:37 +00002798class ROTQMBYVecInst<ValueType vectype>:
2799 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2800 [/* no pattern, $rB must be negated */]>;
Scott Michel66377522007-12-04 22:35:58 +00002801
Scott Michela59d4692008-02-23 18:41:37 +00002802class ROTQMBYRegInst<RegisterClass rclass>:
2803 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00002804 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00002805
Scott Michela59d4692008-02-23 18:41:37 +00002806multiclass RotateQuadBytes
2807{
2808 def v16i8: ROTQMBYVecInst<v16i8>;
2809 def v8i16: ROTQMBYVecInst<v8i16>;
2810 def v4i32: ROTQMBYVecInst<v4i32>;
2811 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel66377522007-12-04 22:35:58 +00002812
Scott Michela59d4692008-02-23 18:41:37 +00002813 def r128: ROTQMBYRegInst<GPRC>;
2814 def r64: ROTQMBYRegInst<R64C>;
2815}
2816
2817defm ROTQMBY : RotateQuadBytes;
2818
Scott Michela59d4692008-02-23 18:41:37 +00002819class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2820 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2821 RotateShift, pattern>;
2822
2823class ROTQMBYIVecInst<ValueType vectype>:
2824 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002825 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002826
Scott Micheldd950092009-01-06 03:36:14 +00002827class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2828 PatLeaf pred>:
Scott Michela59d4692008-02-23 18:41:37 +00002829 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002830 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002831
Scott Micheldd950092009-01-06 03:36:14 +00002832// 128-bit zero extension form:
2833class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2834 ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2835 [/* no pattern */]>;
2836
Scott Michela59d4692008-02-23 18:41:37 +00002837multiclass RotateQuadBytesImm
2838{
2839 def v16i8: ROTQMBYIVecInst<v16i8>;
2840 def v8i16: ROTQMBYIVecInst<v8i16>;
2841 def v4i32: ROTQMBYIVecInst<v4i32>;
2842 def v2i64: ROTQMBYIVecInst<v2i64>;
2843
2844 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2845 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
Scott Micheldd950092009-01-06 03:36:14 +00002846
2847 def r128_zext_r8: ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2848 def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2849 def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2850 def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
Scott Michela59d4692008-02-23 18:41:37 +00002851}
2852
2853defm ROTQMBYI : RotateQuadBytesImm;
2854
Scott Michela59d4692008-02-23 18:41:37 +00002855//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2856// Rotate right and mask by bit count
2857//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2858
2859class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2860 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2861 RotateShift, pattern>;
2862
2863class ROTQMBYBIVecInst<ValueType vectype>:
Scott Michel02d711b2008-12-30 23:28:25 +00002864 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2865 [/* no pattern, */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002866
2867multiclass RotateMaskQuadByBitCount
2868{
2869 def v16i8: ROTQMBYBIVecInst<v16i8>;
2870 def v8i16: ROTQMBYBIVecInst<v8i16>;
2871 def v4i32: ROTQMBYBIVecInst<v4i32>;
2872 def v2i64: ROTQMBYBIVecInst<v2i64>;
2873}
2874
2875defm ROTQMBYBI: RotateMaskQuadByBitCount;
2876
2877//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2878// Rotate quad and mask by bits
2879// Note that the rotate amount has to be negated
2880//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2881
2882class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2883 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2884 RotateShift, pattern>;
2885
2886class ROTQMBIVecInst<ValueType vectype>:
2887 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2888 [/* no pattern */]>;
2889
2890class ROTQMBIRegInst<RegisterClass rclass>:
2891 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2892 [/* no pattern */]>;
2893
2894multiclass RotateMaskQuadByBits
2895{
2896 def v16i8: ROTQMBIVecInst<v16i8>;
2897 def v8i16: ROTQMBIVecInst<v8i16>;
2898 def v4i32: ROTQMBIVecInst<v4i32>;
2899 def v2i64: ROTQMBIVecInst<v2i64>;
2900
2901 def r128: ROTQMBIRegInst<GPRC>;
2902 def r64: ROTQMBIRegInst<R64C>;
2903}
2904
2905defm ROTQMBI: RotateMaskQuadByBits;
2906
Scott Michela59d4692008-02-23 18:41:37 +00002907//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2908// Rotate quad and mask by bits, immediate
2909//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2910
2911class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2912 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2913 RotateShift, pattern>;
2914
2915class ROTQMBIIVecInst<ValueType vectype>:
2916 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002917 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002918
2919class ROTQMBIIRegInst<RegisterClass rclass>:
2920 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
Scott Michel02d711b2008-12-30 23:28:25 +00002921 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00002922
2923multiclass RotateMaskQuadByBitsImm
2924{
2925 def v16i8: ROTQMBIIVecInst<v16i8>;
2926 def v8i16: ROTQMBIIVecInst<v8i16>;
2927 def v4i32: ROTQMBIIVecInst<v4i32>;
2928 def v2i64: ROTQMBIIVecInst<v2i64>;
2929
2930 def r128: ROTQMBIIRegInst<GPRC>;
2931 def r64: ROTQMBIIRegInst<R64C>;
2932}
2933
2934defm ROTQMBII: RotateMaskQuadByBitsImm;
2935
2936//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2937//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00002938
2939def ROTMAHv8i16:
2940 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2941 "rotmah\t$rT, $rA, $rB", RotateShift,
2942 [/* see patterns below - $rB must be negated */]>;
2943
Chris Lattner420c69d2010-03-15 05:53:47 +00002944def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002945 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2946
Chris Lattner420c69d2010-03-15 05:53:47 +00002947def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel66377522007-12-04 22:35:58 +00002948 (ROTMAHv8i16 VECREG:$rA,
2949 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2950
Chris Lattner420c69d2010-03-15 05:53:47 +00002951def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel504c3692007-12-17 22:32:34 +00002952 (ROTMAHv8i16 VECREG:$rA,
2953 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2954
Scott Michel66377522007-12-04 22:35:58 +00002955def ROTMAHr16:
2956 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2957 "rotmah\t$rT, $rA, $rB", RotateShift,
2958 [/* see patterns below - $rB must be negated */]>;
2959
2960def : Pat<(sra R16C:$rA, R32C:$rB),
2961 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2962
2963def : Pat<(sra R16C:$rA, R16C:$rB),
2964 (ROTMAHr16 R16C:$rA,
2965 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2966
Scott Michel504c3692007-12-17 22:32:34 +00002967def : Pat<(sra R16C:$rA, R8C:$rB),
2968 (ROTMAHr16 R16C:$rA,
2969 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2970
Scott Michel66377522007-12-04 22:35:58 +00002971def ROTMAHIv8i16:
2972 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2973 "rotmahi\t$rT, $rA, $val", RotateShift,
2974 [(set (v8i16 VECREG:$rT),
Scott Michela59d4692008-02-23 18:41:37 +00002975 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00002976
Scott Michela59d4692008-02-23 18:41:37 +00002977def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002978 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002979
Scott Michela59d4692008-02-23 18:41:37 +00002980def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002981 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002982
Scott Michel66377522007-12-04 22:35:58 +00002983def ROTMAHIr16:
2984 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2985 "rotmahi\t$rT, $rA, $val", RotateShift,
2986 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2987
2988def : Pat<(sra R16C:$rA, (i32 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002989 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel66377522007-12-04 22:35:58 +00002990
Scott Michel504c3692007-12-17 22:32:34 +00002991def : Pat<(sra R16C:$rA, (i8 imm:$val)),
Chris Lattner420c69d2010-03-15 05:53:47 +00002992 (ROTMAHIr16 R16C:$rA, (TO_IMM32 uimm7:$val))>;
Scott Michel504c3692007-12-17 22:32:34 +00002993
Scott Michel66377522007-12-04 22:35:58 +00002994def ROTMAv4i32:
2995 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2996 "rotma\t$rT, $rA, $rB", RotateShift,
2997 [/* see patterns below - $rB must be negated */]>;
2998
Chris Lattner420c69d2010-03-15 05:53:47 +00002999def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R32C:$rB),
3000 (ROTMAv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
Scott Michel66377522007-12-04 22:35:58 +00003001
Chris Lattner420c69d2010-03-15 05:53:47 +00003002def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R16C:$rB),
3003 (ROTMAv4i32 VECREG:$rA,
Scott Michel66377522007-12-04 22:35:58 +00003004 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3005
Chris Lattner420c69d2010-03-15 05:53:47 +00003006def : Pat<(SPUvec_sra (v4i32 VECREG:$rA), R8C:$rB),
3007 (ROTMAv4i32 VECREG:$rA,
Scott Michel504c3692007-12-17 22:32:34 +00003008 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3009
Scott Michel66377522007-12-04 22:35:58 +00003010def ROTMAr32:
3011 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3012 "rotma\t$rT, $rA, $rB", RotateShift,
3013 [/* see patterns below - $rB must be negated */]>;
3014
3015def : Pat<(sra R32C:$rA, R32C:$rB),
3016 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3017
3018def : Pat<(sra R32C:$rA, R16C:$rB),
3019 (ROTMAr32 R32C:$rA,
3020 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3021
Scott Michel504c3692007-12-17 22:32:34 +00003022def : Pat<(sra R32C:$rA, R8C:$rB),
3023 (ROTMAr32 R32C:$rA,
3024 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3025
Scott Michel8bf61e82008-06-02 22:18:03 +00003026class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3027 RRForm<0b01011110000, OOL, IOL,
3028 "rotmai\t$rT, $rA, $val",
3029 RotateShift, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003030
Scott Michel8bf61e82008-06-02 22:18:03 +00003031class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3032 ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3033 [(set (vectype VECREG:$rT),
3034 (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003035
Scott Michel8bf61e82008-06-02 22:18:03 +00003036class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3037 ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3038 [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003039
Scott Michel8bf61e82008-06-02 22:18:03 +00003040multiclass RotateMaskAlgebraicImm {
3041 def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3042 def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3043 def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3044 def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3045}
Scott Michel66377522007-12-04 22:35:58 +00003046
Scott Michel8bf61e82008-06-02 22:18:03 +00003047defm ROTMAI : RotateMaskAlgebraicImm;
Scott Michel504c3692007-12-17 22:32:34 +00003048
Scott Michel66377522007-12-04 22:35:58 +00003049//===----------------------------------------------------------------------===//
3050// Branch and conditionals:
3051//===----------------------------------------------------------------------===//
3052
3053let isTerminator = 1, isBarrier = 1 in {
3054 // Halt If Equal (r32 preferred slot only, no vector form)
3055 def HEQr32:
3056 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3057 "heq\t$rA, $rB", BranchResolv,
3058 [/* no pattern to match */]>;
3059
3060 def HEQIr32 :
3061 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3062 "heqi\t$rA, $val", BranchResolv,
3063 [/* no pattern to match */]>;
3064
3065 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3066 // contrasting with HLGT/HLGTI, which use unsigned comparison:
3067 def HGTr32:
3068 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3069 "hgt\t$rA, $rB", BranchResolv,
3070 [/* no pattern to match */]>;
3071
Scott Michelf0569be2008-12-27 04:51:36 +00003072 def HGTIr32:
Scott Michel66377522007-12-04 22:35:58 +00003073 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3074 "hgti\t$rA, $val", BranchResolv,
3075 [/* no pattern to match */]>;
3076
3077 def HLGTr32:
3078 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3079 "hlgt\t$rA, $rB", BranchResolv,
3080 [/* no pattern to match */]>;
3081
3082 def HLGTIr32:
3083 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3084 "hlgti\t$rA, $val", BranchResolv,
3085 [/* no pattern to match */]>;
3086}
3087
Scott Michelf0569be2008-12-27 04:51:36 +00003088//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3089// Comparison operators for i8, i16 and i32:
3090//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003091
Scott Michela59d4692008-02-23 18:41:37 +00003092class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3093 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3094 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003095
Scott Michela59d4692008-02-23 18:41:37 +00003096multiclass CmpEqualByte
3097{
3098 def v16i8 :
3099 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3100 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3101 (v8i16 VECREG:$rB)))]>;
Scott Michel504c3692007-12-17 22:32:34 +00003102
Scott Michela59d4692008-02-23 18:41:37 +00003103 def r8 :
3104 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3105 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3106}
Scott Michel66377522007-12-04 22:35:58 +00003107
Scott Michela59d4692008-02-23 18:41:37 +00003108class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3109 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3110 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003111
Scott Michela59d4692008-02-23 18:41:37 +00003112multiclass CmpEqualByteImm
3113{
3114 def v16i8 :
3115 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3116 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3117 v16i8SExt8Imm:$val))]>;
3118 def r8:
3119 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3120 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3121}
Scott Michel66377522007-12-04 22:35:58 +00003122
Scott Michela59d4692008-02-23 18:41:37 +00003123class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3124 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3125 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003126
Scott Michela59d4692008-02-23 18:41:37 +00003127multiclass CmpEqualHalfword
3128{
3129 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3130 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3131 (v8i16 VECREG:$rB)))]>;
Scott Michel66377522007-12-04 22:35:58 +00003132
Scott Michela59d4692008-02-23 18:41:37 +00003133 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3134 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3135}
Scott Michel66377522007-12-04 22:35:58 +00003136
Scott Michela59d4692008-02-23 18:41:37 +00003137class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3138 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3139 ByteOp, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003140
Scott Michela59d4692008-02-23 18:41:37 +00003141multiclass CmpEqualHalfwordImm
3142{
3143 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3144 [(set (v8i16 VECREG:$rT),
3145 (seteq (v8i16 VECREG:$rA),
3146 (v8i16 v8i16SExt10Imm:$val)))]>;
3147 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3148 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3149}
Scott Michel66377522007-12-04 22:35:58 +00003150
Scott Michela59d4692008-02-23 18:41:37 +00003151class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3152 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3153 ByteOp, pattern>;
3154
3155multiclass CmpEqualWord
3156{
3157 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3158 [(set (v4i32 VECREG:$rT),
3159 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3160
3161 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3162 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3163}
3164
3165class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3166 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3167 ByteOp, pattern>;
3168
3169multiclass CmpEqualWordImm
3170{
3171 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3172 [(set (v4i32 VECREG:$rT),
3173 (seteq (v4i32 VECREG:$rA),
3174 (v4i32 v4i32SExt16Imm:$val)))]>;
3175
3176 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3177 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3178}
3179
3180class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3181 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3182 ByteOp, pattern>;
3183
3184multiclass CmpGtrByte
3185{
3186 def v16i8 :
3187 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3188 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3189 (v8i16 VECREG:$rB)))]>;
3190
3191 def r8 :
3192 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3193 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3194}
3195
3196class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3197 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3198 ByteOp, pattern>;
3199
3200multiclass CmpGtrByteImm
3201{
3202 def v16i8 :
3203 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3204 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3205 v16i8SExt8Imm:$val))]>;
3206 def r8:
3207 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel79698f62008-03-20 00:51:36 +00003208 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003209}
3210
3211class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3212 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3213 ByteOp, pattern>;
3214
3215multiclass CmpGtrHalfword
3216{
3217 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3218 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3219 (v8i16 VECREG:$rB)))]>;
3220
3221 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3222 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3223}
3224
3225class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3226 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3227 ByteOp, pattern>;
3228
3229multiclass CmpGtrHalfwordImm
3230{
3231 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3232 [(set (v8i16 VECREG:$rT),
3233 (setgt (v8i16 VECREG:$rA),
3234 (v8i16 v8i16SExt10Imm:$val)))]>;
3235 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3236 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3237}
3238
3239class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3240 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3241 ByteOp, pattern>;
3242
3243multiclass CmpGtrWord
3244{
3245 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3246 [(set (v4i32 VECREG:$rT),
3247 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3248
3249 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3250 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3251}
3252
3253class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3254 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3255 ByteOp, pattern>;
3256
3257multiclass CmpGtrWordImm
3258{
3259 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3260 [(set (v4i32 VECREG:$rT),
3261 (setgt (v4i32 VECREG:$rA),
3262 (v4i32 v4i32SExt16Imm:$val)))]>;
3263
3264 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3265 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel02d711b2008-12-30 23:28:25 +00003266
3267 // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3268 def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3269 [(set (v4i32 VECREG:$rT),
3270 (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3271 (v4i32 v4i32SExt16Imm:$val)))]>;
3272
3273 def f32: CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
Scott Michel19c10e62009-01-26 03:37:41 +00003274 [/* no pattern */]>;
Scott Michela59d4692008-02-23 18:41:37 +00003275}
3276
3277class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003278 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003279 ByteOp, pattern>;
3280
3281multiclass CmpLGtrByte
3282{
3283 def v16i8 :
3284 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3285 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3286 (v8i16 VECREG:$rB)))]>;
3287
3288 def r8 :
3289 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3290 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3291}
3292
3293class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003294 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003295 ByteOp, pattern>;
3296
3297multiclass CmpLGtrByteImm
3298{
3299 def v16i8 :
3300 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3301 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3302 v16i8SExt8Imm:$val))]>;
3303 def r8:
3304 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3305 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3306}
3307
3308class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003309 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003310 ByteOp, pattern>;
3311
3312multiclass CmpLGtrHalfword
3313{
3314 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3315 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3316 (v8i16 VECREG:$rB)))]>;
3317
3318 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3319 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3320}
3321
3322class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003323 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003324 ByteOp, pattern>;
3325
3326multiclass CmpLGtrHalfwordImm
3327{
3328 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3329 [(set (v8i16 VECREG:$rT),
3330 (setugt (v8i16 VECREG:$rA),
3331 (v8i16 v8i16SExt10Imm:$val)))]>;
3332 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3333 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3334}
3335
3336class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003337 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michela59d4692008-02-23 18:41:37 +00003338 ByteOp, pattern>;
3339
3340multiclass CmpLGtrWord
3341{
3342 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3343 [(set (v4i32 VECREG:$rT),
3344 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3345
3346 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3347 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3348}
3349
3350class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michelad2715e2008-03-05 23:02:02 +00003351 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michela59d4692008-02-23 18:41:37 +00003352 ByteOp, pattern>;
3353
3354multiclass CmpLGtrWordImm
3355{
3356 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3357 [(set (v4i32 VECREG:$rT),
3358 (setugt (v4i32 VECREG:$rA),
3359 (v4i32 v4i32SExt16Imm:$val)))]>;
3360
3361 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michelad2715e2008-03-05 23:02:02 +00003362 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michela59d4692008-02-23 18:41:37 +00003363}
3364
3365defm CEQB : CmpEqualByte;
3366defm CEQBI : CmpEqualByteImm;
3367defm CEQH : CmpEqualHalfword;
3368defm CEQHI : CmpEqualHalfwordImm;
3369defm CEQ : CmpEqualWord;
3370defm CEQI : CmpEqualWordImm;
3371defm CGTB : CmpGtrByte;
3372defm CGTBI : CmpGtrByteImm;
3373defm CGTH : CmpGtrHalfword;
3374defm CGTHI : CmpGtrHalfwordImm;
3375defm CGT : CmpGtrWord;
3376defm CGTI : CmpGtrWordImm;
3377defm CLGTB : CmpLGtrByte;
3378defm CLGTBI : CmpLGtrByteImm;
3379defm CLGTH : CmpLGtrHalfword;
3380defm CLGTHI : CmpLGtrHalfwordImm;
3381defm CLGT : CmpLGtrWord;
3382defm CLGTI : CmpLGtrWordImm;
3383
Scott Michel78c47fa2008-03-10 16:58:52 +00003384//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003385// For SETCC primitives not supported above (setlt, setle, setge, etc.)
3386// define a pattern to generate the right code, as a binary operator
3387// (in a manner of speaking.)
Scott Michel78c47fa2008-03-10 16:58:52 +00003388//
Scott Michelf0569be2008-12-27 04:51:36 +00003389// Notes:
3390// 1. This only matches the setcc set of conditionals. Special pattern
3391// matching is used for select conditionals.
3392//
3393// 2. The "DAG" versions of these classes is almost exclusively used for
3394// i64 comparisons. See the tblgen fundamentals documentation for what
3395// ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3396// class for where ResultInstrs originates.
Scott Michel78c47fa2008-03-10 16:58:52 +00003397//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michela59d4692008-02-23 18:41:37 +00003398
Scott Michel78c47fa2008-03-10 16:58:52 +00003399class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3400 SPUInstr xorinst, SPUInstr cmpare>:
3401 Pat<(cond rclass:$rA, rclass:$rB),
3402 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3403
3404class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3405 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3406 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3407 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3408
Scott Michelf0569be2008-12-27 04:51:36 +00003409def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003410def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3411
Scott Michelf0569be2008-12-27 04:51:36 +00003412def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003413def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3414
3415def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3416def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003417
3418class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3419 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3420 Pat<(cond rclass:$rA, rclass:$rB),
3421 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3422 (cmpOp2 rclass:$rA, rclass:$rB))>;
3423
3424class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3425 ValueType immtype,
3426 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3427 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3428 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3429 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3430
Scott Michel78c47fa2008-03-10 16:58:52 +00003431def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3432def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3433def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3434def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3435def : Pat<(setle R8C:$rA, R8C:$rB),
3436 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3437def : Pat<(setle R8C:$rA, immU8:$imm),
3438 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003439
Scott Michel78c47fa2008-03-10 16:58:52 +00003440def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3441def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3442 ORr16, CGTHIr16, CEQHIr16>;
3443def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3444def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3445def : Pat<(setle R16C:$rA, R16C:$rB),
3446 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3447def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3448 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003449
Scott Michel78c47fa2008-03-10 16:58:52 +00003450def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3451def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3452 ORr32, CGTIr32, CEQIr32>;
3453def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3454def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3455def : Pat<(setle R32C:$rA, R32C:$rB),
3456 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3457def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3458 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003459
Scott Michel78c47fa2008-03-10 16:58:52 +00003460def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3461def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3462def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3463def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3464def : Pat<(setule R8C:$rA, R8C:$rB),
3465 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3466def : Pat<(setule R8C:$rA, immU8:$imm),
3467 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003468
Scott Michel78c47fa2008-03-10 16:58:52 +00003469def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3470def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3471 ORr16, CLGTHIr16, CEQHIr16>;
3472def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3473def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3474 CLGTHIr16, CEQHIr16>;
3475def : Pat<(setule R16C:$rA, R16C:$rB),
3476 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel79698f62008-03-20 00:51:36 +00003477def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel78c47fa2008-03-10 16:58:52 +00003478 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003479
Scott Michel78c47fa2008-03-10 16:58:52 +00003480def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003481def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel78c47fa2008-03-10 16:58:52 +00003482 ORr32, CLGTIr32, CEQIr32>;
3483def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel79698f62008-03-20 00:51:36 +00003484def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003485def : Pat<(setule R32C:$rA, R32C:$rB),
3486 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3487def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3488 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michela59d4692008-02-23 18:41:37 +00003489
Scott Michel78c47fa2008-03-10 16:58:52 +00003490//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3491// select conditional patterns:
3492//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3493
3494class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3495 SPUInstr selinstr, SPUInstr cmpare>:
3496 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3497 rclass:$rTrue, rclass:$rFalse),
3498 (selinstr rclass:$rTrue, rclass:$rFalse,
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003499 (cmpare rclass:$rA, rclass:$rB))>;
Scott Michel78c47fa2008-03-10 16:58:52 +00003500
3501class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3502 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3503 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003504 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003505 (selinstr rclass:$rTrue, rclass:$rFalse,
3506 (cmpare rclass:$rA, immpred:$imm))>;
3507
3508def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3509def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3510def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3511def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3512def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3513def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3514
3515def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3516def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3517def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3518def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3519def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3520def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3521
3522def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3523def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3524def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3525def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3526def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3527def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3528
3529class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3530 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3531 SPUInstr cmpOp2>:
3532 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
Scott Michelf0569be2008-12-27 04:51:36 +00003533 rclass:$rTrue, rclass:$rFalse),
3534 (selinstr rclass:$rFalse, rclass:$rTrue,
Scott Michel78c47fa2008-03-10 16:58:52 +00003535 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3536 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3537
3538class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3539 ValueType inttype,
3540 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3541 SPUInstr cmpOp2>:
3542 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
Bill Wendlingbbf2e062008-07-22 08:50:44 +00003543 rclass:$rTrue, rclass:$rFalse),
Scott Michel78c47fa2008-03-10 16:58:52 +00003544 (selinstr rclass:$rFalse, rclass:$rTrue,
3545 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3546 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3547
3548def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3549def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3550 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3551
3552def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3553def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3554 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3555
3556def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3557def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3558 SELBr32, ORr32, CGTIr32, CEQIr32>;
3559
3560def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3561def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3562 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3563
3564def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3565def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3566 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3567
3568def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3569def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3570 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003571
3572//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel66377522007-12-04 22:35:58 +00003573
3574let isCall = 1,
3575 // All calls clobber the non-callee-saved registers:
3576 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3577 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3578 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3579 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3580 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3581 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3582 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3583 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3584 // All of these instructions use $lr (aka $0)
3585 Uses = [R0] in {
3586 // Branch relative and set link: Used if we actually know that the target
3587 // is within [-32768, 32767] bytes of the target
3588 def BRSL:
3589 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3590 "brsl\t$$lr, $func",
3591 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3592
3593 // Branch absolute and set link: Used if we actually know that the target
3594 // is an absolute address
3595 def BRASL:
3596 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3597 "brasl\t$$lr, $func",
Scott Michel9de5d0d2008-01-11 02:53:15 +00003598 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel66377522007-12-04 22:35:58 +00003599
3600 // Branch indirect and set link if external data. These instructions are not
3601 // actually generated, matched by an intrinsic:
3602 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3603 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3604 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3605 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3606
3607 // Branch indirect and set link. This is the "X-form" address version of a
3608 // function call
3609 def BISL:
3610 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3611}
3612
Scott Michel1df30c42008-12-29 03:23:36 +00003613// Support calls to external symbols:
3614def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3615 (BRSL texternalsym:$func)>;
3616
3617def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3618 (BRASL texternalsym:$func)>;
3619
Scott Michel66377522007-12-04 22:35:58 +00003620// Unconditional branches:
Dan Gohman5b37fba2009-11-10 22:16:57 +00003621let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
3622 let isBarrier = 1 in {
3623 def BR :
3624 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3625 "br\t$dest",
3626 [(br bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003627
Dan Gohman5b37fba2009-11-10 22:16:57 +00003628 // Unconditional, absolute address branch
3629 def BRA:
3630 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3631 "bra\t$dest",
3632 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003633
Dan Gohman5b37fba2009-11-10 22:16:57 +00003634 // Indirect branch
3635 def BI:
3636 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3637 }
Scott Michel66377522007-12-04 22:35:58 +00003638
Scott Micheled741dd2009-01-05 01:34:35 +00003639 // Conditional branches:
Scott Michelf0569be2008-12-27 04:51:36 +00003640 class BRNZInst<dag IOL, list<dag> pattern>:
3641 RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3642 BranchResolv, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003643
Scott Michelf0569be2008-12-27 04:51:36 +00003644 class BRNZRegInst<RegisterClass rclass>:
3645 BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3646 [(brcond rclass:$rCond, bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003647
Scott Michelf0569be2008-12-27 04:51:36 +00003648 class BRNZVecInst<ValueType vectype>:
3649 BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3650 [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
Scott Michel66377522007-12-04 22:35:58 +00003651
Scott Michelf0569be2008-12-27 04:51:36 +00003652 multiclass BranchNotZero {
3653 def v4i32 : BRNZVecInst<v4i32>;
3654 def r32 : BRNZRegInst<R32C>;
3655 }
Scott Michel66377522007-12-04 22:35:58 +00003656
Scott Michelf0569be2008-12-27 04:51:36 +00003657 defm BRNZ : BranchNotZero;
3658
3659 class BRZInst<dag IOL, list<dag> pattern>:
3660 RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3661 BranchResolv, pattern>;
3662
3663 class BRZRegInst<RegisterClass rclass>:
3664 BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3665
3666 class BRZVecInst<ValueType vectype>:
3667 BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3668
3669 multiclass BranchZero {
3670 def v4i32: BRZVecInst<v4i32>;
3671 def r32: BRZRegInst<R32C>;
3672 }
3673
3674 defm BRZ: BranchZero;
3675
3676 // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3677 // be useful:
3678 /*
3679 class BINZInst<dag IOL, list<dag> pattern>:
3680 BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3681
3682 class BINZRegInst<RegisterClass rclass>:
3683 BINZInst<(ins rclass:$rA, brtarget:$dest),
3684 [(brcond rclass:$rA, R32C:$dest)]>;
3685
3686 class BINZVecInst<ValueType vectype>:
3687 BINZInst<(ins VECREG:$rA, R32C:$dest),
3688 [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3689
3690 multiclass BranchNotZeroIndirect {
3691 def v4i32: BINZVecInst<v4i32>;
3692 def r32: BINZRegInst<R32C>;
3693 }
3694
3695 defm BINZ: BranchNotZeroIndirect;
3696
3697 class BIZInst<dag IOL, list<dag> pattern>:
3698 BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3699
3700 class BIZRegInst<RegisterClass rclass>:
3701 BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3702
3703 class BIZVecInst<ValueType vectype>:
3704 BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3705
3706 multiclass BranchZeroIndirect {
3707 def v4i32: BIZVecInst<v4i32>;
3708 def r32: BIZRegInst<R32C>;
3709 }
3710
3711 defm BIZ: BranchZeroIndirect;
3712 */
3713
3714 class BRHNZInst<dag IOL, list<dag> pattern>:
3715 RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3716 pattern>;
3717
3718 class BRHNZRegInst<RegisterClass rclass>:
3719 BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3720 [(brcond rclass:$rCond, bb:$dest)]>;
3721
3722 class BRHNZVecInst<ValueType vectype>:
3723 BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3724
3725 multiclass BranchNotZeroHalfword {
3726 def v8i16: BRHNZVecInst<v8i16>;
3727 def r16: BRHNZRegInst<R16C>;
3728 }
3729
3730 defm BRHNZ: BranchNotZeroHalfword;
3731
3732 class BRHZInst<dag IOL, list<dag> pattern>:
3733 RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3734 pattern>;
3735
3736 class BRHZRegInst<RegisterClass rclass>:
3737 BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3738
3739 class BRHZVecInst<ValueType vectype>:
3740 BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3741
3742 multiclass BranchZeroHalfword {
3743 def v8i16: BRHZVecInst<v8i16>;
3744 def r16: BRHZRegInst<R16C>;
3745 }
3746
3747 defm BRHZ: BranchZeroHalfword;
Scott Michel66377522007-12-04 22:35:58 +00003748}
3749
Scott Michel58c58182008-01-17 20:38:41 +00003750//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003751// setcc and brcond patterns:
Scott Michel58c58182008-01-17 20:38:41 +00003752//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00003753
Scott Michelf0569be2008-12-27 04:51:36 +00003754def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3755 (BRHZr16 R16C:$rA, bb:$dest)>;
3756def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3757 (BRHNZr16 R16C:$rA, bb:$dest)>;
Scott Michela59d4692008-02-23 18:41:37 +00003758
Scott Michelf0569be2008-12-27 04:51:36 +00003759def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3760 (BRZr32 R32C:$rA, bb:$dest)>;
3761def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3762 (BRNZr32 R32C:$rA, bb:$dest)>;
Scott Michel66377522007-12-04 22:35:58 +00003763
Scott Michela59d4692008-02-23 18:41:37 +00003764multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3765{
3766 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3767 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michel053c1da2008-01-29 02:16:57 +00003768
Scott Michela59d4692008-02-23 18:41:37 +00003769 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3770 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3771
3772 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3773 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3774
3775 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3776 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3777}
3778
Scott Micheled741dd2009-01-05 01:34:35 +00003779defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3780defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003781
3782multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3783{
3784 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3785 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3786
3787 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3788 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3789
3790 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3791 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3792
3793 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3794 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3795}
3796
Scott Michelf0569be2008-12-27 04:51:36 +00003797defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3798defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003799
3800multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3801 SPUInstr orinst32, SPUInstr brinst32>
3802{
3803 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3804 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3805 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3806 bb:$dest)>;
3807
3808 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3809 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3810 (CEQHr16 R16C:$rA, R16:$rB)),
3811 bb:$dest)>;
3812
3813 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3814 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3815 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3816 bb:$dest)>;
3817
3818 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3819 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3820 (CEQr32 R32C:$rA, R32C:$rB)),
3821 bb:$dest)>;
3822}
3823
Scott Michelf0569be2008-12-27 04:51:36 +00003824defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3825defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003826
3827multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3828{
3829 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3830 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3831
3832 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3833 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3834
3835 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3836 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3837
3838 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3839 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3840}
3841
Scott Michelf0569be2008-12-27 04:51:36 +00003842defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3843defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
Scott Michela59d4692008-02-23 18:41:37 +00003844
3845multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3846 SPUInstr orinst32, SPUInstr brinst32>
3847{
3848 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3849 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3850 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3851 bb:$dest)>;
3852
3853 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3854 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3855 (CEQHr16 R16C:$rA, R16:$rB)),
3856 bb:$dest)>;
3857
3858 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3859 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3860 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3861 bb:$dest)>;
3862
3863 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3864 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3865 (CEQr32 R32C:$rA, R32C:$rB)),
3866 bb:$dest)>;
3867}
3868
Scott Michelf0569be2008-12-27 04:51:36 +00003869defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3870defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
Scott Michel053c1da2008-01-29 02:16:57 +00003871
Scott Michel66377522007-12-04 22:35:58 +00003872let isTerminator = 1, isBarrier = 1 in {
3873 let isReturn = 1 in {
3874 def RET:
3875 RETForm<"bi\t$$lr", [(retflag)]>;
3876 }
3877}
3878
3879//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00003880// Single precision floating point instructions
3881//===----------------------------------------------------------------------===//
3882
Scott Michelaedc6372008-12-10 00:15:19 +00003883class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3884 RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003885 SPrecFP, pattern>;
Scott Michelf0569be2008-12-27 04:51:36 +00003886
Scott Michelaedc6372008-12-10 00:15:19 +00003887class FAVecInst<ValueType vectype>:
3888 FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3889 [(set (vectype VECREG:$rT),
Scott Michel02d711b2008-12-30 23:28:25 +00003890 (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelf0569be2008-12-27 04:51:36 +00003891
Scott Michelaedc6372008-12-10 00:15:19 +00003892multiclass SFPAdd
3893{
3894 def v4f32: FAVecInst<v4f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003895 def f32: FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3896 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003897}
Scott Michel66377522007-12-04 22:35:58 +00003898
Scott Michelaedc6372008-12-10 00:15:19 +00003899defm FA : SFPAdd;
Scott Michel66377522007-12-04 22:35:58 +00003900
Scott Michelaedc6372008-12-10 00:15:19 +00003901class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3902 RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
Scott Michel02d711b2008-12-30 23:28:25 +00003903 SPrecFP, pattern>;
Scott Michel66377522007-12-04 22:35:58 +00003904
Scott Michelaedc6372008-12-10 00:15:19 +00003905class FSVecInst<ValueType vectype>:
3906 FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
Scott Michel02d711b2008-12-30 23:28:25 +00003907 [(set (vectype VECREG:$rT),
3908 (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003909
3910multiclass SFPSub
3911{
3912 def v4f32: FSVecInst<v4f32>;
Scott Michel02d711b2008-12-30 23:28:25 +00003913 def f32: FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3914 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
Scott Michelaedc6372008-12-10 00:15:19 +00003915}
3916
3917defm FS : SFPSub;
Scott Michel66377522007-12-04 22:35:58 +00003918
3919// Floating point reciprocal estimate
Scott Michel66377522007-12-04 22:35:58 +00003920
Scott Michel02d711b2008-12-30 23:28:25 +00003921class FRESTInst<dag OOL, dag IOL>:
3922 RRForm_1<0b00110111000, OOL, IOL,
3923 "frest\t$rT, $rA", SPrecFP,
3924 [/* no pattern */]>;
3925
3926def FRESTv4f32 :
3927 FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3928
3929def FRESTf32 :
3930 FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
Scott Michel66377522007-12-04 22:35:58 +00003931
3932// Floating point interpolate (used in conjunction with reciprocal estimate)
3933def FIv4f32 :
3934 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3935 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00003936 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003937
3938def FIf32 :
3939 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3940 "fi\t$rT, $rA, $rB", SPrecFP,
Scott Michel02d711b2008-12-30 23:28:25 +00003941 [/* no pattern */]>;
Scott Michel66377522007-12-04 22:35:58 +00003942
Scott Michel9c0c6b22008-11-21 02:56:16 +00003943//--------------------------------------------------------------------------
3944// Basic single precision floating point comparisons:
3945//
3946// Note: There is no support on SPU for single precision NaN. Consequently,
3947// ordered and unordered comparisons are the same.
3948//--------------------------------------------------------------------------
3949
Scott Michel66377522007-12-04 22:35:58 +00003950def FCEQf32 :
3951 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3952 "fceq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003953 [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3954
3955def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3956 (FCEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003957
3958def FCMEQf32 :
3959 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3960 "fcmeq\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003961 [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3962
3963def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3964 (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003965
3966def FCGTf32 :
3967 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3968 "fcgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003969 [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3970
3971def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3972 (FCGTf32 R32FP:$rA, R32FP:$rB)>;
Scott Michel66377522007-12-04 22:35:58 +00003973
3974def FCMGTf32 :
3975 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3976 "fcmgt\t$rT, $rA, $rB", SPrecFP,
Scott Michel9c0c6b22008-11-21 02:56:16 +00003977 [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3978
3979def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3980 (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3981
3982//--------------------------------------------------------------------------
3983// Single precision floating point comparisons and SETCC equivalents:
3984//--------------------------------------------------------------------------
3985
3986def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3987def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3988
3989def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3990def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3991
3992def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3993def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3994
3995def : Pat<(setule R32FP:$rA, R32FP:$rB),
3996 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3997def : Pat<(setole R32FP:$rA, R32FP:$rB),
3998 (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
Scott Michel66377522007-12-04 22:35:58 +00003999
4000// FP Status and Control Register Write
4001// Why isn't rT a don't care in the ISA?
4002// Should we create a special RRForm_3 for this guy and zero out the rT?
4003def FSCRWf32 :
4004 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
4005 "fscrwr\t$rA", SPrecFP,
4006 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
4007
4008// FP Status and Control Register Read
4009def FSCRRf32 :
4010 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
4011 "fscrrd\t$rT", SPrecFP,
4012 [/* This instruction requires an intrinsic */]>;
4013
4014// llvm instruction space
4015// How do these map onto cell instructions?
4016// fdiv rA rB
4017// frest rC rB # c = 1/b (both lines)
4018// fi rC rB rC
4019// fm rD rA rC # d = a * 1/b
4020// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4021// fma rB rB rC rD # b = b * c + d
4022// = -(d *b -a) * c + d
4023// = a * c - c ( a *b *c - a)
4024
4025// fcopysign (???)
4026
4027// Library calls:
4028// These llvm instructions will actually map to library calls.
4029// All that's needed, then, is to check that the appropriate library is
4030// imported and do a brsl to the proper function name.
4031// frem # fmod(x, y): x - (x/y) * y
4032// (Note: fmod(double, double), fmodf(float,float)
4033// fsqrt?
4034// fsin?
4035// fcos?
4036// Unimplemented SPU instruction space
4037// floating reciprocal absolute square root estimate (frsqest)
4038
4039// The following are probably just intrinsics
Scott Michelf0569be2008-12-27 04:51:36 +00004040// status and control register write
Scott Michel66377522007-12-04 22:35:58 +00004041// status and control register read
4042
4043//--------------------------------------
4044// Floating point multiply instructions
4045//--------------------------------------
4046
4047def FMv4f32:
4048 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4049 "fm\t$rT, $rA, $rB", SPrecFP,
4050 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
4051 (v4f32 VECREG:$rB)))]>;
4052
4053def FMf32 :
4054 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4055 "fm\t$rT, $rA, $rB", SPrecFP,
4056 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
4057
4058// Floating point multiply and add
4059// e.g. d = c + (a * b)
4060def FMAv4f32:
4061 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4062 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4063 [(set (v4f32 VECREG:$rT),
4064 (fadd (v4f32 VECREG:$rC),
4065 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4066
4067def FMAf32:
4068 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4069 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4070 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4071
4072// FP multiply and subtract
4073// Subtracts value in rC from product
4074// res = a * b - c
4075def FMSv4f32 :
4076 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4077 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4078 [(set (v4f32 VECREG:$rT),
4079 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4080 (v4f32 VECREG:$rC)))]>;
4081
4082def FMSf32 :
4083 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4084 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4085 [(set R32FP:$rT,
4086 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4087
4088// Floating Negative Mulitply and Subtract
4089// Subtracts product from value in rC
4090// res = fneg(fms a b c)
4091// = - (a * b - c)
4092// = c - a * b
4093// NOTE: subtraction order
4094// fsub a b = a - b
Scott Michelf0569be2008-12-27 04:51:36 +00004095// fs a b = b - a?
Scott Michel66377522007-12-04 22:35:58 +00004096def FNMSf32 :
4097 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4098 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4099 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4100
4101def FNMSv4f32 :
4102 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4103 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
Scott Michelf0569be2008-12-27 04:51:36 +00004104 [(set (v4f32 VECREG:$rT),
4105 (fsub (v4f32 VECREG:$rC),
4106 (fmul (v4f32 VECREG:$rA),
Scott Michel66377522007-12-04 22:35:58 +00004107 (v4f32 VECREG:$rB))))]>;
4108
4109//--------------------------------------
4110// Floating Point Conversions
4111// Signed conversions:
4112def CSiFv4f32:
4113 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4114 "csflt\t$rT, $rA, 0", SPrecFP,
4115 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4116
Scott Michelf0569be2008-12-27 04:51:36 +00004117// Convert signed integer to floating point
Scott Michel66377522007-12-04 22:35:58 +00004118def CSiFf32 :
4119 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4120 "csflt\t$rT, $rA, 0", SPrecFP,
4121 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4122
4123// Convert unsigned into to float
4124def CUiFv4f32 :
4125 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4126 "cuflt\t$rT, $rA, 0", SPrecFP,
4127 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4128
4129def CUiFf32 :
4130 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4131 "cuflt\t$rT, $rA, 0", SPrecFP,
4132 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4133
Scott Michelf0569be2008-12-27 04:51:36 +00004134// Convert float to unsigned int
Scott Michel66377522007-12-04 22:35:58 +00004135// Assume that scale = 0
4136
4137def CFUiv4f32 :
4138 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4139 "cfltu\t$rT, $rA, 0", SPrecFP,
4140 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4141
4142def CFUif32 :
4143 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4144 "cfltu\t$rT, $rA, 0", SPrecFP,
4145 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4146
Scott Michelf0569be2008-12-27 04:51:36 +00004147// Convert float to signed int
Scott Michel66377522007-12-04 22:35:58 +00004148// Assume that scale = 0
4149
4150def CFSiv4f32 :
4151 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4152 "cflts\t$rT, $rA, 0", SPrecFP,
4153 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4154
4155def CFSif32 :
4156 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4157 "cflts\t$rT, $rA, 0", SPrecFP,
4158 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4159
4160//===----------------------------------------------------------------------==//
4161// Single<->Double precision conversions
4162//===----------------------------------------------------------------------==//
4163
4164// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4165// v4f32, output is v2f64--which goes in the name?)
4166
4167// Floating point extend single to double
4168// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4169// operates on two double-word slots (i.e. 1st and 3rd fp numbers
4170// are ignored).
4171def FESDvec :
4172 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4173 "fesd\t$rT, $rA", SPrecFP,
Chris Lattnere9eda0f2010-03-19 04:53:47 +00004174 [/*(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))*/]>;
Scott Michel66377522007-12-04 22:35:58 +00004175
4176def FESDf32 :
4177 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4178 "fesd\t$rT, $rA", SPrecFP,
4179 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4180
4181// Floating point round double to single
4182//def FRDSvec :
4183// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4184// "frds\t$rT, $rA,", SPrecFP,
4185// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4186
4187def FRDSf64 :
4188 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4189 "frds\t$rT, $rA", SPrecFP,
4190 [(set R32FP:$rT, (fround R64FP:$rA))]>;
4191
4192//ToDo include anyextend?
4193
4194//===----------------------------------------------------------------------==//
4195// Double precision floating point instructions
4196//===----------------------------------------------------------------------==//
4197def FAf64 :
4198 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4199 "dfa\t$rT, $rA, $rB", DPrecFP,
4200 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4201
4202def FAv2f64 :
4203 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4204 "dfa\t$rT, $rA, $rB", DPrecFP,
4205 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4206
4207def FSf64 :
4208 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4209 "dfs\t$rT, $rA, $rB", DPrecFP,
4210 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4211
4212def FSv2f64 :
4213 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4214 "dfs\t$rT, $rA, $rB", DPrecFP,
4215 [(set (v2f64 VECREG:$rT),
4216 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4217
4218def FMf64 :
4219 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4220 "dfm\t$rT, $rA, $rB", DPrecFP,
4221 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4222
4223def FMv2f64:
4224 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4225 "dfm\t$rT, $rA, $rB", DPrecFP,
4226 [(set (v2f64 VECREG:$rT),
4227 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4228
4229def FMAf64:
4230 RRForm<0b00111010110, (outs R64FP:$rT),
4231 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4232 "dfma\t$rT, $rA, $rB", DPrecFP,
4233 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4234 RegConstraint<"$rC = $rT">,
4235 NoEncode<"$rC">;
4236
4237def FMAv2f64:
4238 RRForm<0b00111010110, (outs VECREG:$rT),
4239 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4240 "dfma\t$rT, $rA, $rB", DPrecFP,
4241 [(set (v2f64 VECREG:$rT),
4242 (fadd (v2f64 VECREG:$rC),
4243 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4244 RegConstraint<"$rC = $rT">,
4245 NoEncode<"$rC">;
4246
4247def FMSf64 :
4248 RRForm<0b10111010110, (outs R64FP:$rT),
4249 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4250 "dfms\t$rT, $rA, $rB", DPrecFP,
4251 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4252 RegConstraint<"$rC = $rT">,
4253 NoEncode<"$rC">;
4254
4255def FMSv2f64 :
4256 RRForm<0b10111010110, (outs VECREG:$rT),
4257 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4258 "dfms\t$rT, $rA, $rB", DPrecFP,
4259 [(set (v2f64 VECREG:$rT),
4260 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4261 (v2f64 VECREG:$rC)))]>;
4262
Scott Michel7ea02ff2009-03-17 01:15:45 +00004263// DFNMS: - (a * b - c)
Scott Michel66377522007-12-04 22:35:58 +00004264// - (a * b) + c => c - (a * b)
Scott Michel7ea02ff2009-03-17 01:15:45 +00004265
4266class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4267 RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4268 DPrecFP, pattern>,
Scott Michel66377522007-12-04 22:35:58 +00004269 RegConstraint<"$rC = $rT">,
4270 NoEncode<"$rC">;
4271
Scott Michel7ea02ff2009-03-17 01:15:45 +00004272class DFNMSVecInst<list<dag> pattern>:
4273 DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4274 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004275
Scott Michel7ea02ff2009-03-17 01:15:45 +00004276class DFNMSRegInst<list<dag> pattern>:
4277 DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4278 pattern>;
Scott Michel66377522007-12-04 22:35:58 +00004279
Scott Michel7ea02ff2009-03-17 01:15:45 +00004280multiclass DFMultiplySubtract
4281{
4282 def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT),
4283 (fsub (v2f64 VECREG:$rC),
4284 (fmul (v2f64 VECREG:$rA),
4285 (v2f64 VECREG:$rB))))]>;
4286
4287 def f64 : DFNMSRegInst<[(set R64FP:$rT,
4288 (fsub R64FP:$rC,
4289 (fmul R64FP:$rA, R64FP:$rB)))]>;
4290}
4291
4292defm DFNMS : DFMultiplySubtract;
Scott Michel66377522007-12-04 22:35:58 +00004293
4294// - (a * b + c)
4295// - (a * b) - c
4296def FNMAf64 :
4297 RRForm<0b11111010110, (outs R64FP:$rT),
4298 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4299 "dfnma\t$rT, $rA, $rB", DPrecFP,
4300 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4301 RegConstraint<"$rC = $rT">,
4302 NoEncode<"$rC">;
4303
4304def FNMAv2f64 :
4305 RRForm<0b11111010110, (outs VECREG:$rT),
4306 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4307 "dfnma\t$rT, $rA, $rB", DPrecFP,
Scott Michelf0569be2008-12-27 04:51:36 +00004308 [(set (v2f64 VECREG:$rT),
4309 (fneg (fadd (v2f64 VECREG:$rC),
4310 (fmul (v2f64 VECREG:$rA),
Scott Michel66377522007-12-04 22:35:58 +00004311 (v2f64 VECREG:$rB)))))]>,
4312 RegConstraint<"$rC = $rT">,
4313 NoEncode<"$rC">;
4314
4315//===----------------------------------------------------------------------==//
4316// Floating point negation and absolute value
4317//===----------------------------------------------------------------------==//
4318
4319def : Pat<(fneg (v4f32 VECREG:$rA)),
Scott Michela82d3f72009-03-17 16:45:16 +00004320 (XORfnegvec (v4f32 VECREG:$rA),
4321 (v4f32 (ILHUv4i32 0x8000)))>;
Scott Michel66377522007-12-04 22:35:58 +00004322
4323def : Pat<(fneg R32FP:$rA),
Scott Michela82d3f72009-03-17 16:45:16 +00004324 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
Scott Michel66377522007-12-04 22:35:58 +00004325
4326// Floating point absolute value
Scott Michel7ea02ff2009-03-17 01:15:45 +00004327// Note: f64 fabs is custom-selected.
Scott Michel66377522007-12-04 22:35:58 +00004328
4329def : Pat<(fabs R32FP:$rA),
4330 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4331
4332def : Pat<(fabs (v4f32 VECREG:$rA)),
4333 (ANDfabsvec (v4f32 VECREG:$rA),
Scott Michel7ea02ff2009-03-17 01:15:45 +00004334 (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
Scott Michelc9c8b2a2009-01-26 03:31:40 +00004335
Scott Michel66377522007-12-04 22:35:58 +00004336//===----------------------------------------------------------------------===//
Scott Michelaedc6372008-12-10 00:15:19 +00004337// Hint for branch instructions:
4338//===----------------------------------------------------------------------===//
4339
4340/* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4341
4342//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004343// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4344// in the odd pipeline)
4345//===----------------------------------------------------------------------===//
4346
Scott Michela59d4692008-02-23 18:41:37 +00004347def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004348 let Pattern = [];
4349
4350 let Inst{0-10} = 0b10000000010;
4351 let Inst{11-17} = 0;
4352 let Inst{18-24} = 0;
4353 let Inst{25-31} = 0;
4354}
4355
Scott Michela59d4692008-02-23 18:41:37 +00004356def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel66377522007-12-04 22:35:58 +00004357 let Pattern = [];
4358
4359 let Inst{0-10} = 0b10000000000;
4360 let Inst{11-17} = 0;
4361 let Inst{18-24} = 0;
4362 let Inst{25-31} = 0;
4363}
4364
4365//===----------------------------------------------------------------------===//
4366// Bit conversions (type conversions between vector/packed types)
Scott Michel6e1d1472009-03-16 18:47:25 +00004367// NOTE: Promotions are handled using the XS* instructions.
Scott Michel66377522007-12-04 22:35:58 +00004368//===----------------------------------------------------------------------===//
4369def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4370def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4371def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4372def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4373def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4374
4375def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4376def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4377def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4378def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4379def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4380
4381def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4382def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4383def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4384def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4385def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4386
4387def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4388def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4389def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4390def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4391def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4392
4393def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4394def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4395def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4396def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4397def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4398
4399def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4400def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4401def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4402def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
Chris Lattnere82f3362010-03-28 08:36:45 +00004403def : Pat<(v2f64 (bitconvert (v4f32 VECREG:$src))), (v2f64 VECREG:$src)>;
Scott Michel66377522007-12-04 22:35:58 +00004404
Scott Michel6e1d1472009-03-16 18:47:25 +00004405def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4406 (ORi128_vec VECREG:$src)>;
4407def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4408 (ORi128_vec VECREG:$src)>;
4409def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4410 (ORi128_vec VECREG:$src)>;
4411def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4412 (ORi128_vec VECREG:$src)>;
4413def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4414 (ORi128_vec VECREG:$src)>;
4415def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4416 (ORi128_vec VECREG:$src)>;
4417
4418def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4419 (v16i8 (ORvec_i128 GPRC:$src))>;
4420def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4421 (v8i16 (ORvec_i128 GPRC:$src))>;
4422def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4423 (v4i32 (ORvec_i128 GPRC:$src))>;
4424def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4425 (v2i64 (ORvec_i128 GPRC:$src))>;
4426def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4427 (v4f32 (ORvec_i128 GPRC:$src))>;
4428def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4429 (v2f64 (ORvec_i128 GPRC:$src))>;
Scott Michel66377522007-12-04 22:35:58 +00004430
4431//===----------------------------------------------------------------------===//
4432// Instruction patterns:
4433//===----------------------------------------------------------------------===//
4434
4435// General 32-bit constants:
4436def : Pat<(i32 imm:$imm),
4437 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4438
4439// Single precision float constants:
Nate Begemanccef5802008-02-14 18:43:04 +00004440def : Pat<(f32 fpimm:$imm),
Scott Michel66377522007-12-04 22:35:58 +00004441 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4442
4443// General constant 32-bit vectors
4444def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michelad2715e2008-03-05 23:02:02 +00004445 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4446 (LO16_vec v4i32Imm:$imm))>;
Scott Michelf0569be2008-12-27 04:51:36 +00004447
Scott Michel504c3692007-12-17 22:32:34 +00004448// 8-bit constants
4449def : Pat<(i8 imm:$imm),
4450 (ILHr8 imm:$imm)>;
Scott Michel66377522007-12-04 22:35:58 +00004451
4452//===----------------------------------------------------------------------===//
Scott Michel66377522007-12-04 22:35:58 +00004453// Zero/Any/Sign extensions
4454//===----------------------------------------------------------------------===//
4455
Scott Michel66377522007-12-04 22:35:58 +00004456// sext 8->32: Sign extend bytes to words
4457def : Pat<(sext_inreg R32C:$rSrc, i8),
4458 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4459
Scott Michel504c3692007-12-17 22:32:34 +00004460def : Pat<(i32 (sext R8C:$rSrc)),
4461 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4462
Scott Micheldd950092009-01-06 03:36:14 +00004463// sext 8->64: Sign extend bytes to double word
4464def : Pat<(sext_inreg R64C:$rSrc, i8),
4465 (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4466
4467def : Pat<(i64 (sext R8C:$rSrc)),
4468 (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4469
Scott Michel504c3692007-12-17 22:32:34 +00004470// zext 8->16: Zero extend bytes to halfwords
4471def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004472 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004473
Scott Michel504c3692007-12-17 22:32:34 +00004474// zext 8->32: Zero extend bytes to words
4475def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004476 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel504c3692007-12-17 22:32:34 +00004477
Scott Micheldd950092009-01-06 03:36:14 +00004478// zext 8->64: Zero extend bytes to double words
4479def : Pat<(i64 (zext R8C:$rSrc)),
4480 (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4481 (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4482 0x4),
4483 (ILv4i32 0x0),
4484 (FSMBIv4i32 0x0f0f)))>;
4485
4486// anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004487def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004488 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004489
Scott Micheldd950092009-01-06 03:36:14 +00004490// anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
Scott Michel504c3692007-12-17 22:32:34 +00004491def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004492 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel504c3692007-12-17 22:32:34 +00004493
Scott Micheldd950092009-01-06 03:36:14 +00004494// sext 16->64: Sign extend halfword to double word
4495def : Pat<(sext_inreg R64C:$rSrc, i16),
4496 (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4497
4498def : Pat<(sext R16C:$rSrc),
4499 (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4500
Scott Michela59d4692008-02-23 18:41:37 +00004501// zext 16->32: Zero extend halfwords to words
Scott Michel66377522007-12-04 22:35:58 +00004502def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004503 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel66377522007-12-04 22:35:58 +00004504
4505def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michela59d4692008-02-23 18:41:37 +00004506 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel66377522007-12-04 22:35:58 +00004507
4508def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michela59d4692008-02-23 18:41:37 +00004509 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel66377522007-12-04 22:35:58 +00004510
4511def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michela59d4692008-02-23 18:41:37 +00004512 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel66377522007-12-04 22:35:58 +00004513
4514// anyext 16->32: Extend 16->32 bits, irrespective of sign
4515def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michela59d4692008-02-23 18:41:37 +00004516 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel66377522007-12-04 22:35:58 +00004517
4518//===----------------------------------------------------------------------===//
Scott Michelf0569be2008-12-27 04:51:36 +00004519// Truncates:
4520// These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4521// above are custom lowered.
4522//===----------------------------------------------------------------------===//
4523
4524def : Pat<(i8 (trunc GPRC:$src)),
4525 (ORi8_v16i8
4526 (SHUFBgprc GPRC:$src, GPRC:$src,
4527 (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4528
4529def : Pat<(i8 (trunc R64C:$src)),
4530 (ORi8_v16i8
4531 (SHUFBv2i64_m32
4532 (ORv2i64_i64 R64C:$src),
4533 (ORv2i64_i64 R64C:$src),
4534 (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4535
4536def : Pat<(i8 (trunc R32C:$src)),
4537 (ORi8_v16i8
4538 (SHUFBv4i32_m32
4539 (ORv4i32_i32 R32C:$src),
4540 (ORv4i32_i32 R32C:$src),
4541 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4542
4543def : Pat<(i8 (trunc R16C:$src)),
4544 (ORi8_v16i8
4545 (SHUFBv4i32_m32
4546 (ORv8i16_i16 R16C:$src),
4547 (ORv8i16_i16 R16C:$src),
4548 (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4549
4550def : Pat<(i16 (trunc GPRC:$src)),
4551 (ORi16_v8i16
4552 (SHUFBgprc GPRC:$src, GPRC:$src,
4553 (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4554
4555def : Pat<(i16 (trunc R64C:$src)),
4556 (ORi16_v8i16
4557 (SHUFBv2i64_m32
4558 (ORv2i64_i64 R64C:$src),
4559 (ORv2i64_i64 R64C:$src),
4560 (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4561
4562def : Pat<(i16 (trunc R32C:$src)),
4563 (ORi16_v8i16
4564 (SHUFBv4i32_m32
4565 (ORv4i32_i32 R32C:$src),
4566 (ORv4i32_i32 R32C:$src),
4567 (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4568
4569def : Pat<(i32 (trunc GPRC:$src)),
4570 (ORi32_v4i32
4571 (SHUFBgprc GPRC:$src, GPRC:$src,
4572 (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4573
4574def : Pat<(i32 (trunc R64C:$src)),
4575 (ORi32_v4i32
4576 (SHUFBv2i64_m32
4577 (ORv2i64_i64 R64C:$src),
4578 (ORv2i64_i64 R64C:$src),
4579 (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4580
4581//===----------------------------------------------------------------------===//
Scott Michel053c1da2008-01-29 02:16:57 +00004582// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel66377522007-12-04 22:35:58 +00004583// low parts in order to load them into a register.
4584//===----------------------------------------------------------------------===//
4585
Scott Michel053c1da2008-01-29 02:16:57 +00004586def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
4587def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4588def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
4589def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
4590
4591def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4592 (SPUlo tglobaladdr:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004593 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004594
Scott Michel053c1da2008-01-29 02:16:57 +00004595def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4596 (SPUlo texternalsym:$in, 0)),
4597 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4598
4599def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4600 (SPUlo tjumptable:$in, 0)),
Scott Michel9de5d0d2008-01-11 02:53:15 +00004601 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel58c58182008-01-17 20:38:41 +00004602
Scott Michel053c1da2008-01-29 02:16:57 +00004603def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4604 (SPUlo tconstpool:$in, 0)),
4605 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4606
4607def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4608 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4609
4610def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4611 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4612
4613def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4614 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4615
4616def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4617 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel66377522007-12-04 22:35:58 +00004618
Scott Michel6e1d1472009-03-16 18:47:25 +00004619// Intrinsics:
Scott Michel66377522007-12-04 22:35:58 +00004620include "CellSDKIntrinsics.td"
Scott Michel02d711b2008-12-30 23:28:25 +00004621// Various math operator instruction sequences
4622include "SPUMathInstr.td"
Scott Michelf0569be2008-12-27 04:51:36 +00004623// 64-bit "instructions"/support
4624include "SPU64InstrInfo.td"
Scott Micheldd950092009-01-06 03:36:14 +00004625// 128-bit "instructions"/support
4626include "SPU128InstrInfo.td"