[RFC PATCH 0/5] riscv: Add libmvec routines

Yao Zihong zihong.plct@isrc.iscas.ac.cn
Sun Feb 8 22:04:35 GMT 2026


From: Zihong Yao <zihong.plct@isrc.iscas.ac.cn>

Hi all,

This RFC adds initial RVV support for libmvec on RISC-V and uses vector
log/logf as the first users. The goal is to establish the basic structure
for build/export/abi-testing/benchmark works in RISC-V libmvec.

Background
===========
Yulong Shi and Zhijin Zeng previously posted related RISC-V libmvec work[1].
This series takes a different integration approach and adds ABI checks and
benchtests.

Performance and accuracy
=========================
In our local benchtests with SpacemiT X60, the RVV implementations show the
following speedups relative to the scalar libm functions:
  - logf: speedup up to 4x with LMUL=4 and SIMDLEN=32, and then collapses
    to 3x with LMUL=8 and SIMDLEN=64 due to register spilling.  The
    register spilling appears with both GCC 15.2 and Clang 21 with -O3
    optimization and could be avoided by hand-written code.
  - log: speedup up to 2x with LMUL=2 and SIMDLEN=8, having the similar
    issues with logf with higher LMUL.

Accuracy has been tested to be within <= 1 ULP compared with libm.

Feedback requested
===================
Feedback on the points below is especially welcome, but any other review
comments are appreciated as well :)
1. Layout/integration
   The current approach consists of:
     - common RVV helpers (e.g. v_math.h)
     - per-LMUL / per-SIMDLEN instantiations from a single implementation
     - list-driven symbol export, tests, and benchmark entry generation
   Is this structure acceptable for glibc, or is a different integration
   model preferred?

2. Licensing
   The vector log routine is derived from veclibm [2].
   glibc seems to require a clear licensing. Beyond documenting sources in
   commit messages and source comments, are additional steps expected
   like FSF copyright assignment or an explicit relicensing statement
   from the original copyright holders?

3. LMUL vs code generation
   With current GCC and Clang, logf exhibits noticeable register spilling
   for larger LMUL values (especially for LMUL > 4).  This appears to be an
   optimization issue, and we find it could be avoided by handwriting assembly
   code versions.

   Would it be preferable to:
     a) provide hand-written assembly for some or all LMUL variants, or
     b) rely on future compiler improvements and keep the current pattern?

Thanks for any review,
Zihong

References
==========
[1] https://inbox.sourceware.org/libc-alpha/20240415072108.3741341-1-shiyulong@iscas.ac.cn/
[2] https://github.com/rivosinc/veclibm


Zihong Yao (5):
  riscv: libmvec: add RVV log and infrastructure
  riscv: libmvec: add ABI tests
  riscv: libmvec: add benchtests
  riscv: libmvec: add RVV logf
  riscv: libmvec: exercise RVV ABI calls

 sysdeps/aarch64/fpu/vecmath_config.h          |   9 -
 sysdeps/generic/math_private.h                |   9 +
 sysdeps/riscv/rvd/Makeconfig                  |  81 +++++
 sysdeps/riscv/rvd/Makefile                    |  93 ++++++
 sysdeps/riscv/rvd/Versions                    |  26 ++
 sysdeps/riscv/rvd/bench-libmvec-arch.h        |  49 +++
 sysdeps/riscv/rvd/bits/math-vector.h          |  25 ++
 .../riscv/rvd/scripts/bench_libmvec_rvv.py    | 293 ++++++++++++++++++
 sysdeps/riscv/rvd/test-double-libmvec-log.c   |  21 ++
 sysdeps/riscv/rvd/test-float-libmvec-logf.c   |  21 ++
 sysdeps/riscv/rvd/test-vector-abi-arg1.h      | 113 +++++++
 sysdeps/riscv/rvd/test-vector-abi.h           |  36 +++
 sysdeps/riscv/rvd/v_d_log.c                   |  22 ++
 sysdeps/riscv/rvd/v_d_log_data.c              | 152 +++++++++
 sysdeps/riscv/rvd/v_d_log_skeleton.c          | 151 +++++++++
 sysdeps/riscv/rvd/v_f_logf.c                  |  22 ++
 sysdeps/riscv/rvd/v_f_logf_skeleton.c         | 138 +++++++++
 sysdeps/riscv/rvd/v_math.h                    | 169 ++++++++++
 sysdeps/riscv/rvd/v_math_importer.h           | 137 ++++++++
 sysdeps/riscv/rvd/v_math_names.h              |  27 ++
 sysdeps/riscv/rvd/v_math_variants.h           |  48 +++
 sysdeps/riscv/rvd/vecmath_config.h            | 110 +++++++
 sysdeps/unix/sysv/linux/riscv/libmvec.abilist |  22 ++
 23 files changed, 1765 insertions(+), 9 deletions(-)
 create mode 100644 sysdeps/riscv/rvd/Makeconfig
 create mode 100644 sysdeps/riscv/rvd/Makefile
 create mode 100644 sysdeps/riscv/rvd/Versions
 create mode 100644 sysdeps/riscv/rvd/bench-libmvec-arch.h
 create mode 100644 sysdeps/riscv/rvd/bits/math-vector.h
 create mode 100644 sysdeps/riscv/rvd/scripts/bench_libmvec_rvv.py
 create mode 100644 sysdeps/riscv/rvd/test-double-libmvec-log.c
 create mode 100644 sysdeps/riscv/rvd/test-float-libmvec-logf.c
 create mode 100644 sysdeps/riscv/rvd/test-vector-abi-arg1.h
 create mode 100644 sysdeps/riscv/rvd/test-vector-abi.h
 create mode 100644 sysdeps/riscv/rvd/v_d_log.c
 create mode 100644 sysdeps/riscv/rvd/v_d_log_data.c
 create mode 100644 sysdeps/riscv/rvd/v_d_log_skeleton.c
 create mode 100644 sysdeps/riscv/rvd/v_f_logf.c
 create mode 100644 sysdeps/riscv/rvd/v_f_logf_skeleton.c
 create mode 100644 sysdeps/riscv/rvd/v_math.h
 create mode 100644 sysdeps/riscv/rvd/v_math_importer.h
 create mode 100644 sysdeps/riscv/rvd/v_math_names.h
 create mode 100644 sysdeps/riscv/rvd/v_math_variants.h
 create mode 100644 sysdeps/riscv/rvd/vecmath_config.h
 create mode 100644 sysdeps/unix/sysv/linux/riscv/libmvec.abilist

-- 
2.47.3



More information about the Libc-alpha mailing list