[PATCH v1 1/2] riscv: Add RVV memset for both multiarch and non-multiarch builds

Jeff Law jeffreyalaw@gmail.com
Mon Oct 27 13:56:04 GMT 2025



On 10/20/25 9:50 AM, Yao Zihong wrote:
> This patch introduces an RVV-optimized memset for RISC-V and enables it
> for both multiarch (IFUNC) and non-multiarch builds.
> 
> * sysdeps layout
>     - Add the RVV implementation under sysdeps/riscv/rvv.
>     - Use Implies in sysdeps/rv{32,64}/rvv to pull required subdirs.
> * toolchain/feature detection
>     - Extend preconfigure{,.ac} to detect __riscv_vector and, when present,
>       include the rvv sysdeps directory in the search path.  When the
>       assembler/toolchain lacks vector support, the sysdeps selection stays
>       unchanged and no RVV objects are built.
> * multiarch/IFUNC
>     - Provide a generic re-export (__memset_generic) and a vector wrapper
>       (__memset_vector) under sysdeps/riscv/multiarch; the latter includes the
>       RVV body from sysdeps/riscv/rvv.
>     - Register memset in ifunc-impl-list.c and select the RVV variant when
>       RISCV_HWPROBE_KEY_IMA_EXT_0 reports V.
> 
> Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
> Co-authored-by: Jeff Law <jeffreyalaw@gmail.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>   sysdeps/riscv/configure                       |  0
>   .../riscv/multiarch/dl-symbol-redir-ifunc.h   | 27 +++++++++
>   sysdeps/riscv/multiarch/memset-generic.c      | 26 ++++++++
>   sysdeps/riscv/multiarch/memset_vector.S       | 24 ++++++++
>   sysdeps/riscv/preconfigure                    |  9 +++
>   sysdeps/riscv/preconfigure.ac                 |  9 +++
>   sysdeps/riscv/rv32/rvv/Implies                |  2 +
>   sysdeps/riscv/rv64/rvv/Implies                |  2 +
>   sysdeps/riscv/rvv/memset.S                    | 53 +++++++++++++++++
>   .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>   .../linux/riscv/multiarch/ifunc-impl-list.c   | 11 ++++
>   .../unix/sysv/linux/riscv/multiarch/memset.c  | 59 +++++++++++++++++++
>   12 files changed, 225 insertions(+)
>   mode change 100644 => 100755 sysdeps/riscv/configure
>   create mode 100644 sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
>   create mode 100644 sysdeps/riscv/multiarch/memset-generic.c
>   create mode 100644 sysdeps/riscv/multiarch/memset_vector.S
>   mode change 100644 => 100755 sysdeps/riscv/preconfigure
>   create mode 100644 sysdeps/riscv/rv32/rvv/Implies
>   create mode 100644 sysdeps/riscv/rv64/rvv/Implies
>   create mode 100644 sysdeps/riscv/rvv/memset.S
>   create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memset.c
> 



> diff --git a/sysdeps/riscv/preconfigure b/sysdeps/riscv/preconfigure
> old mode 100644
> new mode 100755
> index a5de5ccb7d..ca6fdf5856
> --- a/sysdeps/riscv/preconfigure
> +++ b/sysdeps/riscv/preconfigure
> @@ -7,6 +7,7 @@ riscv*)
>       flen=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_flen \(.*\)/\1/p'`
>       float_abi=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | sed -n 's/^#define __riscv_float_abi_\([^ ]*\) .*/\1/p'`
>       atomic=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | grep '#define __riscv_atomic' | cut -d' ' -f2`
> +    vector=`$CC $CFLAGS $CPPFLAGS -E -dM -xc /dev/null | grep '#define __riscv_vector' | cut -d' ' -f2`
[ ... ]
Please defer the non-multiarch stuff temporarily.  It's not clear to me 
if this will really be useful given the state of the distro ecosystems.



> diff --git a/sysdeps/riscv/rv32/rvv/Implies b/sysdeps/riscv/rv32/rvv/Implies
> new file mode 100644
> index 0000000000..25ce1df222
> --- /dev/null
> +++ b/sysdeps/riscv/rv32/rvv/Implies
> @@ -0,0 +1,2 @@
> +riscv/rv32/rvd
> +riscv/rvv
> diff --git a/sysdeps/riscv/rv64/rvv/Implies b/sysdeps/riscv/rv64/rvv/Implies
> new file mode 100644
> index 0000000000..9993bb30e3
> --- /dev/null
> +++ b/sysdeps/riscv/rv64/rvv/Implies
> @@ -0,0 +1,2 @@
> +riscv/rv64/rvd
> +riscv/rvv
Why were these needed?  If it's realted to a non-ifunc build, let's drop 
them for now.

Jeff







More information about the Libc-alpha mailing list