Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory Hierarchy - Why are registers expensive?

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)?

like image 875
ajdbnabad13 Avatar asked Sep 26 '14 08:09

ajdbnabad13


1 Answers

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.

like image 68
gnasher729 Avatar answered Oct 08 '22 02:10

gnasher729