-
Notifications
You must be signed in to change notification settings - Fork 92
/
q_platform.h
459 lines (353 loc) · 9.4 KB
/
q_platform.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
* Wolfenstein: Enemy Territory GPL Source Code
* Copyright (C) 1999-2010 id Software LLC, a ZeniMax Media company.
*
* ET: Legacy
* Copyright (C) 2012-2024 ET:Legacy team <mail@etlegacy.com>
*
* This file is part of ET: Legacy - http://www.etlegacy.com
*
* ET: Legacy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ET: Legacy is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ET: Legacy. If not, see <http://www.gnu.org/licenses/>.
*
* In addition, Wolfenstein: Enemy Territory GPL Source Code is also
* subject to certain additional terms. You should have received a copy
* of these additional terms immediately following the terms and conditions
* of the GNU General Public License which accompanied the source code.
* If not, please request a copy in writing from id Software at the address below.
*
* id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
*/
/**
* @file q_platform.h
* @brief Platform specific definitions
*/
#ifndef INCLUDE_Q_PLATFORM_H
#define INCLUDE_Q_PLATFORM_H
// this is for determining if we have an asm version of a C function
#define idx64 0
#ifdef Q3_VM
#define id386 0
#define idppc 0
#define idppc_altivec 0
#define idsparc 0
#else
#if (defined _M_IX86 || defined __i386__) && !defined(C_ONLY)
#define id386 1
#else
#define id386 0
#endif
#if (defined(powerc) || defined(powerpc) || defined(ppc) || \
defined(__ppc) || defined(__ppc__) || defined(__PPC__) || \
defined(__POWERPC__)) && !defined(C_ONLY)
#define idppc 1
#if defined(__VEC__) || defined(__ALTIVEC__) || defined(__APPLE_ALTIVEC__)
#define idppc_altivec 1
#ifdef __APPLE__ // Apple's GCC does this differently than the FSF.
#define VECCONST_UINT8(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
(vector unsigned char) (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
#else
#define VECCONST_UINT8(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
(vector unsigned char) { a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p }
#endif
#else
#define idppc_altivec 0
#endif
#else
#define idppc 0
#define idppc_altivec 0
#endif
#if defined(__sparc__) && !defined(C_ONLY)
#define idsparc 1
#else
#define idsparc 0
#endif
#endif
#ifndef __ASM_I386__ // don't include the C bits if included from qasm.h
// for windows fastcall option
#define QDECL
#define QCALL
//================================================================= WIN64/32 ===
#if defined(_WIN64) || defined(__WIN64__)
#undef idx64
#define idx64 1
#undef QDECL
#define QDECL __cdecl
#undef QCALL
#define QCALL __stdcall
#if defined(_MSC_VER)
#define OS_STRING "win_msvc64"
#elif defined __MINGW64__
#define OS_STRING "win_mingw64"
#endif
#define ID_INLINE __inline
#define PATH_SEP '\\'
#if defined(_WIN64)
#define ARCH_STRING "x64"
#elif defined _M_ALPHA
#define ARCH_STRING "AXP"
#endif
#define Q3_LITTLE_ENDIAN
#define DLL_EXT ".dll"
#elif defined(_WIN32) || defined(__WIN32__)
#undef QDECL
#define QDECL __cdecl
#undef QCALL
#define QCALL __stdcall
#if defined(_MSC_VER)
#define OS_STRING "win_msvc"
#elif defined __MINGW32__
#define OS_STRING "win_mingw"
#endif
#define ID_INLINE __inline
#define PATH_SEP '\\'
#if defined(_M_IX86) || defined(__i386__)
#define ARCH_STRING "x86"
#elif defined _M_ALPHA
#define ARCH_STRING "AXP"
#endif
#define Q3_LITTLE_ENDIAN
#define DLL_EXT ".dll"
#endif
//================================================================= MAC OS ===
#if defined(__APPLE__) || defined(__APPLE_CC__)
#define OS_STRING "macos"
#define ID_INLINE __inline
#define PATH_SEP '/'
#ifdef __ppc__
#define ARCH_STRING "ppc"
#define Q3_BIG_ENDIAN
#elif defined __i386__
#define ARCH_STRING "i386"
#define Q3_LITTLE_ENDIAN
#elif defined __x86_64__
#undef idx64
#define idx64 1
#define ARCH_STRING "x86_64"
#define Q3_LITTLE_ENDIAN
#elif defined __arm64__
#undef idx64
#define idx64 1
#define ARCH_STRING "arm64"
#define Q3_LITTLE_ENDIAN
#endif
#define DLL_EXT "_mac"
#endif
//================================================================= LINUX ===
#if defined(__linux__) || defined(__FreeBSD_kernel__)
#include <endian.h>
#if defined(__linux__)
#define OS_STRING "linux"
#else
#define OS_STRING "kFreeBSD"
#endif
#define ID_INLINE inline
#define PATH_SEP '/'
#if defined __i386__
#define ARCH_STRING "i386"
#elif defined __x86_64__
#undef idx64
#define idx64 1
#define ARCH_STRING "x86_64"
#elif defined __powerpc64__
#if BYTE_ORDER == BIG_ENDIAN
#define ARCH_STRING "ppc64"
#else
#define ARCH_STRING "ppc64le"
#endif
#elif defined __powerpc__
#define ARCH_STRING "ppc"
#elif defined __s390__
#define ARCH_STRING "s390"
#elif defined __s390x__
#define ARCH_STRING "s390x"
#elif defined __ia64__
#define ARCH_STRING "ia64"
#elif defined __alpha__
#define ARCH_STRING "alpha"
#elif defined __sparc__
#define ARCH_STRING "sparc"
#elif defined __arm__
#define ARCH_STRING "arm" // __ARM_ARCH_'V'__ FIXME: add ARM version to the ARCH_STRING
#elif defined __aarch64__
#define ARCH_STRING "aarch64"
#elif defined __cris__
#define ARCH_STRING "cris"
#elif defined __hppa__
#define ARCH_STRING "hppa"
#elif defined __mips__
#define ARCH_STRING "mips"
#elif defined __sh__
#define ARCH_STRING "sh"
#endif
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
#define Q3_BIG_ENDIAN
#else
#define Q3_LITTLE_ENDIAN
#endif
#define DLL_EXT ".so"
#endif
//=================================================================== BSD ===
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#include <sys/types.h>
#include <machine/endian.h>
#ifndef __BSD__
#define __BSD__
#endif
#if defined(__FreeBSD__)
#define OS_STRING "freebsd"
#elif defined(__OpenBSD__)
#define OS_STRING "openbsd"
#elif defined(__NetBSD__)
#define OS_STRING "netbsd"
#endif
#define ID_INLINE inline
#define PATH_SEP '/'
#ifdef __i386__
#define ARCH_STRING "i386"
#elif defined __aarch64__
#define ARCH_STRING "aarch64"
#elif defined __amd64__
#undef idx64
#define idx64 1
#define ARCH_STRING "x86_64"
#elif defined __axp__
#define ARCH_STRING "alpha"
#endif
#if BYTE_ORDER == BIG_ENDIAN
#define Q3_BIG_ENDIAN
#else
#define Q3_LITTLE_ENDIAN
#endif
#define DLL_EXT ".so"
#endif
//================================================================= SUNOS ===
#ifdef __sun
#include <stdint.h>
#include <sys/byteorder.h>
#define OS_STRING "solaris"
#define ID_INLINE inline
#define PATH_SEP '/'
#ifdef __i386__
#define ARCH_STRING "i386"
#elif defined __sparc
#define ARCH_STRING "sparc"
#endif
#if defined(_BIG_ENDIAN)
#define Q3_BIG_ENDIAN
#elif defined(_LITTLE_ENDIAN)
#define Q3_LITTLE_ENDIAN
#endif
#define DLL_EXT ".so"
#endif
//================================================================== IRIX ===
#ifdef __sgi
#define OS_STRING "irix"
#define ID_INLINE __inline
#define PATH_SEP '/'
#define ARCH_STRING "mips"
#define Q3_BIG_ENDIAN // SGI's MIPS are always big endian
#define DLL_EXT ".so"
#endif
//================================================================== Q3VM ===
#ifdef Q3_VM
#define OS_STRING "q3vm"
#define ID_INLINE
#define PATH_SEP '/'
#define ARCH_STRING "bytecode"
#define DLL_EXT ".qvm"
#endif
//=============================================================== ANDROID ===
#ifdef __ANDROID__
#ifndef OS_STRING
#define OS_STRING "android"
#endif
#define ID_INLINE inline
#define PATH_SEP '/'
#if defined __arm__
#undef ARCH_STRING
#define ARCH_STRING "armeabi-v7a"
#elif defined __aarch64__
#undef ARCH_STRING
#define ARCH_STRING "arm64-v8a"
#endif
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
#define Q3_BIG_ENDIAN
#else
#define Q3_LITTLE_ENDIAN
#endif
#define DLL_EXT ".so"
#endif
//===========================================================================
//catch missing defines in above blocks
#if !defined(OS_STRING)
#error "Operating system not supported"
#endif
#if !defined(ARCH_STRING)
#error "Architecture not supported"
#endif
#ifndef ID_INLINE
#error "ID_INLINE not defined"
#endif
#ifndef PATH_SEP
#error "PATH_SEP not defined"
#endif
#ifndef DLL_EXT
#error "DLL_EXT not defined"
#endif
// x86 platform?
#if defined(_M_IX86) || defined(__i386__)
#define ARCH_X86 1
#else
#define ARCH_X86 0
#endif
//endianness
short ShortSwap(short l);
int LongSwap(int l);
float FloatSwap(const float *f);
#if defined(Q3_BIG_ENDIAN) && defined(Q3_LITTLE_ENDIAN)
#error "Endianness defined as both big and little"
#elif defined(Q3_BIG_ENDIAN)
#define LittleShort(x) ShortSwap(x)
#define LittleLong(x) LongSwap(x)
#define LittleFloat(x) FloatSwap(&x)
#define BigShort
#define BigLong
#define BigFloat
#elif defined(Q3_LITTLE_ENDIAN)
#define LittleShort
#define LittleLong
#define LittleFloat
#define BigShort(x) ShortSwap(x)
#define BigLong(x) LongSwap(x)
#define BigFloat(x) FloatSwap(&x)
#elif defined(Q3_VM)
#define LittleShort
#define LittleLong
#define LittleFloat
#define BigShort
#define BigLong
#define BigFloat
#else
#error "Endianness not defined"
#endif
//platform string
#ifndef ETLEGACY_DEBUG
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING
#else
#define PLATFORM_STRING OS_STRING "-" ARCH_STRING "-debug"
#endif
#endif
#define LL(x) x = LittleLong(x)
#define LF(x) x = LittleFloat(x)
#endif // #ifndef INCLUDE_Q_PLATFORM_H