A loop runs through a reorder buffer, with every branch guessed not taken. Say what retires in each cycle, what waits, and what a wrong guess throws away.
Hardware context: Test code beside the core: a sum that prices two programs of the real core ap_rv32 on pipelines of 5, 8 and 12 stages, and a model of a two-wide in-order core that replays the instructions the real core executed. ap_rv32 itself is single-issue. Reading the claims of a core: its depth, its width and its IPC on a real program
The core of this worksheet is the model of the lesson. In each cycle, in this order: a finished branch that was guessed wrong squashes everything behind it and redirects the fetch. Then up to two finished instructions retire from the head. Then up to two instructions are dispatched at the fetch address. A dispatched instruction starts in the next cycle at the earliest, and when its sources are finished. A load takes 2 cycles, everything else 1. "Finished in cycle c" allows a reader to start in cycle c plus 1, and allows retirement from cycle c plus 1 on. The buffer has 8 entries.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Address, in hex | Instruction |
|---|---|
| 00 | lui x8, 0x80000 |
| 04 | addi x9, x0, 3 |
| 08 | addi x10, x0, 0 |
| 0c | lw x5, 0(x8) |
| 10 | add x10, x10, x5 |
| 14 | addi x8, x8, 4 |
| 18 | addi x9, x9, -1 |
| 1c | bne x9, x0, 0x0c |
| 20 | sw x10, 0(x8) |
| 24 | ebreak |
The first cycle is cycle 1: it dispatches the instructions at 00 and 04. Enter every value in decimal.
| Entry | Your decision |
|---|---|
| RETIRED_IN_CYCLE_3 | How many instructions retire in cycle 3? |
| RETIRED_IN_CYCLE_4 | How many instructions retire in cycle 4? |
| HELD_AFTER_CYCLE_5 | How many entries does the buffer hold at the end of cycle 5? |
| ADDI_AT_14_FINISHED | In which cycle is the addi at 14 finished, in the first round? |
| ADD_AT_10_FINISHED | In which cycle is the add at 10 finished, in the first round? |
| ADDI_AT_14_RETIRES | In which cycle does that addi at 14 retire? |
| RETIRED_IN_CYCLE_6 | How many instructions retire in cycle 6? |
| BRANCH_FINISHED | In which cycle is the first branch at 1c finished? |
| STORE_AT_20_FINISHED | In which cycle is the store at 20, dispatched behind the first branch, finished? |
| FIRST_SQUASH | In which cycle does the first squash happen? |
| SQUASHED_THERE | How many entries does that squash throw away? |
| SQUASHED_IN_ALL | How many entries are squashed in the whole run? |
| DISPATCHED_IN_ALL | How many times is an instruction dispatched in the whole run, the ebreak included? |
| LAST_STORE_RETIRES | In which cycle does the store at 20 retire? |
| FREE_PLACES_AT_THE_END | The model starts with 16 free physical registers. How many are free at the end? |
| LAST_CYCLE_FOR_K | The instruction at 04 becomes addi x9, x0, K, so the loop runs K times. Give the cycle in which the ebreak retires, as an expression in K, for K of 2 or more. |
Examples
Example 1
RETIRED IN CYCLE 3- Input
How many instructions retire in cycle 3?
- Output
matches = 1
The instructions at 00 and 04 were dispatched in cycle 1 and finished in cycle 2.
Example 2
RETIRED IN CYCLE 4- Input
How many instructions retire in cycle 4?
- Output
matches = 1
The addi at 08, finished in cycle 3. The load at 0c behind it is finished only in cycle 4.
Example 3
HELD AFTER CYCLE 5- Input
How many entries does the buffer hold at the end of cycle 5?
- Output
matches = 1
Ten were dispatched and four have retired.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For LAST_CYCLE_FOR_K, enter a constant expression using K. Only this entry changes with the parameter. The supported integer range is 3 through 12, inclusive.
Hints
Hint 1
Squash, then retire, then dispatch. Write one line for each cycle with what is in, finished and out.
Hint 2
Mark the cycle in which each instruction is finished. It can leave one cycle later at the earliest, and only from the head.
Hint 3
Behind the branch, dispatch goes on at 20. When the branch is finished and was taken, cross out everything behind it.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
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 3 problems on this path