RVSCC/rtl/two_way_lru_cru.sv

38 lines
982 B
Systemverilog
Raw Normal View History

`include "timescale.sv"
2023-01-01 22:28:56 +00:00
module two_way_lru_cru #(
2023-02-28 17:22:02 +00:00
parameter int ADDR_SIZE = 32,
parameter int NUM_SETS = 16,
parameter int BLOCK_SIZE = 32
2023-01-01 22:28:56 +00:00
) (
2023-02-28 17:22:02 +00:00
input logic clk,
input logic rst,
input logic [ADDR_SIZE - 1:0] addr,
2023-01-01 22:28:56 +00:00
input logic replace,
output logic preferred
);
2023-02-28 17:22:02 +00:00
localparam int NumBlocksBytes = BLOCK_SIZE / 4;
localparam int ByteOffsetSize = $clog2(NumBlocksBytes);
2023-03-02 19:56:34 +00:00
localparam int SetSize = $clog2(NUM_SETS);
localparam int TagSize = ADDR_SIZE - SetSize - ByteOffsetSize;
2023-02-28 17:22:02 +00:00
typedef struct packed {
logic [ByteOffsetSize - 1:0] byte_offset;
2023-03-20 04:13:34 +00:00
logic [SetSize - 1:0] xset;
2023-02-28 17:22:02 +00:00
logic [TagSize - 1:0] tag;
} cache_addr_t;
cache_addr_t packed_addr;
assign packed_addr = cache_addr_t'(addr);
logic [NUM_SETS - 1:0] lru;
2023-03-20 04:13:34 +00:00
assign preferred = lru[packed_addr.xset];
2023-02-28 17:22:02 +00:00
always_ff @(posedge clk) begin
2023-03-18 23:45:55 +00:00
if (rst) lru <= 'd0;
2023-02-28 17:22:02 +00:00
else if (replace) begin
2023-03-20 04:13:34 +00:00
lru[packed_addr.xset] <= !lru[packed_addr.xset];
2023-01-01 22:28:56 +00:00
end
2023-02-28 17:22:02 +00:00
end
2023-01-01 22:28:56 +00:00
endmodule