# Modeling dynamic delay range via subroutine

**URL:** <https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Modeling-dynamic-delay-range-via-subroutine\
**Created:** [October 14, 2023, 5:13pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964 "2023-10-14T17:13:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MICRO\_91](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@MICRO\_91](https://verificationacademy.com/forums/u/MICRO_91)\
**Post date:** [October 14, 2023, 5:13pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/1 "2023-10-14T17:13:26Z")

</div>

Hi,  
I was referring to [sva-package-dynamic-and-range-delays-and-repeats](https://verificationacademy.com/forums/systemverilog/sva-package-dynamic-and-range-delays-and-repeats) and was trying out an alternative via SV task which would provide me the flexibility of SV constructs.

The intention is to check for sequence : ( a ##1 b ) ##[min:max] ( c ##1 d ) // min and max are run-time variables with values 4 and 6 respectively.

Here is my attempt : [edalink](https://www.edaplayground.com/x/cprf).

Ideally sequence (c ##1 d) should be checked thrice and the assertion should pass at the 1st match. It should fail only when sequence doesn’t match even after 6 clocks.

[Q1] Any suggestions ?

[2] I was referring to sequence ‘dynamic\_delay’ from the package

```verilog

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

```

```
Consider a case where we call sequence as **dynamic_delay(0)**

LHS sequence: (count<=0) is a match on the very 1st clock.

In RHS sequence: ((1, v=count) ##0 (v>0, v=v-1)[*0:$] ##1 v<=0), due to empty sequence (v>0, v=v-1)[*0] 

**[Q2]For the RHS shouldn't the equivalent expression ((1, v=count) ##0 v<=0) match ?**

 **i.e won't both LHS and RHS sequence of the 'or' operator match on the very 1st clock ?**

 I added some $display() for debugging in [edalink2](https://www.edaplayground.com/x/n4Af), but I don't observe the message "RHS Sequence matches" at T:5

```

---

<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 14, 2023, 9:46pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/2 "2023-10-14T21:46:56Z")

</div>

_In reply to [MICRO\_91](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964):_

> The intention is to check for sequence : ( a ##1 b ) ##[min:max] ( c ##1 d )

I address this with examples is my paper

> **[Understanding the SVA Engine Using the Fork-Join Model](https://verificationacademy.com/verification-horizons/july-2020-volume-16-issue-2/understanding-the-sva-engine-using-the-fork-join-model)**
>
> Understanding the SVA Engine Using the Fork-Join Model is a Verification Academy page

[http://systemverilog.us/vf/ap\_a2bnext3cnextd\_range.sv](http://systemverilog.us/vf/ap_a2bnext3cnextd_range.sv)  
ap\_a2bnext3cnextd\_range : assert property(@(posedge clk) $rose(a) ##2 b|-\> ##[1:3] c ##1 d);

also in [http://systemverilog.us/vf/a\_range\_one.sv](http://systemverilog.us/vf/a_range_one.sv)  
ap\_a1to5b\_then\_3c : assert property(@(posedge clk) $rose(a) ##[1:5] b |-\> ##3 c);

Regarding your code in

> **[EDA Playground](https://www.edaplayground.com/x/cprf)**
>
> Edit, save, simulate, synthesize SystemVerilog, Verilog, VHDL and other HDLs from your web browser.

@( posedge clk ) a ##1 b |-\> ##0( 1, dynamic\_delay\_range( min , max ) ) ;  
Delays or wait statements in match item task calls are not supported by some tools.  
This is most likely because the tool vendor implemented the task call in the Observed region rather than the Reactive region.  
In any case, your task dynamic\_delay\_range does not consider the sequence that follows it.

On your Q2, you are correct.  
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)**
>
> 141.16 KB

or [Cohen\_Links\_to\_papers\_books - Google Docs](https://rb.gy/ibks5p)

Getting started with verification with SystemVerilog

> **[Ben Cohen on LinkedIn: Road map to start with verification: SV, SVA , UVM and TB](https://www.linkedin.com/posts/ben-cohen-1172a0_road-map-to-start-with-verification-sv-activity-7050267628208062464-wnzN?utm_source=share&utm_medium=member_desktop)**
>
> Got this question: 
> Q: I need your advice in getting started with verification with systemverilog. I 've built various projects using Verilog and they was…

---

<div class="post-metadata">

**Author:** ![MICRO\_91](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@MICRO\_91](https://verificationacademy.com/forums/u/MICRO_91)\
**Post date:** [October 15, 2023, 6:33am UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/3 "2023-10-15T06:33:30Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/2):_

For [Q2] I tried changing sequence ‘dynamic\_delay’ with only RHS sequence :

```verilog

sequence dynamic_delay(count); // Actual argument is 0
   int v;
   ( (1, v=count,$display("T:%0t v=count",$time) ) ##0 (v>0,v=v-1)[*0:$] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time)) );
 endsequence

```

The assertion fails at T:5 : [edalink3](https://www.edaplayground.com/x/N2VZ) due to ( v\>0 ) being false.

On changing the code to :

```verilog

sequence dynamic_delay(count);
   int v;
   ( (1, v=count,$display("T:%0t v=count",$time) ) ##0 first_match( (v>0, v=v-1) [*0:$] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time)) ) );
 endsequence

```

Now I do observe **“T:5 RHS Sequence matches” when calling dynamic\_delay(0)**

However in the original code ( [edalink2](https://www.edaplayground.com/x/n4Af) ) since the expression **within dynamic\_delay(0) is equivalent to:**

```verilog

 (count<=0) or ( ( (1,v=count) ##0 (v>0, v=v-1)[*0] ##1 (v<=0) ) or ( (1,v=count) ##0 (v>0, v=v-1)[*1] ##1 (v<=0) ) or ... ( (1,v=count) ##0 (v>0, v=v-1)[*N] ##1 (v<=0) ) )

```

LHS sequence : ( count\<=0) is a match at T:5

RHS sequence consists of multiple sequences **'or’ed** : **( seq1 or seq2 or … seqn )**

```verilog

( (1,v=count) ##0 (v>0, v=v-1)[*0] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) ) or // seq1
( (1,v=count) ##0 (v>0, v=v-1)[*1] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) ) or // seq2
............................................................................................ or
( (1,v=count) ##0 (v>0, v=v-1)[*N] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) )

```

**seq1 has a empty sequence** ( (v\>0, v=v-1)\*_[0]_ ) due to which it can re-written as : **(1,v=count) ##0 (v\<=0,$display(“T:%0t RHS Sequence matches”,$time))**

So why is it that RHS sequence isn’t considered a match at T:5 ? ( since I don’t observe “T:5 RHS Sequence matches” for [edalink2](https://www.edaplayground.com/x/n4Af) )

Since **the input argument ‘count’ is 0, the sequence (v\>0) fails for ALL sub-sequences of the RHS sequence i.e essentially RHS sequence ends at T:5.**  
As per my understanding sub-sequence seq1 does match at T:5, however there is no message “T:5 RHS Sequence matches” in output :(  
**Am I missing something ?**

---

<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 16, 2023, 9:14pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/4 "2023-10-16T21:14:13Z")

</div>

_In reply to [MICRO\_91](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/3):_  
Your analysis of **(count\<=0) or …** not being needed is correct.  
This seems to be a tool issue and I’ll be addressing this with the vendors.  
Curiously, adding () gives different results.  
[dynamic\_delay( 0 ) using RHS sequence(1) - EDA Playground](https://www.edaplayground.com/x/hMh4) // code  
Since we don’t address tools, I can’t go further on this.  
In my **dynamic\_delay(count)** sequence I originally added the \*\*(count\<=0) or …\*\*to make the code work and bypass any tool issue.  
Reality of life!  
:)  
Ben

---

<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:** [April 2, 2024, 11:19pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/5 "2024-04-02T23:19:01Z")

</div>

> [@MICRO\_91](#):
>
> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/2):_  
> However in the original code ( [edalink2](https://www.edaplayground.com/x/n4Af) ) since the expression **within dynamic\_delay(0) is equivalent to:**
> 
> ```auto
> (count<=0) or ( ( (1,v=count) ##0 (v>0, v=v-1)[*0] ##1 (v<=0) ) or ( (1,v=count) ##0 (v>0, v=v-1)[*1] ##1 (v<=0) ) or ... ( (1,v=count) ##0 (v>0, v=v-1)[*N] ##1 (v<=0) ) )
> 
> ```
> 
> LHS sequence : ( count\<=0) is a match at T:5
> 
> RHS sequence consists of multiple sequences **'or’ed** : **( seq1 or seq2 or … seqn )**
> 
> ```verilog
> ( (1,v=count) ##0 (v>0, v=v-1)[*0] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) ) or // seq1
> ( (1,v=count) ##0 (v>0, v=v-1)[*1] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) ) or // seq2
> ............................................................................................ or
> ( (1,v=count) ##0 (v>0, v=v-1)[*N] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time) ) )
> 
> ```
> 
> **seq1 has a empty sequence** ( (v\>0, v=v-1)\*_[0]_ ) due to which it can re-written as : **(1,v=count) ##0 (v\<=0,$display(“T:%0t RHS Sequence matches”,$time))**
> 
> So why is it that RHS sequence isn’t considered a match at T:5 ? ( since I don’t observe “T:5 RHS Sequence matches” for [edalink2](https://www.edaplayground.com/x/n4Af) )
> 
> Since **the input argument ‘count’ is 0, the sequence (v\>0) fails for ALL sub-sequences of the RHS sequence i.e essentially RHS sequence ends at T:5.**  
> As per my understanding sub-sequence seq1 does match at T:5, however there is no message “T:5 RHS Sequence matches” in output :(  
> **Am I missing something ?**

**Using left to right associativity ‘seq1’ is a No match ( 0 )** due to (1,v=count) ##0 (v\>0, v=v-1)[\*0]  
The rest of the sequence ##1 (v\<=0,$display(“T:%0t RHS Sequence matches”,$time) ) is never evaluated.

Hence your display message “T:5 RHS Sequence matches” doesn’t execute.

**As Ben suggested by adding an enclosed parenthesis in your RHS sequence**

```auto
( (1, v=count) ##0 ( (v>0, v=v-1) [*0:$] ##1 (v<=0,$display("T:%0t RHS Sequence matches",$time)) ) );
// == ==         

```

In this case your ‘seq1’ is equivalent to :: (1,v=count) ##0 (v\<=0,$display(“T:%0t RHS Sequence matches”,$time) )  
**Hence the display message “T:5 RHS Sequence matches” executes.**

---

<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:** [April 2, 2024, 11:25pm UTC](https://verificationacademy.com/forums/t/modeling-dynamic-delay-range-via-subroutine/42964/6 "2024-04-02T23:25:06Z")

</div>

Ben ,

1. I believe the tools are correct in their output.  
By simply adding an enclosed parenthesis your sequence ‘dynamic\_delay’ from [sva-package-for-dynamic-and-range-delays-and-repeats](https://verificationacademy.com/forums/t/sva-package-for-dynamic-and-range-delays-and-repeats/35446) can be re-written as

```auto
// ******DYNAMIC DELAY ##d1**********
    // Implements ##[d1] 
    // Application: sq_1 ##0 dynamic_delay(d1) ##0 sq_2;
    sequence dynamic_delay(count);
        int v;
     ( (1, v=count) ##0 ( (v>0, v=v-1) [*0:$] ##1 v<=0 ) );
    endsequence // dynamic_delay

```

When actual to **count is 0 / -ve value** sequence is equivalent to

> ( (1, v=count) ##0 v\<=0 ) )

**It matches at the same time that the sequence is invoked**

1. Using [dynamic\_delay(0)](https://www.edaplayground.com/x/q8Dd) ,  
Why is it that we observe **either “T:5 LHS Sequence matches”** or **“T:5 RHS Sequence matches” ?**  
( **3 tools shows one of the either message but not both , 1 tool shows both messages** )  
**Since both LHS and RHS sequence match at T:5 , shouldn’t we observe both messages ?  
Or is it that due to implicit first\_match in consequent that a tool shows only one message ?**  
Ideally as per LRM would it be incorrect if a tool were to show both display messages ?
