我认为这个时间有点长,1us就是400个时钟周期,求解个字符串长度竟然要400个时钟周期
GPT生成了个,还不如C库自带的
[C] 纯文本查看 复制代码 #include <stdint.h>
#include <stddef.h>
__STATIC_FORCEINLINE size_t strlen_fast64(const char *s)
{
const char *p = s;
/* 对齐到8字节 */
while ((uintptr_t)p & 7U)
{
if (*p == '\0')
return (size_t)(p - s);
p++;
}
for (;;)
{
uint64_t v = *(const uint64_t *)p;
if ((v - 0x0101010101010101ULL) &
(~v) &
0x8080808080808080ULL)
{
while (*p)
p++;
return (size_t)(p - s);
}
p += 8;
}
}
|