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

  ViewVC Help
Powered by ViewVC 1.1.22