Hi Forum ,
I have following Code ::
class ADD ;
rand bit [30:0] a[2] ;
constraint SUMM { a.sum with ( int'(item) ) == 32'd2**32-2 ; } // Would it Pass ??
endclass
ADD obj ;
initial begin
obj = new() ;
repeat(2)
if ( obj.randomize() )
$display("Success with %p",obj);
else
$display("Fails");
end
I Observe different Output across Simulators ::
SIMULATOR1_FAILS whereas it passes with Other Simulators ( Run with different Simulator on EDAPlayground )
[ Although the Other Simulators are older version I actually Observe Same results with their respective Licensed Simulators @ work ]
I believe some implementation uses a Sign Extension ( 31st bit is Duplicated ) leading to failure
Please note that my intention isn’t to discuss Simulator Issues
LRM 7.12.3 says :: "When specified, the with clause is used to determine the type of the result.
Casting item to an int in the with clause causes the array elements to be extended to 32 bits before being summed.
The result of calling sum in this example is 32 bits since the width of the reduction method result
shall be the same as the width of the expression in the with clause"
My Understanding is to achieve 32-bits ::
(1) 0-Padding Should take place ( if each element is smaller than 32-bits ) if the element is Unsigned type ( bit / logic )
**(2) Sign Extension Should take place ( if each element is smaller than 32-bits ) if the element is Signed type ( bit signed / byte )
**
[Q1] Agree OR Disagree with (1) and (2) ??
[Q2] I believe Randomization Should have Passed in the Code above !!
i.e I Should Observe a:'{'h7fffffff, 'h7fffffff}