-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cache.v
103 lines (84 loc) · 2.04 KB
/
Cache.v
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
`timescale 1ns / 1ps
module Cache
(
input [31:0] Address,
input [127:0] DataLine,
input clk,
output reg[31:0] Instruction,
output reg Hit
);
//wires and variables declaration
reg [153:0] Cache [7:0];
//reg [3:0] counter=0; //baraye 5 clk
integer i;
//address jadid
reg [1:0] offset;
reg [2:0] index;
reg [24:0] tag;
always@(Address) begin
offset = Address[3:2];
index = Address[6:4];
tag = Address[31:7];
end
//address vojood dare
always@(posedge clk) begin
//$display("in posedge");
//for(i=0;i<8;i=i+1)begin
//$display("Cache[i] = %b", Cache[i]);
//end
//$display("bala Hit = ",Hit);
if(Cache[index][153] == 1 && tag == Cache[index][152:128] && Address[1:0] == 2'b00) begin //valid bit and tag
//$display("Cache[index][153] == %d",Cache[index][153]);
Hit = 1;
if(offset == 0)begin
Instruction = Cache[index][31:0];
end
else if (offset == 1)begin
Instruction = Cache[index][63:32];
end
else if (offset == 2)begin
Instruction = Cache[index][95:64];
end
else if (offset == 3)begin
Instruction = Cache[index][127:96];
end
else begin
Hit = 0;
Instruction = 32'bx;
end
end
else begin
Hit = 0;
Instruction = 32'bx;
end
//$display("paiin Hit = ",Hit);
end
//address vojood nadare
always@(DataLine) begin
//for(i=0;i<8;i=i+1)begin
//$display("in Dataline Cache[i] = %b", Cache[i]);
//end
//$display("counter = %d",counter);
//$display("in dataline");
//if (counter < 5) begin
//counter = counter +1;
//end
//else if (counter == 5 && DataLine !== 128'bx ) begin
if(DataLine !== 128'bx ) begin
Cache[index][152:128] <= tag; //25bit
Cache[index][153] <= 1; //valid mikonim 1bit
// counter <= 0;
Cache[index][127:0] <= DataLine; // 128bit
//25+1+128 =154bits
end
end
//initialize valid bit Cache
initial begin
for (i = 0; i<8 ;i=i+1) begin
Cache[i] = 0;
end
//for(i=0;i<8;i=i+1)begin
//$display("Cache[i] = %b", Cache[i]);
//end
end
endmodule