Fastrange: A fast alternative to the modulo reduction (github.com) 21 points by henrikm85 9y ago ↗ HN
[–] dmitrygr 9y ago ↗ This is how we've been doing division by a constant in the embedded world since...foreverthis is so well known in fact that arm gcc defaults to this when a proper constant exists if you do division or modulus operator... [–] lvs 9y ago ↗ I was going to say, this is an ancient and well-known optimization. I have no idea how old it is, but I would venture it's been a regular practice for at least two decades.
[–] lvs 9y ago ↗ I was going to say, this is an ancient and well-known optimization. I have no idea how old it is, but I would venture it's been a regular practice for at least two decades.
[–] rkwasny 9y ago ↗ Shouldn't a good compiler apply this type of optimisations? [–] AstralStorm 9y ago ↗ It generally does. (GCC, Clang and ICC) But it cannot simplify the operation on some architectures or when the factor is variable.The "fastrange" is a very different operation on prime factors than modulo.
[–] AstralStorm 9y ago ↗ It generally does. (GCC, Clang and ICC) But it cannot simplify the operation on some architectures or when the factor is variable.The "fastrange" is a very different operation on prime factors than modulo.
4 comments
[ 2.3 ms ] story [ 15.5 ms ] threadthis is so well known in fact that arm gcc defaults to this when a proper constant exists if you do division or modulus operator...
The "fastrange" is a very different operation on prime factors than modulo.