Hi All,
I am writing a constraint with the following intention:
There are total 1026 Controllers comprising of 2 Parent Controllers (PC) and 1024 Child Controllers (CC)
The 2 PCs are associated with Controller ID as 0 and 1 whereas the 1024 CCs have controller ids from 2 to 1025.
Each PC has 32 credits whereas upto 32 CCs would have 8 credits each.
Remaining 992 ( 1024 - 32 ) CCs could have 4 credits.
Total credits across the 1026 controllers should not cross 'd4288
One possible solution is 2 PCs with 32 credits each.
No CC with 8 credits i.e all 1024 CCs have 4 credits each
Another possible solution is 2 PCs with 32 credits each.
32 CCs with 8 credits each. Remaining 992 ( i.e 1024 - 32 ) CCs with 4 credits each
Total credits are 4288 in this case
Here is my attempt using a helper array
rand bit [7:0] wr_ctrl_depth[1026];
rand bit [10:0] cc_id_with_8credits[]; // 11-bit since CC can have Max. Index as 'd1025. Unpacked Size is upto 32 ( Min. can be 0 as well !! ) since 32 CC's can have 8 Credits
constraint No_of_CC_with_8credits { cc_id_with_8credits.size() inside {[0:32]} ; }
constraint Index_of_32_CC {
if( cc_id_with_8credits.size() > 0 ) // Is the constraint guard essential ?
{
foreach(cc_id_with_8credits[i])
{
cc_id_with_8credits[i] inside {['d2:'d1025]}; // Value should be Valid Controller ID for VF
}
unique { cc_id_with_8credits } ; // Unique CTRL_ID's
}
}
constraint wr_ctrl_depth_valid {
foreach(wr_ctrl_depth[i]) // Index 'i' is essentially Controller ID
{
if( i inside {[0:1]} ) // PF is related to Controller ID 0-1
wr_ctrl_depth[i] == 32'd32 ;
else if ( i inside { cc_id_with_8credits } )
{
wr_ctrl_depth[i] == 32'd8 ;
}
else {
wr_ctrl_depth[i] == 32'd4 ;
}
}
wr_ctrl_depth.sum() with( int'(item) ) <= 'd4288;
}
As per my understanding there is an implicit ordering b/w size() and foreach iteration.
(1) If the constraint solver picks size() as 0 and I were to remove the constraint guard for size(),
would there be any possible side-effect with constraint ‘Index_of_32_CC’ ?
(2) Is there a possible solution without using any helper array ( ‘cc_id_with_8credits’ ) ?
Thanks in Advance