I have following code ::
class main;
rand bit b1num[16];
rand bit [3:0] b4num[16];
constraint SUM {
b1num.sum with ( int'( ( item.index % 2 ) ? item : !item ) ) == 8 ;
b4num.sum with ( int'( ( item.index % 2 ) ? item : !item ) ) == 8 ;
}
endclass
main m ;
initial begin
m = new();
if ( m.randomize() )
begin
$display(" b1 is %p", m.b1num);
$display(" b4 is %p", m.b4num);
end
end
I see following output ::
b1 is '{1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1} // Sum of odd indexes from 1 , 3 to 15 is 6 ; Sum of even indexes from 0 , 2 to 14 is 6
b4 is '{5, 0, 11, 0, 3, 3, 0, 0, 2, 0, 8, 1, 2, 2, 9, 1} // Sum of odd indexes from 1 , 3 to 15 is 7 ; Sum of even indexes from 0 , 2 to 14 is 40
Need help to understand how are the constraint evaluated ?
In int’( ( item.index % 2 ) ? item : !item ) ,
LHS ( item.index % 2 ) is True i.e 1 when index is odd that index 1 , 3 , 5 to 15
[Q1] So when LHS is true isn’t the constraint same as :: int’( b1[1] ) + int’( b1[3] ) + int’( b1[5] ) + … + int’( b1[15] ) == 8
[Q2] Also how does !item contribute to constraint ?
When index is 0 , 2 , 4… 14 what is the Constraint used ?
[Q3] Instead of writing ( item.index % 2 ) in condition can I write ( ( item.index[0] == 1 ) ) . ?