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
| Signal | Width | Role |
|---|---|---|
clk | 1 | stimulus, the same for every design |
count | 2 | stimulus, the same for every design |
full | 1 | stimulus, the same for every design |
busy | 1 | stimulus, the same for every design |
irq | 1 | stimulus, the same for every design |
masked | 1 | stimulus, the same for every design |
your full_errors | 32 | stimulus, the same for every design |
your mask_errors | 32 | stimulus, the same for every design |
Full specification
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, ...):
| Edge | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| count | 0 | 1 | 2 | 2 | 1 | 0 | 1 | 2 | 1 | 0 |
| full | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 0 | 0 |
| busy | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 0 |
| irq | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 1 | 0 | 0 |
| masked | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
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