This is the most fundamental distinction in SystemVerilog data types. Understanding it is essential!
4-State Types (From Verilog)
Can hold four values: 0, 1, X (unknown),
Z (high impedance)
reg- Original Verilog register typelogic- SystemVerilog replacement for reg and wireinteger- 32-bit signed, 4-statetime- 64-bit unsigned for simulation time
2-State Types (New in SystemVerilog)
Can only hold: 0 and 1. Faster simulation, less memory!
bit- Single bit (unsigned)byte- 8 bits signedshortint- 16 bits signedint- 32 bits signedlongint- 64 bits signed
// 4-state: Can detect X/Z from RTL
logic [7:0] rtl_data; // Use in RTL, can be X or Z
wire [7:0] data_bus; // Tri-state bus
// 2-state: Faster, use in testbench when you don't need X/Z
bit [7:0] tb_data; // Testbench variables
int counter; // Loop counters
bit [31:0] expected_value; // Reference model values
// Important: 2-state defaults to 0, not X!
bit b; // Initialized to 0
logic l; // Initialized to X
// Converting 4-state to 2-state
logic [7:0] from_rtl = 8'b1010_xxxx;
bit [7:0] in_tb = from_rtl; // X becomes 0: 8'b1010_0000
// WARNING: Silent conversion!
When to Use Which?
| Use Case | Recommended Type | Reason |
|---|---|---|
| RTL design |
logic
|
Need to detect uninitialized X values |
| Testbench transactions |
bit
|
Faster simulation, known values |
| Loop counters |
int
|
32-bit signed, fast |
| Randomization |
bit
|
Required for rand/randc |
| Checking RTL output |
logic
|
Need to detect X from DUT |