Class BHTableModel

All Implemented Interfaces:
Serializable, TableModel

public class BHTableModel extends AbstractTableModel
Simulates the actual functionality of a Branch History Table (BHT).

The BHT consists of a number of BHT entries which are used to perform branch prediction. The entries of the BHT are stored as a Vector of BHTEntry objects. The number of entries is configurable but has to be a power of 2. The history kept by each BHT entry is also configurable during run-time. A change of the configuration however causes a complete reset of the BHT.

The typical interaction is as follows:

  • Construction of a BHT with a certain number of entries with a given history size.
  • When encountering a branch instruction the index of the relevant BHT entry is calculated via the getIndexForAddress(int) method.
  • The current prediction of the BHT entry at the calculated index is obtained via the getPrediction(int) method.
  • After detecting if the branch was really taken or not, this feedback is provided to the BHT by the updatePrediction(int, boolean) method.

Additionally it serves as TableModel that can be directly used to render the state of the BHT in a JTable. Feedback provided to the BHT causes a change of the internal state and a repaint of the table(s) associated to this model.

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

    • BHTableModel

      public BHTableModel(int numEntries, int historySize, boolean initVal)
      Constructs a new BHT with given number of entries and history size.
      Parameters:
      numEntries - number of entries in the BHT
      historySize - Size of the history (in bits/number of past branches).
  • Method Details

    • getColumnName

      public String getColumnName(int column)
      Returns the name of the given column of the table.
      Specified by:
      getColumnName in interface TableModel
      Overrides:
      getColumnName in class AbstractTableModel
      Parameters:
      column - The index of the column.
      Returns:
      Name of the given column.
    • getColumnClass

      public Class<?> getColumnClass(int column)
      Returns the class/type of the given column of the table. Required by the TableModel interface.
      Specified by:
      getColumnClass in interface TableModel
      Overrides:
      getColumnClass in class AbstractTableModel
      Parameters:
      column - the index of the column
      Returns:
      Class representing the type of the given column.
    • getColumnCount

      public int getColumnCount()
      Returns the number of columns.
      Returns:
      The number of columns.
    • getRowCount

      public int getRowCount()
      Returns the number of entries of the BHT.
      Returns:
      Number of rows (i.e. entries) in the BHT.
    • getValueAt

      public Object getValueAt(int row, int column)
      Returns the value of the cell at the given row and column.
      Parameters:
      row - The row index.
      column - The column index.
      Returns:
      The value of the cell.
    • initialize

      public void initialize(int entryCount, int historySize, boolean initialPrediction)
      Initializes the BHT with the given size and history. All previous data like the BHT entries' history and statistics will get lost. A refresh of the table that use this BHT as model will be triggered.
      Parameters:
      entryCount - Number of entries in the BHT (has to be a power of 2).
      historySize - Size of the history to consider.
      initialPrediction - Initial value for each entry (true means take branch, false means do not take branch).
    • getIndexForAddress

      public int getIndexForAddress(int address)
      Returns the index into the BHT for a given branch instruction address. A simple direct mapping is used.
      Parameters:
      address - The address of the branch instruction.
      Returns:
      The index into the BHT.
    • getPrediction

      public boolean getPrediction(int index)
      Retrieve the prediction for the i-th BHT entry.
      Parameters:
      index - The index of the entry in the BHT.
      Returns:
      The prediction to take (true) or do not take (false) the branch.
    • updatePrediction

      public void updatePrediction(int index, boolean branchTaken)
      Updates the BHT entry with the outcome of the branch instruction. This causes a change in the model and signals to update the connected table(s).
      Parameters:
      index - The index of the entry in the BHT.
      branchTaken - Whether the branch was taken.