0

I have been browsing stackoverflow could not really find a example regarding to this one. I understand the concept of Temporal and Spatial locality for data cache:

Temporarl locality: address revisited

Spatial locality: every x times memory access get a hit

But how does it look like in the mips code? Can anyone give concrete examples and show how it works?

nihulus
  • 1,475
  • 4
  • 24
  • 46

1 Answers1

2

Spatial and temporal localities are not related to a specific architecture, mips or another one. It is more a property of programs and on the way they are processed on a computer.

Temporal locality states that if you access a given memory location, it is very likely that the same location will be accessed a few time after.

Difficult to give a specific example, but the idea is that if, for instance, you modify a variable, there is a high probability that this variable will be used a few instructions after in the program. Of course, it is possible to find counter-examples, but most of the time when a computation is done and stored in a variable, it is because we will need later the result of this operation.

The definition that you give of spatial locality is incorrect. Spatial locality states that if an information in some memory location is required, it is very likely that other informations located in a nearby memory location will also be required some time after.

This property is due the fact that many constructs of programming languages correspond to data stored in consecutive memory locations. This includes :

  • elements of an array

  • fields of a struct

  • local variables that are in successive addresses in the stack

  • parameter of a function that are also close in the stack

Again, it is possible to find counter-examples, but if, for instance, one accesses the firt character of a string, it is probably to do some kind of computation, search or whatever on the string, and most of the time, the other chars of the string will also be accessed.

Alain Merigot
  • 10,667
  • 3
  • 18
  • 31