*
* Compiler-specific definitions. Currently, only GCC and clang are supported.
*
- * The author dedicates this file to the public domain.
- * You can do whatever you want with this file.
+ * The following copying information applies to this specific source code file:
+ *
+ * Written in 2013-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_COMPILER_H
# define WIMLIBAPI __attribute__((visibility("default")))
#endif
-/* Declare that the annotated function should be inlined. Currently, we force
- * the compiler to honor this because we use 'inline' in highly tuned code, e.g.
- * compression codecs. */
-#define inline inline __attribute__((always_inline))
+/* Declare that the annotated function should always be inlined. This might be
+ * desirable in highly tuned code, e.g. compression codecs. */
+#define forceinline inline __attribute__((always_inline))
/* Declare that the annotated function should *not* be inlined. */
#define noinline __attribute__((noinline))
#endif
/* (Optional) Find Last Set bit and Find First Set bit macros. */
-#define compiler_fls32(n) (31 - __builtin_clz(n))
-#define compiler_fls64(n) (63 - __builtin_clzll(n))
-#define compiler_ffs32(n) __builtin_ctz(n)
-#define compiler_ffs64(n) __builtin_ctzll(n)
+#define compiler_bsr32(n) (31 - __builtin_clz(n))
+#define compiler_bsr64(n) (63 - __builtin_clzll(n))
+#define compiler_bsf32(n) __builtin_ctz(n)
+#define compiler_bsf64(n) __builtin_ctzll(n)
/* Optional definitions for checking with 'sparse'. */
#ifdef __CHECKER__
#endif
/* STATIC_ASSERT() - verify the truth of an expression at compilation time. */
-#if __STDC_VERSION__ >= 201112L
+#ifdef __CHECKER__
+# define STATIC_ASSERT(expr)
+#elif __STDC_VERSION__ >= 201112L
# define STATIC_ASSERT(expr) _Static_assert((expr), "")
#else
# define STATIC_ASSERT(expr) ((void)sizeof(char[1 - 2 * !(expr)]))
#endif
+/* STATIC_ASSERT_ZERO() - verify the truth of an expression at compilation time
+ * and also produce a result of value '0' to be used in constant expressions */
+#define STATIC_ASSERT_ZERO(expr) ((int)sizeof(char[-!(expr)]))
+
#define CONCAT_IMPL(s1, s2) s1##s2
/* CONCAT() - concatenate two tokens at preprocessing time. */