Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## mars.tools
Class BHTableModel

    java.lang.Object
      javax.swing.table.AbstractTableModel
          mars.tools.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 `getIdxForAddress(int)` method.
- The current prediction of the BHT entry at the calculated index is obtained via the `getPredictionAtIdx(int)` method.
- After detecting if the branch was really taken or not, this feedback is provided to the BHT by the `updatePredictionAtIdx(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@itec.uni-klu.ac.at
See Also:
  Serialized Form

Field Summary

Fields inherited from class javax.swing.table.AbstractTableModel
`listenerList`

Constructor Summary
`BHTableModel(int numEntries, int historySize, boolean initVal)` Constructs a new BHT with given number of entries and history size.

Method Summary
`Class` | `getColumnClass(int i)` Returns the class/type of the i-th column of the table.
`int` | `getColumnCount()` Returns the number of columns.
`String` | `getColumnName(int i)` Returns the name of the i-th column of the table.
`int` | `getIdxForAddress(int address)` Returns the index into the BHT for a given branch instruction address.
`boolean` | `getPredictionAtIdx(int index)` Retrieve the prediction for the i-th BHT entry.
`int` | `getRowCount()` Returns the number of entries of the BHT.
`Object` | `getValueAt(int row, int col)` Returns the value of the cell at the given row and column Required by the TableModel interface.
`void` | `initBHT(int numEntries, int historySize, boolean initVal)` Initializes the BHT with the given size and history.
`void` | `updatePredictionAtIdx(int index, boolean branchTaken)` Updates the BHT entry with the outcome of the branch instruction.

Methods inherited from class javax.swing.table.AbstractTableModel
`addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### 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 Detail

### getColumnName

    public String getColumnName(int i)

  Returns the name of the i-th column of the table. Required by the TableModel interface.

  Specified by:
    `getColumnName` in interface `TableModel`
  Overrides:
    `getColumnName` in class `AbstractTableModel`
  Parameters:
    `i` - the index of the column
  Returns:
    name of the i-th column

### getColumnClass

    public Class getColumnClass(int i)

  Returns the class/type of the i-th column of the table. Required by the TableModel interface.

  Specified by:
    `getColumnClass` in interface `TableModel`
  Overrides:
    `getColumnClass` in class `AbstractTableModel`
  Parameters:
    `i` - the index of the column
  Returns:
    class representing the type of the i-th column

### getColumnCount

    public int getColumnCount()

  Returns the number of columns. Required by the TableModel interface.

  Returns:
    currently the constant 6

### getRowCount

    public int getRowCount()

  Returns the number of entries of the BHT. Required by the TableModel interface.

  Returns:
    number of rows / entries of the BHT

### getValueAt

    public Object getValueAt(int row,
                             int col)

  Returns the value of the cell at the given row and column Required by the TableModel interface.

  Parameters:
    `row` - the row index
    `col` - the column index
  Returns:
    the value of the cell

### initBHT

    public void initBHT(int numEntries,
                        int historySize,
                        boolean initVal)

  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:
    `numEntries` - number of entries in the BHT (has to be a power of 2)
    `historySize` - size of the history to consider
    `initVal` - initial value for each entry (true means take branch, false do not take branch)

### getIdxForAddress

    public int getIdxForAddress(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

### getPredictionAtIdx

    public boolean getPredictionAtIdx(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

### updatePredictionAtIdx

    public void updatePredictionAtIdx(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` -

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD