I compiled unsigned div10(unsigned x) { return x / 10; } and expected a DIV instruction. Instead the output multiplies by 0xCCCCCCCD (3435973837) and shifts the 64-bit product right by 35 bits. The results are correct for every input I tried, but I cannot see where the constant comes from.
How does multiplying by that number produce an exact quotient, why is it preferred over DIV, and does the same trick apply on microcontrollers that have no hardware divider?




