简体   繁体   English

在systemverilog中与“ with”运算符唯一

[英]unique with “with” operator in systemverilog

I am a new 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 operator. 我是SystemVerilog的新用户,从我的角度来看,我遇到了一种奇怪的行为(从我的角度来看),该行为称为固定数组with操作符结合在一起的唯一方法的组合。

module test();
  int arr[12] = '{1,2,1,2,3,4,5,8,9,10,10,8};
  int q[$]
  initial begin
    q = arr.unique() with (item > 5 ? item : 0);
    $display("the result is %p",q);
  end

I've expected to get queue {8,9,10} but instead I have got {1,8,9,10}. 我期望得到队列{8,9,10},但我却得到了{1,8,9,10}。

Why there is a one at the index 0 ? 为什么索引0处有一个1?

You are trying to combine the operation of the find method with unique . 您正在尝试将find方法的操作与unique结合起来。 Unfortunately, it does not work the way you expect. 不幸的是,它不能按您期望的方式工作。 unique returns the element, not the expression in the with clause, which is 0 for elements 1,2,3,4 and 5. The simulator could have chosen any of those elements to represent the unique value for 0(and different simulators do pick different values) unique返回元素,而不是with子句中的表达式,元素1,2,3,4和5的元素为0。模拟器可能选择了那些元素中的任何一个来表示0的唯一值(不同的模拟器会选择不同的值)

You need to write them separately: 您需要分别编写它们:

module test();
  int arr[$] = '{1,2,1,2,3,4,5,8,9,10,10,8};
  int q[$]
  initial begin
    arr = arr.find() with (item > 5);
    q = arr.unique();
    $display("the result is %p",q);
  end

Update explaining the original results 更新说明原始结果

The with clause generates a list of values to check for uniqueness with子句生成值列表以检查唯一性

'{0,0,0,0,0,0,0,8,9,10,10,8};
  ^.            ^ ^ ^

Assuming the simulator chooses the first occurrence of a replicated value to remain, then it returns {arr[0], arr[7], arr[8], arr[9]} from the original array, which is {1,8,9,10} 假设模拟器选择了要保留的复制值的第一个匹配项,那么它会从原始数组{1,8,9,10}返回{arr[0], arr[7], arr[8], arr[9]} {1,8,9,10}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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