10.6 Creating a new branch predictor

The example predictors that ARM provides are intended to show different techniques for branch prediction to help you create new ones. The source code for them is located in $PVLIB_HOME/plugins/source/BranchPrediction/.

A user-defined branch predictor must:

Example 10-1 Branch predictor

// SamplePredictor.h
#include <ct/BranchPredictionPluginInterfaces.h>
#include "PredictorInterface.h"

namespace BranchPrediction
{
    class SamplePredictor : public PredictorInterface
    {
    public:
        Direction getPredictedDirection(VAddr64_t pc_) SG_OVERRIDE;
        void updateStructures(VAddr64_t pc_, Direction actual_direction_) SG_OVERRIDE;

    public:
        SamplePredictor(Direction dir_ = Direction::TAKEN);
        ~ SamplePredictor();

        static const char* getPredictorName() {
            return "SamplePredictor";
        }

        static PredictorInterface* createInstance() {
            return new SamplePredictor();
        }

    private:
        Direction default_direction;
    };
};


// SamplePredictor.cpp
#include "SamplePredictor.h"

namespace BranchPrediction
{

    SamplePredictor::SamplePredictor()
    {
        // Initialize the predictor
    }

    SamplePredictor::~SamplePredictor()
    {
        // Do nothing
    }

    Direction SamplePredictor::getPredictedDirection(VAddr64_t pc_)
    {
        // Return the predicted direction
        // This is called when the CPU makes a branch prediction
        return Direction::TAKEN;
    }

    void SamplePredictor::updateStructures(VAddr64_t pc_, Direction actual_direction_)
    {
        // Update any structure or tables that this predictor uses
        // This is called when the branch has committed and the direction 
        // taken is known.
    }
}; 
Non-ConfidentialPDF file icon PDF versionARM 100965_1101_00_en
Copyright © 2014–2017 ARM Limited or its affiliates. All rights reserved.