]> git.proxmox.com Git - wasi-libc.git/commitdiff
Use bulk memory opcodes when possible
authorCheng Shao <astrohavoc@gmail.com>
Sat, 4 Dec 2021 03:56:45 +0000 (03:56 +0000)
committerDan Gohman <dev@sunfishcode.online>
Fri, 20 May 2022 20:39:43 +0000 (13:39 -0700)
libc-top-half/musl/src/string/memcpy.c
libc-top-half/musl/src/string/memmove.c
libc-top-half/musl/src/string/memset.c
libc-top-half/musl/src/string/wmemcpy.c
libc-top-half/musl/src/string/wmemmove.c

index 06e88742b1144a3b770184cc34dc14d96bdd2134..18cf47447e9bcfc85134a9e6e6b962af59a9a696 100644 (file)
@@ -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__
 }
index 5dc9cdb924218cb10f284d013984797e03fd4e19..24a7739406585a8d9fac731ac572790715c5f971 100644 (file)
@@ -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__
 }
index 5613a1486e6a6fc3988be6561f41b07b2647d80f..643695677afce8aeb1b0c17b95218cdf138d7f8a 100644 (file)
@@ -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__
 }
index 52e6e6e07b9dac897d5ee6665caed25afccafc70..c477f58c40aa37165b994934a620f17a0861c6a0 100644 (file)
@@ -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__
 }
index 964c9032991ed4620b381cb9dcb31eb789ac19a5..6cb19f7b7d293d1bb50ec351cef1f05b3b32dcc0 100644 (file)
@@ -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__
 }