Skip to content

RISC-V: widen the ZVL256B AXPY vector length to LMUL m4 - #6056

Open
6eanut wants to merge 1 commit into
OpenMathLib:developfrom
6eanut:riscv64-saxpy-lmul4
Open

6eanut wants to merge 1 commit into
OpenMathLib:developfrom
6eanut:riscv64-saxpy-lmul4

Conversation

@6eanut

@6eanut 6eanut commented Sep 18, 2026

Copy link
Copy Markdown

Summary

Raise the LMUL of the ZVL256B real AXPY kernel from m2 to m4.

With a 256-bit vector unit, m2 moves 16 single-precision (8 double-precision)
elements per vle/vse, so the main loop, whose VL is clamped to VLMAX, runs
ceil(n/16) (resp. ceil(n/8)) times. The register file is 32 vector registers
wide and the kernel keeps four vector operands live (vx0, vx1, vy0, vy1),
so m2 occupies 8 of them — the grouping is narrower than the register budget
needs.

m4 doubles the elements per vector load and store and halves both the loop trip
count and the number of vsetvli executions for the same n. It also matches
the branch this file already takes for the other riscv64 targets, where LMUL is
already m4.

Only the vector register grouping changes: for a given column each element is
still processed by one vfmacc over the same operand triplets in the same
ascending element order, so each y[i] accumulates the same sequence of addends
as before. For non-zero increments the emitted results are bit-identical.

This backs both SAXPY and DAXPY.

Performance

benchmark/saxpy.goto and benchmark/daxpy.goto, one X100 core at 2.2 GHz,
single thread, warm-up once and the median of three runs per size:

Benchmark Size Baseline Patched Change
saxpy 256 3603.45 4518.35 +25.39%
saxpy 512 4511.64 5801.53 +28.59%
saxpy 1024 5288.00 6882.56 +30.15%
daxpy 256 2168.87 2789.62 +28.62%
daxpy 512 2535.53 3437.93 +35.59%
daxpy 1024 2701.35 3787.78 +40.22%

Testing

  • make tests returns 0: 125/125 utests, 1473/1473 extension tests, no new
    CBLAS failure.
  • Differential test under QEMU with guard pages around every buffer: 11136
    single-precision and 11136 double-precision cases, covering n = 0..4097 and
    increments of 1, 2, 3, 4, 5, 7, 8 and 16, produce output bit-identical to the
    unpatched kernel, with no out-of-bounds access. Both builds were also checked
    against a double-precision reference.
  • The emitted code was disassembled to confirm the change is real: every
    vsetvli in the kernel moves from e32,m2/e64,m2 to e32,m4/e64,m4.

The ZVL256B real AXPY kernel selected LMUL m2. With a 256-bit vector
unit that makes each vle/vse move 16 single-precision (8 double-
precision) elements, and the main loop, whose VL is clamped to VLMAX,
runs ceil(n/16) (resp. ceil(n/8)) times. The register file is 32 vector
registers wide and the kernel keeps four vector operands live (vx0, vx1,
vy0, vy1), so m2 occupies 8 of them - the grouping is narrower than the
register budget needs.

Raise LMUL to m4, which doubles the elements per vector load and store
and halves both the loop trip count and the number of vsetvli
executions for the same n. This also matches the branch this file
already takes for the other riscv64 targets, where LMUL is m4.

Only the vector register grouping changes: for a given column each
element is still processed by one vfmacc over the same operand triplets
in the same ascending element order, so each y[i] accumulates the same
sequence of addends as before. For non-zero increments the emitted
results are bit-identical: a differential run of the baseline and
patched kernels against each other, and of both against a
double-precision reference, over 11136 single-precision and 11136
double-precision cases covering n = 0..4097 and increments of 1, 2, 3,
4, 5, 7, 8 and 16, with guard pages around every buffer, shows no
mismatch and no out-of-bounds access. The library built from the patched
kernel passes 125/125 utests and 1473/1473 extension tests.

Measured on one X100 core at 2.2 GHz, warm-up once and the median of
three runs per size: saxpy 256 +25.39%, 512 +28.59%, 1024 +30.15%;
daxpy 256 +28.62%, 512 +35.59%, 1024 +40.22%.

Co-authored-by: Yuansheng <yuansheng@isrc.iscas.ac.cn>
Co-authored-by: Ning Tian <tianning24@iscas.ac.cn>
Signed-off-by: jiakai xu <xujiakai2025@iscas.ac.cn>
@martin-frbg martin-frbg added this to the 0.3.35 milestone Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants