Hacker News new | past | comments | ask | show | jobs | submit login
Fastrange: A fast alternative to the modulo reduction (github.com/lemire)
21 points by henrikm85 on Dec 12, 2016 | hide | past | favorite | 4 comments



This is how we've been doing division by a constant in the embedded world since...forever

this is so well known in fact that arm gcc defaults to this when a proper constant exists if you do division or modulus operator...


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.


Shouldn't a good compiler apply this type of optimisations?


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.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: