Systemverilog中的队列操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Systemverilog中的队列操作相关的知识,希望对你有一定的参考价值。
systemverilog中的队列操作十分简单,只需要调用函数即可。
/* Exercise platform: Questa Sim 10.1b */ module queue; int q[$] ; function void sep(); for( int i = 0 ; i < 10 ; i++ ) $write(" *** "); $display(); endfunction:sep function void print(int q[$]); sep(); foreach(q[i]) $display("queue[%2d] = %d",i,q[i]); sep(); endfunction:print initial begin for(int i = 0 ; i < 10 ; i++ ) q.insert(i,i); print(q); $display(" push back 10 "); q.push_back(10); // 还有 push_front 方法 print(q); $display(" pop back 10 "); q.pop_back(); // 还有 pop_front 方法 print(q); $display(" Delete pos 0 "); q.delete(0); // 删除索引为0的队列成员 print(q); q = {}; // 清除队列,犹如c++中的析构函数 end endmodule:queue
仿真结果: # Loading work.queue(fast) >>>run # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # *** *** *** *** *** *** *** *** *** *** # push back 10 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # queue[10] = 10 # *** *** *** *** *** *** *** *** *** *** # pop back 10 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 0 # queue[ 1] = 1 # queue[ 2] = 2 # queue[ 3] = 3 # queue[ 4] = 4 # queue[ 5] = 5 # queue[ 6] = 6 # queue[ 7] = 7 # queue[ 8] = 8 # queue[ 9] = 9 # *** *** *** *** *** *** *** *** *** *** # Delete pos 0 # *** *** *** *** *** *** *** *** *** *** # queue[ 0] = 1 # queue[ 1] = 2 # queue[ 2] = 3 # queue[ 3] = 4 # queue[ 4] = 5 # queue[ 5] = 6 # queue[ 6] = 7 # queue[ 7] = 8 # queue[ 8] = 9 # *** *** *** *** *** *** *** *** *** ***
以上是关于Systemverilog中的队列操作的主要内容,如果未能解决你的问题,请参考以下文章