簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM