1 |
2 |
gorand2 |
`include "config.v"
|
2 |
|
|
|
3 |
6 |
gorand2 |
module datacache(
|
4 |
|
|
input clk,
|
5 |
|
|
input stall,
|
6 |
|
|
input [4:0] stginhibit,
|
7 |
|
|
input [4:0] codemiss,
|
8 |
|
|
input [31:0] addrA,
|
9 |
|
|
output wire [511:0] dataA,
|
10 |
|
|
input [511:0] cacheLine,
|
11 |
|
|
input [31:0] writeData,
|
12 |
|
|
output wire cacheHit,
|
13 |
|
|
input readen,
|
14 |
|
|
input writeen,
|
15 |
|
|
input insert,
|
16 |
|
|
input initEntry,
|
17 |
|
|
input [1:0] readsz,
|
18 |
|
|
output wire [31:0] oldAddr);
|
19 |
2 |
gorand2 |
|
20 |
|
|
wire tagwe;
|
21 |
|
|
wire [31:0] tagAddrA;
|
22 |
|
|
wire [31:0] tagAddrW;
|
23 |
|
|
wire [119:0] tagDataA;
|
24 |
6 |
gorand2 |
wire [119:0] tagDataW;
|
25 |
2 |
gorand2 |
reg [31:0] tagAddrA_reg;
|
26 |
|
|
|
27 |
|
|
reg readen_reg=0;
|
28 |
|
|
reg writeen_reg=0;
|
29 |
|
|
reg insert_reg=0;
|
30 |
|
|
reg initEntry_reg=0;
|
31 |
|
|
reg [119:0] tagDataA_fwd;
|
32 |
|
|
wire [119:0] ramTagDataA;
|
33 |
|
|
reg tag_fwd=0;
|
34 |
|
|
|
35 |
|
|
wire [31:0] pad0;
|
36 |
|
|
wire [31:0] pad1;
|
37 |
|
|
wire [31:0] pad2;
|
38 |
|
|
wire [31:0] pad3;
|
39 |
|
|
wire [1:0] pos0;
|
40 |
|
|
wire [1:0] pos1;
|
41 |
|
|
wire [1:0] pos2;
|
42 |
|
|
wire [1:0] pos3;
|
43 |
|
|
wire val0;
|
44 |
|
|
wire val1;
|
45 |
|
|
wire val2;
|
46 |
|
|
wire val3;
|
47 |
|
|
wire dir0;
|
48 |
|
|
wire dir1;
|
49 |
|
|
wire dir2;
|
50 |
|
|
wire dir3;
|
51 |
|
|
|
52 |
|
|
wire [1:0] newPos0;
|
53 |
|
|
wire [1:0] newPos1;
|
54 |
|
|
wire [1:0] newPos2;
|
55 |
|
|
wire [1:0] newPos3;
|
56 |
|
|
|
57 |
6 |
gorand2 |
wire hit3,hit2,hit1,hit0;
|
58 |
2 |
gorand2 |
wire hit;
|
59 |
|
|
|
60 |
|
|
wire ram0We,ram1We,ram2We,ram3We;
|
61 |
|
|
wire [31:0] ramAddrW;
|
62 |
|
|
wire [31:0] ramAddrA;
|
63 |
|
|
wire [511:0] ramDataR0;
|
64 |
|
|
wire [511:0] ramDataR1;
|
65 |
|
|
wire [511:0] ramDataR2;
|
66 |
|
|
wire [511:0] ramDataR3;
|
67 |
|
|
wire [511:0] ramDataW0;
|
68 |
|
|
wire [511:0] ramDataW1;
|
69 |
|
|
wire [511:0] ramDataW2;
|
70 |
|
|
wire [511:0] ramDataW3;
|
71 |
|
|
wire [511:0] ramDataWA0;
|
72 |
|
|
wire [511:0] ramDataWA1;
|
73 |
|
|
wire [511:0] ramDataWA2;
|
74 |
|
|
wire [511:0] ramDataWA3;
|
75 |
|
|
reg [511:0] cacheLine_reg;
|
76 |
|
|
|
77 |
|
|
wire [31:0] dataA0;
|
78 |
|
|
wire [31:0] dataA1;
|
79 |
|
|
wire [31:0] dataA2;
|
80 |
|
|
wire [31:0] dataA3;
|
81 |
|
|
|
82 |
|
|
reg [1:0] readsz_reg;
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
datacacheramtag tag0(clk,tagwe,tagAddrA[11:6],tagAddrW[11:6],ramTagDataA,tagDataW);
|
86 |
|
|
datacache_get_new_pos newpos0(pos0,pos1,pos2,pos3,hit0,hit1,hit2,hit3,newPos0,newPos1,newPos2,newPos3);
|
87 |
|
|
datacacheramfwd ram0(clk,ram0We,ramAddrA,ramAddrW,ramDataR0,ramDataW0);
|
88 |
|
|
datacacheramfwd ram1(clk,ram1We,ramAddrA,ramAddrW,ramDataR1,ramDataW1);
|
89 |
|
|
datacacheramfwd ram2(clk,ram2We,ramAddrA,ramAddrW,ramDataR2,ramDataW2);
|
90 |
|
|
datacacheramfwd ram3(clk,ram3We,ramAddrA,ramAddrW,ramDataR3,ramDataW3);
|
91 |
|
|
datacache_data_sel data_sel0(ramDataR0,tagAddrA_reg[5:0],readsz_reg,dataA0);
|
92 |
|
|
datacache_data_sel data_sel1(ramDataR1,tagAddrA_reg[5:0],readsz_reg,dataA1);
|
93 |
|
|
datacache_data_sel data_sel2(ramDataR2,tagAddrA_reg[5:0],readsz_reg,dataA2);
|
94 |
|
|
datacache_data_sel data_sel3(ramDataR3,tagAddrA_reg[5:0],readsz_reg,dataA3);
|
95 |
|
|
datacache_get_write_data wrtdat0 (ramDataR0,writeData,tagAddrA_reg,readsz_reg,ramDataWA0);
|
96 |
|
|
datacache_get_write_data wrtdat1 (ramDataR1,writeData,tagAddrA_reg,readsz_reg,ramDataWA1);
|
97 |
|
|
datacache_get_write_data wrtdat2 (ramDataR2,writeData,tagAddrA_reg,readsz_reg,ramDataWA2);
|
98 |
|
|
datacache_get_write_data wrtdat3 (ramDataR3,writeData,tagAddrA_reg,readsz_reg,ramDataWA3);
|
99 |
|
|
|
100 |
|
|
assign tagAddrA=addrA;
|
101 |
|
|
assign tagDataA=tag_fwd ? tagDataA_fwd : ramTagDataA;
|
102 |
|
|
assign tagwe=((readen_reg || writeen_reg) && !stall && !stginhibit[4] && !codemiss[4] ) || insert_reg || initEntry_reg;
|
103 |
|
|
assign tagAddrW=tagAddrA_reg;
|
104 |
|
|
|
105 |
|
|
assign { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
106 |
|
|
pos3,pos2,pos1,pos0,
|
107 |
|
|
val3,val2,val1,val0,
|
108 |
|
|
dir3,dir2,dir1,dir0 } = tagDataA;
|
109 |
|
|
assign pad3[5:0]=6'b0;
|
110 |
|
|
assign pad2[5:0]=6'b0;
|
111 |
|
|
assign pad1[5:0]=6'b0;
|
112 |
|
|
assign pad0[5:0]=6'b0;
|
113 |
|
|
|
114 |
6 |
gorand2 |
assign hit3=(readen_reg || writeen_reg) ? val3 && (pad3[31:6]==tagAddrA_reg[31:6]) : 1'bz;
|
115 |
|
|
assign hit2=(readen_reg || writeen_reg) ? val2 && (pad2[31:6]==tagAddrA_reg[31:6]) : 1'bz;
|
116 |
|
|
assign hit1=(readen_reg || writeen_reg) ? val1 && (pad1[31:6]==tagAddrA_reg[31:6]) : 1'bz;
|
117 |
|
|
assign hit0=(readen_reg || writeen_reg) ? val0 && (pad0[31:6]==tagAddrA_reg[31:6]) : 1'bz;
|
118 |
2 |
gorand2 |
|
119 |
6 |
gorand2 |
assign hit3=insert_reg ? (pos3==2'b11) : 1'bz;
|
120 |
|
|
assign hit2=insert_reg ? (pos2==2'b11) : 1'bz;
|
121 |
|
|
assign hit1=insert_reg ? (pos1==2'b11) : 1'bz;
|
122 |
|
|
assign hit0=insert_reg ? (pos0==2'b11) : 1'bz;
|
123 |
2 |
gorand2 |
|
124 |
6 |
gorand2 |
assign hit3=(!insert_reg && !readen_reg && !writeen_reg) ? 1'b0 : 1'bz;
|
125 |
|
|
assign hit2=(!insert_reg && !readen_reg && !writeen_reg) ? 1'b0 : 1'bz;
|
126 |
|
|
assign hit1=(!insert_reg && !readen_reg && !writeen_reg) ? 1'b0 : 1'bz;
|
127 |
|
|
assign hit0=(!insert_reg && !readen_reg && !writeen_reg) ? 1'b0 : 1'bz;
|
128 |
2 |
gorand2 |
|
129 |
|
|
assign hit=hit3 || hit2 || hit1 || hit0;
|
130 |
|
|
|
131 |
6 |
gorand2 |
assign cacheHit= (insert_reg && hit0) ? val0 && dir0 : 1'bz;
|
132 |
|
|
assign cacheHit= (insert_reg && hit1) ? val1 && dir1 : 1'bz;
|
133 |
|
|
assign cacheHit= (insert_reg && hit2) ? val2 && dir2 : 1'bz;
|
134 |
|
|
assign cacheHit= (insert_reg && hit3) ? val3 && dir3 : 1'bz;
|
135 |
|
|
assign cacheHit= insert_reg ? 1'bz : hit;
|
136 |
2 |
gorand2 |
|
137 |
|
|
assign tagDataW=readen_reg ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
138 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
139 |
|
|
val3,val2,val1,val0,
|
140 |
6 |
gorand2 |
dir3,dir2,dir1,dir0 } : 120'bz;
|
141 |
2 |
gorand2 |
assign tagDataW=(writeen_reg && hit0) ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
142 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
143 |
|
|
val3,val2,val1,val0,
|
144 |
6 |
gorand2 |
dir3,dir2,dir1,1'b1 } : 120'bz;
|
145 |
2 |
gorand2 |
assign tagDataW=(writeen_reg && hit1) ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
146 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
147 |
|
|
val3,val2,val1,val0,
|
148 |
6 |
gorand2 |
dir3,dir2,1'b1,dir0 } : 120'bz;
|
149 |
2 |
gorand2 |
assign tagDataW=(writeen_reg && hit2) ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
150 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
151 |
|
|
val3,val2,val1,val0,
|
152 |
6 |
gorand2 |
dir3,1'b1,dir1,dir0 } : 120'bz;
|
153 |
2 |
gorand2 |
assign tagDataW=(writeen_reg && hit3) ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
154 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
155 |
|
|
val3,val2,val1,val0,
|
156 |
6 |
gorand2 |
1'b1,dir2,dir1,dir0 } : 120'bz;
|
157 |
2 |
gorand2 |
assign tagDataW=(writeen_reg && !hit) ? { pad3[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
158 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
159 |
|
|
val3,val2,val1,val0,
|
160 |
6 |
gorand2 |
dir3,dir2,dir1,dir0 } : 120'bz;
|
161 |
2 |
gorand2 |
|
162 |
|
|
assign tagDataW=(insert_reg && hit0) ? { pad3[31:6],pad2[31:6],pad1[31:6],tagAddrA_reg[31:6],
|
163 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
164 |
|
|
val3,val2,val1,1'b1,
|
165 |
6 |
gorand2 |
dir3,dir2,dir1,1'b0 } : 120'bz;
|
166 |
2 |
gorand2 |
assign tagDataW=(insert_reg && hit1) ? { pad3[31:6],pad2[31:6],tagAddrA_reg[31:6],pad0[31:6],
|
167 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
168 |
|
|
val3,val2,1'b1,val0,
|
169 |
6 |
gorand2 |
dir3,dir2,1'b0,dir0 } : 120'bz;
|
170 |
2 |
gorand2 |
assign tagDataW=(insert_reg && hit2) ? { pad3[31:6],tagAddrA_reg[31:6],pad1[31:6],pad0[31:6],
|
171 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
172 |
|
|
val3,1'b1,val1,val0,
|
173 |
6 |
gorand2 |
dir3,1'b0,dir1,dir0 } : 120'bz;
|
174 |
2 |
gorand2 |
assign tagDataW=(insert_reg && hit3) ? { tagAddrA_reg[31:6],pad2[31:6],pad1[31:6],pad0[31:6],
|
175 |
|
|
newPos3,newPos2,newPos1,newPos0,
|
176 |
|
|
1'b1,val2,val1,val0,
|
177 |
6 |
gorand2 |
1'b0,dir2,dir1,dir0 } : 120'bz;
|
178 |
2 |
gorand2 |
// assign tagDataW=(insert_reg && !hit) ? 120'b0 : 120'bz;
|
179 |
|
|
assign tagDataW=initEntry_reg ? { 26'b0,26'b0,26'b0,26'b0,
|
180 |
|
|
2'b11,2'b10,2'b01,2'b00,
|
181 |
|
|
1'b0,1'b0,1'b0,1'b0,
|
182 |
6 |
gorand2 |
1'b0,1'b0,1'b0,1'b0} : 120'bz;
|
183 |
|
|
assign tagDataW=(!insert_reg && !readen_reg && !writeen_reg && !initEntry_reg) ? 120'b0 : 120'bz;
|
184 |
2 |
gorand2 |
|
185 |
6 |
gorand2 |
assign dataA=(!insert_reg && hit0) ? {480'b0,dataA0} : 512'bz;
|
186 |
|
|
assign dataA=(!insert_reg && hit1) ? {480'b0,dataA1} : 512'bz;
|
187 |
|
|
assign dataA=(!insert_reg && hit2) ? {480'b0,dataA2} : 512'bz;
|
188 |
2 |
gorand2 |
|
189 |
6 |
gorand2 |
assign dataA=(!insert_reg && hit3) ? {480'b0,dataA3} : 512'bz;
|
190 |
2 |
gorand2 |
|
191 |
6 |
gorand2 |
assign dataA=(insert_reg && hit0) ? ramDataR0 : 512'bz;
|
192 |
2 |
gorand2 |
|
193 |
6 |
gorand2 |
assign dataA=(insert_reg && hit1) ? ramDataR1 : 512'bz;
|
194 |
|
|
assign dataA=(insert_reg && hit2) ? ramDataR2 : 512'bz;
|
195 |
|
|
assign dataA=(insert_reg && hit3) ? ramDataR3 : 512'bz;
|
196 |
2 |
gorand2 |
|
197 |
6 |
gorand2 |
assign dataA= hit ? 512'bz : 512'b0; //change to accomodate non-read ops
|
198 |
2 |
gorand2 |
|
199 |
|
|
assign ramDataW0=insert_reg ? cacheLine_reg : ramDataWA0;
|
200 |
|
|
assign ramDataW1=insert_reg ? cacheLine_reg : ramDataWA1;
|
201 |
|
|
assign ramDataW2=insert_reg ? cacheLine_reg : ramDataWA2;
|
202 |
|
|
assign ramDataW3=insert_reg ? cacheLine_reg : ramDataWA3;
|
203 |
|
|
|
204 |
|
|
assign ram0We=(insert_reg || (writeen_reg && !stall && !codemiss[4] && !stginhibit[4])) && hit0;
|
205 |
|
|
assign ram1We=(insert_reg || (writeen_reg && !stall && !codemiss[4] && !stginhibit[4])) && hit1;
|
206 |
|
|
assign ram2We=(insert_reg || (writeen_reg && !stall && !codemiss[4] && !stginhibit[4])) && hit2;
|
207 |
|
|
assign ram3We=(insert_reg || (writeen_reg && !stall && !codemiss[4] && !stginhibit[4])) && hit3;
|
208 |
|
|
|
209 |
6 |
gorand2 |
assign oldAddr=(insert_reg && hit0) ? pad0 : 32'bz;
|
210 |
|
|
assign oldAddr=(insert_reg && hit1) ? pad1 : 32'bz;
|
211 |
|
|
assign oldAddr=(insert_reg && hit2) ? pad2 : 32'bz;
|
212 |
|
|
assign oldAddr=(insert_reg && hit3) ? pad3 : 32'bz;
|
213 |
|
|
assign oldAddr=(!insert_reg) ? 32'b0 : 32'bz;
|
214 |
2 |
gorand2 |
|
215 |
|
|
assign ramAddrA={tagAddrA[31:6],6'b0};
|
216 |
|
|
assign ramAddrW={tagAddrA_reg[31:6],6'b0};
|
217 |
|
|
|
218 |
|
|
always @(posedge clk)
|
219 |
|
|
begin
|
220 |
|
|
tagDataA_fwd<=tagDataW;
|
221 |
|
|
tag_fwd<=tagwe && (addrA[11:6]==tagAddrA_reg[11:6]);
|
222 |
|
|
tagAddrA_reg<=tagAddrA;
|
223 |
|
|
readen_reg<=readen;
|
224 |
|
|
writeen_reg<=writeen;
|
225 |
|
|
insert_reg<=insert;
|
226 |
|
|
initEntry_reg<=initEntry;
|
227 |
|
|
cacheLine_reg<=cacheLine;
|
228 |
|
|
readsz_reg<=readsz;
|
229 |
|
|
end
|
230 |
|
|
|
231 |
|
|
endmodule
|
232 |
|
|
|
233 |
|
|
module datacacheram(input clk,input we,input [5:0] addrA,input [5:0] addrW,output reg [511:0] dataA,input [511:0] dataW);
|
234 |
|
|
reg [511:0] ram [63:0];
|
235 |
|
|
|
236 |
|
|
always @(posedge clk)
|
237 |
|
|
begin
|
238 |
|
|
dataA<=ram[addrA];
|
239 |
|
|
if (we) ram[addrW]<=dataW;
|
240 |
|
|
end
|
241 |
|
|
|
242 |
|
|
endmodule
|
243 |
|
|
|
244 |
|
|
module datacacheramfwd(input clk,input we,input [31:0] addrA,input [31:0] addrW,output wire [511:0] dataA,input [511:0] dataW);
|
245 |
|
|
wire [511:0] ramDataA;
|
246 |
|
|
reg we_reg;
|
247 |
|
|
reg [511:0] dataW_reg;
|
248 |
|
|
reg [31:0] addrW_reg;
|
249 |
|
|
reg fwd=0;
|
250 |
|
|
|
251 |
|
|
datacacheram ram0(clk,we,addrA[11:6],addrW[11:6],ramDataA,dataW);
|
252 |
|
|
|
253 |
|
|
|
254 |
|
|
assign dataA=fwd ? dataW_reg : ramDataA;
|
255 |
|
|
|
256 |
|
|
always@(posedge clk)
|
257 |
|
|
begin
|
258 |
|
|
we_reg<=we;
|
259 |
|
|
dataW_reg<=dataW;
|
260 |
|
|
addrW_reg<=addrW;
|
261 |
|
|
fwd<=we && (addrW[11:6]==addrA[11:6]);
|
262 |
|
|
end
|
263 |
|
|
|
264 |
|
|
endmodule
|
265 |
|
|
|
266 |
|
|
/*
|
267 |
|
|
tag for 4 way set-asociative LRU data cache
|
268 |
|
|
{
|
269 |
|
|
{pad3,pad2,pad1,pad0}, //4x 26 bit physical address
|
270 |
|
|
{pos3,pos2,pos1,pos0}, //4xeach 2 bit LRU position, 8 bit
|
271 |
|
|
{val3,val2,val1,val0} //4x 1 bit valid entry, 4 bit
|
272 |
|
|
{dir3,dir2,dir1,dir0} //4x dirty bit
|
273 |
|
|
}
|
274 |
|
|
length =30*4=120 bit tag
|
275 |
|
|
*/
|
276 |
|
|
|
277 |
|
|
module datacacheramtag(input clk,input we,input [5:0] addrA,input [5:0] addrW,output reg [119:0] dataA,input [119:0] dataW);
|
278 |
|
|
reg [119:0] ram [63:0];
|
279 |
|
|
|
280 |
|
|
always @(posedge clk)
|
281 |
|
|
begin
|
282 |
|
|
dataA<=ram[addrA];
|
283 |
|
|
if (we) ram[addrW]<=dataW;
|
284 |
|
|
end
|
285 |
|
|
|
286 |
|
|
endmodule
|
287 |
|
|
|
288 |
|
|
module datacache_get_new_pos(input [1:0] pos0,input [1:0] pos1,input [1:0] pos2,input [1:0] pos3,
|
289 |
|
|
input hit0,input hit1,input hit2,input hit3,
|
290 |
6 |
gorand2 |
output wire [1:0] newPos0,output wire [1:0] newPos1,output wire [1:0] newPos2,output wire [1:0] newPos3);
|
291 |
2 |
gorand2 |
wire hit;
|
292 |
|
|
|
293 |
|
|
assign hit=hit0 || hit1 || hit2 || hit3;
|
294 |
|
|
|
295 |
6 |
gorand2 |
assign newPos0=hit0 ? 0 : 2'bz;
|
296 |
|
|
assign newPos1=hit0 ? ((pos1<pos0) ? pos1+1:pos1 ) : 2'bz;
|
297 |
|
|
assign newPos2=hit0 ? ((pos2<pos0) ? pos2+1:pos2 ) : 2'bz;
|
298 |
|
|
assign newPos3=hit0 ? ((pos3<pos0) ? pos3+1:pos3 ) : 2'bz;
|
299 |
2 |
gorand2 |
|
300 |
6 |
gorand2 |
assign newPos1=hit1 ? 0 : 2'bz;
|
301 |
|
|
assign newPos0=hit1 ? ((pos0<pos1) ? pos0+1:pos0 ) : 2'bz;
|
302 |
|
|
assign newPos2=hit1 ? ((pos2<pos1) ? pos2+1:pos2 ) : 2'bz;
|
303 |
|
|
assign newPos3=hit1 ? ((pos3<pos1) ? pos3+1:pos3 ) : 2'bz;
|
304 |
2 |
gorand2 |
|
305 |
6 |
gorand2 |
assign newPos2=hit2 ? 0 : 2'bz;
|
306 |
|
|
assign newPos1=hit2 ? ((pos1<pos2) ? pos1+1:pos1 ) : 2'bz;
|
307 |
|
|
assign newPos0=hit2 ? ((pos0<pos2) ? pos0+1:pos0 ) : 2'bz;
|
308 |
|
|
assign newPos3=hit2 ? ((pos3<pos2) ? pos3+1:pos3 ) : 2'bz;
|
309 |
2 |
gorand2 |
|
310 |
6 |
gorand2 |
assign newPos3=hit3 ? 0 : 2'bz;
|
311 |
|
|
assign newPos1=hit3 ? ((pos1<pos3) ? pos1+1:pos1 ) : 2'bz;
|
312 |
|
|
assign newPos2=hit3 ? ((pos2<pos3) ? pos2+1:pos2 ) : 2'bz;
|
313 |
|
|
assign newPos0=hit3 ? ((pos0<pos3) ? pos0+1:pos0 ) : 2'bz;
|
314 |
2 |
gorand2 |
|
315 |
6 |
gorand2 |
assign newPos0=hit ? 2'bz : pos0;
|
316 |
|
|
assign newPos1=hit ? 2'bz : pos1;
|
317 |
|
|
assign newPos2=hit ? 2'bz : pos2;
|
318 |
|
|
assign newPos3=hit ? 2'bz : pos3;
|
319 |
2 |
gorand2 |
|
320 |
|
|
endmodule
|
321 |
|
|
|
322 |
|
|
|
323 |
6 |
gorand2 |
module datacache_data_sel(input [511:0] dataIn,input [5:0] sel, input [1:0] readsz, output wire [31:0] dataOut);
|
324 |
2 |
gorand2 |
wire [255:0] bit5Data;
|
325 |
|
|
wire [127:0] bit4Data;
|
326 |
|
|
wire [63:0] bit3Data;
|
327 |
|
|
wire [31:0] data32;
|
328 |
|
|
wire [15:0] data16;
|
329 |
|
|
wire [7:0] data8;
|
330 |
|
|
|
331 |
|
|
assign bit5Data=sel[5] ? dataIn[511:256] : dataIn[255:0];
|
332 |
|
|
assign bit4Data=sel[4] ? bit5Data[255:128] : bit5Data[127:0];
|
333 |
|
|
assign bit3Data=sel[3] ? bit4Data[127:64] : bit4Data[63:0];
|
334 |
|
|
|
335 |
|
|
assign data32 =sel[2] ? bit3Data[63:32] : bit3Data[31:0];
|
336 |
|
|
assign data16 =sel[1] ? data32[31:16] : data32[15:0];
|
337 |
|
|
assign data8 =sel[0] ? data16[15:8] : data16[7:0];
|
338 |
|
|
|
339 |
6 |
gorand2 |
assign dataOut=(readsz==0) ? {24'b0,data8} : 32'bz;
|
340 |
|
|
assign dataOut=(readsz==1) ? {16'b0,data16} : 32'bz;
|
341 |
|
|
assign dataOut=(readsz==2) ? data32 : 32'bz;
|
342 |
|
|
assign dataOut=(readsz==4) ? 32'b0 : 32'bz;
|
343 |
2 |
gorand2 |
|
344 |
|
|
endmodule
|
345 |
|
|
|
346 |
|
|
|
347 |
|
|
module datacache_write_shift(input [31:0] dataIn,input [1:0] writesz,input [31:0] addr, output wire [511:0] dataOut, output wire [63:0] byteEnable);
|
348 |
6 |
gorand2 |
wire [511:0] data6;
|
349 |
2 |
gorand2 |
wire [511:0] data5;
|
350 |
|
|
wire [511:0] data4;
|
351 |
|
|
wire [511:0] data3;
|
352 |
|
|
wire [511:0] data2;
|
353 |
|
|
wire [511:0] data1;
|
354 |
|
|
wire [511:0] data0;
|
355 |
|
|
|
356 |
6 |
gorand2 |
wire [63:0] byteEnable6;
|
357 |
2 |
gorand2 |
wire [63:0] byteEnable5;
|
358 |
|
|
wire [63:0] byteEnable4;
|
359 |
|
|
wire [63:0] byteEnable3;
|
360 |
|
|
wire [63:0] byteEnable2;
|
361 |
|
|
wire [63:0] byteEnable1;
|
362 |
|
|
wire [63:0] byteEnable0;
|
363 |
|
|
|
364 |
|
|
// change data6 to explicit mux!
|
365 |
6 |
gorand2 |
assign data6=(writesz==0) ? {504'b0,dataIn[7:0]} : 512'bz;
|
366 |
|
|
assign data6=(writesz==1) ? {496'b0,dataIn[15:0]} : 512'bz;
|
367 |
|
|
assign data6=(writesz==2) ? {480'b0,dataIn} : 512'bz;
|
368 |
|
|
assign data6=(writesz==3) ? 512'b0 : 512'bz;
|
369 |
2 |
gorand2 |
|
370 |
|
|
assign data5=addr[5] ? { data6[255:0], 256'b0 }: data6;
|
371 |
|
|
assign data4=addr[4] ? { data5[383:0], 128'b0 }: data5;
|
372 |
|
|
assign data3=addr[3] ? { data4[447:0], 64'b0 }: data4;
|
373 |
|
|
assign data2=addr[2] ? { data3[479:0], 32'b0 }: data3;
|
374 |
|
|
assign data1=addr[1] ? { data2[495:0], 16'b0 }: data2;
|
375 |
|
|
assign data0=addr[0] ? { data1[503:0], 8'b0 }: data1;
|
376 |
|
|
|
377 |
|
|
assign dataOut=data0;
|
378 |
|
|
//change byteEnable6 to explicit mux!
|
379 |
6 |
gorand2 |
assign byteEnable6=(writesz==0) ? 64'b0001 : 64'bz;
|
380 |
|
|
assign byteEnable6=(writesz==1) ? 64'b0011 : 64'bz;
|
381 |
|
|
assign byteEnable6=(writesz==2) ? 64'b1111 : 64'bz;
|
382 |
|
|
assign byteEnable6=(writesz==3) ? 64'b0000 : 64'bz;
|
383 |
2 |
gorand2 |
|
384 |
|
|
assign byteEnable5=addr[5] ? { byteEnable6[31:0],32'b0 } : byteEnable6;
|
385 |
|
|
assign byteEnable4=addr[4] ? { byteEnable5[47:0],16'b0 } : byteEnable5;
|
386 |
|
|
assign byteEnable3=addr[3] ? { byteEnable4[55:0],8'b0 } : byteEnable4;
|
387 |
|
|
assign byteEnable2=addr[2] ? { byteEnable3[59:0],4'b0 } : byteEnable3;
|
388 |
|
|
assign byteEnable1=addr[1] ? { byteEnable2[61:0],2'b0 } : byteEnable2;
|
389 |
|
|
assign byteEnable0=addr[0] ? { byteEnable1[62:0],1'b0 } : byteEnable1;
|
390 |
|
|
|
391 |
|
|
assign byteEnable=byteEnable0;
|
392 |
|
|
|
393 |
|
|
endmodule
|
394 |
|
|
|
395 |
|
|
|
396 |
|
|
module datacache_get_write_data(input [511:0] prevCacheline, input [31:0] data, input [31:0] addr, input [1:0] writesz,output wire [511:0] newCacheline);
|
397 |
|
|
wire [511:0] cacheLine1;
|
398 |
|
|
wire [63:0] byteEnable;
|
399 |
|
|
datacache_write_shift shift0(data,writesz,addr,cacheLine1,byteEnable);
|
400 |
|
|
assign newCacheline=
|
401 |
|
|
{
|
402 |
|
|
byteEnable[63] ? cacheLine1[511:504] : prevCacheline[511:504],
|
403 |
|
|
byteEnable[62] ? cacheLine1[503:496] : prevCacheline[503:496],
|
404 |
|
|
byteEnable[61] ? cacheLine1[495:488] : prevCacheline[495:488],
|
405 |
|
|
byteEnable[60] ? cacheLine1[487:480] : prevCacheline[487:480],
|
406 |
|
|
byteEnable[59] ? cacheLine1[479:472] : prevCacheline[479:472],
|
407 |
|
|
byteEnable[58] ? cacheLine1[471:464] : prevCacheline[471:464],
|
408 |
|
|
byteEnable[57] ? cacheLine1[463:456] : prevCacheline[463:456],
|
409 |
|
|
byteEnable[56] ? cacheLine1[455:448] : prevCacheline[455:448],
|
410 |
|
|
byteEnable[55] ? cacheLine1[447:440] : prevCacheline[447:440],
|
411 |
|
|
byteEnable[54] ? cacheLine1[439:432] : prevCacheline[439:432],
|
412 |
|
|
byteEnable[53] ? cacheLine1[431:424] : prevCacheline[431:424],
|
413 |
|
|
byteEnable[52] ? cacheLine1[423:416] : prevCacheline[423:416],
|
414 |
|
|
byteEnable[51] ? cacheLine1[415:408] : prevCacheline[415:408],
|
415 |
|
|
byteEnable[50] ? cacheLine1[407:400] : prevCacheline[407:400],
|
416 |
|
|
byteEnable[49] ? cacheLine1[399:392] : prevCacheline[399:392],
|
417 |
|
|
byteEnable[48] ? cacheLine1[391:384] : prevCacheline[391:384],
|
418 |
|
|
byteEnable[47] ? cacheLine1[383:376] : prevCacheline[383:376],
|
419 |
|
|
byteEnable[46] ? cacheLine1[375:368] : prevCacheline[375:368],
|
420 |
|
|
byteEnable[45] ? cacheLine1[367:360] : prevCacheline[367:360],
|
421 |
|
|
byteEnable[44] ? cacheLine1[359:352] : prevCacheline[359:352],
|
422 |
|
|
byteEnable[43] ? cacheLine1[351:344] : prevCacheline[351:344],
|
423 |
|
|
byteEnable[42] ? cacheLine1[343:336] : prevCacheline[343:336],
|
424 |
|
|
byteEnable[41] ? cacheLine1[335:328] : prevCacheline[335:328],
|
425 |
|
|
byteEnable[40] ? cacheLine1[327:320] : prevCacheline[327:320],
|
426 |
|
|
byteEnable[39] ? cacheLine1[319:312] : prevCacheline[319:312],
|
427 |
|
|
byteEnable[38] ? cacheLine1[311:304] : prevCacheline[311:304],
|
428 |
|
|
byteEnable[37] ? cacheLine1[303:296] : prevCacheline[303:296],
|
429 |
|
|
byteEnable[36] ? cacheLine1[295:288] : prevCacheline[295:288],
|
430 |
|
|
byteEnable[35] ? cacheLine1[287:280] : prevCacheline[287:280],
|
431 |
|
|
byteEnable[34] ? cacheLine1[279:272] : prevCacheline[279:272],
|
432 |
|
|
byteEnable[33] ? cacheLine1[271:264] : prevCacheline[271:264],
|
433 |
|
|
byteEnable[32] ? cacheLine1[263:256] : prevCacheline[263:256],
|
434 |
|
|
byteEnable[31] ? cacheLine1[255:248] : prevCacheline[255:248],
|
435 |
|
|
byteEnable[30] ? cacheLine1[247:240] : prevCacheline[247:240],
|
436 |
|
|
byteEnable[29] ? cacheLine1[239:232] : prevCacheline[239:232],
|
437 |
|
|
byteEnable[28] ? cacheLine1[231:224] : prevCacheline[231:224],
|
438 |
|
|
byteEnable[27] ? cacheLine1[223:216] : prevCacheline[223:216],
|
439 |
|
|
byteEnable[26] ? cacheLine1[215:208] : prevCacheline[215:208],
|
440 |
|
|
byteEnable[25] ? cacheLine1[207:200] : prevCacheline[207:200],
|
441 |
|
|
byteEnable[24] ? cacheLine1[199:192] : prevCacheline[199:192],
|
442 |
|
|
byteEnable[23] ? cacheLine1[191:184] : prevCacheline[191:184],
|
443 |
|
|
byteEnable[22] ? cacheLine1[183:176] : prevCacheline[183:176],
|
444 |
|
|
byteEnable[21] ? cacheLine1[175:168] : prevCacheline[175:168],
|
445 |
|
|
byteEnable[20] ? cacheLine1[167:160] : prevCacheline[167:160],
|
446 |
|
|
byteEnable[19] ? cacheLine1[159:152] : prevCacheline[159:152],
|
447 |
|
|
byteEnable[18] ? cacheLine1[151:144] : prevCacheline[151:144],
|
448 |
|
|
byteEnable[17] ? cacheLine1[143:136] : prevCacheline[143:136],
|
449 |
|
|
byteEnable[16] ? cacheLine1[135:128] : prevCacheline[135:128],
|
450 |
|
|
byteEnable[15] ? cacheLine1[127:120] : prevCacheline[127:120],
|
451 |
|
|
byteEnable[14] ? cacheLine1[119:112] : prevCacheline[119:112],
|
452 |
|
|
byteEnable[13] ? cacheLine1[111:104] : prevCacheline[111:104],
|
453 |
|
|
byteEnable[12] ? cacheLine1[103:96] : prevCacheline[103:96],
|
454 |
|
|
byteEnable[11] ? cacheLine1[95:88] : prevCacheline[95:88],
|
455 |
|
|
byteEnable[10] ? cacheLine1[87:80] : prevCacheline[87:80],
|
456 |
|
|
byteEnable[9] ? cacheLine1[79:72] : prevCacheline[79:72],
|
457 |
|
|
byteEnable[8] ? cacheLine1[71:64] : prevCacheline[71:64],
|
458 |
|
|
byteEnable[7] ? cacheLine1[63:56] : prevCacheline[63:56],
|
459 |
|
|
byteEnable[6] ? cacheLine1[55:48] : prevCacheline[55:48],
|
460 |
|
|
byteEnable[5] ? cacheLine1[47:40] : prevCacheline[47:40],
|
461 |
|
|
byteEnable[4] ? cacheLine1[39:32] : prevCacheline[39:32],
|
462 |
|
|
byteEnable[3] ? cacheLine1[31:24] : prevCacheline[31:24],
|
463 |
|
|
byteEnable[2] ? cacheLine1[23:16] : prevCacheline[23:16],
|
464 |
|
|
byteEnable[1] ? cacheLine1[15:8] : prevCacheline[15:8],
|
465 |
|
|
byteEnable[0] ? cacheLine1[7:0] : prevCacheline[7:0]
|
466 |
|
|
};
|
467 |
|
|
|
468 |
|
|
endmodule
|