gcc的mtune和march选项分析

给定gcc优化选项时经常要指定march和mtune。我以前都将它们赋为一样的值,例如pentium4.

今天仔细研究了一下它们的区别,原来还是有一些道道的。

首先是man gcc:

-mtune=name
      This option is very similar to the -mcpu= option, except that
      instead of specifying the actual target processor type, and hence
      restricting which instructions can be used, it specifies that GCC
      should tune the performance of the code as if the target were of
      the type specified in this option, but still choosing the instruc-
      tions that it will generate based on the cpu specified by a -mcpu=
      option.

上面是gcc3.2的manpage,现在mcpu已经不用了,一般都用march。望文生义,march指定的是当前cpu的架构,而mtune是真正作用于某一型号cpu的选项。

根据链接:
http://gentoo-wiki.com/Safe_Cflags
的解释,march是“紧约束”,mtune是“松约束”。mtune可以提供后向兼容性,也就是mtune=pentium-mmx编译出来的程序,在pentium4处理器上也是可以运行的。

因此,像-march=i686 -mtune=pentium4这样的优化选项编译出来的程序,是为奔腾4处理器优化过的,但是在任何i686上都可以运行。

我猜,如果指定了-march=pentium3,那么在奔腾4处理器上程序是不能运行的。

上面是自己根据别人的文档整理出来的一些说法,具体是不是这么回事没有试验过。若有错误的地方,还请大虾指正:-)
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值