A3.6.2 Both Ways

MediumImplementVerilator · serverReview the topic

Check a full flag in both directions with iff, and an interrupt mask with a Boolean implies.

Hardware context: A 2-entry buffer with a full flag and an interrupt mask. Check a flag in both directions with iff and a guarded condition with implies.

A 2-entry buffer reports count and a full flag. Rule full_flag: full is 1 exactly when count is 2. Write it with iff, so it fails in both directions.

Rule mask_rule: whenever busy and irq are both 1, masked is 1. Write it with implies. Both rules are concurrent assertions on the rising edge of clk.

Signals in the Timeline

SignalWidthRole
clk1stimulus, the same for every design
count2stimulus, the same for every design
full1stimulus, the same for every design
busy1stimulus, the same for every design
irq1stimulus, the same for every design
masked1stimulus, the same for every design
your full_errors32stimulus, the same for every design
your mask_errors32stimulus, the same for every design
Full specification
The ports (keep them)
module flag_rules (
  input  logic       clk,
  input  logic [1:0] count,          // items in a 2-entry buffer
  input  logic       full,           // the buffer's full flag
  input  logic       busy, irq, masked,
  output int         full_errors,    // rule full_flag
  output int         mask_errors     // rule mask_rule
);
  // full_flag: full is 1 exactly when count is 2 (use iff).
  // mask_rule: when busy and irq are both 1, masked is 1 (use implies).
endmodule

The program shown here gives the sampled value of each signal at each rising edge (at 5, 15, 25, ...):

Edge12345678910
count0122101210
full0001100100
busy0110100100
irq0100101100
masked0100000000

The full check also runs a second program that this page does not show, with another clock and other flags.

Examples

Example 1

Late Flag, Early Flag
Input
Program: 10 edges
Output
full_errors = 2

At edge 3 the buffer is full but the flag is low. At edge 5 the flag is still high after an item left.

Example 2

Unmasked Interrupts While Busy
Input
Program: 10 edges
Output
mask_errors = 2

busy and irq are both 1 at edges 2, 5 and 8. Only edge 2 has masked.

Example 3

Four Failures in All
Input
Program: 10 edges
Output
total = 4

Two from each rule.

Constraints and Contract

  • Use iff for full_flag and implies for mask_rule.
  • Count failures in full_errors and mask_errors.
  • Do not change the ports.

Hints

Hint 1

A one-way implication misses a flag that is set too early.

Hint 2

Which side of implies is the condition, and which is the obligation?

Hint 3

Both rules are Booleans of one edge, so implies behaves like "if then" at that edge.

What the grader checks: Two copies of your rules each watch a fixed program. One is shown here; the other is hidden, with another clock. Graded on each: the two failure counts. The source must use iff and implies.

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 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

Late Flag, Early Flag

Input
Program: 10 edges
Expected output
full_errors = 2

At edge 3 the buffer is full but the flag is low. At edge 5 the flag is still high after an item left.

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

Verilator · server