system-verilog - 从 ASIC 验证应用程序角度将类成员作为参数传递给 randomize() 函数的用例
问题描述
另外,在哪种情况下需要传递“null”参数?请参阅 SV LRM 中的第 18.11 节。
class CA;
rand byte x, y;
byte v, w;
constraint c1 { x < v && y > w );
endclass
CA a = new;
a.randomize(); // random variables: x, y state variables: v, w
a.randomize( x ); // random variables: x state variables: y, v, w
a.randomize( v, w ); // random variables: v, w state variables: x, y
a.randomize( w, x ); // random variables: w, x state variables: y, v
如何在测试平台中使用此功能或此语言功能的用例是什么?
解决方案
假设您有一个特定的测试,需要将变量y
固定为 5。SystemVerilog 为您提供了4种不同的方法来完成此任务!
使用上面显示的方法,您可以y=5
在调用 randomize 之前进行设置:
y=5;
a.randomize( x ); // y becomes a state variable
实际上,除非您要处理的随机变量非常少,否则很少使用此方法。我从未见过有人尝试以这种方式随机化非随机变量。
另一种方法是设置 rand_mode
y=5;
a.y.rand_mode(0); // y becomes a state variable
a.randomize();
如果需要,您必须记住设置 rand_mode(1)。然而,最简单的方法是使用with
约束。
a.randomize() with {y==5;};
但是上述所有方法的问题是它需要修改程序代码。面向对象编程(OOP)方法正在扩展类。
class YCA extends CA;
constraint y5 {y==5;}
endclass
并回答您的最后一个问题,randomize(null)
仅用于检查所有随机变量的当前值是否满足约束,而无需实际随机化任何内容。这对于调试很有用。
推荐阅读
- python - 将 Flatten 层从 PyTorch 转换为 Tensorflow - 等效于 start_dim 和 end_dim
- python - 如何在 python 中使用 plotly 绘制累积数据?
- internationalization - react-intl:使用 .js 文件而不是 .json 文件进行消息存储
- powerbi - 通过编写 DAX 公式查找每个覆盖的通话持续时间
- reactjs - 如何使用钩子进行映射
- assembly - 当我在 nasm 中使用它们时,真正代表什么符号和变量?
- svg - 聚焦、模糊、聚焦、聚焦,不适用于 D3 和 SVG 元素?有替代方案吗?
- raspberry-pi - 将 Raspberry Pi 4 与 EM18 阅读器模块连接
- swift - 从核心数据迁移
- python - gzip压缩的jsonlines文件在python中读写