SystemVerilogのパッケージの概要

1.パッケージの定義:

package 包名;     

endpackage

パッケージは独立した宣言スペースであり、複数のモジュールがユーザー定義の型を共有します。

2.パッケージに含めることができる合成可能な構造:

1)パラメーターとlocalparamの定数定義;
2)constは変数を定数として定義します;
3)typedefユーザー定義型;
4)自動タスクと関数の定義(自動として宣言する必要があり、ストレージ領域は呼び出されるたびに割り当てられます簡単な統合);
5)他のパッケージからステートメントをインポートします;
6)演算子のオーバーロード定義。

3.パッケージの見積もり方法:

1)スコープ解決演算子を使用して::直接引用します
。2)パッケージ内の特定のサブアイテムをモジュールまたはインターフェイス
*インポートします。3)ワイルドカードを使用してパッケージ内のサブアイテムをモジュールまたはインターフェイスインポートします。

たとえば、4つです。

package definitions;

    parameter Version = "1.1";
    typedef enum  {
    
    ADD,SUB,MUL} opcode_t;
    typedef struct{
    
    
        logic [31:0]a,b;
        opcode_t opcode;
    } instruction_t;

    function automatic [31:0]multiplier(input [31:0]a,b);

        return a*b;
      
    endfunction

endpackage

直接参照方法:

module ALU( input definitions::instruction_t IW,
            input logic clock,
            output logic [31:0]result);

            always_ff @(posedge clock) begin
                case(IW.opcode)
                    definitions::ADD:result = IW.a+IW.b;
                    definitions::SUB:result = IW.a-IW.b;
                    definitions::MUL:result = definitions::multiplier(IW.a,IW.b);
                endcase
                
            end
endmodule

インポートを使用して導入します。

module  ALU(input definitions:: instruction_t  IW ,
 			input  logic clock,
 			output logic [31:0] result);

		import definitions:: ADD;
		import definitions:: SUB;
		import definitions:: MUL;
		import definitions:: multiplier;
		always_comb begin
		   case (IW.opcode)
		   ADD: result = IW.a +IW.b;
		   SUB: result = IW.a -IW.b;
		   MUL: result = multiplier(IW.a, IW.b);
		   endcase
		end
endmodule

よりインポートインポートコードの4行よりも、次のように使用することができるtestbenchimport definitions:: *;使い捨てに、すなわち全てのサブキーの代わりに、そのようなものとして、直接使用することができるADDが、書き込まれていませんdefinitions::ADD

import definitions::*;
	module  tb_ALU;
	instruction_t  test_word ;
	logic [31:0] alu_out;
	logic  clock = 0;
	ALU dut(.IW(test_word), .result(alu_out), .clock(clock));
	always #10 clock = ~clock;
	initial begin @(negedge clock)
	          test_word.a = 5;
	          test_word.b =7;
	          test_word.opcode = ADD;
	          @(negedge clock)
	          $display(“alu_out = %d (expected 12), alu_out);
	          $finish;
	end
endmodule

おすすめ

転載: blog.csdn.net/qq_39507748/article/details/112001851