[Writeup] Shared pseudocode: part 13 of 36 ========================================== Section: Silicon & Architectures Started: 2026-11-28 17:45 UTC by admin Replies: 0, last post 2026-11-28 17:45 UTC Page: 1 of 1 Web: https://romdump.net/t/105 ------------------------------------------------------------------------------ #125 admin, 2026-11-28 17:45 UTC [OP] Source: https://romdump.net/raw/125

Shared pseudocode from the offline Arm documentation snapshot. Part 13 of 36.

fpcr.FZ = fpcr.FZ OR fpcr.FIZ; // Flush denormalized input and
output to zero
                                      // if either bit is set.
var result : bits(N);

case modop of
    when MemAtomicOp_FPADD =>    result = FPAdd{N}(op1, op2, fpcr, fpexc);
    when MemAtomicOp_FPMAX =>    result = FPMax{N}(op1, op2, fpcr, altfp, fpexc);
    when MemAtomicOp_FPMIN =>    result = FPMin{N}(op1, op2, fpcr, altfp, fpexc);
    when MemAtomicOp_FPMAXNM =>  result = FPMaxNum{N}(op1, op2, fpcr, fpexc);
    when MemAtomicOp_FPMINNM =>  result = FPMinNum{N}(op1, op2, fpcr, fpexc);
    when MemAtomicOp_BFADD =>    result = BFAdd{N}(op1, op2, fpcr, fpexc);
    when MemAtomicOp_BFMAX =>    result = BFMax{N}(op1, op2, fpcr, altfp, fpexc);
    when MemAtomicOp_BFMIN =>    result = BFMin{N}(op1, op2, fpcr, altfp, fpexc);
    when MemAtomicOp_BFMAXNM =>  result = BFMaxNum{N}(op1, op2, fpcr, fpexc);
    when MemAtomicOp_BFMINNM =>  result = BFMinNum{N}(op1, op2, fpcr, fpexc);
end;
return result;

end;


## Library pseudocode for aarch64/functions/memory/MemAtomicInt

// MemAtomicInt // ============== // Performs Integer Atomic operation

func MemAtomicInt{N}(modop : MemAtomicOp, op1 : bits(N), op2 : bits(N), cmpop : bits(N) ) => (bits(N), boolean, bits(N)) begin var result : bits(N); var cmpfail : boolean = FALSE; var retvalue : bits(N) = op1;

case modop of
    when MemAtomicOp_ADD =>      result = op1 + op2;
    when MemAtomicOp_BIC =>      result = op1 AND NOT(op2);
    when MemAtomicOp_EOR =>      result = op1 XOR op2;
    when MemAtomicOp_ORR =>      result = op1 OR op2;
    when MemAtomicOp_SMAX =>     result = Max(SInt(op1), SInt(op2))[N-1:0];
    when MemAtomicOp_SMIN =>     result = Min(SInt(op1), SInt(op2))[N-1:0];
    when MemAtomicOp_UMAX =>     result = Max(UInt(op1), UInt(op2))[N-1:0];
    when MemAtomicOp_UMIN =>     result = Min(UInt(op1), UInt(op2))[N-1:0];
    when MemAtomicOp_SWP =>      result = op2;
    when MemAtomicOp_CAS =>      (result, cmpfail, retvalue) = CASCompare{N}(op1, cmpop, op2);
    when MemAtomicOp_GCSSS1 =>   (result, cmpfail, retvalue) = CASCompare{N}(op1, cmpop, op2);
end;
return (result, cmpfail, retvalue);

end;


## Library pseudocode for aarch64/functions/memory/MemAtomicRCW

// MemAtomicRCW // ============== // Perform a single-copy-atomic access with Read-Check-Write operation

func MemAtomicRCW{size : integer{64, 128}}(address : bits(64), cmpoperand : bits(size), operand : bits(size), accdesc_in : AccessDescriptor ) => (bits(4), bits(size)) begin assert accdesc_in.atomicop; assert accdesc_in.rcw;

let bytes : integer{} = (size DIV 8) as integer{8, 16};

var nzcv : bits(4);
var oldvalue : bits(size);
var newvalue : bits(size);
var accdesc : AccessDescriptor = accdesc_in;
let aligned : boolean = IsAlignedSize(address, bytes);

// If the instruction encoding permits tag checking, confer with system
register configuration
// which may override this.
if accdesc.tagchecked then
    accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc);
end;

if !aligned && AArch64_UnalignedAccessFaults(accdesc, address, bytes)
then
    let fault : FaultRecord = AlignmentFault(accdesc, address);
    AArch64_Abort(fault);
end;

// MMU or MPU lookup
let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address,
accdesc,
                                                                  aligned, bytes);

// Check for aborts or debug exceptions
if IsFault(memaddrdesc) then
    AArch64_Abort(memaddrdesc.fault);
end;

if ((memaddrdesc.memattrs) &&
        ConstrainUnpredictableBool(Unpredictable_Atomic_NOP)) then
    return (ARBITRARY : bits(4), ARBITRARY : bits(size));
end;

// Effect on exclusives
if memaddrdesc.memattrs.shareability != Shareability_NSH then
    ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), bytes);
end;

// For Store-only Tag checking, the tag check is performed on the store.
if (accdesc.tagchecked &&
      (!IsFeatureImplemented(FEAT_MTE_STORE_ONLY) ||
       (accdesc.el))) then
    let ltag : bits(4) = AArch64_LogicalAddressTag(address);
    let readcheck : boolean = TRUE;
    let fault : FaultRecord = AArch64_CheckTag(memaddrdesc, accdesc, readcheck, bytes, ltag);
    if fault.statuscode != Fault_None then
        AArch64_Abort(fault);
    end;
end;

// All observers in the shareability domain observe the following load and
store atomically.
var memstatus : PhysMemRetStatus;
(memstatus, oldvalue) = PhysMemRead{size}(memaddrdesc, accdesc);
// Depending on the memory type of the physical address, the access might
generate
// either a synchronous External abort or an SError exception
// among other CONSTRAINED UNPREDICTABLE choices.

if IsFault(memstatus) then
    HandleExternalReadAbort(memstatus, memaddrdesc, bytes, accdesc);
end;
if BigEndian(accdesc.acctype) then
    oldvalue = BigEndianReverse{size}(oldvalue);
end;

var cmpfail : boolean = FALSE;
var retvalue : bits(size) = oldvalue;
case accdesc.modop of
    when MemAtomicOp_BIC => newvalue = oldvalue AND NOT(operand);
    when MemAtomicOp_ORR => newvalue = oldvalue OR operand;
    when MemAtomicOp_SWP => newvalue = operand;
    when MemAtomicOp_CAS =>
        (newvalue, cmpfail, retvalue) = CASCompare{size}(oldvalue, cmpoperand, operand);
