S2.15.2 What Retires This Cycle

HardImplement22 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
The program
The loop at 0c to 1c runs three times: the branch at 1c is taken twice. Every branch is guessed not taken. The ebreak at 24 ends the program when it retires: do not count it as an instruction.
Address, in hexInstruction
00lui x8, 0x80000
04addi x9, x0, 3
08addi x10, x0, 0
0clw x5, 0(x8)
10add x10, x10, x5
14addi x8, x8, 4
18addi x9, x9, -1
1cbne x9, x0, 0x0c
20sw x10, 0(x8)
24ebreak

The first cycle is cycle 1: it dispatches the instructions at 00 and 04. Enter every value in decimal.

EntryYour decision
RETIRED_IN_CYCLE_3How many instructions retire in cycle 3?
RETIRED_IN_CYCLE_4How many instructions retire in cycle 4?
HELD_AFTER_CYCLE_5How many entries does the buffer hold at the end of cycle 5?
ADDI_AT_14_FINISHEDIn which cycle is the addi at 14 finished, in the first round?
ADD_AT_10_FINISHEDIn which cycle is the add at 10 finished, in the first round?
ADDI_AT_14_RETIRESIn which cycle does that addi at 14 retire?
RETIRED_IN_CYCLE_6How many instructions retire in cycle 6?
BRANCH_FINISHEDIn which cycle is the first branch at 1c finished?
STORE_AT_20_FINISHEDIn which cycle is the store at 20, dispatched behind the first branch, finished?
FIRST_SQUASHIn which cycle does the first squash happen?
SQUASHED_THEREHow many entries does that squash throw away?
SQUASHED_IN_ALLHow many entries are squashed in the whole run?
DISPATCHED_IN_ALLHow many times is an instruction dispatched in the whole run, the ebreak included?
LAST_STORE_RETIRESIn which cycle does the store at 20 retire?
FREE_PLACES_AT_THE_ENDThe model starts with 16 free physical registers. How many are free at the end?
LAST_CYCLE_FOR_KThe 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

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

RETIRED IN CYCLE 3

Input
How many instructions retire in cycle 3?
Expected output
matches = 1

The instructions at 00 and 04 were dispatched in cycle 1 and finished in cycle 2.

Run samples executes all 3 public checks. Check all tests runs 16 checks on the server.

Icarus Verilog · server