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:
parent
a95452ee8d
commit
829781048d
@ -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;
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user