ランダム制約 - 2023.2 日本語

Vivado Design Suite チュートリアル: ロジック シミュレーション (UG937)

Document ID
UG937
Release Date
2023-11-01
Version
2023.2 日本語

SystemVerilog にはランダム制約があり、ランダム値を生成するのに使用されます。この機能を使用して、制約にランダム変数を設定することもできます。

各シミュレーションで固定数の値を生成するよう、シミュレータはサポートされています。この例では、ランダム化呼び出しは 10 回実行され、シミュレータにより毎回、変数「b1」に対し異なる値が割り当てられます。シミュレーションを閉じ、もう一度実行すると、前回の実行と同じようにまた 10 セットの値が割り当てられます。これはランダム安定性と呼ばれます。

module top();
class c1;
rand bit [3:0] b1;
endclass
c1 obj1 = new();
initial
begin
    for(int i = 0; i < 10; i++)
    begin
        #5 obj1.randomize();
        $display("At time %t the value is %p", $time, obj1);
   end
end
endmodule

セット数を変更する場合は、ランダム シード値を変更する必要があります。AMD Vivado™ シミュレータでは、xsim に -seed オプションを使用すると、この変更が可能です。[Tcl Console] ウィンドウに次のコマンドを入力します。

set_property -name {xsim.simulate.xsim.more_options} -value {-seed 2000} -objects [get_filesets sim_adv_mst_active__pt_passive__slv_comb]

シードには整数値を指定する必要があります。このシード値を変更するだけで、異なるセット数を設定できます。この変更を加えた後に、もう一度コンパイルやエラボレーションを実行する必要はありません。

  1. ファイルに次のコードを追加し、ファイル名を random.sv にします。
    module top();
    class c1;
    rand bit [3:0] b1;
    endclass
    c1 obj1 = new();
    initial
    begin
        for(int i = 0; i < 10; i++)
        begin
            #5 obj1.randomize();
            $display("At time %t the value is %p", $time, obj1);
       end
    end
    endmodule
  2. 次の手順を実行します。
    1. xvlog -sv random.sv コマンドを実行して、コードをコンパイルします。
    2. xelab top -s top コマンドを実行して、コードをエラボレートします。
    3. xsim top run -all コマンドを実行して、コードをシミュレーションします。
    出力を確認します。

    run -all

    At time                 5000 the value is '{b1:3}
    At time                10000 the value is '{b1:7}
    At time                15000 the value is '{b1:7}
    At time                20000 the value is '{b1:0}
    At time                25000 the value is '{b1:0}
    At time                30000 the value is '{b1:5}
    At time                35000 the value is '{b1:9}
    At time                40000 the value is '{b1:3}
    At time                45000 the value is '{b1:12}
    At time                50000 the value is '{b1:0}
    
  3. exit と入力してシミュレーションを終了し、手順 2c をもう一度実行し、値が前回の値と似ていることを確認します。
    注記: これを AMD Vivado™ GUI で実行している場合は、exit ですべての Vivado を終了して、手順 2c だけでなく、すべての手順 2 を再び実行する必要があります。
  4. 異なる SystemVerilog シード (xsim top -sv_seed 5000) でコードをシミュレーションし、値が異なることを確認します。これで、コンパイルおよびエラボレーションを実行せずに、異なる値を生成できます。