• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. What is wrong with this code ? I'm trying to use a Queue...

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 64
  • Views 1398
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

What is wrong with this code ? I'm trying to use a Queue of classes..

archive
archive over 18 years ago

module top;
timeunit 1ns;

class genfra;
rand bit [31:0] dword1;
rand bit [31:0] dword2;
endclass :genfra

integer success,i,dly;
genfra temp1,temp2;

genfra fifo[$] ;
initial
begin
temp1=new();
for(i = 0 ; i < 20 ;i++)
begin
success = temp1.randomize();
success = randomize(dly) with {dly > 2;dly < 5;};
$display("time=%d.. temp1.dword1 = %08x ",$time,temp1.dword1);
$display("time=%d.. temp1.dword2 = %08x ",$time,temp1.dword2);
fifo.push_back(temp1);
#dly;
end
$finish;
end

initial
begin
#15;
forever
begin
$display("time=%d..before pop ",$time);
if(fifo.size())
begin
$display("fifo size before pop ",fifo.size());
temp2=fifo.pop_front();
$display("time=%d.. temp2.dword1 = %08x ",$time,temp2.dword1);
$display("time=%d.. temp2.dword2 = %08x ",$time,temp2.dword2);
$display("fifo size after pop ",fifo.size());
end
else
#1;
end
end

endmodule


I'm getting the following output.. The

temp2=fifo.pop_front();
doesn't seem to do what it should.. It prints the last object and doesn't remove it from the queue ..
can someone point out whats wrong!! (see
--????? below..)
ncverilog: 05.83-p002: (c) Copyright 1995-2006 Cadence Design Systems, Inc.
TOOL: ncverilog 05.83-p002: Started on Dec 14, 2006 at 13:49:26 IST
.
.
.
ncsim> run
SVSEED set from command line: 60
time= 0.. temp1.dword1 = e68182cd
time= 0.. temp1.dword2 = 0321b106
time= 4.. temp1.dword1 = 7bd6b7f7
time= 4.. temp1.dword2 = a9586452
time= 7.. temp1.dword1 = a51a824a
time= 7.. temp1.dword2 = c78e9c8f
time= 10.. temp1.dword1 = 9ba71c37
time= 10.. temp1.dword2 = 106de120
time= 13.. temp1.dword1 = 8798120f
time= 13.. temp1.dword2 = 3b6a8d76
time= 15..before pop
fifo size before pop 5
time= 15.. temp2.dword1 = 8798120f --?????
time= 15.. temp2.dword2 = 3b6a8d76 --?????
fifo size after pop 4
time= 15..before pop
fifo size before pop 4
time= 15.. temp2.dword1 = 8798120f --?????
time= 15.. temp2.dword2 = 3b6a8d76 --?????
fifo size after pop 3
time= 15..before pop
fifo size before pop 3
time= 15.. temp2.dword1 = 8798120f
time= 15.. temp2.dword2 = 3b6a8d76
fifo size after pop 2
time= 15..before pop
fifo size before pop 2
time= 15.. temp2.dword1 = 8798120f
time= 15.. temp2.dword2 = 3b6a8d76
fifo size after pop 1
time= 15..before pop
fifo size before pop 1
time= 15.. temp2.dword1 = 8798120f
time= 15.. temp2.dword2 = 3b6a8d76
fifo size after pop 0
time= 15..before pop
time= 16..before pop
time= 17.. temp1.dword1 = 8e68b41c
time= 17.. temp1.dword2 = 5e7ba1bc
time= 17..before pop
fifo size before pop 1
time= 17.. temp2.dword1 = 8e68b41c
time= 17.. temp2.dword2 = 5e7ba1bc
fifo size after pop 0
time= 17..before pop
time= 18..before pop
time= 19..before pop
time= 20..before pop
time= 21.. temp1.dword1 = 2a916b55
time= 21.. temp1.dword2 = 0dcdad1b
time= 21..before pop
fifo size before pop 1
time= 21.. temp2.dword1 = 2a916b55
time= 21.. temp2.dword2 = 0dcdad1b
fifo size after pop 0
time= 21..before pop
time= 22..before pop
time= 23..before pop
time= 24.. temp1.dword1 = bdfc1c7b
time= 24.. temp1.dword2 = e2a8aec5
time= 24..before pop
fifo size before pop 1
time= 24.. temp2.dword1 = bdfc1c7b
time= 24.. temp2.dword2 = e2a8aec5

.
.
.
 

Thanks..


Originally posted in cdnusers.org by mirzani
  • Cancel
  • archive
    archive over 18 years ago

    Hello,

    I looked at your code and see that you are only calling new() once during the simulation.  So it is only allocating space for one genfra class item.  When you place the item on the queue, you are actually only placing the pointer to genfra.  So it will always remember the last item you randomized.

    To fix the problem, move the temp1=new() inside the for-loop.  It will generate a new item every time.

    initial
      begin
         for (i=0; i<20; i++)
            begin
               temp1=new();  // MOVE HERE!
                success = temp1.randomize();
      ....

    I hope this helps!

    Kathleen Meade


    Originally posted in cdnusers.org by kameade
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    Thanks..


    Originally posted in cdnusers.org by mirzani
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information