-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcache_memory.v
More file actions
98 lines (72 loc) · 1.97 KB
/
cache_memory.v
File metadata and controls
98 lines (72 loc) · 1.97 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
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
`define BLOCKS 256
`define WORDS 16
`define SIZE 32
`define BLOCK_SIZE 512
module cache_memory(clk,address,read,dataIn,dataOut,hit);
input clk;
input [31:0] address;
input read;
input [`BLOCK_SIZE-1:0] dataIn;
output reg hit;
output reg [31:0] dataOut;
reg [`BLOCK_SIZE+20:0] buffer;
reg [7:0] index;
reg [3:0] blockOffset;
reg [`BLOCK_SIZE+20:0] cache [`BLOCKS-1:0];
always@(posedge clk)
begin
index = address[11:4];
blockOffset = address[3:0];
if(read == 0) begin
buffer[0] = 1;
buffer[20:1] = address[31:12];
buffer[532:21] = dataIn;
cache[index] = buffer;
dataOut = cache[index][32*blockOffset+21+31-:32];
hit = 1;
end
if(read == 1) begin
if(address[31:12] == cache[index][20:1]) begin
hit = 1;
end
else begin
hit = 0;
end
// hit = 0;
dataOut = cache[index][32*blockOffset+21+31-:32];
end
else begin
hit = 1;
end
end
endmodule
// input clk,
// input mode,
// input [7:0] index,
// input [3:0] blkOffset,
// input [19:0] tagin,
// input [`SIZE*`WORDS-1:0] datain,
// output reg [`SIZE-1:0] dataout,
// output reg [19:0] tagout,
// output reg valid
// );
// reg[`BLOCKS-1:0] cache [`WORDS*`SIZE+20:0];
// reg [532:0] out;
// always @(posedge clk)
// begin
// if(mode == 1)
// begin
// out[0] <= 1;
// out[20:1] <= tagin;
// out[532:21] <= datain;
// cache[index] <= out;
// end
// else
// begin
// out <= cache[index];
// valid <= out[0];
// dataout = out[32*(blkOffset)+:32];
// tagout <= out[20:1];
// end
// end
// endmodule