64-bit Performance Advantages
Asked Answered
S

6

16

What is the source of the performance advantage 64-bit applications have over 32-bit applications? I'm assuming there is a performance advantage because programs like WinRAR advertise it.

Also, can we get these performance advantages simply by switching to a 64-bit compiler, or are there any changes in code that need to be made?

Answers related to both, unmanaged and managed code, are welcome.

Stripe answered 27/7, 2010 at 12:56 Comment(0)
A
4

In order to take advantage of the 64 bit architecture of the latest CPU's you have to:

  • use a 64 bit CPU and OS
  • develop specifically for 64 bits using a 64 bit api - the implementation has to go all the way down to the most basic code working with the CPU registers (normally written in assembler) to take advantage of the extra registers.
  • develop an application that will really benefit from the extra registers - WinRAR is an application that will take full advantage of the extra registers because it involves a lot of calculus with complex algorithms. If you instead write an application with very simple algorithms, it will not require extra register address space and it will not work faster on 64 bit
  • take also into consideration that when you use a CPU register even if you don't use the the whole address space for a value, it will still take up as much space ( = 64bits).. therefore writing a small application in 64 bit aiming for getting a optimized code will just not work.. that app will take up twice the RAM than if it would be developed under 32 bit and it may be even slower. Programming in 64 bit makes sense for applications using heavy algorithms or that need to allocate huge pieces of memory (4Gb is the limit for a 32bit app).
Algorithm answered 27/7, 2010 at 20:34 Comment(4)
Why would the application take up twice as much RAM? Regarding register space, you can always use the higher and lower pieces of a 64 bit register separately. So judicious use of the registers should naturally solve that issue.Stripe
Yes, twice the amount of space is basically worst case scenario. But even so if you need to work with values much smaller than 32 bits like values represented on max 16 bits, you still waste half of the register space than if you would be working on a 32 bits CPU. And in general the bigger the registers the bigger the memory waste. Anyway imagining that you write your code in something else than assembler, you are to the mercy of the optimizations made by your compiler.. and there are cases when even an optimal compiler will make your code use double the memory needed in 32 bit architectureAlgorithm
@TripShock.. read here for further proof : en.wikipedia.org/wiki/64_bit#Pros_and_cons :)Algorithm
RAM usage will not be twice as much, because most integral types still have the same sizes. Only pointers are doubled. Moreover there are more registers in x86_64 which sometimes means less memory access is required => less cache missLament
R
17

The x64 architecture doubles the number of general purpose registers available in the x86 architecture, so that compilers are able to keep more data in (very fast) CPU registers rather than in (relatively slow) RAM.

Rockoon answered 27/7, 2010 at 13:17 Comment(2)
Extra registers is huge. Additional addressing modes can help (RIP). And these benefit all code with a simple recompile. x86 was had always been criticized for low register count.Purgative
actually it's more than double, because you have ESP/RSP which can't be used as general purpose, making the number of GPRs from 6 to 14 (7 to 15 if you don't use a frame pointer EBP)Lament
L
5

When did they stop lying in ads? Did I miss something? ;-)

