Re:A 100LOC C impl of memset, that is faster than glibc's
by yissp on Friday November 12, 2021 @09:00AM
(#29199300)
Is the choice of 16 as the "limit" value based on benchmarking? As opposed to just doing something like "!buffer[0] && !memcmp(buffer, buffer + 1, size - 1)" which uses the same principle.
[ Parent
| on HN ]
Re:A 100LOC C impl of memset, that is faster than glibc's
by BeeOnRope on Friday November 12, 2021 @09:24AM
(#29199515)
Not the OP, but 16 has the benefit of keeping both pointers in the comparison 16-byte aligned if the buffer was initially aligned.
This would eliminate split loads and provide a decent speedup.
Re:A 100LOC C impl of memset, that is faster than glibc's
by boibombeiro on Saturday November 13, 2021 @03:27AM
(#29208339)
This, and loop unrolling, are two commons misconception about uarch optimization.
https://lemire.me/blog/2012/05/31/data-alignment-for-speed-m...
Memory alignment is innocuous (others than often compromise code legibility).
Loop unrolling, on the other hand, can slow down the code. Specially in small loops.
See Agner uarch PDF.