Whats constarint I should provide to below mentioned randomize number
constraint ex_num {
typ_num[16:0]
}
please advice.
Whats constarint I should provide to below mentioned randomize number
constraint ex_num {
typ_num[16:0]
}
please advice.
constraint ex_num {
$countones(typ_num[16:0]) == 5;
}
In reply to dave_59:
getting error
Error -[NYI-CSTR-SYS-FTC] NYI constraint : sys function calls
System fucntion calls are not yet implemented in constarints.
Remove the function call or if possible replace it with an integral state
variable assigned in pre_randomize()
I have not assigned anything in pre_randomize.
What could be the issue ?
In reply to Sourabh:
Anytime you get a “Not Yet Implemented” or a “Not supported” message, that means you have a tool issue and need to contact your vendor.
A workaround would be to declare an array of bits and constrain the sum of the elements to 5. Then you need another constraint that bitstream casts the array to a 16-bit variable.
rand bit anum[17];
rand bit [16:0] typ_num;
constraint ex_anum { anum.sum() with (int’(item)) == 5; }
constraint ex_tnum { type_num == 16’(anum); }
Dave,
I also have a simialr issue and have a new post for the same.
But what is “item” you are referring to here ??
Thanks!
item is the variable in which the sum of the array is stored. Please refer to section 18.5.8.2 of LRM for more details.
In reply to roopanandakumaran:
Dave,
I also have a simialr issue and have a new post for the same.
But what is “item” you are referring to here ??
Thanks!
In reply to Sourabh:
Please refer following mentioned post for your query.
Randomization for 32 bit vector to have min 4 bits as ‘1’
In reply to Sourabh:
Hi,
Here my two cents.
I find the solution provided in other thread important to be mentioned. That solution is in my opinion longer but quite more efficient than leaving the count function in the constraint solver.
That solution is about creating a vector of indices that you can shuffle, and then randomize the number of index you want to take from that vector to insert the ones. Take in mind that this doesn´t require any constraint and it doesn´t force the solver with try and error but just plain loops.
Here i present an example function where you can configure the max number of ones inside 3 vectors of 32,32 and 128bits respectively and that will be concatenated in one single vector.
function logic[BLK_AIRQC_NUM_IRQS-1:0] randomize_irq(int max_int_ones=15,int max_ext_ones=15,int max_sgi_ones=20);
automatic logic [BLK_AIRQC_NUM_IRQS-1:0] all_irqs_after_randomization=0;
automatic int irqs_128index_arr[BLK_AIRQC_NUM_IRQ_INT_G];
automatic int irqs_32index_arr[BLK_AIRQC_NUM_IRQ_EXT_G];
automatic logic [BLK_AIRQC_NUM_IRQ_INT_G-1:0] int_irqs=0;
automatic logic [BLK_AIRQC_NUM_IRQ_EXT_G-1:0] ext_irqs=0;
automatic logic [BLK_AIRQC_NUM_IRQ_SGI_G-1:0] sgi_irqs=0;
automatic int random_number_of_ones;
//allirqs= (MSB) sgi , ext , int (LSB)
//Initialization of indices
foreach(irqs_32index_arr[i]) begin
irqs_32index_arr[i]=i;//put indices on each element value
end
foreach(irqs_128index_arr[i]) begin
irqs_128index_arr[i]=i;//put indices on each element value
end
//end of initialization
//////////////////////
irqs_32index_arr.shuffle;//randomize the order of the array or indices
assert(std::randomize(random_number_of_ones) with {random_number_of_ones dist {['h1:max_ext_ones]:=100, 0:=0,['h0:32]:=50};});
for (int unsigned i=0; i<random_number_of_ones; i++) begin//now use the n first indices to put ones
ext_irqs[irqs_32index_arr[i]]=1;//put ones for IRQs using the index from the shuffled vector
end
irqs_32index_arr.shuffle;//randomize the order of the array or indices
assert(std::randomize(random_number_of_ones) with {random_number_of_ones dist {['h1:max_sgi_ones]:=100, 0:=0,['h0:32]:=50};});
for (int unsigned i=0; i<random_number_of_ones; i++) begin
sgi_irqs[irqs_32index_arr[i]]=1;//put ones for IRQs using the index from the shuffled vector
end
irqs_128index_arr.shuffle;//randomize the order of the array or indices
assert(std::randomize(random_number_of_ones) with {random_number_of_ones dist {['h1:max_int_ones]:=100, 0:=0,['h0:128]:=30};});
for (int unsigned i=0; i<random_number_of_ones; i++) begin
int_irqs[irqs_128index_arr[i]]=1;//put ones for IRQs using the index from the shuffled vector
end
all_irqs_after_randomization = {sgi_irqs, ext_irqs, int_irqs};
return all_irqs_after_randomization;
endfunction
I hope it helps
Jonathan