S2.26.1 Early or Late

MediumImplement22 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
The program
Program A. The branch at 10 is right behind the instruction that writes x5.
Address, in hexInstruction
00addi x5, x0, 3
04addi x6, x0, 0
08add x6, x6, x5
0caddi x5, x5, -1
10bne x5, x0, 0x08
14addi x7, x6, 1
18ebreak
The program
Program B. Two instructions stand between the write of x5 and the branch at 14.
Address, in hexInstruction
00addi x5, x0, 3
04addi x6, x0, 0
08addi x5, x5, -1
0cadd x6, x6, x5
10addi x8, x6, 0
14bne x5, x0, 0x08
18addi x7, x6, 1
1cebreak
The program
Program C. One instruction stands between the write of x5 and the branch at 10.
Address, in hexInstruction
00addi x5, x0, 3
04addi x6, x0, 0
08addi x5, x5, -1
0caddi x6, x6, 3
10bne x5, x0, 0x08
14ebreak

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.

EntryYour decision
A_CYCLES_DESIGN_1Program A on design 1: how many cycles?
A_WAITS_DESIGN_2Program A on design 2: how many cycles does the branch wait in all?
A_CYCLES_DESIGN_2Program A on design 2: how many cycles?
B_CYCLES_DESIGN_1Program B on design 1: how many cycles?
B_WAITS_DESIGN_2Program B on design 2: how many cycles does the branch wait in all?
B_CYCLES_DESIGN_2Program B on design 2: how many cycles?
C_CYCLES_DESIGN_1Program C on design 1: how many cycles?
C_WAITS_DESIGN_2Program C on design 2: how many cycles does the branch wait in all?
C_CYCLES_DESIGN_2Program C on design 2: how many cycles?
FASTER_FOR_AWhich design runs program A in fewer cycles? Enter 1 or 2.
FASTER_FOR_BWhich design runs program B in fewer cycles? Enter 1 or 2.
FASTER_FOR_CWhich design runs program C in fewer cycles? Enter 1 or 2.
A_CYCLES_DESIGN_2_FOR_KThe 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

Report a problem with this page

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

A CYCLES DESIGN 1

Input
Program A on design 1: how many cycles?
Expected output
matches = 1

Twelve instructions are executed and two branches are taken: 12 plus 4 plus 4.

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

Icarus Verilog · server