In reply to dave_59:
Hi Dave ,
It seems even on Latest Simulators :: 2D_Unpackd_Array.sum() with (item.sum() with (item));
as a Constraint Doesn’t work , but when used in a Procedural Context it runs properly
I have the following Code ::
class A;
rand bit [1:0] A[][];
`ifdef M1
constraint SIZE_CONSTRAINT_1D { A.size() == 9 ; }
constraint sum_constraint_2d { foreach(A[i])
{
A[i].sum() with ( int'(item) ) == 27 ;
}
}
`endif
`ifdef S2 // Size for 2nd Dimension
constraint SIZE_CONSTRAINT_1D { A.size() == 9 ; }
constraint S2_2d { foreach(A[i])
{
A[i].size() == 2 ;
}
}
constraint sum_constraint_2d { foreach(A[i,j])
{
A.sum() with ( item.sum() with ( int'(item) ) ) == 27 ;
}
}
`endif
// Either M1 or S2 Would be Active at a time
endclass
A a1;
initial begin
a1 = new();
repeat(5)
begin
if ( a1.randomize() )
$display("Success with %p",a1);
else
$display("Fails with %p",a1);
end
end
Here is the Output ::
For +define+M1
Simulator1 ::
Fails with '{A:'{}}
Fails with '{A:'{}}
Fails with '{A:'{}}
Fails with '{A:'{}}
Fails with '{A:'{}}
Simulator2 ::
Success with '{A:'{'{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}}}
Success with '{A:'{'{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}}}
Success with '{A:'{'{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}}}
Success with '{A:'{'{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}}}
Success with '{A:'{'{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}, '{}}}
[Q1] Is there anything wrong with the Code ?
Constraint A.size() == 9 would Make the 1st Dimension as 9 but the 2nd Dimension is not Sized
[Q2] How would constraint A[i].sum() with ( int’(item) ) == 27 be Calculated in this Case since 2nd Dimension isn’t Sized ?
[Q2.1] Also is it compulsory to write “item” , can’t I write anything else ?
Output For +define+S2
With (a)
Simulator1 : Works
Simulator 2 and 3 :: Failure
[Q3] Is there any neat alternative for the 2 sizing Constraints :: SIZE_CONSTRAINT_1D and S2_2d ?
[Q3.1] I noticed A.size() with ( item.size() ) Doesn’t work .
Can with() Work with size() ?
[Q4] Any other way for Constraint :: sum_constraint_2d ? So that the Total sum is 27
Example :: constraint Functn_Call_in_Sum { A.sum() with (int'(item)) == SUMWA() ; }
function int unsigned SUMWA ();
int unsigned sum1;
foreach(A[i,j])
sum1 = sum1+ A[j].sum with ( int'(item) ) ;
SUMWA = sum1;
endfunction
Regards,
AGIS