__int64 在 32 位机器上? [英] __int64 on a 32-Bit machine?
问题描述
我刚刚在我的 32 位机器上尝试了 MSVC 2010 中的一些东西,发现我可以在我的程序中使用 __int64
- 这确实有效!
I just tried something in MSVC 2010 on my 32-bit machine here and found out that I can use __int64
in my programs - which actually work!
这怎么可能?
推荐答案
32 位算法在 16 位系统上的工作方式相同.
Same way 32-bit arithmetic worked on 16-bit systems.
在这种情况下,它使用 2 个 32 位内存地址一起组成一个 64 位数字.加法/减法很容易,您可以按部分进行,唯一的问题是将结转从较低的部分转移到较高的部分.对于乘法/除法,它更难(即更多指令).
In this case, it uses 2 32-bit memory addresses to form a 64-bit number together. Addition/substraction is easy, you do it by parts, the only gotcha is taking the carry-over from the lower part to the higher part. For multiplication/division, it's harder (ie more instructions).
它显然很慢,比乘法的 32 位算术慢很多,但如果你需要它,它就在你身边.当您升级到 64 位 处理器 编译器时,它会自动优化为具有更大字长的一条指令.
It's obviously slow, quite a bit slower than 32 bit arithmetic for multiplication, but if you need it, it's there for you. And when you upgrade to a 64-bit processor compiler, it gets automatically optimized to one instruction with the bigger word size.
Visual Studio 2010 Professional 在 32 位处理器上的 64 位乘法实现,在发布模式下编译,是:
The Visual Studio 2010 Professional implementation of 64 bit multiplication on a 32-bit processor, compiled in release mode, is:
_allmul PROC NEAR
A EQU [esp + 4] ; stack address of a
B EQU [esp + 12] ; stack address of b
mov eax,HIWORD(A)
mov ecx,HIWORD(B)
or ecx,eax ;test for both hiwords zero.
mov ecx,LOWORD(B)
jnz short hard ;both are zero, just mult ALO and BLO
mov eax,LOWORD(A)
mul ecx
ret 16 ; callee restores the stack
hard:
push ebx
A2 EQU [esp + 8] ; stack address of a
B2 EQU [esp + 16] ; stack address of b
mul ecx ;eax has AHI, ecx has BLO, so AHI * BLO
mov ebx,eax ;save result
mov eax,LOWORD(A2)
mul dword ptr HIWORD(B2) ;ALO * BHI
add ebx,eax ;ebx = ((ALO * BHI) + (AHI * BLO))
mov eax,LOWORD(A2) ;ecx = BLO
mul ecx ;so edx:eax = ALO*BLO
add edx,ebx ;now edx has all the LO*HI stuff
pop ebx
ret 16 ; callee restores the stack
如您所见,它比普通乘法慢很多.
As you can see, it's a LOT slower than normal multiplication.
这篇关于__int64 在 32 位机器上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!