3 ms·
Honestly the thing that shocked me the most is this kind of query I've been doing for the last 10 hours: Rewrite the following in Rust: size_t strlenNEON(
by 19h 4y ago
Honestly the thing that shocked me the most is this kind of query I've been doing for the last 10 hours:
Rewrite the following in Rust:
size_t strlenNEON(const char *p)
{
const char *const top = p;
uint8x16_t c16 = vdupq_n_u8(0);
/* 16 byte alignment */
size_t n = reinterpret_cast<size_t>(p) & 15;
if (n > 0) {
uint8x16_t x = *(const uint8x16_t*)&p[-n];
uint8x16_t a = vceqq_u8(x, c16);
unsigned long mask = GetByteMask(a) << (16 + n);
if (mask) {
return __builtin_clz(mask);
}
p += 16 - n;
}
assert((reinterpret_cast<size_t>(p) & 15) == 0);
for (;;) {
uint8x16_t x = *(const uint8x16_t*)&p[0];
uint8x16_t a = vceqq_u8(x, c16);
if (isFound(a)) {
unsigned int mask = GetByteMask(a);
return p + __builtin_clz(mask) - top;
}
p += 16;
}
}
It even correctly produces the implementation of the unimplemented functions being called from the C++ impl.
- thdespou 4y agoIt's the journey not the destination that matters.