【问题标题】:How to control the property rand_mode in a SystemVerilog class?如何控制 SystemVerilog 类中的属性 rand_mode?
【发布时间】:2022-12-07 20:38:19
【问题描述】:

假设有一个类A,如下所示:

class A;
rand logic [3:0] a;
rand logic [3:0] b;
rand logic [3:0] c;
constraint a_const{
    a<'h4;
}
constraint b_const{
    b<'h4;
}
endclass

当我使用时:

A at = new();
at.b_const.constraint_mode(0);
assert(at.randomize());

b 也是随机的。但是,我不想这样。

有没有办法只随机化a而不随机化bc

因为一个类中可以有很多逻辑,所以有时我只想随机数其中的一些。将一些逻辑放在一个类中,如 A,而将一些逻辑放在其他类 B 中是解决方案之一,但它太复杂了。

【问题讨论】:

    标签: class constraints system-verilog


    【解决方案1】:

    如果您只想随机化类中的 rand 变量之一,则可以将变量传递给 randomize 函数:

    assert(at.randomize(a));
    

    或者,正如您在问题标题中提到的,您可以使用 rand_mode 禁用单个类变量的随机化:

    at.b.rand_mode(0);
    at.c.rand_mode(0);
    assert(at.randomize());
    

    请参阅 IEEE 标准 1800-2017,第 18.8 节使用 rand_mode() 禁用随机变量.

    使用上述任何一种方法,只有a 会被随机化。


    我怀疑您期望b_const.constraint_mode(0) 禁用变量b 的随机化。该行只是禁用了命名的constraint,使b不受约束。这意味着 b 将被随机化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多