Added Parameterization

This commit is contained in:
Savan Roshan
2019-11-04 13:20:34 -05:00
parent a28a1c45c1
commit 8264339853
7 changed files with 609 additions and 578 deletions

View File

@@ -116,21 +116,39 @@
`define ZERO_REG 5'h0 `define ZERO_REG 5'h0
// `define PARAM // `define PARAM
// Offset //Cache configurations
`define CACHE_OFFSET_NB ($clog2(NUM_WORDS_PER_BLOCK)) `define CACHE_SIZE 4096 //Bytes
`ifdef SYN
`define CACHE_WAYS 1
`else
`define CACHE_WAYS 2
`endif
`define CACHE_BLOCK 128 //Bytes
`define CACHE_BANKS 8
`define NUM_WORDS_PER_BLOCK 4
`define NUM_REQ `NT
`define CACHE_OFFSET_ST (2+$clog2(NUMBER_BANKS)) `define CACHE_WAY_INDEX $clog2(`CACHE_WAYS) //set this to 1 if CACHE_WAYS is 1
//`define CACHE_WAY_INDEX 1
`define CACHE_BLOCK_PER_BANK (`CACHE_BLOCK / `CACHE_BANKS)
// Offset
`define CACHE_OFFSET_NB ($clog2(`NUM_WORDS_PER_BLOCK))
`define CACHE_OFFSET_ST (2+$clog2(`NUMBER_BANKS))
`define CACHE_OFFSET_ED (`CACHE_OFFSET_ST+(`CACHE_OFFSET_NB)-1) `define CACHE_OFFSET_ED (`CACHE_OFFSET_ST+(`CACHE_OFFSET_NB)-1)
`define CACHE_ADDR_OFFSET_RNG `CACHE_OFFSET_ED:`CACHE_OFFSET_ST `define CACHE_ADDR_OFFSET_RNG `CACHE_OFFSET_ED:`CACHE_OFFSET_ST
`define CACHE_OFFSET_SIZE_RNG ($clog2(NUM_WORDS_PER_BLOCK)-1):0 `define CACHE_OFFSET_SIZE_RNG ($clog2(`NUM_WORDS_PER_BLOCK)-1):0
// Index // Index
`define NUM_IND (CACHE_SIZE / (CACHE_WAYS * CACHE_BLOCK_PER_BANK)) `define NUM_IND (`CACHE_SIZE / (`CACHE_WAYS * `CACHE_BLOCK_PER_BANK))
`define CACHE_IND_NB ($clog2(`NUM_IND)) `define CACHE_IND_NB ($clog2(`NUM_IND))
`define CACHE_IND_ST (`CACHE_OFFSET_ED+1) `define CACHE_IND_ST (`CACHE_OFFSET_ED+1)

View File

@@ -52,7 +52,7 @@ module VX_dmem_controller (
VX_d_cache VX_d_cache
#( /*#(
.CACHE_SIZE(4096), // Bytes .CACHE_SIZE(4096), // Bytes
`ifdef SYN `ifdef SYN
.CACHE_WAYS(1), .CACHE_WAYS(1),
@@ -62,7 +62,7 @@ module VX_dmem_controller (
.CACHE_BLOCK(128), // Bytes .CACHE_BLOCK(128), // Bytes
.CACHE_BANKS(8), .CACHE_BANKS(8),
.NUM_REQ(`NT) .NUM_REQ(`NT)
) dcache )*/ dcache
( (
.clk (clk), .clk (clk),
.rst (reset), .rst (reset),

View File

@@ -7,12 +7,12 @@
module VX_Cache_Bank module VX_Cache_Bank
#( /*#(
parameter CACHE_SIZE = 4096, // Bytes parameter CACHE_SIZE = 4096, // Bytes
parameter CACHE_WAYS = 1, parameter CACHE_WAYS = 1,
parameter CACHE_BLOCK = 128, // Bytes parameter CACHE_BLOCK = 128, // Bytes
parameter CACHE_BANKS = 8 parameter CACHE_BANKS = 8
) )*/
( (
clk, clk,
rst, rst,
@@ -42,10 +42,10 @@ module VX_Cache_Bank
way_use way_use
); );
localparam NUMBER_BANKS = CACHE_BANKS; // localparam NUMBER_BANKS = `CACHE_BANKS;
localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS); // localparam CACHE_BLOCK_PER_BANK = (`CACHE_BLOCK / `CACHE_BANKS);
localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4); // localparam NUM_WORDS_PER_BLOCK = `CACHE_BLOCK / (`CACHE_BANKS*4);
localparam NUMBER_INDEXES = `NUM_IND; // localparam NUMBER_INDEXES = `NUM_IND;
localparam CACHE_IDLE = 0; // Idle localparam CACHE_IDLE = 0; // Idle
localparam SEND_MEM_REQ = 1; // Write back this block into memory localparam SEND_MEM_REQ = 1; // Write back this block into memory
@@ -69,14 +69,14 @@ module VX_Cache_Bank
input wire valid_in; input wire valid_in;
input wire read_or_write; // Specifies if it is a read or write operation input wire read_or_write; // Specifies if it is a read or write operation
input wire[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_read;
input wire[2:0] i_p_mem_write; input wire[2:0] i_p_mem_write;
input wire[1:0] byte_select; input wire[1:0] byte_select;
input wire[$clog2(CACHE_WAYS)-1:0] evicted_way; input wire[`CACHE_WAY_INDEX-1:0] evicted_way;
output wire[$clog2(CACHE_WAYS)-1:0] way_use; output wire[`CACHE_WAY_INDEX-1:0] way_use;
// Outputs // Outputs
// Normal shit // Normal shit
@@ -89,11 +89,11 @@ module VX_Cache_Bank
output wire[31:0] eviction_addr; // What's the eviction tag output wire[31:0] eviction_addr; // What's the eviction tag
// Eviction Data (Extraction) // Eviction Data (Extraction)
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_evicted; output wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_evicted;
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use; wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_use;
wire[`CACHE_TAG_SIZE_RNG] tag_use; wire[`CACHE_TAG_SIZE_RNG] tag_use;
wire[`CACHE_TAG_SIZE_RNG] eviction_tag; wire[`CACHE_TAG_SIZE_RNG] eviction_tag;
wire valid_use; wire valid_use;
@@ -104,8 +104,8 @@ module VX_Cache_Bank
wire[$clog2(CACHE_WAYS)-1:0] update_way; wire[`CACHE_WAY_INDEX-1:0] update_way;
wire[$clog2(CACHE_WAYS)-1:0] way_to_update; wire[`CACHE_WAY_INDEX-1:0] way_to_update;
assign miss = (tag_use != o_tag) && valid_use && valid_in; assign miss = (tag_use != o_tag) && valid_use && valid_in;
@@ -180,10 +180,10 @@ module VX_Cache_Bank
wire[3:0] sh_mask = (b0 ? 4'b0011 : 4'b1100); wire[3:0] sh_mask = (b0 ? 4'b0011 : 4'b1100);
wire[NUM_WORDS_PER_BLOCK-1:0][3:0] we; wire[`NUM_WORDS_PER_BLOCK-1:0][3:0] we;
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write; wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_write;
genvar g; genvar g;
for (g = 0; g < 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); wire normal_write = (read_or_write && ((access && (block_offset == g))) && !miss);
assign we[g] = (write_from_mem) ? 4'b1111 : assign we[g] = (write_from_mem) ? 4'b1111 :
@@ -199,12 +199,13 @@ module VX_Cache_Bank
end end
VX_cache_data_per_index #( /*VX_cache_data_per_index #(
.CACHE_SIZE(CACHE_SIZE), .CACHE_SIZE(CACHE_SIZE),
.CACHE_WAYS(CACHE_WAYS), .CACHE_WAYS(CACHE_WAYS),
.CACHE_BLOCK(CACHE_BLOCK), .CACHE_BLOCK(CACHE_BLOCK),
.CACHE_BANKS(CACHE_BANKS), .CACHE_BANKS(CACHE_BANKS),
.NUM_WORDS_PER_BLOCK(NUM_WORDS_PER_BLOCK)) data_structures( .NUM_WORDS_PER_BLOCK(NUM_WORDS_PER_BLOCK)) data_structures(*/
VX_cache_data_per_index data_structures(
.clk (clk), .clk (clk),
.rst (rst), .rst (rst),
.valid_in (valid_in), .valid_in (valid_in),

View File

@@ -3,13 +3,13 @@
`include "../VX_define.v" `include "../VX_define.v"
module VX_cache_data module VX_cache_data
#( /*#(
parameter CACHE_SIZE = 4096, // Bytes parameter CACHE_SIZE = 4096, // Bytes
parameter CACHE_WAYS = 1, parameter CACHE_WAYS = 1,
parameter CACHE_BLOCK = 128, // Bytes parameter CACHE_BLOCK = 128, // Bytes
parameter CACHE_BANKS = 8, parameter CACHE_BANKS = 8,
parameter NUM_WORDS_PER_BLOCK = 4 parameter NUM_WORDS_PER_BLOCK = 4
) )*/
( (
input wire clk, rst, // Clock input wire clk, rst, // Clock
@@ -17,15 +17,15 @@ module VX_cache_data
// Addr // Addr
input wire[`CACHE_IND_SIZE_RNG] addr, input wire[`CACHE_IND_SIZE_RNG] addr,
// WE // WE
input wire[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 evict,
// Data // Data
input wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write, input wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_write,
input wire[`CACHE_TAG_SIZE_RNG] tag_write, input wire[`CACHE_TAG_SIZE_RNG] tag_write,
output wire[`CACHE_TAG_SIZE_RNG] tag_use, output wire[`CACHE_TAG_SIZE_RNG] tag_use,
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use, output wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
output wire valid_use, output wire valid_use,
output wire dirty_use output wire dirty_use
// `else // `else
@@ -47,10 +47,10 @@ module VX_cache_data
); );
localparam NUMBER_BANKS = CACHE_BANKS; //localparam NUMBER_BANKS = CACHE_BANKS;
localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS); //localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS);
// localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4); // localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4);
localparam NUMBER_INDEXES = `NUM_IND; //localparam NUMBER_INDEXES = `NUM_IND;
wire currently_writing = (|we); wire currently_writing = (|we);
wire update_dirty = ((!dirty_use) && currently_writing) || (evict); wire update_dirty = ((!dirty_use) && currently_writing) || (evict);
@@ -61,10 +61,10 @@ module VX_cache_data
`ifndef SYN `ifndef SYN
// (3:0) 4 bytes // (3:0) 4 bytes
reg[NUM_WORDS_PER_BLOCK-1:0][3:0][7:0] data[NUMBER_INDEXES-1:0]; // Actual Data reg[`NUM_WORDS_PER_BLOCK-1:0][3:0][7:0] data[`NUM_IND-1:0]; // Actual Data
reg[`CACHE_TAG_SIZE_RNG] tag[NUMBER_INDEXES-1:0]; reg[`CACHE_TAG_SIZE_RNG] tag[`NUM_IND-1:0];
reg valid[NUMBER_INDEXES-1:0]; reg valid[`NUM_IND-1:0];
reg dirty[NUMBER_INDEXES-1:0]; reg dirty[`NUM_IND-1:0];
// 16 bytes // 16 bytes
@@ -77,7 +77,7 @@ module VX_cache_data
integer ini_ind; integer ini_ind;
always @(posedge clk, posedge rst) begin : update_all always @(posedge clk, posedge rst) begin : update_all
if (rst) begin if (rst) begin
for (ini_ind = 0; ini_ind < NUMBER_INDEXES; ini_ind=ini_ind+1) begin for (ini_ind = 0; ini_ind < `NUM_IND; ini_ind=ini_ind+1) begin
data[ini_ind] <= 0; data[ini_ind] <= 0;
tag[ini_ind] <= 0; tag[ini_ind] <= 0;
valid[ini_ind] <= 0; valid[ini_ind] <= 0;
@@ -88,7 +88,7 @@ module VX_cache_data
if (evict) tag[addr] <= tag_write; if (evict) tag[addr] <= tag_write;
if (evict) valid[addr] <= 1; if (evict) valid[addr] <= 1;
for (f = 0; f < 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][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][1]) data[addr][f][1] <= data_write[f][15:8 ];
if (we[f][2]) data[addr][f][2] <= data_write[f][23:16]; if (we[f][2]) data[addr][f][2] <= data_write[f][23:16];
@@ -103,11 +103,11 @@ module VX_cache_data
wire cena = 1; wire cena = 1;
wire cenb_d = (|we); wire cenb_d = (|we);
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] wdata_d = data_write; 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] write_bit_mask_d;
wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_out_d; wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_out_d;
genvar cur_b; genvar cur_b;
for (cur_b = 0; cur_b < 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]}}; assign write_bit_mask_d[cur_b] = {32{~we[cur_b]}};
end end
assign data_use = data_out_d; assign data_use = data_out_d;

View File

@@ -3,13 +3,13 @@
`include "../VX_define.v" `include "../VX_define.v"
module VX_cache_data_per_index module VX_cache_data_per_index
#( /*#(
parameter CACHE_SIZE = 4096, // Bytes parameter CACHE_SIZE = 4096, // Bytes
parameter CACHE_WAYS = 1, parameter CACHE_WAYS = 1,
parameter CACHE_BLOCK = 128, // Bytes parameter CACHE_BLOCK = 128, // Bytes
parameter CACHE_BANKS = 8, parameter CACHE_BANKS = 8,
parameter NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4) parameter NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4)
) )*/
( (
input wire clk, // Clock input wire clk, // Clock
input wire rst, input wire rst,
@@ -17,52 +17,62 @@ module VX_cache_data_per_index
// Addr // Addr
input wire[`CACHE_IND_SIZE_RNG] addr, input wire[`CACHE_IND_SIZE_RNG] addr,
// WE // WE
input wire[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 evict,
input wire[$clog2(CACHE_WAYS)-1:0] way_to_update, input wire[`CACHE_WAY_INDEX-1:0] way_to_update,
// Data // Data
input wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_write, // Update Data input wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_write, // Update Data
input wire[`CACHE_TAG_SIZE_RNG] tag_write, input wire[`CACHE_TAG_SIZE_RNG] tag_write,
output wire[`CACHE_TAG_SIZE_RNG] tag_use, output wire[`CACHE_TAG_SIZE_RNG] tag_use,
output wire[NUM_WORDS_PER_BLOCK-1:0][31:0] data_use, output wire[`NUM_WORDS_PER_BLOCK-1:0][31:0] data_use,
output wire valid_use, output wire valid_use,
output wire dirty_use, output wire dirty_use,
output wire[$clog2(CACHE_WAYS)-1:0] way output wire[`CACHE_WAY_INDEX-1:0] way
); );
localparam NUMBER_BANKS = CACHE_BANKS; //localparam NUMBER_BANKS = CACHE_BANKS;
localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS); //localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / CACHE_BANKS);
// localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4); // localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4);
localparam NUMBER_INDEXES = `NUM_IND; //localparam NUMBER_INDEXES = `NUM_IND;
wire [CACHE_WAYS-1:0][`CACHE_TAG_SIZE_RNG] tag_use_per_way; wire [`CACHE_WAYS-1:0][`CACHE_TAG_SIZE_RNG] 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][`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] valid_use_per_way;
wire [CACHE_WAYS-1:0] dirty_use_per_way; wire [`CACHE_WAYS-1:0] dirty_use_per_way;
wire [CACHE_WAYS-1:0] hit_per_way; wire [`CACHE_WAYS-1:0] hit_per_way;
reg [NUMBER_INDEXES-1:0][$clog2(CACHE_WAYS)-1:0] eviction_way_index; 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][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][`NUM_WORDS_PER_BLOCK-1:0][31:0] data_write_per_way;
wire [CACHE_WAYS-1:0] write_from_mem_per_way; wire [`CACHE_WAYS-1:0] write_from_mem_per_way;
wire invalid_found; wire invalid_found;
wire [$clog2(CACHE_WAYS)-1:0] way_index; wire [`CACHE_WAY_INDEX-1:0] way_index;
wire [$clog2(CACHE_WAYS)-1:0] invalid_index; wire [`CACHE_WAY_INDEX-1:0] invalid_index;
VX_generic_priority_encoder #(.N(CACHE_WAYS)) valid_index
if(`CACHE_WAYS != 1) begin
VX_generic_priority_encoder #(.N(`CACHE_WAYS)) valid_index
( (
.valids(~valid_use_per_way), .valids(~valid_use_per_way),
.index (invalid_index), .index (invalid_index),
.found (invalid_found) .found (invalid_found)
); );
VX_generic_priority_encoder #(.N(CACHE_WAYS)) way_indexing VX_generic_priority_encoder #(.N(`CACHE_WAYS)) way_indexing
( (
.valids(hit_per_way), .valids(hit_per_way),
.index (way_index), .index (way_index),
.found () .found ()
); );
end
else begin
assign way_index = 0;
assign invalid_found = (valid_use_per_way == 1'b0) ? 1 : 0;
assign invalid_index = 0;
end
@@ -80,18 +90,19 @@ module VX_cache_data_per_index
genvar ways; genvar ways;
for(ways=0; ways < CACHE_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 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 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 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; assign write_from_mem_per_way[ways] = (evict == 1'b1) ? ((ways == way_to_update) ? 1 : 0) : 0;
VX_cache_data #( /*VX_cache_data #(
.CACHE_SIZE(CACHE_SIZE), .CACHE_SIZE(`CACHE_SIZE),
.CACHE_WAYS(CACHE_WAYS), .CACHE_WAYS(`CACHE_WAYS),
.CACHE_BLOCK(CACHE_BLOCK), .CACHE_BLOCK(`CACHE_BLOCK),
.CACHE_BANKS(CACHE_BANKS)) data_structures( .CACHE_BANKS(`CACHE_BANKS)) data_structures(*/
VX_cache_data data_structures(
.clk (clk), .clk (clk),
.rst (rst), .rst (rst),
// Inputs // Inputs
@@ -113,7 +124,7 @@ module VX_cache_data_per_index
eviction_way_index <= 0; eviction_way_index <= 0;
end else begin end else begin
if(miss && dirty_use && valid_use && !evict && valid_in) begin // can be either evict or invalid cache entries if(miss && dirty_use && valid_use && !evict && valid_in) begin // can be either evict or invalid cache entries
if((eviction_way_index[addr]+1) == CACHE_WAYS) begin if((eviction_way_index[addr]+1) == `CACHE_WAYS) begin
eviction_way_index[addr] <= 0; eviction_way_index[addr] <= 0;
end else begin end else begin
eviction_way_index[addr] <= (eviction_way_index[addr] + 1); eviction_way_index[addr] <= (eviction_way_index[addr] + 1);

View File

@@ -14,13 +14,13 @@
//`include "cache_set.v" //`include "cache_set.v"
module VX_d_cache module VX_d_cache
#( /*#(
parameter CACHE_SIZE = 4096, // Bytes parameter CACHE_SIZE = 4096, // Bytes
parameter CACHE_WAYS = 1, parameter CACHE_WAYS = 1,
parameter CACHE_BLOCK = 128, // Bytes parameter CACHE_BLOCK = 128, // Bytes
parameter CACHE_BANKS = 8, parameter CACHE_BANKS = 8,
parameter NUM_REQ = 8 parameter NUM_REQ = 8
) )*/
( (
clk, clk,
rst, rst,
@@ -47,10 +47,10 @@ module VX_d_cache
i_m_ready i_m_ready
); );
parameter NUMBER_BANKS = CACHE_BANKS; //parameter NUMBER_BANKS = `CACHE_BANKS;
localparam NUM_WORDS_PER_BLOCK = CACHE_BLOCK / (CACHE_BANKS*4); //localparam NUM_WORDS_PER_BLOCK = `CACHE_BLOCK / (`CACHE_BANKS*4);
localparam CACHE_BLOCK_PER_BANK = (CACHE_BLOCK / NUMBER_BANKS); //localparam CACHE_BLOCK_PER_BANK = (`CACHE_BLOCK / `CACHE_BANKS);
localparam CACHE_IDLE = 0; // Idle localparam CACHE_IDLE = 0; // Idle
localparam SEND_MEM_REQ = 1; // Write back this block into memory localparam SEND_MEM_REQ = 1; // Write back this block into memory
@@ -59,18 +59,18 @@ module VX_d_cache
//parameter cache_entry = 9; //parameter cache_entry = 9;
input wire clk, rst; input wire clk, rst;
input wire [NUM_REQ-1:0] i_p_valid; 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_addr; // FIXME
input wire [NUM_REQ-1:0][31:0] i_p_writedata; input wire [`NUM_REQ-1:0][31:0] i_p_writedata;
input wire i_p_read_or_write; //, i_p_write; input wire i_p_read_or_write; //, i_p_write;
output reg [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 wire o_p_delay;
output reg [31:0] o_m_evict_addr; // Address is xxxxxxxxxxoooobbbyy output reg [31:0] o_m_evict_addr; // Address is xxxxxxxxxxoooobbbyy
output reg [31:0] o_m_read_addr; output reg [31:0] o_m_read_addr;
output reg o_m_valid; output reg o_m_valid;
output reg[NUMBER_BANKS - 1:0][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; output reg o_m_read_or_write; //, o_m_write;
input wire[NUMBER_BANKS - 1:0][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 i_m_ready;
input wire[2:0] i_p_mem_read; input wire[2:0] i_p_mem_read;
@@ -78,41 +78,41 @@ module VX_d_cache
// Buffer for final data // Buffer for final data
reg [NUM_REQ-1:0][31:0] final_data_read; reg [`NUM_REQ-1:0][31:0] final_data_read;
reg [NUM_REQ-1:0][31:0] new_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; wire[`NUM_REQ-1:0][31:0] new_final_data_read_Qual;
assign o_p_readdata = new_final_data_read_Qual; assign o_p_readdata = new_final_data_read_Qual;
wire[NUMBER_BANKS - 1 : 0][NUM_REQ-1:0] thread_track_banks; // Valid thread mask per bank wire[`CACHE_BANKS - 1 : 0][`NUM_REQ-1:0] thread_track_banks; // Valid thread mask per bank
wire[NUMBER_BANKS - 1 : 0][$clog2(NUM_REQ)-1:0] index_per_bank; // Index of thread each bank will try to service wire[`CACHE_BANKS - 1 : 0][$clog2(`NUM_REQ)-1:0] index_per_bank; // Index of thread each bank will try to service
wire[NUMBER_BANKS - 1 : 0][NUM_REQ-1:0] use_mask_per_bank; // A mask of index_per_bank wire[`CACHE_BANKS - 1 : 0][`NUM_REQ-1:0] use_mask_per_bank; // A mask of index_per_bank
wire[NUMBER_BANKS - 1 : 0] valid_per_bank; // Valid request going to each bank wire[`CACHE_BANKS - 1 : 0] valid_per_bank; // Valid request going to each bank
wire[NUMBER_BANKS - 1 : 0][NUM_REQ-1:0] threads_serviced_per_bank; // Bank successfully serviced per bank wire[`CACHE_BANKS - 1 : 0][`NUM_REQ-1:0] threads_serviced_per_bank; // Bank successfully serviced per bank
wire[NUMBER_BANKS-1:0][31:0] readdata_per_bank; // Data read from each bank wire[`CACHE_BANKS-1:0][31:0] readdata_per_bank; // Data read from each bank
wire[NUMBER_BANKS-1:0] hit_per_bank; // Whether each bank got a hit or a miss wire[`CACHE_BANKS-1:0] hit_per_bank; // Whether each bank got a hit or a miss
wire[NUMBER_BANKS-1:0] eviction_wb; wire[`CACHE_BANKS-1:0] eviction_wb;
reg[NUMBER_BANKS-1:0] eviction_wb_old; reg[`CACHE_BANKS-1:0] eviction_wb_old;
wire[NUMBER_BANKS -1 : 0][$clog2(CACHE_WAYS)-1:0] evicted_way_new; wire[`CACHE_BANKS -1 : 0][`CACHE_WAY_INDEX-1:0] evicted_way_new;
reg [NUMBER_BANKS -1 : 0][$clog2(CACHE_WAYS)-1:0] evicted_way_old; reg [`CACHE_BANKS -1 : 0][`CACHE_WAY_INDEX-1:0] evicted_way_old;
wire[NUMBER_BANKS -1 : 0][$clog2(CACHE_WAYS)-1:0] way_used; wire[`CACHE_BANKS -1 : 0][`CACHE_WAY_INDEX-1:0] way_used;
// Internal State // Internal State
reg [3:0] state; reg [3:0] state;
wire[3:0] new_state; wire[3:0] new_state;
wire[NUM_REQ-1:0] use_valid; // Valid used throught the code 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) 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 wire[`NUM_REQ-1:0] new_stored_valid; // New stored valid
reg[NUMBER_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] miss_addr;
reg[31:0] evict_addr; reg[31:0] evict_addr;
@@ -127,39 +127,39 @@ module VX_d_cache
VX_cache_bank_valid #(.NUMBER_BANKS(NUMBER_BANKS)) multip_banks( VX_cache_bank_valid #(.NUMBER_BANKS(`CACHE_BANKS)) multip_banks(
.i_p_valid (use_valid), .i_p_valid (use_valid),
.i_p_addr (i_p_addr), .i_p_addr (i_p_addr),
.thread_track_banks(thread_track_banks) .thread_track_banks(thread_track_banks)
); );
reg[NUM_REQ-1:0] threads_serviced_Qual; reg[`NUM_REQ-1:0] threads_serviced_Qual;
reg[NUM_REQ-1:0] debug_hit_per_bank_mask[NUMBER_BANKS-1:0]; reg[`NUM_REQ-1:0] debug_hit_per_bank_mask[`CACHE_BANKS-1:0];
genvar bid; genvar bid;
for (bid = 0; bid < NUMBER_BANKS; bid=bid+1) for (bid = 0; bid < `CACHE_BANKS; bid=bid+1)
begin begin
wire[NUM_REQ-1:0] use_threads_track_banks = thread_track_banks[bid]; wire[`NUM_REQ-1:0] use_threads_track_banks = thread_track_banks[bid];
wire[$clog2(NUM_REQ)-1:0] use_thread_index = index_per_bank[bid]; wire[$clog2(`NUM_REQ)-1:0] use_thread_index = index_per_bank[bid];
wire use_write_final_data = hit_per_bank[bid]; wire use_write_final_data = hit_per_bank[bid];
wire[31:0] use_data_final_data = readdata_per_bank[bid]; wire[31:0] use_data_final_data = readdata_per_bank[bid];
VX_priority_encoder_w_mask #(.N(NUM_REQ)) choose_thread( VX_priority_encoder_w_mask #(.N(`NUM_REQ)) choose_thread(
.valids(use_threads_track_banks), .valids(use_threads_track_banks),
.mask (use_mask_per_bank[bid]), .mask (use_mask_per_bank[bid]),
.index (index_per_bank[bid]), .index (index_per_bank[bid]),
.found (valid_per_bank[bid]) .found (valid_per_bank[bid])
); );
assign debug_hit_per_bank_mask[bid] = {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]; assign threads_serviced_per_bank[bid] = use_mask_per_bank[bid] & debug_hit_per_bank_mask[bid];
end end
integer test_bid; integer test_bid;
always @(*) begin always @(*) begin
new_final_data_read = 0; new_final_data_read = 0;
for (test_bid=0; test_bid < NUMBER_BANKS; test_bid=test_bid+1) for (test_bid=0; test_bid < `CACHE_BANKS; test_bid=test_bid+1)
begin begin
if (hit_per_bank[test_bid]) begin if (hit_per_bank[test_bid]) begin
new_final_data_read[index_per_bank[test_bid]] = readdata_per_bank[test_bid]; new_final_data_read[index_per_bank[test_bid]] = readdata_per_bank[test_bid];
@@ -168,7 +168,7 @@ module VX_d_cache
end end
wire[NUMBER_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] | 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[2] | threads_serviced_per_bank[3] |
threads_serviced_per_bank[4] | threads_serviced_per_bank[5] | threads_serviced_per_bank[4] | threads_serviced_per_bank[5] |
@@ -184,7 +184,7 @@ module VX_d_cache
genvar tid; genvar tid;
for (tid = 0; tid < NUM_REQ; tid =tid+1) for (tid = 0; tid < `NUM_REQ; tid =tid+1)
begin begin
assign new_final_data_read_Qual[tid] = threads_serviced_Qual[tid] ? new_final_data_read[tid] : final_data_read[tid]; assign new_final_data_read_Qual[tid] = threads_serviced_Qual[tid] ? new_final_data_read[tid] : final_data_read[tid];
end end
@@ -197,12 +197,12 @@ module VX_d_cache
assign o_p_delay = delay; assign o_p_delay = delay;
wire[NUMBER_BANKS - 1 : 0][$clog2(NUM_REQ)-1:0] send_index_to_bank = index_per_bank; wire[`CACHE_BANKS - 1 : 0][$clog2(`NUM_REQ)-1:0] send_index_to_bank = index_per_bank;
wire[$clog2(NUMBER_BANKS)-1:0] miss_bank_index; wire[`CACHE_WAY_INDEX-1:0] miss_bank_index;
wire miss_found; wire miss_found;
VX_generic_priority_encoder #(.N(NUMBER_BANKS)) get_miss_index VX_generic_priority_encoder #(.N(`CACHE_BANKS)) get_miss_index
( (
.valids(detect_bank_miss), .valids(detect_bank_miss),
.index (miss_bank_index), .index (miss_bank_index),
@@ -258,7 +258,7 @@ module VX_d_cache
genvar bank_id; genvar bank_id;
generate generate
for (bank_id = 0; bank_id < NUMBER_BANKS; bank_id = bank_id + 1) for (bank_id = 0; bank_id < `CACHE_BANKS; bank_id = bank_id + 1)
begin begin
wire[31:0] bank_addr = (state == SEND_MEM_REQ) ? evict_addr : wire[31:0] bank_addr = (state == SEND_MEM_REQ) ? evict_addr :
(state == RECIV_MEM_RSP) ? miss_addr : (state == RECIV_MEM_RSP) ? miss_addr :
@@ -280,12 +280,12 @@ module VX_d_cache
((state == SEND_MEM_REQ)) ? 1'b0 : ((state == SEND_MEM_REQ)) ? 1'b0 :
normal_valid_in; normal_valid_in;
VX_Cache_Bank #( /*VX_Cache_Bank #(
.CACHE_SIZE(CACHE_SIZE), .CACHE_SIZE(CACHE_SIZE),
.CACHE_WAYS(CACHE_WAYS), .CACHE_WAYS(CACHE_WAYS),
.CACHE_BLOCK(CACHE_BLOCK), .CACHE_BLOCK(CACHE_BLOCK),
.CACHE_BANKS(CACHE_BANKS)) bank_structure .CACHE_BANKS(CACHE_BANKS)) bank_structure*/
( VX_Cache_Bank bank_structure(
.clk (clk), .clk (clk),
.rst (rst), .rst (rst),
.state (state), .state (state),

View File

@@ -61,7 +61,8 @@ module vortex_tb (
initial begin initial begin
// $fdumpfile("vortex1.vcd"); // $fdumpfile("vortex1.vcd");
load_file("../../runtime/vortex_runtime.hex"); //load_file("../../runtime/vortex_runtime.hex");
load_file("../../kernel/vortex_test.hex");
$dumpvars(0, vortex_tb); $dumpvars(0, vortex_tb);
reset = 1; reset = 1;
clk = 0; clk = 0;