aboutsummaryrefslogtreecommitdiffstats
path: root/code/qcommon/q_platform.h
blob: cf8a0317805ea16b3ef0d243623a69674300d429 (plain)
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
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.

This file is part of Quake III Arena source code.

Quake III Arena source code 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 2 of the License,
or (at your option) any later version.

Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/
//
#ifndef __Q_PLATFORM_H
#define __Q_PLATFORM_H

// this is for determining if we have an asm version of a C function
#ifdef Q3_VM

#define id386 0
#define idppc 0
#define idppc_altivec 0

#else

#if (defined _M_IX86 || defined __i386__) && \
		!defined __sun && !defined(C_ONLY)
#define id386 1
#else
#define id386 0
#endif

#if (defined(powerc) || defined(powerpc) || defined(ppc) || \
		defined(__ppc) || defined(__ppc__)) && !defined(C_ONLY)
#define idppc 1
#if defined(__VEC__)
#define idppc_altivec 1
#else
#define idppc_altivec 0
#endif
#else
#define idppc 0
#define idppc_altivec 0
#endif

#endif

#ifndef __ASM_I386__ // don't include the C bits if included from qasm.h

// for windows fastcall option

#define QDECL

short	ShortSwap (short l);
int		LongSwap (int l);
float	FloatSwap (const float *f);

//================================================================= WIN32 ===

#ifdef _WIN32

#undef QDECL
#define QDECL __cdecl

// buildstring will be incorporated into the version string
#ifdef _MSC_VER
#ifdef NDEBUG
#ifdef _M_IX86
#define CPUSTRING "win-x86"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP"
#endif
#else
#ifdef _M_IX86
#define CPUSTRING "win-x86-debug"
#elif defined _M_ALPHA
#define CPUSTRING "win-AXP-debug"
#endif
#endif
#elif defined __MINGW32__
#ifdef NDEBUG
#ifdef __i386__
#define CPUSTRING "mingw-x86"
#endif
#else
#ifdef __i386__
#define CPUSTRING "mingw-x86-debug"
#endif
#endif
#endif

#define ID_INLINE __inline

static ID_INLINE short BigShort( short l) { return ShortSwap(l); }
#define LittleShort
static ID_INLINE int BigLong(int l) { return LongSwap(l); }
#define LittleLong
static ID_INLINE float BigFloat(const float l) { return FloatSwap(&l); }
#define LittleFloat

#define PATH_SEP '\\'

#endif

//============================================================== MAC OS X ===

#if defined(MACOS_X)

#define __cdecl
#define __declspec(x)
#define stricmp strcasecmp
#define ID_INLINE inline

#ifdef __ppc__
#define CPUSTRING "MacOSX-ppc"
#elif defined __i386__
#define CPUSTRING "MacOSX-i386"
#else
#define CPUSTRING "MacOSX-other"
#endif

#define PATH_SEP '/'

#define __rlwimi(out, in, shift, maskBegin, maskEnd) \
	asm("rlwimi %0,%1,%2,%3,%4" : "=r" (out) : "r" (in), \
			"i" (shift), "i" (maskBegin), "i" (maskEnd))
#define __dcbt(addr, offset) asm("dcbt %0,%1" : : "b" (addr), "r" (offset))

static ID_INLINE unsigned int __lwbrx(register void *addr,
		register int offset) {
	register unsigned int word;

	asm("lwbrx %0,%2,%1" : "=r" (word) : "r" (addr), "b" (offset));
	return word;
}

static ID_INLINE unsigned short __lhbrx(register void *addr,
		register int offset) {
	register unsigned short halfword;

	asm("lhbrx %0,%2,%1" : "=r" (halfword) : "r" (addr), "b" (offset));
	return halfword;
}

static ID_INLINE float __fctiw(register float f) {
	register float fi;

	asm("fctiw %0,%1" : "=f" (fi) : "f" (f));
	return fi;
}

#define BigShort
static ID_INLINE short LittleShort(short l) { return ShortSwap(l); }
#define BigLong
static ID_INLINE int LittleLong(int l) { return LongSwap(l); }
#define BigFloat
static ID_INLINE float LittleFloat(const float l) { return FloatSwap(&l); }

#endif

//=================================================================== MAC ===

#ifdef __MACOS__

#include <MacTypes.h>
#define ID_INLINE inline

#define CPUSTRING "MacOS-PPC"

#define PATH_SEP ':'

void Sys_PumpEvents( void );

