ASIC with Ankit Ankit Gopani
Ankit Gopani is Experienced Design Verification Engineer. He has been working in the field of ASIC Design and verification and have worked on various IP, SOC, module and subsystem level verification. Ankit has been in the industry for more than 15 years. He is well-known name in the field of ASIC … More » System Verilog Queues which can shrink and grow !May 18th, 2013 by Ankit Gopani
Dear Readers, System Verilog has new data type called ‘queue’ which can grow and shrink. With SV queue, we can easily add and remove elements anywhere that is the reason we say it can shrink and grow as we need. Queues can be used as LIFO (Last In First Out) Buffer or FIFO (First In First Out) type of buffers. Each element in the queue is identified by an ordinal number that represents its position within the queue, with 0 representing the first element and $ represents the last element. The size of the queue is variable similar to dynamic array but queue may be empty with zero element and still its a valid data structure. Lets take a few examples to understand queue operation with different methods we have in system verilog.
###############################################
int a;
Q[$] = {0,1,2,3}; // Initial queue
initial begin
//Insert and delete
Q.insert (1, 1); // This means insert 1 at first element in the queue which becomes {0,1,1,2,3}
Q.delete(2); // This means delete 2nd element from the queue. {0,1,2,3}
//Push_front
Q.push_front (6); //Insert ‘6’ at front of the queue. {6,0,1,2,3}
//Pop_back
a = Q.pop_back; // Poping the last element and stored it to local variable ‘a’, a = 3 in this case. Resultant Queue = {6,0,1,2}
//push_back
Q.push_back(7) // Pushing the element ‘7’ from the back. {6,0,1,2,7}
//Pop_front:
a =Q.pop_front; Poping the first element and stored it to local variable called ‘a’, a=6 in this case. Resultant Queue = {0,1,2,7}
end
#####################################################
Hope this helps in basic understanding of queue and its methods. Happy Reading!
Categories: ASIC FPGA Verification, System Verilog One Response to “System Verilog Queues which can shrink and grow !” |
Like