diff --git a/sqlite3/libc/libc.wasm b/sqlite3/libc/libc.wasm index 821c698..70fa201 100755 Binary files a/sqlite3/libc/libc.wasm and b/sqlite3/libc/libc.wasm differ diff --git a/sqlite3/libc/libc.wat b/sqlite3/libc/libc.wat index 2188a97..2349c96 100644 --- a/sqlite3/libc/libc.wat +++ b/sqlite3/libc/libc.wat @@ -1325,11 +1325,11 @@ ) (i32.const 0) (i32.le_u - (local.get $0) - (i32.add - (local.get $1) + (i32.sub + (local.get $0) (local.get $3) ) + (local.get $1) ) ) ) diff --git a/sqlite3/libc/string.h b/sqlite3/libc/string.h index a040674..37c8718 100644 --- a/sqlite3/libc/string.h +++ b/sqlite3/libc/string.h @@ -113,7 +113,7 @@ void *memchr(const void *v, int c, size_t n) { // That's a match, unless it is beyond the end of the object. // Recall that we decremented n, so less-than-or-equal-to is correct. size_t ctz = __builtin_ctz(mask); - return ctz <= n + align ? (char *)w + ctz : NULL; + return ctz - align <= n ? (char *)w + ctz : NULL; } } // Decrement n; if it overflows we're done. @@ -166,6 +166,8 @@ size_t strlen(const char *s) { // At least one bit will be set, unless we cleared them. // Knowing this helps the compiler. __builtin_assume(mask || align); + // If the mask is zero because of alignment, + // it's as if we didn't find anything. if (mask) { // Find the offset of the first one bit (little-endian). return (char *)w - s + __builtin_ctz(mask); @@ -280,6 +282,8 @@ static char *__strchrnul(const char *s, int c) { // At least one bit will be set, unless we cleared them. // Knowing this helps the compiler. __builtin_assume(mask || align); + // If the mask is zero because of alignment, + // it's as if we didn't find anything. if (mask) { // Find the offset of the first one bit (little-endian). return (char *)w + __builtin_ctz(mask); diff --git a/sqlite3/libc/strings.h b/sqlite3/libc/strings.h index 4cd92c9..4f44eda 100644 --- a/sqlite3/libc/strings.h +++ b/sqlite3/libc/strings.h @@ -57,6 +57,7 @@ int bcmp(const void *v1, const void *v2, size_t n) { #endif // __OPTIMIZE_SIZE__ +__attribute__((always_inline)) static v128_t __tolower8x16(v128_t v) { __i8x16 i = v; i = i + wasm_i8x16_splat(INT8_MAX - ('Z'));