Skip to content

abaksy/BranchPredictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Branch Predictor Project

This project implements multiple branch prediction strategies and provides tools for performance analysis and comparison.

Table of Contents

Overview

This project implements and compares different branch prediction algorithms used in modern processors. Branch prediction is critical for processor performance as it helps predict whether conditional branches will be taken or not taken, allowing the processor to speculatively execute instructions along the predicted path.

The project includes:

  • Static Predictor: Always predicts taken
  • Gshare Predictor: Uses global history with XOR indexing
  • Tournament Predictor: Combines global and local predictors with a chooser
  • Custom TAGE Predictor: Advanced predictor using geometric history length

Implemented Predictors

1. Static Predictor

  • Type: --static
  • Description: Always predicts that branches will be taken
  • Use Case: Baseline for comparison

2. Gshare Predictor

  • Type: --gshare:<ghistory_bits>
  • Description: Uses global branch history XORed with PC bits to index a pattern history table
  • Parameters:
    • ghistory_bits: Number of bits for global history (typically 10-13)
  • Example: --gshare:13

3. Tournament Predictor

  • Type: --tournament:<ghistory>:<lhistory>:<index>
  • Description: Combines global and local predictors using a chooser table
  • Parameters:
    • ghistory: Global history bits
    • lhistory: Local history bits
    • index: PC index bits
  • Example: --tournament:9:10:10

4. Custom TAGE Predictor

  • Type: --custom
  • Description: Advanced predictor using geometric history lengths and tagged entries
  • Features:
    • Multiple components with different history lengths
    • Tagged entries to reduce aliasing
    • Bimodal fallback predictor
    • Memory usage: ~43KB (within 64KB limit)

Installation and Build

Prerequisites

  • GCC compiler (version 5.4 or later recommended)
  • Make utility
  • Python 3 (for analysis scripts)
  • bzip2 (for trace decompression)

Building the Project

# Navigate to the source directory
cd src/

# Clean previous builds
make clean

# Build the predictor
make

This creates an executable named predictor in the src/ directory.

Usage

Basic Usage

# Run on compressed trace file
bunzip2 -kc trace.bz2 | ./predictor --gshare:13

# Run with verbose output
bunzip2 -kc trace.bz2 | ./predictor --gshare:13 --verbose

Command Line Options

  • --help: Display usage information
  • --verbose: Output all predictions to stdout
  • --static: Use static predictor
  • --gshare:<bits>: Use Gshare predictor with specified history bits
  • --tournament:<g>:<l>:<i>: Use tournament predictor with specified parameters
  • --custom: Use custom TAGE predictor

Performance Analysis

Running Analysis

# Generate performance comparison chart
python analyze_results.py

This shows the performance comparison across all predictors and trace files.

Expected Results

Based on the analysis script, the custom TAGE predictor typically achieves the lowest misprediction rates:

  • Floating-point traces: 0.3-0.8% misprediction rate
  • Integer traces: 0.2-8.1% misprediction rate
  • Memory traces: 0.5-6.8% misprediction rate

Technical Details

Predictor Implementations

Gshare Predictor

  • Uses global history register XORed with PC bits
  • 2-bit saturating counters for predictions
  • History updated by shifting in new outcomes

Tournament Predictor

  • Combines global and local predictors
  • Chooser table selects between predictors
  • All counters are 2-bit saturating counters
  • Based on Alpha 21264 architecture

Custom TAGE Predictor

  • Components: 6 geometric history length components
  • Tags: Partial tags to reduce aliasing
  • Bimodal: Fallback predictor for tag misses
  • Memory: ~43KB total usage
  • Features:
    • Geometric history lengths: 76, 44, 26, 15, 9, 5
    • Tagged entries with partial tags
    • Useful counters for entry allocation
    • Compressed history for efficiency

State Machine for 2-bit Counters

        NT      NT      NT
      ----->  ----->  ----->
    ST      WT      WN      SN
      <-----  <-----  <-----
        T       T       T
  • SN: Strongly Not Taken
  • WN: Weakly Not Taken
  • WT: Weakly Taken
  • ST: Strongly Taken

Results

The custom TAGE predictor demonstrates superior performance across all trace types:

Trace Tournament Gshare Custom
fp_1 0.994% 0.825% 0.805%
fp_2 3.410% 1.678% 0.361%
int_1 13.846% 13.839% 8.133%
int_2 0.472% 0.420% 0.256%
mm_1 3.277% 6.696% 0.565%
mm_2 9.145% 10.138% 6.833%

The TAGE predictor achieves an average improvement of:

  • 67% over Tournament predictor
  • 72% over Gshare predictor

About

Implement tournament, gShare and a custom branch prediction algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •