首页 > 解决方案 > 从 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

如何在测试平台中使用此功能或此语言功能的用例是什么?

标签: system-verilog

解决方案


假设您有一个特定的测试,需要将变量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)仅用于检查所有随机变量的当前值是否满足约束,而无需实际随机化任何内容。这对于调试很有用。


推荐阅读