lkml.org 
[lkml]   [2005]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[RFC][PATCH 2.4 1/4] inotify 0.22 2.4.x backport - find_next_bit
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





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;
+}


\
 
 \ /
  Last update: 2005-05-10 17:19    [W:0.028 / U:0.236 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site