mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 08:12:28 +00:00
Fix Clang support
The amalgamated release is now confirmed to be working with Clang, including its integrated assembler. Fixes #41
This commit is contained in:
parent
e06c90fafc
commit
d7733579d3
103 changed files with 384 additions and 359 deletions
|
@ -23,7 +23,7 @@ extern const uint32_t kCrc32cTab[256];
|
|||
/**
|
||||
* Computes Castagnoli CRC-32 on old computers.
|
||||
*/
|
||||
uint32_t crc32c$pure(uint32_t init, const void *data, size_t size) {
|
||||
uint32_t crc32c_pure(uint32_t init, const void *data, size_t size) {
|
||||
const unsigned char *p = data;
|
||||
uint32_t h = init ^ 0xffffffff;
|
||||
unsigned i;
|
||||
|
@ -34,7 +34,7 @@ uint32_t crc32c$pure(uint32_t init, const void *data, size_t size) {
|
|||
}
|
||||
|
||||
/*
|
||||
bench_crc32c$pure for #c per n where c ≈ 0.293ns
|
||||
bench_crc32c_pure for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 4305.000 91.375 44.203 74
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* Hashes data with hardware acceleration at 10GBps.
|
||||
* @note needs Nehalem+ c. 2008 or Bulldozer+ c. 2011
|
||||
*/
|
||||
optimizespeed uint32_t crc32c$sse42(uint32_t init, const void *data, size_t n) {
|
||||
optimizespeed uint32_t crc32c_sse42(uint32_t init, const void *data, size_t n) {
|
||||
const unsigned char *p = (const unsigned char *)data;
|
||||
const unsigned char *pe = (const unsigned char *)data + n;
|
||||
uint32_t h = init ^ 0xffffffff;
|
||||
|
@ -42,7 +42,7 @@ optimizespeed uint32_t crc32c$sse42(uint32_t init, const void *data, size_t n) {
|
|||
}
|
||||
|
||||
/*
|
||||
bench_crc32c$sse42 for #c per n where c ≈ 0.293ns
|
||||
bench_crc32c_sse42 for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 877.000 43.375 40.359 81
|
||||
|
|
|
@ -34,8 +34,8 @@ crc32c: .quad 0
|
|||
.previous
|
||||
|
||||
.init.start 300,_init_crc32c
|
||||
ezlea crc32c$pure,ax
|
||||
ezlea crc32c$sse42,cx
|
||||
ezlea crc32c_pure,ax
|
||||
ezlea crc32c_sse42,cx
|
||||
testb X86_HAVE(SSE4_2)+kCpuids(%rip)
|
||||
cmovnz %rcx,%rax
|
||||
stosq
|
||||
|
|
|
@ -42,7 +42,7 @@ uint32_t crc32_z(uint32_t h, const void *data, size_t size) {
|
|||
if (data) {
|
||||
h ^= 0xffffffff;
|
||||
if (size >= 64 && X86_HAVE(PCLMUL)) {
|
||||
h = crc32$pclmul(h, data, size); /* 51x faster */
|
||||
h = crc32_pclmul(h, data, size); /* 51x faster */
|
||||
skip = rounddown(size, 16);
|
||||
} else {
|
||||
skip = 0;
|
||||
|
|
|
@ -20,14 +20,14 @@
|
|||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
|
||||
void djbsort$avx2(int32_t *, long);
|
||||
void djbsort_avx2(int32_t *, long);
|
||||
|
||||
/**
|
||||
* D.J. Bernstein's outrageously fast integer sorting algorithm.
|
||||
*/
|
||||
void djbsort(int32_t *a, size_t n) {
|
||||
if (X86_HAVE(AVX2)) {
|
||||
djbsort$avx2(a, n);
|
||||
djbsort_avx2(a, n);
|
||||
} else {
|
||||
insertionsort(a, n);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/nexgen32e/cachesize.h"
|
||||
#include "libc/nexgen32e/cpuid4.internal.h"
|
||||
|
||||
static unsigned getcachesize$cpuid4(int type, int level) {
|
||||
static unsigned getcachesize_cpuid4(int type, int level) {
|
||||
unsigned i, k;
|
||||
static int once;
|
||||
static unsigned char kCacheKey[8];
|
||||
|
@ -53,5 +53,5 @@ static unsigned getcachesize$cpuid4(int type, int level) {
|
|||
unsigned getcachesize(int type, int level) {
|
||||
assert(1 <= type && type <= 3);
|
||||
assert(level >= 1);
|
||||
return getcachesize$cpuid4(type, level);
|
||||
return getcachesize_cpuid4(type, level);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ nodebuginfo forceinline bool32 iscont(wint_t c) {
|
|||
return (c & 0300) == 0200;
|
||||
}
|
||||
|
||||
char *strstr$sse42(const char *, const char *) strlenesque hidden;
|
||||
char16_t *strstr16$sse42(const char16_t *, const char16_t *) strlenesque hidden;
|
||||
void *memmem$sse42(const void *, size_t, const void *,
|
||||
char *strstr_sse42(const char *, const char *) strlenesque hidden;
|
||||
char16_t *strstr16_sse42(const char16_t *, const char16_t *) strlenesque hidden;
|
||||
void *memmem_sse42(const void *, size_t, const void *,
|
||||
size_t) strlenesque hidden;
|
||||
void sha256$x86(uint32_t[hasatleast 8], const uint8_t[hasatleast 64],
|
||||
void sha256_x86(uint32_t[hasatleast 8], const uint8_t[hasatleast 64],
|
||||
uint32_t) hidden;
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
|
@ -31,7 +31,7 @@ typedef long long xmm_t __attribute__((__vector_size__(16), __aligned__(1)));
|
|||
* @return dst
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
void *memmove$pure(void *dst, const void *src, size_t n) {
|
||||
void *memmove_pure(void *dst, const void *src, size_t n) {
|
||||
size_t i;
|
||||
xmm_t v, w;
|
||||
char *d, *r;
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
* @return p
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
void *memset$pure(void *p, int c, size_t n) {
|
||||
void *memset_pure(void *p, int c, size_t n) {
|
||||
char *b;
|
||||
uint64_t x;
|
||||
b = p;
|
||||
|
|
|
@ -85,7 +85,7 @@ void sha256_update(struct Sha256Ctx *ctx, const uint8_t *data, size_t size) {
|
|||
#if 0
|
||||
if (!IsTiny() && size >= 64 &&
|
||||
(X86_HAVE(SHA) && X86_HAVE(SSE4_1) && X86_HAVE(SSSE3))) {
|
||||
sha256$x86(ctx->state, data, size);
|
||||
sha256_x86(ctx->state, data, size);
|
||||
i += rounddown(size, 16);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/intrin/pmovmskb.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static noasan size_t stpcpy$sse2(char *d, const char *s, size_t i) {
|
||||
static noasan size_t stpcpy_sse2(char *d, const char *s, size_t i) {
|
||||
uint8_t v1[16], v2[16], vz[16];
|
||||
for (;;) {
|
||||
memset(vz, 0, 16);
|
||||
|
@ -52,7 +52,7 @@ char *stpcpy(char *d, const char *s) {
|
|||
return d + i;
|
||||
}
|
||||
}
|
||||
i = stpcpy$sse2(d, s, i);
|
||||
i = stpcpy_sse2(d, s, i);
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d + i;
|
||||
|
|
|
@ -363,39 +363,39 @@ char *strsignal(int) returnsnonnull libcesque;
|
|||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § strings » address sanitizer ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
void *memset$pure(void *, int, size_t) memcpyesque;
|
||||
void *memmove$pure(void *, const void *, size_t) memcpyesque;
|
||||
size_t strlen$pure(const char *) strlenesque;
|
||||
size_t strcspn$pure(const char *, const char *) strlenesque;
|
||||
void *memset_pure(void *, int, size_t) memcpyesque;
|
||||
void *memmove_pure(void *, const void *, size_t) memcpyesque;
|
||||
size_t strlen_pure(const char *) strlenesque;
|
||||
size_t strcspn_pure(const char *, const char *) strlenesque;
|
||||
#if defined(__FSANITIZE_ADDRESS__)
|
||||
|
||||
#define strcspn(STR, REJECT) strcspn$pure(STR, REJECT)
|
||||
#define strcspn(STR, REJECT) strcspn_pure(STR, REJECT)
|
||||
|
||||
#undef strlen
|
||||
#define strlen(STR) \
|
||||
(__builtin_constant_p(STR) ? __builtin_strlen(STR) : strlen$pure(STR))
|
||||
(__builtin_constant_p(STR) ? __builtin_strlen(STR) : strlen_pure(STR))
|
||||
|
||||
#undef memset
|
||||
#define memset(DST, CHAR, SIZE) \
|
||||
(__memcpy_isgoodsize(SIZE) ? __builtin_memset(DST, CHAR, SIZE) \
|
||||
: memset$pure(DST, CHAR, SIZE))
|
||||
: memset_pure(DST, CHAR, SIZE))
|
||||
|
||||
#undef memmove
|
||||
#define memmove(DST, SRC, SIZE) \
|
||||
(__memcpy_isgoodsize(SIZE) ? __builtin_memmove(DST, SRC, SIZE) \
|
||||
: memmove$pure(DST, SRC, SIZE))
|
||||
: memmove_pure(DST, SRC, SIZE))
|
||||
|
||||
#undef memcpy
|
||||
#define memcpy(DST, SRC, SIZE) \
|
||||
(__memcpy_isgoodsize(SIZE) ? __builtin_memcpy(DST, SRC, SIZE) \
|
||||
: memmove$pure(DST, SRC, SIZE))
|
||||
: memmove_pure(DST, SRC, SIZE))
|
||||
|
||||
#undef mempcpy
|
||||
#define mempcpy(DST, SRC, SIZE) \
|
||||
(__memcpy_isgoodsize(SIZE) ? __builtin_mempcpy(DST, SRC, SIZE) : ({ \
|
||||
void *DsT = (DST); \
|
||||
size_t SiZe = (SIZE); \
|
||||
memmove$pure(DsT, SRC, SiZe); \
|
||||
memmove_pure(DsT, SRC, SiZe); \
|
||||
(void *)((char *)DsT + SiZe); \
|
||||
}))
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
noasan static const unsigned char *strchr$x64(const unsigned char *p,
|
||||
noasan static const unsigned char *strchr_x64(const unsigned char *p,
|
||||
uint64_t c) {
|
||||
unsigned a, b;
|
||||
uint64_t w, x, y;
|
||||
|
@ -63,7 +63,7 @@ char *strchr(const char *s, int c) {
|
|||
if ((*s & 0xff) == c) return s;
|
||||
if (!*s) return NULL;
|
||||
}
|
||||
r = (char *)strchr$x64((const unsigned char *)s, c);
|
||||
r = (char *)strchr_x64((const unsigned char *)s, c);
|
||||
assert(!r || *r || !c);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
noasan static const unsigned char *strchrnul$x64(const unsigned char *p,
|
||||
noasan static const unsigned char *strchrnul_x64(const unsigned char *p,
|
||||
uint64_t c) {
|
||||
unsigned a, b;
|
||||
uint64_t w, x, y;
|
||||
|
@ -63,7 +63,7 @@ char *strchrnul(const char *s, int c) {
|
|||
if ((*s & 0xff) == c) return s;
|
||||
if (!*s) return s;
|
||||
}
|
||||
r = (char *)strchrnul$x64((const unsigned char *)s, c);
|
||||
r = (char *)strchrnul_x64((const unsigned char *)s, c);
|
||||
assert((*r & 0xff) == c || !*r);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "libc/intrin/pmovmskb.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static noasan size_t strcpy$sse2(char *d, const char *s, size_t i) {
|
||||
static noasan size_t strcpy_sse2(char *d, const char *s, size_t i) {
|
||||
uint8_t v1[16], v2[16], vz[16];
|
||||
for (;;) {
|
||||
memset(vz, 0, 16);
|
||||
|
@ -52,7 +52,7 @@ char *strcpy(char *d, const char *s) {
|
|||
return d;
|
||||
}
|
||||
}
|
||||
i = strcpy$sse2(d, s, i);
|
||||
i = strcpy_sse2(d, s, i);
|
||||
for (;;) {
|
||||
if (!(d[i] = s[i])) {
|
||||
return d;
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
* @see strspn(), strtok_r()
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
size_t strcspn$pure(const char *s, const char *reject) {
|
||||
size_t strcspn_pure(const char *s, const char *reject) {
|
||||
size_t i, n;
|
||||
unsigned m;
|
||||
char cv[16], sv[16];
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static noasan size_t strlen$pure$x64(const char *s, size_t i) {
|
||||
static noasan size_t strlen_pure_x64(const char *s, size_t i) {
|
||||
uint64_t w;
|
||||
const unsigned char *p;
|
||||
for (;;) {
|
||||
|
@ -38,12 +38,12 @@ static noasan size_t strlen$pure$x64(const char *s, size_t i) {
|
|||
/**
|
||||
* Returns length of NUL-terminated string.
|
||||
*/
|
||||
size_t strlen$pure(const char *s) {
|
||||
size_t strlen_pure(const char *s) {
|
||||
size_t i;
|
||||
for (i = 0; (uintptr_t)(s + i) & 7; ++i) {
|
||||
if (!s[i]) return i;
|
||||
}
|
||||
i = strlen$pure$x64(s, i);
|
||||
i = strlen_pure_x64(s, i);
|
||||
assert(!i || s[0]);
|
||||
assert(!s[i]);
|
||||
return i;
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "libc/assert.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
static noasan size_t strnlen$x64(const char *s, size_t n, size_t i) {
|
||||
static noasan size_t strnlen_x64(const char *s, size_t n, size_t i) {
|
||||
uint64_t w;
|
||||
const unsigned char *p;
|
||||
for (; i + 8 < n; i += 8) {
|
||||
|
@ -48,7 +48,7 @@ size_t strnlen(const char *s, size_t n) {
|
|||
for (i = 0; (uintptr_t)(s + i) & 7; ++i) {
|
||||
if (i == n || !s[i]) return i;
|
||||
}
|
||||
i = strnlen$x64(s, n, i);
|
||||
i = strnlen_x64(s, n, i);
|
||||
for (;; ++i) {
|
||||
if (i == n || !s[i]) break;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
static const int16_t kDel16[8] = {127, 127, 127, 127, 127, 127, 127, 127};
|
||||
|
||||
/* 10x speedup for ascii */
|
||||
static noasan axdx_t tprecode16to8$sse2(char *dst, size_t dstsize,
|
||||
static noasan axdx_t tprecode16to8_sse2(char *dst, size_t dstsize,
|
||||
const char16_t *src, axdx_t r) {
|
||||
int16_t v1[8], v2[8], v3[8], vz[8];
|
||||
memset(vz, 0, 16);
|
||||
|
@ -63,7 +63,7 @@ axdx_t tprecode16to8(char *dst, size_t dstsize, const char16_t *src) {
|
|||
r.dx = 0;
|
||||
for (;;) {
|
||||
if (!IsTiny() && !((uintptr_t)(src + r.dx) & 15)) {
|
||||
r = tprecode16to8$sse2(dst, dstsize, src, r);
|
||||
r = tprecode16to8_sse2(dst, dstsize, src, r);
|
||||
}
|
||||
if (!(x = src[r.dx++])) break;
|
||||
if (IsUtf16Cont(x)) continue;
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include "libc/str/utf16.h"
|
||||
|
||||
/* 34x speedup for ascii */
|
||||
static noasan axdx_t tprecode8to16$sse2(char16_t *dst, size_t dstsize,
|
||||
static noasan axdx_t tprecode8to16_sse2(char16_t *dst, size_t dstsize,
|
||||
const char *src, axdx_t r) {
|
||||
uint8_t v1[16], v2[16], vz[16];
|
||||
memset(vz, 0, 16);
|
||||
|
@ -61,7 +61,7 @@ axdx_t tprecode8to16(char16_t *dst, size_t dstsize, const char *src) {
|
|||
r.dx = 0;
|
||||
for (;;) {
|
||||
if (!IsTiny() && !((uintptr_t)(src + r.dx) & 15)) {
|
||||
tprecode8to16$sse2(dst, dstsize, src, r);
|
||||
tprecode8to16_sse2(dst, dstsize, src, r);
|
||||
}
|
||||
x = src[r.dx++] & 0xff;
|
||||
if (ThomPikeCont(x)) continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue