SystemVerilog for Design(Chapter2)--SystemVerilog Declaration Spaces

SystemVerilog for Design(Chapter2)–SystemVerilog Declaration Spaces

Topic:

  • Packages definitions and importing definitions from packages
  • $unit compilation declaration space
  • Declarations in unnamed blocks
  • Enhanced time unit definitions

1. Packages definitions and importing definitions from packages

1.1 Package definitions

SystemVerilog adds usr-defined types , using typedef. To enable sharing a usr-defined type definition accross multiple modules , SystemVerilog adds package to the Verilog language, defined between the keywords package and ** endpackage**.

A package which is synthesizable one can contain:

  • parameter and localparam constant definitions
  • const variable definitions
  • typedef usr-define types
  • fully automatic task and function definitions
  • import statement from other packages.
  • Operator overload definitions
    Package can also contain global variable declarations, static task and static function definitions. we won’t discuss these in this blog.

Package definitions are independent of modules. A simple example of a package definition is :

package definitions;
	parameter VERSION = "1.1";
	typedef enum {
   ADD,SUB,MUL} opcodes_t;
	typedef struct{
   
		logic [31:0] a,b;
		opcodes_t opcode;
	} instruction_t;
	function automatic [31:0] multiplier (input [31:0] a, b);
		//code for a custom 32bit multiplier goes here;
		return a*b;//abstract multiplier (no error detection)
	endfunction
endpackage

In a package,a parameter constant can not be redefined, since it is not part of a module instance. In a package, parameter and localparam are synonymous.

1.2 Referencing Package Contents

Package references using the scope resolution operator, SystemVerilog adds a :: “scope resolution operator” to Verilog.

Example 2-2: Explicit package references using the :: scope resolution operator

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
SystemVerilog allows specific package items to be imported into a module, using an import statement.

Example 2-3: Importing specific package items into a module

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

NOTE-> Importing an enumerated type definition does not import the labels used within that definition.
"import definitions::opcode_t;" wouldn’t work.

Wildcard import of package items

A

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这本书,超赞。强烈推荐!!!!!有很多很好的用例! Foreword ................................................................................................................. xxi Preface ................................................................................................................... xxiii Target audience...................................................................................................................... xxiii Topics covered........................................................................................................................xxiv About the examples in this book..............................................................................................xxv Obtaining copies of the examples...........................................................................................xxvi Example testing.......................................................................................................................xxvi Other sources of information .................................................................................................xxvii Acknowledgements..................................................................................................................xxx Chapter 1: Introduction to SystemVerilog...............................................................1 1.1 SystemVerilog origins.......................................................................................................1 1.1.1 Generations of the SystemVerilog standard.......................................................2 1.1.2 Donations to SystemVerilog ..............................................................................4 1.2 Key SystemVerilog enhancements for hardware design...................................................5 1.3 Summary ...........................................................................................................................6 Chapter 2: SystemVerilog Declaration Spaces ....................................

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值