Search code examples
c++gccssesse2

C/C++: -msse and -msse2 Flags do not have any effect on the binaries?


I'm just playing around with gcc (g++) and the compilerflags -msse and -msse2. I have a little test program which looks like that:

#include <iostream>

int main(int argc, char **argv) {
    float a = 12558.5688;
    float b = 6.5585;

    float result = 0.0;

    result = a * b;

    std::cout << "Result: " << result << std::endl;

    return 0;
}

When I compile it with the following statements:

/usr/local/bin/g++-4.9 -W -msse main.cpp -o testsse

and

/usr/local/bin/g++-4.9 -W -msse2 main.cpp -o testsse2

the output files are binary equal. But I've expected that they are not the same because of the SMID flags.

So my question is, do those complier flags do not have any influence on the binary file? I've tested it on OS X 10.10.3 and Fedora 21.

Thanks for your help.

Kind regards

Fabian


Solution

  • In your code very basic floating point maths is involved. And I bet if you turn optimizations on (even -O1) it gets optimized out because those values are constant expressions and so calculable at compile-time.

    SSE is used (movss, mulss) because it's the threshold of floating point calculus, if we want. SSE2 has no scope here.
    In order to find room for SSE2 you need to include more complex calculus which may or may not exploit some instructions available in SSE2; you could look up what some do, do their equivalent and see if the compiler can take advantage of them.