Queues of Dynamic Arrays

Hi,

Are queues of dynamic arrays allowed in either SystemVerilog or VMM? For example:

logic [7:0] Qda [$];

if that’s allowed, how do I initialize the dimension of the dynamic arrays at run-time? Would this still work:

Qda = new[10];

and lastly, suppose I have an dynamic array of the same size:

logic [7:0] DA;
DA = new[10];

how would I push_back this into Qda, essentially adding one more element to the queue? Thanks in advance!

In reply to jin_hsueh:
Yes you can have queues of dynamic arrays in SystemVerilog, but remember that you are declaring an array of an array, not really a multidimensional array. The difference is each dynamic array element in the queue can have a different dynamic array size.

module top;
   logic [7:0] Qda[$] []; // this is a Queue -> of dynamic arrays -> of logic [7:0]
   logic [7:0] DA[]={1,2,3};
   initial begin
      Qda = '{10{ {} }}; // initializes a Queue of 10 empty dynamic arrays
      Qda.push_back(DA); // pushes the eleventh Queue element by copying the DA {1,2,3}
      $display("%p",Qda);
   end
endmodule

That works. Thank you very much!

In reply to jin17:

That works. Thank you very much!

Hi Dave,

Now I’m running into an issue trying to assign a slice of the array above. Instead of

logic [7:0] DA;

I had:

logic [15:0] DA2;

But the following assignment would generate a compile error:

DA2[11:0] = Qda.pop_front();

Error- Incompatible complex type

Incompatible complex type assignment
Type of source expression is incompatible with type of target expression.
Mismatching types cannot be used in assignments, initializations and
instantiations. The type of the target is ‘logic[15:0][]', while the type of the source is 'logic[7:0]’.
Source Expression: this.Qda.pop_front


My intention is to pop the first dynamic array off Qda, and assign it to DA2. But since the packed dimensions are different, I want to put each byte of Qda’s lowest-indexed dynamic array into the LSB’s of each word of DA2. What’s the best way to accomplish this? Thanks again in advance.

In reply to jin17:
Assignments only work with contiguous sets of bits. You will need to pop into an intermediate dynamic array variable, and then use a foreach loop.

module top;
   logic [7:0] Qda[$] []; // this is a Queue -> of dynamic arrays -> of logic [7:0]
   logic [7:0] DA[]={1,2,3};
   logic [7:0] temp_da[];
   logic [15:0] DA2[];
   initial begin
      Qda = '{10{ {} }}; // initializes a Queue of 10 empty dynamic arrays
      Qda.push_back(DA); // pushes the eleventh Queue element by copying the DA {1,2,3}
      //...
      temp_da = Qda.pop_front();
      DA2 = new[temp_da.size];
      foreach(DA2[ii]) DA2[ii] = temp_da[ii];
      $display("%p",DA2);
   end
endmodule




In reply to dave_59:

You are good. Thanks again!

In reply to dave_59:

Dave :
I would like to confirm it
logic [7:0] Qda[] []; this is a**Queue -> of dynamic arrays -> of logic [7:0]** ? logic [7:0] Qda[] [];
this is adynamic array → of Q → of logic [7:0] ?

Thanks

In reply to VE:
Try using
.push_back()
to confirm.