R7.4.1 Translate the Block

EasyFixIcarus Verilog + Yosys · serverReview the topic

Translate a Verilog-2001 header checker to SystemVerilog. The tests compile it with implicit nets turned off.

Hardware context: A Verilog-2001 header checker with a misspelled net and a short sensitivity list; and a bank of four tick dividers whose rates come from defparam statements. Translate the header checker so that it compiles with implicit nets off and follows its brief.

A packet filter compares each header byte with a key and counts the matches. The block is Verilog-2001 and nobody has touched it for years. It is your turn to move it to SystemVerilog, and the project now compiles every file with implicit nets turned off.

This is a Fix problem. The block as found turns implicit nets back on in its second line. Delete that line first. The block then stops compiling, and it has a second defect that a translation brings to light. Translate it, and make it do what the brief says.

The tests put the directive default_nettype none in front of your file. Unless your file switches it back, an undeclared name is a compile error. Then they change the inputs one at a time, read match before each clock edge and read hits after it.

Brief: match is combinational: 1 when en is 1 and hdr equals key. hits counts the rising edges at which match is 1, and wraps at 15. rst_n is asynchronous and active-low and clears hits. Synthesis check: the file must build on the site's synthesis flow, with hdr_chk as the top, and with no latch.

Signals in the Timeline

SignalWidthRole
script170input of each check
Full specification
The ports after translation (keep the name, the port names and the widths)
module hdr_chk (
  input  logic       clk,
  input  logic       rst_n,      // asynchronous, active-low
  input  logic       en,         // 1: compare
  input  logic [7:0] hdr,
  input  logic [7:0] key,
  output logic       match,      // en is 1 and hdr equals key (combinational)
  output logic [3:0] hits        // edges at which match was 1; wraps at 15
);
  ...
endmodule
OutputValue
matchen && (hdr == key), at all times, with no clock
hitsgoes up by 1 at each rising edge where match is 1; 0 after reset; wraps from 15 to 0

Each test resets the block, then runs 10 steps. A step sets en, hdr and key, waits 1 ns, reads match, gives one rising edge and reads hits.

What is graded: your file compiles after default_nettype none, Lint reports no IMPLICIT net, the outputs match a model, and synthesis finds no latch. Other Lint messages are not graded.

Examples

Example 1

Equal Bytes; En Changes Alone
Input
en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a, en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a
Output
match_step0 = no, hits_step0 = 0, match_step1 = yes, hits_step1 = 1, match_step2 = yes, hits_step2 = 2, match_step3 = no, hits_step3 = 2, match_step4 = yes, hits_step4 = 3, match_step5 = no, hits_step5 = 3, match_step6 = no, hits_step6 = 3, match_step7 = yes, hits_step7 = 4, match_step8 = yes, hits_step8 = 5, match_step9 = no, hits_step9 = 5

hdr and key never change after step 0. match must follow en at every step, and hits counts the five steps where en is 1.

Example 2

Bytes That Differ in One Upper Bit
Input
en=1 hdr=80 key=00, en=1 hdr=81 key=01, en=1 hdr=10 key=10, en=1 hdr=12 key=02, en=1 hdr=ff key=7f, en=1 hdr=7f key=7f, en=1 hdr=40 key=00, en=1 hdr=00 key=00, en=1 hdr=20 key=00, en=1 hdr=04 key=00
Output
match_step0 = no, hits_step0 = 0, match_step1 = no, hits_step1 = 0, match_step2 = yes, hits_step2 = 1, match_step3 = no, hits_step3 = 1, match_step4 = no, hits_step4 = 1, match_step5 = yes, hits_step5 = 2, match_step6 = no, hits_step6 = 2, match_step7 = yes, hits_step7 = 3, match_step8 = no, hits_step8 = 3, match_step9 = no, hits_step9 = 3

Most pairs differ only in a bit above bit 0. A compare that looks at one bit of the difference calls them equal.

Example 3

The Header Changes While En Is 0
Input
en=0 hdr=11 key=22, en=0 hdr=22 key=22, en=0 hdr=33 key=22, en=1 hdr=33 key=22, en=1 hdr=33 key=33, en=0 hdr=44 key=33, en=0 hdr=33 key=33, en=1 hdr=33 key=33, en=1 hdr=34 key=33, en=1 hdr=33 key=33
Output
match_step0 = no, hits_step0 = 0, match_step1 = no, hits_step1 = 0, match_step2 = no, hits_step2 = 0, match_step3 = no, hits_step3 = 0, match_step4 = yes, hits_step4 = 1, match_step5 = no, hits_step5 = 1, match_step6 = no, hits_step6 = 1, match_step7 = yes, hits_step7 = 2, match_step8 = no, hits_step8 = 2, match_step9 = yes, hits_step9 = 3

match stays 0 while en is 0, whatever the bytes are. It rises at step 4, where en is 1 and the bytes are equal.

Constraints and Contract

  • Inputs are known 0/1 values.
  • Keep the module name, the port names and the widths. The port list may be old style or new.

Hints

Hint 1

Delete the directive in line 2 and run the tests. The error names a net that is not defined: compare it, letter by letter, with the declarations above it.

Hint 2

List every signal the combinational block reads. Then compare your list with the one in its event control.

Hint 3

always_comb needs no list, and the two always blocks map one to one onto always_comb and always_ff.

What the grader checks: Six directed and ten seeded scripts of ten steps each change one input at a time. match before each edge and hits after it are compared with an independent model. The file is compiled after the directive default_nettype none, so an implicit net fails the build unless the file turns implicit nets back on. Lint then fails any IMPLICIT message, so switching implicit nets back on does not hide one.

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

Equal Bytes; En Changes Alone

Input
en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a, en=0 hdr=5a key=5a, en=1 hdr=5a key=5a, en=1 hdr=5a key=5a, en=0 hdr=5a key=5a
Expected output
match_step0 = no, hits_step0 = 0, match_step1 = yes, hits_step1 = 1, match_step2 = yes, hits_step2 = 2, match_step3 = no, hits_step3 = 2, match_step4 = yes, hits_step4 = 3, match_step5 = no, hits_step5 = 3, match_step6 = no, hits_step6 = 3, match_step7 = yes, hits_step7 = 4, match_step8 = yes, hits_step8 = 5, match_step9 = no, hits_step9 = 5

hdr and key never change after step 0. match must follow en at every step, and hits counts the five steps where en is 1.

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

Icarus Verilog + Yosys · server