#define BigShort
static ID_INLINE short LittleShort(short l) { return ShortSwap(l); }
#define BigLong
static ID_INLINE int LittleLong(int l) { return LongSwap(l); }
#define BigFloat
static ID_INLINE float LittleFloat(const float l) { return FloatSwap(&l); }

#endif

//================================================================= LINUX ===

// the mac compiler can't handle >32k of locals, so we
// just waste space and make big arrays static...
#ifdef __linux__

// bk001205 - from Makefile
#define stricmp strcasecmp

#define ID_INLINE inline

#ifdef __i386__
#define CPUSTRING "linux-i386"
#elif defined __axp__
#define CPUSTRING "linux-alpha"
#elif defined __x86_64__
#define CPUSTRING "linux-x86_64"
#elif defined __powerpc64__
#define CPUSTRING "linux-ppc64"
#elif defined __powerpc__
#define CPUSTRING "linux-ppc"
#elif defined __s390__
#define CPUSTRING "linux-s390"
#elif defined __s390x__
#define CPUSTRING "linux-s390x"
#elif defined __ia64__
#define CPUSTRING "linux-ia64"
#else
#define CPUSTRING "linux-other"
#endif

#define PATH_SEP '/'

#if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
ID_INLINE static short BigShort( short l) { return ShortSwap(l); }
#define LittleShort
ID_INLINE static int BigLong(int l) { return LongSwap(l); }
#define LittleLong
ID_INLINE static float BigFloat(const float l) { return FloatSwap(&l); }
#define LittleFloat
#else
#define BigShort
ID_INLINE static short LittleShort(short l) { return ShortSwap(l); }
#define BigLong
ID_INLINE static int LittleLong(int l) { return LongSwap(l); }
#define BigFloat
ID_INLINE static float LittleFloat(const float l) { return FloatSwap(&l); }
#endif

#endif

//=============================================================== FreeBSD ===

#ifdef __FreeBSD__ // rb010123

#define stricmp strcasecmp

#define ID_INLINE inline

#ifdef __i386__
#define CPUSTRING "freebsd-i386"
#elif defined __axp__
#define CPUSTRING "freebsd-alpha"
#else
#define CPUSTRING "freebsd-other"
#endif

#define PATH_SEP '/'

#if !idppc
static short BigShort( short l) { return ShortSwap(l); }
#define LittleShort
static int BigLong(int l) { return LongSwap(l); }
#define LittleLong
static float BigFloat(const float l) { return FloatSwap(&l); }
#define LittleFloat
#else
#define BigShort
static short LittleShort(short l) { return ShortSwap(l); }
#define BigLong
static int LittleLong(int l) { return LongSwap(l); }
#define BigFloat
static float LittleFloat(const float l) { return FloatSwap(&l); }
#endif

#endif

//================================================================= SUNOS ===

#ifdef __sun

#include <sys/isa_defs.h>
#include <sys/byteorder.h>

// bk001205 - from Makefile
#define stricmp strcasecmp

#define ID_INLINE inline

#ifdef __i386__
#define CPUSTRING "Solaris-i386"
#elif defined __sparc
#define CPUSTRING "Solaris-sparc"
#endif

#define PATH_SEP '/'

#if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
#define BigShort
ID_INLINE static short LittleShort(short l) { return ShortSwap(l); }
#define BigLong
ID_INLINE static int LittleLong(int l) { return LongSwap(l); }
#define BigFloat
ID_INLINE static float LittleFloat(const float l) { return FloatSwap(&l); }

#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
ID_INLINE static short BigShort( short l) { return ShortSwap(l); }
#define LittleShort
ID_INLINE static int BigLong(int l) { return LongSwap(l); }
#define LittleLong
ID_INLINE static float BigFloat(const float l) { return FloatSwap(&l); }
#define LittleFloat

#else
#error "Either _BIG_ENDIAN or _LITTLE_ENDIAN must be #defined, but not both."
#endif

#endif

//================================================================== Q3VM ===

#ifdef Q3_VM

#define ID_INLINE

#define CPUSTRING "q3vm"

#define PATH_SEP '/'

#define LittleShort
#define LittleLong
#define LittleFloat
#define BigShort
#define BigLong
#define BigFloat

#endif

//===========================================================================

//catch missing defines in above blocks
#ifndef CPUSTRING
#error "CPUSTRING not defined"
#endif

#ifndef ID_INLINE
#error "ID_INLINE not defined"
#endif

#ifndef PATH_SEP
#error "PATH_SEP not defined"
#endif

#if !defined(BigLong) && !defined(LittleLong)
#error "Endianness not defined"
#endif

#endif

#endif