Class BHTSimulator
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,EventListener,Accessible,RootPaneContainer,WindowConstants,Memory.Listener,MarsTool
The simulation is based on observing the access to the instruction memory area (text segment). If a branch instruction is encountered, a prediction based on a BHT is performed. The outcome of the branch is compared with the prediction and the prediction is updated accordingly. Statistics about the correct and incorrect number of predictions can be obtained for each BHT entry. The number of entries in the BHT and the history that is considered for each prediction can be configured interactively. A change of the configuration however causes a re-initialization of the BHT.
The tool can be used to show how branch prediction works in case of loops and how effective such simple methods are. In case of nested loops the difference of BHT with 1 or 2 Bit history can be explored and visualized.
- Author:
- Ingo Kofler (ingo.kofler@itec.uni-klu.ac.at)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrameNested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrameNested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow, Window.TypeNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intConstant for the default size of the BHT.static final intConstant for the default history size.static final booleanConstant for the default inital value.static final StringThe name of the tool.static final StringThe version of the tool.Fields inherited from class mars.tools.AbstractMarsTool
dialogFields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabledFields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSORFields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected JComponentCreates a GUI and initialize the GUI with the default values.protected static intextractBranchAddress(int address, BasicStatement statement) Extracts the target address of the branch.getName()Returns the name of the tool.protected voidhandleExecuteBranchInstruction(int branchInstructionAddress, boolean branchTaken) Handles the execution of the branch instruction.protected voidhandlePreBranchInst(int address, BasicStatement statement) Handles the execution branch instruction.protected static booleanisBranchInstruction(BasicStatement statement) Determines if the instruction is a branch instruction or not.voidmemoryRead(int address, int length, int value, int wordAddress, int wordValue) Callback for text segment access by the MIPS simulator.protected voidreset()Perform a reset of the simulator.protected voidAdds BHTSimulator as observer of the text segment.protected voidUnregister this tool as a listener of memory and/or registers, if applicable.protected static booleanwillBranch(BasicStatement statement) Checks if the branch instruction delivered as parameter will branch or not.Methods inherited from class mars.tools.AbstractMarsTool
action, buildButtonArea, buildContentPane, closeTool, getHelpComponent, handleClose, initializePostGUI, initializePreGUIMethods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, updateMethods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecoratedMethods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, show, toBack, toFrontMethods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, resize, resize, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface mars.tools.MarsTool
getIcon, getToolMenuOrderMethods inherited from interface mars.mips.hardware.Memory.Listener
memoryReset, memoryWrittenMethods inherited from interface java.awt.MenuContainer
getFont, postEvent
-
Field Details
-
DEFAULT_ENTRY_COUNT
public static final int DEFAULT_ENTRY_COUNTConstant for the default size of the BHT.- See Also:
-
DEFAULT_HISTORY_SIZE
public static final int DEFAULT_HISTORY_SIZEConstant for the default history size.- See Also:
-
DEFAULT_INITIAL_VALUE
public static final boolean DEFAULT_INITIAL_VALUEConstant for the default inital value.- See Also:
-
NAME
The name of the tool.- See Also:
-
VERSION
The version of the tool.- See Also:
-
-
Constructor Details
-
BHTSimulator
public BHTSimulator()Construct an instance of this tool. This will be used by theToolManager.
-
-
Method Details
-
startObserving
protected void startObserving()Adds BHTSimulator as observer of the text segment. -
stopObserving
protected void stopObserving()Description copied from class:AbstractMarsToolUnregister this tool as a listener of memory and/or registers, if applicable. This method is called when the tool is closed by the user. Does nothing by default.- Overrides:
stopObservingin classAbstractMarsTool- See Also:
-
buildMainDisplayArea
Creates a GUI and initialize the GUI with the default values.- Specified by:
buildMainDisplayAreain classAbstractMarsTool
-
getName
Returns the name of the tool.- Specified by:
getNamein interfaceMarsTool- Specified by:
getNamein classAbstractMarsTool- Returns:
- The tool's name as a string.
-
reset
protected void reset()Perform a reset of the simulator. This causes the BHT to be reseted and the log messages to be cleared.- Overrides:
resetin classAbstractMarsTool
-
handlePreBranchInst
Handles the execution branch instruction. This method is called each time a branch instruction is executed. Based on the address of the instruction the corresponding index into the BHT is calculated. The prediction is obtained from the BHT at the calculated index and is visualized appropriately.- Parameters:
statement- The branch statement that is executed.
-
handleExecuteBranchInstruction
protected void handleExecuteBranchInstruction(int branchInstructionAddress, boolean branchTaken) Handles the execution of the branch instruction. The correctness of the prediction is visualized in both the table and the log message area. The BHT is updated based on the information if the branch instruction was taken or not.- Parameters:
branchInstructionAddress- The address of the branch instruction.branchTaken- The information if the branch is taken or not (determined in a step before).
-
isBranchInstruction
Determines if the instruction is a branch instruction or not.- Parameters:
statement- the statement to investigate- Returns:
- true, if statement is a branch instruction, otherwise false
-
willBranch
Checks if the branch instruction delivered as parameter will branch or not.- Parameters:
statement- The branch instruction to be investigated.- Returns:
- true if the branch will be taken, otherwise false.
-
extractBranchAddress
Extracts the target address of the branch.In MIPS the target address is encoded as 16-bit value. The target address is encoded relative to the address of the instruction after the branch instruction
- Parameters:
statement- The branch instruction.- Returns:
- The address of the instruction that is executed if the branch is taken.
-
memoryRead
public void memoryRead(int address, int length, int value, int wordAddress, int wordValue) Callback for text segment access by the MIPS simulator.The method is called each time the text segment is accessed to fetch the next instruction. If the next instruction to execute was a branch instruction, the branch prediction is performed and visualized. In case the last instruction was a branch instruction, the outcome of the branch prediction is analyzed and visualized.
- Parameters:
address- The address which was read from.length- The number of bytes read. Will always be 1 (single byte),Memory.BYTES_PER_HALFWORD, orMemory.BYTES_PER_WORD.value- The value which was read.wordAddress- The address of the word affected by the operation.wordValue- The full value of the word.
-