How does direct mapped cache work?

前端 未结 4 1338
逝去的感伤
逝去的感伤 2020-12-12 15:01

I am taking a System Architecture course and I have trouble understanding how a direct mapped cache works.

I have looked in several places and they explain it in a d

4条回答
  •  不思量自难忘°
    2020-12-12 15:27

    Lets use an example. A 64 kilobyte cache, with 16 byte cache-lines has 4096 different cache lines.

    You need to break the address down into three different parts.

    1. The lowest bits are used to tell you the byte within a cache line when you get it back, this part isn't directly used in the cache lookup. (bits 0-3 in this example)
    2. The next bits are used to INDEX the cache. If you think of the cache as a big column of cache lines, the index bits tell you which row you need to look in for your data. (bits 4-15 in this example)
    3. All the other bits are TAG bits. These bits are stored in the tag store for the data you have stored in the cache, and we compare the corresponding bits of the cache request to what we have stored to figure out if the data we are cacheing are the data that are being requested.

    The number of bits you use for the index is log_base_2(number_of_cache_lines) [it's really the number of sets, but in a direct mapped cache, there are the same number of lines and sets]

提交回复
热议问题