A1.6.1 The Gated-Clock False Alarm

MediumFixVerilator · serverReview the topic

Fix two assertions clocked on a gated net, so they check only real clock edges where the block runs.

Hardware context: A clock-gated block with busy and done flags and a request/acknowledge pair. Clock each rule on real clock edges where the block runs, never on the gated net.

A block runs only while its clock enable en is 1. Its checker clocks two rules on the gated net gclk = clk & en, and it raises false alarms.

Rule 1: while the block is clocked, it is never busy and done at once. Rule 2: a request seen on a clocked edge gets ack on the next clocked edge, however many gated edges come between.

Fix gate_check. It must stay silent on legal traffic and catch both bugs in the last part of the program.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
en1stimulus, the same for every design
req1stimulus, the same for every design
ack1stimulus, the same for every design
busy1stimulus, the same for every design
done1stimulus, the same for every design
your errors32your checker's error count
Full specification
The ports (keep them)
module gate_check (
  input  logic clk,             // the free-running clock
  input  logic en,              // clock enable: the block is clocked when en is 1
  input  logic stall,           // a different signal: the block's output stall
  input  logic busy, done,
  input  logic req, ack,
  output int   errors
);
  // your two assertions
endmodule
PartWhat happensFailures expected
1 (10-60)a request at 15, two gated edges, then ack at 45; busy and done while gated0
2 (60-80)busy and done while gated; en pulses at 66 while clk is high0
3 (80-130)a request at 85 never answered after gating; busy and done at the clocked edge 1152

stall is a different signal of the block. It is not the clock enable.

The full check also runs a second program that this page does not show. It has another clock period, more gated edges and the bugs in another order.

Examples

Example 1

No False Alarm
Input
Parts 1 and 2: legal
Output
legal_failures = 0

Gated edges are skipped, and the pulse on en at 66 is not a clock edge.

Example 2

The Answer Still Counts After Gating
Input
Part 3: a request at 85, gated at 95
Output
lost_answer_failures = 1

The request from 85 waits through the gated edge at 95. At 105 ack is 0, so it fails there.

Example 3

Busy with Done on a Clocked Edge
Input
Part 3: busy and done at 115
Output
busy_done_failures = 1

At 115 the block is clocked and both flags are 1: one more failure.

Constraints and Contract

  • Keep the ports and the two rules.
  • Count each failure in errors.

Hints

Hint 1

At 66 en rises while clk is high. What does the gated net do then?

Hint 2

An event control can carry a condition: an edge counts only when the condition holds.

Hint 3

Should a request made before gating be forgotten when the clock stops? Compare skipping edges with cancelling attempts.

What the grader checks: Two copies of your checker each watch a fixed program: the one shown here and a hidden one with other timing. Graded on each: failures on legal traffic, and failures on each planted bug.

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

No False Alarm

Input
Parts 1 and 2: legal
Expected output
legal_failures = 0

Gated edges are skipped, and the pulse on en at 66 is not a clock edge.

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

Verilator · server