A Verilog implementation of a 32-bit DLX (a MIPS derivative) RISC processor with pipelining support. This processor follows the DLX architecture, which is a RISC instruction set architecture developed for teaching purposes, based on the MIPS architecture.
This implementation features a 32-bit RISC processor based on the DLX architecture with the following key characteristics:
- 32-bit data path width
- 5-stage pipeline architecture
- Hardware hazard detection and forwarding
- Branch prediction support
- Register file with forwarding logic
- Multiple ALU operations support
- Memory access capabilities
The processor implements a classic 5-stage RISC pipeline:
-
Fetch (F):
- Fetches instruction from instruction memory
- Updates Program Counter (PC)
- Implements PC stalling logic for hazard handling
-
Decode (D):
- Decodes instruction using the Control Unit
- Reads registers from Register File
- Performs immediate value extension (Sign/Zero)
- Implements branch target calculation
- Features forwarding logic for branch resolution
-
Execute (E):
- Performs ALU operations
- Handles data forwarding through multiple MUX units
- Supports multiple operations including:
- Arithmetic: ADD, SUB
- Logical: AND, OR, XOR
- Shifts: SLL, SRL, SRA
- Comparisons: SEQ, SNE, SLT, SLE
-
Memory (M):
- Handles memory access operations
- Performs memory read/write operations
- Manages memory-to-register transfers
-
Writeback (W):
- Writes results back to register file
- Handles result forwarding logic
- Manages register write operations
The CPU supports a rich set of DLX instructions including:
- ADD, ADDI (Addition)
- SUB, SUBI (Subtraction)
- AND, ANDI (Logical AND)
- OR, ORI (Logical OR)
- XOR, XORI (Logical XOR)
- LW (Load Word)
- SW (Store Word)
- LHI (Load High Immediate)
- BEQZ (Branch if Equal to Zero)
- BNEZ (Branch if Not Equal to Zero)
- J (Jump)
- JAL (Jump and Link)
- JALR (Jump and Link Register)
- JR (Jump Register)
- SLLI (Shift Left Logical Immediate)
- SRLI (Shift Right Logical Immediate)
- SRAI (Shift Right Arithmetic Immediate)
- SEQI (Set if Equal Immediate)
- SNEI (Set if Not Equal Immediate)
- SLTI (Set if Less Than Immediate)
- SLEI (Set if Less or Equal Immediate)
The processor implements sophisticated hazard handling mechanisms:
-
Data Hazards:
- Forward paths from Execute, Memory, and Writeback stages
- Stall logic when forwarding isn't possible
- Register file forwarding for dependent instructions
-
Control Hazards:
- Branch prediction logic
- Pipeline flush mechanism for mispredicted branches
- Early branch resolution in Decode stage
-
Structural Hazards:
- Separate instruction and data memory
- Pipelined execution units
- Resource conflict resolution
- Control Unit: Manages instruction decoding and control signal generation
- ALU: Supports multiple operations with 4-bit control signals
- Register File: 32-bit width with forwarding support
- Hazard Unit: Handles pipeline stalls and forwarding control
- Branch Unit: Manages branch prediction and resolution
- Memory Interface: Handles load/store operations
- 32-bit data path
- 32-bit instruction width
- 32-bit general-purpose registers
- Parameterized design (WIDTH parameter)
- Multiple pipeline registers for stage isolation
To use this CPU implementation:
- Ensure you have a Verilog simulator installed
- Clone the repository
- Compile the Verilog files
- Run simulation with your test bench
top_cpu.v
: Main CPU implementation with pipeline stagesALU.v
: Arithmetic Logic Unit implementationControlUnit.v
: Instruction decoder and control signal generator- Multiple supporting modules for pipeline stages and components
Contributions are welcome! Please feel free to submit pull requests or open issues for improvements and bug fixes.