-1

We are given a processor whose instructions operate on 8 - byte operands and whose instructions are also encoded using 8 bytes. We are using a 16 kilo-byte, 4-way set associative cache that contains 1024 sets. The cache has 4 * 1024 = 4096 cache lines in total. That means, each cache line is 16KB=4096 = 4 bytes, so each operand and each instruction needs to be stored in two cache lines, which will require 2 accesses to the cache for each load/store operation and instruction fetches. We are told that the cache cannot apply spatial locality, but why? What does spatial locality mean in this context?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jannè
  • 3
  • 3

1 Answers1

1

So your machine doesn't have single byte loads/stores at all?

If every load is a full cache line (or multiple whole cache lines), then bringing a line into cache for one load will never benefit another load that's spatially nearby.

(Unless you have hardware prefetching to detect sequential accesses and start fetching adjacent cache lines...)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • No, the machine doesn't have single byte loads stores. Isn't the definition of spatial locality that "nearby data will be accessed in the near future"? – jannè Jun 28 '18 at 21:06
  • @jannè: yes. exactly. If your cache lines are so small that loading a value doesn't bring in any nearby values you didn't actually load, then spatial locality in your code doesn't help you. – Peter Cordes Jun 28 '18 at 23:28