# The directory where we're store intermediate artifacts.
OBJDIR ?= $(CURDIR)/build
+# When the length is no larger than this threshold, we consider the
+# overhead of bulk memory opcodes to outweigh the performance benefit,
+# and fall back to the original musl implementation. See
+# https://github.com/WebAssembly/wasi-libc/pull/263 for relevant
+# discussion
+BULK_MEMORY_THRESHOLD ?= 32
+
# Variables from this point on are not meant to be overridable via the
# make command-line.
$(BULK_MEMORY_OBJS): CFLAGS += \
-mbulk-memory
+$(BULK_MEMORY_OBJS): CFLAGS += \
+ -DBULK_MEMORY_THRESHOLD=$(BULK_MEMORY_THRESHOLD)
+
$(LIBWASI_EMULATED_SIGNAL_MUSL_OBJS): CFLAGS += \
-D_WASI_EMULATED_SIGNAL
void *memcpy(void *restrict dest, const void *restrict src, size_t n)
{
#if defined(__wasm_bulk_memory__)
- return __builtin_memcpy(dest, src, n);
-#else
+ if (n > BULK_MEMORY_THRESHOLD)
+ return __builtin_memcpy(dest, src, n);
+#endif
unsigned char *d = dest;
const unsigned char *s = src;
for (; n; n--) *d++ = *s++;
return dest;
-#endif // __wasm_bulk_memory__
}
void *memmove(void *dest, const void *src, size_t n)
{
#if defined(__wasm_bulk_memory__)
- return __builtin_memmove(dest, src, n);
-#else
+ if (n > BULK_MEMORY_THRESHOLD)
+ return __builtin_memmove(dest, src, n);
+#endif
char *d = dest;
const char *s = src;
}
return dest;
-#endif // __wasm_bulk_memory__
}
void *memset(void *dest, int c, size_t n)
{
#if defined(__wasm_bulk_memory__)
- return __builtin_memset(dest, c, n);
-#else
+ if (n > BULK_MEMORY_THRESHOLD)
+ return __builtin_memset(dest, c, n);
+#endif
unsigned char *s = dest;
size_t k;
#endif
return dest;
-#endif // __wasm_bulk_memory__
}