CPU: Difference between revisions
Line 8: | Line 8: | ||
* [[Softcore]] - The CPU is implemented in an programmable logic, typically an [[FPGA]]. The implementation can be thus be changed and optimized for the particular purpose. Also multiple instances of the CPU can be implemented in a single FPGA. | * [[Softcore]] - The CPU is implemented in an programmable logic, typically an [[FPGA]]. The implementation can be thus be changed and optimized for the particular purpose. Also multiple instances of the CPU can be implemented in a single FPGA. | ||
A softcore is slower and needs more power than a comparable hardcore (factors can vary of course, but roughly 5 times slower and 5 times more energy for the same compute) | A softcore is slower and needs more power than a comparable hardcore (factors can vary of course, but roughly 5 times slower and 5 times more energy for the same compute) | ||
* [[VirtualCore]] - The CPU does not really exist, it is simulated on a host CPU (which can be a soft or hard core). | * [[virtual CPU | VirtualCore]] - The CPU does not really exist, it is simulated on a host CPU (which can be a soft or hard core). | ||
==CPU registers== | ==CPU registers== | ||
The CPU registers are the short-term memory inside of the CPU. They are easily accessed via instructions executed. Every CPU architecture has a different register design, and all have essential registers and some "work registers." | The CPU registers are the short-term memory inside of the CPU. They are easily accessed via instructions executed. Every CPU architecture has a different register design, and all have essential registers and some "work registers." |
Latest revision as of 17:55, 6 September 2025
CPU stands for Central Processing Unit, and this is basically the "brain" of a computer. CPUs can have multiple cores. Today, CPU cores are typically 32 bit or 64 bit.
For the sake of this article, we will refer to a single core as a CPU. A CPU has multiple CPU registers. A register is a CPU's internal storage, which can be just a single bit or as many as 32 bits or more.
CPU implementations
A CPU can be implemented in different ways:
- Hardcore - The CPU is implemented in silicon. This is the most common and also the traditional way. Delivers the highest performance and the lowest power consumption, but limited flexibility
- Softcore - The CPU is implemented in an programmable logic, typically an FPGA. The implementation can be thus be changed and optimized for the particular purpose. Also multiple instances of the CPU can be implemented in a single FPGA.
A softcore is slower and needs more power than a comparable hardcore (factors can vary of course, but roughly 5 times slower and 5 times more energy for the same compute)
- VirtualCore - The CPU does not really exist, it is simulated on a host CPU (which can be a soft or hard core).
CPU registers
The CPU registers are the short-term memory inside of the CPU. They are easily accessed via instructions executed. Every CPU architecture has a different register design, and all have essential registers and some "work registers."
Essential registers
All CPUs must have the following registers:
- PC — The program counter. This register contains the address of the next instruction to fetch and then execute.
- SP — Stack Pointer. Contains the address of the next item to push or pop. It typically expands downwards.
- SR — Status register. This register contains certain flags such as "carry," "zero," and other flags.
Work registers
Work registers are vastly different for different CPUs. In general, 8-bit CPUs tend to have 8-bit work registers, 16-bit CPUs have 16-bit work registers, and so on. In the 1970s, when silicon structures were huge and every transistor thus expensive, CPUs were 8 bit and had few registers. The 6502 is a good example of a relatively simple processor, with only three work registers: an 8-bit accumulator A, on which all arithmetic operations are performed, and two 8-bit index registers, called X and Y. Most of the old CPU designs had an accumulator, which was usually called A.
Later on, CPU designers learned that this design came with a disadvantage: If an arithmetic or logical operation needed to be performed on another register, its value needed to be transferred to the accumulator first (typically using something like a MOV A, Rx instruction) and after the operation moved back,(typically using a MOV Rx, A instruction). This affected the code density in a negative way, as a lot of transfers to and from the accumulators were needed.
Modern designs typically have a many general-purpose registers. In an architecture such as ARMv4, 16 such registers exist, and they are called R0, R1, ... R15. More registers give a CPU more performance, as it has more "short-term memory," so it can hold more parameters and variables in registers, where they can be easily and quickly accessed. This also why modern high-end processors have many registers (such as 31 for ARMv8-A, ARM's 64 bit architecture).
So, the upside of having many registers that are all equally accessible is high performance. The downside is that the instructions become wide, as in a lot of cases they need to specify two or even three registers (such as the two operand registers and the destination register). With 32 registers (or 31, with R0 not counted, as it has a constant value of 0), 5 bits are required to specify a register, so 15 bits are needed just to specify the registers.
In applications where code density is not very important, such as PCs and modern servers, this is a good choice, as program size is not particularly relevant, but performance is. In typical embedded systems, code density is important, as program memory (typically Flash memory) is limited.
Modern microcontrollers typically use CPUs with 16 general-purpose registers. ARM's Cortex-M ´microcontrollers have a Thumb-2 instruction set, which favors the lower 8 registers, in an effort to achieve high code density with just a small loss in performance.
CPU word size
CPU word size is not really clearly defined. A true 8-bit CPU will have 8-bit registers only, with the exception of the PC, which needs to be wider in order to not limit the program memory to just 256 bytes. An example of a true 8-bit CPU is the 6502.
The 8080 or Z80 processors are also considered 8-bit CPUs, even though many registers can be grouped and arithmetic operations can be performed on them—such as in add HL, BC. Older CPUs were usually accumulator centered, so they had registers that wer used for most arithmetic operations.
One way of determining the CPU's word size would be the size of the accumulator. Note that the size of the bus interface has nothing to do with the word size. The bus interface can even be 8 bits on a 32-bit CPU. Therefore, we would define the word size as the number of bits processed by a typical instruction.
In embedded systemss 8-bit, 16-bit, and 32-bit CPUs are widely used. Click computers for more information.