stg

Store Allocation Tag (Post-index)

STG <Xt|SP>, [<Xn|SP>], #<simm>

Stores the Allocation Tag to memory, then adds the offset to the base register (post-index).

Pseudocode Operation

address = Xn                        // or SP, which must be 16-byte aligned
MemTag[address] = Xt<59:56>         // one 16-byte granule, unchecked access
Xn = address + (SInt(imm9) << 4)    // post-index writeback

Example

STG x0, [x1], #32

Encoding

Binary Layout
11011001
31:24
00
23:22
1
21
imm9
20:12
01
11:10
Xn
9:5
Xt
4:0
 
Format Load/Store
Opcode 0xD9200400

Operands

  • Xt
    Source register (or SP); bits 59:56 of its logical address tag give the tag stored
  • Xn
    Base register (or SP) holding the address of the granule; updated after the store
  • simm
    Signed immediate added to the base afterwards: a multiple of 16, -4096 to 4080

Related

Other forms of stg

  • stg Store Allocation Tag

More in MTE (Memory Tagging)

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0xD9200400 STG <Xt|SP>, [<Xn|SP>], #<simm> A64 11011001 | 00 | 1 | imm9 | 01 | Xn | Xt
0xD9200C00 STG <Xt|SP>, [<Xn|SP>, #<simm>]! A64 11011001 | 00 | 1 | imm9 | 11 | Xn | Xt
0xD9200800 STG <Xt|SP>, [<Xn|SP>{, #<simm>}] A64 11011001 | 00 | 1 | imm9 | 10 | Xn | Xt

Description

Store Allocation Tag stores an Allocation Tag to memory. The address used for the store is calculated from the base register and an immediate signed offset scaled by the Tag granule. The Allocation Tag is calculated from the Logical Address Tag in the source register. This instruction generates an Unchecked access.

Operation

bits(64) address;

if n == 31 then
    CheckSPAlignment();
    address = SP[];
else
    address = X[n, 64];

AccessDescriptor accdesc = CreateAccDescLDGSTG(MemOp_STORE, FALSE);

if !postindex then
    address = GenerateAddress(address, offset, accdesc);

bits(64) data = if t == 31 then SP[] else X[t, 64];
bits(4) tag = AArch64.AllocationTagFromAddress(data);
AArch64.MemTag[address, accdesc] = tag;

if writeback then
    if postindex then
        address = GenerateAddress(address, offset, accdesc);

    if n == 31 then
        SP[] = address;
    else
        X[n, 64] = address;