end;

if cmpfail then
    nzcv = '1010'; // N = 1 indicates compare failure
else
    nzcv = RCWCheck{size}(retvalue, newvalue, accdesc.rcws);
end;

// If RCWCheck() passes, it returns nzcv == '0010'
let requirewrite : boolean = (nzcv == '0010' ||
                              ConstrainUnpredictableBool(Unpredictable_WRITEFAILEDRCWCAS));

if IsFeatureImplemented(FEAT_MTE_STORE_ONLY) &&
StoreOnlyTagCheckingEnabled(accdesc.el) then
    // If the RCW(S) checks, or if the compare on a Tag checked RCW(S)CAS fails and no write is
    // performed, then it is CONSTRAINED UNPREDICTABLE whether the Tag check is performed.
    if accdesc.tagchecked && !requirewrite then
        accdesc.tagchecked = ConstrainUnpredictableBool(Unpredictable_STRONLYTAGCHECKEDRCWSCAS);
    end;

    if accdesc.tagchecked then
        let ltag : bits(4) = AArch64_LogicalAddressTag(address);
        let readcheck : boolean = FALSE;
        var fault : FaultRecord = AArch64_CheckTag(memaddrdesc, accdesc, readcheck,
                                                   bytes, ltag);
        if fault.statuscode != Fault_None then
            // For a synchronous Tag Check Fault due to FEAT_MTE_STORE_ONLY, set WnR.
            fault.write = TRUE;
            AArch64_Abort(fault);
        end;
    end;
end;

if requirewrite then
    if BigEndian(accdesc.acctype) then
        newvalue = BigEndianReverse{size}(newvalue);
    end;

    memstatus = PhysMemWrite{size}(memaddrdesc, accdesc, newvalue);

    if IsFault(memstatus) then
        HandleExternalWriteAbort(memstatus, memaddrdesc, bytes, accdesc);
    end;
end;

if SPESampleInFlight then
    let is_load : boolean = TRUE;
    SPESampleLoadStore(is_load, accdesc, memaddrdesc);
end;

// Load operations return the old (pre-operation) value.
// Compare and Swap operations return the old (pre-operation) value. For a
successful CAS,
// this might be the value from the compare operand or from memory.
return (nzcv, retvalue);

end;


## Library pseudocode for aarch64/functions/memory/MemLoad64B

// MemLoad64B // ============ // Performs an atomic 64-byte read from a given virtual address.

func MemLoad64B(address : bits(64), accdesc_in : AccessDescriptor) => bits(512) begin let size : integer{} = 512; let bytes : integer{} = size DIV 8; var data : bits(size); var accdesc : AccessDescriptor = accdesc_in; let aligned : boolean = IsAlignedSize(address, bytes);

if !aligned && AArch64_UnalignedAccessFaults(accdesc,
address, bytes) then
    let fault : FaultRecord = AlignmentFault(accdesc, address);
    AArch64_Abort(fault);
end;

// If the instruction encoding permits tag checking, confer with system
register configuration
// which may override this.
if accdesc.tagchecked then
    accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc);
end;

var memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address,
accdesc,
                                                               aligned, bytes);

// Check for aborts or debug exceptions
if IsFault(memaddrdesc) then
    AArch64_Abort(memaddrdesc.fault);
end;

// Effect on exclusives
if memaddrdesc.memattrs.shareability != Shareability_NSH then
    ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), bytes);
end;

if accdesc.tagchecked then
    let ltag : bits(4)      = AArch64_LogicalAddressTag(address);
    let readcheck : boolean = TRUE;
    let fault : FaultRecord = AArch64_CheckTag(memaddrdesc, accdesc, readcheck, bytes, ltag);
    if fault.statuscode != Fault_None then
        AArch64_Abort(fault);
    end;
end;

var byte_atomic : boolean = FALSE;
if ((memaddrdesc.memattrs.memtype == MemType_Device ||
      (memaddrdesc.memattrs.inner.attrs == MemAttr_NC &&
         memaddrdesc.memattrs.outer.attrs == MemAttr_NC)) &&
      (memaddrdesc.paddress.address)) then
    let c : Constraint = ConstrainUnpredictable(Unpredictable_LS64UNSUPPORTED);
    assert c IN {Constraint_LIMITED_ATOMICITY, Constraint_FAULT};
    if c == Constraint_FAULT then
        // Generate a stage 1 Data Abort reported using the DFSC code of 110101.
        let fault : FaultRecord = ExclusiveFault(accdesc, address);
        AArch64_Abort(fault);
    else
        byte_atomic = TRUE;
    end;
elsif IsWBShareable(memaddrdesc.memattrs) && (memaddrdesc) then
    if ImpDefBool("LD64B faults to iWBoWB non-Conventional memory") then
        // Generate a Data Abort reported using the DFSC code of 110101.
        let fault : FaultRecord = ExclusiveFault(accdesc, address);
        AArch64_Abort(fault);
    else
        byte_atomic = TRUE;
    end;
end;

if SPESampleInFlight then
    let is_load : boolean = TRUE;
    SPESampleLoadStore(is_load, accdesc, memaddrdesc);
end;

var memstatus : PhysMemRetStatus;
if byte_atomic then
    // Accesses are not single-copy atomic above the byte level.
    for i = 0 to bytes-1 do
        (memstatus, data[i*:8]) = PhysMemRead{8}(memaddrdesc, accdesc);
        if IsFault(memstatus) then
            HandleExternalReadAbort(memstatus, memaddrdesc, 1, accdesc);
        end;
        memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
        memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
    end;
else
    (memstatus, data) = PhysMemRead{size}(memaddrdesc, accdesc);
    if IsFault(memstatus) then
        HandleExternalReadAbort(memstatus, memaddrdesc, bytes, accdesc);
    end;
end;

return data;

end;


## Library pseudocode for aarch64/functions/memory/MemStore64B

// MemStore64B // ============= // Performs an atomic 64-byte store to a given virtual address. Function does // not return the status of the store.

func MemStore64B(address : bits(64), value : bits(512), accdesc_in : AccessDescriptor) begin let size : integer{} = 512; let bytes : integer{} = size DIV 8; var accdesc : AccessDescriptor = accdesc_in; let aligned : boolean = IsAlignedSize(address, bytes);

if !aligned && AArch64_UnalignedAccessFaults(accdesc,
address, bytes) then
    let fault : FaultRecord = AlignmentFault(accdesc, address);
    AArch64_Abort(fault);
end;

// If the instruction encoding permits tag checking, confer with system
register configuration
// which may override this.
if accdesc.tagchecked then
    accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc);
end;

var memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address,
accdesc,
                                                               aligned, bytes);

// Check for aborts or debug exceptions
if IsFault(memaddrdesc) then
    AArch64_Abort(memaddrdesc.fault);
