Home > Community > Forums > Functional Verification > What is wrong with this code ? I'm trying to use a Queue of classes..

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

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

Last post Thu, Dec 14 2006 1:14 AM by archive. 2 replies.
Started by archive 14 Dec 2006 01:14 AM. Topic has 2 replies and 1177 views
Page 1 of 1 (3 items)
Sort Posts:
  • Thu, Dec 14 2006 1:14 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    What is wrong with this code ? I'm trying to use a Queue of classes.. Reply

    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
    • Post Points: 0
  • Thu, Dec 14 2006 4:49 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: What is wrong with this code ? I'm trying to use a Queue of classes.. Reply

    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
    • Post Points: 0
  • Thu, Dec 14 2006 5:24 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: What is wrong with this code ? I'm trying to use a Queue of classes.. Reply

    Thanks..


    Originally posted in cdnusers.org by mirzani
    • Post Points: 0
Page 1 of 1 (3 items)
Sort Posts:
Started by archive at 14 Dec 2006 01:14 AM. Topic has 2 replies.