user5089054
user5089054

Reputation: 11

Randomization of Associative Array in System Verilog

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".

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":

    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:

   array_normal[0].rand_mode(0);

It works fine and field 1 is not randomized.

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 ?

Upvotes: 1

Views: 1940

Answers (1)

dave_59
dave_59

Reputation: 42698

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.

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

Upvotes: 3

Related Questions