aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-02-06 17:07:04 -0500
committerJukka Jylänki <jujjyl@gmail.com>2014-02-06 17:07:04 -0500
commita2f95d50985660324812286771dbfdcf7da638a4 (patch)
treea7270fa2095c5a794f4dc4d07a549c0a25a30e77
parent51d39aaa3dda0a7f433fa38c365f86011b5fe84c (diff)
Add optimized versions of musl libc string and memory comparison functions.
-rwxr-xr-xemcc7
-rw-r--r--src/library.js66
-rw-r--r--system/lib/libc.symbols5
-rw-r--r--system/lib/libc/musl/src/string/memcmp.c8
-rw-r--r--system/lib/libc/musl/src/string/strcasecmp.c9
-rw-r--r--system/lib/libc/musl/src/string/strcmp.c7
-rw-r--r--system/lib/libc/musl/src/string/strncasecmp.c10
-rw-r--r--system/lib/libc/musl/src/string/strncmp.c9
-rw-r--r--tools/shared.py2
9 files changed, 56 insertions, 67 deletions
diff --git a/emcc b/emcc
index 6bf74707..a5432397 100755
--- a/emcc
+++ b/emcc
@@ -1476,6 +1476,13 @@ try:
['stdlib', [
'atof.c',
'strtod.c',
+ ]],
+ ['string', [
+ 'memcmp.c',
+ 'strcasecmp.c',
+ 'strcmp.c',
+ 'strncasecmp.c',
+ 'strncmp.c',
]]
]
for directory, sources in musl_files:
diff --git a/src/library.js b/src/library.js
index 26ce8457..98d996ab 100644
--- a/src/library.js
+++ b/src/library.js
@@ -3754,10 +3754,6 @@ LibraryManager.library = {
return pdest;
},
- strcmp__deps: ['strncmp'],
- strcmp: function(px, py) {
- return _strncmp(px, py, TOTAL_MEMORY);
- },
// We always assume ASCII locale.
strcoll: 'strcmp',
strcoll_l__deps: ['strcoll'],
@@ -3765,68 +3761,6 @@ LibraryManager.library = {
return _strcoll(px, py); // no locale support yet
},
- strcasecmp__asm: true,
- strcasecmp__sig: 'iii',
- strcasecmp__deps: ['strncasecmp'],
- strcasecmp: function(px, py) {
- px = px|0; py = py|0;
- return _strncasecmp(px, py, -1)|0;
- },
-
- strncmp: function(px, py, n) {
- var i = 0;
- while (i < n) {
- var x = {{{ makeGetValue('px', 'i', 'i8', 0, 1) }}};
- var y = {{{ makeGetValue('py', 'i', 'i8', 0, 1) }}};
- if (x == y && x == 0) return 0;
- if (x == 0) return -1;
- if (y == 0) return 1;
- if (x == y) {
- i ++;
- continue;
- } else {
- return x > y ? 1 : -1;
- }
- }
- return 0;
- },
-
- strncasecmp__asm: true,
- strncasecmp__sig: 'iiii',
- strncasecmp__deps: ['tolower'],
- strncasecmp: function(px, py, n) {
- px = px|0; py = py|0; n = n|0;
- var i = 0, x = 0, y = 0;
- while ((i>>>0) < (n>>>0)) {
- x = _tolower({{{ makeGetValueAsm('px', 'i', 'i8', 0, 1) }}})|0;
- y = _tolower({{{ makeGetValueAsm('py', 'i', 'i8', 0, 1) }}})|0;
- if (((x|0) == (y|0)) & ((x|0) == 0)) return 0;
- if ((x|0) == 0) return -1;
- if ((y|0) == 0) return 1;
- if ((x|0) == (y|0)) {
- i = (i + 1)|0;
- continue;
- } else {
- return ((x>>>0) > (y>>>0) ? 1 : -1)|0;
- }
- }
- return 0;
- },
-
- memcmp__asm: true,
- memcmp__sig: 'iiii',
- memcmp: function(p1, p2, num) {
- p1 = p1|0; p2 = p2|0; num = num|0;
- var i = 0, v1 = 0, v2 = 0;
- while ((i|0) < (num|0)) {
- v1 = {{{ makeGetValueAsm('p1', 'i', 'i8', true) }}};
- v2 = {{{ makeGetValueAsm('p2', 'i', 'i8', true) }}};
- if ((v1|0) != (v2|0)) return ((v1|0) > (v2|0) ? 1 : -1)|0;
- i = (i+1)|0;
- }
- return 0;
- },
-
memchr: function(ptr, chr, num) {
chr = unSign(chr);
for (var i = 0; i < num; i++) {
diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols
index 6f80ef90..705b2c88 100644
--- a/system/lib/libc.symbols
+++ b/system/lib/libc.symbols
@@ -72,7 +72,12 @@
W realloc_in_place
T scalbn
T scalbnl
+ T memcpy
T strtod
+ T strcmp
+ T strncmp
+ T strcasecmp
+ T strncasecmp
T strtod_l
T strtof
T strtof_l
diff --git a/system/lib/libc/musl/src/string/memcmp.c b/system/lib/libc/musl/src/string/memcmp.c
new file mode 100644
index 00000000..bdbce9f0
--- /dev/null
+++ b/system/lib/libc/musl/src/string/memcmp.c
@@ -0,0 +1,8 @@
+#include <string.h>
+
+int memcmp(const void *vl, const void *vr, size_t n)
+{
+ const unsigned char *l=vl, *r=vr;
+ for (; n && *l == *r; n--, l++, r++);
+ return n ? *l-*r : 0;
+}
diff --git a/system/lib/libc/musl/src/string/strcasecmp.c b/system/lib/libc/musl/src/string/strcasecmp.c
new file mode 100644
index 00000000..02fd5f8c
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strcasecmp.c
@@ -0,0 +1,9 @@
+#include <strings.h>
+#include <ctype.h>
+
+int strcasecmp(const char *_l, const char *_r)
+{
+ const unsigned char *l=(void *)_l, *r=(void *)_r;
+ for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++);
+ return tolower(*l) - tolower(*r);
+}
diff --git a/system/lib/libc/musl/src/string/strcmp.c b/system/lib/libc/musl/src/string/strcmp.c
new file mode 100644
index 00000000..808bd837
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strcmp.c
@@ -0,0 +1,7 @@
+#include <string.h>
+
+int strcmp(const char *l, const char *r)
+{
+ for (; *l==*r && *l; l++, r++);
+ return *(unsigned char *)l - *(unsigned char *)r;
+}
diff --git a/system/lib/libc/musl/src/string/strncasecmp.c b/system/lib/libc/musl/src/string/strncasecmp.c
new file mode 100644
index 00000000..24659721
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strncasecmp.c
@@ -0,0 +1,10 @@
+#include <strings.h>
+#include <ctype.h>
+
+int strncasecmp(const char *_l, const char *_r, size_t n)
+{
+ const unsigned char *l=(void *)_l, *r=(void *)_r;
+ if (!n--) return 0;
+ for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--);
+ return tolower(*l) - tolower(*r);
+}
diff --git a/system/lib/libc/musl/src/string/strncmp.c b/system/lib/libc/musl/src/string/strncmp.c
new file mode 100644
index 00000000..e228843f
--- /dev/null
+++ b/system/lib/libc/musl/src/string/strncmp.c
@@ -0,0 +1,9 @@
+#include <string.h>
+
+int strncmp(const char *_l, const char *_r, size_t n)
+{
+ const unsigned char *l=(void *)_l, *r=(void *)_r;
+ if (!n--) return 0;
+ for (; *l && *r && n && *l == *r ; l++, r++, n--);
+ return *l - *r;
+}
diff --git a/tools/shared.py b/tools/shared.py
index 3b0b92a3..dbf1e3ef 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -345,7 +345,7 @@ def find_temp_directory():
# we re-check sanity when the settings are changed)
# We also re-check sanity and clear the cache when the version changes
-EMSCRIPTEN_VERSION = '1.10.1'
+EMSCRIPTEN_VERSION = '1.10.2'
def generate_sanity():
return EMSCRIPTEN_VERSION + '|' + get_llvm_target() + '|' + LLVM_ROOT + '|' + get_clang_version()