public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v5 00/18] riscv: Add RVV str*/mem* routines
@ 2026-02-03 15:05 Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch Yao Zihong
                   ` (19 more replies)
  0 siblings, 20 replies; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong

Changes since v4:
  * Disabled multiarch variants when !IS_IN(libc)

Changes since v3:
  * Added RVV implementation for `stpncpy`
  * Refactored strncpy to reuse the same core logic in `__stpncpy_vector`
    to avoid duplication
  * Deferred the extra `#undef` to keep this series minimal

Changes since v2:
  * Fixed symbol export issues
  * Rebased onto the current RVV multiarch and non-multiarch framework
  * Added RVV implementations for memccpy, memrchr and strrchr
  * Adjusted register usage for Zca-friendliness
  * Improved label naming for readability

Changes since v1:
  * Wrapped RVV assembly with `#if IS_IN (libc)` so that rtld/* does not
    include vectorized code.
  * Added `.option push` / `.option arch, +v` / `.option pop` around
    vectorized functions, so builds succeed even when compilers are
    invoked without global +v support.

Hi all,

This series introduces RVV implementations for the RISC-V str*/mem* family
within current RVV multiarch and non-multiarch framework.

Background
----------
This series is a rework and extension of Hau Hsu's v3 RVV patches [1],
adapted to the current RVV multiarch and non-multiarch framework, and
fixing issues in the previous patch series [2].

In addition to the original set, this series also adds RVV implementations
for memccpy, memrchr and strrchr.

---

Testing
-------
Testing was conducted on MUSE-Pi (SpacemiT M1). The glibc testsuite passed
without any additional regressions compared with glibc master in multiarch
and non-multiarch builds when the RVV extension was not disabled via prctl().

Summary of test results for(MUSE-Pi):
    XFAIL: conform/UNIX98/ndbm.h/conform
    XFAIL: conform/UNIX98/ndbm.h/linknamespace
    XFAIL: conform/UNIX98/varargs.h/conform
    XFAIL: conform/UNIX98/varargs.h/linknamespace
    XFAIL: conform/XOPEN2K/ndbm.h/conform
    XFAIL: conform/XOPEN2K/ndbm.h/linknamespace
    XFAIL: conform/XOPEN2K8/ndbm.h/conform
    XFAIL: conform/XOPEN2K8/ndbm.h/linknamespace
    XFAIL: conform/XPG4/varargs.h/conform
    XFAIL: conform/XPG4/varargs.h/linknamespace
    XFAIL: conform/XPG42/ndbm.h/conform
    XFAIL: conform/XPG42/ndbm.h/linknamespace
    XFAIL: conform/XPG42/varargs.h/conform
    XFAIL: conform/XPG42/varargs.h/linknamespace
    UNSUPPORTED: elf/tst-env-setuid
    XPASS: elf/tst-protected1a
    XPASS: elf/tst-protected1b
    UNSUPPORTED: elf/tst-valgrind-smoke
    UNSUPPORTED: io/tst-faccessat-setuid
    UNSUPPORTED: libio/tst-fopen-compat
    XFAIL: localedata/tst-langinfo-newlocale-static
    UNSUPPORTED: math/test-ceil-except-2
    UNSUPPORTED: math/test-fesetexcept-traps
    UNSUPPORTED: math/test-fexcept-traps
    UNSUPPORTED: math/test-floor-except-2
    UNSUPPORTED: math/test-nearbyint-except-2
    UNSUPPORTED: math/test-trunc-except-2
    UNSUPPORTED: misc/tst-adjtimex
    UNSUPPORTED: misc/tst-clock_adjtime
    UNSUPPORTED: misc/tst-epoll-ioctls
    FAIL: misc/tst-gethostid
    UNSUPPORTED: misc/tst-mseal
    UNSUPPORTED: misc/tst-mseal-pkey
    UNSUPPORTED: misc/tst-ntp_adjtime
    UNSUPPORTED: misc/tst-pidfd_getinfo
    UNSUPPORTED: misc/tst-pkey
    UNSUPPORTED: nptl/test-cond-printers
    UNSUPPORTED: nptl/test-condattr-printers
    UNSUPPORTED: nptl/test-mutex-printers
    UNSUPPORTED: nptl/test-mutexattr-printers
    UNSUPPORTED: nptl/test-rwlock-printers
    UNSUPPORTED: nptl/test-rwlockattr-printers
    FAIL: nss/test-netdb
    XFAIL: posix/annexc
    FAIL: resolv/tst-bug18665
    FAIL: resolv/tst-bug18665-tcp
    FAIL: resolv/tst-ns_rr_cursor
    FAIL: resolv/tst-resolv-ai_idn
    FAIL: resolv/tst-resolv-ai_idn-latin1
    FAIL: resolv/tst-resolv-ai_idn-nolibidn2
    FAIL: resolv/tst-resolv-aliases
    FAIL: resolv/tst-resolv-basic
    FAIL: resolv/tst-resolv-byaddr
    FAIL: resolv/tst-resolv-invalid-cname
    FAIL: resolv/tst-resolv-noaaaa
    FAIL: resolv/tst-resolv-noaaaa-vc
    FAIL: resolv/tst-resolv-res_init-multi
    FAIL: resolv/tst-resolv-search
    FAIL: resolv/tst-resolv-semi-failure
    FAIL: resolv/tst-resolv-short-response
    FAIL: resolv/tst-resolv-threads
    UNSUPPORTED: string/tst-strerror
    UNSUPPORTED: string/tst-strsignal
    UNSUPPORTED: time/tst-clock_settime
    UNSUPPORTED: time/tst-settimeofday

                    === Summary of results ===
        19 FAIL
      6643 PASS
        28 UNSUPPORTED
        16 XFAIL
         2 XPASS

---

Performance
----------
Measured overall performance improvements of the vectorized ("rvv")
implementations vs. the existing Glibc ("scalar") implementations are as
follows:
memccpy: 49% time savings (i.e., if scalar is 100ms, then rvv is 51ms)
memrchr: 58%
stpncpy: 11%
strrchr: 39%

Above data are collected on SpacemiT X60, with glibc existing benchtests.
The performance improvements for the rest of the routines are listed in[2].

---

Reference
----------
[1] https://inbox.sourceware.org/libc-alpha/20230504074851.38763-1-hau.hsu@sifive.com/
[2] https://inbox.sourceware.org/libc-alpha/20250930003543.86600-1-zihong.plct@isrc.iscas.ac.cn/

---

Yao Zihong (18):
  riscv: Add RVV memccpy for multiarch and non-multiarch
  riscv: Add RVV memchr for multiarch and non-multiarch
  riscv: Add RVV memcmp for multiarch and non-multiarch
  riscv: Add RVV memcmpeq for multiarch and non-multiarch
  riscv: Add RVV memcpy for multiarch and non-multiarch
  riscv: Add RVV memmove for multiarch and non-multiarch
  riscv: Add RVV memrchr for multiarch and non-multiarch
  riscv: Add RVV stpncpy for multiarch and non-multiarch
  riscv: Add RVV strcat for multiarch and non-multiarch
  riscv: Add RVV strchr for multiarch and non-multiarch
  riscv: Add RVV strcmp for multiarch and non-multiarch
  riscv: Add RVV strcpy for multiarch and non-multiarch
  riscv: Add RVV strlen for multiarch and non-multiarch
  riscv: Add RVV strncat for multiarch and non-multiarch
  riscv: Add RVV strncmp for multiarch and non-multiarch
  riscv: Add RVV strncpy for multiarch and non-multiarch
  riscv: Add RVV strnlen for multiarch and non-multiarch
  riscv: Add RVV strrchr for multiarch and non-multiarch

 .../riscv/multiarch/dl-symbol-redir-ifunc.h   |   1 +
 sysdeps/riscv/multiarch/memccpy-generic.c     |  26 ++++
 sysdeps/riscv/multiarch/memccpy-vector.S      |  24 ++++
 sysdeps/riscv/multiarch/memchr-generic.c      |  24 ++++
 sysdeps/riscv/multiarch/memchr-vector.S       |  26 ++++
 sysdeps/riscv/multiarch/memcmp-generic.c      |  30 +++++
 sysdeps/riscv/multiarch/memcmp-vector.S       |  30 +++++
 sysdeps/riscv/multiarch/memcmpeq-generic.c    |  30 +++++
 sysdeps/riscv/multiarch/memcmpeq-vector.S     |  30 +++++
 sysdeps/riscv/multiarch/memcpy-vector.S       |  24 ++++
 sysdeps/riscv/multiarch/memmove-generic.c     |  26 ++++
 sysdeps/riscv/multiarch/memmove-vector.S      |  24 ++++
 sysdeps/riscv/multiarch/memrchr-generic.c     |  28 ++++
 sysdeps/riscv/multiarch/memrchr-vector.S      |  28 ++++
 sysdeps/riscv/multiarch/stpncpy-generic.c     |  28 ++++
 sysdeps/riscv/multiarch/stpncpy-vector.S      |  28 ++++
 sysdeps/riscv/multiarch/strcat-generic.c      |  26 ++++
 sysdeps/riscv/multiarch/strcat-vector.S       |  24 ++++
 sysdeps/riscv/multiarch/strchr-generic.c      |  24 ++++
 sysdeps/riscv/multiarch/strchr-vector.S       |  26 ++++
 sysdeps/riscv/multiarch/strcmp-generic.c      |  24 ++++
 sysdeps/riscv/multiarch/strcmp-vector.S       |  24 ++++
 sysdeps/riscv/multiarch/strcpy-generic.c      |  26 ++++
 sysdeps/riscv/multiarch/strcpy-vector.S       |  24 ++++
 sysdeps/riscv/multiarch/strlen-generic.c      |  24 ++++
 sysdeps/riscv/multiarch/strlen-vector.S       |  26 ++++
 sysdeps/riscv/multiarch/strncat-generic.c     |  26 ++++
 sysdeps/riscv/multiarch/strncat-vector.S      |  24 ++++
 sysdeps/riscv/multiarch/strncmp-generic.c     |  26 ++++
 sysdeps/riscv/multiarch/strncmp-vector.S      |  24 ++++
 sysdeps/riscv/multiarch/strncpy-generic.c     |  26 ++++
 sysdeps/riscv/multiarch/strncpy-vector.S      |  24 ++++
 sysdeps/riscv/multiarch/strnlen-generic.c     |  24 ++++
 sysdeps/riscv/multiarch/strnlen-vector.S      |  26 ++++
 sysdeps/riscv/multiarch/strrchr-generic.c     |  28 ++++
 sysdeps/riscv/multiarch/strrchr-vector.S      |  26 ++++
 sysdeps/riscv/riscv-ifunc.h                   |   4 +
 sysdeps/riscv/rvv/memccpy.S                   |  67 ++++++++++
 sysdeps/riscv/rvv/memchr.S                    |  67 ++++++++++
 sysdeps/riscv/rvv/memcmp.S                    |  84 ++++++++++++
 sysdeps/riscv/rvv/memcmpeq.S                  |  67 ++++++++++
 sysdeps/riscv/rvv/memcpy.S                    |  54 ++++++++
 sysdeps/riscv/rvv/memmove.S                   |  74 +++++++++++
 sysdeps/riscv/rvv/memrchr.S                   |  71 ++++++++++
 sysdeps/riscv/rvv/stpncpy.S                   | 114 ++++++++++++++++
 sysdeps/riscv/rvv/strcat.S                    |  75 +++++++++++
 sysdeps/riscv/rvv/strchr.S                    |  65 +++++++++
 sysdeps/riscv/rvv/strcmp.S                    |  93 +++++++++++++
 sysdeps/riscv/rvv/strcpy.S                    |  59 +++++++++
 sysdeps/riscv/rvv/strlen.S                    |  58 +++++++++
 sysdeps/riscv/rvv/strncat.S                   |  81 ++++++++++++
 sysdeps/riscv/rvv/strncmp.S                   |  88 +++++++++++++
 sysdeps/riscv/rvv/strncpy.S                   |  20 +++
 sysdeps/riscv/rvv/strnlen.S                   |  61 +++++++++
 sysdeps/riscv/rvv/strrchr.S                   | 123 ++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  52 ++++++++
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  87 +++++++++++++
 .../unix/sysv/linux/riscv/multiarch/memccpy.c |  58 +++++++++
 .../unix/sysv/linux/riscv/multiarch/memchr.c  |  57 ++++++++
 .../unix/sysv/linux/riscv/multiarch/memcmp.c  |  60 +++++++++
 .../sysv/linux/riscv/multiarch/memcmpeq.c     |  50 +++++++
 .../unix/sysv/linux/riscv/multiarch/memcpy.c  |   5 +
 .../unix/sysv/linux/riscv/multiarch/memmove.c |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/memrchr.c |  50 +++++++
 .../unix/sysv/linux/riscv/multiarch/stpncpy.c |  58 +++++++++
 .../unix/sysv/linux/riscv/multiarch/strcat.c  |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strchr.c  |  58 +++++++++
 .../unix/sysv/linux/riscv/multiarch/strcmp.c  |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strcpy.c  |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strlen.c  |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strncat.c |  52 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strncmp.c |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strncpy.c |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strnlen.c |  56 ++++++++
 .../unix/sysv/linux/riscv/multiarch/strrchr.c |  59 +++++++++
 75 files changed, 3328 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memccpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memccpy-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memchr-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memcmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memcmp-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memcmpeq-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memcmpeq-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memcpy-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memmove-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memmove-vector.S
 create mode 100644 sysdeps/riscv/multiarch/memrchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memrchr-vector.S
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strcat-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcat-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strchr-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcmp-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strcpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcpy-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strlen-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strlen-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strncat-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncat-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncmp-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncpy-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strnlen-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strnlen-vector.S
 create mode 100644 sysdeps/riscv/multiarch/strrchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strrchr-vector.S
 create mode 100644 sysdeps/riscv/rvv/memccpy.S
 create mode 100644 sysdeps/riscv/rvv/memchr.S
 create mode 100644 sysdeps/riscv/rvv/memcmp.S
 create mode 100644 sysdeps/riscv/rvv/memcmpeq.S
 create mode 100644 sysdeps/riscv/rvv/memcpy.S
 create mode 100644 sysdeps/riscv/rvv/memmove.S
 create mode 100644 sysdeps/riscv/rvv/memrchr.S
 create mode 100644 sysdeps/riscv/rvv/stpncpy.S
 create mode 100644 sysdeps/riscv/rvv/strcat.S
 create mode 100644 sysdeps/riscv/rvv/strchr.S
 create mode 100644 sysdeps/riscv/rvv/strcmp.S
 create mode 100644 sysdeps/riscv/rvv/strcpy.S
 create mode 100644 sysdeps/riscv/rvv/strlen.S
 create mode 100644 sysdeps/riscv/rvv/strncat.S
 create mode 100644 sysdeps/riscv/rvv/strncmp.S
 create mode 100644 sysdeps/riscv/rvv/strncpy.S
 create mode 100644 sysdeps/riscv/rvv/strnlen.S
 create mode 100644 sysdeps/riscv/rvv/strrchr.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memccpy.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memcmp.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memcmpeq.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memmove.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strchr.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strnlen.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strrchr.c

