[英]how to operate unique with “with” operator in systemverilog
我是一个 systemverilog 用户,我遇到了一个奇怪的(从我的角度来看)结合使用固定数组的独特方法与“with”子句的行为。
module tb;
int array[9] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
int res[$];
initial begin
res = array.unique(x) with (x <= 3);
$display ("unique : %p", res);
end
endmodule
我希望得到队列 {2,1,3},但我得到了 {4,2}。
我不明白为什么在索引 0 处有一个? 为什么结果中缺少 2 和 3?
让我解释一下你得到的结果。
unique
方法的with
子句定义了用于确定唯一性的表达式。 它将从具有匹配表达式的元素集中删除除一个任意元素之外的所有元素。
由于您选择了结果为 1'b0 或 1'b1 的表达式,因此它选择了x <= 3
为真 (2) 的四个元素 (2, 1, 3, 1) 中的一个,以及五个元素 (4, 7, 5, 7, 6) 是错误的 (4)。
您正试图在单个操作中将find
方法与unique
方法结合起来。 它不是那样工作的。 您必须在两个单独的操作中执行此操作:
module tb;
int array[9] = '{4, 7, 2, 5, 7, 1, 6, 3, 1};
int res[$];
initial begin
res = array.find(x) with (x <= 3);
res = res.unique;
$display ("unique : %p", res);
end
endmodule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.