# SVA: Package for dynamic and range delays and repeats

**URL:** <https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, dynamic-delays-dynamic-repeats\
**Created:** [December 11, 2018, 10:55pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446 "2018-12-11T22:55:44Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [December 11, 2018, 10:55pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/1 "2018-12-11T22:55:44Z")

</div>

The package has been updated and is now uploaded here and is also avaliable at  
[https://systemverilog.us/vf/sva\_repeat\_delay\_thru\_pkg\_011624.sv](https://systemverilog.us/vf/sva_repeat_delay_thru_pkg_011624.sv)  
[sva\_repeat\_delay\_thru\_pkg\_011624.pdf](https://verificationacademy.com/forums/uploads/short-url/dNzEZMN9EY5ko9UraIz20t35gVQ.pdf) (89.0 KB)

Update is based on comment:

> [@Unexpected results for Dynamic delay range](https://verificationacademy.com/forums/t/unexpected-results-for-dynamic-delay-range/42734/15):
>
> Ben, As we discussed at the top of this thread, sequence ‘dynamic\_delay\_lohi\_sq’ has a limitation when sub-sequent sequence doesn’t match even after ##(dyn\_max). The assertion fails at next clock rather than ##(dyn\_max)'th clock. Refer [edalink](https://www.edaplayground.com/x/U8wK) +define+M4. Instead of failure at T:55 the assertion fails at T:65 due to repeat sequence ending. Your later suggested the following :: sequence dynamic\_delay\_lohi\_sq(d1, d2, sq); int v1, vdiff; dynamic\_delay(d1)##0 (sq or (1…

New code

```auto

// Update 01/16/2024
// PACKAGE UPDATE 12/07/2021
// https://verificationacademy.com/forums/systemverilog/sva-package-dynamic-and-range-delays-and-repeats
/* 1) Attached are the .sv file, and simulation results with Questa. 
2) // The package was verified through analysis of the sequences and through random testing    
// Sequences that use the first_match() function along with a range repeat were reported      
// not compatible with formal verification tools 
 3) It would be great if 1800'2022 adds the dynamic possibilities for the definition of the delays and repeats. The value of those variables can be captured and saved at the attempt cycle. I didn't lock them in the package. 

BTW, these are complex sequences, and it took some time to get them to that point. */

/* Ben Cohen Dec 7, 2021 
// This file includes the delay and repeat package along with 
// a testbench to demonstrate its application. 
// The package was verified through analysis of the sequences and through random testing 
// Sequences that use the first_match() function along with a range repeat were reported   
// not compatible with formal verification tools */

 
package sva_delay_repeat_range_pkg;
    //----------------------------------------------------------------
    // ******DYNAMIC DELAY ##d1**********
   // 5/12/25 changed the [*0] to [*1] to avoid degeneracy
    // Implements ##[d1] 
    // Application: sq_1 ##0 dynamic_delay(d1) ##0 sq_2;
    sequence dynamic_delay(count);
        int v;
      (count<=0) or ((1, v=count) ##0 (v>0, v=v-1) [*1:$] ##1 v<=0);
    endsequence // dynamic_delay
 
    //----------------------------------------------------------------
    // ******DYNAMIC DELAY RANGE ##[d1:d2]**********
    // Implements ##[d1:d2] ##0 a_sequence 
    // for use in consequent 
    // Application: $rose(a) |-> dynamic_delay_lohi_sq(d1, d2, q) ;   
    /* sequence dynamic_delay_lohi_sq(d1, d2, sq); // DO NOT USE
        int v1, vdiff;
          ( (1, v1=d1, vdiff=d2-d1) ##0 dynamic_delay(v1) ##0     
              (vdiff>=0, vdiff=vdiff - 1)[*1:$] ##0 sq); 
    endsequence */

    sequence dynamic_delay_lohi_sq(d1, d2, sq);
      int v1, vdiff;
        dynamic_delay(d1)##0 
        (sq or     
        (1, vdiff=d2-d1) ##0 (vdiff>0, vdiff=vdiff - 1)[*1:$] ##1 sq); 
    endsequence
 
    sequence dynamic_delay_fm_lohi_sq(d1, d2, sq);
            int v1, vdiff;
             first_match(dynamic_delay_lohi_sq(d1, d2, sq)); 
    endsequence // dynamic_delay_fm_lohi_sq 
 
    //----------------------------------------------------------------
    // ******DYNAMIC REPEAT q_s[*d1]********** 
    // Implements a_sequence[*count]
    // Application: $rose(a) |-> sq_rpt_simple_count(sq_1, d1)
    sequence sq_rpt_simple_count(sq, count);
        int v=count;
        (1, v=count) ##0 ( v>0 ##0 sq, v=v-1) [*1:$] ##0 v<=0;
    endsequence // sq_rpt_simple_count
    //Note: "The sequence_expr of a sequential property shall not admit an empty match (see 16.12.22)." 
 
    //----------------------------------------------------------------
    // ******DYNAMIC REPEAT RANGE sq_1[*range] ##1 b]**********
    // Implements a_sequence[*1:range] b_sequence 
    // Application: $rose(a) |-> sq1_rpt_simple_range_sq2(sq_1, d1, sq2_2);
    //NOTE: RANGE MUST BE GREATER THAN ZERO !!!!!!
    sequence sq1_rpt_simple_range_sq2(sq1, range, sq2);
      int v, diff;
      (range>0, diff=range) ##0  
      ((diff>0 ##0 sq1, diff=diff-1'b1) [*1:$] ##1 sq2);
    endsequence
 
 
    sequence sq1_rpt_simple_range_fm_sq2(sq1, range, sq2);
      int v, diff;  
      (range>0, diff=range) ##0  
      first_match((diff>0 ##0 sq1, diff=diff-1'b1) [*1:$] ##1 sq2);
    endsequence
 
 
    //----------------------------------------------------------------
    // ******DYNAMIC REPEAT LO-HI RANGE**********
    // Implements a_sequence[*lo:hi] ##1 b_sequence 
    // Application: $rose(a)|-> sq1_rpt_lohi_sq2(sq_1, d1, d2, sq_2); 
    sequence sq1_rpt_lohi_sq2(sq1, d1, d2, sq2); 
        int v, diff;
        (1, v=d1-1, diff=d2-d1+1) ##0 
        sq_rpt_simple_count(sq1, v) ##1
        // TBD Ben Srini q1_rpt_simple_range_q2(sq1, diff, sq2);
        sq1_rpt_simple_range_sq2(sq1, diff, sq2);
    endsequence // sq1_rpt_lohi_sq2 
 
endpackage // sva_delay_repeat_range_pkg
 
 
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++ testbench +++++++++++++++++++++
import uvm_pkg::*; `include "uvm_macros.svh" 
import sva_delay_repeat_range_pkg::*;
module top; 
    timeunit 1ns; timeprecision 100ps;  
    bit clk, a, b, c=1, w;  
    int d1=2, d2=5, range=7;  
    sequence sq_a1_2_b; a ##[1:2] b; endsequence 
    sequence sq_c1_4_b; c ##[1:4] b; endsequence   
    sequence sq_2w; ##2 w; endsequence 
    // default clocking @(posedge clk); endclocking
    initial forever #5 clk=!clk;  
 
    // ******DYNAMIC DELAY ##d1**********    
    ap_dyn_delay2: assert property(@ (posedge clk) 
       $rose(a) |-> dynamic_delay(d1) ##0 sq_2w);   
 
    ap_fix2_delay2: assert property(@ (posedge clk)   
       $rose(a) |-> ##2 sq_2w); 
 
    ap_dyn_delay0: assert property(@ (posedge clk)   
       $rose(a) |-> dynamic_delay(1'b0) ##0 sq_2w);  
 
    ap_fix_delay0: assert property(@ (posedge clk)   
       $rose(a) |-> ##0 sq_2w); 
//----------------------------------------------------------------
    // ******DYNAMIC DELAY RANGE ##[d1:d2]**********
    ap_dly_2_5_consequent_rng: assert property(@ (posedge clk) 
      $rose(a) |-> dynamic_delay_lohi_sq(d1, d2, sq_c1_4_b));  
 
    ap_fix_2to5_consequent: assert property(@ (posedge clk) 
      $rose(a) |-> ##[2:5] sq_c1_4_b );   
 
    ap_dly_rng_2_5_antc: assert property(@ (posedge clk)    
     $rose(a) ##0 dynamic_delay_fm_lohi_sq(d1, d2, sq_c1_4_b) |-> sq_2w);  
 
    ap_fix_2to5_antc: assert property(@ (posedge clk) 
      first_match($rose(a) ##0 (##[2:5] sq_c1_4_b)) |-> sq_2w); 
 
    //===
    // The sub-sequence (vdiff>=0, vdiff=vdiff - 1)[*1:$] ##0 sq)
    // causes the display of the failure to occur 1 cycle later 
    // when vdiff==0 and sq is a nomatch.  
    // At next cycle, vdiff==-1 and the term vdiff>0 is false.
    // That's when the error is display (1 cycle laters) 
    // The passes are displayed at the correct cycle. 
    ap_dly_2to2_consequent_rng: assert property(@ (posedge clk) // ** FLAG, but OK 
      $rose(a) |-> dynamic_delay_lohi_sq(d1, 2, sq_c1_4_b));   
 
    ap_fix_2to2_consequent: assert property(@ (posedge clk) 
      $rose(a) |-> ##[2:2] sq_c1_4_b );   
 
    ap_dly_0to0_consequent_rng: assert property(@ (posedge clk) // ** FLAG, but OK 
      $rose(a) |-> dynamic_delay_lohi_sq(0, 0, sq_c1_4_b));  
 
    ap_fix_0to0_consequent: assert property(@ (posedge clk) 
      $rose(a) |-> ##[0:0] sq_c1_4_b ); 
 
    //------------------------------------------------------------------
    // ******DYNAMIC REPEAT sq_a1_2_b[*d1]********** 
    ap_rpt_count_2_cons: assert property(@ (posedge clk)    
      $rose(a)|-> sq_rpt_simple_count(sq_a1_2_b, d1) ##1 sq_2w);  
 
    ap_rpt_2_fix_cons: assert property(@ (posedge clk)  
       $rose(a)|-> sq_a1_2_b[*2] ##1 sq_2w);            
 
    ap_rpt_count_2_antc: assert property(@ (posedge clk)    
      $rose(a) ##0 sq_rpt_simple_count(sq_a1_2_b, d1) |-> ##1 sq_2w);  
 
    ap_rpt_2_fix_antc: assert property(@ (posedge clk)  
        $rose(a) ##0 sq_a1_2_b[*2] |-> ##1 sq_2w);
 
// ******DYNAMIC REPEAT RANGE sq_1[*rang] ##1 b]**********
    ap_rpt_rng2_5_antc_all: assert property(@ (posedge clk)     
      $rose(a) ##1 sq1_rpt_simple_range_sq2(sq_a1_2_b, range, sq_c1_4_b)
                          |-> sq_2w);  
    ap_rpt_fix2_5_antc_all: assert property(@ (posedge clk) 
      $rose(a) ##1 (sq_a1_2_b[*1:7] ##1 sq_c1_4_b) |-> sq_2w);
 
    ap_rpt_rng2_5_cons: assert property(@ (posedge clk)   
      $rose(a) |-> ##1 sq1_rpt_simple_range_sq2(sq_a1_2_b, range, sq_c1_4_b));
 
    ap_rpt_fix2_5_cons: assert property(@ (posedge clk) 
      $rose(a) |-> ##1 (sq_a1_2_b[*1:7] ##1 sq_c1_4_b));  
 
// first_match() 
    ap_rpt_rng2_5_cons_all_fm: assert property(@ (posedge clk)   
      $rose(a) |-> sq1_rpt_simple_range_fm_sq2(sq_a1_2_b, range, sq_c1_4_b) ##0 sq_2w);
 
    ap_rpt_range_fix2_5_cons_fm: assert property(@ (posedge clk) 
      $rose(a) |-> first_match(sq_a1_2_b[*1:7] ##1 sq_c1_4_b) ##0 sq_2w);    
 
    ap_rpt_rng2_5_antc_fm: assert property(@ (posedge clk)   
      $rose(a) ##1 sq1_rpt_simple_range_fm_sq2(sq_a1_2_b, range, sq_c1_4_b)); 
 
    ap_rpt_fix2_5_antc_fm: assert property(@ (posedge clk) 
      $rose(a) ##1 first_match( (sq_a1_2_b[*1:7] ##1 sq_c1_4_b))); 
 
    initial begin 
    
      repeat(2) @(posedge clk);
      a <= 1'b0; b<=1'b0; c<=1'b0; w<=1'b0; 
      @(posedge clk);
      a <= 1'b1; b<=1'b1; c<=1'b1; w<=1'b1; 
      @(posedge clk) d1<=0; d2<=0; // <------------------ ZERO test 
      repeat(2) @(posedge clk);
      a <= 1'b0; b<=1'b0; c<=1'b0; w<=1'b0; 
      @(posedge clk);
      a <= 1'b1; b<=1'b1; c<=1'b1; w<=1'b1; 
      // Regular test 
      @(posedge clk) d1<=2; d2<=5; // <-------------------- Range test 
      repeat(20) @(posedge clk);
        repeat(1000) begin 
            @(posedge clk); #2;   
            if (!randomize(a, b, c, w) with 
            { a dist {1'b1:=1, 1'b0:=1};
            b dist {1'b1:=1, 1'b0:=1}; 
            c dist {1'b1:=1, 1'b0:=1}; 
            w dist {1'b1:=1, 1'b0:=1}; }) `uvm_error("MYERR", "randomize error");
        end 
        #1;
        repeat(1500) begin 
            @(posedge clk); #2;   
            if (!randomize(a, b, c, w) with 
            { a dist {1'b1:=1, 1'b0:=2};
            b dist {1'b1:=3, 1'b0:=2}; 
            c dist {1'b1:=1, 1'b0:=1}; 
            w dist {1'b1:=3, 1'b0:=1}; }) `uvm_error("MYERR", "randomize error");
        end 
        repeat(1500) begin 
            @(posedge clk); #2;   
            if (!randomize(a, b, c, w) with 
            { a dist {1'b1:=3, 1'b0:=2};
            b dist {1'b1:=1, 1'b0:=2}; 
            c dist {1'b1:=4, 1'b0:=1}; 
            w dist {1'b1:=2, 1'b0:=1}; }) `uvm_error("MYERR", "randomize error");
        end 
        $stop; 
    end 
endmodule   

```

Ben Cohen  
[Ben@systemverilog.us](mailto:Ben@systemverilog.us)  
Link to the list of papers and books that I wrote, many are now donated. [https://systemverilog.us/vf/Cohen\_Links\_to\_papers\_books.pdf](https://systemverilog.us/vf/Cohen_Links_to_papers_books.pdf)

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [December 12, 2018, 3:49am UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/2 "2018-12-12T03:49:06Z")

</div>

Complex assertions can also be more easily written answered through the use of an automatic task.  
I discuss this approach in my paper:  
[https://verificationacademy.com/forums/systemverilog/paper-understanding-sva-engine-simple-alternate-solutions](https://verificationacademy.com/forums/systemverilog/paper-understanding-sva-engine-simple-alternate-solutions)  
Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [April 23, 2021, 6:42am UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/3 "2021-04-23T06:42:56Z")

</div>

Move the imports after the module name. For example

```verilog
 
module top; 
    timeunit 1ns; timeprecision 100ps;  
    import uvm_pkg::*; `include "uvm_macros.svh" 
    import sva_delay_repeat_range_pkg::*;
    bit clk, a, b, c=1, w;  
.... 

```

---

<div class="post-metadata">

**Author:** ![SinghalR](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@SinghalR](https://verificationacademy.com/forums/u/SinghalR)\
**Post date:** [October 30, 2021, 4:23pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/4 "2021-10-30T16:23:19Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/3):_

Hi Ben,

Can this be used for formal verification as well? I see questa propcheck throwing some errors on this.

\*\*\*# Warning : Unsupported variable delay between local variable assign and read or within AND/OR/first\_match/within constructs. Outside supported local variable synthesis subset. Local variable q\_dynamic\_repeat\_v[0].

Thanks & Regards  
Singhal R

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [October 30, 2021, 6:16pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/5 "2021-10-30T18:16:39Z")

</div>

_In reply to [Singhal R](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/4):_

“Unsupported” is a tool specific issue.

This Mentor/Siemens EDA sponsored public forum is not for discussing tool specific usage or issues. Please read your tool’s user manual or contact your tool vendor directly for support.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [October 30, 2021, 8:59pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/6 "2021-10-30T20:59:59Z")

</div>

_In reply to [Singhal R](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/5):_  
Speaking in generalities, we’re talking about 2 things: local variables (LV) as counters and first\_match. This is different from LV for data storage and compare at later cycles.  
Counters are cycle-based kind of thing, and first match is a thread reduction mechanism. That does not seem a FV thing. For specifics talk to your vendor.

A work around for formal might be to use the generate with static variables for a small range (1 to 32)?

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [Home - My cvcblr](http://cvcblr.com/home)  
\*\* SVA Handbook 4th Edition, 2016 ISBN 978-1518681448  
…

1. SVA Package: Dynamic and range delays and repeats [SVA: Package for dynamic and range delays and repeats | Verification Academy](https://rb.gy/a89jlh)
2. Free books: Component Design by Example [FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [Amazon.com](https://rb.gy/cwy7nb)
3. Papers:

- Understanding the SVA Engine,  
[Verification Horizons - July 2020 | Verification Academy](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)
- SVA Alternative for Complex Assertions  
[Verification Horizons - March 2018 Issue | Verification Academy](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- SVA in a UVM Class-based Environment  
[SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [November 1, 2021, 7:42pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/7 "2021-11-01T19:42:22Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/6):_

Here is a workaround for dynamic delays to be used for formal verification:

```verilog

module top; 
    import uvm_pkg::*; `include "uvm_macros.svh" 
    import sva_delay_repeat_range_pkg::*;
    timeunit 1ns; timeprecision 100ps;  
    bit clk, a, b, c=1, w;  
    bit[1:0] v=2;  
       
    initial forever #10 clk=!clk;  
    
    // ******DYNAMIC DELAY ##v**********
    // Application: $rose(a) |-> q_dynamic_delay(v) ##0 my_sequence;
    ap_dyn_delay: assert property(@ (posedge clk) 
       $rose(a) |-> q_dynamic_delay(v) ##0 b);  
    
    ap_fix_delay2: assert property(@ (posedge clk)   
       $rose(a) |-> ##2 b); 

    // For formal verification
    generate for (genvar i=0; i<=3; i++)
        begin 
            ap_fvi: assert property(@ (posedge clk) 
               v==i && $rose(a) |-> ##i b);  
        end
    endgenerate 

```

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
\*\* SVA Handbook 4th Edition, 2016 ISBN 978-1518681448  
…

1. SVA Package: Dynamic and range delays and repeats [SVA: Package for dynamic and range delays and repeats | Verification Academy](https://rb.gy/a89jlh)
2. Free books: Component Design by Example [FREE BOOK: Component Design by Example … A Step-by-Step Process Using VHDL with UART as Vehicle | Verification Academy](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [Amazon.com](https://rb.gy/cwy7nb)
3. Papers:

- Understanding the SVA Engine,  
[Verification Horizons - July 2020 | Verification Academy](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)
- SVA Alternative for Complex Assertions  
[Verification Horizons - March 2018 Issue | Verification Academy](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- SVA in a UVM Class-based Environment  
[SVA in a UVM Class-based Environment | Verification Horizons | Verification Academy](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

Udemy courses by Srinivasan Venkataramanan ([http://cvcblr.com/home.html](http://cvcblr.com/home.html))  
[https://www.udemy.com/course/sva-basic/](https://www.udemy.com/course/sva-basic/)  
[https://www.udemy.com/course/sv-pre-uvm/](https://www.udemy.com/course/sv-pre-uvm/)

---

<div class="post-metadata">

**Author:** ![SinghalR](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/ee59a6/32.png) [@SinghalR](https://verificationacademy.com/forums/u/SinghalR)\
**Post date:** [November 5, 2021, 1:19pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/8 "2021-11-05T13:19:31Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/7):_

Thanks Ben. I am aware of use of generate. However I was wondering if there are other methods. In one of the use case range of variable delays and their combinations are two many.

For example, say delay is controlled by three different variables d1, d2 and d3.  
d1 inside [10:15]  
d2 inside [20:40]  
d3 inside [40-240].

So total combinations becomes about 6_21_201 = 25326 possible cases. In such cases as well generate may not be the best method. Any thoughts on this?

Thanks & Regards  
Singhal R

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [November 5, 2021, 3:29pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/9 "2021-11-05T15:29:02Z")

</div>

_In reply to [Singhal R](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/8):_

> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/8):_… However I was wondering if there are other methods. In one of the use case range of variable delays and their combinations are two many.  
> For example, say delay is controlled by three different variables d1, d2 and d3.  
> d1 inside [10:15]  
> d2 inside [20:40]  
> d3 inside [40-240].

Two points, one with the way the tool is used, the other with the RTL architecture.

1. **Way the tool is used:** If the formal tool does not support the first\_match of a sequence with a repeat (e.g., (first\_match((1, v=v-1’b1) [\*0:$]) the use of the **generate** is the only option I see. I can think of dynamic tasks with fork-join but that is not supported in formal.
2. If you have multiple variables and the number of combinations explodes, you’ll need to add some **assume property** statements to constraint the ranges to something more manageable. For example, you can constraint the generate to smaller ranges and add assume statements:

```verilog

am_d3: assume property(@(posedge clk) d3==40 || d3==50 || d3== 100 || d3==200 || d3==240);

```

1. **RTL architecture:** When I built the RTL to implement the assertion  
$rose(a) |-\> q\_dynamic\_delay(v) ##0 b);  
I first approached the problem by using a cycle counter. That worked fine until you get a 2nd rose while the previous thread did not yet complete. Using counter, it seems that every thread would need it’s own set of counters, and you can do that with threaded forked tasks (that’s not synthesizable, as you know). My solution ended up ignoring other threads until a stated “rose” thread completed the count. That was a very complex solution, and honestly, it took a few iterations to get it working.

1. Complex RTL with a counter for the setting of “b”  
[http://SystemVerilog.us/vf/dynamic\_dly2.sv](http://SystemVerilog.us/vf/dynamic_dly2.sv)  
[http://SystemVerilog.us/vf/dynamic\_dly2.png](http://SystemVerilog.us/vf/dynamic_dly2.png)  
After some thoughts, I came up with a much simpler, more natural solution piping the rose(a) into a register and using a MUX to select bit in pipe for the “b”
2. Simpler RTL piping the rose(a) and a MUX to select bit in pipe for the “b”  
[http://SystemVerilog.us/vf/pipe\_dly.sv](http://SystemVerilog.us/vf/pipe_dly.sv)  
[http://SystemVerilog.us/vf/pipe\_design.png](http://SystemVerilog.us/vf/pipe_design.png)

My point on the architecture is that the simpler one is easier to analyze and probably through thorough analysis have a high level of confidence that the design works in all cases. Again, constraints in formal will cut the formal evaluation time.

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
\*\* SVA Handbook 4th Edition, 2016 ISBN 978-1518681448  
…

1. SVA Package: Dynamic and range delays and repeats [SVA: Package for dynamic and range delays and repeats - SystemVerilog - Verification Academy](https://rb.gy/a89jlh)
2. Free books: Component Design by Example [https://rb.gy/9tcbhl](https://rb.gy/9tcbhl)  
Real Chip Design and Verification Using Verilog and VHDL($3) [Amazon.com](https://rb.gy/cwy7nb)
3. Papers:

- Understanding the SVA Engine,  
[Verification Horizons](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2)
- SVA Alternative for Complex Assertions  
[https://verificationacademy.com/news/verification-horizons-march-2018-issue](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
- SVA in a UVM Class-based Environment  
[https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment](https://verificationacademy.com/verification-horizons/february-2013-volume-9-issue-1/SVA-in-a-UVM-Class-based-Environment)

Udemy courses by Srinivasan Venkataramanan ([http://cvcblr.com/home.html](http://cvcblr.com/home.html))  
[https://www.udemy.com/course/sva-basic/](https://www.udemy.com/course/sva-basic/)  
[https://www.udemy.com/course/sv-pre-uvm/](https://www.udemy.com/course/sv-pre-uvm/)

---

<div class="post-metadata">

**Author:** ![abasili](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/a/ecb155/32.png) [@abasili](https://verificationacademy.com/forums/u/abasili)\
**Post date:** [May 7, 2024, 5:06pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/10 "2024-05-07T17:06:25Z")

</div>

Hi Ben,

sorry to necropost but I’ve bumped into your code here and wanted to use it in our projects. Under which license is it distributed? I haven’t found any trace of a license file or copyright notice.

Thanks a lot for making it clear.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [May 7, 2024, 5:34pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/11 "2024-05-07T17:34:37Z")

</div>

I wrote that package and I donated to the community.  
It is free to use.  
To the best of my knowledge and tests by other users, the code is correct. However, like any code, it is under NO guarantee :)  
Ben Cohen  
[Ben@systemverilog.us](mailto:Ben@systemverilog.us)  
Link to the list of papers and books that I wrote, many are now donated.

> **[Cohen\_Links\_to\_papers\_books.pdf](https://systemverilog.us/vf/Cohen_Links_to_papers_books.pdf)**
>
> 102.86 KB

---

<div class="post-metadata">

**Author:** ![hdlcohen](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hdlcohen](https://verificationacademy.com/forums/u/hdlcohen)\
**Post date:** [March 17, 2025, 10:14pm UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/12 "2025-03-17T22:14:15Z")

</div>

CHANGE FROM

```auto
sequence dynamic_delay(count); // HAS DEGENERACY
        int v;
      (count<=0) or ((1, v=count) ##0 (v>0, v=v-1) [*0:$] ##1 v<=0);
    endsequence // dynamic_delay

```

TO

```auto
sequence dynamic_delay(count); // NEW 
        int v;
      (count<=0) or ((1, v=count) ##0 (v>0, v=v-1) [*1:$] ##1 v<=0);
 endsequence // dynamic_delay

// ANALYSISConsider: the following with count==1
((1, v=count) ##0 (v>0, v=v-1) [*0:$] ##1 v<=0)  
     is equivalent to:
((1, v=1) ##0 (1>0, v=0) [*0] ##1 v<=0) or ((1, v=count) ##0 (v>0, v=v-1) [*1:$] ##1 v<=0)
// SAME AS ((1, v=1) ##0 1 [*0] ##1 v<=0)
// SAME AS ((1, v=2) ##0 EMPTY ##1 v<=0) // degenerate and illegal
// (seq ##0 empty ) is degenerate and illegal
```

---

<div class="post-metadata">

**Author:** ![Have\_A\_Doubt](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/51bf81/32.png) [@Have\_A\_Doubt](https://verificationacademy.com/forums/u/Have_A_Doubt)\
**Post date:** [March 18, 2025, 12:21am UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/13 "2025-03-18T00:21:26Z")

</div>

Hi Ben,  
LRM Section 16.12.22 Nondegeneracy mentions ::  
**Any sequence that is used as a property shall be nondegenerate and shall not admit any empty match**

For count == 1, sequence dynamic\_delay would be equivalent to

```auto
( count <= 0 ) // seq0
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*0] ##1 v <= 0 ) // seq1 
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*1] ##1 v <= 0 ) // seq2
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*2] ##1 v <= 0 ) // seq3
    ..................
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*N] ##1 v <= 0 ) // seqN

```

As **seq1 admits “No Match”** due to `seq ##0 empty_seq i.e 1'b0` ( where seq is 1 ),  
sequence ‘dynamic\_delay’ is equivalent to

```auto
( count <= 0 ) // seq0
     or 
( 1'b0 ) // seq1 
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*1] ##1 v <= 0 ) // seq2
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*2] ##1 v <= 0 ) // seq3
    ..................
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*N] ##1 v <= 0 ) // seqN

```

seq1 i.e 1’b0 can be essentially removed. The equivalent expression would be

```auto
( count <= 0 ) // seq0
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*1] ##1 v <= 0 ) // seq2
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*2] ##1 v <= 0 ) // seq3
    ..................
     or 
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*N] ##1 v <= 0 ) // seqN

```

seq3 to seqN would be **“Not Matched”** for count == 1 whereas seq2 would match

Since there is **No Empty Match** , I believe the original sequence ‘dynamic\_delay’ doesn’t violate the above LRM quote.

( Also I don’t recollect any tool flagging an error or warning message due to degeneracy )

An example of a sequence which violates the LRM quote would be

```auto
ap1:assert property (@(posedge clk) b[*0:3] );

```

which is equivalent to

```auto
ap1:assert property (@(posedge clk) b[*0] or b[*1] or b[*2] or [b*3] );

```

**Due to b[\*0] the sequence admits an Empty match**

On changing it to

```auto
ap2:assert property (@(posedge clk) b[*0:3] ##0 1 );

```

Due to `b[*0] ##0 1` there is **no longer an empty match** but rather a “No Match”  
Hence ‘ap2’ is legal

---

<div class="post-metadata">

**Author:** ![hdlcohen](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/b5e925/32.png) [@hdlcohen](https://verificationacademy.com/forums/u/hdlcohen)\
**Post date:** [March 18, 2025, 1:04am UTC](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446/14 "2025-03-18T01:04:40Z")

</div>

```auto
( ( 1 , v = 1 ) ##0 ( 1 > 0 , v = v - 1 )[*0] ##1 v <= 0 ) // seq1 `
      seq ##0 empty_seq
As **seq1 admits “No Match”** due to `seq ##0 empty_seq i.e 1'b0` ( where seq is 1 ), 

```

I wrote a paper on degeneracy  
Paper: Understanding SVA Degeneracy

> **[Degeneracy111723Ben.pdf](https://systemverilog.us/vf/Degeneracy111723Ben.pdf)**
>
> 251.64 KB

> **[LinkedIn: Log In or Sign Up](https://lnkd.in/gABW3y-j)**
>
> 1 billion members | Manage your professional identity. Build and engage with your professional network. Access knowledge, insights and opportunities.

```auto
I wrote: A sequence that admits at least one nonempty match is called nondegenerate.
The following restrictions apply:
a. Any sequence that is used as a property shall be nondegenerate and shall not admit any empty match.
b |-> a[*0:2]; // Illegal because it admits an empty match, the [*0]
b |-> a and (b ##1 0); // Illegal and degenerate because
// (b ##1 0) is a NO MATCH per 1.2 rule 1
------------
(seq ##0 empty) does not result in a match
Since (seq ##0 empty) is a no match, 1.2 rules 2a, 2b (above) make this sequence degenerate and thus illegal regardless of where it is used, a property or as an antecedent
--------------

```

Honestly, it is confusing. I think that tools are taking (seq ##0 empty) (empty ##0 seq) as not a match.  
As a rule for VF engrs, we should avout this construct.
