移植32位C ++ code到64位 - 是值得吗?为什么?code

2023-09-07 23:03:57 作者:风扬起的思念╯

我知道的x64体系结构的一些明显的收益(更高的可寻址内存地址等)...但是:

I am aware of some the obvious gains of the x64 architecture (higher addressable RAM addresses, etc)... but:

如果我的程序有没有真正的需要在本地64位模式下运行。应该反正我口呢? 是否有任何可预见的期限截至32位支持? 请问我的应用程序运行得更快/更好/原生64位code更安全?

推荐答案

X86-64是有点特例 - (如SPARC)对许多架构,编制为64位模式下的应用程序不给它任何利益除非能盈利比4GB的内存使用较多。它所做的就是增加了二进制文件的大小,这实际上可以使code的慢的,如果它在缓存行为的影响。

x86-64 is a bit of a special case - for many architectures (eg. SPARC), compiling an application for 64 bit mode doesn't give it any benefit unless it can profitably use more than 4GB of memory. All it does is increase the size of the binary, which can actually make the code slower if it impacts on cache behaviour.

不过,X86-64为您提供的不仅仅是一个64位的地址空间和64位整数寄存器 - 它还双打通用寄存器的数量,这对像的x86寄存器缺陷架构可能导致显著的性能提升,只需重新编译。

However, x86-64 gives you more than just a 64 bit address space and 64 bit integer registers - it also doubles the number of general purpose registers, which on a register-deficient architecture like x86 can result in a significant performance increase, with just a recompile.

它也可以让编译器假设很多扩展,如SSE和SSE2,是present,也可以显著提高code优化。

It also lets the compiler assume that many extensions, like SSE and SSE2, are present, which can also significantly improve code optimisation.

的另一个好处是增加了x86-64的PC相对的寻址,从而可以简化显著位置无关code

Another benefit is that x86-64 adds PC-relative addressing, which can significantly simplify position-independent code.

但是,如果应用程序的性能并不敏感,那么这一切都不是非常重要的两种。

However, if the app isn't performance sensitive, then none of this is really important either.