๐ SystemVerilog Data Types โ A Complete Overview (with Default Properties)
#
SystemVerilog improves Verilog by introducing a richer, more precise type system. Below is a full breakdown of key SystemVerilog data types โ including their default bit widths, signedness, and default values.
๐ 1. 4-State vs 2-State Types
#
Type |
States |
Default Size |
Default Signedness |
Default Value |
Notes |
logic |
0, 1, X, Z |
Scalar (1-bit) or user-defined |
Unsigned |
X (unknown) |
Use instead of reg and wire |
reg |
0, 1, X, Z |
Scalar (1-bit) or user-defined |
Unsigned |
X |
Legacy, replaced by logic |
bit |
0, 1 |
Scalar (1-bit) or user-defined |
Unsigned |
0 |
2-state only, useful in simulations |
โ
Use logic
for RTL and bit
when X/Z modeling is unnecessary.
๐งฎ 2. Integer Types
#
Type |
Size |
Signed |
Default Value |
Notes |
byte |
8-bit |
Yes |
0 |
Signed by default |
shortint |
16-bit |
Yes |
0 |
|
int |
32-bit |
Yes |
0 |
Most commonly used |
longint |
64-bit |
Yes |
0 |
|
integer |
โฅ32-bit (impl. defined) |
Yes |
0 |
Legacy type from Verilog |
time |
64-bit |
No |
0 |
Used for simulation timing |
๐ง Tip: Prefer int
, longint
, bit
over legacy integer
.
๐ค 3. String Type
#
Type |
Description |
Default Value |
Notes |
string |
Dynamically sized text |
Empty string "" |
Supports methods like .len() , .putc() |
string msg = "Hello!";
$display("Length = %0d", msg.len());
๐ 4. Enumerations (enum
)
#
Feature |
Description |
Syntax |
typedef enum {A, B, C} name_t; |
Underlying type |
Can be defined (e.g., enum logic [1:0] ) |
Default value |
First listed value (unless specified) |
Signed? |
Follows underlying base type |
๐ฆ 5. Structures (struct
)
#
Feature |
Description |
Syntax |
typedef struct { ... } name_t; |
Packed? |
Use packed keyword for bit-accurate layout |
Default values |
Each field initialized to its typeโs default |
Nesting |
Structs can include other structs |
typedef struct packed {
bit [7:0] id;
logic valid;
} header_t;
๐ 6. Unions (union
)
#
Feature |
Description |
Shared Memory |
All fields use same memory space |
Packed Union |
Use packed for precise layout |
Tagged Union |
Use union tagged to ensure safe access |
๐ 7. Arrays
#
Array Type |
Description |
Packed Array |
Bit vectors (e.g., logic [7:0] ) |
Unpacked Array |
Collection of objects or elements |
Dynamic Array |
Resizable during runtime |
Associative Array |
Indexed by any scalar (e.g., string ) |
Queue |
FIFO-like data structure (e.g., int queue[$] ) |
๐ 8. Other Special Types
#
Type |
Description |
void |
No return value |
event |
Simulation synchronization primitive |
chandle |
C-language pointer |
mailbox |
Communication between processes |
semaphore |
Resource control between processes |
โ
Summary Table (Compact Reference)
#
Type Group |
Examples |
Default Size |
Default Signedness |
Notes |
2-state |
bit , int , byte , longint |
Fixed-width |
Signed (mostly) |
No X/Z states |
4-state |
logic , reg , integer |
Variable |
Unsigned (logic), Signed (integer) |
Supports X and Z |
Textual |
string |
Dynamic |
โ |
Supports common string methods |
Composite |
struct , union , array |
Custom |
Follows fields |
Grouped or indexed values |
Enumeration |
enum |
Customizable |
Base typeโs signed |
Symbolic values with readability |
Special |
time , event , chandle , mailbox |
Varies |
Varies |
Simulation or interprocess use |