-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-05  2:02   ` [EXT] " Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 02/18] riscv: Add RVV memchr " Yao Zihong
                   ` (18 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong

Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memccpy-generic.c     | 26 +++++++
 sysdeps/riscv/multiarch/memccpy-vector.S      | 24 +++++++
 sysdeps/riscv/rvv/memccpy.S                   | 67 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/memccpy.c | 58 ++++++++++++++++
 6 files changed, 183 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memccpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memccpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/memccpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memccpy.c

diff --git a/sysdeps/riscv/multiarch/memccpy-generic.c b/sysdeps/riscv/multiarch/memccpy-generic.c
new file mode 100644
index 0000000000..d7e6e2d847
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memccpy-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default memccpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMCCPY __memccpy_generic
+# undef weak_alias
+# define weak_alias(x, x2)
+# include <string/memccpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memccpy-vector.S b/sysdeps/riscv/multiarch/memccpy-vector.S
new file mode 100644
index 0000000000..8ea121e444
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memccpy-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based memccpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMCCPY __memccpy_vector
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/memccpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memccpy.S b/sysdeps/riscv/rvv/memccpy.S
new file mode 100644
index 0000000000..5854d463c2
--- /dev/null
+++ b/sysdeps/riscv/rvv/memccpy.S
@@ -0,0 +1,67 @@
+/* RISC-V RVV based memccpy.
+   Copyright (C) 2026 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>
+
+#ifndef MEMCCPY
+# define MEMCCPY __memccpy
+#endif
+
+#define dst a0
+#define src a1
+#define c_val a2
+#define num a3
+
+#define ivl a4
+#define dst_ptr a5
+#define vfirst_idx a6
+
+#define ELEM_LMUL_SETTING m8
+#define vdata v0
+#define vmask v8
+
+ENTRY (MEMCCPY)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+L(loop):
+    vsetvli zero, num, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vdata, (src)
+
+    vmseq.vx vmask, vdata, c_val
+    vfirst.m vfirst_idx, vmask
+    csrr ivl, vl
+    bgez vfirst_idx, L(found)
+    vse8.v vdata, (dst_ptr)
+
+    sub num, num, ivl
+    add src, src, ivl
+    add dst_ptr, dst_ptr, ivl
+    bnez num, L(loop)
+    mv a0, zero
+    ret
+L(found):
+    addi vfirst_idx, vfirst_idx, 1
+    vsetvli zero, vfirst_idx, e8, ELEM_LMUL_SETTING, ta, ma
+    vse8.v vdata, (dst_ptr)
+    add a0, dst_ptr, vfirst_idx
+    ret
+.option pop
+END (MEMCCPY)
+weak_alias (MEMCCPY, memccpy)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 1d26966ded..0c1c2b4467 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -1,5 +1,8 @@
 ifeq ($(subdir),string)
 sysdep_routines += \
+  memccpy \
+  memccpy-generic \
+  memccpy-vector \
   memcpy \
   memcpy-generic \
   memcpy_noalignment \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index a3b5731411..cd9460f57e 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -53,5 +53,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memset_vector)
 	      IFUNC_IMPL_ADD (array, i, memset, 1, __memset_generic))
 
+  IFUNC_IMPL (i, name, memccpy,
+	      IFUNC_IMPL_ADD (array, i, memccpy, rvv_enabled,
+			      __memccpy_vector)
+	      IFUNC_IMPL_ADD (array, i, memccpy, 1, __memccpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memccpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memccpy.c
new file mode 100644
index 0000000000..84d300b3cc
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memccpy.c
@@ -0,0 +1,58 @@
+/* Multiple versions of memccpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine memccpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef memccpy
+# define memccpy __redirect_memccpy
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_memccpy) __libc_memccpy;
+
+extern __typeof (__redirect_memccpy) __memccpy_generic attribute_hidden;
+extern __typeof (__redirect_memccpy) __memccpy_vector attribute_hidden;
+
+static inline __typeof (__redirect_memccpy) *
+select_memccpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long v;
+
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memccpy_vector;
+
+  return __memccpy_generic;
+}
+
+riscv_libc_ifunc (__libc_memccpy, select_memccpy_ifunc);
+
+# undef memccpy
+weak_alias (__libc_memccpy, memccpy);
+# ifdef SHARED
+__hidden_ver1 (memccpy, __GI_memccpy, __redirect_memccpy)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memccpy);
+# endif
+#else
+# include <string/memccpy.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 02/18] riscv: Add RVV memchr for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-05  2:03   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 03/18] riscv: Add RVV memcmp " Yao Zihong
                   ` (17 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memchr-generic.c      | 24 +++++++
 sysdeps/riscv/multiarch/memchr-vector.S       | 26 +++++++
 sysdeps/riscv/rvv/memchr.S                    | 67 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/memchr.c  | 57 ++++++++++++++++
 6 files changed, 182 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memchr-vector.S
 create mode 100644 sysdeps/riscv/rvv/memchr.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c

diff --git a/sysdeps/riscv/multiarch/memchr-generic.c b/sysdeps/riscv/multiarch/memchr-generic.c
new file mode 100644
index 0000000000..a95e16ee51
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memchr-generic.c
@@ -0,0 +1,24 @@
+/* Re-include the default memchr implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMCHR __memchr_generic
+# include <string/memchr.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memchr-vector.S b/sysdeps/riscv/multiarch/memchr-vector.S
new file mode 100644
index 0000000000..951f256245
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memchr-vector.S
@@ -0,0 +1,26 @@
+/* Re-include the RISC-V RVV based memchr implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMCHR __memchr_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/memchr.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memchr.S b/sysdeps/riscv/rvv/memchr.S
new file mode 100644
index 0000000000..609b2f94c1
--- /dev/null
+++ b/sysdeps/riscv/rvv/memchr.S
@@ -0,0 +1,67 @@
+/* RISC-V RVV based memchr.
+   Copyright (C) 2026 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>
+
+#ifndef MEMCHR
+# define MEMCHR __memchr
+#endif
+
+#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)
+.option push
+.option arch, +v
+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
+.option pop
+END (MEMCHR)
+weak_alias (MEMCHR, memchr)
+libc_hidden_builtin_def (memchr)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 0c1c2b4467..4ad91c0744 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -3,6 +3,9 @@ sysdep_routines += \
   memccpy \
   memccpy-generic \
   memccpy-vector \
+  memchr \
+  memchr-generic \
+  memchr-vector \
   memcpy \
   memcpy-generic \
   memcpy_noalignment \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index cd9460f57e..65a4b664b2 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -58,5 +58,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memccpy_vector)
 	      IFUNC_IMPL_ADD (array, i, memccpy, 1, __memccpy_generic))
 
+  IFUNC_IMPL (i, name, memchr,
+	      IFUNC_IMPL_ADD (array, i, memchr, rvv_enabled,
+			      __memchr_vector)
+	      IFUNC_IMPL_ADD (array, i, memchr, 1, __memchr_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c
new file mode 100644
index 0000000000..0844a33760
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c
@@ -0,0 +1,57 @@
+/* Multiple versions of memchr.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine memchr so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef memchr
+# define memchr __redirect_memchr
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_memchr) __libc_memchr;
+
+extern __typeof (__redirect_memchr) __memchr_generic attribute_hidden;
+extern __typeof (__redirect_memchr) __memchr_vector attribute_hidden;
+
+static inline __typeof (__redirect_memchr) *
+select_memchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memchr_vector;
+  return __memchr_generic;
+}
+
+riscv_libc_ifunc (__libc_memchr, select_memchr_ifunc);
+
+# undef memchr
+strong_alias (__libc_memchr, memchr);
+strong_alias (memchr, __memchr)
+# ifdef SHARED
+__hidden_ver1 (memchr, __GI_memchr, __redirect_memchr)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memchr);
+# endif
+#else
+# include <string/memchr.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 02/18] riscv: Add RVV memchr " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-05  0:06   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 04/18] riscv: Add RVV memcmpeq " Yao Zihong
                   ` (16 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memcmp-generic.c      | 30 +++++++
 sysdeps/riscv/multiarch/memcmp-vector.S       | 30 +++++++
 sysdeps/riscv/rvv/memcmp.S                    | 84 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/memcmp.c  | 60 +++++++++++++
 6 files changed, 212 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memcmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memcmp-vector.S
 create mode 100644 sysdeps/riscv/rvv/memcmp.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memcmp.c

diff --git a/sysdeps/riscv/multiarch/memcmp-generic.c b/sysdeps/riscv/multiarch/memcmp-generic.c
new file mode 100644
index 0000000000..14f6752406
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memcmp-generic.c
@@ -0,0 +1,30 @@
+/* Re-include the default memcmp implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMCMP __memcmp_generic
+# undef libc_hidden_def
+# define libc_hidden_def(x)
+# undef weak_alias
+# define weak_alias(x, x2)
+# undef strong_alias
+# define strong_alias(x, x2)
+# include <string/memcmp.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memcmp-vector.S b/sysdeps/riscv/multiarch/memcmp-vector.S
new file mode 100644
index 0000000000..b447e945a8
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memcmp-vector.S
@@ -0,0 +1,30 @@
+/* Re-include the RISC-V RVV based memcmp implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMCMP __memcmp_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# undef strong_alias
+# define strong_alias(name, alias)
+# include <sysdeps/riscv/rvv/memcmp.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memcmp.S b/sysdeps/riscv/rvv/memcmp.S
new file mode 100644
index 0000000000..004bf538f0
--- /dev/null
+++ b/sysdeps/riscv/rvv/memcmp.S
@@ -0,0 +1,84 @@
+/* RISC-V RVV based memcmp.
+   Copyright (C) 2026 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>
+
+#ifndef MEMCMP
+# define MEMCMP memcmp
+#endif
+
+#define result a0
+
+#define src1 a0
+#define src2 a1
+#define num a2
+
+#define ivl a3
+#define temp a4
+
+#define ELEM_LMUL_SETTING m8
+#define vdata1 v0
+#define vdata2 v8
+#define vmask v16
+#define vtemp1 v16
+#define vtemp2 v24
+
+ENTRY (MEMCMP)
+.option push
+.option arch, +v
+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
+
+    bgez temp, L(found)
+
+    add src1, src1, ivl
+    add src2, src2, ivl
+
+    bnez num, L(loop)
+
+    li result, 0
+    ret
+L(found):
+    vrgather.vx vtemp1, vdata1, temp
+    vrgather.vx vtemp2, vdata2, temp
+    vmv.x.s result, vtemp1
+    vmv.x.s temp, vtemp2
+    andi result, result, 0xff
+    andi temp, temp, 0xff
+    sub result, result, temp
+    ret
+.option pop
+END (MEMCMP)
+libc_hidden_builtin_def(memcmp)
+#ifdef weak_alias
+#undef bcmp
+weak_alias (MEMCMP, bcmp)
+#endif
+
+#undef __memcmpeq
+strong_alias (MEMCMP, __memcmpeq)
+libc_hidden_builtin_def (MEMCMP)
+libc_hidden_def (__memcmpeq)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 4ad91c0744..0edc677874 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -6,6 +6,9 @@ sysdep_routines += \
   memchr \
   memchr-generic \
   memchr-vector \
+  memcmp \
+  memcmp-generic \
+  memcmp-vector \
   memcpy \
   memcpy-generic \
   memcpy_noalignment \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 65a4b664b2..fe45e043e0 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -63,5 +63,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memchr_vector)
 	      IFUNC_IMPL_ADD (array, i, memchr, 1, __memchr_generic))
 
+  IFUNC_IMPL (i, name, memcmp,
+	      IFUNC_IMPL_ADD (array, i, memcmp, rvv_enabled,
+			      __memcmp_vector)
+	      IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memcmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memcmp.c
new file mode 100644
index 0000000000..20e7b046ab
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memcmp.c
@@ -0,0 +1,60 @@
+/* Multiple versions of memcmp.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine memcmp so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef memcmp
+# define memcmp __redirect_memcmp
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_memcmp) __libc_memcmp;
+
+extern __typeof (__redirect_memcmp) __memcmp_generic attribute_hidden;
+extern __typeof (__redirect_memcmp) __memcmp_vector attribute_hidden;
+
+static inline __typeof (__redirect_memcmp) *
+select_memcmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long v;
+
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memcmp_vector;
+
+  return __memcmp_generic;
+}
+
+riscv_libc_ifunc (__libc_memcmp, select_memcmp_ifunc);
+
+# undef memcmp
+# undef bcmp
+strong_alias (__libc_memcmp, memcmp);
+weak_alias (memcmp, bcmp);
+# ifdef SHARED
+__hidden_ver1 (memcmp, __GI_memcmp, __redirect_memcmp)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memcmp);
+# endif
+#else
+# include <string/memcmp.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 04/18] riscv: Add RVV memcmpeq for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (2 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 03/18] riscv: Add RVV memcmp " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-09 18:59   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 05/18] riscv: Add RVV memcpy " Yao Zihong
                   ` (15 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Yun Hsiang

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Yun Hsiang <yun.hsiang@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memcmpeq-generic.c    | 30 +++++++++
 sysdeps/riscv/multiarch/memcmpeq-vector.S     | 30 +++++++++
 sysdeps/riscv/riscv-ifunc.h                   |  4 ++
 sysdeps/riscv/rvv/memcmpeq.S                  | 67 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../sysv/linux/riscv/multiarch/memcmpeq.c     | 50 ++++++++++++++
 7 files changed, 189 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memcmpeq-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memcmpeq-vector.S
 create mode 100644 sysdeps/riscv/rvv/memcmpeq.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memcmpeq.c

diff --git a/sysdeps/riscv/multiarch/memcmpeq-generic.c b/sysdeps/riscv/multiarch/memcmpeq-generic.c
new file mode 100644
index 0000000000..11ed748d5e
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memcmpeq-generic.c
@@ -0,0 +1,30 @@
+/* Re-include the default memcmpeq implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMCMP ____memcmpeq_generic
+# undef libc_hidden_def
+# define libc_hidden_def(x)
+# undef weak_alias
+# define weak_alias(x, x2)
+# undef strong_alias
+# define strong_alias(x, x2)
+# include <string/memcmp.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memcmpeq-vector.S b/sysdeps/riscv/multiarch/memcmpeq-vector.S
new file mode 100644
index 0000000000..8619c9c968
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memcmpeq-vector.S
@@ -0,0 +1,30 @@
+/* Re-include the RISC-V RVV based memcmpeq implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMCMPEQ ____memcmpeq_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# undef strong_alias
+# define strong_alias(name, alias)
+# include <sysdeps/riscv/rvv/memcmpeq.S>
+#endif
diff --git a/sysdeps/riscv/riscv-ifunc.h b/sysdeps/riscv/riscv-ifunc.h
index 7782738576..59419f504d 100644
--- a/sysdeps/riscv/riscv-ifunc.h
+++ b/sysdeps/riscv/riscv-ifunc.h
@@ -25,3 +25,7 @@
 #define riscv_libc_ifunc(name, expr)				\
   __ifunc_args (name, name, expr(hwcap, hwprobe), INIT_ARCH,	\
                 uint64_t hwcap, __riscv_hwprobe_t hwprobe)
+
+#define riscv_libc_ifunc_redirected(redirected_name, name, expr)	\
+  __ifunc_args (redirected_name, name, expr(hwcap, hwprobe), INIT_ARCH,	\
+                uint64_t hwcap, __riscv_hwprobe_t hwprobe)
diff --git a/sysdeps/riscv/rvv/memcmpeq.S b/sysdeps/riscv/rvv/memcmpeq.S
new file mode 100644
index 0000000000..622c60a8d4
--- /dev/null
+++ b/sysdeps/riscv/rvv/memcmpeq.S
@@ -0,0 +1,67 @@
+/* RISC-V RVV based memcmpeq.
+   Copyright (C) 2026 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>
+
+#ifndef MEMCMPEQ
+# define MEMCMPEQ ____memcmpeq
+#endif
+
+#define result a0
+
+#define src1 a0
+#define src2 a1
+#define num a2
+
+#define ivl a3
+#define temp a4
+
+#define ELEM_LMUL_SETTING m1
+#define vdata1 v0
+#define vdata2 v8
+#define vmask v16
+
+ENTRY (MEMCMPEQ)
+.option push
+.option arch, +v
+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):
+    mv result, ivl
+    ret
+.option pop
+END (MEMCMPEQ)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 0edc677874..7cfb4f04dc 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -9,6 +9,9 @@ sysdep_routines += \
   memcmp \
   memcmp-generic \
   memcmp-vector \
+  memcmpeq \
+  memcmpeq-generic \
+  memcmpeq-vector \
   memcpy \
   memcpy-generic \
   memcpy_noalignment \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index fe45e043e0..6285a3cf0f 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -68,5 +68,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memcmp_vector)
 	      IFUNC_IMPL_ADD (array, i, memcmp, 1, __memcmp_generic))
 
+  IFUNC_IMPL (i, name, __memcmpeq,
+	      IFUNC_IMPL_ADD (array, i, __memcmpeq, rvv_enabled,
+			      ____memcmpeq_vector)
+	      IFUNC_IMPL_ADD (array, i, __memcmpeq, 1, ____memcmpeq_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memcmpeq.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memcmpeq.c
new file mode 100644
index 0000000000..e2dee7e459
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memcmpeq.c
@@ -0,0 +1,50 @@
+/* Multiple versions of __memcmpeq.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine __memcmpeq so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# define __memcmpeq __redirect___memcmpeq
+# include <stdint.h>
+# include <string.h>
+# undef __memcmpeq
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect___memcmpeq) ____memcmpeq_generic attribute_hidden;
+extern __typeof (__redirect___memcmpeq) ____memcmpeq_vector attribute_hidden;
+
+static inline __typeof (__redirect___memcmpeq) *
+select___memcmpeq_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long v;
+
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return ____memcmpeq_vector;
+  return ____memcmpeq_generic;
+}
+
+riscv_libc_ifunc_redirected (__redirect___memcmpeq, __memcmpeq, select___memcmpeq_ifunc);
+# ifdef SHARED
+__hidden_ver1 (__memcmpeq, __GI___memcmpeq, __redirect___memcmpeq)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (__memcmpeq);
+# endif
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 05/18] riscv: Add RVV memcpy for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (3 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 04/18] riscv: Add RVV memcmpeq " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-04-22 21:21   ` [EXT] " Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 06/18] riscv: Add RVV memmove " Yao Zihong
                   ` (14 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 .../riscv/multiarch/dl-symbol-redir-ifunc.h   |  1 +
 sysdeps/riscv/multiarch/memcpy-vector.S       | 24 +++++++++
 sysdeps/riscv/rvv/memcpy.S                    | 54 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  1 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  2 +
 .../unix/sysv/linux/riscv/multiarch/memcpy.c  |  5 ++
 6 files changed, 87 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memcpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/memcpy.S

diff --git a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
index 24b78711e3..230623a068 100644
--- a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
+++ b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
@@ -20,6 +20,7 @@
 #define _DL_IFUNC_GENERIC_H
 
 #ifndef SHARED
+asm ("memcpy = __memcpy_generic");
 asm ("memset = __memset_generic");
 #endif
 
diff --git a/sysdeps/riscv/multiarch/memcpy-vector.S b/sysdeps/riscv/multiarch/memcpy-vector.S
new file mode 100644
index 0000000000..97b80b8069
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memcpy-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based memcpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMCPY __memcpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/memcpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memcpy.S b/sysdeps/riscv/rvv/memcpy.S
new file mode 100644
index 0000000000..b4d600c59d
--- /dev/null
+++ b/sysdeps/riscv/rvv/memcpy.S
@@ -0,0 +1,54 @@
+/* RISC-V RVV based memcpy.
+   Copyright (C) 2026 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>
+
+#ifndef MEMCPY
+# define MEMCPY memcpy
+#endif
+
+#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)
+.option push
+.option arch, +v
+    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
+.option pop
+END (MEMCPY)
+libc_hidden_builtin_def (memcpy)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 7cfb4f04dc..0bf7c8e37d 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -14,6 +14,7 @@ sysdep_routines += \
   memcmpeq-vector \
   memcpy \
   memcpy-generic \
+  memcpy-vector \
   memcpy_noalignment \
   memset \
   memset-generic \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 6285a3cf0f..27a7817308 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -44,6 +44,8 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
   }
 
   IFUNC_IMPL (i, name, memcpy,
+	      IFUNC_IMPL_ADD (array, i, memcpy, rvv_enabled,
+			      __memcpy_vector)
 	      IFUNC_IMPL_ADD (array, i, memcpy, fast_unaligned,
 			      __memcpy_noalignment)
 	      IFUNC_IMPL_ADD (array, i, memcpy, 1, __memcpy_generic))
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
index f096693431..11919d815a 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memcpy.c
@@ -32,11 +32,16 @@ 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 (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memcpy_vector;
+
   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;
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (4 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 05/18] riscv: Add RVV memcpy " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-05-05  2:52   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 07/18] riscv: Add RVV memrchr " Yao Zihong
                   ` (13 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memmove-generic.c     | 26 +++++++
 sysdeps/riscv/multiarch/memmove-vector.S      | 24 ++++++
 sysdeps/riscv/rvv/memmove.S                   | 74 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/memmove.c | 56 ++++++++++++++
 6 files changed, 188 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memmove-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memmove-vector.S
 create mode 100644 sysdeps/riscv/rvv/memmove.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memmove.c

diff --git a/sysdeps/riscv/multiarch/memmove-generic.c b/sysdeps/riscv/multiarch/memmove-generic.c
new file mode 100644
index 0000000000..44c01c887a
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memmove-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default memmove implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMMOVE __memmove_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/memmove.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memmove-vector.S b/sysdeps/riscv/multiarch/memmove-vector.S
new file mode 100644
index 0000000000..6bf2d9f614
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memmove-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based memmove implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMMOVE __memmove_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/memmove.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memmove.S b/sysdeps/riscv/rvv/memmove.S
new file mode 100644
index 0000000000..5e41b13ec5
--- /dev/null
+++ b/sysdeps/riscv/rvv/memmove.S
@@ -0,0 +1,74 @@
+/* RISC-V RVV based memmove.
+   Copyright (C) 2026 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>
+
+#ifndef MEMMOVE
+# define MEMMOVE memmove
+#endif
+
+#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)
+.option push
+.option arch, +v
+    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
+.option pop
+END (MEMMOVE)
+libc_hidden_builtin_def (memmove)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 0bf7c8e37d..a0990c9ff1 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -16,6 +16,9 @@ sysdep_routines += \
   memcpy-generic \
   memcpy-vector \
   memcpy_noalignment \
+  memmove \
+  memmove-generic \
+  memmove-vector \
   memset \
   memset-generic \
   memset-vector \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 27a7817308..d955f56dba 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -75,5 +75,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      ____memcmpeq_vector)
 	      IFUNC_IMPL_ADD (array, i, __memcmpeq, 1, ____memcmpeq_generic))
 
+  IFUNC_IMPL (i, name, memmove,
+	      IFUNC_IMPL_ADD (array, i, memmove, rvv_enabled,
+			      __memmove_vector)
+	      IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memmove.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memmove.c
new file mode 100644
index 0000000000..670f108029
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memmove.c
@@ -0,0 +1,56 @@
+/* Multiple versions of memmove.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine memmove so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef memmove
+# define memmove __redirect_memmove
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_memmove) __libc_memmove;
+
+extern __typeof (__redirect_memmove) __memmove_generic attribute_hidden;
+extern __typeof (__redirect_memmove) __memmove_vector attribute_hidden;
+
+static inline __typeof (__redirect_memmove) *
+select_memmove_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memmove_vector;
+  return __memmove_generic;
+}
+
+riscv_libc_ifunc (__libc_memmove, select_memmove_ifunc);
+
+# undef memmove
+strong_alias (__libc_memmove, memmove);
+# ifdef SHARED
+__hidden_ver1 (memmove, __GI_memmove, __redirect_memmove)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (memmove);
+# endif
+#else
+# include <string/memmove.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 07/18] riscv: Add RVV memrchr for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (5 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 06/18] riscv: Add RVV memmove " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 08/18] riscv: Add RVV stpncpy " Yao Zihong
                   ` (12 subsequent siblings)
  19 siblings, 0 replies; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, daichengrong

Co-authored-by: daichengrong <daichengrong@iscas.ac.cn>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/memrchr-generic.c     | 28 ++++++++
 sysdeps/riscv/multiarch/memrchr-vector.S      | 28 ++++++++
 sysdeps/riscv/rvv/memrchr.S                   | 71 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/memrchr.c | 50 +++++++++++++
 6 files changed, 185 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/memrchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memrchr-vector.S
 create mode 100644 sysdeps/riscv/rvv/memrchr.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c

diff --git a/sysdeps/riscv/multiarch/memrchr-generic.c b/sysdeps/riscv/multiarch/memrchr-generic.c
new file mode 100644
index 0000000000..09766ac565
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memrchr-generic.c
@@ -0,0 +1,28 @@
+/* Re-include the default memrchr implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define MEMRCHR __memrchr_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(a, b)
+# include <string/memrchr.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/memrchr-vector.S b/sysdeps/riscv/multiarch/memrchr-vector.S
new file mode 100644
index 0000000000..1554c066aa
--- /dev/null
+++ b/sysdeps/riscv/multiarch/memrchr-vector.S
@@ -0,0 +1,28 @@
+/* Re-include the RISC-V RVV based memrchr implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define MEMRCHR __memrchr_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/memrchr.S>
+#endif
diff --git a/sysdeps/riscv/rvv/memrchr.S b/sysdeps/riscv/rvv/memrchr.S
new file mode 100644
index 0000000000..00df77e5d7
--- /dev/null
+++ b/sysdeps/riscv/rvv/memrchr.S
@@ -0,0 +1,71 @@
+/* RISC-V RVV based memrchr.
+   Copyright (C) 2026 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>
+
+#ifndef MEMRCHR
+# define MEMRCHR __memrchr
+#endif
+
+#define src a0
+#define ch a1
+#define num a2
+#define vl a3
+#define first_idx a4
+#define idx a5
+
+#define vmask v0
+#define vdata v8
+#define vidx v16
+#define vmax v24
+
+ENTRY (MEMRCHR)
+.option push
+.option arch, +v
+    add src, src, num
+L(loop):
+    beqz num, L(nohit)
+
+    vsetvli vl, num, e8, m4, ta, ma
+    sub src, src, vl
+    vle8.v vdata, (src)
+    sub num, num, vl
+
+    vmseq.vx vmask, vdata, ch
+    vfirst.m first_idx, vmask
+    bltz first_idx, L(loop)
+L(hit):
+    vsetvli zero, vl, e16, m8, ta, ma
+    vid.v vidx
+
+    /* reduce max index over hit lanes */
+    vmv.s.x vmax, x0
+    vredmaxu.vs vmax, vidx, vmax, vmask.t
+    vmv.x.s idx, vmax
+
+    add a0, src, idx
+    ret
+L(nohit):
+    li a0, 0
+    ret
+.option pop
+END (MEMRCHR)
+libc_hidden_def (MEMRCHR)
+weak_alias (MEMRCHR, memrchr)
+libc_hidden_builtin_def (memrchr)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index a0990c9ff1..190e853e6e 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -19,6 +19,9 @@ sysdep_routines += \
   memmove \
   memmove-generic \
   memmove-vector \
+  memrchr \
+  memrchr-generic \
+  memrchr-vector \
   memset \
   memset-generic \
   memset-vector \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index d955f56dba..53e76705df 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -80,5 +80,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memmove_vector)
 	      IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_generic))
 
