Class BHTEntry

java.lang.Object
mars.tools.bhtsim.BHTEntry

public class BHTEntry extends Object
Represents a single entry of the Branch History Table.

The entry holds the information about former branch predictions and outcomes. The number of past branch outcomes can be configured and is called the history. The semantics of the history of size n is as follows. The entry will change its prediction, if it mispredicts the branch n times in series. The prediction of the entry can be obtained by the getCurrentPrediction() method. Feedback of taken or not taken branches is provided to the entry via the updatePrediction(boolean) method. This causes the history and the prediction to be updated.

Additionally the entry keeps track about how many times the prediction was correct or incorrect. The statistics can be obtained by the methods getCorrectCount(), getIncorrectCount() and getPrecision().

Author:
Ingo Kofler (ingo.kofler@itec.uni-klu.ac.at)
  • Constructor Details

    • BHTEntry

      public BHTEntry(int historySize, boolean initialPrediction)
      Constructs a BHT entry with a given history size.

      The size of the history can only be set via the constructor and cannot be changed afterwards.

      Parameters:
      historySize - Number of past branch outcomes to remember.
      initialPrediction - The initial value of the entry (true means take branch, false means do not take branch).
  • Method Details

    • getCurrentPrediction

      public boolean getCurrentPrediction()
      Returns the branch prediction based on the history.
      Returns:
      true if prediction is to take the branch, false otherwise.
    • updatePrediction

      public void updatePrediction(boolean branchTaken)
      Updates the entry's history and prediction. This method provides feedback for a prediction. The history and the statistics are updated accordingly. Based on the updated history, a new prediction is calculated.
      Parameters:
      branchTaken - Signals if the branch was taken (true) or not (false).
    • getIncorrectCount

      public int getIncorrectCount()
      Get the absolute number of mispredictions.
      Returns:
      Number of incorrect predictions (mispredictions).
    • getCorrectCount

      public int getCorrectCount()
      Get the absolute number of correct predictions.
      Returns:
      Number of correct predictions.
    • getPrecision

      public double getPrecision()
      Get the percentage of correct predictions.
      Returns:
      The percentage of correct predictions.
    • getHistoryAsString

      public String getHistoryAsString()
      Builds a string representation of the BHT entry's history. The history is a sequence of flags that signal if the branch was taken (T) or not taken (NT).
      Returns:
      A string representation of the BHT entry's history.
    • getPredictionAsStr

      public String getPredictionAsStr()
      Returns a string representation of the BHT entry's current prediction. The prediction can be either to TAKE or NOT TAKE the branch.
      Returns:
      A string representation of the BHT entry's current prediction.