为什么汇编指令可以在"lea"中包含乘法?操作说明? [英] Why can assembly instructions contain multiplications in the "lea" instruction?

查看:233
本文介绍了为什么汇编指令可以在"lea"中包含乘法?操作说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究性能非常关键的应用程序的非常低级的部分.

I am working on a very low level part of the application in which performance is critical.

在调查生成的程序集时,我注意到以下说明:

While investigating the generated assembly, I noticed the following instruction:

lea eax,[edx*8+8]

使用内存引用(例如[edx + 4])时,我习惯于看到加法,但这是我第一次看到乘法.

I am used to seeing additions when using memory references (e.g. [edx+4]), but this is the first time I see a multiplication.

  • 这是否意味着x86处理器可以在lea指令中执行简单的乘法运算?
  • 这种乘法对执行指令所需的周期数有影响吗?
  • 乘法是否仅限于2的幂(我会假设是这种情况)?

谢谢.

推荐答案

扩大我的评论并回答其余问题...

To expand on my comment and to answer the rest of the question...

是的,仅限于2的幂. (特别是2、4和8),因此不需要乘数,因为它只是一个移位.这样做的目的是从索引变量和指针快速生成地址-数据类型是简单的2、4或8字节字. (尽管它也经常被滥用作其他用途.)

Yes, it's limited to powers of two. (2, 4, and 8 specifically) So no multiplier is needed since it's just a shift. The point of it is to quickly generate an address from an index variable and a pointer - where the datatype is a simple 2, 4, or 8 byte word. (Though it's often abused for other uses as well.)

关于所需的循环数:根据 Agner Fog的表,它看起来像指令在某些机器上是恒定的,而在其他机器上是可变的.

As for the number of cycles that are needed: According to Agner Fog's tables it looks like the lea instruction is constant on some machines and variable on others.

在桑迪桥(Sandy Bridge)上,如果是复杂或相对亲戚",将处以2个周期的罚款.但这并没有说明复杂"的含义...因此,除非您进行基准测试,否则我们只能猜测.

On Sandy Bridge there's a 2-cycle penalty if it's "complex or rip relative". But it doesn't say what "complex" means... So we can only guess unless you do a benchmark.

这篇关于为什么汇编指令可以在"lea"中包含乘法?操作说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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