new file mode 100644
@@ -0,0 +1,62 @@
+/* RVV versions memchr. RISC-V version.
+ Copyright (C) 2023 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+#define result a0
+
+#define src a0
+#define value a1
+#define num a2
+
+#define ivl a3
+#define temp a4
+
+#define ELEM_LMUL_SETTING m8
+#define vdata v0
+#define vmask v8
+
+ENTRY(memchr)
+
+L(loop):
+ vsetvli zero, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+ vle8ff.v vdata, (src)
+ /* Find the value inside the loaded data. */
+ vmseq.vx vmask, vdata, value
+ vfirst.m temp, vmask
+
+ /* Skip the loop if we find the matched value. */
+ bgez temp, L(found)
+
+ csrr ivl, vl
+ sub num, num, ivl
+ add src, src, ivl
+
+ bnez num, L(loop)
+
+ li result, 0
+ ret
+
+L(found):
+ add result, src, temp
+ ret
+
+END(memchr)
+libc_hidden_builtin_def (memchr)
new file mode 100644
@@ -0,0 +1,74 @@
+/* RVV versions memcmp. RISC-V version.
+ Copyright (C) 2023 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+#define result a0
+
+#define src1 a0
+#define src2 a1
+#define num a2
+
+#define ivl a3
+#define temp a4
+#define temp1 a5
+#define temp2 a6
+
+#define ELEM_LMUL_SETTING m8
+#define vdata1 v0
+#define vdata2 v8
+#define vmask v16
+
+ENTRY(memcmp)
+
+L(loop):
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+ vle8.v vdata1, (src1)
+ vle8.v vdata2, (src2)
+
+ vmsne.vv vmask, vdata1, vdata2
+ sub num, num, ivl
+ vfirst.m temp, vmask
+
+ /* Skip the loop if we find the different value between src1 and src2. */
+ bgez temp, L(found)
+
+ add src1, src1, ivl
+ add src2, src2, ivl
+
+ bnez num, L(loop)
+
+ li result, 0
+ ret
+
+L(found):
+ add src1, src1, temp
+ add src2, src2, temp
+ lbu temp1, 0(src1)
+ lbu temp2, 0(src2)
+ sub result, temp1, temp2
+ ret
+
+END(memcmp)
+libc_hidden_builtin_def (memcmp)
+weak_alias (memcmp,bcmp)
+strong_alias (memcmp, __memcmpeq)
+libc_hidden_def (__memcmpeq)
+
new file mode 100644
@@ -0,0 +1,50 @@
+/* RVV versions memcpy. RISC-V version.
+ Copyright (C) 2023 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+#define dst a0
+#define src a1
+#define num a2
+
+#define ivl a3
+#define dst_ptr a4
+
+#define ELEM_LMUL_SETTING m8
+#define vdata v0
+
+ENTRY(memcpy)
+
+ mv dst_ptr, dst
+
+L(loop):
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+ vle8.v vdata, (src)
+ sub num, num, ivl
+ add src, src, ivl
+ vse8.v vdata, (dst_ptr)
+ add dst_ptr, dst_ptr, ivl
+
+ bnez num, L(loop)
+
+ ret
+
+END(memcpy)
+libc_hidden_builtin_def (memcpy)
new file mode 100644
@@ -0,0 +1,71 @@
+/* RVV versions memmove. RISC-V version.
+ Copyright (C) 2023 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+#define dst a0
+#define src a1
+#define num a2
+
+#define ivl a3
+#define dst_ptr a4
+#define src_backward_ptr a5
+#define dst_backward_ptr a6
+
+#define ELEM_LMUL_SETTING m8
+#define vdata v0
+
+ENTRY(memmove)
+
+ mv dst_ptr, dst
+
+ /* If src is equal or after dst, all data in src will be loaded before
+ overwrited for the overlapping case. We could use faster `forward-copy`. */
+ bgeu src, dst, L(forward_copy_loop)
+ add src_backward_ptr, src, num
+ add dst_backward_ptr, dst, num
+ /* If dst inside source data range, we need to use `backward_copy_loop` to
+ handle the overlapping issue. */
+ bltu dst, src_backward_ptr, L(backward_copy_loop)
+
+L(forward_copy_loop):
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+ vle8.v vdata, (src)
+ sub num, num, ivl
+ add src, src, ivl
+ vse8.v vdata, (dst_ptr)
+ add dst_ptr, dst_ptr, ivl
+
+ bnez num, L(forward_copy_loop)
+ ret
+
+L(backward_copy_loop):
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+
+ sub src_backward_ptr, src_backward_ptr, ivl
+ vle8.v vdata, (src_backward_ptr)
+ sub num, num, ivl
+ sub dst_backward_ptr, dst_backward_ptr, ivl
+ vse8.v vdata, (dst_backward_ptr)
+ bnez num, L(backward_copy_loop)
+ ret
+
+END(memmove)
+libc_hidden_builtin_def (memmove)
new file mode 100644
@@ -0,0 +1,49 @@
+/* RVV versions memset. RISC-V version.
+ Copyright (C) 2023 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
+ <http://www.gnu.org/licenses/>. */
+
+#include <sysdep.h>
+#include <sys/asm.h>
+
+#define dst a0
+#define value a1
+#define num a2
+
+#define ivl a3
+#define dst_ptr a5
+
+#define ELEM_LMUL_SETTING m8
+#define vdata v0
+
+ENTRY(memset)
+
+ mv dst_ptr, dst
+
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+ vmv.v.x vdata, value
+
+L(loop):
+ vse8.v vdata, (dst_ptr)
+ sub num, num, ivl
+ add dst_ptr, dst_ptr, ivl
+ vsetvli ivl, num, e8, ELEM_LMUL_SETTING, ta, ma
+ bnez num, L(loop)
+
+ ret
+
+END(memset)
+libc_hidden_builtin_def (memset)