Faster remainders when the divisor is a constant: beating compilers and libdivide
Daniel Lemire
FEBRUARY 8, 2019
I believe that all optimizing C/C++ compilers know how to pull this trick and it is generally beneficial irrespective of the processor’s architecture. There are far more efficient ways to do that, but here is the programming 101 approach in C: for ( uint32_t i = 0 ; i < N ; i + + ) {. Can we do better? if ( ( i % 3 ) = = 0 ).
Let's personalize your content