mars.tools
Class BHTEntry

java.lang.Object
  extended by mars.tools.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 getPrediction() 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 getStatsPredCorrect(), getStatsPredIncorrect() and getStatsPredPrecision().

Author:
ingo.kofler@itec.uni-klu.ac.at

Constructor Summary
BHTEntry(int historySize, boolean initVal)
          Constructs a BHT entry with a given history size.
 
Method Summary
 String getHistoryAsStr()
          Builds a string representation of the BHT entry's history.
 boolean getPrediction()
          Returns the branch prediction based on the history.
 String getPredictionAsStr()
          Returns a string representation of the BHT entry's current prediction.
 int getStatsPredCorrect()
          Get the absolute number of correct predictions.
 int getStatsPredIncorrect()
          Get the absolute number of mispredictions.
 double getStatsPredPrecision()
          Get the percentage of correct predictions.
 void updatePrediction(boolean branchTaken)
          Updates the entry's history and prediction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BHTEntry

public BHTEntry(int historySize,
                boolean initVal)
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
initVal - the initial value of the entry (take or do not take)
Method Detail

getPrediction

public boolean getPrediction()
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)

getStatsPredIncorrect

public int getStatsPredIncorrect()
Get the absolute number of mispredictions.

Returns:
number of incorrect predictions (mispredictions)

getStatsPredCorrect

public int getStatsPredCorrect()
Get the absolute number of correct predictions.

Returns:
number of correct predictions

getStatsPredPrecision

public double getStatsPredPrecision()
Get the percentage of correct predictions.

Returns:
the percentage of correct predictions

getHistoryAsStr

public String getHistoryAsStr()
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 do NOT TAKE the branch.

Returns:
a string representation of the BHT entry's current prediction