aboutsummaryrefslogtreecommitdiff
path: root/system/lib
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-03-16 03:53:58 +0200
committerJukka Jylänki <jujjyl@gmail.com>2014-03-28 23:06:17 -0400
commitf546d9a039d8b1ead4f6b5843e97faf8b4944a70 (patch)
treeaff1cc6e5908752d605f10bcb83af5929d4fcb96 /system/lib
parentd468544eec5b4900228a19b5af1fa0d051e736ac (diff)
Migrate to using musl 0.9.13 memchr for better asm.js performance.
Diffstat (limited to 'system/lib')
-rw-r--r--system/lib/libc/musl/src/string/memchr.c24
-rw-r--r--system/lib/libcextra.symbols1
2 files changed, 25 insertions, 0 deletions
diff --git a/system/lib/libc/musl/src/string/memchr.c b/system/lib/libc/musl/src/string/memchr.c
new file mode 100644
index 00000000..a0472f78
--- /dev/null
+++ b/system/lib/libc/musl/src/string/memchr.c
@@ -0,0 +1,24 @@
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+
+#define SS (sizeof(size_t))
+#define ALIGN (sizeof(size_t)-1)
+#define ONES ((size_t)-1/UCHAR_MAX)
+#define HIGHS (ONES * (UCHAR_MAX/2+1))
+#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
+
+void *memchr(const void *src, int c, size_t n)
+{
+ const unsigned char *s = src;
+ c = (unsigned char)c;
+ for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--);
+ if (n && *s != c) {
+ const size_t *w;
+ size_t k = ONES * c;
+ for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS);
+ for (s = (const void *)w; n && *s != c; s++, n--);
+ }
+ return n ? (void *)s : 0;
+}
diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols
index 30a39d52..94cd79be 100644
--- a/system/lib/libcextra.symbols
+++ b/system/lib/libcextra.symbols
@@ -92,6 +92,7 @@
T mbstowcs
T mbtowc
T memccpy
+ T memchr
T memmem
T mempcpy
W memrchr