G6.1.2 The Pipeline That Collapsed

EasyFixIcarus Verilog + Yosys · serverReview the topic

Repair a three-stage echo pipeline whose clocked block uses blocking assignments, so each stage reads the values from before the edge.

Hardware context: A peripheral's 16-bit control register written a byte at a time, and a three-stage audio echo pipeline. Repair a pipeline whose blocking assignments collapsed its stages.

An audio block delays each sample by three clock edges and adds an echo. Stage 2 adds half of the oldest sample, held in stage 3. In simulation the first sample comes out after one edge, not three, and the echo values are wrong.

This is a Fix problem. The starter is the shipped code. Make echo3 behave as the table says. Every stage must use the values the stages held just before the edge.

Signals in the Timeline

SignalWidthRole
script72input of each check
Full specification
The module (keep the name and the ports)
module echo3 (
  input  logic       clk,
  input  logic       rst,     // synchronous reset: every stage to 0
  input  logic       en,      // 1: the pipeline moves at the rising edge; 0: every stage holds
  input  logic [7:0] din,
  output logic [7:0] dout     // the last stage, s3
);
  ...
endmodule
At a rising edgeStage update (from the values before the edge)
rst = 1s1, s2 and s3 become 0
otherwise, en = 1s1 takes din; s2 takes s1 + (s3 >> 1), 8 bits; s3 takes s2
otherwiseevery stage holds

dout is s3. Each case starts with a reset edge and then runs eight edges. The result shows dout after each edge.

Examples

Example 1

One Sample, Then Zeros
Input
din at each edge (hold = en 0): 40 00 00 00 00 00 00 00
Output
dout_after_edge1 = 0x0, dout_after_edge2 = 0x0, dout_after_edge3 = 0x40, dout_after_edge4 = 0x0, dout_after_edge5 = 0x20, dout_after_edge6 = 0x0, dout_after_edge7 = 0x10, dout_after_edge8 = 0x0

40 enters stage 1 at edge 1 and reaches dout at edge 3. Two edges later, half of it (20) is added back into stage 2, so 20 appears at edge 5.

Example 2

A Steady Input
Input
din at each edge (hold = en 0): 10 10 10 10 10 10 10 10
Output
dout_after_edge1 = 0x0, dout_after_edge2 = 0x0, dout_after_edge3 = 0x10, dout_after_edge4 = 0x10, dout_after_edge5 = 0x18, dout_after_edge6 = 0x18, dout_after_edge7 = 0x1c, dout_after_edge8 = 0x1c

A steady 10 shows at edge 3. From then on stage 2 also adds half of what stage 3 holds, so the output climbs.

Example 3

A Stall in the Middle
Input
din at each edge (hold = en 0): 80 20 hold hold 00 00 00 00
Output
dout_after_edge1 = 0x0, dout_after_edge2 = 0x0, dout_after_edge3 = 0x0, dout_after_edge4 = 0x0, dout_after_edge5 = 0x80, dout_after_edge6 = 0x20, dout_after_edge7 = 0x40, dout_after_edge8 = 0x10

With en = 0 for two edges, every stage holds and dout repeats. Then the pipeline moves on from where it stopped.

Constraints and Contract

  • All inputs are known 0/1 values and change only between edges.
  • Keep the module name and the ports. The design must synthesize with no latches.

Hints

Hint 1

Run the first example. With blocking assignments, after one edge s3 already holds the new sample. Which line read a value that changed earlier in the same block?

Hint 2

Try reordering the three lines. s2 reads s3, and s3 reads s2. Can any order give both the old value?

Hint 3

A nonblocking assignment reads every right-hand side before any left-hand side changes.

What the grader checks: Three directed and ten seeded scripts of eight edges, with stalls. dout is compared with a JavaScript model of the three stages after every edge. Synthesis must report no latches.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

13 checks on Icarus Verilog + Yosys · server. 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 steps and the final capstone

Report a problem with this page

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

One Sample, Then Zeros

Input
din at each edge (hold = en 0): 40 00 00 00 00 00 00 00
Expected output
dout_after_edge1 = 0x0, dout_after_edge2 = 0x0, dout_after_edge3 = 0x40, dout_after_edge4 = 0x0, dout_after_edge5 = 0x20, dout_after_edge6 = 0x0, dout_after_edge7 = 0x10, dout_after_edge8 = 0x0

40 enters stage 1 at edge 1 and reaches dout at edge 3. Two edges later, half of it (20) is added back into stage 2, so 20 appears at edge 5.

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

Icarus Verilog + Yosys · server