# rahul-shahtp/pipelined-32-bit-riscv-processor architecture

> Architecture diagram of the GitHub repository rahul-shahtp/pipelined-32-bit-riscv-processor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahul-shahtp/pipelined-32-bit-riscv-processor
- Repository: https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor

## Overview

This repository implements a five-stage pipelined RV32IM processor, from instruction fetch through writeback, with hazard handling, forwarding, branch resolution, and SRAM-backed data memory. The graph focuses on the documented runtime architecture and its major microarchitectural features. Source excerpts were not provided, so relationships are limited to those stated in the README.

Main entry points: [`rtl/id_stage/id_to_ex_reg.v`](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/id_to_ex_reg.v) (ID/EX Register), [`rtl/id_stage/control_unit.v`](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/control_unit.v) (Decode Control), [`rtl/ex_stage/ex_to_mem_reg.v`](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/ex_to_mem_reg.v) (EX/MEM Register), [`rtl/id_stage/branch_unit.v`](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/branch_unit.v) (Branch Unit)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_if["Instruction Fetch"]
  node_pc["PC Logic<br/>[pc_reg.v]"]
  node_imem[("Instruction Memory<br/>[instr_mem.v]")]
  node_ifid["IF/ID Register<br/>[if_to_id_reg.v]"]
end

subgraph group_id["Decode Control"]
  node_decode["Decode Control<br/>[control_unit.v]"]
  node_registers[("Register File<br/>[register_file.v]")]
  node_immediate["Immediate Generator<br/>[imm_gen.v]"]
  node_branch["Branch Unit<br/>[branch_unit.v]"]
  node_hazard["Hazard Detection"]
  node_idex["ID/EX Register<br/>[id_to_ex_reg.v]"]
end

subgraph group_ex["Execute"]
  node_alu["ALU<br/>[alu.v]"]
  node_forward["Forwarding Unit<br/>[forwarding_unit.v]"]
  node_muldiv["MUL/DIV Unit<br/>[mul_div_unit.v]"]
  node_exmem["EX/MEM Register<br/>[ex_to_mem_reg.v]"]
end

subgraph group_mem["Memory Access"]
  node_datamem[("Data Memory<br/>[data_memory.v]")]
  node_sram[("SRAM Macro")]
  node_memwb["MEM/WB Register<br/>[mem_to_wb_reg.v]"]
end

subgraph group_wb["Writeback"]
  node_writeback["Writeback Mux<br/>[wb_mux.v]"]
end

node_software(("Instruction Stream"))
node_core["RV32IM Core<br/>[rv32im_top.v]"]

node_software -->|"supplies instructions"| node_imem
node_core -->|"integrates"| node_pc
node_pc -->|"selects instruction"| node_imem
node_imem -->|"passes instruction"| node_ifid
node_ifid -->|"passes instruction"| node_decode
node_decode -->|"controls reads"| node_registers
node_decode -->|"decodes immediates"| node_immediate
node_decode -->|"resolves branches"| node_branch
node_hazard -->|"stalls pipeline"| node_ifid
node_hazard -->|"inserts bubble"| node_idex
node_branch -->|"redirects fetch"| node_pc
node_branch -->|"flushes control"| node_idex
node_registers -->|"passes operands"| node_idex
node_immediate -->|"passes immediate"| node_idex
node_idex -->|"provides operands"| node_forward
node_forward -->|"forwards operands"| node_alu
node_idex -->|"dispatches M ops"| node_muldiv
node_alu -->|"passes result"| node_exmem
node_muldiv -->|"passes result"| node_exmem
node_exmem -->|"accesses memory"| node_datamem
node_datamem -->|"uses four macros"| node_sram
node_datamem -->|"passes load data"| node_memwb
node_exmem -->|"passes ALU result"| node_memwb
node_memwb -->|"selects result"| node_writeback
node_writeback -->|"writes register"| node_registers

