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
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Address, in decimal | Instruction |
|---|---|
| 0 | addi x10, x0, 1 |
| 4 | slli x10, x10, 31 |
| 8 | addi x5, x0, 2 |
| 12 | sw x5, 0(x10) |
| 16 | lw x6, 0(x10) |
| 20 | add x7, x6, x6 |
| 24 | lw x8, 0(x10) |
| 28 | sw x8, 4(x10) |
| 32 | lw x9, 4(x10) |
| 36 | addi x11, x7, 1 |
| 40 | add x12, x9, x11 |
| 44 | lw x13, 0(x10) |
| 48 | add x14, x5, x13 |
| 52 | ebreak |
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.
| Address, in decimal | Instruction |
|---|---|
| 0 | addi x10, x0, 1 |
| 4 | slli x10, x10, 31 |
| 8 | addi x5, x0, 2 |
| 12 | sw x5, 0(x10) |
| 16 | lw x6, 0(x10) |
| 20 | add x7, x6, x7 |
| 24 | lw x6, 0(x10) |
| 28 | add x7, x6, x7 |
| 32 | lw x6, 0(x10) |
| 36 | add x7, x6, x7 |
| 40 | lw x8, 0(x10) |
| 44 | addi x9, x5, 1 |
| 48 | add x11, x8, x7 |
| 52 | ebreak |
| Entry | Your decision |
|---|---|
| WAITS_AT_20 | Does the instruction at address 20 wait one cycle? |
| WAITS_AT_28 | Does the instruction at address 28 wait one cycle? |
| WAITS_AT_36 | Does the instruction at address 36 wait one cycle? |
| WAITS_AT_40 | Does the instruction at address 40 wait one cycle? |
| WAITS_AT_48 | Does the instruction at address 48 wait one cycle? |
| STALLS | How many cycles are lost to stalls in the whole program? |
| CYCLES_WITHOUT_STALLS | In which cycle would the last instruction be in WB if nothing waited? |
| CYCLES | In which cycle is the last instruction in WB? |
| CYCLE_OF_20_IN_EX | In which cycle is the instruction at address 20 in EX? |
| BUBBLE_IN_MEM | In which cycle is the first bubble in MEM? |
| SOURCE_OF_X6 | After its wait, the instruction at 20 takes x6 by forwarding. Enter 1 for MEM or 2 for WB. |
| X12_AT_STOP | What does x12 hold when the program stops? |
| LAST_WB_FOR_K | The 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