$past in Systemverilog Assertions

In reply to Tobi:
There is nothing wrong with your code.
The issue may be that the antecedent is never retriggered. Below is a test of your code with debug features added. Try this model with your simulator.


import uvm_pkg::*; `include "uvm_macros.svh" 
module top; 
    timeunit 1ns;     timeprecision 100ps;    
    bit clk, a, b, data_rd, rst=0;  
    bit[3:0]  data; 
    int count; 
    event e160, e_attempt; 
    default clocking @(posedge clk); 
    endclocking
    initial forever #10 clk=!clk;  
    
    always  @(posedge clk)  begin 
        count <= count + 1'b1;
        if (count==160) -> e160;
    end 
    function void attempt();
      -> e_attempt;
    endfunction
    
    ap160: assert property (@(posedge clk) disable iff(rst) 
    count > 160 ##0 ($rose(data_rd) && (data[3:0] !=7), attempt())
                              |-> $past((data[3:0]==7),160)) 
              $display("PASS at cycle %d past(data[3:0])=%b",
                    $realtime, $sampled($past(data[3:0], 160)));
    
    
    initial begin 
        bit va, vb; 
        repeat(500) begin 
            @(posedge clk);   
            if (!randomize(data_rd, data)  with 
            { data_rd dist {1'b1:=1, 1'b0:=3};
              data dist {4:=1, 5:=2, 6:=1, 7:=4};      
        }) `uvm_error("MYERR", "This is a randomize error")
        a <= va; 
        b <= vb;
    end 
    $stop; 
end 
endmodule   

 ** Error: Assertion error.
#    Time: 3270 ns Started: 3270 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       3450 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 3530 ns Started: 3530 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       3630 past(data[3:0])=0111
# PASS at cycle       3750 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 3990 ns Started: 3990 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# ** Error: Assertion error.
#    Time: 4310 ns Started: 4310 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       4690 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 4790 ns Started: 4790 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# ** Error: Assertion error.
#    Time: 4990 ns Started: 4990 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       5190 past(data[3:0])=0111
# PASS at cycle       5310 past(data[3:0])=0111
# PASS at cycle       5390 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 5510 ns Started: 5510 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       5610 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 5790 ns Started: 5790 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# ** Error: Assertion error.
#    Time: 5930 ns Started: 5930 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       6030 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 6070 ns Started: 6070 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       6370 past(data[3:0])=0111
# PASS at cycle       6570 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 6630 ns Started: 6630 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# ** Error: Assertion error.
#    Time: 6830 ns Started: 6830 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       7150 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 7190 ns Started: 7190 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# ** Error: Assertion error.
#    Time: 7330 ns Started: 7330 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       7450 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 7650 ns Started: 7650 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)
# PASS at cycle       7830 past(data[3:0])=0111
# ** Error: Assertion error.
#    Time: 7910 ns Started: 7910 ns  Scope: top.ap160 File: C:/ben_play/./past160.sv Line: 20 Expr: $past(data[3:0]==7,160)

 

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us
For training, consulting, services: contact Home - My cvcblr


See Paper: 1) VF Horizons:PAPER: SVA Alternative for Complex Assertions | Verification Academy
2) http://systemverilog.us/vf/SolvingComplexUsersAssertions.pdf