Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 86399
b: refs/heads/master
c: ef8ece5
h: refs/heads/master
i:
  86397: 5f0ff8d
  86395: 1518b5a
  86391: 7c33b17
  86383: 8a0a875
  86367: 651298c
  86335: 0008f7d
  86271: 5f505c2
v: v3
  • Loading branch information
Lachlan McIlroy authored and Lachlan McIlroy committed Feb 26, 2008
1 parent 24ceb64 commit 25a0c42
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 30 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: db69c915e67705daac25cad06d816c09be634de0
refs/heads/master: ef8ece55d9b6825c28a5c1a4bd89b94040cb7b32
103 changes: 103 additions & 0 deletions trunk/fs/xfs/xfs_bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,109 @@
* XFS bit manipulation routines, used in non-realtime code.
*/

#ifndef HAVE_ARCH_HIGHBIT
/*
* Index of high bit number in byte, -1 for none set, 0..7 otherwise.
*/
static const char xfs_highbit[256] = {
-1, 0, 1, 1, 2, 2, 2, 2, /* 00 .. 07 */
3, 3, 3, 3, 3, 3, 3, 3, /* 08 .. 0f */
4, 4, 4, 4, 4, 4, 4, 4, /* 10 .. 17 */
4, 4, 4, 4, 4, 4, 4, 4, /* 18 .. 1f */
5, 5, 5, 5, 5, 5, 5, 5, /* 20 .. 27 */
5, 5, 5, 5, 5, 5, 5, 5, /* 28 .. 2f */
5, 5, 5, 5, 5, 5, 5, 5, /* 30 .. 37 */
5, 5, 5, 5, 5, 5, 5, 5, /* 38 .. 3f */
6, 6, 6, 6, 6, 6, 6, 6, /* 40 .. 47 */
6, 6, 6, 6, 6, 6, 6, 6, /* 48 .. 4f */
6, 6, 6, 6, 6, 6, 6, 6, /* 50 .. 57 */
6, 6, 6, 6, 6, 6, 6, 6, /* 58 .. 5f */
6, 6, 6, 6, 6, 6, 6, 6, /* 60 .. 67 */
6, 6, 6, 6, 6, 6, 6, 6, /* 68 .. 6f */
6, 6, 6, 6, 6, 6, 6, 6, /* 70 .. 77 */
6, 6, 6, 6, 6, 6, 6, 6, /* 78 .. 7f */
7, 7, 7, 7, 7, 7, 7, 7, /* 80 .. 87 */
7, 7, 7, 7, 7, 7, 7, 7, /* 88 .. 8f */
7, 7, 7, 7, 7, 7, 7, 7, /* 90 .. 97 */
7, 7, 7, 7, 7, 7, 7, 7, /* 98 .. 9f */
7, 7, 7, 7, 7, 7, 7, 7, /* a0 .. a7 */
7, 7, 7, 7, 7, 7, 7, 7, /* a8 .. af */
7, 7, 7, 7, 7, 7, 7, 7, /* b0 .. b7 */
7, 7, 7, 7, 7, 7, 7, 7, /* b8 .. bf */
7, 7, 7, 7, 7, 7, 7, 7, /* c0 .. c7 */
7, 7, 7, 7, 7, 7, 7, 7, /* c8 .. cf */
7, 7, 7, 7, 7, 7, 7, 7, /* d0 .. d7 */
7, 7, 7, 7, 7, 7, 7, 7, /* d8 .. df */
7, 7, 7, 7, 7, 7, 7, 7, /* e0 .. e7 */
7, 7, 7, 7, 7, 7, 7, 7, /* e8 .. ef */
7, 7, 7, 7, 7, 7, 7, 7, /* f0 .. f7 */
7, 7, 7, 7, 7, 7, 7, 7, /* f8 .. ff */
};
#endif

/*
* xfs_highbit32: get high bit set out of 32-bit argument, -1 if none set.
*/
inline int
xfs_highbit32(
__uint32_t v)
{
#ifdef HAVE_ARCH_HIGHBIT
return highbit32(v);
#else
int i;

if (v & 0xffff0000)
if (v & 0xff000000)
i = 24;
else
i = 16;
else if (v & 0x0000ffff)
if (v & 0x0000ff00)
i = 8;
else
i = 0;
else
return -1;
return i + xfs_highbit[(v >> i) & 0xff];
#endif
}

