/[pcsx2_0.9.7]/trunk/common/include/Pcsx2Defs.h
ViewVC logotype

Contents of /trunk/common/include/Pcsx2Defs.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 10619 byte(s)
exported r3113 from ./upstream/trunk
1 /* PCSX2 - PS2 Emulator for PCs
2 * Copyright (C) 2002-2010 PCSX2 Dev Team
3 *
4 * PCSX2 is free software: you can redistribute it and/or modify it under the terms
5 * of the GNU Lesser General Public License as published by the Free Software Found-
6 * ation, either version 3 of the License, or (at your option) any later version.
7 *
8 * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10 * PURPOSE. See the GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License along with PCSX2.
13 * If not, see <http://www.gnu.org/licenses/>.
14 */
15
16 #ifndef __PCSX2DEFS_H__
17 #define __PCSX2DEFS_H__
18
19 // Indicate that this is the wx port to the plugins.
20 #define WX_PCSX2
21
22 // some distributions are lower case
23 #if defined (__linux__) || defined(__CYGWIN__)
24 #if !defined(__LINUX__)
25 # define __LINUX__
26 #endif
27 #endif
28
29 #include "Pcsx2Types.h"
30
31 #ifdef _MSC_VER
32 # include <intrin.h>
33 #else
34 # include <intrin_x86.h>
35 #endif
36
37 // Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air)
38 // Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
39 // that as well. >_<
40 #ifndef ArraySize
41 # define ArraySize(x) (sizeof(x)/sizeof((x)[0]))
42 #endif
43
44 //////////////////////////////////////////////////////////////////////////////////////////
45 // __releaseinline -- a forceinline macro that is enabled for RELEASE/PUBLIC builds ONLY.
46 // This is useful because forceinline can make certain types of debugging problematic since
47 // functions that look like they should be called won't breakpoint since their code is
48 // inlined, and it can make stack traces confusing or near useless.
49 //
50 // Use __releaseinline for things which are generally large functions where trace debugging
51 // from Devel builds is likely useful; but which should be inlined in an optimized Release
52 // environment.
53 //
54 #ifdef PCSX2_DEVBUILD
55 # define __releaseinline
56 #else
57 # define __releaseinline __forceinline
58 #endif
59
60 //////////////////////////////////////////////////////////////////////////////////////////
61 // jASSUME - give hints to the optimizer
62 // This is primarily useful for the default case switch optimizer, which enables VC to
63 // generate more compact switches.
64 //
65 // Note: When using the PCSX2 Utilities library, this is deprecated. Use pxAssert instead,
66 // which itself optimizes to an __assume() hint in release mode builds.
67 //
68 #ifndef jASSUME
69 # ifdef NDEBUG
70 # define jBREAKPOINT() ((void) 0)
71 # ifdef _MSC_VER
72 # define jASSUME(exp) (__assume(exp))
73 # else
74 # define jASSUME(exp) ((void) sizeof(exp))
75 # endif
76 # else
77 # define jBREAKPOINT() __debugbreak();
78 # ifdef wxASSERT
79 # define jASSUME(exp) wxASSERT(exp)
80 # else
81 # define jASSUME(exp) do { if(exp) ; else jBREAKPOINT(); } while(0);
82 # endif
83 # endif
84 #endif
85
86 //////////////////////////////////////////////////////////////////////////////////////////
87 // compile-time assertion; usable at static variable define level.
88 // (typically used to confirm the correct sizeof() for struct types where size
89 // restaints must be enforced).
90 //
91 #ifndef C_ASSERT
92 # define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
93 #endif
94
95 //////////////////////////////////////////////////////////////////////////////////////////
96 // Dev / Debug conditionals - Consts for using if() statements instead of uglier #ifdef.
97 //
98 // Note: Using if() optimizes nicely in Devel and Release builds, but will generate extra
99 // code overhead in debug builds (since debug neither inlines, nor optimizes out const-
100 // level conditionals). Normally not a concern, but if you stick if( IsDevbuild ) in
101 // some tight loops it will likely make debug builds unusably slow.
102 //
103 #ifdef __cplusplus
104 # ifdef PCSX2_DEVBUILD
105 static const bool IsDevBuild = true;
106 # else
107 static const bool IsDevBuild = false;
108 # endif
109
110 # ifdef PCSX2_DEBUG
111 static const bool IsDebugBuild = true;
112 # else
113 static const bool IsDebugBuild = false;
114 # endif
115
116 #else
117
118 # ifdef PCSX2_DEVBUILD
119 static const u8 IsDevBuild = 1;
120 # else
121 static const u8 IsDevBuild = 0;
122 # endif
123
124 # ifdef PCSX2_DEBUG
125 static const u8 IsDebugBuild = 1;
126 # else
127 static const u8 IsDebugBuild = 0;
128 # endif
129 #endif
130
131 #ifdef PCSX2_DEBUG
132 # define pxDebugCode(code) code
133 #else
134 # define pxDebugCode(code)
135 #endif
136
137
138 //////////////////////////////////////////////////////////////////////////////////////////
139 // __aligned / __aligned16 / __pagealigned
140 //
141 // GCC Warning! The GCC linker (LD) typically fails to assure alignment of class members.
142 // If you want alignment to be assured, the variable must either be a member of a struct
143 // or a static global.
144 //
145 // __pagealigned is equivalent to __aligned(0x1000), and is used to align a dynarec code
146 // buffer to a page boundary (allows the use of execution-enabled mprotect).
147 //
148 // General Performance Warning: Any function that specifies alignment on a local (stack)
149 // variable will have to align the stack frame on enter, and restore it on exit (adds
150 // overhead). Furthermore, compilers cannot inline functions that have aligned local
151 // vars. So use local var alignment with much caution.
152 //
153
154 // Defines the memory page size for the target platform at compilation. All supported platforms
155 // (which means Intel only right now) have a 4k granularity.
156 #define PCSX2_PAGESIZE 0x1000
157 static const int __pagesize = PCSX2_PAGESIZE;
158
159 //////////////////////////////////////////////////////////////////////////////////////////
160 // Structure Packing (__packed)
161 //
162 // Current Method:
163 // Use a combination of embedded compiler-specific #pragma mess in conjunction with a
164 // __packed macro. The former appeases the MSVC gods, the latter appeases the GCC gods.
165 // The end result looks something like this:
166 //
167 // #ifdef _MSC_VER
168 // # pragma pack(1)
169 // #endif
170 //
171 // struct SomeKindaFail {
172 // u8 neat;
173 // u32 unaligned32;
174 // } __packed;
175 //
176 // MSVC 2008 and better support __pragma, however there's no way to support that in
177 // a way that's backwards compatible to VS 2005, without still including the old-style
178 // #pragma mess. So there's really not much point (yet) in using it. I've included macros
179 // that utilize __pragma (commented out below) which can be deployed at a time when we
180 // are ok with the idea of completely breaking backwards compat with VC2005/prior.
181 //
182
183 // --------------------------------------------------------------------------------------
184 // Microsoft Visual Studio
185 // --------------------------------------------------------------------------------------
186 #ifdef _MSC_VER
187
188 // Using these breaks compat with VC2005; so we're not using it yet.
189 //# define __pack_begin __pragma(pack(1))
190 //# define __pack_end __pragma(pack())
191
192 // This is the 2005/earlier compatible packing define, which must be used in conjunction
193 // with #ifdef _MSC_VER/#pragma pack() directives (ugly).
194 # define __packed
195
196 # define __aligned(alig) __declspec(align(alig))
197 # define __aligned16 __declspec(align(16))
198 # define __pagealigned __declspec(align(PCSX2_PAGESIZE))
199
200 // Deprecated; use __align instead.
201 # define PCSX2_ALIGNED(alig,x) __declspec(align(alig)) x
202 # define PCSX2_ALIGNED_EXTERN(alig,x) extern __declspec(align(alig)) x
203 # define PCSX2_ALIGNED16(x) __declspec(align(16)) x
204 # define PCSX2_ALIGNED16_EXTERN(x) extern __declspec(align(16)) x
205
206 # define __naked __declspec(naked)
207 # define __noinline __declspec(noinline)
208 # define __threadlocal __declspec(thread)
209
210 // Don't know if there are Visual C++ equivalents of these.
211 # define __hot
212 # define __cold
213 # define likely(x) (!!(x))
214 # define unlikely(x) (!!(x))
215
216 # define CALLBACK __stdcall
217
218 #else
219
220 // --------------------------------------------------------------------------------------
221 // GCC / Intel Compilers Section
222 // --------------------------------------------------------------------------------------
223
224 # define __packed __attribute__((packed))
225
226 # define __aligned(alig) __attribute__((aligned(alig)))
227 # define __aligned16 __attribute__((aligned(16)))
228 # define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE)))
229 // Deprecated; use __align instead.
230 # define PCSX2_ALIGNED(alig,x) x __attribute((aligned(alig)))
231 # define PCSX2_ALIGNED16(x) x __attribute((aligned(16)))
232 # define PCSX2_ALIGNED_EXTERN(alig,x) extern x __attribute((aligned(alig)))
233 # define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16)))
234
235 # define __naked // GCC lacks the naked specifier
236 # define __assume(cond) ((void)0) // GCC has no equivalent for __assume
237 # define CALLBACK __attribute__((stdcall))
238
239 // Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress
240 // warnings when a static inlined function isn't used in the scope of a single file (which
241 // happens *by design* like all the friggen time >_<)
242
243 # define __fastcall __attribute__((fastcall))
244 # define _inline __inline__ __attribute__((unused))
245 # ifdef NDEBUG
246 # define __forceinline __attribute__((always_inline,unused))
247 # else
248 # define __forceinline __attribute__((unused))
249 # endif
250 # define __noinline __attribute__((noinline))
251 # define __hot __attribute__((hot))
252 # define __cold __attribute__((cold))
253 # define __threadlocal __thread
254 # define likely(x) __builtin_expect(!!(x), 1)
255 # define unlikely(x) __builtin_expect(!!(x), 0)
256 #endif
257
258 // --------------------------------------------------------------------------------------
259 // GNU C/C++ Specific Defines
260 // --------------------------------------------------------------------------------------
261 #ifdef __GNUC__
262
263 // GCC 4.4.0 is a bit nutty, as compilers go. it gets a define to itself.
264 # define GCC_VERSION ( __GNUC__ * 10000 \
265 + __GNUC_MINOR__ * 100 \
266 + __GNUC_PATCHLEVEL__)
267
268 // Test for GCC > 4.4.0; Should be adjusted when new versions come out
269 # if GCC_VERSION >= 40400
270 # define THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
271 # define __nooptimization __attribute__((optimize("O0")))
272 # endif
273
274 // This theoretically unoptimizes. Not having much luck so far.
275 /*
276 # ifdef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
277 # pragma GCC optimize ("O0")
278 # endif
279
280 # ifdef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
281 # pragma GCC reset_options
282 # endif
283 */
284
285 #endif // end GCC-specific section.
286
287 #ifndef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
288 # define __nooptimization
289 #endif
290
291
292 #endif

  ViewVC Help
Powered by ViewVC 1.1.22