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

Brian Inglis <[email protected]> Thu, 5 Feb 2026 02:52:50 -0700
Newsgroups gmane.comp.lib.newlib
Organization Systematic Software
Message-ID <[email protected]>
Benefits? - Performance? Accuracy? - numbers to back that up?

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
> [2] 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                        |   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