Re: [RFC PATCH 0/2] Add RISC-V vector math library support

Pincheng Wang <[email protected]> Fri, 27 Feb 2026 00:45:20 +0800
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hi Joel,

Thank you for the thoughtful questions regarding multilib configureation 
and gcc builtins. I apologies for the delayed response. This email 
somehow didn't appear in my inbox, and I only came across it while 
browsing the mailing list archive.

For multilib variants, currently, neither gcc nor newlib defines a 
dedicated multilib variant solely for RISC-V vector extension (e.g a 
seperate rv64gcv). As noted in the cover letter, the current workflow 
requires both --enable-vecmath at configure time and -march=rv64gcv at 
compile time to enable vector math support.

This may indeed an area that may benefit from upstream toolchain 
coordination, especially given that the vector extension has now become 
a mandatory extension of the RVA23 profile. If the community sees value 
in introducing RVV-aware multilib vairiants like rv64gcv_lp64d, I would 
be happy to collaborate on adapting the build infrasturcture accordingly.

Regarding gcc builtins. If you refers to RVV intrinsics: intrinsics 
based on the v0.11 spec have been supported since gcc 13 and clang 16;
Ratified v1.0 intrinsics became available starting with gcc 14 and clang 
19. Our implementation uses v1.0 intrinsics, so gcc 14+ is required.
If you refers to vectorized math function symbols: The naming convention 
and ABI for these vector math functions are currently under review in 
the RISC-V psABI document [1]. The corresponding gcc patch to recognize 
and emit these calls has not yet been merged upstream. This is also why 
this patch series is send as an RFC to gather feedback before the ABI 
solidifies.

Thank you again for valubale insights from a practical application and 
development perspective. I look forward to further discussion and 
suggestions from the community.

Best regards,
Pincheng Wang

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/455
On 2026/2/5 22:31, Joel Sherrill wrote:
> 
> 
> On Thu, Feb 5, 2026, 3:53 AM Brian Inglis 
> <[email protected] 
> <mailto:[email protected]>> wrote:
> 
>     Benefits? - Performance? Accuracy? - numbers to back that up?
> 
> 
> Are the vector extensions enabled by any multilib variant?
> 
> At least for RTEMS, we do not build single variant tool chains. Our 
> risc-v tool chain supports 32 and 64 variants. The OS source uses the 
> compiler predefines to tailor to which cpu variant is being compiled to. 
> What multilib variant would your configuration correspond to?
> 
> When did GCC start having the builtins used?
> 
> --joel
> RTEMS
> 
> 
> 
>     On 2026-02-04 11:15, Pincheng Wang wrote:
>      > This RFC patch series propose adding RISC-V Vector Extension (RVV)
>      > optimized math functions to newlib, starting with a vectorized
>      > implementation of sin().
>      >
>      > The motivation is to enable automatic vectorization of math
>     functions on
>      > RISC-V platforms with vector extensions, which can provide
>     significant
>      > performance improvements for numerical applications.
>      >
>      > After applying the gcc vecmath patch[1], compiler supports automatic
>      > vectorzation using the vector ABI[2](also in RFC). When compiling
>     with
>      > auto-vectorization enabled (-O3 -ffast-math), the compiler can
>     replace
>      > scalar math function calls with vector variants if they are
>     available in
>      > the math library.
>      >
>      > This patch series adds infrastructure support for building vector
>     math
>      > functions conditionally via a newly added "--enable-vecmath"
>     configure
>      > option (disabled by default), and a vectorized sin()
>     implementation for
>      > RISC-V using intrinsics from the RISC-V Vector Extension.
>      >
>      > While adding the above option, I encountered an automake
>     compatibility
>      > issue during math object copying. Therefore, commit 1 is dedicated to
>      > fixing that issue and does not involve any vector math changes.
>      >
>      > The vector sin implementation is derived from the SLEEF library
>     (Boost
>      > licensed) and adapted for newlib's RISC-V target. It uses RVV 1.0
>      > intrinsics and provides performance-optimized computation with proper
>      > handling of edge cases.
>      >
>      > To configure and build, use below command.
>      >       configure --target=riscv64-unknown-elf \
>      >               --prefix=/opt/vecmath-newlib \
>      >               CFLAGS_FOR_TARGET="-O2 -march=rv64gcv -mabi=lp64d" \
>      >               --enable-vecmath
>      >
>      > To compile a program that can take
>      > benefit of this patch, use the patched[1] gcc and run command like
>      > below.
>      >       /opt/vecmath-gcc/bin/riscv64-unknown-elf-gcc \
>      >               -O3 -ffast-math -march=rv64gcv \
>      >               --sysroot=/opt/vecmath-newlib \
>      >               -L/opt/vecmath-newlib/riscv64-unknown-elf/lib \
>      >               -I/opt/vecmath-newlib/riscv64-unknown-elf/include \
>      >               test_sin.c -o test_sin -lm
>      >
>      > Comments and suggestions are welcome!
>      >
>      > [1] https://gcc.gnu.org/pipermail/gcc-patches/2024-
>     November/667352.html <https://gcc.gnu.org/pipermail/gcc-
>     patches/2024-November/667352.html>
>      > [2] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/455
>     <https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/455>
>      >
>      > Thanks,
>      > Pincheng Wang
>      >
>      > Pincheng Wang (2):
>      >    newlib: Fix automake 1.16 compatibility for math object copying
>      >    newlib: Add RISC-V vector math library support
>      >
>      >   newlib/Makefile.am                         |   26 +-
>      >   newlib/configure.ac <http://configure.ac>                     
>        |   10 +
>      >   newlib/libc/include/math.h                 |    1 +
>      >   newlib/libm/machine/riscv/Makefile.inc     |    5 +
>      >   newlib/libm/machine/riscv/riscv-vec-math.h | 1461 +++++++++++++
>     +++++++
>      >   newlib/libm/machine/riscv/vec_sin.c        |   79 ++
>      >   6 files changed, 1569 insertions(+), 13 deletions(-)
>      >   create mode 100644 newlib/libm/machine/riscv/riscv-vec-math.h
>      >   create mode 100644 newlib/libm/machine/riscv/vec_sin.c
>      >
> 
> 
>     -- 
>     Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada
> 
>     La perfection est atteinte                   Perfection is achieved
>     non pas lorsqu'il n'y a plus rien à ajouter  not when there is no
>     more to add
>     mais lorsqu'il n'y a plus rien à retrancher  but when there is no
>     more to cut
>                                       -- Antoine de Saint-Exupéry
>