class C;
rand bit [5:2] arr[2];
constraint c0 {
foreach (arr[i, j]) { if (j>3) arr[i][j] == 1; else arr[i][j] == 0; }
}
endclass
program automatic test;
C obj = new;
initial begin
obj.randomize();
$display("%b", obj.arr[0]); // 1100
$display("%b", obj.arr[1]); // 1100
end
endprogram
注意constraint c0里的foreach约束语法格式foreach(arr[i, j])
网友评论