click node_core "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/top/rv32im_top.v"
click node_pc "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/pc_reg.v"
click node_imem "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/instr_mem.v"
click node_ifid "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/if_to_id_reg.v"
click node_decode "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/control_unit.v"
click node_registers "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/register_file.v"
click node_immediate "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/imm_gen.v"
click node_branch "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/branch_unit.v"
click node_hazard "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/hazard_detection_unit.v"
click node_idex "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/id_to_ex_reg.v"
click node_alu "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/alu.v"
click node_forward "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/forwarding_unit.v"
click node_muldiv "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/mul_div_unit.v"
click node_exmem "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/ex_to_mem_reg.v"
click node_datamem "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/data_memory.v"
click node_sram "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/sram_1kbyte_1rw1r_8x1024_8_bb.v"
click node_memwb "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/mem_to_wb_reg.v"
click node_writeback "https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/wb_stage/wb_mux.v"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pc,node_imem,node_ifid toneBlue
class node_decode,node_registers,node_immediate,node_branch,node_hazard,node_idex toneAmber
class node_alu,node_forward,node_muldiv,node_exmem toneMint
class node_datamem,node_sram,node_memwb toneRose
class node_writeback,node_software toneIndigo
class node_core toneTeal
```

## Components

### Instruction Fetch

- [PC Logic](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/pc_reg.v): `rtl/if_stage/pc_reg.v`
- [Instruction Memory](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/instr_mem.v): `rtl/if_stage/instr_mem.v`
- [IF/ID Register](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/if_stage/if_to_id_reg.v): `rtl/if_stage/if_to_id_reg.v`

### Decode Control

- [Decode Control](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/control_unit.v): `rtl/id_stage/control_unit.v`
- [Register File](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/register_file.v): `rtl/id_stage/register_file.v`
- [Immediate Generator](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/imm_gen.v): `rtl/id_stage/imm_gen.v`
- [Branch Unit](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/branch_unit.v): `rtl/id_stage/branch_unit.v`
- [Hazard Detection](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/hazard_detection_unit.v): `rtl/id_stage/hazard_detection_unit.v`
- [ID/EX Register](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/id_stage/id_to_ex_reg.v): `rtl/id_stage/id_to_ex_reg.v`

### Execute

- [ALU](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/alu.v): `rtl/ex_stage/alu.v`
- [Forwarding Unit](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/forwarding_unit.v): `rtl/ex_stage/forwarding_unit.v`
- [MUL/DIV Unit](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/mul_div_unit.v): `rtl/ex_stage/mul_div_unit.v`
- [EX/MEM Register](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/ex_stage/ex_to_mem_reg.v): `rtl/ex_stage/ex_to_mem_reg.v`

### Memory Access

- [Data Memory](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/data_memory.v): `rtl/mem_stage/data_memory.v`
- [SRAM Macro](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/sram_1kbyte_1rw1r_8x1024_8_bb.v): `rtl/mem_stage/sram_1kbyte_1rw1r_8x1024_8_bb.v`
- [MEM/WB Register](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/mem_stage/mem_to_wb_reg.v): `rtl/mem_stage/mem_to_wb_reg.v`

### Writeback

- [Writeback Mux](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/wb_stage/wb_mux.v): `rtl/wb_stage/wb_mux.v`

### Other components

- **Instruction Stream**
- [RV32IM Core](https://github.com/rahul-shahtp/pipelined-32-bit-riscv-processor/blob/main/rtl/top/rv32im_top.v): `rtl/top/rv32im_top.v`

## Connections

- Instruction Stream → Instruction Memory: supplies instructions (evidence: `README.md`)
- RV32IM Core → PC Logic: integrates (evidence: `README.md`)
- PC Logic → Instruction Memory: selects instruction (evidence: `README.md`)
- Instruction Memory → IF/ID Register: passes instruction (evidence: `README.md`)
- IF/ID Register → Decode Control: passes instruction (evidence: `README.md`)
- Decode Control → Register File: controls reads (evidence: `README.md`)
- Decode Control → Immediate Generator: decodes immediates (evidence: `README.md`)
- Decode Control → Branch Unit: resolves branches (evidence: `README.md`)
- Hazard Detection → IF/ID Register: stalls pipeline (evidence: `README.md`)
- Hazard Detection → ID/EX Register: inserts bubble (evidence: `README.md`)
- Branch Unit → PC Logic: redirects fetch (evidence: `README.md`)
- Branch Unit → ID/EX Register: flushes control (evidence: `README.md`)
- Register File → ID/EX Register: passes operands (evidence: `README.md`)
- Immediate Generator → ID/EX Register: passes immediate (evidence: `README.md`)
- ID/EX Register → Forwarding Unit: provides operands (evidence: `README.md`)
- Forwarding Unit → ALU: forwards operands (evidence: `README.md`)
- ID/EX Register → MUL/DIV Unit: dispatches M ops (evidence: `README.md`)
- ALU → EX/MEM Register: passes result (evidence: `README.md`)
- MUL/DIV Unit → EX/MEM Register: passes result (evidence: `README.md`)
- EX/MEM Register → Data Memory: accesses memory (evidence: `README.md`)
- Data Memory → SRAM Macro: uses four macros (evidence: `README.md`)
- Data Memory → MEM/WB Register: passes load data (evidence: `README.md`)
- EX/MEM Register → MEM/WB Register: passes ALU result (evidence: `README.md`)
- MEM/WB Register → Writeback Mux: selects result (evidence: `README.md`)
- Writeback Mux → Register File: writes register (evidence: `README.md`)
