123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- #ifndef MY_COMPILER_INCLUDED
- #define MY_COMPILER_INCLUDED
- #include <stddef.h> /* size_t */
- #if defined __GNUC__
- # define MY_GNUC_PREREQ(maj, min) \
- ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
- # define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__)
- #else
- # define MY_GNUC_PREREQ(maj, min) (0)
- #endif
- #ifdef HAVE_BUILTIN_EXPECT
- #if defined(__cplusplus)
- inline bool likely(bool expr)
- {
- return __builtin_expect(expr, true);
- }
- inline bool unlikely(bool expr)
- {
- return __builtin_expect(expr, false);
- }
- #else
- # define likely(x) __builtin_expect((x),1)
- # define unlikely(x) __builtin_expect((x),0)
- #endif
- #else
- #if defined(__cplusplus)
- inline bool likely(bool expr)
- {
- return expr;
- }
- inline bool unlikely(bool expr)
- {
- return expr;
- }
- #else
- # define likely(x) (x)
- # define unlikely(x) (x)
- #endif
- #endif
- #ifdef HAVE_BUILTIN_UNREACHABLE
- # define MY_ASSERT_UNREACHABLE() __builtin_unreachable()
- #else
- # define MY_ASSERT_UNREACHABLE() do { assert(0); } while (0)
- #endif
- #if defined __GNUC__ || defined __SUNPRO_C || defined __SUNPRO_CC
- # define MY_ALIGNOF(type) __alignof__(type)
- # define MY_ALIGNED(n) __attribute__((__aligned__((n))))
- #elif defined _MSC_VER
- # define MY_ALIGNOF(type) __alignof(type)
- # define MY_ALIGNED(n) __declspec(align(n))
- #else
- # define MY_ALIGNOF(type)
- # define MY_ALIGNED(size)
- #endif
- #if !defined(__cplusplus) && defined(_MSC_VER)
- # define inline __inline
- #endif
- #if defined(_MSC_VER)
- # define __func__ __FUNCTION__
- #endif
- #ifdef __cplusplus
- template<size_t alignment> struct my_alignment_imp;
- template<> struct MY_ALIGNED(1) my_alignment_imp<1> {};
- template<> struct MY_ALIGNED(2) my_alignment_imp<2> {};
- template<> struct MY_ALIGNED(4) my_alignment_imp<4> {};
- template<> struct MY_ALIGNED(8) my_alignment_imp<8> {};
- template<> struct MY_ALIGNED(16) my_alignment_imp<16> {};
- template <size_t size, size_t alignment>
- struct my_aligned_storage
- {
- union
- {
- char data[size];
- my_alignment_imp<alignment> align;
- };
- };
- #endif
- #ifndef MY_ATTRIBUTE
- #if defined(__GNUC__)
- # define MY_ATTRIBUTE(A) __attribute__(A)
- #else
- # define MY_ATTRIBUTE(A)
- #endif
- #endif
- #ifndef __has_attribute
- # define __has_attribute(x) 0
- #endif
- #if __has_attribute(no_sanitize_undefined)
- # define SUPPRESS_UBSAN __attribute__((no_sanitize_undefined))
- #else
- # define SUPPRESS_UBSAN
- #endif
- #endif
|