简体   繁体   English

如何在 systemverilog 中使用“with”运算符进行唯一操作

[英]how to operate unique with “with” operator in systemverilog

I am a systemverilog user and I have faced a strange (from my point of view) behavior of combination of unique method called for fixed array with "with" clause.我是一个 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

I've expected to get queue {2,1,3} but instead I have got {4,2}.我希望得到队列 {2,1,3},但我得到了 {4,2}。

I can't understand Why there is a one at the index 0?我不明白为什么在索引 0 处有一个? and Why are 2 and 3 missing from the result?为什么结果中缺少 2 和 3?

Let me explain the result you were getting.让我解释一下你得到的结果。

The with clause of the unique method defines the expression used to determine uniqueness . unique方法的with子句定义了用于确定唯一性的表达式。 It will delete all but one arbitrary element from the set of elements having matching expressions.它将从具有匹配表达式的元素集中删除除一个任意元素之外的所有元素。

Since you chose an expression having a result of 1'b0 or 1'b1, it chose one out of the four elements (2, 1, 3, 1) where x <= 3 was true (2), and one out of the five elements (4, 7, 5, 7, 6) where it was false (4).由于您选择了结果为 1'b0 或 1'b1 的表达式,因此它选择了x <= 3为真 (2) 的四个元素 (2, 1, 3, 1) 中的一个,以及五个元素 (4, 7, 5, 7, 6) 是错误的 (4)。

You are trying to combine the find method with the unique method in a single operation.您正试图在单个操作中将find方法与unique方法结合起来。 It doesn't work that way.它不是那样工作的。 You have to do it in two separate operations:您必须在两个单独的操作中执行此操作:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM