转载请标明出处

一、     System Verilog 声明的位置

1.       包(packages)

Verilog要求局部声明:

variables, nets, tasks and functions的声明需要在模块内部的module...endmodule关键词之间

System Verilog 增加了用户定义类型typedef

i.              包的定义

包在packageand endpackage.之间定义。

包中可以包含的可综合的结构有:

         parameter and localparam constant definitions常量

const variable definitions变量

typedef user-defined types用户定义类型

• Fully automatic task and function definitions

import statements from other packages

• Operator overload definitions

模块中的每个实例可以对parameter重新定义,但是包中不能。包中的参数不能重新定义

为了能够综合,包中的定义的task和function必须声明为automatic,且不能包含静态变量

Example: 一个包的定义

package definitions;                                                                //定义一个包

parameter VERSION = "1.1";                                                //定义包中一个参数

typedef enum{ADD, SUB, MUL} opcodes_t;                   //定义包中枚举opcodes_t

typedef struct {

logic [31:0] a, b;

opcodes_t opcode;

} instruction_t;                                                                         //定义包中结构体instruction_t

function automatic [31:0] multiplier (input [31:0] a, b);//定义函数function,其中参数为a,b

return a * b; // 用户定义的function代码从这开始

endfunction                                                                              //function定义结束

endpackage                                                                               //包定义结束

i. 引用包的内容

模块和接口可以用四种方式引用包中的定义和声明:

1. 用范围解析操作符” :: ”直接引用

2. 将包中特定子项导入(import)到module or interface中

3. 将通配符(*)导入包中的子项到module or interface

4. 将包中子项导入(通过import且可使用*)到$unit声明域中(module外)

For 1:

module ALU