+  IFUNC_IMPL (i, name, memrchr,
+	      IFUNC_IMPL_ADD (array, i, memrchr, rvv_enabled,
+			      __memrchr_vector)
+	      IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c
new file mode 100644
index 0000000000..310b8e14f0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c
@@ -0,0 +1,50 @@
+/* Multiple versions of memrchr.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine memrchr so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# define memrchr __redirect_memrchr
+# include <stdint.h>
+# include <string.h>
+# undef memrchr
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_memrchr) __memrchr_generic attribute_hidden;
+extern __typeof (__redirect_memrchr) __memrchr_vector attribute_hidden;
+
+static inline __typeof (__redirect_memrchr) *
+select_memrchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long v;
+
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __memrchr_vector;
+  return __memrchr_generic;
+}
+
+riscv_libc_ifunc_redirected (__redirect_memrchr, __memrchr, select_memrchr_ifunc);
+libc_hidden_def (__memrchr)
+weak_alias (__memrchr, memrchr)
+#else
+# include <string/memrchr.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 08/18] riscv: Add RVV stpncpy for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (6 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 07/18] riscv: Add RVV memrchr " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 09/18] riscv: Add RVV strcat " Yao Zihong
                   ` (11 subsequent siblings)
  19 siblings, 0 replies; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/stpncpy-generic.c     | 28 ++++++
 sysdeps/riscv/multiarch/stpncpy-vector.S      | 28 ++++++
 sysdeps/riscv/rvv/stpncpy.S                   | 97 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 +
 .../unix/sysv/linux/riscv/multiarch/stpncpy.c | 57 +++++++++++
 6 files changed, 218 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/stpncpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c

diff --git a/sysdeps/riscv/multiarch/stpncpy-generic.c b/sysdeps/riscv/multiarch/stpncpy-generic.c
new file mode 100644
index 0000000000..4be8080d88
--- /dev/null
+++ b/sysdeps/riscv/multiarch/stpncpy-generic.c
@@ -0,0 +1,28 @@
+/* Re-include the default stpncpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STPNCPY __stpncpy_generic
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(x, x2)
+# include <string/stpncpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/stpncpy-vector.S b/sysdeps/riscv/multiarch/stpncpy-vector.S
new file mode 100644
index 0000000000..e84d28a1e4
--- /dev/null
+++ b/sysdeps/riscv/multiarch/stpncpy-vector.S
@@ -0,0 +1,28 @@
+/* Re-include the RISC-V RVV based stpncpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STPNCPY __stpncpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/stpncpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/stpncpy.S b/sysdeps/riscv/rvv/stpncpy.S
new file mode 100644
index 0000000000..57406685b0
--- /dev/null
+++ b/sysdeps/riscv/rvv/stpncpy.S
@@ -0,0 +1,97 @@
+/* RISC-V RVV based stpncpy.
+   Copyright (C) 2026 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>
+
+#ifndef STPNCPY
+# ifdef weak_alias
+#  define STPNCPY __stpncpy
+weak_alias (__stpncpy, stpncpy)
+# else
+#  define STPNCPY stpncpy
+# endif
+#endif
+
+#define dst a0
+#define src a1
+#define length a2
+#define dst_ptr a3
+#define active_elem_pos a4
+#define cur_vl a5
+#define ivl a6
+#define temp a1
+
+#define ELEM_LMUL_SETTING m1
+#define vmask1 v0
+#define vmask2 v1
+#define ZERO_FILL_ELEM_LMUL_SETTING m8
+#define vstr1 v8
+#define vstr2 v16
+
+ENTRY (STPNCPY)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+    /* Copy src to dst_ptr.  */
+L(stpcpy_loop):
+    vsetvli zero, length, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr1, (src)
+    vmseq.vx vmask2, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m active_elem_pos, vmask2
+    vmsif.m vmask1, vmask2
+    add src, src, cur_vl
+    sub length, length, cur_vl
+    vse8.v vstr1, (dst_ptr), vmask1.t
+    add dst_ptr, dst_ptr, cur_vl
+    bgez active_elem_pos, L(fill_zero)
+    bnez length, L(stpcpy_loop)
+    mv dst, dst_ptr
+    ret
+
+    /* Fill the tail zero.  */
+L(fill_zero):
+    /* We already copy the `\0` to dst. But we use `vfirst.m` to
+    get the `index` of `\0` position. We need to adjust `-1`
+    to get the correct remaining length for zero filling. */
+    sub temp, cur_vl, active_elem_pos
+    addi temp, temp, -1
+    sub dst, dst_ptr, cur_vl
+    add dst, dst, active_elem_pos
+    add length, length, temp
+    /* Have an earily return for `strlen(src) + 1 == count` case.  */
+    bnez length, L(do_fill_zero)
+    ret
+
+L(do_fill_zero):
+    sub dst_ptr, dst_ptr, temp
+    vsetvli zero, length, e8, ZERO_FILL_ELEM_LMUL_SETTING, ta, ma
+    vmv.v.x vstr2, zero
+L(fill_zero_loop):
+    vsetvli ivl, length, e8, ZERO_FILL_ELEM_LMUL_SETTING, ta, ma
+    vse8.v vstr2, (dst_ptr)
+    sub length, length, ivl
+    add dst_ptr, dst_ptr, ivl
+    bnez length, L(fill_zero_loop)
+    ret
+.option pop
+END (STPNCPY)
+#ifdef weak_alias
+libc_hidden_def (__stpncpy)
+#endif
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 190e853e6e..38d96e8b11 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -25,6 +25,9 @@ sysdep_routines += \
   memset \
   memset-generic \
   memset-vector \
+  stpncpy \
+  stpncpy-generic \
+  stpncpy-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 53e76705df..ed3176d1cc 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -85,5 +85,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memrchr_vector)
 	      IFUNC_IMPL_ADD (array, i, memrchr, 1, __memrchr_generic))
 
+  IFUNC_IMPL (i, name, stpncpy,
+	      IFUNC_IMPL_ADD (array, i, stpncpy, rvv_enabled,
+			      __stpncpy_vector)
+	      IFUNC_IMPL_ADD (array, i, stpncpy, 1, __stpncpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
new file mode 100644
index 0000000000..e451391f1a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
@@ -0,0 +1,57 @@
+/* Multiple versions of stpncpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine stpncpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef stpncpy
+# define stpncpy __redirect_stpncpy
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_stpncpy) __libc_stpncpy;
+
+extern __typeof (__redirect_stpncpy) __stpncpy_generic attribute_hidden;
+extern __typeof (__redirect_stpncpy) __stpncpy_vector attribute_hidden;
+
+static inline __typeof (__redirect_stpncpy) *
+select_stpncpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __stpncpy_vector;
+  return __stpncpy_generic;
+}
+
+riscv_libc_ifunc (__libc_stpncpy, select_stpncpy_ifunc);
+
+# undef stpncpy
+weak_alias (__libc_stpncpy, stpncpy);
+libc_hidden_def (__stpncpy);
+# ifdef SHARED
+__hidden_ver1 (stpncpy, __GI_stpncpy, __redirect_stpncpy)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (stpncpy);
+# endif
+#else
+# include <string/stpncpy.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 09/18] riscv: Add RVV strcat for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (7 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 08/18] riscv: Add RVV stpncpy " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-04-20 15:37   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 10/18] riscv: Add RVV strchr " Yao Zihong
                   ` (10 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strcat-generic.c      | 26 +++++++
 sysdeps/riscv/multiarch/strcat-vector.S       | 24 ++++++
 sysdeps/riscv/rvv/strcat.S                    | 75 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strcat.c  | 56 ++++++++++++++
 6 files changed, 189 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strcat-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcat-vector.S
 create mode 100644 sysdeps/riscv/rvv/strcat.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c

diff --git a/sysdeps/riscv/multiarch/strcat-generic.c b/sysdeps/riscv/multiarch/strcat-generic.c
new file mode 100644
index 0000000000..e28f8f012c
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcat-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strcat implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRCAT __strcat_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strcat.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strcat-vector.S b/sysdeps/riscv/multiarch/strcat-vector.S
new file mode 100644
index 0000000000..581f075fef
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcat-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strcat implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRCAT __strcat_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/strcat.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strcat.S b/sysdeps/riscv/rvv/strcat.S
new file mode 100644
index 0000000000..af08ee561f
--- /dev/null
+++ b/sysdeps/riscv/rvv/strcat.S
@@ -0,0 +1,75 @@
+/* RISC-V RVV based strcat.
+   Copyright (C) 2026 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>
+
+#ifndef STRCAT
+# define STRCAT strcat
+#endif
+
+#define dst a0
+#define src a1
+#define dst_ptr a2
+
+#define ivl a3
+#define cur_vl a4
+#define active_elem_pos a5
+
+#define ELEM_LMUL_SETTING m1
+#define vmask1 v0
+#define vmask2 v1
+#define vstr1 v8
+#define vstr2 v16
+
+ENTRY (STRCAT)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+    /* Perform `strlen(dst)`.  */
+L(strlen_loop):
+    vsetvli ivl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8ff.v vstr1, (dst_ptr)
+    vmseq.vx vmask1, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m active_elem_pos, vmask1
+    add dst_ptr, dst_ptr, cur_vl
+    bltz active_elem_pos, L(strlen_loop)
+
+    sub dst_ptr, dst_ptr, cur_vl
+    add dst_ptr, dst_ptr, active_elem_pos
+
+    /* Perform `strcpy(dst, src)`.  */
+L(strcpy_loop):
+    vsetvli ivl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8ff.v vstr1, (src)
+    vmseq.vx vmask2, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m active_elem_pos, vmask2
+    vmsif.m vmask1, vmask2
+    add src, src, cur_vl
+    vse8.v vstr1, (dst_ptr), vmask1.t
+    add dst_ptr, dst_ptr, cur_vl
+    bltz active_elem_pos, L(strcpy_loop)
+
+    ret
+.option pop
+END (STRCAT)
+libc_hidden_builtin_def (strcat)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 38d96e8b11..17824370f7 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -28,6 +28,9 @@ sysdep_routines += \
   stpncpy \
   stpncpy-generic \
   stpncpy-vector \
+  strcat \
+  strcat-generic \
+  strcat-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index ed3176d1cc..113a0f9c8f 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -90,5 +90,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __stpncpy_vector)
 	      IFUNC_IMPL_ADD (array, i, stpncpy, 1, __stpncpy_generic))
 
+  IFUNC_IMPL (i, name, strcat,
+	      IFUNC_IMPL_ADD (array, i, strcat, rvv_enabled,
+			      __strcat_vector)
+	      IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c
new file mode 100644
index 0000000000..781b0d4cb1
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strcat.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strcat so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strcat
+# define strcat __redirect_strcat
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strcat) __libc_strcat;
+
+extern __typeof (__redirect_strcat) __strcat_generic attribute_hidden;
+extern __typeof (__redirect_strcat) __strcat_vector attribute_hidden;
+
+static inline __typeof (__redirect_strcat) *
+select_strcat_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strcat_vector;
+  return __strcat_generic;
+}
+
+riscv_libc_ifunc (__libc_strcat, select_strcat_ifunc);
+
+# undef strcat
+strong_alias (__libc_strcat, strcat);
+# ifdef SHARED
+__hidden_ver1 (strcat, __GI_strcat, __redirect_strcat)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strcat);
+# endif
+#else
+# include <string/strcat.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 10/18] riscv: Add RVV strchr for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (8 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 09/18] riscv: Add RVV strcat " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-05  2:04   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 11/18] riscv: Add RVV strcmp " Yao Zihong
                   ` (9 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Nick Knight

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Nick Knight <nick.knight@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strchr-generic.c      | 24 +++++++
 sysdeps/riscv/multiarch/strchr-vector.S       | 26 ++++++++
 sysdeps/riscv/rvv/strchr.S                    | 65 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strchr.c  | 58 +++++++++++++++++
 6 files changed, 181 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strchr-vector.S
 create mode 100644 sysdeps/riscv/rvv/strchr.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strchr.c

diff --git a/sysdeps/riscv/multiarch/strchr-generic.c b/sysdeps/riscv/multiarch/strchr-generic.c
new file mode 100644
index 0000000000..301b7dc64b
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strchr-generic.c
@@ -0,0 +1,24 @@
+/* Re-include the default strchr implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRCHR __strchr_generic
+# include <string/strchr.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strchr-vector.S b/sysdeps/riscv/multiarch/strchr-vector.S
new file mode 100644
index 0000000000..c55a1f993f
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strchr-vector.S
@@ -0,0 +1,26 @@
+/* Re-include the RISC-V RVV based strchr implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRCHR __strchr_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/strchr.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strchr.S b/sysdeps/riscv/rvv/strchr.S
new file mode 100644
index 0000000000..2fa95c31ba
--- /dev/null
+++ b/sysdeps/riscv/rvv/strchr.S
@@ -0,0 +1,65 @@
+/* RISC-V RVV based strchr.
+   Copyright (C) 2026 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>
+
+#ifndef STRCHR
+# define STRCHR strchr
+#endif
+
+#define str a0
+#define ch a1
+#define end_offset a2
+#define ch_offset a3
+#define temp1 a4
+#define temp2 a5
+#define cur_vl a6
+#define ivl t0
+
+#define ELEM_LMUL_SETTING m1
+#define vstr v0
+#define vmask_end v8
+#define vmask_ch v9
+
+ENTRY (STRCHR)
+.option push
+.option arch, +v
+L(strchr_loop):
+    vsetvli ivl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr, (str)
+    vmseq.vi vmask_end, vstr, 0
+    vmseq.vx vmask_ch, vstr, ch
+    vfirst.m end_offset, vmask_end /* first occurrence of \0 */
+    vfirst.m ch_offset, vmask_ch /* first occurrence of ch */
+    sltz temp1, ch_offset
+    sltu temp2, end_offset, ch_offset
+    or temp1, temp1, temp2
+    beqz temp1, L(found_ch) /* Found ch, not preceded by \0? */
+    csrr cur_vl, vl
+    add str, str, cur_vl
+    bltz end_offset, L(strchr_loop) /* Didn't find \0? */
+    li str, 0
+    ret
+L(found_ch):
+    add str, str, ch_offset
+    ret
+.option pop
+END (STRCHR)
+weak_alias (STRCHR, index)
+libc_hidden_builtin_def (strchr)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 17824370f7..f3155f41c4 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -31,6 +31,9 @@ sysdep_routines += \
   strcat \
   strcat-generic \
   strcat-vector \
+  strchr \
+  strchr-generic \
+  strchr-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 113a0f9c8f..3d059a33e4 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -95,5 +95,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strcat_vector)
 	      IFUNC_IMPL_ADD (array, i, strcat, 1, __strcat_generic))
 
+  IFUNC_IMPL (i, name, strchr,
+	      IFUNC_IMPL_ADD (array, i, strchr, rvv_enabled,
+			      __strchr_vector)
+	      IFUNC_IMPL_ADD (array, i, strchr, 1, __strchr_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strchr.c
new file mode 100644
index 0000000000..ef75a2b0a9
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strchr.c
@@ -0,0 +1,58 @@
+/* Multiple versions of strchr.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strchr so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strchr
+# define strchr __redirect_strchr
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strchr) __libc_strchr;
+
+extern __typeof (__redirect_strchr) __strchr_generic attribute_hidden;
+extern __typeof (__redirect_strchr) __strchr_vector attribute_hidden;
+
+static inline __typeof (__redirect_strchr) *
+select_strchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strchr_vector;
+  return __strchr_generic;
+}
+
+riscv_libc_ifunc (__libc_strchr, select_strchr_ifunc);
+
+# undef strchr
+# undef index
+strong_alias (__libc_strchr, strchr);
+weak_alias (strchr, index);
+# ifdef SHARED
+__hidden_ver1 (strchr, __GI_strchr, __redirect_strchr)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strchr);
+# endif
+#else
+# include <string/strchr.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 11/18] riscv: Add RVV strcmp for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (9 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 10/18] riscv: Add RVV strchr " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-05-06 19:15   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 12/18] riscv: Add RVV strcpy " Yao Zihong
                   ` (8 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strcmp-generic.c      | 24 +++++
 sysdeps/riscv/multiarch/strcmp-vector.S       | 24 +++++
 sysdeps/riscv/rvv/strcmp.S                    | 93 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 +
 .../unix/sysv/linux/riscv/multiarch/strcmp.c  | 56 +++++++++++
 6 files changed, 205 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcmp-vector.S
 create mode 100644 sysdeps/riscv/rvv/strcmp.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c

diff --git a/sysdeps/riscv/multiarch/strcmp-generic.c b/sysdeps/riscv/multiarch/strcmp-generic.c
new file mode 100644
index 0000000000..8ef46a44b9
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcmp-generic.c
@@ -0,0 +1,24 @@
+/* Re-include the default strcmp implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRCMP __strcmp_generic
+# include <string/strcmp.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strcmp-vector.S b/sysdeps/riscv/multiarch/strcmp-vector.S
new file mode 100644
index 0000000000..b9d9074b24
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcmp-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strcmp implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRCMP __strcmp_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/strcmp.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strcmp.S b/sysdeps/riscv/rvv/strcmp.S
new file mode 100644
index 0000000000..ad672591d4
--- /dev/null
+++ b/sysdeps/riscv/rvv/strcmp.S
@@ -0,0 +1,93 @@
+/* RISC-V RVV based strcmp.
+   Copyright (C) 2026 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>
+
+#ifndef STRCMP
+# define STRCMP strcmp
+#endif
+
+#define result a0
+
+#define str1 a0
+#define str2 a1
+
+#define ivl a2
+#define temp1 a3
+#define temp2 a4
+
+#define vstr1 v0
+#define vstr2 v8
+#define vmask1 v16
+#define vmask2 v17
+
+ENTRY (STRCMP)
+.option push
+.option arch, +v
+    /* lmul=1 */
+L(Loop):
+    vsetvli ivl, zero, e8, m1, ta, ma
+    vle8ff.v vstr1, (str1)
+    /* check if vstr1[i] == 0 */
+    vmseq.vx vmask1, vstr1, zero
+
+    vle8ff.v vstr2, (str2)
+    /* check if vstr1[i] != vstr2[i] */
+    vmsne.vv vmask2, vstr1, vstr2
+
+    /* find the index x for vstr1[x]==0 */
+    vfirst.m temp1, vmask1
+    /* find the index x for vstr1[x]!=vstr2[x] */
+    vfirst.m temp2, vmask2
+
+    bgez temp1, L(check1)
+    bgez temp2, L(check2)
+
+    /* get the current vl updated by vle8ff. */
+    csrr ivl, vl
+    add str1, str1, ivl
+    add str2, str2, ivl
+    j L(Loop)
+
+    /* temp1>=0 */
+L(check1):
+    bltz temp2, L(return_at_nul)
+    blt temp2, temp1, L(check2)
+L(return_at_nul):
+    /* temp2<0 */
+    /* temp2>=0 && temp1<temp2 */
+    add str1, str1, temp1
+    add str2, str2, temp1
+    lbu temp1, 0(str1)
+    lbu temp2, 0(str2)
+    sub result, temp1, temp2
+    ret
+
+    /* temp1<0 */
+    /* temp2>=0 */
+L(check2):
+    add str1, str1, temp2
+    add str2, str2, temp2
+    lbu temp1, 0(str1)
+    lbu temp2, 0(str2)
+    sub result, temp1, temp2
+    ret
+.option pop
+END (STRCMP)
+libc_hidden_builtin_def (strcmp)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index f3155f41c4..3dfee5799c 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -34,6 +34,9 @@ sysdep_routines += \
   strchr \
   strchr-generic \
   strchr-vector \
+  strcmp \
+  strcmp-generic \
+  strcmp-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 3d059a33e4..872e8d12a7 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -100,5 +100,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strchr_vector)
 	      IFUNC_IMPL_ADD (array, i, strchr, 1, __strchr_generic))
 
