【发布时间】:2016-06-29 17:06:59
【问题描述】:
我正在尝试以循环方式随机化系统 verilog 中的 3 个不同变量。我的意思是,我有以下 3 个变量
rand int a;
rand int b;
rand int c;
constraint c_a{
a inside {1,2};
}
constraint c_b{
b inside {1,2,3,4,5,6};
}
constraint c_c{
c inside {1,2,3}
}
有了上述约束,所有 3 个变量的组合共有 36 种 (2x6x3)。
但是如果我们运行一个 36 的循环,像这样:
repeat(36) begin
this.randomize(a,b,c);
$display("%d %d %d", a,b,c);
end
我们不会击中所有可能的组合,因为某些组合可能会重复。因此,我正在寻找一种方法,通过准确地运行循环 36 次来达到所有这些组合。
我通过声明另一个 rand 变量来表示每个组合并像这样使用 randc 来编写一个蛮力方法来做到这一点:
int a;
int b;
int c;
randc int k;
constraint c_k{
k inside {[1:36]};
}
repeat(36) begin
this.randomize(k);
// randomizing variable 'a' to one of the 2 values.
if(k<9)
a = 1;
else
a = 2;
// randomizing variable 'b' to one of the 6 values.
case(k)
1,2,3,19,20,21 : b = 1;
4,5,6,22,23,24 : b = 2;
7,8,9,25,26,27 : b = 3;
//
// finishing the sequence
//
endcase
case(k)
// similar case statement for the final variable
endcase
$display("%d, %d, %d", a,b,c);
end
上述方式效果很好,但对我来说,这似乎是一种忙碌的方式(也不能应用于大型组合),因此想知道是否有更优雅的方法来实现这一点。
感谢您的帮助。
【问题讨论】:
标签: constraints verilog system-verilog