(input definitions::instruction_t IW,                                                        //用范围解析操作符::引用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包中的枚举ADD

definitions::SUB : result = IW.a - IW.b;

definitions::MUL : result = definitions::

multiplier(IW.a, IW.b);

endcase

end

endmodule

For 2:

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

import definitions::ADD;                     //用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

import导入方式是将每个子项逐个导入,在有许多子项需要从包中导入时并不实用,此时使用通配符导入会更实用。

For 3:

通配符导入方式:import definitions::*; // wildcard import 通配符导入不能自动导入包中所有内容,只有在模块/接口中实际引用的子项被导入进来了。

module ALU
(input definitions::instruction_t IW,
input logic clock,
output logic [31:0] result
);
import definitions::*; // 通配符导入。实际上是将包添加到标识符搜索路径中
always_comb begin
  case (IW.opcode)
    ADD : result = IW.a + IW.b;//引用ADD时,在definitions包中查找该名称的定义
    SUB : result = IW.a - IW.b;
    MUL : result = multiplier(IW.a, IW.b);
  endcase
end
endmodule

For 4:

$编译单元声明(不可综合):

只作用于同时编译的源文件(每次编译为一个单元,多次编译之间互不影响)

SV允许在package, module, interface and program block 的外部进行声明。这些外部声明在“编译单元域”(compilation-unit scope)中,并且对所有同时编译的module可见

编译单元contain:

  1. 时间单元和精度声明 2.Variable declarations3. Net declarations 4. Constant declarations    5. User-defined data types, using typedef, enum or class        6. Task and function definitions

可在$unit中声明的可综合结构有:

  1. typedef用户定义类型定义(最好放在包内)   2.Automatic functions

3.Automatic tasks  4. parameter and localparam constants      5.包import

因此,1.不要在$unit空间进行声明,声明在命名包中进行

2.可将包import到$unit

3.import语句要出现在包中子项被引用前

 

import definitions::instruction_t;       //或者import definitions::*;

 

module ALU

(input instruction_t IW,

input logic clock,

output logic [31:0] result

);

加入条件编译后:(条件编译包文件的文件名:definitions.pkg)

`ifndef DEFS_DONE // if the already-compiled flag is not set...

`define DEFS_DONE // set the flag

package definitions;

********//包定义

endpackage

import definitions::*; // import package into $unit

`endif

需要包含条件编译包文件的设计文件:

`include "definitions.pkg" // 编译包文件

module ALU

(input instruction_t IW,   //前面已通过import definitions::*导入包中子项instruction_t

......

endmodule

 

 

ii. 综合指导

1.为了能够综合,包中定义的task和function必须声明为automatic,且不能包含静态变量。

2.综合不支持包中变量声明,静态任务和静态函数。

仿真时,包中变量会被导入该变量的模块共享,而不是通过module port传递数据的模块间通信,是不可综合的

2. 未命名语句块的声明

命名块中的局部变量声明:

Verilog在命名的begin...end 或 fork ... join块中声明局部变量。可对局部变量进行层次化引用(引用命名块里面的局部变量,但是不可综合)

SV可在未命名的begin...end 或 fork ... join块中声明局部变量。,不能对局部变量进行层次化引用(因为块没名啊= =)

3. 仿真时间单位和精度

对比:

A.Verilog使用‘timescale 1ns / 10ps,1ns是时间单位,10ps是时间精度(多个源文件中可对时间单位进行重新定义,若一个源文件未定义,根据编译顺序决定其时间单位)

B.SV可给时间值指定时间单位:forever #5ns clock = ~clock;

SV中支持范围级时间单位:

module adder (input wire [63:0] a, b,);

timeunit 1ns;     //局部时间单元,只在该mudule中有效

timeprecision 10ps;  //局部时间精度,只在该mudule中有效

...

endmodule

时间值单位及精度具体使用哪个来确定采取就近原则(个人理解)

Systemverilog for design 笔记(一)的更多相关文章

  1. Systemverilog for design 笔记(七)

    转载请标明出处 第一章 接口(interface) 1.1.    接口的概念 接口允许许多信号合成一组由一个端口表示. 1.2.    接口声明 //接口定义 Interface main_bus ...

  2. Systemverilog for design 笔记(六)

    转载请标明出处 第一章 有限状态机建模(FSM,finite state machine) 1.1.    使用枚举类型建立状态机模型 l  三过程块建模风格:三个过程块分别实现: a.状态转换(al ...

  3. Systemverilog for design 笔记(五)

    转载请标明出处 第一章 System Verilog过程块.任务和函数 1.1.    verilog通用目的always过程块(procedural block)(可综合) always过程块的综合 ...

  4. Systemverilog for design 笔记(四)

    转载请标明出处 数组.结构体和联合体 1. 结构体(struct) 1.1. 结构体声明 结构体默认是变量,也可以声明为线网 var struct { // 通过var进行结构体变量声明 logic ...

  5. Systemverilog for design 笔记(三)

    转载请标明出处 用户自定义和枚举数据类型 1. 用户自定义类型(typedef) 局部typedef定义:只用于设计的特定部分时,typedef的定义可在module或interface中 共享typ ...

  6. SystemVerilog for design 笔记(二)

    转载请标明出处 1. System Verilog文本值和数据类型 1.1. 增强的文本值赋值 相对于verilog,SV在文本值赋值时可以1.无需指定进制    2.赋值可以是逻辑1 用法: reg ...

  7. Spring Cloud 微服务实战笔记

    Spring Cloud 微服务实战笔记 微服务知识 传统开发所有业务逻辑都在一个应用中, 开发,测试,部署随着需求增加会不断为单个项目增加不同业务模块:前端展现也不局限于html视图模板的形式,后端 ...

  8. 一段比较有意思的代码——介绍system verilog中的新增幅值语句

    system verilog中新加了很多幅值语句,虽然都只适用于阻塞幅值,但是在某些场合中非常实用. 下面是一段有意思的代码,覆盖了一些用法. package definitions; typedef ...

  9. Design Patterns笔记

    一些笔记. strategy : facilitates the switch of the different but related algorithms/behaviors observer p ...

随机推荐

  1. composer update 或者 composer install提示killed解决办法

    出现此原因大多因为缓存不足造成,在linux环境可增加缓存解决. free -mmkdir -p /var/_swap_cd /var/_swap_#Here, 1M * 2000 ~= 2GB of ...

  2. HashMap遍历,取出key和value

    HashMap的遍历有两种常用的方法,那就是使用keyset及entryset来进行遍历,在用keySet(key)取value时候,需要key 第一种: Map map = new HashMap( ...

  3. python匿名函数与三元运算

      匿名函数 匿名函数就是不需要显示式的指定函数名 首先看一行代码: def calc(x,y): return x*y print(calc(2,3)) # 换成匿名函数 calc = lambda ...

  4. jsp用equals判断两个字符串变量是否相等

    使用即可: s1.equals(s2) 如果使用场景: if(s1==s2){} 这样使用可能会出现判断无效的情况. 使用if(s1.equals(s2)){}就可以了.

  5. linux chrome rpm chrome浏览器下载(ver 63-70)

    我的github chrome下载地址:https://github.com/chen1932390299/python 国内开源的资源 chrome下载centos 的:https://www.ch ...

  6. 不要在mutation回调函数之外,修改vuex仓库里属性的状态

    [vuex] do not mutate vuex store state outside mutation handlers. import * as types from './mutation- ...

  7. Top 9 colleges in the world from 2010 to 2020, AI and interdisciplinary areas.

    http://csrankings.org/

  8. SpringBoot+MyBatis+PageHelper分页无效

    POM.XML中的配置如下:<!-- 分页插件 --><!-- https://mvnrepository.com/artifact/com.github.pagehelper/pa ...

  9. cf--TV Subscriptions (Hard Version)

    time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standa ...

  10. Cocos纹理理解

    原文:https://blog.csdn.net/u010223072/article/details/78287294 理论要点 要点一: 文件格式与像素格式的区别:文件格式是图像为了存储信息而使用 ...