Reputation: 3388
I know how to create a random dynamic array in SystemVerilog:
class packet;
rand int unsigned len;
rand byte data[];
constraint size_con {
len < 2000;
data.size = len;
}
endclass: packet
but I can't figure out how to use random 2d dynamic array?
class video_frame;
rand int unsigned width;
rand int unsigned height;
rand int unsigned data[][];
constraint size_con {
width >= 8;
width <= 4096;
height >= 8;
height >= 2048;
// How to constraint data.size to be [height, width]
}
endclass: video_frame;
Upvotes: 0
Views: 2883
Reputation: 42698
You need to realize that SystemVerilog has arrays of arrays which are not the same as multi-dimensional arrays. This means you have a dynamic array where each element is another dynamic array. So you need to constrain the size of each element.
constraint size_con {
width inside {[8:4096]};
height inside {[8:2048]};
data.size == width;
foreach (data[ii]) data[ii].size == height;
}
Upvotes: 5