end;

// Effect on exclusives
if memaddrdesc.memattrs.shareability != Shareability_NSH then
    ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 64);
end;

if accdesc.tagchecked then
    let ltag : bits(4)      = AArch64_LogicalAddressTag(address);
    let readcheck : boolean = FALSE;
    let fault : FaultRecord = AArch64_CheckTag(memaddrdesc, accdesc, readcheck, bytes, ltag);
    if fault.statuscode != Fault_None then
        AArch64_Abort(fault);
    end;
end;

var byte_atomic : boolean = FALSE;
if ((memaddrdesc.memattrs.memtype == MemType_Device ||
      (memaddrdesc.memattrs.inner.attrs == MemAttr_NC &&
         memaddrdesc.memattrs.outer.attrs == MemAttr_NC)) &&
      (memaddrdesc.paddress.address)) then
    let c : Constraint = ConstrainUnpredictable(Unpredictable_LS64UNSUPPORTED);
    assert c IN {Constraint_LIMITED_ATOMICITY, Constraint_FAULT};
    if c == Constraint_FAULT then
        // Generate a Data Abort reported using the DFSC code of 110101.
        let fault : FaultRecord = ExclusiveFault(accdesc, address);
        AArch64_Abort(fault);
    else
        byte_atomic = TRUE;
    end;
elsif IsWBShareable(memaddrdesc.memattrs) && (memaddrdesc) then
    if ImpDefBool("ST64B faults to iWBoWB non-Conventional memory") then
        // Generate a Data Abort reported using the DFSC code of 110101.
        let fault : FaultRecord = ExclusiveFault(accdesc, address);
        AArch64_Abort(fault);
    else
        byte_atomic = TRUE;
    end;
end;

if SPESampleInFlight then
    let is_load : boolean = FALSE;
    SPESampleLoadStore(is_load, accdesc, memaddrdesc);
end;

var memstatus : PhysMemRetStatus;
if byte_atomic then
    // Accesses are not single-copy atomic above the byte level.
    for i = 0 to bytes-1 do
        memstatus = PhysMemWrite{8}(memaddrdesc, accdesc, value[i*:8]);
        if IsFault(memstatus) then
            HandleExternalWriteAbort(memstatus, memaddrdesc, 1, accdesc);
        end;
        memaddrdesc.paddress.address = memaddrdesc.paddress.address + 1;
        memaddrdesc.vaddress         = memaddrdesc.vaddress + 1;
    end;
else
    memstatus = PhysMemWrite{size}(memaddrdesc, accdesc, value);
    if IsFault(memstatus) then
        HandleExternalWriteAbort(memstatus, memaddrdesc, bytes, accdesc);
    end;
end;

return;

end;


## Library pseudocode for aarch64/functions/memory/MemStore64BWithRet

// MemStore64BWithRet // ==================== // Performs an atomic 64-byte store to a given virtual address returning // the status value of the operation.

func MemStore64BWithRet(address : bits(64), value : bits(512), accdesc_in : AccessDescriptor) => bits(64) begin let size : integer{} = 512; let bytes : integer{} = size DIV 8; var accdesc : AccessDescriptor = accdesc_in; let aligned : boolean = IsAlignedSize(address, bytes);

if !aligned && AArch64_UnalignedAccessFaults(accdesc,
address, bytes) then
    let fault : FaultRecord = AlignmentFault(accdesc, address);
    AArch64_Abort(fault);
end;

// If the instruction encoding permits tag checking, confer with system
register configuration
// which may override this.
if accdesc.tagchecked then
    accdesc.tagchecked = AArch64_AccessIsTagChecked(address, accdesc);
end;

let memaddrdesc : AddressDescriptor = AArch64_TranslateAddress(address,
accdesc,
                                                                aligned, bytes);

// Check for aborts or debug exceptions
if IsFault(memaddrdesc) then
    AArch64_Abort(memaddrdesc.fault);
end;

// Effect on exclusives
if memaddrdesc.memattrs.shareability != Shareability_NSH then
    ClearExclusiveByAddress(memaddrdesc.paddress, ProcessorID(), 64);
end;

if accdesc.tagchecked then
    let ltag : bits(4)      = AArch64_LogicalAddressTag(address);
    let readcheck : boolean = FALSE;
    let fault : FaultRecord = AArch64_CheckTag(memaddrdesc, accdesc, readcheck, bytes, ltag);
    if fault.statuscode != Fault_None then
        AArch64_Abort(fault);
    end;
end;

var memstatus : PhysMemRetStatus;
memstatus = PhysMemWrite{size}(memaddrdesc, accdesc, value);

// If an access generated by ST64BV or ST64BV0 fails solely because the memory
location
// does not support 64-byte access, then memstatus does not indicate a fault,
if IsFault(memstatus) then
    HandleExternalWriteAbort(memstatus, memaddrdesc, bytes, accdesc);
end;

if SPESampleInFlight then
    let is_load : boolean = FALSE;
    SPESampleLoadStore(is_load, accdesc, memaddrdesc);
end;

return memstatus.store64bstatus;

end;


## Library pseudocode for aarch64/functions/memory/MemStore64BWithRetStatus

// MemStore64BWithRetStatus // ========================== // Generates the return status of memory write with ST64BV or ST64BV0 // instructions. The status indicates if the operation succeeded, failed, // or was not supported at this memory location.

impdef func MemStore64BWithRetStatus() => bits(64) begin return Zeros{64}; end;


## Library pseudocode for aarch64/functions/memory/NVMem

// NVMem - accessor // ================

accessor NVMem(offset : integer) <=> value : bits(64) begin // This function is the load memory access for the transformed System register read access // when Enhanced Nested Virtualization is enabled with HCR_EL2.NV2 = 1. // The address for the load memory access is calculated using // the formula SignExtend{64}(VNCR_EL2.BADDR :: Offset[11:0]) where, // * VNCR_EL2.BADDR holds the base address of the memory location, and // * Offset is the unique offset value defined architecturally for each System register that // supports transformation of register access to memory access. getter assert offset > 0 && offset MOD 8 == 0; let directread : boolean = FALSE; let baddr : bits(64) = EffectiveBADDR(VNCR_EL2().BADDR :: Zeros{12}, directread); let address : bits(64) = baddr + offset; let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_LOAD); return Mem{64}(address, accdesc); end;

