Move function for calculating number of bits into more central place.

I want to use it so more.

MFC after:	3 days
This commit is contained in:
Pawel Jakub Dawidek 2005-08-19 22:13:09 +00:00
parent a95452ee8d
commit 829781048d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=149302
3 changed files with 14 additions and 6 deletions

View File

@ -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;
}

View File

@ -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)
{

View File

@ -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);