1 //===-- R600Instructions.td - R600 Instruction defs -------*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // R600 Tablegen instruction definitions
12 //===----------------------------------------------------------------------===//
14 include "R600Intrinsics.td"
16 class InstR600 <bits<11> inst, dag outs, dag ins, string asm, list<dag> pattern,
18 : AMDGPUInst <outs, ins, asm, pattern> {
24 bits<2> FlagOperandIdx = 0;
27 bit HasNativeOperands = 0;
29 bits<11> op_code = inst;
31 let Namespace = "AMDGPU";
32 let OutOperandList = outs;
33 let InOperandList = ins;
35 let Pattern = pattern;
38 let TSFlags{4} = Trig;
41 // Vector instructions are instructions that must fill all slots in an
43 let TSFlags{6} = isVector;
44 let TSFlags{8-7} = FlagOperandIdx;
45 let TSFlags{9} = HasNativeOperands;
46 let TSFlags{10} = Op1;
47 let TSFlags{11} = Op2;
50 class InstR600ISA <dag outs, dag ins, string asm, list<dag> pattern> :
51 AMDGPUInst <outs, ins, asm, pattern> {
54 let Namespace = "AMDGPU";
57 def MEMxi : Operand<iPTR> {
58 let MIOperandInfo = (ops R600_TReg32_X:$ptr, i32imm:$index);
59 let PrintMethod = "printMemOperand";
62 def MEMrr : Operand<iPTR> {
63 let MIOperandInfo = (ops R600_Reg32:$ptr, R600_Reg32:$index);
66 // Operands for non-registers
68 class InstFlag<string PM = "printOperand", int Default = 0>
69 : OperandWithDefaultOps <i32, (ops (i32 Default))> {
73 def LITERAL : InstFlag<"printLiteral">;
75 def WRITE : InstFlag <"printWrite", 1>;
76 def OMOD : InstFlag <"printOMOD">;
77 def REL : InstFlag <"printRel">;
78 def CLAMP : InstFlag <"printClamp">;
79 def NEG : InstFlag <"printNeg">;
80 def ABS : InstFlag <"printAbs">;
81 def UEM : InstFlag <"printUpdateExecMask">;
82 def UP : InstFlag <"printUpdatePred">;
84 // XXX: The r600g finalizer in Mesa expects last to be one in most cases.
85 // Once we start using the packetizer in this backend we should have this
87 def LAST : InstFlag<"printLast", 1>;
89 def ADDRParam : ComplexPattern<i32, 2, "SelectADDRParam", [], []>;
90 def ADDRDWord : ComplexPattern<i32, 1, "SelectADDRDWord", [], []>;
91 def ADDRVTX_READ : ComplexPattern<i32, 2, "SelectADDRVTX_READ", [], []>;
102 bits<3> index_mode = 0;
106 bits<9> src0_sel = src0{8-0};
107 bits<2> src0_chan = src0{10-9};
108 bits<9> src1_sel = src1{8-0};
109 bits<2> src1_chan = src1{10-9};
111 let Word0{8-0} = src0_sel;
112 let Word0{9} = src0_rel;
113 let Word0{11-10} = src0_chan;
114 let Word0{12} = src0_neg;
115 let Word0{21-13} = src1_sel;
116 let Word0{22} = src1_rel;
117 let Word0{24-23} = src1_chan;
118 let Word0{25} = src1_neg;
119 let Word0{28-26} = index_mode;
120 let Word0{30-29} = pred_sel;
121 let Word0{31} = last;
124 class R600ALU_Word1 {
125 field bits<32> Word1;
128 bits<3> bank_swizzle = 0;
132 bits<7> dst_sel = dst{6-0};
133 bits<2> dst_chan = dst{10-9};
135 let Word1{20-18} = bank_swizzle;
136 let Word1{27-21} = dst_sel;
137 let Word1{28} = dst_rel;
138 let Word1{30-29} = dst_chan;
139 let Word1{31} = clamp;
142 class R600ALU_Word1_OP2 <bits<11> alu_inst> : R600ALU_Word1{
146 bits<1> update_exec_mask;
151 let Word1{0} = src0_abs;
152 let Word1{1} = src1_abs;
153 let Word1{2} = update_exec_mask;
154 let Word1{3} = update_pred;
155 let Word1{4} = write;
156 let Word1{6-5} = omod;
157 let Word1{17-7} = alu_inst;
160 class R600ALU_Word1_OP3 <bits<5> alu_inst> : R600ALU_Word1{
166 bits<9> src2_sel = src2{8-0};
167 bits<2> src2_chan = src2{10-9};
169 let Word1{8-0} = src2_sel;
170 let Word1{9} = src2_rel;
171 let Word1{11-10} = src2_chan;
172 let Word1{12} = src2_neg;
173 let Word1{17-13} = alu_inst;
177 XXX: R600 subtarget uses a slightly different encoding than the other
178 subtargets. We currently handle this in R600MCCodeEmitter, but we may
179 want to use these instruction classes in the future.
181 class R600ALU_Word1_OP2_r600 : R600ALU_Word1_OP2 {
186 let Inst{37} = fog_merge;
187 let Inst{39-38} = omod;
188 let Inst{49-40} = alu_inst;
191 class R600ALU_Word1_OP2_r700 : R600ALU_Word1_OP2 {
195 let Inst{38-37} = omod;
196 let Inst{49-39} = alu_inst;
200 def R600_Pred : PredicateOperand<i32, (ops R600_Predicate),
204 let mayLoad = 0, mayStore = 0, hasSideEffects = 0 in {
206 // Class for instructions with only one source register.
207 // If you add new ins to this instruction, make sure they are listed before
208 // $literal, because the backend currently assumes that the last operand is
209 // a literal. Also be sure to update the enum R600Op1OperandIndex::ROI in
210 // R600Defines.h, R600InstrInfo::buildDefaultInstruction(),
211 // and R600InstrInfo::getOperandIdx().
212 class R600_1OP <bits<11> inst, string opName, list<dag> pattern,
213 InstrItinClass itin = AnyALU> :
215 (outs R600_Reg32:$dst),
216 (ins WRITE:$write, OMOD:$omod, REL:$dst_rel, CLAMP:$clamp,
217 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel, ABS:$src0_abs,
218 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal),
220 "$clamp $dst$write$dst_rel$omod, "
221 "$src0_neg$src0_abs$src0$src0_abs$src0_rel, "
222 "$literal $pred_sel$last"),
226 R600ALU_Word1_OP2 <inst> {
232 let update_exec_mask = 0;
234 let HasNativeOperands = 1;
236 let DisableEncoding = "$literal";
238 let Inst{31-0} = Word0;
239 let Inst{63-32} = Word1;
242 class R600_1OP_Helper <bits<11> inst, string opName, SDPatternOperator node,
243 InstrItinClass itin = AnyALU> :
244 R600_1OP <inst, opName,
245 [(set R600_Reg32:$dst, (node R600_Reg32:$src0))]
248 // If you add our change the operands for R600_2OP instructions, you must
249 // also update the R600Op2OperandIndex::ROI enum in R600Defines.h,
250 // R600InstrInfo::buildDefaultInstruction(), and R600InstrInfo::getOperandIdx().
251 class R600_2OP <bits<11> inst, string opName, list<dag> pattern,
252 InstrItinClass itin = AnyALU> :
254 (outs R600_Reg32:$dst),
255 (ins UEM:$update_exec_mask, UP:$update_pred, WRITE:$write,
256 OMOD:$omod, REL:$dst_rel, CLAMP:$clamp,
257 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel, ABS:$src0_abs,
258 R600_Reg32:$src1, NEG:$src1_neg, REL:$src1_rel, ABS:$src1_abs,
259 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal),
261 "$clamp $update_exec_mask$update_pred$dst$write$dst_rel$omod, "
262 "$src0_neg$src0_abs$src0$src0_abs$src0_rel, "
263 "$src1_neg$src1_abs$src1$src1_abs$src1_rel, "
264 "$literal $pred_sel$last"),
268 R600ALU_Word1_OP2 <inst> {
270 let HasNativeOperands = 1;
272 let DisableEncoding = "$literal";
274 let Inst{31-0} = Word0;
275 let Inst{63-32} = Word1;
278 class R600_2OP_Helper <bits<11> inst, string opName, SDPatternOperator node,
279 InstrItinClass itim = AnyALU> :
280 R600_2OP <inst, opName,
281 [(set R600_Reg32:$dst, (node R600_Reg32:$src0,
285 // If you add our change the operands for R600_3OP instructions, you must
286 // also update the R600Op3OperandIndex::ROI enum in R600Defines.h,
287 // R600InstrInfo::buildDefaultInstruction(), and
288 // R600InstrInfo::getOperandIdx().
289 class R600_3OP <bits<5> inst, string opName, list<dag> pattern,
290 InstrItinClass itin = AnyALU> :
292 (outs R600_Reg32:$dst),
293 (ins REL:$dst_rel, CLAMP:$clamp,
294 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel,
295 R600_Reg32:$src1, NEG:$src1_neg, REL:$src1_rel,
296 R600_Reg32:$src2, NEG:$src2_neg, REL:$src2_rel,
297 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal),
298 !strconcat(opName, "$clamp $dst$dst_rel, "
299 "$src0_neg$src0$src0_rel, "
300 "$src1_neg$src1$src1_rel, "
301 "$src2_neg$src2$src2_rel, "
302 "$literal $pred_sel$last"),
306 R600ALU_Word1_OP3<inst>{
308 let HasNativeOperands = 1;
309 let DisableEncoding = "$literal";
312 let Inst{31-0} = Word0;
313 let Inst{63-32} = Word1;
316 class R600_REDUCTION <bits<11> inst, dag ins, string asm, list<dag> pattern,
317 InstrItinClass itin = VecALU> :
319 (outs R600_Reg32:$dst),
325 class R600_TEX <bits<11> inst, string opName, list<dag> pattern,
326 InstrItinClass itin = AnyALU> :
328 (outs R600_Reg128:$dst),
329 (ins R600_Reg128:$src0, i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget),
330 !strconcat(opName, "$dst, $src0, $resourceId, $samplerId, $textureTarget"),
333 let Inst {10-0} = inst;
336 } // End mayLoad = 1, mayStore = 0, hasSideEffects = 0
338 def TEX_SHADOW : PatLeaf<
340 [{uint32_t TType = (uint32_t)N->getZExtValue();
341 return (TType >= 6 && TType <= 8) || (TType >= 11 && TType <= 13);
345 class EG_CF_RAT <bits <8> cf_inst, bits <6> rat_inst, bits<4> rat_id, dag outs,
346 dag ins, string asm, list<dag> pattern> :
347 InstR600ISA <outs, ins, asm, pattern> {
364 // CF_ALLOC_EXPORT_WORD0_RAT
365 let Inst{3-0} = rat_id;
366 let Inst{9-4} = rat_inst;
367 let Inst{10} = 0; // Reserved
368 let Inst{12-11} = RIM;
369 let Inst{14-13} = TYPE;
370 let Inst{21-15} = RW_GPR;
371 let Inst{22} = RW_REL;
372 let Inst{29-23} = INDEX_GPR;
373 let Inst{31-30} = ELEM_SIZE;
375 // CF_ALLOC_EXPORT_WORD1_BUF
376 let Inst{43-32} = ARRAY_SIZE;
377 let Inst{47-44} = COMP_MASK;
378 let Inst{51-48} = BURST_COUNT;
381 let Inst{61-54} = cf_inst;
383 let Inst{63} = BARRIER;
386 class LoadParamFrag <PatFrag load_type> : PatFrag <
387 (ops node:$ptr), (load_type node:$ptr),
388 [{ return isParamLoad(dyn_cast<LoadSDNode>(N)); }]
391 def load_param : LoadParamFrag<load>;
392 def load_param_zexti8 : LoadParamFrag<zextloadi8>;
393 def load_param_zexti16 : LoadParamFrag<zextloadi16>;
395 def isR600 : Predicate<"Subtarget.device()"
396 "->getGeneration() == AMDGPUDeviceInfo::HD4XXX">;
397 def isR700 : Predicate<"Subtarget.device()"
398 "->getGeneration() == AMDGPUDeviceInfo::HD4XXX &&"
399 "Subtarget.device()->getDeviceFlag()"
400 ">= OCL_DEVICE_RV710">;
401 def isEG : Predicate<
402 "Subtarget.device()->getGeneration() >= AMDGPUDeviceInfo::HD5XXX && "
403 "Subtarget.device()->getGeneration() < AMDGPUDeviceInfo::HD7XXX && "
404 "Subtarget.device()->getDeviceFlag() != OCL_DEVICE_CAYMAN">;
406 def isCayman : Predicate<"Subtarget.device()"
407 "->getDeviceFlag() == OCL_DEVICE_CAYMAN">;
408 def isEGorCayman : Predicate<"Subtarget.device()"
409 "->getGeneration() == AMDGPUDeviceInfo::HD5XXX"
410 "|| Subtarget.device()->getGeneration() =="
411 "AMDGPUDeviceInfo::HD6XXX">;
413 def isR600toCayman : Predicate<
414 "Subtarget.device()->getGeneration() <= AMDGPUDeviceInfo::HD6XXX">;
416 //===----------------------------------------------------------------------===//
417 // Interpolation Instructions
418 //===----------------------------------------------------------------------===//
420 def INTERP: SDNode<"AMDGPUISD::INTERP",
421 SDTypeProfile<1, 2, [SDTCisFP<0>, SDTCisInt<1>, SDTCisInt<2>]>
424 def INTERP_P0: SDNode<"AMDGPUISD::INTERP_P0",
425 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisInt<1>]>
428 let usesCustomInserter = 1 in {
429 def input_perspective : AMDGPUShaderInst <
430 (outs R600_Reg128:$dst),
431 (ins i32imm:$src0, i32imm:$src1),
432 "input_perspective $src0 $src1 : dst",
433 [(set R600_Reg128:$dst, (INTERP (i32 imm:$src0), (i32 imm:$src1)))]>;
434 } // End usesCustomInserter = 1
436 def input_constant : AMDGPUShaderInst <
437 (outs R600_Reg128:$dst),
439 "input_perspective $src : dst",
440 [(set R600_Reg128:$dst, (INTERP_P0 (i32 imm:$src)))]>;
444 def INTERP_XY : R600_2OP <0xD6, "INTERP_XY", []> {
445 let bank_swizzle = 5;
448 def INTERP_ZW : R600_2OP <0xD7, "INTERP_ZW", []> {
449 let bank_swizzle = 5;
452 def INTERP_LOAD_P0 : R600_1OP <0xE0, "INTERP_LOAD_P0", []>;
454 //===----------------------------------------------------------------------===//
455 // Export Instructions
456 //===----------------------------------------------------------------------===//
458 def ExportType : SDTypeProfile<0, 5, [SDTCisFP<0>, SDTCisInt<1>]>;
460 def EXPORT: SDNode<"AMDGPUISD::EXPORT", ExportType,
461 [SDNPHasChain, SDNPSideEffect]>;
464 field bits<32> Word0;
471 let Word0{12-0} = arraybase;
472 let Word0{14-13} = type;
473 let Word0{21-15} = gpr;
474 let Word0{22} = 0; // RW_REL
475 let Word0{29-23} = 0; // INDEX_GPR
476 let Word0{31-30} = elem_size;
479 class ExportSwzWord1 {
480 field bits<32> Word1;
489 let Word1{2-0} = sw_x;
490 let Word1{5-3} = sw_y;
491 let Word1{8-6} = sw_z;
492 let Word1{11-9} = sw_w;
495 class ExportBufWord1 {
496 field bits<32> Word1;
503 let Word1{11-0} = arraySize;
504 let Word1{15-12} = compMask;
507 multiclass ExportPattern<Instruction ExportInst, bits<8> cf_inst> {
508 def : Pat<(int_R600_store_pixel_depth R600_Reg32:$reg),
510 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), R600_Reg32:$reg, sel_x),
511 0, 61, 0, 7, 7, 7, cf_inst, 0)
514 def : Pat<(int_R600_store_pixel_stencil R600_Reg32:$reg),
516 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), R600_Reg32:$reg, sel_x),
517 0, 61, 7, 0, 7, 7, cf_inst, 0)
520 def : Pat<(int_R600_store_pixel_dummy),
522 (v4f32 (IMPLICIT_DEF)), 0, 0, 7, 7, 7, 7, cf_inst, 0)
525 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 0),
526 (i32 imm:$type), (i32 imm:$arraybase), (i32 imm)),
527 (ExportInst R600_Reg128:$src, imm:$type, imm:$arraybase,
528 0, 1, 2, 3, cf_inst, 0)
532 multiclass SteamOutputExportPattern<Instruction ExportInst,
533 bits<8> buf0inst, bits<8> buf1inst, bits<8> buf2inst, bits<8> buf3inst> {
535 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 1),
536 (i32 imm:$type), (i32 imm:$arraybase), (i32 imm:$mask)),
537 (ExportInst R600_Reg128:$src, imm:$type, imm:$arraybase,
538 4095, imm:$mask, buf0inst, 0)>;
540 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 2),
541 (i32 imm:$type), (i32 imm:$arraybase), (i32 imm:$mask)),
542 (ExportInst R600_Reg128:$src, imm:$type, imm:$arraybase,
543 4095, imm:$mask, buf1inst, 0)>;
545 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 3),
546 (i32 imm:$type), (i32 imm:$arraybase), (i32 imm:$mask)),
547 (ExportInst R600_Reg128:$src, imm:$type, imm:$arraybase,
548 4095, imm:$mask, buf2inst, 0)>;
550 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 4),
551 (i32 imm:$type), (i32 imm:$arraybase), (i32 imm:$mask)),
552 (ExportInst R600_Reg128:$src, imm:$type, imm:$arraybase,
553 4095, imm:$mask, buf3inst, 0)>;
556 let isTerminator = 1, usesCustomInserter = 1 in {
558 class ExportSwzInst : InstR600ISA<(
560 (ins R600_Reg128:$gpr, i32imm:$type, i32imm:$arraybase,
561 i32imm:$sw_x, i32imm:$sw_y, i32imm:$sw_z, i32imm:$sw_w, i32imm:$inst,
563 !strconcat("EXPORT", " $gpr"),
564 []>, ExportWord0, ExportSwzWord1 {
566 let Inst{31-0} = Word0;
567 let Inst{63-32} = Word1;
570 } // End isTerminator = 1, usesCustomInserter = 1
572 class ExportBufInst : InstR600ISA<(
574 (ins R600_Reg128:$gpr, i32imm:$type, i32imm:$arraybase,
575 i32imm:$arraySize, i32imm:$compMask, i32imm:$inst, i32imm:$eop),
576 !strconcat("EXPORT", " $gpr"),
577 []>, ExportWord0, ExportBufWord1 {
579 let Inst{31-0} = Word0;
580 let Inst{63-32} = Word1;
583 let Predicates = [isR600toCayman] in {
585 //===----------------------------------------------------------------------===//
586 // Common Instructions R600, R700, Evergreen, Cayman
587 //===----------------------------------------------------------------------===//
589 def ADD : R600_2OP_Helper <0x0, "ADD", fadd>;
590 // Non-IEEE MUL: 0 * anything = 0
591 def MUL : R600_2OP_Helper <0x1, "MUL NON-IEEE", int_AMDGPU_mul>;
592 def MUL_IEEE : R600_2OP_Helper <0x2, "MUL_IEEE", fmul>;
593 def MAX : R600_2OP_Helper <0x3, "MAX", AMDGPUfmax>;
594 def MIN : R600_2OP_Helper <0x4, "MIN", AMDGPUfmin>;
596 // For the SET* instructions there is a naming conflict in TargetSelectionDAG.td,
597 // so some of the instruction names don't match the asm string.
598 // XXX: Use the defs in TargetSelectionDAG.td instead of intrinsics.
599 def SETE : R600_2OP <
601 [(set R600_Reg32:$dst,
602 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO,
608 [(set R600_Reg32:$dst,
609 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO,
615 [(set R600_Reg32:$dst,
616 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO,
622 [(set R600_Reg32:$dst,
623 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO,
627 def FRACT : R600_1OP_Helper <0x10, "FRACT", AMDGPUfract>;
628 def TRUNC : R600_1OP_Helper <0x11, "TRUNC", int_AMDGPU_trunc>;
629 def CEIL : R600_1OP_Helper <0x12, "CEIL", fceil>;
630 def RNDNE : R600_1OP_Helper <0x13, "RNDNE", frint>;
631 def FLOOR : R600_1OP_Helper <0x14, "FLOOR", ffloor>;
633 def MOV : R600_1OP <0x19, "MOV", []>;
635 let isPseudo = 1, isCodeGenOnly = 1, usesCustomInserter = 1 in {
637 class MOV_IMM <ValueType vt, Operand immType> : AMDGPUInst <
638 (outs R600_Reg32:$dst),
644 } // end let isPseudo = 1, isCodeGenOnly = 1, usesCustomInserter = 1
646 def MOV_IMM_I32 : MOV_IMM<i32, i32imm>;
649 (MOV_IMM_I32 imm:$val)
652 def MOV_IMM_F32 : MOV_IMM<f32, f32imm>;
655 (MOV_IMM_F32 fpimm:$val)
658 def PRED_SETE : R600_2OP <0x20, "PRED_SETE", []>;
659 def PRED_SETGT : R600_2OP <0x21, "PRED_SETGT", []>;
660 def PRED_SETGE : R600_2OP <0x22, "PRED_SETGE", []>;
661 def PRED_SETNE : R600_2OP <0x23, "PRED_SETNE", []>;
663 let hasSideEffects = 1 in {
665 def KILLGT : R600_2OP <0x2D, "KILLGT", []>;
667 } // end hasSideEffects
669 def AND_INT : R600_2OP_Helper <0x30, "AND_INT", and>;
670 def OR_INT : R600_2OP_Helper <0x31, "OR_INT", or>;
671 def XOR_INT : R600_2OP_Helper <0x32, "XOR_INT", xor>;
672 def NOT_INT : R600_1OP_Helper <0x33, "NOT_INT", not>;
673 def ADD_INT : R600_2OP_Helper <0x34, "ADD_INT", add>;
674 def SUB_INT : R600_2OP_Helper <0x35, "SUB_INT", sub>;
675 def MAX_INT : R600_2OP_Helper <0x36, "MAX_INT", AMDGPUsmax>;
676 def MIN_INT : R600_2OP_Helper <0x37, "MIN_INT", AMDGPUsmin>;
677 def MAX_UINT : R600_2OP_Helper <0x38, "MAX_UINT", AMDGPUsmax>;
678 def MIN_UINT : R600_2OP_Helper <0x39, "MIN_UINT", AMDGPUumin>;
680 def SETE_INT : R600_2OP <
682 [(set (i32 R600_Reg32:$dst),
683 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETEQ))]
686 def SETGT_INT : R600_2OP <
688 [(set (i32 R600_Reg32:$dst),
689 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETGT))]
692 def SETGE_INT : R600_2OP <
694 [(set (i32 R600_Reg32:$dst),
695 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETGE))]
698 def SETNE_INT : R600_2OP <
700 [(set (i32 R600_Reg32:$dst),
701 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETNE))]
704 def SETGT_UINT : R600_2OP <
706 [(set (i32 R600_Reg32:$dst),
707 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETUGT))]
710 def SETGE_UINT : R600_2OP <
712 [(set (i32 R600_Reg32:$dst),
713 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETUGE))]
716 def PRED_SETE_INT : R600_2OP <0x42, "PRED_SETE_INT", []>;
717 def PRED_SETGT_INT : R600_2OP <0x43, "PRED_SETGE_INT", []>;
718 def PRED_SETGE_INT : R600_2OP <0x44, "PRED_SETGE_INT", []>;
719 def PRED_SETNE_INT : R600_2OP <0x45, "PRED_SETNE_INT", []>;
721 def CNDE_INT : R600_3OP <
723 [(set (i32 R600_Reg32:$dst),
724 (selectcc (i32 R600_Reg32:$src0), 0,
725 (i32 R600_Reg32:$src1), (i32 R600_Reg32:$src2),
729 def CNDGE_INT : R600_3OP <
731 [(set (i32 R600_Reg32:$dst),
732 (selectcc (i32 R600_Reg32:$src0), 0,
733 (i32 R600_Reg32:$src1), (i32 R600_Reg32:$src2),
737 def CNDGT_INT : R600_3OP <
739 [(set (i32 R600_Reg32:$dst),
740 (selectcc (i32 R600_Reg32:$src0), 0,
741 (i32 R600_Reg32:$src1), (i32 R600_Reg32:$src2),
745 //===----------------------------------------------------------------------===//
746 // Texture instructions
747 //===----------------------------------------------------------------------===//
749 def TEX_LD : R600_TEX <
751 [(set R600_Reg128:$dst, (int_AMDGPU_txf R600_Reg128:$src0, imm:$src1, imm:$src2, imm:$src3, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
753 let AsmString = "TEX_LD $dst, $src0, $src1, $src2, $src3, $resourceId, $samplerId, $textureTarget";
754 let InOperandList = (ins R600_Reg128:$src0, i32imm:$src1, i32imm:$src2, i32imm:$src3, i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget);
757 def TEX_GET_TEXTURE_RESINFO : R600_TEX <
758 0x04, "TEX_GET_TEXTURE_RESINFO",
759 [(set R600_Reg128:$dst, (int_AMDGPU_txq R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
762 def TEX_GET_GRADIENTS_H : R600_TEX <
763 0x07, "TEX_GET_GRADIENTS_H",
764 [(set R600_Reg128:$dst, (int_AMDGPU_ddx R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
767 def TEX_GET_GRADIENTS_V : R600_TEX <
768 0x08, "TEX_GET_GRADIENTS_V",
769 [(set R600_Reg128:$dst, (int_AMDGPU_ddy R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
772 def TEX_SET_GRADIENTS_H : R600_TEX <
773 0x0B, "TEX_SET_GRADIENTS_H",
777 def TEX_SET_GRADIENTS_V : R600_TEX <
778 0x0C, "TEX_SET_GRADIENTS_V",
782 def TEX_SAMPLE : R600_TEX <
784 [(set R600_Reg128:$dst, (int_AMDGPU_tex R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
787 def TEX_SAMPLE_C : R600_TEX <
788 0x18, "TEX_SAMPLE_C",
789 [(set R600_Reg128:$dst, (int_AMDGPU_tex R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, TEX_SHADOW:$textureTarget))]
792 def TEX_SAMPLE_L : R600_TEX <
793 0x11, "TEX_SAMPLE_L",
794 [(set R600_Reg128:$dst, (int_AMDGPU_txl R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
797 def TEX_SAMPLE_C_L : R600_TEX <
798 0x19, "TEX_SAMPLE_C_L",
799 [(set R600_Reg128:$dst, (int_AMDGPU_txl R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, TEX_SHADOW:$textureTarget))]
802 def TEX_SAMPLE_LB : R600_TEX <
803 0x12, "TEX_SAMPLE_LB",
804 [(set R600_Reg128:$dst, (int_AMDGPU_txb R600_Reg128:$src0,imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
807 def TEX_SAMPLE_C_LB : R600_TEX <
808 0x1A, "TEX_SAMPLE_C_LB",
809 [(set R600_Reg128:$dst, (int_AMDGPU_txb R600_Reg128:$src0, imm:$resourceId, imm:$samplerId, TEX_SHADOW:$textureTarget))]
812 def TEX_SAMPLE_G : R600_TEX <
813 0x14, "TEX_SAMPLE_G",
817 def TEX_SAMPLE_C_G : R600_TEX <
818 0x1C, "TEX_SAMPLE_C_G",
822 //===----------------------------------------------------------------------===//
823 // Helper classes for common instructions
824 //===----------------------------------------------------------------------===//
826 class MUL_LIT_Common <bits<5> inst> : R600_3OP <
831 class MULADD_Common <bits<5> inst> : R600_3OP <
833 [(set (f32 R600_Reg32:$dst),
834 (IL_mad R600_Reg32:$src0, R600_Reg32:$src1, R600_Reg32:$src2))]
837 class CNDE_Common <bits<5> inst> : R600_3OP <
839 [(set R600_Reg32:$dst,
840 (selectcc (f32 R600_Reg32:$src0), FP_ZERO,
841 (f32 R600_Reg32:$src1), (f32 R600_Reg32:$src2),
845 class CNDGT_Common <bits<5> inst> : R600_3OP <
847 [(set R600_Reg32:$dst,
848 (selectcc (f32 R600_Reg32:$src0), FP_ZERO,
849 (f32 R600_Reg32:$src1), (f32 R600_Reg32:$src2),
853 class CNDGE_Common <bits<5> inst> : R600_3OP <
855 [(set R600_Reg32:$dst,
856 (selectcc (f32 R600_Reg32:$src0), FP_ZERO,
857 (f32 R600_Reg32:$src1), (f32 R600_Reg32:$src2),
861 multiclass DOT4_Common <bits<11> inst> {
863 def _pseudo : R600_REDUCTION <inst,
864 (ins R600_Reg128:$src0, R600_Reg128:$src1),
865 "DOT4 $dst $src0, $src1",
866 [(set R600_Reg32:$dst, (int_AMDGPU_dp4 R600_Reg128:$src0, R600_Reg128:$src1))]
869 def _real : R600_2OP <inst, "DOT4", []>;
872 let mayLoad = 0, mayStore = 0, hasSideEffects = 0 in {
873 multiclass CUBE_Common <bits<11> inst> {
875 def _pseudo : InstR600 <
877 (outs R600_Reg128:$dst),
878 (ins R600_Reg128:$src),
880 [(set R600_Reg128:$dst, (int_AMDGPU_cube R600_Reg128:$src))],
886 def _real : R600_2OP <inst, "CUBE", []>;
888 } // End mayLoad = 0, mayStore = 0, hasSideEffects = 0
890 class EXP_IEEE_Common <bits<11> inst> : R600_1OP_Helper <
891 inst, "EXP_IEEE", fexp2
894 class FLT_TO_INT_Common <bits<11> inst> : R600_1OP_Helper <
895 inst, "FLT_TO_INT", fp_to_sint
898 class INT_TO_FLT_Common <bits<11> inst> : R600_1OP_Helper <
899 inst, "INT_TO_FLT", sint_to_fp
902 class FLT_TO_UINT_Common <bits<11> inst> : R600_1OP_Helper <
903 inst, "FLT_TO_UINT", fp_to_uint
906 class UINT_TO_FLT_Common <bits<11> inst> : R600_1OP_Helper <
907 inst, "UINT_TO_FLT", uint_to_fp
910 class LOG_CLAMPED_Common <bits<11> inst> : R600_1OP <
911 inst, "LOG_CLAMPED", []
914 class LOG_IEEE_Common <bits<11> inst> : R600_1OP_Helper <
915 inst, "LOG_IEEE", flog2
918 class LSHL_Common <bits<11> inst> : R600_2OP_Helper <inst, "LSHL", shl>;
919 class LSHR_Common <bits<11> inst> : R600_2OP_Helper <inst, "LSHR", srl>;
920 class ASHR_Common <bits<11> inst> : R600_2OP_Helper <inst, "ASHR", sra>;
921 class MULHI_INT_Common <bits<11> inst> : R600_2OP_Helper <
922 inst, "MULHI_INT", mulhs
924 class MULHI_UINT_Common <bits<11> inst> : R600_2OP_Helper <
927 class MULLO_INT_Common <bits<11> inst> : R600_2OP_Helper <
928 inst, "MULLO_INT", mul
930 class MULLO_UINT_Common <bits<11> inst> : R600_2OP <inst, "MULLO_UINT", []>;
932 class RECIP_CLAMPED_Common <bits<11> inst> : R600_1OP <
933 inst, "RECIP_CLAMPED", []
936 class RECIP_IEEE_Common <bits<11> inst> : R600_1OP <
937 inst, "RECIP_IEEE", [(set R600_Reg32:$dst, (fdiv FP_ONE, R600_Reg32:$src0))]
940 class RECIP_UINT_Common <bits<11> inst> : R600_1OP_Helper <
941 inst, "RECIP_UINT", AMDGPUurecip
944 class RECIPSQRT_CLAMPED_Common <bits<11> inst> : R600_1OP_Helper <
945 inst, "RECIPSQRT_CLAMPED", int_AMDGPU_rsq
948 class RECIPSQRT_IEEE_Common <bits<11> inst> : R600_1OP <
949 inst, "RECIPSQRT_IEEE", []
952 class SIN_Common <bits<11> inst> : R600_1OP <
957 class COS_Common <bits<11> inst> : R600_1OP <
962 //===----------------------------------------------------------------------===//
963 // Helper patterns for complex intrinsics
964 //===----------------------------------------------------------------------===//
966 multiclass DIV_Common <InstR600 recip_ieee> {
968 (int_AMDGPU_div R600_Reg32:$src0, R600_Reg32:$src1),
969 (MUL R600_Reg32:$src0, (recip_ieee R600_Reg32:$src1))
973 (fdiv R600_Reg32:$src0, R600_Reg32:$src1),
974 (MUL R600_Reg32:$src0, (recip_ieee R600_Reg32:$src1))
978 class TGSI_LIT_Z_Common <InstR600 mul_lit, InstR600 log_clamped, InstR600 exp_ieee> : Pat <
979 (int_TGSI_lit_z R600_Reg32:$src_x, R600_Reg32:$src_y, R600_Reg32:$src_w),
980 (exp_ieee (mul_lit (log_clamped (MAX R600_Reg32:$src_y, (f32 ZERO))), R600_Reg32:$src_w, R600_Reg32:$src_x))
983 //===----------------------------------------------------------------------===//
984 // R600 / R700 Instructions
985 //===----------------------------------------------------------------------===//
987 let Predicates = [isR600] in {
989 def MUL_LIT_r600 : MUL_LIT_Common<0x0C>;
990 def MULADD_r600 : MULADD_Common<0x10>;
991 def CNDE_r600 : CNDE_Common<0x18>;
992 def CNDGT_r600 : CNDGT_Common<0x19>;
993 def CNDGE_r600 : CNDGE_Common<0x1A>;
994 defm DOT4_r600 : DOT4_Common<0x50>;
995 defm CUBE_r600 : CUBE_Common<0x52>;
996 def EXP_IEEE_r600 : EXP_IEEE_Common<0x61>;
997 def LOG_CLAMPED_r600 : LOG_CLAMPED_Common<0x62>;
998 def LOG_IEEE_r600 : LOG_IEEE_Common<0x63>;
999 def RECIP_CLAMPED_r600 : RECIP_CLAMPED_Common<0x64>;
1000 def RECIP_IEEE_r600 : RECIP_IEEE_Common<0x66>;
1001 def RECIPSQRT_CLAMPED_r600 : RECIPSQRT_CLAMPED_Common<0x67>;
1002 def RECIPSQRT_IEEE_r600 : RECIPSQRT_IEEE_Common<0x69>;
1003 def FLT_TO_INT_r600 : FLT_TO_INT_Common<0x6b>;
1004 def INT_TO_FLT_r600 : INT_TO_FLT_Common<0x6c>;
1005 def FLT_TO_UINT_r600 : FLT_TO_UINT_Common<0x79>;
1006 def UINT_TO_FLT_r600 : UINT_TO_FLT_Common<0x6d>;
1007 def SIN_r600 : SIN_Common<0x6E>;
1008 def COS_r600 : COS_Common<0x6F>;
1009 def ASHR_r600 : ASHR_Common<0x70>;
1010 def LSHR_r600 : LSHR_Common<0x71>;
1011 def LSHL_r600 : LSHL_Common<0x72>;
1012 def MULLO_INT_r600 : MULLO_INT_Common<0x73>;
1013 def MULHI_INT_r600 : MULHI_INT_Common<0x74>;
1014 def MULLO_UINT_r600 : MULLO_UINT_Common<0x75>;
1015 def MULHI_UINT_r600 : MULHI_UINT_Common<0x76>;
1016 def RECIP_UINT_r600 : RECIP_UINT_Common <0x78>;
1018 defm DIV_r600 : DIV_Common<RECIP_IEEE_r600>;
1019 def TGSI_LIT_Z_r600 : TGSI_LIT_Z_Common<MUL_LIT_r600, LOG_CLAMPED_r600, EXP_IEEE_r600>;
1021 def : Pat<(fsqrt R600_Reg32:$src),
1022 (MUL R600_Reg32:$src, (RECIPSQRT_CLAMPED_r600 R600_Reg32:$src))>;
1024 def R600_ExportSwz : ExportSwzInst {
1025 let Word1{20-17} = 1; // BURST_COUNT
1026 let Word1{21} = eop;
1027 let Word1{22} = 1; // VALID_PIXEL_MODE
1028 let Word1{30-23} = inst;
1029 let Word1{31} = 1; // BARRIER
1031 defm : ExportPattern<R600_ExportSwz, 39>;
1033 def R600_ExportBuf : ExportBufInst {
1034 let Word1{20-17} = 1; // BURST_COUNT
1035 let Word1{21} = eop;
1036 let Word1{22} = 1; // VALID_PIXEL_MODE
1037 let Word1{30-23} = inst;
1038 let Word1{31} = 1; // BARRIER
1040 defm : SteamOutputExportPattern<R600_ExportBuf, 0x20, 0x21, 0x22, 0x23>;
1043 // Helper pattern for normalizing inputs to triginomic instructions for R700+
1045 class COS_PAT <InstR600 trig> : Pat<
1046 (fcos R600_Reg32:$src),
1047 (trig (MUL (MOV_IMM_I32 CONST.TWO_PI_INV), R600_Reg32:$src))
1050 class SIN_PAT <InstR600 trig> : Pat<
1051 (fsin R600_Reg32:$src),
1052 (trig (MUL (MOV_IMM_I32 CONST.TWO_PI_INV), R600_Reg32:$src))
1055 //===----------------------------------------------------------------------===//
1056 // R700 Only instructions
1057 //===----------------------------------------------------------------------===//
1059 let Predicates = [isR700] in {
1060 def SIN_r700 : SIN_Common<0x6E>;
1061 def COS_r700 : COS_Common<0x6F>;
1063 // R700 normalizes inputs to SIN/COS the same as EG
1064 def : SIN_PAT <SIN_r700>;
1065 def : COS_PAT <COS_r700>;
1068 //===----------------------------------------------------------------------===//
1069 // Evergreen Only instructions
1070 //===----------------------------------------------------------------------===//
1072 let Predicates = [isEG] in {
1074 def RECIP_IEEE_eg : RECIP_IEEE_Common<0x86>;
1075 defm DIV_eg : DIV_Common<RECIP_IEEE_eg>;
1077 def MULLO_INT_eg : MULLO_INT_Common<0x8F>;
1078 def MULHI_INT_eg : MULHI_INT_Common<0x90>;
1079 def MULLO_UINT_eg : MULLO_UINT_Common<0x91>;
1080 def MULHI_UINT_eg : MULHI_UINT_Common<0x92>;
1081 def RECIP_UINT_eg : RECIP_UINT_Common<0x94>;
1082 def RECIPSQRT_CLAMPED_eg : RECIPSQRT_CLAMPED_Common<0x87>;
1083 def EXP_IEEE_eg : EXP_IEEE_Common<0x81>;
1084 def LOG_IEEE_eg : LOG_IEEE_Common<0x83>;
1085 def RECIP_CLAMPED_eg : RECIP_CLAMPED_Common<0x84>;
1086 def RECIPSQRT_IEEE_eg : RECIPSQRT_IEEE_Common<0x89>;
1087 def SIN_eg : SIN_Common<0x8D>;
1088 def COS_eg : COS_Common<0x8E>;
1090 def : SIN_PAT <SIN_eg>;
1091 def : COS_PAT <COS_eg>;
1092 def : Pat<(fsqrt R600_Reg32:$src),
1093 (MUL R600_Reg32:$src, (RECIPSQRT_CLAMPED_eg R600_Reg32:$src))>;
1094 } // End Predicates = [isEG]
1096 //===----------------------------------------------------------------------===//
1097 // Evergreen / Cayman Instructions
1098 //===----------------------------------------------------------------------===//
1100 let Predicates = [isEGorCayman] in {
1102 // BFE_UINT - bit_extract, an optimization for mask and shift
1107 // bit_extract = (Input << (32 - Offset - Width)) >> (32 - Width)
1112 // (0, 8) = (Input << 24) >> 24 = (Input & 0xff) >> 0
1113 // (8, 8) = (Input << 16) >> 24 = (Input & 0xffff) >> 8
1114 // (16,8) = (Input << 8) >> 24 = (Input & 0xffffff) >> 16
1115 // (24,8) = (Input << 0) >> 24 = (Input & 0xffffffff) >> 24
1116 def BFE_UINT_eg : R600_3OP <0x4, "BFE_UINT",
1117 [(set R600_Reg32:$dst, (int_AMDIL_bit_extract_u32 R600_Reg32:$src0,
1119 R600_Reg32:$src2))],
1123 def BIT_ALIGN_INT_eg : R600_3OP <0xC, "BIT_ALIGN_INT",
1124 [(set R600_Reg32:$dst, (AMDGPUbitalign R600_Reg32:$src0, R600_Reg32:$src1,
1125 R600_Reg32:$src2))],
1129 def MULADD_eg : MULADD_Common<0x14>;
1130 def ASHR_eg : ASHR_Common<0x15>;
1131 def LSHR_eg : LSHR_Common<0x16>;
1132 def LSHL_eg : LSHL_Common<0x17>;
1133 def CNDE_eg : CNDE_Common<0x19>;
1134 def CNDGT_eg : CNDGT_Common<0x1A>;
1135 def CNDGE_eg : CNDGE_Common<0x1B>;
1136 def MUL_LIT_eg : MUL_LIT_Common<0x1F>;
1137 def LOG_CLAMPED_eg : LOG_CLAMPED_Common<0x82>;
1138 defm DOT4_eg : DOT4_Common<0xBE>;
1139 defm CUBE_eg : CUBE_Common<0xC0>;
1141 def TGSI_LIT_Z_eg : TGSI_LIT_Z_Common<MUL_LIT_eg, LOG_CLAMPED_eg, EXP_IEEE_eg>;
1143 def FLT_TO_INT_eg : FLT_TO_INT_Common<0x50> {
1147 def INT_TO_FLT_eg : INT_TO_FLT_Common<0x9B>;
1149 def FLT_TO_UINT_eg : FLT_TO_UINT_Common<0x9A> {
1153 def UINT_TO_FLT_eg : UINT_TO_FLT_Common<0x9C>;
1155 // TRUNC is used for the FLT_TO_INT instructions to work around a
1156 // perceived problem where the rounding modes are applied differently
1157 // depending on the instruction and the slot they are in.
1159 // https://bugs.freedesktop.org/show_bug.cgi?id=50232
1160 // Mesa commit: a1a0974401c467cb86ef818f22df67c21774a38c
1162 // XXX: Lowering SELECT_CC will sometimes generate fp_to_[su]int nodes,
1163 // which do not need to be truncated since the fp values are 0.0f or 1.0f.
1164 // We should look into handling these cases separately.
1165 def : Pat<(fp_to_sint R600_Reg32:$src0),
1166 (FLT_TO_INT_eg (TRUNC R600_Reg32:$src0))>;
1168 def : Pat<(fp_to_uint R600_Reg32:$src0),
1169 (FLT_TO_UINT_eg (TRUNC R600_Reg32:$src0))>;
1171 def EG_ExportSwz : ExportSwzInst {
1172 let Word1{19-16} = 1; // BURST_COUNT
1173 let Word1{20} = 1; // VALID_PIXEL_MODE
1174 let Word1{21} = eop;
1175 let Word1{29-22} = inst;
1176 let Word1{30} = 0; // MARK
1177 let Word1{31} = 1; // BARRIER
1179 defm : ExportPattern<EG_ExportSwz, 83>;
1181 def EG_ExportBuf : ExportBufInst {
1182 let Word1{19-16} = 1; // BURST_COUNT
1183 let Word1{20} = 1; // VALID_PIXEL_MODE
1184 let Word1{21} = eop;
1185 let Word1{29-22} = inst;
1186 let Word1{30} = 0; // MARK
1187 let Word1{31} = 1; // BARRIER
1189 defm : SteamOutputExportPattern<EG_ExportBuf, 0x40, 0x41, 0x42, 0x43>;
1191 //===----------------------------------------------------------------------===//
1192 // Memory read/write instructions
1193 //===----------------------------------------------------------------------===//
1194 let usesCustomInserter = 1 in {
1196 class RAT_WRITE_CACHELESS_eg <dag ins, bits<4> comp_mask, string name,
1198 : EG_CF_RAT <0x57, 0x2, 0, (outs), ins,
1199 !strconcat(name, " $rw_gpr, $index_gpr, $eop"), pattern> {
1201 // XXX: Have a separate instruction for non-indexed writes.
1207 let COMP_MASK = comp_mask;
1208 let BURST_COUNT = 0;
1214 } // End usesCustomInserter = 1
1217 def RAT_WRITE_CACHELESS_32_eg : RAT_WRITE_CACHELESS_eg <
1218 (ins R600_TReg32_X:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
1219 0x1, "RAT_WRITE_CACHELESS_32_eg",
1220 [(global_store (i32 R600_TReg32_X:$rw_gpr), R600_TReg32_X:$index_gpr)]
1224 def RAT_WRITE_CACHELESS_128_eg : RAT_WRITE_CACHELESS_eg <
1225 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
1226 0xf, "RAT_WRITE_CACHELESS_128",
1227 [(global_store (v4i32 R600_Reg128:$rw_gpr), R600_TReg32_X:$index_gpr)]
1230 class VTX_READ_eg <string name, bits<8> buffer_id, dag outs, list<dag> pattern>
1231 : InstR600ISA <outs, (ins MEMxi:$ptr), name#" $dst, $ptr", pattern> {
1238 bits<5> VC_INST = 0;
1239 bits<2> FETCH_TYPE = 2;
1240 bits<1> FETCH_WHOLE_QUAD = 0;
1241 bits<8> BUFFER_ID = buffer_id;
1242 bits<1> SRC_REL = 0;
1243 // XXX: We can infer this field based on the SRC_GPR. This would allow us
1244 // to store vertex addresses in any channel, not just X.
1245 bits<2> SRC_SEL_X = 0;
1246 bits<6> MEGA_FETCH_COUNT;
1247 bits<1> DST_REL = 0;
1252 // The docs say that if this bit is set, then DATA_FORMAT, NUM_FORMAT_ALL,
1253 // FORMAT_COMP_ALL, SRF_MODE_ALL, and ENDIAN_SWAP fields will be ignored,
1254 // however, based on my testing if USE_CONST_FIELDS is set, then all
1255 // these fields need to be set to 0.
1256 bits<1> USE_CONST_FIELDS = 0;
1257 bits<6> DATA_FORMAT;
1258 bits<2> NUM_FORMAT_ALL = 1;
1259 bits<1> FORMAT_COMP_ALL = 0;
1260 bits<1> SRF_MODE_ALL = 0;
1262 // LLVM can only encode 64-bit instructions, so these fields are manually
1263 // encoded in R600CodeEmitter
1266 // bits<2> ENDIAN_SWAP = 0;
1267 // bits<1> CONST_BUF_NO_STRIDE = 0;
1268 // bits<1> MEGA_FETCH = 0;
1269 // bits<1> ALT_CONST = 0;
1270 // bits<2> BUFFER_INDEX_MODE = 0;
1273 let Inst{4-0} = VC_INST;
1274 let Inst{6-5} = FETCH_TYPE;
1275 let Inst{7} = FETCH_WHOLE_QUAD;
1276 let Inst{15-8} = BUFFER_ID;
1277 let Inst{22-16} = SRC_GPR;
1278 let Inst{23} = SRC_REL;
1279 let Inst{25-24} = SRC_SEL_X;
1280 let Inst{31-26} = MEGA_FETCH_COUNT;
1283 let Inst{38-32} = DST_GPR;
1284 let Inst{39} = DST_REL;
1285 let Inst{40} = 0; // Reserved
1286 let Inst{43-41} = DST_SEL_X;
1287 let Inst{46-44} = DST_SEL_Y;
1288 let Inst{49-47} = DST_SEL_Z;
1289 let Inst{52-50} = DST_SEL_W;
1290 let Inst{53} = USE_CONST_FIELDS;
1291 let Inst{59-54} = DATA_FORMAT;
1292 let Inst{61-60} = NUM_FORMAT_ALL;
1293 let Inst{62} = FORMAT_COMP_ALL;
1294 let Inst{63} = SRF_MODE_ALL;
1296 // VTX_WORD2 (LLVM can only encode 64-bit instructions, so WORD2 encoding
1297 // is done in R600CodeEmitter
1299 // Inst{79-64} = OFFSET;
1300 // Inst{81-80} = ENDIAN_SWAP;
1301 // Inst{82} = CONST_BUF_NO_STRIDE;
1302 // Inst{83} = MEGA_FETCH;
1303 // Inst{84} = ALT_CONST;
1304 // Inst{86-85} = BUFFER_INDEX_MODE;
1305 // Inst{95-86} = 0; Reserved
1307 // VTX_WORD3 (Padding)
1309 // Inst{127-96} = 0;
1312 class VTX_READ_8_eg <bits<8> buffer_id, list<dag> pattern>
1313 : VTX_READ_eg <"VTX_READ_8", buffer_id, (outs R600_TReg32_X:$dst),
1316 let MEGA_FETCH_COUNT = 1;
1318 let DST_SEL_Y = 7; // Masked
1319 let DST_SEL_Z = 7; // Masked
1320 let DST_SEL_W = 7; // Masked
1321 let DATA_FORMAT = 1; // FMT_8
1324 class VTX_READ_16_eg <bits<8> buffer_id, list<dag> pattern>
1325 : VTX_READ_eg <"VTX_READ_16", buffer_id, (outs R600_TReg32_X:$dst),
1327 let MEGA_FETCH_COUNT = 2;
1329 let DST_SEL_Y = 7; // Masked
1330 let DST_SEL_Z = 7; // Masked
1331 let DST_SEL_W = 7; // Masked
1332 let DATA_FORMAT = 5; // FMT_16
1336 class VTX_READ_32_eg <bits<8> buffer_id, list<dag> pattern>
1337 : VTX_READ_eg <"VTX_READ_32", buffer_id, (outs R600_TReg32_X:$dst),
1340 let MEGA_FETCH_COUNT = 4;
1342 let DST_SEL_Y = 7; // Masked
1343 let DST_SEL_Z = 7; // Masked
1344 let DST_SEL_W = 7; // Masked
1345 let DATA_FORMAT = 0xD; // COLOR_32
1347 // This is not really necessary, but there were some GPU hangs that appeared
1348 // to be caused by ALU instructions in the next instruction group that wrote
1349 // to the $ptr registers of the VTX_READ.
1351 // %T3_X<def> = VTX_READ_PARAM_32_eg %T2_X<kill>, 24
1352 // %T2_X<def> = MOV %ZERO
1353 //Adding this constraint prevents this from happening.
1354 let Constraints = "$ptr.ptr = $dst";
1357 class VTX_READ_128_eg <bits<8> buffer_id, list<dag> pattern>
1358 : VTX_READ_eg <"VTX_READ_128", buffer_id, (outs R600_Reg128:$dst),
1361 let MEGA_FETCH_COUNT = 16;
1366 let DATA_FORMAT = 0x22; // COLOR_32_32_32_32
1368 // XXX: Need to force VTX_READ_128 instructions to write to the same register
1369 // that holds its buffer address to avoid potential hangs. We can't use
1370 // the same constraint as VTX_READ_32_eg, because the $ptr.ptr and $dst
1371 // registers are different sizes.
1374 //===----------------------------------------------------------------------===//
1375 // VTX Read from parameter memory space
1376 //===----------------------------------------------------------------------===//
1378 def VTX_READ_PARAM_8_eg : VTX_READ_8_eg <0,
1379 [(set (i32 R600_TReg32_X:$dst), (load_param_zexti8 ADDRVTX_READ:$ptr))]
1382 def VTX_READ_PARAM_16_eg : VTX_READ_16_eg <0,
1383 [(set (i32 R600_TReg32_X:$dst), (load_param_zexti16 ADDRVTX_READ:$ptr))]
1386 def VTX_READ_PARAM_32_eg : VTX_READ_32_eg <0,
1387 [(set (i32 R600_TReg32_X:$dst), (load_param ADDRVTX_READ:$ptr))]
1390 //===----------------------------------------------------------------------===//
1391 // VTX Read from global memory space
1392 //===----------------------------------------------------------------------===//
1395 def VTX_READ_GLOBAL_8_eg : VTX_READ_8_eg <1,
1396 [(set (i32 R600_TReg32_X:$dst), (zextloadi8_global ADDRVTX_READ:$ptr))]
1400 def VTX_READ_GLOBAL_32_eg : VTX_READ_32_eg <1,
1401 [(set (i32 R600_TReg32_X:$dst), (global_load ADDRVTX_READ:$ptr))]
1405 def VTX_READ_GLOBAL_128_eg : VTX_READ_128_eg <1,
1406 [(set (v4i32 R600_Reg128:$dst), (global_load ADDRVTX_READ:$ptr))]
1409 //===----------------------------------------------------------------------===//
1411 // XXX: We are currently storing all constants in the global address space.
1412 //===----------------------------------------------------------------------===//
1414 def CONSTANT_LOAD_eg : VTX_READ_32_eg <1,
1415 [(set (i32 R600_TReg32_X:$dst), (constant_load ADDRVTX_READ:$ptr))]
1420 let Predicates = [isCayman] in {
1422 let isVector = 1 in {
1424 def RECIP_IEEE_cm : RECIP_IEEE_Common<0x86>;
1426 def MULLO_INT_cm : MULLO_INT_Common<0x8F>;
1427 def MULHI_INT_cm : MULHI_INT_Common<0x90>;
1428 def MULLO_UINT_cm : MULLO_UINT_Common<0x91>;
1429 def MULHI_UINT_cm : MULHI_UINT_Common<0x92>;
1430 def RECIPSQRT_CLAMPED_cm : RECIPSQRT_CLAMPED_Common<0x87>;
1431 def EXP_IEEE_cm : EXP_IEEE_Common<0x81>;
1432 def LOG_IEEE_ : LOG_IEEE_Common<0x83>;
1433 def RECIP_CLAMPED_cm : RECIP_CLAMPED_Common<0x84>;
1434 def RECIPSQRT_IEEE_cm : RECIPSQRT_IEEE_Common<0x89>;
1435 def SIN_cm : SIN_Common<0x8D>;
1436 def COS_cm : COS_Common<0x8E>;
1437 } // End isVector = 1
1439 def : SIN_PAT <SIN_cm>;
1440 def : COS_PAT <COS_cm>;
1442 defm DIV_cm : DIV_Common<RECIP_IEEE_cm>;
1444 // RECIP_UINT emulation for Cayman
1446 (AMDGPUurecip R600_Reg32:$src0),
1447 (FLT_TO_UINT_eg (MUL_IEEE (RECIP_IEEE_cm (UINT_TO_FLT_eg R600_Reg32:$src0)),
1448 (MOV_IMM_I32 0x4f800000)))
1452 def : Pat<(fsqrt R600_Reg32:$src),
1453 (MUL R600_Reg32:$src, (RECIPSQRT_CLAMPED_cm R600_Reg32:$src))>;
1457 //===----------------------------------------------------------------------===//
1458 // Branch Instructions
1459 //===----------------------------------------------------------------------===//
1462 def IF_PREDICATE_SET : ILFormat<(outs), (ins GPRI32:$src),
1463 "IF_PREDICATE_SET $src", []>;
1465 def PREDICATED_BREAK : ILFormat<(outs), (ins GPRI32:$src),
1466 "PREDICATED_BREAK $src", []>;
1468 //===----------------------------------------------------------------------===//
1469 // Pseudo instructions
1470 //===----------------------------------------------------------------------===//
1472 let isPseudo = 1 in {
1474 def PRED_X : InstR600 <
1475 0, (outs R600_Predicate_Bit:$dst),
1476 (ins R600_Reg32:$src0, i32imm:$src1, i32imm:$flags),
1478 let FlagOperandIdx = 3;
1481 let isTerminator = 1, isBranch = 1, isBarrier = 1 in {
1483 def JUMP : InstR600 <0x10,
1485 (ins brtarget:$target, R600_Pred:$p),
1486 "JUMP $target ($p)",
1490 } // End isTerminator = 1, isBranch = 1, isBarrier = 1
1492 let usesCustomInserter = 1 in {
1494 let mayLoad = 0, mayStore = 0, hasSideEffects = 1 in {
1496 def MASK_WRITE : AMDGPUShaderInst <
1498 (ins R600_Reg32:$src),
1503 } // End mayLoad = 0, mayStore = 0, hasSideEffects = 1
1505 def R600_LOAD_CONST : AMDGPUShaderInst <
1506 (outs R600_Reg32:$dst),
1508 "R600_LOAD_CONST $dst, $src0",
1509 [(set R600_Reg32:$dst, (int_AMDGPU_load_const imm:$src0))]
1512 def RESERVE_REG : AMDGPUShaderInst <
1516 [(int_AMDGPU_reserve_reg imm:$src)]
1519 def TXD: AMDGPUShaderInst <
1520 (outs R600_Reg128:$dst),
1521 (ins R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2, i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget),
1522 "TXD $dst, $src0, $src1, $src2, $resourceId, $samplerId, $textureTarget",
1523 [(set R600_Reg128:$dst, (int_AMDGPU_txd R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2, imm:$resourceId, imm:$samplerId, imm:$textureTarget))]
1526 def TXD_SHADOW: AMDGPUShaderInst <
1527 (outs R600_Reg128:$dst),
1528 (ins R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2, i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget),
1529 "TXD_SHADOW $dst, $src0, $src1, $src2, $resourceId, $samplerId, $textureTarget",
1530 [(set R600_Reg128:$dst, (int_AMDGPU_txd R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2, imm:$resourceId, imm:$samplerId, TEX_SHADOW:$textureTarget))]
1533 } // End isPseudo = 1
1534 } // End usesCustomInserter = 1
1536 def CLAMP_R600 : CLAMP <R600_Reg32>;
1537 def FABS_R600 : FABS<R600_Reg32>;
1538 def FNEG_R600 : FNEG<R600_Reg32>;
1540 //===---------------------------------------------------------------------===//
1541 // Return instruction
1542 //===---------------------------------------------------------------------===//
1543 let isTerminator = 1, isReturn = 1, isBarrier = 1, hasCtrlDep = 1 in {
1544 def RETURN : ILFormat<(outs), (ins variable_ops),
1545 "RETURN", [(IL_retflag)]>;
1548 //===--------------------------------------------------------------------===//
1549 // Instructions support
1550 //===--------------------------------------------------------------------===//
1551 //===---------------------------------------------------------------------===//
1552 // Custom Inserter for Branches and returns, this eventually will be a
1554 //===---------------------------------------------------------------------===//
1555 let isTerminator = 1, usesCustomInserter = 1, isBranch = 1, isBarrier = 1 in {
1556 def BRANCH : ILFormat<(outs), (ins brtarget:$target),
1557 "; Pseudo unconditional branch instruction",
1559 defm BRANCH_COND : BranchConditional<IL_brcond>;
1562 //===---------------------------------------------------------------------===//
1563 // Flow and Program control Instructions
1564 //===---------------------------------------------------------------------===//
1565 let isTerminator=1 in {
1566 def SWITCH : ILFormat< (outs), (ins GPRI32:$src),
1567 !strconcat("SWITCH", " $src"), []>;
1568 def CASE : ILFormat< (outs), (ins GPRI32:$src),
1569 !strconcat("CASE", " $src"), []>;
1570 def BREAK : ILFormat< (outs), (ins),
1572 def CONTINUE : ILFormat< (outs), (ins),
1574 def DEFAULT : ILFormat< (outs), (ins),
1576 def ELSE : ILFormat< (outs), (ins),
1578 def ENDSWITCH : ILFormat< (outs), (ins),
1580 def ENDMAIN : ILFormat< (outs), (ins),
1582 def END : ILFormat< (outs), (ins),
1584 def ENDFUNC : ILFormat< (outs), (ins),
1586 def ENDIF : ILFormat< (outs), (ins),
1588 def WHILELOOP : ILFormat< (outs), (ins),
1590 def ENDLOOP : ILFormat< (outs), (ins),
1592 def FUNC : ILFormat< (outs), (ins),
1594 def RETDYN : ILFormat< (outs), (ins),
1596 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1597 defm IF_LOGICALNZ : BranchInstr<"IF_LOGICALNZ">;
1598 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1599 defm IF_LOGICALZ : BranchInstr<"IF_LOGICALZ">;
1600 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1601 defm BREAK_LOGICALNZ : BranchInstr<"BREAK_LOGICALNZ">;
1602 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1603 defm BREAK_LOGICALZ : BranchInstr<"BREAK_LOGICALZ">;
1604 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1605 defm CONTINUE_LOGICALNZ : BranchInstr<"CONTINUE_LOGICALNZ">;
1606 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
1607 defm CONTINUE_LOGICALZ : BranchInstr<"CONTINUE_LOGICALZ">;
1608 defm IFC : BranchInstr2<"IFC">;
1609 defm BREAKC : BranchInstr2<"BREAKC">;
1610 defm CONTINUEC : BranchInstr2<"CONTINUEC">;
1613 //===----------------------------------------------------------------------===//
1615 //===----------------------------------------------------------------------===//
1617 //CNDGE_INT extra pattern
1619 (selectcc (i32 R600_Reg32:$src0), -1, (i32 R600_Reg32:$src1),
1620 (i32 R600_Reg32:$src2), COND_GT),
1621 (CNDGE_INT R600_Reg32:$src0, R600_Reg32:$src1, R600_Reg32:$src2)
1627 (MASK_WRITE (KILLGT (f32 ONE), (f32 ZERO)))
1631 (int_AMDGPU_kill R600_Reg32:$src0),
1632 (MASK_WRITE (KILLGT (f32 ZERO), (f32 R600_Reg32:$src0)))
1637 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO, COND_LT),
1638 (SGT R600_Reg32:$src1, R600_Reg32:$src0)
1643 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO, COND_LE),
1644 (SGE R600_Reg32:$src1, R600_Reg32:$src0)
1647 // SETGT_INT reverse args
1649 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETLT),
1650 (SETGT_INT R600_Reg32:$src1, R600_Reg32:$src0)
1653 // SETGE_INT reverse args
1655 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETLE),
1656 (SETGE_INT R600_Reg32:$src1, R600_Reg32:$src0)
1659 // SETGT_UINT reverse args
1661 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETULT),
1662 (SETGT_UINT R600_Reg32:$src1, R600_Reg32:$src0)
1665 // SETGE_UINT reverse args
1667 (selectcc (i32 R600_Reg32:$src0), R600_Reg32:$src1, -1, 0, SETULE),
1668 (SETGE_UINT R600_Reg32:$src1, R600_Reg32:$src0)
1671 // The next two patterns are special cases for handling 'true if ordered' and
1672 // 'true if unordered' conditionals. The assumption here is that the behavior of
1673 // SETE and SNE conforms to the Direct3D 10 rules for floating point values
1675 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc308050.aspx#alpha_32_bit
1676 // We assume that SETE returns false when one of the operands is NAN and
1677 // SNE returns true when on of the operands is NAN
1679 //SETE - 'true if ordered'
1681 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO, SETO),
1682 (SETE R600_Reg32:$src0, R600_Reg32:$src1)
1685 //SNE - 'true if unordered'
1687 (selectcc (f32 R600_Reg32:$src0), R600_Reg32:$src1, FP_ONE, FP_ZERO, SETUO),
1688 (SNE R600_Reg32:$src0, R600_Reg32:$src1)
1691 def : Extract_Element <f32, v4f32, R600_Reg128, 0, sel_x>;
1692 def : Extract_Element <f32, v4f32, R600_Reg128, 1, sel_y>;
1693 def : Extract_Element <f32, v4f32, R600_Reg128, 2, sel_z>;
1694 def : Extract_Element <f32, v4f32, R600_Reg128, 3, sel_w>;
1696 def : Insert_Element <f32, v4f32, R600_Reg32, R600_Reg128, 0, sel_x>;
1697 def : Insert_Element <f32, v4f32, R600_Reg32, R600_Reg128, 1, sel_y>;
1698 def : Insert_Element <f32, v4f32, R600_Reg32, R600_Reg128, 2, sel_z>;
1699 def : Insert_Element <f32, v4f32, R600_Reg32, R600_Reg128, 3, sel_w>;
1701 def : Extract_Element <i32, v4i32, R600_Reg128, 0, sel_x>;
1702 def : Extract_Element <i32, v4i32, R600_Reg128, 1, sel_y>;
1703 def : Extract_Element <i32, v4i32, R600_Reg128, 2, sel_z>;
1704 def : Extract_Element <i32, v4i32, R600_Reg128, 3, sel_w>;
1706 def : Insert_Element <i32, v4i32, R600_Reg32, R600_Reg128, 0, sel_x>;
1707 def : Insert_Element <i32, v4i32, R600_Reg32, R600_Reg128, 1, sel_y>;
1708 def : Insert_Element <i32, v4i32, R600_Reg32, R600_Reg128, 2, sel_z>;
1709 def : Insert_Element <i32, v4i32, R600_Reg32, R600_Reg128, 3, sel_w>;
1711 def : Vector_Build <v4f32, R600_Reg128, f32, R600_Reg32>;
1712 def : Vector_Build <v4i32, R600_Reg128, i32, R600_Reg32>;
1714 // bitconvert patterns
1716 def : BitConvert <i32, f32, R600_Reg32>;
1717 def : BitConvert <f32, i32, R600_Reg32>;
1718 def : BitConvert <v4f32, v4i32, R600_Reg128>;
1719 def : BitConvert <v4i32, v4f32, R600_Reg128>;
1721 // DWORDADDR pattern
1722 def : DwordAddrPat <i32, R600_Reg32>;
1724 } // End isR600toCayman Predicate