Constraint to check that value exists in MDA

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;
}



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

Thanks!

The my_mda should be 32-bits, I’m not trying to fill the array but find the indexes that would equal to a specified value.

my_mda[0][0] = 32’hDEAD_BEEF;
my_mda[0][1] = 32’h1122_3344;
my_mda[0][2] = 32’h0000_BEEF;
my_mda[0][3] = 32’h1122_3344;

The constraint solver would come back with {indx_1,indx_2} either with {0,1} or {0,3}.

In reply to harsh pandya:

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

Thanks!

In reply to DVCoder:

What you originally wrote is fine.

In reply to dave_59:

Thanks !!! I wanted to see if there was a more efficient way.