ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/include/compiler.h
(Generate patch)

Comparing deliantra/server/include/compiler.h (file contents):
Revision 1.1 by root, Sat Nov 7 18:30:05 2009 UTC vs.
Revision 1.2 by root, Sun Nov 8 15:11:23 2009 UTC

21 */ 21 */
22 22
23#ifndef COMPILER_H 23#ifndef COMPILER_H
24#define COMPILER_H 24#define COMPILER_H
25 25
26#if __GNUC__ >= 3 26#define GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
27
28#if GCC_VERSION(3,0)
27# define attribute(attrlist) __attribute__(attrlist) 29# define attribute(attrlist) __attribute__(attrlist)
28#else 30#else
29# define attribute(attrlist) 31# define attribute(attrlist)
30#endif 32#endif
31 33
32#if __GNUC__ >= 3 34#if GCC_VERSION(3,0)
33# define is_constant(c) __builtin_constant_p (c) 35# define is_constant(c) __builtin_constant_p (c)
34# define expect(expr,value) __builtin_expect ((expr),(value)) 36# define expect(expr,value) __builtin_expect ((expr),(value))
35# define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) 37# define prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
36# define noinline __attribute__((__noinline__)) 38# define noinline __attribute__((__noinline__))
37#else 39#else
39# define expect(expr,value) (expr) 41# define expect(expr,value) (expr)
40# define prefetch(addr,rw,locality) 42# define prefetch(addr,rw,locality)
41# define noinline 43# define noinline
42#endif 44#endif
43 45
44#if __GNUC__ < 4 || (__GNUC__ == 4 || __GNUC_MINOR__ < 4) 46#if !GCC_VERSION(4,4)
45# define decltype(x) typeof(x) 47# define decltype(x) typeof(x)
48#endif
49
50#if GCC_VERSION(4,5)
51# define unreachable() __builtin_unreachable ()
52#else
53 // this seems to work fine, but gcc always emits a warning for it :/
54 static inline void unreachable () attribute ((noreturn));
55 static inline void unreachable () { }
46#endif 56#endif
47 57
48// put into ifs if you are very sure that the expression 58// put into ifs if you are very sure that the expression
49// is mostly true or mosty false. note that these return 59// is mostly true or mosty false. note that these return
50// booleans, not the expression. 60// booleans, not the expression.
51#define expect_false(expr) expect ((expr) ? 1 : 0, 0) 61#define expect_false(expr) expect ((expr) ? 1 : 0, 0)
52#define expect_true(expr) expect ((expr) ? 1 : 0, 1) 62#define expect_true(expr) expect ((expr) ? 1 : 0, 1)
53 63
64// try to tell the compiler tat some condition is definitely true
65#define assume(cond) do { if (!(cond)) unreachable (); } while (0)
66
54#endif 67#endif
55 68

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines