platform.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #pragma once
  2. ///////////////////////////////////////////////////////////////////////////////////
  3. // Platform
  4. #define GLM_PLATFORM_UNKNOWN 0x00000000
  5. #define GLM_PLATFORM_WINDOWS 0x00010000
  6. #define GLM_PLATFORM_LINUX 0x00020000
  7. #define GLM_PLATFORM_APPLE 0x00040000
  8. //#define GLM_PLATFORM_IOS 0x00080000
  9. #define GLM_PLATFORM_ANDROID 0x00100000
  10. #define GLM_PLATFORM_CHROME_NACL 0x00200000
  11. #define GLM_PLATFORM_UNIX 0x00400000
  12. #define GLM_PLATFORM_QNXNTO 0x00800000
  13. #define GLM_PLATFORM_WINCE 0x01000000
  14. #define GLM_PLATFORM_CYGWIN 0x02000000
  15. #ifdef GLM_FORCE_PLATFORM_UNKNOWN
  16. # define GLM_PLATFORM GLM_PLATFORM_UNKNOWN
  17. #elif defined(__CYGWIN__)
  18. # define GLM_PLATFORM GLM_PLATFORM_CYGWIN
  19. #elif defined(__QNXNTO__)
  20. # define GLM_PLATFORM GLM_PLATFORM_QNXNTO
  21. #elif defined(__APPLE__)
  22. # define GLM_PLATFORM GLM_PLATFORM_APPLE
  23. #elif defined(WINCE)
  24. # define GLM_PLATFORM GLM_PLATFORM_WINCE
  25. #elif defined(_WIN32)
  26. # define GLM_PLATFORM GLM_PLATFORM_WINDOWS
  27. #elif defined(__native_client__)
  28. # define GLM_PLATFORM GLM_PLATFORM_CHROME_NACL
  29. #elif defined(__ANDROID__)
  30. # define GLM_PLATFORM GLM_PLATFORM_ANDROID
  31. #elif defined(__linux)
  32. # define GLM_PLATFORM GLM_PLATFORM_LINUX
  33. #elif defined(__unix)
  34. # define GLM_PLATFORM GLM_PLATFORM_UNIX
  35. #else
  36. # define GLM_PLATFORM GLM_PLATFORM_UNKNOWN
  37. #endif//
  38. ///////////////////////////////////////////////////////////////////////////////////
  39. // Compiler
  40. #define GLM_COMPILER_UNKNOWN 0x00000000
  41. // Intel
  42. #define GLM_COMPILER_INTEL 0x00100000
  43. #define GLM_COMPILER_INTEL14 0x00100040
  44. #define GLM_COMPILER_INTEL15 0x00100050
  45. #define GLM_COMPILER_INTEL16 0x00100060
  46. #define GLM_COMPILER_INTEL17 0x00100070
  47. // Visual C++ defines
  48. #define GLM_COMPILER_VC 0x01000000
  49. #define GLM_COMPILER_VC12 0x01000001
  50. #define GLM_COMPILER_VC14 0x01000002
  51. #define GLM_COMPILER_VC15 0x01000003
  52. #define GLM_COMPILER_VC15_3 0x01000004
  53. #define GLM_COMPILER_VC15_5 0x01000005
  54. #define GLM_COMPILER_VC15_6 0x01000006
  55. #define GLM_COMPILER_VC15_7 0x01000007
  56. // GCC defines
  57. #define GLM_COMPILER_GCC 0x02000000
  58. #define GLM_COMPILER_GCC46 0x020000D0
  59. #define GLM_COMPILER_GCC47 0x020000E0
  60. #define GLM_COMPILER_GCC48 0x020000F0
  61. #define GLM_COMPILER_GCC49 0x02000100
  62. #define GLM_COMPILER_GCC5 0x02000200
  63. #define GLM_COMPILER_GCC6 0x02000300
  64. #define GLM_COMPILER_GCC7 0x02000400
  65. #define GLM_COMPILER_GCC8 0x02000500
  66. // CUDA
  67. #define GLM_COMPILER_CUDA 0x10000000
  68. #define GLM_COMPILER_CUDA70 0x100000A0
  69. #define GLM_COMPILER_CUDA75 0x100000B0
  70. #define GLM_COMPILER_CUDA80 0x100000C0
  71. // Clang
  72. #define GLM_COMPILER_CLANG 0x20000000
  73. #define GLM_COMPILER_CLANG34 0x20000050
  74. #define GLM_COMPILER_CLANG35 0x20000060
  75. #define GLM_COMPILER_CLANG36 0x20000070
  76. #define GLM_COMPILER_CLANG37 0x20000080
  77. #define GLM_COMPILER_CLANG38 0x20000090
  78. #define GLM_COMPILER_CLANG39 0x200000A0
  79. #define GLM_COMPILER_CLANG40 0x200000B0
  80. #define GLM_COMPILER_CLANG41 0x200000C0
  81. #define GLM_COMPILER_CLANG42 0x200000D0
  82. // Build model
  83. #define GLM_MODEL_32 0x00000010
  84. #define GLM_MODEL_64 0x00000020
  85. // Force generic C++ compiler
  86. #ifdef GLM_FORCE_COMPILER_UNKNOWN
  87. # define GLM_COMPILER GLM_COMPILER_UNKNOWN
  88. #elif defined(__INTEL_COMPILER)
  89. # if (__INTEL_COMPILER < 1400)
  90. # error "GLM requires ICC 2013 SP1 or newer"
  91. # elif __INTEL_COMPILER == 1400
  92. # define GLM_COMPILER GLM_COMPILER_INTEL14
  93. # elif __INTEL_COMPILER == 1500
  94. # define GLM_COMPILER GLM_COMPILER_INTEL15
  95. # elif __INTEL_COMPILER == 1600
  96. # define GLM_COMPILER GLM_COMPILER_INTEL16
  97. # elif __INTEL_COMPILER >= 1700
  98. # define GLM_COMPILER GLM_COMPILER_INTEL17
  99. # endif
  100. // CUDA
  101. #elif defined(__CUDACC__)
  102. # if !defined(CUDA_VERSION) && !defined(GLM_FORCE_CUDA)
  103. # include <cuda.h> // make sure version is defined since nvcc does not define it itself!
  104. # endif
  105. # if CUDA_VERSION < 7000
  106. # error "GLM requires CUDA 7.0 or higher"
  107. # elif (CUDA_VERSION >= 7000 && CUDA_VERSION < 7500)
  108. # define GLM_COMPILER GLM_COMPILER_CUDA70
  109. # elif (CUDA_VERSION >= 7500 && CUDA_VERSION < 8000)
  110. # define GLM_COMPILER GLM_COMPILER_CUDA75
  111. # elif (CUDA_VERSION >= 8000)
  112. # define GLM_COMPILER GLM_COMPILER_CUDA80
  113. # endif
  114. // Clang
  115. #elif defined(__clang__)
  116. # if defined(__apple_build_version__)
  117. # if (__clang_major__ < 6)
  118. # error "GLM requires Clang 3.4 / Apple Clang 6.0 or higher"
  119. # elif __clang_major__ == 6 && __clang_minor__ == 0
  120. # define GLM_COMPILER GLM_COMPILER_CLANG35
  121. # elif __clang_major__ == 6 && __clang_minor__ >= 1
  122. # define GLM_COMPILER GLM_COMPILER_CLANG36
  123. # elif __clang_major__ >= 7
  124. # define GLM_COMPILER GLM_COMPILER_CLANG37
  125. # endif
  126. # else
  127. # if ((__clang_major__ == 3) && (__clang_minor__ < 4)) || (__clang_major__ < 3)
  128. # error "GLM requires Clang 3.4 or higher"
  129. # elif __clang_major__ == 3 && __clang_minor__ == 4
  130. # define GLM_COMPILER GLM_COMPILER_CLANG34
  131. # elif __clang_major__ == 3 && __clang_minor__ == 5
  132. # define GLM_COMPILER GLM_COMPILER_CLANG35
  133. # elif __clang_major__ == 3 && __clang_minor__ == 6
  134. # define GLM_COMPILER GLM_COMPILER_CLANG36
  135. # elif __clang_major__ == 3 && __clang_minor__ == 7
  136. # define GLM_COMPILER GLM_COMPILER_CLANG37
  137. # elif __clang_major__ == 3 && __clang_minor__ == 8
  138. # define GLM_COMPILER GLM_COMPILER_CLANG38
  139. # elif __clang_major__ == 3 && __clang_minor__ >= 9
  140. # define GLM_COMPILER GLM_COMPILER_CLANG39
  141. # elif __clang_major__ == 4 && __clang_minor__ == 0
  142. # define GLM_COMPILER GLM_COMPILER_CLANG40
  143. # elif __clang_major__ == 4 && __clang_minor__ == 1
  144. # define GLM_COMPILER GLM_COMPILER_CLANG41
  145. # elif __clang_major__ == 4 && __clang_minor__ >= 2
  146. # define GLM_COMPILER GLM_COMPILER_CLANG42
  147. # elif __clang_major__ >= 4
  148. # define GLM_COMPILER GLM_COMPILER_CLANG42
  149. # endif
  150. # endif
  151. // Visual C++
  152. #elif defined(_MSC_VER)
  153. # if _MSC_VER < 1800
  154. # error "GLM requires Visual C++ 12 - 2013 or higher"
  155. # elif _MSC_VER == 1800
  156. # define GLM_COMPILER GLM_COMPILER_VC12
  157. # elif _MSC_VER == 1900
  158. # define GLM_COMPILER GLM_COMPILER_VC14
  159. # elif _MSC_VER == 1910
  160. # define GLM_COMPILER GLM_COMPILER_VC15
  161. # elif _MSC_VER == 1911
  162. # define GLM_COMPILER GLM_COMPILER_VC15_3
  163. # elif _MSC_VER == 1912
  164. # define GLM_COMPILER GLM_COMPILER_VC15_5
  165. # elif _MSC_VER == 1913
  166. # define GLM_COMPILER GLM_COMPILER_VC15_6
  167. # elif _MSC_VER >= 1914
  168. # define GLM_COMPILER GLM_COMPILER_VC15_7
  169. # endif//_MSC_VER
  170. // G++
  171. #elif defined(__GNUC__) || defined(__MINGW32__)
  172. # if ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) || (__GNUC__ < 4)
  173. # error "GLM requires GCC 4.7 or higher"
  174. # elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 6)
  175. # define GLM_COMPILER (GLM_COMPILER_GCC46)
  176. # elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 7)
  177. # define GLM_COMPILER (GLM_COMPILER_GCC47)
  178. # elif (__GNUC__ == 4) && (__GNUC_MINOR__ == 8)
  179. # define GLM_COMPILER (GLM_COMPILER_GCC48)
  180. # elif (__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)
  181. # define GLM_COMPILER (GLM_COMPILER_GCC49)
  182. # elif (__GNUC__ == 5)
  183. # define GLM_COMPILER (GLM_COMPILER_GCC5)
  184. # elif (__GNUC__ == 6)
  185. # define GLM_COMPILER (GLM_COMPILER_GCC6)
  186. # elif (__GNUC__ == 7)
  187. # define GLM_COMPILER (GLM_COMPILER_GCC7)
  188. # elif (__GNUC__ >= 8)
  189. # define GLM_COMPILER (GLM_COMPILER_GCC8)
  190. # endif
  191. #else
  192. # define GLM_COMPILER GLM_COMPILER_UNKNOWN
  193. #endif
  194. #ifndef GLM_COMPILER
  195. # error "GLM_COMPILER undefined, your compiler may not be supported by GLM. Add #define GLM_COMPILER 0 to ignore this message."
  196. #endif//GLM_COMPILER
  197. ///////////////////////////////////////////////////////////////////////////////////
  198. // Instruction sets
  199. // User defines: GLM_FORCE_PURE GLM_FORCE_SSE2 GLM_FORCE_SSE3 GLM_FORCE_AVX GLM_FORCE_AVX2 GLM_FORCE_AVX2
  200. #define GLM_ARCH_MIPS_BIT (0x10000000)
  201. #define GLM_ARCH_PPC_BIT (0x20000000)
  202. #define GLM_ARCH_ARM_BIT (0x40000000)
  203. #define GLM_ARCH_X86_BIT (0x80000000)
  204. #define GLM_ARCH_SIMD_BIT (0x00001000)
  205. #define GLM_ARCH_NEON_BIT (0x00000001)
  206. #define GLM_ARCH_SSE_BIT (0x00000002)
  207. #define GLM_ARCH_SSE2_BIT (0x00000004)
  208. #define GLM_ARCH_SSE3_BIT (0x00000008)
  209. #define GLM_ARCH_SSSE3_BIT (0x00000010)
  210. #define GLM_ARCH_SSE41_BIT (0x00000020)
  211. #define GLM_ARCH_SSE42_BIT (0x00000040)
  212. #define GLM_ARCH_AVX_BIT (0x00000080)
  213. #define GLM_ARCH_AVX2_BIT (0x00000100)
  214. #define GLM_ARCH_UNKNOWN (0)
  215. #define GLM_ARCH_X86 (GLM_ARCH_X86_BIT)
  216. #define GLM_ARCH_SSE (GLM_ARCH_SSE_BIT | GLM_ARCH_SIMD_BIT | GLM_ARCH_X86)
  217. #define GLM_ARCH_SSE2 (GLM_ARCH_SSE2_BIT | GLM_ARCH_SSE)
  218. #define GLM_ARCH_SSE3 (GLM_ARCH_SSE3_BIT | GLM_ARCH_SSE2)
  219. #define GLM_ARCH_SSSE3 (GLM_ARCH_SSSE3_BIT | GLM_ARCH_SSE3)
  220. #define GLM_ARCH_SSE41 (GLM_ARCH_SSE41_BIT | GLM_ARCH_SSSE3)
  221. #define GLM_ARCH_SSE42 (GLM_ARCH_SSE42_BIT | GLM_ARCH_SSE41)
  222. #define GLM_ARCH_AVX (GLM_ARCH_AVX_BIT | GLM_ARCH_SSE42)
  223. #define GLM_ARCH_AVX2 (GLM_ARCH_AVX2_BIT | GLM_ARCH_AVX)
  224. #define GLM_ARCH_ARM (GLM_ARCH_ARM_BIT)
  225. #define GLM_ARCH_NEON (GLM_ARCH_NEON_BIT | GLM_ARCH_SIMD_BIT | GLM_ARCH_ARM)
  226. #define GLM_ARCH_MIPS (GLM_ARCH_MIPS_BIT)
  227. #define GLM_ARCH_PPC (GLM_ARCH_PPC_BIT)
  228. #ifdef GLM_FORCE_ARCH_UNKNOWN
  229. # define GLM_ARCH GLM_ARCH_UNKNOWN
  230. #elif defined(GLM_FORCE_PURE) || defined(GLM_FORCE_XYZW_ONLY)
  231. # if defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86) || defined(__i386__)
  232. # define GLM_ARCH (GLM_ARCH_X86)
  233. # elif defined(__arm__ ) || defined(_M_ARM)
  234. # define GLM_ARCH (GLM_ARCH_ARM)
  235. # elif defined(__powerpc__ ) || defined(_M_PPC)
  236. # define GLM_ARCH (GLM_ARCH_PPC)
  237. # elif defined(__mips__ )
  238. # define GLM_ARCH (GLM_ARCH_MIPS)
  239. # else
  240. # define GLM_ARCH (GLM_ARCH_UNKNOWN)
  241. # endif
  242. #elif defined(GLM_FORCE_NEON)
  243. # define GLM_ARCH (GLM_ARCH_NEON)
  244. #elif defined(GLM_FORCE_AVX2)
  245. # define GLM_ARCH (GLM_ARCH_AVX2)
  246. #elif defined(GLM_FORCE_AVX)
  247. # define GLM_ARCH (GLM_ARCH_AVX)
  248. #elif defined(GLM_FORCE_SSE42)
  249. # define GLM_ARCH (GLM_ARCH_SSE42)
  250. #elif defined(GLM_FORCE_SSE41)
  251. # define GLM_ARCH (GLM_ARCH_SSE41)
  252. #elif defined(GLM_FORCE_SSSE3)
  253. # define GLM_ARCH (GLM_ARCH_SSSE3)
  254. #elif defined(GLM_FORCE_SSE3)
  255. # define GLM_ARCH (GLM_ARCH_SSE3)
  256. #elif defined(GLM_FORCE_SSE2)
  257. # define GLM_ARCH (GLM_ARCH_SSE2)
  258. #elif defined(GLM_FORCE_SSE)
  259. # define GLM_ARCH (GLM_ARCH_SSE)
  260. #else
  261. # if defined(__AVX2__)
  262. # define GLM_ARCH (GLM_ARCH_AVX2)
  263. # elif defined(__AVX__)
  264. # define GLM_ARCH (GLM_ARCH_AVX)
  265. # elif defined(__SSE4_2__)
  266. # define GLM_ARCH (GLM_ARCH_SSE42)
  267. # elif defined(__SSE4_1__)
  268. # define GLM_ARCH (GLM_ARCH_SSE41)
  269. # elif defined(__SSSE3__)
  270. # define GLM_ARCH (GLM_ARCH_SSSE3)
  271. # elif defined(__SSE3__)
  272. # define GLM_ARCH (GLM_ARCH_SSE3)
  273. # elif defined(__SSE2__) || defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86_FP)
  274. # define GLM_ARCH (GLM_ARCH_SSE2)
  275. # elif defined(__i386__)
  276. # define GLM_ARCH (GLM_ARCH_X86)
  277. # elif defined(__ARM_NEON)
  278. # define GLM_ARCH (GLM_ARCH_ARM | GLM_ARCH_NEON)
  279. # elif defined(__arm__ ) || defined(_M_ARM)
  280. # define GLM_ARCH (GLM_ARCH_ARM)
  281. # elif defined(__mips__ )
  282. # define GLM_ARCH (GLM_ARCH_MIPS)
  283. # elif defined(__powerpc__ ) || defined(_M_PPC)
  284. # define GLM_ARCH (GLM_ARCH_PPC)
  285. # else
  286. # define GLM_ARCH (GLM_ARCH_UNKNOWN)
  287. # endif
  288. #endif
  289. #if GLM_ARCH & GLM_ARCH_AVX2_BIT
  290. # include <immintrin.h>
  291. #elif GLM_ARCH & GLM_ARCH_AVX_BIT
  292. # include <immintrin.h>
  293. #elif GLM_ARCH & GLM_ARCH_SSE42_BIT
  294. # if GLM_COMPILER & GLM_COMPILER_CLANG
  295. # include <popcntintrin.h>
  296. # endif
  297. # include <nmmintrin.h>
  298. #elif GLM_ARCH & GLM_ARCH_SSE41_BIT
  299. # include <smmintrin.h>
  300. #elif GLM_ARCH & GLM_ARCH_SSSE3_BIT
  301. # include <tmmintrin.h>
  302. #elif GLM_ARCH & GLM_ARCH_SSE3_BIT
  303. # include <pmmintrin.h>
  304. #elif GLM_ARCH & GLM_ARCH_SSE2_BIT
  305. # include <emmintrin.h>
  306. #endif//GLM_ARCH
  307. #if GLM_ARCH & GLM_ARCH_SSE2_BIT
  308. typedef __m128 glm_f32vec4;
  309. typedef __m128i glm_i32vec4;
  310. typedef __m128i glm_u32vec4;
  311. typedef __m128d glm_f64vec2;
  312. typedef __m128i glm_i64vec2;
  313. typedef __m128i glm_u64vec2;
  314. typedef glm_f32vec4 glm_vec4;
  315. typedef glm_i32vec4 glm_ivec4;
  316. typedef glm_u32vec4 glm_uvec4;
  317. typedef glm_f64vec2 glm_dvec2;
  318. #endif
  319. #if GLM_ARCH & GLM_ARCH_AVX_BIT
  320. typedef __m256d glm_f64vec4;
  321. typedef glm_f64vec4 glm_dvec4;
  322. #endif
  323. #if GLM_ARCH & GLM_ARCH_AVX2_BIT
  324. typedef __m256i glm_i64vec4;
  325. typedef __m256i glm_u64vec4;
  326. #endif