Parameterization working
This commit is contained in:
96
rtl/cache/VX_Cache_Bank.v
vendored
96
rtl/cache/VX_Cache_Bank.v
vendored
@@ -7,12 +7,30 @@
|
||||
|
||||
|
||||
module VX_Cache_Bank
|
||||
/*#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8
|
||||
)*/
|
||||
#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8,
|
||||
parameter LOG_NUM_BANKS = 3,
|
||||
parameter NUM_REQ = 8,
|
||||
parameter LOG_NUM_REQ = 3,
|
||||
parameter NUM_IND = 8,
|
||||
parameter CACHE_WAY_INDEX = 1,
|
||||
parameter NUM_WORDS_PER_BLOCK = 4,
|
||||
parameter OFFSET_SIZE_START = 0,
|
||||
parameter OFFSET_SIZE_END = 1,
|
||||
parameter TAG_SIZE_START = 0,
|
||||
parameter TAG_SIZE_END = 16,
|
||||
parameter IND_SIZE_START = 0,
|
||||
parameter IND_SIZE_END = 7,
|
||||
parameter ADDR_TAG_START = 15,
|
||||
parameter ADDR_TAG_END = 31,
|
||||
parameter ADDR_OFFSET_START = 5,
|
||||
parameter ADDR_OFFSET_END = 6,
|
||||
parameter ADDR_IND_START = 7,
|
||||
parameter ADDR_IND_END = 14
|
||||
)
|
||||
(
|
||||
clk,
|
||||
rst,
|
||||
@@ -58,25 +76,25 @@ module VX_Cache_Bank
|
||||
//input wire write_from_mem;
|
||||
|
||||
// Reading Data
|
||||
input wire[`DCACHE_IND_SIZE_RNG] actual_index;
|
||||
input wire[IND_SIZE_END:IND_SIZE_START] actual_index;
|
||||
|
||||
|
||||
input wire[`DCACHE_TAG_SIZE_RNG] o_tag; // When write_from_mem = 1, o_tag is the new tag
|
||||
input wire[`DCACHE_OFFSET_SIZE_RNG] block_offset;
|
||||
input wire[TAG_SIZE_END:TAG_SIZE_START] o_tag; // When write_from_mem = 1, o_tag is the new tag
|
||||
input wire[OFFSET_SIZE_END:OFFSET_SIZE_START] block_offset;
|
||||
|
||||
|
||||
input wire[31:0] writedata;
|
||||
input wire valid_in;
|
||||
input wire read_or_write; // Specifies if it is a read or write operation
|
||||
|
||||
input wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] fetched_writedata;
|
||||
input wire[NUM_WORDS_PER_BLOCK-1:0][31:0] fetched_writedata;
|
||||
input wire[2:0] i_p_mem_read;
|
||||
input wire[2:0] i_p_mem_write;
|
||||
input wire[1:0] byte_select;
|
||||
|
||||
|
||||
input wire[`DCACHE_WAY_INDEX-1:0] evicted_way;
|
||||
output wire[`DCACHE_WAY_INDEX-1:0] way_use;
|
||||
input wire[CACHE_WAY_INDEX-1:0] evicted_way;
|
||||
output wire[CACHE_WAY_INDEX-1:0] way_use;
|
||||
|
||||
// Outputs
|
||||
// Normal shit
|
||||
@@ -89,13 +107,13 @@ module VX_Cache_Bank
|
||||
output wire[31:0] eviction_addr; // What's the eviction tag
|
||||
|
||||
// Eviction Data (Extraction)
|
||||
output wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_evicted;
|
||||
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_evicted;
|
||||
|
||||
|
||||
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_use;
|
||||
wire[`DCACHE_TAG_SIZE_RNG] tag_use;
|
||||
wire[`DCACHE_TAG_SIZE_RNG] eviction_tag;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use;
|
||||
wire[TAG_SIZE_END:TAG_SIZE_START] tag_use;
|
||||
wire[TAG_SIZE_END:TAG_SIZE_START] eviction_tag;
|
||||
wire valid_use;
|
||||
wire dirty_use;
|
||||
wire access;
|
||||
@@ -104,8 +122,8 @@ module VX_Cache_Bank
|
||||
|
||||
|
||||
|
||||
wire[`DCACHE_WAY_INDEX-1:0] update_way;
|
||||
wire[`DCACHE_WAY_INDEX-1:0] way_to_update;
|
||||
wire[CACHE_WAY_INDEX-1:0] update_way;
|
||||
wire[CACHE_WAY_INDEX-1:0] way_to_update;
|
||||
|
||||
assign miss = (tag_use != o_tag) && valid_use && valid_in;
|
||||
|
||||
@@ -181,10 +199,10 @@ module VX_Cache_Bank
|
||||
wire[3:0] sh_mask = (b0 ? 4'b0011 : 4'b1100);
|
||||
|
||||
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][3:0] we;
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_write;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][3:0] we;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write;
|
||||
genvar g;
|
||||
for (g = 0; g < `DCACHE_NUM_WORDS_PER_BLOCK; g = g + 1) begin
|
||||
for (g = 0; g < NUM_WORDS_PER_BLOCK; g = g + 1) begin
|
||||
wire normal_write = (read_or_write && ((access && (block_offset == g))) && !miss);
|
||||
|
||||
assign we[g] = (write_from_mem) ? 4'b1111 :
|
||||
@@ -200,13 +218,15 @@ module VX_Cache_Bank
|
||||
end
|
||||
|
||||
|
||||
/*VX_cache_data_per_index #(
|
||||
.CACHE_SIZE(CACHE_SIZE),
|
||||
.CACHE_WAYS(CACHE_WAYS),
|
||||
.CACHE_BLOCK(CACHE_BLOCK),
|
||||
.CACHE_BANKS(CACHE_BANKS),
|
||||
.NUM_WORDS_PER_BLOCK(NUM_WORDS_PER_BLOCK)) data_structures(*/
|
||||
VX_cache_data_per_index data_structures(
|
||||
VX_cache_data_per_index #(
|
||||
.CACHE_WAYS (CACHE_WAYS),
|
||||
.NUM_IND (NUM_IND),
|
||||
.CACHE_WAY_INDEX (CACHE_WAY_INDEX),
|
||||
.NUM_WORDS_PER_BLOCK(NUM_WORDS_PER_BLOCK),
|
||||
.TAG_SIZE_START (TAG_SIZE_START),
|
||||
.TAG_SIZE_END (TAG_SIZE_END),
|
||||
.IND_SIZE_START (IND_SIZE_START),
|
||||
.IND_SIZE_END (IND_SIZE_END)) data_structures(
|
||||
.clk (clk),
|
||||
.rst (rst),
|
||||
.valid_in (valid_in),
|
||||
@@ -225,26 +245,6 @@ module VX_Cache_Bank
|
||||
.way (way_use)
|
||||
);
|
||||
|
||||
// VX_cache_data #(
|
||||
// .CACHE_SIZE(CACHE_SIZE),
|
||||
// .CACHE_WAYS(CACHE_WAYS),
|
||||
// .CACHE_BLOCK(CACHE_BLOCK),
|
||||
// .CACHE_BANKS(CACHE_BANKS),
|
||||
// .NUM_WORDS_PER_BLOCK(NUM_WORDS_PER_BLOCK)) data_structures(
|
||||
// .clk (clk),
|
||||
// .rst (rst),
|
||||
// // Inputs
|
||||
// .addr (actual_index),
|
||||
// .we (we),
|
||||
// .evict (write_from_mem),
|
||||
// .data_write(data_write),
|
||||
// .tag_write (o_tag),
|
||||
// // Outputs
|
||||
// .tag_use (tag_use),
|
||||
// .data_use (data_use),
|
||||
// .valid_use (valid_use),
|
||||
// .dirty_use (dirty_use)
|
||||
// );
|
||||
|
||||
|
||||
endmodule
|
||||
|
||||
50
rtl/cache/VX_cache_bank_valid.v
vendored
50
rtl/cache/VX_cache_bank_valid.v
vendored
@@ -1,24 +1,26 @@
|
||||
`include "../VX_define.v"
|
||||
|
||||
module VX_cache_bank_valid
|
||||
#(
|
||||
parameter NUMBER_BANKS = 0
|
||||
)
|
||||
(
|
||||
input wire [`NT_M1:0] i_p_valid,
|
||||
input wire [`NT_M1:0][31:0] i_p_addr,
|
||||
output reg [NUMBER_BANKS - 1 : 0][`NT_M1:0] thread_track_banks
|
||||
);
|
||||
|
||||
generate
|
||||
integer t_id;
|
||||
always @(*) begin
|
||||
thread_track_banks = 0;
|
||||
for (t_id = 0; t_id <= `NT_M1; t_id = t_id + 1)
|
||||
begin
|
||||
thread_track_banks[i_p_addr[t_id][2+$clog2(NUMBER_BANKS)-1:2]][t_id] = i_p_valid[t_id];
|
||||
end
|
||||
end
|
||||
endgenerate
|
||||
|
||||
endmodule
|
||||
`include "../VX_define.v"
|
||||
|
||||
module VX_cache_bank_valid
|
||||
#(
|
||||
parameter NUMBER_BANKS = 8,
|
||||
parameter LOG_NUM_BANKS = 3,
|
||||
parameter NUM_REQ = 1
|
||||
)
|
||||
(
|
||||
input wire [NUM_REQ-1:0] i_p_valid,
|
||||
input wire [NUM_REQ-1:0][31:0] i_p_addr,
|
||||
output reg [NUMBER_BANKS - 1 : 0][`NT_M1:0] thread_track_banks
|
||||
);
|
||||
|
||||
generate
|
||||
integer t_id;
|
||||
always @(*) begin
|
||||
thread_track_banks = 0;
|
||||
for (t_id = 0; t_id < NUM_REQ; t_id = t_id + 1)
|
||||
begin
|
||||
thread_track_banks[i_p_addr[t_id][2+LOG_NUM_BANKS-1:2]][t_id] = i_p_valid[t_id];
|
||||
end
|
||||
end
|
||||
endgenerate
|
||||
|
||||
endmodule
|
||||
|
||||
49
rtl/cache/VX_cache_data.v
vendored
49
rtl/cache/VX_cache_data.v
vendored
@@ -3,29 +3,30 @@
|
||||
`include "../VX_define.v"
|
||||
|
||||
module VX_cache_data
|
||||
/*#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8,
|
||||
parameter NUM_WORDS_PER_BLOCK = 4
|
||||
)*/
|
||||
#(
|
||||
parameter NUM_IND = 8,
|
||||
parameter NUM_WORDS_PER_BLOCK = 4,
|
||||
parameter TAG_SIZE_START = 0,
|
||||
parameter TAG_SIZE_END = 16,
|
||||
parameter IND_SIZE_START = 0,
|
||||
parameter IND_SIZE_END = 7
|
||||
)
|
||||
(
|
||||
input wire clk, rst, // Clock
|
||||
|
||||
// `ifdef PARAM
|
||||
// Addr
|
||||
input wire[`DCACHE_IND_SIZE_RNG] addr,
|
||||
input wire[IND_SIZE_END:IND_SIZE_START] addr,
|
||||
// WE
|
||||
input wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][3:0] we,
|
||||
input wire[NUM_WORDS_PER_BLOCK-1:0][3:0] we,
|
||||
input wire evict,
|
||||
// Data
|
||||
input wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_write,
|
||||
input wire[`DCACHE_TAG_SIZE_RNG] tag_write,
|
||||
input wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write,
|
||||
input wire[TAG_SIZE_END:TAG_SIZE_START] tag_write,
|
||||
|
||||
|
||||
output wire[`DCACHE_TAG_SIZE_RNG] tag_use,
|
||||
output wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
|
||||
output wire[TAG_SIZE_END:TAG_SIZE_START] tag_use,
|
||||
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
|
||||
output wire valid_use,
|
||||
output wire dirty_use
|
||||
// `else
|
||||
@@ -50,7 +51,7 @@ module VX_cache_data
|
||||
//localparam NUMBER_BANKS = CACHE_BANKS;
|
||||
//localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS);
|
||||
// localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4);
|
||||
//localparam NUMBER_INDEXES = `DCACHE_NUM_IND;
|
||||
//localparam NUMBER_INDEXES = NUM_IND;
|
||||
|
||||
wire currently_writing = (|we);
|
||||
wire update_dirty = ((!dirty_use) && currently_writing) || (evict);
|
||||
@@ -61,10 +62,10 @@ module VX_cache_data
|
||||
`ifndef SYN
|
||||
|
||||
// (3:0) 4 bytes
|
||||
reg[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][3:0][7:0] data[`DCACHE_NUM_IND-1:0]; // Actual Data
|
||||
reg[`DCACHE_TAG_SIZE_RNG] tag[`DCACHE_NUM_IND-1:0];
|
||||
reg valid[`DCACHE_NUM_IND-1:0];
|
||||
reg dirty[`DCACHE_NUM_IND-1:0];
|
||||
reg[NUM_WORDS_PER_BLOCK-1:0][3:0][7:0] data[NUM_IND-1:0]; // Actual Data
|
||||
reg[TAG_SIZE_END:TAG_SIZE_START] tag[NUM_IND-1:0];
|
||||
reg valid[NUM_IND-1:0];
|
||||
reg dirty[NUM_IND-1:0];
|
||||
|
||||
|
||||
// 16 bytes
|
||||
@@ -77,7 +78,7 @@ module VX_cache_data
|
||||
integer ini_ind;
|
||||
always @(posedge clk, posedge rst) begin : update_all
|
||||
if (rst) begin
|
||||
for (ini_ind = 0; ini_ind < `DCACHE_NUM_IND; ini_ind=ini_ind+1) begin
|
||||
for (ini_ind = 0; ini_ind < NUM_IND; ini_ind=ini_ind+1) begin
|
||||
data[ini_ind] <= 0;
|
||||
tag[ini_ind] <= 0;
|
||||
valid[ini_ind] <= 0;
|
||||
@@ -88,7 +89,7 @@ module VX_cache_data
|
||||
if (evict) tag[addr] <= tag_write;
|
||||
if (evict) valid[addr] <= 1;
|
||||
|
||||
for (f = 0; f < `DCACHE_NUM_WORDS_PER_BLOCK; f = f + 1) begin
|
||||
for (f = 0; f < NUM_WORDS_PER_BLOCK; f = f + 1) begin
|
||||
if (we[f][0]) data[addr][f][0] <= data_write[f][7 :0 ];
|
||||
if (we[f][1]) data[addr][f][1] <= data_write[f][15:8 ];
|
||||
if (we[f][2]) data[addr][f][2] <= data_write[f][23:16];
|
||||
@@ -103,11 +104,11 @@ module VX_cache_data
|
||||
wire cena = 1;
|
||||
|
||||
wire cenb_d = (|we);
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] wdata_d = data_write;
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] write_bit_mask_d;
|
||||
wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_out_d;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] wdata_d = data_write;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] write_bit_mask_d;
|
||||
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_out_d;
|
||||
genvar cur_b;
|
||||
for (cur_b = 0; cur_b < `DCACHE_NUM_WORDS_PER_BLOCK; cur_b=cur_b+1) begin
|
||||
for (cur_b = 0; cur_b < NUM_WORDS_PER_BLOCK; cur_b=cur_b+1) begin
|
||||
assign write_bit_mask_d[cur_b] = {32{~we[cur_b]}};
|
||||
end
|
||||
assign data_use = data_out_d;
|
||||
|
||||
78
rtl/cache/VX_cache_data_per_index.v
vendored
78
rtl/cache/VX_cache_data_per_index.v
vendored
@@ -3,33 +3,36 @@
|
||||
`include "../VX_define.v"
|
||||
|
||||
module VX_cache_data_per_index
|
||||
/*#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8,
|
||||
parameter NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4)
|
||||
)*/
|
||||
#(
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter NUM_IND = 8,
|
||||
parameter CACHE_WAY_INDEX = 1,
|
||||
parameter NUM_WORDS_PER_BLOCK = 4,
|
||||
parameter TAG_SIZE_START = 0,
|
||||
parameter TAG_SIZE_END = 16,
|
||||
parameter IND_SIZE_START = 0,
|
||||
parameter IND_SIZE_END = 7
|
||||
)
|
||||
(
|
||||
input wire clk, // Clock
|
||||
input wire rst,
|
||||
input wire valid_in,
|
||||
// Addr
|
||||
input wire[`DCACHE_IND_SIZE_RNG] addr,
|
||||
input wire[IND_SIZE_END:IND_SIZE_START] addr,
|
||||
// WE
|
||||
input wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][3:0] we,
|
||||
input wire[NUM_WORDS_PER_BLOCK-1:0][3:0] we,
|
||||
input wire evict,
|
||||
input wire[`DCACHE_WAY_INDEX-1:0] way_to_update,
|
||||
input wire[CACHE_WAY_INDEX-1:0] way_to_update,
|
||||
// Data
|
||||
input wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_write, // Update Data
|
||||
input wire[`DCACHE_TAG_SIZE_RNG] tag_write,
|
||||
input wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write, // Update Data
|
||||
input wire[TAG_SIZE_END:TAG_SIZE_START] tag_write,
|
||||
|
||||
|
||||
output wire[`DCACHE_TAG_SIZE_RNG] tag_use,
|
||||
output wire[`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
|
||||
output wire[TAG_SIZE_END:TAG_SIZE_START] tag_use,
|
||||
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
|
||||
output wire valid_use,
|
||||
output wire dirty_use,
|
||||
output wire[`DCACHE_WAY_INDEX-1:0] way
|
||||
output wire[CACHE_WAY_INDEX-1:0] way
|
||||
|
||||
);
|
||||
//localparam NUMBER_BANKS = CACHE_BANKS;
|
||||
@@ -37,30 +40,30 @@ module VX_cache_data_per_index
|
||||
// localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4);
|
||||
//localparam NUMBER_INDEXES = `DCACHE_NUM_IND;
|
||||
|
||||
wire [`DCACHE_WAYS-1:0][`DCACHE_TAG_SIZE_RNG] tag_use_per_way;
|
||||
wire [`DCACHE_WAYS-1:0][`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_use_per_way;
|
||||
wire [`DCACHE_WAYS-1:0] valid_use_per_way;
|
||||
wire [`DCACHE_WAYS-1:0] dirty_use_per_way;
|
||||
wire [`DCACHE_WAYS-1:0] hit_per_way;
|
||||
reg [`DCACHE_NUM_IND-1:0][`DCACHE_WAY_INDEX-1:0] eviction_way_index;
|
||||
wire [`DCACHE_WAYS-1:0][`DCACHE_NUM_WORDS_PER_BLOCK-1:0][3:0] we_per_way;
|
||||
wire [`DCACHE_WAYS-1:0][`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] data_write_per_way;
|
||||
wire [`DCACHE_WAYS-1:0] write_from_mem_per_way;
|
||||
wire [CACHE_WAYS-1:0][TAG_SIZE_END:TAG_SIZE_START] tag_use_per_way;
|
||||
wire [CACHE_WAYS-1:0][NUM_WORDS_PER_BLOCK-1:0][31:0] data_use_per_way;
|
||||
wire [CACHE_WAYS-1:0] valid_use_per_way;
|
||||
wire [CACHE_WAYS-1:0] dirty_use_per_way;
|
||||
wire [CACHE_WAYS-1:0] hit_per_way;
|
||||
reg [NUM_IND-1:0][CACHE_WAY_INDEX-1:0] eviction_way_index;
|
||||
wire [CACHE_WAYS-1:0][NUM_WORDS_PER_BLOCK-1:0][3:0] we_per_way;
|
||||
wire [CACHE_WAYS-1:0][NUM_WORDS_PER_BLOCK-1:0][31:0] data_write_per_way;
|
||||
wire [CACHE_WAYS-1:0] write_from_mem_per_way;
|
||||
wire invalid_found;
|
||||
|
||||
wire [`DCACHE_WAY_INDEX-1:0] way_index;
|
||||
wire [`DCACHE_WAY_INDEX-1:0] invalid_index;
|
||||
wire [CACHE_WAY_INDEX-1:0] way_index;
|
||||
wire [CACHE_WAY_INDEX-1:0] invalid_index;
|
||||
|
||||
|
||||
if(`DCACHE_WAYS != 1) begin
|
||||
VX_generic_priority_encoder #(.N(`DCACHE_WAYS)) valid_index
|
||||
if(CACHE_WAYS != 1) begin
|
||||
VX_generic_priority_encoder #(.N(CACHE_WAYS)) valid_index
|
||||
(
|
||||
.valids(~valid_use_per_way),
|
||||
.index (invalid_index),
|
||||
.found (invalid_found)
|
||||
);
|
||||
|
||||
VX_generic_priority_encoder #(.N(`DCACHE_WAYS)) way_indexing
|
||||
VX_generic_priority_encoder #(.N(CACHE_WAYS)) way_indexing
|
||||
(
|
||||
.valids(hit_per_way),
|
||||
.index (way_index),
|
||||
@@ -90,19 +93,20 @@ module VX_cache_data_per_index
|
||||
|
||||
|
||||
genvar ways;
|
||||
for(ways=0; ways < `DCACHE_WAYS; ways = ways + 1) begin
|
||||
for(ways=0; ways < CACHE_WAYS; ways = ways + 1) begin
|
||||
|
||||
assign hit_per_way[ways] = ((valid_use_per_way[ways] == 1'b1) && (tag_use_per_way[ways] == tag_write)) ? 1'b1 : 0;
|
||||
assign we_per_way[ways] = (evict == 1'b1) || (update == 1'b1) ? ((ways == way_to_update) ? (we) : 0) : 0;
|
||||
assign data_write_per_way[ways] = (evict == 1'b1) || (update == 1'b1) ? ((ways == way_to_update) ? data_write : 0) : 0;
|
||||
assign write_from_mem_per_way[ways] = (evict == 1'b1) ? ((ways == way_to_update) ? 1 : 0) : 0;
|
||||
|
||||
/*VX_cache_data #(
|
||||
.CACHE_SIZE(`CACHE_SIZE),
|
||||
.CACHE_WAYS(`DCACHE_WAYS),
|
||||
.CACHE_BLOCK(`CACHE_BLOCK),
|
||||
.CACHE_BANKS(`CACHE_BANKS)) data_structures(*/
|
||||
VX_cache_data data_structures(
|
||||
VX_cache_data #(
|
||||
.NUM_IND (NUM_IND),
|
||||
.NUM_WORDS_PER_BLOCK (NUM_WORDS_PER_BLOCK),
|
||||
.TAG_SIZE_START (TAG_SIZE_START),
|
||||
.TAG_SIZE_END (TAG_SIZE_END),
|
||||
.IND_SIZE_START (IND_SIZE_START),
|
||||
.IND_SIZE_END (IND_SIZE_END)) data_structures(
|
||||
.clk (clk),
|
||||
.rst (rst),
|
||||
// Inputs
|
||||
@@ -124,7 +128,7 @@ module VX_cache_data_per_index
|
||||
eviction_way_index <= 0;
|
||||
end else begin
|
||||
if(miss && dirty_use && valid_use && !evict && valid_in) begin // can be either evict or invalid cache entries
|
||||
if((eviction_way_index[addr]+1) == `DCACHE_WAYS) begin
|
||||
if((eviction_way_index[addr]+1) == CACHE_WAYS) begin
|
||||
eviction_way_index[addr] <= 0;
|
||||
end else begin
|
||||
eviction_way_index[addr] <= (eviction_way_index[addr] + 1);
|
||||
|
||||
152
rtl/cache/VX_d_cache.v
vendored
152
rtl/cache/VX_d_cache.v
vendored
@@ -14,13 +14,30 @@
|
||||
//`include "cache_set.v"
|
||||
|
||||
module VX_d_cache
|
||||
/*#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8,
|
||||
parameter NUM_REQ = 8
|
||||
)*/
|
||||
#(
|
||||
parameter CACHE_SIZE = 4096, // Bytes
|
||||
parameter CACHE_WAYS = 1,
|
||||
parameter CACHE_BLOCK = 128, // Bytes
|
||||
parameter CACHE_BANKS = 8,
|
||||
parameter LOG_NUM_BANKS = 3,
|
||||
parameter NUM_REQ = 8,
|
||||
parameter LOG_NUM_REQ = 3,
|
||||
parameter NUM_IND = 8,
|
||||
parameter CACHE_WAY_INDEX = 1,
|
||||
parameter NUM_WORDS_PER_BLOCK = 4,
|
||||
parameter OFFSET_SIZE_START = 0,
|
||||
parameter OFFSET_SIZE_END = 1,
|
||||
parameter TAG_SIZE_START = 0,
|
||||
parameter TAG_SIZE_END = 16,
|
||||
parameter IND_SIZE_START = 0,
|
||||
parameter IND_SIZE_END = 7,
|
||||
parameter ADDR_TAG_START = 15,
|
||||
parameter ADDR_TAG_END = 31,
|
||||
parameter ADDR_OFFSET_START = 5,
|
||||
parameter ADDR_OFFSET_END = 6,
|
||||
parameter ADDR_IND_START = 7,
|
||||
parameter ADDR_IND_END = 14
|
||||
)
|
||||
(
|
||||
clk,
|
||||
rst,
|
||||
@@ -59,18 +76,18 @@ module VX_d_cache
|
||||
|
||||
//parameter cache_entry = 9;
|
||||
input wire clk, rst;
|
||||
input wire [`DCACHE_NUM_REQ-1:0] i_p_valid;
|
||||
input wire [`DCACHE_NUM_REQ-1:0][31:0] i_p_addr; // FIXME
|
||||
input wire [`DCACHE_NUM_REQ-1:0][31:0] i_p_writedata;
|
||||
input wire [NUM_REQ-1:0] i_p_valid;
|
||||
input wire [NUM_REQ-1:0][31:0] i_p_addr; // FIXME
|
||||
input wire [NUM_REQ-1:0][31:0] i_p_writedata;
|
||||
input wire i_p_read_or_write; //, i_p_write;
|
||||
output reg [`DCACHE_NUM_REQ-1:0][31:0] o_p_readdata;
|
||||
output reg [NUM_REQ-1:0][31:0] o_p_readdata;
|
||||
output wire o_p_delay;
|
||||
output reg [31:0] o_m_evict_addr; // Address is xxxxxxxxxxoooobbbyy
|
||||
output reg [31:0] o_m_read_addr;
|
||||
output reg o_m_valid;
|
||||
output reg[`DCACHE_BANKS - 1:0][`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] o_m_writedata;
|
||||
output reg[CACHE_BANKS - 1:0][NUM_WORDS_PER_BLOCK-1:0][31:0] o_m_writedata;
|
||||
output reg o_m_read_or_write; //, o_m_write;
|
||||
input wire[`DCACHE_BANKS - 1:0][`DCACHE_NUM_WORDS_PER_BLOCK-1:0][31:0] i_m_readdata;
|
||||
input wire[CACHE_BANKS - 1:0][NUM_WORDS_PER_BLOCK-1:0][31:0] i_m_readdata;
|
||||
input wire i_m_ready;
|
||||
|
||||
input wire[2:0] i_p_mem_read;
|
||||
@@ -78,41 +95,41 @@ module VX_d_cache
|
||||
|
||||
|
||||
// Buffer for final data
|
||||
reg [`DCACHE_NUM_REQ-1:0][31:0] final_data_read;
|
||||
reg [`DCACHE_NUM_REQ-1:0][31:0] new_final_data_read;
|
||||
wire[`DCACHE_NUM_REQ-1:0][31:0] new_final_data_read_Qual;
|
||||
reg [NUM_REQ-1:0][31:0] final_data_read;
|
||||
reg [NUM_REQ-1:0][31:0] new_final_data_read;
|
||||
wire[NUM_REQ-1:0][31:0] new_final_data_read_Qual;
|
||||
|
||||
assign o_p_readdata = new_final_data_read_Qual;
|
||||
|
||||
|
||||
|
||||
wire[`DCACHE_BANKS - 1 : 0][`DCACHE_NUM_REQ-1:0] thread_track_banks; // Valid thread mask per bank
|
||||
wire[`DCACHE_BANKS - 1 : 0][$clog2(`DCACHE_NUM_REQ)-1:0] index_per_bank; // Index of thread each bank will try to service
|
||||
wire[`DCACHE_BANKS - 1 : 0][`DCACHE_NUM_REQ-1:0] use_mask_per_bank; // A mask of index_per_bank
|
||||
wire[`DCACHE_BANKS - 1 : 0] valid_per_bank; // Valid request going to each bank
|
||||
wire[`DCACHE_BANKS - 1 : 0][`DCACHE_NUM_REQ-1:0] threads_serviced_per_bank; // Bank successfully serviced per bank
|
||||
wire[CACHE_BANKS - 1 : 0][NUM_REQ-1:0] thread_track_banks; // Valid thread mask per bank
|
||||
wire[CACHE_BANKS - 1 : 0][LOG_NUM_REQ-1:0] index_per_bank; // Index of thread each bank will try to service
|
||||
wire[CACHE_BANKS - 1 : 0][NUM_REQ-1:0] use_mask_per_bank; // A mask of index_per_bank
|
||||
wire[CACHE_BANKS - 1 : 0] valid_per_bank; // Valid request going to each bank
|
||||
wire[CACHE_BANKS - 1 : 0][NUM_REQ-1:0] threads_serviced_per_bank; // Bank successfully serviced per bank
|
||||
|
||||
wire[`DCACHE_BANKS-1:0][31:0] readdata_per_bank; // Data read from each bank
|
||||
wire[`DCACHE_BANKS-1:0] hit_per_bank; // Whether each bank got a hit or a miss
|
||||
wire[`DCACHE_BANKS-1:0] eviction_wb;
|
||||
reg[`DCACHE_BANKS-1:0] eviction_wb_old;
|
||||
wire[CACHE_BANKS-1:0][31:0] readdata_per_bank; // Data read from each bank
|
||||
wire[CACHE_BANKS-1:0] hit_per_bank; // Whether each bank got a hit or a miss
|
||||
wire[CACHE_BANKS-1:0] eviction_wb;
|
||||
reg[CACHE_BANKS-1:0] eviction_wb_old;
|
||||
|
||||
|
||||
wire[`DCACHE_BANKS -1 : 0][`DCACHE_WAY_INDEX-1:0] evicted_way_new;
|
||||
reg [`DCACHE_BANKS -1 : 0][`DCACHE_WAY_INDEX-1:0] evicted_way_old;
|
||||
wire[`DCACHE_BANKS -1 : 0][`DCACHE_WAY_INDEX-1:0] way_used;
|
||||
wire[CACHE_BANKS -1 : 0][CACHE_WAY_INDEX-1:0] evicted_way_new;
|
||||
reg [CACHE_BANKS -1 : 0][CACHE_WAY_INDEX-1:0] evicted_way_old;
|
||||
wire[CACHE_BANKS -1 : 0][CACHE_WAY_INDEX-1:0] way_used;
|
||||
|
||||
// Internal State
|
||||
reg [3:0] state;
|
||||
wire[3:0] new_state;
|
||||
|
||||
wire[`DCACHE_NUM_REQ-1:0] use_valid; // Valid used throught the code
|
||||
reg[`DCACHE_NUM_REQ-1:0] stored_valid; // Saving the threads still left (bank conflict or bank miss)
|
||||
wire[`DCACHE_NUM_REQ-1:0] new_stored_valid; // New stored valid
|
||||
wire[NUM_REQ-1:0] use_valid; // Valid used throught the code
|
||||
reg[NUM_REQ-1:0] stored_valid; // Saving the threads still left (bank conflict or bank miss)
|
||||
wire[NUM_REQ-1:0] new_stored_valid; // New stored valid
|
||||
|
||||
|
||||
|
||||
reg[`DCACHE_BANKS - 1 : 0][31:0] eviction_addr_per_bank;
|
||||
reg[CACHE_BANKS - 1 : 0][31:0] eviction_addr_per_bank;
|
||||
|
||||
reg[31:0] miss_addr;
|
||||
reg[31:0] evict_addr;
|
||||
@@ -127,39 +144,41 @@ module VX_d_cache
|
||||
|
||||
|
||||
|
||||
VX_cache_bank_valid #(.NUMBER_BANKS(`DCACHE_BANKS)) multip_banks(
|
||||
VX_cache_bank_valid #(.NUMBER_BANKS (CACHE_BANKS),
|
||||
.LOG_NUM_BANKS (LOG_NUM_BANKS),
|
||||
.NUM_REQ (NUM_REQ)) multip_banks(
|
||||
.i_p_valid (use_valid),
|
||||
.i_p_addr (i_p_addr),
|
||||
.thread_track_banks(thread_track_banks)
|
||||
);
|
||||
|
||||
|
||||
reg[`DCACHE_NUM_REQ-1:0] threads_serviced_Qual;
|
||||
reg[NUM_REQ-1:0] threads_serviced_Qual;
|
||||
|
||||
reg[`DCACHE_NUM_REQ-1:0] debug_hit_per_bank_mask[`DCACHE_BANKS-1:0];
|
||||
reg[NUM_REQ-1:0] debug_hit_per_bank_mask[CACHE_BANKS-1:0];
|
||||
|
||||
genvar bid;
|
||||
for (bid = 0; bid < `DCACHE_BANKS; bid=bid+1)
|
||||
for (bid = 0; bid < CACHE_BANKS; bid=bid+1)
|
||||
begin
|
||||
wire[`DCACHE_NUM_REQ-1:0] use_threads_track_banks = thread_track_banks[bid];
|
||||
wire[$clog2(`DCACHE_NUM_REQ)-1:0] use_thread_index = index_per_bank[bid];
|
||||
wire[NUM_REQ-1:0] use_threads_track_banks = thread_track_banks[bid];
|
||||
wire[LOG_NUM_REQ-1:0] use_thread_index = index_per_bank[bid];
|
||||
wire use_write_final_data = hit_per_bank[bid];
|
||||
wire[31:0] use_data_final_data = readdata_per_bank[bid];
|
||||
VX_priority_encoder_w_mask #(.N(`DCACHE_NUM_REQ)) choose_thread(
|
||||
VX_priority_encoder_w_mask #(.N(NUM_REQ)) choose_thread(
|
||||
.valids(use_threads_track_banks),
|
||||
.mask (use_mask_per_bank[bid]),
|
||||
.index (index_per_bank[bid]),
|
||||
.found (valid_per_bank[bid])
|
||||
);
|
||||
|
||||
assign debug_hit_per_bank_mask[bid] = {`DCACHE_NUM_REQ{hit_per_bank[bid]}};
|
||||
assign debug_hit_per_bank_mask[bid] = {NUM_REQ{hit_per_bank[bid]}};
|
||||
assign threads_serviced_per_bank[bid] = use_mask_per_bank[bid] & debug_hit_per_bank_mask[bid];
|
||||
end
|
||||
|
||||
integer test_bid;
|
||||
always @(*) begin
|
||||
new_final_data_read = 0;
|
||||
for (test_bid=0; test_bid < `DCACHE_BANKS; test_bid=test_bid+1)
|
||||
for (test_bid=0; test_bid < CACHE_BANKS; test_bid=test_bid+1)
|
||||
begin
|
||||
if (hit_per_bank[test_bid]) begin
|
||||
new_final_data_read[index_per_bank[test_bid]] = readdata_per_bank[test_bid];
|
||||
@@ -168,7 +187,7 @@ module VX_d_cache
|
||||
end
|
||||
|
||||
|
||||
wire[`DCACHE_BANKS - 1 : 0] detect_bank_miss;
|
||||
wire[CACHE_BANKS - 1 : 0] detect_bank_miss;
|
||||
//assign threads_serviced_Qual = threads_serviced_per_bank[0] | threads_serviced_per_bank[1] |
|
||||
// threads_serviced_per_bank[2] | threads_serviced_per_bank[3] |
|
||||
// threads_serviced_per_bank[4] | threads_serviced_per_bank[5] |
|
||||
@@ -176,7 +195,7 @@ module VX_d_cache
|
||||
integer bbid;
|
||||
always @(*) begin
|
||||
threads_serviced_Qual = 0;
|
||||
for (bbid = 0; bbid < `DCACHE_BANKS; bbid=bbid+1)
|
||||
for (bbid = 0; bbid < CACHE_BANKS; bbid=bbid+1)
|
||||
begin
|
||||
threads_serviced_Qual = threads_serviced_Qual | threads_serviced_per_bank[bbid];
|
||||
end
|
||||
@@ -185,7 +204,7 @@ module VX_d_cache
|
||||
|
||||
|
||||
genvar tid;
|
||||
for (tid = 0; tid < `DCACHE_NUM_REQ; tid =tid+1)
|
||||
for (tid = 0; tid < NUM_REQ; tid =tid+1)
|
||||
begin
|
||||
assign new_final_data_read_Qual[tid] = threads_serviced_Qual[tid] ? new_final_data_read[tid] : final_data_read[tid];
|
||||
end
|
||||
@@ -198,12 +217,12 @@ module VX_d_cache
|
||||
|
||||
assign o_p_delay = delay;
|
||||
|
||||
wire[`DCACHE_BANKS - 1 : 0][$clog2(`DCACHE_NUM_REQ)-1:0] send_index_to_bank = index_per_bank;
|
||||
wire[CACHE_BANKS - 1 : 0][LOG_NUM_REQ-1:0] send_index_to_bank = index_per_bank;
|
||||
|
||||
|
||||
wire[$clog2(`DCACHE_BANKS)-1:0] miss_bank_index;
|
||||
wire[LOG_NUM_BANKS-1:0] miss_bank_index;
|
||||
wire miss_found;
|
||||
VX_generic_priority_encoder #(.N(`DCACHE_BANKS)) get_miss_index
|
||||
VX_generic_priority_encoder #(.N(CACHE_BANKS)) get_miss_index
|
||||
(
|
||||
.valids(detect_bank_miss),
|
||||
.index (miss_bank_index),
|
||||
@@ -259,7 +278,7 @@ module VX_d_cache
|
||||
|
||||
genvar bank_id;
|
||||
generate
|
||||
for (bank_id = 0; bank_id < `DCACHE_BANKS; bank_id = bank_id + 1)
|
||||
for (bank_id = 0; bank_id < CACHE_BANKS; bank_id = bank_id + 1)
|
||||
begin
|
||||
wire[31:0] bank_addr = (state == SEND_MEM_REQ) ? evict_addr :
|
||||
(state == RECIV_MEM_RSP) ? miss_addr :
|
||||
@@ -270,9 +289,9 @@ module VX_d_cache
|
||||
0;
|
||||
|
||||
wire[1:0] byte_select = bank_addr[1:0];
|
||||
wire[`DCACHE_OFFSET_SIZE_RNG] cache_offset = bank_addr[`DCACHE_ADDR_OFFSET_RNG];
|
||||
wire[`DCACHE_IND_SIZE_RNG] cache_index = bank_addr[`DCACHE_ADDR_IND_RNG];
|
||||
wire[`DCACHE_TAG_SIZE_RNG] cache_tag = bank_addr[`DCACHE_ADDR_TAG_RNG];
|
||||
wire[OFFSET_SIZE_END:OFFSET_SIZE_START] cache_offset = bank_addr[ADDR_OFFSET_END:ADDR_OFFSET_START];
|
||||
wire[IND_SIZE_END:IND_SIZE_START] cache_index = bank_addr[ADDR_IND_END:ADDR_IND_START];
|
||||
wire[TAG_SIZE_END:TAG_SIZE_START] cache_tag = bank_addr[ADDR_TAG_END:ADDR_TAG_START];
|
||||
|
||||
|
||||
wire normal_valid_in = valid_per_bank[bank_id];
|
||||
@@ -281,12 +300,31 @@ module VX_d_cache
|
||||
((state == SEND_MEM_REQ)) ? 1'b0 :
|
||||
normal_valid_in;
|
||||
|
||||
/*VX_Cache_Bank #(
|
||||
.CACHE_SIZE(CACHE_SIZE),
|
||||
.CACHE_WAYS(CACHE_WAYS),
|
||||
.CACHE_BLOCK(CACHE_BLOCK),
|
||||
.CACHE_BANKS(CACHE_BANKS)) bank_structure*/
|
||||
VX_Cache_Bank bank_structure(
|
||||
|
||||
VX_Cache_Bank #(
|
||||
.CACHE_SIZE (CACHE_SIZE),
|
||||
.CACHE_WAYS (CACHE_WAYS),
|
||||
.CACHE_BLOCK (CACHE_BLOCK),
|
||||
.CACHE_BANKS (CACHE_BANKS),
|
||||
.LOG_NUM_BANKS (LOG_NUM_BANKS),
|
||||
.NUM_REQ (NUM_REQ),
|
||||
.LOG_NUM_REQ (LOG_NUM_REQ),
|
||||
.NUM_IND (NUM_IND),
|
||||
.CACHE_WAY_INDEX (CACHE_WAY_INDEX),
|
||||
.NUM_WORDS_PER_BLOCK (NUM_WORDS_PER_BLOCK),
|
||||
.OFFSET_SIZE_START (OFFSET_SIZE_START),
|
||||
.OFFSET_SIZE_END (OFFSET_SIZE_END),
|
||||
.TAG_SIZE_START (TAG_SIZE_START),
|
||||
.TAG_SIZE_END (TAG_SIZE_END),
|
||||
.IND_SIZE_START (IND_SIZE_START),
|
||||
.IND_SIZE_END (IND_SIZE_END),
|
||||
.ADDR_TAG_START (ADDR_TAG_START),
|
||||
.ADDR_TAG_END (ADDR_TAG_END),
|
||||
.ADDR_OFFSET_START (ADDR_OFFSET_START),
|
||||
.ADDR_OFFSET_END (ADDR_OFFSET_END),
|
||||
.ADDR_IND_START (ADDR_IND_START),
|
||||
.ADDR_IND_END (ADDR_IND_END)
|
||||
) bank_structure (
|
||||
.clk (clk),
|
||||
.rst (rst),
|
||||
.state (state),
|
||||
|
||||
Reference in New Issue
Block a user