summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2005-08-19 22:13:09 +0000
committerpjd <pjd@FreeBSD.org>2005-08-19 22:13:09 +0000
commit94bc690fb5dab9ce2259bca563c83e1457603512 (patch)
tree0a1e817aa8b8fb347dafbaab5238a85c9fb3fe93
parent863deb3c00d07683cfba7aca2e35643099e42dd7 (diff)
downloadFreeBSD-src-94bc690fb5dab9ce2259bca563c83e1457603512.zip
FreeBSD-src-94bc690fb5dab9ce2259bca563c83e1457603512.tar.gz
Move function for calculating number of bits into more central place.
I want to use it so more. MFC after: 3 days
-rw-r--r--sbin/geom/class/raid3/geom_raid3.c7
-rw-r--r--sbin/geom/misc/subr.c12
-rw-r--r--sbin/geom/misc/subr.h1
3 files changed, 14 insertions, 6 deletions
diff --git a/sbin/geom/class/raid3/geom_raid3.c b/sbin/geom/class/raid3/geom_raid3.c
index bef8424..7a8527f 100644
--- a/sbin/geom/class/raid3/geom_raid3.c
+++ b/sbin/geom/class/raid3/geom_raid3.c
@@ -155,12 +155,7 @@ raid3_label(struct gctl_req *req)
gctl_error(req, "Too few arguments.");
return;
}
-#ifndef BITCOUNT
-#define BITCOUNT(x) (((BX_(x) + (BX_(x) >> 4)) & 0x0F0F0F0F) % 255)
-#define BX_(x) ((x) - (((x) >> 1) & 0x77777777) - \
- (((x) >> 2) & 0x33333333) - (((x) >> 3) & 0x11111111))
-#endif
- if (BITCOUNT(*nargs - 2) != 1) {
+ if (bitcount32(*nargs - 2) != 1) {
gctl_error(req, "Invalid number of components.");
return;
}
diff --git a/sbin/geom/misc/subr.c b/sbin/geom/misc/subr.c
index a0525af..599223a 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 ee319a9..164c3b4 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);
OpenPOWER on IntegriCloud