Browse Source

Use bulk memory opcodes when possible

pull/291/head
Cheng Shao 3 years ago
committed by Dan Gohman
parent
commit
75fdabe1ff
  1. 4
      libc-top-half/musl/src/string/memcpy.c
  2. 4
      libc-top-half/musl/src/string/memmove.c
  3. 4
      libc-top-half/musl/src/string/memset.c
  4. 4
      libc-top-half/musl/src/string/wmemcpy.c
  5. 4
      libc-top-half/musl/src/string/wmemmove.c

4
libc-top-half/musl/src/string/memcpy.c

@ -4,6 +4,9 @@
void *memcpy(void *restrict dest, const void *restrict src, size_t n) 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; unsigned char *d = dest;
const unsigned char *s = src; 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++; for (; n; n--) *d++ = *s++;
return dest; return dest;
#endif // __wasm_bulk_memory__
} }

4
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) 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; char *d = dest;
const char *s = src; const char *s = src;
@ -39,4 +42,5 @@ void *memmove(void *dest, const void *src, size_t n)
} }
return dest; return dest;
#endif // __wasm_bulk_memory__
} }

4
libc-top-half/musl/src/string/memset.c

@ -3,6 +3,9 @@
void *memset(void *dest, int c, size_t n) 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; unsigned char *s = dest;
size_t k; size_t k;
@ -87,4 +90,5 @@ void *memset(void *dest, int c, size_t n)
#endif #endif
return dest; return dest;
#endif // __wasm_bulk_memory__
} }

4
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) 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; wchar_t *a = d;
while (n--) *d++ = *s++; while (n--) *d++ = *s++;
return a; return a;
#endif // __wasm_bulk_memory__
} }

4
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) 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; wchar_t *d0 = d;
if (d == s) return d; if (d == s) return d;
if ((uintptr_t)d-(uintptr_t)s < n * sizeof *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 else
while (n--) *d++ = *s++; while (n--) *d++ = *s++;
return d0; return d0;
#endif // __wasm_bulk_memory__
} }

Loading…
Cancel
Save