1//===-- SIInstrFormats.td - SI Instruction Encodings ----------------------===// 2// 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 6// 7//===----------------------------------------------------------------------===// 8// 9// SI Instruction format definitions. 10// 11//===----------------------------------------------------------------------===// 12 13class InstSI <dag outs, dag ins, string asm = "", 14 list<dag> pattern = []> : 15 AMDGPUInst<outs, ins, asm, pattern>, GCNPredicateControl { 16 // Low bits - basic encoding information. 17 field bit SALU = 0; 18 field bit VALU = 0; 19 20 // SALU instruction formats. 21 field bit SOP1 = 0; 22 field bit SOP2 = 0; 23 field bit SOPC = 0; 24 field bit SOPK = 0; 25 field bit SOPP = 0; 26 27 // VALU instruction formats. 28 field bit VOP1 = 0; 29 field bit VOP2 = 0; 30 field bit VOPC = 0; 31 field bit VOP3 = 0; 32 field bit VOP3P = 0; 33 field bit VINTRP = 0; 34 field bit SDWA = 0; 35 field bit DPP = 0; 36 field bit TRANS = 0; 37 38 // Memory instruction formats. 39 field bit MUBUF = 0; 40 field bit MTBUF = 0; 41 field bit SMRD = 0; 42 field bit MIMG = 0; 43 field bit EXP = 0; 44 field bit FLAT = 0; 45 field bit DS = 0; 46 47 // Pseudo instruction formats. 48 field bit VGPRSpill = 0; 49 field bit SGPRSpill = 0; 50 51 // LDSDIR instruction format. 52 field bit LDSDIR = 0; 53 54 // VINTERP instruction format. 55 field bit VINTERP = 0; 56 57 // High bits - other information. 58 field bit VM_CNT = 0; 59 field bit EXP_CNT = 0; 60 field bit LGKM_CNT = 0; 61 62 // Whether WQM _must_ be enabled for this instruction. 63 field bit WQM = 0; 64 65 // Whether WQM _must_ be disabled for this instruction. 66 field bit DisableWQM = 0; 67 68 field bit Gather4 = 0; 69 70 // Most sopk treat the immediate as a signed 16-bit, however some 71 // use it as unsigned. 72 field bit SOPKZext = 0; 73 74 // This is an s_store_dword* instruction that requires a cache flush 75 // on wave termination. It is necessary to distinguish from mayStore 76 // SMEM instructions like the cache flush ones. 77 field bit ScalarStore = 0; 78 79 // Whether the operands can be ignored when computing the 80 // instruction size. 81 field bit FixedSize = 0; 82 83 // This bit tells the assembler to use the 32-bit encoding in case it 84 // is unable to infer the encoding from the operands. 85 field bit VOPAsmPrefer32Bit = 0; 86 87 // This bit indicates that this is a VOP3 opcode which supports op_sel 88 // modifier. 89 field bit VOP3_OPSEL = 0; 90 91 // Is it possible for this instruction to be atomic? 92 field bit maybeAtomic = 0; 93 94 // This bit indicates that this is a VI instruction which is renamed 95 // in GFX9. Required for correct mapping from pseudo to MC. 96 field bit renamedInGFX9 = 0; 97 98 // This bit indicates that this has a floating point result type, so 99 // the clamp modifier has floating point semantics. 100 field bit FPClamp = 0; 101 102 // This bit indicates that instruction may support integer clamping 103 // which depends on GPU features. 104 field bit IntClamp = 0; 105 106 // This field indicates that the clamp applies to the low component 107 // of a packed output register. 108 field bit ClampLo = 0; 109 110 // This field indicates that the clamp applies to the high component 111 // of a packed output register. 112 field bit ClampHi = 0; 113 114 // This bit indicates that this is a packed VOP3P instruction 115 field bit IsPacked = 0; 116 117 // This bit indicates that this is a D16 buffer instruction. 118 field bit D16Buf = 0; 119 120 // This field indicates that FLAT instruction accesses FLAT_GLBL segment. 121 // Must be 0 for non-FLAT instructions. 122 field bit FlatGlobal = 0; 123 124 // Reads the mode register, usually for FP environment. 125 field bit ReadsModeReg = 0; 126 127 // This bit indicates that this uses the floating point double precision 128 // rounding mode flags 129 field bit FPDPRounding = 0; 130 131 // Instruction is FP atomic. 132 field bit FPAtomic = 0; 133 134 // This bit indicates that this is one of MFMA instructions. 135 field bit IsMAI = 0; 136 137 // This bit indicates that this is one of DOT instructions. 138 field bit IsDOT = 0; 139 140 // This field indicates that FLAT instruction accesses FLAT_SCRATCH segment. 141 // Must be 0 for non-FLAT instructions. 142 field bit FlatScratch = 0; 143 144 // Atomic without a return. 145 field bit IsAtomicNoRet = 0; 146 147 // Atomic with return. 148 field bit IsAtomicRet = 0; 149 150 // This bit indicates that this is one of WMMA instructions. 151 field bit IsWMMA = 0; 152 153 // This bit indicates that tied source will not be read. 154 field bit TiedSourceNotRead = 0; 155 156 // This bit indicates that the instruction is never-uniform/divergent 157 field bit IsNeverUniform = 0; 158 159 // These need to be kept in sync with the enum in SIInstrFlags. 160 let TSFlags{0} = SALU; 161 let TSFlags{1} = VALU; 162 163 let TSFlags{2} = SOP1; 164 let TSFlags{3} = SOP2; 165 let TSFlags{4} = SOPC; 166 let TSFlags{5} = SOPK; 167 let TSFlags{6} = SOPP; 168 169 let TSFlags{7} = VOP1; 170 let TSFlags{8} = VOP2; 171 let TSFlags{9} = VOPC; 172 let TSFlags{10} = VOP3; 173 let TSFlags{12} = VOP3P; 174 175 let TSFlags{13} = VINTRP; 176 let TSFlags{14} = SDWA; 177 let TSFlags{15} = DPP; 178 let TSFlags{16} = TRANS; 179 180 let TSFlags{17} = MUBUF; 181 let TSFlags{18} = MTBUF; 182 let TSFlags{19} = SMRD; 183 let TSFlags{20} = MIMG; 184 let TSFlags{21} = EXP; 185 let TSFlags{22} = FLAT; 186 let TSFlags{23} = DS; 187 188 let TSFlags{24} = VGPRSpill; 189 let TSFlags{25} = SGPRSpill; 190 191 let TSFlags{26} = LDSDIR; 192 let TSFlags{27} = VINTERP; 193 194 let TSFlags{32} = VM_CNT; 195 let TSFlags{33} = EXP_CNT; 196 let TSFlags{34} = LGKM_CNT; 197 198 let TSFlags{35} = WQM; 199 let TSFlags{36} = DisableWQM; 200 let TSFlags{37} = Gather4; 201 202 let TSFlags{38} = SOPKZext; 203 let TSFlags{39} = ScalarStore; 204 let TSFlags{40} = FixedSize; 205 let TSFlags{41} = VOPAsmPrefer32Bit; 206 let TSFlags{42} = VOP3_OPSEL; 207 208 let TSFlags{43} = maybeAtomic; 209 let TSFlags{44} = renamedInGFX9; 210 211 let TSFlags{45} = FPClamp; 212 let TSFlags{46} = IntClamp; 213 let TSFlags{47} = ClampLo; 214 let TSFlags{48} = ClampHi; 215 216 let TSFlags{49} = IsPacked; 217 218 let TSFlags{50} = D16Buf; 219 220 let TSFlags{51} = FlatGlobal; 221 222 let TSFlags{52} = FPDPRounding; 223 224 let TSFlags{53} = FPAtomic; 225 226 let TSFlags{54} = IsMAI; 227 228 let TSFlags{55} = IsDOT; 229 230 let TSFlags{56} = FlatScratch; 231 232 let TSFlags{57} = IsAtomicNoRet; 233 234 let TSFlags{58} = IsAtomicRet; 235 236 let TSFlags{59} = IsWMMA; 237 238 let TSFlags{60} = TiedSourceNotRead; 239 240 let TSFlags{61} = IsNeverUniform; 241 242 let SchedRW = [Write32Bit]; 243 244 let AsmVariantName = AMDGPUAsmVariants.Default; 245 246 // Avoid changing source registers in a way that violates constant bus read limitations. 247 let hasExtraSrcRegAllocReq = !or(VOP1, VOP2, VOP3, VOPC, SDWA, VALU); 248} 249 250class PseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = ""> 251 : InstSI<outs, ins, asm, pattern> { 252 let isPseudo = 1; 253 let isCodeGenOnly = 1; 254} 255 256class SPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = ""> 257 : PseudoInstSI<outs, ins, pattern, asm> { 258 let SALU = 1; 259} 260 261class VPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], string asm = ""> 262 : PseudoInstSI<outs, ins, pattern, asm> { 263 let VALU = 1; 264 let Uses = [EXEC]; 265} 266 267class CFPseudoInstSI<dag outs, dag ins, list<dag> pattern = [], 268 bit UseExec = 0, bit DefExec = 0> : 269 SPseudoInstSI<outs, ins, pattern> { 270 271 let Uses = !if(UseExec, [EXEC], []); 272 let Defs = !if(DefExec, [EXEC, SCC], [SCC]); 273 let mayLoad = 0; 274 let mayStore = 0; 275 let hasSideEffects = 0; 276} 277 278class Enc32 { 279 field bits<32> Inst; 280 int Size = 4; 281} 282 283class Enc64 { 284 field bits<64> Inst; 285 int Size = 8; 286} 287 288class Enc96 { 289 field bits<96> Inst; 290 int Size = 12; 291} 292 293def CPolBit { 294 int GLC = 0; 295 int SLC = 1; 296 int DLC = 2; 297 int SCC = 4; 298} 299 300class VOPDstOperand <RegisterClass rc> : RegisterOperand <rc, "printVOPDst">; 301 302class VINTRPe <bits<2> op> : Enc32 { 303 bits<8> vdst; 304 bits<8> vsrc; 305 bits<2> attrchan; 306 bits<6> attr; 307 308 let Inst{7-0} = vsrc; 309 let Inst{9-8} = attrchan; 310 let Inst{15-10} = attr; 311 let Inst{17-16} = op; 312 let Inst{25-18} = vdst; 313 let Inst{31-26} = 0x32; // encoding 314} 315 316class MIMGe_gfxpre11 : Enc64 { 317 bits<10> vdata; 318 bits<4> dmask; 319 bits<1> unorm; 320 bits<5> cpol; 321 bits<1> r128; 322 bits<1> tfe; 323 bits<1> lwe; 324 bit d16; 325 bits<7> srsrc; 326 bits<7> ssamp; 327 328 let Inst{11-8} = dmask; 329 let Inst{12} = unorm; 330 let Inst{13} = cpol{CPolBit.GLC}; 331 let Inst{15} = r128; 332 let Inst{17} = lwe; 333 let Inst{25} = cpol{CPolBit.SLC}; 334 let Inst{31-26} = 0x3c; 335 let Inst{47-40} = vdata{7-0}; 336 let Inst{52-48} = srsrc{6-2}; 337 let Inst{57-53} = ssamp{6-2}; 338 let Inst{63} = d16; 339} 340 341class MIMGe_gfx6789 <bits<8> op> : MIMGe_gfxpre11 { 342 bits<8> vaddr; 343 bits<1> da; 344 345 let Inst{0} = op{7}; 346 let Inst{7} = cpol{CPolBit.SCC}; 347 let Inst{14} = da; 348 let Inst{16} = tfe; 349 let Inst{24-18} = op{6-0}; 350 let Inst{39-32} = vaddr; 351} 352 353class MIMGe_gfx90a <bits<8> op> : MIMGe_gfxpre11 { 354 bits<8> vaddr; 355 bits<1> da; 356 357 let Inst{0} = op{7}; 358 let Inst{7} = cpol{CPolBit.SCC}; 359 let Inst{14} = da; 360 let Inst{16} = vdata{9}; // ACC bit 361 let Inst{24-18} = op{6-0}; 362 let Inst{39-32} = vaddr; 363} 364 365class MIMGe_gfx10 <bits<8> op> : MIMGe_gfxpre11 { 366 bits<8> vaddr0; 367 bits<3> dim; 368 bits<2> nsa; 369 bits<1> a16; 370 371 let Inst{0} = op{7}; 372 let Inst{2-1} = nsa; 373 let Inst{5-3} = dim; 374 let Inst{7} = cpol{CPolBit.DLC}; 375 let Inst{16} = tfe; 376 let Inst{24-18} = op{6-0}; 377 let Inst{39-32} = vaddr0; 378 let Inst{62} = a16; 379} 380 381class MIMGe_gfx11 <bits<8> op> : Enc64 { 382 bits<8> vdata; 383 bits<4> dmask; 384 bits<1> unorm; 385 bits<5> cpol; 386 bits<1> r128; 387 bits<1> tfe; 388 bits<1> lwe; 389 bits<7> srsrc; 390 bits<7> ssamp; 391 bit d16; 392 bits<1> a16; 393 bits<8> vaddr0; 394 bits<3> dim; 395 bits<1> nsa; 396 397 let Inst{0} = nsa; 398 let Inst{4-2} = dim; 399 let Inst{7} = unorm; 400 let Inst{11-8} = dmask; 401 let Inst{12} = cpol{CPolBit.SLC}; 402 let Inst{13} = cpol{CPolBit.DLC}; 403 let Inst{14} = cpol{CPolBit.GLC}; 404 let Inst{15} = r128; 405 let Inst{16} = a16; 406 let Inst{17} = d16; 407 let Inst{25-18} = op; 408 let Inst{31-26} = 0x3c; 409 let Inst{39-32} = vaddr0; 410 let Inst{47-40} = vdata; 411 let Inst{52-48} = srsrc{6-2}; 412 let Inst{53} = tfe; 413 let Inst{54} = lwe; 414 let Inst{62-58} = ssamp{6-2}; 415} 416 417class EXPe : Enc64 { 418 bits<4> en; 419 bits<6> tgt; 420 bits<1> done; 421 bits<8> src0; 422 bits<8> src1; 423 bits<8> src2; 424 bits<8> src3; 425 426 let Inst{3-0} = en; 427 let Inst{9-4} = tgt; 428 let Inst{11} = done; 429 let Inst{31-26} = 0x3e; 430 let Inst{39-32} = src0; 431 let Inst{47-40} = src1; 432 let Inst{55-48} = src2; 433 let Inst{63-56} = src3; 434} 435 436// Pre-GFX11 encoding has compr and vm bits. 437class EXPe_ComprVM : EXPe { 438 bits<1> compr; 439 bits<1> vm; 440 441 let Inst{10} = compr; 442 let Inst{12} = vm; 443} 444 445// GFX11+ encoding has row bit. 446class EXPe_Row : EXPe { 447 bits<1> row; 448 449 let Inst{13} = row; 450} 451 452let Uses = [EXEC] in { 453 454class VINTRPCommon <dag outs, dag ins, string asm, list<dag> pattern> : 455 InstSI <outs, ins, asm, pattern> { 456 let VINTRP = 1; 457 // VINTRP instructions read parameter values from LDS, but these parameter 458 // values are stored outside of the LDS memory that is allocated to the 459 // shader for general purpose use. 460 // 461 // While it may be possible for ds_read/ds_write instructions to access 462 // the parameter values in LDS, this would essentially be an out-of-bounds 463 // memory access which we consider to be undefined behavior. 464 // 465 // So even though these instructions read memory, this memory is outside the 466 // addressable memory space for the shader, and we consider these instructions 467 // to be readnone. 468 let mayLoad = 0; 469 let mayStore = 0; 470 let hasSideEffects = 0; 471 let VALU = 1; 472} 473 474} // End Uses = [EXEC] 475