-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteModule.sv
More file actions
53 lines (40 loc) · 1.29 KB
/
writeModule.sv
File metadata and controls
53 lines (40 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module writeModule
#(
input Memory[255:0][15:0];
input hitmiss;
input reg[15:0] writedata;
input integer position;
);
//for read
if(hitmiss==1'b1) begin
integer a=//convert bit 6-4 to decimal
integer b=//convert way to decimal
integer c=//convert offset to decimal
//data <= dataInCache[a][b][c];
dataInCache[a][b][c]=writedata;
//LRU
Memory[a][b][c]=writedata;
end
else begin
//in this case, we will replace a block
//checking if dirty bit is 1
integer a=//convert bit 6-4 to decimal
integer b=//integer position
reg[13:0] temp=tagArrayInCache[a][b]; //check if the bit at postion 12 is 1
if(temp[12]==1'b1)
begin //dirty bit is set
integer a=//convert bit 6-4 to decimal
integer b=//convert way to decimal
integer addressToMemory= //convert 11-4 bit of previous address(stored in tag) to integer
for(integer i=0;i<16;i++){
Memory[addressToMemory][i]=dataInCache[a][b][i];//update in memory
}
tagArrayInCache[a][b][12];
end
integer addressFromMemory=// convert 11-4 bit of current tag(where we need to read from)
Memory[addressFromMemory]=writedata;
for(integer i=0;i<16;i++){
dataInCache[a][b][i]=Memory[addressFromMemory][i];
}
end
endmodule