diff options
author | Tim Chase <[email protected]> | 2014-04-26 20:56:03 -0500 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2014-07-22 09:47:48 -0700 |
commit | 7f23e0010977ffa492d6df57aee0c97ce8e74278 (patch) | |
tree | 1aced52d08f23ac1d04de9e53b7dfc0391002059 /module | |
parent | 377e12f14a2c3694c3a733782b91ae7beecc44f3 (diff) |
Add functions and macros as used upstream.
Added highbit64() and howmany() which are used in recent upstream
code. Both highbit() and highbit64() should at some point be
re-factored to use the optimized fls() and fls64() functions.
Signed-off-by: Brian Behlendorf <[email protected]>
Signed-off-by: Prakash Surya <[email protected]>
Signed-off-by: Tim Chase <[email protected]>
Closes #363
Diffstat (limited to 'module')
-rw-r--r-- | module/spl/spl-generic.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c index 4f0842b1a..6cb73ddb7 100644 --- a/module/spl/spl-generic.c +++ b/module/spl/spl-generic.c @@ -97,6 +97,36 @@ highbit(unsigned long i) } EXPORT_SYMBOL(highbit); +int +highbit64(uint64_t i) +{ + register int h = 1; + SENTRY; + + if (i == 0) + SRETURN(0); + if (i & 0xffffffff00000000ull) { + h += 32; i >>= 32; + } + if (i & 0xffff0000) { + h += 16; i >>= 16; + } + if (i & 0xff00) { + h += 8; i >>= 8; + } + if (i & 0xf0) { + h += 4; i >>= 4; + } + if (i & 0xc) { + h += 2; i >>= 2; + } + if (i & 0x2) { + h += 1; + } + SRETURN(h); +} +EXPORT_SYMBOL(highbit64); + #if BITS_PER_LONG == 32 /* * Support 64/64 => 64 division on a 32-bit platform. While the kernel |