// This function is the store memory access for the transformed
System register write access
// when Enhanced Nested Virtualization is enabled with HCR_EL2.NV2 = 1.
// The address for the store memory access is calculated using
// the formula SignExtend{64}(VNCR_EL2.BADDR :: Offset[11:0]) where,
//  * VNCR_EL2.BADDR holds the base address of the memory location, and
// * Offset is the unique offset value defined architecturally for each System
register that
//    supports transformation of register access to memory access.
setter
    assert offset > 0 && offset MOD 8 == 0;
    let directread : boolean = FALSE;
    let baddr : bits(64)     = EffectiveBADDR(VNCR_EL2().BADDR :: Zeros{12}, directread);
    let address : bits(64)   = baddr + offset;
    let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_STORE);
    Mem{64}(address, accdesc) = value;
    return;
end;

end;

accessor NVMem128(offset : integer) <=> value : bits(128) begin getter assert offset > 0 && offset MOD 16 == 0; let directread : boolean = FALSE; let baddr : bits(64) = EffectiveBADDR(VNCR_EL2().BADDR :: Zeros{12}, directread); let address : bits(64) = baddr + offset; let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_LOAD); return Mem{128}(address, accdesc); end;

setter
    assert offset > 0 && offset MOD 16 == 0;
    let directread : boolean = FALSE;
    let baddr : bits(64)     = EffectiveBADDR(VNCR_EL2().BADDR :: Zeros{12}, directread);
    let address : bits(64)   = baddr + offset;
    let accdesc : AccessDescriptor = CreateAccDescNV2(MemOp_STORE);
    Mem{128}(address, accdesc) = value;
end;

end;


## Library pseudocode for aarch64/functions/memory/PhysMemTagRead

// PhysMemTagRead // ================ // This is the hardware operation which perform a single-copy atomic, // Allocation Tag granule aligned, memory access from the tag in PA space. // // The function address the array using desc.paddress which supplies: // * A 52-bit physical address // * A single NS bit to select between Secure and Non-secure parts of the array. // // The accdesc descriptor describes the access type: normal, exclusive, ordered, streaming, // etc and other parameters required to access the physical memory or for setting syndrome // register in the event of an External abort.

impdef func PhysMemTagRead(desc : AddressDescriptor, accdesc : AccessDescriptor) => (PhysMemRetStatus, bits(4)) begin return (ARBITRARY : PhysMemRetStatus, Zeros{4}); end;


## Library pseudocode for aarch64/functions/memory/PhysMemTagWrite

// PhysMemTagWrite // ================= // This is the hardware operation which perform a single-copy atomic, // Allocation Tag granule aligned, memory access to the tag in PA space. // // The function address the array using desc.paddress which supplies: // * A 52-bit physical address // * A single NS bit to select between Secure and Non-secure parts of the array. // // The accdesc descriptor describes the access type: normal, exclusive, ordered, streaming, // etc and other parameters required to access the physical memory or for setting syndrome // register in the event of an External abort.

impdef func PhysMemTagWrite(desc : AddressDescriptor, accdesc : AccessDescriptor, value : bits(4)) => PhysMemRetStatus begin return ARBITRARY : PhysMemRetStatus; end;


## Library pseudocode for aarch64/functions/memory/StoreOnlyTagCheckingEnabled

// StoreOnlyTagCheckingEnabled // ============================= // Returns TRUE if loads executed at the given Exception level are Tag unchecked.

readonly func StoreOnlyTagCheckingEnabled(el : bits(2)) => boolean begin assert IsFeatureImplemented(FEAT_MTE_STORE_ONLY); var tcso : bit;

case el of
    when EL0 =>
        if (el) then
            tcso = SCTLR_EL1().TCSO0;
        else
            tcso = SCTLR_EL2().TCSO0;
        end;
    when EL1 =>
        tcso = SCTLR_EL1().TCSO;
    when EL2 =>
        tcso = SCTLR_EL2().TCSO;
    otherwise =>
        tcso = SCTLR_EL3().TCSO;
end;

return tcso == '1';

end;


## Library pseudocode for aarch64/functions/mops/ArchMaxMOPSBlockSize

// ArchMaxMOPSBlockSize // ==================== // Maximum number of bytes CPY/SET instructions can use

constant ArchMaxMOPSBlockSize : integer{} = 0x7FFF_FFFF_FFFF_FFFF;


## Library pseudocode for aarch64/functions/mops/ArchMaxMOPSCPYSize

// ArchMaxMOPSCPYSize // ================== // Maximum number of bytes CPY instructions can use

constant ArchMaxMOPSCPYSize : integer{} = 0x007F_FFFF_FFFF_FFFF;


## Library pseudocode for aarch64/functions/mops/ArchMaxMOPSSETGSize

// ArchMaxMOPSSETGSize // =================== // Maximum number of bytes SETG instructions can use

constant ArchMaxMOPSSETGSize : integer{} = 0x7FFF_FFFF_FFFF_FFF0;


## Library pseudocode for aarch64/functions/mops/CPYFOptionA

// CPYFOptionA // ============= // Returns TRUE if the implementation uses Option A for the // CPYF* instructions, and FALSE otherwise.

func CPYFOptionA() => boolean begin return ImpDefBool("CPYF* instructions use Option A"); end;


## Library pseudocode for aarch64/functions/mops/CPYOptionA

// CPYOptionA // ============ // Returns TRUE if the implementation uses Option A for the // CPY* instructions, and FALSE otherwise.

func CPYOptionA() => boolean begin return ImpDefBool("CPY* instructions use Option A"); end;


## Library pseudocode for aarch64/functions/mops/CPYParams

// CPYParams // =========

type CPYParams of record { stage : MOPSStage, implements_option_a : boolean, forward : boolean, cpysize : integer, stagecpysize : integer, toaddress : bits(64), fromaddress : bits(64), nzcv : bits(4), n : integer, d : integer, s : integer };


## Library pseudocode for aarch64/functions/mops/CPYPostSizeChoice

// CPYPostSizeChoice // =================== // Returns the size of the copy that is performed by the CPYE* instructions for this // implementation given the parameters of the destination, source and size of the copy.

impdef func CPYPostSizeChoice(memcpy : CPYParams) => integer begin return ARBITRARY : integer; end;


## Library pseudocode for aarch64/functions/mops/CPYPreSizeChoice

// CPYPreSizeChoice // ================== // Returns the size of the copy that is performed by the CPYP* instructions for this // implementation given the parameters of the destination, source and size of the copy.

impdef func CPYPreSizeChoice(memcpy : CPYParams) => integer begin return ARBITRARY : integer; end;


## Library pseudocode for aarch64/functions/mops/CPYSizeChoice

// CPYSizeChoice // =============== // Returns the size of the block this performed for an iteration of the copy given the // parameters of the destination, source and size of the copy.

impdef func CPYSizeChoice(memcpy : CPYParams) => MOPSBlockSize begin return ARBITRARY : MOPSBlockSize; end;


## Library pseudocode for
aarch64/functions/mops/CheckCPYConstrainedUnpredictable

