Hi all ,
I have a few questions
[I] Achieving sum() more than 32-bits
Since 32'hFFFF_FFFF + 32'hFFFF_FFFF + 32'hFFFF_FFFF is 36'h2_FFFF_FFFD
class ADD ;
rand bit [31:0] a[3] ;
constraint SUM {
`ifdef M1
a.sum() with ( int'( item ) ) == 36'h2_FFFF_FFFD ;
`elsif M2
a.sum() with ( 32'( item ) ) == 36'h2_FFFF_FFFD ;
`endif
}
endclass
With both defines I observe Randomization Failure !!
Isn’t the Constrained expression unrolled to ::
int'( a[0] ) + int'( a[1] ) + int'( a[2] ) == 36'h2_FFFF_FFFD ;
OR
32'( a[0] ) + 32'( a[1] ) + 32'( a[2] ) == 36'h2_FFFF_FFFD ;
[Q1] Shouldn’t the LHS ( All 3 Indexes of a ) be extended to 36-bits too so that Randomization is a Success ??
[II] Constraining characters
class STRING ;
rand byte a[3] ;
string str ;
constraint CHARAC { foreach( a[i] )
a[i] inside { ["a":"z"] , ["A":"Z"] , [0:10] } ; // Legal ??
}
function void post_randomize() ;
str = { >> { a } } ; // { a[0] , a[1] , a[2] }
$display(" str is %0s",str);
endfunction
endclass
[Q2] Is above Constraint Considered Legal in LRM ??
**[Q3] String variables can’t be constrained directly since it’s neither integral type OR class data type .
Is string data type considered as an aggregate type ??**
[III] Inheritance
class base ;
rand bit [3:0] A[2] ;
constraint VALUE { foreach( A[i] )
A[i] == i ;
}
function void post_randomize() ;
$display("A.size() is %0d",$size(A));
$display("A is %0p",A);
endfunction
endclass
class Ext extends base ;
rand bit [3:0] A[4] ; // Overridden property . Ext has 2 properties named A !!
constraint VALUE { foreach( A[i] )
A[i] == 'hF ;
}
endclass
Ext ext ;
initial begin
ext = new() ;
if ( ! ext.randomize() )
$display("Fails");
end
I observe Output ::
**A.size() is 2
A is '{'h2, 'hd}**
[Q4] Since post_randomize() would be inherited shouldn’t the extended property A of size 4 be displayed ??