]> wimlib.net Git - wimlib/blobdiff - include/wimlib/bitops.h
Use more comprehensive public domain dedications
[wimlib] / include / wimlib / bitops.h
index 2e7a948fd9b91bb9d4065a49a23252ff77d1dc90..70e6c611a888c68feb76ddbb627c57a4d2b89c54 100644 (file)
@@ -1,10 +1,21 @@
 /*
- * bitops.h
+ * bitops.h - inline functions for bit manipulation
  *
- * Inline functions for bit manipulation.
+ * The following copying information applies to this specific source code file:
  *
- * The author dedicates this file to the public domain.
- * You can do whatever you want with this file.
+ * Written in 2014-2016 by Eric Biggers <ebiggers3@gmail.com>
+ *
+ * To the extent possible under law, the author(s) have dedicated all copyright
+ * and related and neighboring rights to this software to the public domain
+ * worldwide via the Creative Commons Zero 1.0 Universal Public Domain
+ * Dedication (the "CC0").
+ *
+ * This software is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the CC0 for more details.
+ *
+ * You should have received a copy of the CC0 along with this software; if not
+ * see <http://creativecommons.org/publicdomain/zero/1.0/>.
  */
 
 #ifndef _WIMLIB_BITOPS_H
@@ -44,7 +55,7 @@ fls64(u64 v)
 static inline unsigned
 flsw(machine_word_t v)
 {
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
        if (WORDSIZE == 4)
                return fls32(v);
        else
@@ -82,11 +93,21 @@ ffs64(u64 v)
 static inline unsigned
 ffsw(machine_word_t v)
 {
-       BUILD_BUG_ON(WORDSIZE != 4 && WORDSIZE != 8);
+       STATIC_ASSERT(WORDSIZE == 4 || WORDSIZE == 8);
        if (WORDSIZE == 4)
                return ffs32(v);
        else
                return ffs64(v);
 }
 
+/* Round up to nearest power of 2  */
+
+static inline size_t
+roundup_pow_of_2(size_t n)
+{
+       if (n <= 1)
+               return 1;
+       return (size_t)1 << (1 + flsw(n - 1));
+}
+
 #endif /* _WIMLIB_BITOPS_H */