2021-02-02 18:42:23 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// forward.sv
|
|
|
|
//
|
2023-01-17 14:02:26 +00:00
|
|
|
// Written: David_Harris@hmc.edu, Sarah.Harris@unlv.edu
|
|
|
|
// Created: 9 January 2021
|
2021-02-02 18:42:23 +00:00
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Determine datapath forwarding
|
|
|
|
//
|
2023-01-12 12:35:44 +00:00
|
|
|
// Documentation: RISC-V System on Chip Design Chapter 4 (Section 4.2.2.3)
|
|
|
|
//
|
2023-01-11 23:15:08 +00:00
|
|
|
// A component of the CORE-V-WALLY configurable RISC-V project.
|
2021-02-02 18:42:23 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-02-02 18:42:23 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-02-02 18:42:23 +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-02 18:42:23 +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-02 18:42:23 +00:00
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module forward(
|
|
|
|
// Detect hazards
|
2023-01-17 14:02:26 +00:00
|
|
|
input logic [4:0] Rs1D, Rs2D, Rs1E, Rs2E, RdE, RdM, RdW, // Source and destination registers
|
|
|
|
input logic MemReadE, MDUE, CSRReadE, // Execute stage instruction is a load (MemReadE), divide (MDUE), or CSR read (CSRReadE)
|
|
|
|
input logic RegWriteM, RegWriteW, // Instruction in Memory or Writeback stage writes register file
|
2023-01-17 18:51:44 +00:00
|
|
|
input logic FCvtIntE, // FPU convert float to int
|
|
|
|
input logic SCE, // Store Conditional instruction
|
2021-02-08 04:21:55 +00:00
|
|
|
// Forwarding controls
|
2023-01-17 14:02:26 +00:00
|
|
|
output logic [1:0] ForwardAE, ForwardBE, // Select signals for forwarding multiplexers
|
|
|
|
output logic FCvtIntStallD, LoadStallD, MDUStallD, CSRRdStallD // Stall due to conversion, load, multiply/divide, CSR read
|
2021-02-02 18:42:23 +00:00
|
|
|
);
|
2021-12-18 13:40:38 +00:00
|
|
|
|
2023-01-17 14:02:26 +00:00
|
|
|
logic MatchDE; // Match between a source register in Decode stage and destination register in Execute stage
|
2021-02-02 18:42:23 +00:00
|
|
|
|
|
|
|
always_comb begin
|
|
|
|
ForwardAE = 2'b00;
|
|
|
|
ForwardBE = 2'b00;
|
|
|
|
if (Rs1E != 5'b0)
|
2021-12-18 13:36:32 +00:00
|
|
|
if ((Rs1E == RdM) & RegWriteM) ForwardAE = 2'b10;
|
|
|
|
else if ((Rs1E == RdW) & RegWriteW) ForwardAE = 2'b01;
|
2021-02-02 18:42:23 +00:00
|
|
|
|
|
|
|
if (Rs2E != 5'b0)
|
2021-12-18 13:36:32 +00:00
|
|
|
if ((Rs2E == RdM) & RegWriteM) ForwardBE = 2'b10;
|
|
|
|
else if ((Rs2E == RdW) & RegWriteW) ForwardBE = 2'b01;
|
2021-02-02 18:42:23 +00:00
|
|
|
end
|
|
|
|
|
2021-02-26 22:00:07 +00:00
|
|
|
// Stall on dependent operations that finish in Mem Stage and can't bypass in time
|
2022-12-23 17:45:42 +00:00
|
|
|
assign MatchDE = ((Rs1D == RdE) | (Rs2D == RdE)) & (RdE != 5'b0); // Decode-stage instruction source depends on result from execute stage instruction
|
2022-12-02 19:55:23 +00:00
|
|
|
assign FCvtIntStallD = FCvtIntE & MatchDE; // FPU to Integer transfers have single-cycle latency except fcvt
|
2021-12-18 13:40:38 +00:00
|
|
|
assign LoadStallD = (MemReadE|SCE) & MatchDE;
|
2023-01-01 21:54:01 +00:00
|
|
|
assign MDUStallD = MDUE & MatchDE; // Int mult/div is at least two cycle latency, even when coming from the FDIV
|
2021-12-18 13:40:38 +00:00
|
|
|
assign CSRRdStallD = CSRReadE & MatchDE;
|
2021-02-02 18:42:23 +00:00
|
|
|
endmodule
|