Whamcloud - gitweb
LU-5577 libcfs: fix warnings in libcfs/curproc.h
[fs/lustre-release.git] / libcfs / include / libcfs / user-bitops.h
index 1b36407..1b16ca7 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -42,7 +42,7 @@
 #define __LIBCFS_USER_BITOPS_H__
 
 /* test if bit nr is set in bitmap addr; returns previous value of bit nr */
-static __inline__ int cfs_test_and_set_bit(int nr, unsigned long *addr)
+static inline int test_and_set_bit(int nr, unsigned long *addr)
 {
         unsigned long mask;
 
@@ -53,10 +53,10 @@ static __inline__ int cfs_test_and_set_bit(int nr, unsigned long *addr)
         return nr;
 }
 
-#define cfs_set_bit(n, a) cfs_test_and_set_bit(n, a)
+#define set_bit(n, a) test_and_set_bit(n, a)
 
 /* clear bit nr in bitmap addr; returns previous value of bit nr*/
-static __inline__ int cfs_test_and_clear_bit(int nr, unsigned long *addr)
+static inline int test_and_clear_bit(int nr, unsigned long *addr)
 {
         unsigned long mask;
 
@@ -67,16 +67,16 @@ static __inline__ int cfs_test_and_clear_bit(int nr, unsigned long *addr)
         return nr;
 }
 
-#define cfs_clear_bit(n, a) cfs_test_and_clear_bit(n, a)
+#define clear_bit(n, a) test_and_clear_bit(n, a)
 
-static __inline__ int cfs_test_bit(int nr, const unsigned long *addr)
+static inline int test_bit(int nr, const unsigned long *addr)
 {
         return ((1UL << (nr & (BITS_PER_LONG - 1))) &
                 ((addr)[nr / BITS_PER_LONG])) != 0;
 }
 
 /* using binary seach */
-static __inline__ unsigned long __cfs_fls(long data)
+static __inline__ unsigned long fls(long data)
 {
        int pos = 32;
 
@@ -84,11 +84,11 @@ static __inline__ unsigned long __cfs_fls(long data)
                return 0;
 
 #if BITS_PER_LONG == 64
-        pos += 32;
-
-        if ((data & 0xFFFFFFFF) == 0) {
-                data <<= 32;
-                pos -= 32;
+        /* If any bit of the high 32 bits are set, shift the high
+         * 32 bits down and pretend like it is a 32-bit value. */
+        if ((data & 0xFFFFFFFF00000000llu)) {
+                data >>= 32;
+                pos += 32;
         }
 #endif
 
@@ -147,17 +147,16 @@ static __inline__ unsigned long __cfs_ffs(long data)
         return pos;
 }
 
-#define __cfs_ffz(x)   __cfs_ffs(~(x))
-#define __cfs_flz(x)   __cfs_fls(~(x))
+#define ffz(x)         ffs(~(x))
+#define flz(x)         fls(~(x))
 
-unsigned long cfs_find_next_bit(unsigned long *addr,
-                                unsigned long size, unsigned long offset);
+unsigned long find_next_bit(unsigned long *addr,
+                           unsigned long size, unsigned long offset);
 
-unsigned long cfs_find_next_zero_bit(unsigned long *addr,
-                                     unsigned long size, unsigned long offset);
+unsigned long find_next_zero_bit(unsigned long *addr,
+                                unsigned long size, unsigned long offset);
 
-#define cfs_find_first_bit(addr,size)     (cfs_find_next_bit((addr),(size),0))
-#define cfs_find_first_zero_bit(addr,size)  \
-        (cfs_find_next_zero_bit((addr),(size),0))
+#define find_first_bit(addr, size)       find_next_bit((addr), (size),0)
+#define find_first_zero_bit(addr, size)  find_next_zero_bit((addr), (size),0)
 
 #endif