Data types Flashcards
New data type advntges
Added new datatypes :
- 2-state data types
- Strings
- with built-in searching/sorting support ( Q,dyn_arr,asso_arr)
- which are Abstract data structures ( classes,structs)
- with Multiple view of same data ( union/packed array)
- which are Easy to WR/RD : enum
Logic
Can be used anywhere, in place of nets/registers.
Except : more than one structural drivers
assign l1 = a&b;
assign l1 = c|d;
All data types
- bit : 1 : 2-state : unsigned
- logic : 1 : 4-state : unsigned
byte : 8 : 2-state : signed
shortint : 16 : 2-state : signed
int : 32 : 2-state : signed
longint : 64 : 2-state : signed
real : 64 : 2-state : signed
* integer : 32 : 4-state : signed
* time : 64
Built-in function
- $isunknown( var ) : returns 1 is XorZ in var
- $timeformat()
- $size() : Returns size of array
Fixed Array
Fixed array
- Declaration : type name[size];
type name[0:size-1];
eg : int arr[5] ::::= int arr[0:5]int arr[5] = '{ 20,21,22,23,24}; // same as == int arr[0:4] Here arr[0] = 20 arr[1] = 21 foreach(arr[i]) : starts with arr[0],arr[1]...arr[4] int arr[4:0] = '{ 20,21,22,23,24}; Here arr[0] = 24 arr[1] = 23 foreach(arr[i]) : starts with arr[4],arr[3]...arr[0]
- Initialization : arr = ‘{ 20,21,3{-1}};
arr = ‘{ 20,21,default:-1}; - size : $size(arr)
- Accessing : foreach(arr[i]) begin arr[i]=-1; end```
int arr_2d[3][2] = ‘{‘{00,01}, ‘{10,11}, ‘{20,21}};
foreach(arr_2d[i,j]) begin … end
foreach(arr_2d[i]) begin foreach(arr_2d[,j]) begin … end end
~~~ - Compare/copy : If arrays of same type & size
Array which is packed
Unpacked ::
~~~
logic[7:0] u_arr1[4] -
——–——–——–bbbbbbbbb : u_arr1[0] : word0
——–——–——–bbbbbbbbb : u_arr1[1] : word1
——–——–——–bbbbbbbbb : u_arr1[2] : word2
——–——–_——–_bbbbbbbbb : u_arr1[3] : word3
~~~
Packed :: logic[3:0][7:0] p_arr1 - bbbbbbbb_bbbbbbbb_bbbbbbbb_bbbbbbbbb : p_arr1 : word0
logic[7:0] u_arr1[4] = '{ 8'haa, 8'hbb, 8'hcc, 8'hdd}; logic[7:0] u_arr2[3:0] = '{ 8'haa, 8'hbb, 8'hcc, 8'hdd}; logic[3:0][7:0] p_arr1 = 32'haabbccdd; logic[4][7:0] p_arr2 = 32'haabbccdd; u_arr1[0] := 8'haa u_arr2[0] := 8'hdd p_arr1[0] := 8'hdd p_arr2[0] := 8'haa
Use of packed array :
* Multiple view of same data
* @(packed_array) : wait condition
when is subscript needed after array
- Depends on number of dimension defined after name
- Page 33-34
2d array indexing
- [i,j], [,j] allowed only in foreach.
- not allowed even in body of foreach
- page : 30,31
Dynamin array
- declaration syntax
- initialization
- size
- accessing elements
- compare/copy
- Built-in functions
- usage
- Page - 35, notebook(ruled)
when is new not needed for dyn array
page 35
Mutli-D dyn array
- Regular/irregular dyn array
- https://verificationguide.com/systemverilog/systemverilog-multidimensional-dynamic-array/
bit [7:0] d_array[][]; initial begin //memory allocation d_array = new[3]; d_array[0] = new[2]; d_array[1] = new[1]; d_array[2] = new[4]; //assigning random value to elements foreach(d_array[i,j]) d_array[i][j] = $random; //displaying array elements foreach(d_array[i,j]) $display("\td_aaray[%0d,%0d] = %0d",i,j, d_array[i][j]); end
fixed and dynamic array copies
- notebook
Queues
- declaration syntax
- initialization
- size
- indexing
- copy/compare
- builtin function
- usage
- notes/page-37
$ to access last element
- applicable only to q
- examples
- note/page37
associative array
- declaration synx ( also class as index type)
- initalization
- size
- copy/compare
- built-in functions
- usage
- https://www.chipverify.com/systemverilog/systemverilog-associative-array
- notes/page-39