[PATCH v4 4/4] add riscv vector support for memcpy
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Wed Jan 22 12:30:17 GMT 2025
On 21/01/25 23:04, daichengrong@iscas.ac.cn wrote:
> From: daichengrong <daichengrong@iscas.ac.cn>
>
> Changes in v4:
> update rvv memcpy support by compiler
> check whether rvv enabled by dl_hwcap
>
> Changes in v3:
> Remove unnecessary whitespace
>
> Changes in v2:
> delete size-0 branch
As before, usually we provide optimization backed up with some performance
numbers on real hardware.
>
> ---
> sysdeps/riscv/multiarch/memcpy_vector.S | 35 +++++++++++++++++++
> .../unix/sysv/linux/riscv/multiarch/Makefile | 8 +++++
> .../unix/sysv/linux/riscv/multiarch/memcpy.c | 7 ++++
> 3 files changed, 50 insertions(+)
> create mode 100644 sysdeps/riscv/multiarch/memcpy_vector.S
>
> diff --git a/sysdeps/riscv/multiarch/memcpy_vector.S b/sysdeps/riscv/multiarch/memcpy_vector.S
> new file mode 100644
> index 0000000000..8fddab8432
> --- /dev/null
> +++ b/sysdeps/riscv/multiarch/memcpy_vector.S
> @@ -0,0 +1,35 @@
> +/* memcpy for RISC-V Vector.
> + Copyright (C) 2024-2025 Free Software Foundation, Inc.
> + This file is part of the GNU C Library.
> +
> + The GNU C Library is free software; you can redistribute it and/or
> + modify it under the terms of the GNU Lesser General Public
> + License as published by the Free Software Foundation; either
> + version 2.1 of the License, or (at your option) any later version.
> +
> + The GNU C Library is distributed in the hope that it will be useful,
> + but WITHOUT ANY WARRANTY; without even the implied warranty of
> + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + Lesser General Public License for more details.
> +
> + You should have received a copy of the GNU Lesser General Public
> + License along with the GNU C Library; if not, see
> + <https://www.gnu.org/licenses/>. */
> +
> +
> +#include <sysdep.h>
> +#include <sys/asm.h>
> +
> +ENTRY (__memcpy_vector)
> + mv a6, a0
> +L(loop):
> + vsetvli a3,a2,e8,m8,ta,mu
> + vle8.v v8,(a1)
> + vse8.v v8,(a6)
> + add a1,a1,a3
> + sub a2,a2,a3
> + add a6,a6,a3
> + bnez a2,L(loop)
> +L(ret):
> + ret
> +END (__memcpy_vector)
> diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
> index fcef5659d4..394033e077 100644
> --- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
> +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
> @@ -5,5 +5,13 @@ sysdep_routines += \
> memcpy_noalignment \
> # sysdep_routines
>
> +ifeq ($(have-gcc-riscv-rvv),yes)
> +sysdep_routines += \
> + memcpy_vector \
> + # rvv sysdep_routines
> +
> +ASFLAGS-memcpy_vector.S += -march=rv64gcv
> +endif
> +
> CFLAGS-memcpy_noalignment.c += -mno-strict-align
> endif
> diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
> index 8544f5402a..4d1fa2073d 100644
> --- a/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
> +++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
> @@ -32,11 +32,18 @@ extern __typeof (__redirect_memcpy) __libc_memcpy;
>
> extern __typeof (__redirect_memcpy) __memcpy_generic attribute_hidden;
> extern __typeof (__redirect_memcpy) __memcpy_noalignment attribute_hidden;
> +extern __typeof (__redirect_memcpy) __memcpy_vector attribute_hidden;
>
> static inline __typeof (__redirect_memcpy) *
> select_memcpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
> {
> unsigned long long int v;
> +
> +#if defined(HAVE_GCC_RISCV_VECTOR)
> + if (dl_hwcap & COMPAT_HWCAP_ISA_V)
> + return __memcpy_vector;
> +#endif
Indentation seems off here.
> +
> if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_CPUPERF_0, &v) == 0
> && (v & RISCV_HWPROBE_MISALIGNED_MASK) == RISCV_HWPROBE_MISALIGNED_FAST)
> return __memcpy_noalignment;
More information about the Libc-alpha
mailing list