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>
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.
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:
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.