mailing list of musl libc
 help / color / mirror / code / Atom feed
blob cd0d1fbc6ab324ecfdb638101222207299c4bd96 1676 bytes (raw)
name: src/string/riscv64/string_dispatch.c 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
#include <stddef.h>
#include <sys/auxv.h>
#include "libc.h"

void *__memset_scalar(void *s, int c, size_t n);
void *__memset_vect(void *s, int c, size_t n);
void *__memcpy_scalar(void *restrict dest, const void *restrict src, size_t n);
void *__memcpy_vect(void *restrict dest, const void *restrict src, size_t n);
void *__memmove_scalar(void *restrict dest, const void *restrict src, size_t n);
void *__memmove_vect(void *restrict dest, const void *restrict src, size_t n);

/* string function pointer, runtime-dispatched based on RVV support */
#ifndef __riscv_vector
static void *(*__memset_ptr)(void *, int, size_t) = __memset_scalar;
static void *(*__memcpy_ptr)(void *, const void *, size_t) = __memcpy_scalar;
static void *(*__memmove_ptr)(void *, const void *, size_t) = __memmove_scalar;
#else
static void *(*__memset_ptr)(void *, int, size_t) = __memset_vect;
static void *(*__memcpy_ptr)(void *, const void *, size_t) = __memcpy_vect;
static void *(*__memmove_ptr)(void *, const void *, size_t) = __memmove_vect;
#endif

void *memset(void *s, int c, size_t n)
{
	return __memset_ptr(s, c, n);
}

void *memcpy(void *restrict dest, const void *restrict src, size_t n)
{
	return __memcpy_ptr(dest, src, n);
}

void *memmove(void *dest, const void *src, size_t n)
{
	return __memmove_ptr(dest, src, n);
}

static inline int __has_rvv_via_hwcap(void)
{
	const unsigned long V_bit = (1ul << ('V' - 'A'));
	unsigned long hwcap = __getauxval(AT_HWCAP);
	return (hwcap & V_bit) != 0;
}

hidden void __init_riscv_string_optimizations(void)
{
	if (__has_rvv_via_hwcap()) {
		__memset_ptr = __memset_vect;
		__memcpy_ptr = __memcpy_vect;
		__memmove_ptr = __memmove_vect;
	}
}

debug log:

solving cd0d1fbc ...
found cd0d1fbc in https://inbox.vuxu.org/musl/20251119054059.514848-2-pincheng.plct@isrc.iscas.ac.cn/

applying [1/1] https://inbox.vuxu.org/musl/20251119054059.514848-2-pincheng.plct@isrc.iscas.ac.cn/
diff --git a/src/string/riscv64/string_dispatch.c b/src/string/riscv64/string_dispatch.c
new file mode 100644
index 00000000..cd0d1fbc

Checking patch src/string/riscv64/string_dispatch.c...
Applied patch src/string/riscv64/string_dispatch.c cleanly.

index at:
100644 cd0d1fbc6ab324ecfdb638101222207299c4bd96	src/string/riscv64/string_dispatch.c

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

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).