Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference of SystemVerilog data types (reg, logic, bit)

Tags:

There are different data types in systemverilog that can be used like the following:

reg [31:0] data; logic [31:0] data; bit [31:0] data; 

How does the three of them differ?

like image 827
e19293001 Avatar asked Nov 08 '12 03:11

e19293001


People also ask

What is the difference between logic and reg data type?

reg and logic are exactly the same. These data types appear inside the always or initial blocks and store values i.e. always @(a) b <= a;, the reg b gets evaluated only when 'a' changes but otherwise it simply stores the value it has been assigned last. wire are just simply connections and need to continuously driven.

What is the difference between reg wire and logic in SystemVerilog?

There is no difference between reg and logic other than their spelling. The keyword reg remains because SystemVerilog is %100 percent backward compatible with Verilog.

What is the difference between reg and wire data type?

The wire is used for a continuous assignment whereas reg is used in a procedural assignment.

What is logic data type in Verilog?

SystemVerilog introduces a new 4-state data type called logic that can be driven in both procedural blocks and continuous assign statements. But, a signal with more than one driver needs to be declared a net-type such as wire so that SystemVerilog can resolve the final value.


1 Answers

reg and wire were the original types. Wires are constantly assigned and regs are evaluated at particular points, the advantage here is for the simulator to make optimisations.

wire w_data; assign w_data = y;  // Same function as above using reg reg r_data; always @*    r_data = y ; 

A common mistake when learning Verilog is to assume the a reg type implies a register in hardware. The earlier optimisation for the simulator can be done through the context of its usage.

This introduces logic which can be used in place of wire and reg.

logic  w_data; assign w_data = y;  // Same function as above using reg logic r_data; always @*    r_data = y ; 

The type bit and byte have also been created that can only hold 2 states 0 or 1 no x or z. byte implies bit [7:0]. Using these types offers a small speed improvement but I would recommend not using them in RTL as your verification may miss uninitialized values or critical resets.

The usage of bit and byte would be more common in testbench components, but can lead to issues in case of having to drive x's to stimulate data corruption and recovery.


Update

At the time of writing I was under the impression that logic could not be used for tristate, I am unable to find the original paper that I based this on. Until further updates, comments or edits, I revoke my assertion that logic can not be used to create tri-state lines.


The tri type has been added, for explicitly defining a tri-state line. It is based on the properties of a wire, logic is based on the properties of a reg.

tri t_data; assign t_data = (drive) ? y : 1'bz ; 

If you no longer have to support backwards compatibility Verilog then I would recommend switching to using logic and tri. Using logic aids re-factoring and and tri reflects the design intent of a tristate line.

like image 104
Morgan Avatar answered Oct 05 '22 20:10

Morgan