# kinzafatim/single-cycle-rv32i-chisel architecture

> Architecture diagram of the GitHub repository kinzafatim/single-cycle-rv32i-chisel, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kinzafatim/single-cycle-rv32i-chisel
- Repository: https://github.com/kinzafatim/single-cycle-rv32i-chisel

## Overview

##### Project type and purpose
- This is a hardware-description project (written in Chisel/Scala) that implements a single-cycle RV32I RISC-V processor.
- Its goal is to fetch, decode, and execute each instruction in one clock cycle, using modules for ALU, Branch, Control, Data Memory, Instruction Memory, PC, Register File, and Immediate Generator.

##### File structure
- src/main/scala/single_cycle: contains all processor modules (ALU.scala, Branch.scala, Control.scala, Datamem.scala, Instr_mem.scala, Pc.scala, RV32I.scala, regfile.scala, ImmGen.scala).
- src/main/scala/gcd: an auxiliary Decoupled GCD example.
- src/test/scala: unit tests for each hardware module.
- build.sbt/build.sc, project directory: SBT/Chisel build and plugin configuration.
- README.md: outlines modules, usage, and testbenches.

##### README for additional insights
- Confirms single-cycle architecture with no pipelining.
- Details on module responsibilities and test procedure via ChiselTest.

##### Elements
- Clear labels for blocks (e.g., “ALU”, “Control Unit”, “Register File”).
- Blue for pure datapath blocks
- Buses (e.g., 32-bit data bus, 32-bit address bus).
- Immediate generator as a small block off the decode stage.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Single-Cycle RV32I Processor"
        direction TB

        %% Fetch Stage
        PC["PC"]:::datapath
        InstrMem["Instruction Memory"]:::memory
        PC -->|"32-bit address"| InstrMem
        InstrMem -->|"32-bit instruction"| RegFile
        InstrMem -->|"32-bit instruction"| ImmGen
        InstrMem -->|"32-bit instruction"| Control

        %% Decode Stage
        RegFile["Register File"]:::datapath
        ImmGen["Immediate Generator"]:::datapath
        Control["Control Unit"]:::control

        %% Execute Stage
        MUX_ALU["ALU Input MUX"]:::datapath
        ALU["ALU"]:::datapath
        BranchLogic["Branch Logic"]:::datapath

        RegFile -->|RS1_data| ALU
        RegFile -->|RS1_data| BranchLogic
        RegFile -->|RS2_data| BranchLogic
        RegFile -->|RS2_data| MUX_ALU
        ImmGen -->|imm value| MUX_ALU
        MUX_ALU -->|operand| ALU
        Control -->|ALUOp| ALU
        Control -->|ALUSrc| MUX_ALU
        Control -->|Branch| MUX_PC

        %% Memory Access Stage
        DMem["Data Memory"]:::memory
        ALU -->|address| DMem
        RegFile -->|RS2_data| DMem
        Control -->|MemRead| DMem
        Control -->|MemWrite| DMem

        %% Write-Back Stage
        MUX_WB["Write-Back MUX"]:::datapath
        DMem -->|read data| MUX_WB
        ALU -->|ALU result| MUX_WB
        Control -->|MemToReg| MUX_WB
        MUX_WB -->|write data| RegFile
        Control -->|RegWrite| RegFile

        %% PC Update
        PCplus4["PC+4"]:::datapath
        BranchTarget["Branch Target"]:::datapath
        PC -->|" +4 "| PCplus4
        BranchLogic -->|target| BranchTarget
        MUX_PC["PC MUX"]:::datapath
        PCplus4 --> MUX_PC
        BranchTarget --> MUX_PC
        Control -->|Jal| MUX_PC
        MUX_PC --> PC

    end

    %% Top-Level Integration
    RV32I["RV32I Top Module"]:::datapath
    RV32I --> PC
    RV32I --> InstrMem
    RV32I --> RegFile
    RV32I --> ImmGen
    RV32I --> Control
    RV32I --> ALU
    RV32I --> BranchLogic
    RV32I --> DMem

    %% Click Events
    click PC "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/Pc.scala"
    click InstrMem "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/Instr_mem.scala"
    click RegFile "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/regfile.scala"
    click ImmGen "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/ImmGen.scala"
    click Control "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/Control.scala"
    click ALU "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/ALU.scala"
    click BranchLogic "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/Branch.scala"
    click DMem "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/Datamem.scala"
    click RV32I "https://github.com/kinzafatim/single-cycle-rv32i-chisel/blob/main/src/main/scala/single_cycle/RV32I.scala"

    %% Styles
    classDef datapath fill:#ADD8E6,stroke:#000
    classDef control fill:#FFAAAA,stroke:#000,stroke-dasharray: 5 5
    classDef memory fill:#90EE90,stroke:#000
```