+  IFUNC_IMPL (i, name, strcmp,
+	      IFUNC_IMPL_ADD (array, i, strcmp, rvv_enabled,
+			      __strcmp_vector)
+	      IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c
new file mode 100644
index 0000000000..9398ad4024
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strcmp.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strcmp so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strcmp
+# define strcmp __redirect_strcmp
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strcmp) __libc_strcmp;
+
+extern __typeof (__redirect_strcmp) __strcmp_generic attribute_hidden;
+extern __typeof (__redirect_strcmp) __strcmp_vector attribute_hidden;
+
+static inline __typeof (__redirect_strcmp) *
+select_strcmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strcmp_vector;
+  return __strcmp_generic;
+}
+
+riscv_libc_ifunc (__libc_strcmp, select_strcmp_ifunc);
+
+# undef strcmp
+strong_alias (__libc_strcmp, strcmp);
+# ifdef SHARED
+__hidden_ver1 (strcmp, __GI_strcmp, __redirect_strcmp)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strcmp);
+# endif
+#else
+# include <string/strcmp.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 12/18] riscv: Add RVV strcpy for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (10 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 11/18] riscv: Add RVV strcmp " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-04-21  0:48   ` [EXT] " Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 13/18] riscv: Add RVV strlen " Yao Zihong
                   ` (7 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strcpy-generic.c      | 26 ++++++++
 sysdeps/riscv/multiarch/strcpy-vector.S       | 24 ++++++++
 sysdeps/riscv/rvv/strcpy.S                    | 59 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strcpy.c  | 56 ++++++++++++++++++
 6 files changed, 173 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strcpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/strcpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c

diff --git a/sysdeps/riscv/multiarch/strcpy-generic.c b/sysdeps/riscv/multiarch/strcpy-generic.c
new file mode 100644
index 0000000000..8a29992570
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcpy-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strcpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRCPY __strcpy_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strcpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strcpy-vector.S b/sysdeps/riscv/multiarch/strcpy-vector.S
new file mode 100644
index 0000000000..f5381a98ce
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strcpy-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strcpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRCPY __strcpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/strcpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strcpy.S b/sysdeps/riscv/rvv/strcpy.S
new file mode 100644
index 0000000000..e73558d812
--- /dev/null
+++ b/sysdeps/riscv/rvv/strcpy.S
@@ -0,0 +1,59 @@
+/* RISC-V RVV based strcpy.
+   Copyright (C) 2026 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>
+
+#ifndef STRCPY
+# define STRCPY strcpy
+#endif
+
+#define dst a0
+#define src a1
+#define dst_ptr a2
+
+#define ivl a3
+#define cur_vl a4
+#define active_elem_pos a5
+
+#define ELEM_LMUL_SETTING m1
+#define vmask1 v0
+#define vmask2 v1
+#define vstr1 v8
+#define vstr2 v16
+
+ENTRY (STRCPY)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+L(strcpy_loop):
+    vsetvli ivl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr1, (src)
+    vmseq.vx vmask2, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m active_elem_pos, vmask2
+    vmsif.m vmask1, vmask2
+    add src, src, cur_vl
+    vse8.v vstr1, (dst_ptr), vmask1.t
+    add dst_ptr, dst_ptr, cur_vl
+    bltz active_elem_pos, L(strcpy_loop)
+
+    ret
+.option pop
+END (STRCPY)
+libc_hidden_builtin_def (strcpy)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 3dfee5799c..5bbd789d46 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -37,6 +37,9 @@ sysdep_routines += \
   strcmp \
   strcmp-generic \
   strcmp-vector \
+  strcpy \
+  strcpy-generic \
+  strcpy-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 872e8d12a7..3f00942167 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -105,5 +105,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strcmp_vector)
 	      IFUNC_IMPL_ADD (array, i, strcmp, 1, __strcmp_generic))
 
+  IFUNC_IMPL (i, name, strcpy,
+	      IFUNC_IMPL_ADD (array, i, strcpy, rvv_enabled,
+			      __strcpy_vector)
+	      IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c
new file mode 100644
index 0000000000..ba47e8f89c
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strcpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strcpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strcpy
+# define strcpy __redirect_strcpy
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strcpy) __libc_strcpy;
+
+extern __typeof (__redirect_strcpy) __strcpy_generic attribute_hidden;
+extern __typeof (__redirect_strcpy) __strcpy_vector attribute_hidden;
+
+static inline __typeof (__redirect_strcpy) *
+select_strcpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strcpy_vector;
+  return __strcpy_generic;
+}
+
+riscv_libc_ifunc (__libc_strcpy, select_strcpy_ifunc);
+
+# undef strcpy
+strong_alias (__libc_strcpy, strcpy);
+# ifdef SHARED
+__hidden_ver1 (strcpy, __GI_strcpy, __redirect_strcpy)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strcpy);
+# endif
+#else
+# include <string/strcpy.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (11 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 12/18] riscv: Add RVV strcpy " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-04-20 20:22   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 14/18] riscv: Add RVV strncat " Yao Zihong
                   ` (6 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strlen-generic.c      | 24 ++++++++
 sysdeps/riscv/multiarch/strlen-vector.S       | 26 +++++++++
 sysdeps/riscv/rvv/strlen.S                    | 58 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strlen.c  | 56 ++++++++++++++++++
 6 files changed, 172 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strlen-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strlen-vector.S
 create mode 100644 sysdeps/riscv/rvv/strlen.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c

diff --git a/sysdeps/riscv/multiarch/strlen-generic.c b/sysdeps/riscv/multiarch/strlen-generic.c
new file mode 100644
index 0000000000..6317b1cb44
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strlen-generic.c
@@ -0,0 +1,24 @@
+/* Re-include the default strlen implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRLEN __strlen_generic
+# include <string/strlen.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strlen-vector.S b/sysdeps/riscv/multiarch/strlen-vector.S
new file mode 100644
index 0000000000..b7841ed295
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strlen-vector.S
@@ -0,0 +1,26 @@
+/* Re-include the RISC-V RVV based strlen implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRLEN __strlen_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/strlen.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strlen.S b/sysdeps/riscv/rvv/strlen.S
new file mode 100644
index 0000000000..0a3b18eb0c
--- /dev/null
+++ b/sysdeps/riscv/rvv/strlen.S
@@ -0,0 +1,58 @@
+/* RISC-V RVV based strlen.
+   Copyright (C) 2026 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>
+
+#ifndef STRLEN
+# define STRLEN __strlen
+#endif
+
+#define result a0
+#define str a0
+#define copy_str a1
+#define ivl a2
+#define cur_vl a2
+#define end_offset a3
+
+#define ELEM_LMUL_SETTING m2
+#define vstr v0
+#define vmask_end v2
+
+ENTRY (STRLEN)
+.option push
+.option arch, +v
+    mv copy_str, str
+L(loop):
+    vsetvli ivl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr, (copy_str)
+    csrr cur_vl, vl
+    vmseq.vi vmask_end, vstr, 0
+    vfirst.m end_offset, vmask_end
+    add copy_str, copy_str, cur_vl
+    bltz end_offset, L(loop)
+
+    add str, str, cur_vl
+    add copy_str, copy_str, end_offset
+    sub result, copy_str, result
+
+    ret
+.option pop
+END (STRLEN)
+weak_alias (STRLEN, strlen)
+libc_hidden_builtin_def (strlen)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 5bbd789d46..47e16078c1 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -40,6 +40,9 @@ sysdep_routines += \
   strcpy \
   strcpy-generic \
   strcpy-vector \
+  strlen \
+  strlen-generic \
+  strlen-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 3f00942167..fa5692a074 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -110,5 +110,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strcpy_vector)
 	      IFUNC_IMPL_ADD (array, i, strcpy, 1, __strcpy_generic))
 
+  IFUNC_IMPL (i, name, strlen,
+	      IFUNC_IMPL_ADD (array, i, strlen, rvv_enabled,
+			      __strlen_vector)
+	      IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c
new file mode 100644
index 0000000000..9975286b85
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strlen.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strlen so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strlen
+# define strlen __redirect_strlen
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strlen) __libc_strlen;
+
+extern __typeof (__redirect_strlen) __strlen_generic attribute_hidden;
+extern __typeof (__redirect_strlen) __strlen_vector attribute_hidden;
+
+static inline __typeof (__redirect_strlen) *
+select_strlen_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strlen_vector;
+  return __strlen_generic;
+}
+
+riscv_libc_ifunc (__libc_strlen, select_strlen_ifunc);
+
+# undef strlen
+strong_alias (__libc_strlen, strlen);
+# ifdef SHARED
+__hidden_ver1 (strlen, __GI_strlen, __redirect_strlen)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strlen);
+# endif
+#else
+# include <string/strlen.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 14/18] riscv: Add RVV strncat for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (12 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 13/18] riscv: Add RVV strlen " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-04-20 15:47   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 15/18] riscv: Add RVV strncmp " Yao Zihong
                   ` (5 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strncat-generic.c     | 26 ++++++
 sysdeps/riscv/multiarch/strncat-vector.S      | 24 ++++++
 sysdeps/riscv/rvv/strncat.S                   | 81 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strncat.c | 52 ++++++++++++
 6 files changed, 191 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strncat-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncat-vector.S
 create mode 100644 sysdeps/riscv/rvv/strncat.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c

diff --git a/sysdeps/riscv/multiarch/strncat-generic.c b/sysdeps/riscv/multiarch/strncat-generic.c
new file mode 100644
index 0000000000..ca8510a569
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncat-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strncat implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRNCAT __strncat_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strncat.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strncat-vector.S b/sysdeps/riscv/multiarch/strncat-vector.S
new file mode 100644
index 0000000000..c98820d7cd
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncat-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strncat implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRNCAT __strncat_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/strncat.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strncat.S b/sysdeps/riscv/rvv/strncat.S
new file mode 100644
index 0000000000..12fe9aa8d8
--- /dev/null
+++ b/sysdeps/riscv/rvv/strncat.S
@@ -0,0 +1,81 @@
+/* RISC-V RVV based strncat.
+   Copyright (C) 2026 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>
+
+#ifndef STRNCAT
+# define STRNCAT strncat
+#endif
+
+#define dst a0
+#define src a1
+#define length a2
+#define dst_ptr a3
+#define cur_vl a4
+#define activate_elem_pos a5
+
+#define ELEM_LMUL_SETTING m1
+#define vmask1 v0
+#define vmask2 v1
+#define vstr1 v8
+#define vstr2 v16
+
+ENTRY (STRNCAT)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+    /* the strlen of dst.  */
+L(strlen_loop):
+    vsetvli cur_vl, zero, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8ff.v vstr1, (dst_ptr)
+    /* find the '\0'.  */
+    vmseq.vx vmask1, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m activate_elem_pos, vmask1
+    add dst_ptr, dst_ptr, cur_vl
+    bltz activate_elem_pos, L(strlen_loop)
+
+    sub dst_ptr, dst_ptr, cur_vl
+    add dst_ptr, dst_ptr, activate_elem_pos
+
+    /* copy src to dst_ptr.  */
+L(strcpy_loop):
+    vsetvli zero, length, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8ff.v vstr1, (src)
+    vmseq.vx vmask2, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m activate_elem_pos, vmask2
+    vmsif.m vmask1, vmask2
+    add src, src, cur_vl
+    sub length, length, cur_vl
+    vse8.v vstr1, (dst_ptr), vmask1.t
+    add dst_ptr, dst_ptr, cur_vl
+    beqz length, L(fill_zero)
+    bltz activate_elem_pos, L(strcpy_loop)
+    ret
+L(fill_zero):
+    bgez activate_elem_pos, L(fill_zero_end)
+    sb zero, (dst_ptr)
+L(fill_zero_end):
+    ret
+.option pop
+END (STRNCAT)
+libc_hidden_builtin_def (strncat)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 47e16078c1..1b568bd3de 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -43,6 +43,9 @@ sysdep_routines += \
   strlen \
   strlen-generic \
   strlen-vector \
+  strncat \
+  strncat-generic \
+  strncat-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index fa5692a074..370d59d4c5 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -115,5 +115,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strlen_vector)
 	      IFUNC_IMPL_ADD (array, i, strlen, 1, __strlen_generic))
 
+  IFUNC_IMPL (i, name, strncat,
+	      IFUNC_IMPL_ADD (array, i, strncat, rvv_enabled,
+			      __strncat_vector)
+	      IFUNC_IMPL_ADD (array, i, strncat, 1, __strncat_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c
new file mode 100644
index 0000000000..a7acfdfe54
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c
@@ -0,0 +1,52 @@
+/* Multiple versions of strncat.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strncat so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# define strncat __redirect_strncat
+# include <stdint.h>
+# include <string.h>
+# undef strncat
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strncat) __strncat_generic attribute_hidden;
+extern __typeof (__redirect_strncat) __strncat_vector attribute_hidden;
+
+static inline __typeof (__redirect_strncat) *
+select_strncat_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strncat_vector;
+  return __strncat_generic;
+}
+
+riscv_libc_ifunc_redirected (__redirect_strncat, strncat, select_strncat_ifunc);
+strong_alias (strncat, __strncat);
+# ifdef SHARED
+__hidden_ver1 (strncat, __GI___strncat, __redirect_strncat)
+  __attribute__((visibility ("hidden"))) __attribute_copy__ (strncat);
+# endif
+#else
+# include <string/strncat.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 15/18] riscv: Add RVV strncmp for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (13 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 14/18] riscv: Add RVV strncat " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-05-06 19:18   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 16/18] riscv: Add RVV strncpy " Yao Zihong
                   ` (4 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Jerry Shih

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strncmp-generic.c     | 26 ++++++
 sysdeps/riscv/multiarch/strncmp-vector.S      | 24 +++++
 sysdeps/riscv/rvv/strncmp.S                   | 88 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strncmp.c | 56 ++++++++++++
 6 files changed, 202 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncmp-vector.S
 create mode 100644 sysdeps/riscv/rvv/strncmp.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c

diff --git a/sysdeps/riscv/multiarch/strncmp-generic.c b/sysdeps/riscv/multiarch/strncmp-generic.c
new file mode 100644
index 0000000000..3d61dce1be
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncmp-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strncmp implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRNCMP __strncmp_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strncmp.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strncmp-vector.S b/sysdeps/riscv/multiarch/strncmp-vector.S
new file mode 100644
index 0000000000..91e25ea826
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncmp-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strncmp implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRNCMP __strncmp_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# include <sysdeps/riscv/rvv/strncmp.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strncmp.S b/sysdeps/riscv/rvv/strncmp.S
new file mode 100644
index 0000000000..2e265fd25a
--- /dev/null
+++ b/sysdeps/riscv/rvv/strncmp.S
@@ -0,0 +1,88 @@
+/* RISC-V RVV based strncmp.
+   Copyright (C) 2026 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>
+
+#ifndef STRNCMP
+# define STRNCMP strncmp
+#endif
+
+#define result a0
+
+#define str1 a0
+#define str2 a1
+#define length a2
+
+#define ivl a3
+#define temp1 a4
+#define temp2 a5
+
+#define ELEM_LMUL_SETTING m1
+#define vstr1 v0
+#define vstr2 v4
+#define vmask1 v8
+#define vmask2 v9
+
+ENTRY (STRNCMP)
+.option push
+.option arch, +v
+    beqz length, L(zero_length)
+L(loop):
+    vsetvli zero, length, e8, ELEM_LMUL_SETTING, ta, ma
+
+    vle8ff.v vstr1, (str1)
+    /* vstr1[i] == 0.  */
+    vmseq.vx vmask1, vstr1, zero
+
+    vle8ff.v vstr2, (str2)
+    /* vstr1[i] != vstr2[i].  */
+    vmsne.vv vmask2, vstr1, vstr2
+
+    csrr ivl, vl
+
+    /* r = mask1 | mask2
+    We could use vfirst.m to get the first zero char or the
+    first different char between str1 and str2. */
+    vmor.mm vmask1, vmask1, vmask2
+
+    sub length, length, ivl
+
+    vfirst.m temp1, vmask1
+
+    bgez temp1, L(end_loop)
+
+    add str1, str1, ivl
+    add str2, str2, ivl
+    bnez length, L(loop)
+L(end_loop):
+
+    add str1, str1, temp1
+    add str2, str2, temp1
+    lbu temp1, 0(str1)
+    lbu temp2, 0(str2)
+
+    sub result, temp1, temp2
+    ret
+
+L(zero_length):
+    li result, 0
+    ret
+.option pop
+END (STRNCMP)
+libc_hidden_builtin_def (strncmp)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 1b568bd3de..bb3488e849 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -46,6 +46,9 @@ sysdep_routines += \
   strncat \
   strncat-generic \
   strncat-vector \
+  strncmp \
+  strncmp-generic \
+  strncmp-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 370d59d4c5..025b026cf3 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -120,5 +120,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strncat_vector)
 	      IFUNC_IMPL_ADD (array, i, strncat, 1, __strncat_generic))
 
+  IFUNC_IMPL (i, name, strncmp,
+	      IFUNC_IMPL_ADD (array, i, strncmp, rvv_enabled,
+			      __strncmp_vector)
+	      IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c
new file mode 100644
index 0000000000..781e562629
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strncmp.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strncmp so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strncmp
+# define strncmp __redirect_strncmp
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strncmp) __libc_strncmp;
+
+extern __typeof (__redirect_strncmp) __strncmp_generic attribute_hidden;
+extern __typeof (__redirect_strncmp) __strncmp_vector attribute_hidden;
+
+static inline __typeof (__redirect_strncmp) *
+select_strncmp_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strncmp_vector;
+  return __strncmp_generic;
+}
+
+riscv_libc_ifunc (__libc_strncmp, select_strncmp_ifunc);
+
+# undef strncmp
+strong_alias (__libc_strncmp, strncmp);
+# ifdef SHARED
+__hidden_ver1 (strncmp, __GI_strncmp, __redirect_strncmp)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strncmp);
+# endif
+#else
+# include <string/strncmp.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 16/18] riscv: Add RVV strncpy for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (14 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 15/18] riscv: Add RVV strncmp " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-07-03 23:44   ` Peter Bergner
  2026-02-03 15:05 ` [PATCH v5 17/18] riscv: Add RVV strnlen " Yao Zihong
                   ` (3 subsequent siblings)
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong

Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strncpy-generic.c     | 26 +++++++++
 sysdeps/riscv/multiarch/strncpy-vector.S      | 24 ++++++++
 sysdeps/riscv/rvv/stpncpy.S                   | 27 +++++++--
 sysdeps/riscv/rvv/strncpy.S                   | 20 +++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/stpncpy.c | 15 ++---
 .../unix/sysv/linux/riscv/multiarch/strncpy.c | 56 +++++++++++++++++++
 8 files changed, 164 insertions(+), 12 deletions(-)
 create mode 100644 sysdeps/riscv/multiarch/strncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/strncpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c

diff --git a/sysdeps/riscv/multiarch/strncpy-generic.c b/sysdeps/riscv/multiarch/strncpy-generic.c
new file mode 100644
index 0000000000..726ca9ed5f
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncpy-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strncpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRNCPY __strncpy_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strncpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strncpy-vector.S b/sysdeps/riscv/multiarch/strncpy-vector.S
new file mode 100644
index 0000000000..32256f7695
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncpy-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strncpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRNCPY __strncpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <sysdeps/riscv/rvv/strncpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/stpncpy.S b/sysdeps/riscv/rvv/stpncpy.S
index 57406685b0..d9004f2fba 100644
--- a/sysdeps/riscv/rvv/stpncpy.S
+++ b/sysdeps/riscv/rvv/stpncpy.S
@@ -19,12 +19,20 @@
 #include <sysdep.h>
 #include <sys/asm.h>
 
-#ifndef STPNCPY
-# ifdef weak_alias
-#  define STPNCPY __stpncpy
+#ifndef USE_AS_STRNCPY
+# ifndef STPNCPY
+#  ifdef weak_alias
+#   define STPNCPY __stpncpy
 weak_alias (__stpncpy, stpncpy)
+#  else
+#   define STPNCPY stpncpy
+#  endif
+# endif
+#else
+# ifndef STRNCPY
+#  define STPNCPY strncpy
 # else
-#  define STPNCPY stpncpy
+#  define STPNCPY STRNCPY
 # endif
 #endif
 
@@ -62,7 +70,9 @@ L(stpcpy_loop):
     add dst_ptr, dst_ptr, cur_vl
     bgez active_elem_pos, L(fill_zero)
     bnez length, L(stpcpy_loop)
+#ifndef USE_AS_STRNCPY
     mv dst, dst_ptr
+#endif
     ret
 
     /* Fill the tail zero.  */
@@ -72,8 +82,10 @@ L(fill_zero):
     to get the correct remaining length for zero filling. */
     sub temp, cur_vl, active_elem_pos
     addi temp, temp, -1
+#ifndef USE_AS_STRNCPY
     sub dst, dst_ptr, cur_vl
     add dst, dst, active_elem_pos
+#endif
     add length, length, temp
     /* Have an earily return for `strlen(src) + 1 == count` case.  */
     bnez length, L(do_fill_zero)
@@ -92,6 +104,11 @@ L(fill_zero_loop):
     ret
 .option pop
 END (STPNCPY)
-#ifdef weak_alias
+
+#ifndef USE_AS_STRNCPY
+# ifdef weak_alias
 libc_hidden_def (__stpncpy)
+# endif
+#else
+libc_hidden_builtin_def (strncpy)
 #endif
diff --git a/sysdeps/riscv/rvv/strncpy.S b/sysdeps/riscv/rvv/strncpy.S
new file mode 100644
index 0000000000..961c16416e
--- /dev/null
+++ b/sysdeps/riscv/rvv/strncpy.S
@@ -0,0 +1,20 @@
+/* RISC-V RVV based strncpy.
+   Copyright (C) 2026 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/>.  */
+
+#define USE_AS_STRNCPY
+#include <sysdeps/riscv/rvv/stpncpy.S>
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index bb3488e849..df33147de9 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -49,6 +49,9 @@ sysdep_routines += \
   strncmp \
   strncmp-generic \
   strncmp-vector \
