Division and Modulo Operations

Note: Low Priority: Use shift operations to avoid expensive division and modulo calculations.

Integer division and modulo operations are particularly costly and should be avoided or replaced with bitwise operations whenever possible: If n is a power of 2, (i/n) is equivalent to (i >> log2(n)) and (i % n) is equivalent to (i & (n-1)).

The compiler will perform these conversions if n is literal. (For further information, refer to Chapter 5 of the CUDA C Programming Guide).