系统Verilog中关联数组的随机化

时间:2021-12-29 03:40:28

I have an associative array:

我有一个关联数组:

    rand uvm_reg_field array_assoc[string];

The array contains the handle of the UVM register fields for registers in the DUT and is indexed by a string (string is the name of the field). Say I have 2 register fields with names "reg_field_1" and "reg_field_2".

该数组包含DUT中寄存器的UVM寄存器字段的句柄,并由字符串索引(字符串是字段的名称)。假设我有2个名称为“reg_field_1”和“reg_field_2”的注册字段。

As described,

    array_assoc["reg_field_1"]= handle of field 1;
    array_assoc["reg_field_2"]= handle of field 2;

I need to randomize only one of the fields, so, I selectively turn the rand_mode off for one of the fields, say "reg_field_1":

我只需要随机化其中一个字段,因此,我选择关闭其中一个字段的rand_mode,比如“reg_field_1”:

    array_assoc["reg_field_1"].rand_mode(0);

Now, if I randomize the associative array, both register fields are getting randomized.

现在,如果我随机化关联数组,两个寄存器字段都会随机化。

What is even more surprising is that, if i declare a normal array with integer indexes, such that :

更令人惊讶的是,如果我声明一个带有整数索引的普通数组,那么:

   rand uvm_reg_field array_normal[2];

   array_normal[0]= handle of field 1;
   array_normal[1]= handle of field 2;

and then turn of the rand_mode for field 1:

然后转为字段1的rand_mode:

   array_normal[0].rand_mode(0);

It works fine and field 1 is not randomized.

它工作正常,字段1不是随机的。

The question is: Why is the register field "reg_field_1" getting randomized even when its rand_mode has been set to 0 in case of associative array ?

问题是:为什么即使在关联数组的情况下将rand_mode设置为0,寄存器字段“reg_field_1”也会随机化?

1 个解决方案

#1


3  

The ability to set rand_mode() on individual elements of an associative array seems to have sporadic support. The following works for me in Questa and one other simulator; gives me a "not supported yet" in another, and the results you are seeing in yet another. So I would contact your tool vendor.

在关联数组的各个元素上设置rand_mode()的能力似乎有零星的支持。以下在Questa和另一个模拟器中为我工作;在另一个中给我一个“不支持”,在另一个中看到你看到的结果。所以我会联系你的工具供应商。

module top;
class B;
   rand byte m;
endclass 
class A;
   rand B a1[2];
   rand B a2[string];
   function void run;
      a2["0"]  = new;
      a2["1"]  = new;
      a1[0]    = new;
      a1[1]    = new;
      a1[0].rand_mode(0);
      a2["0"].rand_mode(0);
      void'(randomize());
      $display(a1[0].m, a1[1].m,,a2["0"].m,a2["1"].m);

      endfunction
endclass
   A a  = new();
   initial repeat(3) a.run();
endmodule

#1


3  

The ability to set rand_mode() on individual elements of an associative array seems to have sporadic support. The following works for me in Questa and one other simulator; gives me a "not supported yet" in another, and the results you are seeing in yet another. So I would contact your tool vendor.

在关联数组的各个元素上设置rand_mode()的能力似乎有零星的支持。以下在Questa和另一个模拟器中为我工作;在另一个中给我一个“不支持”,在另一个中看到你看到的结果。所以我会联系你的工具供应商。

module top;
class B;
   rand byte m;
endclass 
class A;
   rand B a1[2];
   rand B a2[string];
   function void run;
      a2["0"]  = new;
      a2["1"]  = new;
      a1[0]    = new;
      a1[1]    = new;
      a1[0].rand_mode(0);
      a2["0"].rand_mode(0);
      void'(randomize());
      $display(a1[0].m, a1[1].m,,a2["0"].m,a2["1"].m);

      endfunction
endclass
   A a  = new();
   initial repeat(3) a.run();
endmodule