class内のtask/functionはautomaticになる SystemVerilog

Systemverilog

はじめに

task/functionはデフォルトでstaticで宣言されるので注意が必要です。

しかし、LRM 11.9よりclass内のtask/functionはautomaticで宣言されます。

解説

sample1.sv

まずは、普通にtaskを定義します。この場合デフォルトでstaticとなります。

task tkは#10待ってaが1ならTrue、aが0ならFalseを出力します。

module top;
    task tk(input a);  // static
        #10;
        if (a)
            $display("True");
        else 
            $display("False");
    endtask

    initial begin
        fork
            tk(0);
        join_none
        #1;
        tk(1);
    end
endmodule
// 出力
// True
// True
sample2.sv

次に、class内で同じようにtaskを定義します。class内なのでデフォルトでautomaticとなります。

module top;
    class sample;
        task tk(input a);  // automatic
            #10;
            if (a)
                $display("True");
            else 
                $display("False");
        endtask
    endclass

    sample a;
    initial begin
        fork
            a.tk(0);  // 1回目
        join_none
        #1;
        a.tk(1);  // 2回目
    end
endmodule
// 出力
// False
// True

1回目のa.tkのコールでは0を渡しています。2回目のa.tkのコールでは1を渡しています。

task tkがstaticで宣言されていれば、1回目、2回目のa.tkともにTrueが出力されます。

しかし、class内のtask/functionはデフォルトではAutomaticなので、FalseとTrueが出力されています。

まとめ

class内のtask/functionのstatic/automaticついてまとめました。

コメント

タイトルとURLをコピーしました