I am trying to implement a 4-way cache in verilog, but I have some confusions on a cache look up scenario. Say I have the following specs:
C = ABS
C = 1KB
A = 4
B = 128 bits (4 DWORD)
S = C/AB = (8192)/(4*128) = 16
offset = lg(B) = 7 bits
index = lg(S) = 4 bits
tag = 32 - offset - index = 21 bits
C: Capacity in data arrays
A: Way-Associativity
B: Block Size (Cacheline)
How many bytes in a block
S: Number of Sets:
A set contains blocks sharing the same index
And in my memory I have:
H 0000_0000 0000 0000 0000 0000 0000 0000 0|000 0|000 0000
E 0000_0004
L 0000_0008
L 0000_000C
O 0000_0010 0000 0000 0000 0000 0000 0000 0|000 0|001 0000
0000_0014
W 0000_0018
O 0000_001C
R 0000_0020 0000 0000 0000 0000 0000 0000 0|000 0|010 0000
L 0000_0024
D 0000_0028
! 0000_002C
Say I am on a fresh start and I request a load word at address 0x0000_0000, since my cache is empty, I will write HELL
to my cacheline on index 0 in one of the 4 array.
Then I request another load word at address 0x0000_0010, and I am confused at this point.
My question is that since my tag and index are the same, it is a hit, but my cacheline does not have the word O
in it. What should my cache do in this situation? Do I kick out HELL
and write O WO
in same array? If so how should I differentiate those two addresses since we are only looking at the tag and index bit?
The other way I was thinking is since it is a hit, the cache should not be evicted because we found a match. But that match does not have the actual word I am requesting. So this logic is wrong if I don't do a replacement, but my cache is a hit. And I just got into a looping-logic between evict and cache hit.