Calling Functions In Unique Constraint

Hi all ,

I am trying the following Code , but for some reason it doesn’t even Compile .



// Sample 1 

class A # ( int A , B = A ) ; // In case 2nd Argument isn't Given 

rand int unsigned Arr [A]**;

typedef int unsigned q_return [$:(A*B)-1] ; // TO Return Unpacked Array ( Queue ) from a Function 


constraint UNIQ {   
                    foreach(Arr[A,B])
                  {
                      .... // Some Logic When Unique Constraint Should be Applicable 
                   unique { Entire_Block( A , B , Arr )  } ; // Calling a Function in Unique Constraint 
                   
                   }
                }

function q_return Entire_Block ( input int a , b , input int unsigned Arr[A][B] ) ;
    
    ..  // Some Logic Used when I want Values to be Pushed  
    Entire_Block.push_back(..)



endfunction 


endclass


I get the Following Message ::

Simulator 1 => Error :: Invalid argument ‘Entire_Block(this,Row,Col,this.Arr)’ specified for ‘unique’ constraint

Simulator 2 => Error :: Non-constant expression .
The following expression should be a constant.
Expression: ((Row * Col) - 1) // [b]Points to typedef Statement**

[Q1] Is there a Restriction on Calling Functions inside Unique Constraint ?
A Unique Constraint does accept a Queue , Unpacked Array inside it . My Code returns the Queue instead of Explicitly Mentioning it

I then try the following Code





// Sample 2 

class A # ( int A , B = A ) ; // In case 2nd Argument isn't Given 

rand int unsigned Arr [A]**;
rand int unsigned q[$:(A*A)-1][$:(B*B)-1] ;

typedef int unsigned Unpkd_return [0:(B*B)-1] ; // TO Return Unpacked Array from a Function 


constraint UNIQ {   
                    foreach(Arr[A,B])
                  {
                      .... // Some Logic When Constraint Should be Applicable 

                    q[A] ==  Entire_Block( A , B , Arr )  ; // Shows Error Here !!  
                   
                   }
                }

function Unpkd_return Entire_Block ( input int a , b , input int unsigned Arr[A][B] ) ;
    int Index ;
      // Some Logic Used when I want Values to be Written   
          for ( int i = 0 ; i < A ; i ++ )
          begin
            for ( int j = 0 ; j < B ; j ++ )
            begin
 
              Entire_Block[Index] = (Arr[a+i][b+j]);
              Index++; 

            end
         end
      

endfunction 


endclass


I get the Following Message ::

Simulator 1 :: Illegal non-integral expression in random constraint.

Simulator 2 => Error :: Non-constant expression .
The following expression should be a constant.
Expression: ((Row * Col) - 1) // [b]Points to typedef “Unpkd_return” Statement**

[Q2] Is the Statement " q[A] == Entire_Block( A , B , Arr ) " incorrect ?

Regards ,
AGIS

In reply to Etrx91:

The LRM states that the unique constraint needs a list of variables. A function call is not a variable. And you cannot have a function with a non integral return value as all expressions must be integral. You will probably have to break your problem into two separate randomizations.

In reply to dave_59:

Hi Dave ,

I got the " function call is not a variable " part but I am still confused regarding " all expressions must be integral. "

I am not sure what exactly is considered an integral expression
[ Have gone through 6.11.1 Integral types in LRM ]

LRM 18.4 says :: " The solver can randomize singular variables of any integral type "

I understand that Unpacked Arrays are not Integral types . but then still I can have 2D Unpacked arrays as random variables


 // Sample Code 

rand int unsigned q1[$] ;
rand int unsigned q2[$][$] ;

constraint Size1 { q1.size() == 3 ;                     // Statement 1 
                       
                         foreach(q1[i])
                       q1[i] inside { [1:10] } ;        // Statement 2                   
                  }

constraint Sizes_VAL {  q2.size() == 3 ;               // Statement 3
                    
                       foreach(q2[i])
                       q2[i].size() == 2 ;             // Statement 4   
                         
                        foreach(q2[i,j]
                         q2[i][j] inside { [1:10] } ;  // Statement 5 
                  
                    }

[Q1] Can I say that Statements 1 -5 are all integral Expressions ?

[Q2] Specially q2 which is 2D Queue .
(a) Is q2[Only_1st_Dimension] considered an integral expression ?

(b) q2[One][Two] points to a leaf element which is integral type , so I believe it is
considered as an integral type .

[Q3] " You will probably have to break your problem into two separate randomizations. "

 Could you suggest a way how to go about it ? . 
 My further motive in Sample 2 above is to use q[1st_Dimension] inside a unique constraint 

Thanks ,
AGIS