Constraint for selection of Address Bits based on strobe bits

Hi everyone, I am pretty much new in SV. I am trying write a constraint, based on strobe and valid bit, particular bits of address bits will be valid and printed. But as I understand in SV Queues, we can’t assigning in queue unless we define it. How can we achieve the intention which I mentioned here in code?


class packet;
  bit [63:0] address;
  bit [7:0]  strobe;
  bit [7:0]  data[$];
  bit valid;
  
  constraint c1 {
    if (strobe==0 && valid==1)
      data = address[7:0];
    else if (strobe==1 && valid==1)
     data = address[15:8];
    else if (strobe==2 && valid==1)
      data = address[23:16];
    else if (strobe==3 && valid==1)
      data = address[24:30];
    else if (strobe==4 && valid==1)
      data = address[38:31];
    else if (strobe==5 && valid==1)
      data = address[39:47];
    else if (strobe==6 && valid==1)
      data = address[48:55];
    else if (strobe==7 && valid==1)
      data = address[56:63];
    else;                  }
endclass`
      
module TB;
  packet pkt;
  pkt = new();
  
  initial begin
    address = 'h1234_45678_9ABC_DEF10;
    strobe = 1;
    valid =1;
    $display("Address:%0h, Strobe:%0h, Valid:%0d, VALID_DATA:%0h", address, strobe, valid, pkt.data[]);    
  end
endmodule 

Thanks and Regards,

In reply to skyhome0911:


//data size will be 8 . wherever the strobe is selected use mask, otherwise set to zero .
class packet;
  rand bit [63:0] address;
  rand bit [7:0]  strobe;
  rand bit [7:0]  data[8];
  bit valid;
  bit [15:0] mask = 'hff ;
 
  constraint c1 { 
   foreach(strobe[i]){
      if(strobe[i])
      data[i] == ((address & (mask << i*8)) >> i*8); // shift left to use the lower byte assignment 
      else 
      data[i] == 0 ;
   }
}
   
endclass`
 


In reply to kddholak:

Hi kddholak,
Thank you so much for reply and i understood your logic as well which is way more optimized and more correct way of doing. But, I need help in the way I am trying to implement so as to clear my few concepts about queues and its assignment. Could you please help me out in my logic formation?

Thanks and Regards,

In reply to skyhome0911:

It would help to explain with a few example of what results you are looking for. Constraints are used for random values, yet you never declared and rand members or called randomize(). Why is data declared as a queue if you only one to write one byte to it?