简体   繁体   中英

Can there be conflict between `-march` and instruction set switches?

I am compiling an example program with the following command:

$ gcc -march=i386 -mtune=i386 -mmmx -msse4 -m3dnow -m32 -o hello.exe hello.c

Questions:

  1. Why doesn't GCC complain that the switches for enabling MMX, SSE4 and 3DNow! are incompatible with the chosen architecture i386?
  2. Does the compiler generate an executable that cannot run on i386?

Why doesn't GCC complain that the switches for enabling MMX, SSE4 and 3DNow! are incompatible with the chosen architecture i386?

Because the architecture chosen with -march= specifies, among other things, the instruction set extensions that are available; you then explicitly add MMX, SSE4 and 3DNow! to the set of extensions the compiler will use. If you consider that i386 is the "base" architecture for the following architectures which implemented those instruction set extensions, this makes perfect sense.

Putting it another way: -march=i386 by itself reduces the set of instructions used, including extensions, so that the produced code will run on a 386 processor. Later options ( -mmmx etc) add to the set of instructions used. The combination of -march=i386 -mmmx doesn't really make sense, but if you specifically ask for that combination, that's what you'll get. It would take extra logic in the the compiler to deduce that the combination is nonsensical.

( -march also sets various tuning parameters, at least for x86. Unless I'm mistaken, the -mtune=i386 is redundant).

Does the compiler generate an executable that cannot run on i386?

Yes, potentially; this is exactly what you asked it to do with each of -mmmx -msse4 -m3dnow .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM