What is the difference between cache memory and registers?I know them by definition but why do we need the other when we have any one of them?
|
Registers are:
Cache is:
|
|||||||
|
|
to make it simple processor register are much faster than cache memory, and unlike cache memory that store data, the processor register store instructions that manipulate data, by instruction i mean (address , opcode, small chuck of data that we need to operate in ...). |
|||
|
|
Registers are controllable, you can store and retrieve information from them. There are very few of them (on x86 at least), but very fast. A lot of them have very particular uses (Instruction Pointer, Base Pointer, etc) and should not be used by the user. Cache is almost completely uncontrollable. You can invalidate it (INVD and WBINVD privileged instructions) but you cannot explicitly store or retrieve information from it. It is also placed between memory and the CPU, so you don't even know whether it's working or not, unless you do timing comparisons. It is intended to be completely transparent in operations. Also, they can be hierarchical and fairly large (comparatively to registers at least). |
|||
|
|
|
So I guess what you're wondering is, since it's all just stored bytes, why single some of them out as registers, and call the rest cache? Well, it's been a while since I programmed on the PIC but if I remember correctly the PIC does not distinguish between "memory" and "registers", and calls all of its memory "registers"; they all share an address space. Some of these are special purpose, for things like IO ports, but most are general purpose. Is this a good idea? Well it's obviously not a terrible one because the PIC is a reasonably successful microcontroller. But you can see that this would have limitations when you start scaling up to add more memory and a faster clock. (I am not an EE so take this with a grain of salt). The advantage to singling out a few particular registers is that they can be connected to fewer things: all the wires attaching to a circuit add capacitive loading which slows it down. On a modern machine with kilobytes of cache that would be a lot of loading for something you want to access basically every instruction. I imagine there might also cost advantages because you could make the registers out of wide, fast transistors, and then scale down for the cache which doesn't need to be as fast. |
|||
|
|