2021-01-27 11:40:26 +00:00
|
|
|
///////////////////////////////////////////
|
|
|
|
// ieu.sv
|
|
|
|
//
|
|
|
|
// Written: David_Harris@hmc.edu 9 January 2021
|
|
|
|
// Modified:
|
|
|
|
//
|
|
|
|
// Purpose: Integer Execution Unit: datapath and controller
|
|
|
|
//
|
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-27 11:40:26 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// Copyright (C) 2021-23 Harvey Mudd College & Oklahoma State University
|
2021-01-27 11:40:26 +00:00
|
|
|
//
|
2023-01-10 19:35:20 +00:00
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH SHL-2.1
|
2021-01-27 11:40:26 +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-27 11:40:26 +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-27 11:40:26 +00:00
|
|
|
|
|
|
|
`include "wally-config.vh"
|
|
|
|
|
|
|
|
module ieu (
|
2023-01-17 14:02:26 +00:00
|
|
|
input logic clk, reset,
|
|
|
|
// Decode stage signals
|
|
|
|
input logic [31:0] InstrD, // Instruction
|
|
|
|
input logic IllegalIEUInstrFaultD, // Illegal instruction
|
2023-01-17 18:51:44 +00:00
|
|
|
output logic IllegalBaseInstrFaultD, // Illegal I-type instruction, or illegal RV32 access to upper 16 registers
|
2023-01-17 14:02:26 +00:00
|
|
|
// Execute stage signals
|
|
|
|
input logic [`XLEN-1:0] PCE, // PC
|
|
|
|
input logic [`XLEN-1:0] PCLinkE, // PC + 4
|
2023-01-18 15:26:08 +00:00
|
|
|
output logic PCSrcE, // Select next PC (between PC+4 and IEUAdrE)
|
2023-01-17 14:02:26 +00:00
|
|
|
input logic FWriteIntE, FCvtIntE, // FPU writes to integer register file, FPU converts float to int
|
|
|
|
output logic [`XLEN-1:0] IEUAdrE, // Memory address
|
|
|
|
output logic IntDivE, W64E, // Integer divide, RV64 W-type instruction
|
|
|
|
output logic [2:0] Funct3E, // Funct3 instruction field
|
|
|
|
output logic [`XLEN-1:0] ForwardedSrcAE, ForwardedSrcBE, // ALU src inputs before the mux choosing between them and PCE to put in srcA/B
|
|
|
|
output logic [4:0] RdE, // Destination register
|
|
|
|
// Memory stage signals
|
2023-01-17 18:51:44 +00:00
|
|
|
input logic SquashSCW, // Squash store conditional, from LSU
|
2023-01-17 14:02:26 +00:00
|
|
|
output logic [1:0] MemRWM, // Read/write control goes to LSU
|
|
|
|
output logic [1:0] AtomicM, // Atomic control goes to LSU
|
|
|
|
output logic [`XLEN-1:0] WriteDataM, // Write data to LSU
|
|
|
|
output logic [2:0] Funct3M, // Funct3 (size and signedness) to LSU
|
|
|
|
output logic [`XLEN-1:0] SrcAM, // ALU SrcA to Privileged unit and FPU
|
|
|
|
output logic [4:0] RdM, // Destination register
|
2023-01-17 18:51:44 +00:00
|
|
|
input logic [`XLEN-1:0] FIntResM, // Integer result from FPU (fmv, fclass, fcmp)
|
2023-01-17 14:02:26 +00:00
|
|
|
output logic InvalidateICacheM, FlushDCacheM, // Invalidate I$, flush D$
|
2023-02-10 16:33:10 +00:00
|
|
|
output logic InstrValidD, InstrValidE, InstrValidM,// Instruction is valid
|
2023-01-17 14:02:26 +00:00
|
|
|
// Writeback stage signals
|
2023-01-20 22:19:07 +00:00
|
|
|
input logic [`XLEN-1:0] FIntDivResultW, // Integer divide result from FPU fdivsqrt)
|
|
|
|
input logic [`XLEN-1:0] CSRReadValW, // CSR read value,
|
|
|
|
input logic [`XLEN-1:0] MDUResultW, // multiply/divide unit result
|
2023-01-17 18:51:44 +00:00
|
|
|
input logic [`XLEN-1:0] FCvtIntResW, // FPU's float to int conversion result
|
2023-01-17 14:02:26 +00:00
|
|
|
input logic FCvtIntW, // FPU converts float to int
|
|
|
|
output logic [4:0] RdW, // Destination register
|
|
|
|
input logic [`XLEN-1:0] ReadDataW, // LSU's read data
|
|
|
|
// Hazard unit signals
|
2023-01-17 18:51:44 +00:00
|
|
|
input logic StallD, StallE, StallM, StallW, // Stall signals from hazard unit
|
2023-01-17 14:02:26 +00:00
|
|
|
input logic FlushD, FlushE, FlushM, FlushW, // Flush signals
|
2023-01-17 18:51:44 +00:00
|
|
|
output logic FCvtIntStallD, LoadStallD, // Stall causes from IEU to hazard unit
|
2023-01-17 14:08:26 +00:00
|
|
|
output logic MDUStallD, CSRRdStallD, StoreStallD,
|
2023-01-17 18:51:44 +00:00
|
|
|
output logic CSRReadM, CSRWriteM, PrivilegedM,// CSR read, CSR write, is privileged instruction
|
|
|
|
output logic CSRWriteFenceM // CSR write or fence instruction needs to flush subsequent instructions
|
2021-01-27 11:40:26 +00:00
|
|
|
);
|
|
|
|
|
2023-01-18 15:26:08 +00:00
|
|
|
logic [2:0] ImmSrcD; // Select type of immediate extension
|
|
|
|
logic [1:0] FlagsE; // Comparison flags ({eq, lt})
|
2023-02-09 19:18:54 +00:00
|
|
|
logic [6:0] Funct7E; // Instruction's funct7 field in execute stage
|
2023-01-18 15:26:08 +00:00
|
|
|
logic [2:0] ALUControlE; // ALU control indicates function to perform
|
|
|
|
logic ALUSrcAE, ALUSrcBE; // ALU source operands
|
|
|
|
logic [2:0] ResultSrcW; // Selects result in Writeback stage
|
|
|
|
logic ALUResultSrcE; // Selects ALU result to pass on to Memory stage
|
|
|
|
logic SCE; // Store Conditional instruction
|
|
|
|
logic FWriteIntM; // FPU writing to integer register file
|
|
|
|
logic IntDivW; // Integer divide instruction
|
2021-02-02 18:42:23 +00:00
|
|
|
|
2023-01-18 15:26:08 +00:00
|
|
|
// Forwarding signals
|
|
|
|
logic [4:0] Rs1D, Rs2D, Rs1E, Rs2E; // Source and destination registers
|
|
|
|
logic [1:0] ForwardAE, ForwardBE; // Select signals for forwarding multiplexers
|
|
|
|
logic RegWriteM, RegWriteW; // Register will be written in Memory, Writeback stages
|
|
|
|
logic MemReadE, CSRReadE; // Load, CSRRead instruction
|
|
|
|
logic JumpE; // Jump instruction
|
|
|
|
logic BranchSignedE; // Branch does signed comparison on operands
|
|
|
|
logic MDUE; // Multiply/divide instruction
|
2021-01-27 11:40:26 +00:00
|
|
|
|
2021-12-08 08:24:27 +00:00
|
|
|
controller c(
|
2022-01-07 04:07:04 +00:00
|
|
|
.clk, .reset, .StallD, .FlushD, .InstrD, .ImmSrcD,
|
|
|
|
.IllegalIEUInstrFaultD, .IllegalBaseInstrFaultD, .StallE, .FlushE, .FlagsE, .FWriteIntE,
|
|
|
|
.PCSrcE, .ALUControlE, .ALUSrcAE, .ALUSrcBE, .ALUResultSrcE, .MemReadE, .CSRReadE,
|
2023-02-09 19:18:54 +00:00
|
|
|
.Funct3E, .Funct7E, .IntDivE, .MDUE, .W64E, .JumpE, .SCE, .BranchSignedE, .StallM, .FlushM, .MemRWM,
|
2022-06-21 20:30:33 +00:00
|
|
|
.CSRReadM, .CSRWriteM, .PrivilegedM, .AtomicM, .Funct3M,
|
2023-02-10 16:33:10 +00:00
|
|
|
.RegWriteM, .InvalidateICacheM, .FlushDCacheM, .InstrValidM, .InstrValidE, .InstrValidD, .FWriteIntM,
|
2023-01-11 19:06:37 +00:00
|
|
|
.StallW, .FlushW, .RegWriteW, .IntDivW, .ResultSrcW, .CSRWriteFenceM, .StoreStallD);
|
2021-12-08 08:24:27 +00:00
|
|
|
|
|
|
|
datapath dp(
|
2022-01-07 04:07:04 +00:00
|
|
|
.clk, .reset, .ImmSrcD, .InstrD, .StallE, .FlushE, .ForwardAE, .ForwardBE,
|
2023-02-09 19:18:54 +00:00
|
|
|
.ALUControlE, .Funct3E, .Funct7E, .ALUSrcAE, .ALUSrcBE, .ALUResultSrcE, .JumpE, .BranchSignedE,
|
2023-01-27 23:47:15 +00:00
|
|
|
.PCE, .PCLinkE, .FlagsE, .IEUAdrE, .ForwardedSrcAE, .ForwardedSrcBE,
|
2022-08-23 19:17:19 +00:00
|
|
|
.StallM, .FlushM, .FWriteIntM, .FIntResM, .SrcAM, .WriteDataM, .FCvtIntW,
|
2023-01-11 19:06:37 +00:00
|
|
|
.StallW, .FlushW, .RegWriteW, .IntDivW, .SquashSCW, .ResultSrcW, .ReadDataW, .FCvtIntResW,
|
2023-01-27 23:47:15 +00:00
|
|
|
.CSRReadValW, .MDUResultW, .FIntDivResultW, .Rs1D, .Rs2D, .Rs1E, .Rs2E, .RdE, .RdM, .RdW);
|
2021-12-08 08:24:27 +00:00
|
|
|
|
|
|
|
forward fw(
|
|
|
|
.Rs1D, .Rs2D, .Rs1E, .Rs2E, .RdE, .RdM, .RdW,
|
2022-01-07 04:30:00 +00:00
|
|
|
.MemReadE, .MDUE, .CSRReadE, .RegWriteM, .RegWriteW,
|
2022-08-23 19:57:18 +00:00
|
|
|
.FCvtIntE, .SCE, .ForwardAE, .ForwardBE,
|
2022-12-02 19:55:23 +00:00
|
|
|
.FCvtIntStallD, .LoadStallD, .MDUStallD, .CSRRdStallD);
|
2021-01-27 11:40:26 +00:00
|
|
|
endmodule
|
2021-01-28 03:49:47 +00:00
|
|
|
|