从 ASIC 验证应用程序的角度将 class 成员作为参数传递给 randomize() 函数的用例

Use cases for Passing class members as arguments to randomize() function from ASIC verification application perspective

此外,在什么情况下需要传递 "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

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.

class YCA extends CA;
  constraint y5 {y==5;}
endclass 

为了回答您的最后一个问题,randomize(null) 仅用于检查所有随机变量的当前值是否满足约束条件,而不实际随机化任何内容。这对于调试很有用。