Constraining multidimensional queue

Hi all,

I have a 2-dimensional queue that I’d like to fill with incrementing values. In my attempts, I get an out of bounds error or an Invalid X or Z in state expression with a constraint.

I’m using this just to load the queues with simple incrementing data need while I debug other code issues.

Goal: my queue should look like this:

frame_data[0][0] = 0
frame_data[0][1] = 1
frame_data[1][0] = 2
frame_data[1][1] = 3
... 

Assume that the 2nd index value is consistent, so frame_data[0].size = frame_data[1].size, etc.
I tried to use the 'const cast, but apparently I do not fully understand how it is used.

E.g.

     if(!sf_trans.randomize() with {
        sf_trans.frame_data.size() == local::frame_count;

        // set frame size
        foreach(frame_data[i]) 
          sf_trans.frame_data[i].size() == local::frame_dword_count;

        frame_data[0][0] == 0;  

        foreach(frame_data[i,j]) {
            if( (i+j)>0  &&  i+j < ( (frame_data.size()-1 + frame_data[0].size()-1) ) )
              frame_data[i][j] == const'(frame_data[i][j])+1;
        }

Thank you for any suggestions,
Brian

In reply to BrianK:

The const’(expr) cast would be the value the expr has before calling randomize. Just calculate the value with the i and j index values.

if(!sf_trans.randomize() with {
        frame_data.size() == local::frame_count;
 
        // set frame size
        foreach(frame_data[i]) frame_data[i].size() == local::frame_dword_count;
 
        foreach(frame_data[i,j]) 
              frame_data[i][j] == local::frame_dword_count*i + j;
 }


class d_queue;
  rand bit [7:0] q[$][$];
  constraint d_q {
    q.size ==10;
  
    foreach (q[i]) q[i].size ==2;
    foreach (q[i,j]) q[i][j] == (2*i)+j;
  }
  
 
  
endclass

module tb;
  d_queue a1;
  
  initial begin
    a1 = new();
    if (!a1.randomize()) $display ("Error");
    $display ("%p",a1.q);
   
    
  end
  
  
endmodule


In reply to rag123:

Thanks Rag123, works well. I appreciate it.

In reply to dave_59:

Thanks for the ‘const’ explanation Dave,