【问题标题】:which cpu is targeted with gcc's -mtune=generic?gcc 的 -mtune=generic 以哪个 cpu 为目标?
【发布时间】:2016-11-02 00:00:18
【问题描述】:

使用 gcc,您可以指定“-mtune=”或“-mtune=generic”

我如何知道 gcc 的“-mtune=generic”针对的是哪个架构?它应该根据不同版本的GCC而有所不同?

文档https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/x86-Options.html#x86-Options 说:

As new processors are deployed in the marketplace, the behavior of this option will change. Therefore, if you upgrade to a newer version of GCC, code generation controlled by this option will change to reflect the processors that are most common at the time that version of GCC is released.

我如何知道每个 GCC 版本的目标是哪一个?

文档说:

https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/x86-Options.html#x86-Options

...
‘i686’
When used with -march, the Pentium Pro instruction set is used, 
so the code runs on all i686 family chips. When used with -mtune, it has the same meaning as ‘generic’. 

所以我猜通用“意味着”i686,但那是一个特定的 CPU 吗?

【问题讨论】:

  • 您可以尝试添加 -fverbose-asm -S 并检查生成的 asm 的第一行是否有选项...您想知道 x86/x86_64 或任何 gcc 支持的架构的 mtune=generic 吗?
  • 它不一定针对一个特定的 cpu。这可能是一种折衷方案,避免在某些 AMD CPU 上运行速度非常慢的代码,避免在某些英特尔 CPU 上运行速度非常慢的其他代码,最终得到对任何 CPU 都不是最佳但在任何地方都可以的代码。

标签: gcc


【解决方案1】:

我如何知道 gcc 的“-mtune=generic”针对的是哪个架构?

通过阅读真实文档,gcc的源码(switch(tune)后搜索PROCESSOR_GENERIC

对于 x86(32/64 位)gcc/config/i386/i386-c.c,它不会定义 builtins/arch 宏,

  /* Built-ins based on -mtune=.  */
  switch (tune)

    case PROCESSOR_GENERIC:
      break;

并且gcc/config/i386/driver-i386.c 将不会检测具有cpuid 的本地cpu(如果没有cpu=native / tune=native 将不会调用host_detect_local_cpu

您可以尝试添加 -fverbose-asm -S 并检查生成的 asm 的第一行是否有选项..

【讨论】:

    猜你喜欢
    • 2012-09-18
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 2011-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多