VHDL的皇冠明珠
VHDL's Crown Jewel

原始链接: https://www.sigasi.com/opinion/jan/vhdls-crown-jewel/

## VHDL 与 Verilog:确定性的关键 本文重点介绍了 VHDL 和 Verilog 之间的一个关键区别:**确定性**。VHDL 通过其“delta 循环”算法实现可预测的结果。该系统将信号更新和过程评估分为不同的阶段。信号更新首先发生,触发过程,然后过程更新信号——但这些更新被安排在*未来*的 delta 循环中。这确保了过程始终看到信号值的稳定快照,无论每个阶段内的执行顺序如何,从而保证了确定性的结果。 Verilog 缺乏这种分离。信号更新和过程评估可以交错进行,这意味着过程可能会根据执行顺序观察到不同的值,从而导致非确定性行为。虽然 Verilog 的非阻塞赋值*延迟*更新,但它们并未强制执行 VHDL 的分阶段方法。 作者认为 VHDL 的 delta 循环是其最强大的特性,以最小的开销提供内置的确定性。虽然 Verilog 可以通过使用非阻塞赋值在特定的同步设计中实现确定性,但这并非普遍保证。VHDL 依赖于信号进行过程间通信,而信号本质上利用了 delta 循环,这有助于其一致的行为,与 Verilog 依赖 `reg` 类型以及阻塞赋值与非阻塞赋值的复杂性形成了鲜明对比。

这个Hacker News讨论强调了VHDL相比Verilog在硬件描述方面的更优设计方法。一位评论员认为VHDL自1987年起就存在的“Delta Cycle”逻辑,预见了函数式响应式编程的概念,通过将值变化与过程响应分离,从而产生固有更可靠的代码。 他们将此与Verilog进行对比,Verilog由于其赋值规则,经常导致竞争条件,即使SystemVerilog尝试修复也无法完全解决。虽然Verilog允许更快的初始编写,但VHDL *强制* 设计师正确考虑并发性,从而减少错误并产生更健壮的设计。本质上,VHDL优先考虑正确性,并避免了使用Verilog时经常遇到的常见陷阱。
相关文章

原文

In this post, I would like to talk about VHDL’s crown jewel: how it preserves determinism in a concurrent language. Here is a figure of how it works:

What you see is a simplified example of VHDL’s delta cycle algorithm in action. Delta cycles are an HDL concept used to order events that occur in zero physical time. The red circles refer to signal value updates. The blue squares are process evaluations.

A delta cycle starts with a number of signal value updates. A signal value update may trigger a number of processes. In the second phase of the delta cycle, these processes are evaluated. In these processes, signals assignments may occur that schedule value updates in the next delta cycle. And so on.

Let us now zoom in on a single delta cycle:

The delta cycle starts with value updates of signals s, t, and u. The signals were assigned to by independent processes in a previous delta cycle. Signal s triggers two processes P and Q, that also use the value of signals t and u.

As signal updates are conceptually concurrent events, the order of the updates is undefined. The same holds for process evaluations. Therefore, another valid possibility is as follows:

It is easy to see that the result at the end of the delta cycle will be the same as before. Processes P and Q always see the same signal values. The point of the delta cycle algorithm is that signal value updates and process evaluations are kept in separate sets. The signal set is always handled completely before the process set. The order within each set is not relevant for the result. In other words, the result is deterministic even though the execution order within each set is not.

Let’s now come back to the subject of the previous post: the case of Verilog. The two situations above are possible, in addition to many others. For example:

Or even:

What you see is that in Verilog, value update events may validly appear before or after process evaluations. In other words, in terms of event ordering, all bets are off. Well, at least causality is preserved :-). Depending on execution order, the processes will see different values. Therefore, the result is non-deterministic.

I believe that delta cycle event ordering is the most important difference between VHDL and Verilog. Let’s investigate where it comes from. In VHDL, you cannot use ordinary variables to communicate between processes. VHDL has special objects for that purpose: signals. Signals accomplish two things: the value update event is delayed to a future delta cycle, and it is held in a dedicated set that is processed atomically. In this way, determinism is achieved, as demonstrated in the first two examples.

In contrast, Verilog doesn’t have anything like signals. The procedural thing that holds value is (confusingly) called a reg. Regs are used both for computation inside processes and for communication between them. What Verilog does have is two types of procedural assignment: blocking, which is much like ordinary variable assignment, and nonblocking, which delays the value update to a future delta cycle. Using blocking assignments for communication is conceptually unsafe, as values are updated immediately. But nonblocking assignments don’t solve the problem either. They merely influence the delta cycle in which an event becomes active. Once active, they just behave like other events. The fundamental difference is that Verilog does not handle value update events and process evaluation events in separate phases.

Nonblocking assignments are still an improvement. In a purely synchronous design that uses nonblocking assignments for communication, there are only two types of delta cycles: one in which a single clock event triggers all processes, and a second with value update events only. For this special case, the result is deterministic. But that’s also why I called nonblocking assignments a half-baked solution: they solve the problem for an important case, but not in general. Beyond the synchronous design paradigm, like in test benches and high-level models, you are basically on your own.

VHDL’s delta cycle algorithm is its crown jewel. It gives you built-in determinism. Let us treasure it - Verilog doesn’t have anything like it. At the same time, you will agree with me that there is nothing too complicated about the concept. It seems like a zero-cost solution for an important problem. So why then didn’t Verilog do it in a similar way? Perhaps the Verilog language designers had a good reason that we are not aware of yet. That will be the topic of a future post.

For completeness, let me add that VHDL has a few exotic nondeterministic corners also, such as shared variables, file-based IO, and asymmetric resolution functions. However, this is not an issue in practice. During my whole VHDL career, I have never felt the need to use anything else than signals for communication. In contrast, whenever I pick up Verilog, the whole blocking/nonblocking issue invariably comes back. For example, even for synchronous design where a safe solution is available, it is very easy to find highly-regarded reference texts that use blocking assignments for communication. (Verilog designers, don’t do it like that!)

This article is part of Jan’s blog about his personal views on HDL design.
Thanks to Jonathan Bromley for helping me to gain the insights that I try to explain in this post.

联系我们 contact @ memedata.com