STG

Constant buffer, local, shared and global memory instructions

fixed bit field field the encoding fixes should be

STG

6362616059585756555453525150494847464544434241403938373635343332
1110111011011
313029282726252423222120191817161514131211109876543210
pred.notpredRaRd

bits 63:48: 1110 1110 1101 1---

Runs execute_LDG with Form() 1.

Fields

The operation reads some of these fields in some forms alone (it chooses by Form()), so the diagrams show only the decoder's.

FieldBitsFrom
size50:48execute_LDG
immediate43:20execute_LDG
pred.not19the decoder
pred18:16the decoder
Ra15:8RegA()
Rd7:0Dst()

Operation Sail

LDG and STG: a global buffer slot's words at the register at 8 plus the signed offset at 20, less the slot's base (its constant buffer word). An STG the prescan found to be the attribute export (SR_DIRECTCBEWRITEENABLED is zero: the shader's ordinary path) does nothing; a pointer only known at run time is shader_global_dynamic's

let store = Form() == 1;
let at = GbAt();
if store & at == 255 then () else if at == 254 then GlobalDynamic() else {
    let slot = at - 1;
    let base = CbufReadDynamic(GbufBank(slot), to_bits(32, GbufOffset(slot)));
    let immediate = Bits32(SignExtend(Field(20, 24), 32)); /* made before the register's read */
    let address0 = R_read(RegA()) + immediate;
    let address = address0 - base;
    let index = address >> 2;
    let size = UInt(Field(48, 3));
    let words = SizeWords(size);
    if store then LogWritten(slot, address, if size < 2 then 1 else if size < 4 then 2 else words * 4);
    foreach (k from 0 to words - 1) {
        let word0 = if k != 0 then index + to_bits(32, k) else index;
        let ptr = GbufPointer(slot, word0);
        if size < 4 then {
            let byte_offset = address & (if size < 2 then 0x00000003 else 0x00000002);
            let bit_offset = byte_offset << 3;
            let width = SubwordWidth(size);
            if store then CasInsert(ptr, bit_offset, width, Dst())
            else R_write(Dst(), SubwordExtract(AtomicLoad(ptr), bit_offset, width, size))
        } else if store then Store(ptr, R_read(Dst() + k))
        else R_write(Dst() + k, Load(ptr))
    }
}

Made from ScarletNX's Sail at 166ad3910f80. The Sail and the encodings' file are ScarletNX's (GPL-3.0-or-later); its encodings are from Eden's maxwell.inc (GPL-2.0-or-later).