# milleraj66/ece585_tomasuloalgorithm architecture

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

- Interactive diagram: https://gitdiagram.com/milleraj66/ece585_tomasuloalgorithm
- Repository: https://github.com/milleraj66/ece585_tomasuloalgorithm

## Overview

##### Project Type and Purpose
- This is a standalone C++ simulation tool that implements the Tomasulo algorithm’s datapath and scheduling logic.

##### File Structure Analysis
Top‐level files:
- main.cpp            – Program entrypoint; parses configuration and instructions, drives the simulation loop.
- Instruction.h/.cpp  – Defines an Instruction class (rd, rs, rt, opcode).
- ReservationStation.h/.cpp – Models a reservation station: fields for operands, operation type, busy flag, result readiness.
- RegisterStatus.h/.cpp    – Tracks which reservation station will produce each register’s next value (for register renaming / status).
- Makefile            – Build instructions.
- README.md           – Usage and architecture notes.
No client/server or UI layers—pure compute simulation.

##### Key Architecture Concepts from README
- Configurable counts of ADD, MULT, DIV reservation stations.
- Latencies for different functional units and pipeline phases (issue, execute, writeback).
- Register file (vector<int>) and register status table (vector<RegisterStatus>) for renaming.
- Instruction queue (vector<Instruction>) as input program.
- Cycle‐by‐cycle simulation driving issue → execution → writeback, recording timing per instruction.

##### Main Components
a. Instruction Queue
- Holds the input vector<Instruction>.
- Feeds the Issue Unit each cycle.
b. Issue Unit
- Checks head of queue, consults Register Status to decide if operands are ready or which RS to allocate.
- Allocates a Reservation Station (RS) of the appropriate type (ADD/MULT/DIV).
- Updates Register Status table to point the destination register at that RS.
c. Register Status Table
- Maps each architectural register to the RS that will produce its next value or marks it “empty.”
d. Reservation Stations (multiple instances)
- Separate pools: ADD_RS, MULT_RS, DIV_RS (configurable counts).
- Each RS holds operation type, operand values or tags, busy bit, remaining execution time.
e. Functional Units (abstracted within RS in this code)
- Each Reservation Station steps its remaining latency each cycle once its operands are ready.
f. Common Data Bus (CDB) / Writeback Logic
- When an RS finishes execution, it broadcasts its result on the CDB.
- All RS instances and Register Status listen on the bus to wake up dependent operands.
- Register File is updated (the vector<int>) when Writeback occurs.
g. Register File
- Vector of integer values.
- Updated on writeback to hold committed results.
h. Simulation Controller (main.cpp)
- Advances the system clock each iteration.
- Steps: Issue → Execute (decrement latency in each RS) → Writeback (broadcast completions) → Record timing info.

##### Relationships and Data Flows
- Issue Unit → Reservation Station (allocation) and → Register Status Table (update).
- Reservation Stations ↔ Register Status & other RS’s (via CDB broadcasts).
- Reservation Stations → Register File (on writeback).
- Register Status Table → Issue Unit (to check operand availability).
- Main Simulation Loop wraps all of the above in a timed cycle.

##### Architectural Patterns and Principles
- Dynamic scheduling and register renaming via Tomasulo’s algorithm.
- Separation of concerns:
- Issue logic separate from execution state (RS).
- Decoupling of register writes via CDB.
- Parameterization for experimentation: number of RS’s and latencies are constants in code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Control Flow
    SimulationController["Simulation Controller\n(main.cpp)"]:::control
    IssueUnit["Issue Unit"]:::control

    %% Data Storage
    InstructionQueue["Instruction Queue\n(vector<Instruction>)"]:::storage
    InstructionClass["Instruction Class\n(Instruction.h/.cpp)"]:::storage
    RegisterStatus["Register Status Table\n(vector<RegisterStatus>)"]:::storage
    RegisterFile["Register File\n(vector<int>)"]:::storage

    %% Execution Units
    subgraph "Reservation Stations"
        ADD_RS["ADD RS Pool"]:::exec
        MULT_RS["MULT RS Pool"]:::exec
        DIV_RS["DIV RS Pool"]:::exec
    end

    %% Bus
    CDB["CDB / Writeback Bus"]:::bus

    %% Configuration Files
    MakefileNode["Makefile"]:::config
    README["README.md"]:::config

    %% Legend
    Legend["Legend:\nBlue=Control\nGreen=Storage\nOrange=Execution\nGrey=Bus"]:::legend

    %% Relationships
    InstructionQueue -->|"provide instr"| IssueUnit
    IssueUnit -->|"allocate RS"| ADD_RS
    IssueUnit -->|"allocate RS"| MULT_RS
    IssueUnit -->|"allocate RS"| DIV_RS
    IssueUnit -->|"update status"| RegisterStatus
    RegisterStatus -->|"operand info"| IssueUnit

    SimulationController -->|"drive cycle"| IssueUnit
    SimulationController -->|"execute step"| ADD_RS
    SimulationController -->|"execute step"| MULT_RS
    SimulationController -->|"execute step"| DIV_RS
    SimulationController -->|"record timing"| RegisterFile

    ADD_RS -->|"broadcast result"| CDB
    MULT_RS -->|"broadcast result"| CDB
    DIV_RS -->|"broadcast result"| CDB

    CDB -->|"update status"| RegisterStatus
    CDB -->|"writeback"| RegisterFile

    %% Click Events
    click InstructionClass "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/Instruction.h"
    click ADD_RS "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/ReservationStation.h"
    click MULT_RS "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/ReservationStation.h"
    click DIV_RS "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/ReservationStation.h"
    click RegisterStatus "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/RegisterStatus.h"
    click SimulationController "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/main.cpp"
    click MakefileNode "https://github.com/milleraj66/ece585_tomasuloalgorithm/tree/master/Makefile"
    click README "https://github.com/milleraj66/ece585_tomasuloalgorithm/blob/master/README.md"

    %% Styles
    classDef control fill:#CFE2F3,stroke:#0366D6,color:#0366D6,stroke-width:1px;
    classDef storage fill:#E2F0D9,stroke:#295E27,color:#295E27,stroke-width:1px;
    classDef exec fill:#FDE9D9,stroke:#C03504,color:#C03504,stroke-width:1px;
    classDef bus fill:#E7E6E6,stroke:#636363,color:#636363,stroke-width:1px;
    classDef config fill:#FFF2CC,stroke:#7F6000,color:#7F6000,stroke-width:1px;
    classDef legend fill:#FFFFFF,stroke:#CCCCCC,color:#000000,stroke-width:1px,stroke-dasharray: 2 2;
```
