A branch is decided in EX. Write the logic that sends the PC to the target and throws away the two instructions fetched behind the branch.
Hardware context: The lab pipeline with branches decided in EX: a taken branch redirects the PC and puts bubbles into IF/ID and ID/EX; the flush can be switched off. Counting branch penalties in a pipeline trace and reviewing the flush logic of a core
The lab of the lesson let its bench say when to redirect and what to flush. A real pipeline has logic for that, around the PC and the first two pipeline registers.
Write it. Your block owns the PC. It owns the address and the valid bit of IF/ID, and the valid bit of ID/EX. It also carries one decoded bit from ID to EX: whether the instruction is a branch or a jump.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
Full specification
| Case | The PC | IF/ID | ID/EX |
|---|---|---|---|
| The instruction in EX goes to its target | takes target_e | takes a bubble | takes a bubble |
Otherwise, wait_d is 1 | holds | holds | takes a bubble |
| Otherwise | takes the PC plus 4 | takes the instruction in IF: pc_d takes pc_f | takes the instruction in ID, with control_d |
| All of these hold | Why |
|---|---|
| EX holds an instruction | A bubble decides nothing. |
| That instruction is a branch or a jump | For every other instruction, the compare gives a value that means nothing. |
taken_e is 1 | The condition of the branch is true. For a jump the bench always gives 1. |
How to read a result: a public case shows one cycle. It gives redirect, the two valid bits and the low eight bits of the PC. A private case runs many cycles and checks every one.
Examples
Example 1
A Taken Branch in EX- Input
a branch at address 08, in the cycle in which it is in EX and taken, with the target 40
- Output
redirect = 0, valid_d = 1, valid_e = 1, pc_f = 0x10
The branch was fetched in the third cycle, so it is in EX in the fifth. It is taken: redirect is 1. ID and EX still hold instructions, and the PC is 10 in hex. The flush shows in the next cycle.
Example 2
One Cycle Later- Input
the same branch, one cycle later
- Output
redirect = 0, valid_d = 1, valid_e = 1, pc_f = 0x14
The PC holds the target, 40. IF/ID and ID/EX took bubbles: valid_d and valid_e are 0. Nothing is in EX, so redirect is 0.
Example 3
A Branch That Is Not Taken- Input
the branch is not taken: the cycle after it was in EX
- Output
redirect = 0, valid_d = 1, valid_e = 1, pc_f = 0x14
Nothing was thrown away. The PC went on to 14, and ID and EX hold the two instructions behind the branch.
Constraints and Contract
- The reset is asynchronous and active low.
- redirect has no clock: it follows the inputs and your registers. The bench reads all outputs 1 ns after it has set the inputs.
- The bench gives wait_d only in a cycle in which ID holds an instruction and EX holds a load.
- taken_e and target_e may hold anything while EX holds a bubble or an instruction that is not a branch or a jump.
- pc_d is checked only while valid_d must be 1, and control_e only while valid_e must be 1.
Hints
Hint 1
Write one signal that is 1 exactly when the instruction in EX goes to its target. Each row of the second table is one part of it.
Hint 2
That signal picks the first row of the first table. It must win over a wait and over the usual step.
Hint 3
Ask what EX holds in the cycle after a redirect. Can your signal be 1 again without a new branch?
What the grader checks: A taken branch and the cycles after it. A branch that is not taken. A compare that says taken for other instructions, for a bubble and after a flush. Two branches in a row, with the first or the second taken. A wait, and a branch that waited in ID. Requests for a wait that find a bubble in EX. A branch to itself, to address 0 and to a high address. A branch at the target of a branch. Two mixed runs. Every cycle is checked, from the first after a reset.
16 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path