diff --git a/rtl/letc/core/letc_core_cache.sv b/rtl/letc/core/letc_core_cache.sv index d655793..be00233 100644 --- a/rtl/letc/core/letc_core_cache.sv +++ b/rtl/letc/core/letc_core_cache.sv @@ -87,23 +87,38 @@ end //The refilling FSM is the only thing that needs to write to the SRAM, and //the stage using the cache only needs to read it! (with tag comparison also being snooped by the //refilling FSM) -logic cache_line_wen; index_t cache_write_index; -logic [WORD_WIDTH:0] cache_line_wben; +logic [CACHE_LINE_WORDS-1:0] cache_line_wben; cache_line_s cache_line_to_write, cache_line_to_read; amd_lutram #( .DEPTH (CACHE_DEPTH), .BWIDTH(WORD_WIDTH), - .DWIDTH($bits(cache_line_s)) -) sram ( + .DWIDTH($bits(cache_line_s) - $bits(tag_t)) //just storing the data words now +) data_sram ( .i_wclk(i_clk), - .i_wen(cache_line_wen), + .i_wen(axi_fsm_limp.ready), .i_waddr(cache_write_index), .i_wben(cache_line_wben), - .i_wdata(cache_line_to_write), + .i_wdata(cache_line_to_write.data), .i_raddr(stage_index), - .o_rdata(cache_line_to_read) + .o_rdata(cache_line_to_read.data) +); + +logic tag_wen; +amd_lutram #( + .DEPTH (CACHE_DEPTH), + .BWIDTH($bits(tag_t)), + .DWIDTH($bits(tag_t)) +) tags_sram ( + .i_wclk(i_clk), + .i_wen(tag_wen), + .i_waddr(cache_write_index), + .i_wben('1), + .i_wdata(cache_line_to_write.tag), + + .i_raddr(stage_index), + .o_rdata(cache_line_to_read.tag) ); //Valid Flops @@ -114,13 +129,11 @@ always_ff @(posedge i_clk) begin end else begin if (i_flush_cache) begin cache_line_valid <= '0; - end else if (cache_line_wen) begin + end else if (axi_fsm_limp.ready) begin //data ready from the axi fsm means the cache line is being written //Since this is a write-through cache, and there is no need to invalidate lines //for cache coherency for example, the only time a cache line can //become valid is when we write to it; and then it can never become invalid //again until the cache is flushed! - //when a line is evicted, the line that took its place is also - //valid. cache_line_valid[cache_write_index] <= 1'b1; end end @@ -161,55 +174,130 @@ end * Line Refilling FSM and Write Logic * --------------------------------------------------------------------------------------------- */ -//TODO implement this -//------fsm pseudocode--------// -//state 1: idle. -// if request: - // next_state = compare tag -// else: - // next_state = idle -//state 2: compare tag. -// (address splitting exposes correct cache line) -// (hit logic compares tag) -// if hit: - // stage_limp.ready = 1 - // next_state = idle -// else: - // axi_fsm_limp.addr = stage_limp.addr //does this need to be flopped? - // axi_fsm_limp.valid = 1 - // cache_line_wben = 1 - // next_state = refill -//state 3: refill 1 -// if axi_fsm_limp.ready: - // cache_line_wen = 1 - // next_state = refill 2 -// else: - // next_state = refill 1 -//state 4: refill 2 - // cache_line_wen = 0 - // cache_line_wben <<= 1 //how to ensure a shift register is inferred? - // axi_fsm_limp.addr += 4 - // next_state = refill 3 -//state 5: refill 3 -// if cache_line_wben == (1<