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

Subversion Repositories mpmc8

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

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 8 robfinch
reg [15:0] wchi_sel;
94 7 robfinch
reg [31:0] wchi_adr, wchi_adr1;
95 5 robfinch
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 7 robfinch
reg [127:0] lddat1, lddat2;
102
reg [31:0] wadr2;
103 5 robfinch
reg wstrb;
104
reg [$clog2(CACHE_ASSOC)-1:0] wway;
105
 
106
reg [CACHE_ASSOC-1:0] vbito0a;
107
reg [CACHE_ASSOC-1:0] vbito1a;
108
reg [CACHE_ASSOC-1:0] vbito2a;
109
reg [CACHE_ASSOC-1:0] vbito3a;
110
reg [CACHE_ASSOC-1:0] vbito4a;
111
reg [CACHE_ASSOC-1:0] vbito5a;
112
reg [CACHE_ASSOC-1:0] vbito6a;
113
reg [CACHE_ASSOC-1:0] vbito7a;
114
reg [CACHE_ASSOC-1:0] vbito8a;
115
 
116
reg [CACHE_ASSOC-1:0] hit0a;
117
reg [CACHE_ASSOC-1:0] hit1a;
118
reg [CACHE_ASSOC-1:0] hit2a;
119
reg [CACHE_ASSOC-1:0] hit3a;
120
reg [CACHE_ASSOC-1:0] hit4a;
121
reg [CACHE_ASSOC-1:0] hit5a;
122
reg [CACHE_ASSOC-1:0] hit6a;
123
reg [CACHE_ASSOC-1:0] hit7a;
124
reg [CACHE_ASSOC-1:0] hit8a;
125
 
126
reg stb0;
127
reg stb1;
128
reg stb2;
129
reg stb3;
130
reg stb4;
131
reg stb5;
132
reg stb6;
133
reg stb7;
134
reg [8:0] rstb;
135
 
136
always_ff @(posedge ch0clk) radrr[0] <= ch0i.adr;
137
always_ff @(posedge ch1clk) radrr[1] <= ch1i.adr;
138
always_ff @(posedge ch2clk) radrr[2] <= ch2i.adr;
139
always_ff @(posedge ch3clk) radrr[3] <= ch3i.adr;
140
always_ff @(posedge ch4clk) radrr[4] <= ch4i.adr;
141
always_ff @(posedge ch5clk) radrr[5] <= ch5i.adr;
142
always_ff @(posedge ch6clk) radrr[6] <= ch6i.adr;
143
always_ff @(posedge ch7clk) radrr[7] <= ch7i.adr;
144
always_ff @(posedge wclk) radrr[8] <= ld.cyc ? ld.adr : wchi.adr;
145 7 robfinch
always_ff @(posedge wclk) wchi_adr1 <= wchi.adr;
146
always_ff @(posedge wclk) wchi_adr <= wchi_adr1;
147 5 robfinch
 
148
always_ff @(posedge ch0clk) stb0 <= ch0i.stb;
149
always_ff @(posedge ch1clk) stb1 <= ch1i.stb;
150
always_ff @(posedge ch2clk) stb2 <= ch2i.stb;
151
always_ff @(posedge ch3clk) stb3 <= ch3i.stb;
152
always_ff @(posedge ch4clk) stb4 <= ch4i.stb;
153
always_ff @(posedge ch5clk) stb5 <= ch5i.stb;
154
always_ff @(posedge ch6clk) stb6 <= ch6i.stb;
155
always_ff @(posedge ch7clk) stb7 <= ch7i.stb;
156
 
157
always_comb rstb[0] <= ch0i.stb & ~ch0i.we;
158
always_comb rstb[1] <= ch1i.stb & ~ch1i.we;
159
always_comb rstb[2] <= ch2i.stb & ~ch2i.we;
160
always_comb rstb[3] <= ch3i.stb & ~ch3i.we;
161
always_comb rstb[4] <= ch4i.stb & ~ch4i.we;
162
always_comb rstb[5] <= ch5i.stb & ~ch5i.we;
163
always_comb rstb[6] <= ch6i.stb & ~ch6i.we;
164
always_comb rstb[7] <= ch7i.stb & ~ch7i.we;
165 7 robfinch
always_comb rstb[8] <= ld.cyc ? ld.stb : wchi.stb;
166 5 robfinch
 
167
always_ff @(posedge wclk) wchi_stb_r <= wchi.stb;
168
always_ff @(posedge wclk) wchi_stb <= wchi_stb_r;
169 8 robfinch
always_ff @(posedge wclk) wchi_sel <= wchi.sel;
170 5 robfinch
always_ff @(posedge wclk) wchi_dat <= wchi.dat;
171
 
172
reg [8:0] rclkp;
173
always_comb
174
begin
175
        rclkp[0] = ch0clk;
176
        rclkp[1] = ch1clk;
177
        rclkp[2] = ch2clk;
178
        rclkp[3] = ch3clk;
179
        rclkp[4] = ch4clk;
180
        rclkp[5] = ch5clk;
181
        rclkp[6] = ch6clk;
182
        rclkp[7] = ch7clk;
183
        rclkp[8] = wclk;
184
end
185
 
186
reg [HIBIT-LOBIT:0] radr [0:8];
187
always_comb
188
begin
189
        radr[0] = ch0i.adr[HIBIT:LOBIT];
190
        radr[1] = ch1i.adr[HIBIT:LOBIT];
191
        radr[2] = ch2i.adr[HIBIT:LOBIT];
192
        radr[3] = ch3i.adr[HIBIT:LOBIT];
193
        radr[4] = ch4i.adr[HIBIT:LOBIT];
194
        radr[5] = ch5i.adr[HIBIT:LOBIT];
195
        radr[6] = ch6i.adr[HIBIT:LOBIT];
196
        radr[7] = ch7i.adr[HIBIT:LOBIT];
197
        radr[8] = ld.cyc ? ld.adr[HIBIT:LOBIT] : wchi.adr[HIBIT:LOBIT];
198
end
199
 
200
   // xpm_memory_sdpram: Simple Dual Port RAM
201
   // Xilinx Parameterized Macro, version 2020.2
202
 
203
genvar gway,gport;
204
 
205
generate begin : gCacheRAM
206
        for (gport = 0; gport < 9; gport = gport + 1) begin
207
        xpm_memory_sdpram #(
208
                .ADDR_WIDTH_A($clog2(DEP)),
209
                .ADDR_WIDTH_B($clog2(DEP)),
210
                .AUTO_SLEEP_TIME(0),
211
                .BYTE_WRITE_WIDTH_A($bits(mpmc10_quad_cache_line_t)),
212
                .CASCADE_HEIGHT(0),
213
                .CLOCKING_MODE("independent_clock"), // String
214
                .ECC_MODE("no_ecc"),            // String
215
                .MEMORY_INIT_FILE("none"),      // String
216
                .MEMORY_INIT_PARAM("0"),        // String
217
                .MEMORY_OPTIMIZATION("true"),   // String
218
                .MEMORY_PRIMITIVE("block"),      // String
219
                .MEMORY_SIZE($bits(mpmc10_quad_cache_line_t)*DEP),         // DECIMAL
220
                .MESSAGE_CONTROL(0),            // DECIMAL
221
                .READ_DATA_WIDTH_B($bits(mpmc10_quad_cache_line_t)),         // DECIMAL
222
                .READ_LATENCY_B(1),
223
                .READ_RESET_VALUE_B("0"),       // String
224
                .RST_MODE_A("SYNC"),            // String
225
                .RST_MODE_B("SYNC"),            // String
226
                .SIM_ASSERT_CHK(0),             // DECIMAL; 0=disable simulation messages, 1=enable simulation messages
227
                .USE_EMBEDDED_CONSTRAINT(0),
228
                .USE_MEM_INIT(1),
229
                .WAKEUP_TIME("disable_sleep"),  // String
230
                .WRITE_DATA_WIDTH_A($bits(mpmc10_quad_cache_line_t)),        // DECIMAL
231
                .WRITE_MODE_B("no_change")      // String
232
        )
