2 ms·
> and modulo If the modulo is a compile time constant it should get converted into a multiply. If its not, for whatever reason the performance will be less th
by nullc 5y ago
> and modulo
If the modulo is a compile time constant it should get converted into a multiply. If its not, for whatever reason the performance will be less than amazing.
- ithkuil 5y agoThere is a trick to turn a modulo info a multiplication even if it's not known at compile time: https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/ https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-...
- turminal 5y agoThe blog post you linked is about fair range mapping. I don't see how that applies to the problem of computing a modulo while avoiding expensive cpu instructions.
- nullc 5y agoYeah, that is inapplicable. This is the relevant reference: Arch D. Robison, "{N}-bit Unsigned Division via {N}-bit Multiply-Add" (2005) https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.512.2627&rep=rep1&type=pdf https://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.51...