From: Paul Jackson <pj@sgi.com>
To: Paul Jackson <pj@sgi.com>
Cc: wli@holomorphy.com, linux-kernel@vger.kernel.org
Subject: Re: remove bitmap_shift_*() bitmap length limits
Date: Sat, 3 Apr 2004 22:57:12 -0800 [thread overview]
Message-ID: <20040403225712.7d4acc86.pj@sgi.com> (raw)
In-Reply-To: <20040401144234.2ef3c205.pj@sgi.com>
There was one bug in my untested code for simple bitmap shifts,
the left shift needs to scan downwards, not upwards, so as to
avoid clobbering the input if shifting inplace.
The total text size of my user level test program is actually
made smaller with this per-bit simple implementation, as compared
to the implementation currently in the kernel, by 80 bytes.
Bill Irwin's more sophisticated version grows the text size,
over the current implementation, by 304 bytes. This is on
Pentium pc, gcc version 3.3.2, compiled -O2.
Given the very rare usage this bitmap shift routines receive,
I cast my vote for small and simple.
The more sophisticated logic of Bill's implementation is
impressive, but unjustified in this situation, in my view.
My fixed shift functions are:
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(const 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 = bits-1; k >= 0; 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@sgi.com> 1.650.933.1373
next prev parent reply other threads:[~2004-04-04 6:58 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-03-30 6:51 remove bitmap_shift_*() bitmap length limits William Lee Irwin III
2004-03-30 7:36 ` William Lee Irwin III
2004-03-30 8:11 ` William Lee Irwin III
2004-04-01 21:30 ` Paul Jackson
2004-04-01 22:42 ` Paul Jackson
2004-04-04 6:57 ` Paul Jackson [this message]
2004-04-04 7:04 ` William Lee Irwin III
2004-04-04 7:17 ` Paul Jackson
2004-04-04 7:11 ` Paul Jackson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040403225712.7d4acc86.pj@sgi.com \
--to=pj@sgi.com \
--cc=linux-kernel@vger.kernel.org \
--cc=wli@holomorphy.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox