Vengineerの妄想

人生は短いけど、長いです。人生を楽しみましょう!

Bluespec SystemVerilog : COUNTERを学ぶ(その6)

Verification Engineerの戯言


(その5)では、Counterインターフェースの内部カウンタのビット幅をパラメータにしました。
今回は、内部カウンタ、そのものをパラメータにするときの方法です。

 ビット幅をパラメータ化

    interface Counter#(type size_t);
      method Bit#(size_t) read();
      method Action increment();
      method Action decrement();
      method Action load(Bit#(size_t) newval);
    endinterface

 内部カウンタの型をパラメータ化

    interface Counter#(type count_t);
      method count_t read();
      method Action increment();
      method Action decrement();
      method Action load(count_t) newval);
    endinterface

Bit#(size_t)count_tに置き換わりました。
(SystemVerilogでは#(type count_t)という記述になります。)

この変更によりmkCounterモジュールも次のように変更します。

    module mkCounter(Counter#(count_t))
           provisos(Arith#(count_t), Bits#(count_t, count_t_sz));
      Reg#(count_t) value <- mkReg(0);

      method count_t read();
        return value;
      endmethod

      method Action load(count_t newval);
        value <= newval;
      endmethod

Regのインスタンス部およびread/loadメソッドでは、Bit#(size_t)count_tになるだけです。

新しいキーワードprovisosの行が追加されました。
provisosについては、リファレンスガイドの4.2および14.1.1に詳しい説明がありますので、ここでは説明しません。

検証、Verification、Bluespec SystemVerilog