2021-01-15 04:37:51 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// datapath.sv
|
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Written: sarahleilani@gmail.com and David_Harris@hmc.edu 9 January 2021
|
2021-01-15 04:37:51 +00:00
|
|
|
// Modified:
|
|
|
|
//
|
2021-01-28 20:18:23 +00:00
|
|
|
// Purpose: Wally Integer Datapath
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-12 12:35:44 +00:00
|
|
|
// Documentation: RISC-V System on Chip Design Chapter 4 (Figure 4.12)
|
|
|
|
//
|
2023-01-11 23:15:08 +00:00
|
|
|
// A component of the CORE-V-WALLY configurable RISC-V project.
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-01-15 04:37:51 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-01-15 04:37:51 +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-01-15 04:37:51 +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-01-15 04:37:51 +00:00
|
|
|
|
2021-01-23 15:48:12 +00:00
|
|
|
`include "wally-config.vh"
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2021-01-25 20:57:36 +00:00
|
|
|
module datapath (
|
2021-01-15 04:37:51 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
// Decode stage signals
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic [2:0] ImmSrcD,
|
|
|
|
input logic [31:0] InstrD,
|
2021-12-08 20:33:53 +00:00
|
|
|
input logic [2:0] Funct3E,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Execute stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallE, FlushE,
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic [1:0] ForwardAE, ForwardBE,
|
2021-12-08 20:33:53 +00:00
|
|
|
input logic [2:0] ALUControlE,
|
2021-01-28 20:18:23 +00:00
|
|
|
input logic ALUSrcAE, ALUSrcBE,
|
2021-12-08 20:33:53 +00:00
|
|
|
input logic ALUResultSrcE,
|
2021-02-27 02:12:27 +00:00
|
|
|
input logic JumpE,
|
2022-06-21 20:30:33 +00:00
|
|
|
input logic BranchSignedE,
|
2021-01-28 03:49:47 +00:00
|
|
|
input logic [`XLEN-1:0] PCE,
|
2021-02-27 02:12:27 +00:00
|
|
|
input logic [`XLEN-1:0] PCLinkE,
|
2022-06-21 20:30:33 +00:00
|
|
|
output logic [1:0] FlagsE,
|
2021-12-15 20:10:45 +00:00
|
|
|
output logic [`XLEN-1:0] IEUAdrE,
|
2021-11-17 18:53:17 +00:00
|
|
|
output logic [`XLEN-1:0] ForwardedSrcAE, ForwardedSrcBE, // *** these are the src outputs before the mux choosing between them and PCE to put in srcA/B
|
2021-01-15 04:37:51 +00:00
|
|
|
// Memory stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallM, FlushM,
|
2022-08-23 19:17:19 +00:00
|
|
|
input logic FWriteIntM, FCvtIntW,
|
2021-06-24 22:39:18 +00:00
|
|
|
input logic [`XLEN-1:0] FIntResM,
|
2021-01-28 20:18:23 +00:00
|
|
|
output logic [`XLEN-1:0] SrcAM,
|
2022-08-22 20:43:04 +00:00
|
|
|
output logic [`XLEN-1:0] WriteDataM,
|
2021-01-15 04:37:51 +00:00
|
|
|
// Writeback stage signals
|
2021-02-08 04:21:55 +00:00
|
|
|
input logic StallW, FlushW,
|
2023-01-11 19:06:37 +00:00
|
|
|
(* mark_debug = "true" *) input logic RegWriteW, IntDivW,
|
2021-03-01 05:09:45 +00:00
|
|
|
input logic SquashSCW,
|
2021-02-16 03:27:35 +00:00
|
|
|
input logic [2:0] ResultSrcW,
|
2022-06-13 22:47:51 +00:00
|
|
|
input logic [`XLEN-1:0] FCvtIntResW,
|
2022-06-20 22:53:13 +00:00
|
|
|
input logic [`XLEN-1:0] ReadDataW,
|
|
|
|
input logic [`XLEN-1:0] CSRReadValW, MDUResultW,
|
2023-01-11 19:46:36 +00:00
|
|
|
input logic [`XLEN-1:0] FIntDivResultW,
|
2022-12-15 01:03:13 +00:00
|
|
|
// Hazard Unit signals
|
2021-01-28 20:18:23 +00:00
|
|
|
output logic [4:0] Rs1D, Rs2D, Rs1E, Rs2E,
|
2021-02-02 18:42:23 +00:00
|
|
|
output logic [4:0] RdE, RdM, RdW
|
2021-01-28 20:18:23 +00:00
|
|
|
);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Fetch stage signals
|
|
|
|
// Decode stage signals
|
2021-12-19 05:26:00 +00:00
|
|
|
logic [`XLEN-1:0] R1D, R2D;
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] ExtImmD;
|
2021-01-15 04:37:51 +00:00
|
|
|
logic [4:0] RdD;
|
|
|
|
// Execute stage signals
|
2021-12-19 05:26:00 +00:00
|
|
|
logic [`XLEN-1:0] R1E, R2E;
|
2021-01-28 03:49:47 +00:00
|
|
|
logic [`XLEN-1:0] ExtImmE;
|
2021-12-08 20:33:53 +00:00
|
|
|
logic [`XLEN-1:0] SrcAE, SrcBE;
|
2021-12-15 19:38:26 +00:00
|
|
|
logic [`XLEN-1:0] ALUResultE, AltResultE, IEUResultE;
|
2021-01-15 04:37:51 +00:00
|
|
|
// Memory stage signals
|
2021-12-15 19:38:26 +00:00
|
|
|
logic [`XLEN-1:0] IEUResultM;
|
2022-02-28 20:50:51 +00:00
|
|
|
logic [`XLEN-1:0] IFResultM;
|
2021-01-15 04:37:51 +00:00
|
|
|
// Writeback stage signals
|
2021-03-01 05:09:45 +00:00
|
|
|
logic [`XLEN-1:0] SCResultW;
|
2021-01-23 15:48:12 +00:00
|
|
|
logic [`XLEN-1:0] ResultW;
|
2022-12-15 01:03:13 +00:00
|
|
|
logic [`XLEN-1:0] IFResultW, IFCvtResultW, MulDivResultW;
|
2022-08-23 18:16:36 +00:00
|
|
|
|
2021-02-03 00:44:37 +00:00
|
|
|
// Decode stage
|
2021-01-28 03:49:47 +00:00
|
|
|
assign Rs1D = InstrD[19:15];
|
|
|
|
assign Rs2D = InstrD[24:20];
|
|
|
|
assign RdD = InstrD[11:7];
|
2022-02-28 20:50:51 +00:00
|
|
|
regfile regf(clk, reset, RegWriteW, Rs1D, Rs2D, RdW, ResultW, R1D, R2D);
|
2021-12-08 08:24:27 +00:00
|
|
|
extend ext(.InstrD(InstrD[31:7]), .ImmSrcD, .ExtImmD);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Execute stage pipeline register and logic
|
2021-12-19 05:26:00 +00:00
|
|
|
flopenrc #(`XLEN) RD1EReg(clk, reset, FlushE, ~StallE, R1D, R1E);
|
|
|
|
flopenrc #(`XLEN) RD2EReg(clk, reset, FlushE, ~StallE, R2D, R2E);
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) ExtImmEReg(clk, reset, FlushE, ~StallE, ExtImmD, ExtImmE);
|
2021-12-14 19:15:47 +00:00
|
|
|
flopenrc #(5) Rs1EReg(clk, reset, FlushE, ~StallE, Rs1D, Rs1E);
|
|
|
|
flopenrc #(5) Rs2EReg(clk, reset, FlushE, ~StallE, Rs2D, Rs2E);
|
|
|
|
flopenrc #(5) RdEReg(clk, reset, FlushE, ~StallE, RdD, RdE);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
2022-02-28 20:50:51 +00:00
|
|
|
mux3 #(`XLEN) faemux(R1E, ResultW, IFResultM, ForwardAE, ForwardedSrcAE);
|
|
|
|
mux3 #(`XLEN) fbemux(R2E, ResultW, IFResultM, ForwardBE, ForwardedSrcBE);
|
2022-06-21 20:30:33 +00:00
|
|
|
comparator_dc_flip #(`XLEN) comp(ForwardedSrcAE, ForwardedSrcBE, BranchSignedE, FlagsE);
|
2021-11-17 18:53:17 +00:00
|
|
|
mux2 #(`XLEN) srcamux(ForwardedSrcAE, PCE, ALUSrcAE, SrcAE);
|
|
|
|
mux2 #(`XLEN) srcbmux(ForwardedSrcBE, ExtImmE, ALUSrcBE, SrcBE);
|
2021-12-15 20:10:45 +00:00
|
|
|
alu #(`XLEN) alu(SrcAE, SrcBE, ALUControlE, Funct3E, ALUResultE, IEUAdrE);
|
2021-12-14 19:15:47 +00:00
|
|
|
mux2 #(`XLEN) altresultmux(ExtImmE, PCLinkE, JumpE, AltResultE);
|
2021-12-15 19:38:26 +00:00
|
|
|
mux2 #(`XLEN) ieuresultmux(ALUResultE, AltResultE, ALUResultSrcE, IEUResultE);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Memory stage pipeline register
|
2021-02-08 04:21:55 +00:00
|
|
|
flopenrc #(`XLEN) SrcAMReg(clk, reset, FlushM, ~StallM, SrcAE, SrcAM);
|
2021-12-15 19:38:26 +00:00
|
|
|
flopenrc #(`XLEN) IEUResultMReg(clk, reset, FlushM, ~StallM, IEUResultE, IEUResultM);
|
2021-12-14 19:15:47 +00:00
|
|
|
flopenrc #(5) RdMReg(clk, reset, FlushM, ~StallM, RdE, RdM);
|
2022-08-22 20:43:04 +00:00
|
|
|
flopenrc #(`XLEN) WriteDataMReg(clk, reset, FlushM, ~StallM, ForwardedSrcBE, WriteDataM);
|
2021-01-15 04:37:51 +00:00
|
|
|
|
|
|
|
// Writeback stage pipeline register and logic
|
2022-02-28 20:50:51 +00:00
|
|
|
flopenrc #(`XLEN) IFResultWReg(clk, reset, FlushW, ~StallW, IFResultM, IFResultW);
|
2021-12-14 19:15:47 +00:00
|
|
|
flopenrc #(5) RdWReg(clk, reset, FlushW, ~StallW, RdM, RdW);
|
2021-12-18 13:36:32 +00:00
|
|
|
|
2022-08-23 18:16:36 +00:00
|
|
|
// floating point inputs: FIntResM comes from fclass, fcmp, fmv; FCvtIntResW comes from fcvt
|
2022-08-22 20:28:51 +00:00
|
|
|
if (`F_SUPPORTED) begin:fpmux
|
2022-06-28 21:33:31 +00:00
|
|
|
mux2 #(`XLEN) resultmuxM(IEUResultM, FIntResM, FWriteIntM, IFResultM);
|
2022-08-23 19:17:19 +00:00
|
|
|
mux2 #(`XLEN) cvtresultmuxW(IFResultW, FCvtIntResW, FCvtIntW, IFCvtResultW);
|
2022-12-15 14:37:55 +00:00
|
|
|
if (`IDIV_ON_FPU) begin
|
2023-01-11 19:46:36 +00:00
|
|
|
mux2 #(`XLEN) divresultmuxW(MDUResultW, FIntDivResultW, IntDivW, MulDivResultW);
|
2022-12-15 14:37:55 +00:00
|
|
|
end else begin
|
|
|
|
assign MulDivResultW = MDUResultW;
|
|
|
|
end
|
2022-01-05 14:35:25 +00:00
|
|
|
end else begin:fpmux
|
2022-08-23 18:16:36 +00:00
|
|
|
assign IFResultM = IEUResultM; assign IFCvtResultW = IFResultW;
|
2022-12-15 01:03:13 +00:00
|
|
|
assign MulDivResultW = MDUResultW;
|
2022-01-05 14:35:25 +00:00
|
|
|
end
|
2022-12-15 01:03:13 +00:00
|
|
|
mux5 #(`XLEN) resultmuxW(IFCvtResultW, ReadDataW, CSRReadValW, MulDivResultW, SCResultW, ResultSrcW, ResultW);
|
2022-08-22 20:28:51 +00:00
|
|
|
|
2021-03-01 05:09:45 +00:00
|
|
|
// handle Store Conditional result if atomic extension supported
|
2022-01-05 14:35:25 +00:00
|
|
|
if (`A_SUPPORTED) assign SCResultW = {{(`XLEN-1){1'b0}}, SquashSCW};
|
|
|
|
else assign SCResultW = 0;
|
2021-01-15 04:37:51 +00:00
|
|
|
endmodule
|