blob: bd288d3bd6a039a04ba5b75372bcdeb06b7a6473 [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 {
25 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm:$amt),
26 "${:comment} ADJCALLSTACKDOWN",
27 [(callseq_start imm:$amt)]>;
28 def ADJCALLSTACKUP : Pseudo<(outs), (ins u16imm:$amt),
29 "${: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
293def CWX : RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
294 "cwx\t$rT, $src", ShuffleOp,
295 [(set (v4i32 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
296
297def CDD : RI7Form<0b11101111100, (outs VECREG:$rT), (ins memri7:$src),
298 "cdd\t$rT, $src", ShuffleOp,
299 [(set (v2i64 VECREG:$rT), (SPUvecinsmask dform2_addr:$src))]>;
300
301def CDX : RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
302 "cdx\t$rT, $src", ShuffleOp,
303 [(set (v2i64 VECREG:$rT), (SPUvecinsmask xform_addr:$src))]>;
304
305//===----------------------------------------------------------------------===//
306// Constant formation:
307//===----------------------------------------------------------------------===//
308
309def ILHv8i16:
310 RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
311 "ilh\t$rT, $val", ImmLoad,
312 [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
313
314def ILHr16:
315 RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
316 "ilh\t$rT, $val", ImmLoad,
317 [(set R16C:$rT, immSExt16:$val)]>;
318
Scott Michel438be252007-12-17 22:32:34 +0000319// Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
320// the right constant")
321def ILHr8:
322 RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
323 "ilh\t$rT, $val", ImmLoad,
324 [(set R8C:$rT, immSExt8:$val)]>;
325
Scott Michel8b6b4202007-12-04 22:35:58 +0000326// IL does sign extension!
Scott Michel8b6b4202007-12-04 22:35:58 +0000327
Scott Michel6baba072008-03-05 23:02:02 +0000328class ILInst<dag OOL, dag IOL, list<dag> pattern>:
329 RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
330 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000331
Scott Michel6baba072008-03-05 23:02:02 +0000332class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
333 ILInst<(outs VECREG:$rT), (ins immtype:$val),
334 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000335
Scott Michel6baba072008-03-05 23:02:02 +0000336class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
337 ILInst<(outs rclass:$rT), (ins immtype:$val),
338 [(set rclass:$rT, xform:$val)]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000339
Scott Michel6baba072008-03-05 23:02:02 +0000340multiclass ImmediateLoad
341{
342 def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
343 def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000344
Scott Michel6baba072008-03-05 23:02:02 +0000345 // TODO: Need v2f64, v4f32
Scott Michel8b6b4202007-12-04 22:35:58 +0000346
Scott Michel6baba072008-03-05 23:02:02 +0000347 def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
348 def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
349 def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
350 def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
351}
Scott Michel8b6b4202007-12-04 22:35:58 +0000352
Scott Michel6baba072008-03-05 23:02:02 +0000353defm IL : ImmediateLoad;
Scott Michel8b6b4202007-12-04 22:35:58 +0000354
Scott Michel6baba072008-03-05 23:02:02 +0000355class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
356 RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
357 ImmLoad, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000358
Scott Michel6baba072008-03-05 23:02:02 +0000359class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
360 ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
361 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
362
363class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
364 ILHUInst<(outs rclass:$rT), (ins immtype:$val),
365 [(set rclass:$rT, xform:$val)]>;
366
367multiclass ImmLoadHalfwordUpper
368{
369 def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
370 def v4i32: ILHUVecInst<v4i32, u16imm, immILHUvec>;
371
372 def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
373 def r32: ILHURegInst<R32C, u16imm, hi16>;
374
375 // Loads the high portion of an address
376 def hi: ILHURegInst<R32C, symbolHi, hi16>;
377
378 // Used in custom lowering constant SFP loads:
379 def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
380}
381
382defm ILHU : ImmLoadHalfwordUpper;
Scott Michel8b6b4202007-12-04 22:35:58 +0000383
384// Immediate load address (can also be used to load 18-bit unsigned constants,
385// see the zext 16->32 pattern)
Scott Michel6baba072008-03-05 23:02:02 +0000386
Scott Michel97872d32008-02-23 18:41:37 +0000387class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
388 RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
389 LoadNOP, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000390
Scott Michel6baba072008-03-05 23:02:02 +0000391class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
392 ILAInst<(outs VECREG:$rT), (ins immtype:$val),
393 [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
394
395class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
396 ILAInst<(outs rclass:$rT), (ins immtype:$val),
397 [(set rclass:$rT, xform:$val)]>;
398
Scott Michel97872d32008-02-23 18:41:37 +0000399multiclass ImmLoadAddress
400{
Scott Michel6baba072008-03-05 23:02:02 +0000401 def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
402 def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000403
Scott Michel6baba072008-03-05 23:02:02 +0000404 def r64: ILARegInst<R64C, u18imm_i64, imm18>;
405 def r32: ILARegInst<R32C, u18imm, imm18>;
406 def f32: ILARegInst<R32FP, f18imm, fpimm18>;
407 def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000408
Scott Michel6baba072008-03-05 23:02:02 +0000409 def lo: ILARegInst<R32C, symbolLo, imm18>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000410
Scott Michel97872d32008-02-23 18:41:37 +0000411 def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
412 [/* no pattern */]>;
413}
414
415defm ILA : ImmLoadAddress;
Scott Michel8b6b4202007-12-04 22:35:58 +0000416
417// Immediate OR, Halfword Lower: The "other" part of loading large constants
418// into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
419// Note that these are really two operand instructions, but they're encoded
420// as three operands with the first two arguments tied-to each other.
421
Scott Michel6baba072008-03-05 23:02:02 +0000422class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
423 RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
424 ImmLoad, pattern>,
425 RegConstraint<"$rS = $rT">,
426 NoEncode<"$rS">;
Scott Michel8b6b4202007-12-04 22:35:58 +0000427
Scott Michel6baba072008-03-05 23:02:02 +0000428class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
429 IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
430 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000431
Scott Michel6baba072008-03-05 23:02:02 +0000432class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
433 IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
434 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000435
Scott Michel6baba072008-03-05 23:02:02 +0000436multiclass ImmOrHalfwordLower
437{
438 def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
439 def v4i32: IOHLVecInst<v4i32, u16imm>;
440
441 def r32: IOHLRegInst<R32C, i32imm>;
442 def f32: IOHLRegInst<R32FP, f32imm>;
443
444 def lo: IOHLRegInst<R32C, symbolLo>;
445}
446
447defm IOHL: ImmOrHalfwordLower;
Scott Micheldbac4cf2008-01-11 02:53:15 +0000448
Scott Michel8b6b4202007-12-04 22:35:58 +0000449// Form select mask for bytes using immediate, used in conjunction with the
450// SELB instruction:
451
Scott Michel6baba072008-03-05 23:02:02 +0000452class FSMBIVec<ValueType vectype>:
453 RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
454 "fsmbi\t$rT, $val",
455 SelectOp,
456 [(set (vectype VECREG:$rT), (SPUfsmbi (i32 immU16:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000457
Scott Michel97872d32008-02-23 18:41:37 +0000458multiclass FormSelectMaskBytesImm
Scott Michelf9f42e62008-01-29 02:16:57 +0000459{
460 def v16i8: FSMBIVec<v16i8>;
461 def v8i16: FSMBIVec<v8i16>;
462 def v4i32: FSMBIVec<v4i32>;
463 def v2i64: FSMBIVec<v2i64>;
464}
Scott Michel8b6b4202007-12-04 22:35:58 +0000465
Scott Michel97872d32008-02-23 18:41:37 +0000466defm FSMBI : FormSelectMaskBytesImm;
467
468// fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
469def FSMB:
470 RRForm_1<0b01101101100, (outs VECREG:$rT), (ins R16C:$rA),
Scott Michel6baba072008-03-05 23:02:02 +0000471 "fsmb\t$rT, $rA", SelectOp,
472 [(set (v16i8 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000473
474// fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
475// only 8-bits wide (even though it's input as 16-bits here)
476def FSMH:
477 RRForm_1<0b10101101100, (outs VECREG:$rT), (ins R16C:$rA),
478 "fsmh\t$rT, $rA", SelectOp,
Scott Michel6baba072008-03-05 23:02:02 +0000479 [(set (v8i16 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel97872d32008-02-23 18:41:37 +0000480
481// fsm: Form select mask for words. Like the other fsm* instructions,
482// only the lower 4 bits of $rA are significant.
483def FSM:
484 RRForm_1<0b00101101100, (outs VECREG:$rT), (ins R16C:$rA),
485 "fsm\t$rT, $rA", SelectOp,
Scott Michel6baba072008-03-05 23:02:02 +0000486 [(set (v4i32 VECREG:$rT), (SPUfsmbi R16C:$rA))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000487
488//===----------------------------------------------------------------------===//
489// Integer and Logical Operations:
490//===----------------------------------------------------------------------===//
491
492def AHv8i16:
493 RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
494 "ah\t$rT, $rA, $rB", IntegerOp,
495 [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
496
497def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
498 (AHv8i16 VECREG:$rA, VECREG:$rB)>;
499
Scott Michel8b6b4202007-12-04 22:35:58 +0000500def AHr16:
501 RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
502 "ah\t$rT, $rA, $rB", IntegerOp,
503 [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
504
505def AHIvec:
506 RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
507 "ahi\t$rT, $rA, $val", IntegerOp,
508 [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
509 v8i16SExt10Imm:$val))]>;
510
Scott Michel97872d32008-02-23 18:41:37 +0000511def AHIr16:
512 RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
513 "ahi\t$rT, $rA, $val", IntegerOp,
514 [(set R16C:$rT, (add R16C:$rA, v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000515
Scott Michel97872d32008-02-23 18:41:37 +0000516def Avec:
517 RRForm<0b00000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
518 "a\t$rT, $rA, $rB", IntegerOp,
519 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000520
521def : Pat<(add (v16i8 VECREG:$rA), (v16i8 VECREG:$rB)),
522 (Avec VECREG:$rA, VECREG:$rB)>;
523
Scott Michel97872d32008-02-23 18:41:37 +0000524def Ar32:
525 RRForm<0b00000011000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
526 "a\t$rT, $rA, $rB", IntegerOp,
527 [(set R32C:$rT, (add R32C:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000528
Scott Michel438be252007-12-17 22:32:34 +0000529def Ar8:
530 RRForm<0b00000011000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
531 "a\t$rT, $rA, $rB", IntegerOp,
532 [(set R8C:$rT, (add R8C:$rA, R8C:$rB))]>;
533
Scott Michel8b6b4202007-12-04 22:35:58 +0000534def AIvec:
535 RI10Form<0b00111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
536 "ai\t$rT, $rA, $val", IntegerOp,
537 [(set (v4i32 VECREG:$rT), (add (v4i32 VECREG:$rA),
538 v4i32SExt10Imm:$val))]>;
539
Scott Michel438be252007-12-17 22:32:34 +0000540def AIr32:
541 RI10Form<0b00111000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
542 "ai\t$rT, $rA, $val", IntegerOp,
543 [(set R32C:$rT, (add R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000544
Scott Michel438be252007-12-17 22:32:34 +0000545def SFHvec:
546 RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
547 "sfh\t$rT, $rA, $rB", IntegerOp,
548 [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
549 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000550
Scott Michel438be252007-12-17 22:32:34 +0000551def SFHr16:
552 RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
553 "sfh\t$rT, $rA, $rB", IntegerOp,
554 [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000555
556def SFHIvec:
557 RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
558 "sfhi\t$rT, $rA, $val", IntegerOp,
559 [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
560 (v8i16 VECREG:$rA)))]>;
561
562def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
563 "sfhi\t$rT, $rA, $val", IntegerOp,
564 [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
565
566def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
567 (ins VECREG:$rA, VECREG:$rB),
568 "sf\t$rT, $rA, $rB", IntegerOp,
569 [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
570
571def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
572 "sf\t$rT, $rA, $rB", IntegerOp,
573 [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
574
575def SFIvec:
576 RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
577 "sfi\t$rT, $rA, $val", IntegerOp,
578 [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
579 (v4i32 VECREG:$rA)))]>;
580
581def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
582 (ins R32C:$rA, s10imm_i32:$val),
583 "sfi\t$rT, $rA, $val", IntegerOp,
584 [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
585
586// ADDX: only available in vector form, doesn't match a pattern.
587def ADDXvec:
588 RRForm<0b00000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
589 VECREG:$rCarry),
590 "addx\t$rT, $rA, $rB", IntegerOp,
591 []>,
592 RegConstraint<"$rCarry = $rT">,
593 NoEncode<"$rCarry">;
594
595// CG: only available in vector form, doesn't match a pattern.
596def CGvec:
597 RRForm<0b01000011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
598 VECREG:$rCarry),
599 "cg\t$rT, $rA, $rB", IntegerOp,
600 []>,
601 RegConstraint<"$rCarry = $rT">,
602 NoEncode<"$rCarry">;
603
604// SFX: only available in vector form, doesn't match a pattern
605def SFXvec:
606 RRForm<0b10000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
607 VECREG:$rCarry),
608 "sfx\t$rT, $rA, $rB", IntegerOp,
609 []>,
610 RegConstraint<"$rCarry = $rT">,
611 NoEncode<"$rCarry">;
612
613// BG: only available in vector form, doesn't match a pattern.
614def BGvec:
615 RRForm<0b01000010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
616 VECREG:$rCarry),
617 "bg\t$rT, $rA, $rB", IntegerOp,
618 []>,
619 RegConstraint<"$rCarry = $rT">,
620 NoEncode<"$rCarry">;
621
622// BGX: only available in vector form, doesn't match a pattern.
623def BGXvec:
624 RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
625 VECREG:$rCarry),
626 "bgx\t$rT, $rA, $rB", IntegerOp,
627 []>,
628 RegConstraint<"$rCarry = $rT">,
629 NoEncode<"$rCarry">;
630
631// Halfword multiply variants:
632// N.B: These can be used to build up larger quantities (16x16 -> 32)
633
634def MPYv8i16:
635 RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
636 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
637 [(set (v8i16 VECREG:$rT), (SPUmpy_v8i16 (v8i16 VECREG:$rA),
638 (v8i16 VECREG:$rB)))]>;
639
640def MPYr16:
641 RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
642 "mpy\t$rT, $rA, $rB", IntegerMulDiv,
643 [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
644
645def MPYUv4i32:
646 RRForm<0b00110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
647 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
648 [(set (v4i32 VECREG:$rT),
649 (SPUmpyu_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
650
651def MPYUr16:
652 RRForm<0b00110011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
653 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
654 [(set R32C:$rT, (mul (zext R16C:$rA),
655 (zext R16C:$rB)))]>;
656
657def MPYUr32:
658 RRForm<0b00110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
659 "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
660 [(set R32C:$rT, (SPUmpyu_i32 R32C:$rA, R32C:$rB))]>;
661
662// mpyi: multiply 16 x s10imm -> 32 result (custom lowering for 32 bit result,
663// this only produces the lower 16 bits)
664def MPYIvec:
665 RI10Form<0b00101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
666 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
667 [(set (v8i16 VECREG:$rT), (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
668
669def MPYIr16:
670 RI10Form<0b00101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
671 "mpyi\t$rT, $rA, $val", IntegerMulDiv,
672 [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
673
674// mpyui: same issues as other multiplies, plus, this doesn't match a
675// pattern... but may be used during target DAG selection or lowering
676def MPYUIvec:
677 RI10Form<0b10101110, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
678 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
679 []>;
680
681def MPYUIr16:
682 RI10Form<0b10101110, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
683 "mpyui\t$rT, $rA, $val", IntegerMulDiv,
684 []>;
685
686// mpya: 16 x 16 + 16 -> 32 bit result
687def MPYAvec:
688 RRRForm<0b0011, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
689 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
690 [(set (v4i32 VECREG:$rT), (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
691 (v8i16 VECREG:$rB)))),
692 (v4i32 VECREG:$rC)))]>;
693
694def MPYAr32:
695 RRRForm<0b0011, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
696 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
697 [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
698 R32C:$rC))]>;
699
700def : Pat<(add (mul (sext R16C:$rA), (sext R16C:$rB)), R32C:$rC),
701 (MPYAr32 R16C:$rA, R16C:$rB, R32C:$rC)>;
702
703def MPYAr32_sextinreg:
704 RRRForm<0b0011, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
705 "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
706 [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
707 (sext_inreg R32C:$rB, i16)),
708 R32C:$rC))]>;
709
710//def 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
716// mpyh: multiply high, used to synthesize 32-bit multiplies
717def MPYHv4i32:
718 RRForm<0b10100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
719 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
720 [(set (v4i32 VECREG:$rT),
721 (SPUmpyh_v4i32 (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
722
723def MPYHr32:
724 RRForm<0b10100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
725 "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
726 [(set R32C:$rT, (SPUmpyh_i32 R32C:$rA, R32C:$rB))]>;
727
728// mpys: multiply high and shift right (returns the top half of
729// a 16-bit multiply, sign extended to 32 bits.)
730def MPYSvec:
731 RRForm<0b11100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
732 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
733 []>;
734
735def MPYSr16:
736 RRForm<0b11100011110, (outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
737 "mpys\t$rT, $rA, $rB", IntegerMulDiv,
738 []>;
739
740// mpyhh: multiply high-high (returns the 32-bit result from multiplying
741// the top 16 bits of the $rA, $rB)
742def MPYHHv8i16:
743 RRForm<0b01100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
744 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
745 [(set (v8i16 VECREG:$rT),
746 (SPUmpyhh_v8i16 (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)))]>;
747
748def MPYHHr32:
749 RRForm<0b01100011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
750 "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
751 []>;
752
753// mpyhha: Multiply high-high, add to $rT:
754def MPYHHAvec:
755 RRForm<0b01100010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
756 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
757 []>;
758
759def MPYHHAr32:
760 RRForm<0b01100010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
761 "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
762 []>;
763
764// mpyhhu: Multiply high-high, unsigned
765def MPYHHUvec:
766 RRForm<0b01110011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
767 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
768 []>;
769
770def MPYHHUr32:
771 RRForm<0b01110011110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
772 "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
773 []>;
774
775// mpyhhau: Multiply high-high, unsigned
776def MPYHHAUvec:
777 RRForm<0b01110010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
778 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
779 []>;
780
781def MPYHHAUr32:
782 RRForm<0b01110010110, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
783 "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
784 []>;
785
786// clz: Count leading zeroes
787def CLZv4i32:
788 RRForm_1<0b10100101010, (outs VECREG:$rT), (ins VECREG:$rA),
789 "clz\t$rT, $rA", IntegerOp,
790 [/* intrinsic */]>;
791
792def CLZr32:
793 RRForm_1<0b10100101010, (outs R32C:$rT), (ins R32C:$rA),
794 "clz\t$rT, $rA", IntegerOp,
795 [(set R32C:$rT, (ctlz R32C:$rA))]>;
796
797// cntb: Count ones in bytes (aka "population count")
798// NOTE: This instruction is really a vector instruction, but the custom
799// lowering code uses it in unorthodox ways to support CTPOP for other
800// data types!
801def CNTBv16i8:
802 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
803 "cntb\t$rT, $rA", IntegerOp,
804 [(set (v16i8 VECREG:$rT), (SPUcntb_v16i8 (v16i8 VECREG:$rA)))]>;
805
806def CNTBv8i16 :
807 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
808 "cntb\t$rT, $rA", IntegerOp,
809 [(set (v8i16 VECREG:$rT), (SPUcntb_v8i16 (v8i16 VECREG:$rA)))]>;
810
811def CNTBv4i32 :
812 RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
813 "cntb\t$rT, $rA", IntegerOp,
814 [(set (v4i32 VECREG:$rT), (SPUcntb_v4i32 (v4i32 VECREG:$rA)))]>;
815
Scott Michel8b6b4202007-12-04 22:35:58 +0000816// gbb: Gather all low order bits from each byte in $rA into a single 16-bit
817// quantity stored into $rT
818def GBB:
819 RRForm_1<0b01001101100, (outs R16C:$rT), (ins VECREG:$rA),
820 "gbb\t$rT, $rA", GatherOp,
821 []>;
822
823// gbh: Gather all low order bits from each halfword in $rA into a single
824// 8-bit quantity stored in $rT
825def GBH:
826 RRForm_1<0b10001101100, (outs R16C:$rT), (ins VECREG:$rA),
827 "gbh\t$rT, $rA", GatherOp,
828 []>;
829
830// gb: Gather all low order bits from each word in $rA into a single
831// 4-bit quantity stored in $rT
832def GB:
833 RRForm_1<0b00001101100, (outs R16C:$rT), (ins VECREG:$rA),
834 "gb\t$rT, $rA", GatherOp,
835 []>;
836
837// avgb: average bytes
838def AVGB:
839 RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
840 "avgb\t$rT, $rA, $rB", ByteOp,
841 []>;
842
843// absdb: absolute difference of bytes
844def ABSDB:
845 RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
846 "absdb\t$rT, $rA, $rB", ByteOp,
847 []>;
848
849// sumb: sum bytes into halfwords
850def SUMB:
851 RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
852 "sumb\t$rT, $rA, $rB", ByteOp,
853 []>;
854
855// Sign extension operations:
856def XSBHvec:
857 RRForm_1<0b01101101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
858 "xsbh\t$rDst, $rSrc", IntegerOp,
859 [(set (v8i16 VECREG:$rDst), (sext (v16i8 VECREG:$rSrc)))]>;
860
861// Ordinary form for XSBH
862def XSBHr16:
863 RRForm_1<0b01101101010, (outs R16C:$rDst), (ins R16C:$rSrc),
864 "xsbh\t$rDst, $rSrc", IntegerOp,
865 [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
866
Scott Michel438be252007-12-17 22:32:34 +0000867def XSBHr8:
868 RRForm_1<0b01101101010, (outs R16C:$rDst), (ins R8C:$rSrc),
869 "xsbh\t$rDst, $rSrc", IntegerOp,
870 [(set R16C:$rDst, (sext R8C:$rSrc))]>;
871
Scott Michel8b6b4202007-12-04 22:35:58 +0000872// 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
873// quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
874// pattern below). Intentionally doesn't match a pattern because we want the
875// sext 8->32 pattern to do the work for us, namely because we need the extra
876// XSHWr32.
877def XSBHr32:
878 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
879 "xsbh\t$rDst, $rSrc", IntegerOp,
880 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i8))]>;
881
882// Sign extend halfwords to words:
883def XSHWvec:
884 RRForm_1<0b01101101010, (outs VECREG:$rDest), (ins VECREG:$rSrc),
885 "xshw\t$rDest, $rSrc", IntegerOp,
886 [(set (v4i32 VECREG:$rDest), (sext (v8i16 VECREG:$rSrc)))]>;
887
888def XSHWr32:
889 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R32C:$rSrc),
890 "xshw\t$rDst, $rSrc", IntegerOp,
891 [(set R32C:$rDst, (sext_inreg R32C:$rSrc, i16))]>;
892
893def XSHWr16:
894 RRForm_1<0b01101101010, (outs R32C:$rDst), (ins R16C:$rSrc),
895 "xshw\t$rDst, $rSrc", IntegerOp,
896 [(set R32C:$rDst, (sext R16C:$rSrc))]>;
897
898def XSWDvec:
899 RRForm_1<0b01100101010, (outs VECREG:$rDst), (ins VECREG:$rSrc),
900 "xswd\t$rDst, $rSrc", IntegerOp,
901 [(set (v2i64 VECREG:$rDst), (sext (v4i32 VECREG:$rSrc)))]>;
902
903def XSWDr64:
904 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R64C:$rSrc),
905 "xswd\t$rDst, $rSrc", IntegerOp,
906 [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
907
908def XSWDr32:
909 RRForm_1<0b01100101010, (outs R64C:$rDst), (ins R32C:$rSrc),
910 "xswd\t$rDst, $rSrc", IntegerOp,
911 [(set R64C:$rDst, (SPUsext32_to_64 R32C:$rSrc))]>;
912
913def : Pat<(sext R32C:$inp),
914 (XSWDr32 R32C:$inp)>;
915
916// AND operations
Scott Michel8b6b4202007-12-04 22:35:58 +0000917
Scott Michel97872d32008-02-23 18:41:37 +0000918class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
919 RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
920 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000921
Scott Michel97872d32008-02-23 18:41:37 +0000922class ANDVecInst<ValueType vectype>:
923 ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
924 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
925 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000926
Scott Michel6baba072008-03-05 23:02:02 +0000927class ANDRegInst<RegisterClass rclass>:
928 ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
929 [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
930
Scott Michel97872d32008-02-23 18:41:37 +0000931multiclass BitwiseAnd
932{
933 def v16i8: ANDVecInst<v16i8>;
934 def v8i16: ANDVecInst<v8i16>;
935 def v4i32: ANDVecInst<v4i32>;
936 def v2i64: ANDVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000937
Scott Michel6baba072008-03-05 23:02:02 +0000938 def r128: ANDRegInst<GPRC>;
939 def r64: ANDRegInst<R64C>;
940 def r32: ANDRegInst<R32C>;
941 def r16: ANDRegInst<R16C>;
942 def r8: ANDRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000943
Scott Michel97872d32008-02-23 18:41:37 +0000944 //===---------------------------------------------
945 // Special instructions to perform the fabs instruction
946 def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
947 [/* Intentionally does not match a pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000948
Scott Michel97872d32008-02-23 18:41:37 +0000949 def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
950 [/* Intentionally does not match a pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +0000951
Scott Michel97872d32008-02-23 18:41:37 +0000952 // Could use v4i32, but won't for clarity
953 def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
954 [/* Intentionally does not match a pattern */]>;
955
956 //===---------------------------------------------
957
958 // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
959 // quantities -- see 16->32 zext pattern.
960 //
961 // This pattern is somewhat artificial, since it might match some
962 // compiler generated pattern but it is unlikely to do so.
963
964 def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
965 [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
966}
967
968defm AND : BitwiseAnd;
Scott Michel8b6b4202007-12-04 22:35:58 +0000969
970// N.B.: vnot_conv is one of those special target selection pattern fragments,
971// in which we expect there to be a bit_convert on the constant. Bear in mind
972// that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
973// constant -1 vector.)
Scott Michel8b6b4202007-12-04 22:35:58 +0000974
Scott Michel97872d32008-02-23 18:41:37 +0000975class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
976 RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
977 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000978
Scott Michel97872d32008-02-23 18:41:37 +0000979class ANDCVecInst<ValueType vectype>:
980 ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
981 [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
982 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000983
Scott Michel97872d32008-02-23 18:41:37 +0000984class ANDCRegInst<RegisterClass rclass>:
985 ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
986 [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000987
Scott Michel97872d32008-02-23 18:41:37 +0000988multiclass AndComplement
989{
990 def v16i8: ANDCVecInst<v16i8>;
991 def v8i16: ANDCVecInst<v8i16>;
992 def v4i32: ANDCVecInst<v4i32>;
993 def v2i64: ANDCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +0000994
Scott Michel97872d32008-02-23 18:41:37 +0000995 def r128: ANDCRegInst<GPRC>;
996 def r64: ANDCRegInst<R64C>;
997 def r32: ANDCRegInst<R32C>;
998 def r16: ANDCRegInst<R16C>;
999 def r8: ANDCRegInst<R8C>;
1000}
Scott Michel438be252007-12-17 22:32:34 +00001001
Scott Michel97872d32008-02-23 18:41:37 +00001002defm ANDC : AndComplement;
Scott Michel8b6b4202007-12-04 22:35:58 +00001003
Scott Michel97872d32008-02-23 18:41:37 +00001004class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1005 RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1006 IntegerOp, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001007
Scott Michel97872d32008-02-23 18:41:37 +00001008multiclass AndByteImm
1009{
1010 def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1011 [(set (v16i8 VECREG:$rT),
1012 (and (v16i8 VECREG:$rA),
1013 (v16i8 v16i8U8Imm:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001014
Scott Michel97872d32008-02-23 18:41:37 +00001015 def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1016 [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1017}
Scott Michel438be252007-12-17 22:32:34 +00001018
Scott Michel97872d32008-02-23 18:41:37 +00001019defm ANDBI : AndByteImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001020
Scott Michel97872d32008-02-23 18:41:37 +00001021class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1022 RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1023 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001024
Scott Michel97872d32008-02-23 18:41:37 +00001025multiclass AndHalfwordImm
1026{
1027 def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1028 [(set (v8i16 VECREG:$rT),
1029 (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001030
Scott Michel97872d32008-02-23 18:41:37 +00001031 def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1032 [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001033
Scott Michel97872d32008-02-23 18:41:37 +00001034 // Zero-extend i8 to i16:
1035 def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1036 [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1037}
Scott Michel8b6b4202007-12-04 22:35:58 +00001038
Scott Michel97872d32008-02-23 18:41:37 +00001039defm ANDHI : AndHalfwordImm;
1040
1041class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1042 RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1043 IntegerOp, pattern>;
1044
1045multiclass AndWordImm
1046{
1047 def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1048 [(set (v4i32 VECREG:$rT),
1049 (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1050
1051 def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1052 [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1053
1054 // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1055 // pattern below.
1056 def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1057 [(set R32C:$rT,
1058 (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1059
1060 // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1061 // zext 16->32 pattern below.
1062 //
1063 // Note that this pattern is somewhat artificial, since it might match
1064 // something the compiler generates but is unlikely to occur in practice.
1065 def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1066 [(set R32C:$rT,
1067 (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1068}
1069
1070defm ANDI : AndWordImm;
1071
1072//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001073// Bitwise OR group:
Scott Michel97872d32008-02-23 18:41:37 +00001074//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1075
Scott Michel8b6b4202007-12-04 22:35:58 +00001076// Bitwise "or" (N.B.: These are also register-register copy instructions...)
Scott Michel97872d32008-02-23 18:41:37 +00001077class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1078 RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1079 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001080
Scott Michel97872d32008-02-23 18:41:37 +00001081class ORVecInst<ValueType vectype>:
1082 ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1083 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1084 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001085
Scott Michel97872d32008-02-23 18:41:37 +00001086class ORRegInst<RegisterClass rclass>:
1087 ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1088 [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001089
Scott Michel97872d32008-02-23 18:41:37 +00001090class ORPromoteScalar<RegisterClass rclass>:
1091 ORInst<(outs VECREG:$rT), (ins rclass:$rA, rclass:$rB),
1092 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001093
Scott Michel97872d32008-02-23 18:41:37 +00001094class ORExtractElt<RegisterClass rclass>:
1095 ORInst<(outs rclass:$rT), (ins VECREG:$rA, VECREG:$rB),
1096 [/* no pattern */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001097
Scott Michel97872d32008-02-23 18:41:37 +00001098multiclass BitwiseOr
1099{
1100 def v16i8: ORVecInst<v16i8>;
1101 def v8i16: ORVecInst<v8i16>;
1102 def v4i32: ORVecInst<v4i32>;
1103 def v2i64: ORVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001104
Scott Michel97872d32008-02-23 18:41:37 +00001105 def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1106 [(set (v4f32 VECREG:$rT),
1107 (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1108 (v4i32 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001109
Scott Michel97872d32008-02-23 18:41:37 +00001110 def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1111 [(set (v2f64 VECREG:$rT),
1112 (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1113 (v2i64 VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001114
Scott Michel97872d32008-02-23 18:41:37 +00001115 def r64: ORRegInst<R64C>;
1116 def r32: ORRegInst<R32C>;
1117 def r16: ORRegInst<R16C>;
1118 def r8: ORRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001119
Scott Michel97872d32008-02-23 18:41:37 +00001120 // OR instructions used to copy f32 and f64 registers.
1121 def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1122 [/* no pattern */]>;
Scott Michel438be252007-12-17 22:32:34 +00001123
Scott Michel97872d32008-02-23 18:41:37 +00001124 def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1125 [/* no pattern */]>;
Scott Michel754d8662007-12-20 00:44:13 +00001126
Scott Michel97872d32008-02-23 18:41:37 +00001127 // scalar->vector promotion:
1128 def v16i8_i8: ORPromoteScalar<R8C>;
1129 def v8i16_i16: ORPromoteScalar<R16C>;
1130 def v4i32_i32: ORPromoteScalar<R32C>;
1131 def v2i64_i64: ORPromoteScalar<R64C>;
1132 def v4f32_f32: ORPromoteScalar<R32FP>;
1133 def v2f64_f64: ORPromoteScalar<R64FP>;
Scott Michel754d8662007-12-20 00:44:13 +00001134
Scott Michel97872d32008-02-23 18:41:37 +00001135 // extract element 0:
1136 def i8_v16i8: ORExtractElt<R8C>;
1137 def i16_v8i16: ORExtractElt<R16C>;
1138 def i32_v4i32: ORExtractElt<R32C>;
1139 def i64_v2i64: ORExtractElt<R64C>;
1140 def f32_v4f32: ORExtractElt<R32FP>;
1141 def f64_v2f64: ORExtractElt<R64FP>;
1142}
Scott Michel438be252007-12-17 22:32:34 +00001143
Scott Michel97872d32008-02-23 18:41:37 +00001144defm OR : BitwiseOr;
1145
1146// scalar->vector promotion patterns:
Scott Michel438be252007-12-17 22:32:34 +00001147def : Pat<(v16i8 (SPUpromote_scalar R8C:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001148 (ORv16i8_i8 R8C:$rA, R8C:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001149
Scott Michel8b6b4202007-12-04 22:35:58 +00001150def : Pat<(v8i16 (SPUpromote_scalar R16C:$rA)),
1151 (ORv8i16_i16 R16C:$rA, R16C:$rA)>;
1152
Scott Michel8b6b4202007-12-04 22:35:58 +00001153def : Pat<(v4i32 (SPUpromote_scalar R32C:$rA)),
1154 (ORv4i32_i32 R32C:$rA, R32C:$rA)>;
1155
Scott Michel8b6b4202007-12-04 22:35:58 +00001156def : Pat<(v2i64 (SPUpromote_scalar R64C:$rA)),
1157 (ORv2i64_i64 R64C:$rA, R64C:$rA)>;
1158
Scott Michel8b6b4202007-12-04 22:35:58 +00001159def : Pat<(v4f32 (SPUpromote_scalar R32FP:$rA)),
1160 (ORv4f32_f32 R32FP:$rA, R32FP:$rA)>;
1161
Scott Michel8b6b4202007-12-04 22:35:58 +00001162def : Pat<(v2f64 (SPUpromote_scalar R64FP:$rA)),
1163 (ORv2f64_f64 R64FP:$rA, R64FP:$rA)>;
1164
1165// ORi*_v*: Used to extract vector element 0 (the preferred slot)
Scott Michel438be252007-12-17 22:32:34 +00001166
1167def : Pat<(SPUextract_elt0 (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001168 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel438be252007-12-17 22:32:34 +00001169
Scott Michel394e26d2008-01-17 20:38:41 +00001170def : Pat<(SPUextract_elt0_chained (v16i8 VECREG:$rA)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00001171 (ORi8_v16i8 VECREG:$rA, VECREG:$rA)>;
Scott Michel394e26d2008-01-17 20:38:41 +00001172
Scott Michel8b6b4202007-12-04 22:35:58 +00001173def : Pat<(SPUextract_elt0 (v8i16 VECREG:$rA)),
1174 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1175
1176def : Pat<(SPUextract_elt0_chained (v8i16 VECREG:$rA)),
1177 (ORi16_v8i16 VECREG:$rA, VECREG:$rA)>;
1178
Scott Michel8b6b4202007-12-04 22:35:58 +00001179def : Pat<(SPUextract_elt0 (v4i32 VECREG:$rA)),
1180 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1181
1182def : Pat<(SPUextract_elt0_chained (v4i32 VECREG:$rA)),
1183 (ORi32_v4i32 VECREG:$rA, VECREG:$rA)>;
1184
Scott Michel8b6b4202007-12-04 22:35:58 +00001185def : Pat<(SPUextract_elt0 (v2i64 VECREG:$rA)),
1186 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1187
1188def : Pat<(SPUextract_elt0_chained (v2i64 VECREG:$rA)),
1189 (ORi64_v2i64 VECREG:$rA, VECREG:$rA)>;
1190
Scott Michel8b6b4202007-12-04 22:35:58 +00001191def : Pat<(SPUextract_elt0 (v4f32 VECREG:$rA)),
1192 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1193
1194def : Pat<(SPUextract_elt0_chained (v4f32 VECREG:$rA)),
1195 (ORf32_v4f32 VECREG:$rA, VECREG:$rA)>;
1196
Scott Michel8b6b4202007-12-04 22:35:58 +00001197def : Pat<(SPUextract_elt0 (v2f64 VECREG:$rA)),
1198 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1199
1200def : Pat<(SPUextract_elt0_chained (v2f64 VECREG:$rA)),
1201 (ORf64_v2f64 VECREG:$rA, VECREG:$rA)>;
1202
Scott Michel97872d32008-02-23 18:41:37 +00001203// ORC: Bitwise "or" with complement (c = a | ~b)
Scott Michel8b6b4202007-12-04 22:35:58 +00001204
Scott Michel97872d32008-02-23 18:41:37 +00001205class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1206 RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1207 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001208
Scott Michel97872d32008-02-23 18:41:37 +00001209class ORCVecInst<ValueType vectype>:
1210 ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1211 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1212 (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001213
Scott Michel97872d32008-02-23 18:41:37 +00001214class ORCRegInst<RegisterClass rclass>:
1215 ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1216 [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001217
Scott Michel97872d32008-02-23 18:41:37 +00001218multiclass BitwiseOrComplement
1219{
1220 def v16i8: ORCVecInst<v16i8>;
1221 def v8i16: ORCVecInst<v8i16>;
1222 def v4i32: ORCVecInst<v4i32>;
1223 def v2i64: ORCVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001224
Scott Michel97872d32008-02-23 18:41:37 +00001225 def r64: ORCRegInst<R64C>;
1226 def r32: ORCRegInst<R32C>;
1227 def r16: ORCRegInst<R16C>;
1228 def r8: ORCRegInst<R8C>;
1229}
1230
1231defm ORC : BitwiseOrComplement;
Scott Michel438be252007-12-17 22:32:34 +00001232
Scott Michel8b6b4202007-12-04 22:35:58 +00001233// OR byte immediate
Scott Michel97872d32008-02-23 18:41:37 +00001234class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1235 RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1236 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001237
Scott Michel97872d32008-02-23 18:41:37 +00001238class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1239 ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1240 [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1241 (vectype immpred:$val)))]>;
1242
1243multiclass BitwiseOrByteImm
1244{
1245 def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1246
1247 def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1248 [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1249}
1250
1251defm ORBI : BitwiseOrByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001252
Scott Michel8b6b4202007-12-04 22:35:58 +00001253// OR halfword immediate
Scott Michel97872d32008-02-23 18:41:37 +00001254class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1255 RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1256 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001257
Scott Michel97872d32008-02-23 18:41:37 +00001258class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1259 ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1260 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1261 immpred:$val))]>;
Scott Michel438be252007-12-17 22:32:34 +00001262
Scott Michel97872d32008-02-23 18:41:37 +00001263multiclass BitwiseOrHalfwordImm
1264{
1265 def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1266
1267 def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1268 [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1269
1270 // Specialized ORHI form used to promote 8-bit registers to 16-bit
1271 def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1272 [(set R16C:$rT, (or (anyext R8C:$rA),
1273 i16ImmSExt10:$val))]>;
1274}
1275
1276defm ORHI : BitwiseOrHalfwordImm;
1277
1278class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1279 RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1280 IntegerOp, pattern>;
1281
1282class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1283 ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1284 [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1285 immpred:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001286
1287// Bitwise "or" with immediate
Scott Michel97872d32008-02-23 18:41:37 +00001288multiclass BitwiseOrImm
1289{
1290 def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001291
Scott Michel97872d32008-02-23 18:41:37 +00001292 def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1293 [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001294
Scott Michel97872d32008-02-23 18:41:37 +00001295 // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1296 // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1297 // infra "anyext 16->32" pattern.)
1298 def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1299 [(set R32C:$rT, (or (anyext R16C:$rA),
1300 i32ImmSExt10:$val))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001301
Scott Michel97872d32008-02-23 18:41:37 +00001302 // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1303 // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1304 // infra "anyext 16->32" pattern.)
1305 def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1306 [(set R32C:$rT, (or (anyext R8C:$rA),
1307 i32ImmSExt10:$val))]>;
1308}
Scott Michel8b6b4202007-12-04 22:35:58 +00001309
Scott Michel97872d32008-02-23 18:41:37 +00001310defm ORI : BitwiseOrImm;
Scott Michel438be252007-12-17 22:32:34 +00001311
Scott Michel8b6b4202007-12-04 22:35:58 +00001312// ORX: "or" across the vector: or's $rA's word slots leaving the result in
1313// $rT[0], slots 1-3 are zeroed.
1314//
Scott Michel438be252007-12-17 22:32:34 +00001315// FIXME: Needs to match an intrinsic pattern.
Scott Michel8b6b4202007-12-04 22:35:58 +00001316def ORXv4i32:
1317 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1318 "orx\t$rT, $rA, $rB", IntegerOp,
1319 []>;
1320
Scott Michel438be252007-12-17 22:32:34 +00001321// XOR:
Scott Michel8b6b4202007-12-04 22:35:58 +00001322
Scott Michel6baba072008-03-05 23:02:02 +00001323class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1324 RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1325 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001326
Scott Michel6baba072008-03-05 23:02:02 +00001327class XORVecInst<ValueType vectype>:
1328 XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1329 [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1330 (vectype VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001331
Scott Michel6baba072008-03-05 23:02:02 +00001332class XORRegInst<RegisterClass rclass>:
1333 XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1334 [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1335
1336multiclass BitwiseExclusiveOr
1337{
1338 def v16i8: XORVecInst<v16i8>;
1339 def v8i16: XORVecInst<v8i16>;
1340 def v4i32: XORVecInst<v4i32>;
1341 def v2i64: XORVecInst<v2i64>;
1342
1343 def r128: XORRegInst<GPRC>;
1344 def r64: XORRegInst<R64C>;
1345 def r32: XORRegInst<R32C>;
1346 def r16: XORRegInst<R16C>;
1347 def r8: XORRegInst<R8C>;
1348
1349 // Special forms for floating point instructions.
1350 // fneg and fabs require bitwise logical ops to manipulate the sign bit.
1351
1352 def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1353 [/* no pattern */]>;
1354
1355 def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, VECREG:$rB),
1356 [/* no pattern */]>;
1357
1358 def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1359 [/* no pattern, see fneg{32,64} */]>;
1360}
1361
1362defm XOR : BitwiseExclusiveOr;
Scott Michel8b6b4202007-12-04 22:35:58 +00001363
1364//==----------------------------------------------------------
Scott Michel438be252007-12-17 22:32:34 +00001365
Scott Michel97872d32008-02-23 18:41:37 +00001366class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1367 RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1368 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001369
Scott Michel97872d32008-02-23 18:41:37 +00001370multiclass XorByteImm
1371{
1372 def v16i8:
1373 XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1374 [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1375
1376 def r8:
1377 XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1378 [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1379}
1380
1381defm XORBI : XorByteImm;
Scott Michel438be252007-12-17 22:32:34 +00001382
Scott Michel8b6b4202007-12-04 22:35:58 +00001383def XORHIv8i16:
Scott Michel97872d32008-02-23 18:41:37 +00001384 RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001385 "xorhi\t$rT, $rA, $val", IntegerOp,
1386 [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1387 v8i16SExt10Imm:$val))]>;
1388
1389def XORHIr16:
1390 RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1391 "xorhi\t$rT, $rA, $val", IntegerOp,
1392 [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1393
1394def XORIv4i32:
Scott Michel53ab7792008-03-10 16:58:52 +00001395 RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
Scott Michel8b6b4202007-12-04 22:35:58 +00001396 "xori\t$rT, $rA, $val", IntegerOp,
1397 [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1398 v4i32SExt10Imm:$val))]>;
1399
1400def XORIr32:
1401 RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1402 "xori\t$rT, $rA, $val", IntegerOp,
1403 [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1404
1405// NAND:
1406def NANDv16i8:
1407 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1408 "nand\t$rT, $rA, $rB", IntegerOp,
1409 [(set (v16i8 VECREG:$rT), (vnot (and (v16i8 VECREG:$rA),
1410 (v16i8 VECREG:$rB))))]>;
1411
1412def NANDv8i16:
1413 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1414 "nand\t$rT, $rA, $rB", IntegerOp,
1415 [(set (v8i16 VECREG:$rT), (vnot (and (v8i16 VECREG:$rA),
1416 (v8i16 VECREG:$rB))))]>;
1417
1418def NANDv4i32:
1419 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1420 "nand\t$rT, $rA, $rB", IntegerOp,
1421 [(set (v4i32 VECREG:$rT), (vnot (and (v4i32 VECREG:$rA),
1422 (v4i32 VECREG:$rB))))]>;
1423
1424def NANDr32:
1425 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1426 "nand\t$rT, $rA, $rB", IntegerOp,
1427 [(set R32C:$rT, (not (and R32C:$rA, R32C:$rB)))]>;
1428
1429def NANDr16:
1430 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1431 "nand\t$rT, $rA, $rB", IntegerOp,
1432 [(set R16C:$rT, (not (and R16C:$rA, R16C:$rB)))]>;
1433
Scott Michel438be252007-12-17 22:32:34 +00001434def NANDr8:
1435 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1436 "nand\t$rT, $rA, $rB", IntegerOp,
1437 [(set R8C:$rT, (not (and R8C:$rA, R8C:$rB)))]>;
1438
Scott Michel8b6b4202007-12-04 22:35:58 +00001439// NOR:
1440def NORv16i8:
1441 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1442 "nor\t$rT, $rA, $rB", IntegerOp,
1443 [(set (v16i8 VECREG:$rT), (vnot (or (v16i8 VECREG:$rA),
1444 (v16i8 VECREG:$rB))))]>;
1445
1446def NORv8i16:
1447 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1448 "nor\t$rT, $rA, $rB", IntegerOp,
1449 [(set (v8i16 VECREG:$rT), (vnot (or (v8i16 VECREG:$rA),
1450 (v8i16 VECREG:$rB))))]>;
1451
1452def NORv4i32:
1453 RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1454 "nor\t$rT, $rA, $rB", IntegerOp,
1455 [(set (v4i32 VECREG:$rT), (vnot (or (v4i32 VECREG:$rA),
1456 (v4i32 VECREG:$rB))))]>;
1457
1458def NORr32:
1459 RRForm<0b10010010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1460 "nor\t$rT, $rA, $rB", IntegerOp,
1461 [(set R32C:$rT, (not (or R32C:$rA, R32C:$rB)))]>;
1462
1463def NORr16:
1464 RRForm<0b10010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1465 "nor\t$rT, $rA, $rB", IntegerOp,
1466 [(set R16C:$rT, (not (or R16C:$rA, R16C:$rB)))]>;
1467
Scott Michel438be252007-12-17 22:32:34 +00001468def NORr8:
1469 RRForm<0b10010010000, (outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
1470 "nor\t$rT, $rA, $rB", IntegerOp,
1471 [(set R8C:$rT, (not (or R8C:$rA, R8C:$rB)))]>;
1472
Scott Michel8b6b4202007-12-04 22:35:58 +00001473// Select bits:
Scott Michel6baba072008-03-05 23:02:02 +00001474class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1475 RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1476 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001477
Scott Michel6baba072008-03-05 23:02:02 +00001478class SELBVecInst<ValueType vectype>:
1479 SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1480 [(set (vectype VECREG:$rT),
1481 (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1482 (and (vnot (vectype VECREG:$rC)),
1483 (vectype VECREG:$rA))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001484
Scott Michel6baba072008-03-05 23:02:02 +00001485class SELBRegInst<RegisterClass rclass>:
1486 SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1487 [(set rclass:$rT,
1488 (or (and rclass:$rA, rclass:$rC),
1489 (and rclass:$rB, (not rclass:$rC))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001490
Scott Michel6baba072008-03-05 23:02:02 +00001491multiclass SelectBits
1492{
1493 def v16i8: SELBVecInst<v16i8>;
1494 def v8i16: SELBVecInst<v8i16>;
1495 def v4i32: SELBVecInst<v4i32>;
1496 def v2i64: SELBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001497
Scott Michel6baba072008-03-05 23:02:02 +00001498 def r128: SELBRegInst<GPRC>;
1499 def r64: SELBRegInst<R64C>;
1500 def r32: SELBRegInst<R32C>;
1501 def r16: SELBRegInst<R16C>;
1502 def r8: SELBRegInst<R8C>;
1503}
Scott Michel8b6b4202007-12-04 22:35:58 +00001504
Scott Michel6baba072008-03-05 23:02:02 +00001505defm SELB : SelectBits;
Scott Michel8b6b4202007-12-04 22:35:58 +00001506
Scott Michel6baba072008-03-05 23:02:02 +00001507class SPUselbPat<ValueType vectype, SPUInstr inst>:
1508 Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1509 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001510
Scott Michel6baba072008-03-05 23:02:02 +00001511def : SPUselbPat<v16i8, SELBv16i8>;
1512def : SPUselbPat<v8i16, SELBv8i16>;
1513def : SPUselbPat<v4i32, SELBv4i32>;
1514def : SPUselbPat<v2i64, SELBv2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001515
Scott Michel6baba072008-03-05 23:02:02 +00001516class SelectConditional<RegisterClass rclass, SPUInstr inst>:
1517 Pat<(select rclass:$rCond, rclass:$rTrue, rclass:$rFalse),
Scott Michel53ab7792008-03-10 16:58:52 +00001518 (inst rclass:$rFalse, rclass:$rTrue, rclass:$rCond)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001519
Scott Michel6baba072008-03-05 23:02:02 +00001520def : SelectConditional<R32C, SELBr32>;
1521def : SelectConditional<R16C, SELBr16>;
1522def : SelectConditional<R8C, SELBr8>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001523
Scott Michel6baba072008-03-05 23:02:02 +00001524// EQV: Equivalence (1 for each same bit, otherwise 0)
1525//
1526// Note: There are a lot of ways to match this bit operator and these patterns
1527// attempt to be as exhaustive as possible.
Scott Michel8b6b4202007-12-04 22:35:58 +00001528
Scott Michel6baba072008-03-05 23:02:02 +00001529class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
1530 RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
1531 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001532
Scott Michel6baba072008-03-05 23:02:02 +00001533class EQVVecInst<ValueType vectype>:
1534 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1535 [(set (vectype VECREG:$rT),
1536 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1537 (and (vnot (vectype VECREG:$rA)),
1538 (vnot (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001539
Scott Michel6baba072008-03-05 23:02:02 +00001540class EQVRegInst<RegisterClass rclass>:
1541 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1542 [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
1543 (and (not rclass:$rA), (not rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001544
Scott Michel6baba072008-03-05 23:02:02 +00001545class EQVVecPattern1<ValueType vectype>:
1546 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1547 [(set (vectype VECREG:$rT),
1548 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001549
Scott Michel6baba072008-03-05 23:02:02 +00001550class EQVRegPattern1<RegisterClass rclass>:
1551 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1552 [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001553
Scott Michel6baba072008-03-05 23:02:02 +00001554class EQVVecPattern2<ValueType vectype>:
1555 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1556 [(set (vectype VECREG:$rT),
1557 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
1558 (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001559
Scott Michel6baba072008-03-05 23:02:02 +00001560class EQVRegPattern2<RegisterClass rclass>:
1561 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1562 [(set rclass:$rT,
1563 (or (and rclass:$rA, rclass:$rB),
1564 (not (or rclass:$rA, rclass:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001565
Scott Michel6baba072008-03-05 23:02:02 +00001566class EQVVecPattern3<ValueType vectype>:
1567 EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1568 [(set (vectype VECREG:$rT),
1569 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001570
Scott Michel6baba072008-03-05 23:02:02 +00001571class EQVRegPattern3<RegisterClass rclass>:
1572 EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1573 [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001574
Scott Michel6baba072008-03-05 23:02:02 +00001575multiclass BitEquivalence
1576{
1577 def v16i8: EQVVecInst<v16i8>;
1578 def v8i16: EQVVecInst<v8i16>;
1579 def v4i32: EQVVecInst<v4i32>;
1580 def v2i64: EQVVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001581
Scott Michel6baba072008-03-05 23:02:02 +00001582 def v16i8_1: EQVVecPattern1<v16i8>;
1583 def v8i16_1: EQVVecPattern1<v8i16>;
1584 def v4i32_1: EQVVecPattern1<v4i32>;
1585 def v2i64_1: EQVVecPattern1<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001586
Scott Michel6baba072008-03-05 23:02:02 +00001587 def v16i8_2: EQVVecPattern2<v16i8>;
1588 def v8i16_2: EQVVecPattern2<v8i16>;
1589 def v4i32_2: EQVVecPattern2<v4i32>;
1590 def v2i64_2: EQVVecPattern2<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001591
Scott Michel6baba072008-03-05 23:02:02 +00001592 def v16i8_3: EQVVecPattern3<v16i8>;
1593 def v8i16_3: EQVVecPattern3<v8i16>;
1594 def v4i32_3: EQVVecPattern3<v4i32>;
1595 def v2i64_3: EQVVecPattern3<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001596
Scott Michel6baba072008-03-05 23:02:02 +00001597 def r128: EQVRegInst<GPRC>;
1598 def r64: EQVRegInst<R64C>;
1599 def r32: EQVRegInst<R32C>;
1600 def r16: EQVRegInst<R16C>;
1601 def r8: EQVRegInst<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001602
Scott Michel6baba072008-03-05 23:02:02 +00001603 def r128_1: EQVRegPattern1<GPRC>;
1604 def r64_1: EQVRegPattern1<R64C>;
1605 def r32_1: EQVRegPattern1<R32C>;
1606 def r16_1: EQVRegPattern1<R16C>;
1607 def r8_1: EQVRegPattern1<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001608
Scott Michel6baba072008-03-05 23:02:02 +00001609 def r128_2: EQVRegPattern2<GPRC>;
1610 def r64_2: EQVRegPattern2<R64C>;
1611 def r32_2: EQVRegPattern2<R32C>;
1612 def r16_2: EQVRegPattern2<R16C>;
1613 def r8_2: EQVRegPattern2<R8C>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001614
Scott Michel6baba072008-03-05 23:02:02 +00001615 def r128_3: EQVRegPattern3<GPRC>;
1616 def r64_3: EQVRegPattern3<R64C>;
1617 def r32_3: EQVRegPattern3<R32C>;
1618 def r16_3: EQVRegPattern3<R16C>;
1619 def r8_3: EQVRegPattern3<R8C>;
1620}
Scott Michel438be252007-12-17 22:32:34 +00001621
Scott Michel6baba072008-03-05 23:02:02 +00001622defm EQV: BitEquivalence;
Scott Michel8b6b4202007-12-04 22:35:58 +00001623
1624//===----------------------------------------------------------------------===//
1625// Vector shuffle...
1626//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001627// SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
1628// See the SPUshuffle SDNode operand above, which sets up the DAG pattern
1629// matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
1630// the SPUISD::SHUFB opcode.
Scott Michel97872d32008-02-23 18:41:37 +00001631//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001632
Scott Michel97872d32008-02-23 18:41:37 +00001633class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
1634 RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
1635 IntegerOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001636
Scott Michel97872d32008-02-23 18:41:37 +00001637class SHUFBVecInst<ValueType vectype>:
1638 SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1639 [(set (vectype VECREG:$rT), (SPUshuffle (vectype VECREG:$rA),
1640 (vectype VECREG:$rB),
1641 (vectype VECREG:$rC)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001642
Scott Michel97872d32008-02-23 18:41:37 +00001643// It's this pattern that's probably the most useful, since SPUISelLowering
1644// methods create a v16i8 vector for $rC:
1645class SHUFBVecPat1<ValueType vectype, SPUInstr inst>:
1646 Pat<(SPUshuffle (vectype VECREG:$rA), (vectype VECREG:$rB),
1647 (v16i8 VECREG:$rC)),
1648 (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
Scott Michel754d8662007-12-20 00:44:13 +00001649
Scott Michel97872d32008-02-23 18:41:37 +00001650multiclass ShuffleBytes
1651{
1652 def v16i8 : SHUFBVecInst<v16i8>;
1653 def v8i16 : SHUFBVecInst<v8i16>;
1654 def v4i32 : SHUFBVecInst<v4i32>;
1655 def v2i64 : SHUFBVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001656
Scott Michel97872d32008-02-23 18:41:37 +00001657 def v4f32 : SHUFBVecInst<v4f32>;
1658 def v2f64 : SHUFBVecInst<v2f64>;
1659}
1660
1661defm SHUFB : ShuffleBytes;
1662
1663def : SHUFBVecPat1<v8i16, SHUFBv16i8>;
1664def : SHUFBVecPat1<v4i32, SHUFBv16i8>;
1665def : SHUFBVecPat1<v2i64, SHUFBv16i8>;
1666def : SHUFBVecPat1<v4f32, SHUFBv16i8>;
1667def : SHUFBVecPat1<v2f64, SHUFBv16i8>;
Scott Michel754d8662007-12-20 00:44:13 +00001668
Scott Michel8b6b4202007-12-04 22:35:58 +00001669//===----------------------------------------------------------------------===//
1670// Shift and rotate group:
1671//===----------------------------------------------------------------------===//
1672
Scott Michel97872d32008-02-23 18:41:37 +00001673class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
1674 RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
1675 RotateShift, pattern>;
1676
1677class SHLHVecInst<ValueType vectype>:
1678 SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1679 [(set (vectype VECREG:$rT),
1680 (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001681
1682// $rB gets promoted to 32-bit register type when confronted with
1683// this llvm assembly code:
1684//
1685// define i16 @shlh_i16_1(i16 %arg1, i16 %arg2) {
1686// %A = shl i16 %arg1, %arg2
1687// ret i16 %A
1688// }
Scott Michel8b6b4202007-12-04 22:35:58 +00001689
Scott Michel97872d32008-02-23 18:41:37 +00001690multiclass ShiftLeftHalfword
1691{
1692 def v8i16: SHLHVecInst<v8i16>;
1693 def r16: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
1694 [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
1695 def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1696 [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
1697}
Scott Michel8b6b4202007-12-04 22:35:58 +00001698
Scott Michel97872d32008-02-23 18:41:37 +00001699defm SHLH : ShiftLeftHalfword;
Scott Michel8b6b4202007-12-04 22:35:58 +00001700
Scott Michel97872d32008-02-23 18:41:37 +00001701//===----------------------------------------------------------------------===//
Scott Michel438be252007-12-17 22:32:34 +00001702
Scott Michel97872d32008-02-23 18:41:37 +00001703class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
1704 RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
1705 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001706
Scott Michel97872d32008-02-23 18:41:37 +00001707class SHLHIVecInst<ValueType vectype>:
1708 SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1709 [(set (vectype VECREG:$rT),
1710 (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001711
Scott Michel97872d32008-02-23 18:41:37 +00001712multiclass ShiftLeftHalfwordImm
1713{
1714 def v8i16: SHLHIVecInst<v8i16>;
1715 def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1716 [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
1717}
1718
1719defm SHLHI : ShiftLeftHalfwordImm;
1720
1721def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
1722 (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
1723
1724def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00001725 (SHLHIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001726
Scott Michel97872d32008-02-23 18:41:37 +00001727//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001728
Scott Michel97872d32008-02-23 18:41:37 +00001729class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
1730 RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
1731 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001732
Scott Michel97872d32008-02-23 18:41:37 +00001733multiclass ShiftLeftWord
1734{
1735 def v4i32:
1736 SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
1737 [(set (v4i32 VECREG:$rT),
1738 (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
1739 def r32:
1740 SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
1741 [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
1742}
Scott Michel8b6b4202007-12-04 22:35:58 +00001743
Scott Michel97872d32008-02-23 18:41:37 +00001744defm SHL: ShiftLeftWord;
Scott Michel438be252007-12-17 22:32:34 +00001745
Scott Michel97872d32008-02-23 18:41:37 +00001746//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001747
Scott Michel97872d32008-02-23 18:41:37 +00001748class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
1749 RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
1750 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001751
Scott Michel97872d32008-02-23 18:41:37 +00001752multiclass ShiftLeftWordImm
1753{
1754 def v4i32:
1755 SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1756 [(set (v4i32 VECREG:$rT),
1757 (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001758
Scott Michel97872d32008-02-23 18:41:37 +00001759 def r32:
1760 SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
1761 [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
1762}
Scott Michel8b6b4202007-12-04 22:35:58 +00001763
Scott Michel97872d32008-02-23 18:41:37 +00001764defm SHLI : ShiftLeftWordImm;
Scott Michel438be252007-12-17 22:32:34 +00001765
Scott Michel97872d32008-02-23 18:41:37 +00001766//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00001767// SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
1768// register) to the left. Vector form is here to ensure type correctness.
Scott Michel97872d32008-02-23 18:41:37 +00001769//
1770// The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
1771// of 7 bits is actually possible.
1772//
1773// Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
1774// to shift i64 and i128. SHLQBI is the residual left over after shifting by
1775// bytes with SHLQBY.
Scott Michel8b6b4202007-12-04 22:35:58 +00001776
Scott Michel97872d32008-02-23 18:41:37 +00001777class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
1778 RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
1779 RotateShift, pattern>;
1780
1781class SHLQBIVecInst<ValueType vectype>:
1782 SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1783 [(set (vectype VECREG:$rT),
1784 (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
1785
1786multiclass ShiftLeftQuadByBits
1787{
1788 def v16i8: SHLQBIVecInst<v16i8>;
1789 def v8i16: SHLQBIVecInst<v8i16>;
1790 def v4i32: SHLQBIVecInst<v4i32>;
1791 def v2i64: SHLQBIVecInst<v2i64>;
1792}
1793
1794defm SHLQBI : ShiftLeftQuadByBits;
1795
1796// See note above on SHLQBI. In this case, the predicate actually does then
1797// enforcement, whereas with SHLQBI, we have to "take it on faith."
1798class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
1799 RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
1800 RotateShift, pattern>;
1801
1802class SHLQBIIVecInst<ValueType vectype>:
1803 SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1804 [(set (vectype VECREG:$rT),
1805 (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
1806
1807multiclass ShiftLeftQuadByBitsImm
1808{
1809 def v16i8 : SHLQBIIVecInst<v16i8>;
1810 def v8i16 : SHLQBIIVecInst<v8i16>;
1811 def v4i32 : SHLQBIIVecInst<v4i32>;
1812 def v2i64 : SHLQBIIVecInst<v2i64>;
1813}
1814
1815defm SHLQBII : ShiftLeftQuadByBitsImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00001816
1817// SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
Scott Michel97872d32008-02-23 18:41:37 +00001818// not by bits. See notes above on SHLQBI.
Scott Michel8b6b4202007-12-04 22:35:58 +00001819
Scott Michel97872d32008-02-23 18:41:37 +00001820class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
1821 RI7Form<0b11111011100, OOL, IOL, "shlqbyi\t$rT, $rA, $rB",
1822 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001823
Scott Michel97872d32008-02-23 18:41:37 +00001824class SHLQBYVecInst<ValueType vectype>:
1825 SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1826 [(set (vectype VECREG:$rT),
1827 (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001828
Scott Michel97872d32008-02-23 18:41:37 +00001829multiclass ShiftLeftQuadBytes
1830{
1831 def v16i8: SHLQBYVecInst<v16i8>;
1832 def v8i16: SHLQBYVecInst<v8i16>;
1833 def v4i32: SHLQBYVecInst<v4i32>;
1834 def v2i64: SHLQBYVecInst<v2i64>;
1835 def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
1836 [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
1837}
Scott Michel8b6b4202007-12-04 22:35:58 +00001838
Scott Michel97872d32008-02-23 18:41:37 +00001839defm SHLQBY: ShiftLeftQuadBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00001840
Scott Michel97872d32008-02-23 18:41:37 +00001841class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
1842 RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
1843 RotateShift, pattern>;
Scott Michel438be252007-12-17 22:32:34 +00001844
Scott Michel97872d32008-02-23 18:41:37 +00001845class SHLQBYIVecInst<ValueType vectype>:
1846 SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
1847 [(set (vectype VECREG:$rT),
1848 (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00001849
Scott Michel97872d32008-02-23 18:41:37 +00001850multiclass ShiftLeftQuadBytesImm
1851{
1852 def v16i8: SHLQBYIVecInst<v16i8>;
1853 def v8i16: SHLQBYIVecInst<v8i16>;
1854 def v4i32: SHLQBYIVecInst<v4i32>;
1855 def v2i64: SHLQBYIVecInst<v2i64>;
1856 def r128: SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
1857 [(set GPRC:$rT,
1858 (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
1859}
Scott Michel438be252007-12-17 22:32:34 +00001860
Scott Michel97872d32008-02-23 18:41:37 +00001861defm SHLQBYI : ShiftLeftQuadBytesImm;
Scott Michel438be252007-12-17 22:32:34 +00001862
Scott Michel97872d32008-02-23 18:41:37 +00001863// Special form for truncating i64 to i32:
1864def SHLQBYItrunc64: SHLQBYIInst<(outs R32C:$rT), (ins R64C:$rA, u7imm_i32:$val),
1865 [/* no pattern, see below */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001866
Scott Michel97872d32008-02-23 18:41:37 +00001867def : Pat<(trunc R64C:$rSrc),
1868 (SHLQBYItrunc64 R64C:$rSrc, 4)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001869
Scott Michel97872d32008-02-23 18:41:37 +00001870//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1871// Rotate halfword:
1872//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1873class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
1874 RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
1875 RotateShift, pattern>;
1876
1877class ROTHVecInst<ValueType vectype>:
1878 ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1879 [(set (vectype VECREG:$rT),
1880 (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
1881
1882class ROTHRegInst<RegisterClass rclass>:
1883 ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1884 [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
1885
1886multiclass RotateLeftHalfword
1887{
1888 def v8i16: ROTHVecInst<v8i16>;
1889 def r16: ROTHRegInst<R16C>;
1890}
1891
1892defm ROTH: RotateLeftHalfword;
1893
1894def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
1895 [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
1896
1897//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1898// Rotate halfword, immediate:
1899//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1900class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
1901 RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
1902 RotateShift, pattern>;
1903
1904class ROTHIVecInst<ValueType vectype>:
1905 ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
1906 [(set (vectype VECREG:$rT),
1907 (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
1908
1909multiclass RotateLeftHalfwordImm
1910{
1911 def v8i16: ROTHIVecInst<v8i16>;
1912 def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
1913 [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
1914 def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
1915 [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
1916}
1917
1918defm ROTHI: RotateLeftHalfwordImm;
1919
1920def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00001921 (ROTHIv8i16 VECREG:$rA, imm:$val)>;
1922
Scott Michel97872d32008-02-23 18:41:37 +00001923//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1924// Rotate word:
1925//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001926
Scott Michel97872d32008-02-23 18:41:37 +00001927class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
1928 RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
1929 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001930
Scott Michel97872d32008-02-23 18:41:37 +00001931class ROTVecInst<ValueType vectype>:
1932 ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
1933 [(set (vectype VECREG:$rT),
1934 (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
Scott Michel438be252007-12-17 22:32:34 +00001935
Scott Michel97872d32008-02-23 18:41:37 +00001936class ROTRegInst<RegisterClass rclass>:
1937 ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
1938 [(set rclass:$rT,
1939 (rotl rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001940
Scott Michel97872d32008-02-23 18:41:37 +00001941multiclass RotateLeftWord
1942{
1943 def v4i32: ROTVecInst<v4i32>;
1944 def r32: ROTRegInst<R32C>;
1945}
1946
1947defm ROT: RotateLeftWord;
Scott Michel8b6b4202007-12-04 22:35:58 +00001948
Scott Michel438be252007-12-17 22:32:34 +00001949// The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
1950// 32-bit register
1951def ROTr32_r16_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00001952 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
1953 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00001954
1955def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
1956 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
1957
1958def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
1959 (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
1960
1961def ROTr32_r8_anyext:
Scott Michel97872d32008-02-23 18:41:37 +00001962 ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
1963 [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
Scott Michel438be252007-12-17 22:32:34 +00001964
1965def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
1966 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
1967
1968def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
1969 (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
1970
Scott Michel97872d32008-02-23 18:41:37 +00001971//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1972// Rotate word, immediate
1973//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00001974
Scott Michel97872d32008-02-23 18:41:37 +00001975class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
1976 RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
1977 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001978
Scott Michel97872d32008-02-23 18:41:37 +00001979class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
1980 ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
1981 [(set (vectype VECREG:$rT),
1982 (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
Scott Michel438be252007-12-17 22:32:34 +00001983
Scott Michel97872d32008-02-23 18:41:37 +00001984class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
1985 ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
1986 [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001987
Scott Michel97872d32008-02-23 18:41:37 +00001988multiclass RotateLeftWordImm
1989{
1990 def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
1991 def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
1992 def v4i32_i8: ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
Scott Michel8b6b4202007-12-04 22:35:58 +00001993
Scott Michel97872d32008-02-23 18:41:37 +00001994 def r32: ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
1995 def r32_i16: ROTIRegInst<R32C, u7imm, i16, uimm7>;
1996 def r32_i8: ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
1997}
Scott Michel438be252007-12-17 22:32:34 +00001998
Scott Michel97872d32008-02-23 18:41:37 +00001999defm ROTI : RotateLeftWordImm;
2000
2001//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2002// Rotate quad by byte (count)
2003//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2004
2005class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2006 RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2007 RotateShift, pattern>;
2008
2009class ROTQBYVecInst<ValueType vectype>:
2010 ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2011 [(set (vectype VECREG:$rT),
2012 (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2013
2014multiclass RotateQuadLeftByBytes
2015{
2016 def v16i8: ROTQBYVecInst<v16i8>;
2017 def v8i16: ROTQBYVecInst<v8i16>;
2018 def v4i32: ROTQBYVecInst<v4i32>;
2019 def v2i64: ROTQBYVecInst<v2i64>;
2020}
2021
2022defm ROTQBY: RotateQuadLeftByBytes;
Scott Michel8b6b4202007-12-04 22:35:58 +00002023
Scott Micheldbac4cf2008-01-11 02:53:15 +00002024def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), R32C:$rB),
Scott Michel97872d32008-02-23 18:41:37 +00002025 (ROTQBYv16i8 VECREG:$rA, R32C:$rB)>;
2026def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), R32C:$rB),
2027 (ROTQBYv8i16 VECREG:$rA, R32C:$rB)>;
2028def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), R32C:$rB),
2029 (ROTQBYv4i32 VECREG:$rA, R32C:$rB)>;
2030def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), R32C:$rB),
2031 (ROTQBYv2i64 VECREG:$rA, R32C:$rB)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002032
Scott Michel97872d32008-02-23 18:41:37 +00002033//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2034// Rotate quad by byte (count), immediate
2035//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2036
2037class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2038 RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2039 RotateShift, pattern>;
2040
2041class ROTQBYIVecInst<ValueType vectype>:
2042 ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2043 [(set (vectype VECREG:$rT),
2044 (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2045
2046multiclass RotateQuadByBytesImm
2047{
2048 def v16i8: ROTQBYIVecInst<v16i8>;
2049 def v8i16: ROTQBYIVecInst<v8i16>;
2050 def v4i32: ROTQBYIVecInst<v4i32>;
2051 def v2i64: ROTQBYIVecInst<v2i64>;
2052}
2053
2054defm ROTQBYI: RotateQuadByBytesImm;
Scott Michel8b6b4202007-12-04 22:35:58 +00002055
2056def : Pat<(SPUrotbytes_left_chained (v16i8 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel97872d32008-02-23 18:41:37 +00002057 (ROTQBYIv16i8 VECREG:$rA, uimm7:$val)>;
2058def : Pat<(SPUrotbytes_left_chained (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2059 (ROTQBYIv8i16 VECREG:$rA, uimm7:$val)>;
2060def : Pat<(SPUrotbytes_left_chained (v4i32 VECREG:$rA), (i16 uimm7:$val)),
2061 (ROTQBYIv4i32 VECREG:$rA, uimm7:$val)>;
2062def : Pat<(SPUrotbytes_left_chained (v2i64 VECREG:$rA), (i16 uimm7:$val)),
2063 (ROTQBYIv2i64 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002064
2065// See ROTQBY note above.
2066def ROTQBYBIvec:
2067 RI7Form<0b00110011100, (outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2068 "rotqbybi\t$rT, $rA, $val", RotateShift,
2069 [/* intrinsic */]>;
2070
Scott Michel97872d32008-02-23 18:41:37 +00002071//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002072// See ROTQBY note above.
2073//
2074// Assume that the user of this instruction knows to shift the rotate count
2075// into bit 29
Scott Michel97872d32008-02-23 18:41:37 +00002076//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002077
Scott Michel97872d32008-02-23 18:41:37 +00002078class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2079 RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2080 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002081
Scott Michel97872d32008-02-23 18:41:37 +00002082class ROTQBIVecInst<ValueType vectype>:
2083 ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2084 [/* no pattern yet */]>;
2085
2086class ROTQBIRegInst<RegisterClass rclass>:
2087 ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2088 [/* no pattern yet */]>;
2089
2090multiclass RotateQuadByBitCount
2091{
2092 def v16i8: ROTQBIVecInst<v16i8>;
2093 def v8i16: ROTQBIVecInst<v8i16>;
2094 def v4i32: ROTQBIVecInst<v4i32>;
2095 def v2i64: ROTQBIVecInst<v2i64>;
2096
2097 def r128: ROTQBIRegInst<GPRC>;
2098 def r64: ROTQBIRegInst<R64C>;
2099}
2100
2101defm ROTQBI: RotateQuadByBitCount;
2102
2103class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2104 RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2105 RotateShift, pattern>;
2106
2107class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2108 PatLeaf pred>:
2109 ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2110 [/* no pattern yet */]>;
2111
2112class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2113 PatLeaf pred>:
2114 ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2115 [/* no pattern yet */]>;
2116
2117multiclass RotateQuadByBitCountImm
2118{
2119 def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2120 def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2121 def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2122 def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2123
2124 def r128: ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2125 def r64: ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2126}
2127
2128defm ROTQBII : RotateQuadByBitCountImm;
2129
2130//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002131// ROTHM v8i16 form:
2132// NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2133// so this only matches a synthetically generated/lowered code
2134// fragment.
2135// NOTE(2): $rB must be negated before the right rotate!
Scott Michel97872d32008-02-23 18:41:37 +00002136//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002137
Scott Michel97872d32008-02-23 18:41:37 +00002138class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2139 RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2140 RotateShift, pattern>;
2141
2142def ROTHMv8i16:
2143 ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2144 [/* see patterns below - $rB must be negated */]>;
2145
2146def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002147 (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2148
Scott Michel97872d32008-02-23 18:41:37 +00002149def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002150 (ROTHMv8i16 VECREG:$rA,
2151 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2152
Scott Michel97872d32008-02-23 18:41:37 +00002153def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002154 (ROTHMv8i16 VECREG:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002155 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002156
2157// ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2158// Note: This instruction doesn't match a pattern because rB must be negated
2159// for the instruction to work. Thus, the pattern below the instruction!
Scott Michel97872d32008-02-23 18:41:37 +00002160
Scott Michel8b6b4202007-12-04 22:35:58 +00002161def ROTHMr16:
Scott Michel97872d32008-02-23 18:41:37 +00002162 ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2163 [/* see patterns below - $rB must be negated! */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002164
2165def : Pat<(srl R16C:$rA, R32C:$rB),
2166 (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2167
2168def : Pat<(srl R16C:$rA, R16C:$rB),
2169 (ROTHMr16 R16C:$rA,
2170 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2171
Scott Michel438be252007-12-17 22:32:34 +00002172def : Pat<(srl R16C:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002173 (ROTHMr16 R16C:$rA,
Scott Michel438be252007-12-17 22:32:34 +00002174 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002175
2176// ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2177// that the immediate can be complemented, so that the user doesn't have to
2178// worry about it.
Scott Michel8b6b4202007-12-04 22:35:58 +00002179
Scott Michel97872d32008-02-23 18:41:37 +00002180class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2181 RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2182 RotateShift, pattern>;
2183
2184def ROTHMIv8i16:
2185 ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2186 [/* no pattern */]>;
2187
2188def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2189 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2190
2191def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002192 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002193
Scott Michel97872d32008-02-23 18:41:37 +00002194def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
Scott Michel5a6f17b2008-01-30 02:55:46 +00002195 (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002196
2197def ROTHMIr16:
Scott Michel97872d32008-02-23 18:41:37 +00002198 ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2199 [/* no pattern */]>;
2200
2201def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2202 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002203
2204def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2205 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2206
Scott Michel438be252007-12-17 22:32:34 +00002207def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2208 (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2209
Scott Michel8b6b4202007-12-04 22:35:58 +00002210// ROTM v4i32 form: See the ROTHM v8i16 comments.
Scott Michel97872d32008-02-23 18:41:37 +00002211class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2212 RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2213 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002214
Scott Michel97872d32008-02-23 18:41:37 +00002215def ROTMv4i32:
2216 ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2217 [/* see patterns below - $rB must be negated */]>;
2218
2219def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002220 (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2221
Scott Michel97872d32008-02-23 18:41:37 +00002222def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002223 (ROTMv4i32 VECREG:$rA,
2224 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2225
Scott Michel97872d32008-02-23 18:41:37 +00002226def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002227 (ROTMv4i32 VECREG:$rA,
Scott Michel97872d32008-02-23 18:41:37 +00002228 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002229
2230def ROTMr32:
Scott Michel97872d32008-02-23 18:41:37 +00002231 ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2232 [/* see patterns below - $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002233
2234def : Pat<(srl R32C:$rA, R32C:$rB),
2235 (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2236
2237def : Pat<(srl R32C:$rA, R16C:$rB),
2238 (ROTMr32 R32C:$rA,
2239 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2240
Scott Michel438be252007-12-17 22:32:34 +00002241def : Pat<(srl R32C:$rA, R8C:$rB),
2242 (ROTMr32 R32C:$rA,
2243 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2244
Scott Michel8b6b4202007-12-04 22:35:58 +00002245// ROTMI v4i32 form: See the comment for ROTHM v8i16.
2246def ROTMIv4i32:
2247 RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2248 "rotmi\t$rT, $rA, $val", RotateShift,
2249 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002250 (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002251
Scott Michel97872d32008-02-23 18:41:37 +00002252def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002253 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel438be252007-12-17 22:32:34 +00002254
Scott Michel97872d32008-02-23 18:41:37 +00002255def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002256 (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002257
2258// ROTMI r32 form: know how to complement the immediate value.
2259def ROTMIr32:
2260 RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2261 "rotmi\t$rT, $rA, $val", RotateShift,
2262 [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2263
2264def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2265 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2266
Scott Michel438be252007-12-17 22:32:34 +00002267def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2268 (ROTMIr32 R32C:$rA, uimm7:$val)>;
2269
Scott Michel97872d32008-02-23 18:41:37 +00002270//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002271// ROTQMBYvec: This is a vector form merely so that when used in an
2272// instruction pattern, type checking will succeed. This instruction assumes
Scott Michel97872d32008-02-23 18:41:37 +00002273// that the user knew to negate $rB.
2274//
2275// Using the SPUrotquad_rz_bytes target-specific DAG node, the patterns
2276// ensure that $rB is negated.
2277//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002278
Scott Michel97872d32008-02-23 18:41:37 +00002279class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2280 RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2281 RotateShift, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002282
Scott Michel97872d32008-02-23 18:41:37 +00002283class ROTQMBYVecInst<ValueType vectype>:
2284 ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2285 [/* no pattern, $rB must be negated */]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002286
Scott Michel97872d32008-02-23 18:41:37 +00002287class ROTQMBYRegInst<RegisterClass rclass>:
2288 ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2289 [(set rclass:$rT,
2290 (SPUrotquad_rz_bytes rclass:$rA, R32C:$rB))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002291
Scott Michel97872d32008-02-23 18:41:37 +00002292multiclass RotateQuadBytes
2293{
2294 def v16i8: ROTQMBYVecInst<v16i8>;
2295 def v8i16: ROTQMBYVecInst<v8i16>;
2296 def v4i32: ROTQMBYVecInst<v4i32>;
2297 def v2i64: ROTQMBYVecInst<v2i64>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002298
Scott Michel97872d32008-02-23 18:41:37 +00002299 def r128: ROTQMBYRegInst<GPRC>;
2300 def r64: ROTQMBYRegInst<R64C>;
2301}
2302
2303defm ROTQMBY : RotateQuadBytes;
2304
2305def : Pat<(SPUrotquad_rz_bytes (v16i8 VECREG:$rA), R32C:$rB),
2306 (ROTQMBYv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2307def : Pat<(SPUrotquad_rz_bytes (v8i16 VECREG:$rA), R32C:$rB),
2308 (ROTQMBYv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2309def : Pat<(SPUrotquad_rz_bytes (v4i32 VECREG:$rA), R32C:$rB),
2310 (ROTQMBYv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2311def : Pat<(SPUrotquad_rz_bytes (v2i64 VECREG:$rA), R32C:$rB),
2312 (ROTQMBYv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2313def : Pat<(SPUrotquad_rz_bytes GPRC:$rA, R32C:$rB),
2314 (ROTQMBYr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2315def : Pat<(SPUrotquad_rz_bytes R64C:$rA, R32C:$rB),
2316 (ROTQMBYr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2317
2318class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2319 RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2320 RotateShift, pattern>;
2321
2322class ROTQMBYIVecInst<ValueType vectype>:
2323 ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2324 [(set (vectype VECREG:$rT),
2325 (SPUrotquad_rz_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2326
2327class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2328 ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2329 [(set rclass:$rT,
2330 (SPUrotquad_rz_bytes rclass:$rA, (inttype pred:$val)))]>;
2331
2332multiclass RotateQuadBytesImm
2333{
2334 def v16i8: ROTQMBYIVecInst<v16i8>;
2335 def v8i16: ROTQMBYIVecInst<v8i16>;
2336 def v4i32: ROTQMBYIVecInst<v4i32>;
2337 def v2i64: ROTQMBYIVecInst<v2i64>;
2338
2339 def r128: ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2340 def r64: ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2341}
2342
2343defm ROTQMBYI : RotateQuadBytesImm;
2344
2345
2346//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2347// Rotate right and mask by bit count
2348//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2349
2350class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2351 RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2352 RotateShift, pattern>;
2353
2354class ROTQMBYBIVecInst<ValueType vectype>:
2355 ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2356 [/* no pattern, intrinsic? */]>;
2357
2358multiclass RotateMaskQuadByBitCount
2359{
2360 def v16i8: ROTQMBYBIVecInst<v16i8>;
2361 def v8i16: ROTQMBYBIVecInst<v8i16>;
2362 def v4i32: ROTQMBYBIVecInst<v4i32>;
2363 def v2i64: ROTQMBYBIVecInst<v2i64>;
2364}
2365
2366defm ROTQMBYBI: RotateMaskQuadByBitCount;
2367
2368//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2369// Rotate quad and mask by bits
2370// Note that the rotate amount has to be negated
2371//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2372
2373class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2374 RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2375 RotateShift, pattern>;
2376
2377class ROTQMBIVecInst<ValueType vectype>:
2378 ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2379 [/* no pattern */]>;
2380
2381class ROTQMBIRegInst<RegisterClass rclass>:
2382 ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2383 [/* no pattern */]>;
2384
2385multiclass RotateMaskQuadByBits
2386{
2387 def v16i8: ROTQMBIVecInst<v16i8>;
2388 def v8i16: ROTQMBIVecInst<v8i16>;
2389 def v4i32: ROTQMBIVecInst<v4i32>;
2390 def v2i64: ROTQMBIVecInst<v2i64>;
2391
2392 def r128: ROTQMBIRegInst<GPRC>;
2393 def r64: ROTQMBIRegInst<R64C>;
2394}
2395
2396defm ROTQMBI: RotateMaskQuadByBits;
2397
2398def : Pat<(SPUrotquad_rz_bits (v16i8 VECREG:$rA), R32C:$rB),
2399 (ROTQMBIv16i8 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2400def : Pat<(SPUrotquad_rz_bits (v8i16 VECREG:$rA), R32C:$rB),
2401 (ROTQMBIv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2402def : Pat<(SPUrotquad_rz_bits (v4i32 VECREG:$rA), R32C:$rB),
2403 (ROTQMBIv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2404def : Pat<(SPUrotquad_rz_bits (v2i64 VECREG:$rA), R32C:$rB),
2405 (ROTQMBIv2i64 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2406def : Pat<(SPUrotquad_rz_bits GPRC:$rA, R32C:$rB),
2407 (ROTQMBIr128 GPRC:$rA, (SFIr32 R32C:$rB, 0))>;
2408def : Pat<(SPUrotquad_rz_bits R64C:$rA, R32C:$rB),
2409 (ROTQMBIr64 R64C:$rA, (SFIr32 R32C:$rB, 0))>;
2410
2411//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2412// Rotate quad and mask by bits, immediate
2413//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2414
2415class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2416 RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2417 RotateShift, pattern>;
2418
2419class ROTQMBIIVecInst<ValueType vectype>:
2420 ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2421 [(set (vectype VECREG:$rT),
2422 (SPUrotquad_rz_bits (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2423
2424class ROTQMBIIRegInst<RegisterClass rclass>:
2425 ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2426 [(set rclass:$rT,
2427 (SPUrotquad_rz_bits rclass:$rA, (i32 uimm7:$val)))]>;
2428
2429multiclass RotateMaskQuadByBitsImm
2430{
2431 def v16i8: ROTQMBIIVecInst<v16i8>;
2432 def v8i16: ROTQMBIIVecInst<v8i16>;
2433 def v4i32: ROTQMBIIVecInst<v4i32>;
2434 def v2i64: ROTQMBIIVecInst<v2i64>;
2435
2436 def r128: ROTQMBIIRegInst<GPRC>;
2437 def r64: ROTQMBIIRegInst<R64C>;
2438}
2439
2440defm ROTQMBII: RotateMaskQuadByBitsImm;
2441
2442//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2443//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00002444
2445def ROTMAHv8i16:
2446 RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2447 "rotmah\t$rT, $rA, $rB", RotateShift,
2448 [/* see patterns below - $rB must be negated */]>;
2449
Scott Michel97872d32008-02-23 18:41:37 +00002450def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002451 (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2452
Scott Michel97872d32008-02-23 18:41:37 +00002453def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002454 (ROTMAHv8i16 VECREG:$rA,
2455 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2456
Scott Michel97872d32008-02-23 18:41:37 +00002457def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002458 (ROTMAHv8i16 VECREG:$rA,
2459 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2460
Scott Michel8b6b4202007-12-04 22:35:58 +00002461def ROTMAHr16:
2462 RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2463 "rotmah\t$rT, $rA, $rB", RotateShift,
2464 [/* see patterns below - $rB must be negated */]>;
2465
2466def : Pat<(sra R16C:$rA, R32C:$rB),
2467 (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2468
2469def : Pat<(sra R16C:$rA, R16C:$rB),
2470 (ROTMAHr16 R16C:$rA,
2471 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2472
Scott Michel438be252007-12-17 22:32:34 +00002473def : Pat<(sra R16C:$rA, R8C:$rB),
2474 (ROTMAHr16 R16C:$rA,
2475 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2476
Scott Michel8b6b4202007-12-04 22:35:58 +00002477def ROTMAHIv8i16:
2478 RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2479 "rotmahi\t$rT, $rA, $val", RotateShift,
2480 [(set (v8i16 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002481 (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002482
Scott Michel97872d32008-02-23 18:41:37 +00002483def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002484 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2485
Scott Michel97872d32008-02-23 18:41:37 +00002486def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
Scott Michel438be252007-12-17 22:32:34 +00002487 (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2488
Scott Michel8b6b4202007-12-04 22:35:58 +00002489def ROTMAHIr16:
2490 RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2491 "rotmahi\t$rT, $rA, $val", RotateShift,
2492 [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2493
2494def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2495 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2496
Scott Michel438be252007-12-17 22:32:34 +00002497def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2498 (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2499
Scott Michel8b6b4202007-12-04 22:35:58 +00002500def ROTMAv4i32:
2501 RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2502 "rotma\t$rT, $rA, $rB", RotateShift,
2503 [/* see patterns below - $rB must be negated */]>;
2504
Scott Michel97872d32008-02-23 18:41:37 +00002505def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002506 (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2507
Scott Michel97872d32008-02-23 18:41:37 +00002508def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
Scott Michel8b6b4202007-12-04 22:35:58 +00002509 (ROTMAv4i32 (v4i32 VECREG:$rA),
2510 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2511
Scott Michel97872d32008-02-23 18:41:37 +00002512def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
Scott Michel438be252007-12-17 22:32:34 +00002513 (ROTMAv4i32 (v4i32 VECREG:$rA),
2514 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2515
Scott Michel8b6b4202007-12-04 22:35:58 +00002516def ROTMAr32:
2517 RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2518 "rotma\t$rT, $rA, $rB", RotateShift,
2519 [/* see patterns below - $rB must be negated */]>;
2520
2521def : Pat<(sra R32C:$rA, R32C:$rB),
2522 (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2523
2524def : Pat<(sra R32C:$rA, R16C:$rB),
2525 (ROTMAr32 R32C:$rA,
2526 (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2527
Scott Michel438be252007-12-17 22:32:34 +00002528def : Pat<(sra R32C:$rA, R8C:$rB),
2529 (ROTMAr32 R32C:$rA,
2530 (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2531
Scott Michel8b6b4202007-12-04 22:35:58 +00002532def ROTMAIv4i32:
2533 RRForm<0b01011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2534 "rotmai\t$rT, $rA, $val", RotateShift,
2535 [(set (v4i32 VECREG:$rT),
Scott Michel97872d32008-02-23 18:41:37 +00002536 (SPUvec_sra VECREG:$rA, (i32 uimm7:$val)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002537
Scott Michel97872d32008-02-23 18:41:37 +00002538def : Pat<(SPUvec_sra VECREG:$rA, (i16 uimm7:$val)),
Scott Michel8b6b4202007-12-04 22:35:58 +00002539 (ROTMAIv4i32 VECREG:$rA, uimm7:$val)>;
2540
2541def ROTMAIr32:
2542 RRForm<0b01011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2543 "rotmai\t$rT, $rA, $val", RotateShift,
2544 [(set R32C:$rT, (sra R32C:$rA, (i32 uimm7:$val)))]>;
2545
2546def : Pat<(sra R32C:$rA, (i16 uimm7:$val)),
2547 (ROTMAIr32 R32C:$rA, uimm7:$val)>;
2548
Scott Michel438be252007-12-17 22:32:34 +00002549def : Pat<(sra R32C:$rA, (i8 uimm7:$val)),
2550 (ROTMAIr32 R32C:$rA, uimm7:$val)>;
2551
Scott Michel8b6b4202007-12-04 22:35:58 +00002552//===----------------------------------------------------------------------===//
2553// Branch and conditionals:
2554//===----------------------------------------------------------------------===//
2555
2556let isTerminator = 1, isBarrier = 1 in {
2557 // Halt If Equal (r32 preferred slot only, no vector form)
2558 def HEQr32:
2559 RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
2560 "heq\t$rA, $rB", BranchResolv,
2561 [/* no pattern to match */]>;
2562
2563 def HEQIr32 :
2564 RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
2565 "heqi\t$rA, $val", BranchResolv,
2566 [/* no pattern to match */]>;
2567
2568 // HGT/HGTI: These instructions use signed arithmetic for the comparison,
2569 // contrasting with HLGT/HLGTI, which use unsigned comparison:
2570 def HGTr32:
2571 RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
2572 "hgt\t$rA, $rB", BranchResolv,
2573 [/* no pattern to match */]>;
2574
2575 def HGTIr32:
2576 RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
2577 "hgti\t$rA, $val", BranchResolv,
2578 [/* no pattern to match */]>;
2579
2580 def HLGTr32:
2581 RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
2582 "hlgt\t$rA, $rB", BranchResolv,
2583 [/* no pattern to match */]>;
2584
2585 def HLGTIr32:
2586 RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
2587 "hlgti\t$rA, $val", BranchResolv,
2588 [/* no pattern to match */]>;
2589}
2590
Scott Michel97872d32008-02-23 18:41:37 +00002591//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002592// Comparison operators:
Scott Michel97872d32008-02-23 18:41:37 +00002593//------------------------------------------------------------------------
Scott Michel8b6b4202007-12-04 22:35:58 +00002594
Scott Michel97872d32008-02-23 18:41:37 +00002595class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
2596 RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
2597 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002598
Scott Michel97872d32008-02-23 18:41:37 +00002599multiclass CmpEqualByte
2600{
2601 def v16i8 :
2602 CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2603 [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2604 (v8i16 VECREG:$rB)))]>;
Scott Michel438be252007-12-17 22:32:34 +00002605
Scott Michel97872d32008-02-23 18:41:37 +00002606 def r8 :
2607 CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2608 [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
2609}
Scott Michel8b6b4202007-12-04 22:35:58 +00002610
Scott Michel97872d32008-02-23 18:41:37 +00002611class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
2612 RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
2613 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002614
Scott Michel97872d32008-02-23 18:41:37 +00002615multiclass CmpEqualByteImm
2616{
2617 def v16i8 :
2618 CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2619 [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
2620 v16i8SExt8Imm:$val))]>;
2621 def r8:
2622 CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2623 [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
2624}
Scott Michel8b6b4202007-12-04 22:35:58 +00002625
Scott Michel97872d32008-02-23 18:41:37 +00002626class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
2627 RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
2628 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002629
Scott Michel97872d32008-02-23 18:41:37 +00002630multiclass CmpEqualHalfword
2631{
2632 def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2633 [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
2634 (v8i16 VECREG:$rB)))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002635
Scott Michel97872d32008-02-23 18:41:37 +00002636 def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2637 [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
2638}
Scott Michel8b6b4202007-12-04 22:35:58 +00002639
Scott Michel97872d32008-02-23 18:41:37 +00002640class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
2641 RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
2642 ByteOp, pattern>;
Scott Michel8b6b4202007-12-04 22:35:58 +00002643
Scott Michel97872d32008-02-23 18:41:37 +00002644multiclass CmpEqualHalfwordImm
2645{
2646 def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2647 [(set (v8i16 VECREG:$rT),
2648 (seteq (v8i16 VECREG:$rA),
2649 (v8i16 v8i16SExt10Imm:$val)))]>;
2650 def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2651 [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
2652}
Scott Michel8b6b4202007-12-04 22:35:58 +00002653
Scott Michel97872d32008-02-23 18:41:37 +00002654class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
2655 RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
2656 ByteOp, pattern>;
2657
2658multiclass CmpEqualWord
2659{
2660 def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2661 [(set (v4i32 VECREG:$rT),
2662 (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2663
2664 def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2665 [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
2666}
2667
2668class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
2669 RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
2670 ByteOp, pattern>;
2671
2672multiclass CmpEqualWordImm
2673{
2674 def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2675 [(set (v4i32 VECREG:$rT),
2676 (seteq (v4i32 VECREG:$rA),
2677 (v4i32 v4i32SExt16Imm:$val)))]>;
2678
2679 def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2680 [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
2681}
2682
2683class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
2684 RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
2685 ByteOp, pattern>;
2686
2687multiclass CmpGtrByte
2688{
2689 def v16i8 :
2690 CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2691 [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2692 (v8i16 VECREG:$rB)))]>;
2693
2694 def r8 :
2695 CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2696 [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
2697}
2698
2699class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
2700 RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
2701 ByteOp, pattern>;
2702
2703multiclass CmpGtrByteImm
2704{
2705 def v16i8 :
2706 CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2707 [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
2708 v16i8SExt8Imm:$val))]>;
2709 def r8:
2710 CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2711 [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
2712}
2713
2714class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
2715 RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
2716 ByteOp, pattern>;
2717
2718multiclass CmpGtrHalfword
2719{
2720 def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2721 [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
2722 (v8i16 VECREG:$rB)))]>;
2723
2724 def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2725 [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
2726}
2727
2728class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
2729 RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
2730 ByteOp, pattern>;
2731
2732multiclass CmpGtrHalfwordImm
2733{
2734 def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2735 [(set (v8i16 VECREG:$rT),
2736 (setgt (v8i16 VECREG:$rA),
2737 (v8i16 v8i16SExt10Imm:$val)))]>;
2738 def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2739 [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
2740}
2741
2742class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
2743 RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
2744 ByteOp, pattern>;
2745
2746multiclass CmpGtrWord
2747{
2748 def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2749 [(set (v4i32 VECREG:$rT),
2750 (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2751
2752 def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2753 [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
2754}
2755
2756class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
2757 RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
2758 ByteOp, pattern>;
2759
2760multiclass CmpGtrWordImm
2761{
2762 def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2763 [(set (v4i32 VECREG:$rT),
2764 (setgt (v4i32 VECREG:$rA),
2765 (v4i32 v4i32SExt16Imm:$val)))]>;
2766
2767 def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
2768 [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
2769}
2770
2771class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002772 RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002773 ByteOp, pattern>;
2774
2775multiclass CmpLGtrByte
2776{
2777 def v16i8 :
2778 CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2779 [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2780 (v8i16 VECREG:$rB)))]>;
2781
2782 def r8 :
2783 CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
2784 [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
2785}
2786
2787class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002788 RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002789 ByteOp, pattern>;
2790
2791multiclass CmpLGtrByteImm
2792{
2793 def v16i8 :
2794 CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
2795 [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
2796 v16i8SExt8Imm:$val))]>;
2797 def r8:
2798 CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
2799 [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
2800}
2801
2802class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002803 RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002804 ByteOp, pattern>;
2805
2806multiclass CmpLGtrHalfword
2807{
2808 def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2809 [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
2810 (v8i16 VECREG:$rB)))]>;
2811
2812 def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2813 [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
2814}
2815
2816class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002817 RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002818 ByteOp, pattern>;
2819
2820multiclass CmpLGtrHalfwordImm
2821{
2822 def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2823 [(set (v8i16 VECREG:$rT),
2824 (setugt (v8i16 VECREG:$rA),
2825 (v8i16 v8i16SExt10Imm:$val)))]>;
2826 def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
2827 [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
2828}
2829
2830class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002831 RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
Scott Michel97872d32008-02-23 18:41:37 +00002832 ByteOp, pattern>;
2833
2834multiclass CmpLGtrWord
2835{
2836 def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2837 [(set (v4i32 VECREG:$rT),
2838 (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
2839
2840 def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2841 [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
2842}
2843
2844class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
Scott Michel6baba072008-03-05 23:02:02 +00002845 RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
Scott Michel97872d32008-02-23 18:41:37 +00002846 ByteOp, pattern>;
2847
2848multiclass CmpLGtrWordImm
2849{
2850 def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
2851 [(set (v4i32 VECREG:$rT),
2852 (setugt (v4i32 VECREG:$rA),
2853 (v4i32 v4i32SExt16Imm:$val)))]>;
2854
2855 def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
Scott Michel6baba072008-03-05 23:02:02 +00002856 [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
Scott Michel97872d32008-02-23 18:41:37 +00002857}
2858
2859defm CEQB : CmpEqualByte;
2860defm CEQBI : CmpEqualByteImm;
2861defm CEQH : CmpEqualHalfword;
2862defm CEQHI : CmpEqualHalfwordImm;
2863defm CEQ : CmpEqualWord;
2864defm CEQI : CmpEqualWordImm;
2865defm CGTB : CmpGtrByte;
2866defm CGTBI : CmpGtrByteImm;
2867defm CGTH : CmpGtrHalfword;
2868defm CGTHI : CmpGtrHalfwordImm;
2869defm CGT : CmpGtrWord;
2870defm CGTI : CmpGtrWordImm;
2871defm CLGTB : CmpLGtrByte;
2872defm CLGTBI : CmpLGtrByteImm;
2873defm CLGTH : CmpLGtrHalfword;
2874defm CLGTHI : CmpLGtrHalfwordImm;
2875defm CLGT : CmpLGtrWord;
2876defm CLGTI : CmpLGtrWordImm;
2877
Scott Michel53ab7792008-03-10 16:58:52 +00002878//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00002879// For SETCC primitives not supported above (setlt, setle, setge, etc.)
2880// define a pattern to generate the right code, as a binary operator
2881// (in a manner of speaking.)
Scott Michel53ab7792008-03-10 16:58:52 +00002882//
2883// N.B.: This only matches the setcc set of conditionals. Special pattern
2884// matching is used for select conditionals.
2885//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel97872d32008-02-23 18:41:37 +00002886
Scott Michel53ab7792008-03-10 16:58:52 +00002887class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
2888 SPUInstr xorinst, SPUInstr cmpare>:
2889 Pat<(cond rclass:$rA, rclass:$rB),
2890 (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
2891
2892class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
2893 PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
2894 Pat<(cond rclass:$rA, (inttype immpred:$imm)),
2895 (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
2896
2897def : SETCCNegCondReg<setne, R8C, i8, XORBIr8, CEQBr8>;
2898def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
2899
2900def : SETCCNegCondReg<setne, R16C, i16, XORHIr16, CEQHr16>;
2901def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
2902
2903def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
2904def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00002905
2906class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
2907 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
2908 Pat<(cond rclass:$rA, rclass:$rB),
2909 (binop (cmpOp1 rclass:$rA, rclass:$rB),
2910 (cmpOp2 rclass:$rA, rclass:$rB))>;
2911
2912class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
2913 ValueType immtype,
2914 SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
2915 Pat<(cond rclass:$rA, (immtype immpred:$imm)),
2916 (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
2917 (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
2918
Scott Michel53ab7792008-03-10 16:58:52 +00002919def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
2920def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
2921def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
2922def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
2923def : Pat<(setle R8C:$rA, R8C:$rB),
2924 (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
2925def : Pat<(setle R8C:$rA, immU8:$imm),
2926 (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002927
Scott Michel53ab7792008-03-10 16:58:52 +00002928def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
2929def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
2930 ORr16, CGTHIr16, CEQHIr16>;
2931def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
2932def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
2933def : Pat<(setle R16C:$rA, R16C:$rB),
2934 (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
2935def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
2936 (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002937
Scott Michel53ab7792008-03-10 16:58:52 +00002938def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
2939def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
2940 ORr32, CGTIr32, CEQIr32>;
2941def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
2942def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
2943def : Pat<(setle R32C:$rA, R32C:$rB),
2944 (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
2945def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
2946 (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002947
Scott Michel53ab7792008-03-10 16:58:52 +00002948def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
2949def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
2950def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
2951def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
2952def : Pat<(setule R8C:$rA, R8C:$rB),
2953 (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
2954def : Pat<(setule R8C:$rA, immU8:$imm),
2955 (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002956
Scott Michel53ab7792008-03-10 16:58:52 +00002957def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
2958def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
2959 ORr16, CLGTHIr16, CEQHIr16>;
2960def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
2961def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
2962 CLGTHIr16, CEQHIr16>;
2963def : Pat<(setule R16C:$rA, R16C:$rB),
2964 (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
2965def : Pat<(setule R16C:$rA, i16ImmUns10:$imm),
2966 (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002967
Scott Michel53ab7792008-03-10 16:58:52 +00002968def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
2969def : SETCCBinOpImm<setuge, R32C, i32ImmUns10, i32,
2970 ORr32, CLGTIr32, CEQIr32>;
2971def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
2972def : SETCCBinOpImm<setult, R32C, immSExt8, i32, NORr32, CLGTIr32, CEQIr32>;
2973def : Pat<(setule R32C:$rA, R32C:$rB),
2974 (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
2975def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
2976 (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
Scott Michel97872d32008-02-23 18:41:37 +00002977
Scott Michel53ab7792008-03-10 16:58:52 +00002978//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2979// select conditional patterns:
2980//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2981
2982class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
2983 SPUInstr selinstr, SPUInstr cmpare>:
2984 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
2985 rclass:$rTrue, rclass:$rFalse),
2986 (selinstr rclass:$rTrue, rclass:$rFalse,
2987 (cmpare rclass:$rA, rclass:$rB))>;
2988
2989class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
2990 PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
2991 Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
2992 rclass:$rTrue, rclass:$rFalse),
2993 (selinstr rclass:$rTrue, rclass:$rFalse,
2994 (cmpare rclass:$rA, immpred:$imm))>;
2995
2996def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
2997def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
2998def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
2999def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3000def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3001def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3002
3003def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3004def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3005def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3006def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3007def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3008def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3009
3010def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3011def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3012def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3013def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3014def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3015def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3016
3017class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3018 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3019 SPUInstr cmpOp2>:
3020 Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3021 rclass:$rFalse, rclass:$rTrue),
3022 (selinstr rclass:$rTrue, rclass:$rFalse,
3023 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3024 (cmpOp2 rclass:$rA, rclass:$rB)))>;
3025
3026class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3027 ValueType inttype,
3028 SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3029 SPUInstr cmpOp2>:
3030 Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
3031 rclass:$rTrue, rclass:$rFalse),
3032 (selinstr rclass:$rFalse, rclass:$rTrue,
3033 (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3034 (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3035
3036def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3037def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3038 SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3039
3040def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3041def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3042 SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3043
3044def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3045def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3046 SELBr32, ORr32, CGTIr32, CEQIr32>;
3047
3048def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3049def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3050 SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3051
3052def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3053def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3054 SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3055
3056def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3057def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3058 SELBr32, ORr32, CLGTIr32, CEQIr32>;
Scott Michel97872d32008-02-23 18:41:37 +00003059
3060//-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Scott Michel8b6b4202007-12-04 22:35:58 +00003061
3062let isCall = 1,
3063 // All calls clobber the non-callee-saved registers:
3064 Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3065 R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3066 R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3067 R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3068 R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3069 R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3070 R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3071 R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3072 // All of these instructions use $lr (aka $0)
3073 Uses = [R0] in {
3074 // Branch relative and set link: Used if we actually know that the target
3075 // is within [-32768, 32767] bytes of the target
3076 def BRSL:
3077 BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3078 "brsl\t$$lr, $func",
3079 [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3080
3081 // Branch absolute and set link: Used if we actually know that the target
3082 // is an absolute address
3083 def BRASL:
3084 BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3085 "brasl\t$$lr, $func",
Scott Micheldbac4cf2008-01-11 02:53:15 +00003086 [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003087
3088 // Branch indirect and set link if external data. These instructions are not
3089 // actually generated, matched by an intrinsic:
3090 def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3091 def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3092 def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3093 def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3094
3095 // Branch indirect and set link. This is the "X-form" address version of a
3096 // function call
3097 def BISL:
3098 BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3099}
3100
3101// Unconditional branches:
3102let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3103 def BR :
3104 UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3105 "br\t$dest",
3106 [(br bb:$dest)]>;
3107
3108 // Unconditional, absolute address branch
3109 def BRA:
3110 UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3111 "bra\t$dest",
3112 [/* no pattern */]>;
3113
3114 // Indirect branch
3115 def BI:
3116 BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3117
3118 // Various branches:
3119 def BRNZ:
3120 RI16Form<0b010000100, (outs), (ins R32C:$rCond, brtarget:$dest),
3121 "brnz\t$rCond,$dest",
3122 BranchResolv,
3123 [(brcond R32C:$rCond, bb:$dest)]>;
3124
3125 def BRZ:
3126 RI16Form<0b000000100, (outs), (ins R32C:$rT, brtarget:$dest),
3127 "brz\t$rT,$dest",
3128 BranchResolv,
3129 [/* no pattern */]>;
3130
3131 def BRHNZ:
3132 RI16Form<0b011000100, (outs), (ins R16C:$rCond, brtarget:$dest),
3133 "brhnz\t$rCond,$dest",
3134 BranchResolv,
3135 [(brcond R16C:$rCond, bb:$dest)]>;
3136
3137 def BRHZ:
3138 RI16Form<0b001000100, (outs), (ins R16C:$rT, brtarget:$dest),
3139 "brhz\t$rT,$dest",
3140 BranchResolv,
3141 [/* no pattern */]>;
3142
3143/*
3144 def BINZ:
3145 BICondForm<0b10010100100, "binz\t$rA, $func",
3146 [(SPUbinz R32C:$rA, R32C:$func)]>;
3147
3148 def BIZ:
3149 BICondForm<0b00010100100, "biz\t$rA, $func",
3150 [(SPUbiz R32C:$rA, R32C:$func)]>;
3151*/
3152}
3153
Scott Michel394e26d2008-01-17 20:38:41 +00003154//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003155// setcc and brcond patterns:
Scott Michel394e26d2008-01-17 20:38:41 +00003156//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003157
Scott Michel8b6b4202007-12-04 22:35:58 +00003158def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3159 (BRHZ R16C:$rA, bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003160def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3161 (BRHNZ R16C:$rA, bb:$dest)>;
Scott Michel97872d32008-02-23 18:41:37 +00003162
3163def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3164 (BRZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003165def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
Scott Michel394e26d2008-01-17 20:38:41 +00003166 (BRNZ R32C:$rA, bb:$dest)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003167
Scott Michel97872d32008-02-23 18:41:37 +00003168multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3169{
3170 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3171 (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003172
Scott Michel97872d32008-02-23 18:41:37 +00003173 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3174 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3175
3176 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3177 (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3178
3179 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3180 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3181}
3182
3183defm BRCONDeq : BranchCondEQ<seteq, BRHZ, BRZ>;
3184defm BRCONDne : BranchCondEQ<setne, BRHNZ, BRNZ>;
3185
3186multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3187{
3188 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3189 (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3190
3191 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3192 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3193
3194 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3195 (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3196
3197 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3198 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3199}
3200
3201defm BRCONDugt : BranchCondLGT<setugt, BRHNZ, BRNZ>;
3202defm BRCONDule : BranchCondLGT<setule, BRHZ, BRZ>;
3203
3204multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3205 SPUInstr orinst32, SPUInstr brinst32>
3206{
3207 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3208 (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3209 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3210 bb:$dest)>;
3211
3212 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3213 (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3214 (CEQHr16 R16C:$rA, R16:$rB)),
3215 bb:$dest)>;
3216
3217 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3218 (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3219 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3220 bb:$dest)>;
3221
3222 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3223 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3224 (CEQr32 R32C:$rA, R32C:$rB)),
3225 bb:$dest)>;
3226}
3227
3228defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZ, ORr32, BRNZ>;
3229defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZ, ORr32, BRZ>;
3230
3231multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3232{
3233 def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3234 (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3235
3236 def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3237 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3238
3239 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3240 (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3241
3242 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3243 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3244}
3245
3246defm BRCONDgt : BranchCondGT<setgt, BRHNZ, BRNZ>;
3247defm BRCONDle : BranchCondGT<setle, BRHZ, BRZ>;
3248
3249multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3250 SPUInstr orinst32, SPUInstr brinst32>
3251{
3252 def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3253 (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3254 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3255 bb:$dest)>;
3256
3257 def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3258 (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3259 (CEQHr16 R16C:$rA, R16:$rB)),
3260 bb:$dest)>;
3261
3262 def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3263 (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3264 (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3265 bb:$dest)>;
3266
3267 def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3268 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3269 (CEQr32 R32C:$rA, R32C:$rB)),
3270 bb:$dest)>;
3271}
3272
3273defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZ, ORr32, BRNZ>;
3274defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZ, ORr32, BRZ>;
Scott Michelf9f42e62008-01-29 02:16:57 +00003275
Scott Michel8b6b4202007-12-04 22:35:58 +00003276let isTerminator = 1, isBarrier = 1 in {
3277 let isReturn = 1 in {
3278 def RET:
3279 RETForm<"bi\t$$lr", [(retflag)]>;
3280 }
3281}
3282
3283//===----------------------------------------------------------------------===//
Scott Michel8b6b4202007-12-04 22:35:58 +00003284// Single precision floating point instructions
3285//===----------------------------------------------------------------------===//
3286
3287def FAv4f32:
3288 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3289 "fa\t$rT, $rA, $rB", SPrecFP,
3290 [(set (v4f32 VECREG:$rT), (fadd (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3291
3292def FAf32 :
3293 RRForm<0b00100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3294 "fa\t$rT, $rA, $rB", SPrecFP,
3295 [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3296
3297def FSv4f32:
3298 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3299 "fs\t$rT, $rA, $rB", SPrecFP,
3300 [(set (v4f32 VECREG:$rT), (fsub (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)))]>;
3301
3302def FSf32 :
3303 RRForm<0b10100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3304 "fs\t$rT, $rA, $rB", SPrecFP,
3305 [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3306
3307// Floating point reciprocal estimate
3308def FREv4f32 :
3309 RRForm_1<0b00011101100, (outs VECREG:$rT), (ins VECREG:$rA),
3310 "frest\t$rT, $rA", SPrecFP,
3311 [(set (v4f32 VECREG:$rT), (SPUreciprocalEst (v4f32 VECREG:$rA)))]>;
3312
3313def FREf32 :
3314 RRForm_1<0b00011101100, (outs R32FP:$rT), (ins R32FP:$rA),
3315 "frest\t$rT, $rA", SPrecFP,
3316 [(set R32FP:$rT, (SPUreciprocalEst R32FP:$rA))]>;
3317
3318// Floating point interpolate (used in conjunction with reciprocal estimate)
3319def FIv4f32 :
3320 RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3321 "fi\t$rT, $rA, $rB", SPrecFP,
3322 [(set (v4f32 VECREG:$rT), (SPUinterpolate (v4f32 VECREG:$rA),
3323 (v4f32 VECREG:$rB)))]>;
3324
3325def FIf32 :
3326 RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3327 "fi\t$rT, $rA, $rB", SPrecFP,
3328 [(set R32FP:$rT, (SPUinterpolate R32FP:$rA, R32FP:$rB))]>;
3329
3330// Floating Compare Equal
3331def FCEQf32 :
3332 RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3333 "fceq\t$rT, $rA, $rB", SPrecFP,
3334 [(set R32C:$rT, (setoeq R32FP:$rA, R32FP:$rB))]>;
3335
3336def FCMEQf32 :
3337 RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3338 "fcmeq\t$rT, $rA, $rB", SPrecFP,
3339 [(set R32C:$rT, (setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3340
3341def FCGTf32 :
3342 RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3343 "fcgt\t$rT, $rA, $rB", SPrecFP,
3344 [(set R32C:$rT, (setogt R32FP:$rA, R32FP:$rB))]>;
3345
3346def FCMGTf32 :
3347 RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3348 "fcmgt\t$rT, $rA, $rB", SPrecFP,
3349 [(set R32C:$rT, (setogt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3350
3351// FP Status and Control Register Write
3352// Why isn't rT a don't care in the ISA?
3353// Should we create a special RRForm_3 for this guy and zero out the rT?
3354def FSCRWf32 :
3355 RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3356 "fscrwr\t$rA", SPrecFP,
3357 [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3358
3359// FP Status and Control Register Read
3360def FSCRRf32 :
3361 RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3362 "fscrrd\t$rT", SPrecFP,
3363 [/* This instruction requires an intrinsic */]>;
3364
3365// llvm instruction space
3366// How do these map onto cell instructions?
3367// fdiv rA rB
3368// frest rC rB # c = 1/b (both lines)
3369// fi rC rB rC
3370// fm rD rA rC # d = a * 1/b
3371// fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
3372// fma rB rB rC rD # b = b * c + d
3373// = -(d *b -a) * c + d
3374// = a * c - c ( a *b *c - a)
3375
3376// fcopysign (???)
3377
3378// Library calls:
3379// These llvm instructions will actually map to library calls.
3380// All that's needed, then, is to check that the appropriate library is
3381// imported and do a brsl to the proper function name.
3382// frem # fmod(x, y): x - (x/y) * y
3383// (Note: fmod(double, double), fmodf(float,float)
3384// fsqrt?
3385// fsin?
3386// fcos?
3387// Unimplemented SPU instruction space
3388// floating reciprocal absolute square root estimate (frsqest)
3389
3390// The following are probably just intrinsics
3391// status and control register write
3392// status and control register read
3393
3394//--------------------------------------
3395// Floating point multiply instructions
3396//--------------------------------------
3397
3398def FMv4f32:
3399 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3400 "fm\t$rT, $rA, $rB", SPrecFP,
3401 [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
3402 (v4f32 VECREG:$rB)))]>;
3403
3404def FMf32 :
3405 RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3406 "fm\t$rT, $rA, $rB", SPrecFP,
3407 [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
3408
3409// Floating point multiply and add
3410// e.g. d = c + (a * b)
3411def FMAv4f32:
3412 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3413 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3414 [(set (v4f32 VECREG:$rT),
3415 (fadd (v4f32 VECREG:$rC),
3416 (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
3417
3418def FMAf32:
3419 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3420 "fma\t$rT, $rA, $rB, $rC", SPrecFP,
3421 [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3422
3423// FP multiply and subtract
3424// Subtracts value in rC from product
3425// res = a * b - c
3426def FMSv4f32 :
3427 RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3428 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3429 [(set (v4f32 VECREG:$rT),
3430 (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
3431 (v4f32 VECREG:$rC)))]>;
3432
3433def FMSf32 :
3434 RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3435 "fms\t$rT, $rA, $rB, $rC", SPrecFP,
3436 [(set R32FP:$rT,
3437 (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
3438
3439// Floating Negative Mulitply and Subtract
3440// Subtracts product from value in rC
3441// res = fneg(fms a b c)
3442// = - (a * b - c)
3443// = c - a * b
3444// NOTE: subtraction order
3445// fsub a b = a - b
3446// fs a b = b - a?
3447def FNMSf32 :
3448 RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
3449 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3450 [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
3451
3452def FNMSv4f32 :
3453 RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3454 "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
3455 [(set (v4f32 VECREG:$rT),
3456 (fsub (v4f32 VECREG:$rC),
3457 (fmul (v4f32 VECREG:$rA),
3458 (v4f32 VECREG:$rB))))]>;
3459
3460//--------------------------------------
3461// Floating Point Conversions
3462// Signed conversions:
3463def CSiFv4f32:
3464 CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3465 "csflt\t$rT, $rA, 0", SPrecFP,
3466 [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
3467
3468// Convert signed integer to floating point
3469def CSiFf32 :
3470 CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
3471 "csflt\t$rT, $rA, 0", SPrecFP,
3472 [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
3473
3474// Convert unsigned into to float
3475def CUiFv4f32 :
3476 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3477 "cuflt\t$rT, $rA, 0", SPrecFP,
3478 [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
3479
3480def CUiFf32 :
3481 CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
3482 "cuflt\t$rT, $rA, 0", SPrecFP,
3483 [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
3484
3485// Convert float to unsigned int
3486// Assume that scale = 0
3487
3488def CFUiv4f32 :
3489 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3490 "cfltu\t$rT, $rA, 0", SPrecFP,
3491 [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
3492
3493def CFUif32 :
3494 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3495 "cfltu\t$rT, $rA, 0", SPrecFP,
3496 [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
3497
3498// Convert float to signed int
3499// Assume that scale = 0
3500
3501def CFSiv4f32 :
3502 CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
3503 "cflts\t$rT, $rA, 0", SPrecFP,
3504 [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
3505
3506def CFSif32 :
3507 CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
3508 "cflts\t$rT, $rA, 0", SPrecFP,
3509 [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
3510
3511//===----------------------------------------------------------------------==//
3512// Single<->Double precision conversions
3513//===----------------------------------------------------------------------==//
3514
3515// NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
3516// v4f32, output is v2f64--which goes in the name?)
3517
3518// Floating point extend single to double
3519// NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
3520// operates on two double-word slots (i.e. 1st and 3rd fp numbers
3521// are ignored).
3522def FESDvec :
3523 RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3524 "fesd\t$rT, $rA", SPrecFP,
3525 [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
3526
3527def FESDf32 :
3528 RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
3529 "fesd\t$rT, $rA", SPrecFP,
3530 [(set R64FP:$rT, (fextend R32FP:$rA))]>;
3531
3532// Floating point round double to single
3533//def FRDSvec :
3534// RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
3535// "frds\t$rT, $rA,", SPrecFP,
3536// [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
3537
3538def FRDSf64 :
3539 RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
3540 "frds\t$rT, $rA", SPrecFP,
3541 [(set R32FP:$rT, (fround R64FP:$rA))]>;
3542
3543//ToDo include anyextend?
3544
3545//===----------------------------------------------------------------------==//
3546// Double precision floating point instructions
3547//===----------------------------------------------------------------------==//
3548def FAf64 :
3549 RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3550 "dfa\t$rT, $rA, $rB", DPrecFP,
3551 [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
3552
3553def FAv2f64 :
3554 RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3555 "dfa\t$rT, $rA, $rB", DPrecFP,
3556 [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3557
3558def FSf64 :
3559 RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3560 "dfs\t$rT, $rA, $rB", DPrecFP,
3561 [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
3562
3563def FSv2f64 :
3564 RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3565 "dfs\t$rT, $rA, $rB", DPrecFP,
3566 [(set (v2f64 VECREG:$rT),
3567 (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3568
3569def FMf64 :
3570 RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
3571 "dfm\t$rT, $rA, $rB", DPrecFP,
3572 [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
3573
3574def FMv2f64:
3575 RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3576 "dfm\t$rT, $rA, $rB", DPrecFP,
3577 [(set (v2f64 VECREG:$rT),
3578 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
3579
3580def FMAf64:
3581 RRForm<0b00111010110, (outs R64FP:$rT),
3582 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3583 "dfma\t$rT, $rA, $rB", DPrecFP,
3584 [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3585 RegConstraint<"$rC = $rT">,
3586 NoEncode<"$rC">;
3587
3588def FMAv2f64:
3589 RRForm<0b00111010110, (outs VECREG:$rT),
3590 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3591 "dfma\t$rT, $rA, $rB", DPrecFP,
3592 [(set (v2f64 VECREG:$rT),
3593 (fadd (v2f64 VECREG:$rC),
3594 (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
3595 RegConstraint<"$rC = $rT">,
3596 NoEncode<"$rC">;
3597
3598def FMSf64 :
3599 RRForm<0b10111010110, (outs R64FP:$rT),
3600 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3601 "dfms\t$rT, $rA, $rB", DPrecFP,
3602 [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
3603 RegConstraint<"$rC = $rT">,
3604 NoEncode<"$rC">;
3605
3606def FMSv2f64 :
3607 RRForm<0b10111010110, (outs VECREG:$rT),
3608 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3609 "dfms\t$rT, $rA, $rB", DPrecFP,
3610 [(set (v2f64 VECREG:$rT),
3611 (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3612 (v2f64 VECREG:$rC)))]>;
3613
3614// FNMS: - (a * b - c)
3615// - (a * b) + c => c - (a * b)
3616def FNMSf64 :
3617 RRForm<0b01111010110, (outs R64FP:$rT),
3618 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3619 "dfnms\t$rT, $rA, $rB", DPrecFP,
3620 [(set R64FP:$rT, (fsub R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
3621 RegConstraint<"$rC = $rT">,
3622 NoEncode<"$rC">;
3623
3624def : Pat<(fneg (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC)),
3625 (FNMSf64 R64FP:$rA, R64FP:$rB, R64FP:$rC)>;
3626
3627def FNMSv2f64 :
3628 RRForm<0b01111010110, (outs VECREG:$rT),
3629 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3630 "dfnms\t$rT, $rA, $rB", DPrecFP,
3631 [(set (v2f64 VECREG:$rT),
3632 (fsub (v2f64 VECREG:$rC),
3633 (fmul (v2f64 VECREG:$rA),
3634 (v2f64 VECREG:$rB))))]>,
3635 RegConstraint<"$rC = $rT">,
3636 NoEncode<"$rC">;
3637
3638def : Pat<(fneg (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
3639 (v2f64 VECREG:$rC))),
3640 (FNMSv2f64 VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
3641
3642// - (a * b + c)
3643// - (a * b) - c
3644def FNMAf64 :
3645 RRForm<0b11111010110, (outs R64FP:$rT),
3646 (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
3647 "dfnma\t$rT, $rA, $rB", DPrecFP,
3648 [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
3649 RegConstraint<"$rC = $rT">,
3650 NoEncode<"$rC">;
3651
3652def FNMAv2f64 :
3653 RRForm<0b11111010110, (outs VECREG:$rT),
3654 (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
3655 "dfnma\t$rT, $rA, $rB", DPrecFP,
3656 [(set (v2f64 VECREG:$rT),
3657 (fneg (fadd (v2f64 VECREG:$rC),
3658 (fmul (v2f64 VECREG:$rA),
3659 (v2f64 VECREG:$rB)))))]>,
3660 RegConstraint<"$rC = $rT">,
3661 NoEncode<"$rC">;
3662
3663//===----------------------------------------------------------------------==//
3664// Floating point negation and absolute value
3665//===----------------------------------------------------------------------==//
3666
3667def : Pat<(fneg (v4f32 VECREG:$rA)),
3668 (XORfnegvec (v4f32 VECREG:$rA),
3669 (v4f32 (ILHUv4i32 0x8000)))>;
3670
3671def : Pat<(fneg R32FP:$rA),
3672 (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
3673
3674def : Pat<(fneg (v2f64 VECREG:$rA)),
3675 (XORfnegvec (v2f64 VECREG:$rA),
3676 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80)))>;
3677
3678def : Pat<(fneg R64FP:$rA),
3679 (XORfneg64 R64FP:$rA,
3680 (ANDBIv16i8 (FSMBIv16i8 0x8080), 0x80))>;
3681
3682// Floating point absolute value
3683
3684def : Pat<(fabs R32FP:$rA),
3685 (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
3686
3687def : Pat<(fabs (v4f32 VECREG:$rA)),
3688 (ANDfabsvec (v4f32 VECREG:$rA),
3689 (v4f32 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3690
3691def : Pat<(fabs R64FP:$rA),
3692 (ANDfabs64 R64FP:$rA, (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f))>;
3693
3694def : Pat<(fabs (v2f64 VECREG:$rA)),
3695 (ANDfabsvec (v2f64 VECREG:$rA),
3696 (v2f64 (ANDBIv16i8 (FSMBIv16i8 0xffff), 0x7f)))>;
3697
3698//===----------------------------------------------------------------------===//
3699// Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
3700// in the odd pipeline)
3701//===----------------------------------------------------------------------===//
3702
Scott Michel97872d32008-02-23 18:41:37 +00003703def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003704 let Pattern = [];
3705
3706 let Inst{0-10} = 0b10000000010;
3707 let Inst{11-17} = 0;
3708 let Inst{18-24} = 0;
3709 let Inst{25-31} = 0;
3710}
3711
Scott Michel97872d32008-02-23 18:41:37 +00003712def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
Scott Michel8b6b4202007-12-04 22:35:58 +00003713 let Pattern = [];
3714
3715 let Inst{0-10} = 0b10000000000;
3716 let Inst{11-17} = 0;
3717 let Inst{18-24} = 0;
3718 let Inst{25-31} = 0;
3719}
3720
3721//===----------------------------------------------------------------------===//
3722// Bit conversions (type conversions between vector/packed types)
3723// NOTE: Promotions are handled using the XS* instructions. Truncation
3724// is not handled.
3725//===----------------------------------------------------------------------===//
3726def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
3727def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
3728def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
3729def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
3730def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
3731
3732def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
3733def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
3734def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
3735def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
3736def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
3737
3738def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
3739def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
3740def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
3741def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
3742def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
3743
3744def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
3745def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
3746def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
3747def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
3748def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
3749
3750def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
3751def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
3752def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
3753def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
3754def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
3755
3756def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
3757def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
3758def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
3759def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
3760def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
3761
3762def : Pat<(f32 (bitconvert (i32 R32C:$src))), (f32 R32FP:$src)>;
Scott Michel754d8662007-12-20 00:44:13 +00003763def : Pat<(f64 (bitconvert (i64 R64C:$src))), (f64 R64FP:$src)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003764
3765//===----------------------------------------------------------------------===//
3766// Instruction patterns:
3767//===----------------------------------------------------------------------===//
3768
3769// General 32-bit constants:
3770def : Pat<(i32 imm:$imm),
3771 (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
3772
3773// Single precision float constants:
Nate Begeman78125042008-02-14 18:43:04 +00003774def : Pat<(f32 fpimm:$imm),
Scott Michel8b6b4202007-12-04 22:35:58 +00003775 (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
3776
3777// General constant 32-bit vectors
3778def : Pat<(v4i32 v4i32Imm:$imm),
Scott Michel6baba072008-03-05 23:02:02 +00003779 (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
3780 (LO16_vec v4i32Imm:$imm))>;
Scott Michel438be252007-12-17 22:32:34 +00003781
3782// 8-bit constants
3783def : Pat<(i8 imm:$imm),
3784 (ILHr8 imm:$imm)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003785
3786//===----------------------------------------------------------------------===//
3787// Call instruction patterns:
3788//===----------------------------------------------------------------------===//
3789// Return void
3790def : Pat<(ret),
3791 (RET)>;
3792
3793//===----------------------------------------------------------------------===//
3794// Zero/Any/Sign extensions
3795//===----------------------------------------------------------------------===//
3796
3797// zext 1->32: Zero extend i1 to i32
3798def : Pat<(SPUextract_i1_zext R32C:$rSrc),
3799 (ANDIr32 R32C:$rSrc, 0x1)>;
3800
3801// sext 8->32: Sign extend bytes to words
3802def : Pat<(sext_inreg R32C:$rSrc, i8),
3803 (XSHWr32 (XSBHr32 R32C:$rSrc))>;
3804
Scott Michel438be252007-12-17 22:32:34 +00003805def : Pat<(i32 (sext R8C:$rSrc)),
3806 (XSHWr16 (XSBHr8 R8C:$rSrc))>;
3807
Scott Michel8b6b4202007-12-04 22:35:58 +00003808def : Pat<(SPUextract_i8_sext VECREG:$rSrc),
3809 (XSHWr32 (XSBHr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc),
3810 (v4i32 VECREG:$rSrc))))>;
3811
Scott Michel438be252007-12-17 22:32:34 +00003812// zext 8->16: Zero extend bytes to halfwords
3813def : Pat<(i16 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003814 (ANDHIi8i16 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00003815
3816// zext 8->32 from preferred slot in load/store
Scott Michel8b6b4202007-12-04 22:35:58 +00003817def : Pat<(SPUextract_i8_zext VECREG:$rSrc),
3818 (ANDIr32 (ORi32_v4i32 (v4i32 VECREG:$rSrc), (v4i32 VECREG:$rSrc)),
3819 0xff)>;
3820
Scott Michel438be252007-12-17 22:32:34 +00003821// zext 8->32: Zero extend bytes to words
3822def : Pat<(i32 (zext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003823 (ANDIi8i32 R8C:$rSrc, 0xff)>;
Scott Michel438be252007-12-17 22:32:34 +00003824
3825// anyext 8->16: Extend 8->16 bits, irrespective of sign
3826def : Pat<(i16 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003827 (ORHIi8i16 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00003828
3829// anyext 8->32: Extend 8->32 bits, irrespective of sign
3830def : Pat<(i32 (anyext R8C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003831 (ORIi8i32 R8C:$rSrc, 0)>;
Scott Michel438be252007-12-17 22:32:34 +00003832
Scott Michel97872d32008-02-23 18:41:37 +00003833// zext 16->32: Zero extend halfwords to words
Scott Michel8b6b4202007-12-04 22:35:58 +00003834def : Pat<(i32 (zext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003835 (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003836
3837def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
Scott Michel97872d32008-02-23 18:41:37 +00003838 (ANDIi16i32 R16C:$rSrc, 0xf)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003839
3840def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
Scott Michel97872d32008-02-23 18:41:37 +00003841 (ANDIi16i32 R16C:$rSrc, 0xff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003842
3843def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
Scott Michel97872d32008-02-23 18:41:37 +00003844 (ANDIi16i32 R16C:$rSrc, 0xfff)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003845
3846// anyext 16->32: Extend 16->32 bits, irrespective of sign
3847def : Pat<(i32 (anyext R16C:$rSrc)),
Scott Michel97872d32008-02-23 18:41:37 +00003848 (ORIi16i32 R16C:$rSrc, 0)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003849
3850//===----------------------------------------------------------------------===//
Scott Michelf9f42e62008-01-29 02:16:57 +00003851// Address generation: SPU, like PPC, has to split addresses into high and
Scott Michel8b6b4202007-12-04 22:35:58 +00003852// low parts in order to load them into a register.
3853//===----------------------------------------------------------------------===//
3854
Scott Michelf9f42e62008-01-29 02:16:57 +00003855def : Pat<(SPUaform tglobaladdr:$in, 0), (ILAlsa tglobaladdr:$in)>;
3856def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
3857def : Pat<(SPUaform tjumptable:$in, 0), (ILAlsa tjumptable:$in)>;
3858def : Pat<(SPUaform tconstpool:$in, 0), (ILAlsa tconstpool:$in)>;
3859
3860def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
3861 (SPUlo tglobaladdr:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00003862 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00003863
Scott Michelf9f42e62008-01-29 02:16:57 +00003864def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
3865 (SPUlo texternalsym:$in, 0)),
3866 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
3867
3868def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
3869 (SPUlo tjumptable:$in, 0)),
Scott Micheldbac4cf2008-01-11 02:53:15 +00003870 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
Scott Michel394e26d2008-01-17 20:38:41 +00003871
Scott Michelf9f42e62008-01-29 02:16:57 +00003872def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
3873 (SPUlo tconstpool:$in, 0)),
3874 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
3875
3876def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
3877 (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
3878
3879def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
3880 (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
3881
3882def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
3883 (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
3884
3885def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
3886 (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
Scott Michel8b6b4202007-12-04 22:35:58 +00003887
Scott Michel8b6b4202007-12-04 22:35:58 +00003888// Instrinsics:
3889include "CellSDKIntrinsics.td"