A1.4.1 The Token Check That Fails Mid-Step

MediumFixVerilator · serverReview the topic

Fix an immediate one-hot check that fails on legal handoffs, so it reports only the real bugs and the values it checked.

Hardware context: Two agents that pass a token, each with a one-bit ownership flag. Check the flag pair where it has settled, at the clock edge, and record what the check read.

Two agents pass a token. Agent A owns it while flag a is 1, and agent B while b is 1. Exactly one flag must be 1 at every rising edge of clk.

A handoff writes the two flags in two steps of one time step, between clock edges. For a moment both flags are 0, and no register ever sees that moment.

The checker token_check fails in every regression, even on runs with legal handoffs only. Fix it. It must report each real bug once per rising edge, and record what it checked at the first failure.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
a1stimulus, the same for every design
b1stimulus, the same for every design
your errors32your checker's error count
Full specification
The ports (keep them)
module token_check (
  input  logic       clk,
  input  logic       a, b,          // the token flags of the two agents
  output int         errors,        // failures so far
  output logic [1:0] first_bad,     // {a, b} as checked at the first failure
  output int         first_time     // $time of the first failure
);
  // your check
endmodule
OutputMeaning
errorsone count per failed check
first_badthe {a, b} pair that the first failing check read
first_timethe $time of the first failure

The program shown here has two legal handoffs (at 12 and 22) and two bugs. Both flags are 1 across the edge at 35, and both are 0 across the edge at 45. In the first bug the flags are registers that change right after the edges at 25 and 35.

The full check also runs a second program that this page does not show. It has another clock period, other handoff times and other bugs.

Examples

Example 1

Only the Two Bugs Fail
Input
Program: 2 legal handoffs, 2 bugs
Output
errors = 2

The legal handoffs at 12 and 22 must not count. The bugs are seen at the edges at 35 and 45.

Example 2

The First Failure Is at 35
Input
Program: 2 legal handoffs, 2 bugs
Output
first_time = 35

The flags change to 11 just after the edge at 25, so the first edge that reads 11 is 35.

Example 3

Record the Pair That Was Checked
Input
Program: 2 legal handoffs, 2 bugs
Output
first_bad = 3

first_bad must be 11 (3): the value the check read, not the value after the edge.

Constraints and Contract

  • Check the pair with an immediate assertion. Label it token_one_hot.
  • Count each failure in errors and record first_bad and first_time at the first one.
  • Do not change the ports.

Hints

Hint 1

How many times does always @(a or b) run during one handoff written as a = 0; #0 b = 1;?

Hint 2

Registers capture at the rising edge of clk. Check the pair there, where the flags have settled.

Hint 3

An immediate assertion at a rising edge reads the flags before the registers update at that edge. Record the pair only at the first failure.

What the grader checks: Two copies of your checker each watch a fixed 60 ns program. One program is shown here. The other is hidden, with other timing and bugs. Graded on each: the number of failures, and the time and value of the first one. The source must hold an immediate assertion on a and b.

6 checks on Verilator · 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 3 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

Only the Two Bugs Fail

Input
Program: 2 legal handoffs, 2 bugs
Expected output
errors = 2

The legal handoffs at 12 and 22 must not count. The bugs are seen at the edges at 35 and 45.

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

Verilator · server