Add missing lib/ffz.h file
authorJens Axboe <jens.axboe@oracle.com>
Mon, 2 Jun 2008 07:19:37 +0000 (09:19 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 2 Jun 2008 07:19:37 +0000 (09:19 +0200)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
lib/ffz.h [new file with mode: 0644]

diff --git a/lib/ffz.h b/lib/ffz.h
new file mode 100644 (file)
index 0000000..7fc7d45
--- /dev/null
+++ b/lib/ffz.h
@@ -0,0 +1,37 @@
+#ifndef FIO_FFZ_H
+#define FIO_FFZ_H
+
+static inline int __ffs(int word)
+{
+       int r = 0;
+
+       if (!(word & 0xffff)) {
+               word >>= 16;
+               r += 16;
+       }
+       if (!(word & 0xff)) {
+               word >>= 8;
+               r += 8;
+       }
+       if (!(word & 0xf)) {
+               word >>= 4;
+               r += 4;
+       }
+       if (!(word & 3)) {
+               word >>= 2;
+               r += 2;
+       }
+       if (!(word & 1)) {
+               word >>= 1;
+               r += 1;
+       }
+
+       return r;
+}
+
+static inline int ffz(unsigned int bitmask)
+{
+       return ffs(~bitmask);
+}
+
+#endif