Answer by keraba for Optimisation of division in gcc
The difference in speed is caused by the compiler not knowing if "div" will change value. When it is non-const, it is treating it like a variable being passed in. It could be anything, and so the...
View ArticleAnswer by Greg Rogers for Optimisation of division in gcc
I'm guessing its just the severely old GCC version you are running. The oldest compiler I have on my machine - gcc-4.1.2, performs the fast way with both the non-const and the wrap versions (and does...
View ArticleAnswer by Marc Mutz - mmutz for Optimisation of division in gcc
Is there a known way of wrapping an int such that the compiler can discard the wrapping when optimising?Try passing WrappedInt by value. Then WrappedInts can be passed in registers....
View ArticleAnswer by Mark Ransom for Optimisation of division in gcc
Try combining const int v in your WrappedInt class with const T in your fizzbuzz function and see if the compiler can optimize that.By declaring const int you've created a special case - a compile time...
View ArticleOptimisation of division in gcc
Here's some code (full program follows later in the question):template <typename T>T fizzbuzz(T n) { T count(0); #if CONST const T div(3); #else T div(3); #endif for (T i(0); i <= n; ++i) { if...
View Article
More Pages to Explore .....