# teivah/majorana architecture

> Architecture diagram of the GitHub repository teivah/majorana, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/teivah/majorana
- Repository: https://github.com/teivah/majorana

## Overview

##### Main Components

a. Core Processing Units:
- Fetch Unit (FU)
- Decode Unit (DU)
- Execute Unit (EU)
- Write Unit (WU)
- Branch Unit (BU)
- Control Unit (CU) [for MVP-6 and above]

b. Memory Hierarchy:
- L1I Cache (Instruction Cache)
- L1D Cache (Data Cache)
- L3 Cache (Shared Cache)
- Main Memory
- Memory Management Unit (MMU)

c. Special Components:
- Branch Target Buffer (BTB)
- MSI Protocol Controller
- Register File
- Cache Coherency Controller

**┌─────────────────────────────────────────────┐**
- Pipeline Stage              │
- ┤
- FU → DU → CU → EU → WU                    │
- ┤
- Memory Hierarchy                  │
- L1I  L1D        L3         Main Memory    │
- ┘

##### Specific Elements

- Instruction flow path
- Data flow path
- Control signals
- Cache coherency messages

b. Component Interfaces:
- Cache line sizes (64 bytes)
- Pipeline width (dual-issue for superscalar)
- Register file connections

##### Multiple Views

- Basic pipeline (MVP-1)
- Cache hierarchy (MVP-2/3)
- Superscalar pipeline (MVP-6+)
- Cache coherency (MVP-7/8)

##### Important Details to Capture

- MSI protocol states (Modified, Shared, Invalid)
- Forwarding paths for hazard resolution
- Demonstrate the branch prediction mechanism
- Register renaming process

**┌──────────┐**
- Component │ → Regular component
- ┘

**╔══════════╗**
**║ Control  ║ → Control component**
**╚══════════╝**

**〈 Cache 〉    → Memory component**

**⇒           → Main data flow**
**→           → Control flow**
- >      → Feedback path

##### Implementation Notes

- Maintain consistent spacing and alignment
- Document pipeline stages and their latencies

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef pipeline fill:#a8d1f0,stroke:#000
    classDef memory fill:#90EE90,stroke:#000
    classDef control fill:#FFE5B4,stroke:#000
    classDef special fill:#DDA0DD,stroke:#000
    classDef datapath fill:#FF6961,stroke:#000

    %% Legend
    subgraph Legend
        P1[Pipeline Component]:::pipeline
        M1[Memory Component]:::memory
        C1[Control Component]:::control
        S1[Special Component]:::special
        D1[Data Path]:::datapath
    end

    %% Pipeline Stage
    subgraph Pipeline
        FU[Fetch Unit]:::pipeline
        DU[Decode Unit]:::pipeline
        EU[Execute Unit]:::pipeline
        WU[Write Unit]:::pipeline
        
        FU --> DU --> EU --> WU
    end

    %% Control Components
    subgraph Control
        CU[Control Unit]:::control
        BU[Branch Unit]:::control
        MMU[Memory Management Unit]:::control
    end

    %% Memory Hierarchy
    subgraph Memory
        L1I[L1I Cache]:::memory
        L1D[L1D Cache]:::memory
        L3[L3 Cache]:::memory
        MM[Main Memory]:::memory
    end

    %% Special Components
    subgraph Special
        BTB[Branch Target Buffer]:::special
        MSI[MSI Protocol Controller]:::special
        RF[Register File]:::special
        CC[Cache Coherency Controller]:::special
    end

    %% Connections
    FU --> L1I
    EU --> L1D
    L1I --> L3
    L1D --> L3
    L3 --> MM
    BU --> BTB
    MMU --> L1I
    MMU --> L1D
    CU --> EU
    MSI --> CC
    CC --> L1I
    CC --> L1D
    DU --> RF
    EU --> RF

    %% Click events
    click FU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/fu.go"
    click DU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/du.go"
    click EU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/eu.go"
    click WU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/wu.go"
    click BU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/bu.go"
    click CU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/cu.go"
    click MMU "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/mmu.go"
    click BTB "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/btb.go"
    click MSI "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/msi.go"
    click CC "https://github.com/teivah/majorana/blob/main/proc/mvp8-0/cc.go"
    click RF "https://github.com/teivah/majorana/blob/main/proc/comp/rat.go"
    click L1I "https://github.com/teivah/majorana/blob/main/proc/comp/cache.go"
    click L1D "https://github.com/teivah/majorana/blob/main/proc/comp/cache.go"
    click L3 "https://github.com/teivah/majorana/blob/main/proc/comp/cache.go"
```
