Pyrogenesis  trunk
arch.h
Go to the documentation of this file.
1 /* Copyright (c) 2015 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * CPU architecture detection.
25  */
26 
27 #ifndef INCLUDED_ARCH
28 #define INCLUDED_ARCH
29 
30 // detect target CPU architecture via predefined macros
31 // .. IA-32
32 #if defined(_M_IX86) || defined(__X86__) || defined(_X86_) || defined(__i386__) || defined(__i386) || defined(i386)
33 # define ARCH_IA32 1
34 #else
35 # define ARCH_IA32 0
36 #endif
37 // .. IA-64
38 #if defined(_M_IA64) || defined(__ia64__)
39 # define ARCH_IA64 1
40 #else
41 # define ARCH_IA64 0
42 #endif
43 // .. AMD64
44 #if defined(_M_X64) || defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64)
45 # define ARCH_AMD64 1
46 #else
47 # define ARCH_AMD64 0
48 #endif
49 // .. Alpha
50 #if defined(_M_ALPHA) || defined(__alpha__) || defined(__alpha)
51 # define ARCH_ALPHA 1
52 #else
53 # define ARCH_ALPHA 0
54 #endif
55 // .. ARM
56 #if defined(__arm__)
57 # define ARCH_ARM 1
58 #else
59 # define ARCH_ARM 0
60 #endif
61 // .. AArch64 (ARM64)
62 #if defined(__aarch64__)
63 # define ARCH_AARCH64 1
64 #else
65 # define ARCH_AARCH64 0
66 #endif
67 // .. MIPS
68 #if defined(__MIPS__) || defined(__mips__) || defined(__mips)
69 # define ARCH_MIPS 1
70 #else
71 # define ARCH_MIPS 0
72 #endif
73 
74 // ensure exactly one architecture has been detected
75 #if (ARCH_IA32+ARCH_IA64+ARCH_AMD64+ARCH_ALPHA+ARCH_ARM+ARCH_AARCH64+ARCH_MIPS) != 1
76 # error "architecture not correctly detected (either none or multiple ARCH_* defined)"
77 #endif
78 
79 // "X86_X64"-specific code requires either IA-32 or AMD64
80 #define ARCH_X86_X64 (ARCH_IA32|ARCH_AMD64)
81 
82 #endif // #ifndef INCLUDED_ARCH