In reply to Jonathan_Alvarez:
I’m using a Cadence simulator.
I get a constraint error using vf.sum (32’(item)) == 2048.
I tried vf.sum (item+32’b0) == 2048, but I get a constraint error.
Here’s my code.
``` verilog
class rand_vf_queues extends uvm_object;
rand bit [7:0] vf_size;
rand bit [11:0] vf[];
constraint c_num_vf {vf_size == 248;}
constraint c_vf_queues {
vf.size == 248;
vf.sum == 2048;
foreach (vf[i]) {
vf[i] inside {[0:2048]};
}
}
function new (string name = "");
endfunction // new
function void post_randomize();
int sum_vf = 0;
`uvm_info(get_type_name(), $psprintf("vf_size = %0d, total_qctl_queues = %0d",vf_size,total_qctl_queues), UVM_LOW)
for(int i=0; i<vf_size; i++) begin
`uvm_info(get_type_name(), $psprintf("VF[%0d] = %0d",i,vf[i]), UVM_LOW)
sum_vf = sum_vf + vf[i];
end
`uvm_info(get_type_name(), $psprintf("VF.SUM() = %0d, sum_vf = %0d",vf.sum(),sum_vf), UVM_LOW)
endfunction
endclass // rand_vf_queues
> Here's partial display results showing the end of the array values and sum_vf. Notice VF.SUM() has maxed out to 2048 but the actual sum_vf is much larger.
``` verilog
[0ns] reporter: VF[242] = 1455
[0ns] reporter: VF[243] = 19
[0ns] reporter: VF[244] = 469
[0ns] reporter: VF[245] = 353
[0ns] reporter: VF[246] = 946
[0ns] reporter: VF[247] = 2038
[0ns] reporter: VF.SUM() = 2048, sum_vf = 256000
What I would like to do is constrain all the values from 0-2048 and have the total array sum = 2048 and I want the possibility to have only a couple of the vf[i] to have a couple of indexes = > 0 and all the other indexes = 0.
i.e. vf[0] = 2000, vf[230] = 48, all other indexes will = 0.