Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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).


This 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.


I 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.)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: