In reply to dave_59:
Hi Dave ,
I have a few questions ::
// Constraint to have val between 1 to 50
constraint c_value { a.or(item) with ( val inside { [ a[item.index]:b[item.index] ] } ) ; }
[1] Why use or() reduction operator ?
Since our goal is to have a comma separated constraint and inside operator evaluates to
( val inside {[1:10] } ) || ( val inside {[11:20] } ) || ( val inside {[21:30] } ) || ( val inside {[31:40] } ) || ( val inside {[41:50] } )
or() reduction operator helps us achieve the logical OR .
Is this the main reason to use or() reduction Operator ?
[2] I notice that using sum() reduction operator gives us val between 1 to 50 too .
a.sum(item) with ( val inside { [ a[item.index]:b[item.index] ] } ) ; // Works as well !!
[3] Is the expression specified within with ( val inside { [ a[item.index]:b[item.index] ] } ) the actual Constraint for the solver ?
i.e For solver to chose a value between [1:10] , [11:20] , … [41:50]
I ask cos normally the result of the with() clause acts as an expression for the constraint solver to actually solve .
eg :: array.sum() with (int'(item)) == 10 ;
[4] When I use ::
$display("%0d",obj.a.sum(item) with ( int' ( obj.val inside { [ obj.a[item.index]:obj.b[item.index] ] } ) ) ) // int'() cast used !!
I notice an Output of 1 always ( Even if I use a.or(item) ... ) .
Is it cos that although val unrolls into 5 Constraints separated by || , at a time val can only be inside a specific range ?
Eg : if val is chosen as 11 , only val inside [11:20} would return 1’b1 whereas the other 4 inside constraint would return 0 . So 32’b0 + 32’b1 + 32’b0 + 32’b0 + 32’b0 == 32’b1
[5] Regarding Applying weights from a variable sized array ::
Syntax 18-3 of LRM specifies syntax as ::
expression_or_dist ::= expression [ dist { dist_list } ]
So can any expression be used on LHS of dist ?
(a) Ternary Operator would work too ?
eg :
constraint DIST { ( condition ) ? dist { .. } : 1 ; }
// If condition is false , the 1 would ensure constraint DIST returns true ( Non-zero )
(b) I tried using :
a.or(item) with ( ( val inside { [ a[item.index]:b[item.index] ] } ) dist { 1:/c[item] } ) ;
Shouldn’t this work based on Syntax 18-3 of LRM ?
(c) I modified code to ::
a.or(item) with ( val dist { [ a[item.index]:b[item.index] ] :/ c[item.index] } ) ;
This flashed an error :: " Feature is not yet supported: Usage of dist inside the property " on latest simulator ( 2020 version ) .
It does recognize it as a valid syntax .