简体   繁体   English

-march和指令集开关之间是否会有冲突?

[英]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! GCC为什么不抱怨启用MMX,SSE4和3DNow的开关! are incompatible with the chosen architecture i386? 与所选架构i386不兼容?
  2. Does the compiler generate an executable that cannot run on i386? 编译器会生成无法在i386上运行的可执行文件吗?

Why doesn't GCC complain that the switches for enabling MMX, SSE4 and 3DNow! GCC为什么不抱怨启用MMX,SSE4和3DNow的开关! are incompatible with the chosen architecture i386? 与所选架构i386不兼容?

Because the architecture chosen with -march= specifies, among other things, the instruction set extensions that are available; 因为用-march=选择的体系结构特别指定了可用的指令集扩展; you then explicitly add MMX, SSE4 and 3DNow! 然后,您可以显式添加MMX,SSE4和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. 如果您认为i386是以下实现这些指令集扩展的体系结构的“基础”体系结构,那么这是很合理的。

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. 换种说法: -march=i386本身减少了所使用的指令集(包括扩展名),因此产生的代码将在386处理器上运行。 Later options ( -mmmx etc) add to the set of instructions used. 后面的选项( -mmmx等)添加到所使用的指令集中。 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. -march=i386 -mmmx的组合实际上没有任何意义,但是,如果您明确要求该组合,那么您会得到。 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). -march至少为x86还设置了各种调整参数。除非我没有记错,否则-mtune=i386是多余的)。

Does the compiler generate an executable that cannot run on i386? 编译器会生成无法在i386上运行的可执行文件吗?

Yes, potentially; 是的,可能; this is exactly what you asked it to do with each of -mmmx -msse4 -m3dnow . 这正是您要求它对-mmmx -msse4 -m3dnow

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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