All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sandeen <sandeen@sandeen.net>
To: xfs-oss <xfs@oss.sgi.com>
Subject: [PATCH 1/2] Use generic routines for xfs_next_bit
Date: Fri, 28 Sep 2007 08:15:56 -0500	[thread overview]
Message-ID: <46FCFE8C.9020405@sandeen.net> (raw)

We can use find_next_bit, which is assembly on some arches,
to implement xfs_next_bit.  Tested on x86.

Signed-off-by: Eric Sandeen <sandeen@sandeen.net>

Index: linux-2.6.22.i386/fs/xfs/xfs_bit.c
===================================================================
--- linux-2.6.22.i386.orig/fs/xfs/xfs_bit.c
+++ linux-2.6.22.i386/fs/xfs/xfs_bit.c
@@ -192,32 +192,16 @@ found:
  */
 int xfs_next_bit(uint *map, uint size, uint start_bit)
 {
-	uint * p = ((unsigned int *) map) + (start_bit >> BIT_TO_WORD_SHIFT);
-	uint result = start_bit & ~(NBWORD - 1);
-	uint tmp;
+	int result;
 
-	size <<= BIT_TO_WORD_SHIFT;
+	size <<= BIT_TO_WORD_SHIFT;
+	if (start_bit >= size)	/* beyond end of bitmap */
+		return -1;
 
-	if (start_bit >= size)
-		return -1;
-	size -= result;
-	start_bit &= (NBWORD - 1);
-	if (start_bit) {
-		tmp = *p++;
-		/* set to zero first offset bits prior to start */
-		tmp &= (~0U << start_bit);
-		if (tmp != 0U)
-			goto found;
-		result += NBWORD;
-		size -= NBWORD;
-	}
-	while (size) {
-		if ((tmp = *p++) != 0U)
-			goto found;
-		result += NBWORD;
-		size -= NBWORD;
-	}
-	return -1;
-found:
-	return result + ffs(tmp) - 1;
+	result = find_next_bit((unsigned long *)map, size, start_bit);
+
+	if (result == size)	/* no bits set */
+		return -1;
+
+	return result;
 }

                 reply	other threads:[~2007-09-28 13:16 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=46FCFE8C.9020405@sandeen.net \
    --to=sandeen@sandeen.net \
    --cc=xfs@oss.sgi.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.