Add optimized versions of musl libc string and memory comparison functions.
This commit is contained in:
Родитель
51d39aaa3d
Коммит
a2f95d5098
7
emcc
7
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:
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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()
|
||||
|
|
Загрузка…
Ссылка в новой задаче