mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-30 16:28:30 +00:00
Make further progress on non-x86 support
This commit is contained in:
parent
aef9a69a60
commit
036b9a0002
155 changed files with 2307 additions and 653 deletions
|
@ -20,8 +20,6 @@
|
|||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
/**
|
||||
* Returns length of NUL-terminated string.
|
||||
*
|
||||
|
@ -30,16 +28,33 @@ typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
|||
* @asyncsignalsafe
|
||||
*/
|
||||
noasan size_t strlen(const char *s) {
|
||||
if (IsAsan()) __asan_verify_str(s);
|
||||
#ifdef __x86_64__
|
||||
size_t n;
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
xmm_t z = {0};
|
||||
unsigned m, k = (uintptr_t)s & 15;
|
||||
const xmm_t *p = (const xmm_t *)((uintptr_t)s & -16);
|
||||
if (IsAsan()) __asan_verify_str(s);
|
||||
m = __builtin_ia32_pmovmskb128(*p == z) >> k << k;
|
||||
while (!m) m = __builtin_ia32_pmovmskb128(*++p == z);
|
||||
n = (const char *)p + __builtin_ctzl(m) - s;
|
||||
return n;
|
||||
return (const char *)p + __builtin_ctzl(m) - s;
|
||||
#elif defined(__GNUC__) || defined(__llvm__)
|
||||
#define ONES ((word)-1 / 255)
|
||||
#define BANE (ONES * (255 / 2 + 1))
|
||||
typedef unsigned long mayalias word;
|
||||
word w;
|
||||
unsigned k;
|
||||
const word *p;
|
||||
k = (uintptr_t)s & (sizeof(word) - 1);
|
||||
p = (const word *)((uintptr_t)s & -sizeof(word));
|
||||
w = *p;
|
||||
w = ~w & (w - ONES) & BANE;
|
||||
w >>= k << 3;
|
||||
w <<= k << 3;
|
||||
while (!w) {
|
||||
w = *++p;
|
||||
w = ~w & (w - ONES) & BANE;
|
||||
}
|
||||
return (const char *)p + (__builtin_ctzl(w) >> 3) - s;
|
||||
#else
|
||||
size_t n = 0;
|
||||
while (*s++) ++n;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue