X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=include%2Fwimlib%2Fcompiler.h;h=6bce5d0152e11742905461df5d1b6fcc1b71411d;hp=102deb73d2a1a4a72aa90c58b6d1128f21cd75df;hb=8618172276fae088f311923a61bbf26c3d4d8941;hpb=d07109b91683a701a76a5941b675b67b46227f91 diff --git a/include/wimlib/compiler.h b/include/wimlib/compiler.h index 102deb73..6bce5d01 100644 --- a/include/wimlib/compiler.h +++ b/include/wimlib/compiler.h @@ -3,8 +3,21 @@ * * 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 + * + * 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 . */ #ifndef _WIMLIB_COMPILER_H @@ -84,8 +97,15 @@ * returns will not alias any pointer previously in use by the program. */ #define _malloc_attribute __attribute__((malloc)) -/* TODO: _format_attribute is currently ignored. */ -#define _format_attribute(type, format_str, format_start) +/* Hint that the annotated function takes a printf()-like format string and + * arguments. This is currently disabled on Windows because MinGW does not + * support this attribute on functions taking wide-character strings. */ +#ifdef __WIN32__ +# define _format_attribute(type, format_str, format_start) +#else +# define _format_attribute(type, format_str, format_start) \ + __attribute__((format(type, format_str, format_start))) +#endif /* Hint that the annotated function is intentionally not used. This might be * the case if the function contains only static assertions. */ @@ -107,12 +127,12 @@ #endif #define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN) -#if defined(__x86_64__) || defined(__i386__) -# define UNALIGNED_ACCESS_SPEED 3 -#elif defined(__ARM_FEATURE_UNALIGNED) && (__ARM_FEATURE_UNALIGNED == 1) -# define UNALIGNED_ACCESS_SPEED 2 +/* UNALIGNED_ACCESS_IS_FAST should be defined to 1 if unaligned memory accesses + * can be performed efficiently on the target platform. */ +#if defined(__x86_64__) || defined(__i386__) || defined(__ARM_FEATURE_UNALIGNED) +# define UNALIGNED_ACCESS_IS_FAST 1 #else -# define UNALIGNED_ACCESS_SPEED 0 +# define UNALIGNED_ACCESS_IS_FAST 0 #endif /* Get the type of the specified expression. */ @@ -151,10 +171,10 @@ #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__ @@ -172,6 +192,10 @@ # 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. */