Which distribution does randomization consider base or extended?

Hi,

If I am using the following code,

class BASE_A;
rand [3:0] bit Var1;

constraint Var1_c {
  Var1 dist {
     0      := 10,
     [1:7]  := 10,
     [8:15] := 10 
  }
}

endclass

class Ext_A extends BASE_A;

constraint Var1_new_c {
  Var1 dist {
     0      := 5,
     [1:7]  := 20,
     [8:15] := 5 
  }
}

endclass

Does the constraint solver try to satisfy both the distribution or only consider the extended?

If we run the test for 30 seeds what the constraints resolved.

Note: This is not constraint override.

Regards,
Ashith

HI Ashith,

As you have written two constraint for same variable, with two different name.One in Parent class and second in Extended class.

So, Constraint solver try to satisfy both the distribution.

If you had written code like that,

class BASE_A;
rand [3:0] bit Var1;

constraint Var1_c {
Var1 dist {
0 := 10,
[1:7] := 10,
[8:15] := 10 
}
}

endclass

class Ext_A extends BASE_A;

constraint Var1_c {
Var1 dist {
0 := 5,
[1:7] := 20,
[8:15] := 5 
}
}

endclass

Here both the constraint has same name. so Constraint will be overridden and constraint solver try to satisfy constraint which you have written in Extended class.

In reply to Darshan@Dehuniya:

I agree both are different constraint names. This was done intentionally.

I assume it wont be able to resolve both constraints because the weightages in the distribution are different so would not make any sense to say solver will resolve both.

Only one distribution would make sense.

When you call randomize() on an object of an Ext_A class, both dist constraints are in effect because you did not override the constraint in the BASA_A class. It will behave as if you had two dist constraints in the same class on the same variable. In that case it will only satisfy the range membership properties of the dist constraints, and weights will be ignored.

In your particular example, the dist constraint just happens to specify the same complete value range of a 4-bit random variable on both Var1_c and Var1_new_c dist constraints, and the dist constraint in BASE_A just happens to be a uniform distribution, which gives you the same results as if you had no constraints.

In reply to dave_59:

Thank you for the reply Dave.

Does that mean, if in the base class the weights were not equal then when I randomize multiple times I am not guaranteed of the hitting the expected behavior in the extended class, i.e weights of 5, 20, 5.

  • Ashith

In reply to Ashith:

Yes. You need to either override the constraint or turn the base constraint off with constraint_mode() for the dist constraint in the EXT_A class to be satisfied.

In reply to dave_59:

Thank you so much Dave. I appreciate your effort in making us understand concepts.