10

Why does ARM have only 16 registers? Is that the ideal number?

Does distance of registers with more registers also increase the processing time/power ?

1
  • its a case of 2, 3, 4, or 5 bits encoded in the instruction set, and what mix and flavor of instructions you can have for a fixed size instruction. 3 or 4 bits is somewhat optimal as we have seen from a number of instruction sets.
    – old_timer
    Mar 29, 2019 at 15:15

5 Answers 5

21

As the number of the general-purpose registers becomes smaller, you need to start using the stack for variables. Using the stack requires more instructions, so code size increases. Using the stack also increases the number of memory accesses, which hurts both performance and power usage. The trade off is that to represent more registers you need more bits in your instruction, and you need more room on the chip for the register file, which increases power requirements. You can see how differing register counts affects code size and the frequency of load/store instructions by compiling the same set of code with different numbers of registers. The result of that type of exercise can be seen in table 1 of this paper:

Extendable Instruction Set Computing

Register   Program   Load/Store  
Count      Size      Frequency  

27 100.00 27.90%
16 101.62 30.22%
8 114.76 44.45%

(They used 27 as a base because that is the number of GPRs available on a MIPS processor)

As you can see, there are only marginal improvements in both programs size and the number of load/stores required as you drop the register count down to 16. The real penalties don't kick in until you drop down to 8 registers. I suspect ARM designers felt that 16 registers was a kind of sweet spot when you were looking for the best performance per watt.

6
  • Are you saying more registers is better? ;) Oct 6, 2012 at 17:47
  • I would like to elaborate on stack and registers. If the number of registers are not sufficient then we need to use stack, but if we start using stack then there needs to memory read/write i.e. fetch/store for performing the operation. This will lead to more cycle for execution and will act as overhead. So there needs to be trade-off between stack and registers. Dec 12, 2013 at 13:11
  • 1
    If you only count real GPRs in MIPS like that then in ARM32 there's only 13 registers (R0-R12, minus SP, LR and PC) and x86 has 7 (minus SP, when omitting frame pointers). x86_64 has 15 and ARM64 has 31
    – phuclv
    Jan 23, 2015 at 6:22
  • If 16 is an ideal number then why should ARM64 increase it? The number is chosen based a lot of reasons and benchmarks
    – phuclv
    Jan 27, 2015 at 4:21
  • @Lưu Vĩnh Phúc - The first ARM processor was created in the mid 1980's and had a transistor count of around 30,000. At that point in time increasing the size of the register file to support 32 GPRs would have significantly increased both the cost and the power requirements without a commensurate benefit to code density. By the time the ARM64 was being designed there were already chips with over a billion of transistors, making the impact of increasing the register file size a non-issue. Jun 12, 2017 at 3:34
4

To choose one of 16 registers you would need 4bit therefore it could be that this is the best match for opcodes (machine commands) otherwise you would have to introduce a more complex instructions set, which would lead to bigger coder which implies additional costs (execution time).

Wikipedia says It has "Fixed instruction width of 32 bits to ease decoding and pipelining" so it is a reasonable tradeoff.

1
  • 1
    Yes, we want the instruction to fit into 32 bits, but you can divide those up however you like. For instance, if you have an ISA that can have two source registers and one dest register, you can specify those three registers with 15 bits, and then you have 17 left over for other stuff like opcodes and whatnot. Jun 25, 2015 at 20:50
4

32-bit ARM has 16 registers because it only use 4 bits for encoding the register, not because 16 is the ideal number. Likewise x86 has only 8 registers because in history they used 3 bits to encode the register so that some instructions fit in a byte.

That's such a limited number so both x86 and ARM when going to 64-bit doubled the number to 16 and 32 registers respectively. The old ARM instruction encoding has no remaining bit left enough for the larger register number so they must do a trade-off by dropping the ability to execute almost every instruction conditionally and use the 4-bit condition for the new features (that's an oversimplification, in reality it's not exactly like that because the encoding is new, but you do need 3 more bits for the new registers).

2

Back in the 80's (IIRC) an academic paper was published that examined a number of different workloads, comparing expected performance benefits of different numbers of registers. This was at a time when RISC processors were transitioning from academic ideas to mainstream hardware, and it was important to decide what was optimal. CPUs were already pulling ahead of memory in speed, and RISC was making this worse by limiting addressing modes and having separate load and store instructions. Having more registers meant you could "cache" more data for immediate access and therefore access main memory less.

Considering only powers of two, it was found that 32 registers was optimal, although 16 wasn't terribly far behind.

0

ARM is unique in that each of the registers can have a conditional execution code avoiding tests & branches. Don't forget, many 32 register machines fix R0 to 0 so conditional tests are done by comparing to R0. I know from experience. 20 years ago I had to program a 'Mode 7' (from SNES terminology) floor. The CPUs were SH2 for the 32x (or rather 2 of them), MIPS3000 (Playstation) and 3DO (ARM), the inner loop of the code were 19,15 & 11. If the 3DO had been running at the same speed as the other 2, it would have been twice as fast. As it was, it was just a bit slower.

1
  • 1
    Are those 19, 15, 11 numbers of instructions in the loop? How many registers do those different CPUs have? If you clarify that, then this might just barely work as an answer instead of an anecdote that should be a comment. Also, ARM predicated execution is per-instruction, not per-register. Number of registers is unrelated (other than the fact that they both consume bits in a 32-bit instruction word, as other answers point out.) Sep 3, 2016 at 11:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.