Timeline
Timeline
2025-10-30
init
This article introduces the SVE/SVE2 scalable vector instruction set developed for high-performance computing and machine learning in the ARM architecture, discusses in detail its variable vector length programming model (VLA) and new register groups such as Z, P, and FFR, and summarizes unique programming patterns and core technologies including predicated instructions, gather loads and scatter stores, predicated loop control, and software speculation-based vector partitioning.
Reference documents:
SVE
Scalable Vector Extension
- SVE-related manuals:
- <<ARM Architecture Reference Manual Supplement, The Scalable Vector Extension>>
- <<ARM A64 Instruction Set Architecture ARMv9, for Armv9-A architecture profile>>
Scalable Vector Instructions SVE/SVE2
- SVE stands for Scalable Vector Extension
- The first version was added in ARMv8.2, and the second version in ARMv9
- SVE is a new vector instruction set developed for high-performance computing (HPC) and machine learning, serving as the next-generation SIMD instruction set implementation, andit is not a simple extension of the NEON instruction set
- Many concepts in the SVE instruction set are similar to those in the NEON instruction set, such as vectors, lanes, and data elements
- SVE introduces a new concept:Variable Vector Length Programming Model (Vector Length Agnostic,VLA)
SVE Registers
- 32 new variable-length vector registers Z0 to Z31
- 16 predicate registers P0~P15
- First Fault predicate Register (FFR)
- SVE control register ZCR_ELx
Set vector register length
| Register type | Name | Quantity | Length per register | Description |
|---|---|---|---|---|
| Z registers | Z0–Z31 | 32 | VL bits | Vector data registers |
| P registers | P0–P15 | 16 | VL / 8 bits | Predicate registers (mask) |
| FFR | FFR | 1 | VL / 8 bits | First-Fault Register |
vector length is calledvector length
variable-length vector register

predicate register

SVE instruction syntax
- SVE instruction format consists of opcode, destination register, predicate register, and input operands
1 | LD1D {<Zt>.D}, <Pg>/Z, [<Xn|SP>, <Xm>, LSL #3] |
1 | ADD <Zdn>.<T>, <Pg>/M, <Zdn>.<T>, <Zm>.<T> |
SVE experimental environment
early Cortex-A cores
- Cortex-A53 / A55 / A57 / A72 / A76 / A77 / A78
- only supportsNEON(128-bit SIMD), does not support SVE or SVE2
QEMU
1 | qemu-system-aarch64 -m 1024 -cpu max,sve=on,sve256=on -M virt,gic-version=3,its=on,iommu=smmuv3\ |

SVE-specific programming mode 1: Predicate instructions
- The SVE instruction set provides a governing predicate mechanism to support variable-length vector computation
- Predicate instructions use the governing predicate mechanism to determine which data elements in the vector register are active. Only these active data elements are processed in predicate instructions; inactive data elements are not processed.
- Example:

Merging predication and zeroing predication
- Zeroing predication: In the destination vector register, the values of inactive data elements are filled with 0
- Merging predication: In the destination vector register, the values of inactive data elements remain unchanged
Zeroing predication

Merging predication

SVE-specific programming mode 2: Gather-load and scatter-store
- Supports gather-load and scatter-store modes
- Gather-load and scatter-store refer to the ability toUse the value of each lane in the vector register as a base address or offset to achieve non-contiguous address loading and storing
- The traditional NEON instruction set only supports linear address load and store operations.
Example: Gather load, loading values from multiple discrete addresses.

Scatter store

SVE-specific programming mode 3: Predicate-based loop control
- Usingpredicate register Pninactive data elements as objects to implement loop control
- PSTATE and NZCV status flags
- The SVE instruction set provides the following groups of instructions related to loop control:
- Instructions to initialize predicate registers, such as WHILELO, etc.
- Instructions to increment element counts based on predicate constraints, such as INCB, etc.
- Instructions that combine SVE condition opcodes with branch instructions to perform conditional branching, such as B.FIRST, etc.
- Comparison instructions based on data elements, such as CMPEQ instruction, etc.
- Loop termination instruction, such as BRKA instruction
PSTATE processor state and NZCV
- The loop control method based on data elements can be organically combined with the processor state PSTATE
- When SVE generates a prediction result, it updates the NZCV status flags of PSTATE
- SVE instructions update the NZCV status flags of PSTATE based on the result of the predicate register or the FFR register
- SVE instructions can also update the NZCV status flags of PSTATE based on the CTERMEQ/CTERMNE instructions

Initialize predicate register instruction
Similar to a C language while loop, given an initial value and a target value, using the number of data elements contained in a vector register as the step size, then traversing and initializing the data elements in the predicate register in an incrementing or decrementing manner

Taking whilelt as an example
1 | whilelt <pd>.<T>, <Rn>, <Rm> |
- <pd>: Destination predicate register (e.g., p0, p1)
- <T>: Element type (e.g., .b, .h, .s, .d)
- <Rn>: Starting index or count register
: end index or upper bound register
1 | p[i] = (Rn + i*sizeof(T)/8 < Rm) ? 1 : 0 |
- Starting from Rn, compare indices element by element;
- As long as the current index is still “less than Rm”, set the corresponding
pbit to 1; - Once exceeded, set to 0.
| Type | Element bit width | Increment per step (bytes) | Example |
|---|---|---|---|
.b | 8-bit | 1 | 1-byte aligned |
.h | 16-bit | 2 | 2-byte aligned |
.s | 32-bit | 4 | 4-byte aligned |
.d | 64-bit | 8 | 8-byte aligned |
Example
1 | whilelt p0.b, xzr, x2 |
- p0.b: b indicates that the number of register channels to be predicted is 8 bits wide
- xzr is the starting value
- x2 is the target value, incrementing from low to high until reaching x2 or until all values in the predicate register have been initialized
SVE condition opcode

Increment statistical count of data elements based on predicate constraints

Comparison instruction based on data elements as objects

Break loop instruction
- BRKA instruction
1 | BRKA <Pd>.B, <Pg>/<ZM>, <Pn>.B |
break after

- BRKB instruction
1 | BRKB <Pd>.B, <Pg>/<ZM>, <Pn>.B |

Experiment 2: Implement memcpy_1b() function using SVE instructions

1 | .global sve_ld1_test |
AssumeVLis 256, then p0 can describe at most 32 8-bit (B) count registers, so incb x3 will change x3 from 0 to 32 (32 bytes)
The instruction whilelt p0.b, x3, x2 sets p0.b to all 0s when x3=32
b.any means a branch is triggered as long as any element in the vector register is active
Experiment 3: Implement the memcpy_4b() function using SVE instructions

1 | .global sve_ld1_test |

SVE-specific programming pattern 4: Software-based speculative vector partitioning
- NEON does not support speculative load operations; SVE does
- Challenge with speculative load operations: If some elements encounter a memory fault or access an invalid page during reading, it may be difficult to track which lane’s data read operation caused it
- SVE introduces:
- First-Fault predicate Register (FFR)
- First-fault load instructions, such asLDFF1B
Example:
1 | LDFF1D Z0.D, P0/Z, [Z1.D] |
Using the value of each lane in the Z1.D register as the base address, load the element corresponding to that address into Z0

The third lane has an invalid address, directly mark it as a load failure without reporting to the CPU
SVE/SVE2 Instructions
- SVE was introduced in ARMv8.2, and SVE2 was introduced in ARMv9
- SVE/SVE2 Instruction Manual: <<Arm A64 Instruction Set Architecture Armv9, for Armv9-A architecture profile>>
- The SVE instruction set contains hundreds of instructions, which can be divided into the following major categories
- Load and store instructions and prefetch instructions
- Vector move instructions
- Integer arithmetic instructions
- Bit manipulation instructions
- Floating-point arithmetic instructions
- Predicate operation instructions
- Data element operation instructions
- How to read the instruction manual:

Experiment 4: Case Study 1 - Using SVE Instructions to Optimize the strcmp Function

- There are two difficulties in using SVE instructions to optimize strcmp():
- Difficulty 1: The lengths of strings str1 and str2 are unknown. In C, the end of a string is determined by checking whether the character is ‘\0’. In vector operations, the SVE load instruction loads data from multiple lanes at once. If data beyond the end of the string is loaded, it will cause an illegal access, leading to program errors.
- Difficulty 2: The tail handling problem
1 | .global strcmp_sve |

Case 5: RGB24 to BGR24

Case 6: 4×4 product matrix


Differences from Neon instructions


Summary: SVE instructions used above
- whilelt/whilelo instructions
- b.Any branch instructions
- BRKA and BRKB instructions
- LASTA instruction
- LD1 and ST1 instructions
- LD3 and ST3 instructions
- FMLA instruction
- INCB instructions
- ld1ff1b instructions
- Setffr and rdffrs instructions
- Cmpeq and cmpne instructions
- Mov instructions
