如何查看 -march=native 将激活哪些标志?
我正在使用 GCC 4.3 编译我的 C++ 应用程序。我没有手动选择优化标志,而是使用 -march=native
,理论上它应该添加适用于我正在编译的硬件的所有优化标志。但我如何检查它实际使用了哪些标志?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用
-Q --help=target
选项:-v
选项也可能有用。您可以查看有关
--help
选项的文档 此处。You can use the
-Q --help=target
options:The
-v
option may also be of use.You can see the documentation on the
--help
option here.要查看命令行标志,请使用:
如果您想查看由某些参数设置的编译器/预编译器定义,请执行以下操作:
To see command-line flags, use:
If you want to see the compiler/precompiler defines set by certain parameters, do this:
它应该是(
-###
类似于-v
):显示 gcc 的“真实”本机标志。
您可以使用命令使它们看起来更“清晰”:
并且您可以使用 -mno-* 删除标志:
It should be (
-###
is similar to-v
):To show the "real" native flags for gcc.
You can make them appear more "clearly" with a command:
and you can get rid of flags with -mno-* with:
如果您想了解如何设置非本机交叉编译,我发现这很有用:
在目标计算机上,
然后在构建计算机上使用它:
If you want to find out how to set-up a non-native cross compile, I found this useful:
On the target machine,
Then use this on the build machine:
我将在这个问题上投入我的两分钱,并建议对埃利亚斯的答案进行稍微更详细的扩展。从 gcc 4.6 开始,运行 gcc -march=native -v -E -
/dev/null
以多余的-mno-*
标志的形式发出越来越多的垃圾邮件。以下内容将删除这些内容:但是,我仅在两个不同的 CPU(Intel Core2 和 AMD Phenom)上验证了此操作的正确性,因此我建议还运行以下脚本以确保所有这些
-mno- *
标志可以被安全地剥离。2021 编辑:确实有一些机器的
-march=native
使用特定的-march
值,但必须禁用一些带有-mno-*
的隐含 ISA(指令集架构)。我还没有发现 gcc -march=native -v -E -
gcc -march=native -v -E -
之间的区别/dev/null
和gcc -march=native -### -E -
/dev/null
除了一些被引用的参数之外——以及不包含特殊字符的参数,所以我不确定在什么情况下这会产生任何真正的区别。最后,请注意
--march=native
是在 gcc 4.2 中引入的,在此之前它只是一个无法识别的参数。I'm going to throw my two cents into this question and suggest a slightly more verbose extension of elias's answer. As of gcc 4.6, running of
gcc -march=native -v -E - < /dev/null
emits an increasing amount of spam in the form of superfluous-mno-*
flags. The following will strip these:However, I have only verified the correctness of this on two different CPUs (an Intel Core2 and AMD Phenom), so I suggest also running the following script to be sure that all of these
-mno-*
flags can be safely stripped.2021 EDIT: There are indeed machines where
-march=native
uses a particular-march
value, but must disable some implied ISAs (Instruction Set Architecture) with-mno-*
.I haven't found a difference between
gcc -march=native -v -E - < /dev/null
andgcc -march=native -### -E - < /dev/null
other than some parameters being quoted -- and parameters that contain no special characters, so I'm not sure under what circumstances this makes any real difference.Finally, note that
--march=native
was introduced in gcc 4.2, prior to which it is just an unrecognized argument.resolve-march-native 正是为此:它解析 GCC 输出并结合将多次调用 GCC 的输出转化为最终答案。例如:
还有 distccflags 但它 似乎已停止。
PS:我是resolve-march-native的作者。
There is resolve-march-native for exactly this: It parses GCC output and combines the output from multiple calls to GCC into the eventual answer. For example:
There is also distccflags but it seems discontinued.
PS: I am the author of resolve-march-native.