Skip to content

t2ncay/cpuinsight

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

155 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CPUINSIGHT - CPU Branch Prediction Visualizer

C++ SFML CMake Platform CI Build

CPUINSIGHT is a graphical user interface built on top of the CPUINSIGHT CPU simulation backend, providing real-time visualization of CPU instruction execution and branch prediction behavior.

This repository focuses on the GUI frontend, enabling interactive inspection of pipeline flow, register states, and branch predictor performance while leveraging the original CPU simulation core.

Features

  • Interactive GUI - Real-time visualization of CPU pipeline
  • Multiple Branch Predictors - Support for various prediction algorithms
  • Instruction Pipeline Display - Visualize instruction execution flow
  • Register File Visualization - Watch register values update in real-time
  • Performance Metrics - Track prediction accuracy and performance

Screenshots

Base Profile Screenshot 2025 12 30 - 02 05 30 37

πŸš€ Quick Start

Prerequisites

  • CMake 3.16+ - Download
  • Git - Download
  • C++17 Compiler
    • Windows: Visual Studio 2019+ or MinGW
    • Linux: GCC 8+ or Clang 7+
    • Mac: Xcode Command Line Tools

Installation & Build

Windows (Command Prompt/PowerShell)

# Clone the repository
git clone https://github.com/tuncaygafarli/cpuinsight.git
cd cpuinsight

# Create build directory
mkdir build
cd build

# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build the project
cmake --build . --config Release

# Run the application
cd bin/Release
CPUINSIGHT.exe

Linux/Mac

# Clone the repository
git clone https://github.com/tuncaygafarli/cpuinsight.git
cd cpuinsight

# Create build directory
mkdir build
cd build

# Configure with CMake
cmake .. -DCMAKE_BUILD_TYPE=Release

# Build the project
cmake --build . --config Release -j4  # Use 4 cores for faster build

# Run the application
cd bin/Release
./CPUINSIGHT

One-Click Build Scripts

Windows (build.bat):

@echo off
echo Building CPUINSIGHT...
mkdir build 2>nul
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release
echo.
echo Running CPUINSIGHT...
cd bin/Release
CPUINSIGHT.exe
pause

Linux/Mac (build.sh):

#!/bin/bash
echo "Building CPUINSIGHT..."
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release -j$(nproc)
echo -e "\nRunning CPUINSIGHT..."
cd bin
./CPUINSIGHT

Project Structure

cpuinsight/
β”œβ”€β”€ cpu/                                      # CPU simulation core
β”‚ β”œβ”€β”€ cpu.cpp                                 # CPU emulation
β”‚ β”œβ”€β”€ cpu.h                                   # CPU definitions
β”‚ β”œβ”€β”€ branchpredictor.cpp                     # Branch predictor algorithms
β”‚ β”œβ”€β”€ branchpredictor.h                       # Branch predictor definitions
β”‚ β”œβ”€β”€ instruction.cpp                         # Instructions logic
β”‚ └── instruction.h                           # Instructor definitions
β”œβ”€β”€ gui/                                      # GUI rendering and interface
β”‚ β”œβ”€β”€ gui_render.cpp                          # Main GUI rendering logic
β”‚ β”œβ”€β”€ gui_render.h                            # GUI Rendering definitions
β”‚ β”œβ”€β”€ gui_command_parser.cpp                  # GUI Command Parser logic (CLI)
β”‚ β”œβ”€β”€ gui_command_parser.h                    # GUI Command Parser definitions
β”‚ β”œβ”€β”€ helpers.cpp                             # Helper functions
β”‚ └── helpers.h                               # Helpers definitions
β”œβ”€β”€ parser/                                   # Parser files
β”‚ β”œβ”€β”€ parser.cpp                              # Assembly parsing
β”‚ β”œβ”€β”€ parser.h                                # Parser definitions
β”‚ β”œβ”€β”€ lookup.cpp                              # Instruction lookup tables
β”‚ β”œβ”€β”€ lookup.h                                # Lookup definitions
β”‚ └── token.h                                 # Token definitions
β”œβ”€β”€ main.cpp                                  # Entry point
β”œβ”€β”€ aliases.h                                 # Aliases definitions
β”œβ”€β”€ CMakeLists.txt                            # CMake Lists
└── (other files...)

Usage

Basic controls

  • ArrowUp : Scrolls up in INSTRUCTION section
  • ArrowDown : Scrolls down in INSTRUCTION section
  • SpaceBar : Executes only one instruction
  • V : Enables / disables automatic execution
  • R : Resets the process
  • LShift : Increases auto CPU execution delay
  • LControl : Decreases auto CPU execution delay

Build options

Configure different build types:

# Debug build (with symbols)
cmake .. -DCMAKE_BUILD_TYPE=Debug

# Release build (optimized)
cmake .. -DCMAKE_BUILD_TYPE=Release

# RelWithDebInfo (optimized with debug info)
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo

# MinSizeRel (minimum size)
cmake .. -DCMAKE_BUILD_TYPE=MinSizeRel

Build specific configurations:

# Build Debug version
cmake --build . --config Debug

# Build Release version
cmake --build . --config Release

# Clean and rebuild
cmake --build . --config Release --clean-first

Supported Branch Predictors

1. Simple Predictor

Basic implementation using simple heuristics for branch prediction.

2. GAg (Global Adaptive)

Uses a global history register to track branch patterns and adapts prediction based on recent history.

3. PAg (Per-address Adaptive)

Maintains separate prediction history for each branch address, allowing per-branch optimization.

4. GShare

Hybrid approach that combines global branch history with branch address for improved accuracy.

πŸ› οΈ Development

Adding New Features

  1. Add source files to the appropriate directory (src/gui/, src/cpu/, or src/parser/)
  2. Update CMakeLists.txt if adding new source files:
    # Add to the existing file glob pattern
    file(GLOB_RECURSE SRC_FILES
        "src/gui/*.cpp"
        "src/cpu/*.cpp"
        "src/parser/*.cpp"
        # Add new patterns here if needed
    )
  3. Rebuild the project:
    cd build
    cmake --build . --config Debug

🧾 Credits

  • CPU Simulation Backend Developed by f3rhd Licensed under the MIT License

  • GUI Frontend Developed by Tuncay Gafarli

This repository is a fork of the original CPUINSIGHT project and focuses on GUI-level visualization.


πŸ“œ License

  • The CPU simulation backend is licensed under the MIT License Β© 2025 f3rhd

  • The GUI frontend additions in this repository are Β© 2025 Tuncay Gafarli

See the LICENSE files for full details.

About

Simple emulator for dynamic branch prediction analysis.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 83.8%
  • CMake 8.1%
  • Assembly 8.1%