A9.2.1 Restrict in Simulation and Formal

EasyDebugIcarus · browser samples / server checksReview the topic

One rule written as restrict and as assume, run in simulation and in formal. Say what each engine does with it.

Hardware context: An arbiter whose formal run is restricted to single requests. Know which engine checks a restriction and which one only obeys it.

The rule "never both requests" appears as a restrict and as an assume. A simulation breaks it. Three formal runs use the restriction, one of them on an arbiter with a bug.

Write answer(q). Questions 3 and 4 ask about the simulation. Questions 5 to 7 ask for formal results: 1 for PASS or cover reached, 0 for FAIL or unreached.

Questions 0 to 2 are worked examples with assume. Questions 3 to 7 are graded only by the full check.

Signals in the Timeline

SignalWidthRole
question4input of each check
Full specification
The simulation, questions 3 and 4
module tb;
  logic clk = 0;
  always #5 clk = ~clk;                         // rising edges at 5, 15, ..., 65
  logic req0 = 0, req1 = 0;
  int a_fails = 0, a_first = 0;
  only_one_r: restrict property (@(posedge clk) !(req0 && req1));
  only_one_a: assume   property (@(posedge clk) !(req0 && req1))
    else begin a_fails++; if (a_first == 0) a_first = $time; end
  initial begin
    #12 req0 = 1;                               // t=12
    #5  req1 = 1;                               // t=17
    #15 req1 = 0;                               // t=32
    #10 req1 = 1;                               // t=42
    #20 req0 = 0;                               // t=62
    #6  $display("a_fails=%0d a_first=%0d", a_fails, a_first);
    $finish;
  end
endmodule
The arbiter with the restriction, questions 5 and 6 (question 7 adds a phantom grant on the third grant to port 0)
module top(input clk, input req0, input req1, output reg gnt0 = 0, output reg gnt1 = 0);
  always @(posedge clk) begin
    gnt0 <= req0;
    gnt1 <= req1;
  end
`ifdef FORMAL
  always @(posedge clk) restrict(!(req0 && req1));   // formal only
`endif
endmodule

Simulator note: The formal engine takes no restrict property. The runs use its immediate form restrict(expr) under ifdef FORMAL, which constrains the run in the same way. That form is the tool's, not IEEE 1800 syntax: the standard writes restrict property (@(posedge clk) !(req0 && req1)); (16.14.4).

q=5: Arbiter with restrict, cover gnt1. Mode cover, depth 10, smtbmc yices. props.sv:
c_gnt1: cover property (@(posedge clk) gnt1);
q=6: Arbiter with restrict, cover both requests. Mode cover, depth 10, smtbmc yices. props.sv:
both: cover property (@(posedge clk) req0 && req1);
q=7: Buggy arbiter with restrict, assert one grant. Mode bmc, depth 12, smtbmc yices. props.sv:
one_grant: assert property (@(posedge clk) !(gnt0 && gnt1));
qReturn
0worked example: the failures of only_one_a if req0 dropped at 52 instead of 62
1, 2worked examples: the two formal runs below, on the arbiter without the restriction
3a_fails
4a_first
5, 6, 7the three formal runs above
q=1: Arbiter with assume, assert one grant. Mode prove, depth 4, smtbmc yices. props.sv:
one_req: assume property (@(posedge clk) !(req0 && req1));
one_grant: assert property (@(posedge clk) !(gnt0 && gnt1));
q=2: Arbiter with assume, cover a single request. Mode cover, depth 10, smtbmc yices. props.sv:
one_req: assume property (@(posedge clk) !(req0 && req1));
single: cover property (@(posedge clk) req0 && !req1);

Simulator note: Simulation keys were measured on Verilator 5.052, formal keys with the formal engine v1. Your answer function is checked by a small bench on Icarus 12.

Examples

Example 1

An Assumption Is Checked in Simulation
Input
answer(0)
Output
answer = 2

Each edge that breaks the rule fails the assumption once.

Example 2

An Assumption in Formal
Input
answer(1)
Output
answer = 1

With both requests removed, two grants are impossible: PASS.

Example 3

A Cover Keeps the Assumption Honest
Input
answer(2)
Output
answer = 1

A single request is still allowed, so the cover is reached.

Constraints and Contract

  • Return one value per question from answer(q).
  • Keep the function header.

Hints

Hint 1

List the sampled requests at each edge: a change between two edges shows at the later one.

Hint 2

A restriction removes input sequences, as an assumption does. It removes no behaviour of the design itself.

Hint 3

A cover on an output asks whether some allowed input sequence reaches it.

What the grader checks: Eight constant answers: three worked examples and five graded questions. They are measured on Verilator 5.052 and the formal engine v1, and checked against IEEE 1800-2023 16.14.4.

8 checks on Icarus · browser samples / server checks. 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

An Assumption Is Checked in Simulation

Input
answer(0)
Expected output
answer = 2

Each edge that breaks the rule fails the assumption once.

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

Icarus · browser samples / server checks