--- deliantra/server/include/compiler.h 2009/11/07 18:30:05 1.1 +++ deliantra/server/include/compiler.h 2009/11/08 15:11:23 1.2 @@ -23,13 +23,15 @@ #ifndef COMPILER_H #define COMPILER_H -#if __GNUC__ >= 3 +#define GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) + +#if GCC_VERSION(3,0) # define attribute(attrlist) __attribute__(attrlist) #else # define attribute(attrlist) #endif -#if __GNUC__ >= 3 +#if GCC_VERSION(3,0) # define is_constant(c) __builtin_constant_p (c) # define expect(expr,value) __builtin_expect ((expr),(value)) # define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) @@ -41,15 +43,26 @@ # define noinline #endif -#if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) +#if !GCC_VERSION(4,4) # define decltype(x) typeof(x) #endif +#if GCC_VERSION(4,5) +# define unreachable() __builtin_unreachable () +#else + // this seems to work fine, but gcc always emits a warning for it :/ + static inline void unreachable () attribute ((noreturn)); + static inline void unreachable () { } +#endif + // put into ifs if you are very sure that the expression // is mostly true or mosty false. note that these return // booleans, not the expression. #define expect_false(expr) expect ((expr) ? 1 : 0, 0) #define expect_true(expr) expect ((expr) ? 1 : 0, 1) +// try to tell the compiler tat some condition is definitely true +#define assume(cond) do { if (!(cond)) unreachable (); } while (0) + #endif