This forum was built by humans, for humans. AI was used exclusively for security auditing. The forum officially launched on November 24, 2026. Read more

romdump.net
romdump.net › Forum › Silicon & Architectures › Shared pseudocode: part 15 of 36

Writeup Shared pseudocode: part 15 of 36

started by admin

admin admin admingod mode Posts 116
Rep 505
Joined Nov 2026
2d ago OP #127

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

            enpacm_bit = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnPACM else '0';
        when EL1 =>
            enpacm_bit = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnPACM else '0';
        when EL0 =>
            if IsInHost() then
                enpacm_bit = if IsSCTLR2EL2Enabled() then SCTLR2_EL2().EnPACM0 else '0';
            else
                enpacm_bit = if IsSCTLR2EL1Enabled() then SCTLR2_EL1().EnPACM0 else '0';
            end;
    end;
    enabled = enpacm_bit == '1';
end;

return enabled;

end;


## Library pseudocode for aarch64/functions/pac/pac/IsTrivialPACMImplementation

// IsTrivialPACMImplementation // ============================= // Returns TRUE if the PE has a trivial implementation of PACM.

func IsTrivialPACMImplementation() => boolean begin return (IsFeatureImplemented(FEAT_PACIMP) && ImpDefBool("Trivial PSTATE.PACM implementation")); end;


## Library pseudocode for aarch64/functions/pac/pac/PtrHasUpperAndLowerAddRanges

// PtrHasUpperAndLowerAddRanges // ============================== // Returns TRUE if the pointer has upper and lower address ranges, FALSE otherwise.

func PtrHasUpperAndLowerAddRanges() => boolean begin let regime : Regime = TranslationRegime(PSTATE.EL);

return HasUnprivileged(regime);

end;


## Library pseudocode for aarch64/functions/pac/strip/Strip

// Strip // ======= // Strip() returns a 64-bit value containing A, but replacing the pointer authentication // code field bits with the extension of the address bits. This can apply to either // instructions or data, where, as the use of tagged pointers is distinct, it might be // handled differently.

readonly func Strip(A : bits(64), data : boolean) => bits(64) begin var original_ptr : bits(64); var extfield : bits(64); let tbi : boolean = EffectiveTBI(A, !data, PSTATE.EL) == '1'; let mtx : boolean = (IsFeatureImplemented(FEAT_MTE_NO_ADDRESS_TAGS) && EffectiveMTX(A, !data, PSTATE.EL) == '1'); let bottom_PAC_bit : AddressSize = CalculateBottomPACBit(A[55]); let EL3_using_lva3 : boolean = (IsFeatureImplemented(FEAT_LVA3) && TranslationRegime(PSTATE.EL) == Regime_EL3 && AArch64_IASize(TCR_EL3().T0SZ) > 52); if EL3_using_lva3 then extfield = Replicate{64}('0'); else extfield = Replicate{64}(A[55]); end;

if tbi then
    if (bottom_PAC_bit <= 55) then
        original_ptr = (A[63:56] ::
                        extfield[55:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0]);
    else
        original_ptr = A[63:56] :: A[55:0];
    end;
elsif mtx then
    if (bottom_PAC_bit <= 55) then
        original_ptr = (extfield[63:60] :: A[59:56] ::
                        extfield[55:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0]);
    else
        original_ptr = extfield[63:60] :: A[59:56] :: A[55:0];
    end;
else
    original_ptr =  extfield[63:bottom_PAC_bit] :: A[bottom_PAC_bit-1:0];
end;

return original_ptr;

end;


## Library pseudocode for aarch64/functions/pac/trappacuse/TrapPACUse

// TrapPACUse // ============ // Used for the trapping of the pointer authentication functions by higher exception // levels.

noreturn func TrapPACUse(target_el : bits(2)) begin assert HaveEL(target_el) && target_el != EL0 && UInt(target_el) >= UInt(PSTATE.EL);

let preferred_exception_return : bits(64) = ThisInstrAddr{}();var except : ExceptionRecord;let vect_offset : integer = 0;except = ExceptionSyndrome(Exception_PACTrap);AArch64_TakeException(target_el, except, preferred_exception_return, vect_offset);

end;


## Library pseudocode for aarch64/functions/predictionrestrict/AArch64\_RestrictPrediction

// AArch64_RestrictPrediction // ============================ // Clear all predictions in the context.

func AArch64_RestrictPrediction(val : bits(64), restriction : RestrictType) begin

var c : ExecutionCntxt;
let target_el : bits(2)    = val[25:24];

// If the target EL is not implemented or the instruction is executed at an // EL lower than the specified level, the instruction is treated as a NOP. if (target_el) || UInt(target_el) > UInt(PSTATE.EL) then ExecuteAsNOP(); end;

let ns : bit = val[26]; let nse : bit = val[27]; let ss : SecurityState = TargetSecurityState(ns, nse);

// If the combination of Security state and Exception level is not implemented, // the instruction is treated as a NOP. if ss == SS_Root && target_el != EL3 then ExecuteAsNOP(); end; if !IsFeatureImplemented(FEAT_RME) && target_el == EL3 && ss != SS_Secure then ExecuteAsNOP(); end;

c.security = ss; c.target_el = target_el;

if EL2Enabled() then if (PSTATE.EL == EL0 && ()) || PSTATE.EL == EL1 then c.is_vmid_valid = TRUE; c.all_vmid = FALSE; c.vmid = VMID();

elsif (target_el == EL0 &amp;&amp; (target_el)) || target_el == EL1 then    c.is_vmid_valid = TRUE;    c.all_vmid      = val[48] == '1';    c.vmid          = val[47:32];       // Only valid if  val[48] == '0';else    c.is_vmid_valid = FALSE;end;

else c.is_vmid_valid = FALSE; end;

if PSTATE.EL == EL0 then c.is_asid_valid = TRUE; c.all_asid = FALSE; c.asid = ASID();

elsif target_el == EL0 then c.is_asid_valid = TRUE; c.all_asid = val[16] == '1'; c.asid = val[15:0]; // Only valid if val[16] == '0';

else c.is_asid_valid = FALSE; end;

c.software_context = Zeros{64}; if IsFeatureImplemented(FEAT_CSV2_2) then case target_el of when EL3 => c.software_context = SCXTNUM_EL3(); when EL2 => c.software_context = SCXTNUM_EL2(); when EL1 => c.software_context = SCXTNUM_EL1(); when EL0 => c.software_context = SCXTNUM_EL0(); end; end;

c.restriction = restriction; RESTRICT_PREDICTIONS(c);

end;


## Library pseudocode for aarch64/functions/prefetch/Prefetch

// Prefetch // ==========

// Decode and execute the prefetch hint on ADDRESS specified by PRFOP

