Three loops run on two pipelines. One decides a branch in EX, the other in ID. Count the cycles of each, and say which design wins.
Hardware context: The lab pipeline with the branch compare and the target adder in ID, beside the same pipeline with the decision in EX as in the real core. Choosing the stage that resolves branches and judging its effect on cycles and on the clock period
Each program below starts at address 0, and its first instruction is in IF in cycle 1. Design 1 decides a branch in EX, like ap_rv32: a taken branch loses 2 cycles, and nothing waits. Design 2 decides in ID: a taken branch loses 1 cycle. Design 2 forwards nothing into ID. So a branch waits there while an instruction that writes one of its registers is in EX or in MEM.
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 | addi x5, x0, 3 |
| 04 | addi x6, x0, 0 |
| 08 | add x6, x6, x5 |
| 0c | addi x5, x5, -1 |
| 10 | bne x5, x0, 0x08 |
| 14 | addi x7, x6, 1 |
| 18 | ebreak |
| Address, in hex | Instruction |
|---|---|
| 00 | addi x5, x0, 3 |
| 04 | addi x6, x0, 0 |
| 08 | addi x5, x5, -1 |
| 0c | add x6, x6, x5 |
| 10 | addi x8, x6, 0 |
| 14 | bne x5, x0, 0x08 |
| 18 | addi x7, x6, 1 |
| 1c | ebreak |
| Address, in hex | Instruction |
|---|---|
| 00 | addi x5, x0, 3 |
| 04 | addi x6, x0, 0 |
| 08 | addi x5, x5, -1 |
| 0c | addi x6, x6, 3 |
| 10 | bne x5, x0, 0x08 |
| 14 | ebreak |
Each loop runs three times. Enter every value in decimal. Give a cycle count as the cycle in which the last instruction before the ebreak is in WB.
| Entry | Your decision |
|---|---|
| A_CYCLES_DESIGN_1 | Program A on design 1: how many cycles? |
| A_WAITS_DESIGN_2 | Program A on design 2: how many cycles does the branch wait in all? |
| A_CYCLES_DESIGN_2 | Program A on design 2: how many cycles? |
| B_CYCLES_DESIGN_1 | Program B on design 1: how many cycles? |
| B_WAITS_DESIGN_2 | Program B on design 2: how many cycles does the branch wait in all? |
| B_CYCLES_DESIGN_2 | Program B on design 2: how many cycles? |
| C_CYCLES_DESIGN_1 | Program C on design 1: how many cycles? |
| C_WAITS_DESIGN_2 | Program C on design 2: how many cycles does the branch wait in all? |
| C_CYCLES_DESIGN_2 | Program C on design 2: how many cycles? |
| FASTER_FOR_A | Which design runs program A in fewer cycles? Enter 1 or 2. |
| FASTER_FOR_B | Which design runs program B in fewer cycles? Enter 1 or 2. |
| FASTER_FOR_C | Which design runs program C in fewer cycles? Enter 1 or 2. |
| A_CYCLES_DESIGN_2_FOR_K | The first instruction of program A becomes addi x5, x0, K, so its loop runs K times. Give its cycle count on design 2 as an expression in K. |
Examples
Example 1
A CYCLES DESIGN 1- Input
Program A on design 1: how many cycles?
- Output
matches = 1
Twelve instructions are executed and two branches are taken: 12 plus 4 plus 4.
Example 2
A WAITS DESIGN 2- Input
Program A on design 2: how many cycles does the branch wait in all?
- Output
matches = 1
The writer of x5 is right before the branch. The branch waits 2 cycles in each of the 3 rounds, also in the last.
Example 3
A CYCLES DESIGN 2- Input
Program A on design 2: how many cycles?
- Output
matches = 1
12 plus 4, plus 6 of waiting, plus 1 for each of the 2 taken branches.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For A_CYCLES_DESIGN_2_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
First count the instructions that are executed, round by round. Add 4 for the pipeline.
Hint 2
Add 2 for each taken branch. Nothing else is lost.
Hint 3
Add 1 for each taken branch. Then look at what is right before the branch: add the cycles it waits, in every round.
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 1 problem on this path