8

I understand that:

Faster access time > More expensive

Slower access time > Less expensive

I also understand that registers are the top of the hierarchy, and have the fastest access time. What I am having a hard time researching is why it's so expensive? To my knowledge, registers are literally circuits built directly into the ALU. If they're literally built into the CPU (the ALU especially), what actually makes it the most expensive?

Is it the size (registers being the smallest, of course)?

ajdbnabad13
  • 355
  • 3
  • 11
  • 1
    Think addressing. They're close to the ALU, so we have minimal bus width for the register mux select. This is directly related to the instruction width, which can only choose a limited number of registers. If you had 1024 general purpose registers, you'd need 10 bits in the instruction to select each register. – Jonathon Reinhart Sep 26 '14 at 08:48
  • 1
    Also think about the clock. The more of something you have, the larger it is, which usually demands a slower clock frequency. This is why your RAM runs at a lower clock frequency than your CPU. – Jonathon Reinhart Sep 26 '14 at 08:50
  • 2
    Supply and demand. Registers are very scarce, so they are very expensive. L1 cache is scarce, but not as a register. L2 more abundant. RAM is plenty. Disk is abundant. S3 is infinite. The more abundant, the less expensive, but slower access. – Remus Rusanu Sep 26 '14 at 09:11

1 Answers1

14

Registers are very, very expensive because they have to be very, very fast and they need to be accessed from many places simultaneously.

For example if you have statements a = a + x; b = b + x; c = c + x; you have three instructions which all want to read the same register. So the register is not just the memory. There are also all the data paths that need to be in the processor so the same data from the register holding x can be sent to three instructions at the same time. And the data can go to many, many places. If you write double a = x; and x is an integer, then there must be a data path that sends the register x to the floating point unit. Or to a vector unit. And so on.

Then you have the problem that not only to you need to store the data, you also must make sure that it is available. If you write x = y + z; a = a + x; someone must keep track when the first instruction runs that the register holding x is not valid right now until the result of the addition is stored, and stop the second addition from running. That is super expensive.

So there is much more to building a register than just adding a bit of memory, and that needs to be paid for. And registers are so essential to the speed of the processor, that the most expensive and fastest technology is used to build them.

gnasher729
  • 51,477
  • 5
  • 75
  • 98