How to create random dynamic 2D arrays in SystemVerilog?

匿名 (未验证) 提交于 2019-12-03 01:09:02

问题:

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; 

回答1:

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;     } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!