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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 62 - (show annotations) (download)
Tue Sep 7 11:08:22 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 5786 byte(s)
Auto Commited Import of: pcsx2-0.9.7-r3738-debug in ./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 __PCSX2TYPES_H__
17 #define __PCSX2TYPES_H__
18
19 // --------------------------------------------------------------------------------------
20 // Forward declarations
21 // --------------------------------------------------------------------------------------
22 // Forward declarations for wxWidgets-supporting features.
23 // If you aren't linking against wxWidgets libraries, then functions that
24 // depend on these types will not be usable (they will yield linker errors).
25
26 #ifdef __cplusplus
27 class wxString;
28 class FastFormatAscii;
29 class FastFormatUnicode;
30 #endif
31
32
33 // --------------------------------------------------------------------------------------
34 // Basic Atomic Types
35 // --------------------------------------------------------------------------------------
36
37 #if defined(_MSC_VER)
38
39 typedef __int8 s8;
40 typedef __int16 s16;
41 typedef __int32 s32;
42 typedef __int64 s64;
43
44 typedef unsigned __int8 u8;
45 typedef unsigned __int16 u16;
46 typedef unsigned __int32 u32;
47 typedef unsigned __int64 u64;
48
49 typedef unsigned int uint;
50
51 #else // _MSC_VER*/
52
53 #ifdef __LINUX__
54
55 #ifdef HAVE_STDINT_H
56 #include "stdint.h"
57
58 // note: char and int8_t are not interchangable types on gcc, because int8_t apparently
59 // maps to 'signed char' which (due to 1's compliment or something) is its own unique
60 // type. This creates cross-compiler inconsistencies, in addition to being entirely
61 // unexpected behavior to any sane programmer, so we typecast s8 to char instead. :)
62
63 //typedef int8_t s8;
64 typedef char s8;
65 typedef int16_t s16;
66 typedef int32_t s32;
67 typedef int64_t s64;
68
69 typedef uint8_t u8;
70 typedef uint16_t u16;
71 typedef uint32_t u32;
72 typedef uint64_t u64;
73
74 typedef uintptr_t uptr;
75 typedef intptr_t sptr;
76
77 #else // HAVE_STDINT_H
78
79 typedef char s8;
80 typedef short s16;
81 typedef int s32;
82 typedef long long s64;
83
84 typedef unsigned char u8;
85 typedef unsigned short u16;
86 typedef unsigned int u32;
87 typedef unsigned long long u64;
88
89 #endif // HAVE_STDINT_H
90
91 typedef unsigned int uint;
92
93 #define LONG long
94 typedef union _LARGE_INTEGER
95 {
96 long long QuadPart;
97 } LARGE_INTEGER;
98
99 #endif // __LINUX__
100 #endif //_MSC_VER
101
102 #if !defined(__LINUX__) || !defined(HAVE_STDINT_H)
103 #if defined(__x86_64__)
104 typedef u64 uptr;
105 typedef s64 sptr;
106 #else
107 typedef u32 uptr;
108 typedef s32 sptr;
109 #endif
110 #endif
111
112 // --------------------------------------------------------------------------------------
113 // u128 / s128 - A rough-and-ready cross platform 128-bit datatype, Non-SSE style.
114 // --------------------------------------------------------------------------------------
115 // Note: These structs don't provide any additional constructors because C++ doesn't allow
116 // the use of datatypes with constructors in unions (and since unions aren't the primary
117 // uses of these types, that means we can't have constructors). Embedded functions for
118 // performing explicit conversion from 64 and 32 bit values are provided instead.
119 //
120 #ifdef __cplusplus
121 union u128
122 {
123 struct
124 {
125 u64 lo;
126 u64 hi;
127 };
128
129 u64 _u64[2];
130 u32 _u32[4];
131 u16 _u16[8];
132 u8 _u8[16];
133
134 // Explicit conversion from u64. Zero-extends the source through 128 bits.
135 static u128 From64( u64 src )
136 {
137 u128 retval;
138 retval.lo = src;
139 retval.hi = 0;
140 return retval;
141 }
142
143 // Explicit conversion from u32. Zero-extends the source through 128 bits.
144 static u128 From32( u32 src )
145 {
146 u128 retval;
147 retval._u32[0] = src;
148 retval._u32[1] = 0;
149 retval.hi = 0;
150 return retval;
151 }
152
153 operator u32() const { return _u32[0]; }
154 operator u16() const { return _u16[0]; }
155 operator u8() const { return _u8[0]; }
156
157 bool operator==( const u128& right ) const
158 {
159 return (lo == right.lo) && (hi == right.hi);
160 }
161
162 bool operator!=( const u128& right ) const
163 {
164 return (lo != right.lo) && (hi != right.hi);
165 }
166
167 // In order for the following ToString() and WriteTo methods to be available, you must
168 // be linking to both wxWidgets and the pxWidgets extension library. If you are not
169 // using them, then you will need to provide your own implementations of these methods.
170 wxString ToString() const;
171 wxString ToString64() const;
172 wxString ToString8() const;
173
174 void WriteTo( FastFormatAscii& dest ) const;
175 void WriteTo8( FastFormatAscii& dest ) const;
176 void WriteTo64( FastFormatAscii& dest ) const;
177 };
178
179 struct s128
180 {
181 s64 lo;
182 s64 hi;
183
184 // explicit conversion from s64, with sign extension.
185 static s128 From64( s64 src )
186 {
187 s128 retval = { src, (src < 0) ? -1 : 0 };
188 return retval;
189 }
190
191 // explicit conversion from s32, with sign extension.
192 static s128 From64( s32 src )
193 {
194 s128 retval = { src, (src < 0) ? -1 : 0 };
195 return retval;
196 }
197
198 operator u32() const { return (s32)lo; }
199 operator u16() const { return (s16)lo; }
200 operator u8() const { return (s8)lo; }
201
202 bool operator==( const s128& right ) const
203 {
204 return (lo == right.lo) && (hi == right.hi);
205 }
206
207 bool operator!=( const s128& right ) const
208 {
209 return (lo != right.lo) && (hi != right.hi);
210 }
211 };
212
213 #else
214
215 typedef union _u128_t
216 {
217 struct
218 {
219 u64 lo;
220 u64 hi;
221 };
222
223 u64 _u64[2];
224 u32 _u32[4];
225 u16 _u16[8];
226 u8 _u8[16];
227 } u128;
228
229 typedef union _s128_t
230 {
231 u64 lo;
232 s64 hi;
233 } s128;
234
235 #endif
236
237 #endif

  ViewVC Help
Powered by ViewVC 1.1.22