R600/SI: Start implementing an assembler
[oota-llvm.git] / lib / Target / R600 / AMDGPUInstructions.td
1 //===-- AMDGPUInstructions.td - Common instruction defs ---*- 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 //
10 // This file contains instruction defs that are common to all hw codegen
11 // targets.
12 //
13 //===----------------------------------------------------------------------===//
14
15 class AMDGPUInst <dag outs, dag ins, string asm, list<dag> pattern> : Instruction {
16   field bit isRegisterLoad = 0;
17   field bit isRegisterStore = 0;
18
19   let Namespace = "AMDGPU";
20   let OutOperandList = outs;
21   let InOperandList = ins;
22   let AsmString = asm;
23   let Pattern = pattern;
24   let Itinerary = NullALU;
25
26   let isCodeGenOnly = 1;
27
28   let TSFlags{63} = isRegisterLoad;
29   let TSFlags{62} = isRegisterStore;
30 }
31
32 class AMDGPUShaderInst <dag outs, dag ins, string asm, list<dag> pattern>
33     : AMDGPUInst<outs, ins, asm, pattern> {
34
35   field bits<32> Inst = 0xffffffff;
36
37 }
38
39 def FP32Denormals : Predicate<"Subtarget.hasFP32Denormals()">;
40 def FP64Denormals : Predicate<"Subtarget.hasFP64Denormals()">;
41 def UnsafeFPMath : Predicate<"TM.Options.UnsafeFPMath">;
42
43 def InstFlag : OperandWithDefaultOps <i32, (ops (i32 0))>;
44 def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
45
46 let OperandType = "OPERAND_IMMEDIATE" in {
47
48 def u32imm : Operand<i32> {
49   let PrintMethod = "printU32ImmOperand";
50 }
51
52 def u16imm : Operand<i16> {
53   let PrintMethod = "printU16ImmOperand";
54 }
55
56 def u8imm : Operand<i8> {
57   let PrintMethod = "printU8ImmOperand";
58 }
59
60 } // End OperandType = "OPERAND_IMMEDIATE"
61
62 //===--------------------------------------------------------------------===//
63 // Custom Operands
64 //===--------------------------------------------------------------------===//
65 def brtarget   : Operand<OtherVT>;
66
67 //===----------------------------------------------------------------------===//
68 // PatLeafs for floating-point comparisons
69 //===----------------------------------------------------------------------===//
70
71 def COND_OEQ : PatLeaf <
72   (cond),
73   [{return N->get() == ISD::SETOEQ || N->get() == ISD::SETEQ;}]
74 >;
75
76 def COND_OGT : PatLeaf <
77   (cond),
78   [{return N->get() == ISD::SETOGT || N->get() == ISD::SETGT;}]
79 >;
80
81 def COND_OGE : PatLeaf <
82   (cond),
83   [{return N->get() == ISD::SETOGE || N->get() == ISD::SETGE;}]
84 >;
85
86 def COND_OLT : PatLeaf <
87   (cond),
88   [{return N->get() == ISD::SETOLT || N->get() == ISD::SETLT;}]
89 >;
90
91 def COND_OLE : PatLeaf <
92   (cond),
93   [{return N->get() == ISD::SETOLE || N->get() == ISD::SETLE;}]
94 >;
95
96 def COND_UNE : PatLeaf <
97   (cond),
98   [{return N->get() == ISD::SETUNE || N->get() == ISD::SETNE;}]
99 >;
100
101 def COND_O : PatLeaf <(cond), [{return N->get() == ISD::SETO;}]>;
102 def COND_UO : PatLeaf <(cond), [{return N->get() == ISD::SETUO;}]>;
103
104 //===----------------------------------------------------------------------===//
105 // PatLeafs for unsigned comparisons
106 //===----------------------------------------------------------------------===//
107
108 def COND_UGT : PatLeaf <(cond), [{return N->get() == ISD::SETUGT;}]>;
109 def COND_UGE : PatLeaf <(cond), [{return N->get() == ISD::SETUGE;}]>;
110 def COND_ULT : PatLeaf <(cond), [{return N->get() == ISD::SETULT;}]>;
111 def COND_ULE : PatLeaf <(cond), [{return N->get() == ISD::SETULE;}]>;
112
113 //===----------------------------------------------------------------------===//
114 // PatLeafs for signed comparisons
115 //===----------------------------------------------------------------------===//
116
117 def COND_SGT : PatLeaf <(cond), [{return N->get() == ISD::SETGT;}]>;
118 def COND_SGE : PatLeaf <(cond), [{return N->get() == ISD::SETGE;}]>;
119 def COND_SLT : PatLeaf <(cond), [{return N->get() == ISD::SETLT;}]>;
120 def COND_SLE : PatLeaf <(cond), [{return N->get() == ISD::SETLE;}]>;
121
122 //===----------------------------------------------------------------------===//
123 // PatLeafs for integer equality
124 //===----------------------------------------------------------------------===//
125
126 def COND_EQ : PatLeaf <
127   (cond),
128   [{return N->get() == ISD::SETEQ || N->get() == ISD::SETUEQ;}]
129 >;
130
131 def COND_NE : PatLeaf <
132   (cond),
133   [{return N->get() == ISD::SETNE || N->get() == ISD::SETUNE;}]
134 >;
135
136 def COND_NULL : PatLeaf <
137   (cond),
138   [{(void)N; return false;}]
139 >;
140
141 //===----------------------------------------------------------------------===//
142 // Load/Store Pattern Fragments
143 //===----------------------------------------------------------------------===//
144
145 class PrivateMemOp <dag ops, dag frag> : PatFrag <ops, frag, [{
146   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS;
147 }]>;
148
149 class PrivateLoad <SDPatternOperator op> : PrivateMemOp <
150   (ops node:$ptr), (op node:$ptr)
151 >;
152
153 class PrivateStore <SDPatternOperator op> : PrivateMemOp <
154   (ops node:$value, node:$ptr), (op node:$value, node:$ptr)
155 >;
156
157 def extloadi8_private : PrivateLoad <extloadi8>;
158 def sextloadi8_private : PrivateLoad <sextloadi8>;
159 def extloadi16_private : PrivateLoad <extloadi16>;
160 def sextloadi16_private : PrivateLoad <sextloadi16>;
161 def load_private : PrivateLoad <load>;
162
163 def truncstorei8_private : PrivateStore <truncstorei8>;
164 def truncstorei16_private : PrivateStore <truncstorei16>;
165 def store_private : PrivateStore <store>;
166
167 def global_store : PatFrag<(ops node:$val, node:$ptr),
168     (store node:$val, node:$ptr), [{
169         return isGlobalStore(dyn_cast<StoreSDNode>(N));
170 }]>;
171
172 // Global address space loads
173 def global_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
174     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
175 }]>;
176
177 // Constant address space loads
178 def constant_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
179     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
180 }]>;
181
182 def az_extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
183   LoadSDNode *L = cast<LoadSDNode>(N);
184   return L->getExtensionType() == ISD::ZEXTLOAD ||
185          L->getExtensionType() == ISD::EXTLOAD;
186 }]>;
187
188 def az_extloadi8 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
189   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
190 }]>;
191
192 def az_extloadi8_global : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
193     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
194 }]>;
195
196 def sextloadi8_global : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
197     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
198 }]>;
199
200 def az_extloadi8_flat : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
201     return isFlatLoad(dyn_cast<LoadSDNode>(N));
202 }]>;
203
204 def sextloadi8_flat : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
205     return isFlatLoad(dyn_cast<LoadSDNode>(N));
206 }]>;
207
208 def az_extloadi8_constant : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
209     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
210 }]>;
211
212 def sextloadi8_constant : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
213     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
214 }]>;
215
216 def az_extloadi8_local : PatFrag<(ops node:$ptr), (az_extloadi8 node:$ptr), [{
217     return isLocalLoad(dyn_cast<LoadSDNode>(N));
218 }]>;
219
220 def sextloadi8_local : PatFrag<(ops node:$ptr), (sextloadi8 node:$ptr), [{
221     return isLocalLoad(dyn_cast<LoadSDNode>(N));
222 }]>;
223
224 def az_extloadi16 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
225   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
226 }]>;
227
228 def az_extloadi16_global : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
229     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
230 }]>;
231
232 def sextloadi16_global : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
233     return isGlobalLoad(dyn_cast<LoadSDNode>(N));
234 }]>;
235
236 def az_extloadi16_flat : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
237     return isFlatLoad(dyn_cast<LoadSDNode>(N));
238 }]>;
239
240 def sextloadi16_flat : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
241     return isFlatLoad(dyn_cast<LoadSDNode>(N));
242 }]>;
243
244 def az_extloadi16_constant : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
245     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
246 }]>;
247
248 def sextloadi16_constant : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
249     return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
250 }]>;
251
252 def az_extloadi16_local : PatFrag<(ops node:$ptr), (az_extloadi16 node:$ptr), [{
253     return isLocalLoad(dyn_cast<LoadSDNode>(N));
254 }]>;
255
256 def sextloadi16_local : PatFrag<(ops node:$ptr), (sextloadi16 node:$ptr), [{
257     return isLocalLoad(dyn_cast<LoadSDNode>(N));
258 }]>;
259
260 def az_extloadi32 : PatFrag<(ops node:$ptr), (az_extload node:$ptr), [{
261   return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
262 }]>;
263
264 def az_extloadi32_global : PatFrag<(ops node:$ptr),
265                                    (az_extloadi32 node:$ptr), [{
266   return isGlobalLoad(dyn_cast<LoadSDNode>(N));
267 }]>;
268
269 def az_extloadi32_flat : PatFrag<(ops node:$ptr),
270                                    (az_extloadi32 node:$ptr), [{
271   return isFlatLoad(dyn_cast<LoadSDNode>(N));
272 }]>;
273
274 def az_extloadi32_constant : PatFrag<(ops node:$ptr),
275                                      (az_extloadi32 node:$ptr), [{
276   return isConstantLoad(dyn_cast<LoadSDNode>(N), -1);
277 }]>;
278
279 def truncstorei8_global : PatFrag<(ops node:$val, node:$ptr),
280                                   (truncstorei8 node:$val, node:$ptr), [{
281   return isGlobalStore(dyn_cast<StoreSDNode>(N));
282 }]>;
283
284 def truncstorei16_global : PatFrag<(ops node:$val, node:$ptr),
285                                   (truncstorei16 node:$val, node:$ptr), [{
286   return isGlobalStore(dyn_cast<StoreSDNode>(N));
287 }]>;
288
289 def truncstorei8_flat : PatFrag<(ops node:$val, node:$ptr),
290                                   (truncstorei8 node:$val, node:$ptr), [{
291   return isFlatStore(dyn_cast<StoreSDNode>(N));
292 }]>;
293
294 def truncstorei16_flat : PatFrag<(ops node:$val, node:$ptr),
295                                   (truncstorei16 node:$val, node:$ptr), [{
296   return isFlatStore(dyn_cast<StoreSDNode>(N));
297 }]>;
298
299 def local_store : PatFrag<(ops node:$val, node:$ptr),
300                              (store node:$val, node:$ptr), [{
301   return isLocalStore(dyn_cast<StoreSDNode>(N));
302 }]>;
303
304 def truncstorei8_local : PatFrag<(ops node:$val, node:$ptr),
305                                   (truncstorei8 node:$val, node:$ptr), [{
306   return isLocalStore(dyn_cast<StoreSDNode>(N));
307 }]>;
308
309 def truncstorei16_local : PatFrag<(ops node:$val, node:$ptr),
310                                   (truncstorei16 node:$val, node:$ptr), [{
311   return isLocalStore(dyn_cast<StoreSDNode>(N));
312 }]>;
313
314 def local_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
315     return isLocalLoad(dyn_cast<LoadSDNode>(N));
316 }]>;
317
318 class Aligned8Bytes <dag ops, dag frag> : PatFrag <ops, frag, [{
319     return cast<MemSDNode>(N)->getAlignment() % 8 == 0;
320 }]>;
321
322 def local_load_aligned8bytes : Aligned8Bytes <
323   (ops node:$ptr), (local_load node:$ptr)
324 >;
325
326 def local_store_aligned8bytes : Aligned8Bytes <
327   (ops node:$val, node:$ptr), (local_store node:$val, node:$ptr)
328 >;
329
330 class local_binary_atomic_op<SDNode atomic_op> :
331   PatFrag<(ops node:$ptr, node:$value),
332     (atomic_op node:$ptr, node:$value), [{
333   return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
334 }]>;
335
336
337 def atomic_swap_local : local_binary_atomic_op<atomic_swap>;
338 def atomic_load_add_local : local_binary_atomic_op<atomic_load_add>;
339 def atomic_load_sub_local : local_binary_atomic_op<atomic_load_sub>;
340 def atomic_load_and_local : local_binary_atomic_op<atomic_load_and>;
341 def atomic_load_or_local : local_binary_atomic_op<atomic_load_or>;
342 def atomic_load_xor_local : local_binary_atomic_op<atomic_load_xor>;
343 def atomic_load_nand_local : local_binary_atomic_op<atomic_load_nand>;
344 def atomic_load_min_local : local_binary_atomic_op<atomic_load_min>;
345 def atomic_load_max_local : local_binary_atomic_op<atomic_load_max>;
346 def atomic_load_umin_local : local_binary_atomic_op<atomic_load_umin>;
347 def atomic_load_umax_local : local_binary_atomic_op<atomic_load_umax>;
348
349 def mskor_global : PatFrag<(ops node:$val, node:$ptr),
350                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
351   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;
352 }]>;
353
354
355 def atomic_cmp_swap_32_local :
356   PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
357           (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
358   AtomicSDNode *AN = cast<AtomicSDNode>(N);
359   return AN->getMemoryVT() == MVT::i32 &&
360          AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
361 }]>;
362
363 def atomic_cmp_swap_64_local :
364   PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
365           (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
366   AtomicSDNode *AN = cast<AtomicSDNode>(N);
367   return AN->getMemoryVT() == MVT::i64 &&
368          AN->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS;
369 }]>;
370
371 def flat_load : PatFrag<(ops node:$ptr), (load node:$ptr), [{
372     return isFlatLoad(dyn_cast<LoadSDNode>(N));
373 }]>;
374
375 def flat_store : PatFrag<(ops node:$val, node:$ptr),
376                          (store node:$val, node:$ptr), [{
377   return isFlatStore(dyn_cast<StoreSDNode>(N));
378 }]>;
379
380 def mskor_flat : PatFrag<(ops node:$val, node:$ptr),
381                             (AMDGPUstore_mskor node:$val, node:$ptr), [{
382   return dyn_cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::FLAT_ADDRESS;
383 }]>;
384
385 class global_binary_atomic_op<SDNode atomic_op> : PatFrag<
386   (ops node:$ptr, node:$value),
387   (atomic_op node:$ptr, node:$value),
388   [{return cast<MemSDNode>(N)->getAddressSpace() == AMDGPUAS::GLOBAL_ADDRESS;}]
389 >;
390
391 def atomic_swap_global : global_binary_atomic_op<atomic_swap>;
392 def atomic_add_global : global_binary_atomic_op<atomic_load_add>;
393 def atomic_and_global : global_binary_atomic_op<atomic_load_and>;
394 def atomic_max_global : global_binary_atomic_op<atomic_load_max>;
395 def atomic_min_global : global_binary_atomic_op<atomic_load_min>;
396 def atomic_or_global : global_binary_atomic_op<atomic_load_or>;
397 def atomic_sub_global : global_binary_atomic_op<atomic_load_sub>;
398 def atomic_umax_global : global_binary_atomic_op<atomic_load_umax>;
399 def atomic_umin_global : global_binary_atomic_op<atomic_load_umin>;
400 def atomic_xor_global : global_binary_atomic_op<atomic_load_xor>;
401
402 //===----------------------------------------------------------------------===//
403 // Misc Pattern Fragments
404 //===----------------------------------------------------------------------===//
405
406 def fmad : PatFrag <
407   (ops node:$src0, node:$src1, node:$src2),
408   (fadd (fmul node:$src0, node:$src1), node:$src2)
409 >;
410
411 class Constants {
412 int TWO_PI = 0x40c90fdb;
413 int PI = 0x40490fdb;
414 int TWO_PI_INV = 0x3e22f983;
415 int FP_UINT_MAX_PLUS_1 = 0x4f800000;    // 1 << 32 in floating point encoding
416 int FP32_NEG_ONE = 0xbf800000;
417 int FP32_ONE = 0x3f800000;
418 }
419 def CONST : Constants;
420
421 def FP_ZERO : PatLeaf <
422   (fpimm),
423   [{return N->getValueAPF().isZero();}]
424 >;
425
426 def FP_ONE : PatLeaf <
427   (fpimm),
428   [{return N->isExactlyValue(1.0);}]
429 >;
430
431 let isCodeGenOnly = 1, isPseudo = 1 in {
432
433 let usesCustomInserter = 1  in {
434
435 class CLAMP <RegisterClass rc> : AMDGPUShaderInst <
436   (outs rc:$dst),
437   (ins rc:$src0),
438   "CLAMP $dst, $src0",
439   [(set f32:$dst, (AMDGPUclamp f32:$src0, (f32 FP_ZERO), (f32 FP_ONE)))]
440 >;
441
442 class FABS <RegisterClass rc> : AMDGPUShaderInst <
443   (outs rc:$dst),
444   (ins rc:$src0),
445   "FABS $dst, $src0",
446   [(set f32:$dst, (fabs f32:$src0))]
447 >;
448
449 class FNEG <RegisterClass rc> : AMDGPUShaderInst <
450   (outs rc:$dst),
451   (ins rc:$src0),
452   "FNEG $dst, $src0",
453   [(set f32:$dst, (fneg f32:$src0))]
454 >;
455
456 } // usesCustomInserter = 1
457
458 multiclass RegisterLoadStore <RegisterClass dstClass, Operand addrClass,
459                     ComplexPattern addrPat> {
460 let UseNamedOperandTable = 1 in {
461
462   def RegisterLoad : AMDGPUShaderInst <
463     (outs dstClass:$dst),
464     (ins addrClass:$addr, i32imm:$chan),
465     "RegisterLoad $dst, $addr",
466     [(set i32:$dst, (AMDGPUregister_load addrPat:$addr, (i32 timm:$chan)))]
467   > {
468     let isRegisterLoad = 1;
469   }
470
471   def RegisterStore : AMDGPUShaderInst <
472     (outs),
473     (ins dstClass:$val, addrClass:$addr, i32imm:$chan),
474     "RegisterStore $val, $addr",
475     [(AMDGPUregister_store i32:$val, addrPat:$addr, (i32 timm:$chan))]
476   > {
477     let isRegisterStore = 1;
478   }
479 }
480 }
481
482 } // End isCodeGenOnly = 1, isPseudo = 1
483
484 /* Generic helper patterns for intrinsics */
485 /* -------------------------------------- */
486
487 class POW_Common <AMDGPUInst log_ieee, AMDGPUInst exp_ieee, AMDGPUInst mul>
488   : Pat <
489   (fpow f32:$src0, f32:$src1),
490   (exp_ieee (mul f32:$src1, (log_ieee f32:$src0)))
491 >;
492
493 /* Other helper patterns */
494 /* --------------------- */
495
496 /* Extract element pattern */
497 class Extract_Element <ValueType sub_type, ValueType vec_type, int sub_idx,
498                        SubRegIndex sub_reg>
499   : Pat<
500   (sub_type (vector_extract vec_type:$src, sub_idx)),
501   (EXTRACT_SUBREG $src, sub_reg)
502 >;
503
504 /* Insert element pattern */
505 class Insert_Element <ValueType elem_type, ValueType vec_type,
506                       int sub_idx, SubRegIndex sub_reg>
507   : Pat <
508   (vector_insert vec_type:$vec, elem_type:$elem, sub_idx),
509   (INSERT_SUBREG $vec, $elem, sub_reg)
510 >;
511
512 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
513 // can handle COPY instructions.
514 // bitconvert pattern
515 class BitConvert <ValueType dt, ValueType st, RegisterClass rc> : Pat <
516   (dt (bitconvert (st rc:$src0))),
517   (dt rc:$src0)
518 >;
519
520 // XXX: Convert to new syntax and use COPY_TO_REG, once the DFAPacketizer
521 // can handle COPY instructions.
522 class DwordAddrPat<ValueType vt, RegisterClass rc> : Pat <
523   (vt (AMDGPUdwordaddr (vt rc:$addr))),
524   (vt rc:$addr)
525 >;
526
527 // BFI_INT patterns
528
529 multiclass BFIPatterns <Instruction BFI_INT,
530                         Instruction LoadImm32,
531                         RegisterClass RC64> {
532   // Definition from ISA doc:
533   // (y & x) | (z & ~x)
534   def : Pat <
535     (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
536     (BFI_INT $x, $y, $z)
537   >;
538
539   // SHA-256 Ch function
540   // z ^ (x & (y ^ z))
541   def : Pat <
542     (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
543     (BFI_INT $x, $y, $z)
544   >;
545
546   def : Pat <
547     (fcopysign f32:$src0, f32:$src1),
548     (BFI_INT (LoadImm32 0x7fffffff), $src0, $src1)
549   >;
550
551   def : Pat <
552     (f64 (fcopysign f64:$src0, f64:$src1)),
553     (REG_SEQUENCE RC64,
554       (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
555       (BFI_INT (LoadImm32 0x7fffffff),
556                (i32 (EXTRACT_SUBREG $src0, sub1)),
557                (i32 (EXTRACT_SUBREG $src1, sub1))), sub1)
558   >;
559 }
560
561 // SHA-256 Ma patterns
562
563 // ((x & z) | (y & (x | z))) -> BFI_INT (XOR x, y), z, y
564 class SHA256MaPattern <Instruction BFI_INT, Instruction XOR> : Pat <
565   (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
566   (BFI_INT (XOR i32:$x, i32:$y), i32:$z, i32:$y)
567 >;
568
569 // Bitfield extract patterns
570
571 /*
572
573 XXX: The BFE pattern is not working correctly because the XForm is not being
574 applied.
575
576 def legalshift32 : ImmLeaf <i32, [{return Imm >=0 && Imm < 32;}]>;
577 def bfemask : PatLeaf <(imm), [{return isMask_32(N->getZExtValue());}],
578                             SDNodeXForm<imm, [{ return CurDAG->getTargetConstant(CountTrailingOnes_32(N->getZExtValue()), MVT::i32);}]>>;
579
580 class BFEPattern <Instruction BFE> : Pat <
581   (and (srl i32:$x, legalshift32:$y), bfemask:$z),
582   (BFE $x, $y, $z)
583 >;
584
585 */
586
587 // rotr pattern
588 class ROTRPattern <Instruction BIT_ALIGN> : Pat <
589   (rotr i32:$src0, i32:$src1),
590   (BIT_ALIGN $src0, $src0, $src1)
591 >;
592
593 // 24-bit arithmetic patterns
594 def umul24 : PatFrag <(ops node:$x, node:$y), (mul node:$x, node:$y)>;
595
596 /*
597 class UMUL24Pattern <Instruction UMUL24> : Pat <
598   (mul U24:$x, U24:$y),
599   (UMUL24 $x, $y)
600 >;
601 */
602
603 class IMad24Pat<Instruction Inst> : Pat <
604   (add (AMDGPUmul_i24 i32:$src0, i32:$src1), i32:$src2),
605   (Inst $src0, $src1, $src2)
606 >;
607
608 class UMad24Pat<Instruction Inst> : Pat <
609   (add (AMDGPUmul_u24 i32:$src0, i32:$src1), i32:$src2),
610   (Inst $src0, $src1, $src2)
611 >;
612
613 multiclass Expand24IBitOps<Instruction MulInst, Instruction AddInst> {
614   def _expand_imad24 : Pat <
615     (AMDGPUmad_i24 i32:$src0, i32:$src1, i32:$src2),
616     (AddInst (MulInst $src0, $src1), $src2)
617   >;
618
619   def _expand_imul24 : Pat <
620     (AMDGPUmul_i24 i32:$src0, i32:$src1),
621     (MulInst $src0, $src1)
622   >;
623 }
624
625 multiclass Expand24UBitOps<Instruction MulInst, Instruction AddInst> {
626   def _expand_umad24 : Pat <
627     (AMDGPUmad_u24 i32:$src0, i32:$src1, i32:$src2),
628     (AddInst (MulInst $src0, $src1), $src2)
629   >;
630
631   def _expand_umul24 : Pat <
632     (AMDGPUmul_u24 i32:$src0, i32:$src1),
633     (MulInst $src0, $src1)
634   >;
635 }
636
637 class RcpPat<Instruction RcpInst, ValueType vt> : Pat <
638   (fdiv FP_ONE, vt:$src),
639   (RcpInst $src)
640 >;
641
642 multiclass RsqPat<Instruction RsqInst, ValueType vt> {
643   def : Pat <
644     (fdiv FP_ONE, (fsqrt vt:$src)),
645     (RsqInst $src)
646   >;
647
648   def : Pat <
649     (AMDGPUrcp (fsqrt vt:$src)),
650     (RsqInst $src)
651   >;
652 }
653
654 include "R600Instructions.td"
655 include "R700Instructions.td"
656 include "EvergreenInstructions.td"
657 include "CaymanInstructions.td"
658
659 include "SIInstrInfo.td"
660