我知道如何在 SystemVerilog 中创建随机动态数组:
class packet;
rand int unsigned len;
rand byte data[];
constraint size_con {
len < 2000;
data.size = len;
}
endclass: packet
Run Code Online (Sandbox Code Playgroud)
但我不知道如何使用随机二维动态数组?
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;
Run Code Online (Sandbox Code Playgroud)
您需要意识到 SystemVerilog 具有与多维数组不同的数组数组。这意味着您有一个动态数组,其中每个元素都是另一个动态数组。所以你需要限制每个元素的大小。
constraint size_con {
width inside {[8:4096]};
height inside {[8:2048]};
data.size == width;
foreach (data[ii]) data[ii].size == height;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2729 次 |
| 最近记录: |