![Article Title](https://tistory1.daumcdn.net/tistory/342254/skin/images/icon_post_title.gif)
< Data Types >
☞ https://www.doulos.com/knowhow/sysverilog/tutorial/datatypes/
* Integer and Real Types
- 4-state logic(0,1,x,z) @verilog : reg[unser-defined], logic[user-defined], integer(32b, signed)
cf. 'logic' can be used instead of 'wire' or 'reg'
- 2-state logic(0,1) introduced by System Verilog : bit[user-defined], byte(8b), shortint(16b), int(32b), longint(64b)
- Non-integer type : time(64b, unsinged), shortreal(=float in C), real(=double in C), realtime(=real)
* Arrays
- may have either packed or unpacked dimensions, or both, e.g.
reg [3:0][7:0] register [0:9]; // packed [3:0][7:0], unpacked [0:9]
-> Packed dimensions : laid out contiguously in memory, cab be sliced, restricted to "bit" types or some types with fixed-size(e.g. int)
-> Unpacked dimensions : arranged in memory in any way, can be copied on to another array of the same type(for different types, a cast must be used ), any type
* Queue : a variable-size, ordered collection of homogeneous elements
☞ https://www.verificationguide.com/p/systemverilog-queues.html
- Declaration
data_type queue_name[$]; // specifying $ as the array size ( '$' is also used as the last index of Queue )
// data_type : data type of the queue elements (e.g. bit, int, byte, string, etc.)
// queue_name : name of the queue
// e.g. byte queue_a[$:255]; // max entry size = 256
// e.g. string queue_b[$];
- Initialization :
Queue_Name = {element0, element2, ... }; // for string : "element"
- Queue Methods
size() --> returns the number of items in the queue // queue_a.size()
insert() --> inserts the given item at the specified index position
// queue_a.insert(1,100) // Insert the element of '100' into #1 position
// the previous elements with the index equal to and larger than the specified index have the index which is increased by 1
delete() --> deletes the item at the specified index position.
// queue_a.delete(5) // delete the element in #5 position
// the previous elements with the index equal to and larger than the specified index have the index which is decreased by 1
push_front() --> inserts the given element at the front of the queue // same as 'insert(0,element)'
push_back() --> inserts the given element at the end of the queue // same as 'insert($+1,element)'
pop_front() --> removes and returns the first element of the queue
// same as '$display(Queue_Name[0]) + Queue_Name.delete[0]'
pop_back() --> removes and returns the last element of the queue
// same as '$display(Queue_Name[$]) + Queue_Name.delete[$]'
* enum : a set of named values
% syntax : enum {element_0, ..., elelement_n} enum_variable; // 'enum_variable' can store one of enum elements
% example
enum {RED, YELLOW, GREEN} light_1; // int type; RED = 0, YELLOW = 1, GREEN = 2
enum bit[1:0] {RED, YELLOW, GREEN} light_2; // bit type; RED = 0, YELLOW = 1, GREEN = 2
enum {RED = 4, YELLOW = 9, GREEN} light_4; // RED = 4, YELLOW = 9, GREEN = 10 (automatically assigned)
* Typedef :
typedef reg [7:0] Octet;
typedef Octet [3:0] QuadOctet;
QuadOctet qByptes [0:10]; // same as 'reg [3:0][7:0] qBytes [0:10];