• 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. sv array method sum()

Stats

  • Locked Locked
  • Replies 2
  • Subscribers 67
  • Views 19140
  • 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

sv array method sum()

arjuny
arjuny over 14 years ago

 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.

  • Cancel
Parents
  • opmishra
    opmishra over 10 years ago

    Explanation on values "0"(if item > 3) :

    cnt = (1>3) + (2>3) + (3>3) + (4>3) + (5>3) = F+F+F+T+T=0+0+0+1+1=single bit 0

    Explanation on values "1"(if item > 2) :

    cnt = (1>2) + (2>2) + (3>2) + (4>2) + (5>2) = F+F+T+T+T=0+0+1+1+1=single bit 1

    To get output  "9"  for  (item > 3 ) , rewrite the code as : 

    cnt = dyn.sum() with ((item > 3)?item:0)  //returns "9"

    To get output  "12"  for  (item > 2 ) , rewrite the code as : 

    cnt = dyn.sum() with ((item > 2)?item:0); //returns "12"

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Reply
  • opmishra
    opmishra over 10 years ago

    Explanation on values "0"(if item > 3) :

    cnt = (1>3) + (2>3) + (3>3) + (4>3) + (5>3) = F+F+F+T+T=0+0+0+1+1=single bit 0

    Explanation on values "1"(if item > 2) :

    cnt = (1>2) + (2>2) + (3>2) + (4>2) + (5>2) = F+F+T+T+T=0+0+1+1+1=single bit 1

    To get output  "9"  for  (item > 3 ) , rewrite the code as : 

    cnt = dyn.sum() with ((item > 3)?item:0)  //returns "9"

    To get output  "12"  for  (item > 2 ) , rewrite the code as : 

    cnt = dyn.sum() with ((item > 2)?item:0); //returns "12"

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
Children
No Data

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