Re: errata/128: clogb2 still wrong

From: Steven Sharp (sharp@cadence.com)
Date: Mon Apr 07 2003 - 12:40:07 PDT

  • Next message: Karen Pieper: "Minutes for today's meeting"

    Precedence: bulk

    The following reply was made to PR errata/128; it has been noted by GNATS.

    From: Steven Sharp <sharp@cadence.com>
    To: etf-bugs@boyd.com, Shalom.Bresticker@motorola.com
    Cc:
    Subject: Re: errata/128: clogb2 still wrong
    Date: Mon, 7 Apr 2003 15:39:17 -0400 (EDT)

     Shalom's version appears to be correct. Another approach would be more like
     the original version in the standard, with the bugs fixed:
     
     function integer clogb2;
     input [31:0] value;
     begin
       for (clogb2 = 0; 2**clogb2 < value; clogb2 = clogb2 + 1)
         begin end // nothing to do
     end
     endfunction
     
     Or if you don't like the odd-looking null loop body:
     
     function integer clogb2;
     input [31:0] value;
     begin
       clogb2 = 0;
       while (2**clogb2 < value)
         clogb2 = clogb2 + 1;
     end
     endfunction
     
     And you can use (1<<clogb2) instead of (2**clogb2), if you are worried
     about uncertainty in the still-pending decision on signed powers.
     
     There are some differences in behavior from Shalom's version at the
     endpoints: value equal to 0 or greater than 2**31. In fact, this one
     will go into an infinite loop for value greater than 2**31. That could
     be fixed by declaring value as an integer or signed reg.
     
     Steven Sharp
     sharp@cadence.com
     



    This archive was generated by hypermail 2.1.4 : Mon Apr 07 2003 - 12:40:39 PDT and
    sponsored by Boyd Technology, Inc.