Reproducer: https://godbolt.org/z/6caGGoo1e
int is_all_ones(unsigned char *p) {
unsigned char a = p[0];
unsigned char b = p[1];
return a == 255 && b == 255;
}
I've expected this to compile to a single read + comparison on platforms that support unaligned accesses. Instead, this happened:
is_all_ones:
movzx ecx, byte ptr [rdi + 1]
and cl, byte ptr [rdi]
xor eax, eax
cmp cl, -1
sete al
ret