public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yoshinori Sato <ysato@users.sourceforge.jp>
To: Linus Torvalds <torvalds@osdl.org>
Cc: linux kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] H8/300 update (1/9) bitops.h add find_next_bit
Date: Wed, 12 May 2004 01:36:15 +0900	[thread overview]
Message-ID: <m21xlqsyyo.wl%ysato@users.sourceforge.jp> (raw)

- add find_next_bit

-- 
Yoshinori Sato
<ysato@users.sourceforge.jp>

diff -Nru linux-2.6.6/include/asm-h8300/bitops.h linux-2.6.6-h8300/include/asm-h8300/bitops.h
--- linux-2.6.6/include/asm-h8300/bitops.h	2004-05-11 14:30:27.000000000 +0900
+++ linux-2.6.6-h8300/include/asm-h8300/bitops.h	2004-05-11 21:28:11.000000000 +0900
@@ -181,6 +181,23 @@
 #define find_first_zero_bit(addr, size) \
 	find_next_zero_bit((addr), (size), 0)
 
+static __inline__ unsigned long __ffs(unsigned long word)
+{
+	unsigned long result;
+
+	result = -1;
+	__asm__("1:\n\t"
+		"shlr.l %2\n\t"
+		"adds #1,%0\n\t"
+		"bcc 1b"
+		: "=r" (result)
+		: "0"(result),"r"(word));
+	return result;
+}
+
+#define ffs(x) generic_ffs(x)
+#define fls(x) generic_fls(x)
+
 static __inline__ int find_next_zero_bit (void * addr, int size, int offset)
 {
 	unsigned long *p = (unsigned long *)(((unsigned long)addr + (offset >> 3)) & ~3);
@@ -217,22 +234,44 @@
 	return result + ffz(tmp);
 }
 
-static __inline__ unsigned long __ffs(unsigned long word)
+static __inline__ unsigned long find_next_bit(const unsigned long *addr,
+	unsigned long size, unsigned long offset)
 {
-	unsigned long result;
+	unsigned long *p = (unsigned long *)(((unsigned long)addr + (offset >> 3)) & ~3);
+	unsigned int result = offset & ~31UL;
+	unsigned int tmp;
 
-	result = -1;
-	__asm__("1:\n\t"
-		"shlr.l %2\n\t"
-		"adds #1,%0\n\t"
-		"bcc 1b"
-		: "=r" (result)
-		: "0"(result),"r"(word));
-	return result;
-}
+	if (offset >= size)
+		return size;
+	size -= result;
+	offset &= 31UL;
+	if (offset) {
+		tmp = *(p++);
+		tmp &= ~0UL << offset;
+		if (size < 32)
+			goto found_first;
+		if (tmp)
+			goto found_middle;
+		size -= 32;
+		result += 32;
+	}
+	while (size >= 32) {
+		if ((tmp = *p++) != 0)
+			goto found_middle;
+		result += 32;
+		size -= 32;
+	}
+	if (!size)
+		return result;
+	tmp = *p;
 
-#define ffs(x) generic_ffs(x)
-#define fls(x) generic_fls(x)
+found_first:
+	tmp &= ~0UL >> (32 - size);
+	if (tmp == 0UL)
+		return result + size;
+found_middle:
+	return result + __ffs(tmp);
+}
 
 /*
  * Every architecture must define this function. It's the fastest

                 reply	other threads:[~2004-05-11 16:51 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=m21xlqsyyo.wl%ysato@users.sourceforge.jp \
    --to=ysato@users.sourceforge.jp \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /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