Applyig Unique Constraint to 2D Unpacked Array

Hi all ,

I have the following Code ::



class A;

rand bit [2:0] B [][];

constraint UNIQ { unique { B } ; }

constraint SIZE1 { B.size() inside { [1:8] } ; }

constraint SIZE2 {     foreach(B[i])
                       B[i].size() inside { [1:8] } ;
                  }



Now I want to add another constraint such that Unique Constraint doesn’t fail i.e
B[8][1] , B[1][8] , B[4][2] , B[2][4] are all valid Scenarios since they all have 8 elements in them

The additional constraint must ensure that sum of the sizes of the 2 Dimensions is exactly 8

Example ::



rand int unsigned sum1 ;

constraint SUM { 
                   foreach(B[i,j])
                   sum1 = sum1 + 1 ; // THIS WOULD BE AN ERROR !! 
               }

constraint SUMM { sum1 == 8 ; }
                    

Regards,
AGIS

In reply to Etrx91:

constraint c_dim { B.sum() with (item.size()) == 8;}