{"id":62,"date":"2023-05-25T17:50:48","date_gmt":"2023-05-25T17:50:48","guid":{"rendered":"https:\/\/amvrao.in\/blog\/?p=62"},"modified":"2024-07-24T10:30:54","modified_gmt":"2024-07-24T10:30:54","slug":"basics-of-systemverilog-queue","status":"publish","type":"post","link":"https:\/\/amvrao.in\/blog\/index.php\/2023\/05\/25\/basics-of-systemverilog-queue\/","title":{"rendered":"Basics of systemverilog Queue"},"content":{"rendered":"\n<ul class=\"wp-block-list\">\n<li>Well what&#8217;s a queue? A First In First Out data structure. Coming to system verilog, here comes the basic properties of Queues.\n<ul class=\"wp-block-list\">\n<li>The size of queue will be infinite by default. (Well until your simulator or your machine crashes)<\/li>\n\n\n\n<li>A fixed size queue.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>In any case the simulator will manage the modifications to this queue. May it be any additions or deletions of elements or updations to its elements.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Now how do you declare a queue in system verilog. The syntax is not too complicated yet.\n<ul class=\"wp-block-list\">\n<li>Unbounded or an infinite queue.\n<ul class=\"wp-block-list\">\n<li>&lt;data-type&gt; &lt;queue_identifier&gt;[$]<\/li>\n\n\n\n<li>Eg: <code>int id_que[$];<\/code><\/li>\n\n\n\n<li>This will create a queue of name id_queue which can hold integer objects. Now int can be replaced by data type of your own choice<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Bounded or a finite queue.\n<ul class=\"wp-block-list\">\n<li>In this case if you don&#8217;t want to waste space and you know your queue does not need more than N number of elements you can use bounded queues.<\/li>\n\n\n\n<li>&lt;data-type&gt; &lt;queue_identifier&gt;[$:&lt;size&gt;]<\/li>\n\n\n\n<li>Eg: <code>int id_que[$:9]; \/\/This stores 10 elements<\/code><\/li>\n\n\n\n<li>This will create a queue of size (size+1). it can store (size+1) elements in it.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Now having been declared and you have to make use of it.<\/li>\n\n\n\n<li>Tasks\/Functions for queue:\n<ul class=\"wp-block-list\">\n<li>size():\n<ul class=\"wp-block-list\">\n<li>id_que.size(): will return the number of elements present in the queue at the time when this is called.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>insert():\n<ul class=\"wp-block-list\">\n<li>id_que.insert(10, 1001); This will insert 1001 into queue at index 10.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>delete()\n<ul class=\"wp-block-list\">\n<li>id_que.delete(10): This will delete 10th element in the queue. <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>push_back()\n<ul class=\"wp-block-list\">\n<li>id_que.push_back(VALUE) : This will append VALUE at the end of the queue. The pushed value is the tail or last element in the queue.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>push_front()\n<ul class=\"wp-block-list\">\n<li>id_que.push_front(VALUE): This will prepend VALUE at the beginning of the queue. The pushed value is the head or first element in the queue. <\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>pop_back():\n<ul class=\"wp-block-list\">\n<li>int a = id_queue.pop_back(): This will remove last element or tail from the queue and returns the value stored.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>pop_front()\n<ul class=\"wp-block-list\">\n<li>int b = id_que.pop_front(): This will remove the first element or the head from the queue and returns the value stored in first lement.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Trivia:<\/li>\n\n\n\n<li>what happens when you pop from empty queue?<\/li>\n\n\n\n<li>what happens from when you push when queue is full?<\/li>\n\n\n\n<li>what happens if you push a wrong data type?<\/li>\n\n\n\n<li>what happens if you pop and assign to a wrong data type?<\/li>\n\n\n\n<li><\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Some practice:<\/li>\n\n\n\n<li>How do you implement mailbox functionality by using only queue and its methods<\/li>\n<\/ul>\n\n\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-uncategorized","excerpt","zoom","full-without-featured","even","excerpt-0"],"_links":{"self":[{"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/62"}],"collection":[{"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=62"}],"version-history":[{"count":6,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":87,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/posts\/62\/revisions\/87"}],"wp:attachment":[{"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amvrao.in\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}