3 ms·
How strange, I was going to respond to a question about this code: https://git.musl-libc.org/cgit/musl/tree/src/string/memchr.c https://git.musl-libc.org/cgit/
by projektfu 4y ago
How strange, I was going to respond to a question about this code:
https://git.musl-libc.org/cgit/musl/tree/src/string/memchr.c https://git.musl-libc.org/cgit/musl/tree/src/string/memchr.c
and the user has completely disappeared along with their comment/question.
Anyhow, you can think about the __GNUC__ part as an attempt to fast-forward the loop by testing size_t-length chunks for the character by XOR-ing the chunk with a repeated string of that character. The first loop aligns the pointer for the fast-forward. The final loop is then used to test the unaligned part, which when not using __GNUC__, would be the complete loop.
I felt the need to answer because I'd done the work.