4 ms·
One thing that's not all that obvious from this large chunk of assembly is that Clang manages to rewrite (x >= 'a' && x <= 'z') into (x - 'a') < <some co
by Sesse__ 2y ago
One thing that's not all that obvious from this large chunk of assembly is that Clang manages to rewrite
(x >= 'a' && x <= 'z')
into
(x - 'a') < <some constant>
which saves one instruction (and sometimes, a register load due to weird opcode encoding thingies).
- neonsunset 2y agoThis is a common transformation for range-check style comparisons. It is always nice to see that LLVM reasons about it in a generalized fashion and applies it to vector operations, and it is what I ultimately ended up on when writing a similar to author's implementation.
- Sesse__ 2y agoI sometimes write intrinsic comparisons (e.g., something like "x < 'a'" instead of "_mm_cmplt_epi8(x, _mm_set1_epi8('a'))") just to make sure the compiler understands what's going on and can do that sort of transformations. (It also sometimes makes for more code sharing between e.g. x86 and NEON.)