1 /* 16 cache entries, 64-byte long cache lines */
6 /* ARM core interface */
10 output reg [31:0] rd_data,
15 output reg [31:0] bus_addr,
16 input [31:0] bus_rdata,
17 output wire [31:0] bus_wdata,
25 /* [31 tag 10] [9 cache index 6] [5 data index 0]
26 * so the data index is 6 bits long
27 * so the cache index is 4 bits long
28 * so the tag is 22 bits long. c.c
31 reg cache_valid [15:0];
32 reg [21:0] cache_tags [15:0];
33 reg [31:0] cache_data [255:0 /* {line, word} */]; //synthesis attribute ram_style of cache_data is distributed
37 for (i = 0; i < 16; i = i + 1)
39 cache_valid[i[3:0]] = 0;
40 cache_tags[i[3:0]] = 0;
43 wire [5:0] rd_didx = rd_addr[5:0];
44 wire [3:0] rd_didx_word = rd_didx[5:2];
45 wire [3:0] rd_idx = rd_addr[9:6];
46 wire [21:0] rd_tag = rd_addr[31:10];
48 reg [31:0] prev_rd_addr = 32'hFFFFFFFF;
50 wire cache_hit = cache_valid[rd_idx] && (cache_tags[rd_idx] == rd_tag);
52 reg [3:0] cache_fill_pos = 0;
53 assign bus_req = rd_req && !cache_hit; /* xxx, needed for Verilator */
55 if (rd_req && !cache_hit && bus_ack) begin
56 bus_addr = {rd_addr[31:6], cache_fill_pos[3:0], 2'b00 /* reads are 32-bits */};
63 wire [31:0] curdata = cache_data[{rd_idx,rd_didx_word}];
65 rd_wait = rd_req && !cache_hit;
69 always @(posedge clk) begin
70 prev_rd_addr <= {rd_addr[31:6], 6'b0};
71 if (cache_fill_pos != 0 && ((prev_rd_addr != {rd_addr[31:6], 6'b0}) || cache_hit)) /* If this wasn't from the same line, or we've moved on somehow, reset the fill circuitry. */
73 else if (rd_req && !cache_hit && bus_ack && bus_ready) begin
74 $display("ICACHE: FILL: rd addr %08x; bus addr %08x; bus data %08x", rd_addr, bus_addr, bus_rdata);
75 cache_data[{rd_idx,cache_fill_pos}] <= bus_rdata;
76 cache_fill_pos <= cache_fill_pos + 1;
77 if (cache_fill_pos == 15) begin /* Done? */
78 cache_tags[rd_idx] <= rd_tag;
79 cache_valid[rd_idx] <= 1;
80 $display("ICACHE: Fill complete for line %x, tag %x", rd_idx, rd_tag);
82 cache_valid[rd_idx] <= 0;