func Prefetch(address : bits(64), prfop : bits(5), supports_ir : boolean) begin var hint : PrefetchHint; var target : integer; var stream : boolean;

case prfop of
    when '00xxx'                   => hint = Prefetch_READ;      // PLD: prefetch for load
    when '01xxx'                   => hint = Prefetch_EXEC;      // PLI: preload instructions
    when '10xxx'                   => hint = Prefetch_WRITE;     // PST: prepare for store
    when '11000' where supports_ir => hint = Prefetch_IR;        // IR: intent to read
    otherwise                      => return;                    // unallocated hint
end;

// If <type> is IR, then <target> and <policy> are not specified and Rt[2:0] are '000'. if hint != Prefetch_IR then target = UInt(prfop[2:1]); // target cache level stream = (prfop[0] != '0'); // streaming (non-temporal) else target = ARBITRARY: integer; stream = ARBITRARY: boolean; end; Hint_Prefetch(address, hint, target, stream); return;

end;


## Library pseudocode for aarch64/functions/pstatefield/PSTATEField

// PSTATEField // =========== // MSR (immediate) instruction destinations.

type PSTATEField of enumeration { PSTATEField_DAIFSet, PSTATEField_DAIFClr, PSTATEField_PAN, // Armv8.1 PSTATEField_UAO, // Armv8.2 PSTATEField_DIT, // Armv8.4 PSTATEField_SSBS, PSTATEField_TCO, // Armv8.5 PSTATEField_SVCRSM, PSTATEField_SVCRZA, PSTATEField_SVCRSMZA, PSTATEField_ALLINT, PSTATEField_PM, PSTATEField_SP };


## Library pseudocode for aarch64/functions/ras/AArch64\_DelegatedSErrorTarget

// AArch64_DelegatedSErrorTarget // =============================== // Returns whether a delegated SError exception pended by SCR_EL3.VSE is masked, // and the target Exception level of the delegated SError exception.

func AArch64_DelegatedSErrorTarget() => (boolean, bits(2)) begin assert IsFeatureImplemented(FEAT_E3DSE); if Halted() || PSTATE.EL == EL3 then return (TRUE, ARBITRARY : bits(2)); end;

let effective_amo : bit = EffectiveHCR_AMO();
let effective_tge : bit = EffectiveTGE();

// The exception is masked by software. var masked : boolean; case PSTATE.EL of when EL2 => masked = ((effective_tge == '0' && effective_amo == '0') || PSTATE.A == '1'); when EL1, EL0 => masked = (effective_amo == '0' && PSTATE.A == '1'); otherwise => unreachable; end;

// The exception might be disabled debug in the Security state indicated by // SCR_EL3().[NS, NSE] by external debug. let intdis : boolean = ExternalDebugInterruptsDisabled(EL1);

var target_el : bits(2) = ARBITRARY : bits(2); if EL2Enabled() && effective_amo == '1' && !intdis && PSTATE.EL IN {EL0, EL1} then target_el = EL2; masked = FALSE;

elsif (EffectiveHCRX_EL2_TMEA() == '1' && !intdis && ((PSTATE.EL == EL1 && PSTATE.A == '1') || (PSTATE.EL == EL0 && masked && ()))) then target_el = EL2; masked = FALSE;

elsif PSTATE.EL == EL2 || IsInHost() then if !masked then target_el = EL2; end;

else assert (PSTATE.EL == EL1 || (PSTATE.EL == EL0 && ())); if !masked then target_el = EL1; end; end;

// External debug might disable the delegated exception for the target Exception level. if ExternalDebugInterruptsDisabled(target_el) then masked = TRUE; target_el = ARBITRARY : bits(2); end;

return (masked, target_el);

end;


## Library pseudocode for aarch64/functions/ras/AArch64\_ESBOperation

// AArch64_ESBOperation // ====================== // Perform the AArch64 ESB operation, either for ESB executed in AArch64 state, or for // ESB in AArch32 state when SError interrupts are routed to an Exception level using // AArch64

func AArch64_ESBOperation begin var target_el : bits(2); var masked : boolean;

(masked, target_el) = PhysicalSErrorTarget();

// Check for a masked Physical SError pending that can be synchronized // by an Error synchronization event. if masked && IsSynchronizablePhysicalSErrorPending() then // This function might be called for an interprocessing case, and INTdis is masking // the SError interrupt. if ELUsingAArch32(S1TranslationRegime()) then var syndrome : bits(32) = Zeros{}; syndrome[31] = '1'; // A syndrome[15:0] = AArch32_PhysicalSErrorSyndrome(); DISR() = syndrome; else let implicit_esb : boolean = FALSE; let is_esb : boolean = TRUE; var syndrome : bits(64) = Zeros{};

    syndrome[31]   = '1';       // A    syndrome[24:0] = AArch64_PhysicalSErrorSyndrome(is_esb, implicit_esb);    DISR_EL1()     = syndrome;end;ClearPendingPhysicalSError();   // Set ISR_EL1.A to 0

end;

return;

end;


## Library pseudocode for aarch64/functions/ras/AArch64\_EncodeAsyncErrorSyndrome

// AArch64_EncodeAsyncErrorSyndrome // ================================== // Return the encoding for specified ErrorState for an SError exception taken // to AArch64 state.

func AArch64_EncodeAsyncErrorSyndrome(errorstate : ErrorState) => bits(3) begin case errorstate of when ErrorState_UC => return '000'; when ErrorState_UEU => return '001'; when ErrorState_UEO => return '010'; when ErrorState_UER => return '011'; when ErrorState_CE => return '110'; otherwise => unreachable; end; end;


## Library pseudocode for aarch64/functions/ras/AArch64\_EncodeSyncErrorSyndrome

// AArch64_EncodeSyncErrorSyndrome // ================================= // Return the encoding for specified ErrorState for a synchronous Abort // exception taken to AArch64 state.

func AArch64_EncodeSyncErrorSyndrome(errorstate : ErrorState) => bits(2) begin case errorstate of when ErrorState_UC => return '10'; when ErrorState_UEU => return '10'; // UEU is reported as UC when ErrorState_UEO => return '11'; when ErrorState_UER => return '00'; otherwise => unreachable; end; end;


## Library pseudocode for aarch64/functions/ras/AArch64\_PhysicalSErrorSyndrome

// AArch64_PhysicalSErrorSyndrome // ================================ // Generate SError syndrome.

func AArch64_PhysicalSErrorSyndrome(is_esb : boolean, implicit_esb : boolean) => bits(25) begin var syndrome : bits(25) = Zeros{}; var target_el : bits(2); (-, target_el) = PhysicalSErrorTarget();

if ReportErrorAsUncategorized() then
    syndrome = Zeros{25};
elsif ReportErrorAsIMPDEF() then
    syndrome[24]   = '1';                                             // IDS
    syndrome[23:0] = ImpDefBits{24}("IMPDEF ErrorState");
else
    let fault : FaultRecord = GetPendingPhysicalSError();
    let errorstate : ErrorState = PEErrorState(fault);
    syndrome[24]    = '0';                                            // IDS
    if (!is_esb && IsFeatureImplemented(FEAT_PFAR) &&
          !(EL2Enabled() &&
          (HCR_EL2().VM == '1' || (IsFeatureImplemented(FEAT_HCRMAC) && HCR_EL2().DC == '1')) &&
          target_el == EL1)) then
        syndrome[14] = if IsPFARValid(fault) then '1' else '0';
    end;
    syndrome[13]    = if implicit_esb then '1' else '0';              // IESB
    syndrome[12:10] = AArch64_EncodeAsyncErrorSyndrome(errorstate);   // AET
    syndrome[9]     = fault.extflag;                                  // EA
    syndrome[5:0]   = '010001';                                       // DFSC
end;

return syndrome;

end;


## Library pseudocode for aarch64/functions/ras/AArch64\_dESBOperation

// AArch64_dESBOperation // ======================= // Perform the AArch64 ESB operation for a pending delegated SError exception.

func AArch64_dESBOperation begin assert (IsFeatureImplemented(FEAT_E3DSE) && (EL3) && PSTATE.EL != EL3); // When FEAT_E3DSE is implemented, SCR_EL3.DSE might inject a delegated SError exception. var dsei_pending, dsei_masked : boolean; dsei_pending = EffectiveSCR_EL3_EnDSE() == '1' && SCR_EL3().DSE == '1'; (dsei_masked, -) = AArch64_DelegatedSErrorTarget(); if dsei_pending && dsei_masked then var target : bits(64) = Zeros{}; target[31] = '1'; // A target[24:0] = VSESR_EL3()[24:0]; VDISR_EL3() = target; ClearPendingDelegatedSError(); end; return; end;


## Library pseudocode for aarch64/functions/ras/AArch64\_vESBOperation

// AArch64_vESBOperation // ======================= // Perform the AArch64 ESB operation for an unmasked pending virtual SError exception. // If FEAT_E3DSE is implemented and there is no unmasked virtual SError exception // pending, then AArch64_dESBOperation() is called to perform the AArch64 ESB operation // for a pending delegated SError exception.

func AArch64_vESBOperation begin assert PSTATE.EL IN {EL0, EL1} && EL2Enabled() && (EL2);

// If physical SError exceptions are routed to EL2, and TGE is not set, then a virtual
// SError exception might be pending.
let vsei_pending : boolean = (IsVirtualSErrorPending() && EffectiveTGE() == '0' &&
                              (EffectiveHCR_AMO() == '1' || EffectiveHCRX_EL2_TMEA() == '1'));
let vsei_masked : boolean = PSTATE.A == '1' || Halted() || ExternalDebugInterruptsDisabled(EL1);

// Check for a masked virtual SError pending if vsei_pending && vsei_masked then // This function might be called for the interprocessing case, and INTdis is masking // the virtual SError exception. if ELUsingAArch32(EL1) then var target : bits(32) = Zeros{}; target[31] = '1'; // A target[15:14] = VDFSR()[15:14]; // AET target[12] = VDFSR()[12]; // ExT target[9] = TTBCR().EAE; // LPAE if TTBCR().EAE == '1' then // Long-descriptor format target[5:0] = '010001'; // STATUS else // Short-descriptor format target[10,3:0] = '10110'; // FS end; VDISR() = target; else var target : bits(64) = Zeros{}; target[31] = '1'; // A target[24:0] = VSESR_EL2()[24:0]; VDISR_EL2() = target; end; ClearPendingVirtualSError(); elsif IsFeatureImplemented(FEAT_E3DSE) then AArch64_dESBOperation(); end;

return;

end;


## Library pseudocode for aarch64/functions/ras/CheckEnADERRApplies

// CheckEnADERRApplies // ===================== // Returns TRUE if SCTLR2_ELx().EnADERR applies to the given memory read access.

func CheckEnADERRApplies(accdesc : AccessDescriptor) => boolean begin var imp_specific_access : boolean = FALSE;

case accdesc.acctype of
    when AccessType_ASIMD  => imp_specific_access = TRUE;
    when AccessType_SVE    => imp_specific_access = TRUE;
    when AccessType_SME    => imp_specific_access = TRUE;
    when AccessType_GPR    =>
        imp_specific_access = FALSE;
        imp_specific_access = imp_specific_access || accdesc.atomicop;
        imp_specific_access = imp_specific_access || accdesc.rcw || accdesc.rcws;
        imp_specific_access = imp_specific_access || (accdesc.ls64 && accdesc.withstatus);
when AccessType_NV2    =&gt; imp_specific_access = TRUE;otherwise              =&gt; imp_specific_access = FALSE;

end;

if imp_specific_access then return ImpDefBool("EnADERR applies to given memory read AccessType"); end; return TRUE;

end;


## Library pseudocode for aarch64/functions/ras/CheckEnANERRApplies

// CheckEnANERRApplies // ===================== // Returns TRUE if SCTLR2_ELx().EnANERR applies to the given memory read access.

func CheckEnANERRApplies(accdesc : AccessDescriptor, desc : AddressDescriptor) => boolean begin var imp_specific_access : boolean = FALSE;

case accdesc.acctype of
    when AccessType_GPR =>
        imp_specific_access = FALSE;
        imp_specific_access = imp_specific_access || accdesc.atomicop;
        imp_specific_access = imp_specific_access || accdesc.rcw || accdesc.rcws;
        imp_specific_access = imp_specific_access || (accdesc.ls64 && accdesc.withstatus);
    when {AccessType_ASIMD, AccessType_SVE} =>
        imp_specific_access = IsFeatureImplemented(FEAT_SME) && PSTATE.SM == '1';
    when AccessType_SME =>
        imp_specific_access = TRUE;
    when AccessType_NV2 =>
        imp_specific_access = (desc.memattrs);
    otherwise =>
        imp_specific_access = FALSE;
end;

if imp_specific_access then return ImpDefBool("EnANERR applies to given memory read AccessType"); end; return TRUE;

end;


## Library pseudocode for aarch64/functions/ras/EffectiveHCRX\_EL2\_EnSDERR

// EffectiveHCRX_EL2_EnSDERR // =========================== // Return the Effective value of HCRX_EL2().EnSDERR

func EffectiveHCRX_EL2_EnSDERR() => bit begin if () then return '0'; end; if ELIsInHost(EL0) then return '0'; end;

 if (IsFeatureImplemented(FEAT_ANERR) && GetADERRErrorMode() == ErrSignalMode_TiedToPeer &&       HCRX_EL2().[EnSDERR, EnSNERR] == '10') then    return '0';end;return HCRX_EL2().EnSDERR;

end;


## Library pseudocode for aarch64/functions/ras/EffectiveHCRX\_EL2\_EnSNERR

// EffectiveHCRX_EL2_EnSNERR // =========================== // Return the Effective value of HCRX_EL2().EnSNERR

func EffectiveHCRX_EL2_EnSNERR() => bit begin if () then return '0'; end; if ELIsInHost(EL0) then return '0'; end;

if (IsFeatureImplemented(FEAT_ADERR) && GetADERRErrorMode() == ErrSignalMode_TiedToPeer &&      HCRX_EL2().[EnSDERR, EnSNERR] == '01') then    return '0';end;return HCRX_EL2().EnSNERR;

end;


## Library pseudocode for aarch64/functions/ras/ErrSignalMode

// ErrSignalMode // ============= // Implementation options for the ANERR/ADERR synchronous error behavior.

type ErrSignalMode of enumeration { ErrSignalMode_NotImplemented, ErrSignalMode_EnSelfOnly, // EnANERR-only / EnADERR-only ErrSignalMode_TiedToPeer, // ANERR tied to ADERR, or vice versa ErrSignalMode_EnxNERRIndependent };


## Library pseudocode for aarch64/functions/ras/FirstRecordOfNode

// FirstRecordOfNode // =================== // Return the first record in the node that contains the record n.

func FirstRecordOfNode(n : integer) => integer begin for q = n downto 0 do if IsFirstRecordOfNode(q) then return q; end; end; unreachable; end;


## Library pseudocode for aarch64/functions/ras/GetADERRErrorMode

// GetADERRErrorMode // =================== // Returns the ADERR implementation level

impdef func GetADERRErrorMode() => ErrSignalMode begin return ErrSignalMode_EnxNERRIndependent; end;


## Library pseudocode for aarch64/functions/ras/GetANERRErrorMode

// GetANERRErrorMode // =================== // Returns the ANERR implementation level

impdef func GetANERRErrorMode() => ErrSignalMode begin return ErrSignalMode_EnxNERRIndependent; end;


## Library pseudocode for aarch64/functions/ras/IsCommonFaultInjectionImplemented

// IsCommonFaultInjectionImplemented // =================================== // Check if the Common Fault Injection Model Extension is implemented by the node that owns this // error record.

impdef func IsCommonFaultInjectionImplemented(n : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/ras/IsCountableErrorsRecorded

// IsCountableErrorsRecorded // =========================== // Check whether Error record n records countable errors.

impdef func IsCountableErrorsRecorded(n : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/ras/IsDeviceMemoryReadErrorSynchronous

// IsDeviceMemoryReadErrorSynchronous // ==================================== // Returns TRUE when the Device memory read is synchronous in the current Exception level.

func IsDeviceMemoryReadErrorSynchronous(accdesc : AccessDescriptor, desc : AddressDescriptor) => boolean begin if !IsFeatureImplemented(FEAT_ADERR) || (accdesc) then return ImpDefBool("Device read error sync when EnADERR not implemented or does not apply"); end; case S1TranslationRegime(accdesc.el) of when EL3 => if ((!IsFeatureImplemented(FEAT_ANERR) || GetADERRErrorMode() != ErrSignalMode_TiedToPeer || SCTLR2_EL3().EnANERR == '0') && SCTLR2_EL3().EnADERR == '0') then return TRUE; end;

    when EL2 =>
        if () then
            if ImpDefBool("SCTLR2_ELx.EnADERR resets to 0 at highest ELx") then
                return TRUE;
            end;
        elsif ((!IsFeatureImplemented(FEAT_ANERR) ||
                GetADERRErrorMode() != ErrSignalMode_TiedToPeer ||
                SCTLR2_EL2().EnANERR == '0') && SCTLR2_EL2().EnADERR == '0') then
            return TRUE;
        end;
when EL1 =&gt;    if EffectiveHCRX_EL2_EnSDERR() == '1' then        return TRUE;    end;    if () then        if ImpDefBool("SCTLR2_ELx.EnADERR resets to 0 at highest ELx") then            return TRUE;        end;    elsif ((!IsFeatureImplemented(FEAT_ANERR) ||            GetADERRErrorMode() != ErrSignalMode_TiedToPeer ||            SCTLR2_EL1().EnANERR == '0') &amp;&amp;           SCTLR2_EL1().EnADERR == '0') then        return TRUE;    end;otherwise =&gt; unreachable;

end; return ImpDefBool("Device read error sync when the Effective value of EnADERR is 1");

end;


## Library pseudocode for aarch64/functions/ras/IsErrorAddressIncluded

// IsErrorAddressIncluded // ======================== // Check whether Error record n includes an address associated with an error.

impdef func IsErrorAddressIncluded(n : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/ras/IsErrorRecordImplemented

// IsErrorRecordImplemented // ========================== // Is the error record n implemented

readonly impdef func IsErrorRecordImplemented(n : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/ras/IsFirstRecordOfNode

// IsFirstRecordOfNode // ===================== // Check if the record q is the first error record in its node.

readonly impdef func IsFirstRecordOfNode(q : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/ras/IsNormalMemoryReadErrorSynchronous

// IsNormalMemoryReadErrorSynchronous // ==================================== // Returns TRUE when error signaled on a load from Normal memory is taken synchronously.

func IsNormalMemoryReadErrorSynchronous(accdesc : AccessDescriptor, desc : AddressDescriptor) => boolean begin if !IsFeatureImplemented(FEAT_ANERR) || (accdesc, desc) then return ImpDefBool("Normal read error sync when EnANERR not implemented or does not apply"); end; case S1TranslationRegime(accdesc.el) of when EL3 => if ((!IsFeatureImplemented(FEAT_ADERR) || GetANERRErrorMode() != ErrSignalMode_TiedToPeer || SCTLR2_EL3().EnADERR == '0') && SCTLR2_EL3().EnANERR == '0') then return TRUE; end;

    when EL2 =>
        if () then
            if ImpDefBool("SCTLR2_ELx.EnANERR resets to 0 at highest ELx") then
                return TRUE;
            end;
        elsif ((!IsFeatureImplemented(FEAT_ADERR) ||
                GetANERRErrorMode() != ErrSignalMode_TiedToPeer ||
                SCTLR2_EL2().EnADERR == '0') && SCTLR2_EL2().EnANERR == '0') then
            return TRUE;
        end;
when EL1 =&gt;    if EffectiveHCRX_EL2_EnSNERR() == '1' then        return TRUE;    end;    if () then        if ImpDefBool("SCTLR2_ELx.EnANERR resets to 0 at highest ELx") then            return TRUE;        end;    elsif ((!IsFeatureImplemented(FEAT_ADERR) ||            GetANERRErrorMode() != ErrSignalMode_TiedToPeer ||            SCTLR2_EL1().EnADERR == '0') &amp;&amp;           SCTLR2_EL1().EnANERR == '0') then        return TRUE;    end;otherwise =&gt; unreachable;

end; return ImpDefBool("Normal read error sync when the Effective value of EnANERR is 1");

end;


## Library pseudocode for aarch64/functions/ras/IsPFARValid

// IsPFARValid // ============= // Determine if faulting PA can be reported.

impdef func IsPFARValid(fault : FaultRecord) => boolean begin return (fault); end;


## Library pseudocode for aarch64/functions/ras/IsSPMUCounterImplemented

// IsSPMUCounterImplemented // ========================== // Does the System PMU s implement the counter n.

impdef func IsSPMUCounterImplemented(s : integer, n : integer) => boolean begin return TRUE; end;


## Library pseudocode for aarch64/functions/rcw

constant RCW64_PROTECTED_BIT : integer = 52; constant RCW128_PROTECTED_BIT : integer = 114;


## Library pseudocode for aarch64/functions/rcw/ProtectionEnabled

// ProtectionEnabled // =================== // Returns TRUE if the ProtectedBit is // enabled in the current Exception level.

func ProtectionEnabled(el : bits(2)) => boolean begin assert HaveEL(el); let regime : bits(2) = S1TranslationRegime(el); assert((regime)); if ((el)) then case regime of when EL1 => return IsTCR2EL1Enabled() && TCR2_EL1().PnCH == '1'; when EL2 => return IsTCR2EL2Enabled() && TCR2_EL2().PnCH == '1'; when EL3 => return TCR_EL3().PnCH == '1'; end; else return TRUE; end; return FALSE; end;


## Library pseudocode for aarch64/functions/rcw/RCWCheck

// RCWCheck // ========== // Returns nzcv based on : if the new value for RCW/RCWS instructions satisfy RCW and/or RCWS checks // Z is set to 1 if RCW checks fail // C is set to 0 if RCWS checks fail

func RCWCheck{N}(old : bits(N), new : bits(N), soft : boolean) => bits(4) begin assert N IN {64,128}; let protectedbit : integer = if N == 128 then RCW128_PROTECTED_BIT else RCW64_PROTECTED_BIT; var rcw_fail : boolean = FALSE; var rcws_fail : boolean = FALSE; var rcw_state_fail : boolean = FALSE; var rcws_state_fail : boolean = FALSE; var rcw_mask_fail : boolean = FALSE; var rcws_mask_fail : boolean = FALSE;

//Effective RCWMask calculation
var rcwmask : bits(N) = RCWMASK_EL1()[N-1:0];
if N == 64 then
    rcwmask[49:18] = Replicate{32}(rcwmask[17]);
    rcwmask[0] = '0';
else
    rcwmask[55:17] = Replicate{39}(rcwmask[16]);
    rcwmask[126:125,120:119,107:101,90:56,1:0] = Zeros{48};
end;

//Effective RCWSMask calculation var rcwsoftmask : bits(N) = RCWSMASK_EL1()[N-1:0]; if N == 64 then rcwsoftmask[49:18] = Replicate{32}(rcwsoftmask[17]); rcwsoftmask[0] = '0'; if(ProtectionEnabled(PSTATE.EL)) then rcwsoftmask[52] = '0'; end; else rcwsoftmask[55:17] = Replicate{39}(rcwsoftmask[16]); rcwsoftmask[126:125,120:119,107:101,90:56,1:0] = Zeros{48}; rcwsoftmask[114] = '0'; end;

//RCW Checks //State Check if (ProtectionEnabled(PSTATE.EL)) then if old[protectedbit] == '1' then rcw_state_fail = new[protectedbit,0] != old[protectedbit,0]; elsif old[protectedbit] == '0' then rcw_state_fail = new[protectedbit] != old[protectedbit]; end; end;

//Mask Check if (ProtectionEnabled(PSTATE.EL)) then if old[protectedbit,0] == '11' then rcw_mask_fail = !IsZero((new XOR old) AND NOT(rcwmask)); end; end;

//RCWS Checks if soft then //State Check if old[0] == '1' then rcws_state_fail = new[0] != old[0]; elsif ((PSTATE.EL) || (ProtectionEnabled(PSTATE.EL) && old[protectedbit] == '0')) then rcws_state_fail = new[0] != old[0] ; end; //Mask Check if old[0] == '1' then rcws_mask_fail = !IsZero((new XOR old) AND NOT(rcwsoftmask)); end; end;

rcw_fail = rcw_state_fail || rcw_mask_fail ; rcws_fail = rcws_state_fail || rcws_mask_fail;

let n : bit = '0'; let z : bit = if rcw_fail then '1' else '0'; let c : bit = if rcws_fail then '0' else '1'; let v : bit = '0'; return n::z::c::v;

end;


## Library pseudocode for aarch64/functions/reduceop/FPReduce

// FPReduce // ========== // Perform the floating-point operation 'op' on pairs of elements from the input vector, // reducing the vector to a scalar result.

func FPReduce{esize, N}(op : ReduceOp, input : bits(N), fpcr : FPCR_Type) => bits(esize) recurselimit 8 begin var hi : bits(esize); var lo : bits(esize); var result : bits(esize); let half : integer{} = N DIV 2;

if N == esize then
    return input[esize-1:0];
end;

hi = FPReduce{esize, (N - N DIV 2)}(op, input[N-1:half], fpcr); lo = FPReduce{esize, N DIV 2}(op, input[half-1:0], fpcr); case op of when ReduceOp_FMINNUM => result = FPMinNum{esize}(lo, hi, fpcr); when ReduceOp_FMAXNUM => result = FPMaxNum{esize}(lo, hi, fpcr); when ReduceOp_FMIN => result = FPMin{esize}(lo, hi, fpcr); when ReduceOp_FMAX => result = FPMax{esize}(lo, hi, fpcr); when ReduceOp_FADD => result = FPAdd{esize}(lo, hi, fpcr); end;

return result;

end;


## Library pseudocode for aarch64/functions/reduceop/IntReduce

// IntReduce // =========== // Perform the integer operation 'op' on pairs of elements from the input vector, // reducing the vector to a scalar result.

func IntReduce{esize, N}(op : ReduceOp, input : bits(N)) => bits(esize) recurselimit 8 begin var hi : bits(esize); var lo : bits(esize); var result : bits(esize); let half : integer{} = N DIV 2; if N == esize then return input[esize-1:0]; end;

hi = IntReduce{esize, (N - N DIV 2)}(op, input[N-1:half]);
lo = IntReduce{esize, N DIV 2}(op, input[half-1:0]);
case op of
    when ReduceOp_ADD =>
        result = lo + hi;
end;

return result;

end;


## Library pseudocode for aarch64/functions/reduceop/ReduceOp

// ReduceOp // ======== // Vector reduce instruction types.

type ReduceOp of enumeration {ReduceOp_FMINNUM, ReduceOp_FMAXNUM, ReduceOp_FMIN, ReduceOp_FMAX, ReduceOp_FADD, ReduceOp_ADD};


## Library pseudocode for aarch64/functions/registers/AArch64\_MaybeZeroRegisterUppers

// AArch64_MaybeZeroRegisterUppers // ================================= // On taking an exception to AArch64 from AArch32, it is CONSTRAINED UNPREDICTABLE whether the top // 32 bits of registers visible at any lower Exception level using AArch32 are set to zero.

func AArch64_MaybeZeroRegisterUppers begin assert UsingAArch32(); // Always called from AArch32 state before entering AArch64 state

var first : integer;
var last : integer;
var include_R15 : boolean;
if PSTATE.EL == EL0 && (EL1) then
    first = 0;  last = 14;  include_R15 = FALSE;
elsif PSTATE.EL IN {EL0, EL1} && EL2Enabled() && (EL2) then
    first = 0;  last = 30;  include_R15 = FALSE;
else
    first = 0;  last = 30;  include_R15 = TRUE;
end;

for n = first to last do if (n != 15 || include_R15) && ConstrainUnpredictableBool(Unpredictable_ZEROUPPER) then _R[[n]][63:32] = Zeros{32}; end; end;

return;

end;


## Library pseudocode for aarch64/functions/registers/AArch64\_ResetGeneralRegisters

// AArch64_ResetGeneralRegisters // ===============================

func AArch64_ResetGeneralRegisters begin

for i = 0 to 30 do    X{64}(i) = ARBITRARY : bits(64);end;

end;


## Library pseudocode for aarch64/functions/registers/AArch64\_ResetSIMDFPRegisters

// AArch64_ResetSIMDFPRegisters // ==============================

func AArch64_ResetSIMDFPRegisters begin

for i = 0 to 31 do    V{128}(i) = ARBITRARY : bits(128);end;

end;


## Library pseudocode for aarch64/functions/registers/AArch64\_ResetSpecialRegisters

// AArch64_ResetSpecialRegisters // ===============================

func AArch64_ResetSpecialRegisters begin

// AArch64 special registers
SP_EL0()       = ARBITRARY : bits(64);
SP_EL1()       = ARBITRARY : bits(64);

SPSR_EL1() = ARBITRARY : bits(64); ELR_EL1() = ARBITRARY : bits(64); if HaveEL(EL2) then SP_EL2() = ARBITRARY : bits(64); SPSR_EL2() = ARBITRARY : bits(64); ELR_EL2() = ARBITRARY : bits(64); end;

// AArch32 special registers that are not architecturally mapped to AArch64 registers if HaveAArch32EL(EL1) then SPSR_fiq()[31:0] = ARBITRARY : bits(32); SPSR_irq()[31:0] = ARBITRARY : bits(32); SPSR_abt()[31:0] = ARBITRARY : bits(32); SPSR_und()[31:0] = ARBITRARY : bits(32); end;

// External debug special registers DLR_EL0() = ARBITRARY : bits(64); DSPSR_EL0() = ARBITRARY : bits(64);

return;

end;


## Library pseudocode for aarch64/functions/registers/AArch64\_ResetSystemRegisters

// AArch64_ResetSystemRegisters // ==============================

impdef func AArch64_ResetSystemRegisters(cold_reset : boolean) begin return; end;


## Library pseudocode for aarch64/functions/registers/PC64

// PC64 - getter // ============= // Read 64-bit program counter.

readonly func PC64() => bits(64) begin return _PC; end;


## Library pseudocode for aarch64/functions/registers/SP

// SP - accessor // =============

accessor SP{width}() <=> value : bits(width) begin // Write a 32-bit or 64-bit value to the current stack pointer. setter assert width IN {64, 32}; if PSTATE.SP == '0' then SP_EL0() = ZeroExtend{64}(value); else case PSTATE.EL of when EL0 => SP_EL0() = ZeroExtend{64}(value); when EL1 => SP_EL1() = ZeroExtend{64}(value); when EL2 => SP_EL2() = ZeroExtend{64}(value); when EL3 => SP_EL3() = ZeroExtend{64}(value); end; end; end;

// Read the least-significant 32 or 64 bits from the current stack pointer.getter    assert width IN {64, 32};    if PSTATE.SP == '0' then        return SP_EL0()[width-1:0];    else        case PSTATE.EL of            when EL0 =>  return SP_EL0()[width-1:0];            when EL1 =>  return SP_EL1()[width-1:0];            when EL2 =>  return SP_EL2()[width-1:0];            when EL3 =>  return SP_EL3()[width-1:0];        end;    end;end;

end;


## Library pseudocode for aarch64/functions/registers/X

// X - accessor // ============

accessor X{width}(n : integer) <=> value : bits(width) begin // Write a 32-bit or 64-bit value to a general-purpose register. setter assert n >= 0 && n <= 31; assert width IN {32,64}; if n != 31 then _R[[n]] = ZeroExtend{64}(value); end; return; end;

// Read the least-significant 8, 16, 32, or 64 bits from a general-purpose register.readonly getter    assert n >= 0 && n <= 31;    let rw : integer{} = width as integer{8, 16, 32, 64};    if n != 31 then        return _R[[n]][rw-1:0];    else        return Zeros{rw};    end;end;

end;

// X - accessor // ============

accessor X{width}(lr : integer, hr : integer) <=> value : bits(width) begin // Write a 128-bit value to two general-purpose registers. setter assert width == 128; let half : integer{} = width DIV 2; X{half}(lr) = value[0+:half]; X{half}(hr) = value[half+:half]; return; end;

// Read 128 bits from two separate general-purpose registers.readonly getter    assert width == 128;    let half : integer{} = width DIV 2;    return X{half}(hr) :: X{half}(lr);end;

end;


## Library pseudocode for aarch64/functions/shiftreg/DecodeShift

// DecodeShift // ============= // Decode shift encodings

func DecodeShift(op : bits(2)) => ShiftType begin case op of when '00' => return ShiftType_LSL; when '01' => return ShiftType_LSR; when '10' => return ShiftType_ASR; when '11' => return ShiftType_ROR; end; end;


## Library pseudocode for aarch64/functions/shiftreg/ShiftReg

// ShiftReg // ========== // Perform shift of a register operand

func ShiftReg{N}(reg : integer, shiftype : ShiftType, amount : integer) => bits(N) begin var result : bits(N) = X{}(reg); case shiftype of when ShiftType_LSL => result = LSL(result, amount); when ShiftType_LSR => result = LSR(result, amount); when ShiftType_ASR => result = ASR(result, amount); when ShiftType_ROR => result = ROR(result, amount); end; return result; end;


## Library pseudocode for aarch64/functions/shiftreg/ShiftType

// ShiftType // ========= // AArch64 register shifts.

type ShiftType of enumeration {ShiftType_LSL, ShiftType_LSR, ShiftType_ASR, ShiftType_ROR};


## Library pseudocode for aarch64/functions/sme/CounterToPredicate

// CounterToPredicate // ====================

func CounterToPredicate{width}(pred : bits(16)) => bits(width) begin var count : integer; var esize : ESize; var elements : integer; let VL : VecLen = CurrentVL(); let PL : PredLen = VL DIV 8; let maxbit : integer{} = FloorLog2(PL * 4) as integer{0..14}; var result : bits(PL*4); let invert : boolean = pred[15] == '1';

assert width == PL || width == PL*2 || width == PL*3 || width == PL*4;

case pred[3:0] of when '0000' => return Zeros{width}; when 'xxx1' => count = UInt(pred[maxbit:1]); esize = 8; when 'xx10' => count = UInt(pred[maxbit:2]); esize = 16; when 'x100' => count = UInt(pred[maxbit:3]); esize = 32; when '1000' => count = UInt(pred[maxbit:4]); esize = 64; end;

elements = (VL * 4) DIV esize; result = Zeros{PL4}; let psize : integer{} = esize DIV 8; for e = 0 to elements-1 do var pbit : bit = if e < count then '1' else '0'; if invert then pbit = NOT(pbit); end; result[e:psize] = ZeroExtend{psize}(pbit); end;

return result[width-1:0];

end;


## Library pseudocode for aarch64/functions/sme/EncodePredCount

// EncodePredCount // =================

func EncodePredCount{width}(esize : ESize, elements : integer, count_in : integer, invert_in : boolean) => bits(width) begin var count : integer = count_in; var invert : boolean = invert_in; let PL : PredLen = CurrentVL() DIV 8; assert width == PL; assert count >=0 && count <= elements; var pred : bits(16);

if count == 0 then
    return Zeros{width};
end;

if invert then count = elements - count; elsif count == elements then count = 0; invert = TRUE; end;

let inv : bit = (if invert then '1' else '0'); case esize of when 8 => pred = inv :: count[13:0] :: '1'; when 16 => pred = inv :: count[12:0] :: '10'; when 32 => pred = inv :: count[11:0] :: '100'; when 64 => pred = inv :: count[10:0] :: '1000'; end;

return ZeroExtend{width}(pred);

end;


## Library pseudocode for aarch64/functions/sme/Lookup

// Lookup Table // ============

var _ZT0 : bits(ZT0_LEN);


## Library pseudocode for aarch64/functions/sme/PredCountTest

// PredCountTest // ===============

func PredCountTest(elements : integer, count : integer, invert : boolean) => bits(4) begin var n, z, c, v : bit; z = (if count == 0 then '1' else '0'); // none active if !invert then n = (if count != 0 then '1' else '0'); // first active c = (if count == elements then '0' else '1'); // NOT last active else n = (if count == elements then '1' else '0'); // first active c = (if count != 0 then '0' else '1'); // NOT last active end; v = '0';

return n::z::c::v;

end;


## Library pseudocode for aarch64/functions/sme/System

// System Registers // ================

var _ZA : array [[256]] of bits(MAX_VL);


## Library pseudocode for aarch64/functions/sme/ZAhslice

// ZAhslice - accessor // ===================

accessor ZAhslice{width}(tile : integer, esize : ESize, slice : integer) <=> value : bits(width) begin getter let tiles : integer = esize DIV 8; assert tile >= 0 && tile < tiles; let slices : integer = CurrentSVL() DIV esize; assert slice >= 0 && slice < slices;

    return ZAvector{width}(tile + slice * tiles);
end;
setter
    let tiles : integer = esize DIV 8;
    assert tile >= 0 && tile < tiles;
    let slices : integer = CurrentSVL() DIV esize;
    assert slice >= 0 && slice < slices;
ZAvector{width}(tile + slice * tiles) = value;

end;

end;


## Library pseudocode for aarch64/functions/sme/ZAslice

// ZAslice - accessor // ==================

accessor ZAslice{width}(tile : integer, esize : ESize, vertical : boolean, slice : integer) <=> value : bits(width) begin getter var result : bits(width);

    if vertical then
        result = ZAvslice{width}(tile, esize, slice);
    else
        result = ZAhslice{width}(tile, esize, slice);
    end;
return result;

end; setter if vertical then ZAvslice{width}(tile, esize, slice) = value; else ZAhslice{width}(tile, esize, slice) = value; end; end;

end;


## Library pseudocode for aarch64/functions/sme/ZAtile

// ZAtile - accessor // =================

accessor ZAtile{width}(tile : integer, esize : ESize) <=> value : bits(width) begin getter let SVL : VecLen = CurrentSVL(); let slices : integer = SVL DIV esize; assert width == SVL * slices; var result : bits(width);

    for slice = 0 to slices-1 do
        result[slice*:SVL] = ZAhslice{SVL}(tile, esize, slice);
    end;
return result;

end; setter let SVL : VecLen = CurrentSVL(); let slices : integer = SVL DIV esize; assert width == SVL * slices;

for slice = 0 to slices-1 do    ZAhslice{SVL}(tile, esize, slice) = value[slice*:SVL];end;

end;

end;


## Library pseudocode for aarch64/functions/sme/ZAvector

// ZAvector - accessor // ===================

accessor ZAvector{width}(index : integer) <=> value : bits(width) begin getter assert width == CurrentSVL(); assert index >= 0 && index < (width DIV 8);

    return _ZA[[index]][width-1:0];
end;

setter assert width == CurrentSVL(); assert index >= 0 && index < (width DIV 8);

if ConstrainUnpredictableBool(Unpredictable_SMEZEROUPPER) then    _ZA[[index]] = ZeroExtend{MAX_VL}(value);else    _ZA[[index]][width-1:0] = value;end;

end;

end;


## Library pseudocode for aarch64/functions/sme/ZAvslice

// ZAvslice - accessor // ===================

accessor ZAvslice{width}(tile : integer, esize : ESize, slice : integer) <=> value : bits(width) begin getter let slices : integer = CurrentSVL() DIV esize; var result : bits(width);

    for s = 0 to slices-1 do
        let hslice : bits(width) = ZAhslice{}(tile, esize, s);
        result[s*:esize] = hslice[slice*:esize];
    end;
return result;

end;

setter let slices : integer = CurrentSVL() DIV esize;

for s = 0 to slices-1 do    var hslice : bits(width) = ZAhslice{}(tile, esize, s);    hslice[slice*:esize] = value[s*:esize];    ZAhslice{width}(tile, esize, s) = hslice;end;

end;

end;


## Library pseudocode for aarch64/functions/sme/ZT0

// ZT0 - accessor // ==============

accessor ZT0{width}() <=> value : bits(width) begin getter assert width == ZT0_LEN; return _ZT0[width-1:0]; end; setter assert width == ZT0_LEN; _ZT0[width-1:0] = value; end; end;


## Library pseudocode for aarch64/functions/sve/AArch32\_IsFPEnabled

// AArch32_IsFPEnabled // ===================== // Returns TRUE if access to the SIMD&FP instructions or System registers are // enabled at the target exception level in AArch32 state and FALSE otherwise.

func AArch32_IsFPEnabled(el : bits(2)) => boolean begin if el == EL0 && (EL1) then return AArch64_IsFPEnabled(el); end;

if HaveEL(EL3) && ELUsingAArch32(EL3) && CurrentSecurityState() == SS_NonSecure then
    // Check if access disabled in NSACR
    if NSACR().cp10 == '0' then return FALSE; end;
end;

if el IN {EL0, EL1} then // Check if access disabled in CPACR var disabled : boolean; case CPACR().cp10 of when '00' => disabled = TRUE; when '01' => disabled = el == EL0; when '10' => disabled = ConstrainUnpredictableBool(Unpredictable_RESCPACR); when '11' => disabled = FALSE; end; if disabled then return FALSE; end; end;

if el IN {EL0, EL1, EL2} && EL2Enabled() then if (EL2) then return AArch64_IsFPEnabled(EL2); end; if HCPTR().TCP10 == '1' then return FALSE; end; end;

if HaveEL(EL3) && (EL3) then // Check if access disabled in CPTR_EL3 if CPTR_EL3().TFP == '1' then return FALSE; end; end;

return TRUE;

end;


## Library pseudocode for aarch64/functions/sve/AArch64\_IsFPEnabled

// AArch64_IsFPEnabled // ===================== // Returns TRUE if access to the SIMD&FP instructions or System registers are // enabled at the target exception level in AArch64 state and FALSE otherwise.

func AArch64_IsFPEnabled(el : bits(2)) => boolean begin // Check if access disabled in CPACR_EL1 if el IN {EL0, EL1} && () then // Check SIMD&FP at EL0/EL1 var disabled : boolean; case CPACR_EL1().FPEN of when 'x0' => disabled = TRUE; when '01' => disabled = el == EL0; when '11' => disabled = FALSE; end; if disabled then return FALSE; end; end;

// Check if access disabled in CPTR_EL2
if el IN {EL0, EL1, EL2} && EL2Enabled() then
    if ELIsInHost(EL2) then
        var disabled : boolean;
        case CPTR_EL2().FPEN of
            when 'x0' => disabled = TRUE;
            when '01' => disabled = el == EL0 && HCR_EL2().TGE == '1';
            when '11' => disabled = FALSE;
        end;
        if disabled then return FALSE; end;
    else
        if CPTR_EL2().TFP == '1' then return FALSE; end;
    end;
end;

// Check if access disabled in CPTR_EL3 if HaveEL(EL3) then if CPTR_EL3().TFP == '1' then return FALSE; end; end;

return TRUE;

end;


## Library pseudocode for aarch64/functions/sve/ActivePredicateElement

// ActivePredicateElement // ======================== // Returns TRUE if the predicate bit is 1 and FALSE otherwise

func ActivePredicateElement{N}(pred : bits(N), e : integer, esize : integer) => boolean begin assert esize IN {8, 16, 32, 64, 128}; let n : integer = e * (esize DIV 8); assert n >= 0 && n < N; return pred[n] == '1'; end;


## Library pseudocode for aarch64/functions/sve/AllElementsActive

// AllElementsActive // =================== // Return TRUE if all the elements are active in the mask. Otherwise, // return FALSE.

func AllElementsActive{N}(mask : bits(N), esize : integer) => boolean begin let elements : integer = N DIV (esize DIV 8); var active : integer = 0; for e = 0 to elements-1 do if ActivePredicateElement{N}(mask, e, esize) then active = active + 1; end; end; return active == elements; end;


## Library pseudocode for aarch64/functions/sve/AnyActiveElement

// AnyActiveElement // ================== // Return TRUE if there is at least one active element in mask. Otherwise, // return FALSE.

func AnyActiveElement{N}(mask : bits(N), esize : integer) => boolean begin return LastActiveElement{N}(mask, esize) >= 0; end;


## Library pseudocode for aarch64/functions/sve/BitDeposit

// BitDeposit // ============ // Deposit the least significant bits from DATA into result positions // selected by nonzero bits in MASK, setting other result bits to zero.

func BitDeposit{N}(data : bits(N), mask : bits(N)) => bits(N) begin var res : bits(N) = Zeros{}; var db : integer = 0; for rb = 0 to N-1 do if mask[rb] == '1' then res[rb] = data[db]; db = db + 1; end; end; return res; end;


## Library pseudocode for aarch64/functions/sve/BitExtract

// BitExtract // ============ // Extract and pack DATA bits selected by the nonzero bits in MASK into // the least significant result bits, setting other result bits to zero.

func BitExtract{N}(data : bits(N), mask : bits(N)) => bits(N) begin var res : bits(N) = Zeros{}; var rb : integer = 0; for db = 0 to N-1 do if mask[db] == '1' then res[rb] = data[db]; rb = rb + 1; end; end; return res; end;


## Library pseudocode for aarch64/functions/sve/BitGroup

// BitGroup // ========== // Extract and pack DATA bits selected by the nonzero bits in MASK into // the least significant result bits, and pack unselected bits into the // most significant result bits.

func BitGroup{N}(data : bits(N), mask : bits(N)) => bits(N) begin var res : bits(N); var rb : integer = 0;

// compress masked bits to rightfor db = 0 to N-1 do    if mask[db] == '1' then        res[rb] = data[db];        rb      = rb + 1;    end;end;// compress unmasked bits to leftfor db = 0 to N-1 do    if mask[db] == '0' then        res[rb] = data[db];        rb      = rb + 1;    end;end;return res;

end;


## Library pseudocode for aarch64/functions/sve/CheckNonStreamingSVEEnabled

// CheckNonStreamingSVEEnabled // ============================= // Checks for traps on SVE instructions that are not legal when executed in Streaming mode.

func CheckNonStreamingSVEEnabled begin CheckSVEEnabled();

if IsFeatureImplemented(FEAT_SME) && PSTATE.SM == '1' && () then    SMEAccessTrap(SMEExceptionType_Streaming, PSTATE.EL);end;

end;

Log in to reply.