Debian Codegraph @

code/qcommon/q_platform.h

raw symbols SCIP
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #ifndef __Q_PLATFORM_H
24 #define __Q_PLATFORM_H
25
26 // this is for determining if we have an asm version of a C function
27 #define idx64 0
28
29 #ifdef Q3_VM
30
31 #define id386 0
32 #define idppc 0
33 #define idppc_altivec 0
34 #define idsparc 0
35
36 #else
37
38 #if (defined _M_IX86 || defined __i386__) && !defined(C_ONLY)
39 #define id386 1
40 #else
41 #define id386 0
42 #endif
43
44 #if (defined(powerc) || defined(powerpc) || defined(ppc) || \
45 defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
46 #define idppc 1
47 #if defined(__VEC__)
48 #define idppc_altivec 1
49 #ifdef __APPLE__ // Apple's GCC does this differently than the FSF.
50 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
51 (vector unsigned char) (a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
52 #else
53 #define VECCONST_UINT8(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
54 (vector unsigned char) {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p}
55 #endif
56 #else
57 #define idppc_altivec 0
58 #endif
59 #else
60 #define idppc 0
61 #define idppc_altivec 0
62 #endif
63
64 #if defined(__sparc__) && !defined(C_ONLY)
65 #define idsparc 1
66 #else
67 #define idsparc 0
68 #endif
69
70 #endif
71
72 // for windows fastcall option
73 #define QDECL
74 #define QCALL
75
76 //================================================================= WIN64/32 ===
77
78 #if defined(_WIN64) || defined(__WIN64__)
79
80 #undef QDECL
81 #define QDECL __cdecl
82
83 #undef QCALL
84 #define QCALL __stdcall
85
86 #if defined( _MSC_VER )
87 #define OS_STRING "win_msvc64"
88 #elif defined __MINGW64__
89 #define OS_STRING "win_mingw64"
90 #endif
91
92 #define ID_INLINE __inline
93 #define PATH_SEP '\\'
94
95 #if defined(__x86_64__) || defined(_M_X64)
96 #undef idx64
97 #define idx64 1
98 #define ARCH_STRING "x86_64"
99 #define HAVE_VM_COMPILED
100 #elif defined(__aarch64__) || defined(__ARM64__) || defined (_M_ARM64)
101 #define ARCH_STRING "arm64"
102 #endif
103
104 #define Q3_LITTLE_ENDIAN
105
106 #define DLL_EXT ".dll"
107
108 #elif defined(_WIN32) || defined(__WIN32__)
109
110 #undef QDECL
111 #define QDECL __cdecl
112
113 #undef QCALL
114 #define QCALL __stdcall
115
116 #if defined( _MSC_VER )
117 #define OS_STRING "win_msvc"
118 #elif defined __MINGW32__
119 #define OS_STRING "win_mingw"
120 #endif
121
122 #define ID_INLINE __inline
123 #define PATH_SEP '\\'
124
125 #if defined( _M_IX86 ) || defined( __i386__ )
126 #define ARCH_STRING "x86"
127 #define HAVE_VM_COMPILED
128 #elif defined(__arm__) || defined(_M_ARM)
129 #define ARCH_STRING "arm"
130 #endif
131
132 #define Q3_LITTLE_ENDIAN
133
134 #define DLL_EXT ".dll"
135
136 #endif
137
138
139 //================================================================ MAC OS ===
140
141 #if defined(__APPLE__) || defined(__APPLE_CC__)
142
143 #define OS_STRING "macosx"
144 #define ID_INLINE inline
145 #define PATH_SEP '/'
146
147 #ifdef __ppc__
148 #define ARCH_STRING "ppc"
149 #define Q3_BIG_ENDIAN
150 #define HAVE_VM_COMPILED
151 #elif defined __i386__
152 #define ARCH_STRING "x86"
153 #define Q3_LITTLE_ENDIAN
154 #define HAVE_VM_COMPILED
155 #elif defined __x86_64__
156 #undef idx64
157 #define idx64 1
158 #define ARCH_STRING "x86_64"
159 #define Q3_LITTLE_ENDIAN
160 #define HAVE_VM_COMPILED
161 #elif defined __aarch64__
162 #define ARCH_STRING "arm64"
163 #define Q3_LITTLE_ENDIAN
164 #endif
165
166 #define DLL_EXT ".dylib"
167
168 #endif
169
170 //================================================================= LINUX ===
171
172 #if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__GNU__)
173
174 #include <endian.h>
175
176 #if defined(__linux__)
177 #define OS_STRING "linux"
178 #elif defined(__FreeBSD_kernel__)
179 #define OS_STRING "kFreeBSD"
180 #else
181 #define OS_STRING "GNU"
182 #endif
183
184 #define ID_INLINE inline
185
186 #define PATH_SEP '/'
187
188 #if defined(__x86_64__) || defined(__amd64__)
189 # define ARCH_STRING "x86_64"
190 # define HAVE_VM_COMPILED
191 #elif defined(__i386__)
192 # define ARCH_STRING "x86"
193 # define HAVE_VM_COMPILED
194 #elif defined(__aarch64__)
195 # define ARCH_STRING "arm64"
196 #elif defined(__arm__)
197 # define ARCH_STRING "arm"
198 # define HAVE_VM_COMPILED
199 #elif defined(__powerpc64__) || defined(__ppc64__)
200 # define ARCH_STRING "ppc64"
201 # define HAVE_VM_COMPILED
202 #elif defined(__powerpc__) || defined(__ppc__)
203 # define ARCH_STRING "ppc"
204 # define HAVE_VM_COMPILED
205 #elif defined(__alpha__)
206 # define ARCH_STRING "alpha"
207 #endif
208
209 #if defined __x86_64__
210 #undef idx64
211 #define idx64 1
212 #endif
213
214 #if __FLOAT_WORD_ORDER == __BIG_ENDIAN
215 #define Q3_BIG_ENDIAN
216 #else
217 #define Q3_LITTLE_ENDIAN
218 #endif
219
220 #define DLL_EXT ".so"
221
222 #endif
223
224 //=================================================================== BSD ===
225
226 #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
227
228 #include <sys/types.h>
229 #include <machine/endian.h>
230
231 #ifndef __BSD__
232 #define __BSD__
233 #endif
234
235 #if defined(__FreeBSD__)
236 #define OS_STRING "freebsd"
237 #elif defined(__OpenBSD__)
238 #define OS_STRING "openbsd"
239 #elif defined(__NetBSD__)
240 #define OS_STRING "netbsd"
241 #endif
242
243 #define ID_INLINE inline
244 #define PATH_SEP '/'
245
246 #ifdef __i386__
247 #define ARCH_STRING "x86"
248 #define HAVE_VM_COMPILED
249 #elif defined __amd64__
250 #undef idx64
251 #define idx64 1
252 #define ARCH_STRING "x86_64"
253 #define HAVE_VM_COMPILED
254 #elif defined __axp__
255 #define ARCH_STRING "alpha"
256 #endif
257
258 #if BYTE_ORDER == BIG_ENDIAN
259 #define Q3_BIG_ENDIAN
260 #else
261 #define Q3_LITTLE_ENDIAN
262 #endif
263
264 #define DLL_EXT ".so"
265
266 #endif
267
268 //================================================================= SUNOS ===
269
270 #ifdef __sun
271
272 #include <stdint.h>
273 #include <sys/byteorder.h>
274
275 #define OS_STRING "solaris"
276 #define ID_INLINE inline
277 #define PATH_SEP '/'
278
279 #ifdef __i386__
280 #define ARCH_STRING "x86"
281 #define HAVE_VM_COMPILED
282 #elif defined __sparc
283 #define ARCH_STRING "sparc"
284 #define HAVE_VM_COMPILED
285 #endif
286
287 #if defined( _BIG_ENDIAN )
288 #define Q3_BIG_ENDIAN
289 #elif defined( _LITTLE_ENDIAN )
290 #define Q3_LITTLE_ENDIAN
291 #endif
292
293 #define DLL_EXT ".so"
294
295 #endif
296
297 //================================================================== IRIX ===
298
299 #ifdef __sgi
300
301 #define OS_STRING "irix"
302 #define ID_INLINE __inline
303 #define PATH_SEP '/'
304
305 #define ARCH_STRING "mips"
306
307 #define Q3_BIG_ENDIAN // SGI's MIPS are always big endian
308
309 #define DLL_EXT ".so"
310
311 #endif
312
313 //============================================================ EMSCRIPTEN ===
314
315 #ifdef __EMSCRIPTEN__
316
317 #define OS_STRING "emscripten"
318 #define ID_INLINE inline
319 #define PATH_SEP '/'
320
321 #define ARCH_STRING "wasm32"
322
323 #define Q3_LITTLE_ENDIAN
324
325 #define DLL_EXT ".wasm"
326
327 #endif
328
329 //================================================================== Q3VM ===
330
331 #ifdef Q3_VM
332
333 #define OS_STRING "q3vm"
334 #define ID_INLINE
335 #define PATH_SEP '/'
336
337 #define ARCH_STRING "bytecode"
338
339 #define DLL_EXT ".qvm"
340
341 #endif
342
343 //===========================================================================
344
345 // Catch missing defines in above blocks
346
347 #ifndef OS_STRING
348 #error "Operating system not supported"
349 #endif
350
351 #ifndef ARCH_STRING
352 // ARCH_STRING is (mostly) only used for informational purposes, so we allow
353 // it to be undefined so that more diverse architectures may be compiled
354 #define ARCH_STRING "unknown"
355 #endif
356
357 #ifndef ID_INLINE
358 #error "ID_INLINE not defined"
359 #endif
360
361 #ifndef PATH_SEP
362 #error "PATH_SEP not defined"
363 #endif
364
365 #ifndef DLL_EXT
366 #error "DLL_EXT not defined"
367 #endif
368
369
370 //endianness
371 void CopyShortSwap (void *dest, void *src);
372 void CopyLongSwap (void *dest, void *src);
373 short ShortSwap (short l);
374 int LongSwap (int l);
375 float FloatSwap (const float *f);
376
377 #if defined( Q3_BIG_ENDIAN ) && defined( Q3_LITTLE_ENDIAN )
378 #error "Endianness defined as both big and little"
379 #elif defined( Q3_BIG_ENDIAN )
380
381 #define CopyLittleShort(dest, src) CopyShortSwap(dest, src)
382 #define CopyLittleLong(dest, src) CopyLongSwap(dest, src)
383 #define LittleShort(x) ShortSwap(x)
384 #define LittleLong(x) LongSwap(x)
385 #define LittleFloat(x) FloatSwap(&x)
386 #define BigShort
387 #define BigLong
388 #define BigFloat
389
390 #elif defined( Q3_LITTLE_ENDIAN )
391
392 #define CopyLittleShort(dest, src) Com_Memcpy(dest, src, 2)
393 #define CopyLittleLong(dest, src) Com_Memcpy(dest, src, 4)
394 #define LittleShort
395 #define LittleLong
396 #define LittleFloat
397 #define BigShort(x) ShortSwap(x)
398 #define BigLong(x) LongSwap(x)
399 #define BigFloat(x) FloatSwap(&x)
400
401 #elif defined( Q3_VM )
402
403 #define LittleShort
404 #define LittleLong
405 #define LittleFloat
406 #define BigShort
407 #define BigLong
408 #define BigFloat
409
410 #else
411 #error "Endianness not defined"
412 #endif
413
414
415 //platform string
416 #ifdef NDEBUG
417 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING
418 #else
419 #define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug"
420 #endif
421
422 #endif