aboutsummaryrefslogtreecommitdiffstats
path: root/sbin/geom/misc
diff options
context:
space:
mode:
authorPawel Jakub Dawidek <pjd@FreeBSD.org>2005-08-19 22:13:09 +0000
committerPawel Jakub Dawidek <pjd@FreeBSD.org>2005-08-19 22:13:09 +0000
commit829781048d3056bd66235529dda1aceee0f5ff7f (patch)
tree0a1e817aa8b8fb347dafbaab5238a85c9fb3fe93 /sbin/geom/misc
parenta95452ee8dd44f31e1c1c32d3f0358e5e14810a4 (diff)
downloadsrc-829781048d3056bd66235529dda1aceee0f5ff7f.tar.gz
src-829781048d3056bd66235529dda1aceee0f5ff7f.zip
Move function for calculating number of bits into more central place.
I want to use it so more. MFC after: 3 days
Notes
Notes: svn path=/head/; revision=149302
Diffstat (limited to 'sbin/geom/misc')
-rw-r--r--sbin/geom/misc/subr.c12
-rw-r--r--sbin/geom/misc/subr.h1
2 files changed, 13 insertions, 0 deletions
diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c
index a0525af6aff4..599223a80e5f 100644
--- a/sbin/geom/misc/subr.c
+++ b/sbin/geom/misc/subr.c
@@ -95,6 +95,18 @@ g_lcm(unsigned a, unsigned b)
return ((a * b) / gcd(a, b));
}
+uint32_t
+bitcount32(uint32_t x)
+{
+
+ x = (x & 0x55555555) + ((x & 0xaaaaaaaa) >> 1);
+ x = (x & 0x33333333) + ((x & 0xcccccccc) >> 2);
+ x = (x & 0x0f0f0f0f) + ((x & 0xf0f0f0f0) >> 4);
+ x = (x & 0x00ff00ff) + ((x & 0xff00ff00) >> 8);
+ x = (x & 0x0000ffff) + ((x & 0xffff0000) >> 16);
+ return (x);
+}
+
off_t
g_get_mediasize(const char *name)
{
diff --git a/sbin/geom/misc/subr.h b/sbin/geom/misc/subr.h
index ee319a983bc5..164c3b46dc0e 100644
--- a/sbin/geom/misc/subr.h
+++ b/sbin/geom/misc/subr.h
@@ -29,6 +29,7 @@
#ifndef _SUBR_H_
#define _SUBR_H_
unsigned g_lcm(unsigned a, unsigned b);
+uint32_t bitcount32(uint32_t x);
off_t g_get_mediasize(const char *name);
unsigned g_get_sectorsize(const char *name);