From: Pincheng Wang <pincheng.plct@isrc.iscas.ac.cn>
To: musl@lists.openwall.com
Cc: pincheng.plct@isrc.iscas.ac.cn
Subject: [musl] [PATCH v3 0/1] riscv64: Add RVV optimized memset implementation
Date: Thu, 30 Oct 2025 20:09:07 +0800 [thread overview]
Message-ID: <20251030120908.47909-1-pincheng.plct@isrc.iscas.ac.cn> (raw)
Hi all,
This is v3 of the RISC-V Vector (RVV) optimized memset patch.
Changes from v2:
- Drop global vector disable in arch.mak; explicitly enable 'V'
extension via `.option arch` in memset_vector.S.
- Use __getauxval instead of getauxval and rename memset_{scalar,vect}
to __memset_{scalar,vect} to avoid symbol conflicts.
- Remove the small-size fast path; now use vector code uniformly for all
sizes to avoid branch mispredictions and simplify control flow.
Changes from v1:
- Replaced compile-time detection (__riscv_vetor macro) with runtime
detection using AT_HWCAP, addressing the main concern from v1
feedback.
- Introduced a dispatch mechanism (memset_dispatch.c) that selects
appropriate implementation at process startup.
Implementation details:
- memset.c is renamed internally to __memset_scalar via macro,
preserving the generic C implementation scalar fallback.
- memset_vector.S provides the optimized __memset_vector symbol.
- memset_dispatch.c exports the public memset() symbol, which dispatches
via function pointer.
- __init_riscv_string_optimizations is called in __libc_start_main to
initialize the function pointer based on AT_HWCAP.
- The vector implementation uses vsetvli for bulk fills.
Performance:
- On Spacemit X60: up to ~3.36x faster (256B), with consistent gains
across medium and large sizes.
For very small sizes (<8 bytes), there can be minor regressions compared
to the generic C version. This is trade off for the significant gains on
larger sizes.
Testing:
- QEMU with QEMU_CPU="rv64,v=true" and "rv64,v=false".
- Spacemit X60 with V extension support.
- CFLAGS="-march=rv64gc" and "-march=rv64gcv".
Functional behavior matches generic memset.
Thanks,
Pincheng Wang
Pincheng Wang (1):
riscv64: add runtime-detected vector optimized memset
src/env/__libc_start_main.c | 3 +++
src/internal/libc.h | 3 +++
src/string/riscv64/memset.c | 4 ++++
src/string/riscv64/memset_dispatch.c | 36 ++++++++++++++++++++++++++++
src/string/riscv64/memset_vector.S | 28 ++++++++++++++++++++++
5 files changed, 74 insertions(+)
create mode 100644 src/string/riscv64/memset.c
create mode 100644 src/string/riscv64/memset_dispatch.c
create mode 100644 src/string/riscv64/memset_vector.S
--
2.39.5
next reply other threads:[~2025-10-30 12:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 12:09 Pincheng Wang [this message]
2025-10-30 12:09 ` [musl] [PATCH v3 1/1] riscv64: add runtime-detected vector optimized memset 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=20251030120908.47909-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).