new file mode 100644
@@ -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,ma
+ 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)
@@ -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
@@ -19,6 +19,7 @@
#include <ifunc-impl-list.h>
#include <string.h>
#include <sys/hwprobe.h>
+#include <ldsodefs.h>
size_t
__libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
@@ -27,6 +28,9 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
size_t i = max;
bool fast_unaligned = false;
+#if defined(HAVE_RISCV_ASM_VECTOR_SUPPORT)
+ bool rvv_ext = false;
+#endif
struct riscv_hwprobe pair = { .key = RISCV_HWPROBE_KEY_CPUPERF_0 };
if (__riscv_hwprobe (&pair, 1, 0, NULL, 0) == 0
@@ -34,7 +38,16 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
== RISCV_HWPROBE_MISALIGNED_FAST)
fast_unaligned = true;
+#if defined(HAVE_RISCV_ASM_VECTOR_SUPPORT)
+ if (GLRO(dl_hwcap) & COMPAT_HWCAP_ISA_V)
+ rvv_ext = true;
+#endif
+
IFUNC_IMPL (i, name, memcpy,
+#if defined(HAVE_RISCV_ASM_VECTOR_SUPPORT)
+ IFUNC_IMPL_ADD (array, i, memcpy, rvv_ext,
+ __memcpy_vector)
+#endif
IFUNC_IMPL_ADD (array, i, memcpy, fast_unaligned,
__memcpy_noalignment)
IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_generic))
@@ -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_RISCV_ASM_VECTOR_SUPPORT)
+ if (dl_hwcap & COMPAT_HWCAP_ISA_V)
+ return __memcpy_vector;
+#endif
+
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;