views:

146

answers:

3

Mason asked about the advantages of a 64-bit processor.

Well, an obvious disadvantage is that you have to move more bits around. And given that memory accesses are a serious issue these days[1], moving around twice as much memory for a fair number of operations can't be a good thing.

But how bad is the effect of this, really? And what makes up for it? Or should I be running all my small apps on 32-bit machines?

I should mention that I'm considering, in particular, the case where one has a choice of running 32- or 64-bit on the same machine, so in either mode the bandwidth to main memory is the same.

[1]: And even fifteen years ago, for that matter. I remember talk as far back as that about good cache behaviour, and also particularly that the Alpha CPUs that won all the benchmarks had a giant, for the time, 8 MB of L2 cache.

+2  A: 

I think you're starting off with a bad assumption here. You say:

moving around twice as much memory for a fair number of operations can't be a good thing

and the first question is ask is "why not"? In a true 64 bit machine, the data path is 64 bits wide, and so moving 64 bits takes exactly (to a first approximation) as many cycles as moving 32 bits on a 32 bit machine. So, if you need to move 128 bytes, it takes half as many cycles as it would take on a 32 bit machine.

Charlie Martin
Memory busses have been wider than 32-bits for far longer than processors have had 64-bit registers and address spaces. The real penalty of making apps 64-bit comes from having all the pointers and its be twice the size they need to be, effectively halving the cache size.
Yes, and what happens then? You have to latch the CPU multiple times to make use of the bus. Caches in 64 bit chips tend to be bigger as well; I'd like to see some empirical data to validate the notion that there's a real issue here.
Charlie Martin
I've edited the question. Consider the case of the same hardware where you have the choice of 32- or 64-bit mode. Memory bandwidth is the same. Only, in 32-bit mode you get twice as many ints loaded per cache line.
Curt Sampson
Okay, so now, like a good performance guy, I ask "okay, so what's your workload like"? IF your workload is such that having a high proportion of cache hits is good, AND you're not doing lots of floating point ops or moving to memory much, THEN you get some benefit. I rant about this regularly, but I'll hit it once here: what's your empirical evidence that realistic workloads are *negatively* impacted by 64 bit operation,and under what conditions does it happen?
Charlie Martin
That's not fair asking me to look at my workload! Next you'll be asking me to profile! :-)More seriously, I guess I'm looking to see if there are any rules of thumb in this area that, while obviously being nowhere near as important, one can use as we use big-O notation. And I think that there's no question these days that cache performance is always critical, given the latency differential in modern CPUs.But I think you might even be able to ask my question better than me; would you do so and drop me a note?
Curt Sampson
BTW, I don't see caches in 64-bit chips being bigger these days ("these days" being since the death of the Alpha and other high-end CPUs). My five-year-old 32-bit Pentium M has far more L2 cache than current I7s, and performs pretty respectably—for many applications, better than a faster Core 2 from the same era.
Curt Sampson
+8  A: 

Whether your app should be 64-bit depends a lot on what kind of computation it does. If you need to process very large data sets, you obviously need 64-bit pointers. If not, you need to know whether your app spends relatively more time doing arithmetic or memory accesses. On x86-64, the general purpose registers are not only twice as wide, there are twice as many and they are more "general purpose". This means that 64-bit code can have much better integer op performance. However, if your code doesn't need the extra register space, you'll probably see better performance by using smaller pointers and data, due to increased cache effectiveness. If your app is dominated by floating point operations, there probably isn't much point in making it 32-bit, because most of the memory accesses will be for wide vectors anyways, and having the extra SSE registers will help.

+3  A: 

Most 64-bit programming environments use the "LP64" model, meaning that only pointers and long int variables (if you're a C/C++ programmer) are 64 bits. Integers (ints) remain 32-bits unless you're in the "ILP64" model, which is fairly uncommon.

I only bring it up because most int variables aren't being used for size_t-like purposes--that is, they stay within ranges comfortably held by 32 bits. For variables of that nature, you'll never be able to tell the difference.

If you're doing numerical or data-heavy work with > 4GB of data, you'll need 64 bits anyways. If you're not, you won't notice the difference, unless you're in the habit of using longs where most would use ints.

Drew Hall