// CheckCPYConstrainedUnpredictable // ================================== // Check for CONSTRAINED UNPREDICTABLE behavior in the CPY* and CPYF* instructions.

func CheckCPYConstrainedUnpredictable(n : integer, d : integer, s : integer) begin if (s == n || s == d || n == d) then let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP); assert c IN {Constraint_UNDEF, Constraint_NOP}; case c of when Constraint_UNDEF => Undefined(); when Constraint_NOP => ExecuteAsNOP(); end; end;

if (d == 31 || s == 31 || n == 31) then
    let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPS_R31);
    assert c IN {Constraint_UNDEF, Constraint_NOP};
    case c of
        when Constraint_UNDEF =>      Undefined();
        when Constraint_NOP =>        ExecuteAsNOP();
    end;
end;

end;


## Library pseudocode for aarch64/functions/mops/CheckMOPSEnabled

// CheckMOPSEnabled // ================== // Check for EL0 and EL1 access to the CPY* and SET* instructions.

func CheckMOPSEnabled begin if (PSTATE.EL IN {EL0, EL1} && EL2Enabled() && (EL0) && (() || HCRX_EL2().MSCEn == '0')) then Undefined(); end;

if PSTATE.EL == EL0 && () && SCTLR_EL1().MSCEn ==
'0' then
    Undefined();
end;

if PSTATE.EL == EL0 && IsInHost() && SCTLR_EL2().MSCEn == '0'
then
    Undefined();
end;

end;


## Library pseudocode for aarch64/functions/mops/CheckMemCpyParams

// CheckMemCpyParams // =================== // Check if the parameters to a CPY* or CPYF* instruction are consistent with the // PE state and well-formed.

func CheckMemCpyParams(memcpy : CPYParams, options : bits(4)) begin let from_epilogue : boolean = memcpy.stage == MOPSStage_Epilogue;

// Check if this version is consistent with the state of the call.
if ((memcpy.stagecpysize != 0 || MemStageCpyZeroSizeCheck()) &&
      (memcpy.cpysize != 0 || MemCpyZeroSizeCheck())) then
    let using_option_a : boolean = memcpy.nzcv[1] == '0';
    if memcpy.implements_option_a != using_option_a then
        let formatoption : bits(2) = '1':: (if memcpy.implements_option_a then '1' else '0');
        MismatchedMemCpyException(memcpy, options, formatoption);
    end;
end;

// Check if the parameters to this instruction are valid.
if memcpy.stage == MOPSStage_Main then
    if MemCpyParametersIllformedM(memcpy) then
        let formatoption : bits(2) = '0':: (if memcpy.implements_option_a then '1' else '0');
        MismatchedMemCpyException(memcpy, options, formatoption);
    end;
else
    let postsize : integer = CPYPostSizeChoice(memcpy);
    if memcpy.cpysize != postsize || MemCpyParametersIllformedE(memcpy) then
        let formatoption : bits(2) = '0':: (if memcpy.implements_option_a then '1' else '0');
        MismatchedMemCpyException(memcpy, options, formatoption);
    end;
end;

return;

end;


## Library pseudocode for aarch64/functions/mops/CheckMemSetParams

// CheckMemSetParams // =================== // Check if the parameters to a SET* or SETG* instruction are consistent with the // PE state and well-formed.

func CheckMemSetParams(memset : SETParams, options : bits(2)) begin let from_epilogue : boolean = memset.stage == MOPSStage_Epilogue;

// Check if this version is consistent with the state of the call.
if ((memset.stagesetsize != 0 || MemStageSetZeroSizeCheck()) &&
      (memset.setsize != 0 || MemSetZeroSizeCheck())) then
    let using_option_a : boolean = memset.nzcv[1] == '0';
    if memset.implements_option_a != using_option_a then
        let formatoption : bits(2) = '1':: (if memset.implements_option_a then '1' else '0');
        MismatchedMemSetException(memset, options, formatoption);
    end;
end;

// Check if the parameters to this instruction are valid.
if memset.stage == MOPSStage_Main then
    if MemSetParametersIllformedM(memset) then
        let formatoption : bits(2) = '0':: (if memset.implements_option_a then '1' else '0');
        MismatchedMemSetException(memset, options, formatoption);
    end;
else
    let postsize : integer = SETPostSizeChoice(memset);
    if memset.setsize != postsize || MemSetParametersIllformedE(memset) then
        let formatoption : bits(2) = '0':: (if memset.implements_option_a then '1' else '0');
        MismatchedMemSetException(memset, options, formatoption);
    end;
end;

return;

end;


## Library pseudocode for
aarch64/functions/mops/CheckSETConstrainedUnpredictable

// CheckSETConstrainedUnpredictable // ================================== // Check for CONSTRAINED UNPREDICTABLE behavior in the SET* and SETG* instructions.

func CheckSETConstrainedUnpredictable(memset : SETParams) begin if (memset.s == memset.n || memset.s == memset.d || memset.n == memset.d) then let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPSOVERLAP); assert c IN {Constraint_UNDEF, Constraint_NOP}; case c of when Constraint_UNDEF => Undefined(); when Constraint_NOP => ExecuteAsNOP(); end; end;

if (memset.d == 31 || memset.n == 31) then
    let c : Constraint = ConstrainUnpredictable(Unpredictable_MOPS_R31);
    assert c IN {Constraint_UNDEF, Constraint_NOP};
    case c of
        when Constraint_UNDEF => Undefined();
        when Constraint_NOP   => ExecuteAsNOP();
    end;
end;

end;


## Library pseudocode for aarch64/functions/mops/IsMemCpyForward

// IsMemCpyForward // ================= // Returns TRUE if in a memcpy of size cpysize bytes from the source address fromaddress // to destination address toaddress is done in the forward direction on this implementation.

func IsMemCpyForward(memcpy : CPYParams) => boolean begin var forward : boolean;

// Check for overlapping cases
if ((UInt(memcpy.fromaddress[55:0]) > UInt(memcpy.toaddress[55:0]))
&&
      (UInt(memcpy.fromaddress[55:0]) < UInt(ZeroExtend{64}(memcpy.toaddress[55:0]) +
         memcpy.cpysize))) then
    forward = TRUE;

elsif ((UInt(memcpy.fromaddress[55:0]) < UInt(memcpy.toaddress[55:0]))
&&
         (UInt(ZeroExtend{64}(memcpy.fromaddress[55:0]) + memcpy.cpysize) >
            UInt(memcpy.toaddress[55:0]))) then
    forward = FALSE;

// Non-overlapping case
else
    forward = ImpDefBool("CPY in the forward direction");
end;

return forward;

end;


## Library pseudocode for aarch64/functions/mops/MOPSBlockSize

// MOPSBlockSize // ================

type MOPSBlockSize of integer{0..MaxMOPSBlockSize};