+  strncpy \
+  strncpy-generic \
+  strncpy-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 025b026cf3..26444cc99d 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -125,5 +125,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strncmp_vector)
 	      IFUNC_IMPL_ADD (array, i, strncmp, 1, __strncmp_generic))
 
+  IFUNC_IMPL (i, name, strncpy,
+	      IFUNC_IMPL_ADD (array, i, strncpy, rvv_enabled,
+			      __strncpy_vector)
+	      IFUNC_IMPL_ADD (array, i, strncpy, 1, __strncpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
index e451391f1a..190b479a1b 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
@@ -22,14 +22,15 @@
    mismatch with the IFUNC selector in strong_alias, below.  */
 # undef stpncpy
 # define stpncpy __redirect_stpncpy
+# define __stpncpy __redirect___stpncpy
 # include <stdint.h>
 # include <string.h>
+# undef stpncpy
+# undef __stpncpy
 # include <ifunc-init.h>
 # include <riscv-ifunc.h>
 # include <sys/hwprobe.h>
 
-extern __typeof (__redirect_stpncpy) __libc_stpncpy;
-
 extern __typeof (__redirect_stpncpy) __stpncpy_generic attribute_hidden;
 extern __typeof (__redirect_stpncpy) __stpncpy_vector attribute_hidden;
 
@@ -43,14 +44,14 @@ select_stpncpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
   return __stpncpy_generic;
 }
 
-riscv_libc_ifunc (__libc_stpncpy, select_stpncpy_ifunc);
+riscv_libc_ifunc_redirected (__redirect___stpncpy, __stpncpy,
+			     select_stpncpy_ifunc);
 
 # undef stpncpy
-weak_alias (__libc_stpncpy, stpncpy);
-libc_hidden_def (__stpncpy);
+weak_alias (__stpncpy, stpncpy);
 # ifdef SHARED
-__hidden_ver1 (stpncpy, __GI_stpncpy, __redirect_stpncpy)
-  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (stpncpy);
+__hidden_ver1 (__stpncpy, __GI___stpncpy, __redirect___stpncpy)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (__stpncpy);
 # endif
 #else
 # include <string/stpncpy.c>
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c
new file mode 100644
index 0000000000..459032312f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strncpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strncpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strncpy
+# define strncpy __redirect_strncpy
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strncpy) __libc_strncpy;
+
+extern __typeof (__redirect_strncpy) __strncpy_generic attribute_hidden;
+extern __typeof (__redirect_strncpy) __strncpy_vector attribute_hidden;
+
+static inline __typeof (__redirect_strncpy) *
+select_strncpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strncpy_vector;
+  return __strncpy_generic;
+}
+
+riscv_libc_ifunc (__libc_strncpy, select_strncpy_ifunc);
+
+# undef strncpy
+strong_alias (__libc_strncpy, strncpy);
+# ifdef SHARED
+__hidden_ver1 (strncpy, __GI_strncpy, __redirect_strncpy)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strncpy);
+# endif
+#else
+# include <string/strncpy.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 17/18] riscv: Add RVV strnlen for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (15 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 16/18] riscv: Add RVV strncpy " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-02-03 15:05 ` [PATCH v5 18/18] riscv: Add RVV strrchr " Yao Zihong
                   ` (2 subsequent siblings)
  19 siblings, 0 replies; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong, Hau Hsu, Nick Knight

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Nick Knight <nick.knight@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strnlen-generic.c     | 24 ++++++++
 sysdeps/riscv/multiarch/strnlen-vector.S      | 26 ++++++++
 sysdeps/riscv/rvv/strnlen.S                   | 61 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strnlen.c | 56 +++++++++++++++++
 6 files changed, 175 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strnlen-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strnlen-vector.S
 create mode 100644 sysdeps/riscv/rvv/strnlen.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strnlen.c

diff --git a/sysdeps/riscv/multiarch/strnlen-generic.c b/sysdeps/riscv/multiarch/strnlen-generic.c
new file mode 100644
index 0000000000..171b267b58
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strnlen-generic.c
@@ -0,0 +1,24 @@
+/* Re-include the default strnlen implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRNLEN __strnlen_generic
+# include <string/strnlen.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strnlen-vector.S b/sysdeps/riscv/multiarch/strnlen-vector.S
new file mode 100644
index 0000000000..8571af14ad
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strnlen-vector.S
@@ -0,0 +1,26 @@
+/* Re-include the RISC-V RVV based strnlen implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRNLEN __strnlen_vector
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/strnlen.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strnlen.S b/sysdeps/riscv/rvv/strnlen.S
new file mode 100644
index 0000000000..0e114f8cd7
--- /dev/null
+++ b/sysdeps/riscv/rvv/strnlen.S
@@ -0,0 +1,61 @@
+/* RISC-V RVV based strnlen.
+   Copyright (C) 2026 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>
+
+#ifndef STRNLEN
+# define STRNLEN __strnlen
+#endif
+
+#define str a0
+#define copy_str a2
+#define ret_value a0
+#define max_len a1
+#define cur_vl a3
+#define end_offset a4
+
+#define ELEM_LMUL_SETTING m1
+#define vstr v0
+#define vmask_end v8
+
+ENTRY (STRNLEN)
+.option push
+.option arch, +v
+    mv copy_str, str
+    mv ret_value, max_len
+L(strnlen_vector_loop):
+    beqz max_len, L(end_strnlen_vector_loop)
+    vsetvli zero, max_len, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr, (copy_str)
+    vmseq.vi vmask_end, vstr, 0
+    vfirst.m end_offset, vmask_end /* first occurence of \0 */
+    csrr cur_vl, vl
+    add copy_str, copy_str, cur_vl
+    sub max_len, max_len, cur_vl
+    bltz end_offset, L(strnlen_vector_loop)
+    add max_len, max_len, cur_vl
+    sub ret_value, ret_value, max_len
+    add ret_value, ret_value, end_offset
+L(end_strnlen_vector_loop):
+    ret
+.option pop
+END (STRNLEN)
+weak_alias (STRNLEN, strnlen)
+libc_hidden_def (STRNLEN)
+libc_hidden_def (strnlen)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index df33147de9..4e10723636 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -52,6 +52,9 @@ sysdep_routines += \
   strncpy \
   strncpy-generic \
   strncpy-vector \
+  strnlen \
+  strnlen-generic \
+  strnlen-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 26444cc99d..dba3d852fd 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -130,5 +130,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strncpy_vector)
 	      IFUNC_IMPL_ADD (array, i, strncpy, 1, __strncpy_generic))
 
+  IFUNC_IMPL (i, name, strnlen,
+	      IFUNC_IMPL_ADD (array, i, strnlen, rvv_enabled,
+			      __strnlen_vector)
+	      IFUNC_IMPL_ADD (array, i, strnlen, 1, __strnlen_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strnlen.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strnlen.c
new file mode 100644
index 0000000000..6e570e6e4a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strnlen.c
@@ -0,0 +1,56 @@
+/* Multiple versions of strnlen.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strnlen so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# define strnlen __redirect_strnlen
+# define __strnlen __redirect___strnlen
+# include <stdint.h>
+# include <string.h>
+# undef __strnlen
+# undef strnlen
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strnlen) __strnlen_generic attribute_hidden;
+extern __typeof (__redirect_strnlen) __strnlen_vector attribute_hidden;
+
+static inline __typeof (__redirect_strnlen) *
+select_strnlen_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strnlen_vector;
+  return __strnlen_generic;
+}
+
+riscv_libc_ifunc_redirected (__redirect_strnlen, __strnlen, select_strnlen_ifunc);
+weak_alias (__strnlen, strnlen);
+# ifdef SHARED
+__hidden_ver1 (__strnlen, __GI___strnlen, __redirect___strnlen)
+  __attribute__((visibility ("hidden"))) __attribute_copy__ (strnlen);
+__hidden_ver1 (__strnlen, __GI_strnlen, __redirect_strnlen)
+  __attribute__((weak, visibility ("hidden"))) __attribute_copy__ (strnlen);
+# endif
+#else
+# include <string/strnlen.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* [PATCH v5 18/18] riscv: Add RVV strrchr for multiarch and non-multiarch
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (16 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 17/18] riscv: Add RVV strnlen " Yao Zihong
@ 2026-02-03 15:05 ` Yao Zihong
  2026-06-05  2:06   ` Peter Bergner
  2026-02-24 16:40 ` [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Peter Bergner
  2026-04-17  7:03 ` Zihong Yao
  19 siblings, 1 reply; 66+ messages in thread
From: Yao Zihong @ 2026-02-03 15:05 UTC (permalink / raw)
  To: libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, bergner, jlaw, zhangyin2018,
	enh, zihongyao, Yao Zihong

Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
---
 sysdeps/riscv/multiarch/strrchr-generic.c     |  28 ++++
 sysdeps/riscv/multiarch/strrchr-vector.S      |  26 ++++
 sysdeps/riscv/rvv/strrchr.S                   | 123 ++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |   3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |   5 +
 .../unix/sysv/linux/riscv/multiarch/strrchr.c |  59 +++++++++
 6 files changed, 244 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/strrchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strrchr-vector.S
 create mode 100644 sysdeps/riscv/rvv/strrchr.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strrchr.c

diff --git a/sysdeps/riscv/multiarch/strrchr-generic.c b/sysdeps/riscv/multiarch/strrchr-generic.c
new file mode 100644
index 0000000000..c61c6e1a03
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strrchr-generic.c
@@ -0,0 +1,28 @@
+/* Re-include the default strrchr implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRRCHR __strrchr_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# undef weak_alias
+# define weak_alias(x, x2)
+# include <string/strrchr.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strrchr-vector.S b/sysdeps/riscv/multiarch/strrchr-vector.S
new file mode 100644
index 0000000000..8fef68eae0
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strrchr-vector.S
@@ -0,0 +1,26 @@
+/* Re-include the RISC-V RVV based strrchr implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRRCHR __strrchr_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/strrchr.S>
+#endif
diff --git a/sysdeps/riscv/rvv/strrchr.S b/sysdeps/riscv/rvv/strrchr.S
new file mode 100644
index 0000000000..f2da8a4b23
--- /dev/null
+++ b/sysdeps/riscv/rvv/strrchr.S
@@ -0,0 +1,123 @@
+/* RISC-V RVV based strrchr.
+   Copyright (C) 2026 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>
+
+#ifndef STRRCHR
+# define STRRCHR strrchr
+#endif
+
+#define str a0
+#define ch a1
+#define blk_base a2
+#define loc_max a3
+#define latest_ptr a4
+#define first_idx a5
+#define len_valid a5
+#define cur_vl a6
+
+#define vhit v0
+#define vstr v4
+#define vmask_end v8
+#define vmask_ch v10
+#define vvalid v12
+#define vidx v16
+#define vacc v20
+
+#if __riscv_xlen == 64
+# define XLEN_SHIFT 63
+#else
+# define XLEN_SHIFT 31
+#endif
+
+ENTRY (STRRCHR)
+.option push
+.option arch, +v
+	beqz ch, L(search_zero)
+	mv latest_ptr, zero
+L(loop):
+    mv blk_base, str
+
+    vsetvli cur_vl, zero, e8, m2, ta, ma
+    vle8ff.v vstr, (str)
+
+    vmseq.vi vmask_end, vstr, 0
+    vmsbf.m vvalid, vmask_end
+    vmseq.vx vmask_ch, vstr, ch
+    vmand.mm vhit, vmask_ch, vvalid
+
+    vfirst.m first_idx, vhit
+    csrr cur_vl, vl
+    bltz first_idx, L(no_hit_in_block)
+
+    vsetvli zero, cur_vl, e16, m4, ta, ma
+    vid.v vidx
+    vmv.s.x vacc, x0
+    /* Compute per-block last hit index (or -1 if none). */
+    vredmaxu.vs vacc, vidx, vacc, vhit.t
+    vmv.x.s loc_max, vacc
+    j L(loc_max_ready)
+
+L(no_hit_in_block):
+    li loc_max, -1
+
+L(loc_max_ready):
+    vsetvli zero, cur_vl, e8, m2, ta, ma
+    vcpop.m len_valid, vvalid
+
+    bne len_valid, cur_vl, L(tail_block)
+    bltz loc_max, L(advance)
+
+    add latest_ptr, blk_base, loc_max
+
+L(advance):
+    add str, str, cur_vl
+    j L(loop)
+
+L(tail_block):
+    add str, blk_base, loc_max
+
+    /* sign = -1 if loc_max < 0 else 0; then invert to
+    build selection mask */
+    srai loc_max, loc_max, XLEN_SHIFT
+    and len_valid, loc_max, latest_ptr
+    xori loc_max, loc_max, -1
+    and str, loc_max, str
+    or str, str, len_valid
+    ret
+
+L(search_zero):
+L(sz_loop):
+    vsetvli cur_vl, zero, e8, m4, ta, ma
+    vle8ff.v vstr, (str)
+
+    vmseq.vi vmask_end, vstr, 0
+    vfirst.m first_idx, vmask_end
+    bltz first_idx, L(sz_advance)
+    add str, str, first_idx
+    ret
+L(sz_advance):
+    csrr cur_vl, vl
+    add str, str, cur_vl
+    j L(sz_loop)
+
+.option pop
+END (STRRCHR)
+weak_alias (STRRCHR, rindex)
+libc_hidden_builtin_def (strrchr)
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 4e10723636..8e2b1632da 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -55,6 +55,9 @@ sysdep_routines += \
   strnlen \
   strnlen-generic \
   strnlen-vector \
+  strrchr \
+  strrchr-generic \
+  strrchr-vector \
   # sysdep_routines
 
 CFLAGS-memcpy_noalignment.c += -mno-strict-align
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index dba3d852fd..d7db46cf81 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -135,5 +135,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __strnlen_vector)
 	      IFUNC_IMPL_ADD (array, i, strnlen, 1, __strnlen_generic))
 
+  IFUNC_IMPL (i, name, strrchr,
+	      IFUNC_IMPL_ADD (array, i, strrchr, rvv_enabled,
+			      __strrchr_vector)
+	      IFUNC_IMPL_ADD (array, i, strrchr, 1, __strrchr_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strrchr.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strrchr.c
new file mode 100644
index 0000000000..3532af0dc0
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strrchr.c
@@ -0,0 +1,59 @@
+/* Multiple versions of strrchr.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+/* Redefine strrchr so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strrchr
+# define strrchr __redirect_strrchr
+# include <stdint.h>
+# include <string.h>
+# include <ifunc-init.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (__redirect_strrchr) __libc_strrchr;
+
+extern __typeof (__redirect_strrchr) __strrchr_generic attribute_hidden;
+extern __typeof (__redirect_strrchr) __strrchr_vector attribute_hidden;
+
+static inline __typeof (__redirect_strrchr) *
+select_strrchr_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long v;
+
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return __strrchr_vector;
+  return __strrchr_generic;
+}
+
+riscv_libc_ifunc (__libc_strrchr, select_strrchr_ifunc);
+
+# undef strrchr
+# undef rindex
+strong_alias (__libc_strrchr, strrchr);
+weak_alias (strrchr, rindex);
+# ifdef SHARED
+__hidden_ver1 (strrchr, __GI_strrchr, __redirect_strrchr)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strrchr);
+# endif
+#else
+# include <string/strrchr.c>
+#endif
-- 
2.47.3


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 00/18] riscv: Add RVV str*/mem* routines
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (17 preceding siblings ...)
  2026-02-03 15:05 ` [PATCH v5 18/18] riscv: Add RVV strrchr " Yao Zihong
@ 2026-02-24 16:40 ` Peter Bergner
  2026-04-17  7:03 ` Zihong Yao
  19 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-02-24 16:40 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh, zihongyao

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Changes since v4:
>   * Disabled multiarch variants when !IS_IN(libc)

Just an FYI, but I am looking at these and my apologies for not
responding sooner.  I have several of your patches committed locally,
but I hesitate to push them as I'm going on vacation today and I want
to be around in case there is any unexpected fall-out.

I return from vacation March 13th and will push the patches that
Jeff already Ack'd then and then I'll work on the reviews of the
others.  Thanks for your patience.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 00/18] riscv: Add RVV str*/mem* routines
  2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
                   ` (18 preceding siblings ...)
  2026-02-24 16:40 ` [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Peter Bergner
@ 2026-04-17  7:03 ` Zihong Yao
  19 siblings, 0 replies; 66+ messages in thread
From: Zihong Yao @ 2026-04-17  7:03 UTC (permalink / raw)
  To: zihong.plct
  Cc: adhemerval.zanella, andrew, bergner, enh, jlaw, libc-alpha,
	schwab, zhangyin2018, zihongyao

Hi,

Gentle ping on this thread.

Please let me know if there are any remaining concerns, or if a resend would be helpful.

Thanks,
Zihong


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 09/18] riscv: Add RVV strcat for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 09/18] riscv: Add RVV strcat " Yao Zihong
@ 2026-04-20 15:37   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-04-20 15:37 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
>  sysdeps/riscv/multiarch/strcat-generic.c      | 26 +++++++
>  sysdeps/riscv/multiarch/strcat-vector.S       | 24 ++++++
>  sysdeps/riscv/rvv/strcat.S                    | 75 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/strcat.c  | 56 ++++++++++++++
>  6 files changed, 189 insertions(+)
>  create mode 100644 sysdeps/riscv/multiarch/strcat-generic.c
>  create mode 100644 sysdeps/riscv/multiarch/strcat-vector.S
>  create mode 100644 sysdeps/riscv/rvv/strcat.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcat.c

LGTM.  Pushed.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 14/18] riscv: Add RVV strncat for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 14/18] riscv: Add RVV strncat " Yao Zihong
@ 2026-04-20 15:47   ` Peter Bergner
  2026-04-27 14:17     ` Zihong Yao
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-04-20 15:47 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

> diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncat.c
[snip]
> +riscv_libc_ifunc_redirected (__redirect_strncat, strncat, select_strncat_ifunc);

This is different than the riscv/multiarch/{memset,strcat}.c changes
that use riscv_libc_ifunc().  Can you explain why the need for this
new riscv_libc_ifunc_redirected macro and its use here?  Ie, why doesn't
this just use the same template as the memset and strcat files?

Ditto for the strncpy, strnlen, memcmpeq and memrchr patches.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 13/18] riscv: Add RVV strlen " Yao Zihong
@ 2026-04-20 20:22   ` Peter Bergner
  2026-04-27 14:21     ` Zihong Yao
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-04-20 20:22 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
> --- /dev/null
> +++ b/sysdeps/riscv/multiarch/strlen-generic.c
> @@ -0,0 +1,24 @@
> +#if IS_IN(libc)
> +# define STRLEN __strlen_generic
> +# include <string/strlen.c>
> +#endif

Is it on purpose you don't have:

  +# undef libc_hidden_builtin_def
  +# define libc_hidden_builtin_def(x)

...above, whereas memset-generic.c and strcat-generic.c have it,
as does your strlen-vector.S?



Otherwise, this is looking good.

Peter


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [EXT] [PATCH v5 12/18] riscv: Add RVV strcpy for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 12/18] riscv: Add RVV strcpy " Yao Zihong
@ 2026-04-21  0:48   ` Peter Bergner
  2026-04-21 18:22     ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-04-21  0:48 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
>  sysdeps/riscv/multiarch/strcpy-generic.c      | 26 ++++++++
>  sysdeps/riscv/multiarch/strcpy-vector.S       | 24 ++++++++
>  sysdeps/riscv/rvv/strcpy.S                    | 59 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/strcpy.c  | 56 ++++++++++++++++++
>  6 files changed, 173 insertions(+)
>  create mode 100644 sysdeps/riscv/multiarch/strcpy-generic.c
>  create mode 100644 sysdeps/riscv/multiarch/strcpy-vector.S
>  create mode 100644 sysdeps/riscv/rvv/strcpy.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcpy.c

This LGTM.  I'm currently testing this and will push it if the
testsuite run is clean.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [EXT] [PATCH v5 12/18] riscv: Add RVV strcpy for multiarch and non-multiarch
  2026-04-21  0:48   ` [EXT] " Peter Bergner
@ 2026-04-21 18:22     ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-04-21 18:22 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 4/20/26 7:48 PM, Peter Bergner wrote:
> This LGTM.  I'm currently testing this and will push it if the
> testsuite run is clean.

Testing was clean, so I pushed it.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [EXT] [PATCH v5 05/18] riscv: Add RVV memcpy for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 05/18] riscv: Add RVV memcpy " Yao Zihong
@ 2026-04-22 21:21   ` Peter Bergner
  2026-04-23  4:28     ` Aurelien Jarno
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-04-22 21:21 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
>  .../riscv/multiarch/dl-symbol-redir-ifunc.h   |  1 +
>  sysdeps/riscv/multiarch/memcpy-vector.S       | 24 +++++++++
>  sysdeps/riscv/rvv/memcpy.S                    | 54 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  1 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  2 +
>  .../unix/sysv/linux/riscv/multiarch/memcpy.c  |  5 ++
>  6 files changed, 87 insertions(+)
>  create mode 100644 sysdeps/riscv/multiarch/memcpy-vector.S
>  create mode 100644 sysdeps/riscv/rvv/memcpy.S

LGTM, so pushed.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>



>  static inline __typeof (__redirect_memcpy) *
>  select_memcpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
>  {
>    unsigned long long int v;
> +  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
> +      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
> +    return __memcpy_vector;
> +
>    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;

These two hwprobe calls could potentially be combined into one call to hwprobe
with two keys, similar to what we do in riscv/multiarch/ifunc-impl-list.c,
but we'd have to manually code it since we don't have a __riscv_hwprobe_two
or some such interface.  I also expect in the future, the majority of systems
will have vector, so maybe it'll be marginally faster to keep it this way?

..so I'm accepting the code as is and if someone prefers to combine them,
then they can submit a patch.

Thanks.

Peter





^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [EXT] [PATCH v5 05/18] riscv: Add RVV memcpy for multiarch and non-multiarch
  2026-04-22 21:21   ` [EXT] " Peter Bergner
@ 2026-04-23  4:28     ` Aurelien Jarno
  2026-04-23 13:25       ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Aurelien Jarno @ 2026-04-23  4:28 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, schwab, jlaw,
	zhangyin2018, enh, zihongyao, Hau Hsu, Jerry Shih

Hi,

On 2026-04-22 16:21, Peter Bergner wrote:
> On 2/3/26 9:05 AM, Yao Zihong wrote:
> >  .../riscv/multiarch/dl-symbol-redir-ifunc.h   |  1 +
> >  sysdeps/riscv/multiarch/memcpy-vector.S       | 24 +++++++++
> >  sysdeps/riscv/rvv/memcpy.S                    | 54 +++++++++++++++++++
> >  .../unix/sysv/linux/riscv/multiarch/Makefile  |  1 +
> >  .../linux/riscv/multiarch/ifunc-impl-list.c   |  2 +
> >  .../unix/sysv/linux/riscv/multiarch/memcpy.c  |  5 ++
> >  6 files changed, 87 insertions(+)
> >  create mode 100644 sysdeps/riscv/multiarch/memcpy-vector.S
> >  create mode 100644 sysdeps/riscv/rvv/memcpy.S
> 
> LGTM, so pushed.
> 
> Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Thanks. I noticed that due to the commit 89edb2e8c6a7 ("riscv: Resolve 
calls to memcpy using memcpy-generic in early startup") already adding
__memcpy_generic to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h, 
this is now duplicated:

diff --git a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
index 69a0790838..a4ff47107b 100644
--- a/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
+++ b/sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h
@@ -20,6 +20,7 @@
 #define _DL_IFUNC_GENERIC_H
 
 #ifndef SHARED
+asm ("memcpy = __memcpy_generic");
 asm ("memset = __memset_generic");
 asm ("memcpy = __memcpy_generic");
 #endif

Regards
Aurelien 

-- 
Aurelien Jarno                          GPG: 4096R/1DDD8C9B
aurelien@aurel32.net                     http://aurel32.net

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 05/18] riscv: Add RVV memcpy for multiarch and non-multiarch
  2026-04-23  4:28     ` Aurelien Jarno
@ 2026-04-23 13:25       ` Peter Bergner
  2026-06-05 16:55         ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-04-23 13:25 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, schwab, jlaw,
	zhangyin2018, enh, zihongyao, Hau Hsu, Jerry Shih

On 4/22/26 11:28 PM, Aurelien Jarno wrote:
> Thanks. I noticed that due to the commit 89edb2e8c6a7 ("riscv: Resolve 
> calls to memcpy using memcpy-generic in early startup") already adding
> __memcpy_generic to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h, 
> this is now duplicated:

Weird.  That is not part of the patch and I'm surprised that applying
the patch didn't complain that the context was off.  Thanks for spotting
this and I'll remove the duplicate.

Peter


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 14/18] riscv: Add RVV strncat for multiarch and non-multiarch
  2026-04-20 15:47   ` Peter Bergner
@ 2026-04-27 14:17     ` Zihong Yao
  0 siblings, 0 replies; 66+ messages in thread
From: Zihong Yao @ 2026-04-27 14:17 UTC (permalink / raw)
  To: bergner
  Cc: adhemerval.zanella, andrew, enh, hau.hsu, jerry.shih, jlaw,
	libc-alpha, schwab, zhangyin2018, zihong.plct, zihongyao

Hi Peter,

For `memrchr` and `strnlen`, the generic implementations are on `__memrchr`
and `__strnlen`, with `memrchr`/`strnlen` just being aliases to them. So in
those two cases, it seemed more natural to make `__memrchr`/`__strnlen` themselves
the IFUNC symbols, and the redirected form makes that straightforward.

But `strncat` and `__memcmpeq` are a bit different. I mainly kept that form there
because I was following the x86_64 pattern. `strncpy` already uses the simpler
form.

I'm happy to rework them if you prefer to keep cases aligned.

Zihong


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-04-20 20:22   ` Peter Bergner
@ 2026-04-27 14:21     ` Zihong Yao
  2026-05-04 19:40       ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Zihong Yao @ 2026-04-27 14:21 UTC (permalink / raw)
  To: bergner
  Cc: adhemerval.zanella, andrew, enh, hau.hsu, jerry.shih, jlaw,
	libc-alpha, schwab, zhangyin2018, zihong.plct, zihongyao

Yes, that's on purpose.

The included string/strlen.c does not emit libc_hidden_builtin_def (strlen) here
once STRLEN is defined, so the explicit no-op redefine is not needed. I left it
out to keep the change minimal.

Zihong


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-04-27 14:21     ` Zihong Yao
@ 2026-05-04 19:40       ` Peter Bergner
  2026-05-10  9:48         ` Andreas Schwab
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-05-04 19:40 UTC (permalink / raw)
  To: Zihong Yao
  Cc: adhemerval.zanella, andrew, enh, hau.hsu, jerry.shih, jlaw,
	libc-alpha, schwab, zhangyin2018, zihongyao

On 4/27/26 9:21 AM, Zihong Yao wrote:
> Yes, that's on purpose.
> 
> The included string/strlen.c does not emit libc_hidden_builtin_def (strlen) here
> once STRLEN is defined, so the explicit no-op redefine is not needed. I left it
> out to keep the change minimal.

Ok.  I've pushed this now, after running it through a build/test myself.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 06/18] riscv: Add RVV memmove " Yao Zihong
@ 2026-05-05  2:52   ` Peter Bergner
  2026-06-09 13:46     ` Zihong Yao
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-05-05  2:52 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Jerry Shih

I'm removing Hau Hsu <hau.hsu@sifive.com> from the CC list, since mail
has been bouncing from this address in my previous replies.


On 2/3/26 9:05 AM, Yao Zihong wrote:
> +    /* 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)

Since we need to compare DST and SRC to see whether we can use the forward
copy loop or whether we have to use the backward copy loop, I think we can
rewrite the code above to also optimize the special case of DST == SRC and
return immediately in that case.

We should be able to subtract DST and SRC and if the difference is zero,
we can return immediately.  Otherwise, we can compare that difference to
NUM to see whether there is 1) any overlap or 2) whether DST < SRC (given
the sign of the difference).  I think checking for 1) and 2) should be
doable in one unsigned conditional branch insn.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 11/18] riscv: Add RVV strcmp for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 11/18] riscv: Add RVV strcmp " Yao Zihong
@ 2026-05-06 19:15   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-05-06 19:15 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
> Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/strcmp-generic.c      | 24 +++++
>  sysdeps/riscv/multiarch/strcmp-vector.S       | 24 +++++
>  sysdeps/riscv/rvv/strcmp.S                    | 93 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 +
>  .../unix/sysv/linux/riscv/multiarch/strcmp.c  | 56 +++++++++++
>  6 files changed, 205 insertions(+)
>  create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c
>  create mode 100644 sysdeps/riscv/multiarch/strcmp-vector.S
>  create mode 100644 sysdeps/riscv/rvv/strcmp.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c


This LGTM.  I'm currently testing this and will push it if the
testsuite run is clean.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 15/18] riscv: Add RVV strncmp for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 15/18] riscv: Add RVV strncmp " Yao Zihong
@ 2026-05-06 19:18   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-05-06 19:18 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
> Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/strncmp-generic.c     | 26 ++++++
>  sysdeps/riscv/multiarch/strncmp-vector.S      | 24 +++++
>  sysdeps/riscv/rvv/strncmp.S                   | 88 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/strncmp.c | 56 ++++++++++++
>  6 files changed, 202 insertions(+)
>  create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c
>  create mode 100644 sysdeps/riscv/multiarch/strncmp-vector.S
>  create mode 100644 sysdeps/riscv/rvv/strncmp.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c

This LGTM.  I'm currently testing this and will push it if the
testsuite run is clean.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-04 19:40       ` Peter Bergner
@ 2026-05-10  9:48         ` Andreas Schwab
  2026-05-10 12:09           ` H.J. Lu
  0 siblings, 1 reply; 66+ messages in thread
From: Andreas Schwab @ 2026-05-10  9:48 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Zihong Yao, adhemerval.zanella, andrew, enh, hau.hsu, jerry.shih,
	jlaw, libc-alpha, zhangyin2018, zihongyao

This breaks statically linked programs when any tunable env var is set,
because __tunables_init calls strlen, which jumps to the uninitialized
PLT.

$ echo 'int main() { return 0; }' > main.c
$ gcc -static main.c -o main
$ MALLOC_CHECK_=3 ./main


-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-10  9:48         ` Andreas Schwab
@ 2026-05-10 12:09           ` H.J. Lu
  2026-05-11  6:25             ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: H.J. Lu @ 2026-05-10 12:09 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Peter Bergner, Zihong Yao, adhemerval.zanella, andrew, enh,
	hau.hsu, jerry.shih, jlaw, libc-alpha, zhangyin2018, zihongyao

On Sun, May 10, 2026 at 5:49 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> This breaks statically linked programs when any tunable env var is set,
> because __tunables_init calls strlen, which jumps to the uninitialized
> PLT.

Please add

asm ("strlen = __strlen_generic");

to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.

> $ echo 'int main() { return 0; }' > main.c
> $ gcc -static main.c -o main
> $ MALLOC_CHECK_=3 ./main
>
>
> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."



-- 
H.J.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-10 12:09           ` H.J. Lu
@ 2026-05-11  6:25             ` Peter Bergner
  2026-05-11 14:24               ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-05-11  6:25 UTC (permalink / raw)
  To: H.J. Lu, Andreas Schwab
  Cc: Zihong Yao, adhemerval.zanella, andrew, enh, hau.hsu, jerry.shih,
	jlaw, libc-alpha, zhangyin2018, zihongyao

On 5/10/26 7:09 AM, H.J. Lu wrote:
> On Sun, May 10, 2026 at 5:49 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> This breaks statically linked programs when any tunable env var is set,
>> because __tunables_init calls strlen, which jumps to the uninitialized
>> PLT.
> 
> Please add
> 
> asm ("strlen = __strlen_generic");
> 
> to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.

I'll need to add static builds to my testing matrix.  Thanks to you
and Andreas for pointing this out!  Are there any other known symbols
that need handling like this as well (memcpy and memset already were
handled)?

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-11  6:25             ` Peter Bergner
@ 2026-05-11 14:24               ` Adhemerval Zanella Netto
  2026-05-11 19:49                 ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Adhemerval Zanella Netto @ 2026-05-11 14:24 UTC (permalink / raw)
  To: Peter Bergner, H.J. Lu, Andreas Schwab
  Cc: Zihong Yao, andrew, enh, hau.hsu, jerry.shih, jlaw, libc-alpha,
	zhangyin2018, zihongyao



On 11/05/26 03:25, Peter Bergner wrote:
> On 5/10/26 7:09 AM, H.J. Lu wrote:
>> On Sun, May 10, 2026 at 5:49 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>>>
>>> This breaks statically linked programs when any tunable env var is set,
>>> because __tunables_init calls strlen, which jumps to the uninitialized
>>> PLT.
>>
>> Please add
>>
>> asm ("strlen = __strlen_generic");
>>
>> to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.
> 
> I'll need to add static builds to my testing matrix.  Thanks to you
> and Andreas for pointing this out!  Are there any other known symbols
> that need handling like this as well (memcpy and memset already were
> handled)?

We already have tests that checks for this, after this patch I noticed:

FAIL: elf/tst-env-setuid-static
FAIL: elf/tst-tunables
FAIL: elf/tst-tunables-enable_secure

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-11 14:24               ` Adhemerval Zanella Netto
@ 2026-05-11 19:49                 ` Peter Bergner
  2026-05-11 20:10                   ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-05-11 19:49 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, H.J. Lu, Andreas Schwab
  Cc: Zihong Yao, andrew, enh, hau.hsu, jerry.shih, jlaw, libc-alpha,
	zhangyin2018, zihongyao

On 5/11/26 9:24 AM, Adhemerval Zanella Netto wrote:
> On 11/05/26 03:25, Peter Bergner wrote:
>> On 5/10/26 7:09 AM, H.J. Lu wrote:
>>> Please add
>>>
>>> asm ("strlen = __strlen_generic");
>>>
>>> to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.
>>
>> I'll need to add static builds to my testing matrix.  Thanks to you
>> and Andreas for pointing this out!  Are there any other known symbols
>> that need handling like this as well (memcpy and memset already were
>> handled)?

I see Andreas already pushed a fix for this.  Thanks Andreas!


> We already have tests that checks for this, after this patch I noticed:
> 
> FAIL: elf/tst-env-setuid-static
> FAIL: elf/tst-tunables
> FAIL: elf/tst-tunables-enable_secure

So I'm not sure how I missed this during my testing.  Maybe my compiler
defaulted to vector being enabled, so skipped this altogether?  I'll keep
a better eye out for things like this.  It's good to know we do have tests
that test for this.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-11 19:49                 ` Peter Bergner
@ 2026-05-11 20:10                   ` Adhemerval Zanella Netto
  2026-05-11 22:26                     ` Jeffrey Law
  0 siblings, 1 reply; 66+ messages in thread
From: Adhemerval Zanella Netto @ 2026-05-11 20:10 UTC (permalink / raw)
  To: Peter Bergner, H.J. Lu, Andreas Schwab
  Cc: Zihong Yao, andrew, enh, hau.hsu, jerry.shih, jlaw, libc-alpha,
	zhangyin2018, zihongyao



On 11/05/26 16:49, Peter Bergner wrote:
> On 5/11/26 9:24 AM, Adhemerval Zanella Netto wrote:
>> On 11/05/26 03:25, Peter Bergner wrote:
>>> On 5/10/26 7:09 AM, H.J. Lu wrote:
>>>> Please add
>>>>
>>>> asm ("strlen = __strlen_generic");
>>>>
>>>> to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.
>>>
>>> I'll need to add static builds to my testing matrix.  Thanks to you
>>> and Andreas for pointing this out!  Are there any other known symbols
>>> that need handling like this as well (memcpy and memset already were
>>> handled)?
> 
> I see Andreas already pushed a fix for this.  Thanks Andreas!
> 
> 
>> We already have tests that checks for this, after this patch I noticed:
>>
>> FAIL: elf/tst-env-setuid-static
>> FAIL: elf/tst-tunables
>> FAIL: elf/tst-tunables-enable_secure
> 
> So I'm not sure how I missed this during my testing.  Maybe my compiler
> defaulted to vector being enabled, so skipped this altogether?  I'll keep
> a better eye out for things like this.  It's good to know we do have tests
> that test for this.

I think these issues might depend of the gcc version and how cleaver it
optimizes loops to str/mem calls.  If you compiler with older gcc version
you might not trigger this issue.


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 13/18] riscv: Add RVV strlen for multiarch and non-multiarch
  2026-05-11 20:10                   ` Adhemerval Zanella Netto
@ 2026-05-11 22:26                     ` Jeffrey Law
  0 siblings, 0 replies; 66+ messages in thread
From: Jeffrey Law @ 2026-05-11 22:26 UTC (permalink / raw)
  To: Adhemerval Zanella Netto, Peter Bergner, H.J. Lu, Andreas Schwab
  Cc: Zihong Yao, andrew, enh, hau.hsu, jerry.shih, jlaw, libc-alpha,
	zhangyin2018, zihongyao



On 5/11/2026 2:10 PM, Adhemerval Zanella Netto wrote:
>
> On 11/05/26 16:49, Peter Bergner wrote:
>> On 5/11/26 9:24 AM, Adhemerval Zanella Netto wrote:
>>> On 11/05/26 03:25, Peter Bergner wrote:
>>>> On 5/10/26 7:09 AM, H.J. Lu wrote:
>>>>> Please add
>>>>>
>>>>> asm ("strlen = __strlen_generic");
>>>>>
>>>>> to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h.
>>>> I'll need to add static builds to my testing matrix.  Thanks to you
>>>> and Andreas for pointing this out!  Are there any other known symbols
>>>> that need handling like this as well (memcpy and memset already were
>>>> handled)?
>> I see Andreas already pushed a fix for this.  Thanks Andreas!
>>
>>
>>> We already have tests that checks for this, after this patch I noticed:
>>>
>>> FAIL: elf/tst-env-setuid-static
>>> FAIL: elf/tst-tunables
>>> FAIL: elf/tst-tunables-enable_secure
>> So I'm not sure how I missed this during my testing.  Maybe my compiler
>> defaulted to vector being enabled, so skipped this altogether?  I'll keep
>> a better eye out for things like this.  It's good to know we do have tests
>> that test for this.
> I think these issues might depend of the gcc version and how cleaver it
> optimizes loops to str/mem calls.  If you compiler with older gcc version
> you might not trigger this issue.
That would make a lot of sense.  We've certainly adjusted things like 
the ability to inline strlen over the last few years.

Jeff

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 03/18] riscv: Add RVV memcmp " Yao Zihong
@ 2026-06-05  0:06   ` Peter Bergner
  2026-06-05  7:41     ` Andreas Schwab
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-06-05  0:06 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
> Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/memcmp-generic.c      | 30 +++++++
>  sysdeps/riscv/multiarch/memcmp-vector.S       | 30 +++++++
>  sysdeps/riscv/rvv/memcmp.S                    | 84 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/memcmp.c  | 60 +++++++++++++

LGTM, modulo I added an entry to dl-symbol-redir-ifunc.h to redirect
memcmp to the generic routine during the early startup code similar
to other architectures.

Pushed.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [EXT] [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch Yao Zihong
@ 2026-06-05  2:02   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-05  2:02 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh, zihongyao

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/memccpy-generic.c     | 26 +++++++
>  sysdeps/riscv/multiarch/memccpy-vector.S      | 24 +++++++
>  sysdeps/riscv/rvv/memccpy.S                   | 67 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/memccpy.c | 58 ++++++++++++++++å

LGTM, pushed.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter




^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 02/18] riscv: Add RVV memchr for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 02/18] riscv: Add RVV memchr " Yao Zihong
@ 2026-06-05  2:03   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-05  2:03 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Hau Hsu, Jerry Shih

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
> Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/memchr-generic.c      | 24 +++++++
>  sysdeps/riscv/multiarch/memchr-vector.S       | 26 +++++++
>  sysdeps/riscv/rvv/memchr.S                    | 67 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/memchr.c  | 57 ++++++++++++++++


LGTM, pushed after testing.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 10/18] riscv: Add RVV strchr for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 10/18] riscv: Add RVV strchr " Yao Zihong
@ 2026-06-05  2:04   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-05  2:04 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Nick Knight

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
> Co-authored-by: Nick Knight <nick.knight@sifive.com>
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/strchr-generic.c      | 24 +++++++
>  sysdeps/riscv/multiarch/strchr-vector.S       | 26 ++++++++
>  sysdeps/riscv/rvv/strchr.S                    | 65 +++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/strchr.c  | 58 +++++++++++++++++


LGTM, pushed after testing.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter




^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 18/18] riscv: Add RVV strrchr for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 18/18] riscv: Add RVV strrchr " Yao Zihong
@ 2026-06-05  2:06   ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-05  2:06 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh, zihongyao

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/strrchr-generic.c     |  28 ++++
>  sysdeps/riscv/multiarch/strrchr-vector.S      |  26 ++++
>  sysdeps/riscv/rvv/strrchr.S                   | 123 ++++++++++++++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |   3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |   5 +
>  .../unix/sysv/linux/riscv/multiarch/strrchr.c |  59 +++++++++

LGTM, pushed after testing.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>

Peter





^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05  0:06   ` Peter Bergner
@ 2026-06-05  7:41     ` Andreas Schwab
  2026-06-05 12:38       ` 姚子宏
  2026-06-05 15:46       ` Peter Bergner
  0 siblings, 2 replies; 66+ messages in thread
From: Andreas Schwab @ 2026-06-05  7:41 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
--- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
+++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
@@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
-GLIBC_2.35 __memcmpeq F
  0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
make[1]: *** [Makerules:1310: check-abi] Error 1
make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
make: *** [Makefile:20: check-abi] Error 2

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05  7:41     ` Andreas Schwab
@ 2026-06-05 12:38       ` 姚子宏
  2026-06-05 12:58         ` Adhemerval Zanella Netto
  2026-06-05 15:46       ` Peter Bergner
  1 sibling, 1 reply; 66+ messages in thread
From: 姚子宏 @ 2026-06-05 12:38 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Peter Bergner, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

On Fri, 05 Jun 2026 09:41:24 +0200, Andreas Schwab wrote:
> make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
> if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
> 	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
> --- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
> +++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
> @@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
> -GLIBC_2.35 __memcmpeq F
>   0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
> make[1]: *** [Makerules:1310: check-abi] Error 1
> make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
> make: *** [Makefile:20: check-abi] Error 2

This comes from the current intermediate state where the RVV memcmp
has been merged, while the dedicated RVV __memcmpeq is still under review.

I can send a follow-up patch to restore the __memcmpeq alias for now, or would
you prefer to handle this through __memcmpeq patch directly?

Thanks,
Zihong

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05 12:38       ` 姚子宏
@ 2026-06-05 12:58         ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 66+ messages in thread
From: Adhemerval Zanella Netto @ 2026-06-05 12:58 UTC (permalink / raw)
  To: 姚子宏, Andreas Schwab
  Cc: Peter Bergner, libc-alpha, andrew, jlaw, zhangyin2018, enh,
	zihongyao, Jerry Shih



On 05/06/26 09:38, 姚子宏 wrote:
> On Fri, 05 Jun 2026 09:41:24 +0200, Andreas Schwab wrote:
>> make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>> if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
>> 	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
>> --- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
>> +++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
>> @@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
>> -GLIBC_2.35 __memcmpeq F
>>   0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
>> make[1]: *** [Makerules:1310: check-abi] Error 1
>> make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>> make: *** [Makefile:20: check-abi] Error 2
> 
> This comes from the current intermediate state where the RVV memcmp
> has been merged, while the dedicated RVV __memcmpeq is still under review.
> 
> I can send a follow-up patch to restore the __memcmpeq alias for now, or would
> you prefer to handle this through __memcmpeq patch directly?
Please add an alias that fix the build for now.

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05  7:41     ` Andreas Schwab
  2026-06-05 12:38       ` 姚子宏
@ 2026-06-05 15:46       ` Peter Bergner
  2026-06-05 17:56         ` Andreas Schwab
  1 sibling, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-06-05 15:46 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

On 6/5/26 2:41 AM, Andreas Schwab wrote:
> make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
> if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
> 	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
> --- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
> +++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
> @@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
> -GLIBC_2.35 __memcmpeq F
>   0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
> make[1]: *** [Makerules:1310: check-abi] Error 1
> make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
> make: *** [Makefile:20: check-abi] Error 2

How did you hit this?  Special configure or make/make check options?
I did not see this in my builds or testing.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 05/18] riscv: Add RVV memcpy for multiarch and non-multiarch
  2026-04-23 13:25       ` Peter Bergner
@ 2026-06-05 16:55         ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 66+ messages in thread
From: Adhemerval Zanella Netto @ 2026-06-05 16:55 UTC (permalink / raw)
  To: Peter Bergner, Yao Zihong, libc-alpha, andrew, schwab, jlaw,
	zhangyin2018, enh, zihongyao, Hau Hsu, Jerry Shih



On 23/04/26 10:25, Peter Bergner wrote:
> On 4/22/26 11:28 PM, Aurelien Jarno wrote:
>> Thanks. I noticed that due to the commit 89edb2e8c6a7 ("riscv: Resolve 
>> calls to memcpy using memcpy-generic in early startup") already adding
>> __memcpy_generic to sysdeps/riscv/multiarch/dl-symbol-redir-ifunc.h, 
>> this is now duplicated:
> 
> Weird.  That is not part of the patch and I'm surprised that applying
> the patch didn't complain that the context was off.  Thanks for spotting
> this and I'll remove the duplicate.
You can check with:

riscv64-linux-gnu-rv64imafdc-lp64d-work $ make check-abi
[...]
if grep -q '^FAIL:' /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-work/*/check-abi*.test-result; then \
        cat /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-work/*/check-abi*.out && exit 1; fi
--- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist  2026-06-03 16:17:08.093669275 -0300
+++ /home/azanella/Projects/glibc/build/riscv64-linux-gnu-rv64imafdc-lp64d-work/libc.symlist    2026-06-05 13:54:35.058403411 -0300
@@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
-GLIBC_2.35 __memcmpeq F
  0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
make[1]: *** [Makerules:1310: check-abi] Error 1
make[1]: Leaving directory '/home/azanella/Projects/glibc/glibc-git-work'
make: *** [Makefile:20: check-abi] Error 2

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05 15:46       ` Peter Bergner
@ 2026-06-05 17:56         ` Andreas Schwab
  2026-06-05 20:37           ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Andreas Schwab @ 2026-06-05 17:56 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

On Jun 05 2026, Peter Bergner wrote:

> On 6/5/26 2:41 AM, Andreas Schwab wrote:
>> make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>> if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
>> 	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
>> --- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
>> +++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
>> @@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
>> -GLIBC_2.35 __memcmpeq F
>>   0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
>> make[1]: *** [Makerules:1310: check-abi] Error 1
>> make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>> make: *** [Makefile:20: check-abi] Error 2
                           ^^^^^^^^^
>
> How did you hit this?  Special configure or make/make check options?
> I did not see this in my builds or testing.

It's a normal test, see above.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05 17:56         ` Andreas Schwab
@ 2026-06-05 20:37           ` Peter Bergner
  2026-06-05 22:19             ` Andreas Schwab
  2026-06-08 17:35             ` Joseph Myers
  0 siblings, 2 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-05 20:37 UTC (permalink / raw)
  To: Andreas Schwab
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

On 6/5/26 12:56 PM, Andreas Schwab wrote:
> On Jun 05 2026, Peter Bergner wrote:
> 
>> On 6/5/26 2:41 AM, Andreas Schwab wrote:
>>> make[1]: Entering directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>>> if grep -q '^FAIL:' /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.test-result; then \
>>> 	cat /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/*/check-abi*.out && exit 1; fi
>>> --- ../sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist	2026-06-05 00:48:14.000000000 +0000
>>> +++ /home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b/cc-base/libc.symlist	2026-06-05 05:50:04.986000000 +0000
>>> @@ -2578 +2577,0 @@ GLIBC_2.34 tss_set F
>>> -GLIBC_2.35 __memcmpeq F
>>>   0x0278: Rev: 1  Flags: none  Index: 19  Cnt: 2  Name: GLIBC_ABI_DT_RELR
>>> make[1]: *** [Makerules:1310: check-abi] Error 1
>>> make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/glibc-2.43.9000.389.gc275c424b-build/glibc-2.43.9000.389.gc275c424b'
>>> make: *** [Makefile:20: check-abi] Error 2
>                            ^^^^^^^^^
>>
>> How did you hit this?  Special configure or make/make check options?
>> I did not see this in my builds or testing.
> 
> It's a normal test, see above.

Ok, my testing did not include make check-abi...I wasn't even aware of that. :-(
I'll add that to my build and testing process, thanks!

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05 20:37           ` Peter Bergner
@ 2026-06-05 22:19             ` Andreas Schwab
  2026-06-08 17:35             ` Joseph Myers
  1 sibling, 0 replies; 66+ messages in thread
From: Andreas Schwab @ 2026-06-05 22:19 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Yao Zihong, libc-alpha, adhemerval.zanella, andrew, jlaw,
	zhangyin2018, enh, zihongyao, Jerry Shih

On Jun 05 2026, Peter Bergner wrote:

> Ok, my testing did not include make check-abi

It's always included.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-05 20:37           ` Peter Bergner
  2026-06-05 22:19             ` Andreas Schwab
@ 2026-06-08 17:35             ` Joseph Myers
  2026-06-09  3:43               ` Zihong Yao
  1 sibling, 1 reply; 66+ messages in thread
From: Joseph Myers @ 2026-06-08 17:35 UTC (permalink / raw)
  To: Peter Bergner
  Cc: Andreas Schwab, Yao Zihong, libc-alpha, adhemerval.zanella,
	andrew, jlaw, zhangyin2018, enh, zihongyao, Jerry Shih

My bot is showing testsuite build failures for riscv (undefined reference 
to __memcmpeq building string/inl-tester).  It seems quite likely this is 
related to the problems reported by other people.

https://sourceware.org/pipermail/libc-testresults/2026q2/014717.html

-- 
Joseph S. Myers
josmyers@redhat.com


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 03/18] riscv: Add RVV memcmp for multiarch and non-multiarch
  2026-06-08 17:35             ` Joseph Myers
@ 2026-06-09  3:43               ` Zihong Yao
  0 siblings, 0 replies; 66+ messages in thread
From: Zihong Yao @ 2026-06-09  3:43 UTC (permalink / raw)
  To: josmyers
  Cc: adhemerval.zanella, andrew, bergner, enh, jerry.shih, jlaw,
	libc-alpha, schwab, zhangyin2018, zihong.plct, zihongyao

Thanks for catching this. It is caused by the ABI issue reported by
Andreas, and I have been testing the fix. A fix patch has just been
sent [1], and it also fixes this issue on my end.

[1] https://inbox.sourceware.org/libc-alpha/20260609032836.3427860-1-zihong.plct@isrc.iscas.ac.cn/

Zihong


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-05-05  2:52   ` Peter Bergner
@ 2026-06-09 13:46     ` Zihong Yao
  2026-06-09 19:56       ` Peter Bergner
  2026-06-21  4:07       ` Peter Bergner
  0 siblings, 2 replies; 66+ messages in thread
From: Zihong Yao @ 2026-06-09 13:46 UTC (permalink / raw)
  To: bergner
  Cc: adhemerval.zanella, andrew, enh, jerry.shih, jlaw, libc-alpha,
	schwab, zhangyin2018, zihong.plct, zihongyao

Hi Peter,

For memmove, the overlap handling is being updated in v6 to use the algorithm
you suggested. The updated version has shown better overall bench-memmove results.

The symbol export style is also being reworked for the following routines:
    memmove, strnlen, __memcmpeq, memrchr, strncat

In addition, a set of new routines is queued for testing and further
optimization, and is planned to be sent as part of v6.

With those changes, stpncpy and strncpy seem to be the only remaining routines
in the current v5 thread that still need review.

Thanks,
Zihong


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 04/18] riscv: Add RVV memcmpeq for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 04/18] riscv: Add RVV memcmpeq " Yao Zihong
@ 2026-06-09 18:59   ` Peter Bergner
  2026-06-09 19:10     ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-06-09 18:59 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Yun Hsiang

Thanks for fixing the __memcmpeq build issue and thanks to Adhemerval
for reviewing and pushing the fix!  I'm not sure why I didn't see that
failure when doing my memcmp testing.

That said, I know you're going to post a v6 of the memcmpeq patch,
but do look out for unneeded '_'s.  I believe all of the symbols
below would be just fine with only two '_'s, rather then four.


On 2/3/26 9:05 AM, Yao Zihong wrote:
> diff --git a/sysdeps/riscv/multiarch/memcmpeq-generic.c b/sysdeps/riscv/multiarch/memcmpeq-generic.c
[snip]
> +# define MEMCMP ____memcmpeq_generic


> diff --git a/sysdeps/riscv/multiarch/memcmpeq-vector.S b/sysdeps/riscv/multiarch/memcmpeq-vector.S
[snip]
> +# define MEMCMPEQ ____memcmpeq_vector


> diff --git a/sysdeps/riscv/rvv/memcmpeq.S b/sysdeps/riscv/rvv/memcmpeq.S
[snip]
> +# define MEMCMPEQ ____memcmpeq


Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 04/18] riscv: Add RVV memcmpeq for multiarch and non-multiarch
  2026-06-09 18:59   ` Peter Bergner
@ 2026-06-09 19:10     ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-09 19:10 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh,
	zihongyao, Yun Hsiang

On 6/9/26 1:59 PM, Peter Bergner wrote:
> That said, I know you're going to post a v6 of the memcmpeq patch,
> but do look out for unneeded '_'s.  I believe all of the symbols
> below would be just fine with only two '_'s, rather then four.
>
>> diff --git a/sysdeps/riscv/rvv/memcmpeq.S b/sysdeps/riscv/rvv/memcmpeq.S
> [snip]
>> +# define MEMCMPEQ ____memcmpeq

...of course, we'll need to remove the __memcmpeq alias in the
sysdeps/riscv/rvv/memcmp.S file too, since it isn't needed anymore
and would conflict with this new usage.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-06-09 13:46     ` Zihong Yao
@ 2026-06-09 19:56       ` Peter Bergner
  2026-07-03 23:38         ` Peter Bergner
  2026-06-21  4:07       ` Peter Bergner
  1 sibling, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-06-09 19:56 UTC (permalink / raw)
  To: Zihong Yao
  Cc: adhemerval.zanella, andrew, enh, jerry.shih, jlaw, libc-alpha,
	schwab, zhangyin2018, zihongyao

On 6/9/26 8:46 AM, Zihong Yao wrote:
> With those changes, stpncpy and strncpy seem to be the only remaining routines
> in the current v5 thread that still need review.


I'll note I see the following with the v5 stpncpy patch doing a normal
glibc build with -march=rv64gc (ie, no vector):


./../include/libc-symbols.h:475:33: error: '__EI___stpncpy' aliased to undefined symbol '__GI___stpncpy'
  475 |   extern thread __typeof (name) __EI_##name \
      |                                 ^~~~~
./../include/libc-symbols.h:471:3: note: in expansion of macro '__hidden_ver2'
  471 |   __hidden_ver2 (, local, internal, name)
      |   ^~~~~~~~~~~~~
./../include/libc-symbols.h:479:41: note: in expansion of macro '__hidden_ver1'
  479 | #  define hidden_def(name)              __hidden_ver1(__GI_##name, name, name);
      |                                         ^~~~~~~~~~~~~
./../include/libc-symbols.h:560:32: note: in expansion of macro 'hidden_def'
  560 | # define libc_hidden_def(name) hidden_def (name)
      |                                ^~~~~~~~~~
../sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c:50:1: note: in expansion of macro 'libc_hidden_def'
   50 | libc_hidden_def (__stpncpy);
      | ^~~~~~~~~~~~~~~

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-06-09 13:46     ` Zihong Yao
  2026-06-09 19:56       ` Peter Bergner
@ 2026-06-21  4:07       ` Peter Bergner
  1 sibling, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-06-21  4:07 UTC (permalink / raw)
  To: Zihong Yao
  Cc: adhemerval.zanella, andrew, enh, jerry.shih, jlaw, libc-alpha,
	schwab, zhangyin2018, zihongyao

