Docsity

CS61C Summer 2016 Discussion 8 - Caches: A Comprehensive Guide to Cache Memory Concepts, Lecture notes of Advanced Computer Architecture

Toggle sidebar
bg1
!
!
CS61C%Summer%2016%Discussion%8%–%Caches%
!
In!the!following!diagram,!each!blank!box!in!the!CPU!Cache!represents!8!bits!(1!byte)!of!data.!Our!
memory!is!byte-addressed,!meaning!that!there!is!one!address!for!each!byte.!Compare!this!to!word-
addressed,!which!means!that!there!is!one!address!for!each!word.!
!
Index!bits=log2!(Number!of!index!rows)! Offset!bits=log2!(Number!of!offsets! columns)!
!
Tag%bits%
Index%bits%
Offset%bits%
Total%
30%
0%
2%
32%
!
What!type!of!cache!is!this?!fully%associative%
!
!
Tag%bits%
Index%bits%
Offset%bits%
29%
1%
2%
!
!
!
!
What!type!of!cache!is!this?!2-way%set%associative%
!
!
Tag%bits%
Index%bits%
Offset%bits%
Total%
28%
2%
2%
32%
!
What!type!of!cache!is!this?!direct%mapped!
!
1. Direct%mapped%caches!
1. How!many!bytes!of!data!can!our!cache!hold?!16%bytes! How!many!words?!4%words
2. Fill!in!the!“Tag!bits,!Index!bits,!Offset!bits”!with!the!correct!T:I:O!breakdown!according!to!the
!
diagram.!
3. Let’s!say!we!have!a!8192KiB!cache!with!an!128B!block!size,!what!is!the!tag,!index,!and!offset
!
of!0xFEEDF00D?!
FE!
ED!
F0!
0D!
1111!1110
!
1110!1101
!
1111!0000
!
0000!1101
!
!
Tag:!111111101%(0x1FD)!!Index:!1101101111100000%(0xDBE0)%Offset:!0001101%(0x0D)
4. Fill!in!the!table!below.!Assume!we!have!a!write-through!cache,!so!the!number!of!bits!per!
row!includes!only!the!cache!data,!the!tag,!and!the!valid!bit.!
Address%size
%
(bits)!
!
Cache%size!
!
Block%size!
!
Tag%bits!
!
Index%bits!
!
Offset%bits!
!
Bits%per%row!
CPU%
Cache%
Offset%
3%
2%
1%
0%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
%
CPU%
Cache%
Index%
Number%
Offset%
3%
2%
1%
0%
0%
%
%
%
%
1%
%
%
%
%
CPU%
Cache%
Index%
Number%
Offset%
3%
2%
1%
0%
0%
%
%
%
%
1%
%
%
%
%
CPU%
Cache%
Index%
Number%
Offset%
3%
2%
1%
0%
0%
%
%
%
%
1%
%
%
%
%
2%
%
%
%
%
3%
%
%
%
%
pf3

Partial preview of the text

Download CS61C Summer 2016 Discussion 8 - Caches: A Comprehensive Guide to Cache Memory Concepts and more Lecture notes Advanced Computer Architecture in PDF only on Docsity!

CS61C Summer 2016 Discussion 8 – Caches

In the following diagram, each blank box in the CPU Cache represents 8 bits (1 byte) of data. Our

memory is byte-addressed, meaning that there is one address for each byte. Compare this to word-

addressed, which means that there is one address for each word.

Index bits=log 2

(Number of index rows) Offset bits=log 2

(Number of offsets columns)

Tag bits Index bits Offset bits Total

What type of cache is this? fully associative

Tag bits Index bits Offset bits Total

What type of cache is this? 2 - way set associative

Tag bits Index bits Offset bits Total

What type of cache is this? direct mapped

1. Direct mapped caches

  1. How many bytes of data can our cache hold? 16 bytes How many words? 4 words
  2. Fill in the “Tag bits, Index bits, Offset bits” with the correct T:I:O breakdown according to the

diagram.

  1. Let’s say we have a 8192KiB cache with an 128B block size, what is the tag, index, and offset

of 0xFEEDF00D?

FE ED F0 0D

Tag: 111111101 (0x1FD) Index: 1101101111100000 (0xDBE0) Offset: 0001101 (0x0D)

  1. Fill in the table below. Assume we have a write-through cache, so the number of bits per

row includes only the cache data, the tag, and the valid bit.

Address size

(bits) Cache size Block size Tag bits Index bits Offset bits Bits per row

CPU

Cache

Offset

CPU

Cache

Index

Number

Offset

CPU

Cache

Index

Number

Offset

CPU

Cache

Index

Number

Offset

16 4KiB 4B 4 10 2 3 2+4+

32 32KiB 16B

17 11 4 128+17+

64 KiB 16B 16 12 4 128+16+

64 2048KiB 128B 43 14 7 1068

2. Cache hits and misses

Assume we have the following cache. Of the 32 bits in each address, which bits do we use to find the

row of the cache to use? We use the 4

th

and 5

th

least significant bit since the offset is 3 bits

Classify each of the following byte memory accesses as a cache hit (H), cache miss (M), or cache miss

with replacement (R).

  1. 0x0000000 4 Index 0, Tag 0: M

  2. 0x0000000 5 Index 0, Tag 0: H

  3. 0x000000 68 Index 1, Tag 3: M

4.0x000000C8 Index 1, Tag 6: R

5 .0x000000 68 Index 1, Tag 3: R

  1. 0x000000DD Index 3, Tag 6: M

  2. 0x000000 45 Index 0, Tag 2: R

  3. 0x0000000 4 Index 0, Tag 0: R

  4. 0x000000C8 Index 1, Tag 6: R

3. Analyzing C Code

#define NUM_INTS 8192

int A[NUM_INTS]; /* A lives at 0x10000 0 */

int i, total = 0;

for (i = 0; i < NUM_INTS; i += 128) { A[i] = i; } /* Line 1 */

for (i = 0; i < NUM_INTS; i += 128) { total += A[i]; } /* Line 2 */

Let’s say you have a byte-addressed computer with a total memory of 1MiB. It features a 16KiB CPU

cache with 1KiB blocks.

  1. How many bits make up a memory address on this computer? 20
  2. What is the T:I:O breakdown? tag bits: 6 index bits: 4 offset bits: 10
  3. Calculate the cache hit rate for the line marked Line 1: 50%

The integer accesses are 4*128=512 bytes apart, which means there are 2 accesses per block.

The first accesses in each block is a cache miss, but the second is a hit because A[i] and

A[i+128] are in the same cache block.

  1. Calculate the cache hit rate for the line marked Line 2: 50%

The size of A is 8192*4 = 2

15

bytes. This is exactly twice the size of our cache. At the end of

line 1, we have the second half of A inside the cache, while in line 2 we start accesses from

C U

C h

Ind x

Numb

ffs t