【问题标题】:How to create random dynamic 2D arrays in SystemVerilog?如何在 SystemVerilog 中创建随机动态二维数组?
【发布时间】:2016-11-21 16:00:52
【问题描述】:

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

class packet;
    rand int unsigned len;
    rand byte data[];

    constraint size_con {
        len < 2000;
        data.size = len;
    }
endclass: packet

但我不知道如何使用随机二维动态数组?

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;

【问题讨论】:

    标签: system-verilog


    【解决方案1】:

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

       constraint size_con {
            width  inside {[8:4096]};
            height inside {[8:2048]};
            data.size == width;
            foreach (data[ii]) data[ii].size == height;
        }
    

    【讨论】:

      猜你喜欢
      • 2015-07-15
      • 2011-02-12
      • 1970-01-01
      • 2013-05-02
      • 2013-02-22
      • 2011-08-14
      • 2016-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多