# SVA evaluation

**URL:** <https://verificationacademy.com/forums/t/sva-evaluation/33470>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog\
**Created:** [September 9, 2017, 10:36am UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470 "2017-09-09T10:36:01Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harshit](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c57346/32.png) [@Harshit](https://verificationacademy.com/forums/u/Harshit)\
**Post date:** [September 9, 2017, 10:36am UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/1 "2017-09-09T10:36:01Z")

</div>

Why SystemVerilog assertions are evaluated in observed region, although the values are sampled in preponed region ?

---

<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:** [September 10, 2017, 7:14pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/2 "2017-09-10T19:14:10Z")

</div>

_In reply to [Harshit](https://verificationacademy.com/forums/t/sva-evaluation/33470):_

> Why SystemVerilog assertions are evaluated in observed region, although the values are sampled in preponed region ?

Keep in mind that SystemVerilog must emulate concurrency using a sequencial non-concurret processing computer. Before getting into an example that explains the regions, let me review the regions, as explained from my [SVA Handbook 4th Edition](http://goo.gl/JOfuEB)  
The bottom line:

1. In an assertion, all signals are sampled in the Preponed region  
Thus, with (1, y=q), the module variable “q” is sampled,  
and every “q” referenced is the sampled value
2. If within the sequence-matched-item, I update my property local variable with the return of a function call, like (1, w=getq()), that call is made in the Observed region, past the Active and NBA regions. Thus, in this model (below) w gets the updated value of q.  
390 sampled q= 25, current q= 25, past q= 8, var w= 31

Go over the example and think about the results. It all makes sense.

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/29336b539514a1c55a258551712b19acaf25b283.png)

Example code: [http://SystemVerilog.us/fv/regions2.sv](http://SystemVerilog.us/fv/regions2.sv)

```verilog

import uvm_pkg::*; `include "uvm_macros.svh" 
module top; 
	bit clk, a;  
	int q, qin, k;
	
	always_comb k=q+1'b1; 
	
	default clocking @(posedge clk); endclocking
		initial forever #10 clk=!clk;  
 
	always_ff @(posedge clk) begin 
		q <= qin;
	end 
	
	function automatic int getq(); 
		automatic int v; 
		v=k; 
		return v; 
	endfunction : getq
	
	property test;
		int y, w; 
		a |-> 
			(1, y=q, $display("%t sampled q=%d, current q=%d, past q=%d, var y=%d", $time, $sampled(q), q, $past(q), y)) ##0 
			(1, w=getq(), $display("%t sampled q=%d, current q=%d, past q=%d, var w=%d", $time, $sampled(q), q, $past(q), w));
	endproperty 
	ap_test: assert property(test);  

	initial begin 
		repeat(200) begin 
			@(posedge clk); #3;   
			if (!randomize(a, qin) with 
					{ a dist {1'b1:=1, 1'b0:=3};
					  qin dist {[1:10]:=1, [20:30]:=2};
					}) `uvm_error("MYERR", "This is a randomize error")
					end 
					$stop; 
		end 
endmodule 	 

```

Sim results

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/6ecae83f06207a9a7f3132c909cee2ebc6eb3208.png)

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](http://goo.gl/JOfuEB)
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- [Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712](https://goo.gl/d10QHh)
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

---

<div class="post-metadata">

**Author:** ![Harshit](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/c57346/32.png) [@Harshit](https://verificationacademy.com/forums/u/Harshit)\
**Post date:** [September 23, 2017, 1:10pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/3 "2017-09-23T13:10:20Z")

</div>

@Ben  
Thanks for your inputs.

In which region immediate assertions are sampled and evaluated ?

---

<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:** [September 23, 2017, 3:26pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/4 "2017-09-23T15:26:01Z")

</div>

_In reply to [Harshit](https://verificationacademy.com/forums/t/sva-evaluation/33470/3):_

The signals in an immediate assertion are never sampled; they are evaluated at the point in the procedural process they appear.

The action block of a simple immediate assertion executes at that point as well. It’s the same an if-statement except you get the coverage recorded with pass/fail statistics.

The action block of a deferred immediate assertion gets postponed. This is to avoid glitches in combinational logic where the immediate assertion could get evaluated multiple times in the same time slot. Only the last evaluation of the assertion is considered.

---

<div class="post-metadata">

**Author:** ![samirxd](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@samirxd](https://verificationacademy.com/forums/u/samirxd)\
**Post date:** [September 6, 2021, 12:59pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/5 "2021-09-06T12:59:39Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/4):_

Hi Ben,

Can you explain why “%t sampled q=%d, current q=%d, past q=%d, var **w** =%d” is getting printed before “%t sampled q=%d, current q=%d, past q=%d, var **y** =%d” although it has ##0 delay ?

In assertion the $display will get evaluated in active region or re-active region?

---

<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:** [September 6, 2021, 5:44pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/6 "2021-09-06T17:44:24Z")

</div>

_In reply to [samirxd](https://verificationacademy.com/forums/t/sva-evaluation/33470/5):_

> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/5):_  
> Can you explain why “%t sampled q=%d, current q=%d, past q=%d, var **w** =%d” is getting printed before “%t sampled q=%d, current q=%d, past q=%d, var **y** =%d” although it has ##0 delay ?

NO, but I believe it is how the tool handles the printing.  
I tried the model at [Edit code - EDA Playground](https://edaplayground.com/x/MA4A)  
got what you expected, the “y” print before the “w” print

```verilog

# 210 sampled q= 30, current q= 30, past q= 27, var y= 30
# 210 sampled q= 30, current q= 30, past q= 27, var w= 10
# 250 sampled q= 25, current q= 25, past q= 9, var y= 25
# 250 sampled q= 25, current q= 25, past q= 9, var w= 2q

```

> In assertion the $display will get evaluated in active region or re-active region?

- In immediate assertions, the $display is evaluated at the point in the procedural process they appear. Thus,

```verilog

module m;
bit a, b, d, clk;
always_comb begin
a_ab: assert(a==b) else $display("%t a=%b, b=%b", $realtime, a, b);
// $display is evaluated in the Active Region.
end

```

- Concurrent assertion

```verilog

property p;
bit v;
(a, v=d) |-> ##1
(v, $display("%t EVALUATED IN OBSERVED REGION a=%b, b=%b", $realtime, a, b)) ##0 b;
endproperty
ap_p: assert property(@(posedge clk) p) else $display("%t ACTION BLOCK IN RACTIVE REGION : a=%b, b=%b", $realtime, a, b);

```

---

<div class="post-metadata">

**Author:** ![samirxd](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@samirxd](https://verificationacademy.com/forums/u/samirxd)\
**Post date:** [September 7, 2021, 7:18am UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/7 "2021-09-07T07:18:51Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/6):_

Thanks Ben.

---

<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:** [September 7, 2021, 8:22pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/8 "2021-09-07T20:22:37Z")

</div>

_In reply to [samirxd](https://verificationacademy.com/forums/t/sva-evaluation/33470/7):_

##0 is sequence concatenation indicating the beginning of the second sequence is in the same clock tick as the end of the first sequence. Since these are both single clock sequences, they are concurrently true .There is no implied ordering between the sequence match items. However within a list, the statements get executed in the order they appear. So you should write this as:

```verilog
property test;
		int y, w; 
		a |-> 
		   (1, y=q, $display("%t sampled q=%d, current q=%d, past q=%d, var y=%d", $time, $sampled(q), q, $past(q), y),
		       w=getq(), $display("%t sampled q=%d, current q=%d, past q=%d, var w=%d", $time, $sampled(q), q, $past(q), w));
endproperty

```

---

<div class="post-metadata">

**Author:** ![samirxd](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/c37758/32.png) [@samirxd](https://verificationacademy.com/forums/u/samirxd)\
**Post date:** [September 8, 2021, 2:54pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/9 "2021-09-08T14:54:13Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/sva-evaluation/33470/8):_

Thanks Dave.

---

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [March 20, 2022, 11:42am UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/10 "2022-03-20T11:42:42Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/9):_

Hi Ben ,

If I were to define the subroutine as ::

```verilog

       function automatic int getq(); 
		return k ; // Simply return ' k ' without defining variables .
	endfunction : getq

```

I observe the updated value of k is assigned to local variable w .

Are there any additional advantages of defining the variables within the subroutine as automatic ?

My understanding is that if the subroutine were to be called in parallel from  
multiple places each call will have their own copy .

So if I pass different values as input to the subroutine from different places  
at the same time , each invocation would return an appropriate value due to the automatic variables defined within the subroutine .

---

<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:** [March 20, 2022, 11:41pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/11 "2022-03-20T23:41:23Z")

</div>

_In reply to [hisingh](https://verificationacademy.com/forums/t/sva-evaluation/33470/10):_

> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/10):_

```verilog

function automatic int getq(); 
return k ; // Simply return ' k ' without defining variables .
endfunction : getq

```

I observe the updated value of k is assigned to local variable w .

```verilog

   function bit test();
    $display("%t sampled(w)= %b", $realtime, $sampled(w));
    $display("%t Observed(w)= %b",$realtime, w);
    return w;      
   endfunction
   property p; 
    bit v; 
    @(posedge clk) (a, v=test()) |-> b; // test(b);  
   endproperty 
   ap_p: assert property(p);  

```

Properties are executed in the Observed region. The function should return the value of w in the Observed Region, which could have been updated in the NBA Region.

 ![](https://verificationacademy.com/forums/uploads/default/original/1X/cb8cfee5f8c2a3ccad8d527710e543c9227cb6cc.png)

> Are there any additional advantages of defining the variables within the subroutine as automatic ?

NO. BTW, it is bad practice to do what you are proposing.

> My understanding is that if the subroutine were to be called in parallel from  
> multiple places each call will have their own copy .  
> So if I pass different values as input to the subroutine from different places  
> at the same time , each invocation would return an appropriate value due to the automatic variables defined within the subroutine .

Function will return the value seen in the Observed Region.  
Any, bad practice.

---

<div class="post-metadata">

**Author:** ![hisingh](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/h/97f17d/32.png) [@hisingh](https://verificationacademy.com/forums/u/hisingh)\
**Post date:** [March 25, 2022, 6:28pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/12 "2022-03-25T18:28:50Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/11):_

Hi Ben ,

I am a little confused about the clocking event ( @ posedge clk ) in the property A2C .

**Concurrent assertion is evaluated in Observed region whereas the event i.e @ posedge clk occurs in Active Region .**

So by Observed region the event trigger has passed by then .  
**So what triggers the property A2C if it’s being evaluated in Observed Region ?**

Can I say the clocking event triggers the property , but the expression is checked  
later in observed region using the values sampled in pre-poned region

---

<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:** [March 25, 2022, 7:07pm UTC](https://verificationacademy.com/forums/t/sva-evaluation/33470/13 "2022-03-25T19:07:28Z")

</div>

_In reply to [hisingh](https://verificationacademy.com/forums/t/sva-evaluation/33470/12):_

> _In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sva-evaluation/33470/12):_  
> I am a little confused about the clocking event ( @ posedge clk ) in the property A2C .  
> **Concurrent assertion is evaluated in Observed region whereas the event i.e @ posedge clk occurs in Active Region .**

Every clocking event has these main regions in order to emulate concurrency while using an evaluation machine that is sequential in operation.  
Thus, ap: assert property(@ (posedge clk) a |-\> b ); the simulator considers that clocking event (the @(posedge clk)) and before doing anything else stores the value of a and b (that’s the Preponed Region).  
The simulator then does other things in the other regions at the same time period. In other words, time stops. Following the completions of whatever needs to be done in the NBA, it stars pressing the assertion using those stored values in the Preponed region.  
Sorry, but saying _@ posedge clk occurs in Active Region_ does not make sense. @(posedge clk) is an event that starts the chain of things in these defined regions.

> So by Observed region the event trigger has passed by then .  
> **So what triggers the property A2C if it’s being evaluated in Observed Region ?**

All these regions are at the same time period. The split of regions is just to have a simulator do its calculations to emulate concurrency. When you watch a movie, let’s say a traffic accident, what do you see? 1) car coming, then person walking, then car coming then person walking, then accident. All these things occur at the same time, but you see them sequentially. So in movies, the emulation is to split the scene into Regions (or small scenes) to emulate concurrency.

> Can I say the clocking event triggers the property , but the expression is checked  
> later in observed region using the values sampled in pre-poned region

YES!
