# SV Assertions for Arbiter priority

**URL:** <https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, Arbiter-priority, assertion\
**Created:** [July 18, 2014, 5:41pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722 "2014-07-18T17:41:28Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vignesh\_Raghavan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vignesh\_Raghavan](https://verificationacademy.com/forums/u/Vignesh_Raghavan)\
**Post date:** [July 18, 2014, 5:41pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/1 "2014-07-18T17:41:28Z")

</div>

Hi,

If I have to test a priority encoded arbiter with say, 4-inputs (request signals) and 4-outputs (grant signals), What assertions are required for verifying this arbiter?

---

<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:** [July 19, 2014, 7:28pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/2 "2014-07-19T19:28:30Z")

</div>

The following is a generalized solution for a large vector up to 30 bits (i.e., 29:0]).  
The concern for 32 bits is that setting v[31]to 1’b1 creates a negative number and would cause error in my req \< v. One solution for larger vectors would be to use time data type, which is a 4-state data type, 64-bit unsigned integer.

```auto
module arbiter;
//If I have to test a arbiter encoded arbiter with say, 4-inputs (request signals) and 4-outputs (grant signals), 
//What assertions are required for verifying this arbiter?
	bit[15:0] req, grnt;
	bit clk;
	
  generate for (genvar i=0; i<=15; i++) 
    begin
      property p_arbiter; 
        bit[16:0] v; 
         (req[i]==1'b1, v=0, v[i+1]=1'b1) ##0 req < v |-> 
          grnt[i]==1'b1 ##0 $onehot(grnt);
      endproperty : p_arbiter
      ap_arbiter: assert property(@(posedge clk) p_arbiter); 
     end 
  endgenerate
  ap_zero_req: assert property(@(posedge clk) req==0 |-> grnt==0); 
endmodule
// bit 1111 11
// 5432 1098 7654 3210
//-----------------------------------
// req = 0000_0000_0011_1011
// grnt= 0000_0000_0010_0000
// v = 0000_0000_0000_0010 -- i==0 req[0]==1, req > v, thus vacuous 
// v = 0000_0000_0000_0100 -- i==1 req[1]==1, req > v, thus vacuous 
// v = 0000_0000_0000_1000 -- i==2 req[2]==0, thus vacuous 
// v = 0000_0000_0001_0000 -- i==3 req[3]==1, req > v, thus vacuous 
// v = 0000_0000_0010_0000 -- i==4 req[4]==1, req > v, thus vacuous 
// v = 0000_0000_0100_0000 -- i==5 req[5]==1, req < v, thus nonvacuous 
// v = 0000_0000_1000_0000 -- i==6 req[6]==0, thus vacuous 
// v = 0000_0001_0000_0000 -- i==7 req[7]==0, thus vacuous

```

