Home > Community > Forums > Functional Verification > sv array method sum()

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: *

 sv array method sum() 

Last post Wed, Nov 3 2010 11:49 PM by Ravisinha. 1 replies.
Started by arjuny 02 Nov 2010 09:19 AM. Topic has 1 replies and 1192 views
Page 1 of 1 (2 items)
Sort Posts:
  • Tue, Nov 2 2010 9:19 AM

    • arjuny
    • Not Ranked
    • Joined on Tue, May 5 2009
    • Posts 5
    • Points 85
    sv array method sum() Reply

     Hi,

        I was going through the "sv for verification". I am trying to run the examples given in the book on IUS(9.2).

        As per LRM (array reduction methods),"sum() returns the sum of all the array elements or, if a with clause is specified, returns the sum of the values yielded by evaluating the expression for each array element." 

        But the following code generates values "0"(if item > 3) or "1"(if item > 2) when i tried to run the following example.

        As per my understanding with LRM, if (item > 3 ) the output should be "9" and if (item > 2) the output should be "12".

    module test;
      bit[7:0] dyn[='{1,2,3,4,5},cnt;
      initial begin
        foreach(dyn[i]) begin
          $display("dyn[%0d]=%0d",i,dyn[i]);
        end
        //check website
        //cnt = dyn.sum() with (item > 3); //returns "0"
        cnt = dyn.sum() with (item > 2); //returns "1"
        $display("dyn : %d",cnt);
      end
    endmodule


    How the tools is generating output "0" or "1"?

     Thanks & Regards,

    Arjun.

    Filed under: ,
    • Post Points: 20
  • Wed, Nov 3 2010 11:49 PM

    • Ravisinha
    • Top 500 Contributor
    • Joined on Mon, Nov 23 2009
    • Posts 21
    • Points 315
    Re: sv array method sum() Reply
    Hi Arjun, As i know .sum() method is not safe to use.. Whatever expression you are giving as per the LRM it will result in the following expression like : For dyn.sum() with(item >3) will result in cnt = (1>3) + (2>3) + (3>3) + (4>3) + (5>3) And i am not sure what will be the output of this expression.
    • Post Points: 5
Page 1 of 1 (2 items)
Sort Posts:
Started by arjuny at 02 Nov 2010 09:19 AM. Topic has 1 replies.