1 |
root |
1.1 |
/* |
2 |
|
|
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
|
|
* |
4 |
root |
1.6 |
* Copyright (©) 2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
root |
1.1 |
* |
6 |
|
|
* Deliantra is free software: you can redistribute it and/or modify it under |
7 |
|
|
* the terms of the Affero GNU General Public License as published by the |
8 |
|
|
* Free Software Foundation, either version 3 of the License, or (at your |
9 |
|
|
* option) any later version. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the Affero GNU General Public License |
17 |
|
|
* and the GNU General Public License along with this program. If not, see |
18 |
|
|
* <http://www.gnu.org/licenses/>. |
19 |
|
|
* |
20 |
|
|
* The authors can be reached via e-mail to <support@deliantra.net> |
21 |
|
|
*/ |
22 |
|
|
|
23 |
|
|
#ifndef COMPILER_H |
24 |
|
|
#define COMPILER_H |
25 |
|
|
|
26 |
root |
1.2 |
#define GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
27 |
|
|
|
28 |
|
|
#if GCC_VERSION(3,0) |
29 |
root |
1.1 |
# define attribute(attrlist) __attribute__(attrlist) |
30 |
|
|
#else |
31 |
|
|
# define attribute(attrlist) |
32 |
|
|
#endif |
33 |
|
|
|
34 |
root |
1.2 |
#if GCC_VERSION(3,0) |
35 |
root |
1.1 |
# 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 |
root |
1.5 |
#if GCC_VERSION(4,5) |
47 |
|
|
# define decltype(x) __decltype(x) |
48 |
|
|
#elif GCC_VERSION(3,0) |
49 |
root |
1.1 |
# define decltype(x) typeof(x) |
50 |
|
|
#endif |
51 |
|
|
|
52 |
root |
1.7 |
#if GCC_VERSION(4,5) && 0 // the #else part is generating better code on 4.5 |
53 |
root |
1.2 |
# define unreachable() __builtin_unreachable () |
54 |
|
|
#else |
55 |
|
|
// this seems to work fine, but gcc always emits a warning for it :/ |
56 |
|
|
static inline void unreachable () attribute ((noreturn)); |
57 |
|
|
static inline void unreachable () { } |
58 |
|
|
#endif |
59 |
|
|
|
60 |
root |
1.1 |
// put into ifs if you are very sure that the expression |
61 |
|
|
// is mostly true or mosty false. note that these return |
62 |
|
|
// booleans, not the expression. |
63 |
|
|
#define expect_false(expr) expect ((expr) ? 1 : 0, 0) |
64 |
|
|
#define expect_true(expr) expect ((expr) ? 1 : 0, 1) |
65 |
|
|
|
66 |
root |
1.2 |
// try to tell the compiler tat some condition is definitely true |
67 |
|
|
#define assume(cond) do { if (!(cond)) unreachable (); } while (0) |
68 |
|
|
|
69 |
root |
1.1 |
#endif |
70 |
|
|
|