From 75fdabe1ff6f71f9c5c7fa3b5e81c94254c01d65 Mon Sep 17 00:00:00 2001 From: Cheng Shao Date: Sat, 4 Dec 2021 03:56:45 +0000 Subject: [PATCH] Use bulk memory opcodes when possible --- libc-top-half/musl/src/string/memcpy.c | 4 ++++ libc-top-half/musl/src/string/memmove.c | 4 ++++ libc-top-half/musl/src/string/memset.c | 4 ++++ libc-top-half/musl/src/string/wmemcpy.c | 4 ++++ libc-top-half/musl/src/string/wmemmove.c | 4 ++++ 5 files changed, 20 insertions(+) diff --git a/libc-top-half/musl/src/string/memcpy.c b/libc-top-half/musl/src/string/memcpy.c index 06e8874..18cf474 100644 --- a/libc-top-half/musl/src/string/memcpy.c +++ b/libc-top-half/musl/src/string/memcpy.c @@ -4,6 +4,9 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n) { +#if defined(__wasm_bulk_memory__) + return __builtin_memcpy(dest, src, n); +#else unsigned char *d = dest; const unsigned char *s = src; @@ -121,4 +124,5 @@ void *memcpy(void *restrict dest, const void *restrict src, size_t n) for (; n; n--) *d++ = *s++; return dest; +#endif // __wasm_bulk_memory__ } diff --git a/libc-top-half/musl/src/string/memmove.c b/libc-top-half/musl/src/string/memmove.c index 5dc9cdb..24a7739 100644 --- a/libc-top-half/musl/src/string/memmove.c +++ b/libc-top-half/musl/src/string/memmove.c @@ -8,6 +8,9 @@ typedef __attribute__((__may_alias__)) size_t WT; void *memmove(void *dest, const void *src, size_t n) { +#if defined(__wasm_bulk_memory__) + return __builtin_memmove(dest, src, n); +#else char *d = dest; const char *s = src; @@ -39,4 +42,5 @@ void *memmove(void *dest, const void *src, size_t n) } return dest; +#endif // __wasm_bulk_memory__ } diff --git a/libc-top-half/musl/src/string/memset.c b/libc-top-half/musl/src/string/memset.c index 5613a14..6436956 100644 --- a/libc-top-half/musl/src/string/memset.c +++ b/libc-top-half/musl/src/string/memset.c @@ -3,6 +3,9 @@ void *memset(void *dest, int c, size_t n) { +#if defined(__wasm_bulk_memory__) + return __builtin_memset(dest, c, n); +#else unsigned char *s = dest; size_t k; @@ -87,4 +90,5 @@ void *memset(void *dest, int c, size_t n) #endif return dest; +#endif // __wasm_bulk_memory__ } diff --git a/libc-top-half/musl/src/string/wmemcpy.c b/libc-top-half/musl/src/string/wmemcpy.c index 52e6e6e..c477f58 100644 --- a/libc-top-half/musl/src/string/wmemcpy.c +++ b/libc-top-half/musl/src/string/wmemcpy.c @@ -2,7 +2,11 @@ wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) { +#if defined(__wasm_bulk_memory__) + return __builtin_wmemcpy(d, s, n); +#else wchar_t *a = d; while (n--) *d++ = *s++; return a; +#endif // __wasm_bulk_memory__ } diff --git a/libc-top-half/musl/src/string/wmemmove.c b/libc-top-half/musl/src/string/wmemmove.c index 964c903..6cb19f7 100644 --- a/libc-top-half/musl/src/string/wmemmove.c +++ b/libc-top-half/musl/src/string/wmemmove.c @@ -3,6 +3,9 @@ wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) { +#if defined(__wasm_bulk_memory__) + return __builtin_wmemmove(d, s, n); +#else wchar_t *d0 = d; if (d == s) return d; if ((uintptr_t)d-(uintptr_t)s < n * sizeof *d) @@ -10,4 +13,5 @@ wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) else while (n--) *d++ = *s++; return d0; +#endif // __wasm_bulk_memory__ } -- 2.39.2