blob: 8e1933c8ba0256a1138726a334204836807349c2 [file] [log] [blame]
Scott Michel8b6b4202007-12-04 22:35:58 +00001//==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-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 Michel8b6b4202007-12-04 22:35:58 +00007//
8//===----------------------------------------------------------------------===//
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 Michelbc5fbc12008-04-30 00:30:08 +000025 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000026 "${:comment} ADJCALLSTACKDOWN",
27 [(callseq_start imm:$amt)]>;
Scott Michelbc5fbc12008-04-30 00:30:08 +000028 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm_i32:$amt),
Scott Michel8b6b4202007-12-04 22:35:58 +000029 "${:comment} ADJCALLSTACKUP",
30 [(callseq_end imm:$amt)]>;
31}
32
33//===----------------------------------------------------------------------===//
34// DWARF debugging Pseudo Instructions
35//===----------------------------------------------------------------------===//
36
37def DWARF_LOC : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38 "${:comment} .loc $file, $line, $col",
39 [(dwarf_loc (i32 imm:$line), (i32 imm:$col),
40 (i32 imm:$file))]>;
41
42//===----------------------------------------------------------------------===//
43// Loads:
44// NB: The ordering is actually important, since the instruction selection
45// will try each of the instructions in sequence, i.e., the D-form first with
46// the 10-bit displacement, then the A-form with the 16 bit displacement, and
47// finally the X-form with the register-register.
48//===----------------------------------------------------------------------===//
49
Chris Lattner1a1932c2008-01-06 23:38:27 +000050let isSimpleLoad = 1 in {
Scott Michelf9f42e62008-01-29 02:16:57 +000051 class LoadDFormVec<ValueType vectype>
52 : RI10Form<0b00101100, (outs VECREG:$rT), (ins memri10:$src),
53 "lqd\t$rT, $src",
54 LoadStore,
55 [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
56 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000057
Scott Michelf9f42e62008-01-29 02:16:57 +000058 class LoadDForm<RegisterClass rclass>
59 : RI10Form<0b00101100, (outs rclass:$rT), (ins memri10:$src),
60 "lqd\t$rT, $src",
61 LoadStore,
62 [(set rclass:$rT, (load dform_addr:$src))]>
63 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000064
Scott Michelf9f42e62008-01-29 02:16:57 +000065 multiclass LoadDForms
66 {
67 def v16i8: LoadDFormVec<v16i8>;
68 def v8i16: LoadDFormVec<v8i16>;
69 def v4i32: LoadDFormVec<v4i32>;
70 def v2i64: LoadDFormVec<v2i64>;
71 def v4f32: LoadDFormVec<v4f32>;
72 def v2f64: LoadDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +000073
Scott Michelf9f42e62008-01-29 02:16:57 +000074 def r128: LoadDForm<GPRC>;
75 def r64: LoadDForm<R64C>;
76 def r32: LoadDForm<R32C>;
77 def f32: LoadDForm<R32FP>;
78 def f64: LoadDForm<R64FP>;
79 def r16: LoadDForm<R16C>;
80 def r8: LoadDForm<R8C>;
81 }
Scott Michel8b6b4202007-12-04 22:35:58 +000082
Scott Michelf9f42e62008-01-29 02:16:57 +000083 class LoadAFormVec<ValueType vectype>
84 : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
85 "lqa\t$rT, $src",
86 LoadStore,
87 [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
88 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000089
Scott Michelf9f42e62008-01-29 02:16:57 +000090 class LoadAForm<RegisterClass rclass>
91 : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
92 "lqa\t$rT, $src",
93 LoadStore,
94 [(set rclass:$rT, (load aform_addr:$src))]>
95 { }
Scott Michel8b6b4202007-12-04 22:35:58 +000096
Scott Michelf9f42e62008-01-29 02:16:57 +000097 multiclass LoadAForms
98 {
99 def v16i8: LoadAFormVec<v16i8>;
100 def v8i16: LoadAFormVec<v8i16>;
101 def v4i32: LoadAFormVec<v4i32>;
102 def v2i64: LoadAFormVec<v2i64>;
103 def v4f32: LoadAFormVec<v4f32>;
104 def v2f64: LoadAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000105
Scott Michelf9f42e62008-01-29 02:16:57 +0000106 def r128: LoadAForm<GPRC>;
107 def r64: LoadAForm<R64C>;
108 def r32: LoadAForm<R32C>;
109 def f32: LoadAForm<R32FP>;
110 def f64: LoadAForm<R64FP>;
111 def r16: LoadAForm<R16C>;
112 def r8: LoadAForm<R8C>;
113 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000114
Scott Michelf9f42e62008-01-29 02:16:57 +0000115 class LoadXFormVec<ValueType vectype>
116 : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
117 "lqx\t$rT, $src",
118 LoadStore,
119 [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
120 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000121
Scott Michelf9f42e62008-01-29 02:16:57 +0000122 class LoadXForm<RegisterClass rclass>
123 : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
124 "lqx\t$rT, $src",
125 LoadStore,
126 [(set rclass:$rT, (load xform_addr:$src))]>
127 { }
Scott Michel8b6b4202007-12-04 22:35:58 +0000128
Scott Michelf9f42e62008-01-29 02:16:57 +0000129 multiclass LoadXForms
130 {
131 def v16i8: LoadXFormVec<v16i8>;
132 def v8i16: LoadXFormVec<v8i16>;
133 def v4i32: LoadXFormVec<v4i32>;
134 def v2i64: LoadXFormVec<v2i64>;
135 def v4f32: LoadXFormVec<v4f32>;
136 def v2f64: LoadXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000137
Scott Michelf9f42e62008-01-29 02:16:57 +0000138 def r128: LoadXForm<GPRC>;
139 def r64: LoadXForm<R64C>;
140 def r32: LoadXForm<R32C>;
141 def f32: LoadXForm<R32FP>;
142 def f64: LoadXForm<R64FP>;
143 def r16: LoadXForm<R16C>;
144 def r8: LoadXForm<R8C>;
145 }
Scott Michel8b6b4202007-12-04 22:35:58 +0000146
Scott Michelf9f42e62008-01-29 02:16:57 +0000147 defm LQA : LoadAForms;
148 defm LQD : LoadDForms;
149 defm LQX : LoadXForms;
Scott Michel438be252007-12-17 22:32:34 +0000150
Scott Michel8b6b4202007-12-04 22:35:58 +0000151/* Load quadword, PC relative: Not much use at this point in time.
Scott Michelf9f42e62008-01-29 02:16:57 +0000152 Might be of use later for relocatable code. It's effectively the
153 same as LQA, but uses PC-relative addressing.
Scott Michel8b6b4202007-12-04 22:35:58 +0000154 def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
155 "lqr\t$rT, $disp", LoadStore,
156 [(set VECREG:$rT, (load iaddr:$disp))]>;
157 */
Scott Michel8b6b4202007-12-04 22:35:58 +0000158}
159
160//===----------------------------------------------------------------------===//
161// Stores:
162//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +0000163class StoreDFormVec<ValueType vectype>
164 : RI10Form<0b00100100, (outs), (ins VECREG:$rT, memri10:$src),
165 "stqd\t$rT, $src",
166 LoadStore,
167 [(store (vectype VECREG:$rT), dform_addr:$src)]>
168{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000169
Scott Michelf9f42e62008-01-29 02:16:57 +0000170class StoreDForm<RegisterClass rclass>
171 : RI10Form<0b00100100, (outs), (ins rclass:$rT, memri10:$src),
172 "stqd\t$rT, $src",
173 LoadStore,
174 [(store rclass:$rT, dform_addr:$src)]>
175{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000176
Scott Michelf9f42e62008-01-29 02:16:57 +0000177multiclass StoreDForms
178{
179 def v16i8: StoreDFormVec<v16i8>;
180 def v8i16: StoreDFormVec<v8i16>;
181 def v4i32: StoreDFormVec<v4i32>;
182 def v2i64: StoreDFormVec<v2i64>;
183 def v4f32: StoreDFormVec<v4f32>;
184 def v2f64: StoreDFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000185
Scott Michelf9f42e62008-01-29 02:16:57 +0000186 def r128: StoreDForm<GPRC>;
187 def r64: StoreDForm<R64C>;
188 def r32: StoreDForm<R32C>;
189 def f32: StoreDForm<R32FP>;
190 def f64: StoreDForm<R64FP>;
191 def r16: StoreDForm<R16C>;
192 def r8: StoreDForm<R8C>;
193}
Scott Michel8b6b4202007-12-04 22:35:58 +0000194
Scott Michelf9f42e62008-01-29 02:16:57 +0000195class StoreAFormVec<ValueType vectype>
196 : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000197 "stqa\t$rT, $src",
198 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000199 [(store (vectype VECREG:$rT), aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000200
Scott Michelf9f42e62008-01-29 02:16:57 +0000201class StoreAForm<RegisterClass rclass>
202 : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000203 "stqa\t$rT, $src",
204 LoadStore,
Scott Michel6baba072008-03-05 23:02:02 +0000205 [(store rclass:$rT, aform_addr:$src)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000206
Scott Michelf9f42e62008-01-29 02:16:57 +0000207multiclass StoreAForms
208{
209 def v16i8: StoreAFormVec<v16i8>;
210 def v8i16: StoreAFormVec<v8i16>;
211 def v4i32: StoreAFormVec<v4i32>;
212 def v2i64: StoreAFormVec<v2i64>;
213 def v4f32: StoreAFormVec<v4f32>;
214 def v2f64: StoreAFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000215
Scott Michelf9f42e62008-01-29 02:16:57 +0000216 def r128: StoreAForm<GPRC>;
217 def r64: StoreAForm<R64C>;
218 def r32: StoreAForm<R32C>;
219 def f32: StoreAForm<R32FP>;
220 def f64: StoreAForm<R64FP>;
221 def r16: StoreAForm<R16C>;
222 def r8: StoreAForm<R8C>;
223}
Scott Michel8b6b4202007-12-04 22:35:58 +0000224
Scott Michelf9f42e62008-01-29 02:16:57 +0000225class StoreXFormVec<ValueType vectype>
226 : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000227 "stqx\t$rT, $src",
228 LoadStore,
229 [(store (vectype VECREG:$rT), xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000230{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000231
Scott Michelf9f42e62008-01-29 02:16:57 +0000232class StoreXForm<RegisterClass rclass>
233 : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
Scott Michel5a6f17b2008-01-30 02:55:46 +0000234 "stqx\t$rT, $src",
235 LoadStore,
236 [(store rclass:$rT, xform_addr:$src)]>
Scott Michelf9f42e62008-01-29 02:16:57 +0000237{ }
Scott Michel8b6b4202007-12-04 22:35:58 +0000238
Scott Michelf9f42e62008-01-29 02:16:57 +0000239multiclass StoreXForms
240{
241 def v16i8: StoreXFormVec<v16i8>;
242 def v8i16: StoreXFormVec<v8i16>;
243 def v4i32: StoreXFormVec<v4i32>;
244 def v2i64: StoreXFormVec<v2i64>;
245 def v4f32: StoreXFormVec<v4f32>;
246 def v2f64: StoreXFormVec<v2f64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000247
Scott Michelf9f42e62008-01-29 02:16:57 +0000248 def r128: StoreXForm<GPRC>;
249 def r64: StoreXForm<R64C>;
250 def r32: StoreXForm<R32C>;
251 def f32: StoreXForm<R32FP>;
252 def f64: StoreXForm<R64FP>;
253 def r16: StoreXForm<R16C>;
254 def r8: StoreXForm<R8C>;
255}
Scott Michel8b6b4202007-12-04 22:35:58 +0000256
Scott Michelf9f42e62008-01-29 02:16:57 +0000257defm STQD : StoreDForms;
258defm STQA : StoreAForms;
259defm STQX : StoreXForms;
Scott Michel8b6b4202007-12-04 22:35:58 +0000260
261/* Store quadword, PC relative: Not much use at this point in time. Might
Scott Michelf9f42e62008-01-29 02:16:57 +0000262 be useful for relocatable code.
Chris Lattneref8d6082008-01-06 06:44:58 +0000263def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
264 "stqr\t$rT, $disp", LoadStore,
265 [(store VECREG:$rT, iaddr:$disp)]>;
266*/
Scott Michel8b6b4202007-12-04 22:35:58 +0000267
268//===----------------------------------------------------------------------===//
269// Generate Controls for Insertion:
270//===----------------------------------------------------------------------===//
271
272def CBD :
273 RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
274 "cbd\t$rT, $src", ShuffleOp,
275 [(set (v16i8 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
276
277def CBX : RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
278 "cbx\t$rT, $src", ShuffleOp,
279 [(set (v16i8 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
280
281def CHD : RI7Form<0b10101111100, (outs VECREG:$rT), (ins memri7:$src),
282 "chd\t$rT, $src", ShuffleOp,
283 [(set (v8i16 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
284
285def CHX : RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
286 "chx\t$rT, $src", ShuffleOp,
287 [(set (v8i16 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
288
289def CWD : RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
290 "cwd\t$rT, $src", ShuffleOp,
291 [(set (v4i32 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
292
Scott Michelbc5fbc12008-04-30 00:30:08 +0000293def CWDf32 : RI7Form<0b01101111100, (outs VECREG:$rT), (ins memri7:$src),
294 "cwd\t$rT, $src", ShuffleOp,
295 [(set (v4f32 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
296
Scott Michel8b6b4202007-12-04 22:35:58 +0000297def CWX : RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
298 "cwx\t$rT, $src", ShuffleOp,
299 [(set (v4i32 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
300
Scott Michelbc5fbc12008-04-30 00:30:08 +0000301def CWXf32 : RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
302 "cwx\t$rT, $src", ShuffleOp,
303 [(set (v4f32 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
304
Scott Michel8b6b4202007-12-04 22:35:58 +0000305def CDD : RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
306 "cdd\t$rT, $src", ShuffleOp,
307 [(set (v2i64 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
308
Scott Michelbc5fbc12008-04-30 00:30:08 +0000309def CDDf64 : RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
310 "cdd\t$rT, $src", ShuffleOp,
311 [(set (v2f64 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
312
Scott Michel8b6b4202007-12-04 22:35:58 +0000313def CDX : RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
314 "cdx\t$rT, $src", ShuffleOp,
315 [(set (v2i64 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
316
Scott Michelbc5fbc12008-04-30 00:30:08 +0000317def CDXf64 : RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
318 "cdx\t$rT, $src", ShuffleOp,
319 [(set (v2f64 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
320
Scott Michel8b6b4202007-12-04 22:35:58 +0000321//===----------------------------------------------------------------------===//
322// Constant formation:
323//===----------------------------------------------------------------------===//
324
325def ILHv8i16:
326 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
327 "ilh\t$rT, $val", ImmLoad,
328 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
329
330def ILHr16:
331 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
332 "ilh\t$rT, $val", ImmLoad,
333 [(set R16C:$rT, immSExt16:$val)]>;
334
Scott Michel438be252007-12-17 22:32:34 +0000335// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
336// the right constant")
337def ILHr8:
338 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
339 "ilh\t$rT, $val", ImmLoad,
340 [(set R8C:$rT, immSExt8:$val)]>;
341
Scott Michel8b6b4202007-12-04 22:35:58 +0000342// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000343
Scott Michel6baba072008-03-05 23:02:02 +0000344class ILInst<dag OOL, dag IOL, list<dag> pattern>:
345 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
346 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000347
Scott Michel6baba072008-03-05 23:02:02 +0000348class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
349 ILInst<(outs VECREG:$rT), (ins immtype:$val),
350 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000351
Scott Michel6baba072008-03-05 23:02:02 +0000352class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
353 ILInst<(outs rclass:$rT), (ins immtype:$val),
354 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000355
Scott Michel6baba072008-03-05 23:02:02 +0000356multiclass ImmediateLoad
357{
358 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
359 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000360
Scott Michel6baba072008-03-05 23:02:02 +0000361 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000362
Scott Michel6baba072008-03-05 23:02:02 +0000363 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
364 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
365 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
366 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
367}
Scott Michel8b6b4202007-12-04 22:35:58 +0000368
Scott Michel6baba072008-03-05 23:02:02 +0000369defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000370
Scott Michel6baba072008-03-05 23:02:02 +0000371class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
372 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
373 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000374
Scott Michel6baba072008-03-05 23:02:02 +0000375class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
376 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
377 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
378
379class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
380 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
381 [(set rclass:$rT, xform:$val)]>;
382
383multiclass ImmLoadHalfwordUpper
384{
385 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000386 def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
Scott Michel6baba072008-03-05 23:02:02 +0000387
388 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000389 def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
Scott Michel6baba072008-03-05 23:02:02 +0000390
391 // Loads the high portion of an address
392 def hi: ILHURegInst<R32C, symbolHi, hi16>;
393
394 // Used in custom lowering constant SFP loads:
395 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
396}
397
398defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000399
400// Immediate load address (can also be used to load 18-bit unsigned constants,
401// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000402
Scott Michel97872d32008-02-23 18:41:37 +0000403class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
404 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
405 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000406
Scott Michel6baba072008-03-05 23:02:02 +0000407class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
408 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
409 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
410
411class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
412 ILAInst<(outs rclass:$rT), (ins immtype:$val),
413 [(set rclass:$rT, xform:$val)]>;
414
Scott Michel97872d32008-02-23 18:41:37 +0000415multiclass ImmLoadAddress
416{
Scott Michel6baba072008-03-05 23:02:02 +0000417 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
418 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000419
Scott Michel6baba072008-03-05 23:02:02 +0000420 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
421 def r32: ILARegInst<R32C, u18imm, imm18>;
422 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
423 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000424
Scott Michel6baba072008-03-05 23:02:02 +0000425 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000426
Scott Michel97872d32008-02-23 18:41:37 +0000427 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
428 [/* no pattern */]>;
429}
430
431defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000432
433// Immediate OR, Halfword Lower: The "other" part of loading large constants
434// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
435// Note that these are really two operand instructions, but they're encoded
436// as three operands with the first two arguments tied-to each other.
437
Scott Michel6baba072008-03-05 23:02:02 +0000438class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
439 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
440 ImmLoad, pattern>,
441 RegConstraint<"$rS = $rT">,
442 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000443
Scott Michel6baba072008-03-05 23:02:02 +0000444class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
445 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
446 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000447
Scott Michel6baba072008-03-05 23:02:02 +0000448class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
449 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
450 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000451
Scott Michel6baba072008-03-05 23:02:02 +0000452multiclass ImmOrHalfwordLower
453{
454 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
Scott Michelbc5fbc12008-04-30 00:30:08 +0000455 def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
Scott Michel6baba072008-03-05 23:02:02 +0000456
457 def r32: IOHLRegInst<R32C, i32imm>;
458 def f32: IOHLRegInst<R32FP, f32imm>;
459
460 def lo: IOHLRegInst<R32C, symbolLo>;
461}
462
463defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000464
Scott Michel8b6b4202007-12-04 22:35:58 +0000465// Form select mask for bytes using immediate, used in conjunction with the
466// SELB instruction:
467
Scott Michel6baba072008-03-05 23:02:02 +0000468class FSMBIVec<ValueType vectype>:
469 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
470 "fsmbi\t$rT, $val",
471 SelectOp,
Scott Michelbc5fbc12008-04-30 00:30:08 +0000472 [(set (vectype VECREG:$rT), (SPUfsmbi (i16 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000473
Scott Michel97872d32008-02-23 18:41:37 +0000474multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000475{
476 def v16i8: FSMBIVec<v16i8>;
477 def v8i16: FSMBIVec<v8i16>;
478 def v4i32: FSMBIVec<v4i32>;
479 def v2i64: FSMBIVec<v2i64>;
480}
Scott Michel8b6b4202007-12-04 22:35:58 +0000481
Scott Michel97872d32008-02-23 18:41:37 +0000482defm FSMBI : FormSelectMaskBytesImm;
483
484// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
485def FSMB:
486 RRForm_1<0b01101101100, (outs VECREG:$rT), (ins R16C:$rA),
Scott Michel6baba072008-03-05 23:02:02 +0000487 "fsmb\t$rT, $rA", SelectOp,
488 [(set (v16i8 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000489
490// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
491// only 8-bits wide (even though it's input as 16-bits here)
492def FSMH:
493 RRForm_1<0b10101101100, (outs VECREG:$rT), (ins R16C:$rA),
494 "fsmh\t$rT, $rA", SelectOp,
Scott Michel6baba072008-03-05 23:02:02 +0000495 [(set (v8i16 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000496
497// fsm: Form select mask for words. Like the other fsm* instructions,
498// only the lower 4 bits of $rA are significant.
499def FSM:
500 RRForm_1<0b00101101100, (outs VECREG:$rT), (ins R16C:$rA),
501 "fsm\t$rT, $rA", SelectOp,
Scott Michel6baba072008-03-05 23:02:02 +0000502 [(set (v4i32 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000503
504//===----------------------------------------------------------------------===//
505// Integer and Logical Operations:
506//===----------------------------------------------------------------------===//
507
508def AHv8i16:
509 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
510 "ah\t$rT, $rA, $rB", IntegerOp,
511 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
512
513def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
514 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
515
Scott Michel8b6b4202007-12-04 22:35:58 +0000516def AHr16:
517 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
518 "ah\t$rT, $rA, $rB", IntegerOp,
519 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
520
521def AHIvec:
522 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
523 "ahi\t$rT, $rA, $val", IntegerOp,
524 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
525 v8i16SExt10Imm:$val))]>;
526
Scott Michel97872d32008-02-23 18:41:37 +0000527def AHIr16:
528 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
529 "ahi\t$rT, $rA, $val", IntegerOp,
530 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000531
Scott Michel97872d32008-02-23 18:41:37 +0000532def Avec:
533 RRForm<0b00000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
534 "a\t$rT, $rA, $rB", IntegerOp,
535 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000536
537def : Pat<(add (v16i8 VECREG:$rA), (v16i8 VECREG:$rB)),
538 (Avec VECREG:$rA, VECREG:$rB)>;
539
Scott Michel97872d32008-02-23 18:41:37 +0000540def Ar32:
541 RRForm<0b00000011000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
542 "a\t$rT, $rA, $rB", IntegerOp,
543 [(set R32C:$rT, (add R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000544
Scott Michel438be252007-12-17 22:32:34 +0000545def Ar8:
546 RRForm<0b00000011000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
547 "a\t$rT, $rA, $rB", IntegerOp,
548 [(set R8C:$rT, (add R8C:$rA, R8C:$rB))]>;
549
Scott Michel8b6b4202007-12-04 22:35:58 +0000550def AIvec:
551 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
552 "ai\t$rT, $rA, $val", IntegerOp,
553 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
554 v4i32SExt10Imm:$val))]>;
555
Scott Michel438be252007-12-17 22:32:34 +0000556def AIr32:
557 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
558 "ai\t$rT, $rA, $val", IntegerOp,
559 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000560
Scott Michel438be252007-12-17 22:32:34 +0000561def SFHvec:
562 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
563 "sfh\t$rT, $rA, $rB", IntegerOp,
564 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
565 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000566
Scott Michel438be252007-12-17 22:32:34 +0000567def SFHr16:
568 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
569 "sfh\t$rT, $rA, $rB", IntegerOp,
570 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000571
572def SFHIvec:
573 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
574 "sfhi\t$rT, $rA, $val", IntegerOp,
575 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
576 (v8i16 VECREG:$rA)))]>;
577
578def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
579 "sfhi\t$rT, $rA, $val", IntegerOp,
580 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
581
582def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
583 (ins VECREG:$rA, VECREG:$rB),
584 "sf\t$rT, $rA, $rB", IntegerOp,
585 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
586
587def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
588 "sf\t$rT, $rA, $rB", IntegerOp,
589 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
590
591def SFIvec:
592 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
593 "sfi\t$rT, $rA, $val", IntegerOp,
594 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
595 (v4i32 VECREG:$rA)))]>;
596
597def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
598 (ins R32C:$rA, s10imm_i32:$val),
599 "sfi\t$rT, $rA, $val", IntegerOp,
600 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
601
602// ADDX: only available in vector form, doesn't match a pattern.
603def ADDXvec:
604 RRForm<0b00000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
605 VECREG:$rCarry),
606 "addx\t$rT, $rA, $rB", IntegerOp,
607 []>,
608 RegConstraint<"$rCarry = $rT">,
609 NoEncode<"$rCarry">;
610
611// CG: only available in vector form, doesn't match a pattern.
612def CGvec:
613 RRForm<0b01000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
614 VECREG:$rCarry),
615 "cg\t$rT, $rA, $rB", IntegerOp,
616 []>,
617 RegConstraint<"$rCarry = $rT">,
618 NoEncode<"$rCarry">;
619
620// SFX: only available in vector form, doesn't match a pattern
621def SFXvec:
622 RRForm<0b10000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
623 VECREG:$rCarry),
624 "sfx\t$rT, $rA, $rB", IntegerOp,
625 []>,
626 RegConstraint<"$rCarry = $rT">,
627 NoEncode<"$rCarry">;
628
629// BG: only available in vector form, doesn't match a pattern.
630def BGvec:
631 RRForm<0b01000010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
632 VECREG:$rCarry),
633 "bg\t$rT, $rA, $rB", IntegerOp,
634 []>,
635 RegConstraint<"$rCarry = $rT">,
636 NoEncode<"$rCarry">;
637
638// BGX: only available in vector form, doesn't match a pattern.
639def BGXvec:
640 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
641 VECREG:$rCarry),
642 "bgx\t$rT, $rA, $rB", IntegerOp,
643 []>,
644 RegConstraint<"$rCarry = $rT">,
645 NoEncode<"$rCarry">;
646
647// Halfword multiply variants:
648// N.B: These can be used to build up larger quantities (16x16 -> 32)
649
650def MPYv8i16:
651 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
652 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
653 [(set (v8i16 VECREG:$rT), (SPUmpy_v8i16 (v8i16 VECREG:$rA),
654 (v8i16 VECREG:$rB)))]>;
655
656def MPYr16:
657 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
658 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
659 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
660
661def MPYUv4i32:
662 RRForm<0b00110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
663 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
664 [(set (v4i32 VECREG:$rT),
665 (SPUmpyu_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
666
667def MPYUr16:
668 RRForm<0b00110011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
669 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
670 [(set R32C:$rT, (mul (zext R16C:$rA),
671 (zext R16C:$rB)))]>;
672
673def MPYUr32:
674 RRForm<0b00110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
675 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
676 [(set R32C:$rT, (SPUmpyu_i32 R32C:$rA, R32C:$rB))]>;
677
678// mpyi: multiply 16 x s10imm -> 32 result (custom lowering for 32 bit result,
679// this only produces the lower 16 bits)
680def MPYIvec:
681 RI10Form<0b00101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
682 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
683 [(set (v8i16 VECREG:$rT), (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
684
685def MPYIr16:
686 RI10Form<0b00101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
687 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
688 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
689
690// mpyui: same issues as other multiplies, plus, this doesn't match a
691// pattern... but may be used during target DAG selection or lowering
692def MPYUIvec:
693 RI10Form<0b10101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
694 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
695 []>;
696
697def MPYUIr16:
698 RI10Form<0b10101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
699 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
700 []>;
701
702// mpya: 16 x 16 + 16 -> 32 bit result
703def MPYAvec:
704 RRRForm<0b0011, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
705 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
706 [(set (v4i32 VECREG:$rT), (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
707 (v8i16 VECREG:$rB)))),
708 (v4i32 VECREG:$rC)))]>;
709
710def MPYAr32:
711 RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
712 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
713 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
714 R32C:$rC))]>;
715
716def : Pat<(add (mul (sext R16C:$rA), (sext R16C:$rB)), R32C:$rC),
717 (MPYAr32 R16C:$rA, R16C:$rB, R32C:$rC)>;
718
719def MPYAr32_sextinreg:
720 RRRForm<0b0011, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
721 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
722 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
723 (sext_inreg R32C:$rB, i16)),
724 R32C:$rC))]>;
725
726//def MPYAr32:
727// RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
728// "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
729// [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
730// R32C:$rC))]>;
731
732// mpyh: multiply high, used to synthesize 32-bit multiplies
733def MPYHv4i32:
734 RRForm<0b10100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
735 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
736 [(set (v4i32 VECREG:$rT),
737 (SPUmpyh_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
738
739def MPYHr32:
740 RRForm<0b10100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
741 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
742 [(set R32C:$rT, (SPUmpyh_i32 R32C:$rA, R32C:$rB))]>;
743
744// mpys: multiply high and shift right (returns the top half of
745// a 16-bit multiply, sign extended to 32 bits.)
746def MPYSvec:
747 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
748 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
749 []>;
750
751def MPYSr16:
752 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
753 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
754 []>;
755
756// mpyhh: multiply high-high (returns the 32-bit result from multiplying
757// the top 16 bits of the $rA, $rB)
758def MPYHHv8i16:
759 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
760 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
761 [(set (v8i16 VECREG:$rT),
762 (SPUmpyhh_v8i16 (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
763
764def MPYHHr32:
765 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
766 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
767 []>;
768
769// mpyhha: Multiply high-high, add to $rT:
770def MPYHHAvec:
771 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
772 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
773 []>;
774
775def MPYHHAr32:
776 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
777 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
778 []>;
779
780// mpyhhu: Multiply high-high, unsigned
781def MPYHHUvec:
782 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
783 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
784 []>;
785
786def MPYHHUr32:
787 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
788 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
789 []>;
790
791// mpyhhau: Multiply high-high, unsigned
792def MPYHHAUvec:
793 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
794 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
795 []>;
796
797def MPYHHAUr32:
798 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
799 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
800 []>;
801
802// clz: Count leading zeroes
803def CLZv4i32:
804 RRForm_1<0b10100101010, (outs VECREG:$rT), (ins VECREG:$rA),
805 "clz\t$rT, $rA", IntegerOp,
806 [/* intrinsic */]>;
807
808def CLZr32:
809 RRForm_1<0b10100101010, (outs R32C:$rT), (ins R32C:$rA),
810 "clz\t$rT, $rA", IntegerOp,
811 [(set R32C:$rT, (ctlz R32C:$rA))]>;
812
813// cntb: Count ones in bytes (aka "population count")
814// NOTE: This instruction is really a vector instruction, but the custom
815// lowering code uses it in unorthodox ways to support CTPOP for other
816// data types!
817def CNTBv16i8:
818 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
819 "cntb\t$rT, $rA", IntegerOp,
820 [(set (v16i8 VECREG:$rT), (SPUcntb_v16i8 (v16i8 VECREG:$rA)))]>;
821
822def CNTBv8i16 :
823 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
824 "cntb\t$rT, $rA", IntegerOp,
825 [(set (v8i16 VECREG:$rT), (SPUcntb_v8i16 (v8i16 VECREG:$rA)))]>;
826
827def CNTBv4i32 :
828 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
829 "cntb\t$rT, $rA", IntegerOp,
830 [(set (v4i32 VECREG:$rT), (SPUcntb_v4i32 (v4i32 VECREG:$rA)))]>;
831
Scott Michel8b6b4202007-12-04 22:35:58 +0000832// gbb: Gather all low order bits from each byte in $rA into a single 16-bit
833// quantity stored into $rT
834def GBB:
835 RRForm_1<0b01001101100, (outs R16C:$rT), (ins VECREG:$rA),
836 "gbb\t$rT, $rA", GatherOp,
837 []>;
838
839// gbh: Gather all low order bits from each halfword in $rA into a single
840// 8-bit quantity stored in $rT
841def GBH:
842 RRForm_1<0b10001101100, (outs R16C:$rT), (ins VECREG:$rA),
843 "gbh\t$rT, $rA", GatherOp,
844 []>;
845
846// gb: Gather all low order bits from each word in $rA into a single
847// 4-bit quantity stored in $rT
848def GB:
849 RRForm_1<0b00001101100, (outs R16C:$rT), (ins VECREG:$rA),
850 "gb\t$rT, $rA", GatherOp,
851 []>;
852
853// avgb: average bytes
854def AVGB:
855 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
856 "avgb\t$rT, $rA, $rB", ByteOp,
857 []>;
858
859// absdb: absolute difference of bytes
860def ABSDB:
861 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
862 "absdb\t$rT, $rA, $rB", ByteOp,
863 []>;
864
865// sumb: sum bytes into halfwords
866def SUMB:
867 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
868 "sumb\t$rT, $rA, $rB", ByteOp,
869 []>;
870
871// Sign extension operations:
872def XSBHvec:
873 RRForm_1<0b01101101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
874 "xsbh\t$rDst, $rSrc", IntegerOp,
875 [(set (v8i16 VECREG:$rDst), (sext (v16i8 VECREG:$rSrc)))]>;
876
877// Ordinary form for XSBH
878def XSBHr16:
879 RRForm_1<0b01101101010, (outs R16C:$rDst), (ins R16C:$rSrc),
880 "xsbh\t$rDst, $rSrc", IntegerOp,
881 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
882
Scott Michel438be252007-12-17 22:32:34 +0000883def XSBHr8:
884 RRForm_1<0b01101101010, (outs R16C:$rDst), (ins R8C:$rSrc),
885 "xsbh\t$rDst, $rSrc", IntegerOp,
886 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
887
Scott Michel8b6b4202007-12-04 22:35:58 +0000888// 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
889// quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
890// pattern below). Intentionally doesn't match a pattern because we want the
891// sext 8->32 pattern to do the work for us, namely because we need the extra
892// XSHWr32.
893def XSBHr32:
894 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
895 "xsbh\t$rDst, $rSrc", IntegerOp,
896 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i8))]>;
897
898// Sign extend halfwords to words:
899def XSHWvec:
900 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
901 "xshw\t$rDest, $rSrc", IntegerOp,
902 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
903
904def XSHWr32:
905 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
906 "xshw\t$rDst, $rSrc", IntegerOp,
907 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
908
909def XSHWr16:
910 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
911 "xshw\t$rDst, $rSrc", IntegerOp,
912 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
913
914def XSWDvec:
915 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
916 "xswd\t$rDst, $rSrc", IntegerOp,
917 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
918
919def XSWDr64:
920 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
921 "xswd\t$rDst, $rSrc", IntegerOp,
922 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
923
924def XSWDr32:
925 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
926 "xswd\t$rDst, $rSrc", IntegerOp,
927 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
928
929def : Pat<(sext R32C:$inp),
930 (XSWDr32 R32C:$inp)>;
931
932// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +0000933
Scott Michel97872d32008-02-23 18:41:37 +0000934class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
935 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
936 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000937
Scott Michel97872d32008-02-23 18:41:37 +0000938class ANDVecInst<ValueType vectype>:
939 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
940 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
941 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000942
Scott Michel6baba072008-03-05 23:02:02 +0000943class ANDRegInst<RegisterClass rclass>:
944 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
945 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
946
Scott Michel97872d32008-02-23 18:41:37 +0000947multiclass BitwiseAnd
948{
949 def v16i8: ANDVecInst<v16i8>;
950 def v8i16: ANDVecInst<v8i16>;
951 def v4i32: ANDVecInst<v4i32>;
952 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000953
Scott Michel6baba072008-03-05 23:02:02 +0000954 def r128: ANDRegInst<GPRC>;
955 def r64: ANDRegInst<R64C>;
956 def r32: ANDRegInst<R32C>;
957 def r16: ANDRegInst<R16C>;
958 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000959
Scott Michel97872d32008-02-23 18:41:37 +0000960 //===---------------------------------------------
961 // Special instructions to perform the fabs instruction
962 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
963 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000964
Scott Michel97872d32008-02-23 18:41:37 +0000965 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
966 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +0000967
Scott Michel97872d32008-02-23 18:41:37 +0000968 // Could use v4i32, but won't for clarity
969 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
970 [/* Intentionally does not match a pattern */]>;
971
972 //===---------------------------------------------
973
974 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
975 // quantities -- see 16->32 zext pattern.
976 //
977 // This pattern is somewhat artificial, since it might match some
978 // compiler generated pattern but it is unlikely to do so.
979
980 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
981 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
982}
983
984defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +0000985
986// N.B.: vnot_conv is one of those special target selection pattern fragments,
987// in which we expect there to be a bit_convert on the constant. Bear in mind
988// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
989// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000990
Scott Michel97872d32008-02-23 18:41:37 +0000991class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
992 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
993 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000994
Scott Michel97872d32008-02-23 18:41:37 +0000995class ANDCVecInst<ValueType vectype>:
996 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
997 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
998 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000999
Scott Michel97872d32008-02-23 18:41:37 +00001000class ANDCRegInst<RegisterClass rclass>:
1001 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1002 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001003
Scott Michel97872d32008-02-23 18:41:37 +00001004multiclass AndComplement
1005{
1006 def v16i8: ANDCVecInst<v16i8>;
1007 def v8i16: ANDCVecInst<v8i16>;
1008 def v4i32: ANDCVecInst<v4i32>;
1009 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001010
Scott Michel97872d32008-02-23 18:41:37 +00001011 def r128: ANDCRegInst<GPRC>;
1012 def r64: ANDCRegInst<R64C>;
1013 def r32: ANDCRegInst<R32C>;
1014 def r16: ANDCRegInst<R16C>;
1015 def r8: ANDCRegInst<R8C>;
1016}
Scott Michel438be252007-12-17 22:32:34 +00001017
Scott Michel97872d32008-02-23 18:41:37 +00001018defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001019
Scott Michel97872d32008-02-23 18:41:37 +00001020class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1021 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1022 IntegerOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001023
Scott Michel97872d32008-02-23 18:41:37 +00001024multiclass AndByteImm
1025{
1026 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1027 [(set (v16i8 VECREG:$rT),
1028 (and (v16i8 VECREG:$rA),
1029 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001030
Scott Michel97872d32008-02-23 18:41:37 +00001031 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1032 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1033}
Scott Michel438be252007-12-17 22:32:34 +00001034
Scott Michel97872d32008-02-23 18:41:37 +00001035defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001036
Scott Michel97872d32008-02-23 18:41:37 +00001037class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1038 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1039 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001040
Scott Michel97872d32008-02-23 18:41:37 +00001041multiclass AndHalfwordImm
1042{
1043 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1044 [(set (v8i16 VECREG:$rT),
1045 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001046
Scott Michel97872d32008-02-23 18:41:37 +00001047 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1048 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001049
Scott Michel97872d32008-02-23 18:41:37 +00001050 // Zero-extend i8 to i16:
1051 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1052 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1053}
Scott Michel8b6b4202007-12-04 22:35:58 +00001054
Scott Michel97872d32008-02-23 18:41:37 +00001055defm ANDHI : AndHalfwordImm;
1056
1057class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1058 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1059 IntegerOp, pattern>;
1060
1061multiclass AndWordImm
1062{
1063 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1064 [(set (v4i32 VECREG:$rT),
1065 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1066
1067 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1068 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1069
1070 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1071 // pattern below.
1072 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1073 [(set R32C:$rT,
1074 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1075
1076 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1077 // zext 16->32 pattern below.
1078 //
1079 // Note that this pattern is somewhat artificial, since it might match
1080 // something the compiler generates but is unlikely to occur in practice.
1081 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1082 [(set R32C:$rT,
1083 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1084}
1085
1086defm ANDI : AndWordImm;
1087
1088//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001089// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001090//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1091
Scott Michel8b6b4202007-12-04 22:35:58 +00001092// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001093class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1094 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1095 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001096
Scott Michel97872d32008-02-23 18:41:37 +00001097class ORVecInst<ValueType vectype>:
1098 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1099 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1100 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001101
Scott Michel97872d32008-02-23 18:41:37 +00001102class ORRegInst<RegisterClass rclass>:
1103 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1104 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001105
Scott Michel97872d32008-02-23 18:41:37 +00001106class ORPromoteScalar<RegisterClass rclass>:
1107 ORInst<(outs VECREG:$rT), (ins rclass:$rA, rclass:$rB),
1108 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001109
Scott Michel97872d32008-02-23 18:41:37 +00001110class ORExtractElt<RegisterClass rclass>:
1111 ORInst<(outs rclass:$rT), (ins VECREG:$rA, VECREG:$rB),
1112 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001113
Scott Michel97872d32008-02-23 18:41:37 +00001114multiclass BitwiseOr
1115{
1116 def v16i8: ORVecInst<v16i8>;
1117 def v8i16: ORVecInst<v8i16>;
1118 def v4i32: ORVecInst<v4i32>;
1119 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001120
Scott Michel97872d32008-02-23 18:41:37 +00001121 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1122 [(set (v4f32 VECREG:$rT),
1123 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1124 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001125
Scott Michel97872d32008-02-23 18:41:37 +00001126 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1127 [(set (v2f64 VECREG:$rT),
1128 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1129 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001130
Scott Michel97872d32008-02-23 18:41:37 +00001131 def r64: ORRegInst<R64C>;
1132 def r32: ORRegInst<R32C>;
1133 def r16: ORRegInst<R16C>;
1134 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001135
Scott Michel97872d32008-02-23 18:41:37 +00001136 // OR instructions used to copy f32 and f64 registers.
1137 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1138 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001139
Scott Michel97872d32008-02-23 18:41:37 +00001140 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1141 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001142
Scott Michel97872d32008-02-23 18:41:37 +00001143 // scalar->vector promotion:
1144 def v16i8_i8: ORPromoteScalar<R8C>;
1145 def v8i16_i16: ORPromoteScalar<R16C>;
1146 def v4i32_i32: ORPromoteScalar<R32C>;
1147 def v2i64_i64: ORPromoteScalar<R64C>;
1148 def v4f32_f32: ORPromoteScalar<R32FP>;
1149 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001150
Scott Michel97872d32008-02-23 18:41:37 +00001151 // extract element 0:
1152 def i8_v16i8: ORExtractElt<R8C>;
1153 def i16_v8i16: ORExtractElt<R16C>;
1154 def i32_v4i32: ORExtractElt<R32C>;
1155 def i64_v2i64: ORExtractElt<R64C>;
1156 def f32_v4f32: ORExtractElt<R32FP>;
1157 def f64_v2f64: ORExtractElt<R64FP>;
1158}
Scott Michel438be252007-12-17 22:32:34 +00001159
Scott Michel97872d32008-02-23 18:41:37 +00001160defm OR : BitwiseOr;
1161
1162// scalar->vector promotion patterns:
Scott Michel438be252007-12-17 22:32:34 +00001163def : Pat<(v16i8 (SPUpromote_scalar R8C:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001164 (ORv16i8_i8 R8C:$rA, R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001165
Scott Michel8b6b4202007-12-04 22:35:58 +00001166def : Pat<(v8i16 (SPUpromote_scalar R16C:$rA)),
1167 (ORv8i16_i16 R16C:$rA, R16C:$rA)>;
1168
Scott Michel8b6b4202007-12-04 22:35:58 +00001169def : Pat<(v4i32 (SPUpromote_scalar R32C:$rA)),
1170 (ORv4i32_i32 R32C:$rA, R32C:$rA)>;
1171
Scott Michel8b6b4202007-12-04 22:35:58 +00001172def : Pat<(v2i64 (SPUpromote_scalar R64C:$rA)),
1173 (ORv2i64_i64 R64C:$rA, R64C:$rA)>;
1174
Scott Michel8b6b4202007-12-04 22:35:58 +00001175def : Pat<(v4f32 (SPUpromote_scalar R32FP:$rA)),
1176 (ORv4f32_f32 R32FP:$rA, R32FP:$rA)>;
1177
Scott Michel8b6b4202007-12-04 22:35:58 +00001178def : Pat<(v2f64 (SPUpromote_scalar R64FP:$rA)),
1179 (ORv2f64_f64 R64FP:$rA, R64FP:$rA)>;
1180
1181// ORi*_v*: Used to extract vector element 0 (the preferred slot)
Scott Michel438be252007-12-17 22:32:34 +00001182
1183def : Pat<(SPUextract_elt0 (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001184 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001185
Scott Michel394e26d2008-01-17 20:38:41 +00001186def : Pat<(SPUextract_elt0_chained (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001187 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel394e26d2008-01-17 20:38:41 +00001188
Scott Michel8b6b4202007-12-04 22:35:58 +00001189def : Pat<(SPUextract_elt0 (v8i16 VECREG:$rA)),
1190 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1191
1192def : Pat<(SPUextract_elt0_chained (v8i16 VECREG:$rA)),
1193 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1194
Scott Michel8b6b4202007-12-04 22:35:58 +00001195def : Pat<(SPUextract_elt0 (v4i32 VECREG:$rA)),
1196 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1197
1198def : Pat<(SPUextract_elt0_chained (v4i32 VECREG:$rA)),
1199 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1200
Scott Michel8b6b4202007-12-04 22:35:58 +00001201def : Pat<(SPUextract_elt0 (v2i64 VECREG:$rA)),
1202 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1203
1204def : Pat<(SPUextract_elt0_chained (v2i64 VECREG:$rA)),
1205 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1206
Scott Michel8b6b4202007-12-04 22:35:58 +00001207def : Pat<(SPUextract_elt0 (v4f32 VECREG:$rA)),
1208 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1209
1210def : Pat<(SPUextract_elt0_chained (v4f32 VECREG:$rA)),
1211 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1212
Scott Michel8b6b4202007-12-04 22:35:58 +00001213def : Pat<(SPUextract_elt0 (v2f64 VECREG:$rA)),
1214 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1215
1216def : Pat<(SPUextract_elt0_chained (v2f64 VECREG:$rA)),
1217 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1218
Scott Michel97872d32008-02-23 18:41:37 +00001219// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001220
Scott Michel97872d32008-02-23 18:41:37 +00001221class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1222 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1223 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001224
Scott Michel97872d32008-02-23 18:41:37 +00001225class ORCVecInst<ValueType vectype>:
1226 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1227 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1228 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001229
Scott Michel97872d32008-02-23 18:41:37 +00001230class ORCRegInst<RegisterClass rclass>:
1231 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1232 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001233
Scott Michel97872d32008-02-23 18:41:37 +00001234multiclass BitwiseOrComplement
1235{
1236 def v16i8: ORCVecInst<v16i8>;
1237 def v8i16: ORCVecInst<v8i16>;
1238 def v4i32: ORCVecInst<v4i32>;
1239 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001240
Scott Michel97872d32008-02-23 18:41:37 +00001241 def r64: ORCRegInst<R64C>;
1242 def r32: ORCRegInst<R32C>;
1243 def r16: ORCRegInst<R16C>;
1244 def r8: ORCRegInst<R8C>;
1245}
1246
1247defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001248
Scott Michel8b6b4202007-12-04 22:35:58 +00001249// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001250class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1251 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1252 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001253
Scott Michel97872d32008-02-23 18:41:37 +00001254class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1255 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1256 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1257 (vectype immpred:$val)))]>;
1258
1259multiclass BitwiseOrByteImm
1260{
1261 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1262
1263 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1264 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1265}
1266
1267defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001268
Scott Michel8b6b4202007-12-04 22:35:58 +00001269// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001270class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1271 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1272 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001273
Scott Michel97872d32008-02-23 18:41:37 +00001274class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1275 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1276 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1277 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001278
Scott Michel97872d32008-02-23 18:41:37 +00001279multiclass BitwiseOrHalfwordImm
1280{
1281 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1282
1283 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1284 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1285
1286 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1287 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1288 [(set R16C:$rT, (or (anyext R8C:$rA),
1289 i16ImmSExt10:$val))]>;
1290}
1291
1292defm ORHI : BitwiseOrHalfwordImm;
1293
1294class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1295 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1296 IntegerOp, pattern>;
1297
1298class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1299 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1300 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1301 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001302
1303// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001304multiclass BitwiseOrImm
1305{
1306 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001307
Scott Michel97872d32008-02-23 18:41:37 +00001308 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1309 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001310
Scott Michel97872d32008-02-23 18:41:37 +00001311 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1312 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1313 // infra "anyext 16->32" pattern.)
1314 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1315 [(set R32C:$rT, (or (anyext R16C:$rA),
1316 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001317
Scott Michel97872d32008-02-23 18:41:37 +00001318 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1319 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1320 // infra "anyext 16->32" pattern.)
1321 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1322 [(set R32C:$rT, (or (anyext R8C:$rA),
1323 i32ImmSExt10:$val))]>;
1324}
Scott Michel8b6b4202007-12-04 22:35:58 +00001325
Scott Michel97872d32008-02-23 18:41:37 +00001326defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001327
Scott Michel8b6b4202007-12-04 22:35:58 +00001328// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1329// $rT[0], slots 1-3 are zeroed.
1330//
Scott Michel438be252007-12-17 22:32:34 +00001331// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001332def ORXv4i32:
1333 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1334 "orx\t$rT, $rA, $rB", IntegerOp,
1335 []>;
1336
Scott Michel438be252007-12-17 22:32:34 +00001337// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001338
Scott Michel6baba072008-03-05 23:02:02 +00001339class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1340 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1341 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001342
Scott Michel6baba072008-03-05 23:02:02 +00001343class XORVecInst<ValueType vectype>:
1344 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1345 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1346 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001347
Scott Michel6baba072008-03-05 23:02:02 +00001348class XORRegInst<RegisterClass rclass>:
1349 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1350 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1351
1352multiclass BitwiseExclusiveOr
1353{
1354 def v16i8: XORVecInst<v16i8>;
1355 def v8i16: XORVecInst<v8i16>;
1356 def v4i32: XORVecInst<v4i32>;
1357 def v2i64: XORVecInst<v2i64>;
1358
1359 def r128: XORRegInst<GPRC>;
1360 def r64: XORRegInst<R64C>;
1361 def r32: XORRegInst<R32C>;
1362 def r16: XORRegInst<R16C>;
1363 def r8: XORRegInst<R8C>;
1364
1365 // Special forms for floating point instructions.
1366 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1367
1368 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1369 [/* no pattern */]>;
1370
1371 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1372 [/* no pattern */]>;
1373
1374 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1375 [/* no pattern, see fneg{32,64} */]>;
1376}
1377
1378defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001379
1380//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001381
Scott Michel97872d32008-02-23 18:41:37 +00001382class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1383 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1384 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001385
Scott Michel97872d32008-02-23 18:41:37 +00001386multiclass XorByteImm
1387{
1388 def v16i8:
1389 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1390 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1391
1392 def r8:
1393 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1394 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1395}
1396
1397defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001398
Scott Michel8b6b4202007-12-04 22:35:58 +00001399def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001400 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001401 "xorhi\t$rT, $rA, $val", IntegerOp,
1402 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1403 v8i16SExt10Imm:$val))]>;
1404
1405def XORHIr16:
1406 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1407 "xorhi\t$rT, $rA, $val", IntegerOp,
1408 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1409
1410def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001411 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001412 "xori\t$rT, $rA, $val", IntegerOp,
1413 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1414 v4i32SExt10Imm:$val))]>;
1415
1416def XORIr32:
1417 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1418 "xori\t$rT, $rA, $val", IntegerOp,
1419 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1420
1421// NAND:
1422def NANDv16i8:
1423 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1424 "nand\t$rT, $rA, $rB", IntegerOp,
1425 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1426 (v16i8 VECREG:$rB))))]>;
1427
1428def NANDv8i16:
1429 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1430 "nand\t$rT, $rA, $rB", IntegerOp,
1431 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1432 (v8i16 VECREG:$rB))))]>;
1433
1434def NANDv4i32:
1435 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1436 "nand\t$rT, $rA, $rB", IntegerOp,
1437 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1438 (v4i32 VECREG:$rB))))]>;
1439
1440def NANDr32:
1441 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1442 "nand\t$rT, $rA, $rB", IntegerOp,
1443 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1444
1445def NANDr16:
1446 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1447 "nand\t$rT, $rA, $rB", IntegerOp,
1448 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1449
Scott Michel438be252007-12-17 22:32:34 +00001450def NANDr8:
1451 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1452 "nand\t$rT, $rA, $rB", IntegerOp,
1453 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1454
Scott Michel8b6b4202007-12-04 22:35:58 +00001455// NOR:
1456def NORv16i8:
1457 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1458 "nor\t$rT, $rA, $rB", IntegerOp,
1459 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1460 (v16i8 VECREG:$rB))))]>;
1461
1462def NORv8i16:
1463 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1464 "nor\t$rT, $rA, $rB", IntegerOp,
1465 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1466 (v8i16 VECREG:$rB))))]>;
1467
1468def NORv4i32:
1469 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1470 "nor\t$rT, $rA, $rB", IntegerOp,
1471 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1472 (v4i32 VECREG:$rB))))]>;
1473
1474def NORr32:
1475 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1476 "nor\t$rT, $rA, $rB", IntegerOp,
1477 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1478
1479def NORr16:
1480 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1481 "nor\t$rT, $rA, $rB", IntegerOp,
1482 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1483
Scott Michel438be252007-12-17 22:32:34 +00001484def NORr8:
1485 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1486 "nor\t$rT, $rA, $rB", IntegerOp,
1487 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1488
Scott Michel8b6b4202007-12-04 22:35:58 +00001489// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001490class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1491 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1492 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001493
Scott Michel6baba072008-03-05 23:02:02 +00001494class SELBVecInst<ValueType vectype>:
1495 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1496 [(set (vectype VECREG:$rT),
1497 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1498 (and (vnot (vectype VECREG:$rC)),
1499 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001500
Scott Michel6baba072008-03-05 23:02:02 +00001501class SELBRegInst<RegisterClass rclass>:
1502 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1503 [(set rclass:$rT,
1504 (or (and rclass:$rA, rclass:$rC),
1505 (and rclass:$rB, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001506
Scott Michel6baba072008-03-05 23:02:02 +00001507multiclass SelectBits
1508{
1509 def v16i8: SELBVecInst<v16i8>;
1510 def v8i16: SELBVecInst<v8i16>;
1511 def v4i32: SELBVecInst<v4i32>;
1512 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001513
Scott Michel6baba072008-03-05 23:02:02 +00001514 def r128: SELBRegInst<GPRC>;
1515 def r64: SELBRegInst<R64C>;
1516 def r32: SELBRegInst<R32C>;
1517 def r16: SELBRegInst<R16C>;
1518 def r8: SELBRegInst<R8C>;
1519}
Scott Michel8b6b4202007-12-04 22:35:58 +00001520
Scott Michel6baba072008-03-05 23:02:02 +00001521defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001522
Scott Michel6baba072008-03-05 23:02:02 +00001523class SPUselbPat<ValueType vectype, SPUInstr inst>:
1524 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1525 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001526
Scott Michel6baba072008-03-05 23:02:02 +00001527def : SPUselbPat<v16i8, SELBv16i8>;
1528def : SPUselbPat<v8i16, SELBv8i16>;
1529def : SPUselbPat<v4i32, SELBv4i32>;
1530def : SPUselbPat<v2i64, SELBv2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001531
Scott Michel6baba072008-03-05 23:02:02 +00001532class SelectConditional<RegisterClass rclass, SPUInstr inst>:
1533 Pat<(select rclass:$rCond, rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00001534 (inst rclass:$rFalse, rclass:$rTrue, rclass:$rCond)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001535
Scott Michel6baba072008-03-05 23:02:02 +00001536def : SelectConditional<R32C, SELBr32>;
1537def : SelectConditional<R16C, SELBr16>;
1538def : SelectConditional<R8C, SELBr8>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001539
Scott Michel6baba072008-03-05 23:02:02 +00001540// EQV: Equivalence (1 for each same bit, otherwise 0)
1541//
1542// Note: There are a lot of ways to match this bit operator and these patterns
1543// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001544
Scott Michel6baba072008-03-05 23:02:02 +00001545class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1546 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1547 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001548
Scott Michel6baba072008-03-05 23:02:02 +00001549class EQVVecInst<ValueType vectype>:
1550 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1551 [(set (vectype VECREG:$rT),
1552 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1553 (and (vnot (vectype VECREG:$rA)),
1554 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001555
Scott Michel6baba072008-03-05 23:02:02 +00001556class EQVRegInst<RegisterClass rclass>:
1557 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1558 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1559 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001560
Scott Michel6baba072008-03-05 23:02:02 +00001561class EQVVecPattern1<ValueType vectype>:
1562 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1563 [(set (vectype VECREG:$rT),
1564 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001565
Scott Michel6baba072008-03-05 23:02:02 +00001566class EQVRegPattern1<RegisterClass rclass>:
1567 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1568 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001569
Scott Michel6baba072008-03-05 23:02:02 +00001570class EQVVecPattern2<ValueType vectype>:
1571 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1572 [(set (vectype VECREG:$rT),
1573 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1574 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001575
Scott Michel6baba072008-03-05 23:02:02 +00001576class EQVRegPattern2<RegisterClass rclass>:
1577 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1578 [(set rclass:$rT,
1579 (or (and rclass:$rA, rclass:$rB),
1580 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001581
Scott Michel6baba072008-03-05 23:02:02 +00001582class EQVVecPattern3<ValueType vectype>:
1583 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1584 [(set (vectype VECREG:$rT),
1585 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Scott Michel6baba072008-03-05 23:02:02 +00001587class EQVRegPattern3<RegisterClass rclass>:
1588 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1589 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001590
Scott Michel6baba072008-03-05 23:02:02 +00001591multiclass BitEquivalence
1592{
1593 def v16i8: EQVVecInst<v16i8>;
1594 def v8i16: EQVVecInst<v8i16>;
1595 def v4i32: EQVVecInst<v4i32>;
1596 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001597
Scott Michel6baba072008-03-05 23:02:02 +00001598 def v16i8_1: EQVVecPattern1<v16i8>;
1599 def v8i16_1: EQVVecPattern1<v8i16>;
1600 def v4i32_1: EQVVecPattern1<v4i32>;
1601 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001602
Scott Michel6baba072008-03-05 23:02:02 +00001603 def v16i8_2: EQVVecPattern2<v16i8>;
1604 def v8i16_2: EQVVecPattern2<v8i16>;
1605 def v4i32_2: EQVVecPattern2<v4i32>;
1606 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001607
Scott Michel6baba072008-03-05 23:02:02 +00001608 def v16i8_3: EQVVecPattern3<v16i8>;
1609 def v8i16_3: EQVVecPattern3<v8i16>;
1610 def v4i32_3: EQVVecPattern3<v4i32>;
1611 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001612
Scott Michel6baba072008-03-05 23:02:02 +00001613 def r128: EQVRegInst<GPRC>;
1614 def r64: EQVRegInst<R64C>;
1615 def r32: EQVRegInst<R32C>;
1616 def r16: EQVRegInst<R16C>;
1617 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001618
Scott Michel6baba072008-03-05 23:02:02 +00001619 def r128_1: EQVRegPattern1<GPRC>;
1620 def r64_1: EQVRegPattern1<R64C>;
1621 def r32_1: EQVRegPattern1<R32C>;
1622 def r16_1: EQVRegPattern1<R16C>;
1623 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001624
Scott Michel6baba072008-03-05 23:02:02 +00001625 def r128_2: EQVRegPattern2<GPRC>;
1626 def r64_2: EQVRegPattern2<R64C>;
1627 def r32_2: EQVRegPattern2<R32C>;
1628 def r16_2: EQVRegPattern2<R16C>;
1629 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001630
Scott Michel6baba072008-03-05 23:02:02 +00001631 def r128_3: EQVRegPattern3<GPRC>;
1632 def r64_3: EQVRegPattern3<R64C>;
1633 def r32_3: EQVRegPattern3<R32C>;
1634 def r16_3: EQVRegPattern3<R16C>;
1635 def r8_3: EQVRegPattern3<R8C>;
1636}
Scott Michel438be252007-12-17 22:32:34 +00001637
Scott Michel6baba072008-03-05 23:02:02 +00001638defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001639
1640//===----------------------------------------------------------------------===//
1641// Vector shuffle...
1642//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001643// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1644// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1645// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1646// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00001647//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001648
Scott Michel97872d32008-02-23 18:41:37 +00001649class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1650 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1651 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001652
Scott Michel97872d32008-02-23 18:41:37 +00001653class SHUFBVecInst<ValueType vectype>:
1654 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1655 [(set (vectype VECREG:$rT), (SPUshuffle (vectype VECREG:$rA),
1656 (vectype VECREG:$rB),
1657 (vectype VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001658
Scott Michel97872d32008-02-23 18:41:37 +00001659// It's this pattern that's probably the most useful, since SPUISelLowering
1660// methods create a v16i8 vector for $rC:
1661class SHUFBVecPat1<ValueType vectype, SPUInstr inst>:
1662 Pat<(SPUshuffle (vectype VECREG:$rA), (vectype VECREG:$rB),
1663 (v16i8 VECREG:$rC)),
1664 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel754d8662007-12-20 00:44:13 +00001665
Scott Michel97872d32008-02-23 18:41:37 +00001666multiclass ShuffleBytes
1667{
1668 def v16i8 : SHUFBVecInst<v16i8>;
1669 def v8i16 : SHUFBVecInst<v8i16>;
1670 def v4i32 : SHUFBVecInst<v4i32>;
1671 def v2i64 : SHUFBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001672
Scott Michel97872d32008-02-23 18:41:37 +00001673 def v4f32 : SHUFBVecInst<v4f32>;
1674 def v2f64 : SHUFBVecInst<v2f64>;
1675}
1676
1677defm SHUFB : ShuffleBytes;
1678
1679def : SHUFBVecPat1<v8i16, SHUFBv16i8>;
1680def : SHUFBVecPat1<v4i32, SHUFBv16i8>;
1681def : SHUFBVecPat1<v2i64, SHUFBv16i8>;
1682def : SHUFBVecPat1<v4f32, SHUFBv16i8>;
1683def : SHUFBVecPat1<v2f64, SHUFBv16i8>;
Scott Michel754d8662007-12-20 00:44:13 +00001684
Scott Michel8b6b4202007-12-04 22:35:58 +00001685//===----------------------------------------------------------------------===//
1686// Shift and rotate group:
1687//===----------------------------------------------------------------------===//
1688
Scott Michel97872d32008-02-23 18:41:37 +00001689class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
1690 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
1691 RotateShift, pattern>;
1692
1693class SHLHVecInst<ValueType vectype>:
1694 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1695 [(set (vectype VECREG:$rT),
1696 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001697
1698// $rB gets promoted to 32-bit register type when confronted with
1699// this llvm assembly code:
1700//
1701// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
1702// %A = shl i16 %arg1, %arg2
1703// ret i16 %A
1704// }
Scott Michel8b6b4202007-12-04 22:35:58 +00001705
Scott Michel97872d32008-02-23 18:41:37 +00001706multiclass ShiftLeftHalfword
1707{
1708 def v8i16: SHLHVecInst<v8i16>;
1709 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1710 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
1711 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1712 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
1713}
Scott Michel8b6b4202007-12-04 22:35:58 +00001714
Scott Michel97872d32008-02-23 18:41:37 +00001715defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001716
Scott Michel97872d32008-02-23 18:41:37 +00001717//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00001718
Scott Michel97872d32008-02-23 18:41:37 +00001719class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
1720 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
1721 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001722
Scott Michel97872d32008-02-23 18:41:37 +00001723class SHLHIVecInst<ValueType vectype>:
1724 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1725 [(set (vectype VECREG:$rT),
1726 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001727
Scott Michel97872d32008-02-23 18:41:37 +00001728multiclass ShiftLeftHalfwordImm
1729{
1730 def v8i16: SHLHIVecInst<v8i16>;
1731 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1732 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
1733}
1734
1735defm SHLHI : ShiftLeftHalfwordImm;
1736
1737def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
1738 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
1739
1740def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00001741 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001742
Scott Michel97872d32008-02-23 18:41:37 +00001743//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001744
Scott Michel97872d32008-02-23 18:41:37 +00001745class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
1746 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
1747 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001748
Scott Michel97872d32008-02-23 18:41:37 +00001749multiclass ShiftLeftWord
1750{
1751 def v4i32:
1752 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1753 [(set (v4i32 VECREG:$rT),
1754 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
1755 def r32:
1756 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1757 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
1758}
Scott Michel8b6b4202007-12-04 22:35:58 +00001759
Scott Michel97872d32008-02-23 18:41:37 +00001760defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00001761
Scott Michel97872d32008-02-23 18:41:37 +00001762//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001763
Scott Michel97872d32008-02-23 18:41:37 +00001764class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
1765 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
1766 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001767
Scott Michel97872d32008-02-23 18:41:37 +00001768multiclass ShiftLeftWordImm
1769{
1770 def v4i32:
1771 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1772 [(set (v4i32 VECREG:$rT),
1773 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001774
Scott Michel97872d32008-02-23 18:41:37 +00001775 def r32:
1776 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
1777 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
1778}
Scott Michel8b6b4202007-12-04 22:35:58 +00001779
Scott Michel97872d32008-02-23 18:41:37 +00001780defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00001781
Scott Michel97872d32008-02-23 18:41:37 +00001782//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001783// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
1784// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00001785//
1786// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
1787// of 7 bits is actually possible.
1788//
1789// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
1790// to shift i64 and i128. SHLQBI is the residual left over after shifting by
1791// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00001792
Scott Michel97872d32008-02-23 18:41:37 +00001793class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
1794 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
1795 RotateShift, pattern>;
1796
1797class SHLQBIVecInst<ValueType vectype>:
1798 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1799 [(set (vectype VECREG:$rT),
1800 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
1801
1802multiclass ShiftLeftQuadByBits
1803{
1804 def v16i8: SHLQBIVecInst<v16i8>;
1805 def v8i16: SHLQBIVecInst<v8i16>;
1806 def v4i32: SHLQBIVecInst<v4i32>;
1807 def v2i64: SHLQBIVecInst<v2i64>;
1808}
1809
1810defm SHLQBI : ShiftLeftQuadByBits;
1811
1812// See note above on SHLQBI. In this case, the predicate actually does then
1813// enforcement, whereas with SHLQBI, we have to "take it on faith."
1814class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
1815 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
1816 RotateShift, pattern>;
1817
1818class SHLQBIIVecInst<ValueType vectype>:
1819 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1820 [(set (vectype VECREG:$rT),
1821 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
1822
1823multiclass ShiftLeftQuadByBitsImm
1824{
1825 def v16i8 : SHLQBIIVecInst<v16i8>;
1826 def v8i16 : SHLQBIIVecInst<v8i16>;
1827 def v4i32 : SHLQBIIVecInst<v4i32>;
1828 def v2i64 : SHLQBIIVecInst<v2i64>;
1829}
1830
1831defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001832
1833// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00001834// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00001835
Scott Michel97872d32008-02-23 18:41:37 +00001836class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
1837 RI7Form<0b11111011100, OOL, IOL, "shlqbyi\t$rT, $rA, $rB",
1838 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001839
Scott Michel97872d32008-02-23 18:41:37 +00001840class SHLQBYVecInst<ValueType vectype>:
1841 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1842 [(set (vectype VECREG:$rT),
1843 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001844
Scott Michel97872d32008-02-23 18:41:37 +00001845multiclass ShiftLeftQuadBytes
1846{
1847 def v16i8: SHLQBYVecInst<v16i8>;
1848 def v8i16: SHLQBYVecInst<v8i16>;
1849 def v4i32: SHLQBYVecInst<v4i32>;
1850 def v2i64: SHLQBYVecInst<v2i64>;
1851 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
1852 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
1853}
Scott Michel8b6b4202007-12-04 22:35:58 +00001854
Scott Michel97872d32008-02-23 18:41:37 +00001855defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001856
Scott Michel97872d32008-02-23 18:41:37 +00001857class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
1858 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
1859 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001860
Scott Michel97872d32008-02-23 18:41:37 +00001861class SHLQBYIVecInst<ValueType vectype>:
1862 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1863 [(set (vectype VECREG:$rT),
1864 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00001865
Scott Michel97872d32008-02-23 18:41:37 +00001866multiclass ShiftLeftQuadBytesImm
1867{
1868 def v16i8: SHLQBYIVecInst<v16i8>;
1869 def v8i16: SHLQBYIVecInst<v8i16>;
1870 def v4i32: SHLQBYIVecInst<v4i32>;
1871 def v2i64: SHLQBYIVecInst<v2i64>;
1872 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
1873 [(set GPRC:$rT,
1874 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
1875}
Scott Michel438be252007-12-17 22:32:34 +00001876
Scott Michel97872d32008-02-23 18:41:37 +00001877defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00001878
Scott Michel97872d32008-02-23 18:41:37 +00001879// Special form for truncating i64 to i32:
1880def SHLQBYItrunc64: SHLQBYIInst<(outs R32C:$rT), (ins R64C:$rA, u7imm_i32:$val),
1881 [/* no pattern, see below */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001882
Scott Michel97872d32008-02-23 18:41:37 +00001883def : Pat<(trunc R64C:$rSrc),
1884 (SHLQBYItrunc64 R64C:$rSrc, 4)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001885
Scott Michel97872d32008-02-23 18:41:37 +00001886//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1887// Rotate halfword:
1888//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1889class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
1890 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
1891 RotateShift, pattern>;
1892
1893class ROTHVecInst<ValueType vectype>:
1894 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1895 [(set (vectype VECREG:$rT),
1896 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
1897
1898class ROTHRegInst<RegisterClass rclass>:
1899 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1900 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
1901
1902multiclass RotateLeftHalfword
1903{
1904 def v8i16: ROTHVecInst<v8i16>;
1905 def r16: ROTHRegInst<R16C>;
1906}
1907
1908defm ROTH: RotateLeftHalfword;
1909
1910def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1911 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
1912
1913//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1914// Rotate halfword, immediate:
1915//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1916class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
1917 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
1918 RotateShift, pattern>;
1919
1920class ROTHIVecInst<ValueType vectype>:
1921 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1922 [(set (vectype VECREG:$rT),
1923 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
1924
1925multiclass RotateLeftHalfwordImm
1926{
1927 def v8i16: ROTHIVecInst<v8i16>;
1928 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1929 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
1930 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
1931 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
1932}
1933
1934defm ROTHI: RotateLeftHalfwordImm;
1935
1936def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001937 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
1938
Scott Michel97872d32008-02-23 18:41:37 +00001939//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1940// Rotate word:
1941//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001942
Scott Michel97872d32008-02-23 18:41:37 +00001943class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
1944 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
1945 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001946
Scott Michel97872d32008-02-23 18:41:37 +00001947class ROTVecInst<ValueType vectype>:
1948 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1949 [(set (vectype VECREG:$rT),
1950 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00001951
Scott Michel97872d32008-02-23 18:41:37 +00001952class ROTRegInst<RegisterClass rclass>:
1953 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
1954 [(set rclass:$rT,
1955 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001956
Scott Michel97872d32008-02-23 18:41:37 +00001957multiclass RotateLeftWord
1958{
1959 def v4i32: ROTVecInst<v4i32>;
1960 def r32: ROTRegInst<R32C>;
1961}
1962
1963defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001964
Scott Michel438be252007-12-17 22:32:34 +00001965// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
1966// 32-bit register
1967def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00001968 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
1969 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00001970
1971def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
1972 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
1973
1974def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
1975 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
1976
1977def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00001978 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
1979 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00001980
1981def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
1982 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
1983
1984def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
1985 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
1986
Scott Michel97872d32008-02-23 18:41:37 +00001987//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1988// Rotate word, immediate
1989//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001990
Scott Michel97872d32008-02-23 18:41:37 +00001991class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
1992 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
1993 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001994
Scott Michel97872d32008-02-23 18:41:37 +00001995class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
1996 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
1997 [(set (vectype VECREG:$rT),
1998 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00001999
Scott Michel97872d32008-02-23 18:41:37 +00002000class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2001 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2002 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002003
Scott Michel97872d32008-02-23 18:41:37 +00002004multiclass RotateLeftWordImm
2005{
2006 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2007 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2008 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002009
Scott Michel97872d32008-02-23 18:41:37 +00002010 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2011 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
2012 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2013}
Scott Michel438be252007-12-17 22:32:34 +00002014
Scott Michel97872d32008-02-23 18:41:37 +00002015defm ROTI : RotateLeftWordImm;
2016
2017//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2018// Rotate quad by byte (count)
2019//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2020
2021class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2022 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2023 RotateShift, pattern>;
2024
2025class ROTQBYVecInst<ValueType vectype>:
2026 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2027 [(set (vectype VECREG:$rT),
2028 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2029
2030multiclass RotateQuadLeftByBytes
2031{
2032 def v16i8: ROTQBYVecInst<v16i8>;
2033 def v8i16: ROTQBYVecInst<v8i16>;
2034 def v4i32: ROTQBYVecInst<v4i32>;
2035 def v2i64: ROTQBYVecInst<v2i64>;
2036}
2037
2038defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002039
Scott Micheldbac4cf2008-01-11 02:53:15 +00002040def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002041 (ROTQBYv16i8 VECREG:$rA, R32C:$rB)>;
2042def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), R32C:$rB),
2043 (ROTQBYv8i16 VECREG:$rA, R32C:$rB)>;
2044def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), R32C:$rB),
2045 (ROTQBYv4i32 VECREG:$rA, R32C:$rB)>;
2046def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), R32C:$rB),
2047 (ROTQBYv2i64 VECREG:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002048
Scott Michel97872d32008-02-23 18:41:37 +00002049//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2050// Rotate quad by byte (count), immediate
2051//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2052
2053class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2054 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2055 RotateShift, pattern>;
2056
2057class ROTQBYIVecInst<ValueType vectype>:
2058 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2059 [(set (vectype VECREG:$rT),
2060 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2061
2062multiclass RotateQuadByBytesImm
2063{
2064 def v16i8: ROTQBYIVecInst<v16i8>;
2065 def v8i16: ROTQBYIVecInst<v8i16>;
2066 def v4i32: ROTQBYIVecInst<v4i32>;
2067 def v2i64: ROTQBYIVecInst<v2i64>;
2068}
2069
2070defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002071
2072def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel97872d32008-02-23 18:41:37 +00002073 (ROTQBYIv16i8 VECREG:$rA, uimm7:$val)>;
2074def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2075 (ROTQBYIv8i16 VECREG:$rA, uimm7:$val)>;
2076def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2077 (ROTQBYIv4i32 VECREG:$rA, uimm7:$val)>;
2078def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), (i16 uimm7:$val)),
2079 (ROTQBYIv2i64 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002080
2081// See ROTQBY note above.
2082def ROTQBYBIvec:
2083 RI7Form<0b00110011100, (outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2084 "rotqbybi\t$rT, $rA, $val", RotateShift,
2085 [/* intrinsic */]>;
2086
Scott Michel97872d32008-02-23 18:41:37 +00002087//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002088// See ROTQBY note above.
2089//
2090// Assume that the user of this instruction knows to shift the rotate count
2091// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002092//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002093
Scott Michel97872d32008-02-23 18:41:37 +00002094class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2095 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2096 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002097
Scott Michel97872d32008-02-23 18:41:37 +00002098class ROTQBIVecInst<ValueType vectype>:
2099 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2100 [/* no pattern yet */]>;
2101
2102class ROTQBIRegInst<RegisterClass rclass>:
2103 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2104 [/* no pattern yet */]>;
2105
2106multiclass RotateQuadByBitCount
2107{
2108 def v16i8: ROTQBIVecInst<v16i8>;
2109 def v8i16: ROTQBIVecInst<v8i16>;
2110 def v4i32: ROTQBIVecInst<v4i32>;
2111 def v2i64: ROTQBIVecInst<v2i64>;
2112
2113 def r128: ROTQBIRegInst<GPRC>;
2114 def r64: ROTQBIRegInst<R64C>;
2115}
2116
2117defm ROTQBI: RotateQuadByBitCount;
2118
2119class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2120 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2121 RotateShift, pattern>;
2122
2123class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2124 PatLeaf pred>:
2125 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2126 [/* no pattern yet */]>;
2127
2128class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2129 PatLeaf pred>:
2130 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2131 [/* no pattern yet */]>;
2132
2133multiclass RotateQuadByBitCountImm
2134{
2135 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2136 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2137 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2138 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2139
2140 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2141 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2142}
2143
2144defm ROTQBII : RotateQuadByBitCountImm;
2145
2146//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002147// ROTHM v8i16 form:
2148// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2149// so this only matches a synthetically generated/lowered code
2150// fragment.
2151// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002152//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002153
Scott Michel97872d32008-02-23 18:41:37 +00002154class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2155 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2156 RotateShift, pattern>;
2157
2158def ROTHMv8i16:
2159 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2160 [/* see patterns below - $rB must be negated */]>;
2161
2162def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002163 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2164
Scott Michel97872d32008-02-23 18:41:37 +00002165def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002166 (ROTHMv8i16 VECREG:$rA,
2167 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2168
Scott Michel97872d32008-02-23 18:41:37 +00002169def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002170 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002171 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002172
2173// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2174// Note: This instruction doesn't match a pattern because rB must be negated
2175// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002176
Scott Michel8b6b4202007-12-04 22:35:58 +00002177def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002178 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2179 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002180
2181def : Pat<(srl R16C:$rA, R32C:$rB),
2182 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2183
2184def : Pat<(srl R16C:$rA, R16C:$rB),
2185 (ROTHMr16 R16C:$rA,
2186 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2187
Scott Michel438be252007-12-17 22:32:34 +00002188def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002189 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002190 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002191
2192// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2193// that the immediate can be complemented, so that the user doesn't have to
2194// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002195
Scott Michel97872d32008-02-23 18:41:37 +00002196class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2197 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2198 RotateShift, pattern>;
2199
2200def ROTHMIv8i16:
2201 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2202 [/* no pattern */]>;
2203
2204def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2205 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2206
2207def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002208 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002209
Scott Michel97872d32008-02-23 18:41:37 +00002210def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002211 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002212
2213def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002214 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2215 [/* no pattern */]>;
2216
2217def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2218 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002219
2220def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2221 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2222
Scott Michel438be252007-12-17 22:32:34 +00002223def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2224 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2225
Scott Michel8b6b4202007-12-04 22:35:58 +00002226// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002227class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2228 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2229 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002230
Scott Michel97872d32008-02-23 18:41:37 +00002231def ROTMv4i32:
2232 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2233 [/* see patterns below - $rB must be negated */]>;
2234
2235def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002236 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2237
Scott Michel97872d32008-02-23 18:41:37 +00002238def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002239 (ROTMv4i32 VECREG:$rA,
2240 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2241
Scott Michel97872d32008-02-23 18:41:37 +00002242def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002243 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002244 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002245
2246def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002247 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2248 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002249
2250def : Pat<(srl R32C:$rA, R32C:$rB),
2251 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2252
2253def : Pat<(srl R32C:$rA, R16C:$rB),
2254 (ROTMr32 R32C:$rA,
2255 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2256
Scott Michel438be252007-12-17 22:32:34 +00002257def : Pat<(srl R32C:$rA, R8C:$rB),
2258 (ROTMr32 R32C:$rA,
2259 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2260
Scott Michel8b6b4202007-12-04 22:35:58 +00002261// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2262def ROTMIv4i32:
2263 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2264 "rotmi\t$rT, $rA, $val", RotateShift,
2265 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002266 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002267
Scott Michel97872d32008-02-23 18:41:37 +00002268def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002269 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002270
Scott Michel97872d32008-02-23 18:41:37 +00002271def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002272 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002273
2274// ROTMI r32 form: know how to complement the immediate value.
2275def ROTMIr32:
2276 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2277 "rotmi\t$rT, $rA, $val", RotateShift,
2278 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2279
2280def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2281 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2282
Scott Michel438be252007-12-17 22:32:34 +00002283def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2284 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2285
Scott Michel97872d32008-02-23 18:41:37 +00002286//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002287// ROTQMBYvec: This is a vector form merely so that when used in an
2288// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002289// that the user knew to negate $rB.
2290//
2291// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2292// ensure that $rB is negated.
2293//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002294
Scott Michel97872d32008-02-23 18:41:37 +00002295class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2296 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2297 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002298
Scott Michel97872d32008-02-23 18:41:37 +00002299class ROTQMBYVecInst<ValueType vectype>:
2300 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2301 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002302
Scott Michel97872d32008-02-23 18:41:37 +00002303class ROTQMBYRegInst<RegisterClass rclass>:
2304 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2305 [(set rclass:$rT,
2306 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002307
Scott Michel97872d32008-02-23 18:41:37 +00002308multiclass RotateQuadBytes
2309{
2310 def v16i8: ROTQMBYVecInst<v16i8>;
2311 def v8i16: ROTQMBYVecInst<v8i16>;
2312 def v4i32: ROTQMBYVecInst<v4i32>;
2313 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002314
Scott Michel97872d32008-02-23 18:41:37 +00002315 def r128: ROTQMBYRegInst<GPRC>;
2316 def r64: ROTQMBYRegInst<R64C>;
2317}
2318
2319defm ROTQMBY : RotateQuadBytes;
2320
2321def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2322 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2323def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2324 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2325def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2326 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2327def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2328 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2329def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2330 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2331def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2332 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2333
2334class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2335 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2336 RotateShift, pattern>;
2337
2338class ROTQMBYIVecInst<ValueType vectype>:
2339 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2340 [(set (vectype VECREG:$rT),
2341 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2342
2343class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2344 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2345 [(set rclass:$rT,
2346 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2347
2348multiclass RotateQuadBytesImm
2349{
2350 def v16i8: ROTQMBYIVecInst<v16i8>;
2351 def v8i16: ROTQMBYIVecInst<v8i16>;
2352 def v4i32: ROTQMBYIVecInst<v4i32>;
2353 def v2i64: ROTQMBYIVecInst<v2i64>;
2354
2355 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2356 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2357}
2358
2359defm ROTQMBYI : RotateQuadBytesImm;
2360
2361
2362//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2363// Rotate right and mask by bit count
2364//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2365
2366class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2367 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2368 RotateShift, pattern>;
2369
2370class ROTQMBYBIVecInst<ValueType vectype>:
2371 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2372 [/* no pattern, intrinsic? */]>;
2373
2374multiclass RotateMaskQuadByBitCount
2375{
2376 def v16i8: ROTQMBYBIVecInst<v16i8>;
2377 def v8i16: ROTQMBYBIVecInst<v8i16>;
2378 def v4i32: ROTQMBYBIVecInst<v4i32>;
2379 def v2i64: ROTQMBYBIVecInst<v2i64>;
2380}
2381
2382defm ROTQMBYBI: RotateMaskQuadByBitCount;
2383
2384//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2385// Rotate quad and mask by bits
2386// Note that the rotate amount has to be negated
2387//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2388
2389class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2390 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2391 RotateShift, pattern>;
2392
2393class ROTQMBIVecInst<ValueType vectype>:
2394 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2395 [/* no pattern */]>;
2396
2397class ROTQMBIRegInst<RegisterClass rclass>:
2398 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2399 [/* no pattern */]>;
2400
2401multiclass RotateMaskQuadByBits
2402{
2403 def v16i8: ROTQMBIVecInst<v16i8>;
2404 def v8i16: ROTQMBIVecInst<v8i16>;
2405 def v4i32: ROTQMBIVecInst<v4i32>;
2406 def v2i64: ROTQMBIVecInst<v2i64>;
2407
2408 def r128: ROTQMBIRegInst<GPRC>;
2409 def r64: ROTQMBIRegInst<R64C>;
2410}
2411
2412defm ROTQMBI: RotateMaskQuadByBits;
2413
2414def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2415 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2416def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2417 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2418def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2419 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2420def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2421 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2422def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2423 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2424def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2425 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2426
2427//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2428// Rotate quad and mask by bits, immediate
2429//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2430
2431class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2432 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2433 RotateShift, pattern>;
2434
2435class ROTQMBIIVecInst<ValueType vectype>:
2436 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2437 [(set (vectype VECREG:$rT),
2438 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2439
2440class ROTQMBIIRegInst<RegisterClass rclass>:
2441 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2442 [(set rclass:$rT,
2443 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2444
2445multiclass RotateMaskQuadByBitsImm
2446{
2447 def v16i8: ROTQMBIIVecInst<v16i8>;
2448 def v8i16: ROTQMBIIVecInst<v8i16>;
2449 def v4i32: ROTQMBIIVecInst<v4i32>;
2450 def v2i64: ROTQMBIIVecInst<v2i64>;
2451
2452 def r128: ROTQMBIIRegInst<GPRC>;
2453 def r64: ROTQMBIIRegInst<R64C>;
2454}
2455
2456defm ROTQMBII: RotateMaskQuadByBitsImm;
2457
2458//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2459//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002460
2461def ROTMAHv8i16:
2462 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2463 "rotmah\t$rT, $rA, $rB", RotateShift,
2464 [/* see patterns below - $rB must be negated */]>;
2465
Scott Michel97872d32008-02-23 18:41:37 +00002466def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002467 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2468
Scott Michel97872d32008-02-23 18:41:37 +00002469def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002470 (ROTMAHv8i16 VECREG:$rA,
2471 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2472
Scott Michel97872d32008-02-23 18:41:37 +00002473def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002474 (ROTMAHv8i16 VECREG:$rA,
2475 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2476
Scott Michel8b6b4202007-12-04 22:35:58 +00002477def ROTMAHr16:
2478 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2479 "rotmah\t$rT, $rA, $rB", RotateShift,
2480 [/* see patterns below - $rB must be negated */]>;
2481
2482def : Pat<(sra R16C:$rA, R32C:$rB),
2483 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2484
2485def : Pat<(sra R16C:$rA, R16C:$rB),
2486 (ROTMAHr16 R16C:$rA,
2487 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2488
Scott Michel438be252007-12-17 22:32:34 +00002489def : Pat<(sra R16C:$rA, R8C:$rB),
2490 (ROTMAHr16 R16C:$rA,
2491 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2492
Scott Michel8b6b4202007-12-04 22:35:58 +00002493def ROTMAHIv8i16:
2494 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2495 "rotmahi\t$rT, $rA, $val", RotateShift,
2496 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002497 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002498
Scott Michel97872d32008-02-23 18:41:37 +00002499def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002500 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2501
Scott Michel97872d32008-02-23 18:41:37 +00002502def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002503 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2504
Scott Michel8b6b4202007-12-04 22:35:58 +00002505def ROTMAHIr16:
2506 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2507 "rotmahi\t$rT, $rA, $val", RotateShift,
2508 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2509
2510def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2511 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2512
Scott Michel438be252007-12-17 22:32:34 +00002513def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2514 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2515
Scott Michel8b6b4202007-12-04 22:35:58 +00002516def ROTMAv4i32:
2517 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2518 "rotma\t$rT, $rA, $rB", RotateShift,
2519 [/* see patterns below - $rB must be negated */]>;
2520
Scott Michel97872d32008-02-23 18:41:37 +00002521def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002522 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2523
Scott Michel97872d32008-02-23 18:41:37 +00002524def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002525 (ROTMAv4i32 (v4i32 VECREG:$rA),
2526 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2527
Scott Michel97872d32008-02-23 18:41:37 +00002528def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002529 (ROTMAv4i32 (v4i32 VECREG:$rA),
2530 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2531
Scott Michel8b6b4202007-12-04 22:35:58 +00002532def ROTMAr32:
2533 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2534 "rotma\t$rT, $rA, $rB", RotateShift,
2535 [/* see patterns below - $rB must be negated */]>;
2536
2537def : Pat<(sra R32C:$rA, R32C:$rB),
2538 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2539
2540def : Pat<(sra R32C:$rA, R16C:$rB),
2541 (ROTMAr32 R32C:$rA,
2542 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2543
Scott Michel438be252007-12-17 22:32:34 +00002544def : Pat<(sra R32C:$rA, R8C:$rB),
2545 (ROTMAr32 R32C:$rA,
2546 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2547
Scott Michel8b6b4202007-12-04 22:35:58 +00002548def ROTMAIv4i32:
2549 RRForm<0b01011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2550 "rotmai\t$rT, $rA, $val", RotateShift,
2551 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002552 (SPUvec_sra VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002553
Scott Michel97872d32008-02-23 18:41:37 +00002554def : Pat<(SPUvec_sra VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002555 (ROTMAIv4i32 VECREG:$rA, uimm7:$val)>;
2556
2557def ROTMAIr32:
2558 RRForm<0b01011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2559 "rotmai\t$rT, $rA, $val", RotateShift,
2560 [(set R32C:$rT, (sra R32C:$rA, (i32 uimm7:$val)))]>;
2561
2562def : Pat<(sra R32C:$rA, (i16 uimm7:$val)),
2563 (ROTMAIr32 R32C:$rA, uimm7:$val)>;
2564
Scott Michel438be252007-12-17 22:32:34 +00002565def : Pat<(sra R32C:$rA, (i8 uimm7:$val)),
2566 (ROTMAIr32 R32C:$rA, uimm7:$val)>;
2567
Scott Michel8b6b4202007-12-04 22:35:58 +00002568//===----------------------------------------------------------------------===//
2569// Branch and conditionals:
2570//===----------------------------------------------------------------------===//
2571
2572let isTerminator = 1, isBarrier = 1 in {
2573 // Halt If Equal (r32 preferred slot only, no vector form)
2574 def HEQr32:
2575 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2576 "heq\t$rA, $rB", BranchResolv,
2577 [/* no pattern to match */]>;
2578
2579 def HEQIr32 :
2580 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2581 "heqi\t$rA, $val", BranchResolv,
2582 [/* no pattern to match */]>;
2583
2584 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2585 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2586 def HGTr32:
2587 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2588 "hgt\t$rA, $rB", BranchResolv,
2589 [/* no pattern to match */]>;
2590
2591 def HGTIr32:
2592 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2593 "hgti\t$rA, $val", BranchResolv,
2594 [/* no pattern to match */]>;
2595
2596 def HLGTr32:
2597 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2598 "hlgt\t$rA, $rB", BranchResolv,
2599 [/* no pattern to match */]>;
2600
2601 def HLGTIr32:
2602 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2603 "hlgti\t$rA, $val", BranchResolv,
2604 [/* no pattern to match */]>;
2605}
2606
Scott Michel97872d32008-02-23 18:41:37 +00002607//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002608// Comparison operators:
Scott Michel97872d32008-02-23 18:41:37 +00002609//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002610
Scott Michel97872d32008-02-23 18:41:37 +00002611class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2612 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2613 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002614
Scott Michel97872d32008-02-23 18:41:37 +00002615multiclass CmpEqualByte
2616{
2617 def v16i8 :
2618 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2619 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2620 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002621
Scott Michel97872d32008-02-23 18:41:37 +00002622 def r8 :
2623 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2624 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2625}
Scott Michel8b6b4202007-12-04 22:35:58 +00002626
Scott Michel97872d32008-02-23 18:41:37 +00002627class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2628 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2629 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002630
Scott Michel97872d32008-02-23 18:41:37 +00002631multiclass CmpEqualByteImm
2632{
2633 def v16i8 :
2634 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2635 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2636 v16i8SExt8Imm:$val))]>;
2637 def r8:
2638 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2639 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2640}
Scott Michel8b6b4202007-12-04 22:35:58 +00002641
Scott Michel97872d32008-02-23 18:41:37 +00002642class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2643 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2644 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002645
Scott Michel97872d32008-02-23 18:41:37 +00002646multiclass CmpEqualHalfword
2647{
2648 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2649 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2650 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002651
Scott Michel97872d32008-02-23 18:41:37 +00002652 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2653 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2654}
Scott Michel8b6b4202007-12-04 22:35:58 +00002655
Scott Michel97872d32008-02-23 18:41:37 +00002656class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2657 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2658 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002659
Scott Michel97872d32008-02-23 18:41:37 +00002660multiclass CmpEqualHalfwordImm
2661{
2662 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2663 [(set (v8i16 VECREG:$rT),
2664 (seteq (v8i16 VECREG:$rA),
2665 (v8i16 v8i16SExt10Imm:$val)))]>;
2666 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2667 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2668}
Scott Michel8b6b4202007-12-04 22:35:58 +00002669
Scott Michel97872d32008-02-23 18:41:37 +00002670class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2671 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2672 ByteOp, pattern>;
2673
2674multiclass CmpEqualWord
2675{
2676 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2677 [(set (v4i32 VECREG:$rT),
2678 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2679
2680 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2681 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
2682}
2683
2684class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
2685 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
2686 ByteOp, pattern>;
2687
2688multiclass CmpEqualWordImm
2689{
2690 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2691 [(set (v4i32 VECREG:$rT),
2692 (seteq (v4i32 VECREG:$rA),
2693 (v4i32 v4i32SExt16Imm:$val)))]>;
2694
2695 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2696 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
2697}
2698
2699class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
2700 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
2701 ByteOp, pattern>;
2702
2703multiclass CmpGtrByte
2704{
2705 def v16i8 :
2706 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2707 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2708 (v8i16 VECREG:$rB)))]>;
2709
2710 def r8 :
2711 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2712 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
2713}
2714
2715class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
2716 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
2717 ByteOp, pattern>;
2718
2719multiclass CmpGtrByteImm
2720{
2721 def v16i8 :
2722 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2723 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
2724 v16i8SExt8Imm:$val))]>;
2725 def r8:
2726 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
Scott Michel7833d472008-03-20 00:51:36 +00002727 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002728}
2729
2730class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
2731 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
2732 ByteOp, pattern>;
2733
2734multiclass CmpGtrHalfword
2735{
2736 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2737 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2738 (v8i16 VECREG:$rB)))]>;
2739
2740 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2741 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
2742}
2743
2744class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
2745 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
2746 ByteOp, pattern>;
2747
2748multiclass CmpGtrHalfwordImm
2749{
2750 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2751 [(set (v8i16 VECREG:$rT),
2752 (setgt (v8i16 VECREG:$rA),
2753 (v8i16 v8i16SExt10Imm:$val)))]>;
2754 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2755 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
2756}
2757
2758class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
2759 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
2760 ByteOp, pattern>;
2761
2762multiclass CmpGtrWord
2763{
2764 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2765 [(set (v4i32 VECREG:$rT),
2766 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2767
2768 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2769 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
2770}
2771
2772class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
2773 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
2774 ByteOp, pattern>;
2775
2776multiclass CmpGtrWordImm
2777{
2778 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2779 [(set (v4i32 VECREG:$rT),
2780 (setgt (v4i32 VECREG:$rA),
2781 (v4i32 v4i32SExt16Imm:$val)))]>;
2782
2783 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2784 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
2785}
2786
2787class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002788 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002789 ByteOp, pattern>;
2790
2791multiclass CmpLGtrByte
2792{
2793 def v16i8 :
2794 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2795 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2796 (v8i16 VECREG:$rB)))]>;
2797
2798 def r8 :
2799 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2800 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
2801}
2802
2803class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002804 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002805 ByteOp, pattern>;
2806
2807multiclass CmpLGtrByteImm
2808{
2809 def v16i8 :
2810 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2811 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
2812 v16i8SExt8Imm:$val))]>;
2813 def r8:
2814 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2815 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
2816}
2817
2818class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002819 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002820 ByteOp, pattern>;
2821
2822multiclass CmpLGtrHalfword
2823{
2824 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2825 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2826 (v8i16 VECREG:$rB)))]>;
2827
2828 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2829 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
2830}
2831
2832class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002833 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002834 ByteOp, pattern>;
2835
2836multiclass CmpLGtrHalfwordImm
2837{
2838 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2839 [(set (v8i16 VECREG:$rT),
2840 (setugt (v8i16 VECREG:$rA),
2841 (v8i16 v8i16SExt10Imm:$val)))]>;
2842 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2843 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
2844}
2845
2846class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002847 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002848 ByteOp, pattern>;
2849
2850multiclass CmpLGtrWord
2851{
2852 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2853 [(set (v4i32 VECREG:$rT),
2854 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2855
2856 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2857 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
2858}
2859
2860class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002861 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002862 ByteOp, pattern>;
2863
2864multiclass CmpLGtrWordImm
2865{
2866 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2867 [(set (v4i32 VECREG:$rT),
2868 (setugt (v4i32 VECREG:$rA),
2869 (v4i32 v4i32SExt16Imm:$val)))]>;
2870
2871 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00002872 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002873}
2874
2875defm CEQB : CmpEqualByte;
2876defm CEQBI : CmpEqualByteImm;
2877defm CEQH : CmpEqualHalfword;
2878defm CEQHI : CmpEqualHalfwordImm;
2879defm CEQ : CmpEqualWord;
2880defm CEQI : CmpEqualWordImm;
2881defm CGTB : CmpGtrByte;
2882defm CGTBI : CmpGtrByteImm;
2883defm CGTH : CmpGtrHalfword;
2884defm CGTHI : CmpGtrHalfwordImm;
2885defm CGT : CmpGtrWord;
2886defm CGTI : CmpGtrWordImm;
2887defm CLGTB : CmpLGtrByte;
2888defm CLGTBI : CmpLGtrByteImm;
2889defm CLGTH : CmpLGtrHalfword;
2890defm CLGTHI : CmpLGtrHalfwordImm;
2891defm CLGT : CmpLGtrWord;
2892defm CLGTI : CmpLGtrWordImm;
2893
Scott Michel53ab7792008-03-10 16:58:52 +00002894//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00002895// For SETCC primitives not supported above (setlt, setle, setge, etc.)
2896// define a pattern to generate the right code, as a binary operator
2897// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00002898//
2899// N.B.: This only matches the setcc set of conditionals. Special pattern
2900// matching is used for select conditionals.
2901//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00002902
Scott Michel53ab7792008-03-10 16:58:52 +00002903class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
2904 SPUInstr xorinst, SPUInstr cmpare>:
2905 Pat<(cond rclass:$rA, rclass:$rB),
2906 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
2907
2908class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
2909 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
2910 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
2911 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
2912
2913def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
2914def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
2915
2916def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
2917def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
2918
2919def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
2920def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00002921
2922class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
2923 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
2924 Pat<(cond rclass:$rA, rclass:$rB),
2925 (binop (cmpOp1 rclass:$rA, rclass:$rB),
2926 (cmpOp2 rclass:$rA, rclass:$rB))>;
2927
2928class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
2929 ValueType immtype,
2930 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
2931 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
2932 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
2933 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
2934
Scott Michel53ab7792008-03-10 16:58:52 +00002935def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
2936def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
2937def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
2938def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
2939def : Pat<(setle R8C:$rA, R8C:$rB),
2940 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
2941def : Pat<(setle R8C:$rA, immU8:$imm),
2942 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002943
Scott Michel53ab7792008-03-10 16:58:52 +00002944def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
2945def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
2946 ORr16, CGTHIr16, CEQHIr16>;
2947def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
2948def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
2949def : Pat<(setle R16C:$rA, R16C:$rB),
2950 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
2951def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
2952 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002953
Scott Michel53ab7792008-03-10 16:58:52 +00002954def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
2955def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
2956 ORr32, CGTIr32, CEQIr32>;
2957def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
2958def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
2959def : Pat<(setle R32C:$rA, R32C:$rB),
2960 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
2961def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
2962 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002963
Scott Michel53ab7792008-03-10 16:58:52 +00002964def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
2965def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
2966def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
2967def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
2968def : Pat<(setule R8C:$rA, R8C:$rB),
2969 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
2970def : Pat<(setule R8C:$rA, immU8:$imm),
2971 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002972
Scott Michel53ab7792008-03-10 16:58:52 +00002973def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
2974def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
2975 ORr16, CLGTHIr16, CEQHIr16>;
2976def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
2977def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
2978 CLGTHIr16, CEQHIr16>;
2979def : Pat<(setule R16C:$rA, R16C:$rB),
2980 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
Scott Michel7833d472008-03-20 00:51:36 +00002981def : Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
Scott Michel53ab7792008-03-10 16:58:52 +00002982 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002983
Scott Michel53ab7792008-03-10 16:58:52 +00002984def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00002985def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
Scott Michel53ab7792008-03-10 16:58:52 +00002986 ORr32, CLGTIr32, CEQIr32>;
2987def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
Scott Michel7833d472008-03-20 00:51:36 +00002988def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
Scott Michel53ab7792008-03-10 16:58:52 +00002989def : Pat<(setule R32C:$rA, R32C:$rB),
2990 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
2991def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
2992 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002993
Scott Michel53ab7792008-03-10 16:58:52 +00002994//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2995// select conditional patterns:
2996//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2997
2998class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
2999 SPUInstr selinstr, SPUInstr cmpare>:
3000 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3001 rclass:$rTrue, rclass:$rFalse),
3002 (selinstr rclass:$rTrue, rclass:$rFalse,
3003 (cmpare rclass:$rA, rclass:$rB))>;
3004
3005class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3006 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3007 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
3008 rclass:$rTrue, rclass:$rFalse),
3009 (selinstr rclass:$rTrue, rclass:$rFalse,
3010 (cmpare rclass:$rA, immpred:$imm))>;
3011
3012def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3013def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3014def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3015def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3016def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3017def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3018
3019def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3020def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3021def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3022def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3023def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3024def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3025
3026def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3027def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3028def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3029def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3030def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3031def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3032
3033class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3034 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3035 SPUInstr cmpOp2>:
3036 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3037 rclass:$rFalse, rclass:$rTrue),
3038 (selinstr rclass:$rTrue, rclass:$rFalse,
3039 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3040 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3041
3042class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3043 ValueType inttype,
3044 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3045 SPUInstr cmpOp2>:
3046 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
3047 rclass:$rTrue, rclass:$rFalse),
3048 (selinstr rclass:$rFalse, rclass:$rTrue,
3049 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3050 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3051
3052def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3053def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3054 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3055
3056def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3057def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3058 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3059
3060def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3061def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3062 SELBr32, ORr32, CGTIr32, CEQIr32>;
3063
3064def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3065def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3066 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3067
3068def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3069def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3070 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3071
3072def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3073def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3074 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003075
3076//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003077
3078let isCall = 1,
3079 // All calls clobber the non-callee-saved registers:
3080 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3081 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3082 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3083 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3084 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3085 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3086 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3087 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3088 // All of these instructions use $lr (aka $0)
3089 Uses = [R0] in {
3090 // Branch relative and set link: Used if we actually know that the target
3091 // is within [-32768, 32767] bytes of the target
3092 def BRSL:
3093 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3094 "brsl\t$$lr, $func",
3095 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3096
3097 // Branch absolute and set link: Used if we actually know that the target
3098 // is an absolute address
3099 def BRASL:
3100 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3101 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003102 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003103
3104 // Branch indirect and set link if external data. These instructions are not
3105 // actually generated, matched by an intrinsic:
3106 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3107 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3108 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3109 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3110
3111 // Branch indirect and set link. This is the "X-form" address version of a
3112 // function call
3113 def BISL:
3114 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3115}
3116
3117// Unconditional branches:
3118let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3119 def BR :
3120 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3121 "br\t$dest",
3122 [(br bb:$dest)]>;
3123
3124 // Unconditional, absolute address branch
3125 def BRA:
3126 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3127 "bra\t$dest",
3128 [/* no pattern */]>;
3129
3130 // Indirect branch
3131 def BI:
3132 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3133
3134 // Various branches:
3135 def BRNZ:
3136 RI16Form<0b010000100, (outs), (ins R32C:$rCond, brtarget:$dest),
3137 "brnz\t$rCond,$dest",
3138 BranchResolv,
3139 [(brcond R32C:$rCond, bb:$dest)]>;
3140
3141 def BRZ:
3142 RI16Form<0b000000100, (outs), (ins R32C:$rT, brtarget:$dest),
3143 "brz\t$rT,$dest",
3144 BranchResolv,
3145 [/* no pattern */]>;
3146
3147 def BRHNZ:
3148 RI16Form<0b011000100, (outs), (ins R16C:$rCond, brtarget:$dest),
3149 "brhnz\t$rCond,$dest",
3150 BranchResolv,
3151 [(brcond R16C:$rCond, bb:$dest)]>;
3152
3153 def BRHZ:
3154 RI16Form<0b001000100, (outs), (ins R16C:$rT, brtarget:$dest),
3155 "brhz\t$rT,$dest",
3156 BranchResolv,
3157 [/* no pattern */]>;
3158
3159/*
3160 def BINZ:
3161 BICondForm<0b10010100100, "binz\t$rA, $func",
3162 [(SPUbinz R32C:$rA, R32C:$func)]>;
3163
3164 def BIZ:
3165 BICondForm<0b00010100100, "biz\t$rA, $func",
3166 [(SPUbiz R32C:$rA, R32C:$func)]>;
3167*/
3168}
3169
Scott Michel394e26d2008-01-17 20:38:41 +00003170//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003171// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003172//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003173
Scott Michel8b6b4202007-12-04 22:35:58 +00003174def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3175 (BRHZ R16C:$rA, bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003176def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3177 (BRHNZ R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003178
3179def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3180 (BRZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003181def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
Scott Michel394e26d2008-01-17 20:38:41 +00003182 (BRNZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003183
Scott Michel97872d32008-02-23 18:41:37 +00003184multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3185{
3186 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3187 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003188
Scott Michel97872d32008-02-23 18:41:37 +00003189 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3190 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3191
3192 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3193 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3194
3195 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3196 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3197}
3198
3199defm BRCONDeq : BranchCondEQ<seteq, BRHZ, BRZ>;
3200defm BRCONDne : BranchCondEQ<setne, BRHNZ, BRNZ>;
3201
3202multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3203{
3204 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3205 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3206
3207 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3208 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3209
3210 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3211 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3212
3213 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3214 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3215}
3216
3217defm BRCONDugt : BranchCondLGT<setugt, BRHNZ, BRNZ>;
3218defm BRCONDule : BranchCondLGT<setule, BRHZ, BRZ>;
3219
3220multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3221 SPUInstr orinst32, SPUInstr brinst32>
3222{
3223 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3224 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3225 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3226 bb:$dest)>;
3227
3228 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3229 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3230 (CEQHr16 R16C:$rA, R16:$rB)),
3231 bb:$dest)>;
3232
3233 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3234 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3235 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3236 bb:$dest)>;
3237
3238 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3239 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3240 (CEQr32 R32C:$rA, R32C:$rB)),
3241 bb:$dest)>;
3242}
3243
3244defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZ, ORr32, BRNZ>;
3245defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZ, ORr32, BRZ>;
3246
3247multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3248{
3249 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3250 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3251
3252 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3253 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3254
3255 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3256 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3257
3258 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3259 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3260}
3261
3262defm BRCONDgt : BranchCondGT<setgt, BRHNZ, BRNZ>;
3263defm BRCONDle : BranchCondGT<setle, BRHZ, BRZ>;
3264
3265multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3266 SPUInstr orinst32, SPUInstr brinst32>
3267{
3268 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3269 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3270 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3271 bb:$dest)>;
3272
3273 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3274 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3275 (CEQHr16 R16C:$rA, R16:$rB)),
3276 bb:$dest)>;
3277
3278 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3279 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3280 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3281 bb:$dest)>;
3282
3283 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3284 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3285 (CEQr32 R32C:$rA, R32C:$rB)),
3286 bb:$dest)>;
3287}
3288
3289defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZ, ORr32, BRNZ>;
3290defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZ, ORr32, BRZ>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003291
Scott Michel8b6b4202007-12-04 22:35:58 +00003292let isTerminator = 1, isBarrier = 1 in {
3293 let isReturn = 1 in {
3294 def RET:
3295 RETForm<"bi\t$$lr", [(retflag)]>;
3296 }
3297}
3298
3299//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003300// Single precision floating point instructions
3301//===----------------------------------------------------------------------===//
3302
3303def FAv4f32:
3304 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3305 "fa\t$rT, $rA, $rB", SPrecFP,
3306 [(set (v4f32 VECREG:$rT), (fadd (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3307
3308def FAf32 :
3309 RRForm<0b00100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3310 "fa\t$rT, $rA, $rB", SPrecFP,
3311 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3312
3313def FSv4f32:
3314 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3315 "fs\t$rT, $rA, $rB", SPrecFP,
3316 [(set (v4f32 VECREG:$rT), (fsub (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3317
3318def FSf32 :
3319 RRForm<0b10100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3320 "fs\t$rT, $rA, $rB", SPrecFP,
3321 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3322
3323// Floating point reciprocal estimate
3324def FREv4f32 :
3325 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3326 "frest\t$rT, $rA", SPrecFP,
3327 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3328
3329def FREf32 :
3330 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3331 "frest\t$rT, $rA", SPrecFP,
3332 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3333
3334// Floating point interpolate (used in conjunction with reciprocal estimate)
3335def FIv4f32 :
3336 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3337 "fi\t$rT, $rA, $rB", SPrecFP,
3338 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3339 (v4f32 VECREG:$rB)))]>;
3340
3341def FIf32 :
3342 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3343 "fi\t$rT, $rA, $rB", SPrecFP,
3344 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3345
3346// Floating Compare Equal
3347def FCEQf32 :
3348 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3349 "fceq\t$rT, $rA, $rB", SPrecFP,
3350 [(set R32C:$rT, (setoeq R32FP:$rA, R32FP:$rB))]>;
3351
3352def FCMEQf32 :
3353 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3354 "fcmeq\t$rT, $rA, $rB", SPrecFP,
3355 [(set R32C:$rT, (setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3356
3357def FCGTf32 :
3358 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3359 "fcgt\t$rT, $rA, $rB", SPrecFP,
3360 [(set R32C:$rT, (setogt R32FP:$rA, R32FP:$rB))]>;
3361
3362def FCMGTf32 :
3363 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3364 "fcmgt\t$rT, $rA, $rB", SPrecFP,
3365 [(set R32C:$rT, (setogt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3366
3367// FP Status and Control Register Write
3368// Why isn't rT a don't care in the ISA?
3369// Should we create a special RRForm_3 for this guy and zero out the rT?
3370def FSCRWf32 :
3371 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3372 "fscrwr\t$rA", SPrecFP,
3373 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3374
3375// FP Status and Control Register Read
3376def FSCRRf32 :
3377 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3378 "fscrrd\t$rT", SPrecFP,
3379 [/* This instruction requires an intrinsic */]>;
3380
3381// llvm instruction space
3382// How do these map onto cell instructions?
3383// fdiv rA rB
3384// frest rC rB # c = 1/b (both lines)
3385// fi rC rB rC
3386// fm rD rA rC # d = a * 1/b
3387// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3388// fma rB rB rC rD # b = b * c + d
3389// = -(d *b -a) * c + d
3390// = a * c - c ( a *b *c - a)
3391
3392// fcopysign (???)
3393
3394// Library calls:
3395// These llvm instructions will actually map to library calls.
3396// All that's needed, then, is to check that the appropriate library is
3397// imported and do a brsl to the proper function name.
3398// frem # fmod(x, y): x - (x/y) * y
3399// (Note: fmod(double, double), fmodf(float,float)
3400// fsqrt?
3401// fsin?
3402// fcos?
3403// Unimplemented SPU instruction space
3404// floating reciprocal absolute square root estimate (frsqest)
3405
3406// The following are probably just intrinsics
3407// status and control register write
3408// status and control register read
3409
3410//--------------------------------------
3411// Floating point multiply instructions
3412//--------------------------------------
3413
3414def FMv4f32:
3415 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3416 "fm\t$rT, $rA, $rB", SPrecFP,
3417 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3418 (v4f32 VECREG:$rB)))]>;
3419
3420def FMf32 :
3421 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3422 "fm\t$rT, $rA, $rB", SPrecFP,
3423 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3424
3425// Floating point multiply and add
3426// e.g. d = c + (a * b)
3427def FMAv4f32:
3428 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3429 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3430 [(set (v4f32 VECREG:$rT),
3431 (fadd (v4f32 VECREG:$rC),
3432 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3433
3434def FMAf32:
3435 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3436 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3437 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3438
3439// FP multiply and subtract
3440// Subtracts value in rC from product
3441// res = a * b - c
3442def FMSv4f32 :
3443 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3444 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3445 [(set (v4f32 VECREG:$rT),
3446 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3447 (v4f32 VECREG:$rC)))]>;
3448
3449def FMSf32 :
3450 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3451 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3452 [(set R32FP:$rT,
3453 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3454
3455// Floating Negative Mulitply and Subtract
3456// Subtracts product from value in rC
3457// res = fneg(fms a b c)
3458// = - (a * b - c)
3459// = c - a * b
3460// NOTE: subtraction order
3461// fsub a b = a - b
3462// fs a b = b - a?
3463def FNMSf32 :
3464 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3465 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3466 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3467
3468def FNMSv4f32 :
3469 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3470 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3471 [(set (v4f32 VECREG:$rT),
3472 (fsub (v4f32 VECREG:$rC),
3473 (fmul (v4f32 VECREG:$rA),
3474 (v4f32 VECREG:$rB))))]>;
3475
3476//--------------------------------------
3477// Floating Point Conversions
3478// Signed conversions:
3479def CSiFv4f32:
3480 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3481 "csflt\t$rT, $rA, 0", SPrecFP,
3482 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3483
3484// Convert signed integer to floating point
3485def CSiFf32 :
3486 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3487 "csflt\t$rT, $rA, 0", SPrecFP,
3488 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3489
3490// Convert unsigned into to float
3491def CUiFv4f32 :
3492 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3493 "cuflt\t$rT, $rA, 0", SPrecFP,
3494 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3495
3496def CUiFf32 :
3497 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3498 "cuflt\t$rT, $rA, 0", SPrecFP,
3499 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3500
3501// Convert float to unsigned int
3502// Assume that scale = 0
3503
3504def CFUiv4f32 :
3505 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3506 "cfltu\t$rT, $rA, 0", SPrecFP,
3507 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3508
3509def CFUif32 :
3510 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3511 "cfltu\t$rT, $rA, 0", SPrecFP,
3512 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3513
3514// Convert float to signed int
3515// Assume that scale = 0
3516
3517def CFSiv4f32 :
3518 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3519 "cflts\t$rT, $rA, 0", SPrecFP,
3520 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
3521
3522def CFSif32 :
3523 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3524 "cflts\t$rT, $rA, 0", SPrecFP,
3525 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
3526
3527//===----------------------------------------------------------------------==//
3528// Single<->Double precision conversions
3529//===----------------------------------------------------------------------==//
3530
3531// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
3532// v4f32, output is v2f64--which goes in the name?)
3533
3534// Floating point extend single to double
3535// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
3536// operates on two double-word slots (i.e. 1st and 3rd fp numbers
3537// are ignored).
3538def FESDvec :
3539 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3540 "fesd\t$rT, $rA", SPrecFP,
3541 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
3542
3543def FESDf32 :
3544 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
3545 "fesd\t$rT, $rA", SPrecFP,
3546 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
3547
3548// Floating point round double to single
3549//def FRDSvec :
3550// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3551// "frds\t$rT, $rA,", SPrecFP,
3552// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
3553
3554def FRDSf64 :
3555 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
3556 "frds\t$rT, $rA", SPrecFP,
3557 [(set R32FP:$rT, (fround R64FP:$rA))]>;
3558
3559//ToDo include anyextend?
3560
3561//===----------------------------------------------------------------------==//
3562// Double precision floating point instructions
3563//===----------------------------------------------------------------------==//
3564def FAf64 :
3565 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3566 "dfa\t$rT, $rA, $rB", DPrecFP,
3567 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
3568
3569def FAv2f64 :
3570 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3571 "dfa\t$rT, $rA, $rB", DPrecFP,
3572 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3573
3574def FSf64 :
3575 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3576 "dfs\t$rT, $rA, $rB", DPrecFP,
3577 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
3578
3579def FSv2f64 :
3580 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3581 "dfs\t$rT, $rA, $rB", DPrecFP,
3582 [(set (v2f64 VECREG:$rT),
3583 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3584
3585def FMf64 :
3586 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3587 "dfm\t$rT, $rA, $rB", DPrecFP,
3588 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
3589
3590def FMv2f64:
3591 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3592 "dfm\t$rT, $rA, $rB", DPrecFP,
3593 [(set (v2f64 VECREG:$rT),
3594 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3595
3596def FMAf64:
3597 RRForm<0b00111010110, (outs R64FP:$rT),
3598 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3599 "dfma\t$rT, $rA, $rB", DPrecFP,
3600 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3601 RegConstraint<"$rC = $rT">,
3602 NoEncode<"$rC">;
3603
3604def FMAv2f64:
3605 RRForm<0b00111010110, (outs VECREG:$rT),
3606 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3607 "dfma\t$rT, $rA, $rB", DPrecFP,
3608 [(set (v2f64 VECREG:$rT),
3609 (fadd (v2f64 VECREG:$rC),
3610 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
3611 RegConstraint<"$rC = $rT">,
3612 NoEncode<"$rC">;
3613
3614def FMSf64 :
3615 RRForm<0b10111010110, (outs R64FP:$rT),
3616 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3617 "dfms\t$rT, $rA, $rB", DPrecFP,
3618 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
3619 RegConstraint<"$rC = $rT">,
3620 NoEncode<"$rC">;
3621
3622def FMSv2f64 :
3623 RRForm<0b10111010110, (outs VECREG:$rT),
3624 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3625 "dfms\t$rT, $rA, $rB", DPrecFP,
3626 [(set (v2f64 VECREG:$rT),
3627 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3628 (v2f64 VECREG:$rC)))]>;
3629
3630// FNMS: - (a * b - c)
3631// - (a * b) + c => c - (a * b)
3632def FNMSf64 :
3633 RRForm<0b01111010110, (outs R64FP:$rT),
3634 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3635 "dfnms\t$rT, $rA, $rB", DPrecFP,
3636 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3637 RegConstraint<"$rC = $rT">,
3638 NoEncode<"$rC">;
3639
3640def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
3641 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
3642
3643def FNMSv2f64 :
3644 RRForm<0b01111010110, (outs VECREG:$rT),
3645 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3646 "dfnms\t$rT, $rA, $rB", DPrecFP,
3647 [(set (v2f64 VECREG:$rT),
3648 (fsub (v2f64 VECREG:$rC),
3649 (fmul (v2f64 VECREG:$rA),
3650 (v2f64 VECREG:$rB))))]>,
3651 RegConstraint<"$rC = $rT">,
3652 NoEncode<"$rC">;
3653
3654def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3655 (v2f64 VECREG:$rC))),
3656 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
3657
3658// - (a * b + c)
3659// - (a * b) - c
3660def FNMAf64 :
3661 RRForm<0b11111010110, (outs R64FP:$rT),
3662 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3663 "dfnma\t$rT, $rA, $rB", DPrecFP,
3664 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
3665 RegConstraint<"$rC = $rT">,
3666 NoEncode<"$rC">;
3667
3668def FNMAv2f64 :
3669 RRForm<0b11111010110, (outs VECREG:$rT),
3670 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3671 "dfnma\t$rT, $rA, $rB", DPrecFP,
3672 [(set (v2f64 VECREG:$rT),
3673 (fneg (fadd (v2f64 VECREG:$rC),
3674 (fmul (v2f64 VECREG:$rA),
3675 (v2f64 VECREG:$rB)))))]>,
3676 RegConstraint<"$rC = $rT">,
3677 NoEncode<"$rC">;
3678
3679//===----------------------------------------------------------------------==//
3680// Floating point negation and absolute value
3681//===----------------------------------------------------------------------==//
3682
3683def : Pat<(fneg (v4f32 VECREG:$rA)),
3684 (XORfnegvec (v4f32 VECREG:$rA),
3685 (v4f32 (ILHUv4i32 0x8000)))>;
3686
3687def : Pat<(fneg R32FP:$rA),
3688 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
3689
3690def : Pat<(fneg (v2f64 VECREG:$rA)),
3691 (XORfnegvec (v2f64 VECREG:$rA),
3692 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
3693
3694def : Pat<(fneg R64FP:$rA),
3695 (XORfneg64 R64FP:$rA,
3696 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
3697
3698// Floating point absolute value
3699
3700def : Pat<(fabs R32FP:$rA),
3701 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
3702
3703def : Pat<(fabs (v4f32 VECREG:$rA)),
3704 (ANDfabsvec (v4f32 VECREG:$rA),
3705 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3706
3707def : Pat<(fabs R64FP:$rA),
3708 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
3709
3710def : Pat<(fabs (v2f64 VECREG:$rA)),
3711 (ANDfabsvec (v2f64 VECREG:$rA),
3712 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3713
3714//===----------------------------------------------------------------------===//
3715// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
3716// in the odd pipeline)
3717//===----------------------------------------------------------------------===//
3718
Scott Michel97872d32008-02-23 18:41:37 +00003719def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003720 let Pattern = [];
3721
3722 let Inst{0-10} = 0b10000000010;
3723 let Inst{11-17} = 0;
3724 let Inst{18-24} = 0;
3725 let Inst{25-31} = 0;
3726}
3727
Scott Michel97872d32008-02-23 18:41:37 +00003728def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003729 let Pattern = [];
3730
3731 let Inst{0-10} = 0b10000000000;
3732 let Inst{11-17} = 0;
3733 let Inst{18-24} = 0;
3734 let Inst{25-31} = 0;
3735}
3736
3737//===----------------------------------------------------------------------===//
3738// Bit conversions (type conversions between vector/packed types)
3739// NOTE: Promotions are handled using the XS* instructions. Truncation
3740// is not handled.
3741//===----------------------------------------------------------------------===//
3742def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
3743def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
3744def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
3745def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
3746def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
3747
3748def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
3749def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
3750def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
3751def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
3752def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
3753
3754def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
3755def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
3756def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
3757def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
3758def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
3759
3760def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
3761def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
3762def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
3763def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
3764def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
3765
3766def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
3767def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
3768def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
3769def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
3770def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
3771
3772def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
3773def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
3774def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
3775def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
3776def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
3777
3778def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00003779def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003780
3781//===----------------------------------------------------------------------===//
3782// Instruction patterns:
3783//===----------------------------------------------------------------------===//
3784
3785// General 32-bit constants:
3786def : Pat<(i32 imm:$imm),
3787 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
3788
3789// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00003790def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00003791 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
3792
3793// General constant 32-bit vectors
3794def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00003795 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
3796 (LO16_vec v4i32Imm:$imm))>;
Scott Michel438be252007-12-17 22:32:34 +00003797
3798// 8-bit constants
3799def : Pat<(i8 imm:$imm),
3800 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003801
3802//===----------------------------------------------------------------------===//
3803// Call instruction patterns:
3804//===----------------------------------------------------------------------===//
3805// Return void
3806def : Pat<(ret),
3807 (RET)>;
3808
3809//===----------------------------------------------------------------------===//
3810// Zero/Any/Sign extensions
3811//===----------------------------------------------------------------------===//
3812
3813// zext 1->32: Zero extend i1 to i32
3814def : Pat<(SPUextract_i1_zext R32C:$rSrc),
3815 (ANDIr32 R32C:$rSrc, 0x1)>;
3816
3817// sext 8->32: Sign extend bytes to words
3818def : Pat<(sext_inreg R32C:$rSrc, i8),
3819 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
3820
Scott Michel438be252007-12-17 22:32:34 +00003821def : Pat<(i32 (sext R8C:$rSrc)),
3822 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
3823
Scott Michel8b6b4202007-12-04 22:35:58 +00003824def : Pat<(SPUextract_i8_sext VECREG:$rSrc),
3825 (XSHWr32 (XSBHr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc),
3826 (v4i32 VECREG:$rSrc))))>;
3827
Scott Michel438be252007-12-17 22:32:34 +00003828// zext 8->16: Zero extend bytes to halfwords
3829def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003830 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00003831
3832// zext 8->32 from preferred slot in load/store
Scott Michel8b6b4202007-12-04 22:35:58 +00003833def : Pat<(SPUextract_i8_zext VECREG:$rSrc),
3834 (ANDIr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc), (v4i32 VECREG:$rSrc)),
3835 0xff)>;
3836
Scott Michel438be252007-12-17 22:32:34 +00003837// zext 8->32: Zero extend bytes to words
3838def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003839 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00003840
3841// anyext 8->16: Extend 8->16 bits, irrespective of sign
3842def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003843 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00003844
3845// anyext 8->32: Extend 8->32 bits, irrespective of sign
3846def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003847 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00003848
Scott Michel97872d32008-02-23 18:41:37 +00003849// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00003850def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003851 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003852
3853def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00003854 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003855
3856def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00003857 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003858
3859def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00003860 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003861
3862// anyext 16->32: Extend 16->32 bits, irrespective of sign
3863def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003864 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003865
3866//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003867// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00003868// low parts in order to load them into a register.
3869//===----------------------------------------------------------------------===//
3870
Scott Michelf9f42e62008-01-29 02:16:57 +00003871def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
3872def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
3873def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
3874def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
3875
3876def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
3877 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00003878 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00003879
Scott Michelf9f42e62008-01-29 02:16:57 +00003880def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
3881 (SPUlo texternalsym:$in, 0)),
3882 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
3883
3884def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
3885 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00003886 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00003887
Scott Michelf9f42e62008-01-29 02:16:57 +00003888def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
3889 (SPUlo tconstpool:$in, 0)),
3890 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
3891
Scott Michelbc5fbc12008-04-30 00:30:08 +00003892def : Pat<(SPUindirect R32C:$sp, i32ImmSExt10:$imm),
3893 (AIr32 R32C:$sp, i32ImmSExt10:$imm)>;
3894
3895def : Pat<(SPUindirect R32C:$sp, imm:$imm),
3896 (Ar32 R32C:$sp,
3897 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm)))>;
3898
Scott Michelf9f42e62008-01-29 02:16:57 +00003899def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
3900 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
3901
3902def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
3903 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
3904
3905def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
3906 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
3907
3908def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
3909 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003910
Scott Michel8b6b4202007-12-04 22:35:58 +00003911// Instrinsics:
3912include "CellSDKIntrinsics.td"