2021-02-15 20:51:39 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// 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.
|
2021-02-15 20:51:39 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-02-15 20:51:39 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-02-15 20:51:39 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// 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
|
2021-02-15 20:51:39 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// 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.
|
2022-01-07 12:58:40 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
2021-02-15 20:51:39 +00:00
|
|
|
|
|
|
|
`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,
|
2023-01-14 00:05:47 +00:00
|
|
|
input logic [3:0] WrongPredInstrClassD,
|
2023-01-25 23:06:25 +00:00
|
|
|
input logic [3:0] InstrClassD, InstrClassE, PredInstrClassF,
|
2023-01-14 00:05:47 +00:00
|
|
|
input logic [`XLEN-1:0] PCLinkE
|
2021-02-15 20:51:39 +00:00
|
|
|
);
|
|
|
|
|
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;
|
2021-02-15 20:51:39 +00:00
|
|
|
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;
|
2021-02-15 20:51:39 +00:00
|
|
|
|
2023-01-25 23:06:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
assign PopF = PredInstrClassF[2] & ~StallF;
|
|
|
|
assign PushE = InstrClassE[3] & ~StallE;
|
|
|
|
|
|
|
|
assign CounterEn = PopF | PushE | WrongPredInstrClassD[2];
|
2021-02-15 20:51:39 +00:00
|
|
|
|
2023-01-14 00:05:47 +00:00
|
|
|
assign PtrD = PopF | InstrClassD[2] ? PtrM1 : PtrP1;
|
2021-02-15 20:51:39 +00:00
|
|
|
|
|
|
|
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.
|
2021-02-15 20:51:39 +00:00
|
|
|
// *** what happens if jal is executing and there is a return being flushed in Decode?
|
|
|
|
|
2021-03-31 16:54:02 +00:00
|
|
|
flopenr #(Depth) PTR(.clk(clk),
|
2021-10-27 19:43:55 +00:00
|
|
|
.reset(reset),
|
|
|
|
.en(CounterEn),
|
|
|
|
.d(PtrD),
|
|
|
|
.q(PtrQ));
|
2021-02-15 20:51:39 +00:00
|
|
|
|
2021-02-20 02:09:07 +00:00
|
|
|
// RAS must be reset.
|
2021-10-27 14:57:11 +00:00
|
|
|
always_ff @ (posedge clk) begin
|
2021-02-20 02:09:07 +00:00
|
|
|
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;
|
2021-02-15 20:51:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-01-13 21:56:10 +00:00
|
|
|
assign RASPCF = memory[PtrQ];
|
2021-02-15 20:51:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
|