On 6/9/26 8:46 AM, Zihong Yao wrote:
> For memmove, the overlap handling is being updated in v6 to use the algorithm
> you suggested. The updated version has shown better overall bench-memmove results.

So the soft freeze for the upcoming release is today and I didn't want
memmove to miss the release, so I rewrote the overlap handling myself,
simplified some of the register use (ie, got rid of the {src,dst}_backward_ptr
regs), tested it and pushed it.

Please don't feel that what I pushed is "final".  If your v6 memove changes
are better, them I'm all for using them, I just wanted something in before
the soft freeze.  Post patches against the new upstream code to bring it
into alignment with your code if your code is better.



> The symbol export style is also being reworked for the following routines:
>     memmove, strnlen, __memcmpeq, memrchr, strncat

The same goes for this, if your v6 is better, then make a patch on
the currently upstream rvv memmove code.



> In addition, a set of new routines is queued for testing and further
> optimization, and is planned to be sent as part of v6.

Depending on the hardness of the soft-freeze and the number of functions,
these may need to wait until after the release.  



> With those changes, stpncpy and strncpy seem to be the only remaining routines
> in the current v5 thread that still need review.

...so let's get the rest of the missing v5 functions handled first before
we start on any new functions not already posted.

Peter


^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-06-09 19:56       ` Peter Bergner
@ 2026-07-03 23:38         ` Peter Bergner
  2026-07-05 13:45           ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-07-03 23:38 UTC (permalink / raw)
  To: Zihong Yao
  Cc: adhemerval.zanella, andrew, enh, jerry.shih, jlaw, libc-alpha,
	schwab, zhangyin2018, zihongyao

