IMPORTANT NOTICE: Please be advised that the Verification Academy Forums will be offline for scheduled maintenance on Sunday, April 6th at 2:00 US/Pacific.
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
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
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] ?