隐式网络类型声明和`default-nettype

Implicit net-type declaration and `default-nettype

我对 SystemVerilog 的 `default_nettype 指令有疑问。

默认如下代码即可

module m1 (
   input logic i1,
   output logic o1
   );
   logic l1;
   assign l1 = i1;
   assign o1 = l1;
endmodule

但是,当我将默认网络类型更改为 none:

`default_nettype none

只有i1导致错误:

ERROR: [VRFC 10-1103] net type must be explicitly specified for i1 when default_nettype is none ...

我的问题是为什么只有 input logic i1 会导致错误并要求显式 wire,而 output logic o1logic l1 不会。

这是 SystemVerilog 令人困惑的部分。你的代码在我的模拟器上运行,输出警告而不是错误。

如果您深入研究帮助消息,您会发现标识符的“类型”(如 net 与 var,与“数据类型”相反,后者是逻辑或其他任何东西)是上下文敏感的,特别是输入端口是默认情况下是网络,而输出端口默认是变量。这意味着使用“default_nettype none”您的所有输入端口都没有得到有效的完整描述,因为编译器不知道网络的解析函数(例如,您可能需要一根魔杖)。您的输出端口是变量,不需要解析函数,因此不会引发错误。

因为除非你真的尝试,否则你不能真正将同一个端口连接到多个信号,这对我来说似乎是多余的,但如果输入网络由多个驱动,则由于网络强制规则的详细说明,可能需要它一个分配在设计的其他地方。

我的理解是“default_nettype none”主要是用来确保你没有未声明的标识符(由于单比特推断导致宽度不匹配)并且声明了一个端口,所以您可能会检查您的工具是否有为端口推断线路的选项(同样,我的模拟器输出警告并默认执行此操作,合成器也不会抱怨)。

除此之外,我看到的唯一解决方法是在 ANSI 端口声明和“default_nettype wire”之后的第一件事是“default_nettype none” endmodule 之前的最后一件事,在每个模块中。 我们不能这样做,根据 1800-2017 22.8:

The directive `default_nettype controls the net type created for implicit net declarations (see 6.10). It can be used only outside design elements.

隐式网络声明的参考是 IEEE 1800-2017 中的第 6.10 节,尽管从那里开始提到的部分似乎仅指向非 ANSI 声明……您可能需要更深入地了解才能完全理解这个问题.

Verilog 有太多隐式规则无法适应懒惰的程序员(即对设计硬件感兴趣而不是编写软件的人)

此错误在 23.2.2.3 确定端口类型、数据类型和方向的规则

部分进行了解释

For the first port in an ANSI style port list:

  • If the port kind is omitted:
    • For input and inout ports, the port shall default to a net of default net type. The default net type can be changed using the `default_nettype compiler directive

这个隐含的 'net' 端口规则与声明输出端口以及端口外的所有其他声明时使用的规则相反。这背后的原因是输入端口是模块中使用的绝大多数端口,并且将端口连接保持为电线允许端口折叠,这对于模拟更有效。