A6.4.2 Future Functions on a Trace

MediumDebugIcarus · browser samples / server checksReview the topic

Read four future-function rules on a trace: when each prints, which attempt failed, and how often.

Hardware context: A status vector and a hold flag watched on a fast global clock. Tell the attempt that failed from the later tick at which its action block runs.

The main program below has four assertions on the global clock. Each one uses a future global-clock function.

Write answer(q). Questions 3 to 7 ask for print times, an attempt time and counts. A print time is the $time the action block shows.

Questions 0 to 2 are worked examples on a smaller program. Questions 3 to 7 are graded only by the full check.

Signals in the Timeline

SignalWidthRole
question4input of each check
Full specification
The main program, questions 3 to 7
module tb;
  logic sys = 0;
  always #5 sys = ~sys;                         // global ticks at 5, 15, 25, ...
  global clocking @(posedge sys); endclocking
  logic [3:0] v = 4'd1;
  logic go = 0, s = 0;

  fut_q:    assert property (@($global_clock) $future_gclk(v) != 4'd5) else $display("fut_q at %0t", $time);
  fall_q:   assert property (@($global_clock) !$falling_gclk(v))      else $display("fall_q at %0t", $time);
  steady_q: assert property (@($global_clock) go |-> $steady_gclk(s))  else $display("steady_q at %0t", $time);
  chg_q:    assert property (@($global_clock) !$changing_gclk(s))     else $display("chg_q at %0t", $time);

  initial begin
    #13 v = 4'd5;                               // t=13
    #11 v = 4'd6;                               // t=24
    #16 go = 1;                                 // t=40
    #3  s = 1;                                  // t=43
    #1  v = 4'd3;                               // t=44
    #8  s = 0;                                  // t=52
    #6  s = 1;                                  // t=58
    #2  go = 0;                                 // t=60
    #3  v = 4'd2;                               // t=63
    #14 s = 0;                                  // t=77
    #20 s = 1;                                  // t=97
    #2  $finish;                                // t=99
  end
endmodule
qReturnProgram
0the first print time of rise_qworked example
1the time of the attempt behind that printworked example
2how many times rise_q printsworked example
3the first print time of fut_qmain, graded
4the first print time of fall_qmain, graded
5the time of the attempt behind that fall_q printmain, graded
6how many times steady_q printsmain, graded
7how many times chg_q printsmain, graded
The worked examples, questions 0 to 2
module tb;
  logic sys = 0;
  always #4 sys = ~sys;                         // global ticks at 4, 12, 20, 28, 36
  global clocking @(posedge sys); endclocking
  logic r = 0;
  rise_q: assert property (@($global_clock) !$rising_gclk(r)) else $display("rise_q at %0t", $time);
  initial begin
    #14 r = 1;                                  // t=14
    #10 r = 0;                                  // t=24
    #8  r = 1;                                  // t=32
    #8  $finish;                                // t=40
  end
endmodule

Simulator note: The key was measured on Verilator 5.052 and agrees with IEEE 1800-2023 16.9.4. Your answer function is checked by a small bench on Icarus 12.

Examples

Example 1

When the Action Runs
Input
answer(0)
Output
answer = 20

r changes at 14, so the tick at 20 is the first to sample it high. The attempt that saw the rise coming prints there.

Example 2

Which Attempt Failed
Input
answer(1)
Output
answer = 12

The action of a future-function assertion runs one global tick after its attempt. One tick before 20 is 12.

Example 3

Count the Rises
Input
answer(2)
Output
answer = 2

r is sampled 0, 0, 1, 0, 1 at the five ticks. It rises twice.

Constraints and Contract

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

Hints

Hint 1

Write down the sample of each signal at every global tick. A change between two ticks shows at the later one.

Hint 2

An attempt at one tick reads the next tick. Its action block runs at that next tick.

Hint 3

$falling_gclk reads bit 0 of a vector. The last tick before $finish has no next tick.

What the grader checks: Eight constant answers: three worked examples and five graded questions. They are graded against times and counts measured on Verilator 5.052 and derived by hand from the standard.

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

When the Action Runs

Input
answer(0)
Expected output
answer = 20

r changes at 14, so the tick at 20 is the first to sample it high. The attempt that saw the rise coming prints there.

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

Icarus · browser samples / server checks