On Apr 1, 2013, at 6:20 AM, Tom Browder wrote:
> I've always been taught to avoid div unless really needed, and a "/ 2"
> usually makes me wince when looking through code.
>
> (I know, maybe premature optimization, but...)
I have the same best practice engrained, but modern compilers are more than
smart enough to figure it out these days. Most do that for you automatically
if you turn on any level of optimization. You can confirm this yourself with a
simple test, say an input like this:
int main(int ac, char *av) {
volatile double x = 100.0;
if (x > 25.0)
return x / 2.0;
else
return 100.0 / 0.5;
}
With GCC, the -S option (gcc -S test.c; cat test.s) tells it to output the
assembler before linking. Doing this, you'll see a divsd instruction (on Intel
x86) but it won't even output the second division since it's constant. Turning
on any level of optimization and you won't see the first either as it gets
turned into a multiply.
As for the recent commits, those were all automated cleanup. It would have
warranted a much more careful regex and testing had the ops been modified.
That said, it rarely does harm to convert them to multiplies too.
Cheers!
Sean
------------------------------------------------------------------------------
Own the Future-Intel® Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game
on Steam. $5K grand prize plus 10 genre and skill prizes.
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
BRL-CAD Developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-devel