S2.7.3 Read the Pipeline Diagram

EasyImplement12 minIcarus Verilog · serverReview the topic

Six instructions run on a five-stage pipeline. Say which instruction is in which stage, cycle by cycle.

Hardware context: The five stages of ap_rv32_p5 cut down to arithmetic, lw and sw, with the register file and the ALU of the real core and no hazard logic. Reading a pipeline diagram and a pipeline trace of a processor

The program below starts at address 0. It runs on the five-stage pipeline of the lesson. The first instruction is in IF in cycle 1. No instruction reads a register that another one writes, so nothing waits. Addresses are in decimal here, so that you can enter them as they are.

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
Six instructions and an ebreak. The ebreak, at address 24, is not counted as an instruction of the program.
Address, in decimalInstruction
0addi x5, x0, 1
4addi x6, x0, 2
8addi x7, x0, 3
12addi x8, x0, 4
16addi x9, x0, 5
20addi x10, x0, 6
24ebreak

Draw the pipeline diagram first: a row for each instruction, a column for each cycle. Then read the answers from it. Enter every value in decimal.

EntryYour decision
STAGESHow many stages does an instruction pass through?
FIRST_IN_WBIn which cycle is the instruction at address 0 in WB?
IN_EX_AT_5Give the address of the instruction that is in EX in cycle 5.
IN_IF_AT_5Give the address of the instruction that is in IF in cycle 5.
CYCLE_OF_12_IN_MEMIn which cycle is the instruction at address 12 in MEM?
CYCLE_OF_20_IN_IDIn which cycle is the instruction at address 20 in ID?
AT_WORK_IN_3How many instructions of the program are in the pipeline in cycle 3?
AT_WORK_IN_6How many instructions of the program are in the pipeline in cycle 6?
AT_WORK_IN_9How many instructions of the program are in the pipeline in cycle 9?
CYCLE_X7_WRITTENThe instruction at address 8 writes x7. In which cycle is it in WB?
SINGLE_CYCLEHow many cycles do the six instructions take on the single-cycle core, after its first fetch?
LAST_WB_FOR_KThe program has K instructions before the ebreak. Give the cycle in which the last of them is in WB, as an expression in K.

Examples

Example 1

STAGES
Input
How many stages does an instruction pass through?
Output
matches = 1

IF, ID, EX, MEM and WB.

Example 2

FIRST IN WB
Input
In which cycle is the instruction at address 0 in WB?
Output
matches = 1

It is in IF in cycle 1. WB is four stages later.

Example 3

IN EX AT 5
Input
Give the address of the instruction that is in EX in cycle 5.
Output
matches = 1

The instruction in WB is at 0. EX is two stages behind it: two instructions, 8 bytes.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For LAST_WB_FOR_K, enter a constant expression using K. Only this entry changes with the parameter. The supported integer range is 1 through 40, inclusive.

Hints

Hint 1

Each row of the diagram is the row above it, moved one cycle to the right.

Hint 2

To follow an instruction, read its row. To see one cycle, read its column.

Hint 3

The instruction number n is in IF in cycle n. Add 1 for each stage after IF.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

12 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

STAGES

Input
How many stages does an instruction pass through?
Expected output
matches = 1

IF, ID, EX, MEM and WB.

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

Icarus Verilog · server