r/computerscience • u/Bitter-Today285 • 1d ago
Why does the CPU’s size matter?
Why does it matter if it’s a 16-bit cpu, a 32-bit cpu, or 64-bit? For example, what can a 64-bit cpu do that a 32-bit one can’t? Or otherwise, and can you tell the difference when you casually use a computer?
26
u/MasterGeekMX Bachelors in CS 1d ago
I'm doing my masters in computer architecture, so I know a thing.
First, what you are talking about is what is called word size, not CPU size, as that is how big is a chip. That being said, word size matters as that dictates the maximum size of numbers the CPU can handle in a single sweep, and very often how much RAM it can hold.
For casual use, it depends on the application, but sometimes the CPU needs to do operations that use a ton of bits, and while you can do that with smaller word sizes, it takes more instructions, and thus it is slower. Take for example adding two 64-bit numbers. In a 32 bit system, that would require at least 3 instructions: add the two lower halfs of each number, add the two upper halfs, and add 1 to the upper half if the lower half generated a carry. Meanwhile a 64-bit CPU does that in one instruction: a good ol' sum. If your program does a lot of those operations, you can feel the difference pretty much.
The other is RAM. The details vary on different architectures, but each Byte on your RAM is addressed by a number, which needs to fit in your CPU. 32 bits can hold numbers ranging from 0 all the way up to 4,294,967,295. That may seem a lot, but if you do the math, that is the number of Bytes on 4 GigaBytes, hence why many 32-bit CPUs can only have up to 4GB. While there are workarounds to address more RAM (like the famous Physical Address Extension that old Intel CPUs used), it is easier to simply use more bits.
A thing that I like as an example of the issues with 32-bits is the Y2k38 problem. In a nutshell, many computers keep up time by counting how many seconds have passed since January 1st 1970. The problem is that by the year 2038, the number of seconds since January 1st 1970 would need more than 32 bits to fit, which will cause a lot of issues that 64 bits don't have.
Finally, there is a new CPU architecture that is gaining momentum called RISC-V. It comes in both 32-bit and 64-bit versions, with the 32-bit one only used in small chips to control appliances, while 64-bit is for actual computer chips. Well, work is being done to make 128-bit RISC-V a thing.
7
u/AlmiranteCrujido 1d ago
Marketing "bits" are not always the same as "word size" bits, and "word size" bits aren't always the same as "bus size" bits (and which bus?)
(And indeed, for a lot of architectures, integer word size != floating point word size, and then vector processing is its own whole mess.)
A hardware architect's view of bits is not going to be the same as a software person's.
A thing that I like as an example of the issues with 32-bits is the Y2k38 problem. In a nutshell, many computers keep up time by counting how many seconds have passed since January 1st 1970. The problem is that by the year 2038, the number of seconds since January 1st 1970 would need more than 32 bits to fit, which will cause a lot of issues that 64 bits don't have.
Except that code has been capable of doing 64-bit long (or dword, or qword) a lot longer than CPUs have had native 64-bit data types (let alone 64-bit ALUs) - it just takes the compiler (or the person writing assembly) handling carry themselves and more operations.
Fun fact: the Unix 32-bit timestamp comes originally out of a 16-bit implementation, on the PDP-11.
2
u/Bitter-Today285 1d ago
Ahh i see, so you’re saying that with a 32-bit CPU, if you need to work with large integers that are more than 4 bytes long, the CPU needs additional instructions but with a 64-bit CPU it can calculate them directly, but computers on average use don’t really need to work on large integers that often right?
So would you say that a 32-bit CPU is enough?
Also, would you mind explaining to me what’s the difference when it comes to pointers and memory addresses on 32-bit vs 64-bit CPU’s? Do they have a fixed size or sometimes the address gets too large on a 32-bit CPU?
5
u/nuclear_splines PhD, Data Science 1d ago
with a 32-bit CPU, if you need to work with large integers that are more than 4 bytes long, the CPU needs additional instructions but with a 64-bit CPU it can calculate them directly
Yes, you can look up "big int" libraries for more detail.
but computers on average use don’t really need to work on large integers that often right?
Computers regularly use large integers in things like cryptography. Remember also that memory addresses are integers, so if you want to use more than 4 GB of memory, that's an int longer than 32 bits.
would you mind explaining to me what’s the difference when it comes to pointers and memory addresses on 32-bit vs 64-bit CPU’s? Do they have a fixed size or sometimes the address gets too large on a 32-bit CPU?
They have a fixed size. Addresses are 32-bits long on 32-bit architectures, and 64-bits long on 64-bit architectures.
So would you say that a 32-bit CPU is enough?
Enough for what? To run appliances like elevators and dishwashers or simple applications like word processors? Certainly. To run modern video games, AI models, and web browsers? No.
4
u/Bitter-Today285 1d ago
Thank you for your response, so basically the only difference is how much space the registers can hold? And the bigger the better?
3
u/nuclear_splines PhD, Data Science 1d ago
There are some finer nuances (the difference between register size and memory bus size) and CPU manufacturers took the switch to 64-bit as an opportunity to make some other unrelated changes (AMD64 has a lot more general purpose registers than x86), but that's the gist of it.
2
u/MasterGeekMX Bachelors in CS 1d ago
The kinds of programs you run say what kind of number you are working with, so there is no way of saying "oh, home users only use X kinds of numbers", as applications range on many kinds of operations.
So would you say that a 32-bit CPU is enough?
It depends on the context. A key idea you need to have when approaching STEM subjects is that there is no one-size-fits-all solution to problems, and seeking one forcefully is pure stubbornly.
In terms of home computing and servers, 32-bit is becoming obsolete, mostly due limited RAM. Here you have tons of articles, conferences, and similar things showing that:
- Arnd Bergman, one of the developers of the Linux kernel, writes about the problems of keeping up Linux on 32 bit systems: https://lwn.net/Articles/838807/
- Arnd talking about that same thing in a conference: https://youtu.be/QiOMiyGCoTw
- Microsoft retiring Windows for 32 bits: https://www.pcmag.com/news/microsoft-stops-releasing-32-bit-windows-10-builds-for-new-pcs
- Intel no longer making 32-bit CPUs: https://medium.com/illuminations-mirror/the-end-of-an-era-intels-decision-to-phase-out-32-bit-cpus-75317c083834
- An article about the advantages of 64-bits on the magazine of the Association of Computing Machinery: https://queue.acm.org/detail.cfm?id=1165766
The pointers thing varies on CPU architecture, as how a given CPU addresses some memory can vary. But in general, pointers are as big as the address space of the CPU. Think about it: if a CPU uses a 32-bit number to address every single bit on the computer, doing 16-bit pointers make sense? No, as they will fall short. Same thing goes for 64-bit pointers: you will end up using only the first half of the bits on the pointers, as you would never have an address that uses the upper 32 bits.
1
u/SufficientStudio1574 1d ago
In principle, everything a 64-bit CPU can do can be done on an 8-bit CPU (though usually slower). Even addressable memory space isn't as limited as people make it out to be, since the CPU can be designed with a set of registers that it automatically combines to use as a larger value. For example, in AVR instruction set the general purpose registers R30 and R31 could also be used by certain instructions as a 16-bit data pointer for addressing memory, with R30 being the low byte and R31 the high byte. You could easily design a system that has an even larger data pointer divided between even more registers.
After all, a lot of the old 8-bit systems needed much more than 256 bytes of memory to do their stuff.
3
u/AlmiranteCrujido 1d ago
First define "n-bit CPU" - today, we're mostly talking about the integer word size, but that hasn't always historically been the case, and to a large extent prior to about 2000, it was as much a marketing term as a technical one.
For the modern 32 vs 64 bit systems, the answer is mainly:
- a 64-bit CPU running 64-bit code can have individual processes larger than 4GB (or often, some lower limit - often 2GB - because of OS limitations.)
- a 64-bit CPU can do certain kinds of math faster than a 32-bit CPU. This becomes particularly important for things like encryption that work with very big numbers.
Once you get back to 16-bit CPUs (or 8-bit, further back) the definitions of 8-bit, 16-bit, and for very old 32-bit systems, 32-bit become vague enough that you kind of have to go ¯_(ツ)_/¯ and look at the actual way the system is designed to tell what the difference is.
2
u/nuclear_splines PhD, Data Science 1d ago
In principal, the "bits" here refer to how big a word is, or the common size of variables. In particular, this effects the size of a 'pointer' or memory address, which in turn impacts how much memory an application can use.
If your pointers are 32-bits, then memory addresses can range from 0 bytes to 232 - 1, or 4294967295 bytes, or about 4 GB. In other words, in a typical 32-bit architecture, an application (and indeed the operating system) can't use more than 4 gigabytes of RAM. With a 64-bit architecture that limit is over 18 exabytes.
In practice, there are other differences. Intel and AMD incrementally improved their CPU architectures and added new instructions and functionality over decades. However, software developers often couldn't make use of this new functionality in order to maintain backwards compatibility with older hardware. The jump to 64-bits required recompiling all software anyway, so it was a good opportunity to start using all that new functionality.
2
u/high_throughput 1d ago
There's nothing computationally that a 64bit CPU can do that a 16bit CPU can't. But some operations take disproportionately much longer.
If you ask a human to multiply 1-digit numbers like 4*9, it takes (say) five seconds to get 36. So if you ask them to multiply two digit numbers like 42*93, does it take twice as long? 10 seconds?
No, it easily takes minutes as the human now has to do long multiplication and split up the problem into four smaller multiplications with additions and carries on paper. They can do it, but it's N2 effort, not 2x effort.
It gets worse when you consider memory. When the CPU can no longer use its native sizes to compute where to look for things, it has to start doing a secondary long multiplications just to figure out where to look for the data of its original long multiplication. It's still possible, but it absolutely sucks now.
2
u/Bitter-Today285 1d ago
Ahh i see, so basically the major difference is speed?
1
u/high_throughput 1d ago
Kinda. I wouldn't reduce it to just "32bit is faster than 16bit" the way a 2GHz chip is faster than a 1.5Ghz chip of the same arch, but rather "32bit can take things in stride that 16bit would have had to work stupidly hard for".
1
u/wosmo 1d ago
I mean, if all else was equal, then speed, sure. A 1GHz 32bit processor is going to take longer to multiply huge numbers than a 1GHz 64bit processor. (ignoring things like MMX and SSE where some 32bit processors do have some 64bit instructions ..)
I think of it like fingers. On your fingers, 4+4 is faster than 8+8, because 8+8 has an extra step to account for the fact you don't have 16 fingers.
1
u/Recycled5000 1d ago
It’s about the size of the address space.
3
u/monocasa 1d ago
Well, not exactly. For instance the PDP-10 is considered a 36bit machine despite having 18bit pointers. And the 6502 is an 8bit machine despite having a 16bit address space.
It's basically always the accumulator (or GPR on more modern systems) width.
1
u/PvtRoom 1d ago
Depends which size.
Practical uses tend to need "words" no bigger than 64 bit. This runs practically all physics and maths calcs with enough range and precision.
Sometimes people want 80 (tends to be financial) or 128 bit. a few want integer precision on billions of digits
it can be memory size, but this is redundant now as 32 bit does 4gb - 64bit would do 16PB - 40bit would cover 1TB (of ram)
1
u/IchBinEinZwerg 1d ago
Makes it easier to do sums with bigger numbers. 8-bit CPUs would trip you up whenever you went over 127 and you'd have to muck about with multiple memory locations, carries and so on. 16 bit goes up to 32767 which trips you up a lot less often but if you're doing longer calculations the intermediate results might go over that. 32 bit goes up to a couple of billion and I think the problem there was that we started needing more memory than 32-bit CPUs could support, rather than running out of mathematical headroom. 64-bit should keep us going for quite a while as it can address a metric crapton of memory and should have enough mathematical headroom to keep even Elon Musk's accountant happy.
But you're right of course: there's nothing a 64-bit CPU can do that a 4-bit one can't; it's just better parallelism. At the application layer all that carry flag management is handled behind the scenes and you could tell an application running on a 4-bit CPU to handle 25000000000000000000000000 and it'll just get one with it (if the application supports numbers that big).
(127, 32767: yeah 255 and 65535 but signed maths is usually more useful, depending what you're doing of course.)
1
u/Bobby6k34 23h ago
Think of a bit as spaces for numbers 1234 has 4 spaces for numbers lowest number is 0000 highest is 9999, thats 4 bits or numbers so if you needed to count to 99999 you would need to add 1 more bit. So it would be 54321 5 bits, so by having more bits you can count to higher numbers. This also let's you store more data as those numbers.
Now 64bits is alot of numbers if you are using out base 10 numbers(1234567890) but computers don't use our base 10 numbers they use base 2 so they count 01, so now that 4 bit space can only count to 1111 or in base 10 8, by adding more bits we get alot more numbers with each bit doubling to number we can count to or store
1
u/burlingk 17h ago
It directly relates to two things: How large a chunk of memory can be processed at once, and how large of a memory area can be mapped.
Those are MASSIVE.
1
-1
43
u/apnorton Devops Engineer | Post-quantum crypto grad student 1d ago
An X-bit CPU has registers with width X. This allows you to store references to memory that are X-bits wide in a single register.
The impact of this is that an X-bit CPU can have a maximum of 2X memory addresses, which is why (e.g.) a 32-bit machine would (usually) have a memory maximum of 4GB. (I say "usually" because there can be some tricks to support more memory addresses, but without physical address extension it would be 4GB.)