从VS 2008/2010 86 MUL指令 [英] x86 MUL Instruction from VS 2008/2010

查看:190
本文介绍了从VS 2008/2010 86 MUL指令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请问现代(2008/2010)Visual Studio或Visual C ++防爆preSS生产的x86指令MUL(无符号乘)在编译code咒语?我似乎无法找到或设计,他们出现在编译code。使用无符号类型,即使一个例子。

Will modern (2008/2010) incantations of Visual Studio or Visual C++ Express produce x86 MUL instructions (unsigned multiply) in the compiled code? I cannot seem to find or contrive an example where they appear in compiled code, even when using unsigned types.

如果VS没有编译使用MUL,有一个理由,为什么?

If VS does not compile using MUL, is there a rationale why?

推荐答案

IMUL (签字)和 MUL (无符号)都有一个操作数形式,做 EDX:EAX = EAX * SRC 。即一个32x32b => 64B满乘(或64x64b => 128B)。

imul (signed) and mul (unsigned) both have a one-operand form that does edx:eax = eax * src. i.e. a 32x32b => 64b full multiply (or 64x64b => 128b).

286添加了一个 IMUL DEST(REG),SRC(REG / MEM),直接 形式,和386添加了一个 IMUL R32,R / M32 的形式,两者只计算下半部分的结果。 (链接从 86 标签的wiki)。

286 added an imul dest(reg), src(reg/mem), immediate form, and 386 added an imul r32, r/m32 form, both of which which only compute the lower half of the result. (Link from the x86 tag wiki).

在乘两个32位值,其结果的最低显著32位都是一样的,不管你考虑值进行带符号。换句话说,有符号和无符号乘法之间的区别变得很明显只有当你在看结果的上的一半,其中一个操作数 IMUL / MUL 放入 EDX 和两个或三个操作数 IMUL 提出行不通的。因此, IMUL 的多操作数形式可以在符号和无符号值使用,没有必要为英特尔增加 MUL的新形式为好。 (他们可以做多操作数 MUL IMUL 的代名词,但是这将使反汇编输出不匹配源。)

When multiplying two 32-bit values, the least significant 32 bits of the result are the same, whether you consider the values to be signed or unsigned. In other words, the difference between a signed and an unsigned multiply becomes apparent only if you look at the "upper" half of the result, which one-operand imul/mul puts in edx and two or three operand imul puts nowhere. Thus, the multi-operand forms of imul can be used on signed and unsigned values, and there was no need for Intel to add new forms of mul as well. (They could have made multi-operand mul a synonym for imul, but that would make disassembly output not match the source.)

在C,算术运算结果具有相同类型的操作数(整数后晋升为窄整数类型)。如果将两个 INT 在一起,你会得到一个 INT ,而不是长长:上半不保留。因此,C编译器只需要什么 IMUL 规定,自 IMUL 更容易使用比 MUL ,C编译器使用 IMUL 来避免需要 MOV 指令将数据导入输入/输出的 EAX

In C, results of arithmetic operations have the same type as the operands (after integer promotion for narrow integer types). If you multiply two int together, you get an int, not a long long: the "upper half" is not retained. Hence, the C compiler only needs what imul provides, and since imul is easier to use than mul, the C compiler uses imul to avoid needing mov instructions to get data into / out of eax.

第二步,由于C编译器使用 IMUL 大量的多操作数的形式,Intel和AMD投入精力使它尽可能快。只写入一个输出寄存器,而不是 E / RDX:E / RAX ,所以这是有可能的CPU比单操作数的形式更容易优化。这使得 IMUL 更具吸引力。

As a second step, since C compilers use the multiple-operand form of imul a lot, Intel and AMD invest effort into making it as fast as possible. It only writes one output register, not e/rdx:e/rax, so it was possible for CPUs to optimize it more easily than the one-operand form. This makes imul even more attractive.

MUL / IMUL 的一个操作数形式来实现大的数字运算时非常有用。在C,在32位模式下,你应该乘以无符号长长值加在一起得到一些 MUL 调用。但是,根据不同的编译器和操作系统,那些 MUL 运算codeS可能隐藏在一些专用的功能,所以你不一定会看到它们。在64位模式下,长长只有64位,而不是128,编译器会简单地使用 IMUL

The one-operand form of mul/imul is useful when implementing big number arithmetic. In C, in 32-bit mode, you should get some mul invocations by multiplying unsigned long long values together. But, depending on the compiler and OS, those mul opcodes may be hidden in some dedicated function, so you will not necessarily see them. In 64-bit mode, long long has only 64 bits, not 128, and the compiler will simply use imul.

这篇关于从VS 2008/2010 86 MUL指令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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