簡體   English   中英

在systemverilog中與“ with”運算符唯一

[英]unique with “with” operator in systemverilog

我是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

我期望得到隊列{8,9,10},但我卻得到了{1,8,9,10}。

為什么索引0處有一個1?

您正在嘗試將find方法的操作與unique結合起來。 不幸的是,它不能按您期望的方式工作。 unique返回元素,而不是with子句中的表達式,元素1,2,3,4和5的元素為0。模擬器可能選擇了那些元素中的任何一個來表示0的唯一值(不同的模擬器會選擇不同的值)

您需要分別編寫它們:

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

更新說明原始結果

with子句生成值列表以檢查唯一性

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

假設模擬器選擇了要保留的復制值的第一個匹配項,那么它會從原始數組{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