module Accelerator.SM90.Instruction import Accelerator.SM86.Control import Accelerator.SM86.Instruction import Accelerator.SM86.Types import Accelerator.SM90.UniformOperands -- The sm_90 forms in which an SM86-shaped program's global-memory accesses -- and branches run on Hopper. Every other instruction an SM86 program holds -- is decoded by Hopper as Ampere decodes it, so it keeps its SM86 word -- (Accelerator.SM90.Lowering); these are the ones whose bits must change: -- -- * Global accesses take the raw address form `[Ra.64+URZ+offset]`: the -- 64-bit address the register pair holds, with no memory descriptor. -- Ampere's encoders set the `desc[UR4]` bit (76) and name UR4, which -- Ampere ignores and Hopper honours -- it would read a descriptor from a -- uniform register no SM86 program loads. The raw form is Mesa NAK's; -- ptxas never emits it, so its oracle is nvdisasm's reading of the words -- (reference/oracles/nvidia-sm90-ptxas/global-branch/README.md), and the -- H100 runs of 2026-10-10 (comparisons/h100/README.md) executed it. -- * BRA splits its displacement: bits 2..9 at instruction bits 16..23 and -- bits 10..57 at 34..81 (ptxas -arch=sm_90a output). -- -- Offsets are byte counts (naturals): a global offset is the signed 24-bit -- immediate's non-negative half, as Accelerator.SM86's encoders admit it. family SM90GlobalLoadWidth : Type 0 -- LDG.E: one 32-bit word constructor SM90GlobalLoad32 -- LDG.E.128: four words into a register quad constructor SM90GlobalLoad128 -- LDG.E.STRONG.GPU: one word, a strong load at the GPU's scope -- (ld.relaxed.gpu / ld.acquire.gpu less its fence): it reads the L2's -- word, not a stale L1 line -- what a spin on another CTA's flag needs constructor SM90GlobalLoad32Strong -- LDG.E.128.STRONG.GPU: four words, strong at the GPU's scope (another -- CTA's partial tile, read after its flag) constructor SM90GlobalLoad128Strong -- LDG.E.128.CONSTANT: the non-coherent read-only path (ld.global.nc). -- Its input must remain immutable; never use it to observe a CTA's writes. constructor SM90GlobalLoad128ReadOnly end-family family SM90GlobalStoreWidth : Type 0 -- STG.E: one 32-bit word constructor SM90GlobalStore32 -- STG.E.64: a register pair (an 8-byte-aligned address) constructor SM90GlobalStore64 -- STG.E.128: a register quad (a 16-byte-aligned address) constructor SM90GlobalStore128 -- STG.E.STRONG.GPU: one word, a strong store at the GPU's scope -- (st.relaxed.gpu; st.release.gpu is MEMBAR.ALL.GPU then this) constructor SM90GlobalStore32Strong end-family -- A branch's displacement in bytes from the next instruction, by direction: -- the encoder writes its two's complement. A forward branch of 0 continues -- with the next instruction; a backward branch moves at least one word. family SM90BranchTarget : Type 0 constructor SM90BranchForward field unrestricted sm90BranchForwardBytes : Nat constructor SM90BranchBackward field unrestricted sm90BranchBackwardBytes : Nat end-family -- PRMT uses four low selector nibbles. Registers also permit sign-byte -- replication through each nibble's high bit; no modifier mode is implicit. family SM90ByteSelector : Type 0 constructor SM90ByteSelectorImmediate field unrestricted sm90ByteSelectorImmediateValue : Nat constructor SM90ByteSelectorRegister field unrestricted sm90ByteSelectorRegisterValue : (family SM86Register) end-family -- Allocation is a performance hint, independent of width and memory ordering. -- NoAllocate avoids filling L1 with streaming operands; it adds no ordering. family SM90LoadAllocation : Type 0 constructor SM90LoadAllocate constructor SM90LoadNoAllocate end-family family SM90Instruction : Type 0 -- SASS LDG.E[.128] Rd, [Ra.64+URZ+offset] constructor SM90LoadGlobal field unrestricted sm90LoadGlobalGuard : (family SM86InstructionGuard) field unrestricted sm90LoadGlobalWidth : (family SM90GlobalLoadWidth) field unrestricted sm90LoadGlobalAllocation : (family SM90LoadAllocation) field unrestricted sm90LoadGlobalDestination : (family SM86Register) field unrestricted sm90LoadGlobalAddress : (family SM86Register) field unrestricted sm90LoadGlobalOffset : Nat field unrestricted sm90LoadGlobalControl : (family SM86Control) -- Returning U32 add at GPU scope, through the CUDA global descriptor. -- Keep its descriptor pair explicit; raw-address ATOMG is not qualified. constructor SM90FetchAddGlobal32 field unrestricted sm90FetchAddGuard : (family SM86InstructionGuard) field unrestricted sm90FetchAddDestination : (family SM86Register) field unrestricted sm90FetchAddAddress : (family SM86Register) field unrestricted sm90FetchAddValue : (family SM86Register) field unrestricted sm90FetchAddDescriptor : (family SM90UniformRegister) field unrestricted sm90FetchAddOffset : Nat field unrestricted sm90FetchAddControl : (family SM86Control) -- SASS STG.E[.64|.128] [Ra.64+URZ+offset], Rv constructor SM90StoreGlobal field unrestricted sm90StoreGlobalGuard : (family SM86InstructionGuard) field unrestricted sm90StoreGlobalWidth : (family SM90GlobalStoreWidth) field unrestricted sm90StoreGlobalAddress : (family SM86Register) field unrestricted sm90StoreGlobalValue : (family SM86Register) field unrestricted sm90StoreGlobalOffset : Nat field unrestricted sm90StoreGlobalControl : (family SM86Control) -- SASS LDGSTS.E.BYPASS.128 [Rs+sharedOffset], [Rg.64+sourceOffset] -- (cp.async.cg, 16 bytes): the asynchronous copy of Accelerator.SM86's -- SM86LoadGlobalToShared, in the raw global form. constructor SM90CopyGlobalToShared field unrestricted sm90CopyGlobalToSharedGuard : (family SM86InstructionGuard) field unrestricted sm90CopyGlobalToSharedAddress : (family SM86Register) field unrestricted sm90CopyGlobalToSharedOffset : Nat field unrestricted sm90CopyGlobalToSharedSource : (family SM86Register) field unrestricted sm90CopyGlobalToSharedSourceOffset : Nat field unrestricted sm90CopyGlobalToSharedControl : (family SM86Control) -- SASS BRA: continue at the instruction the target names. constructor SM90Branch field unrestricted sm90BranchGuard : (family SM86InstructionGuard) field unrestricted sm90BranchTarget : (family SM90BranchTarget) field unrestricted sm90BranchControl : (family SM86Control) -- SASS REDG.E.ADD.F32.FTZ.RN.STRONG.GPU [Ra.64+URZ+offset], Rv -- (red.global.add.f32): Rv added to the binary32 at the address atomically, -- rounded to nearest, subnormals flushed -- Accelerator.SM86's -- SM86ReduceGlobalAddFloat32 in the raw form. RED's descriptor flag is bit -- 71, not 76: bit 76 is part of its operand type (F32.FTZ against F16x4; -- reference/oracles/nvidia-sm90-ptxas/global-branch/README.md). constructor SM90ReduceGlobalAddFloat32 field unrestricted sm90ReduceGlobalGuard : (family SM86InstructionGuard) field unrestricted sm90ReduceGlobalAddress : (family SM86Register) field unrestricted sm90ReduceGlobalValue : (family SM86Register) field unrestricted sm90ReduceGlobalOffset : Nat field unrestricted sm90ReduceGlobalControl : (family SM86Control) -- Default-mode PRMT: each result byte selects one of {right,left}'s -- eight bytes, or replicates its sign byte when selector bit 3 is set. constructor SM90PermuteBytes field unrestricted sm90PermuteGuard : (family SM86InstructionGuard) field unrestricted sm90PermuteDestination : (family SM86Register) field unrestricted sm90PermuteLeft : (family SM86Register) field unrestricted sm90PermuteRight : (family SM86Register) field unrestricted sm90PermuteSelector : (family SM90ByteSelector) field unrestricted sm90PermuteControl : (family SM86Control) -- General three-register LOP3. The SM86-shaped helper fixes its third -- input to RZ; this form exposes all three operands and its byte table. constructor SM90LogicThree field unrestricted sm90LogicGuard : (family SM86InstructionGuard) field unrestricted sm90LogicDestination : (family SM86Register) field unrestricted sm90LogicFirst : (family SM86Register) field unrestricted sm90LogicSecond : (family SM86Register) field unrestricted sm90LogicThird : (family SM86Register) field unrestricted sm90LogicTruth : Byte field unrestricted sm90LogicControl : (family SM86Control) end-family -- Why an encoder or decoder refused: named, so a law can pin the reason. family SM90EncodingRefusal : Type 0 -- a global offset at or above 2^23 (the immediate is signed) constructor SM90RefusalGlobalOffsetOutOfRange -- an LDGSTS source offset at or above 2^11 or shared offset at or above 2^20 constructor SM90RefusalCopyOffsetOutOfRange -- a stall, wait mask or reuse mask wider than its control field constructor SM90RefusalControlOutOfRange -- a branch displacement that is not a whole number of 4-byte units constructor SM90RefusalBranchUnaligned -- a branch displacement outside the 58-bit field (or a backward branch of 0) constructor SM90RefusalBranchOutOfRange -- a word whose opcode is none of this family's constructor SM90RefusalUnknownOpcode -- a word with the opcode of a form whose other bits are not that form's -- a 64-bit global address register that is not an even pair below R254 -- (Ra:Ra+1 holds the address; an odd Ra faults: the fill kernel's -- STG [R3.64] never retired on the H100, comparisons/h100-microbench run -- 20261017T114758Z) constructor SM90RefusalAddressUnaligned -- a 64- or 128-bit data register not aligned to its width (an even pair, -- a multiple-of-4 quad) or running past R254 constructor SM90RefusalDataUnaligned constructor SM90RefusalSelectorOutOfRange constructor SM90RefusalNotCanonical end-family