Hi,
Can someone help to constrain 2 dynamic arrays to get even distribution?
- C0,C1 evenly distribute
- E0,E1,E2,E3 evenly distribute
- En in C0 has same distribution as En in C1
One possible solution:
Cs: C0,C0,C1,C1,C0,C1,C1,C0 // num of C0 = num of C1
Es: E0,E1,E1,E0,E2,E3,E2,E3 // number of En is same
// The index of C0 include E0,E1,E2,E3
// The index of C1 include E0,E1,E2,E3
The code below somehow give a solution as below is not intention.
Cs:‘{C1, C0, C0, C0, C1, C0, C1, C1}
Es:’{E1, E3, E1, E3, E2, E2, E0, E0} //against 3 b/c E3,E1,E3,E2 under C0, ideally should be E3,E1,E0,E2
typedef enum bit[0:0] {C0=0, C1} c_typ_e; //c_typ_e is fixed to C{0,1}
typedef enum bit[1:0] {E0=0, E1, E2, E3} e_typ_e; //e_typ_e is fixed to E{0,1,2,3}
class A;
rand c_typ_e Cs[];
rand e_typ_e Es[];
rand shortint arr_sz;
//arr_sz mostly are 8*n(n>0), sometimes always could be 2*n(such as 2,4,6)
constraint arr_sz_cs {
arr_sz == 8;
}
constraint cs_cs {
Cs.size == arr_sz;
}
constraint cs_val {
if(arr_sz % 2 == 0) {
Cs.sum with(int'(item==C0)) == arr_sz/2;
Cs.sum with(int'(item==C1)) == arr_sz/2;
}
}
constraint es_cs {
Es.size == arr_sz;
}
constraint es_val {
if(arr_sz % 4 == 0) {
Es.sum with(int'(item==E0)) == arr_sz/4;
Es.sum with(int'(item==E1)) == arr_sz/4;
Es.sum with(int'(item==E2)) == arr_sz/4;
Es.sum with(int'(item==E3)) == arr_sz/4;
}
}
function void randomize_it();
this.randomize();
$display("Cs:%p",Cs);
$display("Es:%p",Es);
endfunction // randomize_it
endclass // A
module tb;
A a;
initial begin
a = new();
a.randomize_it();
end
endmodule // tb