cvw/pipelined/src/ieu/datapath.sv

144 lines
6.3 KiB
Systemverilog
Raw Normal View History

2021-01-15 04:37:51 +00:00
///////////////////////////////////////////
// datapath.sv
//
// Written: David_Harris@hmc.edu 9 January 2021
// Modified:
//
// Purpose: Wally Integer Datapath
2021-01-15 04:37:51 +00:00
//
// A component of the Wally configurable RISC-V project.
//
// Copyright (C) 2021 Harvey Mudd College & Oklahoma State University
//
// MIT LICENSE
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
2021-01-15 04:37:51 +00:00
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
2021-01-15 04:37:51 +00:00
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
// OR OTHER DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////
2021-01-15 04:37:51 +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
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,
input logic [1:0] ForwardAE, ForwardBE,
2021-12-08 20:33:53 +00:00
input logic [2:0] ALUControlE,
input logic ALUSrcAE, ALUSrcBE,
2021-12-08 20:33:53 +00:00
input logic ALUResultSrcE,
input logic JumpE,
input logic IllegalFPUInstrE,
2021-06-24 22:39:18 +00:00
input logic [`XLEN-1:0] FWriteDataE,
input logic [`XLEN-1:0] PCE,
input logic [`XLEN-1:0] PCLinkE,
output logic [2:0] FlagsE,
output logic [`XLEN-1:0] IEUAdrE,
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,
2021-06-24 22:39:18 +00:00
input logic FWriteIntM,
input logic [`XLEN-1:0] FIntResM,
output logic [`XLEN-1:0] SrcAM,
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,
2022-01-18 23:29:21 +00:00
(* mark_debug = "true" *) input logic RegWriteW,
input logic SquashSCW,
2021-02-16 03:27:35 +00:00
input logic [2:0] ResultSrcW,
output logic [`XLEN-1:0] ReadDataW,
// input logic [`XLEN-1:0] PCLinkW,
input logic [`XLEN-1:0] CSRReadValW, ReadDataM, MDUResultW,
2021-01-15 04:37:51 +00:00
// Hazard Unit signals
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-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;
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;
logic [`XLEN-1:0] ExtImmE;
// logic [`XLEN-1:0] ForwardedSrcAE, ForwardedSrcBE, SrcAE2, SrcBE2; // *** MAde forwardedsrcae an output to get rid of a mux in the critical path.
2021-12-08 20:33:53 +00:00
logic [`XLEN-1:0] SrcAE, SrcBE;
logic [`XLEN-1:0] SrcAE2, SrcBE2;
2021-12-15 19:38:26 +00:00
logic [`XLEN-1:0] ALUResultE, AltResultE, IEUResultE;
logic [`XLEN-1:0] WriteDataE;
2021-01-15 04:37:51 +00:00
// Memory stage signals
2021-12-15 19:38:26 +00:00
logic [`XLEN-1:0] IEUResultM;
2021-06-24 15:20:21 +00:00
logic [`XLEN-1:0] ResultM;
2021-01-15 04:37:51 +00:00
// Writeback stage signals
logic [`XLEN-1:0] SCResultW;
2021-05-21 02:17:59 +00:00
logic [`XLEN-1:0] WriteDataW;
logic [`XLEN-1:0] ResultW;
2021-02-03 00:44:37 +00:00
// Decode stage
assign Rs1D = InstrD[19:15];
assign Rs2D = InstrD[24:20];
assign RdD = InstrD[11:7];
2021-12-19 05:26:00 +00:00
regfile regf(clk, reset, RegWriteW, Rs1D, Rs2D, RdW, WriteDataW, R1D, R2D);
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
2021-12-19 05:26:00 +00:00
mux3 #(`XLEN) faemux(R1E, WriteDataW, ResultM, ForwardAE, ForwardedSrcAE);
mux3 #(`XLEN) fbemux(R2E, WriteDataW, ResultM, ForwardBE, ForwardedSrcBE);
2021-12-15 19:38:26 +00:00
comparator #(`XLEN) comp(ForwardedSrcAE, ForwardedSrcBE, FlagsE);
mux2 #(`XLEN) srcamux(ForwardedSrcAE, PCE, ALUSrcAE, SrcAE);
mux2 #(`XLEN) srcbmux(ForwardedSrcBE, ExtImmE, ALUSrcBE, SrcBE);
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-02-08 04:21:55 +00:00
flopenrc #(`XLEN) WriteDataMReg(clk, reset, FlushM, ~StallM, WriteDataE, WriteDataM);
2021-12-14 19:15:47 +00:00
flopenrc #(5) RdMReg(clk, reset, FlushM, ~StallM, RdE, RdM);
2021-01-15 04:37:51 +00:00
// Writeback stage pipeline register and logic
2021-06-24 22:39:18 +00:00
flopenrc #(`XLEN) ResultWReg(clk, reset, FlushW, ~StallW, ResultM, ResultW);
2021-12-14 19:15:47 +00:00
flopenrc #(5) RdWReg(clk, reset, FlushW, ~StallW, RdM, RdW);
flopen #(`XLEN) ReadDataWReg(.clk, .en(~StallW), .d(ReadDataM), .q(ReadDataW));
mux5 #(`XLEN) resultmuxW(ResultW, ReadDataW, CSRReadValW, MDUResultW, SCResultW, ResultSrcW, WriteDataW);
// floating point interactions: fcvt, fp stores
2022-01-05 14:35:25 +00:00
if (`F_SUPPORTED) begin:fpmux
mux2 #(`XLEN) resultmuxM(IEUResultM, FIntResM, FWriteIntM, ResultM);
mux2 #(`XLEN) writedatamux(ForwardedSrcBE, FWriteDataE, ~IllegalFPUInstrE, WriteDataE);
end else begin:fpmux
assign ResultM = IEUResultM;
assign WriteDataE = ForwardedSrcBE;
end
2021-01-15 04:37:51 +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