Porting 32 bit C++ code to 64 bit - is it worth it? Why?

前端 未结 19 2741
攒了一身酷
攒了一身酷 2020-12-24 00:58

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

  • What if my program has no real need to run in nati
相关标签:
19条回答
  • 2020-12-24 01:51

    If you don't have any real need now, and likely never will, for 64-bit mode, you shouldn't do porting.

    If you don't have the need now, but may have it some day, you should try to estimate how much effort it will be (e.g. by turning on all respective compiler warnings, and attempting a 64-bit compilation). Expect that some things aren't trivial, so it will be useful to know how what problems you would likely encounter, and how long it would likely take to fix them.

    Notice that a need may also arise from dependencies: if your program is a library (e.g. a DLL), it may be necessary to port it to 64-bit mode just because some host application gets ported.

    For a foreseeable future, 32-bit applications will continue to be supported.

    0 讨论(0)
  • 2020-12-24 01:51

    See my answer to this question here. I closed out that post saying that a 64-bit computer can store and retrieve much more information than a 32-bit computer. For most users this really doesn't mean a whole lot because things like browsing the web, checking email and playing Solitaire all work comfortably within the confines of 32-bit addressing. Where the 64-bit benefit will really shine is in areas where you have a lot of data the computer will have to churn through. Digital signal processing, gigapixel photography and advanced 3D gaming are all areas where their massive amounts of data processing would see a big boost in a 64-bit environment.

    As for your code running faster/better, it's entirely up to your code and the requirements imposed on it.

    0 讨论(0)
  • 2020-12-24 01:53

    Some OSs or configurations are unable to run 32-bit programs. A minimal Linux without 32-bit libc installed for example. Also IIRC I usually compile out the 32-bit support from the kernel.

    If these OSs or configurations are part of your potential user base then yes, you should port it.

    If you need more speed, then you should also port it (as others have said, x86-64 has more registers and cool instructions that speed it up).

    Or, of course, if you want to mmap() or otherwise map a large file or lots of memory. Then 64-bit helps.

    0 讨论(0)
  • 2020-12-24 01:54

    Although its true that 32-bit will be around for a while in some form or another, Windows Server 2008 R2 ships with a 64-bit SKU only. I would not be surprised to see WOW64 as an install option as early as Windows 8 as more software migrates to 64-bit. WOW64 is a install, memory and performance overhead. The 3.5GB RAM limit in 32-bit Windows along with increasing RAM densities will encourage this migration. I'd rather have more RAM than CPU...

    Embrace 64-bit! Take the time to make your 32-bit code 64-bit compatible, its a no brainer and straightforward. For normal applications the changes are more accurately describes as code corrections. For drivers the choice is: adapt or lose users. When the time comes you'll be ready to deploy on any platform with a recompile.

    IMO the current cache related issues are moot; silicon improvements in this area and further 64-bit optimisation will be forthcoming.

    0 讨论(0)
  • 2020-12-24 01:54

    As to performance issues, it depends on your program actually. If your program is pointer-intensive, porting to 64-bit may cause performance downgrading, since for CPU cache with the same size, each 64-bit pointer occupy more space on cache, and virtual-to-physical mappings also occupies more TLB space. Otherwise, if your program is not pointer-intensive, its performance will benefit from x64.

    Of course performance is not the only reason for porting, other issues like porting effort, time scheduling should also be considered.

    0 讨论(0)
  • 2020-12-24 01:56

    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.

    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.

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

    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.

    0 讨论(0)
提交回复
热议问题