X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=include%2Fwimlib%2Fcompiler.h;h=4bd92d78dee0bffcade4ff5b8247ef7f63094737;hb=a92076249aa233d18ecc378062e654729e27c0d8;hp=3134b119b9c447e6d0d48ebafb76ab1ac11cc91e;hpb=e8c3ca2d1d0cac3d64985b45a9f654d2029a7518;p=wimlib diff --git a/include/wimlib/compiler.h b/include/wimlib/compiler.h index 3134b119..4bd92d78 100644 --- a/include/wimlib/compiler.h +++ b/include/wimlib/compiler.h @@ -1,27 +1,95 @@ +/* + * compiler.h + * + * The author dedicates this file to the public domain. + * You can do whatever you want with this file. + */ + #ifndef _WIMLIB_COMPILER_H #define _WIMLIB_COMPILER_H #ifdef __GNUC__ -# if defined(__CYGWIN__) || defined(__WIN32__) -# define WIMLIBAPI __declspec(dllexport) -# else -# define WIMLIBAPI __attribute__((visibility("default"))) -# endif -# define ALWAYS_INLINE inline __attribute__((always_inline)) -# define PACKED __attribute__((packed)) -# define FORMAT(type, format_str, args_start) \ - /*__attribute__((format(type, format_str, args_start))) */ -# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -# define COLD __attribute__((cold)) -# else -# define COLD -# endif +# include "wimlib/compiler-gcc.h" #else -# define WIMLIBAPI -# define ALWAYS_INLINE inline -# define FORMAT(type, format_str, args_start) -# define COLD -# define PACKED -#endif /* __GNUC__ */ +# error "Unrecognized compiler. Please add a header file for your compiler." +#endif + +#ifndef WIMLIBAPI +# define WIMLIBAPI +#endif + +#ifndef _packed_attribute +# error "missing required definition of _packed_attribute" +#endif + +#ifndef _aligned_attribute +# error "missing required definition of _aligned_attribute" +#endif + +#ifndef _may_alias_attribute +# error "missing required definition of _may_alias_attribute" +#endif + +#ifndef likely +# define likely(expr) (expr) +#endif + +#ifndef unlikely +# define unlikely(expr) (expr) +#endif + +#ifndef prefetch +# define prefetch(addr) +#endif + +#ifndef _cold_attribute +# define _cold_attribute +#endif + +#ifndef _malloc_attribute +# define _malloc_attribute +#endif + +#ifndef _format_attribute +# define _format_attribute(type, format_str, format_start) +#endif + +#ifndef noinline +# define noinline +#endif + +#ifndef CPU_IS_BIG_ENDIAN +# error "missing required endianness definition" +#endif + +#define CPU_IS_LITTLE_ENDIAN (!CPU_IS_BIG_ENDIAN) + +#ifndef UNALIGNED_ACCESS_SPEED +# define UNALIGNED_ACCESS_SPEED 0 +#endif + +#define UNALIGNED_ACCESS_IS_ALLOWED (UNALIGNED_ACCESS_SPEED >= 1) +#define UNALIGNED_ACCESS_IS_FAST (UNALIGNED_ACCESS_SPEED >= 2) +#define UNALIGNED_ACCESS_IS_VERY_FAST (UNALIGNED_ACCESS_SPEED >= 3) + +#ifndef typeof +# error "missing required definition of typeof" +#endif + +#if !defined(min) || !defined(max) || !defined(swap) +# error "missing required definitions of min(), max(), and swap() macros" +#endif + +#ifdef __CHECKER__ +# define _bitwise_attr __attribute__((bitwise)) +# define _force_attr __attribute__((force)) +#else +# define _bitwise_attr +# define _force_attr +#endif + +#ifndef BUILD_BUG_ON +# define BUILD_BUG_ON(expr) ((void)sizeof(char[1 - 2*!!(expr)])) +#endif #endif /* _WIMLIB_COMPILER_H */