mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH v2 0/1] riscv64: add optimized string functions
@ 2025-11-19  5:40 Pincheng Wang
  2025-11-19  5:40 ` [musl] [PATCH v2 1/1] riscv64: add optimized memset, memcpy and memmove Pincheng Wang
  0 siblings, 1 reply; 2+ messages in thread
From: Pincheng Wang @ 2025-11-19  5:40 UTC (permalink / raw)
  To: musl; +Cc: pincheng.plct

Hi all,

This patch series supersedes my previous RVV-optimized memset patch
series, now extending support to memmove and memcpy as well. It provides
optimized versions of these string functions for RISC-V with vector
extension, dispatching at runtime based on CPU capability (RVV support).

Changes from v1:
- Change function pointers' attribute from hidden to static.
- Change conditional compilation condition from __riscv to __riscv &&
  __riscv_xlen==64.

Implementation details:
- mem{set,cpy,move}.c are renamed internally to
  __mem{set,cpy,move}_scalar via macro, preserving the generic C
  implementation scalar fallback.
- mem{set,cpy,move}_vector.S provide the optimized
  __mem{set,cpy,move}_vector symbols.
- string_dispatch.c exports the public mem{set,cpy,move}() symbols,
  which dispatches via function pointer.
- __init_riscv_string_optimizations is called in __libc_start_main to
  initialize function pointers based on AT_HWCAP.
- The vector implementation uses m8 register grouping for bulk fills.

Performance:
Function	Size	Improvement
memset		16B		0.06%
memset		64B		49.22%
memset		256B	127.81%
memset		1KB		58.12%
memset		4KB		47.95%
memset		64KB	2.56%

memcpy		16B		0.02%
memcpy		64B		35.94%
memcpy		256B	205.10%
memcpy		1KB		126.01%
memcpy		4KB		107.71%
memcpy		64KB	36.15%

memmove_bwd	16B		-0.67%
memmove_bwd	64B		47.03%
memmove_bwd	256B	207.32%
memmove_bwd	1KB		125.33%
memmove_bwd	4KB		106.72%
memmove_bwd	64KB	41.46%
Benchmarks are conducted on a Spacemit X60 CPU.

Functional behavior matches generic functions.

Thanks,
Pincheng Wang

Pincheng Wang (1):
  riscv64: add optimized memset, memcpy and memmove

 src/env/__libc_start_main.c          |  3 ++
 src/internal/libc.h                  |  3 ++
 src/string/riscv64/memcpy.c          |  4 +++
 src/string/riscv64/memcpy_vector.S   | 28 +++++++++++++++
 src/string/riscv64/memmove.c         |  4 +++
 src/string/riscv64/memmove_vector.S  | 52 ++++++++++++++++++++++++++++
 src/string/riscv64/memset.c          |  4 +++
 src/string/riscv64/memset_vector.S   | 29 ++++++++++++++++
 src/string/riscv64/string_dispatch.c | 52 ++++++++++++++++++++++++++++
 9 files changed, 179 insertions(+)
 create mode 100644 src/string/riscv64/memcpy.c
 create mode 100644 src/string/riscv64/memcpy_vector.S
 create mode 100644 src/string/riscv64/memmove.c
 create mode 100644 src/string/riscv64/memmove_vector.S
 create mode 100644 src/string/riscv64/memset.c
 create mode 100644 src/string/riscv64/memset_vector.S
 create mode 100644 src/string/riscv64/string_dispatch.c

-- 
2.39.5


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

end of thread, other threads:[~2025-11-19  5:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-19  5:40 [musl] [PATCH v2 0/1] riscv64: add optimized string functions Pincheng Wang
2025-11-19  5:40 ` [musl] [PATCH v2 1/1] riscv64: add optimized memset, memcpy and memmove Pincheng Wang

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).