A custom-designed, 5-stage pipelined RISC processor implemented in Verilog, featuring hardware support for 4-way Simultaneous Multithreading (SMT).
Unlike standard educational processors, this core is heavily optimized to execute complex, compiler-generated C programs (such as Bubble Sort) natively. It features a custom Micro-operation (Micro-op) Control Engine to handle multi-cycle CISC-like instructions and a hardware-level Memory Management Unit (MMU) to guarantee thread safety during concurrent execution.
This processor was designed to solve complex architectural hazards and concurrency issues at the hardware level:
Standard RISC pipelines execute one instruction per cycle, making ARM's multi-register load/store (LDMIA/STMIA like push {fp, lr}) notoriously difficult to implement.
- The Solution: Engineered a hardware micro-sequencer state machine inside the Control Unit. It dynamically freezes the frontend (IF/ID), iterates through a 16-bit register mask cycle-by-cycle, and safely resumes the pipeline without ghost states or deadlocks.
- Base Register Protection: Implemented intelligent register overriding to cache the Base Register (
Rn) during multi-cycle execution, preventing data corruption as the pipeline shifts.
- Designed a Quad-Banked Register File (4 independent contexts, RF0–RF3) and 4 dedicated Program Counters.
- The hardware round-robin scheduler rotates threads every clock cycle, achieving zero-overhead context switching.
- Synchronization: The scheduler dynamically pauses rotation when any thread enters a multi-cycle micro-op state, completely preventing thread-clashing.
When 4 threads concurrently execute sorting algorithms on shared memory, race conditions destroy data integrity.
- The Solution: Implemented a hardware-level MMU. The CPU utilizes a continuous 16KB SRAM, but the MMU translates virtual addresses into physically isolated 4KB memory banks for each thread.
- Automatically offsets the Stack Pointer (
SP) for each thread at hardware reset, ensuring global data arrays and local stack variables never overlap.
The 5-Stage Pipeline
- IF (Instruction Fetch): Fetches 32-bit instructions from IMEM based on the dynamically scheduled Thread's PC.
- ID (Instruction Decode): Decodes opcodes, handles immediate generation, and reads from the banked Register File.
- EX (Execute): ALU operations, barrel shifting, and precise branch target evaluation (
Target = PC + 8 + offset). - MEM (Memory Access): Load/Store operations with combinational reads for perfect pipeline timing alignment.
- WB (Write Back): Updates the architectural state.
The processor natively executes 32-bit ARM instructions generated by the GCC compiler:
| Category | Instructions Supported | Hardware Implementation Details |
|---|---|---|
| Data Processing | ADD, SUB, MOV, CMP |
Integrated with a full internal Barrel Shifter. |
| Memory Access | LDR, STR |
Single-cycle load/store. |
| Block Transfer | LDMIA, STMIA, PUSH, POP |
Executed via dynamic Micro-op State Machine. |
| Flow Control | B, BGE, BLE, BX |
Fully implemented conditional branching. |
This project validates the full stack, from high-level software to silicon logic:
- Compilation: C source code (e.g.,
sort.c) is compiled using thearm-none-eabi-gcctoolchain. - Assembly Analysis: Validated stack frame generations and memory mapping.
- Hex Generation: Converted binaries into
.hexfiles for Verilog$readmemh. - Simulation: Cycle-accurate verification using ModelSim to analyze waveforms and memory dumps.
The architecture was rigorously verified using ModelSim. Below are the key validation milestones:
Verified through Memory Dumps that all 4 hardware threads can independently and simultaneously sort arrays within their isolated memory banks without data corruption.
Caption: Memory dump showing a perfectly sorted array processed by Thread 1 in its isolated physical bank.
Caption: The Control Unit intercepting an LDMIA instruction, stalling the pipeline, and executing sequential memory accesses.
In traditional pipelined processors, a taken branch introduces control hazards that require flushing the pipeline (Branch Penalty). However, this architecture leverages its 4-way interleaved SMT design to completely hide branch latencies.
When a branch instruction is resolved in the Execute (EX) stage for Thread A, the instructions currently in the Decode (ID) and Fetch (IF) stages belong to independent threads (e.g., Thread B and Thread C). Therefore, the Program Counter for Thread A is dynamically updated without needing to flush the pipeline, achieving a Zero Branch Penalty.
Caption: A Branch instruction (ea000024) is successfully resolved in the EX stage (actual_branch = 1). The PC updates instantly without flushing the trailing instructions in the IF/ID stages, demonstrating the zero-penalty advantage of thread interleaving.
- Clone this repository:
git clone https://github.com/YourUsername/Quad-Thread-ARM-CPU.git - Open ModelSim and set the working directory to the project folder.
- Compile all Verilog files:
vlog components.v pipelinepc.v tb_pipelinepc.v - Load the simulation:
vsim tb_pipelinepc - Run the simulation for at least
300000 nsto allow the complex sorting algorithms to complete across all threads:run 300000ns - Inspect
data_dump.hexor the ModelSim Memory Viewer to verify the sorted arrays.
Designed by [Ian Chen] - University of Southern California (USC), ECE Dept.