I have a packed MDA already preloaded and I want to find the indexes that would equal to some value, what is the best way to check that? I have something like below but is it efficient?
bit [16][8][31:0] my_mda;
rand bit [3:0] indx_1;
rand bit [2:0] indx_2:
constraint my_c{
my_mda[indx_1][indx_2] == 32’h1122_3344;
}
I am not sure, first why you have write constraints to find index of pre-loaded array.
Second, your array is 1 bit only. SO, it can hold only 0 or 1.
Generally constraints used to fill array with specific value when declarer with rand.
However, in Your case array is pre-loaded then You can easily find index with foreach + comparison ( like below )
module m;
class k;
bit [16][8][31:0] my_mda;
rand bit [3:0] indx_1;
rand bit [2:0] indx_2;
/*
//Not used to check Array Index
// is used to fill specific value, when my_mda define as rand
constraint my_c{
my_mda[indx_1][indx_2] == 32’h1122_3344;
}
*/
endclass : k
k k1 = new;
initial begin
int x;
k1.randomize();
foreach(k1.my_mda[i,j,k])begin
k1.my_mda[i][j][k] = $urandom;
if(k1.my_mda[i][j][k] == 1 /*your value*/ )$display("Index %0d %d %d",i,j,k);
end
end
endmodule : m
In reply to DVCoder:
I am not sure, first why you have write constraints to find index of pre-loaded array.
Second, your array is 1 bit only. SO, it can hold only 0 or 1.
Generally constraints used to fill array with specific value when declarer with rand.
However, in Your case array is pre-loaded then You can easily find index with foreach + comparison ( like below )
module m;
class k;
bit [16][8][31:0] my_mda;
rand bit [3:0] indx_1;
rand bit [2:0] indx_2;
/*
//Not used to check Array Index
// is used to fill specific value, when my_mda define as rand
constraint my_c{
my_mda[indx_1][indx_2] == 32’h1122_3344;
}
*/
endclass : k
k k1 = new;
initial begin
int x;
k1.randomize();
foreach(k1.my_mda[i,j,k])begin
k1.my_mda[i][j][k] = $urandom;
if(k1.my_mda[i][j][k] == 1 /*your value*/ )$display("Index %0d %d %d",i,j,k);
end
end
endmodule : m