On 6/9/26 2:56 PM, Peter Bergner wrote:
> I'll note I see the following with the v5 stpncpy patch doing a normal
> glibc build with -march=rv64gc (ie, no vector):
> 
> 
> ./../include/libc-symbols.h:475:33: error: '__EI___stpncpy' aliased to undefined symbol '__GI___stpncpy'
>   475 |   extern thread __typeof (name) __EI_##name \
>       |                                 ^~~~~
> ./../include/libc-symbols.h:471:3: note: in expansion of macro '__hidden_ver2'
>   471 |   __hidden_ver2 (, local, internal, name)
>       |   ^~~~~~~~~~~~~
> ./../include/libc-symbols.h:479:41: note: in expansion of macro '__hidden_ver1'
>   479 | #  define hidden_def(name)              __hidden_ver1(__GI_##name, name, name);
>       |                                         ^~~~~~~~~~~~~
> ./../include/libc-symbols.h:560:32: note: in expansion of macro 'hidden_def'
>   560 | # define libc_hidden_def(name) hidden_def (name)
>       |                                ^~~~~~~~~~
> ../sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c:50:1: note: in expansion of macro 'libc_hidden_def'
>    50 | libc_hidden_def (__stpncpy);
>       | ^~~~~~~~~~~~~~~

Given the freeze is coming this weekend, I spent some time fixing this issue, as well as a few others
once this issue is fixed.  Basically, I needed the following patch to fix the compile and
make chack-abi errors:

@@ -19,9 +19,11 @@

 #if IS_IN (libc)
 /* Redefine stpncpy so that the compiler won't complain about the type
-   mismatch with the IFUNC selector in strong_alias, below.  */
+   mismatch with the IFUNC selector in weak_alias, below.  */
 # undef stpncpy
+# undef __stpncpy
 # define stpncpy __redirect_stpncpy
+# define __stpncpy __redirect___stpncpy
 # include <stdint.h>
 # include <string.h>
 # include <ifunc-init.h>
@@ -46,10 +48,11 @@
 riscv_libc_ifunc (__libc_stpncpy, select_stpncpy_ifunc);

 # undef stpncpy
+# undef __stpncpy
 weak_alias (__libc_stpncpy, stpncpy);
-libc_hidden_def (__stpncpy);
+weak_alias (__libc_stpncpy, __stpncpy);
 # ifdef SHARED
-__hidden_ver1 (stpncpy, __GI_stpncpy, __redirect_stpncpy)
+__hidden_ver1 (stpncpy, __GI___stpncpy, __redirect_stpncpy)
   __attribute__ ((visibility ("hidden"))) __attribute_copy__ (stpncpy);
 # endif
 #else

That said, I went a little further and made a couple more changes to stpncpy.c to make our
implementation use the macros defined in ifunc-init.h similar to x86_64's.  I'm including
the full updated patch below which includes some comment fixes in the stpncpy.S file too.
I plan on pushing this commit tomorrow unless someone notices a problem with it.

Peter




riscv: Add RVV stpncpy for both multiarch and non-multiarch builds

This patch adds an RVV-optimized implementation of stpncpy for RISC-V and
enables it for both multiarch (IFUNC) and non-multiarch builds.

The implementation integrates Hau Hsu's 2023 RVV work under a unified
ifunc-based framework. A vectorized version (__stpncpy_vector) is added
alongside the generic fallback (__stpncpy_generic). The runtime resolver
selects the RVV variant when RISCV_HWPROBE_KEY_IMA_EXT_0 reports vector
support (RVV).

Currently, the resolver still selects the RVV variant even when the RVV
extension is disabled via prctl(). As a consequence, any process that
has RVV disabled via prctl() will receive SIGILL when calling stpncpy().

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
Reviewed-by: Peter Bergner <bergner@tenstorrent.com>
---
 sysdeps/riscv/multiarch/stpncpy-generic.c     | 28 ++++++
 sysdeps/riscv/multiarch/stpncpy-vector.S      | 28 ++++++
 sysdeps/riscv/rvv/stpncpy.S                   | 97 +++++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 +
 .../unix/sysv/linux/riscv/multiarch/stpncpy.c | 62 ++++++++++++
 6 files changed, 223 insertions(+)
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/stpncpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/stpncpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c

