SystemVerilog 约束,每第 n 次迭代固定值
SystemVerilog Constraint, Fixing value every nth iteration
class Base
rand bit b;
// constraint c1 { every 5th randomization should have b =0;}
endclass
我知道我可以创建一个静态计数变量并更新该计数变量,然后在约束条件下我可以检查 count%5 是否为零,然后使 b=0,但是有更好的方法吗?谢谢
无需将计数设置为静态,只需非随机即可。
class Base;
rand bit b;
int count;
constraint c1 { count%5 -> b==0;}
function post_randomize();
count++;
endfunction
endclass
如果你知道b
的上限,那么你可以像下面这样写一个约束。
constraint abc
{
b dist {0:=20, 1:=80}
}
这将使 0
的权重变为 20
,1
的权重变为 80
。所以这样一来,每5次随机化就会出现一次0。
class Base
rand bit b;
// constraint c1 { every 5th randomization should have b =0;}
endclass
我知道我可以创建一个静态计数变量并更新该计数变量,然后在约束条件下我可以检查 count%5 是否为零,然后使 b=0,但是有更好的方法吗?谢谢
无需将计数设置为静态,只需非随机即可。
class Base;
rand bit b;
int count;
constraint c1 { count%5 -> b==0;}
function post_randomize();
count++;
endfunction
endclass
如果你知道b
的上限,那么你可以像下面这样写一个约束。
constraint abc
{
b dist {0:=20, 1:=80}
}
这将使 0
的权重变为 20
,1
的权重变为 80
。所以这样一来,每5次随机化就会出现一次0。