Sequence item is as follows:
rand unique_bit
rand num_of_reqs;
rand Bit [10:0] x [];
rand Bit[10:0] y[];
rand Bit [10:0] width[];
rand Bit [10:0] height[];
rand bit [10:0] frame_width;
rand bit [10:0] frame_height;
Conditions for constraints.....
each request is combination of x,y, width & height
x+width must be less than or equal to frame width
y+height must be less than or equal to frame height
if unique bit is set , combination of x,y,w,h must not be equal to any of other x,y,w,h
Code::
class test;
rand bit unique_bit;
rand int unsigned num_of_reqs;
rand bit [10:0] x[];
rand bit [10:0] y[];
rand bit [10:0] w[];
rand bit [10:0] h[];
rand bit [10:0] frame_width;
rand bit [10:0] frame_height;
constraint c_num_reqs {
num_of_reqs inside {[1:5]};
x.size() == num_of_reqs;
y.size() == num_of_reqs;
w.size() == num_of_reqs;
h.size() == num_of_reqs;
}
constraint c_frame_width {
frame_width inside {[0:1023]}; // Constraint will fail , if you don't cap your width
foreach (x[i]) {
int'(x[i] + w[i])<= frame_width;
x[i] inside {[0:frame_width]};
w[i] inside {[0:frame_width]};
}
}
constraint c_frame_height {
frame_height inside {[0:1023]}; // Constraint will fail , if you don't cap your height
foreach (y[i]) {
solve frame_height before x[i],h[i];
int'(y[i] + h[i]) <= frame_height;
y[i] inside {[0:frame_height]};
h[i] inside {[0:frame_height]};
}
}
constraint c_unique {
solve unique_bit before x,y,w,h,frame_height,frame_width;
if(unique_bit) {
unique {x};
unique {y};
unique {w};
unique {h};
}
}
function void display();
$display("Unique Bit:%0d",unique_bit);
$display("Num of Requests:%0d", num_of_reqs);
$display("Frame Height:%0d Width:%0d",frame_height,frame_width);
foreach(x[i])
$display("X:%04d W:%04d || Y:%04d H:%04d",x[i],w[i],y[i],h[i]);
endfunction
endclass
module top;
test t;
initial begin
t = new;
if(!t.randomize()) $error("Randomization failed");
t.display();
end
endmodule