public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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: Thu, 1 Apr 2004 14:42:34 -0800	[thread overview]
Message-ID: <20040401144234.2ef3c205.pj@sgi.com> (raw)
In-Reply-To: <20040401133033.435a3857.pj@sgi.com>

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@sgi.com> 1.650.933.1373

  reply	other threads:[~2004-04-01 22:43 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 [this message]
2004-04-04  6:57         ` Paul Jackson
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=20040401144234.2ef3c205.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