Hi All ,
I was seeking suggestions for following requirements
- Size of array to 10 , each element would be within value 1,3 or 5. Elements should be in ascending order
rand bit[3:0] arr[];
constraint SIZE { arr.size() == 10; }
constraint element_value {
foreach( arr[i] ) { arr[i] inside { 1 , 3 , 5 } ; }
}
function void post_randomize();
arr.sort();
endfunction
However one limitation is that there is no constraint to ensure that there is at least one occurrence of each of 1,3 and 5.
Eg: One possible output is '{'h3, 'h3, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5, 'h5}
I then tried using sum() constraint
// Instead of constraint 'element_value'
constraint element_value_using_sum {
arr.sum() with ( int'(item==1) ) + arr.sum() with ( int'(item==3) )
+ arr.sum() with ( int'(item==5) ) == arr.size() ;
}
However this too has the similar limitation as above
[Q1] Is it possible to constraint the elements within values 1,3 and 5 as well as constraint at least one occurrence of each value, using a single constraint expression ?
- Randc behavior using rand
rand bit[3:0] a;
bit[3:0] q[$];
constraint rand_cyclic { if( q.size() != 0 ) !( a inside { q } ); }
function void post_randomize();
if( q.size() == 16 ) q.delete();
endfunction
Q2] If I were to remove the constraint-guard ( if( q.size() != 0 ) ) , during the 1st call to randomize, would the constraint !( a inside { q } ) have any side-effects ( since the queue is empty ) ?