Action Engine
Loading...
Searching...
No Matches
platform.h
1// Copyright (c) 2014 Steinwurf ApS
2// All Rights Reserved
3//
4// Distributed under the "BSD License". See the accompanying LICENSE.rst file.
5
6#ifndef ACTIONENGINE_UTIL_PLATFORM_H_
7#define ACTIONENGINE_UTIL_PLATFORM_H_
8
9// Here we create a number of defines to make it easy to choose between
10// different compilers, operatings systems and CPU architectures.
11// Some information about the defines used can be found here:
12// http://sourceforge.net/p/predef/wiki/Architectures/
13
14// Detect operating systems
15#if defined(__linux__)
16#define PLATFORM_LINUX 1
17#if defined(__ANDROID__)
18#define PLATFORM_ANDROID 1
19#endif
20#elif defined(_WIN32)
21#define PLATFORM_WINDOWS 1
22#if defined(WINAPI_FAMILY)
23#include <winapifamily.h>
24#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
25#define PLATFORM_WINDOWS_PHONE 1
26#endif
27#endif
28#elif defined(__APPLE__)
29// Detect iOS before MacOSX (__MACH__ is also defined for iOS)
30#if defined(IPHONE)
31#define PLATFORM_IOS 1
32#elif defined(__MACH__)
33#define PLATFORM_MAC 1
34#endif
35#elif defined(__EMSCRIPTEN__)
36#define PLATFORM_EMSCRIPTEN 1
37#elif defined(__FreeBSD__)
38#define PLATFORM_FREEBSD 1
39#else
40#error "Unable to determine operating system"
41#endif
42
43// Detect compilers and CPU architectures
44// Note: clang also defines __GNUC__ since it aims to be compatible with GCC.
45// Therefore we need to check for __clang__ or __llvm__ first.
46#if defined(__clang__) || defined(__llvm__)
47#define PLATFORM_CLANG 1
48#define PLATFORM_GCC_COMPATIBLE 1
49#if defined(__i386__) || defined(__x86_64__)
50#define PLATFORM_X86 1
51#define PLATFORM_CLANG_X86 1
52#define PLATFORM_GCC_COMPATIBLE_X86 1
53#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
54#define PLATFORM_ARM 1
55#define PLATFORM_CLANG_ARM 1
56#define PLATFORM_GCC_COMPATIBLE_ARM 1
57#elif defined(__mips__)
58#define PLATFORM_MIPS 1
59#define PLATFORM_CLANG_MIPS 1
60#define PLATFORM_GCC_COMPATIBLE_MIPS 1
61#elif defined(__asmjs__)
62#define PLATFORM_ASMJS 1
63#define PLATFORM_CLANG_ASMJS 1
64#define PLATFORM_GCC_COMPATIBLE_ASMJS 1
65#endif
66#elif defined(__GNUC__)
67#define PLATFORM_GCC 1
68#define PLATFORM_GCC_COMPATIBLE 1
69#if defined(__i386__) || defined(__x86_64__)
70#define PLATFORM_X86 1
71#define PLATFORM_GCC_X86 1
72#define PLATFORM_GCC_COMPATIBLE_X86 1
73#elif defined(__arm__) || defined(__arm64__) || defined(__aarch64__)
74#define PLATFORM_ARM 1
75#define PLATFORM_GCC_ARM 1
76#define PLATFORM_GCC_COMPATIBLE_ARM 1
77#elif defined(__mips__)
78#define PLATFORM_MIPS 1
79#define PLATFORM_GCC_MIPS 1
80#define PLATFORM_GCC_COMPATIBLE_MIPS 1
81#endif
82#elif defined(_MSC_VER)
83#define PLATFORM_MSVC 1
84#if defined(_M_IX86) || defined(_M_X64)
85#define PLATFORM_X86 1
86#define PLATFORM_MSVC_X86 1
87#elif defined(_M_ARM) || defined(_M_ARMT)
88#define PLATFORM_ARM 1
89#define PLATFORM_MSVC_ARM 1
90#endif
91#else
92#error "Unable to determine compiler"
93#endif
94
95// Define macros for supported CPU instruction sets
96#if defined(PLATFORM_GCC_COMPATIBLE)
97#if defined(__MMX__)
98#define PLATFORM_MMX 1
99#endif
100#if defined(__SSE__)
101#define PLATFORM_SSE 1
102#endif
103#if defined(__SSE2__)
104#define PLATFORM_SSE2 1
105#endif
106#if defined(__SSE3__)
107#define PLATFORM_SSE3 1
108#endif
109#if defined(__SSSE3__)
110#define PLATFORM_SSSE3 1
111#endif
112#if defined(__SSE4_1__)
113#define PLATFORM_SSE41 1
114#endif
115#if defined(__SSE4_2__)
116#define PLATFORM_SSE42 1
117#endif
118#if defined(__PCLMUL__)
119#define PLATFORM_PCLMUL 1
120#endif
121#if defined(__AVX__)
122#define PLATFORM_AVX 1
123#endif
124#if defined(__AVX2__)
125#define PLATFORM_AVX2 1
126#endif
127#if defined(__ARM_NEON__) || defined(__ARM_NEON)
128#define PLATFORM_NEON 1
129#endif
130// First, check the PLATFORM_WINDOWS_PHONE define, because
131// the X86 instructions sets are not supported on the Windows Phone emulator
132#elif defined(PLATFORM_WINDOWS_PHONE)
133#if defined(PLATFORM_MSVC_ARM)
134// NEON introduced in VS2012
135#if (_MSC_VER >= 1700)
136#define PLATFORM_NEON 1
137#endif
138#endif
139#elif defined(PLATFORM_MSVC_X86)
140// MMX, SSE and SSE2 introduced in VS2003
141#if (_MSC_VER >= 1310)
142#define PLATFORM_MMX 1
143#define PLATFORM_SSE 1
144#define PLATFORM_SSE2 1
145#endif
146// SSE3 introduced in VS2005
147#if (_MSC_VER >= 1400)
148#define PLATFORM_SSE3 1
149#endif
150// SSSE3, SSE4.1, SSE4.2, PCLMUL introduced in VS2008
151#if (_MSC_VER >= 1500)
152#define PLATFORM_SSSE3 1
153#define PLATFORM_SSE41 1
154#define PLATFORM_SSE42 1
155#define PLATFORM_PCLMUL 1
156#endif
157// AVX and AVX2 introduced in VS2012
158#if (_MSC_VER >= 1700)
159#define PLATFORM_AVX 1
160#define PLATFORM_AVX2 1
161#endif
162#endif
163
164#endif // ACTIONENGINE_UTIL_PLATFORM_H_