/*
* xfs_lowbit64: get low bit set out of 64-bit argument, -1 if none set.
*/
int
xfs_lowbit64(
__uint64_t v)
{
__uint32_t w = (__uint32_t)v;
int n = 0;

if (w) { /* lower bits */
n = ffs(w);
} else { /* upper bits */
w = (__uint32_t)(v >> 32);
if (w && (n = ffs(w)))
n += 32;
}
return n - 1;
}

/*
* xfs_highbit64: get high bit set out of 64-bit argument, -1 if none set.
*/
int
xfs_highbit64(
__uint64_t v)
{
__uint32_t h = (__uint32_t)(v >> 32);

if (h)
return xfs_highbit32(h) + 32;
return xfs_highbit32((__uint32_t)v);
}


/*
* Return whether bitmap is empty.
* Size is number of words in the bitmap, which is padded to word boundary
Expand Down
27 changes: 5 additions & 22 deletions trunk/fs/xfs/xfs_bit.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,13 @@ static inline __uint64_t xfs_mask64lo(int n)
}

/* Get high bit set out of 32-bit argument, -1 if none set */
static inline int xfs_highbit32(__uint32_t v)
{
return fls(v) - 1;
}

/* Get high bit set out of 64-bit argument, -1 if none set */
static inline int xfs_highbit64(__uint64_t v)
{
return fls64(v) - 1;
}

/* Get low bit set out of 32-bit argument, -1 if none set */
static inline int xfs_lowbit32(__uint32_t v)
{
unsigned long t = v;
return (v) ? find_first_bit(&t, 32) : -1;
}
extern int xfs_highbit32(__uint32_t v);

/* Get low bit set out of 64-bit argument, -1 if none set */
static inline int xfs_lowbit64(__uint64_t v)
{
unsigned long t = v;
return (v) ? find_first_bit(&t, 64) : -1;
}
extern int xfs_lowbit64(__uint64_t v);

/* Get high bit set out of 64-bit argument, -1 if none set */
extern int xfs_highbit64(__uint64_t);

/* Return whether bitmap is empty (1 == empty) */
extern int xfs_bitmap_empty(uint *map, uint size);
Expand Down
19 changes: 12 additions & 7 deletions trunk/fs/xfs/xfs_rtalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ STATIC int xfs_rtmodify_summary(xfs_mount_t *, xfs_trans_t *, int,
* Internal functions.
*/

/*
* xfs_lowbit32: get low bit set out of 32-bit argument, -1 if none set.
*/
STATIC int
xfs_lowbit32(
__uint32_t v)
{
if (v)
return ffs(v) - 1;
return -1;
}

/*
* Allocate space to the bitmap or summary file, and zero it, for growfs.
*/
Expand Down Expand Up @@ -432,7 +444,6 @@ xfs_rtallocate_extent_near(
}
bbno = XFS_BITTOBLOCK(mp, bno);
i = 0;
ASSERT(minlen != 0);
log2len = xfs_highbit32(minlen);
/*
* Loop over all bitmap blocks (bbno + i is current block).
Expand Down Expand Up @@ -601,8 +612,6 @@ xfs_rtallocate_extent_size(
xfs_suminfo_t sum; /* summary information for extents */

ASSERT(minlen % prod == 0 && maxlen % prod == 0);
ASSERT(maxlen != 0);

/*
* Loop over all the levels starting with maxlen.
* At each level, look at all the bitmap blocks, to see if there
Expand Down Expand Up @@ -660,9 +669,6 @@ xfs_rtallocate_extent_size(
*rtblock = NULLRTBLOCK;
return 0;
}
ASSERT(minlen != 0);
ASSERT(maxlen != 0);

/*
* Loop over sizes, from maxlen down to minlen.
* This time, when we do the allocations, allow smaller ones
Expand Down Expand Up @@ -1948,7 +1954,6 @@ xfs_growfs_rt(
nsbp->sb_blocksize * nsbp->sb_rextsize);
nsbp->sb_rextents = nsbp->sb_rblocks;
do_div(nsbp->sb_rextents, nsbp->sb_rextsize);
ASSERT(nsbp->sb_rextents != 0);
nsbp->sb_rextslog = xfs_highbit32(nsbp->sb_rextents);
nrsumlevels = nmp->m_rsumlevels = nsbp->sb_rextslog + 1;
nrsumsize =
Expand Down

0 comments on commit 25a0c42

Please sign in to comment.