Make further progress on non-x86 support

This commit is contained in:
Justine Tunney 2023-05-08 21:38:30 -07:00
parent aef9a69a60
commit 036b9a0002
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
155 changed files with 2307 additions and 653 deletions

View file

@ -26,7 +26,7 @@
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
static dontinline antiquity void bzero_sse(char *p, size_t n) {
static void bzero_sse(char *p, size_t n) {
xmm_t v = {0};
if (IsAsan()) __asan_verify(p, n);
if (n <= 32) {

View file

@ -31,7 +31,7 @@ asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
/* clang-format off */
// clang-format off
/**
* Returns 𝑥 × 2ʸ.

View file

@ -18,6 +18,9 @@
*/
#include "libc/math.h"
/**
* Returns 𝑥 × 2ʸ.
*/
long double ldexpl(long double x, int n) {
return scalbnl(x, n);
}

View file

@ -26,7 +26,7 @@
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
typedef long long xmm_a __attribute__((__vector_size__(16), __aligned__(16)));
static dontinline antiquity void *memset_sse(char *p, char c, size_t n) {
static void *memset_sse(char *p, char c, size_t n) {
xmm_t v = {c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c};
if (IsAsan()) __asan_verify(p, n);
if (n <= 32) {

View file

@ -32,20 +32,16 @@ asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
/* clang-format off */
// clang-format off
long double scalblnl(long double x, long n) {
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double scalblnl(long double x, long n)
{
return scalbln(x, n);
}
#else
long double scalblnl(long double x, long n)
{
if (n > INT_MAX)
n = INT_MAX;
else if (n < INT_MIN)
n = INT_MIN;
return scalbnl(x, n);
}
#endif
}

View file

@ -32,18 +32,16 @@ asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
/* clang-format off */
// clang-format off
/**
* Returns 𝑥 × 2ʸ.
*/
long double scalbnl(long double x, int n) {
#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
long double scalbnl(long double x, int n)
{
return scalbn(x, n);
}
#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
long double scalbnl(long double x, int n)
{
union ldshape u;
if (n > 16383) {
x *= 0x1p16383L;
n -= 16383;
@ -66,5 +64,7 @@ long double scalbnl(long double x, int n)
u.f = 1.0;
u.i.se = 0x3fff + n;
return x * u.f;
}
#else
#error "architecture unsupported"
#endif
}

View file

@ -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;