基于 std::randomize 和 class 的随机化之间的区别

difference between std::randomize and class based randomize

选项A和选项B有什么区别

选项A:

sucess = std::randomize(type_l) with { 
   type_l inside { A ,B ,C};
   type_l dist { A := 2 ,B := 5 ,C := 4 }; 
};

if(  sucess == 0 ) begin
   `uvm_fatal("TEST_CFG", "type_l randomization failed")
end

选项 B:

class gen_type;

   enum_type type_l;

   constraint type_c{ 
      type_l inside { A ,B ,C};
      type_l dist { A := 2 ,B := 5 ,C := 4 }; 
   };       
endclass

此处选项A是内联约束的一个示例,其中可以随机化class或模块或程序块的局部变量,而无需将其声明为randrandc

选项B是对象变量随机化的一个例子。在此构造中,您必须声明一个变量,您希望将其随机化为 randrandc(此处,您尚未将枚举变量声明为 randrandc, 所以会报错).

详情请参考以下link。 http://forums.accellera.org/topic/1235-stdrandomize-vs-randomize-vs-thisrandomize-and-scope/

基本区别在于 std::randomize 是函数而不是 class 方法,而 class::randomize 是 class 方法。 randomize 函数可用于任何变量,任何约束都必须是内联约束。

randomize class 方法允许您为 class 的所有实例提供和控制约束。它将始终使用 class 中指定的约束以及您提供的任何可选内联约束。 randomize 方法还在执行随机化之前调用 pre_randomize 方法并在之后调用 post_randomize 方法。

所以:

选项A:

enum_type type_1;
std::randomize(type_1); // No constraints

选项 B:

gen_type a;
a.randomize(); // Use constraints specified in class. Call pre/post_randomize

选项 A

  • 实际上不是随机化,而是内联的方法调用 约束。
  • 你不能修改那个约束,你没有任何 控制它。

选项 B

  • 实际上是随机化。您需要添加 randrandc type1 声明,让它随机化。
  • 您可以完全控制随机化。
  • 你可以通过constraint_mode方法来转on/off约束。
  • 您可以通过rand_mode方法将type1的on/off随机化。