0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

SystemVerilog中的Queue Methods

芯片验证工程师 来源:芯片验证工程师 作者:芯片验证工程师 2022-10-31 09:20 次阅读

队列提供了许多内置方法。如下表所示:

c6dfb3f0-586d-11ed-a3b6-dac502259ad0.png

module dq;
 bit[7:0] dq1[$]; // A unbounded queue of unsigned 8-bit
 int q3[$:5] = {0,1,2,3,4,5}; //bounded queue
 int a;
 initial begin
 a = dq1.size( ); //empty queue
 $display ($stime,,, "empty dq1 size = %0d",a);
 dq1[0] = 0; dq1[1] = 1; dq1[2] = 2;
 $display ($stime,,, "dq1 SIZE = %0d",dq1.size( ));
 $display ($stime,,, "dq1=",dq1);
 dq1.insert (3,3); //index, value
 $display($stime,,, "After Insert dq1 SIZE = %0d",dq1.size( ));
 $display ($stime,,, "dq1=",dq1);
 dq1.delete (3); //index
 $display ($stime,,, "After delete dq1 SIZE = %0d",dq1.size( ));
 $display ($stime,,, "dq1=",dq1);
 a = dq1.pop_front( ); //pop frst entry of the queue
 $display ($stime,,, "dq1 pop front = %0d ",a);
 $display ($stime,,, "dq1=",dq1);
 a = dq1.pop_back( ); //pop last entry of the queue
 $display ($stime,,, "dq1 pop back = %0d ",a);
 $display ($stime,,, "dq1=",dq1);
 //push the frst entry of the queue with '4'
 dq1.push_front(4);
 $display ($stime,,, "push front dq1=",dq1);
 //push the last entry of the queue with '5'
 dq1.push_back(5);
 $display ($stime,,, "push back dq1=",dq1);
 
 q3_size = q3.size + 5; //size > q3 size
 //underfow : pop from index 6,7,8,9,10 – run time Warning
 for (int i = 0; i < q3_size; i++)
 $display($stime,,,"q3[%0d] = %0d", i, q3.pop_front( ) );
 end
 //Solution for underfow - check for size before pop
 while (q3.size( ) > 0)
 $display($stime,,,"q3 = %0d", q3.pop_front ( ));
 //overfow : push over the bound limit – run time Warning
 for (int i = 0; i < q3_size; i++) begin
 q3.push_front( i );
 $display($stime,,,"q3[%0d] :: q3 = %p", i , q3);
 end
 endmodule

仿真log:

 0 empty dq1 size = 0 //empty queue size
 0 dq1 SIZE = 3 //size after providing values to frst three elements
 0 dq1='{'h0, 'h1, 'h2} //assigned frst three elements
 0 After Insert dq1 SIZE = 4 //Insert value 3 at index 3.
 0 dq1='{'h0, 'h1, 'h2, 'h3} //shows inserted value
 0 After delete dq1 SIZE = 3 //delete value at index 3
 0 dq1='{'h0, 'h1, 'h2} //shows dq1 after deletion
 0 dq1 pop front = 0 //pop the front index of the queue
 0 dq1='{'h1, 'h2} //dq1 after element at index 0 is gone (popped)
 0 dq1 pop back = 2 //pop the back (last) index of the queue
 0 dq1='{'h1} //the last index/value is gone
 0 push front dq1='{'h4, 'h1} //push at the front of the queue (value 4)
 0 push back dq1='{'h4, 'h1, 'h5} //push at the end of the queue (value 5)

上面我们通过队列dq1展示了push和pop的行为。然后我们声明了有界队列q3,最大的index限制是5,所以这个队列最大的size是6.
将队列q3初始化为{0,1,2,3,4,5},然后pop超过6次。

q3_size = q3.size + 5; //size > q3 size
 //underfow : pop from index 6,7,8,9,10 – run time Warning
 //Queue 'q3' is empty after index 5.
 for (int i = 0; i < q3_size; i++)
 $display($stime,,,"q3[%0d] = %0d", i, q3.pop_front( ) );
 end

这个时候仿真器会上报warnnin:

# RUNTIME: Warning: RUNTIME_0219 testbench.sv (54): Cannot pop from an 
empty queue.

