What's the difference among cflgs sse options of -msse, -msse2, -mssse3, -msse4 rtc..? and how to determine?

yaya picture yaya · May 21, 2012 · Viewed 26.7k times · Source

For the GCC CFLAGS options: -msse, -msse2, -mssse3, -msse4, -msse4.1, -msse4.2. Are they exclusive in their use or can they be used together?

My understanding is that the choosing which to set depends on whether the target arch, which the program will run on, supports it or not - is this correct?

If so, how could I know what sse my target arch supports? In Linux, I cat /proc/cpuinfo, but what if Mac or Windows?

Thanks!

Answer

Gunther Piez picture Gunther Piez · May 21, 2012

The -m switched can be used in parallel, furthermore some of them are implied by the architecture or other switches. For instance, if you build code for x86_64, -msse -msse2 is always enabled.

For code intended to run on your system you should choose -march=native, which will select what is available on your processor. For instance, if you have a Sandy Bridge, this will enable -msse -msse2 -msse3 -mssse3 -msse4 -msse4.1 -msse4.2 -mavx.

If you want to specify in detail which instruction set to use, you should only use what is available, not always the "latest". The "latest" one is currently -mavx2, which I don't recommend: The first processor which will support it will be available in 2013.