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
) (
input logic clk,
input logic rst,
input logic [ADDR_SIZE - 1:0] addr,
2023-01-01 22:28:56 +00:00
input logic write_enable,
2023-02-28 17:22:02 +00:00
input logic [BLOCK_SIZE - 1:0] write_data,
output logic [BLOCK_SIZE - 1:0] read_data,
2023-01-01 22:28:56 +00:00
output logic hit
);
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;
logic [SetSize - 1:0] set;
logic [TagSize - 1:0] tag;
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 (
.clk(clk),
.rst(rst),
2023-03-02 19:56:34 +00:00
.write_way(write_way),
2023-02-28 17:22:02 +00:00
.set(set),
.tag(tag),
.write_enable(write_enable),
.write_data(write_data),
.read_data(read_data),
2023-03-02 19:56:34 +00:00
.populate_way(populate_way),
.hit(hit)
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 (
.clk(clk),
.rst(rst),
.addr(addr),
.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 (
.addr(addr),
.write_enable(write_enable),
.replace_way(replace_preferred_way),
2023-03-02 19:56:34 +00:00
.populate_way(populate_way),
.cru_enable(cru_enable),
.write_way(write_way),
2023-02-28 17:22:02 +00:00
.set(set),
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