审核编辑:汤梓红

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 仿真器
    +关注

    关注

    14

    文章

    988

    浏览量

    82998
  • Verilog
    +关注

    关注

    28

    文章

    1327

    浏览量

    109313
  • System
    +关注

    关注

    0

    文章

    161

    浏览量

    36575

原文标题:SystemVerilog中的Queue Methods

文章出处:【微信号:芯片验证工程师,微信公众号:芯片验证工程师】欢迎添加关注!文章转载请注明出处。

收藏 人收藏

    评论

    相关推荐

    SystemVerilog中的Virtual Methods

    SystemVerilog中多态能够工作的前提是父类中的方法被声明为virtual的。
    发表于 11-28 11:12 509次阅读

    [启芯公开课] SystemVerilog for Verification

    学快速发展,这些趋势你了解吗?SystemVerilog + VM是目前的主流,在未来也将被大量采用,这些语言和方法学,你熟练掌握了吗?对SoC芯片设计验证感兴趣的朋友,可以关注启芯工作室推出的SoC芯片
    发表于 06-10 09:25

    systemverilog学习教程

    systemverilog的一些基本语法以及和verilog语言之间的区别。
    发表于 04-01 14:24

    使用SystemVerilog来简化FPGA接口的连接方式

    FPGA接口的连接方式。    也许很多FPGA工程师对SystemVerilog并不是很了解,因为以前的FPGA开发工具是不支持SystemVerilog的,导致大家都是用VHDL或者Verilog来
    发表于 01-08 17:23

    SystemVerilog有哪些标准?

    SystemVerilog有哪些标准?
    发表于 06-21 08:09

    RT-Thread的data_queue是什么?怎样去使用

    1. data_queue 是什么data_queue 直接翻译过来是 数据队列。这个名字和 消息队列 很像。那么他们有什么区别呢?消息队列:消息队列能够接收来自线程或中断服务例程不固定
    发表于 04-15 15:56

    更好地理解SystemVerilog的多态Polymorphism

    多态(Polymorphism) ,从字面意思上看指的是多种形式,在OOP(面向对象编程)中指的是同一个父类的函数可以体现为不同的行为。在SystemVerilog,指的是我们可以使用父类句柄来
    发表于 12-05 17:34

    Some Programming Methods for I

    Some Programming Methods for Increasing the Operating Speed of PLC Program Absbad With Mitsubishi
    发表于 01-19 12:42 15次下载

    SystemVerilog Assertion Handbo

    SystemVerilog Assertion Handbook1 ROLE OF SYSTEMVERILOG ASSERTIONSIN A VERIFICATION METHODOLOGY
    发表于 07-22 14:08 188次下载

    SystemVerilog的断言手册

    SystemVerilog Assertion Handbook1 ROLE OF SYSTEMVERILOG ASSERTIONSIN A VERIFICATION METHODOLOGY
    发表于 07-22 14:12 20次下载

    Linux之work_queue_share教程

    Linux之work_queue_share教程,很好的Linux资料,快来学习吧
    发表于 04-15 17:49 13次下载

    ThreadX(九)------消息队列Queue

    消息队列QueueAPItx_queue_createtx_queue_deletex_queue_flushtx_queue_front_sendtx_queue_receivetx_queue_send_notifyAPItx_queue_createtx_queue_deletetx_queue_flushtx_qu
    发表于 12-28 19:35 2次下载
    ThreadX(九)------消息队列<b class='flag-5'>Queue</b>

    队列Queue的常用方法有哪些

    FIFO(先入先出)队列Queue,LIFO(后入先出)队列LifoQueue,和优先级队列PriorityQueue。
    的头像 发表于 08-19 10:24 5157次阅读
    队列<b class='flag-5'>Queue</b>的常用方法有哪些

    什么是queue

    queue 容器,又称队列容器,是简单地装饰deque容器而成为另外的一种容器。
    的头像 发表于 02-27 15:43 1006次阅读

    RTOS中Queue的工作原理

    Queue即消息队列是通过RTOS内核提供的一种服务。它是一种线程间同步数据的安全方法。
    的头像 发表于 07-25 15:45 1867次阅读
    RTOS中<b class='flag-5'>Queue</b>的工作原理