# Constraint with Multiple array dependencies

**URL:** <https://verificationacademy.com/forums/t/constraint-with-multiple-array-dependencies/31867>\
**Category:** SystemVerilog\
**Tags:** dependencies, SystemVerilog, total-size, constraints, 2Darray\
**Created:** [May 27, 2016, 1:01pm UTC](https://verificationacademy.com/forums/t/constraint-with-multiple-array-dependencies/31867 "2016-05-27T13:01:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lakshmikanth\_t](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/l/d6d6ee/32.png) [@lakshmikanth\_t](https://verificationacademy.com/forums/u/lakshmikanth_t)\
**Post date:** [May 27, 2016, 1:01pm UTC](https://verificationacademy.com/forums/t/constraint-with-multiple-array-dependencies/31867/1 "2016-05-27T13:01:55Z")

</div>

I have two class member arrays:

rand bit [3:0] grp\_depth[`num_of_groups]; rand bit [15:0] sub_grp_enables[`num\_of\_sub\_groups]

now each group has all the sub\_groups with randomly enabled 16bits. each bit enabled means 4Bytes of space.

Now total such size needs to be within a given size. Want these grps and subgroups and number of elements in that group to be randomly selected.

theoretical requirement expression =

```verilog
for (int i=0; i<num_of_groups;i++)
  for (int j=0; j<num_of_sub_grps;j++)
    for (int k=0; k<15; k++)
      if (sub_grp_enables[j][k]==1) total_size+=grp_depth[i];

```

this size should be less than 512KB

So how do i write random constraint to enable this size restriction while generating grp\_depth and grp\_enables randomly?

I am trying to write something like this if i solve the expression taking out the common groups. But i cannot use … in the real code :(

```verilog
 constraint RAM_SIZE_c {

 ($countones(sub_group[0]) + $countones(sub_group[1])+...+$countones(sub_group[`num_of_sub_groups]) )*
  (grp_depth[0]+grp_depth[1]+....+grp_depth[num_of_groups]) <= 512KB

}

```

Any good suggestions?

Thanks and Regards,  
Lakshmi Kanth

---

<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:** [May 27, 2016, 3:43pm UTC](https://verificationacademy.com/forums/t/constraint-with-multiple-array-dependencies/31867/2 "2016-05-27T15:43:22Z")

</div>

_In reply to [lakshmikanth\_t](https://verificationacademy.com/forums/t/constraint-with-multiple-array-dependencies/31867):_  
But you can use … using the sum() method.

```verilog
 constraint RAM_SIZE_c {
         (sub_group.sum() with ($countones(item)) * grp_depth.sum() with (int'(item)) )
          <= 512KB ;}

```
