2

What is the difference between option A and Option B

Option 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

Option 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
e19293001
  • 2,783
  • 9
  • 42
  • 54

3 Answers3

0

Here Option A is an example of inline constraints, in which one can randomize a local variable of a class or module or program block without declaring it as a rand or randc.

While option B is an example of a randomization of variables of the object. In this construct, you must declare a variable, which u want to randomize as a rand or randc (Here, you haven't declared the enum variable as rand or randc, so it'll give an error).

Please refer following link for more details. http://forums.accellera.org/topic/1235-stdrandomize-vs-randomize-vs-thisrandomize-and-scope/

H.Modh
  • 428
  • 4
  • 12
0

The basic difference is that std::randomize is a function not a class method and class::randomize is a class method. The randomize function can be used on any variable and any constraints must be inline constraints.

The randomize class method allows you to provide and control constraints for all instances of the class. It will always use the constraints specified in the class plus any optional inline constraints you provide. The randomize method also calls the pre_randomize method before doing the randomization and calls post_randomize after.

So:

Option A:

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

Option B:

gen_type a;
a.randomize(); // Use constraints specified in class. Call pre/post_randomize
nick_g
  • 489
  • 1
  • 7
  • 15
-2

Option A

  • Not actually a randomization, but a method call with inline constraint.
  • You can not modify that constraint, you don't have any control over it.

Option B

  • Actually a randomization. You need to add rand or randc with type1 declaration, to get it randomized.
  • You have complete control over randomization.
  • You can turn on/off the constraint through constraint_mode method.
  • You can turn on/off randomization of type1 through rand_mode method.
Karan Shah
  • 1,912
  • 1
  • 29
  • 42