3 ms·
Indeed, llvm is smart enough not to use a DIV instruction for modulo of a constant. Turns out you can compute x%3 == 0 with even fewer steps, it's (x*0xaaaaaaa
by raphlinus 9y ago
Indeed, llvm is smart enough not to use a DIV instruction for modulo of a constant.
Turns out you can compute x%3 == 0 with even fewer steps, it's (x*0xaaaaaaaab) < 0x55555556 (assuming wrapping unsigned 32 bit arithmetic).
- pcordes 9y agoNice. It seems gcc/clang don't know that trick. They still divide and then check that x/3 * 3 == x. https://godbolt.org/g/V4kfuu https://godbolt.org/g/V4kfuu. (So do ICC17 and MSVC CL19).