[SystemVerilog语法拾遗] 一文讲清楚SystemVerilog中的阻塞赋值与非阻塞赋值

本文探讨了SystemVerilog中的阻塞赋值与非阻塞赋值,强调了它们在并行执行和仿真调度中的角色,以及遵循CliffordCummings的编程原则的重要性。文章还涉及UVM中driver和monitor的不同赋值策略,以及如何在实际项目中避免潜在的竞争和不确定性问题。

[SystemVerilog语法拾遗] 一文讲清楚SystemVerilog中的阻塞赋值与非阻塞赋值

引言

我们设计的硬件、仿真环境抽象意义上是可以并行运行的。但是在实际仿真时,不过是运行在cpu上的串行执行的程序而已(先不讨论多核)。SystemVerilog专门为这种并行到串行的转换定义了调度机制。但IEEE在制定规范时,并未规定一部分并行的事件执行的先后顺序,这点会引入不确定性(Nondeterminism),这种不确定性往往会体现在不同厂家的仿真器上(因为不同的厂家采用的调度算法是不一样的),最严重的后果就是在不同仿真器上看到的最终结果是不一样的。所以作为一名合格的工程师,应该对sv仿真器的调度机制、确定性与不确定性有基础的了解。(引用 SystemVerilog调度机制与一些现象的思考_uvm_wait_for_nba_region-CSDN博客

本文首先结合SystemVerilog标准中关于语句执行的调度顺序的描述理解一些基本概念,再从Clifford Cummings大神在SNUG-2000上发表的排名第1的文章"Nonblocking Assignments in Verilog Synthesis, Coding Style That Kill!"来讲述使用阻塞赋值和非阻塞赋值应该遵循的一些原则,最后再以项目实例介绍为什么UVM中driver要使用非阻塞赋值而monitor中要使用阻塞赋值,然后引申出SystemVerilog中两种赋值类型使用时的一些注意事项。

《IEEE SystemVerilog 1800-2017》标准相关内容介绍

我们先看下《IEEE SystemVerilog 1800-2017》标准中对于"Scheduling semantics"的一些关键描述。

SystemVerilog is a parallel programming language. The execution of certain language constructs is defined by parallel execution of blocks or processes. It is important to understand what execution order is guaranteed to the user and what execution order is indeterminate.(SystemVerilog是并发执行的程序语言,该语言的执行完全由其定义的并发执行的语句块和进程决定,理解并发执行时哪些执行顺序是确定的、哪些是不确定的,这一点很重要。)
The SystemVerilog language is defined in terms of a discrete event execution model.(SystemVerilog是为离散事件执行模型(discrete event execution)所定义的一种语言。)
A SystemVerilog description consists of connected threads of execution or processes. (SystemVerilog是由一系列相关联的进程所组成的。进程(Processes)是SystemVerilog中并发调度的单元,比如:原语(Primitives)、initial过程块、always过程块、连续赋值(continuous assign)、异步任务(asynchronous tasks)、过程赋值(procedural assignment)等。进程是可以被执行的,有相应的状态标志(state,比如挂起)。进程会响应输入的变化并产生对应的输出。SystemVerilog的描述的对象也正是这些进程。)
Every change in state of a net or variable in the system description being simulated is considered an update event.(仿真中,net或者variable上每次的变化被认为是一次更新事件)
Processes are sensitive to update events. When an update event is executed, all the processes that are sensitive to that event are considered for evaluation in an arbitrary order. The evaluation of a process is also an event, known as an evaluation event.(进程对更新事件敏感!当一个更新事件被执行时,所有对该更新事件敏感的进程都会被求值,但是顺序是任意的。进程的求值本身也被认为是一种事件,即求值事件(evaluation event)。更新事件和求值事件的相互交替执行,推动了仿真时间的前移。)
In addition to events, another key aspect of a simulator is time . The term simulation time is used to refer to the time value maintained by the simulator to model the actual time it would take for the system description being simulated.The term time is used interchangeably with simulation time in this clause.
To fully support clear and predictable interactions, a single time slot is divided into multiple regions where events can be scheduled that provide for an ordering of particular types of execution

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值