## Library pseudocode for aarch64/functions/mops/MOPSStage

// MOPSStage // =========

type MOPSStage of enumeration { MOPSStage_Prologue, MOPSStage_Main, MOPSStage_Epilogue };


## Library pseudocode for aarch64/functions/mops/MaxMOPSBlockSize

// MaxMOPSBlockSize // ================ // Maximum number of bytes CPY/SET instructions can use

config MaxMOPSBlockSize : integer{1..ArchMaxMOPSBlockSize} = 64;


## Library pseudocode for aarch64/functions/mops/MemCpyBytes

// MemCpyBytes // ============= // Copies 'bytes' bytes of memory from fromaddress to toaddress. // The integer return parameter indicates the number of bytes copied. The boolean return parameter // indicates if a Fault or Abort occurred on the write. The AddressDescriptor and PhysMemRetStatus // parameters contain Fault or Abort information for the caller to handle.

func MemCpyBytes(toaddress : bits(64), fromaddress : bits(64), forward : boolean, bytes : MOPSBlockSize, raccdesc : AccessDescriptor, waccdesc : AccessDescriptor ) => (integer, boolean, AddressDescriptor, PhysMemRetStatus) begin var rmemaddrdesc : AddressDescriptor; // AddressDescriptor for reads var rmemstatus : PhysMemRetStatus; // PhysMemRetStatus for writes rmemaddrdesc.fault = NoFault(); rmemstatus.statuscode = Fault_None;

var wmemaddrdesc : AddressDescriptor; // AddressDescriptor for
writes
var wmemstatus : PhysMemRetStatus; // PhysMemRetStatus for writes
wmemaddrdesc.fault    = NoFault();
wmemstatus.statuscode = Fault_None;

var value : bits(8*bytes);
let aligned : boolean = TRUE;

if forward then
    var read : integer  = 0;                          // Bytes read
    var write : integer = 0;                          // Bytes written

    // Read until all bytes are read or until a fault is encountered.
    while (read < bytes && !IsFault(rmemaddrdesc) && !IsFault(rmemstatus))
                                        looplimit MaxMOPSBlockSize do
        (value[8 * read +:8], rmemaddrdesc, rmemstatus) = AArch64_MemSingleRead{8}(
                                                                        fromaddress + read,
                                                                        raccdesc, aligned);
        read = read + 1;
    end;

    // Ensure no UNKNOWN data is written.
    if IsFault(rmemaddrdesc) || IsFault(rmemstatus) then
        read = read - 1;
    end;

    // Write all bytes that were read or until a fault is encountered.
    while write < read && !IsFault(wmemaddrdesc) && !IsFault(wmemstatus)
                                    looplimit MaxMOPSBlockSize  do
        (wmemaddrdesc, wmemstatus) = AArch64_MemSingleWrite{8}(toaddress + write,
                                                            waccdesc, aligned,
                                                            value[8 * write +:8]);
        write = write + 1;
    end;

    // Check all bytes were written.
    if IsFault(wmemaddrdesc) || IsFault(wmemstatus) then
        let fault_on_write : boolean = TRUE;
        return (write - 1, fault_on_write, wmemaddrdesc, wmemstatus);
    end;

    // Check all bytes were read.
    if IsFault(rmemaddrdesc) || IsFault(rmemstatus) then
        let fault_on_write : boolean = FALSE;
        return (read, fault_on_write, rmemaddrdesc, rmemstatus);
    end;

else
    var read : integer  = bytes;                      // Bytes to read
    var write : integer = bytes;                      // Bytes to write

    // Read until all bytes are read or until a fault is encountered.
    while read > 0 && !IsFault(rmemaddrdesc) && !IsFault(rmemstatus)
                                        looplimit MaxMOPSBlockSize do
        read = read - 1;
        (value[8 * read +:8], rmemaddrdesc, rmemstatus) = AArch64_MemSingleRead{8}(
                                                                        fromaddress + read,
                                                                        raccdesc, aligned);
    end;

    // Ensure no UNKNOWN data is written.
    if IsFault(rmemaddrdesc) || IsFault(rmemstatus) then
        read = read + 1;
    end;

    // Write all bytes that were read or until a fault is encountered.
    while write > read && !IsFault(wmemaddrdesc) && !IsFault(wmemstatus)
                                            looplimit MaxMOPSBlockSize do
        write = write - 1;
        (wmemaddrdesc, wmemstatus) = AArch64_MemSingleWrite{8}(toaddress + write,
                                                            waccdesc, aligned,
                                                            value[8 * write +:8]);
    end;

    // Check all bytes were written.
    if IsFault(wmemaddrdesc) || IsFault(wmemstatus) then
        let fault_on_write : boolean = TRUE;
        return (bytes - (write + 1), fault_on_write, wmemaddrdesc, wmemstatus);
    end;

    // Check all bytes were read.
    if IsFault(rmemaddrdesc) || IsFault(rmemstatus) then
        let fault_on_write : boolean = FALSE;
        return (bytes - read, fault_on_write, rmemaddrdesc, rmemstatus);
    end;
end;

// Return any AddressDescriptor and PhysMemRetStatus.
return (bytes, FALSE, wmemaddrdesc, wmemstatus);

end;


## Library pseudocode for aarch64/functions/mops/MemCpyParametersIllformedE

// MemCpyParametersIllformedE // ============================ // Returns TRUE if the inputs are not well formed (in terms of their size and/or alignment) // for a CPYE* instruction for this implementation given the parameters of the destination, // source and size of the copy.

impdef func MemCpyParametersIllformedE(memcpy : CPYParams) => boolean begin return FALSE; end;


## Library pseudocode for aarch64/functions/mops/MemCpyParametersIllformedM

// MemCpyParametersIllformedM // ============================ // Returns TRUE if the inputs are not well formed (in terms of their size and/or alignment) // for a CPYM* instruction for this implementation given the parameters of the destination, // source and size of the copy.

impdef func MemCpyParametersIllformedM(memcpy : CPYParams) => boolean begin return FALSE; end;


## Library pseudocode for aarch64/functions/mops/MemCpyStageSize

// MemCpyStageSize // ================= // Returns the number of bytes copied by the given stage of a CPY* or CPYF* instruction.

func MemCpyStageSize(memcpy : CPYParams) => integer begin var stagecpysize : integer;

if memcpy.stage == MOPSStage_Prologue then
    // IMP DEF selection of the amount covered by pre-processing.
    stagecpysize = CPYPreSizeChoice(memcpy);
    assert stagecpysize == 0 || (stagecpysize < 0) == (memcpy.cpysize < 0);

    if memcpy.cpysize > 0 then
        assert stagecpysize <= memcpy.cpysize;
    else
        assert stagecpysize >= memcpy.cpysize;
    end;

