cvw/pipelined/src/ifu/brpred/RAsPredictor.sv

91 lines
2.7 KiB
Systemverilog
Raw Normal View History

///////////////////////////////////////////
// RASPredictor.sv
//
// Written: Ross Thomposn
// Email: ross1728@gmail.com
// Created: February 15, 2021
// Modified:
//
// Purpose: 2 bit saturating counter predictor with parameterized table depth.
//
2023-01-11 23:15:08 +00:00
// A component of the CORE-V-WALLY configurable RISC-V project.
//
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
//
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
//
// Licensed under the Solderpad Hardware License v 2.1 (the “License”); you may not use this file
// except in compliance with the License, or, at your option, the Apache License version 2.0. You
// may obtain a copy of the License at
//
// https://solderpad.org/licenses/SHL-2.1/
//
// Unless required by applicable law or agreed to in writing, any work distributed under the
// License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
// either express or implied. See the License for the specific language governing permissions
// and limitations under the License.
////////////////////////////////////////////////////////////////////////////////////////////////
`include "wally-config.vh"
module RASPredictor
#(parameter int StackSize = 16
)
2021-10-27 19:43:55 +00:00
(input logic clk,
2023-01-25 23:06:25 +00:00
input logic reset, StallF, StallD, StallE,
2023-01-13 21:56:10 +00:00
output logic [`XLEN-1:0] RASPCF,
input logic [3:0] WrongPredInstrClassD,
2023-01-25 23:06:25 +00:00
input logic [3:0] InstrClassD, InstrClassE, PredInstrClassF,
input logic [`XLEN-1:0] PCLinkE
);
2023-01-13 21:56:10 +00:00
// *** need to update so it either doesn't push until the memory stage
// or need to repair flushed push.
// *** need to repair popped and then flushed returns.
2021-10-27 19:43:55 +00:00
logic CounterEn;
localparam Depth = $clog2(StackSize);
2021-10-27 19:43:55 +00:00
logic [Depth-1:0] PtrD, PtrQ, PtrP1, PtrM1;
logic [StackSize-1:0] [`XLEN-1:0] memory;
integer index;
2023-01-25 23:06:25 +00:00
logic PopF;
logic PushE;
2023-01-25 23:06:25 +00:00
assign PopF = PredInstrClassF[2] & ~StallF;
assign PushE = InstrClassE[3] & ~StallE;
assign CounterEn = PopF | PushE | WrongPredInstrClassD[2];
assign PtrD = PopF | InstrClassD[2] ? PtrM1 : PtrP1;
assign PtrM1 = PtrQ - 1'b1;
assign PtrP1 = PtrQ + 1'b1;
2023-01-13 21:56:10 +00:00
// may have to handle a PushE and an incr at the same time.
// *** what happens if jal is executing and there is a return being flushed in Decode?
flopenr #(Depth) PTR(.clk(clk),
2021-10-27 19:43:55 +00:00
.reset(reset),
.en(CounterEn),
.d(PtrD),
.q(PtrQ));
// RAS must be reset.
always_ff @ (posedge clk) begin
if(reset) begin
for(index=0; index<StackSize; index++)
2021-10-27 19:43:55 +00:00
memory[index] <= {`XLEN{1'b0}};
2023-01-13 21:56:10 +00:00
end else if(PushE) begin
memory[PtrP1] <= #1 PCLinkE;
end
end
2023-01-13 21:56:10 +00:00
assign RASPCF = memory[PtrQ];
endmodule