News for hackers. Stuff that matters.
Re:Why is this C++ code faster than my hand-written assembly... by raphlinus on Tuesday August 22, 2017 @12:10PM (#15073777)
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).

Re:Why is this C++ code faster than my hand-written assembly... by pcordes on Tuesday August 22, 2017 @01:02PM (#15074287)
Nice. 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. (So do ICC17 and MSVC CL19).