RVSCC/rtl/two_way_lru_cache.sv

76 lines
1.9 KiB
Systemverilog
Raw Normal View History

`include "timescale.sv"
2023-01-01 22:28:56 +00:00
module two_way_lru_cache #(
2023-02-28 17:22:02 +00:00
parameter int ADDR_SIZE = 32,
parameter int NUM_SETS = 16,
parameter int BLOCK_SIZE = 32
) (
2023-03-18 23:45:55 +00:00
data_memory_if.cache data_mem_if
2023-01-01 22:28:56 +00:00
);
2023-02-28 17:22:02 +00:00
localparam int NumWays = 2;
localparam int NumBlockBytes = BLOCK_SIZE / 4;
2023-03-02 19:56:34 +00:00
localparam int ByteOffsetSize = $clog2(NumBlockBytes);
localparam int WaySize = $clog2(NumWays);
2023-02-28 17:22:02 +00:00
localparam int SetSize = $clog2(NUM_SETS);
2023-03-02 19:56:34 +00:00
localparam int TagSize = ADDR_SIZE - SetSize - ByteOffsetSize;
2023-02-28 17:22:02 +00:00
2023-03-02 19:56:34 +00:00
logic [$clog2(NumWays) - 1:0] populate_way;
logic read_valid;
2023-02-28 17:22:02 +00:00
2023-03-02 19:56:34 +00:00
logic [WaySize - 1:0] way;
2023-03-20 04:13:34 +00:00
logic [SetSize - 1:0] xset;
2023-03-02 19:56:34 +00:00
logic [TagSize - 1:0] tag;
2023-02-28 17:22:02 +00:00
2023-03-20 04:13:34 +00:00
logic write_way;
logic populated;
2023-02-28 17:22:02 +00:00
cache_memory #(
.ADDR_SIZE (ADDR_SIZE),
.NUM_SETS (NUM_SETS),
.NUM_WAYS (NumWays),
.BLOCK_SIZE(BLOCK_SIZE)
) cache_memory (
2023-03-18 23:45:55 +00:00
.clk(data_mem_if.clk),
.rst(data_mem_if.rst),
2023-03-02 19:56:34 +00:00
.write_way(write_way),
2023-03-20 04:13:34 +00:00
.set(xset),
2023-02-28 17:22:02 +00:00
.tag(tag),
2023-03-18 23:45:55 +00:00
.write_enable(data_mem_if.write_enable),
.write_data(data_mem_if.write_data),
.read_data(data_mem_if.read_data),
2023-03-02 19:56:34 +00:00
.populate_way(populate_way),
2023-03-18 23:45:55 +00:00
.populated(populated),
.hit(data_mem_if.hit)
2023-02-28 17:22:02 +00:00
);
2023-03-20 04:13:34 +00:00
logic cru_enable;
logic replace_preferred_way;
2023-02-28 17:22:02 +00:00
two_way_lru_cru #(
.ADDR_SIZE (ADDR_SIZE),
.NUM_SETS (NUM_SETS),
2023-03-02 19:56:34 +00:00
.BLOCK_SIZE(BLOCK_SIZE)
2023-02-28 17:22:02 +00:00
) cache_replace_unit (
2023-03-18 23:45:55 +00:00
.clk(data_mem_if.clk),
.rst(data_mem_if.rst),
.addr(data_mem_if.addr),
2023-02-28 17:22:02 +00:00
.replace(cru_enable),
.preferred(replace_preferred_way)
);
cache_controller #(
.ADDR_SIZE (ADDR_SIZE),
.NUM_SETS (NUM_SETS),
2023-03-02 19:56:34 +00:00
.NUM_WAYS (NumWays),
2023-02-28 17:22:02 +00:00
.BLOCK_SIZE(BLOCK_SIZE)
) cache_controller (
2023-03-18 23:45:55 +00:00
.addr(data_mem_if.addr),
.write_enable(data_mem_if.write_enable),
2023-02-28 17:22:02 +00:00
.replace_way(replace_preferred_way),
2023-03-02 19:56:34 +00:00
.populate_way(populate_way),
2023-03-18 23:45:55 +00:00
.populated(populated),
2023-03-02 19:56:34 +00:00
.cru_enable(cru_enable),
.write_way(write_way),
2023-03-20 04:13:34 +00:00
.set(xset),
2023-03-02 19:56:34 +00:00
.tag(tag)
2023-02-28 17:22:02 +00:00
);
2023-01-01 22:28:56 +00:00
endmodule