Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 native 64 bit mode. Should I port it anyway?
  • Are there any foreseeable deadlines for ending 32 bit support?
  • Would my application run faster / better / more secure as native x64 code?
like image 881
NTDLS Avatar asked Sep 25 '09 23:09

NTDLS


People also ask

Why do people go from 32bit to 64bit?

Most computers released over the past two decades were built on a 32-bit architecture, hence most operating systems were designed to run on a 32-bit processor. A 64-bit register can theoretically reference 18,446,744,073,709,551,616 bytes, or 17,179,869,184 GB (16 exabytes) of memory.

Is it better to run 32-bit on 64-bit?

Can you run a 32-bit program on a 64-bit machine? To put it in simple words, if you run a 32-bit program on a 64-bit machine, it will work fine, and you won't encounter any problems. Backward compatibility is an important part when it comes to computer technology.

What is the advantage of a 64-bit address bus over a 32-bit bus?

There are 3 most obvious advantages of 64-bit processors over their 32-bit counterparts: extended address space, capacity increase, and larger number of general-purpose registers.

What is the significance of a 32-bit bus as opposed to a 64-bit bus?

A 32 bit architecture allows the arithmetic and logic unit (ALU), or digital circuit, to perform 32-bit integer arithmetic and logical operations. For architecture with 64-bits, it allows a 64-bit version of Windows to handle large amounts of RAM better than a 32-bit system.


1 Answers

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.

like image 76
caf Avatar answered Oct 03 '22 14:10

caf