System Verilog Part2 1738590562
System Verilog Part2 1738590562
SCALAR
It represents a single piece of data, such as a single bit (bit), a single 4-state value
(logic), or a single integer (int, integer).
integer: A 32-bit signed integer (similar to int but with some differences in
usage).
VECTOR
1
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
LOGIC:
Why logic in system verilog.
reg is used in Procedural Logic for defining variables that need to hold their value
within procedural blocks.
Wire is used in Sequential Logic for connecting signals, especially between sequential
elements like flip-flops or memory elements.
Logic can be used as reg and wire
X UNKNOWN
Z HIGH IMPEDENCE
Usage Context Used in always, initial, or final blocks Used in always_ff blocks with clocking
Procedurally driven (sequential logic, not Stateful, stores values between clock
Behavior stored between clock cycles) cycles
SIMPLE CODE:
Logic data type used for sequential assignment
Logic data type used for procedural assignment
Logic used for module & gates
EDA EXAMPLE:
https://edaplayground.com/x/vyxH
2
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
DEFAULT/RESET/INITIAL VALUES:
3
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EDA EXAMPLE:
https://edaplayground.com/x/iG47
Result
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Jan 29 03:36 2025
Default value of 'i' (int): 0
Default value of 'b' (reg): x
Default value of 'w' (wire): z
Default value of 'l' (logic): x
Default value of 'bt' (bit): 0
Default value of 'by' (byte): 00000000
Default value of 'si' (shortint): 0
Default value of 'li' (longint): 0
Default value of 'r' (real): 0.000000
Default value of 'str' (string): ""
Default value of 't' (time): 0
VCS Simulation Report
4
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
2-State means the variable can only represent two values, typically 0 and 1.
o Examples: bit, int, shortint, longint, time, real (and floating-point types in
general).
o These types cannot hold unknown (x) or high-impedance (z) states.
o Signed and unsigned versions of these types exist (like int being signed, and
bit being unsigned by default).
4-State means the variable can represent four values: 0, 1, x (unknown), and z (high
impedance).
o Examples: reg, wire, logic.
o These types can represent a wider range of logic states, which is essential for
modeling digital circuits where certain conditions may be undefined or
disconnected.
o Signed and unsigned versions of these types also exist (like reg signed [3:0] or
wire [7:0]).
5
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
https://edaplayground.com/x/ngS5
Result:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Jan 29 04:22 2025
Data value: xx01
The register 'data' contains an unknown value (x or z).
The wire 'signal' contains an unknown value (x or z).
VCS Simulation Report
Explanation:
1. $isunknown(): This is the SystemVerilog system function used to check if a signal (of
any type like reg or wire) contains an unknown value (x or z). It returns 1 (true) if the
signal contains an unknown value, and 0 (false) if it does not.
2. Test Setup:
o We assign an unknown value (4'bx01) to the data register. The x in 4'bx01
represents an unknown value.
o We assign a high-impedance value (4'bz) to the signal wire, which is also an
unknown value.
3. Detection:
o We use $isunknown(data) to check if the data register contains any unknown
value (x or z).
6
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Key Points:
1. Unsigned:
o Used for variables that should only hold non-negative values.
o Example: reg [7:0] unsigned_data;
2. Signed:
o Used for variables that can hold both positive and negative values.
o Example: reg signed [7:0] signed_data;
3. Two's Complement Representation:
o SystemVerilog uses two's complement to represent negative numbers in
signed types.
o The MSB (Most Significant Bit) determines the sign: 0 for positive and 1 for
negative.
4. No Implicit Sign:
o If you declare a variable with no explicit signed or unsigned, SystemVerilog
assumes unsigned by default.
7
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Result:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Jan 29 04:34 2025
Unsigned data (8'b11111111): 255
Unsigned negative example (-5): 251
Signed data (8'b11111111): -1
Signed negative example (-5): -5
VCS Simulation Report
8
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
FINAL CONCLUSION:
In Verilog, to assign a value to all the bits of a vector, the user had to specify the value
explicitly for each bit. SystemVerilog simplifies this by introducing unsized single-bit
literals using a preceding apostrophe (').
9
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT
Equivalents in Verilog-2001:
'x is equivalent to 'bx.
'z is equivalent to 'bz.
'1 is equivalent to assigning all 1s.
'0 is equivalent to assigning all 0s.
2. Time Literals
Time literals represent time values and are used in timing constructs. They are written in
integer or fixed-point format, followed by a time unit (fs, ps, ns, us, ms, s, step).
EXAMPLE:
RESULT :
10
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Behavior:
Time literals are interpreted as real-time values scaled to the current time unit and
rounded to the current time precision.
3. Array Literals
Array literals are used to initialize arrays. They are syntactically similar to C initializers but
include the replicate operator ({{}}) for repeating values.
Key Points:
The nesting of braces must match the number of dimensions in the array.
The replicate operator ({{}}) can be used to repeat values within a dimension.
Replicate operators can be nested, but the inner pair of braces in a replication is
removed.
Summary of Literals
11
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
12
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
ARRAY
Fixed size array: size is fixed
Single dimension array
Index 0 1 2 3
Length of array is 4
INDEX 0 1 2 3
ELEMENTS 5 2 5 2
RESULT:
-------displaying array1-------
array1[0] = 5
array1[1] = 4
array1[2] = 3
array1[3] = 2
VCS Simulation Report
13
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
MULTIDIMENSIONAL ARRAY
2 DIMENSIONAL ARRAYS:
int array[3][2];
RESULT:
-------displaying array2-------
array[0][0] = 1
array[0][1] = 5
array[1][0] = 2
array[1][1] = 6
array[2][0] = 3
array[2][1] = 7
VCS Simulation Report
14
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 2:
Result
------displaying array2-------
array[0][0] = 1
array[0][1] = 5
array[1][0] = 2
array[1][1] = 6
array[2][0] = 3
array[2][1] = 7
VCS Simulation Report
0 1
0 1 5
1 2 6
2 3 7
15
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
3 DIMENSIONAL ARRAY:
int array[2][3][4];
2*3*4=24 element
RESULT:
16
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
array[1][0][0] = 200
array[1][0][1] = 201
array[1][0][2] = 202
array[1][0][3] = 203
array[1][1][0] = 210
array[1][1][1] = 211
array[1][1][2] = 212
array[1][1][3] = 213
array[1][2][0] = 220
array[1][2][1] = 221
array[1][2][2] = 222
array[1][2][3] = 223
VCS Simulation Report
ANOTHER WAY
0 1 2 3
0 0 100 101 102 103
1 110 111 112 113
2 120 121 122 123
17
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
PACKED ARRAY:
Packed arrays can be defined from single bit data types ( bit, logic, reg ), enumerated types,
and other packed arrays or packed structures
A packed array refers to the dimension mentioned before the variable or object name. This is
also known as the vector width.
2 1 0
ARRAY0
3 2 1 0 3 2 1 0 3 2 1 0
ARRAY2 ARRAY1 ARRAY0
18
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 1:
RESULT:
19
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
UNPACKED ARRAY:
7 6 5 4 3 2 1 0
0
1
2
20
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
3x3 matrix
0 1 2
0 8’h1 8’h2 8’h3
1 8’h4 8’h5 8’h6
2 8’h7 8’h8 8’h9
Result:
21
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 2:
0 1 2 3
0
1
2
EXAMPLE 3
22
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Verilog does not allow changing the dimensions of the array once it is declared
Fixed size array as its size is set at compile time
If you store the transaction in an fixed size array it would have to be large enough to
hold the maximum number of transaction wasting memory
Dynamic array that can be allocated and resized during simulation time so your
simulation consume minimum amount of memory
A dynamic array is one dimension of an unpacked array whose size can be set or
changed at run-time.
Dynamic array is declared using an empty word subscript [ ].
The size of an array can be specified during run-time by using new [ ].
By default, the size of a dynamic array is 0 unless a new [ ] is used.
Dynamic arrays require fixed-size elements, so you cannot use bit or logic directly.
Instead, use a fixed-size vector type (e.g., typedef logic [7:0] byte_t).
Limitations:
o You can only access elements using integer indices.
o Searching for a specific value (e.g., finding an element by its
content) can be slow (O(n) in the worst case).
When you declare a dynamic array, SystemVerilog needs to know the size of each
element in the array so it can allocate memory efficiently.
Scalar types like int and integer have a fixed size (e.g., 32 bits), so they can be used
directly in dynamic arrays.
Vector types like bit or logic can represent a single bit or a multi-bit vector, which
introduces ambiguity. For example:
o Is bit a single bit or a vector of bits?
o Is logic a single 4-state value or a vector of 4-state values?
Because of this ambiguity, SystemVerilog does not allow dynamic arrays
of bit or logic directly. Instead, you must define a fixed-size vector (e.g., bit
[7:0] or logic [15:0]) and then use that type in the dynamic array.
23
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
1. New
2. Size
3. Delete
1. NEW [] (ALLOCATION)
Allocates memory for the dynamic array.
int array[];
2. SIZE()
Returns the current size of the dynamic array.
int size;
3. DELETE()
24
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 1:
25
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 2:
26
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT :
Before Memory Allocation
Size of Dynamic array 0
After Memory Allocation
Size of Dynamic array 5
dyn[0] = 100
dyn[1] = 200
dyn[2] = 300
dyn[3] = 400
dyn[4] = 500
Increasing the size by overriding previous values
Size of Dynamic array 10
dyn[0] = 88
dyn[1] = 11
dyn[2] = 22
dyn[3] = 33
dyn[4] = 44
dyn[5] = 55
dyn[6] = 66
dyn[7] = 77
dyn[8] = 99
dyn[9] = 12
Increasing the size by retaining previous values
Size of Dynamic array 10
dyn[0] = 88
dyn[1] = 11
dyn[2] = 22
dyn[3] = 33
dyn[4] = 44
dyn[5] = 55
dyn[6] = 66
dyn[7] = 77
dyn[8] = 99
dyn[9] = 12
Copy dyn to dyn1
dyn1[0] = 88
dyn1[1] = 11
dyn1[2] = 22
dyn1[3] = 33
dyn1[4] = 44
dyn1[5] = 55
dyn1[6] = 66
dyn1[7] = 77
dyn1[8] = 99
dyn1[9] = 12
After Array Delete
Size of dyn 0
Size of dyn1 10
VCS Simulation Report
Time: 0 ns
CPU Time: 0.440 seconds; Data structure size: 0.2Mb
Sat Feb 1 03:57:01 2025
27
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Associative array
Associative array stores entries in a sparse matrix. This means that while you can
address a very large address space ,system verilog only allocates memory for an
element when you write on it.
When the size of the collection is unknown or the data space is sparse, an associative
array is a better option.
An associative array (also called a map, dictionary, or hash table) stores key-value
pairs, where keys can be of any data type (e.g., strings, numbers, objects). Values are
accessed using their corresponding keys.
Use Case:
o When you need to associate data with specific keys (e.g., storing user
information by username).
o When you need fast lookups by key (O(1) on average for hash-based
implementations).
o When the keys are not integers or are not sequential.
o When you need to store and retrieve data in a way that doesn't rely on order.
Advantages:
o Flexibility in key types (e.g., strings, objects, etc.).
o Efficient lookups, insertions, and deletions by key.
o Ideal for scenarios where you need to map one piece of data to another (e.g.,
phone books, configuration settings, etc.).
1. Non-Integer Keys:
o If you need to use keys that are not integers (e.g., strings, objects), associative
arrays are necessary.
o Example: Storing user data by username (userData["john_doe"] = {age: 30,
email: "[email protected]"}).
2. Fast Lookups by Key:
o If you need to frequently look up values based on a specific key, associative
arrays are more efficient than dynamic arrays.
o Example: Checking if a username exists in a database.
3. Sparse Data:
o If your data is sparse (i.e., you don't need to store values for every possible
index), associative arrays save memory by only storing the key-value pairs
that exist.
4. Mapping Relationships:
o If you need to represent relationships between two pieces of data (e.g., word
frequencies, graph edges), associative arrays are ideal.
o Example: Counting word occurrences in a text (wordCounts["hello"] = 5).
5. Configuration or Settings:
o Associative arrays are great for storing configuration settings where keys are
meaningful names (e.g., config["theme"] = "dark").
28
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE SCENARIOS
1. Dynamic Array:
o Storing a list of numbers: [10, 20, 30, 40].
o Iterating over elements in order.
2. Associative Array:
o Storing user information: {"john_doe": {age: 30, email:
"[email protected]"}, "jane_doe": {age: 25, email: "[email protected]"}}.
o Looking up a user's email by their username.
In a dense array, most or all of the indices are occupied by meaningful values.
o Example: [1, 2, 3, 4, 5] (every index is filled).
In a sparse array, only a few indices contain meaningful values, and the rest are empty
or default (e.g., 0, null, or undefined).
o Example: [1, null, null, 4, null] (only indices 0 and 3 have meaningful values).
29
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
METHODS:
Method Description
30
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE:
RESULT:
See http://www.eda.org/svdb/view.php?id=3770 for more details.
31
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 2:
32
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
--------------------------------------------------------
Number of entries in mem is 3
--- Associative array mem entries and Values are ---
mem[BLUE] =3
mem[ORANGE] =4
mem[RED] = 2
--------------------------------------------------------
First entry is mem[BLUE] = 3
--------------------------------------------------------
Last entry is mem[RED] = 2
--------------------------------------------------------
mem.exists("RED")
--------------------------------------------------------
Number of entries in mem after deletion is 2
--- Associative array mem entries and Values are ---
mem[BLUE] =3
mem[RED] = 2
--------------------------------------------------------
First entry is at index BLUE
--------------------------------------------------------
Next entry is at index RED after the first index
VCS Simulation Report
Time: 0 ns
CPU Time: 0.420 seconds; Data structure size: 0.2Mb
33
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
34
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
QUEUE:
Queue are like fifo
A Queue is analogous to one dimensional unpacked array that grows and shrinks
automatically
Queues can be used to model a last in, first out buffer or first in, first out buffer.
Queues support insertion and deletion of elements from random locations using an
Index.
Queues can be passed to tasks / functions as ref or non-ref arguments. Type Checking
is also done.
Queues are declared using the same syntax as unpacked arrays, but specifying $ as the
array size. In queue 0 represents the first, and $ representing the last entries.
Which combines the best of an linked list and array A queue can be bounded or
unbounded
bounded queue – queue with the number of entries limited or queue size specifiedun
bounded queue – queue with unlimited entries or queue size not specified
data_type queue_name[$];
where:
data_type – data type of the queue elements.
queue_name – name of the queue.
1. INTEGER TYPES:
o bit: Single-bit unsigned value.
o logic: Single-bit or multi-bit value (4-state: 0, 1, X, Z).
o reg: Legacy type, similar to logic.
o byte: 8-bit signed integer.
o shortint: 16-bit signed integer.
o int: 32-bit signed integer.
35
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Queue Methods
Method Description
36
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
https://edaplayground.com/x/VZz7
37
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
38
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
39
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
40
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT :
----------------------------------------------------------------
You are using a version of the UVM library that has been compiled
with `UVM_NO_DEPRECATED undefined.
See http://www.eda.org/svdb/view.php?id=3313 for more details.
You are using a version of the UVM library that has been compiled
with `UVM_OBJECT_DO_NOT_NEED_CONSTRUCTOR undefined.
See http://www.eda.org/svdb/view.php?id=3770 for more details.
Initial Queues:
bit_queue: '{'h1, 'h0}
logic_queue: '{'ha, 'hX}
reg_queue: '{'haa, 'hbb}
byte_queue: '{127, -128}
shortint_queue: '{32767, -32768}
int_queue: '{2147483647, -2147483648}
longint_queue: '{9223372036854775807, -9223372036854775808}
integer_queue: '{2147483647, -2147483648}
41
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
shortint_queue: '{0, 32767, -32768}
int_queue: '{0, 2147483647, -2147483648}
longint_queue: '{0, 9223372036854775807, -9223372036854775808}
integer_queue: '{0, 2147483647, -2147483648}
Queue Sizes:
bit_queue size: 1
logic_queue size: 1
reg_queue size: 1
byte_queue size: 1
shortint_queue size: 1
int_queue size: 1
42
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
longint_queue size: 1
integer_queue size: 1
43
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
LINKED L
in-progress
The List package implements a classic list data-structure, and is analogous to the STL
(Standard Template Library) List container that is popular with C++ programmers. The
container is defined as a parameterized class, meaning that it can be customized to
hold data of any type. The List package supports lists of any arbitrary predefined
type, such as integer, string, or class object. First declare the Linked list type and
then take instances of it. SystemVerilog has many methods to operate on these
instances.
A double linked list is a chain of data structures called nodes. Each node has 3
members, one points to the next item or points to a null value if it is last node, one
points to the previous item or points to a null value if it is first node and other has the
data.
The disadvantage of the linked list is that data can only be accessed sequentially and
not in random order. To read the 1000th element of a linked list, you must read the
999 elements that precede it.
List Definitions:
list :- A list is a doubly linked list, where every element has a predecessor and
successor. It is a sequence that supports both forward and backward traversal, as well
as amortized constant time insertion and removal of elements at the beginning, end,
or middle.
container :- A container is a collection of objects of the same type .Containers are
objects that contain and manage other objects and provide iterators that allow the
contained objects (elements) to be addressed. A container has methods for accessing
its elements. Every container has an associated iterator type that can be used to
iterate through the container´s elements.
iterator :- Iterators provide the interface to containers. They also provide a means to
traverse the container elements. Iterators are pointers to nodes within a list. If an
iterator points to an object in a range of objects and the iterator is incremented, the
iterator then points to the next object in the range.
44
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
The List_Iterator class provides methods to iterate over the elements of lists.
The next() method changes the iterator so that it refers to the next element in the
list.
The prev() method changes the iterator so that it refers to the previous element in
the list.
The eq() method compares two iterators and returns 1 if both iterators refer to the
same list element.
The neq() method is the negation of eq().
The data() method returns the data stored in the element at the given iterator
location.
List Methods
The List class provides methods to query the size of the list; obtain iterators to the
head or tail of the list;
retrieve the data stored in the list; and methods to add, remove, and reorder the
elements of the list.
The size() method returns the number of elements stored in the list.
The empty() method returns 1 if the number elements stored in the list is zero and 0
otherwise.
The push_front() method inserts the specified value at the front of the list.
The push_back() method inserts the specified value at the end of the list.
The front() method returns the data stored in the first element of the list.
The back() method returns the data stored in the last element of the list.
The pop_front() method removes the first element of the list.
The pop_back() method removes the last element of the list.
The start() method returns an iterator to the position of the first element in the list.
The finish() method returns an iterator to a position just past the last element in the
list.
The insert() method inserts the given data into the list at the position specified by the
iterator.
The insert_range() method inserts the elements contained in the list range specified
by the iterators first and last at the specified list position.
The erase() method removes from the list the element at the specified position.
The erase_range() method removes from a list the range of elements specified by the
first and last iterators.
The set() method assigns to the list object the elements that lie in the range specified
by the first and last iterators.
The swap() method exchanges the contents of two equal-size lists.
The clear() method removes all the elements from a list, but not the list itself.
The purge() method removes all the list elements (as in clear) and the list itself.
45
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
46
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
47
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Memory Layout Elements are stored contiguously in Elements are stored non-contiguously
memory. in memory.
Memory Efficiency Efficient: No memory wasted since Less efficient: Memory may be wasted
all bits are contiguous. due to non-contiguous element
storage.
Fixed vs Dynamic Fixed size, defined at compile-time. Dynamic size, can be resized at
Size runtime.
Memory Waste for None: Memory is allocated for the Possible waste: If the array is resized,
Dynamic Size exact size at compile-time. memory allocation may lead to
fragmentation or unused memory.
Variable Element No: All elements must have the same Yes: Elements can be of different types
Width size. and sizes.
Memory Waste for None: All elements have the same Possible waste: Different element sizes
Varying Widths width, so no waste. could lead to unused or wasted
memory (e.g., if elements require
more space than necessary).
Access Time for Faster: Elements are contiguous, so Slower: Access times may be slower
Large Arrays memory access is fast. for non-contiguous elements.
Memory Allocation Fixed Memory: Memory is allocated Heap Memory: Dynamic allocation
for Large Arrays for the exact size at compile-time. may lead to fragmentation or unused
memory if not properly managed.
Used for Hardware Yes: Suitable for representing No: Not ideal for hardware modeling
Modeling hardware (e.g., registers, buses) with due to non-contiguous storage and
no wasted space. potential memory waste.
Use of Memory for Limited: Cannot store elements of Flexible: Can store complex types such
Complex Types varying types (only scalars with fixed as objects, classes, or structs with
widths). potentially wasteful memory allocation
if not managed properly.
48
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Usage Used when the size of the Used for sparse arrays or Used for FIFO
array is not known at compile when non-integer indexing is operations or when
time. needed. elements need to
be added/removed
frequently.
Limitations - Size must be explicitly - Slower access time - No random access
resized using new[]. compared to dynamic arrays. (only FIFO
operations).
- Wastes memory if oversized. - Higher memory overhead. - Limited to integer
indexing.
Memory Wastes memory if allocated Efficient for sparse arrays but Efficient for FIFO
Efficiency size is larger than needed. has higher overhead for key- operations but
value storage. wastes memory if
elements are not
removed.
Compile/Ru Size is determined at runtime. Size is determined at runtime. Size is determined
ntime at runtime.
Operations - new[] to resize. - exists() to check if a key - push_back() to
exists. add.
- size() to get the size. - delete to remove a key- - pop_front() to
value. remove.
- delete to clear. - size() to get size.
Example int dynamic_array[]; int associative_array[string];
dynamic_array = new[10]; associative_array["key"] = 10;
49
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Fixed vs Size can change dynamically at Size dynamically managed by Size dynamically
Dynamic runtime adding/removing keys changes as
Size elements are added
or removed
Access Indexed access (by integer Key-based access (using FIFO access (First In
Method index) string, int, etc.) First Out)
Memory Memory usage is proportional Memory usage is sparse, only Memory usage
Efficiency to the current size allocated for stored keys proportional to the
number of elements
in the queue
Memory Possible memory waste during Sparse, but may have Memory wasted if
Waste resizing overhead for key lookup and elements are added
hash tables without being
removed; potential
fragmentation
Performanc Low overhead for accessing Higher overhead for key- No random access,
e Overhead elements by index based access only FIFO access,
but quick
insertion/removal
Limitations Cannot have non-integer Key-based lookup overhead, No random access,
indices, resizing may incur cannot use negative indices memory overhead
overhead for dynamic resizing
Best For Arrays with a known type and Sparse data structures with FIFO or dynamic
size (resizable) key-based access ordered storage
(e.g., queues)
Key new(size), delete, size() num(), delete(index), size(), insert(index,
Methods exists(index), first(var), item), delete(index),
last(var), next(var), prev(var) push_front(item),
push_back(item),
pop_front(),
pop_back()
Method - new(size): Allocates the array - num(): Returns the number - size(): Returns the
Description with the specified size. of entries in the associative number of elements
s array. in the queue.
- delete: Deallocates the - delete(index): Removes the - insert(index, item):
dynamic array. entry at the specified key. Inserts the given
item at the specified
index.
- size(): Returns the number of - exists(index): Returns 1 if an - delete(index):
elements in the dynamic element exists at the specified Removes the item
array. key, otherwise returns 0. at the specified
index.
- first(var): Assigns the value - push_front(item):
of the first index to the Inserts the given
variable var. element at the front
of the queue.
- last(var): Assigns the value of - push_back(item):
the last index to the variable Inserts the given
var. element at the end
of the queue.
50
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
ARRAY METHODS
$low Returns the minimum of $left and $right of the array's dimension. 1
51
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 08:19 2025
Left bound of arr[1:4]: 1
Right bound of arr[1:4]: 4
Low bound of arr[1:4]: 1
High bound of arr[1:4]: 4
Increment of arr[1:4]: -1
Size of arr[1:4]: 4
Dimensions of arr: 3
52
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
find_last() Returns the last element satisfying the given find_last() found: 20
expression.
find_last_index() Returns the index of the last element satisfying find_last_index()
the given expression. found at index: 3
min() Returns the element with the minimum value min() found: 10
or whose expression evaluates to a minimum.
max() Returns the element with the maximum value max() found: 40
or whose expression evaluates to a maximum.
unique() Returns all elements with unique values or unique() found unique
whose expression is unique. element: 10 at index 0
unique_index() Returns the indexes of all elements with unique unique_index() found
values or whose expression is unique. at index: 0
53
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
54
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 08:55 2025
find: 13 43 36 39 237
-------------------------------------------------------->
find_index: 2
-------------------------------------------------------->
find_first: Bob
-------------------------------------------------------->
find_last: Henry
-------------------------------------------------------->
find_last_index:
-------------------------------------------------------->
min: 3
-------------------------------------------------------->
max:
-------------------------------------------------------->
unique: Bob Abc Henry John
-------------------------------------------------------->
unique with tolower: Bob Abc Henry John
-------------------------------------------------------->
VCS Simulation Report
55
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
56
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 13:06 2025
Original numbers: '{10, 40, 30, 20}
Original fruits: '{"apple", "kiwi", "banana"}
57
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
58
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 12:54 2025
sum() result: 15
sum(evens) result: 6
product() result: 120
product(>3) result: 20
and() result: 0
and(LSB) result: 0
or() result: 7
or(>3) result: 5
xor() result: 1
xor(LSB flip) result: 0
VCS Simulation Report
59
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT “
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 13:21 2025
Items equal to their index in arr:
Index: 0, Value: 0
Index: 1, Value: 1
Index: 2, Value: 2
Index: 3, Value: 3
Index: 4, Value: 4
Index: 5, Value: 5
Index: 6, Value: 6
Index: 7, Value: 7
Index: 8, Value: 8
Index: 9, Value: 9
-------------------------------------------------------->
Items in mem greater than corresponding items in mem2:
Index: (0, 1), Value in mem: 2, Value in mem2: 1
Index: (0, 2), Value in mem: 3, Value in mem2: 1
Index: (0, 3), Value in mem: 4, Value in mem2: 1
60
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Index: (0, 4), Value in mem: 5, Value in mem2: 1
Index: (1, 0), Value in mem: 6, Value in mem2: 2
Index: (1, 1), Value in mem: 7, Value in mem2: 2
Index: (1, 2), Value in mem: 8, Value in mem2: 2
Index: (1, 3), Value in mem: 9, Value in mem2: 2
Index: (1, 4), Value in mem: 10, Value in mem2: 2
Index: (2, 0), Value in mem: 11, Value in mem2: 3
Index: (2, 1), Value in mem: 12, Value in mem2: 3
Index: (2, 2), Value in mem: 13, Value in mem2: 3
Index: (2, 3), Value in mem: 14, Value in mem2: 3
Index: (2, 4), Value in mem: 15, Value in mem2: 3
Index: (3, 0), Value in mem: 16, Value in mem2: 4
Index: (3, 1), Value in mem: 17, Value in mem2: 4
Index: (3, 2), Value in mem: 18, Value in mem2: 4
Index: (3, 3), Value in mem: 19, Value in mem2: 4
Index: (3, 4), Value in mem: 20, Value in mem2: 4
Index: (4, 0), Value in mem: 21, Value in mem2: 5
Index: (4, 1), Value in mem: 22, Value in mem2: 5
Index: (4, 2), Value in mem: 23, Value in mem2: 5
Index: (4, 3), Value in mem: 24, Value in mem2: 5
Index: (4, 4), Value in mem: 25, Value in mem2: 5
-------------------------------------------------------->
VCS Simulation Report
Time: 0 ns
CPU Time: 0.380 seconds; Data structure size: 0.0Mb
61
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
STRING
62
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
1. str.len():
o Returns the number of characters in the string.
o Example: "VIKRAM RENESAS" has a length of 14.
2. str.putc(i, c):
o Replaces the ith character in the string with the character c.
o Example: Replacing the 7th character (' ') with 'X' results
in "VIKRAMXRENESAS".
3. str.getc(i):
o Returns the ASCII code of the ith character in the string.
o Example: The 3rd character ('K') has an ASCII code of 75.
4. str.toupper():
o Converts all characters in the string to uppercase.
o Example: "VIKRAMXRENESAS" remains the same since it is already in
uppercase.
5. str.tolower():
o Converts all characters in the string to lowercase.
o Example: "vikramxrenesas".
6. str.compare(s):
o Compares two strings case-sensitively.
o Returns 0 if equal, a negative value if str < s, and a positive value if str > s.
7. str.icompare(s):
o Compares two strings case-insensitively.
o Returns 0 if equal, regardless of case.
8. str.substr(i, j):
o Extracts a substring from index i to j.
o Example: str.substr(0, 5) returns "VIKRAM".
9. str.atoi():
o Converts a string representing a decimal number to an integer.
o Example: "12345" is converted to 12345.
10. str.atoreal():
o Converts a string representing a floating-point number to a real number.
o Example: "123.45" is converted to 123.45.
11. str.itoa(i):
o Converts an integer to its ASCII decimal representation.
o Example: 6789 is converted to "6789".
12. str.hextoa(i):
o Converts an integer to its ASCII hexadecimal representation.
o Example: 255 is converted to "ff".
13. str.bintoa(i):
o Converts an integer to its ASCII binary representation.
o Example: 10 is converted to "1010".
63
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
64
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
65
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
66
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
System verilog allows the user to define data types. There are different ways to define u ser
defined data types. They are
1. Class.
2. Enumerations.
3. Struct.
4. Union.
5. Typedef.
ENUMERATIONS (ENUM)
Enum (short for enumeration) is used to define a type with a set of named values. It allows
you to define a variable that can take only one of the predefined values, improving code
readability and reducing errors.
Declaration:
enum <type> { <value1>, <value2>, ..., <valueN> };
Where:
<type> is the underlying data type of the enumeration (typically int, logic, etc.)
<value1>, <value2>, ..., <valueN> are the possible values the enumeration can take.
Strong Typing: When you define an enumerated type, variables of that type can only
take values from the enumerated set, which helps prevent invalid values.
Default Behavior: By default, enumerated data types are assigned integer values
starting from 0.
If you don't explicitly assign a value to an enumerator, the next value will be
automatically incremented from the previous value.
Enum as String: You can also print enum values as strings in SystemVerilog.
67
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Below are the key rules and guidelines for using enums in SystemVerilog:
1. Defining Enums
You can define an enum with specific named constants, optionally assigning integer values to
them. If no values are explicitly given, SystemVerilog will automatically assign sequential
integers starting from 0.
Syntax:
Example:
Here, the color enum type has three named constants: RED, GREEN, and BLUE.
2. Implicit Increment
If you do not assign specific values to enum elements, SystemVerilog will automatically
assign incremental integer values starting from 0.
Example:
a=0
b=1
c=2
3. Explicit Values
You can explicitly assign integer values to some or all elements of the enum. If one element
is explicitly assigned a value, the following elements will continue from the last assigned
value unless otherwise specified.
Example:
a = 10
b = 20
c = 21 (implicitly assigned the next value)
4. Scoped Enums
68
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Enum names should be unique within a given scope. If you have multiple enums, you cannot
reuse the same name (e.g., a, b, etc.) unless they are scoped differently (e.g., inside different
modules or classes).
Example:
Enum values can be used in assignments and comparisons just like integer constants.
EXAMPLE:
6. SIZE OF ENUM
By default, SystemVerilog will allocate just enough bits to represent all the enum values.
However, you can specify a size for the underlying integer type if needed.
Example:
enum [3:0] {a=0, b=1, c=2, d=3} alphabet; // 4-bit integer representation
7. FORWARD REFERENCES
Enums in SystemVerilog are processed in the order they appear. You cannot reference an
enum member before it is defined.
Example:
a=0
b=5
c=6
Enum variables are of the type specified by the enum, and they can be assigned values from
the list of named constants.
69
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Example:
You can also define an enum as a type using the typedef keyword.
Example:
Enums can be compared using relational operators like ==, !=, <, >, etc.
Example:
You can assign an integer directly to an enum variable, but the value must be within the
defined enum range.
Example:
You can mix explicit and implicit values in the same enum definition.
Example:
If you define enums with conflicting values, you'll get an error. For example, you cannot
assign two members of the same enum the same value unless you're intentionally using the
same value.
70
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Example:
enum {a=5, b=5, c} alphabet; // Error: two values have the same value
Methods
day = 7;
name() error Empty string for invalid values day.name() ""
71
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
72
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 14:12 2025
First day: MON
------------------------------->
Last day: SUN
------------------------------->
Next day after TUE: WED
------------------------------->
Next 2 days after WED: FRI
------------------------------->
Previous day before FRI: THU
------------------------------->
Previous 3 days before SAT: WED
------------------------------->
Name of day: SUN
------------------------------->
Invalid enum name: ''
------------------------------->
VCS Simulation Report
Time: 0 ns
CPU Time: 0.400 seconds; Data structure size: 0.0Mb
EXAMPLE 2:
73
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 3
74
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
75
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT :
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 14:50 2025
Initial state: XX
Next state: S1
Next state: S2
Next state: XX
Next state: IDLE
VCS Simulation Report
Time: 0 ns
CPU Time: 0.440 seconds; Data structure size: 0.0Mb
76
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
STRUCT:
The disadvantage of arrays is that all the elements stored in then are to be of the Same
data type.
If we need to use a collection of different data types, it is not possible using an array.
When we require using a collection of different data items of different data types we
can use a structure.
Structure is a method of packing data of different types. A structure is a convenient
MEMORY ALLOCATION
Memory Breakdown:
1. int a:
o Size: 4 bytes.
o Offset: 0.
2. byte b:
o Size: 1 byte.
o Offset: 4 (immediately after int a).
3. bit [7:0] c:
o Size: 1 byte.
o Offset: 5 (immediately after byte b).
4. Padding:
o To align the struct to a 4-byte boundary, 2 bytes of padding are added at the
end.
o Offset: 6.
The int type (4 bytes) requires alignment to a 4-byte boundary for efficient memory
access.
After the int and byte fields, the struct size is 5 bytes, which is not a multiple of 4.
To ensure proper alignment, 2 bytes of padding are added, making the total size 8
bytes.
77
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 15:31 2025
Struct Field Values:
a = deadbeef
b = a5
c = 10101010
Memory Layout:
Field 'a' (int): Size = 4 bytes, Offset = 0
Field 'b' (byte): Size = 1 bytes, Offset = 4
Field 'c' (bit): Size = 1 bytes, Offset = 5
Total Size: 6 bytes (with padding)
VCS Simulation Report
Time: 0 ns
CPU Time: 0.400 seconds; Data structure size: 0.0Mb
78
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
UNIONS
In SystemVerilog, a union is a data structure that allows multiple variables to share the same
memory location. A union can hold one of its members at a time, and all members share the
same memory space. This is useful when you want to store different types of data but do not
need them all to exist simultaneously. The size of the union will be determined by the largest
member.
RESULT “
Chronologic VCS simulator copyright 1991-2023
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 15:51 2025
Integer value: 42
Byte value: ff
Byte array: 01 02 03 04
Integer value after byte array assignment: 131073
VCS Simulation Report
79
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Memory Usage Shared memory for all members Separate memory for each member
Use Case Interpret memory in multiple ways Group related data together
80
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
CAST:
In SystemVerilog, casting refers to converting one data type into another, which can be
important when working with different sizes or types of variables. There are two main kinds
of casting: implicit and explicit.
Convert data type
1. IMPLICIT CASTING
This happens automatically when the data type is compatible, and SystemVerilog will handle
it for you. For example, when you assign a bit (1 bit) to a logic (multiple bits), the conversion
happens implicitly.
bit a;
logic [3:0] b;
b = a; // Implicit casting
2. EXPLICIT CASTING
Explicit casting is when you need to manually convert one type to another, often using the
cast operator or casting functions like $cast or $signed/$unsigned.
int unsigned a = 8;
shortint b;
This function is used when you want to convert one type to another, and it returns a boolean
indicating success or failure:
You can cast a variable to signed or unsigned types using the $signed or $unsigned system
functions:
81
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
This function is used when you want to convert one type to another, and it returns a boolean
indicating success or failure:
int a = 10;
real b;
// Successfully casted
// Cast failed
End
82
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
2. TYPES OF CASTING
Static
Dynamic
If the layout of the bits between source and destination variables are same such as int
& enum cast b/w two values
if bit layout are different such as array of bytes & words use the streming operators to
rearrange them
STATIC CASTING:
o Performed at compile time.
o Static cast operation converts between two types with n o checking of value
o Uses the casting operator (').
o Syntax: casting_type'(expression).
o Example: int'(2.5) converts the floating-point value 2.5 to an integer.
EXAMPLE:
RESULT
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 2 02:53 2025
-------------------------------------------->>>
Static Cast: real 5.700000 -> int 6
-------------------------------------------->>>
Example 2:
83
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
-------------------------------------------->>>
Explicit Casting: x = 1000, y = 1000
-------------------------------------------->>>
Casting using $signed: s_data = -43
-------------------------------------------->>>
$cast result: r = 123.000000 (success)
-------------------------------------------->>>
VCS Simulation Report
Time: 0 ns
CPU Time: 0.350 seconds; Data structure size: 0.0Mb
84
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
2. DYNAMIC CASTING:
o Performed at runtime.
o Uses the $cast system task or function.
o Allows handling invalid assignments gracefully.
o Will cover during class explanation
85
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
OPERATORS
Assignment Operators
2. Conditional Operator
3. Unary Operators
` ` Reduction OR
`~ ` Reduction NOR
86
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
+ Addition int m = 5 + 3; // m = 8
- Subtraction int n = 5 - 3; // n = 2
* Multiplication int o = 5 * 3; // o = 15
/ Division int p = 15 / 3; // p = 5
** Exponentiation int q = 2 ** 3; // q = 8
% Modulus int r = 5 % 3; // r = 2
5. Bitwise Operators
` ` Bitwise OR
6. Shift Operators
87
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
7. Logical Operators
bit aa = 1 && 0;
&& Logical AND // aa = 0
` `
8. Relational Operators
bit ac = 5 < 3; //
< Less than ac = 0
bit ad = 5 <= 5; //
<= Less than or equal ad = 1
bit ae = 5 > 3; //
> Greater than ae = 1
bit af = 5 >= 5; //
>= Greater than or equal af = 1
9. Equality Operators
bit ag = 5 == 5; //
== Logical equality ag = 1
88
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
bit ah = 5 != 5; //
!= Logical inequality ah = 0
bit ai = 4'b1010
=== 4'b1010; // ai
=== Case equality =1
bit aj = 4'b1010
!== 4'b1010; // aj
!== Case inequality =0
bit ak = 4'b1010
==? 4'b1x1x; // ak
==? Wildcard equality =1
bit al = 4'b1010
!=? 4'b1x1x; // al
!=? Wildcard inequality =0
int am = 5; am++;
++ Increment // am = 6
int an = 5; an--; //
-- Decrement an = 4
bit ao = 5 inside
inside Set membership {1, 3, 5}; // ao = 1
89
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
int ap =
$dist_uniform(1,
10); // ap =
random value
between 1 and
dist Distribution 10
bit [7:0] aq =
{4'b1010,
4'b1100}; // aq =
{} Concatenation 8'b10101100
bit [7:0] ar =
{2{4'b1010}}; //
{{}} Replication ar = 8'b10101010
bit [7:0] as =
{<<{4'b1010}}; //
{<<{}} Left stream as = 8'b10100000
bit [7:0] at =
{>>{4'b1010}}; //
{>>{}} Right stream at = 8'b00001010
90
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
~ Bitwise NOT Inverts each bit of the
operand
& Bitwise AND AND operation on each bit
` ` Bitwise OR
^ Bitwise XOR XOR operation on each bit
^~ Bitwise XNOR XNOR operation on each bit
SUMMARY
91
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
-------------------------------------------->>>
Bitwise OR: a | b = 00000000000000000000000000001110
Logical OR: c || d = 1
-------------------------------------------->>>
Bitwise XOR: a ^ b = 00000000000000000000000000000110
Logical XOR: c ^ d = 1
-------------------------------------------->>>
Bitwise NOT: ~a = 11111111111111111111111111110101
92
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Logical NOT: !c = 0
-------------------------------------------->>>
Bitwise AND with assignment: a &= b, a = 1000
Logical AND with assignment: c = 0
-------------------------------------------->>>
Bitwise OR with assignment: a |= b, a = 1100
Logical OR with assignment: c = 0
-------------------------------------------->>>
Bitwise XOR with assignment: a ^= b, a = 0000
Logical XOR with assignment: c = 0
-------------------------------------------->>>
Bitwise NOT with assignment: a = ~a, a = 0101
Logical NOT with assignment: c = 1
-------------------------------------------->>>
VCS Simulation Report
93
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE 2: https://edaplayground.com/x/WtZx
94
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
95
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
96
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
97
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT
-------------------------------------------->>>
Bitwise OR: a | b = 00000000000000000000000000001110
Logical OR: c || d = 1
-------------------------------------------->>>
Bitwise XOR: a ^ b = 00000000000000000000000000000110
Logical XOR: c ^ d = 1
-------------------------------------------->>>
Bitwise NOT: ~a = 11111111111111111111111111110101
Logical NOT: !c = 0
-------------------------------------------->>>
Bitwise AND with assignment: a &= b, a = 1000
Logical AND with assignment: c = 0
-------------------------------------------->>>
Bitwise OR with assignment: a |= b, a = 1100
Logical OR with assignment: c = 0
-------------------------------------------->>>
Bitwise XOR with assignment: a ^= b, a = 0000
Logical XOR with assignment: c = 0
-------------------------------------------->>>
Bitwise NOT with assignment: a = ~a, a = 0101
Logical NOT with assignment: c = 1
-------------------------------------------->>>
VCS Simulation Report
98
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Parentheses have the highest precedence and are used to explicitly specify the order of
operations.
Example:
These operators are used to increase or decrease the value of a variable by 1. They
have higher precedence than most operators.
Example:
a++; // Post-increment
++a; // Pre-increment
Bitwise NOT (~), AND (&), OR (|), XOR (^), and their respective Negations (~&, ~|, ~^):
These are unary and binary bitwise operators. They perform operations at the bit level
and have higher precedence than arithmetic and relational operators.
Example:
These arithmetic operators have higher precedence than addition and subtraction.
Example:
result = a * b; // Multiplication
result = a % b; // Modulus
These are basic arithmetic operators, and they come after the multiplication, division,
and modulus operators in precedence.
Example:
99
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
result = a + b; // Addition
result = a - b; // Subtraction
These operators perform bitwise shifts (left or right) and have precedence just below
arithmetic operators.
Example:
These operators are used to compare values and are evaluated after the arithmetic and
shift operators.
Example:
Equality Operators (==, !=, ===, !==, =?=, !?=, ==?, !=?):
These operators are used to check for equality or inequality. The === and !== are
used for case-sensitive comparison (where x and z values are considered), while ==
and != are more standard.
Example:
Bitwise AND (&), Bitwise AND NOT (&~), XOR (^), XOR NOT (^~), OR (|), OR NOT
(|~):
These operators are bitwise and have precedence after the relational and equality
operators.
Example:
This operator is used for logical comparisons (e.g., in conditional statements) and has
lower precedence than the bitwise AND (&).
100
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Example:
if (a && b) begin
// Execute code if both 'a' and 'b' are non-zero
end
Logical OR (||):
This operator performs logical OR and has a lower precedence than logical AND
(&&).
Example:
if (a || b) begin
// Execute code if either 'a' or 'b' is non-zero
end
systemverilog
Copy
result = (a > b) ? 1 : 0; // If a > b, result = 1; otherwise 0
These operators are used to assign values and have the lowest precedence.
Example:
a = b; // Simple assignment
a += 5; // Add and assign
101
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EXAMPLE:
102
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 2
04:08 2025
Result with parentheses: 16
Post-increment a: 6
Pre-increment b: 4
Bitwise AND: 4
Bitwise OR: 6
Bitwise XOR: 2
Addition with multiplication precedence: 14
Logical Left Shift: 12
Logical Right Shift: 3
Arithmetic Right Shift: 3
a > b: 1
a == b: 0
Logical AND: 1
Logical OR: 1
Ternary conditional (a > b): 1
VCS Simulation Report
In SystemVerilog, streaming operators are used to manage and manipulate the flow of
bitstreams. These operators allow you to pack and unpack multiple variables into a single
bitstream, and also to reverse the order of the streamed data.
The order in which blocks of data are streamed is controlled by these streaming operators:
>>: This operator streams data from left to right, following the usual order of data.
For example, when applied to an array or multiple variables, the values will be packed
or streamed in the original order.
<<: This operator streams data from right to left, causing a reversal in the order of the
data. It's often used to simulate little-endian packing or to reverse the bits of a data
stream.
103
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Packing is done by using the streaming operators to combine multiple variables into
one single stream. Here, the order of variables can be customized by choosing
between << or >>.
Unpacking is performed by using the streaming operator on the left-hand side (LHS)
of an expression. This allows you to retrieve multiple values from a single packed
stream of bits.
104
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
When dealing with dynamically sized data, you can pack and unpack content using the
streaming operator. You can specify the size of the streamed data and the specific portions of
the object to include.
These streaming operators provide an elegant and powerful way to manage data transfer,
packing, and unpacking in hardware designs, and they are highly useful in situations where
you need to work with data streams and bit manipulation.
105
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
EVENTS
TRIGGERED
The "triggered" event property evaluates to true if the given event has been triggered
in the current time-step and false otherwise. If event_identifier is null, then the
triggered event property evaluates to false. Using this mechanism, an event trigger
shall unblock the waiting process whether the wait executes before or at the same
simulation time as the trigger operation.
106
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT :
--------------------------------------->
Event 'my_event' triggered at time 0
--------------------------------------->
--------------------------------------->
Waiting for 'my_event' to be triggered...
Event 'my_event' triggered at time 10
--------------------------------------->
107
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
The process will block until the event is triggered by another part of the simulation.
TRIGGERED PROPERTY
The .triggered property can be used to check if an event has been triggered during the current
time-step. This property returns true if the event has been triggered, and false otherwise.
Explanation:
The -> operator triggers the event immediately at the current simulation time. Once triggered,
the event becomes active, and processes waiting on this event can resume.
-> my_event; // Trigger the event 'my_event'
108
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
The ->> operator also triggers an event, but with a delayed trigger. The event is scheduled to
be triggered at the end of the current simulation time step, allowing other operations in the
same time-step to finish before the event is activated.
->> my_event; // Trigger the event at the end of the current time step
->> my_event; // Trigger the event at the end of the current time step
############################################
Event 'my_event' triggered at time 5
############################################
The difference between -> and ->> is subtle, but the second operator is used when you want
the event to be triggered after all actions within the current time step are completed.
109
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Once an event is triggered, processes or threads can wait for the event to occur. There are
several ways to wait for an event in SystemVerilog:
The @ operator is used to wait for an event. The process will pause at the @event_name
statement and will only continue execution once the event is triggered.
@my_event; // Wait until 'my_event' is triggered
############################################
Waiting for 'my_event' to be triggered...
Event 'my_event' triggered at time 10
############################################
110
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
The wait operator is used to pause a process until a certain condition (typically an event or a
boolean expression) becomes true. It can be used for both events and other conditions.
In this example, the wait operator will pause the process until the .triggered property of
my_event evaluates to true.
############################################
Event 'my_event' triggered at time 10
############################################
VCS Simulation Report
SystemVerilog provides the wait_order() function to wait for a set of events in a specified
order. This is useful when you need to ensure that certain events are triggered in a specific
order.
The process will wait until event1 is triggered, and only after that will it proceed to wait for
event2. This is useful when there is a strict order in which events should occur.
111
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
RESULT:
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 2
05:08 2025
Both events triggered in order.
VCS Simulation Report
Merging events means combining multiple events and waiting for all of them to be triggered.
The @ operator can be used for merging multiple events, where the process will block until
all of the listed events are triggered.
@ (event1 and event2); // Wait for both event1 and event2 to trigger
############################################
One of the events triggered at time 5
VCS Simulation Report
Time: 5 ns
CPU Time: 0.400 seconds; Data structure size: 0.0Mb
112
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
This example demonstrates how a process waits for an event using the @ operator.
Explanation:
The first process waits for the event e to be triggered using @e.
The second process triggers e at time 10.
When e is triggered, the first process resumes and displays the message that the event
has been triggered.
113
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
This example demonstrates how an event can be triggered first and then the process
waits for it to be triggered again
Explanation:
114
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
You can also use events to synchronize different parts of your design. Here’s an example of
two processes that synchronize using events:
Process 1 waits for the start_event, does some work (simulated with a delay), and then
triggers the end_event.
115
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
WORK IN PROGRESS
In progress :
Control Statements
Program Block
Procedural Blocks
Fork Join
Fork Control
Subroutines
Semaphore
Mailbox
Fine Grain Process
Control
Procedural Statements and Flow Control
Index
Blocking
Non-Blocking assignments
Unique-If
Priority-If
while, do-while
foreach
Named Blocks,
Statement Labels
disable block and disable statements
Event Control
Processes
Index
fork-join
fork-join_any
fork-join_none
wait-fork
disable-fork
116
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
117
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Result :
CPU time: .340 seconds to compile + .387 seconds to elab + .321 seconds to link
Chronologic VCS simulator copyright 1991-2023
Contains Synopsys proprietary information.
Compiler version U-2023.03-SP2_Full64; Runtime version U-2023.03-SP2_Full64; Feb 1 06:19 2025
Packet: id=1, name=Packet1
Packet: id=2, name=Packet2
VCS Simulation Report
118
SYSTEM VERILOG DATA TYPES BY VIKRAM RENESAS
Associative array for class
Result:
119