News for hackers. Stuff that matters.
Re:A 100LOC C impl of memset, that is faster than glibc's by dahfizz on Friday November 12, 2021 @02:29PM (#29203533)
I wonder if it would be meaningfully faster if you checked the first 16 bytes as uint64_t or uint128_t instead of byte by byte. It would save you 14 or 15 comparisons per function call.
Re:A 100LOC C impl of memset, that is faster than glibc's by rwmj on Friday November 12, 2021 @05:10PM (#29205133)
GCC (-O3) actually unrolls the loop completely into 16 x (cmpb + jne), which I find slightly surprising.

We can't easily use a larger size because we mustn't read beyond the end of the buffer if it's shorter than 16 bytes and not a multiple of 2, 4, etc.

Re:A 100LOC C impl of memset, that is faster than glibc's by dahfizz on Friday November 12, 2021 @06:09PM (#29205577)
Yeah, dealing with the smaller buffers is annoying. You could put buffers < 16 bytes in a separate codepath, but that's trading elegance for pretty minor gains.