## Note: I did not test this code, but I believe that it should work. Compiles OK.

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- SystemVerilog Assertions Handbook 3rd Edition, 2013 ISBN 878-0-9705394-3-6
- 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 0-9705394-2-8
- 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:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [July 20, 2014, 3:54am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/3 "2014-07-20T03:54:53Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/2):_

Note: the v=0 (below) is not really necessary and can be deleted since v is initialized to 0 anyway.  
Making v=0 clarifies the intent.  
(req[i]==1’b1, v=0, v[i+1]=1’b1) ##0 req \< v |-\>

Thus, this would be OK too  
(req[i]==1’b1, v[i+1]=1’b1) ##0 req \< v |-\>  
Ben

---

<div class="post-metadata">

**Author:** ![Vignesh\_Raghavan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vignesh\_Raghavan](https://verificationacademy.com/forums/u/Vignesh_Raghavan)\
**Post date:** [July 20, 2014, 5:07am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/4 "2014-07-20T05:07:41Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/3):_

Hi Ben,

The above logic seems ok to verify a priority-encoded arbiter.

- Only 1 grant is active in a clock cycle.
- The active grant corresponds to the (higher numbered bit in) active request.
- No grant is issued if no request is active.  
Here, a particular active request will remain active until it sees a corresponding active grant in the sampling clock edge.

As I understand, Since at every sampling clock, the local variable v to the property is created newly and used for asserting if the property holds, hence, v will be initialised to 0 when bit[16:0] v; statement is executed. By default, SV assigns ‘0’ to 2-state variables (here, bit[16:0] v).

Is that the reason behind why we can ignore v=0 in the property expression?

---

<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:** [July 20, 2014, 5:25am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/5 "2014-07-20T05:25:48Z")

</div>

_In reply to [Vignesh Raghavan](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/4):_

> As I understand, Since at every sampling clock, the local variable v to the property is created newly and used for asserting if the property holds, hence, v will be initialised to 0 when bit[16:0] v; statement is executed. By default, SV assigns ‘0’ to 2-state variables (here, bit[16:0] v).  
> Is that the reason behind why we can ignore v=0 in the property expression?

The short answer is YES.  
The formal answer is from 1800, specifically,

> 16.8.2 Local variable formal arguments in sequence declarations  
> In general, a local variable formal argument behaves in the same way as a local variable declared in an  
> assertion\_variable\_declaration. The rules in 16.10 for assigning to and referencing local variables,  
> including the rules of local variable flow, apply to local variable formal arguments with the following  
> provisions:  
> Without further specification, the term local variable shall mean either a local variable formal  
> argument or a local variable declared in an assertion\_variable\_declaration.  
> — At the beginning of each evaluation attempt of an instance of a named sequence, **a new copy of each  
> of its local variable formal arguments shall be created.**

Ben Cohen  
[SystemVerilog.us](http://SystemVerilog.us)

---

<div class="post-metadata">

**Author:** ![Vignesh\_Raghavan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vignesh\_Raghavan](https://verificationacademy.com/forums/u/Vignesh_Raghavan)\
**Post date:** [July 20, 2014, 7:00am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/6 "2014-07-20T07:00:23Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/5):_

Thanks Ben…

---

<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:** [August 9, 2014, 1:29am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/7 "2014-08-09T01:29:21Z")

</div>

_In reply to [Vignesh Raghavan](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/6):_

Another solution, simpler, but without concurrent assertions.

```auto
module arbiter; 
//If I have to test a arbiter encoded arbiter with say, 4-inputs (request signals) and 4-outputs (grant signals), 
//What assertions are required for verifying this arbiter? 
   bit[15:0] req, grnt; 
   bit clk; 
    
 always @(posedge clk) begin 
    for (int i=15; i< 0; i--) begin 
       if (req[i]) 
          begin 
            assert(grnt[i]==1'b1 && $onehot(grnt)); // immediate assertion 
            break; 
          end 
    end 
  end 

  ap_zero_req: assert property(@(posedge clk) req==0 |-> grnt==0);

```

---

<div class="post-metadata">

**Author:** ![Vignesh\_Raghavan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vignesh\_Raghavan](https://verificationacademy.com/forums/u/Vignesh_Raghavan)\
**Post date:** [August 9, 2014, 1:21pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/8 "2014-08-09T13:21:37Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/7):_

Hi Ben,

This looks great. I guess there is no necessity for a break statement inside the begin…end block.  
Because we are checking grnt[i] == 1’b1 and at the same time, if gnt itself is one-hot encoded. So, Even if other iterations run, I hope it should not affect our results. Or does it?

---

<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:** [August 9, 2014, 3:22pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/9 "2014-08-09T15:22:27Z")

</div>

_In reply to [Vignesh Raghavan](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/8):_

> I guess there is no necessity for a break statement inside the begin…end block.

You’re correct, however, the break gives you the following advantages:

1. It clarifies the requirements in that once you find the high bit being true, the lower order bits are irrelevant, or don’t care.
2. Efficiency.  
Ben [SystemVerilog.us](http://SystemVerilog.us)

---

<div class="post-metadata">

**Author:** ![Vignesh\_Raghavan](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/ecccb3/32.png) [@Vignesh\_Raghavan](https://verificationacademy.com/forums/u/Vignesh_Raghavan)\
**Post date:** [August 9, 2014, 3:47pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/10 "2014-08-09T15:47:07Z")

</div>

_In reply to [ben@SystemVerilog.us](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/9):_

So True, Ben.

One more important reason to add break statement is, which i didn’t think of before -

if more than 1 request is asserted simultaneously, the assertion in begin…end block will pass for highest priority request. But, If break statement is not used, the assertion will fail for the lower priority requests (which is valid but we do not want to see redundant errors), as the grant is high only corresponding to highest priority request.

Thanks,  
Vignesh

---

<div class="post-metadata">

**Author:** ![devil47](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/d/71c47a/32.png) [@devil47](https://verificationacademy.com/forums/u/devil47)\
**Post date:** [January 11, 2020, 5:54am UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/11 "2020-01-11T05:54:46Z")

</div>

Another Solution from SVA cookbook videos. Adding so that it is indexed.  
[SVA Cookbook Link](https://verificationacademy.com/sessions/cookbook-examples/video/23?play=1)  
Assumes the fixed priority 0 \> 1 \> 2 \> 3 \> 4 \> 5

If a high priority req[i] is asserted then gnt[i] is not seen before the low priority gnt[j], such a sequence should not be seen.

```verilog

property priority_arb(i,j);
   @(posedge clk) disable iff(rst)
      not( ((j>i) && req[i]) ##1 ( !gnt[i] throughout (gnt[j][->1]) ) );
endproperty

generate
genvar i,j;
   for(i=0; i<6; i++)
      for(j=0; j<6; j++)
          assert property(priority_arb(i,j));
      end
    end
endgenerate

```

Have not tested it though!!!

---

<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:** [January 11, 2020, 9:54pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/12 "2020-01-11T21:54:55Z")

</div>

_In reply to [devil47](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/11):_

Tested your code with the generate. It failed to verify a $onehot(gnt). See

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

```verilog

property priority_arb(i,j); // BAD by itself, needs ap_gnt 
   @(posedge clk) // disable iff(rst)
   not( ((j>i) && req[i]) ##1 ( !gnt[i] throughout (gnt[j] && $countones(gnt)==1[->1]) ) );
endproperty
generate begin 
        genvar i, j; 
        for (i = 0; i<=2; i++) begin 
            for (j = 0; j<=2; j++) begin 
                assert property (priority_arb(i,j)); 
            end 
        end 
    end 
endgenerate 

```

In general, I prefer to use the **not** operator on a property of a single simple expression rather than a sequence because it is harder to understand. Also, the **not** says that something should Not happen, but it does not express what you expect to happen.

```verilog

bit[2:0] req, gnt; // req[0] is high priority *****
// the following assertions seem to work 
 ap000: assert property(req[0] |=> gnt== 3'b000 [*0:$] ##1 $onehot(gnt) && gnt[0]);    
    
    ap010: assert property(req[1] |=> gnt<= 3'b010 || gnt==3'b000 [*0:$] ##1 $onehot(gnt) && gnt[1]);  
// No higher priority gnt provided after req[1] 
    
    ap100: assert property(req[2] |=> gnt<=3'b100 || gnt==3'b000 [*0:$] ##1 $onehot(gnt) && gnt[2]); 
// No higher priority gnt provided after req[2] 
    

```

In the above assertions, the higher priority fails when gnt is given to a lower priority

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

// my testbench  
[http://systemverilog.us/vf/priority03.sv](http://systemverilog.us/vf/priority03.sv)

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [http://cvcblr.com/home](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

* * *

1. SVA Alternative for Complex Assertions  
[https://verificationacademy.com/news/verification-horizons-march-2018-issue](https://verificationacademy.com/news/verification-horizons-march-2018-issue)
2. [SVA: Package for dynamic and range delays and repeats - SystemVerilog - Verification Academy](https://verificationacademy.com/forums/systemverilog/sva-package-dynamic-and-range-delays-and-repeats)
3. 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)

---

<div class="post-metadata">

**Author:** ![Mechanic](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mechanic](https://verificationacademy.com/forums/u/Mechanic)\
**Post date:** [April 25, 2020, 5:10pm UTC](https://verificationacademy.com/forums/t/sv-assertions-for-arbiter-priority/29722/13 "2020-04-25T17:10:45Z")

</div>

Hi ,

In addition to the above scenario if i want to check for other requests also gnt is asserted or not ?is it possible using assertions?

scenario: Once after servicing the priority interrupts i need to check other interrupts also got serviced or not.

generate for (genvar i=0; i\<=15; i++)  
begin  
property p\_arbiter;  
bit[16:0] v;  
(req[i]==1’b1, v=0, v[i+1]=1’b1) ##0 req \< v |-\>  
grnt[i]==1’b1 ##0 ($countones(req)==$countones(gnt));  
endproperty : p\_arbiter  
ap\_arbiter: assert property(@(posedge clk) p\_arbiter);  
end  
endgenerate

Please let me know

Thanks in advance
