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