mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-28 15: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
|
@ -22,8 +22,6 @@
|
|||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
|
||||
unsigned char c) {
|
||||
for (;; ++s) {
|
||||
|
@ -34,6 +32,7 @@ static inline const unsigned char *rawmemchr_pure(const unsigned char *s,
|
|||
}
|
||||
|
||||
#ifdef __x86_64__
|
||||
typedef char xmm_t __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
|
||||
unsigned k;
|
||||
unsigned m;
|
||||
|
@ -54,6 +53,12 @@ noasan static inline const char *rawmemchr_sse(const char *s, unsigned char c) {
|
|||
}
|
||||
#endif
|
||||
|
||||
static inline noasan uint64_t UncheckedAlignedRead64(unsigned char *p) {
|
||||
return (uint64_t)p[7] << 070 | (uint64_t)p[6] << 060 | (uint64_t)p[5] << 050 |
|
||||
(uint64_t)p[4] << 040 | (uint64_t)p[3] << 030 | (uint64_t)p[2] << 020 |
|
||||
(uint64_t)p[1] << 010 | (uint64_t)p[0] << 000;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pointer to first instance of character.
|
||||
*
|
||||
|
@ -72,6 +77,22 @@ void *rawmemchr(const void *s, int c) {
|
|||
}
|
||||
return (void *)r;
|
||||
#else
|
||||
return rawmemchr_pure(s, c);
|
||||
uint64_t v, w;
|
||||
const unsigned char *p;
|
||||
p = s;
|
||||
c &= 255;
|
||||
v = 0x0101010101010101ul * c;
|
||||
for (; (uintptr_t)p & 7; ++p) {
|
||||
if (*p == c) return p;
|
||||
}
|
||||
for (;; p += 8) {
|
||||
w = UncheckedAlignedRead64(p);
|
||||
if ((w = ~(w ^ v) & ((w ^ v) - 0x0101010101010101) & 0x8080808080808080)) {
|
||||
p += (unsigned)__builtin_ctzll(w) >> 3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assert(*p == c);
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue