SystemVerilogランドケース



Systemverilog Randcase



ソルバーに多くの文の1つをランダムに選択させたい状況に遭遇することがあります。キーワードrandcaseは、そのブランチの1つをランダムに選択するcaseステートメントを導入します。ケースアイテム式は正の整数値であり、各アイテムに関連付けられた重みを表します。製品を選択する可能性は、製品の重量をすべての重量の合計で割ることによって得られます。

構文

randcase item : statement ... endcase

すべての重みの合計は9であるため、最初のブランチを選択する確率は1/9または11.11%、2番目のブランチを選択する確率は5/9または55.56%、最後のブランチを選択する確率は3 /です。 9または33.33%。



module tb initial begin for (int i = 0 i < 10 i++) randcase 1 : $display ('Wt 1') 5 : $display ('Wt 5') 3 : $display ('Wt 3') endcase end endmodule Simulation Log ncsim> run Wt 5 Wt 5 Wt 3 Wt 5 Wt 1 Wt 3 Wt 5 Wt 3 Wt 3 Wt 5 ncsim: *W,RNQUIE: Simulation is complete.

最大発生回数は5回、最小発生回数は1回、2回の出現回数は3回であることに注意してください。
ブランチに割り当てられた重みがゼロの場合、ブランチは採用されません。

module tb initial begin for (int i = 0 i < 10 i++) randcase 0 : $display ('Wt 1') 5 : $display ('Wt 5') 3 : $display ('Wt 3') endcase end endmodule Simulation Log ncsim> run Wt 5 Wt 5 Wt 3 Wt 5 Wt 5 Wt 3 Wt 5 Wt 3 Wt 3 Wt 5 ncsim: *W,RNQUIE: Simulation is complete.

すべてのrandcase_itemsがゼロの重みを指定している場合、それが意味をなさない場合でも、分岐は行われず、実行時警告が発生する可能性があります。



module tb initial begin for (int i = 0 i < 10 i++) randcase 0 : $display ('Wt 1') 0 : $display ('Wt 5') 0 : $display ('Wt 3') endcase end endmodule Simulation Log ncsim> run ncsim: *W,RANDNOB: The sum of the weight expressions in the randcase statement is 0. No randcase branch was taken. File: ./testbench.sv, line = 4, pos = 14 Scope: tb.unmblk1 Time: 0 FS + 0 ncsim: *W,RANDNOB: The sum of the weight expressions in the randcase statement is 0. No randcase branch was taken. File: ./testbench.sv, line = 4, pos = 14 Scope: tb.unmblk1 Time: 0 FS + 0 ncsim: *W,RANDNOB: The sum of the weight expressions in the randcase statement is 0. No randcase branch was taken. File: ./testbench.sv, line = 4, pos = 14 Scope: tb.unmblk1 Time: 0 FS + 0 ...

参照:
【1】https://www.chipverify.com/systemverilog/systemverilog-randcase