1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| | #include <stddef.h>
#include <stdint.h>
#include <string.h>
#define HIGHS(x) ((x) - ((x)*0-1) / 255 * 128)
#define LOWS(x) (((x)*0-1) / 255)
#define has_zero(x) ((x) - LOWS(x) & ~(x) & HIGHS(x))
#undef strcmp
int strcmp(const char *l, const char *r)
{
const size_t *wl;
const size_t *wr;
if ((uintptr_t)l % sizeof(size_t) != (uintptr_t)r % sizeof(size_t))
goto bytewise;
for (; (uintptr_t)l % sizeof(size_t); l++, r++) {
if (*l != *r || !*l || !*r) {
return *(unsigned char *)l
- *(unsigned char *)r;
}
}
for (wl = (const size_t *)l, wr = (const size_t *)r
; has_zero(*wl) || has_zero(*wr) && *wl == *wr
; wl++, wr++);
l = (const char *)wl;
r = (const char *)wr;
bytewise:
for(; *l == *r && *l && *r; l++, r++);
return *(unsigned char *)l - *(unsigned char *)r;
}
|