Project Report On Verilog Implementation of Different Types of Caches
Project Report On Verilog Implementation of Different Types of Caches
TECHNOLOGY, BANGALORE
Project Report on
Verilog Implementation of Different
Types of Caches
Project members :
Swapnil Rawat(MT2019526)
1
Contents:
2
Design:
Memory Specification:
assumption:1 word =1 byte
(NOTE: Number of extra bits that will be required for associating tag, valid bit or/and lru with
each cache line will depend on the type of cache )
3
Direct Mapping Cache:
In Direct mapping, each memory block is assigned to a specific line in the
cache.
If a line is previously taken up by a memory block when a new block needs to
be loaded, the old block is trashed.
L0
L1
L2
L3
Formula to find which block from memory will go to which line number in cache
k mod n
4
6 4 3 2 1 0
Tag Line
Line no.
No. Block
Blockoffset
offset
Working:
Note: Write back policy is employed
cache write:
valid+tag match => s0
valid+tag dosen’t match =>write the memory with the current block => s2
not valid => s0
cache write:
write new word into the block read from memory
update the cache
goto s0
(note: memory still has old data and not has been updated. Memory will be updated only when
we replace the block from cache, since memory write is costly)
s2: make memory_write signal low and memory_read signal high to read new block from memory
for which cpu has sent the address
goto s1
5
K- way Set Associative Cache:
Instead of having exactly one line that a block can map to in the cache, we will
group a few lines together creating a SET. Then a block in memory can map to
any one of the lines of a specific set.
L0
L1
L2
S1
L3
Formula to find which block from memory will go to which block number in the
cache
k mod n
6
CPU to cache Address: 7 bits
6 3 2 1 0
Tag Line
Set No
no. Block
Blockoffset
offset
Working:
Note: Write through policy is employed
line1 valid + line2 valid + tag doesn’t match => check lru : line 1 is lru => s1
line 2 is lru => s2
line1 valid + line2 not valid + tag doesn’t match in line 1 => s2
line1 not valid + line2 valid + tag doesn’t match in line 2 => s1
7
Fully Associative Cache:
Any block can go into any line of the cache.
L0
L1
L3
L2
L3
L4
Mru
6 2 1 0
8
Working:
Note: Write through policy is employed
S0: line 0 valid + line1 valid + line 2 valid + line 3 valid + tag match => cache hit
find the line in which tag is matched and make that as mru
if read => s0
if write => s2
line 0 valid + line1 valid + line 2 valid + line 3 invalid + tag match => cache hit
find the line in which tag is matched and make that as mru
if read => s0
if write => s2
line 0 valid + line1 valid + line 2 invalid + line 3 invalid + tag match => cache hit
find the line in which tag is matched and make that as mru
if read => s0
if write => s2
line 0 valid + line1 invalid + line 2 invalid + line 3 invalid + tag match => cache hit
find the line in which tag is matched and make that as mru
if read => s0
if write => s2
line 0 valid + line1 valid + line 2 valid + line 3 valid + tag dosen’t match => cache miss
if read => s2
if write => s2
line 0 valid + line1 valid + line 2 valid + line 3 invalid + tag dosen’t match => cache miss
if read => s1
if write => s1
line 0 valid + line1 valid + line 2 invalid + line 3 invalid + tag dosen’t match => cache miss
if read => s1
if write => s1
line 0 valid + line1 invalid + line 2 invalid + line 3 invalid + tag dosen’t match => cache miss
if read => s1
if write => s1
line 0 invalid + line1 invalid + line 2 invalid + line 3 invalid + tag dosen’t match => cache
miss
if read => s1
if write => s1
9
s1: Read block from memory/ write word to the memory
10
Simulation Results:
Direct Mapping cache:
Fully Associative :
11
Conclusion:
All the three Caches i.e i ) Direct Mapping Cache
ii ) 2-way set Associative Cache
iii ) Fully-Associative Cache
are working fine and are showing the expected hits and misses.
12