1570af302Sopenharmony_ci#include <string.h>
2570af302Sopenharmony_ci#include <stdint.h>
3570af302Sopenharmony_ci#include <limits.h>
4570af302Sopenharmony_ci
5570af302Sopenharmony_ci#define ALIGN (sizeof(size_t))
6570af302Sopenharmony_ci#define ONES ((size_t)-1/UCHAR_MAX)
7570af302Sopenharmony_ci#define HIGHS (ONES * (UCHAR_MAX/2+1))
8570af302Sopenharmony_ci#define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
9570af302Sopenharmony_ci
10570af302Sopenharmony_cisize_t strlen(const char *s)
11570af302Sopenharmony_ci{
12570af302Sopenharmony_ci	const char *a = s;
13570af302Sopenharmony_ci#ifdef __GNUC__
14570af302Sopenharmony_ci	typedef size_t __attribute__((__may_alias__)) word;
15570af302Sopenharmony_ci	const word *w;
16570af302Sopenharmony_ci	for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a;
17570af302Sopenharmony_ci	for (w = (const void *)s; !HASZERO(*w); w++);
18570af302Sopenharmony_ci	s = (const void *)w;
19570af302Sopenharmony_ci#endif
20570af302Sopenharmony_ci	for (; *s; s++);
21570af302Sopenharmony_ci	return s-a;
22570af302Sopenharmony_ci}
23