Verilog:使用原始模块与位运算符的实现

Verilog: Implementation Using Primitive Modules vs. Bit-wise Operators

我正在阅读的教科书使用内置原始模块实现 1 位加法器:

module yAdder1(z, cout, a, b, cin);
     output[0:0] z, cout;
     input[0:0] a, b, cin;
     wire[0:0] tmp, outL, outR;

     xor left_xor(tmp, a, b);
     xor right_xor(z, cin, tmp);
     and left_and(outL, a, b);
     and right_and(outR, tmp, cin);
     or my_or(cout, outR, outL);
endmodule

但为什么不使用位运算符呢?看起来更简单。

module yAdder1(z, cout, a, b, cin);
     output[0:0] z, cout;
     input[0:0] a, b, cin;

     assign z = (a ^ b) ^ cin;
     assign cout = (a & b) | ((a ^ b) & cin);
endmodule

除非按位运算符隐式使用原始模块?

内置基元是在门级模型中表达门的便捷方式。通常它们是由其他工具生成的。除此之外,没有太多理由在常规 verilog 中使用它们。

可能很少有您可以 运行 跨越的,主要是各种可用于驱动总线的三态缓冲器。但所有其他人都没有那么多使用。

它们不会在模拟中隐式使用。

只是verilog的写法不同而已。前者是结构格式,后者更倾向于behavioral/functional格式。

添加到@Serge 的观点,如果您尝试单独合成它们中的每一个,您将看到一个非常相似(可能完全相同)的网表。 以结构化方式编写代码将简化综合工具将 RTL 映射到现有基元(在特征化库中)的工作——缺点是难以理解查看结构化代码的功能。