Commit 15cb8a4f authored by Nathan Scott's avatar Nathan Scott

[XFS] Fix xfs_lowbit64, it mishandled zero in the high bits.

Cleanup a couple of other ffs users, since ffs(0) is apparently
undefined on some architectures.

SGI Modid: xfs-linux:xfs-kern:173034a
Signed-off-by: nathans@sgi.com
parent 1f152c17
/*
* Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
......@@ -154,14 +154,17 @@ int
xfs_lowbit64(
__uint64_t v)
{
int n;
n = ffs((unsigned)v);
if (n <= 0) {
n = ffs(v >> 32);
if (n >= 0)
n+=32;
__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 <= 0) ? n : n-1;
return n - 1;
}
/*
......@@ -171,10 +174,11 @@ int
xfs_highbit64(
__uint64_t v)
{
__uint32_t h = v >> 32;
__uint32_t h = (__uint32_t)(v >> 32);
if (h)
return xfs_highbit32(h) + 32;
return xfs_highbit32((__u32)v);
return xfs_highbit32((__uint32_t)v);
}
......
/*
* Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
* Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
......@@ -100,7 +100,9 @@ STATIC int
xfs_lowbit32(
__uint32_t v)
{
return ffs(v)-1;
if (v)
return ffs(v) - 1;
return -1;
}
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment