Question about inline optimization
Arkadiusz Pawlik
apawlik@V-LO.krakow.pl
Fri Aug 6 15:19:00 GMT 2004
I recently wrote the following code:
----------x.cpp
class C {
public:
double x, y;
};
inline double f(C a, C b) {
return a.x * b.y - a.y * b.x;
}
bool g(C a, C b) {
return f(a, b) == 0;
}
---------
Compiling with the command "g++ -O3 -S x.cpp" created a rather
surprising output. (I have only GCC 3.3.3 on CRUX GNU/Linux for i686;
sorry about that; maybe somebody could test it with 3.4.1)
GCC did not optimize copying variables to stack. That is, "g()" placed
the variables a.x, a.y, b.x, b.y on the stack with moves and then from
the stack to fpu.
Why does it happen? This function is performance-critical in my
program, so optimizing the movs could be very beneficient to me.
More information about the Gcc
mailing list