为什么ICC生产和QUOT; INC"代替"新增]在x86汇编? [英] Why does ICC produce "inc" instead of "add" in assembly on x86?

查看:187
本文介绍了为什么ICC生产和QUOT; INC"代替"新增]在x86汇编?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然用简单的C code摆弄,我发现了一些奇怪的。为什么ICC产生含%EAX 组装code为增量,而不是 ADDL $ 1,%EAX 产生的?海湾合作委员会的行为就像预期的那样,使用添加

While fiddling with simple C code, I noticed something strange. Why does ICC produces incl %eax in assembly code generated for increment instead of addl $1, %eax? GCC behaves as expected though, using add.

举例code( -O3 对GCC和ICC使用)

Example code (-O3 used on both GCC and ICC)

int A, B, C, D, E;

void foo()
{
    A = B + 1;
    B = 0;
    C++;
    D++;
    D++;
    E += 2;
}

结果对ICC

L__routine_start_foo_0:
foo:
    movl      B(%rip), %eax                                 #5.13
    movl      D(%rip), %edx                                 #8.9
    incl      %eax                                          #5.17
    movl      E(%rip), %ecx                                 #10.9
    addl      $2, %edx                                      #9.9
    addl      $2, %ecx                                      #10.9
    movl      %eax, A(%rip)                                 #5.9
    movl      $0, B(%rip)                                   #6.9
    incl      C(%rip)                                       #7.9
    movl      %edx, D(%rip)                                 #9.9
    movl      %ecx, E(%rip)                                 #10.9
    ret   

例如,请参见这里

因此​​,我不知道 - 这是一个预期的功能,错误或一些怪癖一些特定的设置导致?如果添加是(据说)由于更好地标志更新或效率(这是基于下面的链接结论) - 为什么ICC使用 INC

As such, I'm wondering - is this an intended feature, a bug or some quirk resulting from some specific setting? If add is (supposedly) better due to flags update or efficiency (which is the conclusion based on the links below) - why does ICC use inc?

相关阅读:

<一个href=\"http://stackoverflow.com/questions/5993326/relative-performance-of-x86-inc-vs-add-instruction\">Relative 86 INC与性能加指令

的是添加1比真快INC? 86

GCC不使用INC

请注意:

我要问这个问题,明确因为没有我发现或者是针对上也是如此解释这种现象的问题。我关于这件事previous问题得到了关闭,因为,据说,这是的琐碎的和的已经回答了的。我并不觉得微不足道。我没有发现在所有给出的链接和答案的答案。这不是另一个如何插入我的鼠标插入我的电脑的问题。所有的问题,解释为什么添加是/可能是新的x86处理器好,或为什么GCC使用它,但没有涉及国际刑事法院。

I'm asking this question explicitly because none of the questions I found or was directed to on SO does explain this behaviour. My previous question concerning this matter got closed because, supposedly, it's trivial and has been answered. I don't find it trivial. I didn't find an answer in all of the links and answers given. It's not another "how to plug my mouse into my PC" problem. All of the questions explain why add is/could be better on new x86 processors or why GCC uses it, but none concerns ICC.

在ICC的设计选择任何有识之士将也非常欢迎。

Any insight on ICC design choices would be also very welcome.

PS我不认为它是因为它一个有效的答案。

PS I don't consider "it does it because it does" a valid answer.

推荐答案

这不是没有道理的在这一点上承担的包括的选择,因为它需要只有一个字节(0X40)代替三( 0X83将0xC0 0x01)的。

It is not unreasonable to assume at this point that incl was selected as it takes only one byte (0x40) instead of three (0x83 0xc0 0x01).

这篇关于为什么ICC生产和QUOT; INC&QUOT;代替&QUOT;新增]在x86汇编?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