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 22:03:44 +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,
|
|
|
|
input logic reset,
|
|
|
|
input logic pop,
|
2021-02-15 20:51:39 +00:00
|
|
|
output logic [`XLEN-1:0] popPC,
|
2021-10-27 19:43:55 +00:00
|
|
|
input logic push,
|
|
|
|
input logic incr,
|
2021-02-15 20:51:39 +00:00
|
|
|
input logic [`XLEN-1:0] pushPC
|
|
|
|
);
|
|
|
|
|
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;
|
2021-02-15 20:51:39 +00:00
|
|
|
|
|
|
|
assign CounterEn = pop | push | incr;
|
|
|
|
|
|
|
|
assign PtrD = pop ? PtrM1 : PtrP1;
|
|
|
|
|
|
|
|
assign PtrM1 = PtrQ - 1'b1;
|
|
|
|
assign PtrP1 = PtrQ + 1'b1;
|
|
|
|
// may have to handle a push and an incr at the same time.
|
|
|
|
// *** 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}};
|
2021-02-20 02:09:07 +00:00
|
|
|
end else if(push) begin
|
2021-02-15 20:51:39 +00:00
|
|
|
memory[PtrP1] <= #1 pushPC;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assign popPC = memory[PtrQ];
|
|
|
|
|
|
|
|
|
|
|
|
endmodule
|
|
|
|
|
|
|
|
|
|
|
|
|