Re: remove bitmap_shift_*() bitmap length limits

From: Paul Jackson
Date: Thu Apr 01 2004 - 17:44:44 EST


Bill,

Here's roughly what I mean by slow and stupid (code untested, just a way
of presenting an alternative idea). Perhaps my head is in a weird
place, but I find the following easier to understand.

lib/bitmap.c:
=============

static void _setbitval(unsigned long *dst,
unsigned int n, int val, unsigned int nbits)
{
if (n >= nbits)
return;
if (val)
set_bit(n, dst);
else
clear_bit(n, dst);
}

static int _getbitval(unsigned long *src, unsigned int n, unsigned int nbits)
{
if (n >= nbits)
return 0;
return test_bit(n, src) ? 1 : 0;
}

void bitmap_shift_right(unsigned long *dst,
const unsigned long *src, int shift, int bits)
{
int k;
for (k = 0; k < bits; k++)
_setbitval(dst, k, _getbitval(src, k+shift, bits), bits);
}
EXPORT_SYMBOL(bitmap_shift_right);

void bitmap_shift_left(unsigned long *dst,
const unsigned long *src, int shift, int bits)
{
int k;
for (k = 0; k < bits; k++)
_setbitval(dst, k, _getbitval(src, k-shift, bits), bits);
}
EXPORT_SYMBOL(bitmap_shift_left);

--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@xxxxxxx> 1.650.933.1373
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/