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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 401 - (hide annotations) (download)
Fri Feb 25 17:31:09 2011 UTC (9 years, 5 months ago) by william
File MIME type: text/plain
File size: 11414 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4358 local: v0.9.7.313-latest) in ./trunk
1 william 31 /* 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 william 401 extern "C" unsigned __int64 __xgetbv(int);
34 william 31 #else
35     # include <intrin_x86.h>
36     #endif
37    
38     // Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air)
39     // Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with
40     // that as well. >_<
41     #ifndef ArraySize
42     # define ArraySize(x) (sizeof(x)/sizeof((x)[0]))
43     #endif
44    
45 william 62 // --------------------------------------------------------------------------------------
46     // jASSUME - give hints to the optimizer [obsolete, use pxAssume() instead]
47     // --------------------------------------------------------------------------------------
48 william 31 // This is primarily useful for the default case switch optimizer, which enables VC to
49     // generate more compact switches.
50     //
51     // Note: When using the PCSX2 Utilities library, this is deprecated. Use pxAssert instead,
52     // which itself optimizes to an __assume() hint in release mode builds.
53     //
54     #ifndef jASSUME
55     # ifdef NDEBUG
56     # define jBREAKPOINT() ((void) 0)
57     # ifdef _MSC_VER
58     # define jASSUME(exp) (__assume(exp))
59     # else
60     # define jASSUME(exp) ((void) sizeof(exp))
61     # endif
62     # else
63     # define jBREAKPOINT() __debugbreak();
64     # ifdef wxASSERT
65     # define jASSUME(exp) wxASSERT(exp)
66     # else
67     # define jASSUME(exp) do { if(exp) ; else jBREAKPOINT(); } while(0);
68     # endif
69     # endif
70     #endif
71    
72 william 62 // --------------------------------------------------------------------------------------
73     // C_ASSERT
74     // --------------------------------------------------------------------------------------
75 william 31 // compile-time assertion; usable at static variable define level.
76     // (typically used to confirm the correct sizeof() for struct types where size
77     // restaints must be enforced).
78     //
79     #ifndef C_ASSERT
80     # define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
81     #endif
82    
83 william 62 // --------------------------------------------------------------------------------------
84 william 31 // Dev / Debug conditionals - Consts for using if() statements instead of uglier #ifdef.
85 william 62 // --------------------------------------------------------------------------------------
86 william 31 // Note: Using if() optimizes nicely in Devel and Release builds, but will generate extra
87     // code overhead in debug builds (since debug neither inlines, nor optimizes out const-
88     // level conditionals). Normally not a concern, but if you stick if( IsDevbuild ) in
89     // some tight loops it will likely make debug builds unusably slow.
90     //
91     #ifdef __cplusplus
92     # ifdef PCSX2_DEVBUILD
93     static const bool IsDevBuild = true;
94     # else
95     static const bool IsDevBuild = false;
96     # endif
97    
98     # ifdef PCSX2_DEBUG
99     static const bool IsDebugBuild = true;
100     # else
101     static const bool IsDebugBuild = false;
102     # endif
103    
104     #else
105    
106     # ifdef PCSX2_DEVBUILD
107     static const u8 IsDevBuild = 1;
108     # else
109     static const u8 IsDevBuild = 0;
110     # endif
111    
112     # ifdef PCSX2_DEBUG
113     static const u8 IsDebugBuild = 1;
114     # else
115     static const u8 IsDebugBuild = 0;
116     # endif
117     #endif
118    
119     #ifdef PCSX2_DEBUG
120     # define pxDebugCode(code) code
121     #else
122     # define pxDebugCode(code)
123     #endif
124    
125 william 62 #ifdef PCSX2_DEVBUILD
126     # define pxDevelCode(code) code
127     #else
128     # define pxDevelCode(code)
129     #endif
130 william 31
131 william 62 #if !defined(PCSX2_DEBUG) && !defined(PCSX2_DEVEL)
132     # define pxReleaseCode(code)
133     #else
134     # define pxReleaseCode(code) code
135     #endif
136    
137     // --------------------------------------------------------------------------------------
138 william 31 // __aligned / __aligned16 / __pagealigned
139 william 62 // --------------------------------------------------------------------------------------
140 william 31 // GCC Warning! The GCC linker (LD) typically fails to assure alignment of class members.
141     // If you want alignment to be assured, the variable must either be a member of a struct
142     // or a static global.
143     //
144     // __pagealigned is equivalent to __aligned(0x1000), and is used to align a dynarec code
145     // buffer to a page boundary (allows the use of execution-enabled mprotect).
146     //
147     // General Performance Warning: Any function that specifies alignment on a local (stack)
148     // variable will have to align the stack frame on enter, and restore it on exit (adds
149     // overhead). Furthermore, compilers cannot inline functions that have aligned local
150     // vars. So use local var alignment with much caution.
151     //
152    
153     // Defines the memory page size for the target platform at compilation. All supported platforms
154     // (which means Intel only right now) have a 4k granularity.
155     #define PCSX2_PAGESIZE 0x1000
156     static const int __pagesize = PCSX2_PAGESIZE;
157    
158 william 62 // --------------------------------------------------------------------------------------
159 william 31 // Structure Packing (__packed)
160 william 62 // --------------------------------------------------------------------------------------
161 william 31 // Current Method:
162     // Use a combination of embedded compiler-specific #pragma mess in conjunction with a
163     // __packed macro. The former appeases the MSVC gods, the latter appeases the GCC gods.
164     // The end result looks something like this:
165     //
166     // #ifdef _MSC_VER
167     // # pragma pack(1)
168     // #endif
169     //
170     // struct SomeKindaFail {
171     // u8 neat;
172     // u32 unaligned32;
173     // } __packed;
174     //
175     // MSVC 2008 and better support __pragma, however there's no way to support that in
176     // a way that's backwards compatible to VS 2005, without still including the old-style
177     // #pragma mess. So there's really not much point (yet) in using it. I've included macros
178     // that utilize __pragma (commented out below) which can be deployed at a time when we
179     // are ok with the idea of completely breaking backwards compat with VC2005/prior.
180     //
181    
182     // --------------------------------------------------------------------------------------
183     // Microsoft Visual Studio
184     // --------------------------------------------------------------------------------------
185     #ifdef _MSC_VER
186    
187     // Using these breaks compat with VC2005; so we're not using it yet.
188     //# define __pack_begin __pragma(pack(1))
189     //# define __pack_end __pragma(pack())
190    
191     // This is the 2005/earlier compatible packing define, which must be used in conjunction
192     // with #ifdef _MSC_VER/#pragma pack() directives (ugly).
193     # define __packed
194    
195     # define __aligned(alig) __declspec(align(alig))
196     # define __aligned16 __declspec(align(16))
197 william 401 # define __aligned32 __declspec(align(32))
198 william 31 # 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 william 401 # define __aligned32 __attribute__((aligned(32)))
229 william 31 # define __pagealigned __attribute__((aligned(PCSX2_PAGESIZE)))
230     // Deprecated; use __align instead.
231     # define PCSX2_ALIGNED(alig,x) x __attribute((aligned(alig)))
232     # define PCSX2_ALIGNED16(x) x __attribute((aligned(16)))
233     # define PCSX2_ALIGNED_EXTERN(alig,x) extern x __attribute((aligned(alig)))
234     # define PCSX2_ALIGNED16_EXTERN(x) extern x __attribute((aligned(16)))
235    
236     # define __naked // GCC lacks the naked specifier
237     # define __assume(cond) ((void)0) // GCC has no equivalent for __assume
238     # define CALLBACK __attribute__((stdcall))
239    
240     // Inlining note: GCC needs ((unused)) attributes defined on inlined functions to suppress
241     // warnings when a static inlined function isn't used in the scope of a single file (which
242     // happens *by design* like all the friggen time >_<)
243    
244     # define __fastcall __attribute__((fastcall))
245     # define _inline __inline__ __attribute__((unused))
246     # ifdef NDEBUG
247     # define __forceinline __attribute__((always_inline,unused))
248     # else
249     # define __forceinline __attribute__((unused))
250     # endif
251     # define __noinline __attribute__((noinline))
252     # define __hot __attribute__((hot))
253     # define __cold __attribute__((cold))
254     # define __threadlocal __thread
255     # define likely(x) __builtin_expect(!!(x), 1)
256     # define unlikely(x) __builtin_expect(!!(x), 0)
257     #endif
258    
259     // --------------------------------------------------------------------------------------
260     // GNU C/C++ Specific Defines
261     // --------------------------------------------------------------------------------------
262     #ifdef __GNUC__
263    
264     // GCC 4.4.0 is a bit nutty, as compilers go. it gets a define to itself.
265     # define GCC_VERSION ( __GNUC__ * 10000 \
266     + __GNUC_MINOR__ * 100 \
267     + __GNUC_PATCHLEVEL__)
268    
269     // Test for GCC > 4.4.0; Should be adjusted when new versions come out
270     # if GCC_VERSION >= 40400
271     # define THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
272     # define __nooptimization __attribute__((optimize("O0")))
273     # endif
274    
275     // This theoretically unoptimizes. Not having much luck so far.
276     /*
277     # ifdef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
278     # pragma GCC optimize ("O0")
279     # endif
280    
281     # ifdef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
282     # pragma GCC reset_options
283     # endif
284     */
285    
286     #endif // end GCC-specific section.
287    
288     #ifndef THE_UNBEARABLE_LIGHTNESS_OF_BEING_GCC_4_4_0
289 william 62 # define __nooptimization // Pretty sure this is obsolete now, since we fixed __asm contraints and stuff. --air
290 william 31 #endif
291    
292 william 62 // --------------------------------------------------------------------------------------
293     // __releaseinline / __ri -- a forceinline macro that is enabled for RELEASE/PUBLIC builds ONLY.
294     // --------------------------------------------------------------------------------------
295     // This is useful because forceinline can make certain types of debugging problematic since
296     // functions that look like they should be called won't breakpoint since their code is
297     // inlined, and it can make stack traces confusing or near useless.
298     //
299     // Use __releaseinline for things which are generally large functions where trace debugging
300     // from Devel builds is likely useful; but which should be inlined in an optimized Release
301     // environment.
302     //
303     #ifdef PCSX2_DEVBUILD
304     # define __releaseinline
305     #else
306     # define __releaseinline __forceinline
307     #endif
308 william 31
309 william 62 #define __ri __releaseinline
310     #define __fi __forceinline
311    
312    
313 william 31 #endif

  ViewVC Help
Powered by ViewVC 1.1.22