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"
15 include "R600InstrFormats.td"
17 class InstR600ISA <dag outs, dag ins, string asm, list<dag> pattern> :
18 InstR600 <outs, ins, asm, pattern, NullALU> {
20 let Namespace = "AMDGPU";
23 def MEMxi : Operand<iPTR> {
24 let MIOperandInfo = (ops R600_TReg32_X:$ptr, i32imm:$index);
25 let PrintMethod = "printMemOperand";
28 def MEMrr : Operand<iPTR> {
29 let MIOperandInfo = (ops R600_Reg32:$ptr, R600_Reg32:$index);
32 // Operands for non-registers
34 class InstFlag<string PM = "printOperand", int Default = 0>
35 : OperandWithDefaultOps <i32, (ops (i32 Default))> {
39 // src_sel for ALU src operands, see also ALU_CONST, ALU_PARAM registers
40 def SEL : OperandWithDefaultOps <i32, (ops (i32 -1))> {
41 let PrintMethod = "printSel";
43 def BANK_SWIZZLE : OperandWithDefaultOps <i32, (ops (i32 0))> {
44 let PrintMethod = "printBankSwizzle";
47 def LITERAL : InstFlag<"printLiteral">;
49 def WRITE : InstFlag <"printWrite", 1>;
50 def OMOD : InstFlag <"printOMOD">;
51 def REL : InstFlag <"printRel">;
52 def CLAMP : InstFlag <"printClamp">;
53 def NEG : InstFlag <"printNeg">;
54 def ABS : InstFlag <"printAbs">;
55 def UEM : InstFlag <"printUpdateExecMask">;
56 def UP : InstFlag <"printUpdatePred">;
58 // XXX: The r600g finalizer in Mesa expects last to be one in most cases.
59 // Once we start using the packetizer in this backend we should have this
61 def LAST : InstFlag<"printLast", 1>;
62 def RSel : Operand<i32> {
63 let PrintMethod = "printRSel";
65 def CT: Operand<i32> {
66 let PrintMethod = "printCT";
69 def FRAMEri : Operand<iPTR> {
70 let MIOperandInfo = (ops R600_Reg32:$ptr, i32imm:$index);
73 def ADDRParam : ComplexPattern<i32, 2, "SelectADDRParam", [], []>;
74 def ADDRDWord : ComplexPattern<i32, 1, "SelectADDRDWord", [], []>;
75 def ADDRVTX_READ : ComplexPattern<i32, 2, "SelectADDRVTX_READ", [], []>;
76 def ADDRGA_CONST_OFFSET : ComplexPattern<i32, 1, "SelectGlobalValueConstantOffset", [], []>;
77 def ADDRGA_VAR_OFFSET : ComplexPattern<i32, 2, "SelectGlobalValueVariableOffset", [], []>;
78 def ADDRIndirect : ComplexPattern<iPTR, 2, "SelectADDRIndirect", [], []>;
81 def R600_Pred : PredicateOperand<i32, (ops R600_Predicate),
85 let mayLoad = 0, mayStore = 0, hasSideEffects = 0 in {
87 // Class for instructions with only one source register.
88 // If you add new ins to this instruction, make sure they are listed before
89 // $literal, because the backend currently assumes that the last operand is
90 // a literal. Also be sure to update the enum R600Op1OperandIndex::ROI in
91 // R600Defines.h, R600InstrInfo::buildDefaultInstruction(),
92 // and R600InstrInfo::getOperandIdx().
93 class R600_1OP <bits<11> inst, string opName, list<dag> pattern,
94 InstrItinClass itin = AnyALU> :
95 InstR600 <(outs R600_Reg32:$dst),
96 (ins WRITE:$write, OMOD:$omod, REL:$dst_rel, CLAMP:$clamp,
97 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel, ABS:$src0_abs, SEL:$src0_sel,
98 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal,
99 BANK_SWIZZLE:$bank_swizzle),
100 !strconcat(" ", opName,
101 "$clamp $last $dst$write$dst_rel$omod, "
102 "$src0_neg$src0_abs$src0$src0_abs$src0_rel, "
103 "$pred_sel $bank_swizzle"),
107 R600ALU_Word1_OP2 <inst> {
113 let update_exec_mask = 0;
115 let HasNativeOperands = 1;
117 let DisableEncoding = "$literal";
119 let Inst{31-0} = Word0;
120 let Inst{63-32} = Word1;
123 class R600_1OP_Helper <bits<11> inst, string opName, SDPatternOperator node,
124 InstrItinClass itin = AnyALU> :
125 R600_1OP <inst, opName,
126 [(set R600_Reg32:$dst, (node R600_Reg32:$src0))]
129 // If you add or change the operands for R600_2OP instructions, you must
130 // also update the R600Op2OperandIndex::ROI enum in R600Defines.h,
131 // R600InstrInfo::buildDefaultInstruction(), and R600InstrInfo::getOperandIdx().
132 class R600_2OP <bits<11> inst, string opName, list<dag> pattern,
133 InstrItinClass itin = AnyALU> :
134 InstR600 <(outs R600_Reg32:$dst),
135 (ins UEM:$update_exec_mask, UP:$update_pred, WRITE:$write,
136 OMOD:$omod, REL:$dst_rel, CLAMP:$clamp,
137 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel, ABS:$src0_abs, SEL:$src0_sel,
138 R600_Reg32:$src1, NEG:$src1_neg, REL:$src1_rel, ABS:$src1_abs, SEL:$src1_sel,
139 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal,
140 BANK_SWIZZLE:$bank_swizzle),
141 !strconcat(" ", opName,
142 "$clamp $last $update_exec_mask$update_pred$dst$write$dst_rel$omod, "
143 "$src0_neg$src0_abs$src0$src0_abs$src0_rel, "
144 "$src1_neg$src1_abs$src1$src1_abs$src1_rel, "
145 "$pred_sel $bank_swizzle"),
149 R600ALU_Word1_OP2 <inst> {
151 let HasNativeOperands = 1;
153 let DisableEncoding = "$literal";
155 let Inst{31-0} = Word0;
156 let Inst{63-32} = Word1;
159 class R600_2OP_Helper <bits<11> inst, string opName, SDPatternOperator node,
160 InstrItinClass itim = AnyALU> :
161 R600_2OP <inst, opName,
162 [(set R600_Reg32:$dst, (node R600_Reg32:$src0,
166 // If you add our change the operands for R600_3OP instructions, you must
167 // also update the R600Op3OperandIndex::ROI enum in R600Defines.h,
168 // R600InstrInfo::buildDefaultInstruction(), and
169 // R600InstrInfo::getOperandIdx().
170 class R600_3OP <bits<5> inst, string opName, list<dag> pattern,
171 InstrItinClass itin = AnyALU> :
172 InstR600 <(outs R600_Reg32:$dst),
173 (ins REL:$dst_rel, CLAMP:$clamp,
174 R600_Reg32:$src0, NEG:$src0_neg, REL:$src0_rel, SEL:$src0_sel,
175 R600_Reg32:$src1, NEG:$src1_neg, REL:$src1_rel, SEL:$src1_sel,
176 R600_Reg32:$src2, NEG:$src2_neg, REL:$src2_rel, SEL:$src2_sel,
177 LAST:$last, R600_Pred:$pred_sel, LITERAL:$literal,
178 BANK_SWIZZLE:$bank_swizzle),
179 !strconcat(" ", opName, "$clamp $last $dst$dst_rel, "
180 "$src0_neg$src0$src0_rel, "
181 "$src1_neg$src1$src1_rel, "
182 "$src2_neg$src2$src2_rel, "
188 R600ALU_Word1_OP3<inst>{
190 let HasNativeOperands = 1;
191 let DisableEncoding = "$literal";
194 let Inst{31-0} = Word0;
195 let Inst{63-32} = Word1;
198 class R600_REDUCTION <bits<11> inst, dag ins, string asm, list<dag> pattern,
199 InstrItinClass itin = VecALU> :
200 InstR600 <(outs R600_Reg32:$dst),
208 } // End mayLoad = 1, mayStore = 0, hasSideEffects = 0
210 def TEX_SHADOW : PatLeaf<
212 [{uint32_t TType = (uint32_t)N->getZExtValue();
213 return (TType >= 6 && TType <= 8) || (TType >= 11 && TType <= 13);
217 def TEX_RECT : PatLeaf<
219 [{uint32_t TType = (uint32_t)N->getZExtValue();
224 def TEX_ARRAY : PatLeaf<
226 [{uint32_t TType = (uint32_t)N->getZExtValue();
227 return TType == 9 || TType == 10 || TType == 15 || TType == 16;
231 def TEX_SHADOW_ARRAY : PatLeaf<
233 [{uint32_t TType = (uint32_t)N->getZExtValue();
234 return TType == 11 || TType == 12 || TType == 17;
238 class EG_CF_RAT <bits <8> cfinst, bits <6> ratinst, bits<4> mask, dag outs,
239 dag ins, string asm, list<dag> pattern> :
240 InstR600ISA <outs, ins, asm, pattern>,
241 CF_ALLOC_EXPORT_WORD0_RAT, CF_ALLOC_EXPORT_WORD1_BUF {
244 let rat_inst = ratinst;
246 // XXX: Have a separate instruction for non-indexed writes.
252 let comp_mask = mask;
255 let cf_inst = cfinst;
259 let Inst{31-0} = Word0;
260 let Inst{63-32} = Word1;
264 class VTX_READ <string name, bits<8> buffer_id, dag outs, list<dag> pattern>
265 : InstR600ISA <outs, (ins MEMxi:$src_gpr), name, pattern>,
270 // The docs say that if this bit is set, then DATA_FORMAT, NUM_FORMAT_ALL,
271 // FORMAT_COMP_ALL, SRF_MODE_ALL, and ENDIAN_SWAP fields will be ignored,
272 // however, based on my testing if USE_CONST_FIELDS is set, then all
273 // these fields need to be set to 0.
274 let USE_CONST_FIELDS = 0;
275 let NUM_FORMAT_ALL = 1;
276 let FORMAT_COMP_ALL = 0;
277 let SRF_MODE_ALL = 0;
279 let Inst{63-32} = Word1;
280 // LLVM can only encode 64-bit instructions, so these fields are manually
281 // encoded in R600CodeEmitter
284 // bits<2> ENDIAN_SWAP = 0;
285 // bits<1> CONST_BUF_NO_STRIDE = 0;
286 // bits<1> MEGA_FETCH = 0;
287 // bits<1> ALT_CONST = 0;
288 // bits<2> BUFFER_INDEX_MODE = 0;
290 // VTX_WORD2 (LLVM can only encode 64-bit instructions, so WORD2 encoding
291 // is done in R600CodeEmitter
293 // Inst{79-64} = OFFSET;
294 // Inst{81-80} = ENDIAN_SWAP;
295 // Inst{82} = CONST_BUF_NO_STRIDE;
296 // Inst{83} = MEGA_FETCH;
297 // Inst{84} = ALT_CONST;
298 // Inst{86-85} = BUFFER_INDEX_MODE;
299 // Inst{95-86} = 0; Reserved
301 // VTX_WORD3 (Padding)
308 class LoadParamFrag <PatFrag load_type> : PatFrag <
309 (ops node:$ptr), (load_type node:$ptr),
310 [{ return isParamLoad(dyn_cast<LoadSDNode>(N)); }]
313 def load_param : LoadParamFrag<load>;
314 def load_param_zexti8 : LoadParamFrag<zextloadi8>;
315 def load_param_zexti16 : LoadParamFrag<zextloadi16>;
317 def isR600 : Predicate<"Subtarget.getGeneration() <= AMDGPUSubtarget::R700">;
318 def isR700 : Predicate<"Subtarget.getGeneration() == AMDGPUSubtarget::R700">;
319 def isEG : Predicate<
320 "Subtarget.getGeneration() >= AMDGPUSubtarget::EVERGREEN && "
321 "Subtarget.getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS && "
322 "!Subtarget.hasCaymanISA()">;
324 def isCayman : Predicate<"Subtarget.hasCaymanISA()">;
325 def isEGorCayman : Predicate<"Subtarget.getGeneration() == "
326 "AMDGPUSubtarget::EVERGREEN"
327 "|| Subtarget.getGeneration() =="
328 "AMDGPUSubtarget::NORTHERN_ISLANDS">;
330 def isR600toCayman : Predicate<
331 "Subtarget.getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS">;
333 //===----------------------------------------------------------------------===//
335 //===----------------------------------------------------------------------===//
337 def INTERP_PAIR_XY : AMDGPUShaderInst <
338 (outs R600_TReg32_X:$dst0, R600_TReg32_Y:$dst1),
339 (ins i32imm:$src0, R600_TReg32_Y:$src1, R600_TReg32_X:$src2),
340 "INTERP_PAIR_XY $src0 $src1 $src2 : $dst0 dst1",
343 def INTERP_PAIR_ZW : AMDGPUShaderInst <
344 (outs R600_TReg32_Z:$dst0, R600_TReg32_W:$dst1),
345 (ins i32imm:$src0, R600_TReg32_Y:$src1, R600_TReg32_X:$src2),
346 "INTERP_PAIR_ZW $src0 $src1 $src2 : $dst0 dst1",
349 def CONST_ADDRESS: SDNode<"AMDGPUISD::CONST_ADDRESS",
350 SDTypeProfile<1, -1, [SDTCisInt<0>, SDTCisPtrTy<1>]>,
354 def DOT4 : SDNode<"AMDGPUISD::DOT4",
355 SDTypeProfile<1, 8, [SDTCisFP<0>, SDTCisVT<1, f32>, SDTCisVT<2, f32>,
356 SDTCisVT<3, f32>, SDTCisVT<4, f32>, SDTCisVT<5, f32>,
357 SDTCisVT<6, f32>, SDTCisVT<7, f32>, SDTCisVT<8, f32>]>,
361 def TEXTURE_FETCH_Type : SDTypeProfile<1, 19, [SDTCisFP<0>]>;
363 def TEXTURE_FETCH: SDNode<"AMDGPUISD::TEXTURE_FETCH", TEXTURE_FETCH_Type, []>;
365 multiclass TexPattern<bits<32> TextureOp, Instruction inst, ValueType vt = v4f32> {
366 def : Pat<(TEXTURE_FETCH (i32 TextureOp), vt:$SRC_GPR,
367 (i32 imm:$srcx), (i32 imm:$srcy), (i32 imm:$srcz), (i32 imm:$srcw),
368 (i32 imm:$offsetx), (i32 imm:$offsety), (i32 imm:$offsetz),
369 (i32 imm:$DST_SEL_X), (i32 imm:$DST_SEL_Y), (i32 imm:$DST_SEL_Z),
370 (i32 imm:$DST_SEL_W),
371 (i32 imm:$RESOURCE_ID), (i32 imm:$SAMPLER_ID),
372 (i32 imm:$COORD_TYPE_X), (i32 imm:$COORD_TYPE_Y), (i32 imm:$COORD_TYPE_Z),
373 (i32 imm:$COORD_TYPE_W)),
374 (inst R600_Reg128:$SRC_GPR,
375 imm:$srcx, imm:$srcy, imm:$srcz, imm:$srcw,
376 imm:$offsetx, imm:$offsety, imm:$offsetz,
377 imm:$DST_SEL_X, imm:$DST_SEL_Y, imm:$DST_SEL_Z,
379 imm:$RESOURCE_ID, imm:$SAMPLER_ID,
380 imm:$COORD_TYPE_X, imm:$COORD_TYPE_Y, imm:$COORD_TYPE_Z,
384 //===----------------------------------------------------------------------===//
385 // Interpolation Instructions
386 //===----------------------------------------------------------------------===//
388 def INTERP_VEC_LOAD : AMDGPUShaderInst <
389 (outs R600_Reg128:$dst),
391 "INTERP_LOAD $src0 : $dst",
394 def INTERP_XY : R600_2OP <0xD6, "INTERP_XY", []> {
395 let bank_swizzle = 5;
398 def INTERP_ZW : R600_2OP <0xD7, "INTERP_ZW", []> {
399 let bank_swizzle = 5;
402 def INTERP_LOAD_P0 : R600_1OP <0xE0, "INTERP_LOAD_P0", []>;
404 //===----------------------------------------------------------------------===//
405 // Export Instructions
406 //===----------------------------------------------------------------------===//
408 def ExportType : SDTypeProfile<0, 7, [SDTCisFP<0>, SDTCisInt<1>]>;
410 def EXPORT: SDNode<"AMDGPUISD::EXPORT", ExportType,
411 [SDNPHasChain, SDNPSideEffect]>;
414 field bits<32> Word0;
421 let Word0{12-0} = arraybase;
422 let Word0{14-13} = type;
423 let Word0{21-15} = gpr;
424 let Word0{22} = 0; // RW_REL
425 let Word0{29-23} = 0; // INDEX_GPR
426 let Word0{31-30} = elem_size;
429 class ExportSwzWord1 {
430 field bits<32> Word1;
439 let Word1{2-0} = sw_x;
440 let Word1{5-3} = sw_y;
441 let Word1{8-6} = sw_z;
442 let Word1{11-9} = sw_w;
445 class ExportBufWord1 {
446 field bits<32> Word1;
453 let Word1{11-0} = arraySize;
454 let Word1{15-12} = compMask;
457 multiclass ExportPattern<Instruction ExportInst, bits<8> cf_inst> {
458 def : Pat<(int_R600_store_pixel_depth R600_Reg32:$reg),
460 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), R600_Reg32:$reg, sub0),
461 0, 61, 0, 7, 7, 7, cf_inst, 0)
464 def : Pat<(int_R600_store_pixel_stencil R600_Reg32:$reg),
466 (INSERT_SUBREG (v4f32 (IMPLICIT_DEF)), R600_Reg32:$reg, sub0),
467 0, 61, 7, 0, 7, 7, cf_inst, 0)
470 def : Pat<(int_R600_store_dummy (i32 imm:$type)),
472 (v4f32 (IMPLICIT_DEF)), imm:$type, 0, 7, 7, 7, 7, cf_inst, 0)
475 def : Pat<(int_R600_store_dummy 1),
477 (v4f32 (IMPLICIT_DEF)), 1, 60, 7, 7, 7, 7, cf_inst, 0)
480 def : Pat<(EXPORT (v4f32 R600_Reg128:$src), (i32 imm:$base), (i32 imm:$type),
481 (i32 imm:$swz_x), (i32 imm:$swz_y), (i32 imm:$swz_z), (i32 imm:$swz_w)),
482 (ExportInst R600_Reg128:$src, imm:$type, imm:$base,
483 imm:$swz_x, imm:$swz_y, imm:$swz_z, imm:$swz_w, cf_inst, 0)
488 multiclass SteamOutputExportPattern<Instruction ExportInst,
489 bits<8> buf0inst, bits<8> buf1inst, bits<8> buf2inst, bits<8> buf3inst> {
491 def : Pat<(int_R600_store_stream_output (v4f32 R600_Reg128:$src),
492 (i32 imm:$arraybase), (i32 0), (i32 imm:$mask)),
493 (ExportInst R600_Reg128:$src, 0, imm:$arraybase,
494 4095, imm:$mask, buf0inst, 0)>;
496 def : Pat<(int_R600_store_stream_output (v4f32 R600_Reg128:$src),
497 (i32 imm:$arraybase), (i32 1), (i32 imm:$mask)),
498 (ExportInst R600_Reg128:$src, 0, imm:$arraybase,
499 4095, imm:$mask, buf1inst, 0)>;
501 def : Pat<(int_R600_store_stream_output (v4f32 R600_Reg128:$src),
502 (i32 imm:$arraybase), (i32 2), (i32 imm:$mask)),
503 (ExportInst R600_Reg128:$src, 0, imm:$arraybase,
504 4095, imm:$mask, buf2inst, 0)>;
506 def : Pat<(int_R600_store_stream_output (v4f32 R600_Reg128:$src),
507 (i32 imm:$arraybase), (i32 3), (i32 imm:$mask)),
508 (ExportInst R600_Reg128:$src, 0, imm:$arraybase,
509 4095, imm:$mask, buf3inst, 0)>;
512 // Export Instructions should not be duplicated by TailDuplication pass
513 // (which assumes that duplicable instruction are affected by exec mask)
514 let usesCustomInserter = 1, isNotDuplicable = 1 in {
516 class ExportSwzInst : InstR600ISA<(
518 (ins R600_Reg128:$gpr, i32imm:$type, i32imm:$arraybase,
519 i32imm:$sw_x, i32imm:$sw_y, i32imm:$sw_z, i32imm:$sw_w, i32imm:$inst,
521 !strconcat("EXPORT", " $gpr"),
522 []>, ExportWord0, ExportSwzWord1 {
524 let Inst{31-0} = Word0;
525 let Inst{63-32} = Word1;
528 } // End usesCustomInserter = 1
530 class ExportBufInst : InstR600ISA<(
532 (ins R600_Reg128:$gpr, i32imm:$type, i32imm:$arraybase,
533 i32imm:$arraySize, i32imm:$compMask, i32imm:$inst, i32imm:$eop),
534 !strconcat("EXPORT", " $gpr"),
535 []>, ExportWord0, ExportBufWord1 {
537 let Inst{31-0} = Word0;
538 let Inst{63-32} = Word1;
541 //===----------------------------------------------------------------------===//
542 // Control Flow Instructions
543 //===----------------------------------------------------------------------===//
546 def KCACHE : InstFlag<"printKCache">;
548 class ALU_CLAUSE<bits<4> inst, string OpName> : AMDGPUInst <(outs),
549 (ins i32imm:$ADDR, i32imm:$KCACHE_BANK0, i32imm:$KCACHE_BANK1,
550 KCACHE:$KCACHE_MODE0, KCACHE:$KCACHE_MODE1,
551 i32imm:$KCACHE_ADDR0, i32imm:$KCACHE_ADDR1,
553 !strconcat(OpName, " $COUNT, @$ADDR, "
554 "KC0[$KCACHE_MODE0], KC1[$KCACHE_MODE1]"),
555 [] >, CF_ALU_WORD0, CF_ALU_WORD1 {
560 let WHOLE_QUAD_MODE = 0;
563 let Inst{31-0} = Word0;
564 let Inst{63-32} = Word1;
567 class CF_WORD0_R600 {
568 field bits<32> Word0;
575 class CF_CLAUSE_R600 <bits<7> inst, dag ins, string AsmPrint> : AMDGPUInst <(outs),
576 ins, AsmPrint, [] >, CF_WORD0_R600, CF_WORD1_R600 {
583 let VALID_PIXEL_MODE = 0;
585 let COUNT = CNT{2-0};
587 let COUNT_3 = CNT{3};
588 let END_OF_PROGRAM = 0;
589 let WHOLE_QUAD_MODE = 0;
591 let Inst{31-0} = Word0;
592 let Inst{63-32} = Word1;
595 class CF_CLAUSE_EG <bits<8> inst, dag ins, string AsmPrint> : AMDGPUInst <(outs),
596 ins, AsmPrint, [] >, CF_WORD0_EG, CF_WORD1_EG {
601 let JUMPTABLE_SEL = 0;
603 let VALID_PIXEL_MODE = 0;
605 let END_OF_PROGRAM = 0;
607 let Inst{31-0} = Word0;
608 let Inst{63-32} = Word1;
611 def CF_ALU : ALU_CLAUSE<8, "ALU">;
612 def CF_ALU_PUSH_BEFORE : ALU_CLAUSE<9, "ALU_PUSH_BEFORE">;
614 def FETCH_CLAUSE : AMDGPUInst <(outs),
615 (ins i32imm:$addr), "Fetch clause starting at $addr:", [] > {
621 def ALU_CLAUSE : AMDGPUInst <(outs),
622 (ins i32imm:$addr), "ALU clause starting at $addr:", [] > {
628 def LITERALS : AMDGPUInst <(outs),
629 (ins LITERAL:$literal1, LITERAL:$literal2), "$literal1, $literal2", [] > {
634 let Inst{31-0} = literal1;
635 let Inst{63-32} = literal2;
638 def PAD : AMDGPUInst <(outs), (ins), "PAD", [] > {
642 let Predicates = [isR600toCayman] in {
644 //===----------------------------------------------------------------------===//
645 // Common Instructions R600, R700, Evergreen, Cayman
646 //===----------------------------------------------------------------------===//
648 def ADD : R600_2OP_Helper <0x0, "ADD", fadd>;
649 // Non-IEEE MUL: 0 * anything = 0
650 def MUL : R600_2OP_Helper <0x1, "MUL NON-IEEE", int_AMDGPU_mul>;
651 def MUL_IEEE : R600_2OP_Helper <0x2, "MUL_IEEE", fmul>;
652 def MAX : R600_2OP_Helper <0x3, "MAX", AMDGPUfmax>;
653 def MIN : R600_2OP_Helper <0x4, "MIN", AMDGPUfmin>;
655 // For the SET* instructions there is a naming conflict in TargetSelectionDAG.td,
656 // so some of the instruction names don't match the asm string.
657 // XXX: Use the defs in TargetSelectionDAG.td instead of intrinsics.
658 def SETE : R600_2OP <
660 [(set f32:$dst, (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_EQ))]
665 [(set f32:$dst, (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_GT))]
670 [(set f32:$dst, (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_GE))]
675 [(set f32:$dst, (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_NE))]
678 def SETE_DX10 : R600_2OP <
680 [(set i32:$dst, (selectcc f32:$src0, f32:$src1, -1, 0, COND_EQ))]
683 def SETGT_DX10 : R600_2OP <
685 [(set i32:$dst, (selectcc f32:$src0, f32:$src1, -1, 0, COND_GT))]
688 def SETGE_DX10 : R600_2OP <
690 [(set i32:$dst, (selectcc f32:$src0, f32:$src1, -1, 0, COND_GE))]
693 def SETNE_DX10 : R600_2OP <
695 [(set i32:$dst, (selectcc f32:$src0, f32:$src1, -1, 0, COND_NE))]
698 def FRACT : R600_1OP_Helper <0x10, "FRACT", AMDGPUfract>;
699 def TRUNC : R600_1OP_Helper <0x11, "TRUNC", int_AMDGPU_trunc>;
700 def CEIL : R600_1OP_Helper <0x12, "CEIL", fceil>;
701 def RNDNE : R600_1OP_Helper <0x13, "RNDNE", frint>;
702 def FLOOR : R600_1OP_Helper <0x14, "FLOOR", ffloor>;
704 def MOV : R600_1OP <0x19, "MOV", []>;
706 let isPseudo = 1, isCodeGenOnly = 1, usesCustomInserter = 1 in {
708 class MOV_IMM <ValueType vt, Operand immType> : AMDGPUInst <
709 (outs R600_Reg32:$dst),
715 } // end let isPseudo = 1, isCodeGenOnly = 1, usesCustomInserter = 1
717 def MOV_IMM_I32 : MOV_IMM<i32, i32imm>;
720 (MOV_IMM_I32 imm:$val)
723 def MOV_IMM_F32 : MOV_IMM<f32, f32imm>;
726 (MOV_IMM_F32 fpimm:$val)
729 def PRED_SETE : R600_2OP <0x20, "PRED_SETE", []>;
730 def PRED_SETGT : R600_2OP <0x21, "PRED_SETGT", []>;
731 def PRED_SETGE : R600_2OP <0x22, "PRED_SETGE", []>;
732 def PRED_SETNE : R600_2OP <0x23, "PRED_SETNE", []>;
734 let hasSideEffects = 1 in {
736 def KILLGT : R600_2OP <0x2D, "KILLGT", []>;
738 } // end hasSideEffects
740 def AND_INT : R600_2OP_Helper <0x30, "AND_INT", and>;
741 def OR_INT : R600_2OP_Helper <0x31, "OR_INT", or>;
742 def XOR_INT : R600_2OP_Helper <0x32, "XOR_INT", xor>;
743 def NOT_INT : R600_1OP_Helper <0x33, "NOT_INT", not>;
744 def ADD_INT : R600_2OP_Helper <0x34, "ADD_INT", add>;
745 def SUB_INT : R600_2OP_Helper <0x35, "SUB_INT", sub>;
746 def MAX_INT : R600_2OP_Helper <0x36, "MAX_INT", AMDGPUsmax>;
747 def MIN_INT : R600_2OP_Helper <0x37, "MIN_INT", AMDGPUsmin>;
748 def MAX_UINT : R600_2OP_Helper <0x38, "MAX_UINT", AMDGPUumax>;
749 def MIN_UINT : R600_2OP_Helper <0x39, "MIN_UINT", AMDGPUumin>;
751 def SETE_INT : R600_2OP <
753 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETEQ))]
756 def SETGT_INT : R600_2OP <
758 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETGT))]
761 def SETGE_INT : R600_2OP <
763 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETGE))]
766 def SETNE_INT : R600_2OP <
768 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETNE))]
771 def SETGT_UINT : R600_2OP <
773 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETUGT))]
776 def SETGE_UINT : R600_2OP <
778 [(set i32:$dst, (selectcc i32:$src0, i32:$src1, -1, 0, SETUGE))]
781 def PRED_SETE_INT : R600_2OP <0x42, "PRED_SETE_INT", []>;
782 def PRED_SETGT_INT : R600_2OP <0x43, "PRED_SETGE_INT", []>;
783 def PRED_SETGE_INT : R600_2OP <0x44, "PRED_SETGE_INT", []>;
784 def PRED_SETNE_INT : R600_2OP <0x45, "PRED_SETNE_INT", []>;
786 def CNDE_INT : R600_3OP <
788 [(set i32:$dst, (selectcc i32:$src0, 0, i32:$src1, i32:$src2, COND_EQ))]
791 def CNDGE_INT : R600_3OP <
793 [(set i32:$dst, (selectcc i32:$src0, 0, i32:$src1, i32:$src2, COND_GE))]
796 def CNDGT_INT : R600_3OP <
798 [(set i32:$dst, (selectcc i32:$src0, 0, i32:$src1, i32:$src2, COND_GT))]
801 //===----------------------------------------------------------------------===//
802 // Texture instructions
803 //===----------------------------------------------------------------------===//
805 let mayLoad = 0, mayStore = 0, hasSideEffects = 0 in {
807 class R600_TEX <bits<11> inst, string opName> :
808 InstR600 <(outs R600_Reg128:$DST_GPR),
809 (ins R600_Reg128:$SRC_GPR,
810 RSel:$srcx, RSel:$srcy, RSel:$srcz, RSel:$srcw,
811 i32imm:$offsetx, i32imm:$offsety, i32imm:$offsetz,
812 RSel:$DST_SEL_X, RSel:$DST_SEL_Y, RSel:$DST_SEL_Z, RSel:$DST_SEL_W,
813 i32imm:$RESOURCE_ID, i32imm:$SAMPLER_ID,
814 CT:$COORD_TYPE_X, CT:$COORD_TYPE_Y, CT:$COORD_TYPE_Z,
817 " $DST_GPR.$DST_SEL_X$DST_SEL_Y$DST_SEL_Z$DST_SEL_W, "
818 "$SRC_GPR.$srcx$srcy$srcz$srcw "
819 "RID:$RESOURCE_ID SID:$SAMPLER_ID "
820 "CT:$COORD_TYPE_X$COORD_TYPE_Y$COORD_TYPE_Z$COORD_TYPE_W"),
822 NullALU>, TEX_WORD0, TEX_WORD1, TEX_WORD2 {
823 let Inst{31-0} = Word0;
824 let Inst{63-32} = Word1;
826 let TEX_INST = inst{4-0};
832 let FETCH_WHOLE_QUAD = 0;
834 let SAMPLER_INDEX_MODE = 0;
835 let RESOURCE_INDEX_MODE = 0;
840 } // End mayLoad = 0, mayStore = 0, hasSideEffects = 0
844 def TEX_SAMPLE : R600_TEX <0x10, "TEX_SAMPLE">;
845 def TEX_SAMPLE_C : R600_TEX <0x18, "TEX_SAMPLE_C">;
846 def TEX_SAMPLE_L : R600_TEX <0x11, "TEX_SAMPLE_L">;
847 def TEX_SAMPLE_C_L : R600_TEX <0x19, "TEX_SAMPLE_C_L">;
848 def TEX_SAMPLE_LB : R600_TEX <0x12, "TEX_SAMPLE_LB">;
849 def TEX_SAMPLE_C_LB : R600_TEX <0x1A, "TEX_SAMPLE_C_LB">;
850 def TEX_LD : R600_TEX <0x03, "TEX_LD">;
851 def TEX_GET_TEXTURE_RESINFO : R600_TEX <0x04, "TEX_GET_TEXTURE_RESINFO">;
852 def TEX_GET_GRADIENTS_H : R600_TEX <0x07, "TEX_GET_GRADIENTS_H">;
853 def TEX_GET_GRADIENTS_V : R600_TEX <0x08, "TEX_GET_GRADIENTS_V">;
854 def TEX_SET_GRADIENTS_H : R600_TEX <0x0B, "TEX_SET_GRADIENTS_H">;
855 def TEX_SET_GRADIENTS_V : R600_TEX <0x0C, "TEX_SET_GRADIENTS_V">;
856 def TEX_SAMPLE_G : R600_TEX <0x14, "TEX_SAMPLE_G">;
857 def TEX_SAMPLE_C_G : R600_TEX <0x1C, "TEX_SAMPLE_C_G">;
859 defm : TexPattern<0, TEX_SAMPLE>;
860 defm : TexPattern<1, TEX_SAMPLE_C>;
861 defm : TexPattern<2, TEX_SAMPLE_L>;
862 defm : TexPattern<3, TEX_SAMPLE_C_L>;
863 defm : TexPattern<4, TEX_SAMPLE_LB>;
864 defm : TexPattern<5, TEX_SAMPLE_C_LB>;
865 defm : TexPattern<6, TEX_LD, v4i32>;
866 defm : TexPattern<7, TEX_GET_TEXTURE_RESINFO, v4i32>;
867 defm : TexPattern<8, TEX_GET_GRADIENTS_H>;
868 defm : TexPattern<9, TEX_GET_GRADIENTS_V>;
870 //===----------------------------------------------------------------------===//
871 // Helper classes for common instructions
872 //===----------------------------------------------------------------------===//
874 class MUL_LIT_Common <bits<5> inst> : R600_3OP <
879 class MULADD_Common <bits<5> inst> : R600_3OP <
884 class MULADD_IEEE_Common <bits<5> inst> : R600_3OP <
886 [(set f32:$dst, (fadd (fmul f32:$src0, f32:$src1), f32:$src2))]
889 class CNDE_Common <bits<5> inst> : R600_3OP <
891 [(set f32:$dst, (selectcc f32:$src0, FP_ZERO, f32:$src1, f32:$src2, COND_EQ))]
894 class CNDGT_Common <bits<5> inst> : R600_3OP <
896 [(set f32:$dst, (selectcc f32:$src0, FP_ZERO, f32:$src1, f32:$src2, COND_GT))]
899 class CNDGE_Common <bits<5> inst> : R600_3OP <
901 [(set f32:$dst, (selectcc f32:$src0, FP_ZERO, f32:$src1, f32:$src2, COND_GE))]
905 let isCodeGenOnly = 1, isPseudo = 1, Namespace = "AMDGPU" in {
906 class R600_VEC2OP<list<dag> pattern> : InstR600 <(outs R600_Reg32:$dst), (ins
908 UEM:$update_exec_mask_X, UP:$update_pred_X, WRITE:$write_X,
909 OMOD:$omod_X, REL:$dst_rel_X, CLAMP:$clamp_X,
910 R600_TReg32_X:$src0_X, NEG:$src0_neg_X, REL:$src0_rel_X, ABS:$src0_abs_X, SEL:$src0_sel_X,
911 R600_TReg32_X:$src1_X, NEG:$src1_neg_X, REL:$src1_rel_X, ABS:$src1_abs_X, SEL:$src1_sel_X,
912 R600_Pred:$pred_sel_X,
914 UEM:$update_exec_mask_Y, UP:$update_pred_Y, WRITE:$write_Y,
915 OMOD:$omod_Y, REL:$dst_rel_Y, CLAMP:$clamp_Y,
916 R600_TReg32_Y:$src0_Y, NEG:$src0_neg_Y, REL:$src0_rel_Y, ABS:$src0_abs_Y, SEL:$src0_sel_Y,
917 R600_TReg32_Y:$src1_Y, NEG:$src1_neg_Y, REL:$src1_rel_Y, ABS:$src1_abs_Y, SEL:$src1_sel_Y,
918 R600_Pred:$pred_sel_Y,
920 UEM:$update_exec_mask_Z, UP:$update_pred_Z, WRITE:$write_Z,
921 OMOD:$omod_Z, REL:$dst_rel_Z, CLAMP:$clamp_Z,
922 R600_TReg32_Z:$src0_Z, NEG:$src0_neg_Z, REL:$src0_rel_Z, ABS:$src0_abs_Z, SEL:$src0_sel_Z,
923 R600_TReg32_Z:$src1_Z, NEG:$src1_neg_Z, REL:$src1_rel_Z, ABS:$src1_abs_Z, SEL:$src1_sel_Z,
924 R600_Pred:$pred_sel_Z,
926 UEM:$update_exec_mask_W, UP:$update_pred_W, WRITE:$write_W,
927 OMOD:$omod_W, REL:$dst_rel_W, CLAMP:$clamp_W,
928 R600_TReg32_W:$src0_W, NEG:$src0_neg_W, REL:$src0_rel_W, ABS:$src0_abs_W, SEL:$src0_sel_W,
929 R600_TReg32_W:$src1_W, NEG:$src1_neg_W, REL:$src1_rel_W, ABS:$src1_abs_W, SEL:$src1_sel_W,
930 R600_Pred:$pred_sel_W,
931 LITERAL:$literal0, LITERAL:$literal1),
937 def DOT_4 : R600_VEC2OP<[(set R600_Reg32:$dst, (DOT4
938 R600_TReg32_X:$src0_X, R600_TReg32_X:$src1_X,
939 R600_TReg32_Y:$src0_Y, R600_TReg32_Y:$src1_Y,
940 R600_TReg32_Z:$src0_Z, R600_TReg32_Z:$src1_Z,
941 R600_TReg32_W:$src0_W, R600_TReg32_W:$src1_W))]>;
944 class DOT4_Common <bits<11> inst> : R600_2OP <inst, "DOT4", []>;
947 let mayLoad = 0, mayStore = 0, hasSideEffects = 0 in {
948 multiclass CUBE_Common <bits<11> inst> {
950 def _pseudo : InstR600 <
951 (outs R600_Reg128:$dst),
952 (ins R600_Reg128:$src),
954 [(set v4f32:$dst, (int_AMDGPU_cube v4f32:$src))],
960 def _real : R600_2OP <inst, "CUBE", []>;
962 } // End mayLoad = 0, mayStore = 0, hasSideEffects = 0
964 class EXP_IEEE_Common <bits<11> inst> : R600_1OP_Helper <
965 inst, "EXP_IEEE", fexp2
968 let Itinerary = TransALU;
971 class FLT_TO_INT_Common <bits<11> inst> : R600_1OP_Helper <
972 inst, "FLT_TO_INT", fp_to_sint
975 let Itinerary = TransALU;
978 class INT_TO_FLT_Common <bits<11> inst> : R600_1OP_Helper <
979 inst, "INT_TO_FLT", sint_to_fp
982 let Itinerary = TransALU;
985 class FLT_TO_UINT_Common <bits<11> inst> : R600_1OP_Helper <
986 inst, "FLT_TO_UINT", fp_to_uint
989 let Itinerary = TransALU;
992 class UINT_TO_FLT_Common <bits<11> inst> : R600_1OP_Helper <
993 inst, "UINT_TO_FLT", uint_to_fp
996 let Itinerary = TransALU;
999 class LOG_CLAMPED_Common <bits<11> inst> : R600_1OP <
1000 inst, "LOG_CLAMPED", []
1003 class LOG_IEEE_Common <bits<11> inst> : R600_1OP_Helper <
1004 inst, "LOG_IEEE", flog2
1007 let Itinerary = TransALU;
1010 class LSHL_Common <bits<11> inst> : R600_2OP_Helper <inst, "LSHL", shl>;
1011 class LSHR_Common <bits<11> inst> : R600_2OP_Helper <inst, "LSHR", srl>;
1012 class ASHR_Common <bits<11> inst> : R600_2OP_Helper <inst, "ASHR", sra>;
1013 class MULHI_INT_Common <bits<11> inst> : R600_2OP_Helper <
1014 inst, "MULHI_INT", mulhs
1017 let Itinerary = TransALU;
1019 class MULHI_UINT_Common <bits<11> inst> : R600_2OP_Helper <
1020 inst, "MULHI", mulhu
1023 let Itinerary = TransALU;
1025 class MULLO_INT_Common <bits<11> inst> : R600_2OP_Helper <
1026 inst, "MULLO_INT", mul
1029 let Itinerary = TransALU;
1031 class MULLO_UINT_Common <bits<11> inst> : R600_2OP <inst, "MULLO_UINT", []> {
1033 let Itinerary = TransALU;
1036 class RECIP_CLAMPED_Common <bits<11> inst> : R600_1OP <
1037 inst, "RECIP_CLAMPED", []
1040 let Itinerary = TransALU;
1043 class RECIP_IEEE_Common <bits<11> inst> : R600_1OP <
1044 inst, "RECIP_IEEE", [(set f32:$dst, (fdiv FP_ONE, f32:$src0))]
1047 let Itinerary = TransALU;
1050 class RECIP_UINT_Common <bits<11> inst> : R600_1OP_Helper <
1051 inst, "RECIP_UINT", AMDGPUurecip
1054 let Itinerary = TransALU;
1057 class RECIPSQRT_CLAMPED_Common <bits<11> inst> : R600_1OP_Helper <
1058 inst, "RECIPSQRT_CLAMPED", int_AMDGPU_rsq
1061 let Itinerary = TransALU;
1064 class RECIPSQRT_IEEE_Common <bits<11> inst> : R600_1OP <
1065 inst, "RECIPSQRT_IEEE", []
1068 let Itinerary = TransALU;
1071 class SIN_Common <bits<11> inst> : R600_1OP <
1075 let Itinerary = TransALU;
1078 class COS_Common <bits<11> inst> : R600_1OP <
1082 let Itinerary = TransALU;
1085 //===----------------------------------------------------------------------===//
1086 // Helper patterns for complex intrinsics
1087 //===----------------------------------------------------------------------===//
1089 multiclass DIV_Common <InstR600 recip_ieee> {
1091 (int_AMDGPU_div f32:$src0, f32:$src1),
1092 (MUL_IEEE $src0, (recip_ieee $src1))
1096 (fdiv f32:$src0, f32:$src1),
1097 (MUL_IEEE $src0, (recip_ieee $src1))
1101 class TGSI_LIT_Z_Common <InstR600 mul_lit, InstR600 log_clamped, InstR600 exp_ieee>
1103 (int_TGSI_lit_z f32:$src_x, f32:$src_y, f32:$src_w),
1104 (exp_ieee (mul_lit (log_clamped (MAX $src_y, (f32 ZERO))), $src_w, $src_x))
1107 //===----------------------------------------------------------------------===//
1108 // R600 / R700 Instructions
1109 //===----------------------------------------------------------------------===//
1111 let Predicates = [isR600] in {
1113 def MUL_LIT_r600 : MUL_LIT_Common<0x0C>;
1114 def MULADD_r600 : MULADD_Common<0x10>;
1115 def MULADD_IEEE_r600 : MULADD_IEEE_Common<0x14>;
1116 def CNDE_r600 : CNDE_Common<0x18>;
1117 def CNDGT_r600 : CNDGT_Common<0x19>;
1118 def CNDGE_r600 : CNDGE_Common<0x1A>;
1119 def DOT4_r600 : DOT4_Common<0x50>;
1120 defm CUBE_r600 : CUBE_Common<0x52>;
1121 def EXP_IEEE_r600 : EXP_IEEE_Common<0x61>;
1122 def LOG_CLAMPED_r600 : LOG_CLAMPED_Common<0x62>;
1123 def LOG_IEEE_r600 : LOG_IEEE_Common<0x63>;
1124 def RECIP_CLAMPED_r600 : RECIP_CLAMPED_Common<0x64>;
1125 def RECIP_IEEE_r600 : RECIP_IEEE_Common<0x66>;
1126 def RECIPSQRT_CLAMPED_r600 : RECIPSQRT_CLAMPED_Common<0x67>;
1127 def RECIPSQRT_IEEE_r600 : RECIPSQRT_IEEE_Common<0x69>;
1128 def FLT_TO_INT_r600 : FLT_TO_INT_Common<0x6b>;
1129 def INT_TO_FLT_r600 : INT_TO_FLT_Common<0x6c>;
1130 def FLT_TO_UINT_r600 : FLT_TO_UINT_Common<0x79>;
1131 def UINT_TO_FLT_r600 : UINT_TO_FLT_Common<0x6d>;
1132 def SIN_r600 : SIN_Common<0x6E>;
1133 def COS_r600 : COS_Common<0x6F>;
1134 def ASHR_r600 : ASHR_Common<0x70>;
1135 def LSHR_r600 : LSHR_Common<0x71>;
1136 def LSHL_r600 : LSHL_Common<0x72>;
1137 def MULLO_INT_r600 : MULLO_INT_Common<0x73>;
1138 def MULHI_INT_r600 : MULHI_INT_Common<0x74>;
1139 def MULLO_UINT_r600 : MULLO_UINT_Common<0x75>;
1140 def MULHI_UINT_r600 : MULHI_UINT_Common<0x76>;
1141 def RECIP_UINT_r600 : RECIP_UINT_Common <0x78>;
1143 defm DIV_r600 : DIV_Common<RECIP_IEEE_r600>;
1144 def : POW_Common <LOG_IEEE_r600, EXP_IEEE_r600, MUL>;
1145 def TGSI_LIT_Z_r600 : TGSI_LIT_Z_Common<MUL_LIT_r600, LOG_CLAMPED_r600, EXP_IEEE_r600>;
1147 def : Pat<(fsqrt f32:$src), (MUL $src, (RECIPSQRT_CLAMPED_r600 $src))>;
1149 def R600_ExportSwz : ExportSwzInst {
1150 let Word1{20-17} = 0; // BURST_COUNT
1151 let Word1{21} = eop;
1152 let Word1{22} = 1; // VALID_PIXEL_MODE
1153 let Word1{30-23} = inst;
1154 let Word1{31} = 1; // BARRIER
1156 defm : ExportPattern<R600_ExportSwz, 39>;
1158 def R600_ExportBuf : ExportBufInst {
1159 let Word1{20-17} = 0; // BURST_COUNT
1160 let Word1{21} = eop;
1161 let Word1{22} = 1; // VALID_PIXEL_MODE
1162 let Word1{30-23} = inst;
1163 let Word1{31} = 1; // BARRIER
1165 defm : SteamOutputExportPattern<R600_ExportBuf, 0x20, 0x21, 0x22, 0x23>;
1167 def CF_TC_R600 : CF_CLAUSE_R600<1, (ins i32imm:$ADDR, i32imm:$CNT),
1168 "TEX $CNT @$ADDR"> {
1171 def CF_VC_R600 : CF_CLAUSE_R600<2, (ins i32imm:$ADDR, i32imm:$CNT),
1172 "VTX $CNT @$ADDR"> {
1175 def WHILE_LOOP_R600 : CF_CLAUSE_R600<6, (ins i32imm:$ADDR),
1176 "LOOP_START_DX10 @$ADDR"> {
1180 def END_LOOP_R600 : CF_CLAUSE_R600<5, (ins i32imm:$ADDR), "END_LOOP @$ADDR"> {
1184 def LOOP_BREAK_R600 : CF_CLAUSE_R600<9, (ins i32imm:$ADDR),
1185 "LOOP_BREAK @$ADDR"> {
1189 def CF_CONTINUE_R600 : CF_CLAUSE_R600<8, (ins i32imm:$ADDR),
1190 "CONTINUE @$ADDR"> {
1194 def CF_JUMP_R600 : CF_CLAUSE_R600<10, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1195 "JUMP @$ADDR POP:$POP_COUNT"> {
1198 def CF_ELSE_R600 : CF_CLAUSE_R600<13, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1199 "ELSE @$ADDR POP:$POP_COUNT"> {
1202 def CF_CALL_FS_R600 : CF_CLAUSE_R600<19, (ins), "CALL_FS"> {
1207 def POP_R600 : CF_CLAUSE_R600<14, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1208 "POP @$ADDR POP:$POP_COUNT"> {
1211 def CF_END_R600 : CF_CLAUSE_R600<0, (ins), "CF_END"> {
1215 let END_OF_PROGRAM = 1;
1220 // Helper pattern for normalizing inputs to triginomic instructions for R700+
1222 class COS_PAT <InstR600 trig> : Pat<
1224 (trig (MUL_IEEE (MOV_IMM_I32 CONST.TWO_PI_INV), $src))
1227 class SIN_PAT <InstR600 trig> : Pat<
1229 (trig (MUL_IEEE (MOV_IMM_I32 CONST.TWO_PI_INV), $src))
1232 //===----------------------------------------------------------------------===//
1233 // R700 Only instructions
1234 //===----------------------------------------------------------------------===//
1236 let Predicates = [isR700] in {
1237 def SIN_r700 : SIN_Common<0x6E>;
1238 def COS_r700 : COS_Common<0x6F>;
1240 // R700 normalizes inputs to SIN/COS the same as EG
1241 def : SIN_PAT <SIN_r700>;
1242 def : COS_PAT <COS_r700>;
1245 //===----------------------------------------------------------------------===//
1246 // Evergreen Only instructions
1247 //===----------------------------------------------------------------------===//
1249 let Predicates = [isEG] in {
1251 def RECIP_IEEE_eg : RECIP_IEEE_Common<0x86>;
1252 defm DIV_eg : DIV_Common<RECIP_IEEE_eg>;
1254 def MULLO_INT_eg : MULLO_INT_Common<0x8F>;
1255 def MULHI_INT_eg : MULHI_INT_Common<0x90>;
1256 def MULLO_UINT_eg : MULLO_UINT_Common<0x91>;
1257 def MULHI_UINT_eg : MULHI_UINT_Common<0x92>;
1258 def RECIP_UINT_eg : RECIP_UINT_Common<0x94>;
1259 def RECIPSQRT_CLAMPED_eg : RECIPSQRT_CLAMPED_Common<0x87>;
1260 def EXP_IEEE_eg : EXP_IEEE_Common<0x81>;
1261 def LOG_IEEE_eg : LOG_IEEE_Common<0x83>;
1262 def RECIP_CLAMPED_eg : RECIP_CLAMPED_Common<0x84>;
1263 def RECIPSQRT_IEEE_eg : RECIPSQRT_IEEE_Common<0x89>;
1264 def SIN_eg : SIN_Common<0x8D>;
1265 def COS_eg : COS_Common<0x8E>;
1267 def : POW_Common <LOG_IEEE_eg, EXP_IEEE_eg, MUL>;
1268 def : SIN_PAT <SIN_eg>;
1269 def : COS_PAT <COS_eg>;
1270 def : Pat<(fsqrt f32:$src), (MUL $src, (RECIPSQRT_CLAMPED_eg $src))>;
1272 //===----------------------------------------------------------------------===//
1273 // Memory read/write instructions
1274 //===----------------------------------------------------------------------===//
1275 let usesCustomInserter = 1 in {
1277 class RAT_WRITE_CACHELESS_eg <dag ins, bits<4> mask, string name,
1279 : EG_CF_RAT <0x57, 0x2, mask, (outs), ins, name, pattern> {
1282 } // End usesCustomInserter = 1
1285 def RAT_WRITE_CACHELESS_32_eg : RAT_WRITE_CACHELESS_eg <
1286 (ins R600_TReg32_X:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
1287 0x1, "RAT_WRITE_CACHELESS_32_eg $rw_gpr, $index_gpr, $eop",
1288 [(global_store i32:$rw_gpr, i32:$index_gpr)]
1292 def RAT_WRITE_CACHELESS_128_eg : RAT_WRITE_CACHELESS_eg <
1293 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
1294 0xf, "RAT_WRITE_CACHELESS_128 $rw_gpr.XYZW, $index_gpr, $eop",
1295 [(global_store v4i32:$rw_gpr, i32:$index_gpr)]
1298 class VTX_READ_eg <string name, bits<8> buffer_id, dag outs, list<dag> pattern>
1299 : VTX_WORD0_eg, VTX_READ<name, buffer_id, outs, pattern> {
1304 let FETCH_WHOLE_QUAD = 0;
1305 let BUFFER_ID = buffer_id;
1307 // XXX: We can infer this field based on the SRC_GPR. This would allow us
1308 // to store vertex addresses in any channel, not just X.
1311 let Inst{31-0} = Word0;
1314 class VTX_READ_8_eg <bits<8> buffer_id, list<dag> pattern>
1315 : VTX_READ_eg <"VTX_READ_8 $dst_gpr, $src_gpr", buffer_id,
1316 (outs R600_TReg32_X:$dst_gpr), pattern> {
1318 let MEGA_FETCH_COUNT = 1;
1320 let DST_SEL_Y = 7; // Masked
1321 let DST_SEL_Z = 7; // Masked
1322 let DST_SEL_W = 7; // Masked
1323 let DATA_FORMAT = 1; // FMT_8
1326 class VTX_READ_16_eg <bits<8> buffer_id, list<dag> pattern>
1327 : VTX_READ_eg <"VTX_READ_16 $dst_gpr, $src_gpr", buffer_id,
1328 (outs R600_TReg32_X:$dst_gpr), pattern> {
1329 let MEGA_FETCH_COUNT = 2;
1331 let DST_SEL_Y = 7; // Masked
1332 let DST_SEL_Z = 7; // Masked
1333 let DST_SEL_W = 7; // Masked
1334 let DATA_FORMAT = 5; // FMT_16
1338 class VTX_READ_32_eg <bits<8> buffer_id, list<dag> pattern>
1339 : VTX_READ_eg <"VTX_READ_32 $dst_gpr, $src_gpr", buffer_id,
1340 (outs R600_TReg32_X:$dst_gpr), pattern> {
1342 let MEGA_FETCH_COUNT = 4;
1344 let DST_SEL_Y = 7; // Masked
1345 let DST_SEL_Z = 7; // Masked
1346 let DST_SEL_W = 7; // Masked
1347 let DATA_FORMAT = 0xD; // COLOR_32
1349 // This is not really necessary, but there were some GPU hangs that appeared
1350 // to be caused by ALU instructions in the next instruction group that wrote
1351 // to the $src_gpr registers of the VTX_READ.
1353 // %T3_X<def> = VTX_READ_PARAM_32_eg %T2_X<kill>, 24
1354 // %T2_X<def> = MOV %ZERO
1355 //Adding this constraint prevents this from happening.
1356 let Constraints = "$src_gpr.ptr = $dst_gpr";
1359 class VTX_READ_128_eg <bits<8> buffer_id, list<dag> pattern>
1360 : VTX_READ_eg <"VTX_READ_128 $dst_gpr.XYZW, $src_gpr", buffer_id,
1361 (outs R600_Reg128:$dst_gpr), pattern> {
1363 let MEGA_FETCH_COUNT = 16;
1368 let DATA_FORMAT = 0x22; // COLOR_32_32_32_32
1370 // XXX: Need to force VTX_READ_128 instructions to write to the same register
1371 // that holds its buffer address to avoid potential hangs. We can't use
1372 // the same constraint as VTX_READ_32_eg, because the $src_gpr.ptr and $dst
1373 // registers are different sizes.
1376 //===----------------------------------------------------------------------===//
1377 // VTX Read from parameter memory space
1378 //===----------------------------------------------------------------------===//
1380 def VTX_READ_PARAM_8_eg : VTX_READ_8_eg <0,
1381 [(set i32:$dst_gpr, (load_param_zexti8 ADDRVTX_READ:$src_gpr))]
1384 def VTX_READ_PARAM_16_eg : VTX_READ_16_eg <0,
1385 [(set i32:$dst_gpr, (load_param_zexti16 ADDRVTX_READ:$src_gpr))]
1388 def VTX_READ_PARAM_32_eg : VTX_READ_32_eg <0,
1389 [(set i32:$dst_gpr, (load_param ADDRVTX_READ:$src_gpr))]
1392 def VTX_READ_PARAM_128_eg : VTX_READ_128_eg <0,
1393 [(set v4i32:$dst_gpr, (load_param ADDRVTX_READ:$src_gpr))]
1396 //===----------------------------------------------------------------------===//
1397 // VTX Read from global memory space
1398 //===----------------------------------------------------------------------===//
1401 def VTX_READ_GLOBAL_8_eg : VTX_READ_8_eg <1,
1402 [(set i32:$dst_gpr, (zextloadi8_global ADDRVTX_READ:$src_gpr))]
1406 def VTX_READ_GLOBAL_32_eg : VTX_READ_32_eg <1,
1407 [(set i32:$dst_gpr, (global_load ADDRVTX_READ:$src_gpr))]
1411 def VTX_READ_GLOBAL_128_eg : VTX_READ_128_eg <1,
1412 [(set v4i32:$dst_gpr, (global_load ADDRVTX_READ:$src_gpr))]
1415 //===----------------------------------------------------------------------===//
1417 // XXX: We are currently storing all constants in the global address space.
1418 //===----------------------------------------------------------------------===//
1420 def CONSTANT_LOAD_eg : VTX_READ_32_eg <1,
1421 [(set i32:$dst_gpr, (constant_load ADDRVTX_READ:$src_gpr))]
1425 } // End Predicates = [isEG]
1427 //===----------------------------------------------------------------------===//
1428 // Evergreen / Cayman Instructions
1429 //===----------------------------------------------------------------------===//
1431 let Predicates = [isEGorCayman] in {
1433 // BFE_UINT - bit_extract, an optimization for mask and shift
1438 // bit_extract = (Input << (32 - Offset - Width)) >> (32 - Width)
1443 // (0, 8) = (Input << 24) >> 24 = (Input & 0xff) >> 0
1444 // (8, 8) = (Input << 16) >> 24 = (Input & 0xffff) >> 8
1445 // (16,8) = (Input << 8) >> 24 = (Input & 0xffffff) >> 16
1446 // (24,8) = (Input << 0) >> 24 = (Input & 0xffffffff) >> 24
1447 def BFE_UINT_eg : R600_3OP <0x4, "BFE_UINT",
1448 [(set i32:$dst, (int_AMDIL_bit_extract_u32 i32:$src0, i32:$src1,
1452 def : BFEPattern <BFE_UINT_eg>;
1454 def BFI_INT_eg : R600_3OP <0x06, "BFI_INT", [], VecALU>;
1455 defm : BFIPatterns <BFI_INT_eg>;
1457 def BIT_ALIGN_INT_eg : R600_3OP <0xC, "BIT_ALIGN_INT", [], VecALU>;
1458 def : ROTRPattern <BIT_ALIGN_INT_eg>;
1460 def MULADD_eg : MULADD_Common<0x14>;
1461 def MULADD_IEEE_eg : MULADD_IEEE_Common<0x18>;
1462 def ASHR_eg : ASHR_Common<0x15>;
1463 def LSHR_eg : LSHR_Common<0x16>;
1464 def LSHL_eg : LSHL_Common<0x17>;
1465 def CNDE_eg : CNDE_Common<0x19>;
1466 def CNDGT_eg : CNDGT_Common<0x1A>;
1467 def CNDGE_eg : CNDGE_Common<0x1B>;
1468 def MUL_LIT_eg : MUL_LIT_Common<0x1F>;
1469 def LOG_CLAMPED_eg : LOG_CLAMPED_Common<0x82>;
1470 def DOT4_eg : DOT4_Common<0xBE>;
1471 defm CUBE_eg : CUBE_Common<0xC0>;
1473 let hasSideEffects = 1 in {
1474 def MOVA_INT_eg : R600_1OP <0xCC, "MOVA_INT", []>;
1477 def TGSI_LIT_Z_eg : TGSI_LIT_Z_Common<MUL_LIT_eg, LOG_CLAMPED_eg, EXP_IEEE_eg>;
1479 def FLT_TO_INT_eg : FLT_TO_INT_Common<0x50> {
1483 def INT_TO_FLT_eg : INT_TO_FLT_Common<0x9B>;
1485 def FLT_TO_UINT_eg : FLT_TO_UINT_Common<0x9A> {
1489 def UINT_TO_FLT_eg : UINT_TO_FLT_Common<0x9C>;
1491 // TRUNC is used for the FLT_TO_INT instructions to work around a
1492 // perceived problem where the rounding modes are applied differently
1493 // depending on the instruction and the slot they are in.
1495 // https://bugs.freedesktop.org/show_bug.cgi?id=50232
1496 // Mesa commit: a1a0974401c467cb86ef818f22df67c21774a38c
1498 // XXX: Lowering SELECT_CC will sometimes generate fp_to_[su]int nodes,
1499 // which do not need to be truncated since the fp values are 0.0f or 1.0f.
1500 // We should look into handling these cases separately.
1501 def : Pat<(fp_to_sint f32:$src0), (FLT_TO_INT_eg (TRUNC $src0))>;
1503 def : Pat<(fp_to_uint f32:$src0), (FLT_TO_UINT_eg (TRUNC $src0))>;
1506 def : SHA256MaPattern <BFI_INT_eg, XOR_INT>;
1508 def EG_ExportSwz : ExportSwzInst {
1509 let Word1{19-16} = 0; // BURST_COUNT
1510 let Word1{20} = 1; // VALID_PIXEL_MODE
1511 let Word1{21} = eop;
1512 let Word1{29-22} = inst;
1513 let Word1{30} = 0; // MARK
1514 let Word1{31} = 1; // BARRIER
1516 defm : ExportPattern<EG_ExportSwz, 83>;
1518 def EG_ExportBuf : ExportBufInst {
1519 let Word1{19-16} = 0; // BURST_COUNT
1520 let Word1{20} = 1; // VALID_PIXEL_MODE
1521 let Word1{21} = eop;
1522 let Word1{29-22} = inst;
1523 let Word1{30} = 0; // MARK
1524 let Word1{31} = 1; // BARRIER
1526 defm : SteamOutputExportPattern<EG_ExportBuf, 0x40, 0x41, 0x42, 0x43>;
1528 def CF_TC_EG : CF_CLAUSE_EG<1, (ins i32imm:$ADDR, i32imm:$COUNT),
1529 "TEX $COUNT @$ADDR"> {
1532 def CF_VC_EG : CF_CLAUSE_EG<2, (ins i32imm:$ADDR, i32imm:$COUNT),
1533 "VTX $COUNT @$ADDR"> {
1536 def WHILE_LOOP_EG : CF_CLAUSE_EG<6, (ins i32imm:$ADDR),
1537 "LOOP_START_DX10 @$ADDR"> {
1541 def END_LOOP_EG : CF_CLAUSE_EG<5, (ins i32imm:$ADDR), "END_LOOP @$ADDR"> {
1545 def LOOP_BREAK_EG : CF_CLAUSE_EG<9, (ins i32imm:$ADDR),
1546 "LOOP_BREAK @$ADDR"> {
1550 def CF_CONTINUE_EG : CF_CLAUSE_EG<8, (ins i32imm:$ADDR),
1551 "CONTINUE @$ADDR"> {
1555 def CF_JUMP_EG : CF_CLAUSE_EG<10, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1556 "JUMP @$ADDR POP:$POP_COUNT"> {
1559 def CF_ELSE_EG : CF_CLAUSE_EG<13, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1560 "ELSE @$ADDR POP:$POP_COUNT"> {
1563 def CF_CALL_FS_EG : CF_CLAUSE_EG<19, (ins), "CALL_FS"> {
1568 def POP_EG : CF_CLAUSE_EG<14, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
1569 "POP @$ADDR POP:$POP_COUNT"> {
1572 def CF_END_EG : CF_CLAUSE_EG<0, (ins), "CF_END"> {
1576 let END_OF_PROGRAM = 1;
1579 } // End Predicates = [isEGorCayman]
1581 //===----------------------------------------------------------------------===//
1582 // Regist loads and stores - for indirect addressing
1583 //===----------------------------------------------------------------------===//
1585 defm R600_ : RegisterLoadStore <R600_Reg32, FRAMEri, ADDRIndirect>;
1587 //===----------------------------------------------------------------------===//
1588 // Cayman Instructions
1589 //===----------------------------------------------------------------------===//
1591 let Predicates = [isCayman] in {
1593 let isVector = 1 in {
1595 def RECIP_IEEE_cm : RECIP_IEEE_Common<0x86>;
1597 def MULLO_INT_cm : MULLO_INT_Common<0x8F>;
1598 def MULHI_INT_cm : MULHI_INT_Common<0x90>;
1599 def MULLO_UINT_cm : MULLO_UINT_Common<0x91>;
1600 def MULHI_UINT_cm : MULHI_UINT_Common<0x92>;
1601 def RECIPSQRT_CLAMPED_cm : RECIPSQRT_CLAMPED_Common<0x87>;
1602 def EXP_IEEE_cm : EXP_IEEE_Common<0x81>;
1603 def LOG_IEEE_cm : LOG_IEEE_Common<0x83>;
1604 def RECIP_CLAMPED_cm : RECIP_CLAMPED_Common<0x84>;
1605 def RECIPSQRT_IEEE_cm : RECIPSQRT_IEEE_Common<0x89>;
1606 def SIN_cm : SIN_Common<0x8D>;
1607 def COS_cm : COS_Common<0x8E>;
1608 } // End isVector = 1
1610 def : POW_Common <LOG_IEEE_cm, EXP_IEEE_cm, MUL>;
1611 def : SIN_PAT <SIN_cm>;
1612 def : COS_PAT <COS_cm>;
1614 defm DIV_cm : DIV_Common<RECIP_IEEE_cm>;
1616 // RECIP_UINT emulation for Cayman
1617 // The multiplication scales from [0,1] to the unsigned integer range
1619 (AMDGPUurecip i32:$src0),
1620 (FLT_TO_UINT_eg (MUL_IEEE (RECIP_IEEE_cm (UINT_TO_FLT_eg $src0)),
1621 (MOV_IMM_I32 CONST.FP_UINT_MAX_PLUS_1)))
1624 def CF_END_CM : CF_CLAUSE_EG<32, (ins), "CF_END"> {
1630 def : Pat<(fsqrt f32:$src), (MUL R600_Reg32:$src, (RECIPSQRT_CLAMPED_cm $src))>;
1633 def RAT_STORE_DWORD_cm : EG_CF_RAT <
1634 0x57, 0x14, 0x1, (outs),
1635 (ins R600_TReg32_X:$rw_gpr, R600_TReg32_X:$index_gpr),
1636 "EXPORT_RAT_INST_STORE_DWORD $rw_gpr, $index_gpr",
1637 [(global_store i32:$rw_gpr, i32:$index_gpr)]
1639 let eop = 0; // This bit is not used on Cayman.
1642 class VTX_READ_cm <string name, bits<8> buffer_id, dag outs, list<dag> pattern>
1643 : VTX_WORD0_cm, VTX_READ<name, buffer_id, outs, pattern> {
1648 let FETCH_WHOLE_QUAD = 0;
1649 let BUFFER_ID = buffer_id;
1651 // XXX: We can infer this field based on the SRC_GPR. This would allow us
1652 // to store vertex addresses in any channel, not just X.
1655 let STRUCTURED_READ = 0;
1657 let COALESCED_READ = 0;
1659 let Inst{31-0} = Word0;
1662 class VTX_READ_8_cm <bits<8> buffer_id, list<dag> pattern>
1663 : VTX_READ_cm <"VTX_READ_8 $dst_gpr, $src_gpr", buffer_id,
1664 (outs R600_TReg32_X:$dst_gpr), pattern> {
1667 let DST_SEL_Y = 7; // Masked
1668 let DST_SEL_Z = 7; // Masked
1669 let DST_SEL_W = 7; // Masked
1670 let DATA_FORMAT = 1; // FMT_8
1673 class VTX_READ_16_cm <bits<8> buffer_id, list<dag> pattern>
1674 : VTX_READ_cm <"VTX_READ_16 $dst_gpr, $src_gpr", buffer_id,
1675 (outs R600_TReg32_X:$dst_gpr), pattern> {
1677 let DST_SEL_Y = 7; // Masked
1678 let DST_SEL_Z = 7; // Masked
1679 let DST_SEL_W = 7; // Masked
1680 let DATA_FORMAT = 5; // FMT_16
1684 class VTX_READ_32_cm <bits<8> buffer_id, list<dag> pattern>
1685 : VTX_READ_cm <"VTX_READ_32 $dst_gpr, $src_gpr", buffer_id,
1686 (outs R600_TReg32_X:$dst_gpr), pattern> {
1689 let DST_SEL_Y = 7; // Masked
1690 let DST_SEL_Z = 7; // Masked
1691 let DST_SEL_W = 7; // Masked
1692 let DATA_FORMAT = 0xD; // COLOR_32
1694 // This is not really necessary, but there were some GPU hangs that appeared
1695 // to be caused by ALU instructions in the next instruction group that wrote
1696 // to the $src_gpr registers of the VTX_READ.
1698 // %T3_X<def> = VTX_READ_PARAM_32_eg %T2_X<kill>, 24
1699 // %T2_X<def> = MOV %ZERO
1700 //Adding this constraint prevents this from happening.
1701 let Constraints = "$src_gpr.ptr = $dst_gpr";
1704 class VTX_READ_128_cm <bits<8> buffer_id, list<dag> pattern>
1705 : VTX_READ_cm <"VTX_READ_128 $dst_gpr.XYZW, $src_gpr", buffer_id,
1706 (outs R600_Reg128:$dst_gpr), pattern> {
1712 let DATA_FORMAT = 0x22; // COLOR_32_32_32_32
1714 // XXX: Need to force VTX_READ_128 instructions to write to the same register
1715 // that holds its buffer address to avoid potential hangs. We can't use
1716 // the same constraint as VTX_READ_32_eg, because the $src_gpr.ptr and $dst
1717 // registers are different sizes.
1720 //===----------------------------------------------------------------------===//
1721 // VTX Read from parameter memory space
1722 //===----------------------------------------------------------------------===//
1723 def VTX_READ_PARAM_8_cm : VTX_READ_8_cm <0,
1724 [(set i32:$dst_gpr, (load_param_zexti8 ADDRVTX_READ:$src_gpr))]
1727 def VTX_READ_PARAM_16_cm : VTX_READ_16_cm <0,
1728 [(set i32:$dst_gpr, (load_param_zexti16 ADDRVTX_READ:$src_gpr))]
1731 def VTX_READ_PARAM_32_cm : VTX_READ_32_cm <0,
1732 [(set i32:$dst_gpr, (load_param ADDRVTX_READ:$src_gpr))]
1735 def VTX_READ_PARAM_128_cm : VTX_READ_128_cm <0,
1736 [(set v4i32:$dst_gpr, (load_param ADDRVTX_READ:$src_gpr))]
1739 //===----------------------------------------------------------------------===//
1740 // VTX Read from global memory space
1741 //===----------------------------------------------------------------------===//
1744 def VTX_READ_GLOBAL_8_cm : VTX_READ_8_cm <1,
1745 [(set i32:$dst_gpr, (zextloadi8_global ADDRVTX_READ:$src_gpr))]
1749 def VTX_READ_GLOBAL_32_cm : VTX_READ_32_cm <1,
1750 [(set i32:$dst_gpr, (global_load ADDRVTX_READ:$src_gpr))]
1754 def VTX_READ_GLOBAL_128_cm : VTX_READ_128_cm <1,
1755 [(set v4i32:$dst_gpr, (global_load ADDRVTX_READ:$src_gpr))]
1758 //===----------------------------------------------------------------------===//
1760 // XXX: We are currently storing all constants in the global address space.
1761 //===----------------------------------------------------------------------===//
1763 def CONSTANT_LOAD_cm : VTX_READ_32_cm <1,
1764 [(set i32:$dst_gpr, (constant_load ADDRVTX_READ:$src_gpr))]
1769 //===----------------------------------------------------------------------===//
1770 // Branch Instructions
1771 //===----------------------------------------------------------------------===//
1774 def IF_PREDICATE_SET : ILFormat<(outs), (ins GPRI32:$src),
1775 "IF_PREDICATE_SET $src", []>;
1777 def PREDICATED_BREAK : ILFormat<(outs), (ins GPRI32:$src),
1778 "PREDICATED_BREAK $src", []>;
1780 //===----------------------------------------------------------------------===//
1781 // Pseudo instructions
1782 //===----------------------------------------------------------------------===//
1784 let isPseudo = 1 in {
1786 def PRED_X : InstR600 <
1787 (outs R600_Predicate_Bit:$dst),
1788 (ins R600_Reg32:$src0, i32imm:$src1, i32imm:$flags),
1790 let FlagOperandIdx = 3;
1793 let isTerminator = 1, isBranch = 1 in {
1794 def JUMP_COND : InstR600 <
1796 (ins brtarget:$target, R600_Predicate_Bit:$p),
1797 "JUMP $target ($p)",
1801 def JUMP : InstR600 <
1803 (ins brtarget:$target),
1808 let isPredicable = 1;
1812 } // End isTerminator = 1, isBranch = 1
1814 let usesCustomInserter = 1 in {
1816 let mayLoad = 0, mayStore = 0, hasSideEffects = 1 in {
1818 def MASK_WRITE : AMDGPUShaderInst <
1820 (ins R600_Reg32:$src),
1825 } // End mayLoad = 0, mayStore = 0, hasSideEffects = 1
1829 (outs R600_Reg128:$dst),
1830 (ins R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2,
1831 i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget),
1832 "TXD $dst, $src0, $src1, $src2, $resourceId, $samplerId, $textureTarget",
1833 [(set v4f32:$dst, (int_AMDGPU_txd v4f32:$src0, v4f32:$src1, v4f32:$src2,
1834 imm:$resourceId, imm:$samplerId, imm:$textureTarget))],
1839 def TXD_SHADOW: InstR600 <
1840 (outs R600_Reg128:$dst),
1841 (ins R600_Reg128:$src0, R600_Reg128:$src1, R600_Reg128:$src2,
1842 i32imm:$resourceId, i32imm:$samplerId, i32imm:$textureTarget),
1843 "TXD_SHADOW $dst, $src0, $src1, $src2, $resourceId, $samplerId, $textureTarget",
1844 [(set v4f32:$dst, (int_AMDGPU_txd v4f32:$src0, v4f32:$src1, v4f32:$src2,
1845 imm:$resourceId, imm:$samplerId, TEX_SHADOW:$textureTarget))],
1850 } // End isPseudo = 1
1851 } // End usesCustomInserter = 1
1853 def CLAMP_R600 : CLAMP <R600_Reg32>;
1854 def FABS_R600 : FABS<R600_Reg32>;
1855 def FNEG_R600 : FNEG<R600_Reg32>;
1857 //===---------------------------------------------------------------------===//
1858 // Return instruction
1859 //===---------------------------------------------------------------------===//
1860 let isTerminator = 1, isReturn = 1, hasCtrlDep = 1,
1861 usesCustomInserter = 1 in {
1862 def RETURN : ILFormat<(outs), (ins variable_ops),
1863 "RETURN", [(IL_retflag)]>;
1867 //===----------------------------------------------------------------------===//
1868 // Constant Buffer Addressing Support
1869 //===----------------------------------------------------------------------===//
1871 let usesCustomInserter = 1, isCodeGenOnly = 1, isPseudo = 1, Namespace = "AMDGPU" in {
1872 def CONST_COPY : Instruction {
1873 let OutOperandList = (outs R600_Reg32:$dst);
1874 let InOperandList = (ins i32imm:$src);
1876 [(set R600_Reg32:$dst, (CONST_ADDRESS ADDRGA_CONST_OFFSET:$src))];
1877 let AsmString = "CONST_COPY";
1878 let neverHasSideEffects = 1;
1879 let isAsCheapAsAMove = 1;
1880 let Itinerary = NullALU;
1882 } // end usesCustomInserter = 1, isCodeGenOnly = 1, isPseudo = 1, Namespace = "AMDGPU"
1884 def TEX_VTX_CONSTBUF :
1885 InstR600ISA <(outs R600_Reg128:$dst), (ins MEMxi:$ptr, i32imm:$BUFFER_ID), "VTX_READ_eg $dst, $ptr",
1886 [(set v4i32:$dst, (CONST_ADDRESS ADDRGA_VAR_OFFSET:$ptr, (i32 imm:$BUFFER_ID)))]>,
1887 VTX_WORD1_GPR, VTX_WORD0_eg {
1891 let FETCH_WHOLE_QUAD = 0;
1895 let USE_CONST_FIELDS = 0;
1896 let NUM_FORMAT_ALL = 2;
1897 let FORMAT_COMP_ALL = 1;
1898 let SRF_MODE_ALL = 1;
1899 let MEGA_FETCH_COUNT = 16;
1904 let DATA_FORMAT = 35;
1906 let Inst{31-0} = Word0;
1907 let Inst{63-32} = Word1;
1909 // LLVM can only encode 64-bit instructions, so these fields are manually
1910 // encoded in R600CodeEmitter
1913 // bits<2> ENDIAN_SWAP = 0;
1914 // bits<1> CONST_BUF_NO_STRIDE = 0;
1915 // bits<1> MEGA_FETCH = 0;
1916 // bits<1> ALT_CONST = 0;
1917 // bits<2> BUFFER_INDEX_MODE = 0;
1921 // VTX_WORD2 (LLVM can only encode 64-bit instructions, so WORD2 encoding
1922 // is done in R600CodeEmitter
1924 // Inst{79-64} = OFFSET;
1925 // Inst{81-80} = ENDIAN_SWAP;
1926 // Inst{82} = CONST_BUF_NO_STRIDE;
1927 // Inst{83} = MEGA_FETCH;
1928 // Inst{84} = ALT_CONST;
1929 // Inst{86-85} = BUFFER_INDEX_MODE;
1930 // Inst{95-86} = 0; Reserved
1932 // VTX_WORD3 (Padding)
1934 // Inst{127-96} = 0;
1939 InstR600ISA <(outs R600_Reg128:$dst), (ins MEMxi:$ptr, i32imm:$BUFFER_ID), "TEX_VTX_EXPLICIT_READ $dst, $ptr",
1940 [(set v4f32:$dst, (int_R600_load_texbuf ADDRGA_VAR_OFFSET:$ptr, imm:$BUFFER_ID))]>,
1941 VTX_WORD1_GPR, VTX_WORD0_eg {
1945 let FETCH_WHOLE_QUAD = 0;
1949 let USE_CONST_FIELDS = 1;
1950 let NUM_FORMAT_ALL = 0;
1951 let FORMAT_COMP_ALL = 0;
1952 let SRF_MODE_ALL = 1;
1953 let MEGA_FETCH_COUNT = 16;
1958 let DATA_FORMAT = 0;
1960 let Inst{31-0} = Word0;
1961 let Inst{63-32} = Word1;
1963 // LLVM can only encode 64-bit instructions, so these fields are manually
1964 // encoded in R600CodeEmitter
1967 // bits<2> ENDIAN_SWAP = 0;
1968 // bits<1> CONST_BUF_NO_STRIDE = 0;
1969 // bits<1> MEGA_FETCH = 0;
1970 // bits<1> ALT_CONST = 0;
1971 // bits<2> BUFFER_INDEX_MODE = 0;
1975 // VTX_WORD2 (LLVM can only encode 64-bit instructions, so WORD2 encoding
1976 // is done in R600CodeEmitter
1978 // Inst{79-64} = OFFSET;
1979 // Inst{81-80} = ENDIAN_SWAP;
1980 // Inst{82} = CONST_BUF_NO_STRIDE;
1981 // Inst{83} = MEGA_FETCH;
1982 // Inst{84} = ALT_CONST;
1983 // Inst{86-85} = BUFFER_INDEX_MODE;
1984 // Inst{95-86} = 0; Reserved
1986 // VTX_WORD3 (Padding)
1988 // Inst{127-96} = 0;
1994 //===--------------------------------------------------------------------===//
1995 // Instructions support
1996 //===--------------------------------------------------------------------===//
1997 //===---------------------------------------------------------------------===//
1998 // Custom Inserter for Branches and returns, this eventually will be a
2000 //===---------------------------------------------------------------------===//
2001 let isTerminator = 1, usesCustomInserter = 1, isBranch = 1, isBarrier = 1 in {
2002 def BRANCH : ILFormat<(outs), (ins brtarget:$target),
2003 "; Pseudo unconditional branch instruction",
2005 defm BRANCH_COND : BranchConditional<IL_brcond>;
2008 //===---------------------------------------------------------------------===//
2009 // Flow and Program control Instructions
2010 //===---------------------------------------------------------------------===//
2011 let isTerminator=1 in {
2012 def SWITCH : ILFormat< (outs), (ins GPRI32:$src),
2013 !strconcat("SWITCH", " $src"), []>;
2014 def CASE : ILFormat< (outs), (ins GPRI32:$src),
2015 !strconcat("CASE", " $src"), []>;
2016 def BREAK : ILFormat< (outs), (ins),
2018 def CONTINUE : ILFormat< (outs), (ins),
2020 def DEFAULT : ILFormat< (outs), (ins),
2022 def ELSE : ILFormat< (outs), (ins),
2024 def ENDSWITCH : ILFormat< (outs), (ins),
2026 def ENDMAIN : ILFormat< (outs), (ins),
2028 def END : ILFormat< (outs), (ins),
2030 def ENDFUNC : ILFormat< (outs), (ins),
2032 def ENDIF : ILFormat< (outs), (ins),
2034 def WHILELOOP : ILFormat< (outs), (ins),
2036 def ENDLOOP : ILFormat< (outs), (ins),
2038 def FUNC : ILFormat< (outs), (ins),
2040 def RETDYN : ILFormat< (outs), (ins),
2042 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2043 defm IF_LOGICALNZ : BranchInstr<"IF_LOGICALNZ">;
2044 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2045 defm IF_LOGICALZ : BranchInstr<"IF_LOGICALZ">;
2046 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2047 defm BREAK_LOGICALNZ : BranchInstr<"BREAK_LOGICALNZ">;
2048 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2049 defm BREAK_LOGICALZ : BranchInstr<"BREAK_LOGICALZ">;
2050 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2051 defm CONTINUE_LOGICALNZ : BranchInstr<"CONTINUE_LOGICALNZ">;
2052 // This opcode has custom swizzle pattern encoded in Swizzle Encoder
2053 defm CONTINUE_LOGICALZ : BranchInstr<"CONTINUE_LOGICALZ">;
2054 defm IFC : BranchInstr2<"IFC">;
2055 defm BREAKC : BranchInstr2<"BREAKC">;
2056 defm CONTINUEC : BranchInstr2<"CONTINUEC">;
2059 //===----------------------------------------------------------------------===//
2061 //===----------------------------------------------------------------------===//
2063 // CND*_INT Pattterns for f32 True / False values
2065 class CND_INT_f32 <InstR600 cnd, CondCode cc> : Pat <
2066 (selectcc i32:$src0, 0, f32:$src1, f32:$src2, cc),
2067 (cnd $src0, $src1, $src2)
2070 def : CND_INT_f32 <CNDE_INT, SETEQ>;
2071 def : CND_INT_f32 <CNDGT_INT, SETGT>;
2072 def : CND_INT_f32 <CNDGE_INT, SETGE>;
2074 //CNDGE_INT extra pattern
2076 (selectcc i32:$src0, -1, i32:$src1, i32:$src2, COND_GT),
2077 (CNDGE_INT $src0, $src1, $src2)
2083 (MASK_WRITE (KILLGT (f32 ONE), (f32 ZERO)))
2087 (int_AMDGPU_kill f32:$src0),
2088 (MASK_WRITE (KILLGT (f32 ZERO), $src0))
2093 (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_LT),
2099 (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, COND_LE),
2103 // SETGT_DX10 reverse args
2105 (selectcc f32:$src0, f32:$src1, -1, 0, COND_LT),
2106 (SETGT_DX10 $src1, $src0)
2109 // SETGE_DX10 reverse args
2111 (selectcc f32:$src0, f32:$src1, -1, 0, COND_LE),
2112 (SETGE_DX10 $src1, $src0)
2115 // SETGT_INT reverse args
2117 (selectcc i32:$src0, i32:$src1, -1, 0, SETLT),
2118 (SETGT_INT $src1, $src0)
2121 // SETGE_INT reverse args
2123 (selectcc i32:$src0, i32:$src1, -1, 0, SETLE),
2124 (SETGE_INT $src1, $src0)
2127 // SETGT_UINT reverse args
2129 (selectcc i32:$src0, i32:$src1, -1, 0, SETULT),
2130 (SETGT_UINT $src1, $src0)
2133 // SETGE_UINT reverse args
2135 (selectcc i32:$src0, i32:$src1, -1, 0, SETULE),
2136 (SETGE_UINT $src1, $src0)
2139 // The next two patterns are special cases for handling 'true if ordered' and
2140 // 'true if unordered' conditionals. The assumption here is that the behavior of
2141 // SETE and SNE conforms to the Direct3D 10 rules for floating point values
2143 // http://msdn.microsoft.com/en-us/library/windows/desktop/cc308050.aspx#alpha_32_bit
2144 // We assume that SETE returns false when one of the operands is NAN and
2145 // SNE returns true when on of the operands is NAN
2147 //SETE - 'true if ordered'
2149 (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, SETO),
2153 //SETE_DX10 - 'true if ordered'
2155 (selectcc f32:$src0, f32:$src1, -1, 0, SETO),
2156 (SETE_DX10 $src0, $src1)
2159 //SNE - 'true if unordered'
2161 (selectcc f32:$src0, f32:$src1, FP_ONE, FP_ZERO, SETUO),
2165 //SETNE_DX10 - 'true if ordered'
2167 (selectcc f32:$src0, f32:$src1, -1, 0, SETUO),
2168 (SETNE_DX10 $src0, $src1)
2171 def : Extract_Element <f32, v4f32, 0, sub0>;
2172 def : Extract_Element <f32, v4f32, 1, sub1>;
2173 def : Extract_Element <f32, v4f32, 2, sub2>;
2174 def : Extract_Element <f32, v4f32, 3, sub3>;
2176 def : Insert_Element <f32, v4f32, 0, sub0>;
2177 def : Insert_Element <f32, v4f32, 1, sub1>;
2178 def : Insert_Element <f32, v4f32, 2, sub2>;
2179 def : Insert_Element <f32, v4f32, 3, sub3>;
2181 def : Extract_Element <i32, v4i32, 0, sub0>;
2182 def : Extract_Element <i32, v4i32, 1, sub1>;
2183 def : Extract_Element <i32, v4i32, 2, sub2>;
2184 def : Extract_Element <i32, v4i32, 3, sub3>;
2186 def : Insert_Element <i32, v4i32, 0, sub0>;
2187 def : Insert_Element <i32, v4i32, 1, sub1>;
2188 def : Insert_Element <i32, v4i32, 2, sub2>;
2189 def : Insert_Element <i32, v4i32, 3, sub3>;
2191 def : Vector4_Build <v4f32, f32>;
2192 def : Vector4_Build <v4i32, i32>;
2194 // bitconvert patterns
2196 def : BitConvert <i32, f32, R600_Reg32>;
2197 def : BitConvert <f32, i32, R600_Reg32>;
2198 def : BitConvert <v4f32, v4i32, R600_Reg128>;
2199 def : BitConvert <v4i32, v4f32, R600_Reg128>;
2201 // DWORDADDR pattern
2202 def : DwordAddrPat <i32, R600_Reg32>;
2204 } // End isR600toCayman Predicate