1 //===-- EvergreenInstructions.td - EG Instruction defs ----*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // TableGen definitions for instructions which are:
10 // - Available to Evergreen and newer VLIW4/VLIW5 GPUs
11 // - Available only on Evergreen family GPUs.
13 //===----------------------------------------------------------------------===//
16 "Subtarget->getGeneration() >= AMDGPUSubtarget::EVERGREEN && "
17 "!Subtarget->hasCaymanISA()"
20 def isEGorCayman : Predicate<
21 "Subtarget->getGeneration() == AMDGPUSubtarget::EVERGREEN ||"
22 "Subtarget->getGeneration() == AMDGPUSubtarget::NORTHERN_ISLANDS"
25 class EGPat<dag pattern, dag result> : AMDGPUPat<pattern, result> {
26 let SubtargetPredicate = isEG;
29 class EGOrCaymanPat<dag pattern, dag result> : AMDGPUPat<pattern, result> {
30 let SubtargetPredicate = isEGorCayman;
33 def IMMZeroBasedBitfieldMask : ImmLeaf <i32, [{
34 return isMask_32(Imm);
37 def IMMPopCount : SDNodeXForm<imm, [{
38 return CurDAG->getTargetConstant(llvm::popcount(N->getZExtValue()), SDLoc(N),
42 //===----------------------------------------------------------------------===//
43 // Evergreen / Cayman store instructions
44 //===----------------------------------------------------------------------===//
46 let SubtargetPredicate = isEGorCayman in {
48 class CF_MEM_RAT_CACHELESS <bits<6> rat_inst, bits<4> rat_id, bits<4> mask, dag ins,
49 string name, list<dag> pattern>
50 : EG_CF_RAT <0x57, rat_inst, rat_id, mask, (outs), ins,
51 "MEM_RAT_CACHELESS "#name, pattern>;
53 class CF_MEM_RAT <bits<6> rat_inst, bits<4> rat_id, bits<4> mask, dag ins,
54 dag outs, string name, list<dag> pattern>
55 : EG_CF_RAT <0x56, rat_inst, rat_id, mask, outs, ins,
56 "MEM_RAT "#name, pattern>;
58 class CF_MEM_RAT_STORE_TYPED<bits<1> has_eop>
59 : CF_MEM_RAT <0x1, ?, 0xf, (ins R600_Reg128:$rw_gpr, R600_Reg128:$index_gpr,
60 i32imm:$rat_id, InstFlag:$eop), (outs),
61 "STORE_TYPED RAT($rat_id) $rw_gpr, $index_gpr"
62 #!if(has_eop, ", $eop", ""),
63 [(int_r600_rat_store_typed R600_Reg128:$rw_gpr,
64 R600_Reg128:$index_gpr,
67 def RAT_MSKOR : CF_MEM_RAT <0x11, 0, 0xf,
68 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr), (outs),
69 "MSKOR $rw_gpr.XW, $index_gpr",
70 [(mskor_global v4i32:$rw_gpr, i32:$index_gpr)]
76 multiclass RAT_ATOMIC<bits<6> op_ret, bits<6> op_noret, string name> {
77 let Constraints = "$rw_gpr = $out_gpr", eop = 0, mayStore = 1 in {
78 def _RTN: CF_MEM_RAT <op_ret, 0, 0xf,
79 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr),
80 (outs R600_Reg128:$out_gpr),
81 name # "_RTN $rw_gpr, $index_gpr", [] >;
82 def _NORET: CF_MEM_RAT <op_noret, 0, 0xf,
83 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr),
84 (outs R600_Reg128:$out_gpr),
85 name # " $rw_gpr, $index_gpr", [] >;
89 // Swap no-ret is just store. Raw store to cached target
90 // can only store on dword, which exactly matches swap_no_ret.
91 defm RAT_ATOMIC_XCHG_INT : RAT_ATOMIC<1, 34, "ATOMIC_XCHG_INT">;
92 defm RAT_ATOMIC_CMPXCHG_INT : RAT_ATOMIC<4, 36, "ATOMIC_CMPXCHG_INT">;
93 defm RAT_ATOMIC_ADD : RAT_ATOMIC<7, 39, "ATOMIC_ADD">;
94 defm RAT_ATOMIC_SUB : RAT_ATOMIC<8, 40, "ATOMIC_SUB">;
95 defm RAT_ATOMIC_RSUB : RAT_ATOMIC<9, 41, "ATOMIC_RSUB">;
96 defm RAT_ATOMIC_MIN_INT : RAT_ATOMIC<10, 42, "ATOMIC_MIN_INT">;
97 defm RAT_ATOMIC_MIN_UINT : RAT_ATOMIC<11, 43, "ATOMIC_MIN_UINT">;
98 defm RAT_ATOMIC_MAX_INT : RAT_ATOMIC<12, 44, "ATOMIC_MAX_INT">;
99 defm RAT_ATOMIC_MAX_UINT : RAT_ATOMIC<13, 45, "ATOMIC_MAX_UINT">;
100 defm RAT_ATOMIC_AND : RAT_ATOMIC<14, 46, "ATOMIC_AND">;
101 defm RAT_ATOMIC_OR : RAT_ATOMIC<15, 47, "ATOMIC_OR">;
102 defm RAT_ATOMIC_XOR : RAT_ATOMIC<16, 48, "ATOMIC_XOR">;
103 defm RAT_ATOMIC_INC_UINT : RAT_ATOMIC<18, 50, "ATOMIC_INC_UINT">;
104 defm RAT_ATOMIC_DEC_UINT : RAT_ATOMIC<19, 51, "ATOMIC_DEC_UINT">;
106 } // End SubtargetPredicate = isEGorCayman
108 //===----------------------------------------------------------------------===//
109 // Evergreen Only instructions
110 //===----------------------------------------------------------------------===//
112 let SubtargetPredicate = isEG in {
114 def RECIP_IEEE_eg : RECIP_IEEE_Common<0x86>;
115 defm DIV_eg : DIV_Common<RECIP_IEEE_eg>;
117 def MULLO_INT_eg : MULLO_INT_Common<0x8F>;
118 def MULHI_INT_eg : MULHI_INT_Common<0x90>;
119 def MULLO_UINT_eg : MULLO_UINT_Common<0x91>;
120 def MULHI_UINT_eg : MULHI_UINT_Common<0x92>;
121 def MULHI_UINT24_eg : MULHI_UINT24_Common<0xb2>;
123 def RECIP_UINT_eg : RECIP_UINT_Common<0x94>;
124 def RECIPSQRT_CLAMPED_eg : RECIPSQRT_CLAMPED_Common<0x87>;
125 def EXP_IEEE_eg : EXP_IEEE_Common<0x81>;
126 def LOG_IEEE_eg : LOG_IEEE_Common<0x83>;
127 def RECIP_CLAMPED_eg : RECIP_CLAMPED_Common<0x84>;
128 def RECIPSQRT_IEEE_eg : RECIPSQRT_IEEE_Common<0x89>;
129 def : SqrtPat<RECIPSQRT_IEEE_eg, RECIP_IEEE_eg>;
131 def SIN_eg : SIN_Common<0x8D>;
132 def COS_eg : COS_Common<0x8E>;
134 def : POW_Common <LOG_IEEE_eg, EXP_IEEE_eg, MUL>;
135 } // End SubtargetPredicate = isEG
137 //===----------------------------------------------------------------------===//
138 // Memory read/write instructions
139 //===----------------------------------------------------------------------===//
141 let usesCustomInserter = 1 in {
144 def RAT_WRITE_CACHELESS_32_eg : CF_MEM_RAT_CACHELESS <0x2, 0, 0x1,
145 (ins R600_TReg32_X:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
146 "STORE_RAW $rw_gpr, $index_gpr, $eop",
147 [(store_global i32:$rw_gpr, i32:$index_gpr)]
151 def RAT_WRITE_CACHELESS_64_eg : CF_MEM_RAT_CACHELESS <0x2, 0, 0x3,
152 (ins R600_Reg64:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
153 "STORE_RAW $rw_gpr.XY, $index_gpr, $eop",
154 [(store_global v2i32:$rw_gpr, i32:$index_gpr)]
158 def RAT_WRITE_CACHELESS_128_eg : CF_MEM_RAT_CACHELESS <0x2, 0, 0xf,
159 (ins R600_Reg128:$rw_gpr, R600_TReg32_X:$index_gpr, InstFlag:$eop),
160 "STORE_RAW $rw_gpr.XYZW, $index_gpr, $eop",
161 [(store_global v4i32:$rw_gpr, i32:$index_gpr)]
164 def RAT_STORE_TYPED_eg: CF_MEM_RAT_STORE_TYPED<1>;
166 } // End usesCustomInserter = 1
168 class VTX_READ_eg <string name, dag outs>
169 : VTX_WORD0_eg, VTX_READ<name, outs, []> {
174 let FETCH_WHOLE_QUAD = 0;
176 // XXX: We can infer this field based on the SRC_GPR. This would allow us
177 // to store vertex addresses in any channel, not just X.
180 let Inst{31-0} = Word0;
184 : VTX_READ_eg <"VTX_READ_8 $dst_gpr, $src_gpr",
185 (outs R600_TReg32_X:$dst_gpr)> {
187 let MEGA_FETCH_COUNT = 1;
189 let DST_SEL_Y = 7; // Masked
190 let DST_SEL_Z = 7; // Masked
191 let DST_SEL_W = 7; // Masked
192 let DATA_FORMAT = 1; // FMT_8
196 : VTX_READ_eg <"VTX_READ_16 $dst_gpr, $src_gpr",
197 (outs R600_TReg32_X:$dst_gpr)> {
198 let MEGA_FETCH_COUNT = 2;
200 let DST_SEL_Y = 7; // Masked
201 let DST_SEL_Z = 7; // Masked
202 let DST_SEL_W = 7; // Masked
203 let DATA_FORMAT = 5; // FMT_16
208 : VTX_READ_eg <"VTX_READ_32 $dst_gpr, $src_gpr",
209 (outs R600_TReg32_X:$dst_gpr)> {
211 let MEGA_FETCH_COUNT = 4;
213 let DST_SEL_Y = 7; // Masked
214 let DST_SEL_Z = 7; // Masked
215 let DST_SEL_W = 7; // Masked
216 let DATA_FORMAT = 0xD; // COLOR_32
218 // This is not really necessary, but there were some GPU hangs that appeared
219 // to be caused by ALU instructions in the next instruction group that wrote
220 // to the $src_gpr registers of the VTX_READ.
222 // %t3_x = VTX_READ_PARAM_32_eg killed %t2_x, 24
224 //Adding this constraint prevents this from happening.
225 let Constraints = "$src_gpr.ptr = $dst_gpr";
229 : VTX_READ_eg <"VTX_READ_64 $dst_gpr.XY, $src_gpr",
230 (outs R600_Reg64:$dst_gpr)> {
232 let MEGA_FETCH_COUNT = 8;
237 let DATA_FORMAT = 0x1D; // COLOR_32_32
241 : VTX_READ_eg <"VTX_READ_128 $dst_gpr.XYZW, $src_gpr",
242 (outs R600_Reg128:$dst_gpr)> {
244 let MEGA_FETCH_COUNT = 16;
249 let DATA_FORMAT = 0x22; // COLOR_32_32_32_32
251 // XXX: Need to force VTX_READ_128 instructions to write to the same register
252 // that holds its buffer address to avoid potential hangs. We can't use
253 // the same constraint as VTX_READ_32_eg, because the $src_gpr.ptr and $dst
254 // registers are different sizes.
257 //===----------------------------------------------------------------------===//
258 // VTX Read from parameter memory space
259 //===----------------------------------------------------------------------===//
260 def : EGPat<(i32:$dst_gpr (vtx_id3_az_extloadi8 ADDRVTX_READ:$src_gpr)),
261 (VTX_READ_8_eg MEMxi:$src_gpr, 3)>;
262 def : EGPat<(i32:$dst_gpr (vtx_id3_az_extloadi16 ADDRVTX_READ:$src_gpr)),
263 (VTX_READ_16_eg MEMxi:$src_gpr, 3)>;
264 def : EGPat<(i32:$dst_gpr (vtx_id3_load ADDRVTX_READ:$src_gpr)),
265 (VTX_READ_32_eg MEMxi:$src_gpr, 3)>;
266 def : EGPat<(v2i32:$dst_gpr (vtx_id3_load ADDRVTX_READ:$src_gpr)),
267 (VTX_READ_64_eg MEMxi:$src_gpr, 3)>;
268 def : EGPat<(v4i32:$dst_gpr (vtx_id3_load ADDRVTX_READ:$src_gpr)),
269 (VTX_READ_128_eg MEMxi:$src_gpr, 3)>;
271 //===----------------------------------------------------------------------===//
272 // VTX Read from constant memory space
273 //===----------------------------------------------------------------------===//
274 def : EGPat<(i32:$dst_gpr (vtx_id2_az_extloadi8 ADDRVTX_READ:$src_gpr)),
275 (VTX_READ_8_eg MEMxi:$src_gpr, 2)>;
276 def : EGPat<(i32:$dst_gpr (vtx_id2_az_extloadi16 ADDRVTX_READ:$src_gpr)),
277 (VTX_READ_16_eg MEMxi:$src_gpr, 2)>;
278 def : EGPat<(i32:$dst_gpr (vtx_id2_load ADDRVTX_READ:$src_gpr)),
279 (VTX_READ_32_eg MEMxi:$src_gpr, 2)>;
280 def : EGPat<(v2i32:$dst_gpr (vtx_id2_load ADDRVTX_READ:$src_gpr)),
281 (VTX_READ_64_eg MEMxi:$src_gpr, 2)>;
282 def : EGPat<(v4i32:$dst_gpr (vtx_id2_load ADDRVTX_READ:$src_gpr)),
283 (VTX_READ_128_eg MEMxi:$src_gpr, 2)>;
285 //===----------------------------------------------------------------------===//
286 // VTX Read from global memory space
287 //===----------------------------------------------------------------------===//
288 def : EGPat<(i32:$dst_gpr (vtx_id1_az_extloadi8 ADDRVTX_READ:$src_gpr)),
289 (VTX_READ_8_eg MEMxi:$src_gpr, 1)>;
290 def : EGPat<(i32:$dst_gpr (vtx_id1_az_extloadi16 ADDRVTX_READ:$src_gpr)),
291 (VTX_READ_16_eg MEMxi:$src_gpr, 1)>;
292 def : EGPat<(i32:$dst_gpr (vtx_id1_load ADDRVTX_READ:$src_gpr)),
293 (VTX_READ_32_eg MEMxi:$src_gpr, 1)>;
294 def : EGPat<(v2i32:$dst_gpr (vtx_id1_load ADDRVTX_READ:$src_gpr)),
295 (VTX_READ_64_eg MEMxi:$src_gpr, 1)>;
296 def : EGPat<(v4i32:$dst_gpr (vtx_id1_load ADDRVTX_READ:$src_gpr)),
297 (VTX_READ_128_eg MEMxi:$src_gpr, 1)>;
299 //===----------------------------------------------------------------------===//
300 // Evergreen / Cayman Instructions
301 //===----------------------------------------------------------------------===//
303 let SubtargetPredicate = isEGorCayman in {
305 multiclass AtomicPat<Instruction inst_noret,
306 SDPatternOperator node_noret> {
307 // FIXME: Add _RTN version. We need per WI scratch location to store the old value
308 // EXTRACT_SUBREG here is dummy, we know the node has no uses
309 def : EGOrCaymanPat<(i32 (node_noret i32:$ptr, i32:$data)),
310 (EXTRACT_SUBREG (inst_noret
311 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), $data, sub0), $ptr), sub1)>;
314 // CMPSWAP is pattern is special
315 // EXTRACT_SUBREG here is dummy, we know the node has no uses
316 // FIXME: Add _RTN version. We need per WI scratch location to store the old value
317 def : EGOrCaymanPat<(i32 (atomic_cmp_swap_global_noret i32:$ptr, i32:$cmp, i32:$data)),
318 (EXTRACT_SUBREG (RAT_ATOMIC_CMPXCHG_INT_NORET
320 (INSERT_SUBREG (v4i32 (IMPLICIT_DEF)), $cmp, sub3),
324 defm AtomicSwapPat : AtomicPat <RAT_ATOMIC_XCHG_INT_NORET,
325 atomic_swap_global_noret_i32>;
326 defm AtomicAddPat : AtomicPat <RAT_ATOMIC_ADD_NORET,
327 atomic_load_add_global_noret_i32>;
328 defm AtomicSubPat : AtomicPat <RAT_ATOMIC_SUB_NORET,
329 atomic_load_sub_global_noret_i32>;
330 defm AtomicMinPat : AtomicPat <RAT_ATOMIC_MIN_INT_NORET,
331 atomic_load_min_global_noret_i32>;
332 defm AtomicUMinPat : AtomicPat <RAT_ATOMIC_MIN_UINT_NORET,
333 atomic_load_umin_global_noret_i32>;
334 defm AtomicMaxPat : AtomicPat <RAT_ATOMIC_MAX_INT_NORET,
335 atomic_load_max_global_noret_i32>;
336 defm AtomicUMaxPat : AtomicPat <RAT_ATOMIC_MAX_UINT_NORET,
337 atomic_load_umax_global_noret_i32>;
338 defm AtomicAndPat : AtomicPat <RAT_ATOMIC_AND_NORET,
339 atomic_load_and_global_noret_i32>;
340 defm AtomicOrPat : AtomicPat <RAT_ATOMIC_OR_NORET,
341 atomic_load_or_global_noret_i32>;
342 defm AtomicXorPat : AtomicPat <RAT_ATOMIC_XOR_NORET,
343 atomic_load_xor_global_noret_i32>;
345 // Should be predicated on FeatureFP64
346 // def FMA_64 : R600_3OP <
348 // [(set f64:$dst, (fma f64:$src0, f64:$src1, f64:$src2))]
351 // BFE_UINT - bit_extract, an optimization for mask and shift
356 // bit_extract = (Input << (32 - Offset - Width)) >> (32 - Width)
361 // (0, 8) = (Input << 24) >> 24 = (Input & 0xff) >> 0
362 // (8, 8) = (Input << 16) >> 24 = (Input & 0xffff) >> 8
363 // (16, 8) = (Input << 8) >> 24 = (Input & 0xffffff) >> 16
364 // (24, 8) = (Input << 0) >> 24 = (Input & 0xffffffff) >> 24
365 def BFE_UINT_eg : R600_3OP <0x4, "BFE_UINT",
366 [(set i32:$dst, (AMDGPUbfe_u32 i32:$src0, i32:$src1, i32:$src2))],
370 def BFE_INT_eg : R600_3OP <0x5, "BFE_INT",
371 [(set i32:$dst, (AMDGPUbfe_i32 i32:$src0, i32:$src1, i32:$src2))],
375 // Bitfield extract patterns
378 (and (i32 (srl i32:$src, i32:$rshift)), IMMZeroBasedBitfieldMask:$mask),
379 (BFE_UINT_eg $src, $rshift, (MOV_IMM_I32 (i32 (IMMPopCount $mask))))
382 // x & ((1 << y) - 1)
384 (and i32:$src, (add_oneuse (shl_oneuse 1, i32:$width), -1)),
385 (BFE_UINT_eg $src, (MOV_IMM_I32 (i32 0)), $width)
390 (and i32:$src, (xor_oneuse (shl_oneuse -1, i32:$width), -1)),
391 (BFE_UINT_eg $src, (MOV_IMM_I32 (i32 0)), $width)
394 // x & (-1 >> (bitwidth - y))
396 (and i32:$src, (srl_oneuse -1, (sub 32, i32:$width))),
397 (BFE_UINT_eg $src, (MOV_IMM_I32 (i32 0)), $width)
400 // x << (bitwidth - y) >> (bitwidth - y)
402 (srl (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
403 (BFE_UINT_eg $src, (MOV_IMM_I32 (i32 0)), $width)
407 (sra (shl_oneuse i32:$src, (sub 32, i32:$width)), (sub 32, i32:$width)),
408 (BFE_INT_eg $src, (MOV_IMM_I32 (i32 0)), $width)
411 def BFI_INT_eg : R600_3OP <0x06, "BFI_INT",
412 [(set i32:$dst, (AMDGPUbfi i32:$src0, i32:$src1, i32:$src2))],
416 def : EGOrCaymanPat<(i32 (sext_inreg i32:$src, i1)),
417 (BFE_INT_eg i32:$src, (i32 ZERO), (i32 ONE_INT))>;
418 def : EGOrCaymanPat<(i32 (sext_inreg i32:$src, i8)),
419 (BFE_INT_eg i32:$src, (i32 ZERO), (MOV_IMM_I32 8))>;
420 def : EGOrCaymanPat<(i32 (sext_inreg i32:$src, i16)),
421 (BFE_INT_eg i32:$src, (i32 ZERO), (MOV_IMM_I32 16))>;
425 // Definition from ISA doc:
426 // (y & x) | (z & ~x)
428 (or (and i32:$y, i32:$x), (and i32:$z, (not i32:$x))),
429 (BFI_INT_eg $x, $y, $z)
434 (or (and i64:$y, i64:$x), (and i64:$z, (not i64:$x))),
435 (REG_SEQUENCE R600_Reg64,
436 (BFI_INT_eg (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub0)),
437 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub0)),
438 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub0))), sub0,
439 (BFI_INT_eg (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub1)),
440 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub1)),
441 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub1))), sub1)
444 // SHA-256 Ch function
447 (xor i32:$z, (and i32:$x, (xor i32:$y, i32:$z))),
448 (BFI_INT_eg $x, $y, $z)
453 (xor i64:$z, (and i64:$x, (xor i64:$y, i64:$z))),
454 (REG_SEQUENCE R600_Reg64,
455 (BFI_INT_eg (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub0)),
456 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub0)),
457 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub0))), sub0,
458 (BFI_INT_eg (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub1)),
459 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub1)),
460 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub1))), sub1)
464 (fcopysign f32:$src0, f32:$src1),
465 (BFI_INT_eg (MOV_IMM_I32 (i32 0x7fffffff)), $src0, $src1)
469 (fcopysign f32:$src0, f64:$src1),
470 (BFI_INT_eg (MOV_IMM_I32 (i32 0x7fffffff)), $src0,
471 (i32 (EXTRACT_SUBREG R600_Reg64:$src1, sub1)))
475 (fcopysign f64:$src0, f64:$src1),
476 (REG_SEQUENCE R600_Reg64,
477 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
478 (BFI_INT_eg (MOV_IMM_I32 (i32 0x7fffffff)),
479 (i32 (EXTRACT_SUBREG R600_Reg64:$src0, sub1)),
480 (i32 (EXTRACT_SUBREG R600_Reg64:$src1, sub1))), sub1)
484 (fcopysign f64:$src0, f32:$src1),
485 (REG_SEQUENCE R600_Reg64,
486 (i32 (EXTRACT_SUBREG $src0, sub0)), sub0,
487 (BFI_INT_eg (MOV_IMM_I32 (i32 0x7fffffff)),
488 (i32 (EXTRACT_SUBREG R600_Reg64:$src0, sub1)),
492 def BFM_INT_eg : R600_2OP <0xA0, "BFM_INT",
493 [(set i32:$dst, (AMDGPUbfm i32:$src0, i32:$src1))],
497 def MULADD_UINT24_eg : R600_3OP <0x10, "MULADD_UINT24",
498 [(set i32:$dst, (AMDGPUmad_u24 i32:$src0, i32:$src1, i32:$src2))], VecALU
501 def : UMad24Pat<MULADD_UINT24_eg>;
503 def BIT_ALIGN_INT_eg : R600_3OP <0xC, "BIT_ALIGN_INT", [], VecALU>;
505 (fshr i32:$src0, i32:$src1, i32:$src2),
506 (BIT_ALIGN_INT_eg $src0, $src1, $src2)
508 def : ROTRPattern <BIT_ALIGN_INT_eg>;
509 def MULADD_eg : MULADD_Common<0x14>;
510 def MULADD_IEEE_eg : MULADD_IEEE_Common<0x18>;
511 def FMA_eg : FMA_Common<0x7>;
512 def ASHR_eg : ASHR_Common<0x15>;
513 def LSHR_eg : LSHR_Common<0x16>;
514 def LSHL_eg : LSHL_Common<0x17>;
515 def CNDE_eg : CNDE_Common<0x19>;
516 def CNDGT_eg : CNDGT_Common<0x1A>;
517 def CNDGE_eg : CNDGE_Common<0x1B>;
518 def MUL_LIT_eg : MUL_LIT_Common<0x1F>;
519 def LOG_CLAMPED_eg : LOG_CLAMPED_Common<0x82>;
520 def MUL_UINT24_eg : R600_2OP <0xB5, "MUL_UINT24",
521 [(set i32:$dst, (AMDGPUmul_u24 i32:$src0, i32:$src1))], VecALU
523 def DOT4_eg : DOT4_Common<0xBE>;
524 defm CUBE_eg : CUBE_Common<0xC0>;
527 def ADDC_UINT : R600_2OP_Helper <0x52, "ADDC_UINT", AMDGPUcarry>;
528 def SUBB_UINT : R600_2OP_Helper <0x53, "SUBB_UINT", AMDGPUborrow>;
530 def FLT32_TO_FLT16 : R600_1OP_Helper <0xA2, "FLT32_TO_FLT16", AMDGPUfp_to_f16, VecALU>;
531 def FLT16_TO_FLT32 : R600_1OP_Helper <0xA3, "FLT16_TO_FLT32", f16_to_fp, VecALU>;
532 def BCNT_INT : R600_1OP_Helper <0xAA, "BCNT_INT", ctpop, VecALU>;
533 def FFBH_UINT : R600_1OP_Helper <0xAB, "FFBH_UINT", AMDGPUffbh_u32, VecALU>;
534 def FFBL_INT : R600_1OP_Helper <0xAC, "FFBL_INT", AMDGPUffbl_b32, VecALU>;
536 let hasSideEffects = 1 in {
537 def MOVA_INT_eg : R600_1OP <0xCC, "MOVA_INT", [], VecALU>;
540 def FLT_TO_INT_eg : FLT_TO_INT_Common<0x50> {
542 let Itinerary = AnyALU;
545 def INT_TO_FLT_eg : INT_TO_FLT_Common<0x9B>;
547 def FLT_TO_UINT_eg : FLT_TO_UINT_Common<0x9A> {
551 def UINT_TO_FLT_eg : UINT_TO_FLT_Common<0x9C>;
553 def GROUP_BARRIER : InstR600 <
554 (outs), (ins), " GROUP_BARRIER", [(int_r600_group_barrier)], AnyALU>,
556 R600ALU_Word1_OP2 <0x54> {
572 let bank_swizzle = 0;
574 let update_exec_mask = 0;
577 let Inst{31-0} = Word0;
578 let Inst{63-32} = Word1;
583 //===----------------------------------------------------------------------===//
585 //===----------------------------------------------------------------------===//
586 class R600_LDS <bits<6> op, dag outs, dag ins, string asm,
587 list<dag> pattern = []> :
589 InstR600 <outs, ins, asm, pattern, XALU>,
596 let Word1{27} = offset{0};
597 let Word1{12} = offset{1};
598 let Word1{28} = offset{2};
599 let Word1{31} = offset{3};
600 let Word0{12} = offset{4};
601 let Word0{25} = offset{5};
604 let Inst{31-0} = Word0;
605 let Inst{63-32} = Word1;
608 let HasNativeOperands = 1;
609 let UseNamedOperandTable = 1;
612 class R600_LDS_1A <bits<6> lds_op, string name, list<dag> pattern> : R600_LDS <
614 (outs R600_Reg32:$dst),
615 (ins R600_Reg32:$src0, REL:$src0_rel, SEL:$src0_sel,
616 LAST:$last, R600_Pred:$pred_sel,
617 BANK_SWIZZLE:$bank_swizzle),
618 " "#name#" $last OQAP, $src0$src0_rel $pred_sel",
627 let usesCustomInserter = 1;
629 let DisableEncoding = "$dst";
632 class R600_LDS_1A1D <bits<6> lds_op, dag outs, string name, list<dag> pattern,
636 (ins R600_Reg32:$src0, REL:$src0_rel, SEL:$src0_sel,
637 R600_Reg32:$src1, REL:$src1_rel, SEL:$src1_sel,
638 LAST:$last, R600_Pred:$pred_sel,
639 BANK_SWIZZLE:$bank_swizzle),
640 " "#name#" $last "#dst#"$src0$src0_rel, $src1$src1_rel, $pred_sel",
651 class R600_LDS_1A1D_NORET <bits<6> lds_op, string name, list<dag> pattern> :
652 R600_LDS_1A1D <lds_op, (outs), name, pattern> {
656 class R600_LDS_1A1D_RET <bits<6> lds_op, string name, list<dag> pattern> :
657 R600_LDS_1A1D <lds_op, (outs R600_Reg32:$dst), name#"_RET", pattern, "OQAP, "> {
660 let usesCustomInserter = 1;
661 let DisableEncoding = "$dst";
664 class R600_LDS_1A2D <bits<6> lds_op, dag outs, string name, list<dag> pattern,
668 (ins R600_Reg32:$src0, REL:$src0_rel, SEL:$src0_sel,
669 R600_Reg32:$src1, REL:$src1_rel, SEL:$src1_sel,
670 R600_Reg32:$src2, REL:$src2_rel, SEL:$src2_sel,
671 LAST:$last, R600_Pred:$pred_sel, BANK_SWIZZLE:$bank_swizzle),
672 " "#name# "$last "#dst#"$src0$src0_rel, $src1$src1_rel, $src2$src2_rel, $pred_sel",
681 class R600_LDS_1A2D_NORET <bits<6> lds_op, string name, list<dag> pattern> :
682 R600_LDS_1A2D <lds_op, (outs), name, pattern> {
686 class R600_LDS_1A2D_RET <bits<6> lds_op, string name, list<dag> pattern> :
687 R600_LDS_1A2D <lds_op, (outs R600_Reg32:$dst), name, pattern> {
690 let usesCustomInserter = 1;
691 let DisableEncoding = "$dst";
694 def LDS_ADD : R600_LDS_1A1D_NORET <0x0, "LDS_ADD", [] >;
695 def LDS_SUB : R600_LDS_1A1D_NORET <0x1, "LDS_SUB", [] >;
696 def LDS_AND : R600_LDS_1A1D_NORET <0x9, "LDS_AND", [] >;
697 def LDS_OR : R600_LDS_1A1D_NORET <0xa, "LDS_OR", [] >;
698 def LDS_XOR : R600_LDS_1A1D_NORET <0xb, "LDS_XOR", [] >;
699 def LDS_WRXCHG: R600_LDS_1A1D_NORET <0xd, "LDS_WRXCHG", [] >;
700 def LDS_CMPST: R600_LDS_1A2D_NORET <0x10, "LDS_CMPST", [] >;
701 def LDS_MIN_INT : R600_LDS_1A1D_NORET <0x5, "LDS_MIN_INT", [] >;
702 def LDS_MAX_INT : R600_LDS_1A1D_NORET <0x6, "LDS_MAX_INT", [] >;
703 def LDS_MIN_UINT : R600_LDS_1A1D_NORET <0x7, "LDS_MIN_UINT", [] >;
704 def LDS_MAX_UINT : R600_LDS_1A1D_NORET <0x8, "LDS_MAX_UINT", [] >;
705 def LDS_WRITE : R600_LDS_1A1D_NORET <0xD, "LDS_WRITE",
706 [(store_local (i32 R600_Reg32:$src1), R600_Reg32:$src0)]
708 def LDS_BYTE_WRITE : R600_LDS_1A1D_NORET<0x12, "LDS_BYTE_WRITE",
709 [(truncstorei8_local i32:$src1, i32:$src0)]
711 def LDS_SHORT_WRITE : R600_LDS_1A1D_NORET<0x13, "LDS_SHORT_WRITE",
712 [(truncstorei16_local i32:$src1, i32:$src0)]
714 def LDS_ADD_RET : R600_LDS_1A1D_RET <0x20, "LDS_ADD",
715 [(set i32:$dst, (atomic_load_add_local_i32 i32:$src0, i32:$src1))]
717 def LDS_SUB_RET : R600_LDS_1A1D_RET <0x21, "LDS_SUB",
718 [(set i32:$dst, (atomic_load_sub_local_i32 i32:$src0, i32:$src1))]
720 def LDS_AND_RET : R600_LDS_1A1D_RET <0x29, "LDS_AND",
721 [(set i32:$dst, (atomic_load_and_local_i32 i32:$src0, i32:$src1))]
723 def LDS_OR_RET : R600_LDS_1A1D_RET <0x2a, "LDS_OR",
724 [(set i32:$dst, (atomic_load_or_local_i32 i32:$src0, i32:$src1))]
726 def LDS_XOR_RET : R600_LDS_1A1D_RET <0x2b, "LDS_XOR",
727 [(set i32:$dst, (atomic_load_xor_local_i32 i32:$src0, i32:$src1))]
729 def LDS_MIN_INT_RET : R600_LDS_1A1D_RET <0x25, "LDS_MIN_INT",
730 [(set i32:$dst, (atomic_load_min_local_i32 i32:$src0, i32:$src1))]
732 def LDS_MAX_INT_RET : R600_LDS_1A1D_RET <0x26, "LDS_MAX_INT",
733 [(set i32:$dst, (atomic_load_max_local_i32 i32:$src0, i32:$src1))]
735 def LDS_MIN_UINT_RET : R600_LDS_1A1D_RET <0x27, "LDS_MIN_UINT",
736 [(set i32:$dst, (atomic_load_umin_local_i32 i32:$src0, i32:$src1))]
738 def LDS_MAX_UINT_RET : R600_LDS_1A1D_RET <0x28, "LDS_MAX_UINT",
739 [(set i32:$dst, (atomic_load_umax_local_i32 i32:$src0, i32:$src1))]
741 def LDS_WRXCHG_RET : R600_LDS_1A1D_RET <0x2d, "LDS_WRXCHG",
742 [(set i32:$dst, (atomic_swap_local_i32 i32:$src0, i32:$src1))]
744 def LDS_CMPST_RET : R600_LDS_1A2D_RET <0x30, "LDS_CMPST",
745 [(set i32:$dst, (atomic_cmp_swap_local_i32 i32:$src0, i32:$src1, i32:$src2))]
747 def LDS_READ_RET : R600_LDS_1A <0x32, "LDS_READ_RET",
748 [(set (i32 R600_Reg32:$dst), (load_local R600_Reg32:$src0))]
750 def LDS_BYTE_READ_RET : R600_LDS_1A <0x36, "LDS_BYTE_READ_RET",
751 [(set i32:$dst, (sextloadi8_local i32:$src0))]
753 def LDS_UBYTE_READ_RET : R600_LDS_1A <0x37, "LDS_UBYTE_READ_RET",
754 [(set i32:$dst, (az_extloadi8_local i32:$src0))]
756 def LDS_SHORT_READ_RET : R600_LDS_1A <0x38, "LDS_SHORT_READ_RET",
757 [(set i32:$dst, (sextloadi16_local i32:$src0))]
759 def LDS_USHORT_READ_RET : R600_LDS_1A <0x39, "LDS_USHORT_READ_RET",
760 [(set i32:$dst, (az_extloadi16_local i32:$src0))]
763 // TRUNC is used for the FLT_TO_INT instructions to work around a
764 // perceived problem where the rounding modes are applied differently
765 // depending on the instruction and the slot they are in.
767 // https://bugs.freedesktop.org/show_bug.cgi?id=50232
768 // Mesa commit: a1a0974401c467cb86ef818f22df67c21774a38c
770 // XXX: Lowering SELECT_CC will sometimes generate fp_to_[su]int nodes,
771 // which do not need to be truncated since the fp values are 0.0f or 1.0f.
772 // We should look into handling these cases separately.
773 def : EGOrCaymanPat<(fp_to_sint f32:$src0), (FLT_TO_INT_eg (TRUNC $src0))>;
775 def : EGOrCaymanPat<(fp_to_uint f32:$src0), (FLT_TO_UINT_eg (TRUNC $src0))>;
777 // SHA-256 Ma patterns
779 // ((x & z) | (y & (x | z))) -> BFI (XOR x, y), z, y
781 (or (and i32:$x, i32:$z), (and i32:$y, (or i32:$x, i32:$z))),
782 (BFI_INT_eg (XOR_INT i32:$x, i32:$y), i32:$z, i32:$y)
786 (or (and i64:$x, i64:$z), (and i64:$y, (or i64:$x, i64:$z))),
787 (REG_SEQUENCE R600_Reg64,
788 (BFI_INT_eg (XOR_INT (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub0)),
789 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub0))),
790 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub0)),
791 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub0))), sub0,
792 (BFI_INT_eg (XOR_INT (i32 (EXTRACT_SUBREG R600_Reg64:$x, sub1)),
793 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub1))),
794 (i32 (EXTRACT_SUBREG R600_Reg64:$z, sub1)),
795 (i32 (EXTRACT_SUBREG R600_Reg64:$y, sub1))), sub1)
798 def EG_ExportSwz : ExportSwzInst {
799 let Word1{19-16} = 0; // BURST_COUNT
800 let Word1{20} = 0; // VALID_PIXEL_MODE
802 let Word1{29-22} = inst;
803 let Word1{30} = 0; // MARK
804 let Word1{31} = 1; // BARRIER
806 defm : ExportPattern<EG_ExportSwz, 83>;
808 def EG_ExportBuf : ExportBufInst {
809 let Word1{19-16} = 0; // BURST_COUNT
810 let Word1{20} = 0; // VALID_PIXEL_MODE
812 let Word1{29-22} = inst;
813 let Word1{30} = 0; // MARK
814 let Word1{31} = 1; // BARRIER
816 defm : SteamOutputExportPattern<EG_ExportBuf, 0x40, 0x41, 0x42, 0x43>;
818 def CF_TC_EG : CF_CLAUSE_EG<1, (ins i32imm:$ADDR, i32imm:$COUNT),
819 "TEX $COUNT @$ADDR"> {
822 def CF_VC_EG : CF_CLAUSE_EG<2, (ins i32imm:$ADDR, i32imm:$COUNT),
823 "VTX $COUNT @$ADDR"> {
826 def WHILE_LOOP_EG : CF_CLAUSE_EG<6, (ins i32imm:$ADDR),
827 "LOOP_START_DX10 @$ADDR"> {
831 def END_LOOP_EG : CF_CLAUSE_EG<5, (ins i32imm:$ADDR), "END_LOOP @$ADDR"> {
835 def LOOP_BREAK_EG : CF_CLAUSE_EG<9, (ins i32imm:$ADDR),
836 "LOOP_BREAK @$ADDR"> {
840 def CF_CONTINUE_EG : CF_CLAUSE_EG<8, (ins i32imm:$ADDR),
845 def CF_JUMP_EG : CF_CLAUSE_EG<10, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
846 "JUMP @$ADDR POP:$POP_COUNT"> {
849 def CF_PUSH_EG : CF_CLAUSE_EG<11, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
850 "PUSH @$ADDR POP:$POP_COUNT"> {
853 def CF_ELSE_EG : CF_CLAUSE_EG<13, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
854 "ELSE @$ADDR POP:$POP_COUNT"> {
857 def CF_CALL_FS_EG : CF_CLAUSE_EG<19, (ins), "CALL_FS"> {
862 def POP_EG : CF_CLAUSE_EG<14, (ins i32imm:$ADDR, i32imm:$POP_COUNT),
863 "POP @$ADDR POP:$POP_COUNT"> {
866 def CF_END_EG : CF_CLAUSE_EG<0, (ins), "CF_END"> {
870 let END_OF_PROGRAM = 1;
873 } // End Predicates = [isEGorCayman]