S2.9.2 Count the Stalls

EasyImplement12 minIcarus Verilog · serverReview the topic

A program with four loads runs on the five-stage pipeline. Find the instructions that must wait, and count the cycles.

Hardware context: The lab pipeline with forwarding and a load-use stall: the PC and IF/ID hold for one cycle and ID/EX takes a bubble; the stall can be switched off. Counting stall cycles in a pipeline trace and reviewing the hazard unit of a core

The first program below starts at address 0 and runs on the five-stage core of the lesson. That core has forwarding and the load-use stall. The first instruction is in IF in cycle 1. The register x10 holds the address 8000_0000 in hex. Addresses of instructions are in decimal here.

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
Thirteen instructions and an ebreak.
Address, in decimalInstruction
0addi x10, x0, 1
4slli x10, x10, 31
8addi x5, x0, 2
12sw x5, 0(x10)
16lw x6, 0(x10)
20add x7, x6, x6
24lw x8, 0(x10)
28sw x8, 4(x10)
32lw x9, 4(x10)
36addi x11, x7, 1
40add x12, x9, x11
44lw x13, 0(x10)
48add x14, x5, x13
52ebreak

In this core, the data of a store is forwarded in EX, like an ALU operand. So a store that stores a value loaded by the instruction right before it must wait as well.

Enter every value in decimal. For a question with yes or no, enter 1 for yes and 0 for no.

The program
A second program, for the last entry. It is shown for K = 3: the pair at 16 and 20 comes K times in a row. The three instructions after the pairs, and the first four, stay as they are.
Address, in decimalInstruction
0addi x10, x0, 1
4slli x10, x10, 31
8addi x5, x0, 2
12sw x5, 0(x10)
16lw x6, 0(x10)
20add x7, x6, x7
24lw x6, 0(x10)
28add x7, x6, x7
32lw x6, 0(x10)
36add x7, x6, x7
40lw x8, 0(x10)
44addi x9, x5, 1
48add x11, x8, x7
52ebreak
EntryYour decision
WAITS_AT_20Does the instruction at address 20 wait one cycle?
WAITS_AT_28Does the instruction at address 28 wait one cycle?
WAITS_AT_36Does the instruction at address 36 wait one cycle?
WAITS_AT_40Does the instruction at address 40 wait one cycle?
WAITS_AT_48Does the instruction at address 48 wait one cycle?
STALLSHow many cycles are lost to stalls in the whole program?
CYCLES_WITHOUT_STALLSIn which cycle would the last instruction be in WB if nothing waited?
CYCLESIn which cycle is the last instruction in WB?
CYCLE_OF_20_IN_EXIn which cycle is the instruction at address 20 in EX?
BUBBLE_IN_MEMIn which cycle is the first bubble in MEM?
SOURCE_OF_X6After its wait, the instruction at 20 takes x6 by forwarding. Enter 1 for MEM or 2 for WB.
X12_AT_STOPWhat does x12 hold when the program stops?
LAST_WB_FOR_KThe second program has K pairs of lw x6, 0(x10) and add x7, x6, x7. Give the cycle in which its last instruction is in WB, as an expression in K.

Examples

Example 1

WAITS AT 20
Input
Does the instruction at address 20 wait one cycle?
Output
matches = 1

It reads x6, and the instruction right before it loads x6.

Example 2

WAITS AT 28
Input
Does the instruction at address 28 wait one cycle?
Output
matches = 1

The store needs x8 as its data in EX. The load right before it has x8 only after MEM.

Example 3

WAITS AT 36
Input
Does the instruction at address 36 wait one cycle?
Output
matches = 1

It comes right after a load of x9, and it reads x7. It does not need the loaded value.

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 0 through 8, inclusive.

Hints

Hint 1

Mark every load. Then look only at the instruction right behind each one.

Hint 2

That instruction waits when it reads the loaded register, as rs1, as rs2 or as the data of a store.

Hint 3

The cycle count is the number of instructions, plus 4, plus one for each wait.

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

13 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

Report a problem with this page

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

WAITS AT 20

Input
Does the instruction at address 20 wait one cycle?
Expected output
matches = 1

It reads x6, and the instruction right before it loads x6.

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

Icarus Verilog · server