cvw/pipelined/src/ieu/forward.sv

62 lines
2.4 KiB
Systemverilog
Raw Normal View History

2021-02-02 18:42:23 +00:00
///////////////////////////////////////////
// forward.sv
//
// Written: David_Harris@hmc.edu 9 January 2021
// Modified:
//
// Purpose: Determine datapath forwarding
//
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
//
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
2021-02-02 18:42:23 +00:00
//
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
2021-02-02 18:42:23 +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
//
// 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.
////////////////////////////////////////////////////////////////////////////////////////////////
2021-02-02 18:42:23 +00:00
`include "wally-config.vh"
module forward(
// Detect hazards
input logic [4:0] Rs1D, Rs2D, Rs1E, Rs2E, RdE, RdM, RdW,
input logic MemReadE, MDUE, CSRReadE,
input logic RegWriteM, RegWriteW,
input logic FCvtIntE,
input logic SCE,
2021-02-08 04:21:55 +00:00
// Forwarding controls
2021-02-02 18:42:23 +00:00
output logic [1:0] ForwardAE, ForwardBE,
2022-12-02 19:55:23 +00:00
output logic FCvtIntStallD, LoadStallD, MDUStallD, CSRRdStallD
2021-02-02 18:42:23 +00:00
);
2021-12-18 13:40:38 +00:00
logic MatchDE;
2021-02-02 18:42:23 +00:00
always_comb begin
ForwardAE = 2'b00;
ForwardBE = 2'b00;
if (Rs1E != 5'b0)
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)
if ((Rs2E == RdM) & RegWriteM) ForwardBE = 2'b10;
else if ((Rs2E == RdW) & RegWriteW) ForwardBE = 2'b01;
2021-02-02 18:42:23 +00:00
end
// Stall on dependent operations that finish in Mem Stage and can't bypass in time
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;
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