将 32 位 C++ 代码移植到 64 位 - 值得吗?为什么? [英] Porting 32 bit C++ code to 64 bit - is it worth it? Why?

查看:36
本文介绍了将 32 位 C++ 代码移植到 64 位 - 值得吗?为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 x64 架构的一些明显优势(更高的可寻址 RAM 地址等)...但是:

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

  • 如果我的程序不需要在本机 64 位模式下运行怎么办.我应该移植它吗?
  • 结束 32 位支持是否有可预见的截止日期?
  • 我的应用程序是否会像原生 x64 代码那样运行得更快/更好/更安全?

推荐答案

x86-64 是一个特殊情况 - 对于许多架构(例如 SPARC),为 64 位模式编译应用程序并没有给它任何除非它可以有利可图地使用超过 4GB 的内存.它所做的只是增加二进制文件的大小,如果它影响缓存行为,这实际上会使代码变慢.

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,这也可以显着改进代码优化.

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 相关的寻址,这可以显着简化与位置无关的代码.

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.

这篇关于将 32 位 C++ 代码移植到 64 位 - 值得吗?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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