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