正文
记录个在写SystemVerilog随机约束时遇到的一个小坑,如果没有认真去查看随机结果是否符合预期,还真不容易发现。
为了方便讲述,写了如下示例代码。类cl_a里有个随机变量aa,初始值为222。在module top里对类cl_a例化并进行约束随机。
class cl_a;
rand int aa = 222;
endclass
module top;
cl_a a;
int b = 1;
initial begin
a = new();
$display("[initial]=> aa:%0d", a.aa);
assert ( a.randomize() with { aa == (b == 1) ? 666 : 999;} )
else $fatal;
$display("[random1]=> aa:%0d", a.aa);
assert ( a.randomize() with { aa == ((b == 1) ? 666 : 999);} )
else $fatal;
$display("[random2]=> aa:%0d", a.aa);
assert ( a.randomize() with { aa == (b == 1);} )
else $fatal;
$display("[random3]=> aa:%0d"

1万+

被折叠的 条评论
为什么被折叠?



