A two-stage pipeline lets bytes out one clock too early. Find the first bad cycle and signal, name the cause, and fix the pipeline.
Hardware context: Registers updated by always blocks at one clock edge, a register with no reset and a flag nobody set. Reading a waveform around a clock edge.
pipe2 should delay every byte by two enabled clocks. The bench sends bytes 1 to 8 and pauses en for two clocks. Every clock it compares dout with its own model of the two stages.
Run the failing test below and read its log and its waveform. The waveform also shows the two stages inside the design.
Step 1: find the first cycle where dout, s1 or s2 is not what the specification says, and name the signal. Step 2: choose the cause. Step 3, optional: fix pipe2; the fix is graded by the normal rows.
A fix must give the same result in every order the standard allows. The rows run on one simulator, so its order is part of what they see. The note under the specification says how.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
scenario | 8 | input of each check |
Full specification
// pipe2: a two-stage pipeline. While en is 1, s1 takes din and s2 takes s1 at each rising edge; while en is 0,
// both hold. dout is s2, so a byte comes out two enabled clocks after it went in. Reset clears both stages.
module pipe2 (input logic clk, rst, en, input logic [7:0] din, output logic [7:0] dout);
...
endmodule
Cycle N is the stretch after the N-th rising edge, counted from the first clock after reset. When two always blocks wake at the same edge, the standard allows either order. The site's Icarus 12 does not even keep one order. Measured on this pipeline, it swaps the two blocks from one edge to the next. So a fix that still depends on the order fails the rows, whichever way round the blocks are written.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
Ten Bytes, En Always High- Input
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
- Output
dout1 = 0, dout2 = 10, dout3 = 11, dout4 = 12, dout5 = 13, dout6 = 14, dout7 = 15, dout8 = 16, dout9 = 17, dout10 = 18
Byte 10 goes in at clock 1 and comes out after clock 2: dout reads 0, 10, 11 and so on.
Example 2
En Low for One Clock in the Middle- Input
20, 21, 22, 23, en=0 24, 25, 26, 27, 28, 29
- Output
dout1 = 0, dout2 = 20, dout3 = 21, dout4 = 22, dout5 = 22, dout6 = 23, dout7 = 25, dout8 = 26, dout9 = 27, dout10 = 28
While en is low both stages hold, so the byte in s2 is shown for one more clock.
Example 3
En High Every Other Clock- Input
en=0 30, 31, en=0 32, 33, en=0 34, 35, en=0 36, 37, en=0 38, 39
- Output
dout1 = 0, dout2 = 0, dout3 = 0, dout4 = 31, dout5 = 31, dout6 = 33, dout7 = 33, dout8 = 35, dout9 = 35, dout10 = 37
Only enabled clocks move the bytes, so each byte takes four clocks to come out.
Constraints and Contract
- Keep the module name, the ports and the names s1 and s2.
- Reset is synchronous and active high.
Hints
Hint 1
Compare s2 with s1 in the same cycle: should they ever be equal while bytes flow?
Hint 2
Each cause shows first in a different cycle or on a different signal.
Hint 3
Think about what each always block reads, and when the other one writes it.
What the grader checks: The failing run is simulated live with the shipped pipeline. The fix is graded on five scripts of en and din, each after two clocks of reset. Each row compares dout in the middle of ten clocks with the specification. Rows run on Icarus 12 only. Its order of the two blocks changes from edge to edge, so the rows see both orders. Another simulator could pick yet another order.
5 checks on Icarus · browser samples / server checks. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 problems on this path