diff --git a/sysdeps/riscv/multiarch/stpncpy-generic.c b/sysdeps/riscv/multiarch/stpncpy-generic.c
new file mode 100644
index 0000000000..4be8080d88
--- /dev/null
+++ b/sysdeps/riscv/multiarch/stpncpy-generic.c
@@ -0,0 +1,28 @@
+/* Re-include the default stpncpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STPNCPY __stpncpy_generic
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(x, x2)
+# include <string/stpncpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/stpncpy-vector.S b/sysdeps/riscv/multiarch/stpncpy-vector.S
new file mode 100644
index 0000000000..e84d28a1e4
--- /dev/null
+++ b/sysdeps/riscv/multiarch/stpncpy-vector.S
@@ -0,0 +1,28 @@
+/* Re-include the RISC-V RVV based stpncpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STPNCPY __stpncpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(name)
+# undef libc_hidden_def
+# define libc_hidden_def(name)
+# undef weak_alias
+# define weak_alias(name, alias)
+# include <sysdeps/riscv/rvv/stpncpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/stpncpy.S b/sysdeps/riscv/rvv/stpncpy.S
new file mode 100644
index 0000000000..7cfc2f76cc
--- /dev/null
+++ b/sysdeps/riscv/rvv/stpncpy.S
@@ -0,0 +1,97 @@
+/* RISC-V RVV based stpncpy.
+   Copyright (C) 2026 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>
+
+#ifndef STPNCPY
+# ifdef weak_alias
+#  define STPNCPY __stpncpy
+weak_alias (__stpncpy, stpncpy)
+# else
+#  define STPNCPY stpncpy
+# endif
+#endif
+
+#define dst a0
+#define src a1
+#define length a2
+#define dst_ptr a3
+#define active_elem_pos a4
+#define cur_vl a5
+#define ivl a6
+#define temp a1
+
+#define ELEM_LMUL_SETTING m1
+#define vmask1 v0
+#define vmask2 v1
+#define ZERO_FILL_ELEM_LMUL_SETTING m8
+#define vstr1 v8
+#define vstr2 v16
+
+ENTRY (STPNCPY)
+.option push
+.option arch, +v
+    mv dst_ptr, dst
+    /* Copy src to dst_ptr.  */
+L(stpcpy_loop):
+    vsetvli zero, length, e8, ELEM_LMUL_SETTING, ta, ma
+    vle8ff.v vstr1, (src)
+    vmseq.vx vmask2, vstr1, zero
+    csrr cur_vl, vl
+    vfirst.m active_elem_pos, vmask2
+    vmsif.m vmask1, vmask2
+    add src, src, cur_vl
+    sub length, length, cur_vl
+    vse8.v vstr1, (dst_ptr), vmask1.t
+    add dst_ptr, dst_ptr, cur_vl
+    bgez active_elem_pos, L(fill_zero)
+    bnez length, L(stpcpy_loop)
+    mv dst, dst_ptr
+    ret
+
+    /* Fill the tail zero.  */
+L(fill_zero):
+    /* We already copied the `\0` to dst, but we use `vfirst.m` to
+       get the `index` of the `\0` position. We need to adjust by `-1`
+       to get the correct remaining length for zero filling.  */
+    sub temp, cur_vl, active_elem_pos
+    addi temp, temp, -1
+    sub dst, dst_ptr, cur_vl
+    add dst, dst, active_elem_pos
+    add length, length, temp
+    /* Return early for the `strlen(src) + 1 == count` case.  */
+    bnez length, L(do_fill_zero)
+    ret
+
+L(do_fill_zero):
+    sub dst_ptr, dst_ptr, temp
+    vsetvli zero, length, e8, ZERO_FILL_ELEM_LMUL_SETTING, ta, ma
+    vmv.v.x vstr2, zero
+L(fill_zero_loop):
+    vsetvli ivl, length, e8, ZERO_FILL_ELEM_LMUL_SETTING, ta, ma
+    vse8.v vstr2, (dst_ptr)
+    sub length, length, ivl
+    add dst_ptr, dst_ptr, ivl
+    bnez length, L(fill_zero_loop)
+    ret
+.option pop
+END (STPNCPY)
+#ifdef weak_alias
+libc_hidden_def (__stpncpy)
+#endif
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 929df14a6f..25d8216d2e 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -19,6 +19,9 @@ sysdep_routines += \
   memset \
   memset-generic \
   memset-vector \
+  stpncpy \
+  stpncpy-generic \
+  stpncpy-vector \
   strcat \
   strcat-generic \
   strcat-vector \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 4c28e22606..755ba9d637 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -110,5 +110,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __memmove_vector)
 	      IFUNC_IMPL_ADD (array, i, memmove, 1, __memmove_generic))
 
+  IFUNC_IMPL (i, name, stpncpy,
+	      IFUNC_IMPL_ADD (array, i, stpncpy, rvv_enabled,
+			      __stpncpy_vector)
+	      IFUNC_IMPL_ADD (array, i, stpncpy, 1, __stpncpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
new file mode 100644
index 0000000000..989003f081
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/stpncpy.c
@@ -0,0 +1,62 @@
+/* Multiple versions of stpncpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+#define SYMBOL_NAME stpncpy
+# include <ifunc-init.h>
+
+/* Redefine stpncpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in weak_alias, below.  */
+# undef stpncpy
+# undef __stpncpy
+# define stpncpy REDIRECT_NAME
+# define __stpncpy __redirect___stpncpy
+# include <string.h>
+# undef stpncpy
+# undef __stpncpy
+
+# include <stdint.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (REDIRECT_NAME) __stpncpy;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (generic) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (vector) attribute_hidden;
+
+static inline __typeof (REDIRECT_NAME) *
+select_stpncpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return OPTIMIZE (vector);
+  return OPTIMIZE (generic);
+}
+
+riscv_libc_ifunc (__stpncpy, select_stpncpy_ifunc);
+
+weak_alias (__stpncpy, stpncpy);
+
+# ifdef SHARED
+__hidden_ver1 (__stpncpy, __GI___stpncpy, __redirect___stpncpy)
+  __attribute__ ((visibility ("hidden")));
+# endif
+#else
+# include <string/stpncpy.c>
+#endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 16/18] riscv: Add RVV strncpy for multiarch and non-multiarch
  2026-02-03 15:05 ` [PATCH v5 16/18] riscv: Add RVV strncpy " Yao Zihong
@ 2026-07-03 23:44   ` Peter Bergner
  2026-07-05 13:46     ` Peter Bergner
  0 siblings, 1 reply; 66+ messages in thread
From: Peter Bergner @ 2026-07-03 23:44 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh, zihongyao

On 2/3/26 9:05 AM, Yao Zihong wrote:
> Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
> ---
>  sysdeps/riscv/multiarch/strncpy-generic.c     | 26 +++++++++
>  sysdeps/riscv/multiarch/strncpy-vector.S      | 24 ++++++++
>  sysdeps/riscv/rvv/stpncpy.S                   | 27 +++++++--
>  sysdeps/riscv/rvv/strncpy.S                   | 20 +++++++
>  .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
>  .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
>  .../unix/sysv/linux/riscv/multiarch/stpncpy.c | 15 ++---
>  .../unix/sysv/linux/riscv/multiarch/strncpy.c | 56 +++++++++++++++++++
>  8 files changed, 164 insertions(+), 12 deletions(-)
>  create mode 100644 sysdeps/riscv/multiarch/strncpy-generic.c
>  create mode 100644 sysdeps/riscv/multiarch/strncpy-vector.S
>  create mode 100644 sysdeps/riscv/rvv/strncpy.S
>  create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c

LGTM, modulo I modified the multiarch/stpncpy.c to again use the special
macros from ifunc-init.h to simplify the implementation a little more,
similar to the stpncpy.c change I replied to earlier.
The updated patch passed make check-abi and a normal make check.
Given the freeze, I plan on pushing this commit tomorrow unless there
are any objections due to issues they see.

Reviewed-by: Peter Bergner <bergner@tenstorrent.com>


I've attached the full updated patch below for awareness.


Peter



riscv: Add RVV strncpy for both multiarch and non-multiarch builds

This patch adds an RVV-optimized implementation of strncpy for RISC-V and
enables it for both multiarch (IFUNC) and non-multiarch builds.

The implementation integrates Hau Hsu's 2023 RVV work under a unified
ifunc-based framework. A vectorized version (__strncpy_vector) is added
alongside the generic fallback (__strncpy_generic). The runtime resolver
selects the RVV variant when RISCV_HWPROBE_KEY_IMA_EXT_0 reports vector
support (RVV).

Currently, the resolver still selects the RVV variant even when the RVV
extension is disabled via prctl(). As a consequence, any process that
has RVV disabled via prctl() will receive SIGILL when calling strncpy().

Co-authored-by: Hau Hsu <hau.hsu@sifive.com>
Co-authored-by: Jerry Shih <jerry.shih@sifive.com>
Signed-off-by: Yao Zihong <zihong.plct@isrc.iscas.ac.cn>
Reviewed-by: Peter Bergner <bergner@tenstorrent.com>
---
 sysdeps/riscv/multiarch/strncpy-generic.c     | 26 ++++++++
 sysdeps/riscv/multiarch/strncpy-vector.S      | 24 ++++++++
 sysdeps/riscv/rvv/stpncpy.S                   | 27 +++++++--
 sysdeps/riscv/rvv/strncpy.S                   | 20 +++++++
 .../unix/sysv/linux/riscv/multiarch/Makefile  |  3 +
 .../linux/riscv/multiarch/ifunc-impl-list.c   |  5 ++
 .../unix/sysv/linux/riscv/multiarch/strncpy.c | 59 +++++++++++++++++++
 7 files changed, 159 insertions(+), 5 deletions(-)
 create mode 100644 sysdeps/riscv/multiarch/strncpy-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncpy-vector.S
 create mode 100644 sysdeps/riscv/rvv/strncpy.S
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c

diff --git a/sysdeps/riscv/multiarch/strncpy-generic.c b/sysdeps/riscv/multiarch/strncpy-generic.c
new file mode 100644
index 0000000000..726ca9ed5f
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncpy-generic.c
@@ -0,0 +1,26 @@
+/* Re-include the default strncpy implementation.
+   Copyright (C) 2026 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 <string.h>
+
+#if IS_IN(libc)
+# define STRNCPY __strncpy_generic
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <string/strncpy.c>
+#endif
diff --git a/sysdeps/riscv/multiarch/strncpy-vector.S b/sysdeps/riscv/multiarch/strncpy-vector.S
new file mode 100644
index 0000000000..32256f7695
--- /dev/null
+++ b/sysdeps/riscv/multiarch/strncpy-vector.S
@@ -0,0 +1,24 @@
+/* Re-include the RISC-V RVV based strncpy implementation.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN(libc)
+# define STRNCPY __strncpy_vector
+# undef libc_hidden_builtin_def
+# define libc_hidden_builtin_def(x)
+# include <sysdeps/riscv/rvv/strncpy.S>
+#endif
diff --git a/sysdeps/riscv/rvv/stpncpy.S b/sysdeps/riscv/rvv/stpncpy.S
index 7cfc2f76cc..71bb46b04e 100644
--- a/sysdeps/riscv/rvv/stpncpy.S
+++ b/sysdeps/riscv/rvv/stpncpy.S
@@ -19,12 +19,20 @@
 #include <sysdep.h>
 #include <sys/asm.h>
 
-#ifndef STPNCPY
-# ifdef weak_alias
-#  define STPNCPY __stpncpy
+#ifndef USE_AS_STRNCPY
+# ifndef STPNCPY
+#  ifdef weak_alias
+#   define STPNCPY __stpncpy
 weak_alias (__stpncpy, stpncpy)
+#  else
+#   define STPNCPY stpncpy
+#  endif
+# endif
+#else
+# ifndef STRNCPY
+#  define STPNCPY strncpy
 # else
-#  define STPNCPY stpncpy
+#  define STPNCPY STRNCPY
 # endif
 #endif
 
@@ -62,7 +70,9 @@ L(stpcpy_loop):
     add dst_ptr, dst_ptr, cur_vl
     bgez active_elem_pos, L(fill_zero)
     bnez length, L(stpcpy_loop)
+#ifndef USE_AS_STRNCPY
     mv dst, dst_ptr
+#endif
     ret
 
     /* Fill the tail zero.  */
@@ -72,8 +82,10 @@ L(fill_zero):
        to get the correct remaining length for zero filling.  */
     sub temp, cur_vl, active_elem_pos
     addi temp, temp, -1
+#ifndef USE_AS_STRNCPY
     sub dst, dst_ptr, cur_vl
     add dst, dst, active_elem_pos
+#endif
     add length, length, temp
     /* Return early for the `strlen(src) + 1 == count` case.  */
     bnez length, L(do_fill_zero)
@@ -92,6 +104,11 @@ L(fill_zero_loop):
     ret
 .option pop
 END (STPNCPY)
-#ifdef weak_alias
+
+#ifndef USE_AS_STRNCPY
+# ifdef weak_alias
 libc_hidden_def (__stpncpy)
+# endif
+#else
+libc_hidden_builtin_def (strncpy)
 #endif
diff --git a/sysdeps/riscv/rvv/strncpy.S b/sysdeps/riscv/rvv/strncpy.S
new file mode 100644
index 0000000000..961c16416e
--- /dev/null
+++ b/sysdeps/riscv/rvv/strncpy.S
@@ -0,0 +1,20 @@
+/* RISC-V RVV based strncpy.
+   Copyright (C) 2026 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/>.  */
+
+#define USE_AS_STRNCPY
+#include <sysdeps/riscv/rvv/stpncpy.S>
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
index 25d8216d2e..4991466369 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/Makefile
@@ -40,6 +40,9 @@ sysdep_routines += \
   strncmp \
   strncmp-generic \
   strncmp-vector \
+  strncpy \
+  strncpy-generic \
+  strncpy-vector \
   strrchr \
   strrchr-generic \
   strrchr-vector \
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
index 755ba9d637..ac2b25de74 100644
--- a/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/ifunc-impl-list.c
@@ -115,5 +115,10 @@ __libc_ifunc_impl_list (const char *name, struct libc_ifunc_impl *array,
 			      __stpncpy_vector)
 	      IFUNC_IMPL_ADD (array, i, stpncpy, 1, __stpncpy_generic))
 
+  IFUNC_IMPL (i, name, strncpy,
+	      IFUNC_IMPL_ADD (array, i, strncpy, rvv_enabled,
+			      __strncpy_vector)
+	      IFUNC_IMPL_ADD (array, i, strncpy, 1, __strncpy_generic))
+
   return 0;
 }
diff --git a/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c b/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c
new file mode 100644
index 0000000000..2ed6878bfd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/riscv/multiarch/strncpy.c
@@ -0,0 +1,59 @@
+/* Multiple versions of strncpy.
+   All versions must be listed in ifunc-impl-list.c.
+   Copyright (C) 2026 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/>.  */
+
+#if IS_IN (libc)
+#define SYMBOL_NAME strncpy
+# include <ifunc-init.h>
+
+/* Redefine strncpy so that the compiler won't complain about the type
+   mismatch with the IFUNC selector in strong_alias, below.  */
+# undef strncpy
+# define strncpy REDIRECT_NAME
+# include <string.h>
+# undef strncpy
+
+# include <stdint.h>
+# include <riscv-ifunc.h>
+# include <sys/hwprobe.h>
+
+extern __typeof (REDIRECT_NAME) __strncpy;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (generic) attribute_hidden;
+extern __typeof (REDIRECT_NAME) OPTIMIZE (vector) attribute_hidden;
+
+static inline __typeof (REDIRECT_NAME) *
+select_strncpy_ifunc (uint64_t dl_hwcap, __riscv_hwprobe_t hwprobe_func)
+{
+  unsigned long long int v;
+  if (__riscv_hwprobe_one (hwprobe_func, RISCV_HWPROBE_KEY_IMA_EXT_0, &v) == 0
+      && (v & RISCV_HWPROBE_IMA_V) == RISCV_HWPROBE_IMA_V)
+    return OPTIMIZE (vector);
+  return OPTIMIZE (generic);
+}
+
+riscv_libc_ifunc (__strncpy, select_strncpy_ifunc);
+
+strong_alias (__strncpy, strncpy);
+
+# ifdef SHARED
+__hidden_ver1 (strncpy, __GI_strncpy, REDIRECT_NAME)
+  __attribute__ ((visibility ("hidden"))) __attribute_copy__ (strncpy);
+# endif
+#else
+# include <string/strncpy.c>
+#endif
-- 
2.43.0



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 06/18] riscv: Add RVV memmove for multiarch and non-multiarch
  2026-07-03 23:38         ` Peter Bergner
@ 2026-07-05 13:45           ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-07-05 13:45 UTC (permalink / raw)
  To: Zihong Yao
  Cc: adhemerval.zanella, andrew, enh, jerry.shih, jlaw, libc-alpha,
	schwab, zhangyin2018, zihongyao

On 7/3/26 6:38 PM, Peter Bergner wrote:
> That said, I went a little further and made a couple more changes to stpncpy.c to make our
> implementation use the macros defined in ifunc-init.h similar to x86_64's.  I'm including
> the full updated patch below which includes some comment fixes in the stpncpy.S file too.
> I plan on pushing this commit tomorrow unless someone notices a problem with it.

I went ahead and pushed the stpncpy commit as slightly modified by me.


Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

* Re: [PATCH v5 16/18] riscv: Add RVV strncpy for multiarch and non-multiarch
  2026-07-03 23:44   ` Peter Bergner
@ 2026-07-05 13:46     ` Peter Bergner
  0 siblings, 0 replies; 66+ messages in thread
From: Peter Bergner @ 2026-07-05 13:46 UTC (permalink / raw)
  To: Yao Zihong, libc-alpha
  Cc: adhemerval.zanella, andrew, schwab, jlaw, zhangyin2018, enh, zihongyao

On 7/3/26 6:44 PM, Peter Bergner wrote:
> LGTM, modulo I modified the multiarch/stpncpy.c to again use the special
> macros from ifunc-init.h to simplify the implementation a little more,
> similar to the stpncpy.c change I replied to earlier.
> The updated patch passed make check-abi and a normal make check.
> Given the freeze, I plan on pushing this commit tomorrow unless there
> are any objections due to issues they see.

Pushed.

Peter



^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2026-07-05 13:46 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-03 15:05 [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Yao Zihong
2026-02-03 15:05 ` [PATCH v5 01/18] riscv: Add RVV memccpy for multiarch and non-multiarch Yao Zihong
2026-06-05  2:02   ` [EXT] " Peter Bergner
2026-02-03 15:05 ` [PATCH v5 02/18] riscv: Add RVV memchr " Yao Zihong
2026-06-05  2:03   ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 03/18] riscv: Add RVV memcmp " Yao Zihong
2026-06-05  0:06   ` Peter Bergner
2026-06-05  7:41     ` Andreas Schwab
2026-06-05 12:38       ` 姚子宏
2026-06-05 12:58         ` Adhemerval Zanella Netto
2026-06-05 15:46       ` Peter Bergner
2026-06-05 17:56         ` Andreas Schwab
2026-06-05 20:37           ` Peter Bergner
2026-06-05 22:19             ` Andreas Schwab
2026-06-08 17:35             ` Joseph Myers
2026-06-09  3:43               ` Zihong Yao
2026-02-03 15:05 ` [PATCH v5 04/18] riscv: Add RVV memcmpeq " Yao Zihong
2026-06-09 18:59   ` Peter Bergner
2026-06-09 19:10     ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 05/18] riscv: Add RVV memcpy " Yao Zihong
2026-04-22 21:21   ` [EXT] " Peter Bergner
2026-04-23  4:28     ` Aurelien Jarno
2026-04-23 13:25       ` Peter Bergner
2026-06-05 16:55         ` Adhemerval Zanella Netto
2026-02-03 15:05 ` [PATCH v5 06/18] riscv: Add RVV memmove " Yao Zihong
2026-05-05  2:52   ` Peter Bergner
2026-06-09 13:46     ` Zihong Yao
2026-06-09 19:56       ` Peter Bergner
2026-07-03 23:38         ` Peter Bergner
2026-07-05 13:45           ` Peter Bergner
2026-06-21  4:07       ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 07/18] riscv: Add RVV memrchr " Yao Zihong
2026-02-03 15:05 ` [PATCH v5 08/18] riscv: Add RVV stpncpy " Yao Zihong
2026-02-03 15:05 ` [PATCH v5 09/18] riscv: Add RVV strcat " Yao Zihong
2026-04-20 15:37   ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 10/18] riscv: Add RVV strchr " Yao Zihong
2026-06-05  2:04   ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 11/18] riscv: Add RVV strcmp " Yao Zihong
2026-05-06 19:15   ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 12/18] riscv: Add RVV strcpy " Yao Zihong
2026-04-21  0:48   ` [EXT] " Peter Bergner
2026-04-21 18:22     ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 13/18] riscv: Add RVV strlen " Yao Zihong
2026-04-20 20:22   ` Peter Bergner
2026-04-27 14:21     ` Zihong Yao
2026-05-04 19:40       ` Peter Bergner
2026-05-10  9:48         ` Andreas Schwab
2026-05-10 12:09           ` H.J. Lu
2026-05-11  6:25             ` Peter Bergner
2026-05-11 14:24               ` Adhemerval Zanella Netto
2026-05-11 19:49                 ` Peter Bergner
2026-05-11 20:10                   ` Adhemerval Zanella Netto
2026-05-11 22:26                     ` Jeffrey Law
2026-02-03 15:05 ` [PATCH v5 14/18] riscv: Add RVV strncat " Yao Zihong
2026-04-20 15:47   ` Peter Bergner
2026-04-27 14:17     ` Zihong Yao
2026-02-03 15:05 ` [PATCH v5 15/18] riscv: Add RVV strncmp " Yao Zihong
2026-05-06 19:18   ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 16/18] riscv: Add RVV strncpy " Yao Zihong
2026-07-03 23:44   ` Peter Bergner
2026-07-05 13:46     ` Peter Bergner
2026-02-03 15:05 ` [PATCH v5 17/18] riscv: Add RVV strnlen " Yao Zihong
2026-02-03 15:05 ` [PATCH v5 18/18] riscv: Add RVV strrchr " Yao Zihong
2026-06-05  2:06   ` Peter Bergner
2026-02-24 16:40 ` [PATCH v5 00/18] riscv: Add RVV str*/mem* routines Peter Bergner
2026-04-17  7:03 ` Zihong Yao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).