A loop runs on a core that takes two instructions in a cycle, in order. Find the pairs, count the cycles, and compare two orders of the same loop.
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 a model: it takes two neighbouring instructions in a cycle, in program order. The second waits for the next cycle when it reads the register that the first writes, or when the first is a branch that is taken. Count issue cycles only: no fetch, no stalls, no branch penalty. The last entries use the five-stage rule of the lessons.
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 |
| Address, in hex | Instruction |
|---|---|
| 00 | lui x8, 0x80000 |
| 04 | addi x9, x0, 3 |
| 08 | addi x10, x0, 0 |
| 0c | lw x5, 0(x8) |
| 10 | addi x9, x9, -1 |
| 14 | add x10, x10, x5 |
| 18 | addi x8, x8, 4 |
| 1c | bne x9, x0, 0x0c |
| 20 | sw x10, 0(x8) |
| 24 | ebreak |
Enter every value in decimal. For a yes or no question, enter 1 for yes and 0 for no. Give an IPC times 100, rounded down: 1.25 is 125.
| Entry | Your decision |
|---|---|
| A_FIRST_TWO_TOGETHER | Program A: do the instructions at 00 and 04 go in the same cycle? |
| A_ADD_WITH_THE_LW | Program A: do the lw at 0c and the add at 10 go in the same cycle? |
| A_CYCLES_OF_A_ROUND | Program A: how many cycles does one round of the loop take, when its branch is taken? |
| A_CYCLES | Program A: how many cycles for all 19 instructions? |
| A_PAIRS | Program A: in how many cycles do two instructions go? |
| A_IPC_TIMES_100 | Program A: the IPC, times 100 and rounded down? |
| B_CYCLES_OF_THE_SECOND_ROUND | Program B: how many cycles does the second round of the loop take? |
| B_CYCLES | Program B: how many cycles for all 19 instructions? |
| B_IPC_TIMES_100 | Program B: the IPC, times 100 and rounded down? |
| A_ON_THE_FIVE_STAGE_CORE | Program A on the five-stage core, one instruction in a cycle: cycles until the sw is in WB? A taken branch costs 2, and an instruction right behind a load that reads its result costs 1. |
| B_ON_THE_FIVE_STAGE_CORE | Program B on the five-stage core: cycles until the sw is in WB? |
| DEEP_5 | Another program executes 100 instructions with 20 taken branches. Cycles on 5 stages with 2 lost for each? |
| DEEP_8 | The same program on 8 stages with 4 lost for each taken branch? |
| A_CYCLES_FOR_K | The instruction at 04 of program A becomes addi x9, x0, K, so the loop runs K times. Give the cycles of the two-wide core as an expression in K. |
Examples
Example 1
A FIRST TWO TOGETHER- Input
Program A: do the instructions at 00 and 04 go in the same cycle?
- Output
matches = 1
The addi at 04 reads x0 only. The lui writes x8.
Example 2
A ADD WITH THE LW- Input
Program A: do the lw at 0c and the add at 10 go in the same cycle?
- Output
matches = 1
The add reads x5, which the lw writes.
Example 3
A CYCLES OF A ROUND- Input
Program A: how many cycles does one round of the loop take, when its branch is taken?
- Output
matches = 1
The lw alone, the add with the addi of x8, the addi of x9 alone, the branch alone.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For A_CYCLES_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
Take the next instruction as the first of a cycle. Then test the one behind it.
Hint 2
Does it read what the first writes? Does the first leave the line? One yes, and it waits.
Hint 3
Every cycle has one or two instructions. IPC is instructions divided by cycles.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
14 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