On Sun, 28 Feb 2021, 19:37 Szabolcs Nagy, wrote: > * Mattias Andrée [2021-02-28 20:22:10 +0100]: > > On x86 modulo is free when doing division, so this removes > > there should be no division. > > div by const is transformed to mul and shift at -O1 and > that's what we should be using instead of manual hacks. Right. Divide by constant is cheap because compilers have a bunch of transforms to get rid of the divide in favour of one of more cheaper instructions. Note that module coming for free with division doesn't make it cheap. Integer division is far more expensive that integer multiply on ~ every architecture. Several architectures implement division in software. It's not cheap on x86, despite the dedicated instruction. Cheers