In reply to dave_59:
Hi Dave ,
I was trying the above Sample Code using data type as ‘bit signed’ .
I see unexpected results with following code ::
class temp;
rand bit signed [2:0] b4num[16];
constraint e {
b4num.sum with ( int'( ( item.index % 2 ) ? item : !item ) ) == 8 ;
}
endclass
temp t ;
initial begin
t = new();
repeat(5)
if ( t.randomize() )
begin
$display(" b4 is %p", t.b4num);
$display(" b4 Even sum is %0d", t.b4num.sum() with ( int'( ( item.index % 2 ) ? 0 : !item ) ));
$display(" b4 Odd sum is %0d", t.b4num.sum() with ( int'( ( item.index % 2 ) ? item : 0 ) ));
end
end
The Output for the code is ::
**
b4 is '{1, 1, 3, -3, -2, 0, -3, 1, -4, 0, -1, 0, 2, 1, -2, 0}
b4 Even sum is 0
b4 Odd sum is 0
b4 is '{-3, 2, 1, 2, -2, 0, -2, 1, -1, 0, 1, 3, -3, 0, 1, 0}
b4 Even sum is 0
b4 Odd sum is 8
b4 is '{2, 1, 1, 0, 2, 2, -2, -4, -4, 0, 1, 0, 2, 1, 2, 0}
b4 Even sum is 0
b4 Odd sum is 0**
Only 2nd Output meets my expectations
I am not sure how 1st and 3rd Output satisfy the sum() Constraint to be 8