15.2 SVE, SVE2 and SME
For firmware, what SVE and SME change most is the size and shape of the register state, and the number of controls that must be set before any of it is usable. This section gives the state and the controls precisely. The instruction-set content is covered only as far as it affects state. EL3 programming is in 15.3.
SVE state
| Register | Count | Size | Notes |
|---|---|---|---|
Z0–Z31 | 32 | VL bits | Vn is the low 128 bits of Zn |
P0–P15 | 16 | VL/8 bits | One bit per byte of a Z register |
FFR | 1 | VL/8 bits | First-fault register, written by first-fault and non-fault loads (LDFF1*, LDNF1*) |
The vector length (VL) is chosen by the implementation. The current ARM ARM permits any power of two from 128 to 2048 bits, and an implementation may support only a subset of those lengths. Early issues allowed any multiple of 128. Arm later restricted the rule, so old documents and old asserts (TF-A still checks SVE_VECTOR_LEN % 128) reflect the looser wording.
At the maximum VL, the non-streaming SVE context is 32 × 256 + 17 × 32 = 8736 bytes, against just over 512 bytes for FP/SIMD alone.
Vector-length agnosticism. Code does not hard-code VL. It reads VL with RDVL/CNTB/CNTW and drives loops with predicates, so the same binary runs on any VL:
// x0 = dst, x1 = src, x2 = n (number of 32-bit elements)
mov x3, #0
whilelo p0.s, x3, x2 // p0 = lanes with x3+i < n
1: ld1w {z0.s}, p0/z, [x1, x3, lsl #2]
add z0.s, z0.s, #1
st1w {z0.s}, p0, [x0, x3, lsl #2]
incw x3 // x3 += number of 32-bit lanes in VL
whilelo p0.s, x3, x2
b.first 1b // loop while the first lane is active
The tail is handled by the predicate, so the loop needs no scalar epilogue. Software that saves state must also be VL-agnostic: a context buffer sized at build time for 128-bit vectors is overrun on a 256-bit part.
Controlling VL: ZCR_ELx. ZCR_EL1, ZCR_EL2 and ZCR_EL3 each have a LEN field in bits [3:0] that requests VL = (LEN+1) × 128 bits. The effective VL at an Exception level is limited by the ZCR of that level and of every higher implemented and enabled level. The PE then uses the largest supported length that does not exceed the result. So ZCR_EL3 caps everything, and EL2 caps its guests. When the effective VL shrinks and later grows again, the ARM ARM does not guarantee that the bits that became inaccessible were preserved (see the ZCR_EL1 description). This matters to any code that changes LEN while live state is held at the old length.
Discovery and versions. ID_AA64PFR0_EL1.SVE (bits [35:32]) reports SVE. ID_AA64ZFR0_EL1.SVEver (bits [3:0]) distinguishes SVE (0b0000), SVE2 (0b0001), SVE2.1 (0b0010) and SVE2.2 (0b0011). The rest of ID_AA64ZFR0_EL1 reports the optional instruction groups. FEAT_SVE is permitted from v8.2. Current DDI0487 issues list FEAT_SVE2 as OPTIONAL from v9.0, even though toolchains treat it as part of -march=armv9-a; only SVEver is authoritative (1.2).
Traps. SVE instructions, and accesses to ZCR_ELx, are controlled by CPACR_EL1.ZEN [17:16] (same encoding as FPEN), CPTR_EL2.TZ bit 8 (or ZEN when E2H=1), and CPTR_EL3.EZ bit 8. EZ is an enable, so 0 traps. An SVE access trap is reported with EC 0x19. SVE instructions are also subject to the FP controls. The ARM ARM pseudocode for the SVE enable check tests the controls from the lowest Exception level upwards, and at each level tests the SVE control before the FP one. A guest with both traps set at EL1 therefore takes EC 0x19, not 0x07.
SME: Streaming SVE mode and ZA
SME adds two independent pieces of state, each with its own enable in PSTATE:
PSTATE.SM, Streaming SVE mode. SVE instructions execute at the streaming vector length (SVL), set bySMCR_ELx.LEN, which may differ from the non-streaming VL. The Z and P registers (and FFR, which is accessible only when FA64 is enabled) take the SVL in this mode. Streaming mode is designed for a separate, wide matrix unit that may be shared between cores. Many instructions that suit a latency-oriented core are therefore illegal in streaming mode: most Advanced SIMD vector instructions, SVE gather/scatter, and the first-fault loads that useFFR. Executing one is reported with EC0x1D,ISS.SMTC=1, unless FEAT_SME_FA64 is implemented (ID_AA64SMFR0_EL1.FA64, bit 63) and enabled bySMCR_ELx.FA64.PSTATE.ZA, the ZA array. ZA is a two-dimensional SVL/8 × SVL/8-byte array, accessed as tiles (ZA0.S–ZA3.S, and so on) or as horizontal and vertical slices. It is the accumulator for outer-product instructions such asFMOPA. At SVL = 512 bits it is 4 KiB; at SVL = 2048 bits it is 64 KiB.
Both live in SVCR (SM is bit 0, ZA is bit 1). They are changed by MSR SVCRSM, #imm, MSR SVCRZA, #imm and MSR SVCRSMZA, #imm, whose preferred aliases are SMSTART/SMSTOP with an optional SM or ZA operand. The architectural side effects are the part firmware must know:
| Event | Effect |
|---|---|
PSTATE.SM changes (either direction) | All implemented bits of Z0–Z31, P0–P15 and FFR are set to zero. FPMR is set to zero. FPSR is set to 0x0800_009F (all cumulative flags set). ZA and ZT0 are not affected. |
PSTATE.ZA 0 → 1 | ZA (and ZT0) are set to zero |
PSTATE.ZA 1 → 0 | ZA contents are lost |
| Exception entry or return | No change. SM and ZA are not in SPSR, so a handler runs in whatever mode the interrupted code was in. |
The last row has consequences at every EL. An EL1 or EL3 handler entered from streaming code that executes an Advanced SIMD instruction, for example in a context-save routine, takes an illegal-in-streaming-mode trap. A save routine running in streaming mode sees Z and P at the SVL, not the VL. Any code that saves vector state must read SVCR first and act on it, or execute SMSTOP SM, which destroys the Z state unless it has been saved first.
SME controls. SMCR_EL1/SMCR_EL2/SMCR_EL3 contain LEN [3:0] (SVL request, capped by higher ELs as for ZCR), FA64 (bit 31) and EZT0 (bit 30, SME2). Traps are CPACR_EL1.SMEN [25:24], CPTR_EL2.TSM bit 12 (or SMEN when E2H=1), and CPTR_EL3.ESM bit 12 (an enable). SVE instructions executed in streaming mode are controlled by these SME controls, not by ZEN/TZ/EZ. The FP controls still apply. The trap codes in ESR_ELx.ISS.SMTC for EC 0x1D are:
| SMTC | Cause |
|---|---|
| 0 | Trapped by SMEN/TSM/ESM |
| 1 | Instruction illegal in Streaming SVE mode |
| 2 | Instruction requires PSTATE.SM=1 and it is 0 |
| 3 | Instruction accesses ZA and PSTATE.ZA=0 |
| 4 | Instruction accesses ZT0 and the applicable SMCR_ELx.EZT0=0 |
Discovery is ID_AA64PFR1_EL1.SME (bits [27:24]: 0b0001 SME, 0b0010 SME2) and ID_AA64SMFR0_EL1, whose SMEver field (bits [59:56]) distinguishes SME, SME2, SME2.1 and SME2.2 and whose other fields list the supported data types. Both FEAT_SME and FEAT_SME2 are optional from v9.2 (see DDI0487 A2).
TPIDR2_EL0 and the lazy ZA save ABI
ZA can be tens of kilobytes, so the procedure-call standard avoids saving it on every call. TPIDR2_EL0 is an EL0-accessible register reserved for this protocol. In the AAPCS64 SME support, ZA is in one of three states:
- off:
PSTATE.ZA=0; - active:
PSTATE.ZA=1andTPIDR2_EL0is null; the current function owns the contents; - dormant:
PSTATE.ZA=1andTPIDR2_EL0points to a 16-byte TPIDR2 block (za_save_bufferpointer, a 16-bitnum_za_save_slices, reserved bytes). The contents belong to a caller and have not yet been saved.
A caller with live ZA that calls a function which does not share ZA sets up the block and makes ZA dormant. A callee that wants ZA checks TPIDR2_EL0. If it is non-null, the callee calls __arm_tpidr2_save, which stores ZA into the caller’s buffer, and then sets TPIDR2_EL0 to null itself (the support routine does not clear it). The callee then owns ZA. After the call, the caller turns ZA back on if necessary and checks TPIDR2_EL0. If it is null, a save happened, and the caller calls __arm_tpidr2_restore. If the callee never used ZA, no save or restore happens at all.
For system software TPIDR2_EL0 is per-thread state, like TPIDR_EL0. EL0 access is enabled by SCTLR_EL1.EnTP2 (bit 60), or SCTLR_EL2.EnTP2 in the EL2&0 regime, and lower-EL access by SCR_EL3.EnTP2 (bit 41). When these are clear, accesses trap with EC 0x18. An OS must save and restore TPIDR2_EL0 on context switch, and it has to define what signal handlers see. Linux saves the SME state in the signal frame and enters the handler with Streaming SVE mode and ZA disabled. Its treatment of TPIDR2_EL0 at signal entry has changed between kernel versions, so check Documentation/arch/arm64/sme.rst for the version you run.
SME2, ZT0 and SME without SVE
SME2 adds multi-vector instructions that operate on groups of two or four consecutive Z registers. ZA can also be addressed as groups of vectors, which allows multi-vector accumulation into ZA without outer products. SME2 adds predicate-as-counter encodings (PN8–PN15, a compact way to express “the first n lanes” across several vectors) and one new register, ZT0: 512 bits, used as a lookup table by LUTI2/LUTI4. ZT0 follows PSTATE.ZA, so it is zeroed and discarded with ZA. Access is gated by SMCR_ELx.EZT0 at each level. For context purposes SME2 adds only ZT0, 64 bytes.
SME without full SVE. FEAT_SME does not require FEAT_SVE. On such an implementation, Z, P and FFR (if FA64 is present) exist only in Streaming SVE mode. Outside streaming mode only the 128-bit V registers are accessible, and ZCR_ELx does not exist. An SVE instruction executed with PSTATE.SM=0 traps with EC 0x1D, SMTC 2: the enable check for SVE instructions becomes the streaming-SVE check. Apple’s M4 is a well-known example of this shape. Firmware and kernels must not infer “SVE present” from “SME present”, and a context-save routine must not use ZCR_ELx or RDVL outside streaming mode on such a part. Use RDSVL for the streaming length.
SVE2.1 and SME2.1 deltas
- SVE2.1 (FEAT_SVE2p1) brings a large part of the SME2 multi-vector and predicate-as-counter model to non-streaming mode: multi-vector contiguous loads and stores governed by
PNregisters,WHILE*forms producing predicate pairs or counters,PEXT, and some formerly SME-only instructions such asSCLAMP/UCLAMPandREVD. It also adds operations on 128-bit segments (“quadword” reductions and permutes such asADDQV,DUPQ,EXTQ,TBLQ) and 128-bit-element gather/scatter (LD1Q/ST1Q). - SME2.1 (FEAT_SME2p1) adds
MOVAZ(move ZA slices to Z and zero the source, which is useful for draining an accumulator),ZEROforms that clear groups of ZA vectors, and related refinements. The new half-precision and BFloat16 SME arithmetic groups are separate features (FEAT_SME_F16F16, FEAT_SVE_B16B16, FEAT_SME_B16B16). - In an Armv9.4 implementation, SVE2 implies SVE2.1 and SME2 implies SME2.1. Neither adds architectural state beyond what SVE2 and SME2 have, so no context-switch code changes.
FPMR and FP8
FEAT_FP8 adds 8-bit floating-point formats: E5M2 and E4M3. The instruction encoding has no room for format and scaling selection, so it moves into a new EL0-accessible register, FPMR (FEAT_FPMR), which FP8 instructions read implicitly:
| Field | Bits | Meaning |
|---|---|---|
F8S1, F8S2 | 2:0, 5:3 | Format of the first and second FP8 source operand (0b000 E5M2, 0b001 E4M3) |
F8D | 8:6 | Format of an FP8 destination |
OSM, OSC | 14, 15 | Overflow saturation for multiplication and for conversion |
LSCALE, NSCALE, LSCALE2 | 22:16, 31:24, 37:32 | Scaling exponents applied by the conversions |
The arithmetic groups are separate features (FEAT_FP8FMA, FEAT_FP8DOT4, FEAT_FP8DOT2, and streaming and SME forms such as FEAT_SSVE_FP8FMA and FEAT_SME_F8F32). ID_AA64PFR2_EL1.FPMR (bits [35:32]) reports the register.
FPMR is new architectural state with its own enables: SCR_EL3.EnFPM (bit 50), HCRX_EL2.EnFPM (bit 23), and SCTLR_EL1.EnFPM/SCTLR_EL2.EnFPM (bit 34) for EL0. A disabled direct access traps with EC 0x18. A disabled implicit read by an FP8 instruction is reported with EC 0x00, the “unknown reason” syndrome, which is easy to mistake for a genuinely UNDEFINED encoding. FPMR is a per-thread value, it belongs to the FP context, and it is zeroed when PSTATE.SM changes. FEAT_FPMR and FP8 arrived with the 2023 architecture extensions. TF-A documents FEAT_FPMR as optional from v9.2. Confirm the base version in DDI0487 A2.
Validation note: The
SVCRside-effect rules are cheap to test directly, and early models and RTL often get them wrong. WithPSTATE.SM=0, write known patterns toZ0,P0,FPSRandFPMR, executeSMSTART SM, and read them back: expect zeros andFPSR=0x0800009F. Repeat forSMSTOP SM, then check that a ZA pattern survives an SM change but notSMSTOP ZAfollowed bySMSTART ZA. Take an exception from streaming mode and check thatSVCRis unchanged in the handler. A wrong result usually shows up later as corrupted vector state after a context switch, which is far harder to attribute.
Checkpoint
Q15.2.1 An EL1 kernel’s context-switch code saves Z registers with STR Zn, [x0, #k, MUL VL] into a buffer sized from RDVL at boot. A user thread was interrupted while in Streaming SVE mode on a core with VL = 128 and SVL = 512. What goes wrong?
- A. Nothing, because exception entry clears
PSTATE.SM, so the save runs at the non-streaming VL - B. The stores run at SVL = 512 because exceptions do not change
PSTATE.SM, so they overrun a buffer sized for 128-bit vectors - C. The
STRinstructions take EC0x1Dwith SMTC 1, because SVE stores are illegal in streaming mode - D. The saved data is zero, because entering the exception zeroed the Z registers
Answer
B. PSTATE.SM and PSTATE.ZA are not changed by exception entry or return, so the handler executes SVE instructions at the streaming vector length. The save must check SVCR and size the save for SVL. A is the common misconception. C is wrong because contiguous STR/ST1 stores are legal in streaming mode; gathers, scatters, FFR access and most Advanced SIMD vector instructions are the illegal ones. D confuses exception entry with an SM change, which is the event that zeroes the registers.
Read more: Arm ARM (DDI0487), SVCR; The Scalable Matrix Extension, Streaming SVE mode
Q15.2.2 A function holds live data in ZA and calls a function that may itself use ZA, following the lazy-save ABI. The callee never touches ZA. After the call returns, what is the state, and what work was done?
- A. ZA was saved to the caller’s buffer at the call and restored at return, because the ABI saves at every call to a non-sharing function
- B. ZA is zero, because the callee entered with ZA dormant and dormant ZA is discarded at return
- C.
TPIDR2_EL0is null, so the caller must call__arm_tpidr2_restore - D. ZA still holds the caller’s data,
TPIDR2_EL0still points to the caller’s block, and no save or restore happened
Answer
D. The caller made ZA dormant by pointing TPIDR2_EL0 at its TPIDR2 block. Only a callee that wants to use ZA performs the save and clears TPIDR2_EL0. When none did, the caller finds TPIDR2_EL0 non-null and skips the restore. The protocol exists so that this, the common case, costs nothing. C describes the outcome when a callee did use ZA.
Read more: Arm ARM (DDI0487), TPIDR2_EL0; Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64), SME support, ZA lazy saving scheme
Q15.2.3 On a part with FP8 support, Linux user code executes an FP8 FCVTN and takes a synchronous exception with EC 0x00. A direct MRS x0, FPMR in the same process takes EC 0x18. What is the most likely cause?
- A. An
EnFPMenable is clear at some level (SCTLR_EL1,HCRX_EL2orSCR_EL3), so the implicit FPMR read by the FP8 instruction and the direct access both trap - B. The core does not implement FEAT_FP8, so the encoding is UNDEFINED
- C. The process is in Streaming SVE mode, and FP8 conversions are illegal in streaming mode
- D.
CPACR_EL1.FPENtraps EL0, and FP8 instructions report that trap with EC0x00
Answer
A. A disabled implicit FPMR read by an FP8 instruction is reported with EC 0x00, and a disabled direct access with EC 0x18. Seeing both together points to an FPMR enable, often EL3 or EL2 firmware that predates FEAT_FPMR. B fits the EC 0x00 alone, but an unimplemented FPMR register access would also be UNDEFINED (EC 0x00), not EC 0x18. D is wrong because an FPEN trap always uses EC 0x07.
Read more: Arm ARM (DDI0487), FPMR, SCTLR_EL1.EnFPM, HCRX_EL2.EnFPM, SCR_EL3.EnFPM