System verilog constraint

write a SystemVerilog constraint for a 64-bit variable data. The requirements are as follows:

  1. The variable should be declared as rand bit [63:0] data.
  2. Whenever a 1 is detected in the pattern, it should be represented as nine consecutive 1s.
  3. All other bits in the data variable can be randomized to 0 or any other pattern, but there should not be any 1s in between the sequences of nine 1s.
  4. The total length of the data variable should remain 64 bits.

pattern looks like 011111111100000011111111100011111111100…0001111111110

What have you developed so far? What is working for you? What is not working for you? Have you posted your code on EDA Playground so that others can see what you have written?

Also, requirement number 3 is contradictory. If all other bits can be randomized to 0 or any other pattern, then having a ‘1’ is valid and contradicts that there should not be any 1s between the sequences of nine 1s.

Hi Rohit,

Could you run this code and see this what you are expecting.
module tb();

  class simple;    
    bit [63:0]a;
    int pos;
   rand bit b;
    bit flag;    
    constraint c_value{      
     flag == 1 -> b==0;       
    }    
    function void post_randomize();      
      if(pos <64) begin
        if(b ==1 && pos<=56) begin
          a[pos+:9] = 9'b111111111;
          pos = pos+9;
          flag =1;
        end
        if(b ==0) begin
          pos = pos+1;
          flag = 0;
        end        
      end      
    endfunction
  endclass
  
  initial begin    
    simple s;
    s= new();
    repeat(64) begin      
      s.randomize();      
    end
    $display("The array value = %0b", s.a);    
  end  
endmodule

output::

The array value = 1111111110111111111011111111101111111110111111111001111111110

@happysri30 Please format your code making your code easier for others to read. I have done that for you.

The code works.
Just a small suggestion for code optimization, the class is randomized 64 times even though it completed randomizing the array much earlier So avoid using fixed number “repeat(64)” and we can randomize the repeat loop==width_of_data and with the repeat loop just check if “s.pos ==data_width” just exit the loop.
eg:

repeat(DATA_WIDTH) begin
s.randomize();
if(s.pos==DATA_WIDTH)
break;
end

Thanks Dave. Let me do it from next time.