Generating multiple non overlapping chunks of memories from a given big memory

Hi,
I want to generate 5 non overlapping memory chunks for a given memory
example:Given memory start_address=0;end_address=10000
now generate 5 small memories whose start and end addresses are within 0 to 10000 and these should be non overlapping.

I tried below code.
But its always giving small memories with strat=0 and end=10000.

Below is my code.
parameter min = 0;
parameter max = 10000;
class line;
    rand int unsigned x_start,x_end;
    constraint c1 {
    x_start inside {min,max};
    x_end inside {min,max};
    //x_start < x_end;
    //unique{x_start,x_end};
  }

endclass

class line_generator;

  rand line line_h[5];
  int que_val[$];

    function new();
      foreach(line_h*)
       line_h[i]=new();
    endfunction

  constraint c2{
    foreach (line_h[i])
    {
      //if(i>0) line_h[i].x_start > line_h[i-1].x_start;
      //if(i>0) line_h[i].x_end > line_h[i-1].x_end;
      line_h[i].x_start<line_h[i].x_end;
      //!(line_h[i].x_start inside {que_val});
      //!(line_h[i].x_end inside {que_val});
    }
  }
    //function void post_randomize();
    //  foreach(line_h[i])
    //    for(int j=line_h[i].x_start;j<=line_h[i].x_end;j=j+1)
    //      que_val.push_back(j);
    //endfunction
endclass
      
module line_test;
line_generator gen;
  
initial
begin
  gen=new();
  gen.randomize();
  foreach(gen.line_h[i])
    $display("start:%d,end:%d",gen.line_h[i].x_start,gen.line_h[i].x_end);
end

endmodule
``` verilog

``` verilog
<font size=13>[i][i]*[/i]</font>

In reply to sra1dreddy:

Your syntax for the ‘inside’ constraints is incorrect. You are providing only two options, not a range. You should look at the syntax in the LRM for additional assistance.

In reply to cgales:

Hi,
Thanks.fixed syntax.

parameter min = 0;
parameter max = 10000;
class line;
rand int unsigned x_start,x_end;
constraint c1 {
x_start inside {[min:max]};
x_end inside {[min:max]};
x_start < x_end;
unique{x_start,x_end};
}

endclass

still the start and end are overlapping for small chunks.

In reply to sra1dreddy:

I believe the constraints you set won’t give you 5 non overlapping memory chunks. This because even though start and end are unique the constraint will not take in account what is already been generated. Meaning you can have something like:

start: 4932,end: 6845 //1
start: 534,end: 3161 //2
start: 3416,end: 8042 //3
start: 3384,end: 6603 //4
start: 1161,end: 4421 //5

If you check out chunk 3 is partially included in chunk 4 same for others. Is this what you are looking for?

In reply to Rsignori92:

Based on your question, I think you almost got it. I see that you are missing the constraint that related the current start_address to the previous end_address. If you have the current start_adddress greater than (or equal to) the previous end_address, you can guarantee non-overlapping regions.

I have the below example code for a memory, you can refer to the constraints and re-use it for your n-lines problem.


parameter min = 0;
parameter max = 10000;

class memory_chunks;
   
  rand int unsigned x_start[];
  rand int unsigned x_end[];
  rand int x_size[];
  rand int chunks;
  
  constraint size_c {
    foreach(x_size[i]) x_size[i] == x_end[i]-x_start[i];
    foreach(x_size[i]) x_size[i] inside {[1:100]};
  }
  
  constraint chucks_n{
    chunks ==5 ;
  }
  
  constraint num_regions_c {
    x_start.size() == chunks;
    x_end.size() == chunks;
  }
  
  constraint c1 {
    foreach(x_start[i]) x_start[i] inside {min,max};
    foreach(x_end[i])   x_end[i] inside {min,max};
    foreach(x_start[i]) x_start[i] < x_end[i];
  }
  
  constraint non_overlapping_c {
    foreach(x_start[i]) { 
      (i > 0) -> (x_start[i] > x_end[i-1]) ; 
    }
  }
 
endclass

In reply to KillSteal:

Yes exactly, thanks for the prompt response

Thanks for the reply.I tried below code and its working as expected.


parameter min=0;
parameter max=15;
module line_example;
class line;
  rand int unsigned x_start;
  rand int unsigned x_end;
  constraint line_c {
    x_start inside {[min:max]};
    x_end inside {[min:max]};
    x_start < x_end;
  }
endclass


class line_generator;

  rand line line_h[5];
  function new();
    foreach(line_h[i])
      line_h[i]=new();
  endfunction
  constraint c1 {
   foreach (line_h[i])
    {
      foreach(line_h[j])
	 { 
       (i!=j)->!(line_h[i].x_start inside {[line_h[j].x_start:line_h[j].x_end]});
       (i!=j)->!(line_h[i].x_end inside {[line_h[j].x_start:line_h[j].x_end]});
     }
    }
    }
endclass
line_generator gen;
initial
  begin
    gen=new();
	  gen.randomize();
	  foreach(gen.line_h[i])
	  $display("%p",gen.line_h[i]);
  end
endmodule

solution:
'{x_start:'hd, x_end:'hf}
'{x_start:'h8, x_end:'hb}
'{x_start:'h3, x_end:'h4}
'{x_start:'h0, x_end:'h1}
'{x_start:'h6, x_end:'h7}