else
    let postsize : integer = CPYPostSizeChoice(memcpy);
    assert postsize == 0 || (postsize < 0) == (memcpy.cpysize < 0);

    if memcpy.stage == MOPSStage_Main then
        stagecpysize = memcpy.cpysize - postsize;
    else
        stagecpysize = postsize;
    end;
end;

return stagecpysize;

end;


## Library pseudocode for aarch64/functions/mops/MemCpyZeroSizeCheck

// MemCpyZeroSizeCheck // ===================== // Returns TRUE if the implementation option is checked on a copy of size zero remaining.

func MemCpyZeroSizeCheck() => boolean begin return ImpDefBool("Implementation option is checked with a cpysize of 0"); end;


## Library pseudocode for aarch64/functions/mops/MemSetBytes

// MemSetBytes // ============= // Writes a byte of data to the given address 'bytes' times. // The integer return parameter indicates the number of bytes set. The AddressDescriptor and // PhysMemRetStatus parameters contain Fault or Abort information for the caller to handle.

func MemSetBytes(toaddress : bits(64), data : bits(8), bytes : MOPSBlockSize, accdesc : AccessDescriptor) => (integer, AddressDescriptor, PhysMemRetStatus) begin var memaddrdesc : AddressDescriptor; var memstatus : PhysMemRetStatus; memaddrdesc.fault = NoFault(); memstatus.statuscode = Fault_None;

let aligned : boolean = TRUE;
var write : integer   = 0;                            // Bytes written

// Write until all bytes are written or a fault is encountered.
while write < bytes && !IsFault(memaddrdesc) &&
!IsFault(memstatus)
                                            looplimit MaxMOPSBlockSize do
    (memaddrdesc, memstatus) = AArch64_MemSingleWrite{8}(toaddress + write, accdesc,
                                                         aligned, data);
    write = write + 1;
end;

// Check all bytes were written.
if IsFault(memaddrdesc) || IsFault(memstatus) then
    return (write - 1, memaddrdesc, memstatus);
end;

return (bytes, memaddrdesc, memstatus);

end;


## Library pseudocode for aarch64/functions/mops/MemSetParametersIllformedE

// MemSetParametersIllformedE // ============================ // Returns TRUE if the inputs are not well formed (in terms of their size and/or // alignment) for a SETE* or SETGE* instruction for this implementation given the // parameters of the destination and size of the set.

impdef func MemSetParametersIllformedE(memset : SETParams) => boolean begin return FALSE; end;


## Library pseudocode for aarch64/functions/mops/MemSetParametersIllformedM

// MemSetParametersIllformedM // ============================ // Returns TRUE if the inputs are not well formed (in terms of their size and/or // alignment) for a SETM* or SETGM* instruction for this implementation given the // parameters of the destination and size of the copy.

impdef func MemSetParametersIllformedM(memset : SETParams) => boolean begin return FALSE; end;


## Library pseudocode for aarch64/functions/mops/MemSetStageSize

// MemSetStageSize // ================= // Returns the number of bytes set by the given stage of a SET* or SETG* instruction.

func MemSetStageSize(memset : SETParams) => integer begin var stagesetsize : integer;

if memset.stage == MOPSStage_Prologue then
    // IMP DEF selection of the amount covered by pre-processing.
    stagesetsize = SETPreSizeChoice(memset);
    assert stagesetsize == 0 || (stagesetsize < 0) == (memset.setsize < 0);

    if memset.is_setg then assert stagesetsize[3:0] == '0000'; end;

    if memset.setsize > 0 then
        assert stagesetsize <= memset.setsize;
    else
        assert stagesetsize >= memset.setsize;
    end;

else
    let postsize : integer = SETPostSizeChoice(memset);
    assert postsize == 0 || (postsize < 0) == (memset.setsize < 0);
    if memset.is_setg then assert postsize[3:0] == '0000'; end;

    if memset.stage == MOPSStage_Main then
        stagesetsize = memset.setsize - postsize;
    else
        stagesetsize = postsize;
    end;
end;

return stagesetsize;

end;


## Library pseudocode for aarch64/functions/mops/MemSetTags

// MemSetTags // ============ // Write Allocation Tags for each Tag Granule in 'size'. // The integer return parameter indicates the number of Tag Granules written. The // AddressDescriptor and PhysMemRetStatus parameters contain Fault or Abort information for // the caller to handle.

func MemSetTags(toaddress : bits(64), tag : bits(4), size : integer, accdesc : AccessDescriptor ) => (integer, AddressDescriptor, PhysMemRetStatus) begin assert IsAlignedSize{64}(toaddress, TAG_GRANULE) && size MOD TAG_GRANULE == 0;

var memaddrdesc : AddressDescriptor;
var memstatus : PhysMemRetStatus;
memaddrdesc.fault     = NoFault();
memstatus.statuscode  = Fault_None;
var tagstep : integer = size DIV TAG_GRANULE;

// Write until all tags are written or a fault is encountered.
while tagstep > 0 && !IsFault(memaddrdesc) &&
!IsFault(memstatus)
                                            looplimit ArchMaxMOPSSETGSize DIV TAG_GRANULE do
    let tagaddr : bits(64) = toaddress + (tagstep - 1) * TAG_GRANULE;
    (memaddrdesc, memstatus) = AArch64_MemTagWrite(tagaddr, accdesc, tag);
    tagstep = tagstep - 1;
end;

if IsFault(memaddrdesc) || IsFault(memstatus) then
    tagstep = tagstep + 1;
end;

let tags_written : integer = (size DIV TAG_GRANULE) - tagstep;
return (tags_written, memaddrdesc, memstatus);

end;


## Library pseudocode for aarch64/functions/mops/MemSetZeroSizeCheck

// MemSetZeroSizeCheck // ===================== // Returns TRUE if the implementation option is checked on a set of size zero remaining.

func MemSetZeroSizeCheck() => boolean begin return ImpDefBool("Implementation option is checked with a setsize of 0"); end;


## Library pseudocode for aarch64/functions/mops/MemStageCpyZeroSizeCheck

// MemStageCpyZeroSizeCheck // ========================== // Returns TRUE if the implementation option is checked on a stage copy of size zero remaining.

func MemStageCpyZeroSizeCheck() => boolean begin return (ImpDefBool( "Implementation option is checked with a stage cpysize of 0")); end;


## Library pseudocode for aarch64/functions/mops/MemStageSetZeroSizeCheck

// MemStageSetZeroSizeCheck // ========================== // Returns TRUE if the implementation option is checked on a stage set of size zero remaining.

func MemStageSetZeroSizeCheck() => boolean begin return (ImpDefBool( "Implementation option is checked with a stage setsize of 0")); end;


## Library pseudocode for aarch64/functions/mops/MismatchedCpySetTargetEL