233
                xpm_memory_sdpram_inst1 (
234
                .dbiterrb(),             // 1-bit output: Status signal to indicate double bit error occurrence
235
                                                 // on the data output of port B.
236
 
237
                .doutb(doutb[gport]),                   // READ_DATA_WIDTH_B-bit output: Data output for port B read operations.
238
                .sbiterrb(),             // 1-bit output: Status signal to indicate single bit error occurrence
239
                                                 // on the data output of port B.
240
 
241
                .addra(wadr2[HIBIT:LOBIT]),                                     // ADDR_WIDTH_A-bit input: Address for port A write operations.
242
                .addrb(radr[gport]),             // ADDR_WIDTH_B-bit input: Address for port B read operations.
243
                .clka(wclk),                 // 1-bit input: Clock signal for port A. Also clocks port B when
244
                                                 // parameter CLOCKING_MODE is "common_clock".
245
 
246
                .clkb(rclkp[gport]),                     // 1-bit input: Clock signal for port B when parameter CLOCKING_MODE is
247
                                                 // "independent_clock". Unused when parameter CLOCKING_MODE is
248
                                                 // "common_clock".
249
 
250
                .dina(wdata),                // WRITE_DATA_WIDTH_A-bit input: Data input for port A write operations.
251
                .ena(wstrb),                            // 1-bit input: Memory enable signal for port A. Must be high on clock
252
                                                 // cycles when write operations are initiated. Pipelined internally.
253
 
254
                .enb(rstb[gport]),                // 1-bit input: Memory enable signal for port B. Must be high on clock
255
                                                 // cycles when read operations are initiated. Pipelined internally.
256
 
257
                .injectdbiterra(1'b0), // 1-bit input: Controls double bit error injection on input data when
258
                                                 // ECC enabled (Error injection capability is not available in
259
                                                 // "decode_only" mode).
260
 
261
                .injectsbiterra(1'b0), // 1-bit input: Controls single bit error injection on input data when
262
                                                 // ECC enabled (Error injection capability is not available in
263
                                                 // "decode_only" mode).
264
 
265
                .regceb(1'b1),                 // 1-bit input: Clock Enable for the last register stage on the output
266
                                                 // data path.
267
 
268
                .rstb(rst),                     // 1-bit input: Reset signal for the final port B output register stage.
269
                                                 // Synchronously resets output port doutb to the value specified by
270
                                                 // parameter READ_RESET_VALUE_B.
271
 
272
                .sleep(1'b0),                   // 1-bit input: sleep signal to enable the dynamic power saving feature.
273
                .wea(wstrb)                     // WRITE_DATA_WIDTH_A/BYTE_WRITE_WIDTH_A-bit input: Write enable vector
274
                                                 // for port A input data port dina. 1 bit wide when word-wide writes are
275
                                                 // used. In byte-wide write configurations, each bit controls the
276
                                                 // writing one byte of dina to address addra. For example, to
277
                                                 // synchronously write only bits [15-8] of dina when WRITE_DATA_WIDTH_A
278
                                                 // is 32, wea would be 4'b0010.
279
 
280
        );
281
        end
282
end
283
endgenerate
284
 
285
genvar g;
286
generate begin : gReaddat
287
        for (g = 0; g < CACHE_ASSOC; g = g + 1) begin
288
                always_comb vbito0a[g] <= vbit[g][radrr[0][HIBIT:LOBIT]];
289
                always_comb vbito1a[g] <= vbit[g][radrr[1][HIBIT:LOBIT]];
290
                always_comb vbito2a[g] <= vbit[g][radrr[2][HIBIT:LOBIT]];
291
                always_comb vbito3a[g] <= vbit[g][radrr[3][HIBIT:LOBIT]];
292
                always_comb vbito4a[g] <= vbit[g][radrr[4][HIBIT:LOBIT]];
293
                always_comb vbito5a[g] <= vbit[g][radrr[5][HIBIT:LOBIT]];
294
                always_comb vbito6a[g] <= vbit[g][radrr[6][HIBIT:LOBIT]];
295
                always_comb vbito7a[g] <= vbit[g][radrr[7][HIBIT:LOBIT]];
296
                always_comb vbito8a[g] <= vbit[g][radrr[8][HIBIT:LOBIT]];
297
 
298 9 robfinch
                always_ff @(posedge ch0clk)     hit0a[g] = (doutb[0].lines[g].tag==radrr[0][31:LOBIT]) && (vbito0a[g]==1'b1);
299
                always_ff @(posedge ch1clk)     hit1a[g] = (doutb[1].lines[g].tag==radrr[1][31:LOBIT]) && (vbito1a[g]==1'b1);
300
                always_ff @(posedge ch2clk)     hit2a[g] = (doutb[2].lines[g].tag==radrr[2][31:LOBIT]) && (vbito2a[g]==1'b1);
301
                always_ff @(posedge ch3clk)     hit3a[g] = (doutb[3].lines[g].tag==radrr[3][31:LOBIT]) && (vbito3a[g]==1'b1);
302
                always_ff @(posedge ch4clk)     hit4a[g] = (doutb[4].lines[g].tag==radrr[4][31:LOBIT]) && (vbito4a[g]==1'b1);
303
                always_ff @(posedge ch5clk)     hit5a[g] = (doutb[5].lines[g].tag==radrr[5][31:LOBIT]) && (vbito5a[g]==1'b1);
304
                always_ff @(posedge ch6clk)     hit6a[g] = (doutb[6].lines[g].tag==radrr[6][31:LOBIT]) && (vbito6a[g]==1'b1);
305
                always_ff @(posedge ch7clk)     hit7a[g] = (doutb[7].lines[g].tag==radrr[7][31:LOBIT]) && (vbito7a[g]==1'b1);
306
                always_ff @(posedge wclk)       hit8a[g] = (doutb[8].lines[g].tag==radrr[8][31:LOBIT]) && (vbito8a[g]==1'b1);
307 5 robfinch
        end
308
        always_comb ch0o.ack = (|hit0a & stb0) | (ch0wack & stb0);
309
        always_comb ch1o.ack = (|hit1a & stb1) | (ch1wack & stb1);
310
        always_comb ch2o.ack = (|hit2a & stb2) | (ch2wack & stb2);
311
        always_comb ch3o.ack = (|hit3a & stb3) | (ch3wack & stb3);
312
        always_comb ch4o.ack = (|hit4a & stb4) | (ch4wack & stb4);
313
        always_comb ch5o.ack = (|hit5a & stb5) | (ch5wack & stb5);
314
        always_comb ch6o.ack = (|hit6a & stb6) | (ch6wack & stb6);
315
        always_comb ch7o.ack = (|hit7a & stb7) | (ch7wack & stb7);
316
        always_comb ch0o.err = 1'b0;
317
        always_comb ch1o.err = 1'b0;
318
        always_comb ch2o.err = 1'b0;
319
        always_comb ch3o.err = 1'b0;
320
        always_comb ch4o.err = 1'b0;
321
        always_comb ch5o.err = 1'b0;
322
        always_comb ch6o.err = 1'b0;
323
        always_comb ch7o.err = 1'b0;
324
        always_comb ch0o.rty = 1'b0;
325
        always_comb ch1o.rty = 1'b0;
326
        always_comb ch2o.rty = 1'b0;
327
        always_comb ch3o.rty = 1'b0;
328
        always_comb ch4o.rty = 1'b0;
329
        always_comb ch5o.rty = 1'b0;
330
        always_comb ch6o.rty = 1'b0;
331
        always_comb ch7o.rty = 1'b0;
332
        always_comb ch0o.cid = ch0i.cid;
333
        always_comb ch1o.cid = ch1i.cid;
334
        always_comb ch2o.cid = ch2i.cid;
335
        always_comb ch3o.cid = ch3i.cid;
336
        always_comb ch4o.cid = ch4i.cid;
337
        always_comb ch5o.cid = ch5i.cid;
338
        always_comb ch6o.cid = ch6i.cid;
339
        always_comb ch7o.cid = ch7i.cid;
340
end
341
endgenerate
342
 
343
always_comb wway = hit8a[0] ? 2'd0 : hit8a[1] ? 2'd1 : hit8a[2] ? 2'd2 : hit8a[3] ? 2'd3 : 2'd0;
344
 
345
always_comb
346
begin
347
        ch0o.dat <= 'd0;
348
        ch1o.dat <= 'd0;
349
        ch2o.dat <= 'd0;
350
        ch3o.dat <= 'd0;
351
        ch4o.dat <= 'd0;
352
        ch5o.dat <= 'd0;
353
        ch6o.dat <= 'd0;
354
        ch7o.dat <= 'd0;
355
        wrdata <= 'd0;
356
        for (n2 = 0; n2 < CACHE_ASSOC; n2 = n2 + 1) begin
357
                if (hit0a[n2]) ch0o.dat <= doutb[0].lines[n2];
358
                if (hit1a[n2]) ch1o.dat <= doutb[1].lines[n2];
359
                if (hit2a[n2]) ch2o.dat <= doutb[2].lines[n2];
360
                if (hit3a[n2]) ch3o.dat <= doutb[3].lines[n2];
361
                if (hit4a[n2]) ch4o.dat <= doutb[4].lines[n2];
362
                if (hit5a[n2]) ch5o.dat <= doutb[5].lines[n2];
363
                if (hit6a[n2]) ch6o.dat <= doutb[6].lines[n2];
364
                if (hit7a[n2]) ch7o.dat <= doutb[7].lines[n2];
365
        end
366
//      if (|hit8a)
367
                wrdata <= doutb[8];
368
end
369
 
370
reg b0,b1,b2;
371
reg ldcycd1,ldcycd2;
372
always_ff @(posedge wclk)
373
        ldcycd1 <= ld.cyc;
374
always_ff @(posedge wclk)
375
        ldcycd2 <= ldcycd1;
376 10 robfinch
 
377 5 robfinch
always_ff @(posedge wclk)
378
if (rst) begin
379
        for (n = 0; n < 4; n = n + 1)
380
                vbit[n] <= 'b0;
381
end
382
else begin
383
        if (ldcycd2) begin
384
                vbit[0][wadr2[HIBIT:LOBIT]] <= 1'b1;
385
                vbit[1][wadr2[HIBIT:LOBIT]] <= b0;
386
                vbit[2][wadr2[HIBIT:LOBIT]] <= b1;
387
                vbit[3][wadr2[HIBIT:LOBIT]] <= b2;
388
        end
389
        if (ldcycd1) begin
390
                b0 <= vbit[0][wadr[HIBIT:LOBIT]];
391
                b1 <= vbit[1][wadr[HIBIT:LOBIT]];
392
                b2 <= vbit[2][wadr[HIBIT:LOBIT]];
393
        end
394 7 robfinch
        if (|hit8a & |wchi_sel & wchi_stb & wchi.we & ~(ld.cyc|ldcycd1|ldcycd2))
395 5 robfinch
                vbit[wway][wadr[HIBIT:LOBIT]] <= 1'b1;
396
        else if (inv)
397
                vbit[wway][wadr[HIBIT:LOBIT]] <= 1'b0;
398
end
399
 
400
// Update the cache only if there was a write hit or if loading the cache line
401
// due to a read miss. For a read miss the entire line is updated, otherwise
402
// just the part of the line relevant to the write is updated.
403
always_ff @(posedge wclk)
404
begin
405
        if (ld.cyc)
406
                wadr <= ld.adr;
407 8 robfinch
        else if (wchi.stb)
408
                wadr <= wchi.adr;
409 5 robfinch
end
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 8 robfinch
always_ff @(posedge wclk)
417
        wstrb <= ldcycd2 | (wchi_stb & |hit8a & wchi.we);
418 5 robfinch
 
419
// Merge write data into cache line.
420
// For a load due to a read miss the entire line is updated.
421
// For a write hit, just the portion of the line corresponding to the hit is
422
// updated.
423
reg [18:0] t0,t1,t2;
424
reg m0,m1,m2;
425
generate begin : gWrData
426
        // LRU update
427
        always_ff @(posedge wclk)
428
        begin
429
                if (ldcycd2) begin
430 9 robfinch
                        wdata.lines[0].tag <= wadr2[31:LOBIT];                  // set tag
431 5 robfinch
                        wdata.lines[1].tag <= t0;
432
                        wdata.lines[2].tag <= t1;
433
                        wdata.lines[3].tag <= t2;
434 9 robfinch
                        wdata.lines[0].modified <= 1'b0;                                                // clear modified flags
435 5 robfinch
                        wdata.lines[1].modified <= m0;
436
                        wdata.lines[2].modified <= m1;
437
                        wdata.lines[3].modified <= m2;
438
                end
439
                if (ldcycd1) begin
440
                        t0 <= wrdata.lines[0].tag;
441
                        t1 <= wrdata.lines[1].tag;
442
                        t2 <= wrdata.lines[2].tag;
443
                        m0 <= wrdata.lines[0].modified;
444
                        m1 <= wrdata.lines[1].modified;
445
                        m2 <= wrdata.lines[2].modified;
446
                end
447
                if (!(ld.cyc|ldcycd1|ldcycd2)) begin
448 7 robfinch
                        if (wchi_stb & hit8a[0] & wchi.we)
449 5 robfinch
                                wdata.lines[0].modified <= 1'b1;
450
                        else
451
                                wdata.lines[0].modified <= wrdata.lines[0].modified;
452 7 robfinch
                        if (wchi_stb & hit8a[1] & wchi.we)
453 5 robfinch
                                wdata.lines[1].modified <= 1'b1;
454
                        else
455 7 robfinch
                                wdata.lines[1].modified <= wrdata.lines[1].modified;
456
                        if (wchi_stb & hit8a[2] & wchi.we)
457 5 robfinch
                                wdata.lines[2].modified <= 1'b1;
458
                        else
459 7 robfinch
                                wdata.lines[2].modified <= wrdata.lines[2].modified;
460
                        if (wchi_stb & hit8a[3] & wchi.we)
461 5 robfinch
                                wdata.lines[3].modified <= 1'b1;
462
                        else
463 7 robfinch
                                wdata.lines[3].modified <= wrdata.lines[3].modified;
464 5 robfinch
                        // Tag stays the same, it was hit
465
                        wdata.lines[0].tag <= wrdata.lines[0].tag;
466
                        wdata.lines[1].tag <= wrdata.lines[1].tag;
467
                        wdata.lines[2].tag <= wrdata.lines[2].tag;
468
                        wdata.lines[3].tag <= wrdata.lines[3].tag;
469
                end
470
        end
471
        for (g = 0; g < 16; g = g + 1)
472
        always_ff @(posedge wclk)
473
                begin
474
                        if (ldcycd2) begin
475
        //                      wdata <= wrdata << $bits(mpmc10_cache_line_t);
476
                                wdata.lines[0].data[g*8+7:g*8] <= lddat2[g*8+7:g*8];            // set data
477
                                wdata.lines[1].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
478
                                wdata.lines[2].data[g*8+7:g*8] <= wrdata.lines[1].data[g*8+7:g*8];
479
                                wdata.lines[3].data[g*8+7:g*8] <= wrdata.lines[2].data[g*8+7:g*8];
480
                        end
481
                        if (!(ld.cyc|ldcycd1|ldcycd2)) begin
482 7 robfinch
                                if (wchi_stb & hit8a[0] & wchi.we)
483 5 robfinch
                                        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];
484
                                else
485
                                        wdata.lines[0].data[g*8+7:g*8] <= wrdata.lines[0].data[g*8+7:g*8];
486 7 robfinch
                                if (wchi_stb & hit8a[1] & wchi.we)
487 5 robfinch
                                        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];
488
                                else
489 7 robfinch
                                        wdata.lines[1].data[g*8+7:g*8] <= wrdata.lines[1].data[g*8+7:g*8];
490
                                if (wchi_stb & hit8a[2] & wchi.we)
491 5 robfinch
                                        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];
492
                                else
493 7 robfinch
                                        wdata.lines[2].data[g*8+7:g*8] <= wrdata.lines[2].data[g*8+7:g*8];
494
                                if (wchi_stb & hit8a[3] & wchi.we)
495 5 robfinch
                                        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];
496
                                else
497 7 robfinch
                                        wdata.lines[3].data[g*8+7:g*8] <= wrdata.lines[3].data[g*8+7:g*8];
498 5 robfinch
                        end
499
                end
500
end
501
endgenerate
502
 
503
// Writes take two clock cycles, 1 to read the RAM and find out if it is a
504
// write hit and a second clock to write the data. The write cycle may be
505
// delayed by a cycle due to a load.
506
reg wack;
507
always_ff @(posedge wclk)
508
if (rst)
509
        wack <= 1'b0;
510
else begin
511
        wack <= 1'b0;
512 9 robfinch
        if (wchi_stb & ~ld.stb & wchi.we)
513 5 robfinch
                wack <= 1'b1;
514
end
515
assign wcho.ack = wack & wchi.stb;
516
 
517
endmodule

powered by: WebSVN 2.1.0

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