Stuff like this is what I think of when I hear "compiler writers are smarter than you, don't micro-optimize".<p>It's amazingly much better to have the compiler hide this, than for application-level programmers to figure out the trick by themselves, and obfuscate their code accordingly. Sweet.
An oldie but goodie. In practice, compilers are pretty good at working this out for you, <i>provided the denominator is a constant expression.</i> In other words, if you're burning cycles because of a division with variable but rarely-changing denominator in an inner loop, it can make sense to precompute the equivalent multiplication factor and perform the multiplication explicitly.
I wish I could understand that. The math and all. If I could, I would be such an awesome programmer.<p>And incredibly smart.<p>Hat's off for this guy at least.
The article is not available at the moment so I am flying a bit blind here.<p>H. Warren, Hackers Delight has a nice discussion of this problem. One of my favorite books, but I like to do code generators.<p><a href="http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201914654/ref=sr_1_1?ie=UTF8&s=books&qid=1266426413&sr=8-1" rel="nofollow">http://www.amazon.com/Hackers-Delight-Henry-S-Warren/dp/0201...</a>
As an aside, Ridiculous Fish, apart from the excellent name, is one of the best blogs I know - interesting topics, good scientific method proving his conclusions, and a great writing style. I wish he posted more.