R11.5.1 The Pragma That Lied

MediumDebugIcarus Verilog + Yosys · serverReview the topic

A packet decoder passed its block tests and failed in gate-level simulation. Find the first bad cycle in the RTL, name the construct that caused it, and fix it.

Hardware context: A packet-kind decoder that lists five of eight kinds behind a full_case attribute; and an ALU control decoder with nine of sixteen opcodes and an enable. Find the first bad cycle of the packet decoder, name the construct that caused it, and fix it.

A receiver decodes the kind field of a packet header into a payload length and a CRC flag. Only kinds 0, 1, 2, 4 and 6 exist. The brief says any other kind gives len 0, has_crc 0 and err 1, so the receiver can drop the packet. The block tests sent the five real kinds and passed.

The first gate-level simulation of the chip failed. A corrupted header carried kind 3, and the netlist answered len=1 has_crc=1 err=0. The receiver took one byte of noise as a payload. That run is a recording, made from the netlist that this site's synthesizer wrote for the shipped file.

The team then ran the same headers on the RTL. That run fails too, with different values. Run it below. Step 1: find the first cycle where an output differs from the brief, and name the signals. Step 2: choose the cause from five real bugs. Each one first goes wrong in a different place.

Step 3 is optional: fix the decoder and run the tests.

Signals in the Timeline

SignalWidthRole
script24input of each check
Full specification
The decoder's ports (keep the name and the ports)
module pkt_dec (
  input  logic [2:0] kind,
  output logic [3:0] len,          // payload length in bytes
  output logic       has_crc,
  output logic       err           // 1: this kind does not exist
);
  ...
endmodule
kindlenhas_crcerr
0100
1200
2410
4810
61210
3, 5, 7001
CyclekindRTL run (live, below)Gate-level run (recorded)
51len=2 has_crc=0 err=0len=2 has_crc=0 err=0
63see the waveformlen=1 has_crc=1 err=0
72len=4 has_crc=1 err=0len=4 has_crc=1 err=0
87see the waveformlen=1 has_crc=1 err=0
95see the waveformlen=1 has_crc=1 err=0

Cycle N is the stretch where the cycle counter shows N. The bench sets kind at the start of a cycle and the receiver reads the outputs before it ends. A signal is wrong in cycle N if its value there differs from the brief.

The fix tests apply eight kinds, one per nanosecond, and record len, has_crc and err after each. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.

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 1 · The first bad cycle and signal
Step 2 · The cause

Step 3 is optional: fix the code in the editor, then run the tests.

Examples

Example 1

Every Listed Kind
Input
kind = 0, 1, 2, 4, 6, 4, 2, 0
Output
len_step0 = 1, crc_step0 = no, err_step0 = no, len_step1 = 2, crc_step1 = no, err_step1 = no, len_step2 = 4, crc_step2 = yes, err_step2 = no, len_step3 = 8, crc_step3 = yes, err_step3 = no, len_step4 = 12, crc_step4 = yes, err_step4 = no, len_step5 = 8, crc_step5 = yes, err_step5 = no, len_step6 = 4, crc_step6 = yes, err_step6 = no, len_step7 = 1, crc_step7 = no, err_step7 = no

The five real kinds give their lengths and CRC flags, and err stays 0.

Example 2

An Unlisted Kind After Each Listed One
Input
kind = 2, 3, 4, 5, 6, 7, 1, 3
Output
len_step0 = 4, crc_step0 = yes, err_step0 = no, len_step1 = 0, crc_step1 = no, err_step1 = yes, len_step2 = 8, crc_step2 = yes, err_step2 = no, len_step3 = 0, crc_step3 = no, err_step3 = yes, len_step4 = 12, crc_step4 = yes, err_step4 = no, len_step5 = 0, crc_step5 = no, err_step5 = yes, len_step6 = 2, crc_step6 = no, err_step6 = no, len_step7 = 0, crc_step7 = no, err_step7 = yes

Kinds 3, 5 and 7 each follow a real kind. Each must give len 0, has_crc 0 and err 1, whatever came before.

Example 3

Unlisted Kinds First
Input
kind = 7, 5, 3, 0, 5, 6, 7, 2
Output
len_step0 = 0, crc_step0 = no, err_step0 = yes, len_step1 = 0, crc_step1 = no, err_step1 = yes, len_step2 = 0, crc_step2 = no, err_step2 = yes, len_step3 = 1, crc_step3 = no, err_step3 = no, len_step4 = 0, crc_step4 = no, err_step4 = yes, len_step5 = 12, crc_step5 = yes, err_step5 = no, len_step6 = 0, crc_step6 = no, err_step6 = yes, len_step7 = 4, crc_step7 = yes, err_step7 = no

The script starts with kinds 7, 5 and 3. A decoder that holds its outputs has nothing sensible to hold yet.

Constraints and Contract

  • kind is a known 0/1 value.
  • Keep the module name and the ports.

Hints

Hint 1

Work out the three outputs for each cycle from the table, and compare them with the waveform. Start where the log points.

Hint 2

In the first bad cycle, look at which outputs are wrong and what they show. Compare them with the cycle before.

Hint 3

The RTL and the gates are both wrong in that cycle, in different ways. Ask what line of the source the simulator ignores and the synthesizer reads.

What the grader checks: The failing RTL run is simulated live with the shipped decoder. The bench simulates the correct decoder and each buggy one on the same twelve headers. The first bad cycle and every option's first wrong value come from those runs. The gate-level column is a recording. The optional fix is compared with an independent model on six directed and ten seeded scripts of eight kinds.

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.

16 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

Every Listed Kind

Input
kind = 0, 1, 2, 4, 6, 4, 2, 0
Expected output
len_step0 = 1, crc_step0 = no, err_step0 = no, len_step1 = 2, crc_step1 = no, err_step1 = no, len_step2 = 4, crc_step2 = yes, err_step2 = no, len_step3 = 8, crc_step3 = yes, err_step3 = no, len_step4 = 12, crc_step4 = yes, err_step4 = no, len_step5 = 8, crc_step5 = yes, err_step5 = no, len_step6 = 4, crc_step6 = yes, err_step6 = no, len_step7 = 1, crc_step7 = no, err_step7 = no

The five real kinds give their lengths and CRC flags, and err stays 0.

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

Icarus Verilog + Yosys · server