The major performance advantage is that in 64bit systems, you can allocate more than 4GB of RAM (actually on most systems that's more 2GB) without swapping. That's a huge speed advantage if you need it.

So 64bit gives an advantage if you have applications that need lots of RAM (image/video/audio processing, world/universe simulations).

On top of that, the 64bit CPUs also have commands that operate on 64bit data types (so you don't need to emulate those with 32bit types). That's also an advantage but it's a) not that big because you the algorithms need to use those types and most don't b) they are still slower then 32bit types (but faster than the emulation).

To give you an idea, here is an old joke from a supercomputer guy: "It takes one day to load the data from disks, then the program takes five minutes to process the data and then we need another day to save the result to disk". Reading data from RAM is between 1000 and 1000000 times faster than an access to disk.

So all in all, for the average user, a 64bit system has little to no advantage.

Louvenialouver answered 27/7, 2010 at 13:3 Comment(8)
Your answer brings the second part of my question to the forefront...do we need to make changes in code to optimize for 64-bit? Because if using 64-bit data-types is the only change that needs to be made, we don't actually need to change code for that, because 64-bit compilers automatically convert types like int to 64-bit (because its size is bound to the word-size). But I've also read somewhere that changes to code are required for getting the full benefits of 64-bit...what changes exactly?Stripe
Most code uses a specific type size instead of plain int. Also, even on 64bit systems, int is usually 32 bit because such a lot of code depends on it being 32bit. long is another matter but there are compiler options to make it 32bit and long long 64bit. That said, what is the advantage of using a 64bit loop counter that is usually well below 100000?Louvenialouver
So my conclusion stands: If you have a specific problem (like wading through a lot of data) and you have an algorithm that can make use of huge types, then it matters. Think of fancy real time graphics manipulation for demos or games. Your OS won't get faster and it will need a lot more RAM (since every pointer is going to need twice as many bytes).Louvenialouver
Swapping or not depends solely on the amount of RAM. When you use more than is physically available it swaps. There are issues around using more than 4GB on 32bit, but swapping is not one of them.Purgative
In case of WinRar x64, there is a speed gain! Besides, if you ever programmed in assembler, you know that sometimes you need more registers than available, and then you have to use another register or to split out your algorithm. Having more registers, can sometimes improve performance, because the CPU can work more things out in a single cycle. Read here: en.wikipedia.org/wiki/CPU_registerAlgorithm
How much faster is WinRar x64 effectively? i.e. how much of the speed gain is swallowed by slower memory accesses?Louvenialouver
Why are memory accesses slower?Stripe
@TripShock: The number of address lanes on your mainboard doesn't change for a 64bit CPU -> memory accesses need twice as long because memory addresses must be transferred in two chunks.Louvenialouver
A
4

In order to take advantage of the 64 bit architecture of the latest CPU's you have to:

  • use a 64 bit CPU and OS
  • develop specifically for 64 bits using a 64 bit api - the implementation has to go all the way down to the most basic code working with the CPU registers (normally written in assembler) to take advantage of the extra registers.
  • develop an application that will really benefit from the extra registers - WinRAR is an application that will take full advantage of the extra registers because it involves a lot of calculus with complex algorithms. If you instead write an application with very simple algorithms, it will not require extra register address space and it will not work faster on 64 bit
  • take also into consideration that when you use a CPU register even if you don't use the the whole address space for a value, it will still take up as much space ( = 64bits).. therefore writing a small application in 64 bit aiming for getting a optimized code will just not work.. that app will take up twice the RAM than if it would be developed under 32 bit and it may be even slower. Programming in 64 bit makes sense for applications using heavy algorithms or that need to allocate huge pieces of memory (4Gb is the limit for a 32bit app).
Algorithm answered 27/7, 2010 at 20:34 Comment(4)
Why would the application take up twice as much RAM? Regarding register space, you can always use the higher and lower pieces of a 64 bit register separately. So judicious use of the registers should naturally solve that issue.Stripe
Yes, twice the amount of space is basically worst case scenario. But even so if you need to work with values much smaller than 32 bits like values represented on max 16 bits, you still waste half of the register space than if you would be working on a 32 bits CPU. And in general the bigger the registers the bigger the memory waste. Anyway imagining that you write your code in something else than assembler, you are to the mercy of the optimizations made by your compiler.. and there are cases when even an optimal compiler will make your code use double the memory needed in 32 bit architectureAlgorithm
@TripShock.. read here for further proof : en.wikipedia.org/wiki/64_bit#Pros_and_cons :)Algorithm
RAM usage will not be twice as much, because most integral types still have the same sizes. Only pointers are doubled. Moreover there are more registers in x86_64 which sometimes means less memory access is required => less cache missLament
C
2

Some great answers here.

As was said, you can access unlimited RAM, which will help performance if you need it.

I would humbly add that if you don't need it, but use it anyway, it will hurt performance.

Never lose sight of one of the oldest laws of science:

Nature Abhors a Vacuum

Chandachandal answered 27/7, 2010 at 16:56 Comment(2)
You can't access unlimited RAM.. there is a limit: en.wikipedia.org/wiki/64-bit#LimitationsAlgorithm
@John: You know what I meant.Chandachandal
M
1

My understanding is that in most circumstances, there is no performance gain as such, apart from the ability to use more memory. (Although it might give higher performance if you're working with 64-bit data types a lot, for example).

Misgiving answered 27/7, 2010 at 13:2 Comment(0)
G
0

Great answers all. Two things I didn't see mentioned:

  1. Drivers can allocate almost as much memory as there is physical memory. You can have a lot more memory in a 64-bit driver than in 32.
  2. You can use floating point operations inside 64-bit drivers (with few restrictions).
Galleon answered 30/7, 2023 at 17:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.