8 ms·
Whether or not the endianness is in your favor, an optimized implementation could still use wide integer comparisons to tear through the bulk of the data quick
by sgtnoodle 6y ago
Whether or not the endianness is in your favor, an optimized implementation could still use wide integer comparisons to tear through the bulk of the data quickly. On mismatch, simply fall back to byte-wise to determine the correct ordering.
On a tangent, strcmp seems like it would be difficult to optimize since the length isn't known until the trailing null is found. Does anyone know how it's typically done?
- zeusk 6y agoI know you asked for strcmp, but the strlen is far better documented on how the null-byte detection works for ARM. https://lkml.org/lkml/2020/9/14/871 https://lkml.org/lkml/2020/9/14/871 https://github.com/ARM-software/optimized-routines/blob/master/string/aarch64/strlen-mte.S https://github.com/ARM-software/optimized-routines/blob/mast...
- sgtnoodle 6y agoI see, so the implementations basically read past the end of the string as long as it won't cross a page boundary and cause a memory protection fault. It's technically a buffer overflow, but since the implementations are architecture specific, it's safe to do. I wonder if there are memory sanitizers that would complain about that sort of access?
- deleted 6y ago[deleted]