Assertions Reference

$rose, $fell, $stable and $past

These functions compare the sampled value at this clock edge with the one at the edge before.

Syntax

$rose(sig)       // 0 or x at the last edge, 1 at this one
$fell(sig)       // 1 at the last edge, 0 at this one
$stable(sig)     // same value at both edges
$past(sig, 2)    // the value two edges ago

Rules

  • They use sampled values: the value just before each clock edge.
  • $rose and $fell look only at the lowest bit of a vector.
  • They need a clock, taken from the assertion or given as an extra argument.
  • At the first edge there is no earlier value. $past then returns the default, x for logic.
  • $rose(a) is not the same as a. It is true for one cycle only, at the change.

Example

module tb;
  logic clk = 0, req = 0;
  logic [3:0] d = 0;
  always #5 clk = ~clk;

  always @(posedge clk) begin
    if ($rose(req)) $display("t=%0t req rose", $time);
    if ($fell(req)) $display("t=%0t req fell", $time);
    if (!$stable(d)) $display("t=%0t d changed: was %0d", $time, $past(d));
  end

  initial begin
    @(negedge clk) req = 1; d = 4;
    @(negedge clk) d = 9;
    @(negedge clk) req = 0;
    @(negedge clk) $finish;
  end
endmodule
Output on Verilator 5.052
t=15 req rose
t=15 d changed: was 0
t=25 d changed: was 4
t=35 req fell

Run It in the Playground

Common Mistake

Expecting $rose to see a change made at the same edge

always @(posedge clk) req <= 1;
assert property (@(posedge clk) $rose(req) |-> ack);
// $rose(req) is true one edge after the assignment

The assertion samples req just before the edge. A flop that changes at this edge is seen at the next one.

Fix: Count cycles from the sampled value, and draw the waveform when unsure.

Learn It Properly

These lessons teach it step by step, with practice problems.

Standard

IEEE 1800-2023, 16.9.3.