How to write constraint for this md array
md_array=‘{‘{‘h0,’h0,’h0,’h0},’{‘h1111,’h0,’h0,’h0},’{‘h1111,’h1111,’h0,’h0},’{‘h1111,’h1111,’h1111,’h0}}
In reply to shravanikuchana:
class my_class;
rand bit [15:0] arr[4][4];
constraint c_arr {
foreach (arr[i]) {
foreach (arr[j]) {
if (i<j)
arr[j][i] == 'h1111;
if (i>=j)
arr[j][i] == 'h0000;
}
}
}
endclass : my_class
module top();
my_class mc = new();
initial begin
mc.randomize();
$display("mc.arr = %p",mc.arr);
end
endmodule : top
Regards,
Mega
In reply to megamind:
I guess the more simpler code would be this
module test();
class cls;
rand bit [15:0]md_array[4][4];
constraint c1{
foreach(md_array[i,j]) {
if(i>j)
md_array[i][j]==16'h1111;
else
md_array[i][j]==16'h000;
}
}
endclass
cls obj;
initial begin
obj =new();
obj.randomize();
$display("obj.arr = %p",obj.md_array);
end
endmodule
In reply to megamind:
Thank You Mega. Its working perfectly…
In reply to sa5691:
Thank you for making it really simple and understandable…