atalur
February 18, 2019, 9:09pm
1
A memory is of size 8192 bytes and it is byte addressable. I need to generate 3 different start and end addresses within this memory space. Each of these 3 sub areas can be a min of 1 byte and a max of 8192 bytes. These need to be non overlapping.
I have tried creating a size variable and start addr variable with solve before constraint for size before address. This is not working for me.
Any help in creating a constraint for this is appreciated.
1 Like
dave_59
February 18, 2019, 11:40pm
2
In reply to kernalmode1 :
class address;
int N = 3;
int memLimit = 8192;
rand bit [15:0] addrs[];
rand bit [15:0] sizes[]
function new;
addrs = new[N];
sizes = new[N]
endfunction
constraint c{
foreach(addrs[Range]) {if (Range != N-1)
addrs[Range] + sizes[Range] < addrs[Range+1];
else
addrs[Range] + sizes[Range] < memLimit;
sizes[Range] inside {[1:memLimit-1]};
}
endclass
atalur
February 19, 2019, 12:03am
3
In reply to dave_59 :
Thanks Dave.
class address;
int N = 3;
int memLimit = 8192;
rand bit [15:0] addrs[];
rand bit [15:0] sizes[];
function new();
addrs = new[N];
sizes = new[N];
endfunction
constraint c {
foreach(addrs[Range]) {
if (Range != N-1)
addrs[Range] + sizes[Range] < addrs[Range+1];
else
addrs[Range] + sizes[Range] < memLimit;
sizes[Range] inside {[1:memLimit-1]};
}
}
endclass
module top;
initial begin
address fc;
fc = new();
repeat(10) begin
fc.randomize();
$display("%p %p", fc.addrs, fc.sizes);
end
end
endmodule
seenu
February 19, 2021, 1:58am
4
In reply to dave_59 :
In reply to kernalmode1 :
class address;
int N = 3;
int memLimit = 8192;
rand bit [15:0] addrs[];
rand bit [15:0] sizes[]
function new;
addrs = new[N];
sizes = new[N]
endfunction
constraint c{
foreach(addrs[Range]) {if (Range != N-1)
addrs[Range] + sizes[Range] < addrs[Range+1];
else
addrs[Range] + sizes[Range] < memLimit;
sizes[Range] inside {[1:memLimit-1]};
}
endclass
Hi Dave,
What is “Range” variable here?
dave_59
February 19, 2021, 4:34am
5
In reply to seenu :
It is the foreach loop iterator variable.
I am getting these as my results
'{'hfe6a, 'hf38c, 'h1092} '{'h523, 'he62, 'h808}
doesn’t this exceed 8192 bytes - 'hfe6a + 'h523 = 66445(in binary greater than 8192?) I think my understanding is wrong please help
Good catch. Remove the else
in the constraint, or simply write
constraint c {
foreach(addrs[Range]) {
if (Range != N-1)
addrs[Range] + sizes[Range] < addrs[Range+1];
addrs[Range] + sizes[Range] < memLimit;
}
}
1 Like