xfs
[Top] [All Lists]

use is_power_of_2() macro?

To: xfs@xxxxxxxxxxx
Subject: use is_power_of_2() macro?
From: "Robert P. J. Day" <rpjday@xxxxxxxxxxxxxx>
Date: Tue, 6 Nov 2007 10:28:44 -0500 (EST)
Sender: xfs-bounce@xxxxxxxxxxx
  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
========================================================================


<Prev in Thread] Current Thread [Next in Thread>