如何在 SystemVerilog 中创建随机动态二维数组? [英] How to create random dynamic 2D arrays in SystemVerilog?

查看:66
本文介绍了如何在 SystemVerilog 中创建随机动态二维数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何在 SystemVerilog 中创建一个随机动态数组:

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;

推荐答案

您需要意识到 SystemVerilog 具有与多维数组不同的数组数组.这意味着您有一个动态数组,其中每个元素都是另一个动态数组.所以你需要限制每个元素的大小.

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

这篇关于如何在 SystemVerilog 中创建随机动态二维数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