From 1315a0bf4a24c36c5c5dc95bd6759d327b67155a Mon Sep 17 00:00:00 2001 From: Ross Thompson Date: Fri, 26 May 2023 16:00:14 -0500 Subject: [PATCH] Got the branch predictor parameterized using Lim's method. Also had to add a global enum included in both cvw.sv and the configs which defines the branch predictor types. This should be synthesizable, but I'll need to double check. --- config/buildroot/config.vh | 3 +- config/rv32e/config.vh | 4 +- config/rv32gc/config.vh | 6 +- config/rv32i/config.vh | 4 +- config/rv32imc/config.vh | 4 +- config/rv64fpquad/config.vh | 4 +- config/rv64gc/config.vh | 5 +- config/rv64gc/wally-config.vh | 2 +- config/rv64i/config.vh | 4 +- config/shared/BranchPredictorType.vh | 3 + config/shared/parameter-defs.vh | 1 + src/fpu/postproc/round.sv | 1 - src/ifu/bpred/RASPredictor.sv | 12 ++-- src/ifu/bpred/bpred.sv | 95 ++++++++++++++-------------- src/ifu/bpred/btb.sv | 38 ++++++----- src/ifu/bpred/gshare.sv | 6 +- src/ifu/bpred/gsharebasic.sv | 7 +- src/ifu/bpred/icpred.sv | 17 ++--- src/ifu/bpred/localaheadbp.sv | 11 ++-- src/ifu/bpred/localbpbasic.sv | 7 +- src/ifu/bpred/localrepairbp.sv | 11 ++-- src/ifu/bpred/satCounter2.sv | 2 - src/ifu/bpred/twoBitPredictor.sv | 7 +- src/ifu/ifu.sv | 2 +- src/wally/cvw.sv | 5 +- 25 files changed, 132 insertions(+), 129 deletions(-) create mode 100644 config/shared/BranchPredictorType.vh diff --git a/config/buildroot/config.vh b/config/buildroot/config.vh index 59848a39a..f5a1b6421 100644 --- a/config/buildroot/config.vh +++ b/config/buildroot/config.vh @@ -27,6 +27,7 @@ // include shared configuration `include "wally-shared.vh" +`include "BranchPredictorType.vh" localparam FPGA = 1; localparam QEMU = 0; @@ -131,7 +132,7 @@ localparam PLIC_UART_ID = 32'd10; localparam PLIC_GPIO_ID = 32'd3; localparam BPRED_SUPPORTED = 1; -localparam BPRED_TYPE = "GSHARE_N"; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT; +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/rv32e/config.vh b/config/rv32e/config.vh index e41db6068..b2e45562e 100644 --- a/config/rv32e/config.vh +++ b/config/rv32e/config.vh @@ -25,6 +25,8 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -131,7 +133,7 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 0; -localparam BPRED_TYPE = "GSHARE_N"; // GSHARE_B, GLOBAL_N, GLOBAL_B, TWOBIT_N +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/rv32gc/config.vh b/config/rv32gc/config.vh index 855a374ae..23c865c8c 100644 --- a/config/rv32gc/config.vh +++ b/config/rv32gc/config.vh @@ -27,6 +27,7 @@ // include shared configuration // `include "wally-shared.vh" +`include "BranchPredictorType.vh" localparam FPGA = 0; localparam QEMU = 0; @@ -133,10 +134,9 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 1; -// BP_GSHARE, BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT -// GSHARE_N, GSHARE_B, GLOBAL_N, GLOBAL_B, TWOBIT_N -localparam BPRED_TYPE = "GSHARE_N"; // GSHARE_B, GLOBAL_N, GLOBAL_B, TWOBIT_N +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd16; +localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; localparam SVADU_SUPPORTED = 1; diff --git a/config/rv32i/config.vh b/config/rv32i/config.vh index 54f9791a5..bd307f17d 100644 --- a/config/rv32i/config.vh +++ b/config/rv32i/config.vh @@ -25,6 +25,8 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -131,7 +133,7 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 0; -localparam BPRED_TYPE = "GSHARE_N"; // GSHARE_B, GLOBAL_N, GLOBAL_B, TWOBIT_N +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/rv32imc/config.vh b/config/rv32imc/config.vh index 5b0535ad9..d49fa7ec3 100644 --- a/config/rv32imc/config.vh +++ b/config/rv32imc/config.vh @@ -25,6 +25,8 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -130,7 +132,7 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 0; -localparam BPRED_TYPE = "GSHARE_N"; // GSHARE_B, GLOBAL_N, GLOBAL_B, TWOBIT_N +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/rv64fpquad/config.vh b/config/rv64fpquad/config.vh index 656e5c90c..655fab9b6 100644 --- a/config/rv64fpquad/config.vh +++ b/config/rv64fpquad/config.vh @@ -25,6 +25,8 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -133,7 +135,7 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 1; -localparam BPRED_TYPE = "GSHARE_N"; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/rv64gc/config.vh b/config/rv64gc/config.vh index 3e6ba806e..923cd08d3 100644 --- a/config/rv64gc/config.vh +++ b/config/rv64gc/config.vh @@ -28,6 +28,8 @@ // include shared configuration // `include "wally-shared.vh" +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -136,7 +138,8 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 1; -localparam BPRED_TYPE = "GSHARE_N"; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT +localparam BPRED_NUM_LHR = 32'd6; localparam BPRED_SIZE = 32'd10; localparam BTB_SIZE = 32'd10; diff --git a/config/rv64gc/wally-config.vh b/config/rv64gc/wally-config.vh index c933d87ae..1dd3d7f4f 100644 --- a/config/rv64gc/wally-config.vh +++ b/config/rv64gc/wally-config.vh @@ -138,7 +138,7 @@ `define BPRED_SUPPORTED 1 //`define BPRED_TYPE "BP_GLOBAL_BASIC" // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT `define BPRED_TYPE "BP_GSHARE" // "BP_LOCAL_REPAIR" // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT -`define BPRED_SIZE 6 +`define BPRED_SIZE 10 `define BPRED_NUM_LHR 4 `define BTB_SIZE 10 diff --git a/config/rv64i/config.vh b/config/rv64i/config.vh index 15c0e7994..d2914c966 100644 --- a/config/rv64i/config.vh +++ b/config/rv64i/config.vh @@ -25,6 +25,8 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// +`include "BranchPredictorType.vh" + localparam FPGA = 0; localparam QEMU = 0; @@ -133,7 +135,7 @@ localparam PLIC_GPIO_ID = 32'd3; localparam PLIC_UART_ID = 32'd10; localparam BPRED_SUPPORTED = 0; -localparam BPRED_TYPE = "GSHARE_N"; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT +localparam BranchPredictorType BPRED_TYPE = BP_GSHARE; // BP_GSHARE_BASIC, BP_GLOBAL, BP_GLOBAL_BASIC, BP_TWOBIT localparam BPRED_SIZE = 32'd10; localparam BPRED_NUM_LHR = 32'd6; localparam BTB_SIZE = 32'd10; diff --git a/config/shared/BranchPredictorType.vh b/config/shared/BranchPredictorType.vh new file mode 100644 index 000000000..0f62fb954 --- /dev/null +++ b/config/shared/BranchPredictorType.vh @@ -0,0 +1,3 @@ +typedef enum {BP_TWOBIT, BP_GSHARE, BP_GLOBAL, BP_GSHARE_BASIC, + BP_GLOBAL_BASIC, BP_LOCAL_BASIC, BP_LOCAL_AHEAD, BP_LOCAL_REPAIR} BranchPredictorType; + diff --git a/config/shared/parameter-defs.vh b/config/shared/parameter-defs.vh index 58e061fbc..1dd28b746 100644 --- a/config/shared/parameter-defs.vh +++ b/config/shared/parameter-defs.vh @@ -74,6 +74,7 @@ parameter cvw_t P = '{ BPRED_SUPPORTED : BPRED_SUPPORTED, BPRED_TYPE : BPRED_TYPE, BPRED_SIZE : BPRED_SIZE, + BPRED_NUM_LHR : BPRED_NUM_LHR, BTB_SIZE : BTB_SIZE, RADIX : RADIX, DIVCOPIES : DIVCOPIES, diff --git a/src/fpu/postproc/round.sv b/src/fpu/postproc/round.sv index 6de52f778..4f6ea819d 100644 --- a/src/fpu/postproc/round.sv +++ b/src/fpu/postproc/round.sv @@ -26,7 +26,6 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// - module round import cvw::*; #(parameter cvw_t P) ( input logic [P.FMTBITS-1:0] OutFmt, // output format input logic [2:0] Frm, // rounding mode diff --git a/src/ifu/bpred/RASPredictor.sv b/src/ifu/bpred/RASPredictor.sv index 21cad922f..85b300fd0 100644 --- a/src/ifu/bpred/RASPredictor.sv +++ b/src/ifu/bpred/RASPredictor.sv @@ -27,9 +27,7 @@ // and limitations under the License. //////////////////////////////////////////////////////////////////////////////////////////////// -`include "wally-config.vh" - -module RASPredictor #(parameter int StackSize = 16 )( +module RASPredictor import cvw::*; #(parameter cvw_t P, StackSize = 16 )( input logic clk, input logic reset, input logic StallF, StallD, StallE, StallM, FlushD, FlushE, FlushM, @@ -37,15 +35,15 @@ module RASPredictor #(parameter int StackSize = 16 )( input logic ReturnD, input logic ReturnE, CallE, // Instr class input logic BPReturnF, - input logic [`XLEN-1:0] PCLinkE, // PC of instruction after a call - output logic [`XLEN-1:0] RASPCF // Top of the stack + input logic [P.XLEN-1:0] PCLinkE, // PC of instruction after a call + output logic [P.XLEN-1:0] RASPCF // Top of the stack ); logic CounterEn; localparam Depth = $clog2(StackSize); logic [Depth-1:0] NextPtr, Ptr, P1, M1, IncDecPtr; - logic [StackSize-1:0] [`XLEN-1:0] memory; + logic [StackSize-1:0] [P.XLEN-1:0] memory; integer index; logic PopF; @@ -85,7 +83,7 @@ module RASPredictor #(parameter int StackSize = 16 )( always_ff @ (posedge clk) begin if(reset) begin for(index=0; index