Remove unused AsmPrinter OptLevel argument, and propogate.
[oota-llvm.git] / lib / Target / CellSPU / SPUInstrInfo.td
1 //==- SPUInstrInfo.td - Describe the Cell SPU Instructions -*- tablegen -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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
24 let hasCtrlDep = 1, Defs = [R1], Uses = [R1] in {
25   def ADJCALLSTACKDOWN : Pseudo<(outs), (ins u16imm_i32:$amt),
26                                 "${:comment} ADJCALLSTACKDOWN",
27                                 [(callseq_start timm:$amt)]>;
28   def ADJCALLSTACKUP   : Pseudo<(outs), (ins u16imm_i32:$amt),
29                                 "${:comment} ADJCALLSTACKUP",
30                                 [(callseq_end timm:$amt)]>;
31 }
32
33 //===----------------------------------------------------------------------===//
34 // DWARF debugging Pseudo Instructions
35 //===----------------------------------------------------------------------===//
36
37 def DWARF_LOC : Pseudo<(outs), (ins i32imm:$line, i32imm:$col, i32imm:$file),
38            ".loc $file, $line, $col",
39            [(dwarf_loc (i32 imm:$line), (i32 imm:$col), (i32 imm:$file))]>;
40
41 //===----------------------------------------------------------------------===//
42 // Loads:
43 // NB: The ordering is actually important, since the instruction selection
44 // will try each of the instructions in sequence, i.e., the D-form first with
45 // the 10-bit displacement, then the A-form with the 16 bit displacement, and
46 // finally the X-form with the register-register.
47 //===----------------------------------------------------------------------===//
48
49 let canFoldAsLoad = 1 in {
50   class LoadDFormVec<ValueType vectype>
51     : RI10Form<0b00101100, (outs VECREG:$rT), (ins dformaddr:$src),
52                "lqd\t$rT, $src",
53                LoadStore,
54                [(set (vectype VECREG:$rT), (load dform_addr:$src))]>
55   { }
56
57   class LoadDForm<RegisterClass rclass>
58     : RI10Form<0b00101100, (outs rclass:$rT), (ins dformaddr:$src),
59                "lqd\t$rT, $src",
60                LoadStore,
61                [(set rclass:$rT, (load dform_addr:$src))]>
62   { }
63
64   multiclass LoadDForms
65   {
66     def v16i8: LoadDFormVec<v16i8>;
67     def v8i16: LoadDFormVec<v8i16>;
68     def v4i32: LoadDFormVec<v4i32>;
69     def v2i64: LoadDFormVec<v2i64>;
70     def v4f32: LoadDFormVec<v4f32>;
71     def v2f64: LoadDFormVec<v2f64>;
72
73     def v2i32: LoadDFormVec<v2i32>;
74
75     def r128:  LoadDForm<GPRC>;
76     def r64:   LoadDForm<R64C>;
77     def r32:   LoadDForm<R32C>;
78     def f32:   LoadDForm<R32FP>;
79     def f64:   LoadDForm<R64FP>;
80     def r16:   LoadDForm<R16C>;
81     def r8:    LoadDForm<R8C>;
82   }
83
84   class LoadAFormVec<ValueType vectype>
85     : RI16Form<0b100001100, (outs VECREG:$rT), (ins addr256k:$src),
86                "lqa\t$rT, $src",
87                LoadStore,
88                [(set (vectype VECREG:$rT), (load aform_addr:$src))]>
89   { }
90
91   class LoadAForm<RegisterClass rclass>
92     : RI16Form<0b100001100, (outs rclass:$rT), (ins addr256k:$src),
93                "lqa\t$rT, $src",
94                LoadStore,
95                [(set rclass:$rT, (load aform_addr:$src))]>
96   { }
97
98   multiclass LoadAForms
99   {
100     def v16i8: LoadAFormVec<v16i8>;
101     def v8i16: LoadAFormVec<v8i16>;
102     def v4i32: LoadAFormVec<v4i32>;
103     def v2i64: LoadAFormVec<v2i64>;
104     def v4f32: LoadAFormVec<v4f32>;
105     def v2f64: LoadAFormVec<v2f64>;
106
107     def v2i32: LoadAFormVec<v2i32>;
108
109     def r128:  LoadAForm<GPRC>;
110     def r64:   LoadAForm<R64C>;
111     def r32:   LoadAForm<R32C>;
112     def f32:   LoadAForm<R32FP>;
113     def f64:   LoadAForm<R64FP>;
114     def r16:   LoadAForm<R16C>;
115     def r8:    LoadAForm<R8C>;
116   }
117
118   class LoadXFormVec<ValueType vectype>
119     : RRForm<0b00100011100, (outs VECREG:$rT), (ins memrr:$src),
120              "lqx\t$rT, $src",
121              LoadStore,
122              [(set (vectype VECREG:$rT), (load xform_addr:$src))]>
123   { }
124
125   class LoadXForm<RegisterClass rclass>
126     : RRForm<0b00100011100, (outs rclass:$rT), (ins memrr:$src),
127              "lqx\t$rT, $src",
128              LoadStore,
129              [(set rclass:$rT, (load xform_addr:$src))]>
130   { }
131
132   multiclass LoadXForms
133   {
134     def v16i8: LoadXFormVec<v16i8>;
135     def v8i16: LoadXFormVec<v8i16>;
136     def v4i32: LoadXFormVec<v4i32>;
137     def v2i64: LoadXFormVec<v2i64>;
138     def v4f32: LoadXFormVec<v4f32>;
139     def v2f64: LoadXFormVec<v2f64>;
140
141     def v2i32: LoadXFormVec<v2i32>;
142
143     def r128:  LoadXForm<GPRC>;
144     def r64:   LoadXForm<R64C>;
145     def r32:   LoadXForm<R32C>;
146     def f32:   LoadXForm<R32FP>;
147     def f64:   LoadXForm<R64FP>;
148     def r16:   LoadXForm<R16C>;
149     def r8:    LoadXForm<R8C>;
150   }
151
152   defm LQA : LoadAForms;
153   defm LQD : LoadDForms;
154   defm LQX : LoadXForms;
155
156 /* Load quadword, PC relative: Not much use at this point in time.
157    Might be of use later for relocatable code. It's effectively the
158    same as LQA, but uses PC-relative addressing.
159   def LQR : RI16Form<0b111001100, (outs VECREG:$rT), (ins s16imm:$disp),
160                      "lqr\t$rT, $disp", LoadStore,
161                      [(set VECREG:$rT, (load iaddr:$disp))]>;
162  */
163 }
164
165 //===----------------------------------------------------------------------===//
166 // Stores:
167 //===----------------------------------------------------------------------===//
168 class StoreDFormVec<ValueType vectype>
169   : RI10Form<0b00100100, (outs), (ins VECREG:$rT, dformaddr:$src),
170              "stqd\t$rT, $src",
171              LoadStore,
172              [(store (vectype VECREG:$rT), dform_addr:$src)]>
173 { }
174
175 class StoreDForm<RegisterClass rclass>
176   : RI10Form<0b00100100, (outs), (ins rclass:$rT, dformaddr:$src),
177              "stqd\t$rT, $src",
178              LoadStore,
179              [(store rclass:$rT, dform_addr:$src)]>
180 { }
181
182 multiclass StoreDForms
183 {
184   def v16i8: StoreDFormVec<v16i8>;
185   def v8i16: StoreDFormVec<v8i16>;
186   def v4i32: StoreDFormVec<v4i32>;
187   def v2i64: StoreDFormVec<v2i64>;
188   def v4f32: StoreDFormVec<v4f32>;
189   def v2f64: StoreDFormVec<v2f64>;
190
191   def v2i32: StoreDFormVec<v2i32>;
192
193   def r128:  StoreDForm<GPRC>;
194   def r64:   StoreDForm<R64C>;
195   def r32:   StoreDForm<R32C>;
196   def f32:   StoreDForm<R32FP>;
197   def f64:   StoreDForm<R64FP>;
198   def r16:   StoreDForm<R16C>;
199   def r8:    StoreDForm<R8C>;
200 }
201
202 class StoreAFormVec<ValueType vectype>
203   : RI16Form<0b0010010, (outs), (ins VECREG:$rT, addr256k:$src),
204              "stqa\t$rT, $src",
205              LoadStore,
206              [(store (vectype VECREG:$rT), aform_addr:$src)]>;
207
208 class StoreAForm<RegisterClass rclass>
209   : RI16Form<0b001001, (outs), (ins rclass:$rT, addr256k:$src),
210              "stqa\t$rT, $src",
211              LoadStore,
212              [(store rclass:$rT, aform_addr:$src)]>;
213
214 multiclass StoreAForms
215 {
216   def v16i8: StoreAFormVec<v16i8>;
217   def v8i16: StoreAFormVec<v8i16>;
218   def v4i32: StoreAFormVec<v4i32>;
219   def v2i64: StoreAFormVec<v2i64>;
220   def v4f32: StoreAFormVec<v4f32>;
221   def v2f64: StoreAFormVec<v2f64>;
222
223   def v2i32: StoreAFormVec<v2i32>;
224
225   def r128:  StoreAForm<GPRC>;
226   def r64:   StoreAForm<R64C>;
227   def r32:   StoreAForm<R32C>;
228   def f32:   StoreAForm<R32FP>;
229   def f64:   StoreAForm<R64FP>;
230   def r16:   StoreAForm<R16C>;
231   def r8:    StoreAForm<R8C>;
232 }
233
234 class StoreXFormVec<ValueType vectype>
235   : RRForm<0b00100100, (outs), (ins VECREG:$rT, memrr:$src),
236            "stqx\t$rT, $src",
237            LoadStore,
238            [(store (vectype VECREG:$rT), xform_addr:$src)]>
239 { }
240
241 class StoreXForm<RegisterClass rclass>
242   : RRForm<0b00100100, (outs), (ins rclass:$rT, memrr:$src),
243            "stqx\t$rT, $src",
244            LoadStore,
245            [(store rclass:$rT, xform_addr:$src)]>
246 { }
247
248 multiclass StoreXForms
249 {
250   def v16i8: StoreXFormVec<v16i8>;
251   def v8i16: StoreXFormVec<v8i16>;
252   def v4i32: StoreXFormVec<v4i32>;
253   def v2i64: StoreXFormVec<v2i64>;
254   def v4f32: StoreXFormVec<v4f32>;
255   def v2f64: StoreXFormVec<v2f64>;
256
257   def v2i32: StoreXFormVec<v2i32>;
258
259   def r128:  StoreXForm<GPRC>;
260   def r64:   StoreXForm<R64C>;
261   def r32:   StoreXForm<R32C>;
262   def f32:   StoreXForm<R32FP>;
263   def f64:   StoreXForm<R64FP>;
264   def r16:   StoreXForm<R16C>;
265   def r8:    StoreXForm<R8C>;
266 }
267
268 defm STQD : StoreDForms;
269 defm STQA : StoreAForms;
270 defm STQX : StoreXForms;
271
272 /* Store quadword, PC relative: Not much use at this point in time. Might
273    be useful for relocatable code.
274 def STQR : RI16Form<0b111000100, (outs), (ins VECREG:$rT, s16imm:$disp),
275                    "stqr\t$rT, $disp", LoadStore,
276                    [(store VECREG:$rT, iaddr:$disp)]>;
277 */
278
279 //===----------------------------------------------------------------------===//
280 // Generate Controls for Insertion:
281 //===----------------------------------------------------------------------===//
282
283 def CBD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
284     "cbd\t$rT, $src", ShuffleOp,
285     [(set (v16i8 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
286
287 def CBX: RRForm<0b00101011100, (outs VECREG:$rT), (ins memrr:$src),
288     "cbx\t$rT, $src", ShuffleOp,
289     [(set (v16i8 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
290
291 def CHD: RI7Form<0b10101111100, (outs VECREG:$rT), (ins shufaddr:$src),
292     "chd\t$rT, $src", ShuffleOp,
293     [(set (v8i16 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
294
295 def CHX: RRForm<0b10101011100, (outs VECREG:$rT), (ins memrr:$src),
296     "chx\t$rT, $src", ShuffleOp,
297     [(set (v8i16 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
298
299 def CWD: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
300     "cwd\t$rT, $src", ShuffleOp,
301     [(set (v4i32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
302
303 def CWX: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
304     "cwx\t$rT, $src", ShuffleOp,
305     [(set (v4i32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
306
307 def CWDf32: RI7Form<0b01101111100, (outs VECREG:$rT), (ins shufaddr:$src),
308     "cwd\t$rT, $src", ShuffleOp,
309     [(set (v4f32 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
310
311 def CWXf32: RRForm<0b01101011100, (outs VECREG:$rT), (ins memrr:$src),
312     "cwx\t$rT, $src", ShuffleOp,
313     [(set (v4f32 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
314
315 def CDD: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
316     "cdd\t$rT, $src", ShuffleOp,
317     [(set (v2i64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
318
319 def CDX: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
320     "cdx\t$rT, $src", ShuffleOp,
321     [(set (v2i64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
322
323 def CDDf64: RI7Form<0b11101111100, (outs VECREG:$rT), (ins shufaddr:$src),
324     "cdd\t$rT, $src", ShuffleOp,
325     [(set (v2f64 VECREG:$rT), (SPUshufmask dform2_addr:$src))]>;
326
327 def CDXf64: RRForm<0b11101011100, (outs VECREG:$rT), (ins memrr:$src),
328     "cdx\t$rT, $src", ShuffleOp,
329     [(set (v2f64 VECREG:$rT), (SPUshufmask xform_addr:$src))]>;
330
331 //===----------------------------------------------------------------------===//
332 // Constant formation:
333 //===----------------------------------------------------------------------===//
334
335 def ILHv8i16:
336   RI16Form<0b110000010, (outs VECREG:$rT), (ins s16imm:$val),
337     "ilh\t$rT, $val", ImmLoad,
338     [(set (v8i16 VECREG:$rT), (v8i16 v8i16SExt16Imm:$val))]>;
339
340 def ILHr16:
341   RI16Form<0b110000010, (outs R16C:$rT), (ins s16imm:$val),
342     "ilh\t$rT, $val", ImmLoad,
343     [(set R16C:$rT, immSExt16:$val)]>;
344
345 // Cell SPU doesn't have a native 8-bit immediate load, but ILH works ("with
346 // the right constant")
347 def ILHr8:
348   RI16Form<0b110000010, (outs R8C:$rT), (ins s16imm_i8:$val),
349     "ilh\t$rT, $val", ImmLoad,
350     [(set R8C:$rT, immSExt8:$val)]>;
351
352 // IL does sign extension!
353
354 class ILInst<dag OOL, dag IOL, list<dag> pattern>:
355   RI16Form<0b100000010, OOL, IOL, "il\t$rT, $val",
356            ImmLoad, pattern>;
357
358 class ILVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
359   ILInst<(outs VECREG:$rT), (ins immtype:$val),
360          [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
361
362 class ILRegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
363   ILInst<(outs rclass:$rT), (ins immtype:$val),
364          [(set rclass:$rT, xform:$val)]>;
365
366 multiclass ImmediateLoad
367 {
368   def v2i64: ILVecInst<v2i64, s16imm_i64, v2i64SExt16Imm>;
369   def v4i32: ILVecInst<v4i32, s16imm_i32, v4i32SExt16Imm>;
370
371   // TODO: Need v2f64, v4f32
372
373   def r64: ILRegInst<R64C, s16imm_i64, immSExt16>;
374   def r32: ILRegInst<R32C, s16imm_i32, immSExt16>;
375   def f32: ILRegInst<R32FP, s16imm_f32, fpimmSExt16>;
376   def f64: ILRegInst<R64FP, s16imm_f64, fpimmSExt16>;
377 }
378
379 defm IL : ImmediateLoad;
380
381 class ILHUInst<dag OOL, dag IOL, list<dag> pattern>:
382   RI16Form<0b010000010, OOL, IOL, "ilhu\t$rT, $val",
383            ImmLoad, pattern>;
384
385 class ILHUVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
386   ILHUInst<(outs VECREG:$rT), (ins immtype:$val),
387            [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
388
389 class ILHURegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
390   ILHUInst<(outs rclass:$rT), (ins immtype:$val),
391            [(set rclass:$rT, xform:$val)]>;
392
393 multiclass ImmLoadHalfwordUpper
394 {
395   def v2i64: ILHUVecInst<v2i64, u16imm_i64, immILHUvec_i64>;
396   def v4i32: ILHUVecInst<v4i32, u16imm_i32, immILHUvec>;
397
398   def r64: ILHURegInst<R64C, u16imm_i64, hi16>;
399   def r32: ILHURegInst<R32C, u16imm_i32, hi16>;
400
401   // Loads the high portion of an address
402   def hi: ILHURegInst<R32C, symbolHi, hi16>;
403
404   // Used in custom lowering constant SFP loads:
405   def f32: ILHURegInst<R32FP, f16imm, hi16_f32>;
406 }
407
408 defm ILHU : ImmLoadHalfwordUpper;
409
410 // Immediate load address (can also be used to load 18-bit unsigned constants,
411 // see the zext 16->32 pattern)
412
413 class ILAInst<dag OOL, dag IOL, list<dag> pattern>:
414   RI18Form<0b1000010, OOL, IOL, "ila\t$rT, $val",
415            LoadNOP, pattern>;
416
417 class ILAVecInst<ValueType vectype, Operand immtype, PatLeaf xform>:
418   ILAInst<(outs VECREG:$rT), (ins immtype:$val),
419           [(set (vectype VECREG:$rT), (vectype xform:$val))]>;
420
421 class ILARegInst<RegisterClass rclass, Operand immtype, PatLeaf xform>:
422   ILAInst<(outs rclass:$rT), (ins immtype:$val),
423           [(set rclass:$rT, xform:$val)]>;
424
425 multiclass ImmLoadAddress
426 {
427   def v2i64: ILAVecInst<v2i64, u18imm, v2i64Uns18Imm>;
428   def v4i32: ILAVecInst<v4i32, u18imm, v4i32Uns18Imm>;
429
430   def r64: ILARegInst<R64C, u18imm_i64, imm18>;
431   def r32: ILARegInst<R32C, u18imm, imm18>;
432   def f32: ILARegInst<R32FP, f18imm, fpimm18>;
433   def f64: ILARegInst<R64FP, f18imm_f64, fpimm18>;
434
435   def hi: ILARegInst<R32C, symbolHi, imm18>;
436   def lo: ILARegInst<R32C, symbolLo, imm18>;
437
438   def lsa: ILAInst<(outs R32C:$rT), (ins symbolLSA:$val),
439                    [/* no pattern */]>;
440 }
441
442 defm ILA : ImmLoadAddress;
443
444 // Immediate OR, Halfword Lower: The "other" part of loading large constants
445 // into 32-bit registers. See the anonymous pattern Pat<(i32 imm:$imm), ...>
446 // Note that these are really two operand instructions, but they're encoded
447 // as three operands with the first two arguments tied-to each other.
448
449 class IOHLInst<dag OOL, dag IOL, list<dag> pattern>:
450   RI16Form<0b100000110, OOL, IOL, "iohl\t$rT, $val",
451            ImmLoad, pattern>,
452   RegConstraint<"$rS = $rT">,
453   NoEncode<"$rS">;
454
455 class IOHLVecInst<ValueType vectype, Operand immtype /* , PatLeaf xform */>:
456   IOHLInst<(outs VECREG:$rT), (ins VECREG:$rS, immtype:$val),
457            [/* no pattern */]>;
458
459 class IOHLRegInst<RegisterClass rclass, Operand immtype /* , PatLeaf xform */>:
460   IOHLInst<(outs rclass:$rT), (ins rclass:$rS, immtype:$val),
461            [/* no pattern */]>;
462
463 multiclass ImmOrHalfwordLower
464 {
465   def v2i64: IOHLVecInst<v2i64, u16imm_i64>;
466   def v4i32: IOHLVecInst<v4i32, u16imm_i32>;
467
468   def r32: IOHLRegInst<R32C, i32imm>;
469   def f32: IOHLRegInst<R32FP, f32imm>;
470
471   def lo: IOHLRegInst<R32C, symbolLo>;
472 }
473
474 defm IOHL: ImmOrHalfwordLower;
475
476 // Form select mask for bytes using immediate, used in conjunction with the
477 // SELB instruction:
478
479 class FSMBIVec<ValueType vectype>:
480   RI16Form<0b101001100, (outs VECREG:$rT), (ins u16imm:$val),
481           "fsmbi\t$rT, $val",
482           SelectOp,
483           [(set (vectype VECREG:$rT), (SPUselmask (i16 immU16:$val)))]>;
484
485 multiclass FormSelectMaskBytesImm
486 {
487   def v16i8: FSMBIVec<v16i8>;
488   def v8i16: FSMBIVec<v8i16>;
489   def v4i32: FSMBIVec<v4i32>;
490   def v2i64: FSMBIVec<v2i64>;
491 }
492
493 defm FSMBI : FormSelectMaskBytesImm;
494
495 // fsmb: Form select mask for bytes. N.B. Input operand, $rA, is 16-bits
496 class FSMBInst<dag OOL, dag IOL, list<dag> pattern>:
497     RRForm_1<0b01101101100, OOL, IOL, "fsmb\t$rT, $rA", SelectOp,
498              pattern>;
499
500 class FSMBRegInst<RegisterClass rclass, ValueType vectype>:
501     FSMBInst<(outs VECREG:$rT), (ins rclass:$rA),
502              [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
503
504 class FSMBVecInst<ValueType vectype>:
505     FSMBInst<(outs VECREG:$rT), (ins VECREG:$rA),
506              [(set (vectype VECREG:$rT),
507                    (SPUselmask (vectype VECREG:$rA)))]>;
508
509 multiclass FormSelectMaskBits {
510   def v16i8_r16: FSMBRegInst<R16C, v16i8>;
511   def v16i8:     FSMBVecInst<v16i8>;
512 }
513
514 defm FSMB: FormSelectMaskBits;
515
516 // fsmh: Form select mask for halfwords. N.B., Input operand, $rA, is
517 // only 8-bits wide (even though it's input as 16-bits here)
518
519 class FSMHInst<dag OOL, dag IOL, list<dag> pattern>:
520     RRForm_1<0b10101101100, OOL, IOL, "fsmh\t$rT, $rA", SelectOp,
521              pattern>;
522
523 class FSMHRegInst<RegisterClass rclass, ValueType vectype>:
524     FSMHInst<(outs VECREG:$rT), (ins rclass:$rA),
525              [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
526
527 class FSMHVecInst<ValueType vectype>:
528     FSMHInst<(outs VECREG:$rT), (ins VECREG:$rA),
529              [(set (vectype VECREG:$rT),
530                    (SPUselmask (vectype VECREG:$rA)))]>;
531
532 multiclass FormSelectMaskHalfword {
533   def v8i16_r16: FSMHRegInst<R16C, v8i16>;
534   def v8i16:     FSMHVecInst<v8i16>;
535 }
536
537 defm FSMH: FormSelectMaskHalfword;
538
539 // fsm: Form select mask for words. Like the other fsm* instructions,
540 // only the lower 4 bits of $rA are significant.
541
542 class FSMInst<dag OOL, dag IOL, list<dag> pattern>:
543     RRForm_1<0b00101101100, OOL, IOL, "fsm\t$rT, $rA", SelectOp,
544              pattern>;
545
546 class FSMRegInst<ValueType vectype, RegisterClass rclass>:
547     FSMInst<(outs VECREG:$rT), (ins rclass:$rA),
548             [(set (vectype VECREG:$rT), (SPUselmask rclass:$rA))]>;
549
550 class FSMVecInst<ValueType vectype>:
551     FSMInst<(outs VECREG:$rT), (ins VECREG:$rA),
552             [(set (vectype VECREG:$rT), (SPUselmask (vectype VECREG:$rA)))]>;
553
554 multiclass FormSelectMaskWord {
555   def v4i32: FSMVecInst<v4i32>;
556
557   def r32 :  FSMRegInst<v4i32, R32C>;
558   def r16 :  FSMRegInst<v4i32, R16C>;
559 }
560
561 defm FSM : FormSelectMaskWord;
562
563 // Special case when used for i64 math operations
564 multiclass FormSelectMaskWord64 {
565   def r32 : FSMRegInst<v2i64, R32C>;
566   def r16 : FSMRegInst<v2i64, R16C>;
567 }
568
569 defm FSM64 : FormSelectMaskWord64;
570
571 //===----------------------------------------------------------------------===//
572 // Integer and Logical Operations:
573 //===----------------------------------------------------------------------===//
574
575 def AHv8i16:
576   RRForm<0b00010011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
577     "ah\t$rT, $rA, $rB", IntegerOp,
578     [(set (v8i16 VECREG:$rT), (int_spu_si_ah VECREG:$rA, VECREG:$rB))]>;
579
580 def : Pat<(add (v8i16 VECREG:$rA), (v8i16 VECREG:$rB)),
581           (AHv8i16 VECREG:$rA, VECREG:$rB)>;
582
583 def AHr16:
584   RRForm<0b00010011000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
585     "ah\t$rT, $rA, $rB", IntegerOp,
586     [(set R16C:$rT, (add R16C:$rA, R16C:$rB))]>;
587
588 def AHIvec:
589     RI10Form<0b10111000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
590       "ahi\t$rT, $rA, $val", IntegerOp,
591       [(set (v8i16 VECREG:$rT), (add (v8i16 VECREG:$rA),
592                                      v8i16SExt10Imm:$val))]>;
593
594 def AHIr16:
595   RI10Form<0b10111000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
596     "ahi\t$rT, $rA, $val", IntegerOp,
597     [(set R16C:$rT, (add R16C:$rA, i16ImmSExt10:$val))]>;
598
599 // v4i32, i32 add instruction:
600
601 class AInst<dag OOL, dag IOL, list<dag> pattern>:
602   RRForm<0b00000011000, OOL, IOL,
603          "a\t$rT, $rA, $rB", IntegerOp,
604          pattern>;
605
606 class AVecInst<ValueType vectype>:
607   AInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
608         [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA),
609                                          (vectype VECREG:$rB)))]>;
610
611 class ARegInst<RegisterClass rclass>:
612   AInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
613         [(set rclass:$rT, (add rclass:$rA, rclass:$rB))]>;
614         
615 multiclass AddInstruction {
616   def v4i32: AVecInst<v4i32>;
617   def v16i8: AVecInst<v16i8>;
618   
619   def r32:   ARegInst<R32C>;
620 }
621
622 defm A : AddInstruction;
623
624 class AIInst<dag OOL, dag IOL, list<dag> pattern>:
625     RI10Form<0b00111000, OOL, IOL,
626              "ai\t$rT, $rA, $val", IntegerOp,
627              pattern>;
628
629 class AIVecInst<ValueType vectype, PatLeaf immpred>:
630     AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
631             [(set (vectype VECREG:$rT), (add (vectype VECREG:$rA), immpred:$val))]>;
632
633 class AIFPVecInst<ValueType vectype, PatLeaf immpred>:
634     AIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
635             [/* no pattern */]>;
636
637 class AIRegInst<RegisterClass rclass, PatLeaf immpred>:
638     AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
639            [(set rclass:$rT, (add rclass:$rA, immpred:$val))]>;
640
641 // This is used to add epsilons to floating point numbers in the f32 fdiv code:
642 class AIFPInst<RegisterClass rclass, PatLeaf immpred>:
643     AIInst<(outs rclass:$rT), (ins rclass:$rA, s10imm_i32:$val),
644            [/* no pattern */]>;
645
646 multiclass AddImmediate {
647   def v4i32: AIVecInst<v4i32, v4i32SExt10Imm>;
648
649   def r32: AIRegInst<R32C, i32ImmSExt10>;
650
651   def v4f32: AIFPVecInst<v4f32, v4i32SExt10Imm>;
652   def f32: AIFPInst<R32FP, i32ImmSExt10>;
653 }
654
655 defm AI : AddImmediate;
656
657 def SFHvec:
658     RRForm<0b00010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
659       "sfh\t$rT, $rA, $rB", IntegerOp,
660       [(set (v8i16 VECREG:$rT), (sub (v8i16 VECREG:$rA),
661                                      (v8i16 VECREG:$rB)))]>;
662
663 def SFHr16:
664     RRForm<0b00010010000, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
665       "sfh\t$rT, $rA, $rB", IntegerOp,
666       [(set R16C:$rT, (sub R16C:$rA, R16C:$rB))]>;
667
668 def SFHIvec:
669     RI10Form<0b10110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
670       "sfhi\t$rT, $rA, $val", IntegerOp,
671       [(set (v8i16 VECREG:$rT), (sub v8i16SExt10Imm:$val,
672                                      (v8i16 VECREG:$rA)))]>;
673
674 def SFHIr16 : RI10Form<0b10110000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
675   "sfhi\t$rT, $rA, $val", IntegerOp,
676   [(set R16C:$rT, (sub i16ImmSExt10:$val, R16C:$rA))]>;
677
678 def SFvec : RRForm<0b00000010000, (outs VECREG:$rT),
679                                   (ins VECREG:$rA, VECREG:$rB),
680   "sf\t$rT, $rA, $rB", IntegerOp,
681   [(set (v4i32 VECREG:$rT), (sub (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
682
683 def SFr32 : RRForm<0b00000010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
684   "sf\t$rT, $rA, $rB", IntegerOp,
685   [(set R32C:$rT, (sub R32C:$rA, R32C:$rB))]>;
686
687 def SFIvec:
688     RI10Form<0b00110000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
689       "sfi\t$rT, $rA, $val", IntegerOp,
690       [(set (v4i32 VECREG:$rT), (sub v4i32SExt10Imm:$val,
691                                      (v4i32 VECREG:$rA)))]>;
692
693 def SFIr32 : RI10Form<0b00110000, (outs R32C:$rT),
694                                   (ins R32C:$rA, s10imm_i32:$val),
695   "sfi\t$rT, $rA, $val", IntegerOp,
696   [(set R32C:$rT, (sub i32ImmSExt10:$val, R32C:$rA))]>;
697
698 // ADDX: only available in vector form, doesn't match a pattern.
699 class ADDXInst<dag OOL, dag IOL, list<dag> pattern>:
700     RRForm<0b00000010110, OOL, IOL,
701       "addx\t$rT, $rA, $rB",
702       IntegerOp, pattern>;
703
704 class ADDXVecInst<ValueType vectype>:
705     ADDXInst<(outs VECREG:$rT),
706              (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
707              [/* no pattern */]>,
708     RegConstraint<"$rCarry = $rT">,
709     NoEncode<"$rCarry">;
710
711 class ADDXRegInst<RegisterClass rclass>:
712     ADDXInst<(outs rclass:$rT),
713              (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
714              [/* no pattern */]>,
715     RegConstraint<"$rCarry = $rT">,
716     NoEncode<"$rCarry">;
717
718 multiclass AddExtended {
719   def v2i64 : ADDXVecInst<v2i64>;
720   def v4i32 : ADDXVecInst<v4i32>;
721   def r64 : ADDXRegInst<R64C>;
722   def r32 : ADDXRegInst<R32C>;
723 }
724
725 defm ADDX : AddExtended;
726
727 // CG: Generate carry for add
728 class CGInst<dag OOL, dag IOL, list<dag> pattern>:
729     RRForm<0b01000011000, OOL, IOL,
730       "cg\t$rT, $rA, $rB",
731       IntegerOp, pattern>;
732
733 class CGVecInst<ValueType vectype>:
734     CGInst<(outs VECREG:$rT),
735            (ins VECREG:$rA, VECREG:$rB),
736            [/* no pattern */]>;
737
738 class CGRegInst<RegisterClass rclass>:
739     CGInst<(outs rclass:$rT),
740            (ins rclass:$rA, rclass:$rB),
741            [/* no pattern */]>;
742
743 multiclass CarryGenerate {
744   def v2i64 : CGVecInst<v2i64>;
745   def v4i32 : CGVecInst<v4i32>;
746   def r64 : CGRegInst<R64C>;
747   def r32 : CGRegInst<R32C>;
748 }
749
750 defm CG : CarryGenerate;
751
752 // SFX: Subract from, extended. This is used in conjunction with BG to subtract
753 // with carry (borrow, in this case)
754 class SFXInst<dag OOL, dag IOL, list<dag> pattern>:
755     RRForm<0b10000010110, OOL, IOL,
756       "sfx\t$rT, $rA, $rB",
757       IntegerOp, pattern>;
758
759 class SFXVecInst<ValueType vectype>:
760     SFXInst<(outs VECREG:$rT),
761             (ins VECREG:$rA, VECREG:$rB, VECREG:$rCarry),
762              [/* no pattern */]>,
763     RegConstraint<"$rCarry = $rT">,
764     NoEncode<"$rCarry">;
765
766 class SFXRegInst<RegisterClass rclass>:
767     SFXInst<(outs rclass:$rT),
768             (ins rclass:$rA, rclass:$rB, rclass:$rCarry),
769              [/* no pattern */]>,
770     RegConstraint<"$rCarry = $rT">,
771     NoEncode<"$rCarry">;
772
773 multiclass SubtractExtended {
774   def v2i64 : SFXVecInst<v2i64>;
775   def v4i32 : SFXVecInst<v4i32>;
776   def r64 : SFXRegInst<R64C>;
777   def r32 : SFXRegInst<R32C>;
778 }
779
780 defm SFX : SubtractExtended;
781
782 // BG: only available in vector form, doesn't match a pattern.
783 class BGInst<dag OOL, dag IOL, list<dag> pattern>:
784     RRForm<0b01000010000, OOL, IOL,
785       "bg\t$rT, $rA, $rB",
786       IntegerOp, pattern>;
787
788 class BGVecInst<ValueType vectype>:
789     BGInst<(outs VECREG:$rT),
790            (ins VECREG:$rA, VECREG:$rB),
791            [/* no pattern */]>;
792
793 class BGRegInst<RegisterClass rclass>:
794     BGInst<(outs rclass:$rT),
795            (ins rclass:$rA, rclass:$rB),
796            [/* no pattern */]>;
797
798 multiclass BorrowGenerate {
799   def v4i32 : BGVecInst<v4i32>;
800   def v2i64 : BGVecInst<v2i64>;
801   def r64 : BGRegInst<R64C>;
802   def r32 : BGRegInst<R32C>;
803 }
804
805 defm BG : BorrowGenerate;
806
807 // BGX: Borrow generate, extended.
808 def BGXvec:
809     RRForm<0b11000010110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB,
810                                 VECREG:$rCarry),
811       "bgx\t$rT, $rA, $rB", IntegerOp,
812       []>,
813     RegConstraint<"$rCarry = $rT">,
814     NoEncode<"$rCarry">;
815
816 // Halfword multiply variants:
817 // N.B: These can be used to build up larger quantities (16x16 -> 32)
818
819 def MPYv8i16:
820   RRForm<0b00100011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
821     "mpy\t$rT, $rA, $rB", IntegerMulDiv,
822     [/* no pattern */]>;
823
824 def MPYr16:
825   RRForm<0b00100011110, (outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
826     "mpy\t$rT, $rA, $rB", IntegerMulDiv,
827     [(set R16C:$rT, (mul R16C:$rA, R16C:$rB))]>;
828
829 // Unsigned 16-bit multiply:
830
831 class MPYUInst<dag OOL, dag IOL, list<dag> pattern>:
832     RRForm<0b00110011110, OOL, IOL,
833       "mpyu\t$rT, $rA, $rB", IntegerMulDiv,
834       pattern>;
835
836 def MPYUv4i32:
837   MPYUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
838            [/* no pattern */]>;
839
840 def MPYUr16:
841   MPYUInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB),
842            [(set R32C:$rT, (mul (zext R16C:$rA), (zext R16C:$rB)))]>;
843
844 def MPYUr32:
845   MPYUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
846            [/* no pattern */]>;
847
848 // mpyi: multiply 16 x s10imm -> 32 result.
849
850 class MPYIInst<dag OOL, dag IOL, list<dag> pattern>:
851   RI10Form<0b00101110, OOL, IOL,
852     "mpyi\t$rT, $rA, $val", IntegerMulDiv,
853     pattern>;
854
855 def MPYIvec:
856   MPYIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
857            [(set (v8i16 VECREG:$rT),
858                  (mul (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
859
860 def MPYIr16:
861   MPYIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
862            [(set R16C:$rT, (mul R16C:$rA, i16ImmSExt10:$val))]>;
863
864 // mpyui: same issues as other multiplies, plus, this doesn't match a
865 // pattern... but may be used during target DAG selection or lowering
866
867 class MPYUIInst<dag OOL, dag IOL, list<dag> pattern>:
868   RI10Form<0b10101110, OOL, IOL,
869            "mpyui\t$rT, $rA, $val", IntegerMulDiv,
870            pattern>;
871     
872 def MPYUIvec:
873   MPYUIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
874             []>;
875
876 def MPYUIr16:
877   MPYUIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
878             []>;
879
880 // mpya: 16 x 16 + 16 -> 32 bit result
881 class MPYAInst<dag OOL, dag IOL, list<dag> pattern>:
882   RRRForm<0b0011, OOL, IOL,
883           "mpya\t$rT, $rA, $rB, $rC", IntegerMulDiv,
884           pattern>;
885           
886 def MPYAv4i32:
887   MPYAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
888            [(set (v4i32 VECREG:$rT),
889                  (add (v4i32 (bitconvert (mul (v8i16 VECREG:$rA),
890                                               (v8i16 VECREG:$rB)))),
891                       (v4i32 VECREG:$rC)))]>;
892
893 def MPYAr32:
894   MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
895            [(set R32C:$rT, (add (sext (mul R16C:$rA, R16C:$rB)),
896                                 R32C:$rC))]>;
897                                 
898 def MPYAr32_sext:
899   MPYAInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB, R32C:$rC),
900            [(set R32C:$rT, (add (mul (sext R16C:$rA), (sext R16C:$rB)),
901                                 R32C:$rC))]>;
902
903 def MPYAr32_sextinreg:
904   MPYAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB, R32C:$rC),
905            [(set R32C:$rT, (add (mul (sext_inreg R32C:$rA, i16),
906                                      (sext_inreg R32C:$rB, i16)),
907                                 R32C:$rC))]>;
908
909 // mpyh: multiply high, used to synthesize 32-bit multiplies
910 class MPYHInst<dag OOL, dag IOL, list<dag> pattern>:
911   RRForm<0b10100011110, OOL, IOL,
912          "mpyh\t$rT, $rA, $rB", IntegerMulDiv,
913          pattern>;
914          
915 def MPYHv4i32:
916     MPYHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
917              [/* no pattern */]>;
918
919 def MPYHr32:
920     MPYHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
921              [/* no pattern */]>;
922
923 // mpys: multiply high and shift right (returns the top half of
924 // a 16-bit multiply, sign extended to 32 bits.)
925
926 class MPYSInst<dag OOL, dag IOL>:
927     RRForm<0b11100011110, OOL, IOL, 
928       "mpys\t$rT, $rA, $rB", IntegerMulDiv,
929       [/* no pattern */]>;
930
931 def MPYSv4i32:
932     MPYSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
933     
934 def MPYSr16:
935     MPYSInst<(outs R32C:$rT), (ins R16C:$rA, R16C:$rB)>;
936
937 // mpyhh: multiply high-high (returns the 32-bit result from multiplying
938 // the top 16 bits of the $rA, $rB)
939
940 class MPYHHInst<dag OOL, dag IOL>:
941   RRForm<0b01100011110, OOL, IOL,
942         "mpyhh\t$rT, $rA, $rB", IntegerMulDiv,
943         [/* no pattern */]>;
944         
945 def MPYHHv8i16:
946     MPYHHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
947
948 def MPYHHr32:
949     MPYHHInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
950
951 // mpyhha: Multiply high-high, add to $rT:
952
953 class MPYHHAInst<dag OOL, dag IOL>:
954     RRForm<0b01100010110, OOL, IOL,
955       "mpyhha\t$rT, $rA, $rB", IntegerMulDiv,
956       [/* no pattern */]>;
957
958 def MPYHHAvec:
959     MPYHHAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
960     
961 def MPYHHAr32:
962     MPYHHAInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
963
964 // mpyhhu: Multiply high-high, unsigned, e.g.:
965 //
966 // +-------+-------+   +-------+-------+   +---------+
967 // |  a0   .  a1   | x |  b0   .  b1   | = | a0 x b0 |
968 // +-------+-------+   +-------+-------+   +---------+
969 //
970 // where a0, b0 are the upper 16 bits of the 32-bit word
971
972 class MPYHHUInst<dag OOL, dag IOL>:
973     RRForm<0b01110011110, OOL, IOL,
974       "mpyhhu\t$rT, $rA, $rB", IntegerMulDiv,
975       [/* no pattern */]>;
976
977 def MPYHHUv4i32:
978     MPYHHUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
979     
980 def MPYHHUr32:
981     MPYHHUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
982
983 // mpyhhau: Multiply high-high, unsigned
984
985 class MPYHHAUInst<dag OOL, dag IOL>:
986     RRForm<0b01110010110, OOL, IOL,
987       "mpyhhau\t$rT, $rA, $rB", IntegerMulDiv,
988       [/* no pattern */]>;
989
990 def MPYHHAUvec:
991     MPYHHAUInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB)>;
992     
993 def MPYHHAUr32:
994     MPYHHAUInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB)>;
995
996 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
997 // clz: Count leading zeroes
998 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
999 class CLZInst<dag OOL, dag IOL, list<dag> pattern>:
1000     RRForm_1<0b10100101010, OOL, IOL, "clz\t$rT, $rA",
1001              IntegerOp, pattern>;
1002
1003 class CLZRegInst<RegisterClass rclass>:
1004     CLZInst<(outs rclass:$rT), (ins rclass:$rA),
1005             [(set rclass:$rT, (ctlz rclass:$rA))]>;
1006
1007 class CLZVecInst<ValueType vectype>:
1008     CLZInst<(outs VECREG:$rT), (ins VECREG:$rA),
1009             [(set (vectype VECREG:$rT), (ctlz (vectype VECREG:$rA)))]>;
1010
1011 multiclass CountLeadingZeroes {
1012   def v4i32 : CLZVecInst<v4i32>;
1013   def r32   : CLZRegInst<R32C>;
1014 }
1015
1016 defm CLZ : CountLeadingZeroes;
1017
1018 // cntb: Count ones in bytes (aka "population count")
1019 //
1020 // NOTE: This instruction is really a vector instruction, but the custom
1021 // lowering code uses it in unorthodox ways to support CTPOP for other
1022 // data types!
1023
1024 def CNTBv16i8:
1025     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1026       "cntb\t$rT, $rA", IntegerOp,
1027       [(set (v16i8 VECREG:$rT), (SPUcntb (v16i8 VECREG:$rA)))]>;
1028
1029 def CNTBv8i16 :
1030     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1031       "cntb\t$rT, $rA", IntegerOp,
1032       [(set (v8i16 VECREG:$rT), (SPUcntb (v8i16 VECREG:$rA)))]>;
1033
1034 def CNTBv4i32 :
1035     RRForm_1<0b00101101010, (outs VECREG:$rT), (ins VECREG:$rA),
1036       "cntb\t$rT, $rA", IntegerOp,
1037       [(set (v4i32 VECREG:$rT), (SPUcntb (v4i32 VECREG:$rA)))]>;
1038
1039 // gbb: Gather the low order bits from each byte in $rA into a single 16-bit
1040 // quantity stored into $rT's slot 0, upper 16 bits are zeroed, as are
1041 // slots 1-3.
1042 //
1043 // Note: This instruction "pairs" with the fsmb instruction for all of the
1044 // various types defined here.
1045 //
1046 // Note 2: The "VecInst" and "RegInst" forms refer to the result being either
1047 // a vector or register.
1048
1049 class GBBInst<dag OOL, dag IOL, list<dag> pattern>:
1050   RRForm_1<0b01001101100, OOL, IOL, "gbb\t$rT, $rA", GatherOp, pattern>;
1051
1052 class GBBRegInst<RegisterClass rclass, ValueType vectype>:
1053   GBBInst<(outs rclass:$rT), (ins VECREG:$rA),
1054           [/* no pattern */]>;
1055
1056 class GBBVecInst<ValueType vectype>:
1057   GBBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1058           [/* no pattern */]>;
1059
1060 multiclass GatherBitsFromBytes {
1061   def v16i8_r32: GBBRegInst<R32C, v16i8>;
1062   def v16i8_r16: GBBRegInst<R16C, v16i8>;
1063   def v16i8:     GBBVecInst<v16i8>;
1064 }
1065
1066 defm GBB: GatherBitsFromBytes;
1067
1068 // gbh: Gather all low order bits from each halfword in $rA into a single
1069 // 8-bit quantity stored in $rT's slot 0, with the upper bits of $rT set to 0
1070 // and slots 1-3 also set to 0.
1071 //
1072 // See notes for GBBInst, above.
1073
1074 class GBHInst<dag OOL, dag IOL, list<dag> pattern>:
1075     RRForm_1<0b10001101100, OOL, IOL, "gbh\t$rT, $rA", GatherOp,
1076              pattern>;
1077
1078 class GBHRegInst<RegisterClass rclass, ValueType vectype>:
1079     GBHInst<(outs rclass:$rT), (ins VECREG:$rA),
1080             [/* no pattern */]>;
1081
1082 class GBHVecInst<ValueType vectype>:
1083     GBHInst<(outs VECREG:$rT), (ins VECREG:$rA),
1084             [/* no pattern */]>;
1085
1086 multiclass GatherBitsHalfword {
1087   def v8i16_r32: GBHRegInst<R32C, v8i16>;
1088   def v8i16_r16: GBHRegInst<R16C, v8i16>;
1089   def v8i16:     GBHVecInst<v8i16>;
1090 }
1091
1092 defm GBH: GatherBitsHalfword;
1093
1094 // gb: Gather all low order bits from each word in $rA into a single
1095 // 4-bit quantity stored in $rT's slot 0, upper bits in $rT set to 0,
1096 // as well as slots 1-3.
1097 //
1098 // See notes for gbb, above.
1099
1100 class GBInst<dag OOL, dag IOL, list<dag> pattern>:
1101     RRForm_1<0b00001101100, OOL, IOL, "gb\t$rT, $rA", GatherOp,
1102              pattern>;
1103
1104 class GBRegInst<RegisterClass rclass, ValueType vectype>:
1105     GBInst<(outs rclass:$rT), (ins VECREG:$rA),
1106            [/* no pattern */]>;
1107
1108 class GBVecInst<ValueType vectype>:
1109     GBInst<(outs VECREG:$rT), (ins VECREG:$rA),
1110            [/* no pattern */]>;
1111
1112 multiclass GatherBitsWord {
1113   def v4i32_r32: GBRegInst<R32C, v4i32>;
1114   def v4i32_r16: GBRegInst<R16C, v4i32>;
1115   def v4i32:     GBVecInst<v4i32>;
1116 }
1117
1118 defm GB: GatherBitsWord;
1119
1120 // avgb: average bytes
1121 def AVGB:
1122     RRForm<0b11001011000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1123       "avgb\t$rT, $rA, $rB", ByteOp,
1124       []>;
1125
1126 // absdb: absolute difference of bytes
1127 def ABSDB:
1128     RRForm<0b11001010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1129       "absdb\t$rT, $rA, $rB", ByteOp,
1130       []>;
1131
1132 // sumb: sum bytes into halfwords
1133 def SUMB:
1134     RRForm<0b11001010010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1135       "sumb\t$rT, $rA, $rB", ByteOp,
1136       []>;
1137
1138 // Sign extension operations:
1139 class XSBHInst<dag OOL, dag IOL, list<dag> pattern>:
1140     RRForm_1<0b01101101010, OOL, IOL,
1141       "xsbh\t$rDst, $rSrc",
1142       IntegerOp, pattern>;
1143
1144 class XSBHVecInst<ValueType vectype>:
1145     XSBHInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1146       [(set (v8i16 VECREG:$rDst), (sext (vectype VECREG:$rSrc)))]>;
1147
1148 class XSBHInRegInst<RegisterClass rclass, list<dag> pattern>:
1149     XSBHInst<(outs rclass:$rDst), (ins rclass:$rSrc),
1150              pattern>;
1151
1152 multiclass ExtendByteHalfword {
1153   def v16i8:     XSBHVecInst<v8i16>;
1154   def r8:        XSBHInst<(outs R16C:$rDst), (ins R8C:$rSrc),
1155                           [(set R16C:$rDst, (sext R8C:$rSrc))]>;
1156   def r16:       XSBHInRegInst<R16C,
1157                                [(set R16C:$rDst, (sext_inreg R16C:$rSrc, i8))]>;
1158
1159   // 32-bit form for XSBH: used to sign extend 8-bit quantities to 16-bit
1160   // quantities to 32-bit quantities via a 32-bit register (see the sext 8->32
1161   // pattern below). Intentionally doesn't match a pattern because we want the
1162   // sext 8->32 pattern to do the work for us, namely because we need the extra
1163   // XSHWr32.
1164   def r32:   XSBHInRegInst<R32C, [/* no pattern */]>;
1165   
1166   // Same as the 32-bit version, but for i64
1167   def r64:   XSBHInRegInst<R64C, [/* no pattern */]>;
1168 }
1169
1170 defm XSBH : ExtendByteHalfword;
1171
1172 // Sign extend halfwords to words:
1173
1174 class XSHWInst<dag OOL, dag IOL, list<dag> pattern>:
1175     RRForm_1<0b01101101010, OOL, IOL, "xshw\t$rDest, $rSrc",
1176             IntegerOp, pattern>;
1177
1178 class XSHWVecInst<ValueType in_vectype, ValueType out_vectype>:
1179     XSHWInst<(outs VECREG:$rDest), (ins VECREG:$rSrc),
1180              [(set (out_vectype VECREG:$rDest),
1181                    (sext (in_vectype VECREG:$rSrc)))]>;
1182
1183 class XSHWInRegInst<RegisterClass rclass, list<dag> pattern>:
1184     XSHWInst<(outs rclass:$rDest), (ins rclass:$rSrc),
1185              pattern>;
1186              
1187 class XSHWRegInst<RegisterClass rclass>:
1188     XSHWInst<(outs rclass:$rDest), (ins R16C:$rSrc),
1189              [(set rclass:$rDest, (sext R16C:$rSrc))]>;
1190
1191 multiclass ExtendHalfwordWord {
1192   def v4i32: XSHWVecInst<v4i32, v8i16>;
1193   
1194   def r16:   XSHWRegInst<R32C>;
1195   
1196   def r32:   XSHWInRegInst<R32C,
1197                           [(set R32C:$rDest, (sext_inreg R32C:$rSrc, i16))]>;
1198   def r64:   XSHWInRegInst<R64C, [/* no pattern */]>;
1199 }
1200
1201 defm XSHW : ExtendHalfwordWord;
1202
1203 // Sign-extend words to doublewords (32->64 bits)
1204
1205 class XSWDInst<dag OOL, dag IOL, list<dag> pattern>:
1206     RRForm_1<0b01100101010, OOL, IOL, "xswd\t$rDst, $rSrc",
1207               IntegerOp, pattern>;
1208       
1209 class XSWDVecInst<ValueType in_vectype, ValueType out_vectype>:
1210     XSWDInst<(outs VECREG:$rDst), (ins VECREG:$rSrc),
1211              [(set (out_vectype VECREG:$rDst),
1212                    (sext (out_vectype VECREG:$rSrc)))]>;
1213       
1214 class XSWDRegInst<RegisterClass in_rclass, RegisterClass out_rclass>:
1215     XSWDInst<(outs out_rclass:$rDst), (ins in_rclass:$rSrc),
1216              [(set out_rclass:$rDst, (sext in_rclass:$rSrc))]>;
1217              
1218 multiclass ExtendWordToDoubleWord {
1219   def v2i64: XSWDVecInst<v4i32, v2i64>;
1220   def r64:   XSWDRegInst<R32C, R64C>;
1221   
1222   def r64_inreg: XSWDInst<(outs R64C:$rDst), (ins R64C:$rSrc),
1223                           [(set R64C:$rDst, (sext_inreg R64C:$rSrc, i32))]>;
1224 }
1225
1226 defm XSWD : ExtendWordToDoubleWord;
1227
1228 // AND operations
1229
1230 class ANDInst<dag OOL, dag IOL, list<dag> pattern> :
1231     RRForm<0b10000011000, OOL, IOL, "and\t$rT, $rA, $rB",
1232            IntegerOp, pattern>;
1233
1234 class ANDVecInst<ValueType vectype>:
1235     ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1236              [(set (vectype VECREG:$rT), (and (vectype VECREG:$rA),
1237                                               (vectype VECREG:$rB)))]>;
1238
1239 class ANDRegInst<RegisterClass rclass>:
1240     ANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1241              [(set rclass:$rT, (and rclass:$rA, rclass:$rB))]>;
1242
1243 multiclass BitwiseAnd
1244 {
1245   def v16i8: ANDVecInst<v16i8>;
1246   def v8i16: ANDVecInst<v8i16>;
1247   def v4i32: ANDVecInst<v4i32>;
1248   def v2i64: ANDVecInst<v2i64>;
1249
1250   def r128:  ANDRegInst<GPRC>;
1251   def r64:   ANDRegInst<R64C>;
1252   def r32:   ANDRegInst<R32C>;
1253   def r16:   ANDRegInst<R16C>;
1254   def r8:    ANDRegInst<R8C>;
1255
1256   //===---------------------------------------------
1257   // Special instructions to perform the fabs instruction
1258   def fabs32: ANDInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1259                       [/* Intentionally does not match a pattern */]>;
1260
1261   def fabs64: ANDInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1262                       [/* Intentionally does not match a pattern */]>;
1263
1264   def fabsvec: ANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1265                        [/* Intentionally does not match a pattern */]>;
1266
1267   //===---------------------------------------------
1268
1269   // Hacked form of AND to zero-extend 16-bit quantities to 32-bit
1270   // quantities -- see 16->32 zext pattern.
1271   //
1272   // This pattern is somewhat artificial, since it might match some
1273   // compiler generated pattern but it is unlikely to do so.
1274
1275   def i16i32: ANDInst<(outs R32C:$rT), (ins R16C:$rA, R32C:$rB),
1276                       [(set R32C:$rT, (and (zext R16C:$rA), R32C:$rB))]>;
1277 }
1278
1279 defm AND : BitwiseAnd;
1280
1281 // N.B.: vnot_conv is one of those special target selection pattern fragments,
1282 // in which we expect there to be a bit_convert on the constant. Bear in mind
1283 // that llvm translates "not <reg>" to "xor <reg>, -1" (or in this case, a
1284 // constant -1 vector.)
1285
1286 class ANDCInst<dag OOL, dag IOL, list<dag> pattern>:
1287     RRForm<0b10000011010, OOL, IOL, "andc\t$rT, $rA, $rB",
1288            IntegerOp, pattern>;
1289
1290 class ANDCVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
1291     ANDCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1292              [(set (vectype VECREG:$rT),
1293                    (and (vectype VECREG:$rA),
1294                         (vnot_frag (vectype VECREG:$rB))))]>;
1295
1296 class ANDCRegInst<RegisterClass rclass>:
1297     ANDCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1298              [(set rclass:$rT, (and rclass:$rA, (not rclass:$rB)))]>;
1299
1300 multiclass AndComplement
1301 {
1302   def v16i8: ANDCVecInst<v16i8>;
1303   def v8i16: ANDCVecInst<v8i16>;
1304   def v4i32: ANDCVecInst<v4i32>;
1305   def v2i64: ANDCVecInst<v2i64>;
1306
1307   def r128: ANDCRegInst<GPRC>;
1308   def r64:  ANDCRegInst<R64C>;
1309   def r32:  ANDCRegInst<R32C>;
1310   def r16:  ANDCRegInst<R16C>;
1311   def r8:   ANDCRegInst<R8C>;
1312
1313   // Sometimes, the xor pattern has a bitcast constant:
1314   def v16i8_conv: ANDCVecInst<v16i8, vnot_conv>;
1315 }
1316
1317 defm ANDC : AndComplement;
1318
1319 class ANDBIInst<dag OOL, dag IOL, list<dag> pattern>:
1320     RI10Form<0b01101000, OOL, IOL, "andbi\t$rT, $rA, $val",
1321              ByteOp, pattern>;
1322
1323 multiclass AndByteImm
1324 {
1325   def v16i8: ANDBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1326                        [(set (v16i8 VECREG:$rT),
1327                              (and (v16i8 VECREG:$rA),
1328                                   (v16i8 v16i8U8Imm:$val)))]>;
1329
1330   def r8: ANDBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1331                     [(set R8C:$rT, (and R8C:$rA, immU8:$val))]>;
1332 }
1333
1334 defm ANDBI : AndByteImm;
1335
1336 class ANDHIInst<dag OOL, dag IOL, list<dag> pattern> :
1337     RI10Form<0b10101000, OOL, IOL, "andhi\t$rT, $rA, $val",
1338              ByteOp, pattern>;
1339
1340 multiclass AndHalfwordImm
1341 {
1342   def v8i16: ANDHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1343                        [(set (v8i16 VECREG:$rT),
1344                              (and (v8i16 VECREG:$rA), v8i16SExt10Imm:$val))]>;
1345
1346   def r16: ANDHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1347                      [(set R16C:$rT, (and R16C:$rA, i16ImmUns10:$val))]>;
1348
1349   // Zero-extend i8 to i16:
1350   def i8i16: ANDHIInst<(outs R16C:$rT), (ins R8C:$rA, u10imm:$val),
1351                       [(set R16C:$rT, (and (zext R8C:$rA), i16ImmUns10:$val))]>;
1352 }
1353
1354 defm ANDHI : AndHalfwordImm;
1355
1356 class ANDIInst<dag OOL, dag IOL, list<dag> pattern> :
1357     RI10Form<0b00101000, OOL, IOL, "andi\t$rT, $rA, $val",
1358              IntegerOp, pattern>;
1359
1360 multiclass AndWordImm
1361 {
1362   def v4i32: ANDIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
1363                       [(set (v4i32 VECREG:$rT),
1364                             (and (v4i32 VECREG:$rA), v4i32SExt10Imm:$val))]>;
1365
1366   def r32: ANDIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1367                     [(set R32C:$rT, (and R32C:$rA, i32ImmSExt10:$val))]>;
1368
1369   // Hacked form of ANDI to zero-extend i8 quantities to i32. See the zext 8->32
1370   // pattern below.
1371   def i8i32: ANDIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1372                       [(set R32C:$rT,
1373                             (and (zext R8C:$rA), i32ImmSExt10:$val))]>;
1374
1375   // Hacked form of ANDI to zero-extend i16 quantities to i32. See the
1376   // zext 16->32 pattern below.
1377   //
1378   // Note that this pattern is somewhat artificial, since it might match
1379   // something the compiler generates but is unlikely to occur in practice.
1380   def i16i32: ANDIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1381                        [(set R32C:$rT,
1382                              (and (zext R16C:$rA), i32ImmSExt10:$val))]>;
1383 }
1384
1385 defm ANDI : AndWordImm;
1386
1387 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1388 // Bitwise OR group:
1389 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
1390
1391 // Bitwise "or" (N.B.: These are also register-register copy instructions...)
1392 class ORInst<dag OOL, dag IOL, list<dag> pattern>:
1393     RRForm<0b10000010000, OOL, IOL, "or\t$rT, $rA, $rB",
1394            IntegerOp, pattern>;
1395
1396 class ORVecInst<ValueType vectype>:
1397     ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1398            [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1399                                            (vectype VECREG:$rB)))]>;
1400
1401 class ORRegInst<RegisterClass rclass>:
1402     ORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1403            [(set rclass:$rT, (or rclass:$rA, rclass:$rB))]>;
1404
1405 // ORCvtForm: OR conversion form
1406 //
1407 // This is used to "convert" the preferred slot to its vector equivalent, as
1408 // well as convert a vector back to its preferred slot.
1409 //
1410 // These are effectively no-ops, but need to exist for proper type conversion
1411 // and type coercion.
1412
1413 class ORCvtForm<dag OOL, dag IOL, list<dag> pattern = [/* no pattern */]>
1414           : SPUInstr<OOL, IOL, "or\t$rT, $rA, $rA", IntegerOp> {
1415   bits<7> RA;
1416   bits<7> RT;
1417
1418   let Pattern = pattern;
1419
1420   let Inst{0-10} = 0b10000010000;
1421   let Inst{11-17} = RA;
1422   let Inst{18-24} = RA;
1423   let Inst{25-31} = RT;
1424 }
1425
1426 class ORPromoteScalar<RegisterClass rclass>:
1427     ORCvtForm<(outs VECREG:$rT), (ins rclass:$rA)>;
1428
1429 class ORExtractElt<RegisterClass rclass>:
1430     ORCvtForm<(outs rclass:$rT), (ins VECREG:$rA)>;
1431
1432 /* class ORCvtRegGPRC<RegisterClass rclass>:
1433     ORCvtForm<(outs GPRC:$rT), (ins rclass:$rA)>; */
1434
1435 /* class ORCvtGPRCReg<RegisterClass rclass>:
1436     ORCvtForm<(outs rclass:$rT), (ins GPRC:$rA)>; */
1437     
1438 class ORCvtFormR32Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1439     ORCvtForm<(outs rclass:$rT), (ins R32C:$rA), pattern>;
1440     
1441 class ORCvtFormRegR32<RegisterClass rclass, list<dag> pattern = [ ]>:
1442     ORCvtForm<(outs R32C:$rT), (ins rclass:$rA), pattern>;
1443
1444 class ORCvtFormR64Reg<RegisterClass rclass, list<dag> pattern = [ ]>:
1445     ORCvtForm<(outs rclass:$rT), (ins R64C:$rA), pattern>;
1446     
1447 class ORCvtFormRegR64<RegisterClass rclass, list<dag> pattern = [ ]>:
1448     ORCvtForm<(outs R64C:$rT), (ins rclass:$rA), pattern>;
1449
1450 class ORCvtGPRCVec:
1451     ORCvtForm<(outs VECREG:$rT), (ins GPRC:$rA)>;
1452
1453 class ORCvtVecGPRC:
1454     ORCvtForm<(outs GPRC:$rT), (ins VECREG:$rA)>;
1455
1456 multiclass BitwiseOr
1457 {
1458   def v16i8: ORVecInst<v16i8>;
1459   def v8i16: ORVecInst<v8i16>;
1460   def v4i32: ORVecInst<v4i32>;
1461   def v2i64: ORVecInst<v2i64>;
1462
1463   def v4f32: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1464                     [(set (v4f32 VECREG:$rT),
1465                           (v4f32 (bitconvert (or (v4i32 VECREG:$rA),
1466                                                  (v4i32 VECREG:$rB)))))]>;
1467
1468   def v2f64: ORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1469                     [(set (v2f64 VECREG:$rT),
1470                           (v2f64 (bitconvert (or (v2i64 VECREG:$rA),
1471                                                  (v2i64 VECREG:$rB)))))]>;
1472
1473   def r128: ORRegInst<GPRC>;
1474   def r64:  ORRegInst<R64C>;
1475   def r32:  ORRegInst<R32C>;
1476   def r16:  ORRegInst<R16C>;
1477   def r8:   ORRegInst<R8C>;
1478
1479   // OR instructions used to copy f32 and f64 registers.
1480   def f32: ORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
1481                   [/* no pattern */]>;
1482
1483   def f64: ORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
1484                   [/* no pattern */]>;
1485
1486   // scalar->vector promotion, prefslot2vec:
1487   def v16i8_i8:  ORPromoteScalar<R8C>;
1488   def v8i16_i16: ORPromoteScalar<R16C>;
1489   def v4i32_i32: ORPromoteScalar<R32C>;
1490   def v2i64_i64: ORPromoteScalar<R64C>;
1491   def v4f32_f32: ORPromoteScalar<R32FP>;
1492   def v2f64_f64: ORPromoteScalar<R64FP>;
1493
1494   // vector->scalar demotion, vec2prefslot:
1495   def i8_v16i8:  ORExtractElt<R8C>;
1496   def i16_v8i16: ORExtractElt<R16C>;
1497   def i32_v4i32: ORExtractElt<R32C>;
1498   def i64_v2i64: ORExtractElt<R64C>;
1499   def f32_v4f32: ORExtractElt<R32FP>;
1500   def f64_v2f64: ORExtractElt<R64FP>;
1501
1502   // Conversion from vector to GPRC
1503   def i128_vec:  ORCvtVecGPRC;
1504
1505   // Conversion from GPRC to vector
1506   def vec_i128:  ORCvtGPRCVec;
1507
1508 /*
1509   // Conversion from register to GPRC
1510   def i128_r64:  ORCvtRegGPRC<R64C>;
1511   def i128_f64:  ORCvtRegGPRC<R64FP>;
1512   def i128_r32:  ORCvtRegGPRC<R32C>;
1513   def i128_f32:  ORCvtRegGPRC<R32FP>;
1514   def i128_r16:  ORCvtRegGPRC<R16C>;
1515   def i128_r8:   ORCvtRegGPRC<R8C>;
1516
1517   // Conversion from GPRC to register
1518   def r64_i128:  ORCvtGPRCReg<R64C>;
1519   def f64_i128:  ORCvtGPRCReg<R64FP>;
1520   def r32_i128:  ORCvtGPRCReg<R32C>;
1521   def f32_i128:  ORCvtGPRCReg<R32FP>;
1522   def r16_i128:  ORCvtGPRCReg<R16C>;
1523   def r8_i128:   ORCvtGPRCReg<R8C>;
1524 */
1525 /*
1526   // Conversion from register to R32C:
1527   def r32_r16:   ORCvtFormRegR32<R16C>;
1528   def r32_r8:    ORCvtFormRegR32<R8C>;
1529   
1530   // Conversion from R32C to register
1531   def r32_r16:   ORCvtFormR32Reg<R16C>;
1532   def r32_r8:    ORCvtFormR32Reg<R8C>;
1533 */
1534   
1535   // Conversion from R64C to register:
1536   def r32_r64:   ORCvtFormR64Reg<R32C>;
1537   // def r16_r64:   ORCvtFormR64Reg<R16C>;
1538   // def r8_r64:    ORCvtFormR64Reg<R8C>;
1539   
1540   // Conversion to R64C from register:
1541   def r64_r32:   ORCvtFormRegR64<R32C>;
1542   // def r64_r16:   ORCvtFormRegR64<R16C>;
1543   // def r64_r8:    ORCvtFormRegR64<R8C>;
1544
1545   // bitconvert patterns:
1546   def r32_f32:   ORCvtFormR32Reg<R32FP,
1547                                  [(set R32FP:$rT, (bitconvert R32C:$rA))]>;
1548   def f32_r32:   ORCvtFormRegR32<R32FP,
1549                                  [(set R32C:$rT, (bitconvert R32FP:$rA))]>;
1550
1551   def r64_f64:   ORCvtFormR64Reg<R64FP,
1552                                  [(set R64FP:$rT, (bitconvert R64C:$rA))]>;
1553   def f64_r64:   ORCvtFormRegR64<R64FP,
1554                                  [(set R64C:$rT, (bitconvert R64FP:$rA))]>;
1555 }
1556
1557 defm OR : BitwiseOr;
1558
1559 // scalar->vector promotion patterns (preferred slot to vector):
1560 def : Pat<(v16i8 (SPUprefslot2vec R8C:$rA)),
1561           (ORv16i8_i8 R8C:$rA)>;
1562
1563 def : Pat<(v8i16 (SPUprefslot2vec R16C:$rA)),
1564           (ORv8i16_i16 R16C:$rA)>;
1565
1566 def : Pat<(v4i32 (SPUprefslot2vec R32C:$rA)),
1567           (ORv4i32_i32 R32C:$rA)>;
1568
1569 def : Pat<(v2i64 (SPUprefslot2vec R64C:$rA)),
1570           (ORv2i64_i64 R64C:$rA)>;
1571
1572 def : Pat<(v4f32 (SPUprefslot2vec R32FP:$rA)),
1573           (ORv4f32_f32 R32FP:$rA)>;
1574
1575 def : Pat<(v2f64 (SPUprefslot2vec R64FP:$rA)),
1576           (ORv2f64_f64 R64FP:$rA)>;
1577
1578 // ORi*_v*: Used to extract vector element 0 (the preferred slot), otherwise
1579 // known as converting the vector back to its preferred slot
1580
1581 def : Pat<(SPUvec2prefslot (v16i8 VECREG:$rA)),
1582           (ORi8_v16i8 VECREG:$rA)>;
1583
1584 def : Pat<(SPUvec2prefslot (v8i16 VECREG:$rA)),
1585           (ORi16_v8i16 VECREG:$rA)>;
1586
1587 def : Pat<(SPUvec2prefslot (v4i32 VECREG:$rA)),
1588           (ORi32_v4i32 VECREG:$rA)>;
1589
1590 def : Pat<(SPUvec2prefslot (v2i64 VECREG:$rA)),
1591           (ORi64_v2i64 VECREG:$rA)>;
1592
1593 def : Pat<(SPUvec2prefslot (v4f32 VECREG:$rA)),
1594           (ORf32_v4f32 VECREG:$rA)>;
1595
1596 def : Pat<(SPUvec2prefslot (v2f64 VECREG:$rA)),
1597           (ORf64_v2f64 VECREG:$rA)>;
1598
1599 // Load Register: This is an assembler alias for a bitwise OR of a register
1600 // against itself. It's here because it brings some clarity to assembly
1601 // language output.
1602
1603 let hasCtrlDep = 1 in {
1604     class LRInst<dag OOL, dag IOL>
1605               : SPUInstr<OOL, IOL, "lr\t$rT, $rA", IntegerOp> {
1606       bits<7> RA;
1607       bits<7> RT;
1608
1609       let Pattern = [/*no pattern*/];
1610
1611       let Inst{0-10} = 0b10000010000;   /* It's an OR operation */
1612       let Inst{11-17} = RA;
1613       let Inst{18-24} = RA;
1614       let Inst{25-31} = RT;
1615     }
1616
1617     class LRVecInst<ValueType vectype>:
1618         LRInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
1619
1620     class LRRegInst<RegisterClass rclass>:
1621         LRInst<(outs rclass:$rT), (ins rclass:$rA)>;
1622
1623     multiclass LoadRegister {
1624       def v2i64: LRVecInst<v2i64>;
1625       def v2f64: LRVecInst<v2f64>;
1626       def v4i32: LRVecInst<v4i32>;
1627       def v4f32: LRVecInst<v4f32>;
1628       def v8i16: LRVecInst<v8i16>;
1629       def v16i8: LRVecInst<v16i8>;
1630
1631       def r128:  LRRegInst<GPRC>;
1632       def r64:   LRRegInst<R64C>;
1633       def f64:   LRRegInst<R64FP>;
1634       def r32:   LRRegInst<R32C>;
1635       def f32:   LRRegInst<R32FP>;
1636       def r16:   LRRegInst<R16C>;
1637       def r8:    LRRegInst<R8C>;
1638     }
1639
1640     defm LR: LoadRegister;
1641 }
1642
1643 // ORC: Bitwise "or" with complement (c = a | ~b)
1644
1645 class ORCInst<dag OOL, dag IOL, list<dag> pattern>:
1646     RRForm<0b10010010000, OOL, IOL, "orc\t$rT, $rA, $rB",
1647            IntegerOp, pattern>;
1648
1649 class ORCVecInst<ValueType vectype>:
1650     ORCInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1651             [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1652                                             (vnot (vectype VECREG:$rB))))]>;
1653
1654 class ORCRegInst<RegisterClass rclass>:
1655   ORCInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1656           [(set rclass:$rT, (or rclass:$rA, (not rclass:$rB)))]>;
1657
1658 multiclass BitwiseOrComplement
1659 {
1660   def v16i8: ORCVecInst<v16i8>;
1661   def v8i16: ORCVecInst<v8i16>;
1662   def v4i32: ORCVecInst<v4i32>;
1663   def v2i64: ORCVecInst<v2i64>;
1664
1665   def r128:  ORCRegInst<GPRC>;
1666   def r64:   ORCRegInst<R64C>;
1667   def r32:   ORCRegInst<R32C>;
1668   def r16:   ORCRegInst<R16C>;
1669   def r8:    ORCRegInst<R8C>;
1670 }
1671
1672 defm ORC : BitwiseOrComplement;
1673
1674 // OR byte immediate
1675 class ORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1676     RI10Form<0b01100000, OOL, IOL, "orbi\t$rT, $rA, $val",
1677              IntegerOp, pattern>;
1678
1679 class ORBIVecInst<ValueType vectype, PatLeaf immpred>:
1680     ORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1681              [(set (v16i8 VECREG:$rT), (or (vectype VECREG:$rA),
1682                                            (vectype immpred:$val)))]>;
1683
1684 multiclass BitwiseOrByteImm
1685 {
1686   def v16i8: ORBIVecInst<v16i8, v16i8U8Imm>;
1687
1688   def r8: ORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1689                    [(set R8C:$rT, (or R8C:$rA, immU8:$val))]>;
1690 }
1691
1692 defm ORBI : BitwiseOrByteImm;
1693
1694 // OR halfword immediate
1695 class ORHIInst<dag OOL, dag IOL, list<dag> pattern>:
1696     RI10Form<0b10100000, OOL, IOL, "orhi\t$rT, $rA, $val",
1697              IntegerOp, pattern>;
1698
1699 class ORHIVecInst<ValueType vectype, PatLeaf immpred>:
1700     ORHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1701               [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1702                                               immpred:$val))]>;
1703
1704 multiclass BitwiseOrHalfwordImm
1705 {
1706   def v8i16: ORHIVecInst<v8i16, v8i16Uns10Imm>;
1707
1708   def r16: ORHIInst<(outs R16C:$rT), (ins R16C:$rA, u10imm:$val),
1709                     [(set R16C:$rT, (or R16C:$rA, i16ImmUns10:$val))]>;
1710
1711   // Specialized ORHI form used to promote 8-bit registers to 16-bit
1712   def i8i16: ORHIInst<(outs R16C:$rT), (ins R8C:$rA, s10imm:$val),
1713                       [(set R16C:$rT, (or (anyext R8C:$rA),
1714                                           i16ImmSExt10:$val))]>;
1715 }
1716
1717 defm ORHI : BitwiseOrHalfwordImm;
1718
1719 class ORIInst<dag OOL, dag IOL, list<dag> pattern>:
1720     RI10Form<0b00100000, OOL, IOL, "ori\t$rT, $rA, $val",
1721              IntegerOp, pattern>;
1722
1723 class ORIVecInst<ValueType vectype, PatLeaf immpred>:
1724     ORIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1725             [(set (vectype VECREG:$rT), (or (vectype VECREG:$rA),
1726                                             immpred:$val))]>;
1727
1728 // Bitwise "or" with immediate
1729 multiclass BitwiseOrImm
1730 {
1731   def v4i32: ORIVecInst<v4i32, v4i32Uns10Imm>;
1732
1733   def r32: ORIInst<(outs R32C:$rT), (ins R32C:$rA, u10imm_i32:$val),
1734                    [(set R32C:$rT, (or R32C:$rA, i32ImmUns10:$val))]>;
1735
1736   // i16i32: hacked version of the ori instruction to extend 16-bit quantities
1737   // to 32-bit quantities. used exclusively to match "anyext" conversions (vide
1738   // infra "anyext 16->32" pattern.)
1739   def i16i32: ORIInst<(outs R32C:$rT), (ins R16C:$rA, s10imm_i32:$val),
1740                       [(set R32C:$rT, (or (anyext R16C:$rA),
1741                                           i32ImmSExt10:$val))]>;
1742
1743   // i8i32: Hacked version of the ORI instruction to extend 16-bit quantities
1744   // to 32-bit quantities. Used exclusively to match "anyext" conversions (vide
1745   // infra "anyext 16->32" pattern.)
1746   def i8i32: ORIInst<(outs R32C:$rT), (ins R8C:$rA, s10imm_i32:$val),
1747                      [(set R32C:$rT, (or (anyext R8C:$rA),
1748                                          i32ImmSExt10:$val))]>;
1749 }
1750
1751 defm ORI : BitwiseOrImm;
1752
1753 // ORX: "or" across the vector: or's $rA's word slots leaving the result in
1754 // $rT[0], slots 1-3 are zeroed.
1755 //
1756 // FIXME: Needs to match an intrinsic pattern.
1757 def ORXv4i32:
1758     RRForm<0b10010010000, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1759       "orx\t$rT, $rA, $rB", IntegerOp,
1760       []>;
1761
1762 // XOR:
1763
1764 class XORInst<dag OOL, dag IOL, list<dag> pattern> :
1765     RRForm<0b10010010000, OOL, IOL, "xor\t$rT, $rA, $rB",
1766            IntegerOp, pattern>;
1767
1768 class XORVecInst<ValueType vectype>:
1769     XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1770              [(set (vectype VECREG:$rT), (xor (vectype VECREG:$rA),
1771                                               (vectype VECREG:$rB)))]>;
1772
1773 class XORRegInst<RegisterClass rclass>:
1774     XORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1775              [(set rclass:$rT, (xor rclass:$rA, rclass:$rB))]>;
1776
1777 multiclass BitwiseExclusiveOr
1778 {
1779   def v16i8: XORVecInst<v16i8>;
1780   def v8i16: XORVecInst<v8i16>;
1781   def v4i32: XORVecInst<v4i32>;
1782   def v2i64: XORVecInst<v2i64>;
1783
1784   def r128:  XORRegInst<GPRC>;
1785   def r64:   XORRegInst<R64C>;
1786   def r32:   XORRegInst<R32C>;
1787   def r16:   XORRegInst<R16C>;
1788   def r8:    XORRegInst<R8C>;
1789
1790   // XOR instructions used to negate f32 and f64 quantities.
1791
1792   def fneg32: XORInst<(outs R32FP:$rT), (ins R32FP:$rA, R32C:$rB),
1793                      [/* no pattern */]>;
1794
1795   def fneg64: XORInst<(outs R64FP:$rT), (ins R64FP:$rA, R64C:$rB),
1796                      [/* no pattern */]>;
1797
1798   def fnegvec: XORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1799                       [/* no pattern, see fneg{32,64} */]>;
1800 }
1801
1802 defm XOR : BitwiseExclusiveOr;
1803
1804 //==----------------------------------------------------------
1805
1806 class XORBIInst<dag OOL, dag IOL, list<dag> pattern>:
1807     RI10Form<0b01100000, OOL, IOL, "xorbi\t$rT, $rA, $val",
1808              IntegerOp, pattern>;
1809
1810 multiclass XorByteImm
1811 {
1812   def v16i8:
1813     XORBIInst<(outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1814               [(set (v16i8 VECREG:$rT), (xor (v16i8 VECREG:$rA), v16i8U8Imm:$val))]>;
1815
1816   def r8:
1817     XORBIInst<(outs R8C:$rT), (ins R8C:$rA, u10imm_i8:$val),
1818               [(set R8C:$rT, (xor R8C:$rA, immU8:$val))]>;
1819 }
1820
1821 defm XORBI : XorByteImm;
1822
1823 def XORHIv8i16:
1824     RI10Form<0b10100000, (outs VECREG:$rT), (ins VECREG:$rA, u10imm:$val),
1825       "xorhi\t$rT, $rA, $val", IntegerOp,
1826       [(set (v8i16 VECREG:$rT), (xor (v8i16 VECREG:$rA),
1827                                       v8i16SExt10Imm:$val))]>;
1828
1829 def XORHIr16:
1830     RI10Form<0b10100000, (outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
1831       "xorhi\t$rT, $rA, $val", IntegerOp,
1832       [(set R16C:$rT, (xor R16C:$rA, i16ImmSExt10:$val))]>;
1833
1834 def XORIv4i32:
1835     RI10Form<0b00100000, (outs VECREG:$rT), (ins VECREG:$rA, s10imm_i32:$val),
1836       "xori\t$rT, $rA, $val", IntegerOp,
1837       [(set (v4i32 VECREG:$rT), (xor (v4i32 VECREG:$rA),
1838                                      v4i32SExt10Imm:$val))]>;
1839
1840 def XORIr32:
1841     RI10Form<0b00100000, (outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
1842       "xori\t$rT, $rA, $val", IntegerOp,
1843       [(set R32C:$rT, (xor R32C:$rA, i32ImmSExt10:$val))]>;
1844
1845 // NAND:
1846
1847 class NANDInst<dag OOL, dag IOL, list<dag> pattern>:
1848     RRForm<0b10010011000, OOL, IOL, "nand\t$rT, $rA, $rB",
1849            IntegerOp, pattern>;
1850
1851 class NANDVecInst<ValueType vectype>:
1852     NANDInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1853              [(set (vectype VECREG:$rT), (vnot (and (vectype VECREG:$rA),
1854                                                     (vectype VECREG:$rB))))]>;
1855 class NANDRegInst<RegisterClass rclass>:
1856     NANDInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1857              [(set rclass:$rT, (not (and rclass:$rA, rclass:$rB)))]>;
1858
1859 multiclass BitwiseNand
1860 {
1861   def v16i8: NANDVecInst<v16i8>;
1862   def v8i16: NANDVecInst<v8i16>;
1863   def v4i32: NANDVecInst<v4i32>;
1864   def v2i64: NANDVecInst<v2i64>;
1865
1866   def r128:  NANDRegInst<GPRC>;
1867   def r64:   NANDRegInst<R64C>;
1868   def r32:   NANDRegInst<R32C>;
1869   def r16:   NANDRegInst<R16C>;
1870   def r8:    NANDRegInst<R8C>;
1871 }
1872
1873 defm NAND : BitwiseNand;
1874
1875 // NOR:
1876
1877 class NORInst<dag OOL, dag IOL, list<dag> pattern>:
1878     RRForm<0b10010010000, OOL, IOL, "nor\t$rT, $rA, $rB",
1879            IntegerOp, pattern>;
1880
1881 class NORVecInst<ValueType vectype>:
1882     NORInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
1883             [(set (vectype VECREG:$rT), (vnot (or (vectype VECREG:$rA),
1884                                                   (vectype VECREG:$rB))))]>;
1885 class NORRegInst<RegisterClass rclass>:
1886     NORInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
1887             [(set rclass:$rT, (not (or rclass:$rA, rclass:$rB)))]>;
1888
1889 multiclass BitwiseNor
1890 {
1891   def v16i8: NORVecInst<v16i8>;
1892   def v8i16: NORVecInst<v8i16>;
1893   def v4i32: NORVecInst<v4i32>;
1894   def v2i64: NORVecInst<v2i64>;
1895
1896   def r128:  NORRegInst<GPRC>;
1897   def r64:   NORRegInst<R64C>;
1898   def r32:   NORRegInst<R32C>;
1899   def r16:   NORRegInst<R16C>;
1900   def r8:    NORRegInst<R8C>;
1901 }
1902
1903 defm NOR : BitwiseNor;
1904
1905 // Select bits:
1906 class SELBInst<dag OOL, dag IOL, list<dag> pattern>:
1907     RRRForm<0b1000, OOL, IOL, "selb\t$rT, $rA, $rB, $rC",
1908             IntegerOp, pattern>;
1909
1910 class SELBVecInst<ValueType vectype, PatFrag vnot_frag = vnot>:
1911   SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1912            [(set (vectype VECREG:$rT),
1913                  (or (and (vectype VECREG:$rC), (vectype VECREG:$rB)),
1914                      (and (vnot_frag (vectype VECREG:$rC)),
1915                           (vectype VECREG:$rA))))]>;
1916
1917 class SELBVecVCondInst<ValueType vectype>:
1918   SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1919            [(set (vectype VECREG:$rT),
1920                  (select (vectype VECREG:$rC),
1921                          (vectype VECREG:$rB),
1922                          (vectype VECREG:$rA)))]>;
1923
1924 class SELBVecCondInst<ValueType vectype>:
1925   SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, R32C:$rC),
1926            [(set (vectype VECREG:$rT),
1927                  (select R32C:$rC,
1928                          (vectype VECREG:$rB),
1929                          (vectype VECREG:$rA)))]>;
1930
1931 class SELBRegInst<RegisterClass rclass>:
1932   SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rclass:$rC),
1933            [(set rclass:$rT,
1934                  (or (and rclass:$rB, rclass:$rC),
1935                      (and rclass:$rA, (not rclass:$rC))))]>;
1936
1937 class SELBRegCondInst<RegisterClass rcond, RegisterClass rclass>:
1938   SELBInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB, rcond:$rC),
1939            [(set rclass:$rT,
1940                  (select rcond:$rC, rclass:$rB, rclass:$rA))]>;
1941
1942 multiclass SelectBits
1943 {
1944   def v16i8: SELBVecInst<v16i8>;
1945   def v8i16: SELBVecInst<v8i16>;
1946   def v4i32: SELBVecInst<v4i32>;
1947   def v2i64: SELBVecInst<v2i64, vnot_conv>;
1948
1949   def r128:  SELBRegInst<GPRC>;
1950   def r64:   SELBRegInst<R64C>;
1951   def r32:   SELBRegInst<R32C>;
1952   def r16:   SELBRegInst<R16C>;
1953   def r8:    SELBRegInst<R8C>;
1954
1955   def v16i8_cond: SELBVecCondInst<v16i8>;
1956   def v8i16_cond: SELBVecCondInst<v8i16>;
1957   def v4i32_cond: SELBVecCondInst<v4i32>;
1958   def v2i64_cond: SELBVecCondInst<v2i64>;
1959
1960   def v16i8_vcond: SELBVecCondInst<v16i8>;
1961   def v8i16_vcond: SELBVecCondInst<v8i16>;
1962   def v4i32_vcond: SELBVecCondInst<v4i32>;
1963   def v2i64_vcond: SELBVecCondInst<v2i64>;
1964
1965   def v4f32_cond:
1966         SELBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
1967                  [(set (v4f32 VECREG:$rT),
1968                        (select (v4i32 VECREG:$rC),
1969                                (v4f32 VECREG:$rB),
1970                                (v4f32 VECREG:$rA)))]>;
1971
1972   // SELBr64_cond is defined in SPU64InstrInfo.td
1973   def r32_cond:   SELBRegCondInst<R32C, R32C>;
1974   def f32_cond:   SELBRegCondInst<R32C, R32FP>;
1975   def r16_cond:   SELBRegCondInst<R16C, R16C>;
1976   def r8_cond:    SELBRegCondInst<R8C,  R8C>;
1977 }
1978
1979 defm SELB : SelectBits;
1980
1981 class SPUselbPatVec<ValueType vectype, SPUInstr inst>:
1982    Pat<(SPUselb (vectype VECREG:$rA), (vectype VECREG:$rB), (vectype VECREG:$rC)),
1983        (inst VECREG:$rA, VECREG:$rB, VECREG:$rC)>;
1984
1985 def : SPUselbPatVec<v16i8, SELBv16i8>;
1986 def : SPUselbPatVec<v8i16, SELBv8i16>;
1987 def : SPUselbPatVec<v4i32, SELBv4i32>;
1988 def : SPUselbPatVec<v2i64, SELBv2i64>;
1989
1990 class SPUselbPatReg<RegisterClass rclass, SPUInstr inst>:
1991    Pat<(SPUselb rclass:$rA, rclass:$rB, rclass:$rC),
1992        (inst rclass:$rA, rclass:$rB, rclass:$rC)>;
1993
1994 def : SPUselbPatReg<R8C,   SELBr8>;
1995 def : SPUselbPatReg<R16C,  SELBr16>;
1996 def : SPUselbPatReg<R32C,  SELBr32>;
1997 def : SPUselbPatReg<R64C,  SELBr64>;
1998
1999 // EQV: Equivalence (1 for each same bit, otherwise 0)
2000 //
2001 // Note: There are a lot of ways to match this bit operator and these patterns
2002 // attempt to be as exhaustive as possible.
2003
2004 class EQVInst<dag OOL, dag IOL, list<dag> pattern>:
2005     RRForm<0b10010010000, OOL, IOL, "eqv\t$rT, $rA, $rB",
2006            IntegerOp, pattern>;
2007
2008 class EQVVecInst<ValueType vectype>:
2009     EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2010             [(set (vectype VECREG:$rT),
2011                   (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2012                       (and (vnot (vectype VECREG:$rA)),
2013                            (vnot (vectype VECREG:$rB)))))]>;
2014
2015 class EQVRegInst<RegisterClass rclass>:
2016     EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2017             [(set rclass:$rT, (or (and rclass:$rA, rclass:$rB),
2018                                   (and (not rclass:$rA), (not rclass:$rB))))]>;
2019
2020 class EQVVecPattern1<ValueType vectype>:
2021   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2022           [(set (vectype VECREG:$rT),
2023                 (xor (vectype VECREG:$rA), (vnot (vectype VECREG:$rB))))]>;
2024
2025 class EQVRegPattern1<RegisterClass rclass>:
2026   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2027           [(set rclass:$rT, (xor rclass:$rA, (not rclass:$rB)))]>;
2028
2029 class EQVVecPattern2<ValueType vectype>:
2030   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2031           [(set (vectype VECREG:$rT),
2032                 (or (and (vectype VECREG:$rA), (vectype VECREG:$rB)),
2033                     (vnot (or (vectype VECREG:$rA), (vectype VECREG:$rB)))))]>;
2034
2035 class EQVRegPattern2<RegisterClass rclass>:
2036   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2037           [(set rclass:$rT,
2038                 (or (and rclass:$rA, rclass:$rB),
2039                     (not (or rclass:$rA, rclass:$rB))))]>;
2040
2041 class EQVVecPattern3<ValueType vectype>:
2042   EQVInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2043           [(set (vectype VECREG:$rT),
2044                 (not (xor (vectype VECREG:$rA), (vectype VECREG:$rB))))]>;
2045
2046 class EQVRegPattern3<RegisterClass rclass>:
2047   EQVInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2048           [(set rclass:$rT, (not (xor rclass:$rA, rclass:$rB)))]>;
2049
2050 multiclass BitEquivalence
2051 {
2052   def v16i8: EQVVecInst<v16i8>;
2053   def v8i16: EQVVecInst<v8i16>;
2054   def v4i32: EQVVecInst<v4i32>;
2055   def v2i64: EQVVecInst<v2i64>;
2056
2057   def v16i8_1: EQVVecPattern1<v16i8>;
2058   def v8i16_1: EQVVecPattern1<v8i16>;
2059   def v4i32_1: EQVVecPattern1<v4i32>;
2060   def v2i64_1: EQVVecPattern1<v2i64>;
2061
2062   def v16i8_2: EQVVecPattern2<v16i8>;
2063   def v8i16_2: EQVVecPattern2<v8i16>;
2064   def v4i32_2: EQVVecPattern2<v4i32>;
2065   def v2i64_2: EQVVecPattern2<v2i64>;
2066
2067   def v16i8_3: EQVVecPattern3<v16i8>;
2068   def v8i16_3: EQVVecPattern3<v8i16>;
2069   def v4i32_3: EQVVecPattern3<v4i32>;
2070   def v2i64_3: EQVVecPattern3<v2i64>;
2071
2072   def r128:  EQVRegInst<GPRC>;
2073   def r64:   EQVRegInst<R64C>;
2074   def r32:   EQVRegInst<R32C>;
2075   def r16:   EQVRegInst<R16C>;
2076   def r8:    EQVRegInst<R8C>;
2077
2078   def r128_1: EQVRegPattern1<GPRC>;
2079   def r64_1:  EQVRegPattern1<R64C>;
2080   def r32_1:  EQVRegPattern1<R32C>;
2081   def r16_1:  EQVRegPattern1<R16C>;
2082   def r8_1:   EQVRegPattern1<R8C>;
2083
2084   def r128_2: EQVRegPattern2<GPRC>;
2085   def r64_2:  EQVRegPattern2<R64C>;
2086   def r32_2:  EQVRegPattern2<R32C>;
2087   def r16_2:  EQVRegPattern2<R16C>;
2088   def r8_2:   EQVRegPattern2<R8C>;
2089
2090   def r128_3: EQVRegPattern3<GPRC>;
2091   def r64_3:  EQVRegPattern3<R64C>;
2092   def r32_3:  EQVRegPattern3<R32C>;
2093   def r16_3:  EQVRegPattern3<R16C>;
2094   def r8_3:   EQVRegPattern3<R8C>;
2095 }
2096
2097 defm EQV: BitEquivalence;
2098
2099 //===----------------------------------------------------------------------===//
2100 // Vector shuffle...
2101 //===----------------------------------------------------------------------===//
2102 // SPUshuffle is generated in LowerVECTOR_SHUFFLE and gets replaced with SHUFB.
2103 // See the SPUshuffle SDNode operand above, which sets up the DAG pattern
2104 // matcher to emit something when the LowerVECTOR_SHUFFLE generates a node with
2105 // the SPUISD::SHUFB opcode.
2106 //===----------------------------------------------------------------------===//
2107
2108 class SHUFBInst<dag OOL, dag IOL, list<dag> pattern>:
2109     RRRForm<0b1000, OOL, IOL, "shufb\t$rT, $rA, $rB, $rC",
2110             IntegerOp, pattern>;
2111
2112 class SHUFBVecInst<ValueType resultvec, ValueType maskvec>:
2113     SHUFBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
2114               [(set (resultvec VECREG:$rT),
2115                     (SPUshuffle (resultvec VECREG:$rA),
2116                                 (resultvec VECREG:$rB),
2117                                 (maskvec VECREG:$rC)))]>;
2118
2119 class SHUFBGPRCInst:
2120     SHUFBInst<(outs VECREG:$rT), (ins GPRC:$rA, GPRC:$rB, VECREG:$rC),
2121               [/* no pattern */]>;
2122
2123 multiclass ShuffleBytes
2124 {
2125   def v16i8     : SHUFBVecInst<v16i8, v16i8>;
2126   def v16i8_m32 : SHUFBVecInst<v16i8, v4i32>;
2127   def v8i16     : SHUFBVecInst<v8i16, v16i8>;
2128   def v8i16_m32 : SHUFBVecInst<v8i16, v4i32>;
2129   def v4i32     : SHUFBVecInst<v4i32, v16i8>;
2130   def v4i32_m32 : SHUFBVecInst<v4i32, v4i32>;
2131   def v2i64     : SHUFBVecInst<v2i64, v16i8>;
2132   def v2i64_m32 : SHUFBVecInst<v2i64, v4i32>;
2133
2134   def v4f32     : SHUFBVecInst<v4f32, v16i8>;
2135   def v4f32_m32 : SHUFBVecInst<v4f32, v4i32>;
2136
2137   def v2f64     : SHUFBVecInst<v2f64, v16i8>;
2138   def v2f64_m32 : SHUFBVecInst<v2f64, v4i32>;
2139
2140   def gprc      : SHUFBGPRCInst;
2141 }
2142
2143 defm SHUFB : ShuffleBytes;
2144
2145 //===----------------------------------------------------------------------===//
2146 // Shift and rotate group:
2147 //===----------------------------------------------------------------------===//
2148
2149 class SHLHInst<dag OOL, dag IOL, list<dag> pattern>:
2150     RRForm<0b11111010000, OOL, IOL, "shlh\t$rT, $rA, $rB",
2151            RotateShift, pattern>;
2152
2153 class SHLHVecInst<ValueType vectype>:
2154     SHLHInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2155              [(set (vectype VECREG:$rT),
2156                    (SPUvec_shl (vectype VECREG:$rA), R16C:$rB))]>;
2157
2158 multiclass ShiftLeftHalfword
2159 {
2160   def v8i16: SHLHVecInst<v8i16>;
2161   def r16:   SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
2162                       [(set R16C:$rT, (shl R16C:$rA, R16C:$rB))]>;
2163   def r16_r32: SHLHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2164                         [(set R16C:$rT, (shl R16C:$rA, R32C:$rB))]>;
2165 }
2166
2167 defm SHLH : ShiftLeftHalfword;
2168
2169 //===----------------------------------------------------------------------===//
2170
2171 class SHLHIInst<dag OOL, dag IOL, list<dag> pattern>:
2172     RI7Form<0b11111010000, OOL, IOL, "shlhi\t$rT, $rA, $val",
2173             RotateShift, pattern>;
2174
2175 class SHLHIVecInst<ValueType vectype>:
2176     SHLHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2177               [(set (vectype VECREG:$rT),
2178                     (SPUvec_shl (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2179
2180 multiclass ShiftLeftHalfwordImm
2181 {
2182   def v8i16: SHLHIVecInst<v8i16>;
2183   def r16: SHLHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2184                      [(set R16C:$rT, (shl R16C:$rA, (i16 uimm7:$val)))]>;
2185 }
2186
2187 defm SHLHI : ShiftLeftHalfwordImm;
2188
2189 def : Pat<(SPUvec_shl (v8i16 VECREG:$rA), (i32 uimm7:$val)),
2190           (SHLHIv8i16 VECREG:$rA, uimm7:$val)>;
2191
2192 def : Pat<(shl R16C:$rA, (i32 uimm7:$val)),
2193           (SHLHIr16 R16C:$rA, uimm7:$val)>;
2194
2195 //===----------------------------------------------------------------------===//
2196
2197 class SHLInst<dag OOL, dag IOL, list<dag> pattern>:
2198     RRForm<0b11111010000, OOL, IOL, "shl\t$rT, $rA, $rB",
2199            RotateShift, pattern>;
2200
2201 multiclass ShiftLeftWord
2202 {
2203   def v4i32:
2204       SHLInst<(outs VECREG:$rT), (ins VECREG:$rA, R16C:$rB),
2205               [(set (v4i32 VECREG:$rT),
2206                     (SPUvec_shl (v4i32 VECREG:$rA), R16C:$rB))]>;
2207   def r32:
2208       SHLInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2209               [(set R32C:$rT, (shl R32C:$rA, R32C:$rB))]>;
2210 }
2211
2212 defm SHL: ShiftLeftWord;
2213
2214 //===----------------------------------------------------------------------===//
2215
2216 class SHLIInst<dag OOL, dag IOL, list<dag> pattern>:
2217     RI7Form<0b11111010000, OOL, IOL, "shli\t$rT, $rA, $val",
2218             RotateShift, pattern>;
2219
2220 multiclass ShiftLeftWordImm
2221 {
2222   def v4i32:
2223     SHLIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2224              [(set (v4i32 VECREG:$rT),
2225                    (SPUvec_shl (v4i32 VECREG:$rA), (i32 uimm7:$val)))]>;
2226
2227   def r32:
2228     SHLIInst<(outs R32C:$rT), (ins R32C:$rA, u7imm_i32:$val),
2229              [(set R32C:$rT, (shl R32C:$rA, (i32 uimm7:$val)))]>;
2230 }
2231
2232 defm SHLI : ShiftLeftWordImm;
2233
2234 //===----------------------------------------------------------------------===//
2235 // SHLQBI vec form: Note that this will shift the entire vector (the 128-bit
2236 // register) to the left. Vector form is here to ensure type correctness.
2237 //
2238 // The shift count is in the lowest 3 bits (29-31) of $rB, so only a bit shift
2239 // of 7 bits is actually possible.
2240 //
2241 // Note also that SHLQBI/SHLQBII are used in conjunction with SHLQBY/SHLQBYI
2242 // to shift i64 and i128. SHLQBI is the residual left over after shifting by
2243 // bytes with SHLQBY.
2244
2245 class SHLQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2246     RRForm<0b11011011100, OOL, IOL, "shlqbi\t$rT, $rA, $rB",
2247            RotateShift, pattern>;
2248
2249 class SHLQBIVecInst<ValueType vectype>:
2250     SHLQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2251                [(set (vectype VECREG:$rT),
2252                      (SPUshlquad_l_bits (vectype VECREG:$rA), R32C:$rB))]>;
2253
2254 class SHLQBIRegInst<RegisterClass rclass>:
2255     SHLQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2256                [/* no pattern */]>;
2257
2258 multiclass ShiftLeftQuadByBits
2259 {
2260   def v16i8: SHLQBIVecInst<v16i8>;
2261   def v8i16: SHLQBIVecInst<v8i16>;
2262   def v4i32: SHLQBIVecInst<v4i32>;
2263   def v4f32: SHLQBIVecInst<v4f32>;
2264   def v2i64: SHLQBIVecInst<v2i64>;
2265   def v2f64: SHLQBIVecInst<v2f64>;
2266
2267   def r128:  SHLQBIRegInst<GPRC>;
2268 }
2269
2270 defm SHLQBI : ShiftLeftQuadByBits;
2271
2272 // See note above on SHLQBI. In this case, the predicate actually does then
2273 // enforcement, whereas with SHLQBI, we have to "take it on faith."
2274 class SHLQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2275     RI7Form<0b11011111100, OOL, IOL, "shlqbii\t$rT, $rA, $val",
2276             RotateShift, pattern>;
2277
2278 class SHLQBIIVecInst<ValueType vectype>:
2279     SHLQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2280                 [(set (vectype VECREG:$rT),
2281                       (SPUshlquad_l_bits (vectype VECREG:$rA), (i32 bitshift:$val)))]>;
2282
2283 multiclass ShiftLeftQuadByBitsImm
2284 {
2285   def v16i8 : SHLQBIIVecInst<v16i8>;
2286   def v8i16 : SHLQBIIVecInst<v8i16>;
2287   def v4i32 : SHLQBIIVecInst<v4i32>;
2288   def v4f32 : SHLQBIIVecInst<v4f32>;
2289   def v2i64 : SHLQBIIVecInst<v2i64>;
2290   def v2f64 : SHLQBIIVecInst<v2f64>;
2291 }
2292
2293 defm SHLQBII : ShiftLeftQuadByBitsImm;
2294
2295 // SHLQBY, SHLQBYI vector forms: Shift the entire vector to the left by bytes,
2296 // not by bits. See notes above on SHLQBI.
2297
2298 class SHLQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2299     RI7Form<0b11111011100, OOL, IOL, "shlqby\t$rT, $rA, $rB",
2300             RotateShift, pattern>;
2301
2302 class SHLQBYVecInst<ValueType vectype>:
2303     SHLQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2304                [(set (vectype VECREG:$rT),
2305                      (SPUshlquad_l_bytes (vectype VECREG:$rA), R32C:$rB))]>;
2306
2307 multiclass ShiftLeftQuadBytes
2308 {
2309   def v16i8: SHLQBYVecInst<v16i8>;
2310   def v8i16: SHLQBYVecInst<v8i16>;
2311   def v4i32: SHLQBYVecInst<v4i32>;
2312   def v4f32: SHLQBYVecInst<v4f32>;
2313   def v2i64: SHLQBYVecInst<v2i64>;
2314   def v2f64: SHLQBYVecInst<v2f64>;
2315   def r128: SHLQBYInst<(outs GPRC:$rT), (ins GPRC:$rA, R32C:$rB),
2316                        [(set GPRC:$rT, (SPUshlquad_l_bytes GPRC:$rA, R32C:$rB))]>;
2317 }
2318
2319 defm SHLQBY: ShiftLeftQuadBytes;
2320
2321 class SHLQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2322     RI7Form<0b11111111100, OOL, IOL, "shlqbyi\t$rT, $rA, $val",
2323             RotateShift, pattern>;
2324
2325 class SHLQBYIVecInst<ValueType vectype>:
2326     SHLQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm_i32:$val),
2327                 [(set (vectype VECREG:$rT),
2328                       (SPUshlquad_l_bytes (vectype VECREG:$rA), (i32 uimm7:$val)))]>;
2329
2330 multiclass ShiftLeftQuadBytesImm
2331 {
2332   def v16i8: SHLQBYIVecInst<v16i8>;
2333   def v8i16: SHLQBYIVecInst<v8i16>;
2334   def v4i32: SHLQBYIVecInst<v4i32>;
2335   def v4f32: SHLQBYIVecInst<v4f32>;
2336   def v2i64: SHLQBYIVecInst<v2i64>;
2337   def v2f64: SHLQBYIVecInst<v2f64>;
2338   def r128:  SHLQBYIInst<(outs GPRC:$rT), (ins GPRC:$rA, u7imm_i32:$val),
2339                          [(set GPRC:$rT,
2340                                (SPUshlquad_l_bytes GPRC:$rA, (i32 uimm7:$val)))]>;
2341 }
2342
2343 defm SHLQBYI : ShiftLeftQuadBytesImm;
2344
2345 class SHLQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2346     RRForm<0b00111001111, OOL, IOL, "shlqbybi\t$rT, $rA, $rB",
2347            RotateShift, pattern>;
2348
2349 class SHLQBYBIVecInst<ValueType vectype>:
2350     SHLQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2351                 [/* no pattern */]>;
2352
2353 class SHLQBYBIRegInst<RegisterClass rclass>:
2354     SHLQBYBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2355                  [/* no pattern */]>;
2356
2357 multiclass ShiftLeftQuadBytesBitCount
2358 {
2359   def v16i8: SHLQBYBIVecInst<v16i8>;
2360   def v8i16: SHLQBYBIVecInst<v8i16>;
2361   def v4i32: SHLQBYBIVecInst<v4i32>;
2362   def v4f32: SHLQBYBIVecInst<v4f32>;
2363   def v2i64: SHLQBYBIVecInst<v2i64>;
2364   def v2f64: SHLQBYBIVecInst<v2f64>;
2365
2366   def r128:  SHLQBYBIRegInst<GPRC>;
2367 }
2368
2369 defm SHLQBYBI : ShiftLeftQuadBytesBitCount;
2370
2371 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2372 // Rotate halfword:
2373 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2374 class ROTHInst<dag OOL, dag IOL, list<dag> pattern>:
2375     RRForm<0b00111010000, OOL, IOL, "roth\t$rT, $rA, $rB",
2376            RotateShift, pattern>;
2377
2378 class ROTHVecInst<ValueType vectype>:
2379     ROTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
2380              [(set (vectype VECREG:$rT),
2381                    (SPUvec_rotl VECREG:$rA, VECREG:$rB))]>;
2382
2383 class ROTHRegInst<RegisterClass rclass>:
2384     ROTHInst<(outs rclass:$rT), (ins rclass:$rA, rclass:$rB),
2385              [(set rclass:$rT, (rotl rclass:$rA, rclass:$rB))]>;
2386
2387 multiclass RotateLeftHalfword
2388 {
2389   def v8i16: ROTHVecInst<v8i16>;
2390   def r16: ROTHRegInst<R16C>;
2391 }
2392
2393 defm ROTH: RotateLeftHalfword;
2394
2395 def ROTHr16_r32: ROTHInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2396                           [(set R16C:$rT, (rotl R16C:$rA, R32C:$rB))]>;
2397
2398 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2399 // Rotate halfword, immediate:
2400 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2401 class ROTHIInst<dag OOL, dag IOL, list<dag> pattern>:
2402     RI7Form<0b00111110000, OOL, IOL, "rothi\t$rT, $rA, $val",
2403             RotateShift, pattern>;
2404
2405 class ROTHIVecInst<ValueType vectype>:
2406     ROTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2407               [(set (vectype VECREG:$rT),
2408                     (SPUvec_rotl VECREG:$rA, (i16 uimm7:$val)))]>;
2409
2410 multiclass RotateLeftHalfwordImm
2411 {
2412   def v8i16: ROTHIVecInst<v8i16>;
2413   def r16: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm:$val),
2414                      [(set R16C:$rT, (rotl R16C:$rA, (i16 uimm7:$val)))]>;
2415   def r16_r32: ROTHIInst<(outs R16C:$rT), (ins R16C:$rA, u7imm_i32:$val),
2416                          [(set R16C:$rT, (rotl R16C:$rA, (i32 uimm7:$val)))]>;
2417 }
2418
2419 defm ROTHI: RotateLeftHalfwordImm;
2420
2421 def : Pat<(SPUvec_rotl VECREG:$rA, (i32 uimm7:$val)),
2422           (ROTHIv8i16 VECREG:$rA, imm:$val)>;
2423
2424 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2425 // Rotate word:
2426 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2427
2428 class ROTInst<dag OOL, dag IOL, list<dag> pattern>:
2429     RRForm<0b00011010000, OOL, IOL, "rot\t$rT, $rA, $rB",
2430            RotateShift, pattern>;
2431
2432 class ROTVecInst<ValueType vectype>:
2433     ROTInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2434             [(set (vectype VECREG:$rT),
2435                   (SPUvec_rotl (vectype VECREG:$rA), R32C:$rB))]>;
2436
2437 class ROTRegInst<RegisterClass rclass>:
2438     ROTInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2439             [(set rclass:$rT,
2440                   (rotl rclass:$rA, R32C:$rB))]>;
2441
2442 multiclass RotateLeftWord
2443 {
2444   def v4i32: ROTVecInst<v4i32>;
2445   def r32:   ROTRegInst<R32C>;
2446 }
2447
2448 defm ROT: RotateLeftWord;
2449
2450 // The rotate amount is in the same bits whether we've got an 8-bit, 16-bit or
2451 // 32-bit register
2452 def ROTr32_r16_anyext:
2453     ROTInst<(outs R32C:$rT), (ins R32C:$rA, R16C:$rB),
2454             [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R16C:$rB))))]>;
2455
2456 def : Pat<(rotl R32C:$rA, (i32 (zext R16C:$rB))),
2457           (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2458
2459 def : Pat<(rotl R32C:$rA, (i32 (sext R16C:$rB))),
2460           (ROTr32_r16_anyext R32C:$rA, R16C:$rB)>;
2461
2462 def ROTr32_r8_anyext:
2463     ROTInst<(outs R32C:$rT), (ins R32C:$rA, R8C:$rB),
2464             [(set R32C:$rT, (rotl R32C:$rA, (i32 (anyext R8C:$rB))))]>;
2465
2466 def : Pat<(rotl R32C:$rA, (i32 (zext R8C:$rB))),
2467           (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2468
2469 def : Pat<(rotl R32C:$rA, (i32 (sext R8C:$rB))),
2470           (ROTr32_r8_anyext R32C:$rA, R8C:$rB)>;
2471
2472 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2473 // Rotate word, immediate
2474 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2475
2476 class ROTIInst<dag OOL, dag IOL, list<dag> pattern>:
2477     RI7Form<0b00011110000, OOL, IOL, "roti\t$rT, $rA, $val",
2478             RotateShift, pattern>;
2479
2480 class ROTIVecInst<ValueType vectype, Operand optype, ValueType inttype, PatLeaf pred>:
2481     ROTIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2482              [(set (vectype VECREG:$rT),
2483                    (SPUvec_rotl (vectype VECREG:$rA), (inttype pred:$val)))]>;
2484
2485 class ROTIRegInst<RegisterClass rclass, Operand optype, ValueType inttype, PatLeaf pred>:
2486     ROTIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2487              [(set rclass:$rT, (rotl rclass:$rA, (inttype pred:$val)))]>;
2488
2489 multiclass RotateLeftWordImm
2490 {
2491   def v4i32: ROTIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2492   def v4i32_i16: ROTIVecInst<v4i32, u7imm, i16, uimm7>;
2493   def v4i32_i8:  ROTIVecInst<v4i32, u7imm_i8, i8, uimm7>;
2494
2495   def r32:       ROTIRegInst<R32C, u7imm_i32, i32, uimm7>;
2496   def r32_i16:   ROTIRegInst<R32C, u7imm, i16, uimm7>;
2497   def r32_i8:    ROTIRegInst<R32C, u7imm_i8, i8, uimm7>;
2498 }
2499
2500 defm ROTI : RotateLeftWordImm;
2501
2502 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2503 // Rotate quad by byte (count)
2504 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2505
2506 class ROTQBYInst<dag OOL, dag IOL, list<dag> pattern>:
2507     RRForm<0b00111011100, OOL, IOL, "rotqby\t$rT, $rA, $rB",
2508            RotateShift, pattern>;
2509
2510 class ROTQBYVecInst<ValueType vectype>:
2511     ROTQBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2512                [(set (vectype VECREG:$rT),
2513                      (SPUrotbytes_left (vectype VECREG:$rA), R32C:$rB))]>;
2514
2515 multiclass RotateQuadLeftByBytes
2516 {
2517   def v16i8: ROTQBYVecInst<v16i8>;
2518   def v8i16: ROTQBYVecInst<v8i16>;
2519   def v4i32: ROTQBYVecInst<v4i32>;
2520   def v4f32: ROTQBYVecInst<v4f32>;
2521   def v2i64: ROTQBYVecInst<v2i64>;
2522   def v2f64: ROTQBYVecInst<v2f64>;
2523 }
2524
2525 defm ROTQBY: RotateQuadLeftByBytes;
2526
2527 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2528 // Rotate quad by byte (count), immediate
2529 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2530
2531 class ROTQBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2532     RI7Form<0b00111111100, OOL, IOL, "rotqbyi\t$rT, $rA, $val",
2533             RotateShift, pattern>;
2534
2535 class ROTQBYIVecInst<ValueType vectype>:
2536     ROTQBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, u7imm:$val),
2537                 [(set (vectype VECREG:$rT),
2538                       (SPUrotbytes_left (vectype VECREG:$rA), (i16 uimm7:$val)))]>;
2539
2540 multiclass RotateQuadByBytesImm
2541 {
2542   def v16i8: ROTQBYIVecInst<v16i8>;
2543   def v8i16: ROTQBYIVecInst<v8i16>;
2544   def v4i32: ROTQBYIVecInst<v4i32>;
2545   def v4f32: ROTQBYIVecInst<v4f32>;
2546   def v2i64: ROTQBYIVecInst<v2i64>;
2547   def vfi64: ROTQBYIVecInst<v2f64>;
2548 }
2549
2550 defm ROTQBYI: RotateQuadByBytesImm;
2551
2552 // See ROTQBY note above.
2553 class ROTQBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2554     RI7Form<0b00110011100, OOL, IOL,
2555       "rotqbybi\t$rT, $rA, $shift",
2556       RotateShift, pattern>;
2557
2558 class ROTQBYBIVecInst<ValueType vectype, RegisterClass rclass>:
2559     ROTQBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, rclass:$shift),
2560       [(set (vectype VECREG:$rT),
2561             (SPUrotbytes_left_bits (vectype VECREG:$rA), rclass:$shift))]>;
2562
2563 multiclass RotateQuadByBytesByBitshift {
2564   def v16i8_r32: ROTQBYBIVecInst<v16i8, R32C>;
2565   def v8i16_r32: ROTQBYBIVecInst<v8i16, R32C>;
2566   def v4i32_r32: ROTQBYBIVecInst<v4i32, R32C>;
2567   def v2i64_r32: ROTQBYBIVecInst<v2i64, R32C>;
2568 }
2569
2570 defm ROTQBYBI : RotateQuadByBytesByBitshift;
2571
2572 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2573 // See ROTQBY note above.
2574 //
2575 // Assume that the user of this instruction knows to shift the rotate count
2576 // into bit 29
2577 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2578
2579 class ROTQBIInst<dag OOL, dag IOL, list<dag> pattern>:
2580     RRForm<0b00011011100, OOL, IOL, "rotqbi\t$rT, $rA, $rB",
2581            RotateShift, pattern>;
2582
2583 class ROTQBIVecInst<ValueType vectype>:
2584     ROTQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2585                [/* no pattern yet */]>;
2586
2587 class ROTQBIRegInst<RegisterClass rclass>:
2588     ROTQBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2589                [/* no pattern yet */]>;
2590
2591 multiclass RotateQuadByBitCount
2592 {
2593   def v16i8: ROTQBIVecInst<v16i8>;
2594   def v8i16: ROTQBIVecInst<v8i16>;
2595   def v4i32: ROTQBIVecInst<v4i32>;
2596   def v2i64: ROTQBIVecInst<v2i64>;
2597
2598   def r128:  ROTQBIRegInst<GPRC>;
2599   def r64:   ROTQBIRegInst<R64C>;
2600 }
2601
2602 defm ROTQBI: RotateQuadByBitCount;
2603
2604 class ROTQBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2605     RI7Form<0b00011111100, OOL, IOL, "rotqbii\t$rT, $rA, $val",
2606             RotateShift, pattern>;
2607
2608 class ROTQBIIVecInst<ValueType vectype, Operand optype, ValueType inttype,
2609                      PatLeaf pred>:
2610     ROTQBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, optype:$val),
2611                 [/* no pattern yet */]>;
2612
2613 class ROTQBIIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2614                      PatLeaf pred>:
2615     ROTQBIIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2616                 [/* no pattern yet */]>;
2617
2618 multiclass RotateQuadByBitCountImm
2619 {
2620   def v16i8: ROTQBIIVecInst<v16i8, u7imm_i32, i32, uimm7>;
2621   def v8i16: ROTQBIIVecInst<v8i16, u7imm_i32, i32, uimm7>;
2622   def v4i32: ROTQBIIVecInst<v4i32, u7imm_i32, i32, uimm7>;
2623   def v2i64: ROTQBIIVecInst<v2i64, u7imm_i32, i32, uimm7>;
2624
2625   def r128:  ROTQBIIRegInst<GPRC, u7imm_i32, i32, uimm7>;
2626   def r64:   ROTQBIIRegInst<R64C, u7imm_i32, i32, uimm7>;
2627 }
2628
2629 defm ROTQBII : RotateQuadByBitCountImm;
2630
2631 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2632 // ROTHM v8i16 form:
2633 // NOTE(1): No vector rotate is generated by the C/C++ frontend (today),
2634 //          so this only matches a synthetically generated/lowered code
2635 //          fragment.
2636 // NOTE(2): $rB must be negated before the right rotate!
2637 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2638
2639 class ROTHMInst<dag OOL, dag IOL, list<dag> pattern>:
2640     RRForm<0b10111010000, OOL, IOL, "rothm\t$rT, $rA, $rB",
2641            RotateShift, pattern>;
2642
2643 def ROTHMv8i16:
2644     ROTHMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2645               [/* see patterns below - $rB must be negated */]>;
2646
2647 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R32C:$rB),
2648           (ROTHMv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2649
2650 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R16C:$rB),
2651           (ROTHMv8i16 VECREG:$rA,
2652                       (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2653
2654 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), R8C:$rB),
2655           (ROTHMv8i16 VECREG:$rA,
2656                       (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
2657
2658 // ROTHM r16 form: Rotate 16-bit quantity to right, zero fill at the left
2659 // Note: This instruction doesn't match a pattern because rB must be negated
2660 // for the instruction to work. Thus, the pattern below the instruction!
2661
2662 def ROTHMr16:
2663     ROTHMInst<(outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2664               [/* see patterns below - $rB must be negated! */]>;
2665
2666 def : Pat<(srl R16C:$rA, R32C:$rB),
2667           (ROTHMr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2668
2669 def : Pat<(srl R16C:$rA, R16C:$rB),
2670           (ROTHMr16 R16C:$rA,
2671                     (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2672
2673 def : Pat<(srl R16C:$rA, R8C:$rB),
2674           (ROTHMr16 R16C:$rA,
2675                     (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB) ), 0))>;
2676
2677 // ROTHMI v8i16 form: See the comment for ROTHM v8i16. The difference here is
2678 // that the immediate can be complemented, so that the user doesn't have to
2679 // worry about it.
2680
2681 class ROTHMIInst<dag OOL, dag IOL, list<dag> pattern>:
2682     RI7Form<0b10111110000, OOL, IOL, "rothmi\t$rT, $rA, $val",
2683             RotateShift, pattern>;
2684
2685 def ROTHMIv8i16:
2686     ROTHMIInst<(outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2687                [/* no pattern */]>;
2688
2689 def : Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i32 imm:$val)),
2690           (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2691
2692 def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i16 imm:$val)),
2693          (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2694
2695 def: Pat<(SPUvec_srl (v8i16 VECREG:$rA), (i8 imm:$val)),
2696          (ROTHMIv8i16 VECREG:$rA, imm:$val)>;
2697
2698 def ROTHMIr16:
2699     ROTHMIInst<(outs R16C:$rT), (ins R16C:$rA, rothNeg7imm:$val),
2700                [/* no pattern */]>;
2701
2702 def: Pat<(srl R16C:$rA, (i32 uimm7:$val)),
2703          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2704
2705 def: Pat<(srl R16C:$rA, (i16 uimm7:$val)),
2706          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2707
2708 def: Pat<(srl R16C:$rA, (i8 uimm7:$val)),
2709          (ROTHMIr16 R16C:$rA, uimm7:$val)>;
2710
2711 // ROTM v4i32 form: See the ROTHM v8i16 comments.
2712 class ROTMInst<dag OOL, dag IOL, list<dag> pattern>:
2713     RRForm<0b10011010000, OOL, IOL, "rotm\t$rT, $rA, $rB",
2714            RotateShift, pattern>;
2715
2716 def ROTMv4i32:
2717     ROTMInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2718              [/* see patterns below - $rB must be negated */]>;
2719
2720 def : Pat<(SPUvec_srl VECREG:$rA, R32C:$rB),
2721           (ROTMv4i32 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2722
2723 def : Pat<(SPUvec_srl VECREG:$rA, R16C:$rB),
2724           (ROTMv4i32 VECREG:$rA,
2725                      (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2726
2727 def : Pat<(SPUvec_srl VECREG:$rA, R8C:$rB),
2728           (ROTMv4i32 VECREG:$rA,
2729                      (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2730
2731 def ROTMr32:
2732     ROTMInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2733              [/* see patterns below - $rB must be negated */]>;
2734
2735 def : Pat<(srl R32C:$rA, R32C:$rB),
2736           (ROTMr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
2737
2738 def : Pat<(srl R32C:$rA, R16C:$rB),
2739           (ROTMr32 R32C:$rA,
2740                    (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2741
2742 def : Pat<(srl R32C:$rA, R8C:$rB),
2743           (ROTMr32 R32C:$rA,
2744                    (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2745
2746 // ROTMI v4i32 form: See the comment for ROTHM v8i16.
2747 def ROTMIv4i32:
2748     RI7Form<0b10011110000, (outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2749       "rotmi\t$rT, $rA, $val", RotateShift,
2750       [(set (v4i32 VECREG:$rT),
2751             (SPUvec_srl VECREG:$rA, (i32 uimm7:$val)))]>;
2752
2753 def : Pat<(SPUvec_srl VECREG:$rA, (i16 uimm7:$val)),
2754           (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
2755
2756 def : Pat<(SPUvec_srl VECREG:$rA, (i8 uimm7:$val)),
2757           (ROTMIv4i32 VECREG:$rA, uimm7:$val)>;
2758
2759 // ROTMI r32 form: know how to complement the immediate value.
2760 def ROTMIr32:
2761     RI7Form<0b10011110000, (outs R32C:$rT), (ins R32C:$rA, rotNeg7imm:$val),
2762       "rotmi\t$rT, $rA, $val", RotateShift,
2763       [(set R32C:$rT, (srl R32C:$rA, (i32 uimm7:$val)))]>;
2764
2765 def : Pat<(srl R32C:$rA, (i16 imm:$val)),
2766           (ROTMIr32 R32C:$rA, uimm7:$val)>;
2767
2768 def : Pat<(srl R32C:$rA, (i8 imm:$val)),
2769           (ROTMIr32 R32C:$rA, uimm7:$val)>;
2770
2771 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2772 // ROTQMBY: This is a vector form merely so that when used in an
2773 // instruction pattern, type checking will succeed. This instruction assumes
2774 // that the user knew to negate $rB.
2775 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2776
2777 class ROTQMBYInst<dag OOL, dag IOL, list<dag> pattern>:
2778     RRForm<0b10111011100, OOL, IOL, "rotqmby\t$rT, $rA, $rB",
2779            RotateShift, pattern>;
2780
2781 class ROTQMBYVecInst<ValueType vectype>:
2782     ROTQMBYInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2783                 [/* no pattern, $rB must be negated */]>;
2784
2785 class ROTQMBYRegInst<RegisterClass rclass>:
2786     ROTQMBYInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2787                 [/* no pattern */]>;
2788
2789 multiclass RotateQuadBytes
2790 {
2791   def v16i8: ROTQMBYVecInst<v16i8>;
2792   def v8i16: ROTQMBYVecInst<v8i16>;
2793   def v4i32: ROTQMBYVecInst<v4i32>;
2794   def v2i64: ROTQMBYVecInst<v2i64>;
2795
2796   def r128: ROTQMBYRegInst<GPRC>;
2797   def r64:  ROTQMBYRegInst<R64C>;
2798 }
2799
2800 defm ROTQMBY : RotateQuadBytes;
2801
2802 class ROTQMBYIInst<dag OOL, dag IOL, list<dag> pattern>:
2803     RI7Form<0b10111111100, OOL, IOL, "rotqmbyi\t$rT, $rA, $val",
2804             RotateShift, pattern>;
2805
2806 class ROTQMBYIVecInst<ValueType vectype>:
2807     ROTQMBYIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2808                  [/* no pattern */]>;
2809
2810 class ROTQMBYIRegInst<RegisterClass rclass, Operand optype, ValueType inttype,
2811                       PatLeaf pred>:
2812     ROTQMBYIInst<(outs rclass:$rT), (ins rclass:$rA, optype:$val),
2813                  [/* no pattern */]>;
2814
2815 // 128-bit zero extension form:
2816 class ROTQMBYIZExtInst<RegisterClass rclass, Operand optype, PatLeaf pred>:
2817     ROTQMBYIInst<(outs GPRC:$rT), (ins rclass:$rA, optype:$val),
2818                  [/* no pattern */]>;
2819
2820 multiclass RotateQuadBytesImm
2821 {
2822   def v16i8: ROTQMBYIVecInst<v16i8>;
2823   def v8i16: ROTQMBYIVecInst<v8i16>;
2824   def v4i32: ROTQMBYIVecInst<v4i32>;
2825   def v2i64: ROTQMBYIVecInst<v2i64>;
2826
2827   def r128:  ROTQMBYIRegInst<GPRC, rotNeg7imm, i32, uimm7>;
2828   def r64:   ROTQMBYIRegInst<R64C, rotNeg7imm, i32, uimm7>;
2829   
2830   def r128_zext_r8:  ROTQMBYIZExtInst<R8C, rotNeg7imm, uimm7>;
2831   def r128_zext_r16: ROTQMBYIZExtInst<R16C, rotNeg7imm, uimm7>;
2832   def r128_zext_r32: ROTQMBYIZExtInst<R32C, rotNeg7imm, uimm7>;
2833   def r128_zext_r64: ROTQMBYIZExtInst<R64C, rotNeg7imm, uimm7>;
2834 }
2835
2836 defm ROTQMBYI : RotateQuadBytesImm;
2837
2838 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2839 // Rotate right and mask by bit count
2840 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2841
2842 class ROTQMBYBIInst<dag OOL, dag IOL, list<dag> pattern>:
2843     RRForm<0b10110011100, OOL, IOL, "rotqmbybi\t$rT, $rA, $rB",
2844            RotateShift, pattern>;
2845
2846 class ROTQMBYBIVecInst<ValueType vectype>:
2847     ROTQMBYBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2848                   [/* no pattern, */]>;
2849
2850 multiclass RotateMaskQuadByBitCount
2851 {
2852   def v16i8: ROTQMBYBIVecInst<v16i8>;
2853   def v8i16: ROTQMBYBIVecInst<v8i16>;
2854   def v4i32: ROTQMBYBIVecInst<v4i32>;
2855   def v2i64: ROTQMBYBIVecInst<v2i64>;
2856 }
2857
2858 defm ROTQMBYBI: RotateMaskQuadByBitCount;
2859
2860 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2861 // Rotate quad and mask by bits
2862 // Note that the rotate amount has to be negated
2863 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2864
2865 class ROTQMBIInst<dag OOL, dag IOL, list<dag> pattern>:
2866     RRForm<0b10011011100, OOL, IOL, "rotqmbi\t$rT, $rA, $rB",
2867            RotateShift, pattern>;
2868
2869 class ROTQMBIVecInst<ValueType vectype>:
2870     ROTQMBIInst<(outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2871                 [/* no pattern */]>;
2872
2873 class ROTQMBIRegInst<RegisterClass rclass>:
2874     ROTQMBIInst<(outs rclass:$rT), (ins rclass:$rA, R32C:$rB),
2875                 [/* no pattern */]>;
2876
2877 multiclass RotateMaskQuadByBits
2878 {
2879   def v16i8: ROTQMBIVecInst<v16i8>;
2880   def v8i16: ROTQMBIVecInst<v8i16>;
2881   def v4i32: ROTQMBIVecInst<v4i32>;
2882   def v2i64: ROTQMBIVecInst<v2i64>;
2883
2884   def r128:  ROTQMBIRegInst<GPRC>;
2885   def r64:   ROTQMBIRegInst<R64C>;
2886 }
2887
2888 defm ROTQMBI: RotateMaskQuadByBits;
2889
2890 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2891 // Rotate quad and mask by bits, immediate
2892 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2893
2894 class ROTQMBIIInst<dag OOL, dag IOL, list<dag> pattern>:
2895     RI7Form<0b10011111100, OOL, IOL, "rotqmbii\t$rT, $rA, $val",
2896             RotateShift, pattern>;
2897
2898 class ROTQMBIIVecInst<ValueType vectype>:
2899    ROTQMBIIInst<(outs VECREG:$rT), (ins VECREG:$rA, rotNeg7imm:$val),
2900                  [/* no pattern */]>;
2901
2902 class ROTQMBIIRegInst<RegisterClass rclass>:
2903    ROTQMBIIInst<(outs rclass:$rT), (ins rclass:$rA, rotNeg7imm:$val),
2904                  [/* no pattern */]>;
2905
2906 multiclass RotateMaskQuadByBitsImm
2907 {
2908   def v16i8: ROTQMBIIVecInst<v16i8>;
2909   def v8i16: ROTQMBIIVecInst<v8i16>;
2910   def v4i32: ROTQMBIIVecInst<v4i32>;
2911   def v2i64: ROTQMBIIVecInst<v2i64>;
2912
2913   def r128:  ROTQMBIIRegInst<GPRC>;
2914   def r64:   ROTQMBIIRegInst<R64C>;
2915 }
2916
2917 defm ROTQMBII: RotateMaskQuadByBitsImm;
2918
2919 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2920 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
2921
2922 def ROTMAHv8i16:
2923     RRForm<0b01111010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2924       "rotmah\t$rT, $rA, $rB", RotateShift,
2925       [/* see patterns below - $rB must be negated */]>;
2926
2927 def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
2928           (ROTMAHv8i16 VECREG:$rA, (SFIr32 R32C:$rB, 0))>;
2929
2930 def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
2931           (ROTMAHv8i16 VECREG:$rA,
2932                        (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2933
2934 def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
2935           (ROTMAHv8i16 VECREG:$rA,
2936                        (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2937
2938 def ROTMAHr16:
2939     RRForm<0b01111010000, (outs R16C:$rT), (ins R16C:$rA, R32C:$rB),
2940       "rotmah\t$rT, $rA, $rB", RotateShift,
2941       [/* see patterns below - $rB must be negated */]>;
2942
2943 def : Pat<(sra R16C:$rA, R32C:$rB),
2944           (ROTMAHr16 R16C:$rA, (SFIr32 R32C:$rB, 0))>;
2945
2946 def : Pat<(sra R16C:$rA, R16C:$rB),
2947           (ROTMAHr16 R16C:$rA,
2948                      (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2949
2950 def : Pat<(sra R16C:$rA, R8C:$rB),
2951           (ROTMAHr16 R16C:$rA,
2952                      (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2953
2954 def ROTMAHIv8i16:
2955     RRForm<0b01111110000, (outs VECREG:$rT), (ins VECREG:$rA, rothNeg7imm:$val),
2956       "rotmahi\t$rT, $rA, $val", RotateShift,
2957       [(set (v8i16 VECREG:$rT),
2958             (SPUvec_sra (v8i16 VECREG:$rA), (i32 uimm7:$val)))]>;
2959
2960 def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i16 uimm7:$val)),
2961           (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2962
2963 def : Pat<(SPUvec_sra (v8i16 VECREG:$rA), (i8 uimm7:$val)),
2964           (ROTMAHIv8i16 (v8i16 VECREG:$rA), (i32 uimm7:$val))>;
2965
2966 def ROTMAHIr16:
2967     RRForm<0b01111110000, (outs R16C:$rT), (ins R16C:$rA, rothNeg7imm_i16:$val),
2968       "rotmahi\t$rT, $rA, $val", RotateShift,
2969       [(set R16C:$rT, (sra R16C:$rA, (i16 uimm7:$val)))]>;
2970
2971 def : Pat<(sra R16C:$rA, (i32 imm:$val)),
2972           (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2973
2974 def : Pat<(sra R16C:$rA, (i8 imm:$val)),
2975           (ROTMAHIr16 R16C:$rA, uimm7:$val)>;
2976
2977 def ROTMAv4i32:
2978     RRForm<0b01011010000, (outs VECREG:$rT), (ins VECREG:$rA, R32C:$rB),
2979       "rotma\t$rT, $rA, $rB", RotateShift,
2980       [/* see patterns below - $rB must be negated */]>;
2981
2982 def : Pat<(SPUvec_sra VECREG:$rA, R32C:$rB),
2983           (ROTMAv4i32 (v4i32 VECREG:$rA), (SFIr32 R32C:$rB, 0))>;
2984
2985 def : Pat<(SPUvec_sra VECREG:$rA, R16C:$rB),
2986           (ROTMAv4i32 (v4i32 VECREG:$rA),
2987                       (SFIr32 (XSHWr16 R16C:$rB), 0))>;
2988
2989 def : Pat<(SPUvec_sra VECREG:$rA, R8C:$rB),
2990           (ROTMAv4i32 (v4i32 VECREG:$rA),
2991                       (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
2992
2993 def ROTMAr32:
2994     RRForm<0b01011010000, (outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
2995       "rotma\t$rT, $rA, $rB", RotateShift,
2996       [/* see patterns below - $rB must be negated */]>;
2997
2998 def : Pat<(sra R32C:$rA, R32C:$rB),
2999           (ROTMAr32 R32C:$rA, (SFIr32 R32C:$rB, 0))>;
3000
3001 def : Pat<(sra R32C:$rA, R16C:$rB),
3002           (ROTMAr32 R32C:$rA,
3003                     (SFIr32 (XSHWr16 R16C:$rB), 0))>;
3004
3005 def : Pat<(sra R32C:$rA, R8C:$rB),
3006           (ROTMAr32 R32C:$rA,
3007                     (SFIr32 (XSHWr16 (XSBHr8 R8C:$rB)), 0))>;
3008
3009 class ROTMAIInst<dag OOL, dag IOL, list<dag> pattern>:
3010     RRForm<0b01011110000, OOL, IOL,
3011       "rotmai\t$rT, $rA, $val",
3012       RotateShift, pattern>;
3013
3014 class ROTMAIVecInst<ValueType vectype, Operand intop, ValueType inttype>:
3015     ROTMAIInst<(outs VECREG:$rT), (ins VECREG:$rA, intop:$val),
3016       [(set (vectype VECREG:$rT),
3017             (SPUvec_sra VECREG:$rA, (inttype uimm7:$val)))]>;
3018
3019 class ROTMAIRegInst<RegisterClass rclass, Operand intop, ValueType inttype>:
3020     ROTMAIInst<(outs rclass:$rT), (ins rclass:$rA, intop:$val),
3021       [(set rclass:$rT, (sra rclass:$rA, (inttype uimm7:$val)))]>;
3022
3023 multiclass RotateMaskAlgebraicImm {
3024   def v2i64_i32 : ROTMAIVecInst<v2i64, rotNeg7imm, i32>;
3025   def v4i32_i32 : ROTMAIVecInst<v4i32, rotNeg7imm, i32>;
3026   def r64_i32 : ROTMAIRegInst<R64C, rotNeg7imm, i32>;
3027   def r32_i32 : ROTMAIRegInst<R32C, rotNeg7imm, i32>;
3028 }
3029
3030 defm ROTMAI : RotateMaskAlgebraicImm;
3031
3032 //===----------------------------------------------------------------------===//
3033 // Branch and conditionals:
3034 //===----------------------------------------------------------------------===//
3035
3036 let isTerminator = 1, isBarrier = 1 in {
3037   // Halt If Equal (r32 preferred slot only, no vector form)
3038   def HEQr32:
3039     RRForm_3<0b00011011110, (outs), (ins R32C:$rA, R32C:$rB),
3040       "heq\t$rA, $rB", BranchResolv,
3041       [/* no pattern to match */]>;
3042
3043   def HEQIr32 :
3044     RI10Form_2<0b11111110, (outs), (ins R32C:$rA, s10imm:$val),
3045       "heqi\t$rA, $val", BranchResolv,
3046       [/* no pattern to match */]>;
3047
3048   // HGT/HGTI: These instructions use signed arithmetic for the comparison,
3049   // contrasting with HLGT/HLGTI, which use unsigned comparison:
3050   def HGTr32:
3051     RRForm_3<0b00011010010, (outs), (ins R32C:$rA, R32C:$rB),
3052       "hgt\t$rA, $rB", BranchResolv,
3053       [/* no pattern to match */]>;
3054
3055   def HGTIr32:
3056     RI10Form_2<0b11110010, (outs), (ins R32C:$rA, s10imm:$val),
3057       "hgti\t$rA, $val", BranchResolv,
3058       [/* no pattern to match */]>;
3059
3060   def HLGTr32:
3061     RRForm_3<0b00011011010, (outs), (ins R32C:$rA, R32C:$rB),
3062       "hlgt\t$rA, $rB", BranchResolv,
3063       [/* no pattern to match */]>;
3064
3065   def HLGTIr32:
3066     RI10Form_2<0b11111010, (outs), (ins R32C:$rA, s10imm:$val),
3067       "hlgti\t$rA, $val", BranchResolv,
3068       [/* no pattern to match */]>;
3069 }
3070
3071 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3072 // Comparison operators for i8, i16 and i32:
3073 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3074
3075 class CEQBInst<dag OOL, dag IOL, list<dag> pattern> :
3076   RRForm<0b00001011110, OOL, IOL, "ceqb\t$rT, $rA, $rB",
3077          ByteOp, pattern>;
3078
3079 multiclass CmpEqualByte
3080 {
3081   def v16i8 :
3082     CEQBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3083       [(set (v16i8 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3084                                        (v8i16 VECREG:$rB)))]>;
3085
3086   def r8 :
3087     CEQBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3088              [(set R8C:$rT, (seteq R8C:$rA, R8C:$rB))]>;
3089 }
3090
3091 class CEQBIInst<dag OOL, dag IOL, list<dag> pattern> :
3092   RI10Form<0b01111110, OOL, IOL, "ceqbi\t$rT, $rA, $val",
3093            ByteOp, pattern>;
3094
3095 multiclass CmpEqualByteImm
3096 {
3097   def v16i8 :
3098     CEQBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3099               [(set (v16i8 VECREG:$rT), (seteq (v16i8 VECREG:$rA),
3100                                                v16i8SExt8Imm:$val))]>;
3101   def r8:
3102     CEQBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3103              [(set R8C:$rT, (seteq R8C:$rA, immSExt8:$val))]>;
3104 }
3105
3106 class CEQHInst<dag OOL, dag IOL, list<dag> pattern> :
3107   RRForm<0b00010011110, OOL, IOL, "ceqh\t$rT, $rA, $rB",
3108          ByteOp, pattern>;
3109
3110 multiclass CmpEqualHalfword
3111 {
3112   def v8i16 : CEQHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3113                        [(set (v8i16 VECREG:$rT), (seteq (v8i16 VECREG:$rA),
3114                                                         (v8i16 VECREG:$rB)))]>;
3115
3116   def r16 : CEQHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3117                      [(set R16C:$rT, (seteq R16C:$rA, R16C:$rB))]>;
3118 }
3119
3120 class CEQHIInst<dag OOL, dag IOL, list<dag> pattern> :
3121   RI10Form<0b10111110, OOL, IOL, "ceqhi\t$rT, $rA, $val",
3122            ByteOp, pattern>;
3123
3124 multiclass CmpEqualHalfwordImm
3125 {
3126   def v8i16 : CEQHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3127                         [(set (v8i16 VECREG:$rT),
3128                               (seteq (v8i16 VECREG:$rA),
3129                                      (v8i16 v8i16SExt10Imm:$val)))]>;
3130   def r16 : CEQHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3131                       [(set R16C:$rT, (seteq R16C:$rA, i16ImmSExt10:$val))]>;
3132 }
3133
3134 class CEQInst<dag OOL, dag IOL, list<dag> pattern> :
3135   RRForm<0b00000011110, OOL, IOL, "ceq\t$rT, $rA, $rB",
3136          ByteOp, pattern>;
3137
3138 multiclass CmpEqualWord
3139 {
3140   def v4i32 : CEQInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3141                       [(set (v4i32 VECREG:$rT),
3142                             (seteq (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3143
3144   def r32 : CEQInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3145                     [(set R32C:$rT, (seteq R32C:$rA, R32C:$rB))]>;
3146 }
3147
3148 class CEQIInst<dag OOL, dag IOL, list<dag> pattern> :
3149   RI10Form<0b00111110, OOL, IOL, "ceqi\t$rT, $rA, $val",
3150            ByteOp, pattern>;
3151
3152 multiclass CmpEqualWordImm
3153 {
3154   def v4i32 : CEQIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3155                        [(set (v4i32 VECREG:$rT),
3156                              (seteq (v4i32 VECREG:$rA),
3157                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3158
3159   def r32: CEQIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3160                     [(set R32C:$rT, (seteq R32C:$rA, i32ImmSExt10:$val))]>;
3161 }
3162
3163 class CGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3164   RRForm<0b00001010010, OOL, IOL, "cgtb\t$rT, $rA, $rB",
3165          ByteOp, pattern>;
3166
3167 multiclass CmpGtrByte
3168 {
3169   def v16i8 :
3170     CGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3171       [(set (v16i8 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3172                                        (v8i16 VECREG:$rB)))]>;
3173
3174   def r8 :
3175     CGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3176              [(set R8C:$rT, (setgt R8C:$rA, R8C:$rB))]>;
3177 }
3178
3179 class CGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3180   RI10Form<0b01110010, OOL, IOL, "cgtbi\t$rT, $rA, $val",
3181            ByteOp, pattern>;
3182
3183 multiclass CmpGtrByteImm
3184 {
3185   def v16i8 :
3186     CGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3187               [(set (v16i8 VECREG:$rT), (setgt (v16i8 VECREG:$rA),
3188                                                v16i8SExt8Imm:$val))]>;
3189   def r8:
3190     CGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3191               [(set R8C:$rT, (setgt R8C:$rA, immSExt8:$val))]>;
3192 }
3193
3194 class CGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3195   RRForm<0b00010010010, OOL, IOL, "cgth\t$rT, $rA, $rB",
3196          ByteOp, pattern>;
3197
3198 multiclass CmpGtrHalfword
3199 {
3200   def v8i16 : CGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3201                        [(set (v8i16 VECREG:$rT), (setgt (v8i16 VECREG:$rA),
3202                                                         (v8i16 VECREG:$rB)))]>;
3203
3204   def r16 : CGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3205                      [(set R16C:$rT, (setgt R16C:$rA, R16C:$rB))]>;
3206 }
3207
3208 class CGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3209   RI10Form<0b10110010, OOL, IOL, "cgthi\t$rT, $rA, $val",
3210            ByteOp, pattern>;
3211
3212 multiclass CmpGtrHalfwordImm
3213 {
3214   def v8i16 : CGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3215                         [(set (v8i16 VECREG:$rT),
3216                               (setgt (v8i16 VECREG:$rA),
3217                                      (v8i16 v8i16SExt10Imm:$val)))]>;
3218   def r16 : CGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3219                       [(set R16C:$rT, (setgt R16C:$rA, i16ImmSExt10:$val))]>;
3220 }
3221
3222 class CGTInst<dag OOL, dag IOL, list<dag> pattern> :
3223   RRForm<0b00000010010, OOL, IOL, "cgt\t$rT, $rA, $rB",
3224          ByteOp, pattern>;
3225
3226 multiclass CmpGtrWord
3227 {
3228   def v4i32 : CGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3229                       [(set (v4i32 VECREG:$rT),
3230                             (setgt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3231
3232   def r32 : CGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3233                     [(set R32C:$rT, (setgt R32C:$rA, R32C:$rB))]>;
3234 }
3235
3236 class CGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3237   RI10Form<0b00110010, OOL, IOL, "cgti\t$rT, $rA, $val",
3238            ByteOp, pattern>;
3239
3240 multiclass CmpGtrWordImm
3241 {
3242   def v4i32 : CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3243                        [(set (v4i32 VECREG:$rT),
3244                              (setgt (v4i32 VECREG:$rA),
3245                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3246
3247   def r32: CGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3248                     [(set R32C:$rT, (setgt R32C:$rA, i32ImmSExt10:$val))]>;
3249
3250   // CGTIv4f32, CGTIf32: These are used in the f32 fdiv instruction sequence:
3251   def v4f32: CGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3252                        [(set (v4i32 VECREG:$rT),
3253                              (setgt (v4i32 (bitconvert (v4f32 VECREG:$rA))),
3254                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3255
3256   def f32:   CGTIInst<(outs R32C:$rT), (ins R32FP:$rA, s10imm_i32:$val),
3257                       [/* no pattern */]>;
3258 }
3259
3260 class CLGTBInst<dag OOL, dag IOL, list<dag> pattern> :
3261   RRForm<0b00001011010, OOL, IOL, "clgtb\t$rT, $rA, $rB",
3262          ByteOp, pattern>;
3263
3264 multiclass CmpLGtrByte
3265 {
3266   def v16i8 :
3267     CLGTBInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3268       [(set (v16i8 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3269                                        (v8i16 VECREG:$rB)))]>;
3270
3271   def r8 :
3272     CLGTBInst<(outs R8C:$rT), (ins R8C:$rA, R8C:$rB),
3273              [(set R8C:$rT, (setugt R8C:$rA, R8C:$rB))]>;
3274 }
3275
3276 class CLGTBIInst<dag OOL, dag IOL, list<dag> pattern> :
3277   RI10Form<0b01111010, OOL, IOL, "clgtbi\t$rT, $rA, $val",
3278            ByteOp, pattern>;
3279
3280 multiclass CmpLGtrByteImm
3281 {
3282   def v16i8 :
3283     CLGTBIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm_i8:$val),
3284               [(set (v16i8 VECREG:$rT), (setugt (v16i8 VECREG:$rA),
3285                                                v16i8SExt8Imm:$val))]>;
3286   def r8:
3287     CLGTBIInst<(outs R8C:$rT), (ins R8C:$rA, s10imm_i8:$val),
3288              [(set R8C:$rT, (setugt R8C:$rA, immSExt8:$val))]>;
3289 }
3290
3291 class CLGTHInst<dag OOL, dag IOL, list<dag> pattern> :
3292   RRForm<0b00010011010, OOL, IOL, "clgth\t$rT, $rA, $rB",
3293          ByteOp, pattern>;
3294
3295 multiclass CmpLGtrHalfword
3296 {
3297   def v8i16 : CLGTHInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3298                        [(set (v8i16 VECREG:$rT), (setugt (v8i16 VECREG:$rA),
3299                                                         (v8i16 VECREG:$rB)))]>;
3300
3301   def r16 : CLGTHInst<(outs R16C:$rT), (ins R16C:$rA, R16C:$rB),
3302                      [(set R16C:$rT, (setugt R16C:$rA, R16C:$rB))]>;
3303 }
3304
3305 class CLGTHIInst<dag OOL, dag IOL, list<dag> pattern> :
3306   RI10Form<0b10111010, OOL, IOL, "clgthi\t$rT, $rA, $val",
3307            ByteOp, pattern>;
3308
3309 multiclass CmpLGtrHalfwordImm
3310 {
3311   def v8i16 : CLGTHIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3312                          [(set (v8i16 VECREG:$rT),
3313                                (setugt (v8i16 VECREG:$rA),
3314                                        (v8i16 v8i16SExt10Imm:$val)))]>;
3315   def r16 : CLGTHIInst<(outs R16C:$rT), (ins R16C:$rA, s10imm:$val),
3316                        [(set R16C:$rT, (setugt R16C:$rA, i16ImmSExt10:$val))]>;
3317 }
3318
3319 class CLGTInst<dag OOL, dag IOL, list<dag> pattern> :
3320   RRForm<0b00000011010, OOL, IOL, "clgt\t$rT, $rA, $rB",
3321          ByteOp, pattern>;
3322
3323 multiclass CmpLGtrWord
3324 {
3325   def v4i32 : CLGTInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3326                       [(set (v4i32 VECREG:$rT),
3327                             (setugt (v4i32 VECREG:$rA), (v4i32 VECREG:$rB)))]>;
3328
3329   def r32 : CLGTInst<(outs R32C:$rT), (ins R32C:$rA, R32C:$rB),
3330                      [(set R32C:$rT, (setugt R32C:$rA, R32C:$rB))]>;
3331 }
3332
3333 class CLGTIInst<dag OOL, dag IOL, list<dag> pattern> :
3334   RI10Form<0b00111010, OOL, IOL, "clgti\t$rT, $rA, $val",
3335            ByteOp, pattern>;
3336
3337 multiclass CmpLGtrWordImm
3338 {
3339   def v4i32 : CLGTIInst<(outs VECREG:$rT), (ins VECREG:$rA, s10imm:$val),
3340                        [(set (v4i32 VECREG:$rT),
3341                              (setugt (v4i32 VECREG:$rA),
3342                                     (v4i32 v4i32SExt16Imm:$val)))]>;
3343
3344   def r32: CLGTIInst<(outs R32C:$rT), (ins R32C:$rA, s10imm_i32:$val),
3345                      [(set R32C:$rT, (setugt R32C:$rA, i32ImmSExt10:$val))]>;
3346 }
3347
3348 defm CEQB   : CmpEqualByte;
3349 defm CEQBI  : CmpEqualByteImm;
3350 defm CEQH   : CmpEqualHalfword;
3351 defm CEQHI  : CmpEqualHalfwordImm;
3352 defm CEQ    : CmpEqualWord;
3353 defm CEQI   : CmpEqualWordImm;
3354 defm CGTB   : CmpGtrByte;
3355 defm CGTBI  : CmpGtrByteImm;
3356 defm CGTH   : CmpGtrHalfword;
3357 defm CGTHI  : CmpGtrHalfwordImm;
3358 defm CGT    : CmpGtrWord;
3359 defm CGTI   : CmpGtrWordImm;
3360 defm CLGTB  : CmpLGtrByte;
3361 defm CLGTBI : CmpLGtrByteImm;
3362 defm CLGTH  : CmpLGtrHalfword;
3363 defm CLGTHI : CmpLGtrHalfwordImm;
3364 defm CLGT   : CmpLGtrWord;
3365 defm CLGTI  : CmpLGtrWordImm;
3366
3367 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3368 // For SETCC primitives not supported above (setlt, setle, setge, etc.)
3369 // define a pattern to generate the right code, as a binary operator
3370 // (in a manner of speaking.)
3371 //
3372 // Notes:
3373 // 1. This only matches the setcc set of conditionals. Special pattern
3374 //    matching is used for select conditionals.
3375 //
3376 // 2. The "DAG" versions of these classes is almost exclusively used for
3377 //    i64 comparisons. See the tblgen fundamentals documentation for what
3378 //    ".ResultInstrs[0]" means; see TargetSelectionDAG.td and the Pattern
3379 //    class for where ResultInstrs originates.
3380 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3381
3382 class SETCCNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3383                       SPUInstr xorinst, SPUInstr cmpare>:
3384   Pat<(cond rclass:$rA, rclass:$rB),
3385       (xorinst (cmpare rclass:$rA, rclass:$rB), (inttype -1))>;
3386
3387 class SETCCNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3388                       PatLeaf immpred, SPUInstr xorinst, SPUInstr cmpare>:
3389   Pat<(cond rclass:$rA, (inttype immpred:$imm)),
3390       (xorinst (cmpare rclass:$rA, (inttype immpred:$imm)), (inttype -1))>;
3391
3392 def : SETCCNegCondReg<setne, R8C, i8, XORBIr8,  CEQBr8>;
3393 def : SETCCNegCondImm<setne, R8C, i8, immSExt8, XORBIr8, CEQBIr8>;
3394
3395 def : SETCCNegCondReg<setne, R16C, i16, XORHIr16,     CEQHr16>;
3396 def : SETCCNegCondImm<setne, R16C, i16, i16ImmSExt10, XORHIr16, CEQHIr16>;
3397
3398 def : SETCCNegCondReg<setne, R32C, i32, XORIr32, CEQr32>;
3399 def : SETCCNegCondImm<setne, R32C, i32, i32ImmSExt10, XORIr32, CEQIr32>;
3400
3401 class SETCCBinOpReg<PatFrag cond, RegisterClass rclass,
3402                     SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3403     Pat<(cond rclass:$rA, rclass:$rB),
3404         (binop (cmpOp1 rclass:$rA, rclass:$rB),
3405                (cmpOp2 rclass:$rA, rclass:$rB))>;
3406
3407 class SETCCBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3408                     ValueType immtype,
3409                     SPUInstr binop, SPUInstr cmpOp1, SPUInstr cmpOp2>:
3410     Pat<(cond rclass:$rA, (immtype immpred:$imm)),
3411         (binop (cmpOp1 rclass:$rA, (immtype immpred:$imm)),
3412                (cmpOp2 rclass:$rA, (immtype immpred:$imm)))>;
3413
3414 def : SETCCBinOpReg<setge, R8C, ORr8, CGTBr8, CEQBr8>;
3415 def : SETCCBinOpImm<setge, R8C, immSExt8, i8, ORr8, CGTBIr8, CEQBIr8>;
3416 def : SETCCBinOpReg<setlt, R8C, NORr8, CGTBr8, CEQBr8>;
3417 def : SETCCBinOpImm<setlt, R8C, immSExt8, i8, NORr8, CGTBIr8, CEQBIr8>;
3418 def : Pat<(setle R8C:$rA, R8C:$rB),
3419           (XORBIr8 (CGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3420 def :  Pat<(setle R8C:$rA, immU8:$imm),
3421            (XORBIr8 (CGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
3422
3423 def : SETCCBinOpReg<setge, R16C, ORr16, CGTHr16, CEQHr16>;
3424 def : SETCCBinOpImm<setge, R16C, i16ImmSExt10, i16,
3425                     ORr16, CGTHIr16, CEQHIr16>;
3426 def : SETCCBinOpReg<setlt, R16C, NORr16, CGTHr16, CEQHr16>;
3427 def : SETCCBinOpImm<setlt, R16C, i16ImmSExt10, i16, NORr16, CGTHIr16, CEQHIr16>;
3428 def : Pat<(setle R16C:$rA, R16C:$rB),
3429           (XORHIr16 (CGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3430 def : Pat<(setle R16C:$rA, i16ImmSExt10:$imm),
3431           (XORHIr16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
3432
3433 def : SETCCBinOpReg<setge, R32C, ORr32, CGTr32, CEQr32>;
3434 def : SETCCBinOpImm<setge, R32C, i32ImmSExt10, i32,
3435                     ORr32, CGTIr32, CEQIr32>;
3436 def : SETCCBinOpReg<setlt, R32C, NORr32, CGTr32, CEQr32>;
3437 def : SETCCBinOpImm<setlt, R32C, i32ImmSExt10, i32, NORr32, CGTIr32, CEQIr32>;
3438 def : Pat<(setle R32C:$rA, R32C:$rB),
3439           (XORIr32 (CGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3440 def : Pat<(setle R32C:$rA, i32ImmSExt10:$imm),
3441           (XORIr32 (CGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
3442
3443 def : SETCCBinOpReg<setuge, R8C, ORr8, CLGTBr8, CEQBr8>;
3444 def : SETCCBinOpImm<setuge, R8C, immSExt8, i8, ORr8, CLGTBIr8, CEQBIr8>;
3445 def : SETCCBinOpReg<setult, R8C, NORr8, CLGTBr8, CEQBr8>;
3446 def : SETCCBinOpImm<setult, R8C, immSExt8, i8, NORr8, CLGTBIr8, CEQBIr8>;
3447 def : Pat<(setule R8C:$rA, R8C:$rB),
3448           (XORBIr8 (CLGTBr8 R8C:$rA, R8C:$rB), 0xff)>;
3449 def :  Pat<(setule R8C:$rA, immU8:$imm),
3450            (XORBIr8 (CLGTBIr8 R8C:$rA, immU8:$imm), 0xff)>;
3451
3452 def : SETCCBinOpReg<setuge, R16C, ORr16, CLGTHr16, CEQHr16>;
3453 def : SETCCBinOpImm<setuge, R16C, i16ImmSExt10, i16,
3454                     ORr16, CLGTHIr16, CEQHIr16>;
3455 def : SETCCBinOpReg<setult, R16C, NORr16, CLGTHr16, CEQHr16>;
3456 def : SETCCBinOpImm<setult, R16C, i16ImmSExt10, i16, NORr16,
3457                     CLGTHIr16, CEQHIr16>;
3458 def : Pat<(setule R16C:$rA, R16C:$rB),
3459           (XORHIr16 (CLGTHr16 R16C:$rA, R16C:$rB), 0xffff)>;
3460 def :  Pat<(setule R16C:$rA, i16ImmSExt10:$imm),
3461            (XORHIr16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$imm), 0xffff)>;
3462
3463 def : SETCCBinOpReg<setuge, R32C, ORr32, CLGTr32, CEQr32>;
3464 def : SETCCBinOpImm<setuge, R32C, i32ImmSExt10, i32,
3465                     ORr32, CLGTIr32, CEQIr32>;
3466 def : SETCCBinOpReg<setult, R32C, NORr32, CLGTr32, CEQr32>;
3467 def : SETCCBinOpImm<setult, R32C, i32ImmSExt10, i32, NORr32, CLGTIr32, CEQIr32>;
3468 def : Pat<(setule R32C:$rA, R32C:$rB),
3469           (XORIr32 (CLGTr32 R32C:$rA, R32C:$rB), 0xffffffff)>;
3470 def : Pat<(setule R32C:$rA, i32ImmSExt10:$imm),
3471           (XORIr32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$imm), 0xffffffff)>;
3472
3473 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3474 // select conditional patterns:
3475 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3476
3477 class SELECTNegCondReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3478                        SPUInstr selinstr, SPUInstr cmpare>:
3479   Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3480               rclass:$rTrue, rclass:$rFalse),
3481       (selinstr rclass:$rTrue, rclass:$rFalse,
3482                 (cmpare rclass:$rA, rclass:$rB))>;
3483
3484 class SELECTNegCondImm<PatFrag cond, RegisterClass rclass, ValueType inttype,
3485                        PatLeaf immpred, SPUInstr selinstr, SPUInstr cmpare>:
3486   Pat<(select (inttype (cond rclass:$rA, immpred:$imm)),
3487               rclass:$rTrue, rclass:$rFalse),
3488       (selinstr rclass:$rTrue, rclass:$rFalse,
3489                 (cmpare rclass:$rA, immpred:$imm))>;
3490
3491 def : SELECTNegCondReg<setne, R8C, i8, SELBr8, CEQBr8>;
3492 def : SELECTNegCondImm<setne, R8C, i8, immSExt8, SELBr8, CEQBIr8>;
3493 def : SELECTNegCondReg<setle, R8C, i8, SELBr8, CGTBr8>;
3494 def : SELECTNegCondImm<setle, R8C, i8, immSExt8, SELBr8, CGTBr8>;
3495 def : SELECTNegCondReg<setule, R8C, i8, SELBr8, CLGTBr8>;
3496 def : SELECTNegCondImm<setule, R8C, i8, immU8, SELBr8, CLGTBIr8>;
3497
3498 def : SELECTNegCondReg<setne, R16C, i16, SELBr16, CEQHr16>;
3499 def : SELECTNegCondImm<setne, R16C, i16, i16ImmSExt10, SELBr16, CEQHIr16>;
3500 def : SELECTNegCondReg<setle, R16C, i16, SELBr16, CGTHr16>;
3501 def : SELECTNegCondImm<setle, R16C, i16, i16ImmSExt10, SELBr16, CGTHIr16>;
3502 def : SELECTNegCondReg<setule, R16C, i16, SELBr16, CLGTHr16>;
3503 def : SELECTNegCondImm<setule, R16C, i16, i16ImmSExt10, SELBr16, CLGTHIr16>;
3504
3505 def : SELECTNegCondReg<setne, R32C, i32, SELBr32, CEQr32>;
3506 def : SELECTNegCondImm<setne, R32C, i32, i32ImmSExt10, SELBr32, CEQIr32>;
3507 def : SELECTNegCondReg<setle, R32C, i32, SELBr32, CGTr32>;
3508 def : SELECTNegCondImm<setle, R32C, i32, i32ImmSExt10, SELBr32, CGTIr32>;
3509 def : SELECTNegCondReg<setule, R32C, i32, SELBr32, CLGTr32>;
3510 def : SELECTNegCondImm<setule, R32C, i32, i32ImmSExt10, SELBr32, CLGTIr32>;
3511
3512 class SELECTBinOpReg<PatFrag cond, RegisterClass rclass, ValueType inttype,
3513                      SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3514                      SPUInstr cmpOp2>:
3515   Pat<(select (inttype (cond rclass:$rA, rclass:$rB)),
3516               rclass:$rTrue, rclass:$rFalse),
3517       (selinstr rclass:$rFalse, rclass:$rTrue,
3518                 (binop (cmpOp1 rclass:$rA, rclass:$rB),
3519                        (cmpOp2 rclass:$rA, rclass:$rB)))>;
3520
3521 class SELECTBinOpImm<PatFrag cond, RegisterClass rclass, PatLeaf immpred,
3522                      ValueType inttype,
3523                      SPUInstr selinstr, SPUInstr binop, SPUInstr cmpOp1,
3524                      SPUInstr cmpOp2>:
3525     Pat<(select (inttype (cond rclass:$rA, (inttype immpred:$imm))),
3526                 rclass:$rTrue, rclass:$rFalse),
3527         (selinstr rclass:$rFalse, rclass:$rTrue,
3528                   (binop (cmpOp1 rclass:$rA, (inttype immpred:$imm)),
3529                          (cmpOp2 rclass:$rA, (inttype immpred:$imm))))>;
3530
3531 def : SELECTBinOpReg<setge, R8C, i8, SELBr8, ORr8, CGTBr8, CEQBr8>;
3532 def : SELECTBinOpImm<setge, R8C, immSExt8, i8,
3533                      SELBr8, ORr8, CGTBIr8, CEQBIr8>;
3534
3535 def : SELECTBinOpReg<setge, R16C, i16, SELBr16, ORr16, CGTHr16, CEQHr16>;
3536 def : SELECTBinOpImm<setge, R16C, i16ImmSExt10, i16,
3537                      SELBr16, ORr16, CGTHIr16, CEQHIr16>;
3538
3539 def : SELECTBinOpReg<setge, R32C, i32, SELBr32, ORr32, CGTr32, CEQr32>;
3540 def : SELECTBinOpImm<setge, R32C, i32ImmSExt10, i32,
3541                      SELBr32, ORr32, CGTIr32, CEQIr32>;
3542
3543 def : SELECTBinOpReg<setuge, R8C, i8, SELBr8, ORr8, CLGTBr8, CEQBr8>;
3544 def : SELECTBinOpImm<setuge, R8C, immSExt8, i8,
3545                      SELBr8, ORr8, CLGTBIr8, CEQBIr8>;
3546
3547 def : SELECTBinOpReg<setuge, R16C, i16, SELBr16, ORr16, CLGTHr16, CEQHr16>;
3548 def : SELECTBinOpImm<setuge, R16C, i16ImmUns10, i16,
3549                      SELBr16, ORr16, CLGTHIr16, CEQHIr16>;
3550
3551 def : SELECTBinOpReg<setuge, R32C, i32, SELBr32, ORr32, CLGTr32, CEQr32>;
3552 def : SELECTBinOpImm<setuge, R32C, i32ImmUns10, i32,
3553                      SELBr32, ORr32, CLGTIr32, CEQIr32>;
3554
3555 //-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
3556
3557 let isCall = 1,
3558   // All calls clobber the non-callee-saved registers:
3559   Defs = [R0, R1, R2, R3, R4, R5, R6, R7, R8, R9,
3560           R10,R11,R12,R13,R14,R15,R16,R17,R18,R19,
3561           R20,R21,R22,R23,R24,R25,R26,R27,R28,R29,
3562           R30,R31,R32,R33,R34,R35,R36,R37,R38,R39,
3563           R40,R41,R42,R43,R44,R45,R46,R47,R48,R49,
3564           R50,R51,R52,R53,R54,R55,R56,R57,R58,R59,
3565           R60,R61,R62,R63,R64,R65,R66,R67,R68,R69,
3566           R70,R71,R72,R73,R74,R75,R76,R77,R78,R79],
3567   // All of these instructions use $lr (aka $0)
3568   Uses = [R0]  in {
3569   // Branch relative and set link: Used if we actually know that the target
3570   // is within [-32768, 32767] bytes of the target
3571   def BRSL:
3572     BranchSetLink<0b011001100, (outs), (ins relcalltarget:$func, variable_ops),
3573       "brsl\t$$lr, $func",
3574       [(SPUcall (SPUpcrel tglobaladdr:$func, 0))]>;
3575
3576   // Branch absolute and set link: Used if we actually know that the target
3577   // is an absolute address
3578   def BRASL:
3579     BranchSetLink<0b011001100, (outs), (ins calltarget:$func, variable_ops),
3580       "brasl\t$$lr, $func",
3581       [(SPUcall (SPUaform tglobaladdr:$func, 0))]>;
3582
3583   // Branch indirect and set link if external data. These instructions are not
3584   // actually generated, matched by an intrinsic:
3585   def BISLED_00: BISLEDForm<0b11, "bisled\t$$lr, $func", [/* empty pattern */]>;
3586   def BISLED_E0: BISLEDForm<0b10, "bisled\t$$lr, $func", [/* empty pattern */]>;
3587   def BISLED_0D: BISLEDForm<0b01, "bisled\t$$lr, $func", [/* empty pattern */]>;
3588   def BISLED_ED: BISLEDForm<0b00, "bisled\t$$lr, $func", [/* empty pattern */]>;
3589
3590   // Branch indirect and set link. This is the "X-form" address version of a
3591   // function call
3592   def BISL:
3593     BIForm<0b10010101100, "bisl\t$$lr, $func", [(SPUcall R32C:$func)]>;
3594 }
3595
3596 // Support calls to external symbols:      
3597 def : Pat<(SPUcall (SPUpcrel texternalsym:$func, 0)),
3598           (BRSL texternalsym:$func)>;
3599       
3600 def : Pat<(SPUcall (SPUaform texternalsym:$func, 0)),
3601           (BRASL texternalsym:$func)>;
3602
3603 // Unconditional branches:
3604 let isBranch = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
3605   def BR :
3606     UncondBranch<0b001001100, (outs), (ins brtarget:$dest),
3607       "br\t$dest",
3608       [(br bb:$dest)]>;
3609
3610   // Unconditional, absolute address branch
3611   def BRA:
3612     UncondBranch<0b001100000, (outs), (ins brtarget:$dest),
3613       "bra\t$dest",
3614       [/* no pattern */]>;
3615
3616   // Indirect branch
3617   def BI:
3618     BIForm<0b00010101100, "bi\t$func", [(brind R32C:$func)]>;
3619
3620   // Conditional branches:
3621   class BRNZInst<dag IOL, list<dag> pattern>:
3622     RI16Form<0b010000100, (outs), IOL, "brnz\t$rCond,$dest",
3623              BranchResolv, pattern>;
3624
3625   class BRNZRegInst<RegisterClass rclass>:
3626     BRNZInst<(ins rclass:$rCond, brtarget:$dest),
3627              [(brcond rclass:$rCond, bb:$dest)]>;
3628
3629   class BRNZVecInst<ValueType vectype>:
3630     BRNZInst<(ins VECREG:$rCond, brtarget:$dest),
3631              [(brcond (vectype VECREG:$rCond), bb:$dest)]>;
3632
3633   multiclass BranchNotZero {
3634     def v4i32 : BRNZVecInst<v4i32>;
3635     def r32   : BRNZRegInst<R32C>;
3636   }
3637
3638   defm BRNZ : BranchNotZero;
3639
3640   class BRZInst<dag IOL, list<dag> pattern>:
3641     RI16Form<0b000000100, (outs), IOL, "brz\t$rT,$dest",
3642              BranchResolv, pattern>;
3643
3644   class BRZRegInst<RegisterClass rclass>:
3645     BRZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3646
3647   class BRZVecInst<ValueType vectype>:
3648     BRZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3649
3650   multiclass BranchZero {
3651     def v4i32: BRZVecInst<v4i32>;
3652     def r32:   BRZRegInst<R32C>;
3653   }
3654
3655   defm BRZ: BranchZero;
3656
3657   // Note: LLVM doesn't do branch conditional, indirect. Otherwise these would
3658   // be useful:
3659   /*
3660   class BINZInst<dag IOL, list<dag> pattern>:
3661    BICondForm<0b10010100100, (outs), IOL, "binz\t$rA, $dest", pattern>;
3662
3663   class BINZRegInst<RegisterClass rclass>:
3664     BINZInst<(ins rclass:$rA, brtarget:$dest),
3665              [(brcond rclass:$rA, R32C:$dest)]>;
3666
3667   class BINZVecInst<ValueType vectype>:
3668     BINZInst<(ins VECREG:$rA, R32C:$dest),
3669              [(brcond (vectype VECREG:$rA), R32C:$dest)]>;
3670
3671   multiclass BranchNotZeroIndirect {
3672     def v4i32: BINZVecInst<v4i32>;
3673     def r32:   BINZRegInst<R32C>;
3674   }
3675
3676   defm BINZ: BranchNotZeroIndirect;
3677
3678   class BIZInst<dag IOL, list<dag> pattern>:
3679     BICondForm<0b00010100100, (outs), IOL, "biz\t$rA, $func", pattern>;
3680
3681   class BIZRegInst<RegisterClass rclass>:
3682     BIZInst<(ins rclass:$rA, R32C:$func), [/* no pattern */]>;
3683
3684   class BIZVecInst<ValueType vectype>:
3685     BIZInst<(ins VECREG:$rA, R32C:$func), [/* no pattern */]>;
3686
3687   multiclass BranchZeroIndirect {
3688     def v4i32: BIZVecInst<v4i32>;
3689     def r32:   BIZRegInst<R32C>;
3690   }
3691
3692   defm BIZ: BranchZeroIndirect;
3693   */
3694
3695   class BRHNZInst<dag IOL, list<dag> pattern>:
3696     RI16Form<0b011000100, (outs), IOL, "brhnz\t$rCond,$dest", BranchResolv,
3697              pattern>;
3698
3699   class BRHNZRegInst<RegisterClass rclass>:
3700     BRHNZInst<(ins rclass:$rCond, brtarget:$dest),
3701               [(brcond rclass:$rCond, bb:$dest)]>;
3702
3703   class BRHNZVecInst<ValueType vectype>:
3704     BRHNZInst<(ins VECREG:$rCond, brtarget:$dest), [/* no pattern */]>;
3705
3706   multiclass BranchNotZeroHalfword {
3707     def v8i16: BRHNZVecInst<v8i16>;
3708     def r16:   BRHNZRegInst<R16C>;
3709   }
3710
3711   defm BRHNZ: BranchNotZeroHalfword;
3712
3713   class BRHZInst<dag IOL, list<dag> pattern>:
3714     RI16Form<0b001000100, (outs), IOL, "brhz\t$rT,$dest", BranchResolv,
3715              pattern>;
3716
3717   class BRHZRegInst<RegisterClass rclass>:
3718     BRHZInst<(ins rclass:$rT, brtarget:$dest), [/* no pattern */]>;
3719
3720   class BRHZVecInst<ValueType vectype>:
3721     BRHZInst<(ins VECREG:$rT, brtarget:$dest), [/* no pattern */]>;
3722
3723   multiclass BranchZeroHalfword {
3724     def v8i16: BRHZVecInst<v8i16>;
3725     def r16:   BRHZRegInst<R16C>;
3726   }
3727
3728   defm BRHZ: BranchZeroHalfword;
3729 }
3730
3731 //===----------------------------------------------------------------------===//
3732 // setcc and brcond patterns:
3733 //===----------------------------------------------------------------------===//
3734
3735 def : Pat<(brcond (i16 (seteq R16C:$rA, 0)), bb:$dest),
3736           (BRHZr16 R16C:$rA, bb:$dest)>;
3737 def : Pat<(brcond (i16 (setne R16C:$rA, 0)), bb:$dest),
3738           (BRHNZr16 R16C:$rA, bb:$dest)>;
3739
3740 def : Pat<(brcond (i32 (seteq R32C:$rA, 0)), bb:$dest),
3741           (BRZr32 R32C:$rA, bb:$dest)>;
3742 def : Pat<(brcond (i32 (setne R32C:$rA, 0)), bb:$dest),
3743           (BRNZr32 R32C:$rA, bb:$dest)>;
3744
3745 multiclass BranchCondEQ<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3746 {
3747   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3748                   (brinst16 (CEQHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3749
3750   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3751                 (brinst16 (CEQHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3752
3753   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3754                    (brinst32 (CEQIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3755
3756   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3757                 (brinst32 (CEQr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3758 }
3759
3760 defm BRCONDeq : BranchCondEQ<seteq, BRHNZr16, BRNZr32>;
3761 defm BRCONDne : BranchCondEQ<setne, BRHZr16, BRZr32>;
3762
3763 multiclass BranchCondLGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3764 {
3765   def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3766                    (brinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3767
3768   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3769                 (brinst16 (CLGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3770
3771   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3772                    (brinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3773
3774   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3775                 (brinst32 (CLGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3776 }
3777
3778 defm BRCONDugt : BranchCondLGT<setugt, BRHNZr16, BRNZr32>;
3779 defm BRCONDule : BranchCondLGT<setule, BRHZr16, BRZr32>;
3780
3781 multiclass BranchCondLGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3782                            SPUInstr orinst32, SPUInstr brinst32>
3783 {
3784   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3785                   (brinst16 (orinst16 (CLGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3786                                       (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3787                             bb:$dest)>;
3788
3789   def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3790                (brinst16 (orinst16 (CLGTHr16 R16C:$rA, R16:$rB),
3791                                    (CEQHr16 R16C:$rA, R16:$rB)),
3792                          bb:$dest)>;
3793
3794   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3795                    (brinst32 (orinst32 (CLGTIr32 R32C:$rA, i32ImmSExt10:$val),
3796                                        (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3797                              bb:$dest)>;
3798
3799   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3800                 (brinst32 (orinst32 (CLGTr32 R32C:$rA, R32C:$rB),
3801                                     (CEQr32 R32C:$rA, R32C:$rB)),
3802                           bb:$dest)>;
3803 }
3804
3805 defm BRCONDuge : BranchCondLGTEQ<setuge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3806 defm BRCONDult : BranchCondLGTEQ<setult, ORr16, BRHZr16, ORr32, BRZr32>;
3807
3808 multiclass BranchCondGT<PatFrag cond, SPUInstr brinst16, SPUInstr brinst32>
3809 {
3810   def r16imm : Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3811                    (brinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val), bb:$dest)>;
3812
3813   def r16 : Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3814                 (brinst16 (CGTHr16 R16C:$rA, R16:$rB), bb:$dest)>;
3815
3816   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3817                    (brinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val), bb:$dest)>;
3818
3819   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3820                 (brinst32 (CGTr32 R32C:$rA, R32C:$rB), bb:$dest)>;
3821 }
3822
3823 defm BRCONDgt : BranchCondGT<setgt, BRHNZr16, BRNZr32>;
3824 defm BRCONDle : BranchCondGT<setle, BRHZr16, BRZr32>;
3825
3826 multiclass BranchCondGTEQ<PatFrag cond, SPUInstr orinst16, SPUInstr brinst16,
3827                           SPUInstr orinst32, SPUInstr brinst32>
3828 {
3829   def r16imm: Pat<(brcond (i16 (cond R16C:$rA, i16ImmSExt10:$val)), bb:$dest),
3830                   (brinst16 (orinst16 (CGTHIr16 R16C:$rA, i16ImmSExt10:$val),
3831                                       (CEQHIr16 R16C:$rA, i16ImmSExt10:$val)),
3832                             bb:$dest)>;
3833
3834   def r16: Pat<(brcond (i16 (cond R16C:$rA, R16C:$rB)), bb:$dest),
3835                (brinst16 (orinst16 (CGTHr16 R16C:$rA, R16:$rB),
3836                                    (CEQHr16 R16C:$rA, R16:$rB)),
3837                          bb:$dest)>;
3838
3839   def r32imm : Pat<(brcond (i32 (cond R32C:$rA, i32ImmSExt10:$val)), bb:$dest),
3840                    (brinst32 (orinst32 (CGTIr32 R32C:$rA, i32ImmSExt10:$val),
3841                                        (CEQIr32 R32C:$rA, i32ImmSExt10:$val)),
3842                              bb:$dest)>;
3843
3844   def r32 : Pat<(brcond (i32 (cond R32C:$rA, R32C:$rB)), bb:$dest),
3845                 (brinst32 (orinst32 (CGTr32 R32C:$rA, R32C:$rB),
3846                                     (CEQr32 R32C:$rA, R32C:$rB)),
3847                           bb:$dest)>;
3848 }
3849
3850 defm BRCONDge : BranchCondGTEQ<setge, ORr16, BRHNZr16, ORr32, BRNZr32>;
3851 defm BRCONDlt : BranchCondGTEQ<setlt, ORr16, BRHZr16, ORr32, BRZr32>;
3852
3853 let isTerminator = 1, isBarrier = 1 in {
3854   let isReturn = 1 in {
3855     def RET:
3856         RETForm<"bi\t$$lr", [(retflag)]>;
3857   }
3858 }
3859
3860 //===----------------------------------------------------------------------===//
3861 // Single precision floating point instructions
3862 //===----------------------------------------------------------------------===//
3863
3864 class FAInst<dag OOL, dag IOL, list<dag> pattern>:
3865     RRForm<0b01011000100, OOL, IOL, "fa\t$rT, $rA, $rB",
3866            SPrecFP, pattern>;
3867
3868 class FAVecInst<ValueType vectype>:
3869     FAInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3870              [(set (vectype VECREG:$rT),
3871                    (fadd (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3872
3873 multiclass SFPAdd
3874 {
3875   def v4f32: FAVecInst<v4f32>;
3876   def f32:   FAInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3877                     [(set R32FP:$rT, (fadd R32FP:$rA, R32FP:$rB))]>;
3878 }
3879
3880 defm FA : SFPAdd;
3881
3882 class FSInst<dag OOL, dag IOL, list<dag> pattern>:
3883     RRForm<0b01011000100, OOL, IOL, "fs\t$rT, $rA, $rB",
3884            SPrecFP, pattern>;
3885
3886 class FSVecInst<ValueType vectype>:
3887     FSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3888            [(set (vectype VECREG:$rT),
3889                  (fsub (vectype VECREG:$rA), (vectype VECREG:$rB)))]>;
3890
3891 multiclass SFPSub
3892 {
3893   def v4f32: FSVecInst<v4f32>;
3894   def f32:   FSInst<(outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3895                     [(set R32FP:$rT, (fsub R32FP:$rA, R32FP:$rB))]>;
3896 }
3897
3898 defm FS : SFPSub;
3899
3900 // Floating point reciprocal estimate
3901
3902 class FRESTInst<dag OOL, dag IOL>:
3903   RRForm_1<0b00110111000, OOL, IOL,
3904            "frest\t$rT, $rA", SPrecFP,
3905            [/* no pattern */]>;
3906
3907 def FRESTv4f32 :
3908     FRESTInst<(outs VECREG:$rT), (ins VECREG:$rA)>;
3909
3910 def FRESTf32 :
3911     FRESTInst<(outs R32FP:$rT), (ins R32FP:$rA)>;
3912
3913 // Floating point interpolate (used in conjunction with reciprocal estimate)
3914 def FIv4f32 :
3915     RRForm<0b00101011110, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
3916       "fi\t$rT, $rA, $rB", SPrecFP,
3917       [/* no pattern */]>;
3918
3919 def FIf32 :
3920     RRForm<0b00101011110, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
3921       "fi\t$rT, $rA, $rB", SPrecFP,
3922       [/* no pattern */]>;
3923
3924 //--------------------------------------------------------------------------
3925 // Basic single precision floating point comparisons:
3926 //
3927 // Note: There is no support on SPU for single precision NaN. Consequently,
3928 // ordered and unordered comparisons are the same.
3929 //--------------------------------------------------------------------------
3930
3931 def FCEQf32 :
3932     RRForm<0b01000011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3933       "fceq\t$rT, $rA, $rB", SPrecFP,
3934       [(set R32C:$rT, (setueq R32FP:$rA, R32FP:$rB))]>;
3935
3936 def : Pat<(setoeq R32FP:$rA, R32FP:$rB),
3937           (FCEQf32 R32FP:$rA, R32FP:$rB)>;
3938
3939 def FCMEQf32 :
3940     RRForm<0b01010011110, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3941       "fcmeq\t$rT, $rA, $rB", SPrecFP,
3942       [(set R32C:$rT, (setueq (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3943
3944 def : Pat<(setoeq (fabs R32FP:$rA), (fabs R32FP:$rB)),
3945           (FCMEQf32 R32FP:$rA, R32FP:$rB)>;
3946
3947 def FCGTf32 :
3948     RRForm<0b01000011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3949       "fcgt\t$rT, $rA, $rB", SPrecFP,
3950       [(set R32C:$rT, (setugt R32FP:$rA, R32FP:$rB))]>;
3951
3952 def : Pat<(setugt R32FP:$rA, R32FP:$rB),
3953           (FCGTf32 R32FP:$rA, R32FP:$rB)>;
3954
3955 def FCMGTf32 :
3956     RRForm<0b01010011010, (outs R32C:$rT), (ins R32FP:$rA, R32FP:$rB),
3957       "fcmgt\t$rT, $rA, $rB", SPrecFP,
3958       [(set R32C:$rT, (setugt (fabs R32FP:$rA), (fabs R32FP:$rB)))]>;
3959
3960 def : Pat<(setugt (fabs R32FP:$rA), (fabs R32FP:$rB)),
3961           (FCMGTf32 R32FP:$rA, R32FP:$rB)>;
3962
3963 //--------------------------------------------------------------------------
3964 // Single precision floating point comparisons and SETCC equivalents:
3965 //--------------------------------------------------------------------------
3966
3967 def : SETCCNegCondReg<setune, R32FP, i32, XORIr32, FCEQf32>;
3968 def : SETCCNegCondReg<setone, R32FP, i32, XORIr32, FCEQf32>;
3969
3970 def : SETCCBinOpReg<setuge, R32FP, ORr32, FCGTf32, FCEQf32>;
3971 def : SETCCBinOpReg<setoge, R32FP, ORr32, FCGTf32, FCEQf32>;
3972
3973 def : SETCCBinOpReg<setult, R32FP, NORr32, FCGTf32, FCEQf32>;
3974 def : SETCCBinOpReg<setolt, R32FP, NORr32, FCGTf32, FCEQf32>;
3975
3976 def : Pat<(setule R32FP:$rA, R32FP:$rB),
3977           (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3978 def : Pat<(setole R32FP:$rA, R32FP:$rB),
3979           (XORIr32 (FCGTf32 R32FP:$rA, R32FP:$rB), 0xffffffff)>;
3980
3981 // FP Status and Control Register Write
3982 // Why isn't rT a don't care in the ISA?
3983 // Should we create a special RRForm_3 for this guy and zero out the rT?
3984 def FSCRWf32 :
3985     RRForm_1<0b01011101110, (outs R32FP:$rT), (ins R32FP:$rA),
3986       "fscrwr\t$rA", SPrecFP,
3987       [/* This instruction requires an intrinsic. Note: rT is unused. */]>;
3988
3989 // FP Status and Control Register Read
3990 def FSCRRf32 :
3991     RRForm_2<0b01011101110, (outs R32FP:$rT), (ins),
3992       "fscrrd\t$rT", SPrecFP,
3993       [/* This instruction requires an intrinsic */]>;
3994
3995 // llvm instruction space
3996 // How do these map onto cell instructions?
3997 // fdiv rA rB
3998 //   frest rC rB        # c = 1/b (both lines)
3999 //   fi rC rB rC
4000 //   fm rD rA rC        # d = a * 1/b
4001 //   fnms rB rD rB rA # b = - (d * b - a) --should == 0 in a perfect world
4002 //   fma rB rB rC rD            # b = b * c + d
4003 //                              = -(d *b -a) * c + d
4004 //                              = a * c - c ( a *b *c - a)
4005
4006 // fcopysign (???)
4007
4008 // Library calls:
4009 // These llvm instructions will actually map to library calls.
4010 // All that's needed, then, is to check that the appropriate library is
4011 // imported and do a brsl to the proper function name.
4012 // frem # fmod(x, y): x - (x/y) * y
4013 // (Note: fmod(double, double), fmodf(float,float)
4014 // fsqrt?
4015 // fsin?
4016 // fcos?
4017 // Unimplemented SPU instruction space
4018 // floating reciprocal absolute square root estimate (frsqest)
4019
4020 // The following are probably just intrinsics
4021 // status and control register write
4022 // status and control register read
4023
4024 //--------------------------------------
4025 // Floating point multiply instructions
4026 //--------------------------------------
4027
4028 def FMv4f32:
4029     RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4030       "fm\t$rT, $rA, $rB", SPrecFP,
4031       [(set (v4f32 VECREG:$rT), (fmul (v4f32 VECREG:$rA),
4032                                       (v4f32 VECREG:$rB)))]>;
4033
4034 def FMf32 :
4035     RRForm<0b01100011010, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB),
4036       "fm\t$rT, $rA, $rB", SPrecFP,
4037       [(set R32FP:$rT, (fmul R32FP:$rA, R32FP:$rB))]>;
4038
4039 // Floating point multiply and add
4040 // e.g. d = c + (a * b)
4041 def FMAv4f32:
4042     RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4043       "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4044       [(set (v4f32 VECREG:$rT),
4045             (fadd (v4f32 VECREG:$rC),
4046                   (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB))))]>;
4047
4048 def FMAf32:
4049     RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4050       "fma\t$rT, $rA, $rB, $rC", SPrecFP,
4051       [(set R32FP:$rT, (fadd R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4052
4053 // FP multiply and subtract
4054 // Subtracts value in rC from product
4055 // res = a * b - c
4056 def FMSv4f32 :
4057     RRRForm<0b0111, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4058       "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4059       [(set (v4f32 VECREG:$rT),
4060             (fsub (fmul (v4f32 VECREG:$rA), (v4f32 VECREG:$rB)),
4061                   (v4f32 VECREG:$rC)))]>;
4062
4063 def FMSf32 :
4064     RRRForm<0b0111, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4065       "fms\t$rT, $rA, $rB, $rC", SPrecFP,
4066       [(set R32FP:$rT,
4067             (fsub (fmul R32FP:$rA, R32FP:$rB), R32FP:$rC))]>;
4068
4069 // Floating Negative Mulitply and Subtract
4070 // Subtracts product from value in rC
4071 // res = fneg(fms a b c)
4072 //     = - (a * b - c)
4073 //     = c - a * b
4074 // NOTE: subtraction order
4075 // fsub a b = a - b
4076 // fs a b = b - a?
4077 def FNMSf32 :
4078     RRRForm<0b1101, (outs R32FP:$rT), (ins R32FP:$rA, R32FP:$rB, R32FP:$rC),
4079       "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4080       [(set R32FP:$rT, (fsub R32FP:$rC, (fmul R32FP:$rA, R32FP:$rB)))]>;
4081
4082 def FNMSv4f32 :
4083     RRRForm<0b1101, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4084       "fnms\t$rT, $rA, $rB, $rC", SPrecFP,
4085       [(set (v4f32 VECREG:$rT),
4086             (fsub (v4f32 VECREG:$rC),
4087                   (fmul (v4f32 VECREG:$rA),
4088                         (v4f32 VECREG:$rB))))]>;
4089
4090 //--------------------------------------
4091 // Floating Point Conversions
4092 // Signed conversions:
4093 def CSiFv4f32:
4094     CVTIntFPForm<0b0101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4095       "csflt\t$rT, $rA, 0", SPrecFP,
4096       [(set (v4f32 VECREG:$rT), (sint_to_fp (v4i32 VECREG:$rA)))]>;
4097
4098 // Convert signed integer to floating point
4099 def CSiFf32 :
4100     CVTIntFPForm<0b0101101110, (outs R32FP:$rT), (ins R32C:$rA),
4101       "csflt\t$rT, $rA, 0", SPrecFP,
4102       [(set R32FP:$rT, (sint_to_fp R32C:$rA))]>;
4103
4104 // Convert unsigned into to float
4105 def CUiFv4f32 :
4106     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4107       "cuflt\t$rT, $rA, 0", SPrecFP,
4108       [(set (v4f32 VECREG:$rT), (uint_to_fp (v4i32 VECREG:$rA)))]>;
4109
4110 def CUiFf32 :
4111     CVTIntFPForm<0b1101101110, (outs R32FP:$rT), (ins R32C:$rA),
4112       "cuflt\t$rT, $rA, 0", SPrecFP,
4113       [(set R32FP:$rT, (uint_to_fp R32C:$rA))]>;
4114
4115 // Convert float to unsigned int
4116 // Assume that scale = 0
4117
4118 def CFUiv4f32 :
4119     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4120       "cfltu\t$rT, $rA, 0", SPrecFP,
4121       [(set (v4i32 VECREG:$rT), (fp_to_uint (v4f32 VECREG:$rA)))]>;
4122
4123 def CFUif32 :
4124     CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4125       "cfltu\t$rT, $rA, 0", SPrecFP,
4126       [(set R32C:$rT, (fp_to_uint R32FP:$rA))]>;
4127
4128 // Convert float to signed int
4129 // Assume that scale = 0
4130
4131 def CFSiv4f32 :
4132     CVTIntFPForm<0b1101101110, (outs VECREG:$rT), (ins VECREG:$rA),
4133       "cflts\t$rT, $rA, 0", SPrecFP,
4134       [(set (v4i32 VECREG:$rT), (fp_to_sint (v4f32 VECREG:$rA)))]>;
4135
4136 def CFSif32 :
4137     CVTIntFPForm<0b1101101110, (outs R32C:$rT), (ins R32FP:$rA),
4138       "cflts\t$rT, $rA, 0", SPrecFP,
4139       [(set R32C:$rT, (fp_to_sint R32FP:$rA))]>;
4140
4141 //===----------------------------------------------------------------------==//
4142 // Single<->Double precision conversions
4143 //===----------------------------------------------------------------------==//
4144
4145 // NOTE: We use "vec" name suffix here to avoid confusion (e.g. input is a
4146 // v4f32, output is v2f64--which goes in the name?)
4147
4148 // Floating point extend single to double
4149 // NOTE: Not sure if passing in v4f32 to FESDvec is correct since it
4150 // operates on two double-word slots (i.e. 1st and 3rd fp numbers
4151 // are ignored).
4152 def FESDvec :
4153     RRForm_1<0b00011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4154       "fesd\t$rT, $rA", SPrecFP,
4155       [(set (v2f64 VECREG:$rT), (fextend (v4f32 VECREG:$rA)))]>;
4156
4157 def FESDf32 :
4158     RRForm_1<0b00011101110, (outs R64FP:$rT), (ins R32FP:$rA),
4159       "fesd\t$rT, $rA", SPrecFP,
4160       [(set R64FP:$rT, (fextend R32FP:$rA))]>;
4161
4162 // Floating point round double to single
4163 //def FRDSvec :
4164 //    RRForm_1<0b10011101110, (outs VECREG:$rT), (ins VECREG:$rA),
4165 //      "frds\t$rT, $rA,", SPrecFP,
4166 //      [(set (v4f32 R32FP:$rT), (fround (v2f64 R64FP:$rA)))]>;
4167
4168 def FRDSf64 :
4169     RRForm_1<0b10011101110, (outs R32FP:$rT), (ins R64FP:$rA),
4170       "frds\t$rT, $rA", SPrecFP,
4171       [(set R32FP:$rT, (fround R64FP:$rA))]>;
4172
4173 //ToDo include anyextend?
4174
4175 //===----------------------------------------------------------------------==//
4176 // Double precision floating point instructions
4177 //===----------------------------------------------------------------------==//
4178 def FAf64 :
4179     RRForm<0b00110011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4180       "dfa\t$rT, $rA, $rB", DPrecFP,
4181       [(set R64FP:$rT, (fadd R64FP:$rA, R64FP:$rB))]>;
4182
4183 def FAv2f64 :
4184     RRForm<0b00110011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4185       "dfa\t$rT, $rA, $rB", DPrecFP,
4186       [(set (v2f64 VECREG:$rT), (fadd (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4187
4188 def FSf64 :
4189     RRForm<0b10100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4190       "dfs\t$rT, $rA, $rB", DPrecFP,
4191       [(set R64FP:$rT, (fsub R64FP:$rA, R64FP:$rB))]>;
4192
4193 def FSv2f64 :
4194     RRForm<0b10100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4195       "dfs\t$rT, $rA, $rB", DPrecFP,
4196       [(set (v2f64 VECREG:$rT),
4197             (fsub (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4198
4199 def FMf64 :
4200     RRForm<0b01100011010, (outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB),
4201       "dfm\t$rT, $rA, $rB", DPrecFP,
4202       [(set R64FP:$rT, (fmul R64FP:$rA, R64FP:$rB))]>;
4203
4204 def FMv2f64:
4205     RRForm<0b00100011010, (outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB),
4206       "dfm\t$rT, $rA, $rB", DPrecFP,
4207       [(set (v2f64 VECREG:$rT),
4208             (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)))]>;
4209
4210 def FMAf64:
4211     RRForm<0b00111010110, (outs R64FP:$rT),
4212                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4213       "dfma\t$rT, $rA, $rB", DPrecFP,
4214       [(set R64FP:$rT, (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB)))]>,
4215     RegConstraint<"$rC = $rT">,
4216     NoEncode<"$rC">;
4217
4218 def FMAv2f64:
4219     RRForm<0b00111010110, (outs VECREG:$rT),
4220                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4221       "dfma\t$rT, $rA, $rB", DPrecFP,
4222       [(set (v2f64 VECREG:$rT),
4223             (fadd (v2f64 VECREG:$rC),
4224                   (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB))))]>,
4225     RegConstraint<"$rC = $rT">,
4226     NoEncode<"$rC">;
4227
4228 def FMSf64 :
4229     RRForm<0b10111010110, (outs R64FP:$rT),
4230                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4231       "dfms\t$rT, $rA, $rB", DPrecFP,
4232       [(set R64FP:$rT, (fsub (fmul R64FP:$rA, R64FP:$rB), R64FP:$rC))]>,
4233     RegConstraint<"$rC = $rT">,
4234     NoEncode<"$rC">;
4235
4236 def FMSv2f64 :
4237     RRForm<0b10111010110, (outs VECREG:$rT),
4238                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4239       "dfms\t$rT, $rA, $rB", DPrecFP,
4240       [(set (v2f64 VECREG:$rT),
4241             (fsub (fmul (v2f64 VECREG:$rA), (v2f64 VECREG:$rB)),
4242                   (v2f64 VECREG:$rC)))]>;
4243
4244 // DFNMS: - (a * b - c)
4245 // - (a * b) + c => c - (a * b)
4246
4247 class DFNMSInst<dag OOL, dag IOL, list<dag> pattern>:
4248     RRForm<0b01111010110, OOL, IOL, "dfnms\t$rT, $rA, $rB",
4249            DPrecFP, pattern>,
4250     RegConstraint<"$rC = $rT">,
4251     NoEncode<"$rC">;
4252
4253 class DFNMSVecInst<list<dag> pattern>:
4254     DFNMSInst<(outs VECREG:$rT), (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4255               pattern>;
4256
4257 class DFNMSRegInst<list<dag> pattern>:
4258     DFNMSInst<(outs R64FP:$rT), (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4259              pattern>;
4260
4261 multiclass DFMultiplySubtract
4262 {
4263   def v2f64 : DFNMSVecInst<[(set (v2f64 VECREG:$rT), 
4264                                  (fsub (v2f64 VECREG:$rC),
4265                                        (fmul (v2f64 VECREG:$rA),
4266                                              (v2f64 VECREG:$rB))))]>;
4267
4268   def f64 : DFNMSRegInst<[(set R64FP:$rT,
4269                                (fsub R64FP:$rC,
4270                                      (fmul R64FP:$rA, R64FP:$rB)))]>;
4271 }
4272
4273 defm DFNMS : DFMultiplySubtract;
4274
4275 // - (a * b + c)
4276 // - (a * b) - c
4277 def FNMAf64 :
4278     RRForm<0b11111010110, (outs R64FP:$rT),
4279                           (ins R64FP:$rA, R64FP:$rB, R64FP:$rC),
4280       "dfnma\t$rT, $rA, $rB", DPrecFP,
4281       [(set R64FP:$rT, (fneg (fadd R64FP:$rC, (fmul R64FP:$rA, R64FP:$rB))))]>,
4282     RegConstraint<"$rC = $rT">,
4283     NoEncode<"$rC">;
4284
4285 def FNMAv2f64 :
4286     RRForm<0b11111010110, (outs VECREG:$rT),
4287                           (ins VECREG:$rA, VECREG:$rB, VECREG:$rC),
4288       "dfnma\t$rT, $rA, $rB", DPrecFP,
4289       [(set (v2f64 VECREG:$rT),
4290             (fneg (fadd (v2f64 VECREG:$rC),
4291                         (fmul (v2f64 VECREG:$rA),
4292                               (v2f64 VECREG:$rB)))))]>,
4293     RegConstraint<"$rC = $rT">,
4294     NoEncode<"$rC">;
4295
4296 //===----------------------------------------------------------------------==//
4297 // Floating point negation and absolute value
4298 //===----------------------------------------------------------------------==//
4299
4300 def : Pat<(fneg (v4f32 VECREG:$rA)),
4301           (XORfnegvec (v4f32 VECREG:$rA),
4302                       (v4f32 (ILHUv4i32 0x8000)))>;
4303
4304 def : Pat<(fneg R32FP:$rA),
4305           (XORfneg32 R32FP:$rA, (ILHUr32 0x8000))>;
4306
4307 // Floating point absolute value
4308 // Note: f64 fabs is custom-selected.
4309
4310 def : Pat<(fabs R32FP:$rA),
4311           (ANDfabs32 R32FP:$rA, (IOHLr32 (ILHUr32 0x7fff), 0xffff))>;
4312
4313 def : Pat<(fabs (v4f32 VECREG:$rA)),
4314           (ANDfabsvec (v4f32 VECREG:$rA),
4315                       (IOHLv4i32 (ILHUv4i32 0x7fff), 0xffff))>;
4316
4317 //===----------------------------------------------------------------------===//
4318 // Hint for branch instructions:
4319 //===----------------------------------------------------------------------===//
4320
4321 /* def HBR : SPUInstr<(outs), (ins), "hbr\t" */
4322
4323 //===----------------------------------------------------------------------===//
4324 // Execution, Load NOP (execute NOPs belong in even pipeline, load NOPs belong
4325 // in the odd pipeline)
4326 //===----------------------------------------------------------------------===//
4327
4328 def ENOP : SPUInstr<(outs), (ins), "enop", ExecNOP> {
4329   let Pattern = [];
4330
4331   let Inst{0-10} = 0b10000000010;
4332   let Inst{11-17} = 0;
4333   let Inst{18-24} = 0;
4334   let Inst{25-31} = 0;
4335 }
4336
4337 def LNOP : SPUInstr<(outs), (ins), "lnop", LoadNOP> {
4338   let Pattern = [];
4339
4340   let Inst{0-10} = 0b10000000000;
4341   let Inst{11-17} = 0;
4342   let Inst{18-24} = 0;
4343   let Inst{25-31} = 0;
4344 }
4345
4346 //===----------------------------------------------------------------------===//
4347 // Bit conversions (type conversions between vector/packed types)
4348 // NOTE: Promotions are handled using the XS* instructions.
4349 //===----------------------------------------------------------------------===//
4350 def : Pat<(v16i8 (bitconvert (v8i16 VECREG:$src))), (v16i8 VECREG:$src)>;
4351 def : Pat<(v16i8 (bitconvert (v4i32 VECREG:$src))), (v16i8 VECREG:$src)>;
4352 def : Pat<(v16i8 (bitconvert (v2i64 VECREG:$src))), (v16i8 VECREG:$src)>;
4353 def : Pat<(v16i8 (bitconvert (v4f32 VECREG:$src))), (v16i8 VECREG:$src)>;
4354 def : Pat<(v16i8 (bitconvert (v2f64 VECREG:$src))), (v16i8 VECREG:$src)>;
4355
4356 def : Pat<(v8i16 (bitconvert (v16i8 VECREG:$src))), (v8i16 VECREG:$src)>;
4357 def : Pat<(v8i16 (bitconvert (v4i32 VECREG:$src))), (v8i16 VECREG:$src)>;
4358 def : Pat<(v8i16 (bitconvert (v2i64 VECREG:$src))), (v8i16 VECREG:$src)>;
4359 def : Pat<(v8i16 (bitconvert (v4f32 VECREG:$src))), (v8i16 VECREG:$src)>;
4360 def : Pat<(v8i16 (bitconvert (v2f64 VECREG:$src))), (v8i16 VECREG:$src)>;
4361
4362 def : Pat<(v4i32 (bitconvert (v16i8 VECREG:$src))), (v4i32 VECREG:$src)>;
4363 def : Pat<(v4i32 (bitconvert (v8i16 VECREG:$src))), (v4i32 VECREG:$src)>;
4364 def : Pat<(v4i32 (bitconvert (v2i64 VECREG:$src))), (v4i32 VECREG:$src)>;
4365 def : Pat<(v4i32 (bitconvert (v4f32 VECREG:$src))), (v4i32 VECREG:$src)>;
4366 def : Pat<(v4i32 (bitconvert (v2f64 VECREG:$src))), (v4i32 VECREG:$src)>;
4367
4368 def : Pat<(v2i64 (bitconvert (v16i8 VECREG:$src))), (v2i64 VECREG:$src)>;
4369 def : Pat<(v2i64 (bitconvert (v8i16 VECREG:$src))), (v2i64 VECREG:$src)>;
4370 def : Pat<(v2i64 (bitconvert (v4i32 VECREG:$src))), (v2i64 VECREG:$src)>;
4371 def : Pat<(v2i64 (bitconvert (v4f32 VECREG:$src))), (v2i64 VECREG:$src)>;
4372 def : Pat<(v2i64 (bitconvert (v2f64 VECREG:$src))), (v2i64 VECREG:$src)>;
4373
4374 def : Pat<(v4f32 (bitconvert (v16i8 VECREG:$src))), (v4f32 VECREG:$src)>;
4375 def : Pat<(v4f32 (bitconvert (v8i16 VECREG:$src))), (v4f32 VECREG:$src)>;
4376 def : Pat<(v4f32 (bitconvert (v2i64 VECREG:$src))), (v4f32 VECREG:$src)>;
4377 def : Pat<(v4f32 (bitconvert (v4i32 VECREG:$src))), (v4f32 VECREG:$src)>;
4378 def : Pat<(v4f32 (bitconvert (v2f64 VECREG:$src))), (v4f32 VECREG:$src)>;
4379
4380 def : Pat<(v2f64 (bitconvert (v16i8 VECREG:$src))), (v2f64 VECREG:$src)>;
4381 def : Pat<(v2f64 (bitconvert (v8i16 VECREG:$src))), (v2f64 VECREG:$src)>;
4382 def : Pat<(v2f64 (bitconvert (v4i32 VECREG:$src))), (v2f64 VECREG:$src)>;
4383 def : Pat<(v2f64 (bitconvert (v2i64 VECREG:$src))), (v2f64 VECREG:$src)>;
4384 def : Pat<(v2f64 (bitconvert (v2f64 VECREG:$src))), (v2f64 VECREG:$src)>;
4385
4386 def : Pat<(i128 (bitconvert (v16i8 VECREG:$src))),
4387           (ORi128_vec VECREG:$src)>;
4388 def : Pat<(i128 (bitconvert (v8i16 VECREG:$src))),
4389           (ORi128_vec VECREG:$src)>;
4390 def : Pat<(i128 (bitconvert (v4i32 VECREG:$src))),
4391           (ORi128_vec VECREG:$src)>;
4392 def : Pat<(i128 (bitconvert (v2i64 VECREG:$src))),
4393           (ORi128_vec VECREG:$src)>;
4394 def : Pat<(i128 (bitconvert (v4f32 VECREG:$src))),
4395           (ORi128_vec VECREG:$src)>;
4396 def : Pat<(i128 (bitconvert (v2f64 VECREG:$src))),
4397           (ORi128_vec VECREG:$src)>;
4398
4399 def : Pat<(v16i8 (bitconvert (i128 GPRC:$src))),
4400           (v16i8 (ORvec_i128 GPRC:$src))>;
4401 def : Pat<(v8i16 (bitconvert (i128 GPRC:$src))),
4402           (v8i16 (ORvec_i128 GPRC:$src))>;
4403 def : Pat<(v4i32 (bitconvert (i128 GPRC:$src))),
4404           (v4i32 (ORvec_i128 GPRC:$src))>;
4405 def : Pat<(v2i64 (bitconvert (i128 GPRC:$src))),
4406           (v2i64 (ORvec_i128 GPRC:$src))>;
4407 def : Pat<(v4f32 (bitconvert (i128 GPRC:$src))),
4408           (v4f32 (ORvec_i128 GPRC:$src))>;
4409 def : Pat<(v2f64 (bitconvert (i128 GPRC:$src))),
4410           (v2f64 (ORvec_i128 GPRC:$src))>;
4411
4412 //===----------------------------------------------------------------------===//
4413 // Instruction patterns:
4414 //===----------------------------------------------------------------------===//
4415
4416 // General 32-bit constants:
4417 def : Pat<(i32 imm:$imm),
4418           (IOHLr32 (ILHUr32 (HI16 imm:$imm)), (LO16 imm:$imm))>;
4419
4420 // Single precision float constants:
4421 def : Pat<(f32 fpimm:$imm),
4422           (IOHLf32 (ILHUf32 (HI16_f32 fpimm:$imm)), (LO16_f32 fpimm:$imm))>;
4423
4424 // General constant 32-bit vectors
4425 def : Pat<(v4i32 v4i32Imm:$imm),
4426           (IOHLv4i32 (v4i32 (ILHUv4i32 (HI16_vec v4i32Imm:$imm))),
4427                      (LO16_vec v4i32Imm:$imm))>;
4428
4429 // 8-bit constants
4430 def : Pat<(i8 imm:$imm),
4431           (ILHr8 imm:$imm)>;
4432
4433 //===----------------------------------------------------------------------===//
4434 // Call instruction patterns:
4435 //===----------------------------------------------------------------------===//
4436 // Return void
4437 def : Pat<(ret),
4438           (RET)>;
4439
4440 //===----------------------------------------------------------------------===//
4441 // Zero/Any/Sign extensions
4442 //===----------------------------------------------------------------------===//
4443
4444 // sext 8->32: Sign extend bytes to words
4445 def : Pat<(sext_inreg R32C:$rSrc, i8),
4446           (XSHWr32 (XSBHr32 R32C:$rSrc))>;
4447
4448 def : Pat<(i32 (sext R8C:$rSrc)),
4449           (XSHWr16 (XSBHr8 R8C:$rSrc))>;
4450
4451 // sext 8->64: Sign extend bytes to double word
4452 def : Pat<(sext_inreg R64C:$rSrc, i8),
4453           (XSWDr64_inreg (XSHWr64 (XSBHr64 R64C:$rSrc)))>;
4454           
4455 def : Pat<(i64 (sext R8C:$rSrc)),
4456           (XSWDr64 (XSHWr16 (XSBHr8 R8C:$rSrc)))>;
4457
4458 // zext 8->16: Zero extend bytes to halfwords
4459 def : Pat<(i16 (zext R8C:$rSrc)),
4460           (ANDHIi8i16 R8C:$rSrc, 0xff)>;
4461
4462 // zext 8->32: Zero extend bytes to words
4463 def : Pat<(i32 (zext R8C:$rSrc)),
4464           (ANDIi8i32 R8C:$rSrc, 0xff)>;
4465
4466 // zext 8->64: Zero extend bytes to double words
4467 def : Pat<(i64 (zext R8C:$rSrc)),
4468           (ORi64_v2i64 (SELBv4i32 (ROTQMBYv4i32
4469                                     (ORv4i32_i32 (ANDIi8i32 R8C:$rSrc, 0xff)),
4470                                     0x4),
4471                                   (ILv4i32 0x0),
4472                                   (FSMBIv4i32 0x0f0f)))>;
4473
4474 // anyext 8->16: Extend 8->16 bits, irrespective of sign, preserves high bits
4475 def : Pat<(i16 (anyext R8C:$rSrc)),
4476           (ORHIi8i16 R8C:$rSrc, 0)>;
4477
4478 // anyext 8->32: Extend 8->32 bits, irrespective of sign, preserves high bits
4479 def : Pat<(i32 (anyext R8C:$rSrc)),
4480           (ORIi8i32 R8C:$rSrc, 0)>;
4481
4482 // sext 16->64: Sign extend halfword to double word
4483 def : Pat<(sext_inreg R64C:$rSrc, i16),
4484           (XSWDr64_inreg (XSHWr64 R64C:$rSrc))>;
4485           
4486 def : Pat<(sext R16C:$rSrc),
4487           (XSWDr64 (XSHWr16 R16C:$rSrc))>;
4488
4489 // zext 16->32: Zero extend halfwords to words
4490 def : Pat<(i32 (zext R16C:$rSrc)),
4491           (ANDi16i32 R16C:$rSrc, (ILAr32 0xffff))>;
4492
4493 def : Pat<(i32 (zext (and R16C:$rSrc, 0xf))),
4494           (ANDIi16i32 R16C:$rSrc, 0xf)>;
4495
4496 def : Pat<(i32 (zext (and R16C:$rSrc, 0xff))),
4497           (ANDIi16i32 R16C:$rSrc, 0xff)>;
4498
4499 def : Pat<(i32 (zext (and R16C:$rSrc, 0xfff))),
4500           (ANDIi16i32 R16C:$rSrc, 0xfff)>;
4501
4502 // anyext 16->32: Extend 16->32 bits, irrespective of sign
4503 def : Pat<(i32 (anyext R16C:$rSrc)),
4504           (ORIi16i32 R16C:$rSrc, 0)>;
4505
4506 //===----------------------------------------------------------------------===//
4507 // Truncates:
4508 // These truncates are for the SPU's supported types (i8, i16, i32). i64 and
4509 // above are custom lowered.
4510 //===----------------------------------------------------------------------===//
4511
4512 def : Pat<(i8 (trunc GPRC:$src)),
4513           (ORi8_v16i8
4514             (SHUFBgprc GPRC:$src, GPRC:$src,
4515                        (IOHLv4i32 (ILHUv4i32 0x0f0f), 0x0f0f)))>;
4516
4517 def : Pat<(i8 (trunc R64C:$src)),
4518           (ORi8_v16i8
4519             (SHUFBv2i64_m32
4520               (ORv2i64_i64 R64C:$src),
4521               (ORv2i64_i64 R64C:$src),
4522               (IOHLv4i32 (ILHUv4i32 0x0707), 0x0707)))>;
4523
4524 def : Pat<(i8 (trunc R32C:$src)),
4525           (ORi8_v16i8
4526             (SHUFBv4i32_m32
4527                (ORv4i32_i32 R32C:$src),
4528                (ORv4i32_i32 R32C:$src),
4529                (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4530
4531 def : Pat<(i8 (trunc R16C:$src)),
4532           (ORi8_v16i8
4533             (SHUFBv4i32_m32
4534                (ORv8i16_i16 R16C:$src),
4535                (ORv8i16_i16 R16C:$src),
4536                (IOHLv4i32 (ILHUv4i32 0x0303), 0x0303)))>;
4537
4538 def : Pat<(i16 (trunc GPRC:$src)),
4539           (ORi16_v8i16
4540             (SHUFBgprc GPRC:$src, GPRC:$src,
4541                        (IOHLv4i32 (ILHUv4i32 0x0e0f), 0x0e0f)))>;
4542
4543 def : Pat<(i16 (trunc R64C:$src)),
4544           (ORi16_v8i16
4545             (SHUFBv2i64_m32
4546               (ORv2i64_i64 R64C:$src),
4547               (ORv2i64_i64 R64C:$src),
4548               (IOHLv4i32 (ILHUv4i32 0x0607), 0x0607)))>;
4549
4550 def : Pat<(i16 (trunc R32C:$src)),
4551           (ORi16_v8i16
4552             (SHUFBv4i32_m32
4553                (ORv4i32_i32 R32C:$src),
4554                (ORv4i32_i32 R32C:$src),
4555                (IOHLv4i32 (ILHUv4i32 0x0203), 0x0203)))>;
4556
4557 def : Pat<(i32 (trunc GPRC:$src)),
4558           (ORi32_v4i32
4559             (SHUFBgprc GPRC:$src, GPRC:$src,
4560                        (IOHLv4i32 (ILHUv4i32 0x0c0d), 0x0e0f)))>;
4561
4562 def : Pat<(i32 (trunc R64C:$src)),
4563           (ORi32_v4i32
4564             (SHUFBv2i64_m32
4565               (ORv2i64_i64 R64C:$src),
4566               (ORv2i64_i64 R64C:$src),
4567               (IOHLv4i32 (ILHUv4i32 0x0405), 0x0607)))>;
4568
4569 //===----------------------------------------------------------------------===//
4570 // Address generation: SPU, like PPC, has to split addresses into high and
4571 // low parts in order to load them into a register.
4572 //===----------------------------------------------------------------------===//
4573
4574 def : Pat<(SPUaform tglobaladdr:$in, 0),  (ILAlsa tglobaladdr:$in)>;
4575 def : Pat<(SPUaform texternalsym:$in, 0), (ILAlsa texternalsym:$in)>;
4576 def : Pat<(SPUaform tjumptable:$in, 0),   (ILAlsa tjumptable:$in)>;
4577 def : Pat<(SPUaform tconstpool:$in, 0),   (ILAlsa  tconstpool:$in)>;
4578
4579 def : Pat<(SPUindirect (SPUhi tglobaladdr:$in, 0),
4580                        (SPUlo tglobaladdr:$in, 0)),
4581           (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4582
4583 def : Pat<(SPUindirect (SPUhi texternalsym:$in, 0),
4584                        (SPUlo texternalsym:$in, 0)),
4585           (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4586
4587 def : Pat<(SPUindirect (SPUhi tjumptable:$in, 0),
4588                        (SPUlo tjumptable:$in, 0)),
4589           (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4590
4591 def : Pat<(SPUindirect (SPUhi tconstpool:$in, 0),
4592                        (SPUlo tconstpool:$in, 0)),
4593           (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4594
4595 def : Pat<(add (SPUhi tglobaladdr:$in, 0), (SPUlo tglobaladdr:$in, 0)),
4596           (IOHLlo (ILHUhi tglobaladdr:$in), tglobaladdr:$in)>;
4597
4598 def : Pat<(add (SPUhi texternalsym:$in, 0), (SPUlo texternalsym:$in, 0)),
4599           (IOHLlo (ILHUhi texternalsym:$in), texternalsym:$in)>;
4600
4601 def : Pat<(add (SPUhi tjumptable:$in, 0), (SPUlo tjumptable:$in, 0)),
4602           (IOHLlo (ILHUhi tjumptable:$in), tjumptable:$in)>;
4603
4604 def : Pat<(add (SPUhi tconstpool:$in, 0), (SPUlo tconstpool:$in, 0)),
4605           (IOHLlo (ILHUhi tconstpool:$in), tconstpool:$in)>;
4606
4607 // Intrinsics:
4608 include "CellSDKIntrinsics.td"
4609 // Various math operator instruction sequences
4610 include "SPUMathInstr.td"
4611 // 64-bit "instructions"/support
4612 include "SPU64InstrInfo.td"
4613 // 128-bit "instructions"/support
4614 include "SPU128InstrInfo.td"