public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* use is_power_of_2() macro?
@ 2007-11-06 15:28 Robert P. J. Day
  2007-11-07  5:18 ` David Chinner
  0 siblings, 1 reply; 2+ messages in thread
From: Robert P. J. Day @ 2007-11-06 15:28 UTC (permalink / raw)
  To: xfs


  given this in fs/xfs/xfs_inode.c:

/*
 * xfs_iroundup: round up argument to next power of two
 */
uint
xfs_iroundup(
        uint    v)
{
        int i;
        uint m;

        if ((v & (v - 1)) == 0)
                return v;
        ASSERT((v & 0x80000000) == 0);
        if ((v & (v + 1)) == 0)
                return v + 1;
        for (i = 0, m = 1; i < 31; i++, m <<= 1) {
                if (v & m)
                        continue;
                v |= m;
                if ((v & (v + 1)) == 0)
                        return v + 1;
        }
        ASSERT(0);
        return( 0 );
}

  is there any reason that can't be rewritten with simply
roundup_pow_of_two() as defined in include/linux/log2.h?

#define roundup_pow_of_two(n)                   \
(                                               \
        __builtin_constant_p(n) ? (             \
                (n == 1) ? 1 :                  \
                (1UL << (ilog2((n) - 1) + 1))   \
                                   ) :          \
        __roundup_pow_of_two(n)                 \
 )

  just curious.

rday

-- 
========================================================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry
Waterloo, Ontario, CANADA

http://crashcourse.ca
========================================================================

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: use is_power_of_2() macro?
  2007-11-06 15:28 use is_power_of_2() macro? Robert P. J. Day
@ 2007-11-07  5:18 ` David Chinner
  0 siblings, 0 replies; 2+ messages in thread
From: David Chinner @ 2007-11-07  5:18 UTC (permalink / raw)
  To: Robert P. J. Day; +Cc: xfs

On Tue, Nov 06, 2007 at 10:28:44AM -0500, Robert P. J. Day wrote:
> 
>   given this in fs/xfs/xfs_inode.c:
> 
> /*
>  * xfs_iroundup: round up argument to next power of two
>  */
> uint
> xfs_iroundup(
>         uint    v)
> {
>         int i;
>         uint m;
> 
>         if ((v & (v - 1)) == 0)
>                 return v;
>         ASSERT((v & 0x80000000) == 0);
>         if ((v & (v + 1)) == 0)
>                 return v + 1;
>         for (i = 0, m = 1; i < 31; i++, m <<= 1) {
>                 if (v & m)
>                         continue;
>                 v |= m;
>                 if ((v & (v + 1)) == 0)
>                         return v + 1;
>         }
>         ASSERT(0);
>         return( 0 );
> }
> 
>   is there any reason that can't be rewritten with simply
> roundup_pow_of_two() as defined in include/linux/log2.h?
> 
> #define roundup_pow_of_two(n)                   \
> (                                               \
>         __builtin_constant_p(n) ? (             \
>                 (n == 1) ? 1 :                  \
>                 (1UL << (ilog2((n) - 1) + 1))   \
>                                    ) :          \
>         __roundup_pow_of_two(n)                 \
>  )
> 
>   just curious.

No - patch please.

Cheers,

Dave.
-- 
Dave Chinner
Principal Engineer
SGI Australian Software Group

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-11-07  5:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-06 15:28 use is_power_of_2() macro? Robert P. J. Day
2007-11-07  5:18 ` David Chinner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox