Multi-dimensional arrays

Hi,

Can anybody explain how I can make a queue of associative arrays and parse them to see whether the element exists?
Basically I need an 3 associative arrays.

I have written something like:

module test;
localparam WIDTH_BITS = 32;
localparam DEPTH_BITS = 6;

bit[WIDTH_BITS-1:0] index[3][DEPTH_BITS-1:0];

initial begin

index[0][8] = 32'hABCD_0123; 
index[1][7] = 32'hABCD_0123; 
index[2][5] = 32'hABCD_0123; 

if(index[0].exists(8)) begin
  $display("element: %h found for sub-index 0 for Index: %0d",index[0][8],8);
end else
  $display("Element not found...");

end

endmodule

But, I get an error, like the one below:

Error-[XMRE] Cross-module reference resolution error
queue_of_assoc_array.sv, 16
Error found while trying to resolve cross-module reference.
token ‘exists’. Originating module ‘test’.
Source info: index[0].exists(8)

(1) What is wrong with the above code ?
(2) In general how do we know in a multi-dimensional array which dimension is for what ?

I would also like to know how to build, load, parse data from , queue of queues, queue of associative/dynamic-arrays and vice versa or any combination of these.

Can anyone explain with an example ? or point me to a paper or source where this is explained with an example?

Thanks,
Madhu

Hi,

you are using a normal array and not an associated one.

Try to change your array declaration to something like:


bit[WIDTH_BITS-1:0] index[3][*];

I hope this helps.

Bye,

Christoph

In reply to frodus:

We strongly recommend declaring a type for the associative array index, rather than using the [*] wildcard index. A wildcard index is very restrictive if you try to use it with other constructs like a foreach loop. What you probably meant is

typedef bit [DEPTH_BITS-1:0] depth_t;
bit[WIDTH_BITS-1:0] index[3][depth_t];

And if you really wanted a queue of an associative arrays, that would be declared as

bit[WIDTH_BITS-1:0] index[$][depth_t];

In reply to dave_59:

Thank you Christoph and dave for your answers.
But in general how do you determine, which argument is for what ?
I mean if you have something like,

k index[n][m]

is it always type n of m items of type k ?

In reply to mseyunni:

Hi Dave,

How would you register such a structure without overloading the copy() function?

Thanks,

In reply to ndalia:

mseyunni,

Yes, section_7.4.5 Multidimensional arrays_ of the 1800-2012 LRM explains this, although that section was written with examples that only show fixed sized arrays. You can substitute a fixed range (e.g. [10:0] or [11]) for an associative array ([int]) or queue ([$]). It’s better to think of arrays of arrays instead of mufti-dimentional arrays.

ndalia,

If by “register” you mean to use one of the `uvm_field macros, we strongly recommend that you do not use them because of the poor performance they introduce, confusion over auto-config, as well as the fact that they are limited in supporting a lot of SV types. See MacroCostBenefit | Verification Academy

Dave

In reply to dave_59:

Hi Dave,

Thanks for the answer. Referring to ndalia's question on registering the multi-dimensional arrays in config db you said there is a performance issue. Sometime back, I had posted a question https://verificationacademy.com/forums/uvm/generating-sequences-based-activity-other-interfaces

regarding passing some information an array / queue, which needs to be referred to modify the stimulus. If you can please refer and comment on whether there is a performance impact with the suggested approach, I would be grateful.

Thanks,
Madhu