I have following code ::
class bad_sum1 ;
rand bit [7:0] b[] ;
rand bit [7:0] max ;
randc int size_randc ;
constraint SUM { b.sum() with ( 10'( item ) ) < 1024 ; }
constraint SIZE { b.size() == size_randc ; }
constraint RANDC { size_randc inside { [1:8] } ; }
constraint MAX_VALUE {
( 1023 / ( size_randc ) ) == max ; // Any issue here ?
}
constraint ELEMENT {
foreach( b[i] )
{
b[i] == max ; // [A]
}
}
function void post_randomize() ;
$display("b.sum() is %0d", (b.sum() with ( 10'( item ) ) ) ) ;
$display("b is %0p",b );
endfunction
endclass
bad_sum1 bs ;
initial begin
bs = new();
repeat(7) // Since size() is 1-7 !!
if ( bs.randomize() )
begin
$display("==========================") ;
end
else
begin
$display("Fails") ;
end
$display("%0d",int'(1023/5));
$display("%0d",int'(1023/6));
end
[Q1] Is the Constraint correct ? I observe that on certain Simulators Constraint Failure occurs and I success only when size is 4/5/6/7 .
Is there any discrepancy with Constraint :: ( 1023 / ( size_randc ) ) == max ?
If the real value ( of 1023 / size_randc ) is X.5 OR X.6 will max be constrained to ( X+1 ) OR X ?
Also ( 1023 / 5 ) has real value of 204.6 so shouldn’t Output be rounded off to 205 ?
Similarly I expected ( 1023 / 6 ) to give 171 rounded off value .