IMUL或移位指令? [英] imul or shift instruction?

查看:257
本文介绍了IMUL或移位指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪一个是快 -

val = val*10;

val = (val<<3) + (val<<2);

多少个时钟周期的确比转向指令时IMUL走?

How much clock cycle does imul take when compared to shift instruction?

-Kartlee

推荐答案

在此情况下,他们可能会采取周期的相同金额,但您的手册优化需要多一个寄存器(​​它可以减缓周围code ):

In this case they probably take the same amount of cycles, though your manual "optimization" needs one more register (which can slow down the surrounding code):

val = val * 10;
lea    (%eax,%eax,4),%eax
add    %eax,%eax

VS

val = (val<<3) + (val<<1);
lea    (%eax,%eax,1),%edx
lea    (%edx,%eax,8),%eax

编译器知道该怎么办强度降低,也许比你好得多。此外,当您端口code到其他平台(例如,ARM),编译器知道该怎么做实力降低该平台上的太(86的 LEA 提供了不同的优化比ARM的机会,添加 RSB )。

The compiler knows how to do strength reduction, and probably much better than you. Also, when you port your code to other platform (say, ARM), the compiler knows how to do strenght reduction on that platform too (x86's LEA provides different optimization opportunities than ARM's ADD and RSB).

这篇关于IMUL或移位指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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