// MismatchedCpySetTargetEL // ========================== // Return the target exception level for an Exception_MemCpyMemSet.

func MismatchedCpySetTargetEL() => bits(2) begin var target_el : bits(2);

if UInt(PSTATE.EL) > UInt(EL1) then
    target_el = PSTATE.EL;
elsif PSTATE.EL == EL0 && EL2Enabled() && HCR_EL2().TGE == '1'
then
    target_el = EL2;
elsif (PSTATE.EL == EL1 && EL2Enabled() &&
    IsHCRXEL2Enabled() && HCRX_EL2().MCE2 == '1') then
    target_el = EL2;
else
    target_el = EL1;
end;

return target_el;

end;


## Library pseudocode for aarch64/functions/mops/MismatchedMemCpyException

// MismatchedMemCpyException // =========================== // Generates an exception for a CPY* instruction if the version // is inconsistent with the state of the call.

func MismatchedMemCpyException(memcpy : CPYParams, options : bits(4), formatoption : bits(2)) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0; let target_el : bits(2) = MismatchedCpySetTargetEL();

var except : ExceptionRecord =
ExceptionSyndrome(Exception_MemCpyMemSet);
except.syndrome.iss[24]    = '0';
except.syndrome.iss[23]    = '0';
except.syndrome.iss[22:19] = options;
except.syndrome.iss[18] = if memcpy.stage == MOPSStage_Epilogue then '1' else
'0';
except.syndrome.iss[17:16] = formatoption;
// exception.syndrome[15] is RES0.
except.syndrome.iss[14:10] = memcpy.d[4:0];
except.syndrome.iss[9:5]   = memcpy.s[4:0];
except.syndrome.iss[4:0]   = memcpy.n[4:0];

AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);

end;


## Library pseudocode for aarch64/functions/mops/MismatchedMemSetException

// MismatchedMemSetException // =========================== // Generates an exception for a SET* instruction if the version // is inconsistent with the state of the call.

func MismatchedMemSetException(memset : SETParams, options : bits(2), formatoption : bits(2)) begin let preferred_exception_return : bits(64) = ThisInstrAddr{}(); let vect_offset : integer = 0x0; let target_el : bits(2) = MismatchedCpySetTargetEL();

var except : ExceptionRecord =
ExceptionSyndrome(Exception_MemCpyMemSet);
except.syndrome.iss[24]    = '1';
except.syndrome.iss[23]    = if memset.is_setg then '1' else '0';
// exception.syndrome[22:21] is RES0.
except.syndrome.iss[20:19] = options;
except.syndrome.iss[18] = if memset.stage == MOPSStage_Epilogue then '1' else
'0';
except.syndrome.iss[17:16] = formatoption;
// exception.syndrome[15] is RES0.
except.syndrome.iss[14:10] = memset.d[4:0];
except.syndrome.iss[9:5]   = memset.s[4:0];
except.syndrome.iss[4:0]   = memset.n[4:0];

AArch64_TakeException(target_el, except, preferred_exception_return,
vect_offset);

end;


## Library pseudocode for aarch64/functions/mops/SETGOptionA

// SETGOptionA // ============= // Returns TRUE if the implementation uses Option A for the // SETG* instructions, and FALSE otherwise.

func SETGOptionA() => boolean begin return ImpDefBool("SETG* instructions use Option A"); end;


## Library pseudocode for aarch64/functions/mops/SETOptionA

// SETOptionA // ============ // Returns TRUE if the implementation uses Option A for the // SET* instructions, and FALSE otherwise.

func SETOptionA() => boolean begin return ImpDefBool("SET* instructions use Option A"); end;


## Library pseudocode for aarch64/functions/mops/SETParams

// SETParams // =========

type SETParams of record { stage : MOPSStage, implements_option_a : boolean, is_setg : boolean, setsize : integer, stagesetsize : integer, toaddress : bits(64), nzcv : bits(4), n : integer, d : integer, s : integer };


## Library pseudocode for aarch64/functions/mops/SETPostSizeChoice

// SETPostSizeChoice // =================== // Returns the size of the set that is performed by the SETE* or SETGE* instructions // for this implementation, given the parameters of the destination and size of the set.

impdef func SETPostSizeChoice(memset : SETParams) => integer begin return ARBITRARY : integer; end;


## Library pseudocode for aarch64/functions/mops/SETPreSizeChoice

// SETPreSizeChoice // ================== // Returns the size of the set that is performed by the SETP* or SETGP* instructions // for this implementation, given the parameters of the destination and size of the set.

impdef func SETPreSizeChoice(memset : SETParams) => integer begin return ARBITRARY : integer; end;


## Library pseudocode for aarch64/functions/mops/SETSizeChoice

// SETSizeChoice // =============== // Returns the size of the block this performed for an iteration of the set given // the parameters of the destination and size of the set. The size of the block // is an integer multiple of alignsize.

impdef func SETSizeChoice(memset : SETParams, alignsize : integer) => MOPSBlockSize begin return ARBITRARY : MOPSBlockSize; end;


## Library pseudocode for aarch64/functions/mops/UpdateCpyRegisters

// UpdateCpyRegisters // ==================== // Performs updates to the X[n], X[d], and X~~ registers, as appropriate, for the CPY* and CPYF* // instructions. When fault is TRUE, the values correspond to the first element not copied, // such that a return to the instruction will enable a resumption of the copy.

func UpdateCpyRegisters(memcpy : CPYParams, fault : boolean, copied : integer) begin if fault then if memcpy.stage == MOPSStage_Prologue then // Undo any formatting of the input parameters performed in the prologue. if memcpy.implements_option_a then if memcpy.forward then // cpysize is negative. let cpysize : integer = memcpy.cpysize + copied; X{64}(memcpy.n) = (0 - cpysize)[63:0]; X{64}(memcpy.d) = memcpy.toaddress + cpysize; X{64}(memcpy.s) = memcpy.fromaddress + cpysize;

            else
                X{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
            end;

        else
            if memcpy.forward then
                X{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
                X{64}(memcpy.d) = memcpy.toaddress   + copied;
                X{64}(memcpy.s) = memcpy.fromaddress + copied;

            else
                X{64}(memcpy.n)  = (memcpy.cpysize - copied)[63:0];
            end;
        end;

    else
        if memcpy.implements_option_a then
            if memcpy.forward then
                X{64}(memcpy.n) = (memcpy.cpysize + copied)[63:0];
            else
                X{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];
            end;

        else
            X{64}(memcpy.n) = (memcpy.cpysize - copied)[63:0];

            if memcpy.forward then
                X{64}(memcpy.d) = memcpy.toaddress   + copied;
                X{64}(memcpy.s) = memcpy.fromaddress + copied;
            else
------------------------------------------------------------------------------ Page 1 of 1. End of thread.