mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Pincheng Wang <pincheng.plct@isrc.iscas.ac.cn>
To: musl@lists.openwall.com
Cc: pincheng.plct@isrc.iscas.ac.cn
Subject: [musl] [PATCH v2 0/1] riscv64: add optimized string functions
Date: Wed, 19 Nov 2025 13:40:58 +0800	[thread overview]
Message-ID: <20251119054059.514848-1-pincheng.plct@isrc.iscas.ac.cn> (raw)

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


             reply	other threads:[~2025-11-19  5:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-19  5:40 Pincheng Wang [this message]
2025-11-19  5:40 ` [musl] [PATCH v2 1/1] riscv64: add optimized memset, memcpy and memmove Pincheng Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251119054059.514848-1-pincheng.plct@isrc.iscas.ac.cn \
    --to=pincheng.plct@isrc.iscas.ac.cn \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).