* swsusp for 2.5.8: find_last_bit_set
@ 2002-04-21 21:30 Pavel Machek
0 siblings, 0 replies; only message in thread
From: Pavel Machek @ 2002-04-21 21:30 UTC (permalink / raw)
To: torvalds, kernel list
Hi!
For software suspend [enabling suspend to disk on any machine], I need
find_last_bit_set interface. Here it is, please apply.
Pavel
--- clean.2.5/include/asm-generic/bitops.h Tue Nov 28 02:47:38 2000
+++ linux-swsusp/include/asm-generic/bitops.h Sun Apr 21 20:40:55 2002
@@ -51,6 +51,12 @@
return ((mask & *addr) != 0);
}
+/*
+ * fls: find last bit set.
+ */
+
+#define fls(x) generic_fls(x)
+
#ifdef __KERNEL__
/*
--- clean.2.5/include/asm-i386/bitops.h Thu Apr 18 22:46:15 2002
+++ linux-swsusp/include/asm-i386/bitops.h Sun Apr 21 21:15:07 2002
@@ -414,6 +414,12 @@
return word;
}
+/*
+ * fls: find last bit set.
+ */
+
+#define fls(x) generic_fls(x)
+
#ifdef __KERNEL__
/*
--- clean.2.5/include/linux/bitops.h Mon Nov 5 21:42:13 2001
+++ linux-swsusp/include/linux/bitops.h Sun Apr 21 21:15:07 2002
@@ -1,6 +1,6 @@
#ifndef _LINUX_BITOPS_H
#define _LINUX_BITOPS_H
-
+#include <asm/bitops.h>
/*
* ffs: find first bit set. This is defined the same way as
@@ -35,6 +35,47 @@
r += 1;
}
return r;
+}
+
+/*
+ * fls: find last bit set.
+ */
+
+extern __inline__ int generic_fls(int x)
+{
+ int r = 32;
+
+ if (!x)
+ return 0;
+ if (!(x & 0xffff0000)) {
+ x <<= 16;
+ r -= 16;
+ }
+ if (!(x & 0xff000000)) {
+ x <<= 8;
+ r -= 8;
+ }
+ if (!(x & 0xf0000000)) {
+ x <<= 4;
+ r -= 4;
+ }
+ if (!(x & 0xc0000000)) {
+ x <<= 2;
+ r -= 2;
+ }
+ if (!(x & 0x80000000)) {
+ x <<= 1;
+ r -= 1;
+ }
+ return r;
+}
+
+extern __inline__ int get_bitmask_order(unsigned int count)
+{
+ int order;
+
+ order = fls(count);
+ return order; /* We could be slightly more clever with -1 here... */
}
/*
--
(about SSSCA) "I don't say this lightly. However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy." --hpa
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2002-04-21 21:47 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-21 21:30 swsusp for 2.5.8: find_last_bit_set Pavel Machek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®