public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mihai Rusu <dizzy@schlund.ro>
To: linux-kernel@vger.kernel.org
Cc: Robert Love <rml@novell.com>
Subject: [RFC][PATCH 2.4 1/4] inotify 0.22 2.4.x backport - find_next_bit
Date: Tue, 10 May 2005 18:12:55 +0300	[thread overview]
Message-ID: <4280CF77.4040102@schlund.ro> (raw)

[-- Attachment #1: Type: text/plain, Size: 271 bytes --]

Hi

This is the find_next_bit implementation from 2.6.11 vanilla. Needed by
"idr.c".

-- 
Mihai Rusu
Linux System Development

Schlund + Partner AG   Tel         : +40-21-231-2544
Str Mircea Eliade 18   EMail       : dizzy@schlund.ro
Sect 1, Bucuresti
71295, Romania





[-- Attachment #2: 01_find_next_bit-2.4.30.patch --]
[-- Type: text/x-patch, Size: 2576 bytes --]


 include/linux/bitops.h |    2 +
 lib/Makefile           |    2 -
 lib/find_next_bit.c    |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)

diff -uNr linux-2.4.30.orig/include/linux/bitops.h linux-2.4.30/include/linux/bitops.h
--- linux-2.4.30.orig/include/linux/bitops.h	2001-11-22 21:46:18.000000000 +0200
+++ linux-2.4.30/include/linux/bitops.h	2005-05-09 13:13:18.000000000 +0300
@@ -66,6 +66,8 @@
         return (res & 0x0F) + ((res >> 4) & 0x0F);
 }
 
+int find_next_bit(const unsigned long *addr, int size, int offset);
+
 #include <asm/bitops.h>
 
 
diff -uNr linux-2.4.30.orig/lib/Makefile linux-2.4.30/lib/Makefile
--- linux-2.4.30.orig/lib/Makefile	2004-04-14 16:05:40.000000000 +0300
+++ linux-2.4.30/lib/Makefile	2005-05-09 13:16:49.000000000 +0300
@@ -12,7 +12,7 @@
 	       rbtree.o crc32.o firmware_class.o
 
 obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
-	 bust_spinlocks.o rbtree.o dump_stack.o
+	 bust_spinlocks.o rbtree.o dump_stack.o find_next_bit.o
 
 obj-$(CONFIG_FW_LOADER) += firmware_class.o
 obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
diff -uNr linux-2.4.30.orig/lib/find_next_bit.c linux-2.4.30/lib/find_next_bit.c
--- linux-2.4.30.orig/lib/find_next_bit.c	1970-01-01 02:00:00.000000000 +0200
+++ linux-2.4.30/lib/find_next_bit.c	2005-05-09 13:13:18.000000000 +0300
@@ -0,0 +1,55 @@
+/* find_next_bit.c: fallback find next bit implementation
+ *
+ * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
+ * Written by David Howells (dhowells@redhat.com)
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version
+ * 2 of the License, or (at your option) any later version.
+ */
+
+#include <linux/bitops.h>
+
+int find_next_bit(const unsigned long *addr, int size, int offset)
+{
+	const unsigned long *base;
+	const int NBITS = sizeof(*addr) * 8;
+	unsigned long tmp;
+
+	base = addr;
+	if (offset) {
+		int suboffset;
+
+		addr += offset / NBITS;
+
+		suboffset = offset % NBITS;
+		if (suboffset) {
+			tmp = *addr;
+			tmp >>= suboffset;
+			if (tmp)
+				goto finish;
+		}
+
+		addr++;
+	}
+
+	while ((tmp = *addr) == 0)
+		addr++;
+
+	offset = (addr - base) * NBITS;
+
+ finish:
+	/* count the remaining bits without using __ffs() since that takes a 32-bit arg */
+	while (!(tmp & 0xff)) {
+		offset += 8;
+		tmp >>= 8;
+	}
+
+	while (!(tmp & 1)) {
+		offset++;
+		tmp >>= 1;
+	}
+
+	return offset;
+}




                 reply	other threads:[~2005-05-10 15:13 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=4280CF77.4040102@schlund.ro \
    --to=dizzy@schlund.ro \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rml@novell.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