现代处理器中是否有对128位整数的硬件支持? [英] Is there hardware support for 128bit integers in modern processors?
问题描述
我们是否仍需要在软件中模拟128位整数,或者这些天您的普通台式机处理器中是否对它们进行硬件支持?
Do we still need to emulate 128bit integers in software, or is there hardware support for them in your average desktop processor these days?
推荐答案
x86-64指令集可以使用一条指令执行64位* 64位至128位(对于未签名的 imul,<< c $ c> mul
表示每个对象都带有一个操作数),因此我认为在某种程度上说x86指令集确实包含对128位整数的支持。
The x86-64 instruction set can do 64-bit*64-bit to 128-bit using one instruction (mul
for unsigned imul
for signed each with one operand) so I would argue that to some degree that the x86 instruction set does include some support for 128-bit integers.
如果您的指令集没有将64位* 64位转换为128位的指令,那么您需要模仿此指令的几条指令。
If your instruction set does not have an instruction to do 64-bit*64-bit to 128-bit then you need several instructions to emulate this.
这就是为什么128 x86-64只需很少的指令就可以完成位* 128位到低位128位的操作。例如,对于GCC
This is why 128-bit * 128-bit to lower 128-bit operations can be done with few instructions with x86-64. For example with GCC
__int128 mul(__int128 a, __int128 b) {
return a*b;
}
生成此程序集
imulq %rdx, %rsi
movq %rdi, %rax
imulq %rdi, %rcx
mulq %rdx
addq %rsi, %rcx
addq %rcx, %rdx
使用一个64位* 64位至128位指令,两个64位* 64位至较低的64位指令以及两个64位加法。
which uses one 64-bit * 64-bit to 128-bit instructions, two 64-bit * 64-bit to lower 64-bit instructions, and two 64-bit additions.
这篇关于现代处理器中是否有对128位整数的硬件支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!