S2.15.3 Pair Them Up

MediumImplement22 minIcarus Verilog · serverReview the topic

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

SignalWidthRole
question8input of each check
Full specification
The program
Program A. The loop at 0c to 1c runs three times. Do not count the ebreak.
Address, in hexInstruction
00lui x8, 0x80000
04addi x9, x0, 3
08addi x10, x0, 0
0clw x5, 0(x8)
10add x10, x10, x5
14addi x8, x8, 4
18addi x9, x9, -1
1cbne x9, x0, 0x0c
20sw x10, 0(x8)
24ebreak
The program
Program B: the same loop with the rows at 10 to 18 in another order.
Address, in hexInstruction
00lui x8, 0x80000
04addi x9, x0, 3
08addi x10, x0, 0
0clw x5, 0(x8)
10addi x9, x9, -1
14add x10, x10, x5
18addi x8, x8, 4
1cbne x9, x0, 0x0c
20sw x10, 0(x8)
24ebreak

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.

EntryYour decision
A_FIRST_TWO_TOGETHERProgram A: do the instructions at 00 and 04 go in the same cycle?
A_ADD_WITH_THE_LWProgram A: do the lw at 0c and the add at 10 go in the same cycle?
A_CYCLES_OF_A_ROUNDProgram A: how many cycles does one round of the loop take, when its branch is taken?
A_CYCLESProgram A: how many cycles for all 19 instructions?
A_PAIRSProgram A: in how many cycles do two instructions go?
A_IPC_TIMES_100Program A: the IPC, times 100 and rounded down?
B_CYCLES_OF_THE_SECOND_ROUNDProgram B: how many cycles does the second round of the loop take?
B_CYCLESProgram B: how many cycles for all 19 instructions?
B_IPC_TIMES_100Program B: the IPC, times 100 and rounded down?
A_ON_THE_FIVE_STAGE_COREProgram 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_COREProgram B on the five-stage core: cycles until the sw is in WB?
DEEP_5Another program executes 100 instructions with 20 taken branches. Cycles on 5 stages with 2 lost for each?
DEEP_8The same program on 8 stages with 4 lost for each taken branch?
A_CYCLES_FOR_KThe 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

Report a problem with this page

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

A FIRST TWO TOGETHER

Input
Program A: do the instructions at 00 and 04 go in the same cycle?
Expected output
matches = 1

The addi at 04 reads x0 only. The lui writes x8.

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

Icarus Verilog · server