Questions on constraint Distribution

Hi Dave,

(1) As per 1800-2017, 18.5.4 Distribution, Syntax 18-3 says

dist_list ::= dist_item { , dist_item }

dist_item ::= value_range [ dist_weight ]

dist_weight ::=           
         := expression 

       | :/ expression 

expression [ dist { dist_list } ]

Annex A.8.3 explains

value_range ::= expression
                | [ expression : expression ]

So essentially expression occurs in 3 places

expression1 dist { expression2 := expression3 }

LRM says

(a) The expression can be any intergral SystemVerilog expression

(b) A dist expression requires that the expression contain at least one rand variable

[Q1] What does expression in (a) and (b) point to ?

Is it expression1 / expression2 / expression3 or any of them ?

(2) Consider the following disturbution constraint for 4-bit random variable a

constraint d1 { (a > 11) dist { 1:/ 80, 0:/ 20 }; }

Result of (a > 11) is 0 or 1.

Essentially d1 constraints the probability of a greater than 11 to 0.8 whereas the probability of a <= 11 is 0.2

(3) Instead of d1 if I write the constraint as

constraint d2 { 1 dist { (a>11):/ 80, (a<=11):/ 20 }; }

[Q2] Isn’t d2 a valid disturbution constraint ? I observe compilation error with d2 on two EDA tools

[Q3] Is d2 equivalent to d1 ?

[Q4] How does a tool interpret d2 ?

Result of (a>11) / (a<=11) is 0/1.

As the lhs expression ( expression1 ) is 1, would the solver ensure that a is greater than 11, 80% of the time ?

(4) Is I were to write d1 as

constraint d1 { a dist { (a>11):/ 80, (a<=11):/ 20 }; }

I observe that a is either 0 or 1 ( although its a 4-bit variable )

This is due to result of (a>11) / (a<=11) being either 0 or 1.

[Q5] How is the distribution of a being 0 or 1 calculated in this case ?

One one of the EDA tool I observe a == 0 occurs much more than value of 1

Thanks

The IEEE 1800-2023 SystemVerilog LRM has made some significant updates and clarifications to this section. It compares the dist constraint to the inside set-membership constraint and specifically calls out the LHS and RHS expressions with what you are calling 1 and 2, and the weight being expression 3.

Although the LRM doesn’t explicitly state it, having the weight be a random variable (at least within the same randomization constraints) would be nonsensical.

Constraint d2 is legal and equivalent to d1. Using the revised wording of the LRM, the expression (a>11) has to match 1 80% of the time, and (a<=11) has to match 20% of the time.

Updating post referring section 18.5.3 of SV LRM-2023.

The expression can be any integral SystemVerilog expression

This statement has been removed in the 2023 LRM probably cause it now allows real expressions as well

expression1 is stated as left-hand expression.expression2 is stated as distribution set

expression3 is stated as distribution weight

The weight can be any integral expression

As random variables could also be an integral type, this tells us that distribution weights could be random variables ( please correct me if I am wrong here )

The distribution set is a comma-separated list of integral or real expressions and ranges

As random variables are essentially integral or real type, this tells us that distribution set could be random variables ( please correct me if I am wrong )

[Q2] An interesting observation via trial and error is that the tool limitation can be resolved via introducing a dummy random variable in lhs expression

rand bit dummy; // Constrained to 0 via d2

constraint d2 { (1+dummy) dist { (a>11):/ 80, (a<=11):/ 20 }; } // Resolves the compilation issue 

I observe a is greater than 11, 80% of the time as per expectations

A few additional questions to conclude this discussion

(4) If I were to write d1 as

constraint d1 { a dist { (a>11):/ 80, (a<=11):/ 20 }; }

I observe a is either 0 or 1 due to result of (a>11) / (a<=11) being 0 or 1

[Q5] How would the weights be used to calculate the probability of a equal to 0 or 1 in this case ?

(5) A dist expression shall not be applied to randc variables

[Q6] It’ s not clear whether this quote is applicable to lhs expression or disturbution set or distribution weight ?

Across tools I observe that they throw an error only when lhs expression contains randc variable whereas they allow randc variables as other two

(6) A dist expression requires that expression contain at least one rand variable

[Q7] Does this mean dist constraint can’t be applied to state variables via std::randomize or handle.randomize( state_variable ) ?

Thanks in Advance

[Q1] It’s clear that either the left-hand side (LHS) or the distribution set items must contain random variables. Otherwise, there’s no logical reason to have a dist constraint with weights. Having a weight have an expression with a random variable doesn’t seem very useful and shouldn’t be considered as satisfying the rule.

[Q2] No comment on a workaround for a tool bug other than to say it clearly demonstrates the error should not have been there in the first place.
[Q3/4/5] The result of a relational operator can only be 0 or 1. therefore the LHS can only be 0 or 1. It doesn’t make much sense in this example to have the same random variable on both sides.
[Q6] Having a random weight has no practical use.
[Q7] No effect on std::randomize