From what I understand every CPU that supports AVX2 supports AVX, and every CPU that supports AVX supports SSE4.2.
Does that mean that just specifying -mavx2
is enough or there is a difference between:
-msse4.2 -mavx -mavx2
and
-mavx2
All I found in GCC docs is this(AVX SSE relationship):
GCC depresses SSEx instructions when -mavx is used. Instead, it generates new AVX instructions or AVX equivalence for all SSEx instructions when needed.
I presume this just means that GCC will use better AVX instructions instead of SSE instructions, so I guess this implies when you have -mavx that msse4.2 is useless, but I could not find anything wrt -mavx2
-mavx
relationship.
I also looked up the clang docs, could not find anything.
Note: I am compiling C++ code, but I presume answer is same for C and C++ compilers.
You can look at the active flags for gcc by adding -Q --help=target
to the command line.
Pipe into files, compare. The two sets of options produced identical settings for me.