OpenCores
URL https://opencores.org/ocsvn/mpmc8/mpmc8/trunk

Subversion Repositories mpmc8

[/] [mpmc8/] [trunk/] [rtl/] [mpmc10/] [mpcm10_cache_wb.sv] - Blame information for rev 5

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 robfinch
`timescale 1ns / 1ps
2
// ============================================================================
3
//        __
4
//   \\__/ o\    (C) 2015-2022  Robert Finch, Waterloo
5
//    \  __ /    All rights reserved.
6
//     \/_//     robfinch@finitron.ca
7
//       ||
8
//
9
// BSD 3-Clause License
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright notice, this
14
//    list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright notice,
17
//    this list of conditions and the following disclaimer in the documentation
18
//    and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the copyright holder nor the names of its
21
//    contributors may be used to endorse or promote products derived from
22
//    this software without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
//
35
// ============================================================================
36
//
37
import const_pkg::*;
38
import wishbone_pkg::*;
39
import mpmc10_pkg::*;
40
 
41
module mpmc10_cache_wb (input rst, wclk, inv,
42
        input wb_write_request128_t wchi,
43
        output wb_write_response_t wcho,
44
        input wb_write_request128_t ld,
45
        input ch0clk,
46
        input ch1clk,
47
        input ch2clk,
48
        input ch3clk,
49
        input ch4clk,
50
        input ch5clk,
51
        input ch6clk,
52
        input ch7clk,
53
        input wb_write_request128_t ch0i,
54
        input wb_write_request128_t ch1i,
55
        input wb_write_request128_t ch2i,
56
        input wb_write_request128_t ch3i,
57
        input wb_write_request128_t ch4i,
58
        input wb_write_request128_t ch5i,
59
        input wb_write_request128_t ch6i,
60
        input wb_write_request128_t ch7i,
61
        input ch0wack,
62
        input ch1wack,
63
        input ch2wack,
64
        input ch3wack,
65
        input ch4wack,
66
        input ch5wack,
67
        input ch6wack,
68
        input ch7wack,
69
        output wb_read_response128_t ch0o,
70
        output wb_read_response128_t ch1o,
71
        output wb_read_response128_t ch2o,
72
        output wb_read_response128_t ch3o,
73
        output wb_read_response128_t ch4o,
74
        output wb_read_response128_t ch5o,
75
        output wb_read_response128_t ch6o,
76
        output wb_read_response128_t ch7o
77
);
78
parameter DEP=1024;
79
parameter LOBIT=4;
80
parameter HIBIT=13;
81
 
82
integer n,n2,n3,n4,n5;
83
 
84
(* ram_style="distributed" *)
85
reg [1023:0] vbit [0:CACHE_ASSOC-1];
86
initial begin
87
        for (n5 = 0; n5 < CACHE_ASSOC; n5 = n5 + 1)
88
                vbit[n5] <= 'd0;
89
end
90
 
91
reg [31:0] radrr [0:8];
92
reg wchi_stb, wchi_stb_r;
93
reg [15:0] wchi_sel, wchi_sel_r;
94
reg [31:0] wchi_adr;
95
reg [127:0] wchi_dat;
96
 
97
mpmc10_quad_cache_line_t doutb [0:8];
98
mpmc10_quad_cache_line_t wrdata, wdata;
99
 
100
reg [31:0] wadr;
101
reg wstrb;
102
reg [$clog2(CACHE_ASSOC)-1:0] wway;
103
 
104
reg [CACHE_ASSOC-1:0] vbito0a;
105
reg [CACHE_ASSOC-1:0] vbito1a;
106
reg [CACHE_ASSOC-1:0] vbito2a;
107
reg [CACHE_ASSOC-1:0] vbito3a;
108
reg [CACHE_ASSOC-1:0] vbito4a;
109
reg [CACHE_ASSOC-1:0] vbito5a;
110
reg [CACHE_ASSOC-1:0] vbito6a;
111
reg [CACHE_ASSOC-1:0] vbito7a;
112
reg [CACHE_ASSOC-1:0] vbito8a;
113
 
114
reg [CACHE_ASSOC-1:0] hit0a;
115
reg [CACHE_ASSOC-1:0] hit1a;
116
reg [CACHE_ASSOC-1:0] hit2a;
117
reg [CACHE_ASSOC-1:0] hit3a;
118
reg [CACHE_ASSOC-1:0] hit4a;
119
reg [CACHE_ASSOC-1:0] hit5a;
120
reg [CACHE_ASSOC-1:0] hit6a;
121
reg [CACHE_ASSOC-1:0] hit7a;
122
reg [CACHE_ASSOC-1:0] hit8a;
123
 
124
reg stb0;
125
reg stb1;
126
reg stb2;
127
reg stb3;
128
reg stb4;
129
reg stb5;
130
reg stb6;
131
reg stb7;
132
reg [8:0] rstb;
133
 
134
always_ff @(posedge ch0clk) radrr[0] <= ch0i.adr;
135
always_ff @(posedge ch1clk) radrr[1] <= ch1i.adr;
136
always_ff @(posedge ch2clk) radrr[2] <= ch2i.adr;
137
always_ff @(posedge ch3clk) radrr[3] <= ch3i.adr;
138
always_ff @(posedge ch4clk) radrr[4] <= ch4i.adr;
139
always_ff @(posedge ch5clk) radrr[5] <= ch5i.adr;
140
always_ff @(posedge ch6clk) radrr[6] <= ch6i.adr;
141
always_ff @(posedge ch7clk) radrr[7] <= ch7i.adr;
142
always_ff @(posedge wclk) radrr[8] <= ld.cyc ? ld.adr : wchi.adr;
143
always_ff @(posedge wclk) wchi_adr <= radrr[8];
144
 
145
always_ff @(posedge ch0clk) stb0 <= ch0i.stb;
146
always_ff @(posedge ch1clk) stb1 <= ch1i.stb;
147
always_ff @(posedge ch2clk) stb2 <= ch2i.stb;
148
always_ff @(posedge ch3clk) stb3 <= ch3i.stb;
149
always_ff @(posedge ch4clk) stb4 <= ch4i.stb;
150
always_ff @(posedge ch5clk) stb5 <= ch5i.stb;
151
always_ff @(posedge ch6clk) stb6 <= ch6i.stb;
152
always_ff @(posedge ch7clk) stb7 <= ch7i.stb;
153
 
154
always_comb rstb[0] <= ch0i.stb & ~ch0i.we;
155
always_comb rstb[1] <= ch1i.stb & ~ch1i.we;
156
always_comb rstb[2] <= ch2i.stb & ~ch2i.we;
157
always_comb rstb[3] <= ch3i.stb & ~ch3i.we;
158
always_comb rstb[4] <= ch4i.stb & ~ch4i.we;
159
always_comb rstb[5] <= ch5i.stb & ~ch5i.we;
160
always_comb rstb[6] <= ch6i.stb & ~ch6i.we;
161
always_comb rstb[7] <= ch7i.stb & ~ch7i.we;
162
always_comb rstb[8] <= ld.stb | wchi.stb;
163
 
164
always_ff @(posedge wclk) wchi_stb_r <= wchi.stb;
165
always_ff @(posedge wclk) wchi_stb <= wchi_stb_r;
166
always_ff @(posedge wclk) wchi_sel_r <= wchi.sel;
167
always_ff @(posedge wclk) wchi_sel <= wchi_sel_r;
168
always_ff @(posedge wclk) wchi_dat <= wchi.dat;
169
 
170
reg [8:0] rclkp;
171
always_comb
172
begin
173
        rclkp[0] = ch0clk;
174
        rclkp[1] = ch1clk;
175
        rclkp[2] = ch2clk;
176
        rclkp[3] = ch3clk;
177
        rclkp[4] = ch4clk;
178
        rclkp[5] = ch5clk;
179
        rclkp[6] = ch6clk;
180
        rclkp[7] = ch7clk;
181
        rclkp[8] = wclk;
182
end
183
 
184
reg [HIBIT-LOBIT:0] radr [0:8];
185
always_comb
186
begin
187
        radr[0] = ch0i.adr[HIBIT:LOBIT];
188
        radr[1] = ch1i.adr[HIBIT:LOBIT];
189
        radr[2] = ch2i.adr[HIBIT:LOBIT];
190
        radr[3] = ch3i.adr[HIBIT:LOBIT];
191
        radr[4] = ch4i.adr[HIBIT:LOBIT];
192
        radr[5] = ch5i.adr[HIBIT:LOBIT];
193
        radr[6] = ch6i.adr[HIBIT:LOBIT];
194
        radr[7] = ch7i.adr[HIBIT:LOBIT];
195
        radr[8] = ld.cyc ? ld.adr[HIBIT:LOBIT] : wchi.adr[HIBIT:LOBIT];
196
end
197
 
198
   // xpm_memory_sdpram: Simple Dual Port RAM
199
   // Xilinx Parameterized Macro, version 2020.2
200
 
201
genvar gway,gport;
202
 
203
generate begin : gCacheRAM
204
        for (gport = 0; gport < 9; gport = gport + 1) begin
205
        xpm_memory_sdpram #(
206
                .ADDR_WIDTH_A($clog2(DEP)),
207
                .ADDR_WIDTH_B($clog2(DEP)),
208
                .AUTO_SLEEP_TIME(0),
209
                .BYTE_WRITE_WIDTH_A($bits(mpmc10_quad_cache_line_t)),
210
                .CASCADE_HEIGHT(0),
211
                .CLOCKING_MODE("independent_clock"), // String
212
                .ECC_MODE("no_ecc"),            // String
213
                .MEMORY_INIT_FILE("none"),      // String
214
                .MEMORY_INIT_PARAM("0"),        // String
215
                .MEMORY_OPTIMIZATION("true"),   // String
216
                .MEMORY_PRIMITIVE("block"),      // String
217
                .MEMORY_SIZE($bits(mpmc10_quad_cache_line_t)*DEP),         // DECIMAL
218
                .MESSAGE_CONTROL(0),            // DECIMAL
219
                .READ_DATA_WIDTH_B($bits(mpmc10_quad_cache_line_t)),         // DECIMAL
220
                .READ_LATENCY_B(1),
221
                .READ_RESET_VALUE_B("0"),       // String
222
                .RST_MODE_A("SYNC"),            // String
223
                .RST_MODE_B("SYNC"),            // String
224
                .SIM_ASSERT_CHK(0),             // DECIMAL; 0=disable simulation messages, 1=enable simulation messages
225
                .USE_EMBEDDED_CONSTRAINT(0),
226
                .USE_MEM_INIT(1),
227
                .WAKEUP_TIME("disable_sleep"),  // String
228
                .WRITE_DATA_WIDTH_A($bits(mpmc10_quad_cache_line_t)),        // DECIMAL
229
                .WRITE_MODE_B("no_change")      // String
230
        )
231
                xpm_memory_sdpram_inst1 (
232
                .dbiterrb(),             // 1-bit output: Status signal to indicate double bit error occurrence
233
                                                 // on the data output of port B.
234
 
235
                .doutb(doutb[gport]),                   // READ_DATA_WIDTH_B-bit output: Data output for port B read operations.
236
                .sbiterrb(),             // 1-bit output: Status signal to indicate single bit error occurrence
237
                                                 // on the data output of port B.
238
 
239
                .addra(wadr2[HIBIT:LOBIT]),                                     // ADDR_WIDTH_A-bit input: Address for port A write operations.
240
                .addrb(radr[gport]),             // ADDR_WIDTH_B-bit input: Address for port B read operations.
241
                .clka(wclk),                 // 1-bit input: Clock signal for port A. Also clocks port B when
242
                                                 // parameter CLOCKING_MODE is "common_clock".
243
 
244
                .clkb(rclkp[gport]),                     // 1-bit input: Clock signal for port B when parameter CLOCKING_MODE is
245
                                                 // "independent_clock". Unused when parameter CLOCKING_MODE is
246
                                                 // "common_clock".
247
 
248
                .dina(wdata),                // WRITE_DATA_WIDTH_A-bit input: Data input for port A write operations.
249
                .ena(wstrb),                            // 1-bit input: Memory enable signal for port A. Must be high on clock
250
                                                 // cycles when write operations are initiated. Pipelined internally.
251
 
252
                .enb(rstb[gport]),                // 1-bit input: Memory enable signal for port B. Must be high on clock
253
                                                 // cycles when read operations are initiated. Pipelined internally.
254
 
255
                .injectdbiterra(1'b0), // 1-bit input: Controls double bit error injection on input data when
256
                                                 // ECC enabled (Error injection capability is not available in
257
                                                 // "decode_only" mode).
258
 
259
                .injectsbiterra(1'b0), // 1-bit input: Controls single bit error injection on input data when
260
                                                 // ECC enabled (Error injection capability is not available in
261
                                                 // "decode_only" mode).
262
 
263
                .regceb(1'b1),                 // 1-bit input: Clock Enable for the last register stage on the output
264
                                                 // data path.
265
 
266
                .rstb(rst),                     // 1-bit input: Reset signal for the final port B output register stage.
267
                                                 // Synchronously resets output port doutb to the value specified by
268
                                                 // parameter READ_RESET_VALUE_B.
269
 
270
                .sleep(1'b0),                   // 1-bit input: sleep signal to enable the dynamic power saving feature.
271
                .wea(wstrb)                     // WRITE_DATA_WIDTH_A/BYTE_WRITE_WIDTH_A-bit input: Write enable vector
272
                                                 // for port A input data port dina. 1 bit wide when word-wide writes are
273
                                                 // used. In byte-wide write configurations, each bit controls the
274
                                                 // writing one byte of dina to address addra. For example, to
275
                                                 // synchronously write only bits [15-8] of dina when WRITE_DATA_WIDTH_A
276
                                                 // is 32, wea would be 4'b0010.
277
 
278
        );
279
        end
280
end
281
endgenerate
282
 
283
genvar g;
284
generate begin : gReaddat
285
        for (g = 0; g < CACHE_ASSOC; g = g + 1) begin
286
                always_comb vbito0a[g] <= vbit[g][radrr[0][HIBIT:LOBIT]];
287
                always_comb vbito1a[g] <= vbit[g][radrr[1][HIBIT:LOBIT]];
288
                always_comb vbito2a[g] <= vbit[g][radrr[2][HIBIT:LOBIT]];
289
                always_comb vbito3a[g] <= vbit[g][radrr[3][HIBIT:LOBIT]];
290
                always_comb vbito4a[g] <= vbit[g][radrr[4][HIBIT:LOBIT]];
291
                always_comb vbito5a[g] <= vbit[g][radrr[5][HIBIT:LOBIT]];
292
                always_comb vbito6a[g] <= vbit[g][radrr[6][HIBIT:LOBIT]];
293
                always_comb vbito7a[g] <= vbit[g][radrr[7][HIBIT:LOBIT]];
294
                always_comb vbito8a[g] <= vbit[g][radrr[8][HIBIT:LOBIT]];
295
 
296
                always_ff @(posedge ch0clk)     hit0a[g] = (doutb[0].lines[g].tag==radrr[0][31:HIBIT+1]) && (vbito0a[g]==1'b1);
297
                always_ff @(posedge ch1clk)     hit1a[g] = (doutb[1].lines[g].tag==radrr[1][31:HIBIT+1]) && (vbito1a[g]==1'b1);
298
                always_ff @(posedge ch2clk)     hit2a[g] = (doutb[2].lines[g].tag==radrr[2][31:HIBIT+1]) && (vbito2a[g]==1'b1);
299
                always_ff @(posedge ch3clk)     hit3a[g] = (doutb[3].lines[g].tag==radrr[3][31:HIBIT+1]) && (vbito3a[g]==1'b1);
300
                always_ff @(posedge ch4clk)     hit4a[g] = (doutb[4].lines[g].tag==radrr[4][31:HIBIT+1]) && (vbito4a[g]==1'b1);
301
                always_ff @(posedge ch5clk)     hit5a[g] = (doutb[5].lines[g].tag==radrr[5][31:HIBIT+1]) && (vbito5a[g]==1'b1);
302
                always_ff @(posedge ch6clk)     hit6a[g] = (doutb[6].lines[g].tag==radrr[6][31:HIBIT+1]) && (vbito6a[g]==1'b1);
303
                always_ff @(posedge ch7clk)     hit7a[g] = (doutb[7].lines[g].tag==radrr[7][31:HIBIT+1]) && (vbito7a[g]==1'b1);
304
                always_ff @(posedge wclk)       hit8a[g] = (doutb[8].lines[g].tag==radrr[8][31:HIBIT+1]) && (vbito8a[g]==1'b1);
305
        end
306
        always_comb ch0o.ack = (|hit0a & stb0) | (ch0wack & stb0);
307
        always_comb ch1o.ack = (|hit1a & stb1) | (ch1wack & stb1);
308
        always_comb ch2o.ack = (|hit2a & stb2) | (ch2wack & stb2);
309
        always_comb ch3o.ack = (|hit3a & stb3) | (ch3wack & stb3);
310
        always_comb ch4o.ack = (|hit4a & stb4) | (ch4wack & stb4);
311
        always_comb ch5o.ack = (|hit5a & stb5) | (ch5wack & stb5);
312
        always_comb ch6o.ack = (|hit6a & stb6) | (ch6wack & stb6);
313
        always_comb ch7o.ack = (|hit7a & stb7) | (ch7wack & stb7);
314
        always_comb ch0o.err = 1'b0;
315
        always_comb ch1o.err = 1'b0;
316
        always_comb ch2o.err = 1'b0;
317
        always_comb ch3o.err = 1'b0;
318
        always_comb ch4o.err = 1'b0;
319
        always_comb ch5o.err = 1'b0;
320
        always_comb ch6o.err = 1'b0;
321
        always_comb ch7o.err = 1'b0;
322
        always_comb ch0o.rty = 1'b0;
323
        always_comb ch1o.rty = 1'b0;
324
        always_comb ch2o.rty = 1'b0;
325
        always_comb ch3o.rty = 1'b0;
326
        always_comb ch4o.rty = 1'b0;
327
        always_comb ch5o.rty = 1'b0;
328
        always_comb ch6o.rty = 1'b0;
329
        always_comb ch7o.rty = 1'b0;
330
        always_comb ch0o.cid = ch0i.cid;
331
        always_comb ch1o.cid = ch1i.cid;
332
        always_comb ch2o.cid = ch2i.cid;
333
        always_comb ch3o.cid = ch3i.cid;
334
        always_comb ch4o.cid = ch4i.cid;
335
        always_comb ch5o.cid = ch5i.cid;
336
        always_comb ch6o.cid = ch6i.cid;
337
        always_comb ch7o.cid = ch7i.cid;
338
end
339
endgenerate
340
 
341
always_comb wway = hit8a[0] ? 2'd0 : hit8a[1] ? 2'd1 : hit8a[2] ? 2'd2 : hit8a[3] ? 2'd3 : 2'd0;
342
 
343
always_comb
344
begin
345
        ch0o.dat <= 'd0;
346
        ch1o.dat <= 'd0;
347
        ch2o.dat <= 'd0;
348
        ch3o.dat <= 'd0;
349
        ch4o.dat <= 'd0;
350
        ch5o.dat <= 'd0;
351
        ch6o.dat <= 'd0;
352
        ch7o.dat <= 'd0;
353
        wrdata <= 'd0;
354
        for (n2 = 0; n2 < CACHE_ASSOC; n2 = n2 + 1) begin
355
                if (hit0a[n2]) ch0o.dat <= doutb[0].lines[n2];
356
                if (hit1a[n2]) ch1o.dat <= doutb[1].lines[n2];
357
                if (hit2a[n2]) ch2o.dat <= doutb[2].lines[n2];
358
                if (hit3a[n2]) ch3o.dat <= doutb[3].lines[n2];
359
                if (hit4a[n2]) ch4o.dat <= doutb[4].lines[n2];
360
                if (hit5a[n2]) ch5o.dat <= doutb[5].lines[n2];
361
                if (hit6a[n2]) ch6o.dat <= doutb[6].lines[n2];
362
                if (hit7a[n2]) ch7o.dat <= doutb[7].lines[n2];
363
        end
364
//      if (|hit8a)
365
                wrdata <= doutb[8];
366
end
367
 
368
reg b0,b1,b2;
369
reg ldcycd1,ldcycd2;
370
always_ff @(posedge wclk)
371
        ldcycd1 <= ld.cyc;
372
always_ff @(posedge wclk)
373
        ldcycd2 <= ldcycd1;
374
always_ff @(posedge wclk)
375
if (rst) begin
376
        for (n = 0; n < 4; n = n + 1)
377
                vbit[n] <= 'b0;
378
end
379
else begin
380
        if (ldcycd2) begin
381
                vbit[0][wadr2[HIBIT:LOBIT]] <= 1'b1;
382
                vbit[1][wadr2[HIBIT:LOBIT]] <= b0;
383
                vbit[2][wadr2[HIBIT:LOBIT]] <= b1;
384
                vbit[3][wadr2[HIBIT:LOBIT]] <= b2;
385
        end
386
        if (ldcycd1) begin
387
                b0 <= vbit[0][wadr[HIBIT:LOBIT]];
388
                b1 <= vbit[1][wadr[HIBIT:LOBIT]];
389
                b2 <= vbit[2][wadr[HIBIT:LOBIT]];
390
        end
391
        if (|wchi_sel & wchi_stb & ~(ld.cyc|ldcycd1|ldcycd2))
392
                vbit[wway][wadr[HIBIT:LOBIT]] <= 1'b1;
393
        else if (inv)
394
                vbit[wway][wadr[HIBIT:LOBIT]] <= 1'b0;
395
end
396
 
397
// Update the cache only if there was a write hit or if loading the cache line
398
// due to a read miss. For a read miss the entire line is updated, otherwise
399
// just the part of the line relevant to the write is updated.
400
always_ff @(posedge wclk)
401
begin
402
        if (ld.cyc)
403
                wadr <= ld.adr;
404
        else if (wchi_stb)
405
                wadr <= wchi_adr;
406
        wstrb <= ldcycd2 | (wchi_stb & |hit8a);
407
end
408
reg [127:0] lddat1, lddat2;
409
reg [31:0] wadr2;
410
always_ff @(posedge wclk)
411
        wadr2 <= wadr;
412
always_ff @(posedge wclk)
413
        lddat1 <= ld.dat;
414
always_ff @(posedge wclk)
415
        lddat2 <= lddat1;
416
 
417
// Merge write data into cache line.
418
// For a load due to a read miss the entire line is updated.
419
// For a write hit, just the portion of the line corresponding to the hit is
420
// updated.
421
reg [18:0] t0,t1,t2;
422
reg m0,m1,m2;
423
generate begin : gWrData
424
        // LRU update
425
        always_ff @(posedge wclk)
426
        begin
427
                if (ldcycd2) begin
428
                        wdata.lines[0].tag <= {5'd0,wadr2[31:HIBIT+1]};                 // set tag
429
                        wdata.lines[1].tag <= t0;
430
                        wdata.lines[2].tag <= t1;
431
                        wdata.lines[3].tag <= t2;
432
                        wdata.lines[0].modified <= 1'b0;                                                                                        // clear modified flags
433
                        wdata.lines[1].modified <= m0;
434
                        wdata.lines[2].modified <= m1;
435
                        wdata.lines[3].modified <= m2;
436
                end
437
                if (ldcycd1) begin
438
                        t0 <= wrdata.lines[0].tag;
439
                        t1 <= wrdata.lines[1].tag;
440
                        t2 <= wrdata.lines[2].tag;
441
                        m0 <= wrdata.lines[0].modified;
442
                        m1 <= wrdata.lines[1].modified;
443
                        m2 <= wrdata.lines[2].modified;
444
                end
445
                if (!(ld.cyc|ldcycd1|ldcycd2)) begin
446
                        if (wchi_stb & hit8a[0])
447
                                wdata.lines[0].modified <= 1'b1;
448
                        else
449
                                wdata.lines[0].modified <= wrdata.lines[0].modified;
450
                        if (wchi_stb & hit8a[1])
451
                                wdata.lines[1].modified <= 1'b1;
452
                        else
453
                                wdata.lines[1].modified <= wrdata.lines[0].modified;
454
                        if (wchi_stb & hit8a[2])
455
                                wdata.lines[2].modified <= 1'b1;
456
                        else
457
                                wdata.lines[2].modified <= wrdata.lines[0].modified;
458
                        if (wchi_stb & hit8a[3])
459
                                wdata.lines[3].modified <= 1'b1;
460
                        else
461
                                wdata.lines[3].modified <= wrdata.lines[0].modified;
462
                        // Tag stays the same, it was hit
463
                        wdata.lines[0].tag <= wrdata.lines[0].tag;
464
                        wdata.lines[1].tag <= wrdata.lines[1].tag;
465
                        wdata.lines[2].tag <= wrdata.lines[2].tag;
466
                        wdata.lines[3].tag <= wrdata.lines[3].tag;
467
                end
468
        end
469
        for (g = 0; g < 16; g = g + 1)
470
        always_ff @(posedge wclk)
471
                begin
472
                        if (ldcycd2) begin
473
        //                      wdata <= wrdata << $bits(mpmc10_cache_line_t);
474
                                wdata.lines[0].data[g*8+7:g*8] <= lddat2[g*8+7:g*8];            // set data
475
                                wdata.lines[1].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
476
                                wdata.lines[2].data[g*8+7:g*8] <= wrdata.lines[1].data[g*8+7:g*8];
477
                                wdata.lines[3].data[g*8+7:g*8] <= wrdata.lines[2].data[g*8+7:g*8];
478
                        end
479
                        if (!(ld.cyc|ldcycd1|ldcycd2)) begin
480
                                if (wchi_stb & hit8a[0])
481
                                        wdata.lines[0].data[g*8+7:g*8] <= wchi_sel[g] ? wchi_dat[g*8+7:g*8] : wrdata.lines[0].data[g*8+7:g*8];
482
                                else
483
                                        wdata.lines[0].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
484
                                if (wchi_stb & hit8a[1])
485
                                        wdata.lines[1].data[g*8+7:g*8] <= wchi_sel[g] ? wchi_dat[g*8+7:g*8] : wrdata.lines[1].data[g*8+7:g*8];
486
                                else
487
                                        wdata.lines[1].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
488
                                if (wchi_stb & hit8a[2])
489
                                        wdata.lines[2].data[g*8+7:g*8] <= wchi_sel[g] ? wchi_dat[g*8+7:g*8] : wrdata.lines[2].data[g*8+7:g*8];
490
                                else
491
                                        wdata.lines[2].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
492
                                if (wchi_stb & hit8a[3])
493
                                        wdata.lines[3].data[g*8+7:g*8] <= wchi_sel[g] ? wchi_dat[g*8+7:g*8] : wrdata.lines[3].data[g*8+7:g*8];
494
                                else
495
                                        wdata.lines[3].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
496
                        end
497
                end
498
end
499
endgenerate
500
 
501
// Writes take two clock cycles, 1 to read the RAM and find out if it is a
502
// write hit and a second clock to write the data. The write cycle may be
503
// delayed by a cycle due to a load.
504
reg wack;
505
always_ff @(posedge wclk)
506
if (rst)
507
        wack <= 1'b0;
508
else begin
509
        wack <= 1'b0;
510
        if (wchi.stb & ~ld.stb)
511
                wack <= 1'b1;
512
end
513
assign wcho.ack = wack & wchi.stb;
514
 
515
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.