Hi All,
If AxSize is ‘N’ then the address must be aligned to 2**N
Eg: For AxSize == 2 then address[1:0] == 0 i.e aligned to 4-byte
For AxSize == 3 then address[2:0] == 0 i.e aligned to 8-byte
Thus lower ‘AxSize’ bits are 0’s i.e Address[ (AxSize-1):0] == 0
// Declaration of address and axsize random variables
rand bit[11:0] axaddr; // In reality Address Width is 32 bit i.e [31:0]
randc bit[2:0] axsize;
I was trying different possible solutions
(Solution 1) Intention is to constraint axaddr[ (axsize-1):0 ] to all zeroes
constraint Addr_Aligned1 {
// axaddr[ (axsize-1):0 ] == 0; // Error-[IRIPS] Illegal range in part select
foreach( axaddr[i] )
{
// if( i inside { [0:(axsize-1)] } ) // [Q] What if axsize == 0 ? What will result of ( axsize - 1 )
be ?
if( i < axsize )
{
axaddr[i] == 0;
}
}
}
[Q1] If I change if - constraint to :: if( i inside { [0:(axsize-1)] } ) and add in-line constraint ::
if( obj.randomize() with { axsize == 0; } ) ,
I observe that the o/p is tool dependent.
When axsize is 0 , what would be the upper bound of [0:(axsize-1)] ? Will it be all ones ?
Is the result dependent on the type ( signed/unsigned ) of “i” ?
(Solution 2) Intention is to constraint axaddr & ( '1 << axsize ) ( which gives result as axaddr[ (axsize - 1) : 0 ] ) as 0
rand bit[2:0] local_axsize ; // helper variable
function bit[2:0] No_of_Zeroes( bit[2:0] ip );
No_of_Zeroes = '1; // All Ones
return( No_of_Zeroes << ip );
endfunction
constraint Addr_Aligned2 {
local_axsize == No_of_Zeroes(axsize);
( axaddr & local_axsize ) ; // Need help here. Should there be RHS ?
}
Result of ( axaddr & local_axsize ) is 12-bit with lower ‘axsize’ no. of bits as 0.
One valid solution is axsize == 0 and axaddr as unconstrained ( including 0x0 )
i.e each address would be aligned to 1-byte
However axsize == 0 and axaddr == 0 won’t be picked via constraint axaddr & local_axsize ( as result is 0 ). The intention is that axsize == 0 and axaddr == 0 should also be picked as a possible solution.
[Q2] How should I use result of local_axsize in order to constraint axaddr accordingly ?
[Q3] Any suggestions for alternative solution are welcome as well