Package mars.simulator
Class DelayedBranch
java.lang.Object
mars.simulator.DelayedBranch
Represents a (potential) delayed branch. Note it is necessary only when
delayed branching is enabled. Here's the protocol for using it:
(1) When a runtime decision to branch is made (by either a branch or jump
instruction's simulate() method in InstructionSet), then if delayed branching
is enabled, the register() method is called with the branch target address
but the program counter is NOT set to the branch target address.
(2) At the end of that instruction cycle, the simulate() method in Simulator
will detect the registered branch, and set its trigger. Don't do anything yet
because the next instruction cycle is the delay slot and needs to complete.
(3) At the end of the next (delay slot) instruction cycle, the simulate()
method in Simulator will detect the triggered branch, set the program counter
to its target value and clear the delayed branch.
The only interesting situation is when the delay slot itself contains a
successful branch! I tried this with SPIM (e.g. beq followed by b) and it
treats it as if nothing was there and continues the delay slot into the next
cycle. The eventual branch taken is the original one (as one would hope) but
in the meantime the first statement following the sequence of successful
branches will constitute the delay slot and will be executed!
Since only one pending delayed branch can be taken at a time, everything here
is done with statics. The class itself represents the potential branch.
- Version:
- June 2007
- Author:
- Pete Sanderson
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
register(int targetAddress)
Register the fact that a successful branch is to occur.
-
Constructor Details
-
DelayedBranch
public DelayedBranch()
-
-
Method Details
-
register
public static void register(int targetAddress)Register the fact that a successful branch is to occur. This is called in the instruction's simulated execution (its simulate() method in InstructionSet). If a branch is registered but not triggered, this registration will be ignored (cannot happen if class usage protocol is followed). If a branch is currently registered and triggered, reset the state back to registered (but not triggered) in order to carry over the delay slot for another execution cycle. This is the only public member of the class.- Parameters:
targetAddress
- The address to branch to after executing the next instruction
-