Skip to content

ARM64 SIMD: NEON, fixed-length SVE2 and scalable SVE2

Status: NEON and fixed-length SVE2 are built and tested in CI (#717). On scalable SVE2, batch is still the scalar fallback, but the reductions (dot, sum of squares, row-major GEMV) and the GEMM micro-kernel are vector-length agnostic (#427). The only measured numbers are #427’s, from CI’s N2 runner (see “Scalable SVE2”). Every other claim about speed is a hypothesis with the experiment that would test it.

Scope: what MTL5 does on each of the three ARM64 vector targets, the requirements that #716 and #717 uncovered, and the performance engineering each target needs.

On AArch64 the build flags decide which vector ISA Highway compiles for, and MTL5’s simd::batch<T> reacts to each one differently:

targetlane count known atwhat batch<T> doestypical flags
NEONcompile time (128 bits)Highway, float_lanes == 4the default (-march=armv8-a)
fixed-length SVE2 (HWY_SVE2_128, HWY_SVE_256)compile time (-msve-vector-bits=N)Highway, stored as a fixed-length ACLE type (#717)-mcpu=neoverse-n2 -msve-vector-bits=128
scalable SVE2 (HWY_SVE2, HWY_SVE)run time onlyscalar fallback, size == 1-march=armv9-a, -mcpu=neoverse-n2, -march=native on SVE hardware

batch<T>::size is a constexpr that the GEMM tile shape, the packing layout and the blocking parameters are derived from at compile time. A scalable target has no such constant, so batch.hpp turns Highway off for it (HWY_HAVE_SCALABLE → MTL5_SIMD_USE_HIGHWAY 0).

The ubuntu-24.04-arm runners are Neoverse N2, with NEON, SVE, SVE2, I8MM and BF16, at a 128-bit SVE vector length (/proc/sys/abi/sve_default_vector_length = 16). Both the GCC 13 and Clang 18 lanes report it; the probe added in #716 prints it as a check annotation on every run.

These were found by compiling Highway 1.4.0’s headers and reading HWY_TARGET and HWY_HAVE_SCALABLE (GCC 15 cross compiler and Clang 18). The #717 CI lanes confirm four of the cells on the N2 runner, each with a compile-time assertion:

  • GCC 13 and Clang 18 at the default flags (NEON_WITHOUT_AES);
  • GCC 13 with -mcpu=neoverse-n2 -msve-vector-bits=128 (SVE2_128);
  • GCC 13 with -march=native (SVE2, scalable, so batch has one lane).

The Clang SVE cells and both SVE_256 cells come from preprocessing only.

flagsGCCClang 18
-march=armv8-a (default)NEON_WITHOUT_AESNEON_WITHOUT_AES
-march=armv9-a or -mcpu=neoverse-n2SVE2, scalableNEON_WITHOUT_AES
-mcpu=neoverse-n2 -msve-vector-bits=128SVE2_128NEON_WITHOUT_AES
-march=armv8.2-a+sve -msve-vector-bits=256SVE_256NEON_WITHOUT_AES

Clang never gets an SVE target in Highway 1.4.0. hwy/detect_targets.h marks SVE2_128 broken before Clang 21, and SVE, SVE_256 and SVE2 broken before Clang 22. Highway then falls back to NEON with no diagnostic, which is why every CI lane now names the target it expects.

R1. batch cannot hold a sizeless SVE type. Highway’s SVE vectors are ACLE types such as svfloat32_t. These are sizeless: they can’t be class members or array elements, and sizeof doesn’t apply to them. Before #717, batch didn’t compile for any SVE target. The scalable targets never reached that code only because the scalar demotion came first. #717’s initial hypothesis was that the SVE2_128 target would work with the existing batch. It wouldn’t have:

batch.hpp:181: error: member variables cannot have SVE type 'svfloat32_t'

On the fixed-length targets ACLE lets the width be attached to the type, so batch stores svfloat32_t __attribute__((arm_sve_vector_bits(__ARM_FEATURE_SVE_BITS))) (simd::detail::vec_storage). That is an ordinary sized type, and it converts implicitly to and from the sizeless one. The scalable targets have no width to attach, so this fix doesn’t reach them.

R2. SVE2_128 needs I8MM and BF16 in the compiler flags. Highway compiles its SVE2_128 functions with +sve2,+i8mm,+bf16 (plus +sve2-aes where available). -march=armv9-a -msve-vector-bits=128 selects the target but lacks I8MM and BF16. Every inlined Highway call from MTL5 code then fails with inlining failed in call to 'always_inline' ...: target specific option mismatch. Use -mcpu=neoverse-n2 (or -march=armv9-a+i8mm+bf16) together with -msve-vector-bits=128.

R3. A fixed-length binary is correct only at its vector length. Code built with -msve-vector-bits=128 assumes a 128-bit SVE vector length. On a machine with a different vector length it misbehaves, and not reliably loudly. Running the SIMD tests under QEMU at the wrong width (see below) gave:

binaryrun atSIMD tests
SVE2_128256-bit6 of 11 fail (crashes and wrong results); 5 pass
SVE_256128-bit11 of 11 crash
SVE_256512-bit11 of 11 crash

A binary that is partly right is the dangerous case: a smoke test can pass.

  • Neoverse N2, V2 and Grace (Graviton 4) are 128 bits.
  • Neoverse V1 (Graviton 3) is 256 bits.
  • A64FX is 512 bits.

CI guards this with a runner check. A library user has no such guard. A check only at startup is not enough either. Linux sets the SVE vector length per thread, and a thread may change its own with prctl(PR_SVE_SET_VL); a new thread inherits the value set by PR_SVE_SET_VL_ONEXEC, or the system default. So a fixed-length build needs both of the following:

  • A documented requirement: the process must not change the SVE vector length of any thread that runs MTL5 code.
  • A check where the work starts: compare svcntb() * 8 with __ARM_FEATURE_SVE_BITS on the executing thread, at the entry points that run SIMD kernels, and in each pool worker when the worker starts. Refuse to run on a mismatch.

svcntb() is a single instruction, so a check per kernel call costs nothing measurable next to a GEMM. It turns a silent wrong answer into a diagnosis.

R4. MTL5_NATIVE_ARCH=ON on an SVE machine with GCC removed SIMD entirely; native builds now use NEON there (#720). -march=native on N2, V1, V2 or Grace selects a scalable target, and batch falls to one lane. The user who asks for the most tuned build got the least vectorized one, slower than the portable default (NEON). Clang users don’t hit this, but only because Highway refuses SVE for Clang before 22 (the table above). CI confirmed it on N2 with GCC 13: HWY_TARGET was SVE2, scalable, and batch<float>::size was 1.

The fix is mitigation 3 below, with mitigation 1’s warning for the opt-out:

  • Disabled SVE targets: when MTL5_NATIVE_ARCH and MTL5_WITH_HIGHWAY are on, and the native flags define __ARM_FEATURE_SVE without a fixed __ARM_FEATURE_SVE_BITS, CMake adds HWY_DISABLED_TARGETS=HWY_ALL_SVE. Highway then takes the best NEON target the flags allow:
    • NEON_BF16 with crypto, bf16 and dotprod (GCC 13.2 or later), which is what N2 has;
    • NEON_WITHOUT_AES without AES.
  • The CI lanes: the native lane asserts NEON_BF16 and runs the full suite. A native-scalable lane sets MTL5_NATIVE_SCALABLE_SVE=ON, which keeps the scalable target with a configure warning, and pins size == 1.
  • Fixed-length SVE: flags that fix the vector length (-msve-vector-bits=N in MTL5_NATIVE_ARCH_FLAGS) keep SVE and are left alone. Such builds also need R2 and R3.

The mitigations that were considered, in increasing cost:

  1. A configure-time warning when MTL5_NATIVE_ARCH=ON, MTL5_WITH_HIGHWAY=ON and the compiler defines __ARM_FEATURE_SVE without __ARM_FEATURE_SVE_BITS.
  2. Append -msve-vector-bits=<detected> to the native flags when configuring on the machine that will run the binary, which is what “native” already means. This must also apply R2 and R3.
  3. Prefer NEON for a scalable target until #427 lands, by defining HWY_DISABLED_TARGETS=HWY_ALL_SVE in native builds. It always works and loses only what SVE adds over NEON at 128 bits (see below).

#427’s dispatch design (below) or mitigation 2 can replace it later.

R5. Every SIMD lane must assert its target. A lane that builds the wrong target still passes the suite, because every target computes correct answers. test_batch now fails to compile when the lane’s MTL5_TEST_EXPECT_HWY_TARGET differs from HWY_TARGET. It also requires size > 1 on AArch64 as it already did on x86-64, except on a scalable target, where it requires size == 1 until #427.

Nothing below has been measured, except where #427 says so. Each subsection ends with the experiment that would settle it.

Where it stands. This is the target every ARM64 Highway build gets by default, and the only ARM target with measurements. The register tile is 8×4 fp64 / 8×8 fp32, with 16 accumulators, half of the 32-register file. It was measured on a Cortex-A78C (simd/blocking.hpp, target_hw_traits). The int8 quad kernel uses SDOT/UDOT natively and USDOT when I8MM is present.

What it needs:

  • Per-core FMA throughput. hw_traits carries one fma_latency and fma_units for all of aarch64. The BLIS bound mr * nr >= Nvec * Lvfma * Nvfma changes sharply across cores:

    • A78 and N2: 2 FP/ASIMD pipes, so the 16-accumulator tile covers the pipeline.
    • V1 and V2: 4 pipes, so the same tile covers half of it. fp64 needs 2 * 4 * 4 = 32 lane-accumulators, i.e. 16 registers at 2 lanes each, with no headroom left.

    V-class cores probably want acc_vectors near 24 and a tile like 12×4 fp64. That is the candidate that lost on the A78C. So the tile has to become a per-core decision, not a per-ISA one.

  • FMA by element. The micro-kernel broadcasts A(i, p) into a register and then issues an FMA. NEON has FMLA Vd.2D, Vn.2D, Vm.D[lane], which reads the multiplier straight from a lane. If the packed A panel is loaded one q-register at a time (2 fp64 or 4 fp32 values), the broadcasts disappear: on a core with two load ports, they are the instruction slots competing with the B-panel loads. Check that the compiler already fuses dup + fmla. If it doesn’t, the fix is a NEON-specific micro-kernel: Highway 1.4.0 has no lane-indexed FMA operation.

  • Paired loads. The B micro-panel row should be loaded with LDP q, q (32 bytes per instruction). Check the disassembly of gemm_microkernel<double, double, 8, 4>.

  • int8 and bf16 matrix instructions. I8MM’s SMMLA/UMMLA/USMMLA and BF16’s BFMMLA compute a 2×8 by 8×2 product into a 2×2 int32 (or fp32) tile per instruction. That is twice the multiply-accumulates of SDOT per instruction, but it needs a different packing: pairs of rows of A and pairs of columns of B, each 8 bytes deep. This is the ARM counterpart of the x86 quad kernel (#451) and probably the largest single int8 gain available on N2, V2 and Grace. N2 has both features.

Experiment: bench_blocking_ab on an N2 or Graviton 4 (V2) host. Sweep mr and acc_vectors exactly as the A78C sweep did. Add the SMMLA kernel as an arm against the SDOT quad kernel at n = 1024.

Fixed-length SVE2 (SVE2_128 on N2/V2/Grace, SVE_256 on V1)

Section titled “Fixed-length SVE2 (SVE2_128 on N2/V2/Grace, SVE_256 on V1)”

Where it stands. It compiles and runs in CI as of #717. The sve2-128 lane runs the full suite on N2. batch is identical in shape to NEON at 128 bits: float_lanes == 4, the same tile and the same packing.

What SVE adds at 128 bits is not width. On N2, V2 and Grace, SVE and NEON share the same 128-bit datapath, so dense GEMM throughput should be the same. What SVE adds:

  • Predicated tails. WHILELT builds a lane mask for the last partial vector, so a loop needs no scalar remainder and no zero-padded temporary. MTL5’s edge tiles go through “a zeroed mr×nr temporary so the micro-kernel only ever writes full tiles” (gemm_blocked.hpp). Masked loads and stores would remove that copy. That matters for skinny and odd shapes, not for large square ones. Highway exposes it as FirstN + MaskedLoad / BlendedStore, which also compile on NEON (emulated), so one source can serve both.
  • Gather/scatter. LD1D with a vector of indices. This is relevant to the CSR kernels (mult_sparse_csr_rows, CSR×dense), whose x[col[k]] access is a gather. Whether hardware gathers beat scalar loads on N2 is unknown and often negative; measure it before building on it.
  • Wider integer dot products. SVE2’s SDOT/UDOT and USDOT (with I8MM) match NEON’s. SVE’s SMMLA exists too. No width gain at 128 bits.

What SVE_256 adds on V1 (Graviton 3) is width: 8 fp32 or 4 fp64 lanes, twice NEON. The tile follows batch::size automatically (nr must be a multiple of the width). But the accumulator budget, the B-panel kc and the packing alignment were tuned at 128 bits and need re-deriving. V1 has SVE but not SVE2, so the target is SVE_256 (-mcpu=neoverse-v1 -msve-vector-bits=256), not SVE2_*.

Requirements before shipping fixed-length SVE to users: R2 (flags), R3 (the per-thread vector-length requirement and check), and recording the target in every benchmark sidecar. simd::backend_name() already reports SVE2_128, so a NEON number and an SVE number can’t be confused afterwards.

Experiment: on the same N2 host, build the same commit twice: NEON (default) and SVE2_128. Compare GEMM n = 256..2048, GEMV, dot and the CSR kernels. The prediction is parity on large GEMM, an SVE win on odd and skinny shapes from predication, and an unknown result for CSR gathers. On a V1 host, SVE_256 against NEON on GEMM is the one place a width gain should appear.

Where it stands. batch<T> is still the scalar fallback on a scalable target (size == 1). That’s what -march=armv9-a and -mcpu=neoverse-n2 produce, and GCC’s -march=native on SVE hardware with MTL5_NATIVE_SCALABLE_SVE=ON (R4).

The reductions no longer go through batch there. They are vector-length agnostic (include/mtl/simd/scalable.hpp, #427, first PR):

  • the kernels are reduce_dot, reduce_sum_squares and the row-major gemv;
  • they hold Highway’s sizeless vectors in locals, take Lanes(d) at run time, and end each loop with a predicated partial vector (FirstN, MaskedLoad) instead of a scalar tail;
  • simd/algorithm.hpp and detail/gemv.hpp forward to them when MTL5_SIMD_SCALABLE is 1. MTL5_SIMD_NO_SCALABLE_KERNELS turns them off, which is how CI measures them against the scalar fallback;
  • one binary passes test_scalable_kernels at 128, 256 and 512 bits under QEMU, and the N2 runner runs the full suite on them.

Measured on Neoverse N2 (CI’s native-scalable lane, GCC 13, 128-bit SVE, the median of six rounds against the scalar fallback):

kernelf32f64
reduce_dot, n = 40964.17x1.48x
row-major gemv, 256 x 2562.51x1.38x
axpy, n = 4096 (VLA version, dropped)1.00x0.89x
col-major gemv, 256 x 256 (VLA version, dropped)0.74x0.73x
  • What the numbers mean: the reductions win because GCC can’t vectorize a floating-point reduction without reassociating it, so the scalar fallback really is scalar there.
  • Why the element-wise kernels were dropped: axpy, scal and the col-major gemv’s strip update have no reduction. GCC vectorizes the scalar fallback itself, with SVE, and the VLA versions measured no better. They were removed, so those kernels keep the batch path.

The GEMM (second PR) runs on a scalable target through detail::gemm_blocked, which picks one of three tiled copies at run time:

  • The copies: vla_tile<T, W> for W = 128, 256 and 512 bits’ worth of lanes. Each one has the tile derive_blocking gives at that width, so the 128-bit copy has NEON’s 8 x 2W tile.
  • The micro-kernel: simd::scalable::gemm_microkernel. It keeps the C tile in named locals, because arrays of sizeless vectors are ill-formed.
  • Selection: gemm_blocked and gemm_plan_for run the copy whose W equals Lanes(d), so a copy never runs at a length it does not assume (the R3 hazard).
    • Per thread: Linux sets the vector length per thread (PR_SVE_SET_VL), so each tile checks Lanes(d) on the thread that runs it.
    • On a mismatch: a pool worker of another width runs batch’s micro-kernel on the same packed panels, which is correct at any width.
  • Fallback: another length, mixed precision and the integer kernels keep batch’s scalar tile.
  • Reporting: detail::gemm_blocking<T>() and gemm_runtime_blocking<T>() report the tile in use.

Measured on N2 before the GEMM PR (the first PR’s three-way run; ms, the median of six rounds; ratios are other / VLA, so above 1 means VLA is faster):

kernelscalarVLANEONVLA vs scalarVLA vs NEON
reduce_dot f322.130.580.573.68x0.98x
reduce_dot f641.841.261.221.46x0.97x
row-major gemv f320.780.290.282.71x0.99x
row-major gemv f640.820.550.541.50x0.98x
gemm 192^3 f32 (scalar tile)2.002.010.891.00x0.44x
gemm 192^3 f64 (scalar tile)1.221.221.801.00x1.47x
  • For the reductions and the GEMV, SVE matches NEON at 128 bits: the vectors are the same width. The GEMM rows differ, for the reason below.
  • The single-lane batch GEMM before the second PR: for f64, GCC’s own vectorization of it beat NEON’s 2-lane tile. For f32 it was 2.2x slower than NEON.

Measured on N2 after the GEMM PR (the same lane at #986’s head, 925d604; ms, the median of six rotated rounds; the VLA build runs the 128-bit vla_tile):

kernelscalarVLANEONVLA vs scalarVLA vs NEON
gemm 192^3 f322.010.600.893.38x1.50x
gemm 192^3 f641.211.191.791.02x1.51x
  • f32: the scalable tile is 3.4x the single-lane tile it replaces, and 1.5x NEON’s.
  • f64: it equals the scalar tile, which GCC already vectorizes with SVE for f64 (the row above), and is 1.5x NEON’s. Both SVE builds beat NEON’s 2-lane tile on f64, so the gain over NEON is SVE code generation, not a wider vector: at 128 bits the registers are the same width.
  • One CI run: these are one lane’s medians on one machine, not a sweep of shapes. The other kernels in that run repeated the first PR’s ratios.

Why it is hard. The vector length is a run-time value, and MTL5’s dense kernels are built on it being a compile-time one:

  • gemm_microkernel<TC, TAB, MR, NR> static-asserts NR % W == 0, and its C tile is batch c[MR][NB]. That is an array of vectors, and arrays of sizeless types are ill-formed (array elements cannot have SVE type). R1’s fix is unavailable because there is no width to attach.
  • simd::default_blocking<T> derives mr × nr at compile time from simd::width<T>.
  • The packed-panel layouts (Ap[p*MR + i], Bp[p*NR + j]) bake NR into the index arithmetic.

Design 1, as first proposed, can’t be header-only. The idea was: compile the hot kernels once per vector length that ships (128 for N2, V2 and Grace, 256 for V1, 512 for A64FX), give each copy R1’s fixed-length storage, and pick one at run time from svcntb().

  • The obstacle: GCC 15 and Clang 21 both accept arm_sve_vector_bits(N) only when the whole translation unit is compiled with -msve-vector-bits=N. Clang says so explicitly (“must match value set by ‘-msve-vector-bits’”). GCC ignores the attribute with “unsupported SVE vector size”, so the type stays sizeless.
  • The consequence: one translation unit can hold a fixed-length batch for at most one length. Per-length copies would need one compiled translation unit per length, which a header-only library doesn’t have.

What #427 does instead, by the maintainer’s choice:

  • Header-only VLA kernels: sizeless locals are allowed, and only members and arrays are not, so the kernels are written against Highway’s scalable API directly.
  • The reductions (done): they need no compile-time lane count at all.
  • The GEMM micro-kernel (done, second PR): copies templated on an assumed lane count (4, 8 or 16 floats). Each copy keeps its C tile in named locals, since arrays are not allowed. The copy is picked at run time from Lanes(d), so the R3 hazard can’t arise: a copy only runs at the length it assumes.
  • RVV: it has the same problem and gets the same kernels where Highway supports it. No RVV hardware or CI runner exists to test it, so that is not claimed.

Experiment: CI’s native-scalable lane compiles benchmarks/scalable_speedup.cpp three ways on the N2 runner and runs them in rotating order:

  • as is;
  • with MTL5_SIMD_NO_SCALABLE_KERNELS (the scalar fallback);
  • with HWY_DISABLED_TARGETS=HWY_ALL_SVE (NEON, what a native build gets by default since #720).

It reports each kernel’s speedup over the scalar and the NEON build. A shared runner’s timings are rough, so the ratios are reported, not gated.

QEMU’s user mode runs aarch64 Linux binaries on an x86-64 Linux host, and it emulates SVE and SVE2 at any vector length from 128 to 2048 bits. That covers widths no CI runner has. It establishes correctness only: emulated timings say nothing about hardware, and mtl5_bench’s rates under QEMU are meaningless, although its checks are valid.

Terminal window
sudo apt install g++-aarch64-linux-gnu qemu-user
cmake --preset aarch64-sve-256 # or aarch64-neon, -sve2-128, -sve2-scalable
cmake --build --preset aarch64-sve-256 # or build only the simd_* targets
ctest --preset aarch64-sve-256-simd # the SIMD tests, run through qemu-aarch64

The toolchain file tools/cmake/toolchains/aarch64-linux-gnu.cmake sets CMAKE_CROSSCOMPILING_EMULATOR, so ctest runs every test under QEMU. MTL5_QEMU_CPU picks the emulated core, and with it the vector length.

presetflagsQEMU CPU (VL)Highway targetbatch<float> lanes
aarch64-neon(default)neoverse-n2 (128)NEON_WITHOUT_AES4
aarch64-sve2-128-mcpu=neoverse-n2 -msve-vector-bits=128neoverse-n2 (128)SVE2_1284
aarch64-sve-256-mcpu=neoverse-v1 -msve-vector-bits=256neoverse-v1 (256)SVE_2568
aarch64-sve2-scalable-mcpu=neoverse-n2max (512)SVE2, scalable1 (the reductions and the GEMM are VLA, #427)

All four pass the 11 SIMD tests. SVE_256 (Graviton 3’s width) had never been compiled or run before this; CI’s runners are 128-bit. The scalable build also passes at 128, 256, 512 and 2048 bits. To rerun it at another width, set -DMTL5_QEMU_CPU=max,sve-default-vector-length=<bytes> and reconfigure. No rebuild is needed, since the binary doesn’t depend on the vector length. This is the test bed for #427: once batch is vector-length agnostic, the same binary has to pass at every width.

Each fixed-length preset is correct only at its own width (R3), so its MTL5_QEMU_CPU must match. QEMU’s neoverse-n2 is 128-bit, neoverse-v1 is 256-bit, and a64fx is 512-bit.

Shared CI runners give correctness, never timing (see benchmarking methodology). The numbers have to come from dedicated hosts, ideally one of each width:

hostcoreSVEVLsettles
Graviton 4 / GraceNeoverse V2SVE2 + I8MM + BF16128V-class tile (4 FP pipes), SMMLA, NEON vs SVE2_128
Azure Cobalt 100Neoverse N2SVE2 + I8MM + BF16128the CI core, timed; predication on odd shapes
Graviton 3Neoverse V1SVE + I8MM + BF16256SVE_256 width gain, R3’s mismatch hazard against 128
A64FXFujitsuSVE512the dispatch design at the widest length

The hardware expansion plan already lists the scalar-fallback cliff as an open capability gap. This document is the engineering plan for closing it.

  • #427: vector-length-agnostic batch<T> (scalable SVE / RVV).
  • #717: ARM64 Highway CI lanes and fixed-length SVE storage.
  • #716: the runner SVE probe.
  • #330: the x64 Highway lane.
  • #643: the NEON register-file budget.
  • #451: quad (int8) kernels.