views:

544

answers:

7

Hi,

I'm not sure I understand it properly: does a 64 bit OS run/compile code faster than a 32 bit OS on the same system?

We're using 64 bit OSs where I am and it seems to only cause compatibility issues with legacy and proprietary software. (We're running Ubuntu 9.04 Jaunty amd64)

+1  A: 

It will speed up compilation if your compile process is memory-bound and you use your 64bit OS to increase the amount of memory usable by your system.

jeffamaphone
+15  A: 

I will restrict this answer to x86-32 (IA-32) vs x86-64 (AMD64), as I believe that's the question you're actually asking.

At the processor level, there are a few advantages. First and most obvious is the expansion of the per-process virtual memory to a much wider range of 48 bits. (64 is allowed in the architecture but not required, if memory serves.) That enables applications to use a lot more of the system's memory available to them, as well as opening up a lot of space for things like memory mapped files that operate on virtual memory that isn't linked to real memory. It also opens up a lot of space for the OS in question to work, as it doesn't have to share your 4 GB limit for its data. In short, applications and the OS can make better use of your machine's resources.

Additionally, the AMD64 architecture addresses one of the biggest problems of IA-32, which is the utter lack of registers. In fact it doubles the available registers, which is a huge win for some types of code. (Actually it's a win for almost ANY code, but some applications suffer from the increased memory cost of 64 bits and it evens out.)

On the Windows side, MS has taken it as an opportunity to break a whole bunch of historical compability problems. It's not a clean break from the old world, but it's a start. I don't believe Linux suffers from the same problems to begin with, and I don't have much perspective to offer on their 64 bit advantages.

Promit
+6  A: 

(As the commentators note, this answer is somewhat generic, some of these points do not apply to intel/amd chips.)

The answer is: it varies, for a few reasons:

  • With larger-width instructions, you're going to get more expressiveness (either a greater variety of instructions or a greater capacity to encode data into those instructions directly), which can mean a reduced number of instructions flowing through the machine, which is generally a win: so ++64bit here.

  • But sometimes larger instructions might take more cycles to decode and execute, because they may be more complex. So a possible --64bit here.

  • Also, you need to transfer these instructions to and from the CPU: 64 bit instructions are twice as big as 32 bit instructions, which means more traffic to and from memory and the caches. CPUs are structured to ameliorate a lot of this cost, but it is a slight --64bit here.

  • More registers are usually available in wider instruction sets, which causes less data traffic to and from the stack and or memory. So ++64bit here.

  • And as everyone's no doubt going to mention, you have the ability to address more memory.

  • (Nearly forgot this one) the native "long" or "int" size may go up, depending on architecture, meaning data structures based on these get larger. Larger = more memory to move around, which means more possible waiting on data moving: --64bit if you're not careful.

Depending on your architecture, a lot of other concerns may apply too. You can rest assured that the processor and compiler vendors are working their butts off to reduce the "--"s above and increase the "++"s.

leander
Of course none of the first three points affect x86-based systems, since x86 provides a full variable length instruction encoding, with instructions anywhere between 1 and 17 bytes. Might even be more than 17 nowadays.
Promit
+9  A: 

As a general rule, developing--or using--a 64-bit operating system, in any context, will be slower than the same 32-bit operating system. Because all pointers are suddenly twice as large, you are far more likely to blow the cache, and can fit less data in RAM. That slows down your application considerably. You normally would only use 64-bit systems when your applications need to address more than 2 to 3 GB of data simultaneously--something very common in scientific computing and some database situations, but otherwise extremely rare. This is why Apple does not advocate unconditionally compiling PowerPC applications in 64-bit mode, for example: the cost due to cache-misses and lack of memory are high enough that going 64-bit only makes sense when you truly can take advantage of the 64-bit space.

But x86 v. AMD64, which is what you're really asking about (since you're discussing Ubuntu), is a very special beast. AMD64 not only extends all pointers to 64-bit; it fixes many, many deficiencies in the x86 architecture, doubling the number of GPRs, simplifying the instructions to be more friendly to modern CPU designs, and more. Because of this, on AMD64 platforms only, you will frequently see a substantial performance boost by going to 64-bit.

There is one other area where, in software development, it makes sense to go to 64-bit: you need to run lots of VMs. Running a couple of VMs can easily blow you past the 3 GB memory barrier of the operating system, making using them very painful. (It will work due to a technology called PAE, or Paged Addressing Extensions, that Intel invented to bridge the gap between 32-bit systems and 64-bit systems, but the result is slow, painful to work with as a developer, and not very well supported on Windows.) Going to a 64-bit OS can provide tremendous benefits.

Benjamin Pollack
This reflects what I've heard from people who measure performance for the living. The extra size of pointers and smaller number of cache hits really impacts performance. There is a small but noticeable hit running 64-bit apps.
Steve Rowe
The boundary is 2-3 GB depending on the OS, not 4. Remember, all major OSes take a 1 or 2 GB slice out of the top of your virtual space for their own use.As for PowerPC, the Power architecture has some bizarre quirks in 64 bit mode that make it faster to run in 32 bit mode. It's not just about pointer sizes.
Promit
@Promit You're of course correct on the boundaries; I've fixed those. Re. PowerPC tough, as much as I agree the architecture has "quirks," the situation was similar on SPARC v. UltraSPARC and 32-bit MIPS v. 64-bit MIPS. Hell, going the other way, it's why ARM has THUMB, MIPS has MIPS16e, and the Hitachi SuperH does surprisingly well: blowing the cache really does hurt.
Benjamin Pollack
Fair enough. I came from the game console world, and you forget eventually whether some particular quirk is IBM's fault, Sony's fault, Microsoft's fault, Nintendo's fault, or a blend of all four.
Promit
This also assumes your application won't benefit from native math on 64 bit values. Applications which use 64 bit values will be faster on x64.
Billy ONeal
@BillyONeal Using 64-bit math does not mean you have to run a 64-bit OS, which is what the initial poster was asking.
Benjamin Pollack
+3  A: 

I have this 5GByte database that needs converting. On a 64-bit system, I just put all data in collections. In the 32-bit system, I had to think about the order in which to load and convert. The problem is not run-time, it is engineering time. Switching to 64 bit saves weeks of development time.

The compatability issues: that's no bug, that's a feature. It shows you who has written clean software.

Stephan Eggermont
+2  A: 

There are also some security advantages to using 64-bit operating systems. There have been some buffer overflow exploits that circumvent address space layout randomization by brute force. On a 64-bit OS, there are simply too many addresses for this kind of attack to be successful.

Jason Baker
+1  A: 

I expect it to be slightly slower, I had that experience with FC10. I don't have real reasons, but it is definitely not the sizeof(pointer) issue. (*)

My own hunch is that it simply is a matter of less optimized drivers or tweaked chipsets.

Also NTFS-3g was funny under 64-bit, while it worked under 32-bit (same distro, same kernel same partition, it just "hung" in some circumstances)

(*) most compiling is disk bound, not CPU bound. Moreover there are other improvements in the x86_64 architecture that cancel out that fact (better PIC, more regs, SSE2 default on, 686 cmov default on) . Unless your app does nothing than randomly moving small blocks around.

Marco van de Voort