# anirudhsinga/tage_bp architecture

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

- Interactive diagram: https://gitdiagram.com/anirudhsinga/tage_bp
- Repository: https://github.com/anirudhsinga/tage_bp

## Overview

##### Project type and purpose
- From the file tree (README.md and tage.cc) and the README, we see this is a low-level, algorithmic component—a standalone implementation of the TAGE branch predictor used in CPU microarchitecture research and simulators.

##### File structure
- There are no separate “frontend/backend” folders or service boundaries. All logic lives in a single source file (tage.cc). This tells us there aren’t multiple services or layers; instead, the focus is on internal modules and data structures.

##### README for additional insights
- The predictor consists of:
- A global history register (GHR)
- Multiple predictor tables (each with geometric history length, partial tags, and usefulness counters)
- A selection mechanism that chooses which table’s prediction to trust
- An update mechanism that adjusts counters and tags after branch resolution

a. Main components
- Input Interface: accepts BranchPC and current GHR
- History-Length Index Generator: computes per-table indices based on different history lengths (geometric series)
- Tag Tables (T0, T1, …, Tn): each contains entries with partial tags, prediction counters, and usefulness counters
- Tag-Match Detector: compares tags from each table to the address tag
- Predictor Selector: picks the highest-priority matching table (using usefulness as tie-breaker)
- Output Interface: emits a Taken/Not-Taken decision back to the CPU pipeline
- Update Unit: on branch resolution, updates prediction counters, usefulness bits, partial tags, and GHR

b. Relationships and data flow
1. BranchPC & GHR → Index Generator
2. Index Generator → each Tag Table
3. Tables → Tag-Match Detector → Predictor Selector → Output
4. Branch outcome + PC → Update Unit → modifies Tables & GHR

c. Architectural patterns / design principles
- “Table of predictors” pattern: multiple tables with different histories
- Tag-based disambiguation to reduce aliasing
- Usefulness bits for confidence tracking and garbage-collection of stale entries

d. Key technologies / libraries
- Pure C++ (single source file) implementing bit-level manipulations
- No external dependencies—meant to be integrated into a CPU simulator

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External entities
    CPUFetch["CPU Fetch Stage"]:::external
    BranchResolve["Branch Resolution Logic"]:::external

    %% Storage elements
    GHR["Global History Register (GHR)"]:::storage
    TagTables["Tag Tables (T0…Tn)"]:::storage

    %% Logic units
    InputInterface["Input Interface"]:::logic
    IndexGen["History-Length Index Generator"]:::logic
    TagMatch["Tag-Match Detector"]:::logic
    Selector["Predictor Selector"]:::logic
    OutputInterface["Output Interface"]:::logic
    UpdateUnit["Update Unit"]:::logic

    %% Documentation
    README["Project Documentation"]:::external

    %% Prediction flow
    CPUFetch -->|"PC, GHR bits"| InputInterface
    InputInterface -->|"Indexed PC, GHR fragments"| IndexGen
    IndexGen -->|"Table indices"| TagTables
    TagTables -->|"Tag & counter readouts"| TagMatch
    TagMatch -->|"Matching entries"| Selector
    Selector -->|"Prediction"| OutputInterface
    OutputInterface -->|"Taken/Not-Taken"| CPUFetch

    %% Update flow
    BranchResolve -->|"Actual Outcome, PC"| UpdateUnit
    UpdateUnit -->|"Update entries"| TagTables
    UpdateUnit -->|"Update GHR bits"| GHR

    %% Click events
    click InputInterface "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click GHR "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click IndexGen "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click TagTables "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click TagMatch "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click Selector "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click OutputInterface "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click UpdateUnit "https://github.com/anirudhsinga/tage_bp/blob/main/tage.cc"
    click README "https://github.com/anirudhsinga/tage_bp/blob/main/README.md"

    %% Styles
    classDef storage fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef logic fill:#90EE90,stroke:#000,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:1px

    %% Link styles
    linkStyle 0,1,2,3,4,5,6 stroke:#0000FF,stroke-width:2px
    linkStyle 7,8,9 stroke:#FF0000,stroke-width:2px
```
