9
3

platform.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. #define GLM_COMPILER_VC15_8 0x01000008
  57. #define GLM_COMPILER_VC15_9 0x01000009
  58. #define GLM_COMPILER_VC16 0x0100000A
  59. // GCC defines
  60. #define GLM_COMPILER_GCC 0x02000000
  61. #define GLM_COMPILER_GCC46 0x020000D0
  62. #define GLM_COMPILER_GCC47 0x020000E0
  63. #define GLM_COMPILER_GCC48 0x020000F0
  64. #define GLM_COMPILER_GCC49 0x02000100
  65. #define GLM_COMPILER_GCC5 0x02000200
  66. #define GLM_COMPILER_GCC6 0x02000300
  67. #define GLM_COMPILER_GCC7 0x02000400
  68. #define GLM_COMPILER_GCC8 0x02000500
  69. // CUDA
  70. #define GLM_COMPILER_CUDA 0x10000000
  71. #define GLM_COMPILER_CUDA75 0x10000001
  72. #define GLM_COMPILER_CUDA80 0x10000002
  73. #define GLM_COMPILER_CUDA90 0x10000004
  74. // SYCL
  75. #define GLM_COMPILER_SYCL 0x00300000
  76. // Clang
  77. #define GLM_COMPILER_CLANG 0x20000000
  78. #define GLM_COMPILER_CLANG34 0x20000050
  79. #define GLM_COMPILER_CLANG35 0x20000060
  80. #define GLM_COMPILER_CLANG36 0x20000070
  81. #define GLM_COMPILER_CLANG37 0x20000080
  82. #define GLM_COMPILER_CLANG38 0x20000090
  83. #define GLM_COMPILER_CLANG39 0x200000A0
  84. #define GLM_COMPILER_CLANG40 0x200000B0
  85. #define GLM_COMPILER_CLANG41 0x200000C0
  86. #define GLM_COMPILER_CLANG42 0x200000D0
  87. // Build model
  88. #define GLM_MODEL_32 0x00000010
  89. #define GLM_MODEL_64 0x00000020
  90. // Force generic C++ compiler
  91. #ifdef GLM_FORCE_COMPILER_UNKNOWN
  92. # define GLM_COMPILER GLM_COMPILER_UNKNOWN
  93. #elif defined(__INTEL_COMPILER)
  94. # if __INTEL_COMPILER >= 1700
  95. # define GLM_COMPILER GLM_COMPILER_INTEL17
  96. # elif __INTEL_COMPILER >= 1600
  97. # define GLM_COMPILER GLM_COMPILER_INTEL16
  98. # elif __INTEL_COMPILER >= 1500
  99. # define GLM_COMPILER GLM_COMPILER_INTEL15
  100. # elif __INTEL_COMPILER >= 1400
  101. # define GLM_COMPILER GLM_COMPILER_INTEL14
  102. # elif __INTEL_COMPILER < 1400
  103. # error "GLM requires ICC 2013 SP1 or newer"
  104. # endif
  105. // CUDA
  106. #elif defined(__CUDACC__)
  107. # if !defined(CUDA_VERSION) && !defined(GLM_FORCE_CUDA)
  108. # include <cuda.h> // make sure version is defined since nvcc does not define it itself!
  109. # endif
  110. # if CUDA_VERSION >= 8000
  111. # define GLM_COMPILER GLM_COMPILER_CUDA80
  112. # elif CUDA_VERSION >= 7500
  113. # define GLM_COMPILER GLM_COMPILER_CUDA75
  114. # elif CUDA_VERSION >= 7000
  115. # define GLM_COMPILER GLM_COMPILER_CUDA70
  116. # elif CUDA_VERSION < 7000
  117. # error "GLM requires CUDA 7.0 or higher"
  118. # endif
  119. // SYCL
  120. #elif defined(__SYCL_DEVICE_ONLY__)
  121. # define GLM_COMPILER GLM_COMPILER_SYCL
  122. // Clang
  123. #elif defined(__clang__)
  124. # if defined(__apple_build_version__)
  125. # if (__clang_major__ < 6)
  126. # error "GLM requires Clang 3.4 / Apple Clang 6.0 or higher"
  127. # elif __clang_major__ == 6 && __clang_minor__ == 0
  128. # define GLM_COMPILER GLM_COMPILER_CLANG35
  129. # elif __clang_major__ == 6 && __clang_minor__ >= 1
  130. # define GLM_COMPILER GLM_COMPILER_CLANG36
  131. # elif __clang_major__ >= 7
  132. # define GLM_COMPILER GLM_COMPILER_CLANG37
  133. # endif
  134. # else
  135. # if ((__clang_major__ == 3) && (__clang_minor__ < 4)) || (__clang_major__ < 3)
  136. # error "GLM requires Clang 3.4 or higher"
  137. # elif __clang_major__ == 3 && __clang_minor__ == 4
  138. # define GLM_COMPILER GLM_COMPILER_CLANG34
  139. # elif __clang_major__ == 3 && __clang_minor__ == 5
  140. # define GLM_COMPILER GLM_COMPILER_CLANG35
  141. # elif __clang_major__ == 3 && __clang_minor__ == 6
  142. # define GLM_COMPILER GLM_COMPILER_CLANG36
  143. # elif __clang_major__ == 3 && __clang_minor__ == 7
  144. # define GLM_COMPILER GLM_COMPILER_CLANG37
  145. # elif __clang_major__ == 3 && __clang_minor__ == 8
  146. # define GLM_COMPILER GLM_COMPILER_CLANG38
  147. # elif __clang_major__ == 3 && __clang_minor__ >= 9
  148. # define GLM_COMPILER GLM_COMPILER_CLANG39
  149. # elif __clang_major__ == 4 && __clang_minor__ == 0
  150. # define GLM_COMPILER GLM_COMPILER_CLANG40
  151. # elif __clang_major__ == 4 && __clang_minor__ == 1
  152. # define GLM_COMPILER GLM_COMPILER_CLANG41
  153. # elif __clang_major__ == 4 && __clang_minor__ >= 2
  154. # define GLM_COMPILER GLM_COMPILER_CLANG42
  155. # elif __clang_major__ >= 4
  156. # define GLM_COMPILER GLM_COMPILER_CLANG42
  157. # endif
  158. # endif
  159. // Visual C++
  160. #elif defined(_MSC_VER)
  161. # if _MSC_VER >= 1920
  162. # define GLM_COMPILER GLM_COMPILER_VC16
  163. # elif _MSC_VER >= 1916
  164. # define GLM_COMPILER GLM_COMPILER_VC15_9
  165. # elif _MSC_VER >= 1915
  166. # define GLM_COMPILER GLM_COMPILER_VC15_8
  167. # elif _MSC_VER >= 1914
  168. # define GLM_COMPILER GLM_COMPILER_VC15_7
  169. # elif _MSC_VER >= 1913
  170. # define GLM_COMPILER GLM_COMPILER_VC15_6
  171. # elif _MSC_VER >= 1912
  172. # define GLM_COMPILER GLM_COMPILER_VC15_5
  173. # elif _MSC_VER >= 1911
  174. # define GLM_COMPILER GLM_COMPILER_VC15_3
  175. # elif _MSC_VER >= 1910
  176. # define GLM_COMPILER GLM_COMPILER_VC15
  177. # elif _MSC_VER >= 1900
  178. # define GLM_COMPILER GLM_COMPILER_VC14
  179. # elif _MSC_VER >= 1800
  180. # define GLM_COMPILER GLM_COMPILER_VC12
  181. # elif _MSC_VER < 1800
  182. # error "GLM requires Visual C++ 12 - 2013 or higher"
  183. # endif//_MSC_VER
  184. // G++
  185. #elif defined(__GNUC__) || defined(__MINGW32__)
  186. # if __GNUC__ >= 8
  187. # define GLM_COMPILER GLM_COMPILER_GCC8
  188. # elif __GNUC__ >= 7
  189. # define GLM_COMPILER GLM_COMPILER_GCC7
  190. # elif __GNUC__ >= 6
  191. # define GLM_COMPILER GLM_COMPILER_GCC6
  192. # elif __GNUC__ >= 5
  193. # define GLM_COMPILER GLM_COMPILER_GCC5
  194. # elif __GNUC__ == 4 && __GNUC_MINOR__ >= 9
  195. # define GLM_COMPILER GLM_COMPILER_GCC49
  196. # elif __GNUC__ == 4 && __GNUC_MINOR__ >= 8
  197. # define GLM_COMPILER GLM_COMPILER_GCC48
  198. # elif __GNUC__ == 4 && __GNUC_MINOR__ >= 7
  199. # define GLM_COMPILER GLM_COMPILER_GCC47
  200. # elif __GNUC__ == 4 && __GNUC_MINOR__ >= 6
  201. # define GLM_COMPILER GLM_COMPILER_GCC46
  202. # elif ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) || (__GNUC__ < 4)
  203. # error "GLM requires GCC 4.6 or higher"
  204. # endif
  205. #else
  206. # define GLM_COMPILER GLM_COMPILER_UNKNOWN
  207. #endif
  208. #ifndef GLM_COMPILER
  209. # error "GLM_COMPILER undefined, your compiler may not be supported by GLM. Add #define GLM_COMPILER 0 to ignore this message."
  210. #endif//GLM_COMPILER
  211. ///////////////////////////////////////////////////////////////////////////////////
  212. // Instruction sets
  213. // User defines: GLM_FORCE_PURE GLM_FORCE_INTRINSICS GLM_FORCE_SSE2 GLM_FORCE_SSE3 GLM_FORCE_AVX GLM_FORCE_AVX2 GLM_FORCE_AVX2
  214. #define GLM_ARCH_MIPS_BIT (0x10000000)
  215. #define GLM_ARCH_PPC_BIT (0x20000000)
  216. #define GLM_ARCH_ARM_BIT (0x40000000)
  217. #define GLM_ARCH_ARMV8_BIT (0x01000000)
  218. #define GLM_ARCH_X86_BIT (0x80000000)
  219. #define GLM_ARCH_SIMD_BIT (0x00001000)
  220. #define GLM_ARCH_NEON_BIT (0x00000001)
  221. #define GLM_ARCH_SSE_BIT (0x00000002)
  222. #define GLM_ARCH_SSE2_BIT (0x00000004)
  223. #define GLM_ARCH_SSE3_BIT (0x00000008)
  224. #define GLM_ARCH_SSSE3_BIT (0x00000010)
  225. #define GLM_ARCH_SSE41_BIT (0x00000020)
  226. #define GLM_ARCH_SSE42_BIT (0x00000040)
  227. #define GLM_ARCH_AVX_BIT (0x00000080)
  228. #define GLM_ARCH_AVX2_BIT (0x00000100)
  229. #define GLM_ARCH_UNKNOWN (0)
  230. #define GLM_ARCH_X86 (GLM_ARCH_X86_BIT)
  231. #define GLM_ARCH_SSE (GLM_ARCH_SSE_BIT | GLM_ARCH_SIMD_BIT | GLM_ARCH_X86)
  232. #define GLM_ARCH_SSE2 (GLM_ARCH_SSE2_BIT | GLM_ARCH_SSE)
  233. #define GLM_ARCH_SSE3 (GLM_ARCH_SSE3_BIT | GLM_ARCH_SSE2)
  234. #define GLM_ARCH_SSSE3 (GLM_ARCH_SSSE3_BIT | GLM_ARCH_SSE3)
  235. #define GLM_ARCH_SSE41 (GLM_ARCH_SSE41_BIT | GLM_ARCH_SSSE3)
  236. #define GLM_ARCH_SSE42 (GLM_ARCH_SSE42_BIT | GLM_ARCH_SSE41)
  237. #define GLM_ARCH_AVX (GLM_ARCH_AVX_BIT | GLM_ARCH_SSE42)
  238. #define GLM_ARCH_AVX2 (GLM_ARCH_AVX2_BIT | GLM_ARCH_AVX)
  239. #define GLM_ARCH_ARM (GLM_ARCH_ARM_BIT)
  240. #define GLM_ARCH_ARMV8 (GLM_ARCH_NEON_BIT | GLM_ARCH_SIMD_BIT | GLM_ARCH_ARM | GLM_ARCH_ARMV8_BIT)
  241. #define GLM_ARCH_NEON (GLM_ARCH_NEON_BIT | GLM_ARCH_SIMD_BIT | GLM_ARCH_ARM)
  242. #define GLM_ARCH_MIPS (GLM_ARCH_MIPS_BIT)
  243. #define GLM_ARCH_PPC (GLM_ARCH_PPC_BIT)
  244. #if defined(GLM_FORCE_ARCH_UNKNOWN) || defined(GLM_FORCE_PURE)
  245. # define GLM_ARCH GLM_ARCH_UNKNOWN
  246. #elif defined(GLM_FORCE_NEON)
  247. # if __ARM_ARCH >= 8
  248. # define GLM_ARCH (GLM_ARCH_ARMV8)
  249. # else
  250. # define GLM_ARCH (GLM_ARCH_NEON)
  251. # endif
  252. # define GLM_FORCE_INTRINSICS
  253. #elif defined(GLM_FORCE_AVX2)
  254. # define GLM_ARCH (GLM_ARCH_AVX2)
  255. # define GLM_FORCE_INTRINSICS
  256. #elif defined(GLM_FORCE_AVX)
  257. # define GLM_ARCH (GLM_ARCH_AVX)
  258. # define GLM_FORCE_INTRINSICS
  259. #elif defined(GLM_FORCE_SSE42)
  260. # define GLM_ARCH (GLM_ARCH_SSE42)
  261. # define GLM_FORCE_INTRINSICS
  262. #elif defined(GLM_FORCE_SSE41)
  263. # define GLM_ARCH (GLM_ARCH_SSE41)
  264. # define GLM_FORCE_INTRINSICS
  265. #elif defined(GLM_FORCE_SSSE3)
  266. # define GLM_ARCH (GLM_ARCH_SSSE3)
  267. # define GLM_FORCE_INTRINSICS
  268. #elif defined(GLM_FORCE_SSE3)
  269. # define GLM_ARCH (GLM_ARCH_SSE3)
  270. # define GLM_FORCE_INTRINSICS
  271. #elif defined(GLM_FORCE_SSE2)
  272. # define GLM_ARCH (GLM_ARCH_SSE2)
  273. # define GLM_FORCE_INTRINSICS
  274. #elif defined(GLM_FORCE_SSE)
  275. # define GLM_ARCH (GLM_ARCH_SSE)
  276. # define GLM_FORCE_INTRINSICS
  277. #elif defined(GLM_FORCE_INTRINSICS) && !defined(GLM_FORCE_XYZW_ONLY)
  278. # if defined(__AVX2__)
  279. # define GLM_ARCH (GLM_ARCH_AVX2)
  280. # elif defined(__AVX__)
  281. # define GLM_ARCH (GLM_ARCH_AVX)
  282. # elif defined(__SSE4_2__)
  283. # define GLM_ARCH (GLM_ARCH_SSE42)
  284. # elif defined(__SSE4_1__)
  285. # define GLM_ARCH (GLM_ARCH_SSE41)
  286. # elif defined(__SSSE3__)
  287. # define GLM_ARCH (GLM_ARCH_SSSE3)
  288. # elif defined(__SSE3__)
  289. # define GLM_ARCH (GLM_ARCH_SSE3)
  290. # elif defined(__SSE2__) || defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86_FP)
  291. # define GLM_ARCH (GLM_ARCH_SSE2)
  292. # elif defined(__i386__)
  293. # define GLM_ARCH (GLM_ARCH_X86)
  294. # elif defined(__ARM_ARCH) && (__ARM_ARCH >= 8)
  295. # define GLM_ARCH (GLM_ARCH_ARMV8)
  296. # elif defined(__ARM_NEON)
  297. # define GLM_ARCH (GLM_ARCH_ARM | GLM_ARCH_NEON)
  298. # elif defined(__arm__ ) || defined(_M_ARM)
  299. # define GLM_ARCH (GLM_ARCH_ARM)
  300. # elif defined(__mips__ )
  301. # define GLM_ARCH (GLM_ARCH_MIPS)
  302. # elif defined(__powerpc__ ) || defined(_M_PPC)
  303. # define GLM_ARCH (GLM_ARCH_PPC)
  304. # else
  305. # define GLM_ARCH (GLM_ARCH_UNKNOWN)
  306. # endif
  307. #else
  308. # if defined(__x86_64__) || defined(_M_X64) || defined(_M_IX86) || defined(__i386__)
  309. # define GLM_ARCH (GLM_ARCH_X86)
  310. # elif defined(__arm__) || defined(_M_ARM)
  311. # define GLM_ARCH (GLM_ARCH_ARM)
  312. # elif defined(__powerpc__) || defined(_M_PPC)
  313. # define GLM_ARCH (GLM_ARCH_PPC)
  314. # elif defined(__mips__)
  315. # define GLM_ARCH (GLM_ARCH_MIPS)
  316. # else
  317. # define GLM_ARCH (GLM_ARCH_UNKNOWN)
  318. # endif
  319. #endif
  320. #if GLM_ARCH & GLM_ARCH_AVX2_BIT
  321. # include <immintrin.h>
  322. #elif GLM_ARCH & GLM_ARCH_AVX_BIT
  323. # include <immintrin.h>
  324. #elif GLM_ARCH & GLM_ARCH_SSE42_BIT
  325. # if GLM_COMPILER & GLM_COMPILER_CLANG
  326. # include <popcntintrin.h>
  327. # endif
  328. # include <nmmintrin.h>
  329. #elif GLM_ARCH & GLM_ARCH_SSE41_BIT
  330. # include <smmintrin.h>
  331. #elif GLM_ARCH & GLM_ARCH_SSSE3_BIT
  332. # include <tmmintrin.h>
  333. #elif GLM_ARCH & GLM_ARCH_SSE3_BIT
  334. # include <pmmintrin.h>
  335. #elif GLM_ARCH & GLM_ARCH_SSE2_BIT
  336. # include <emmintrin.h>
  337. #elif GLM_ARCH & GLM_ARCH_NEON_BIT
  338. # include "neon.h"
  339. #endif//GLM_ARCH
  340. #if GLM_ARCH & GLM_ARCH_SSE2_BIT
  341. typedef __m128 glm_f32vec4;
  342. typedef __m128i glm_i32vec4;
  343. typedef __m128i glm_u32vec4;
  344. typedef __m128d glm_f64vec2;
  345. typedef __m128i glm_i64vec2;
  346. typedef __m128i glm_u64vec2;
  347. typedef glm_f32vec4 glm_vec4;
  348. typedef glm_i32vec4 glm_ivec4;
  349. typedef glm_u32vec4 glm_uvec4;
  350. typedef glm_f64vec2 glm_dvec2;
  351. #endif
  352. #if GLM_ARCH & GLM_ARCH_AVX_BIT
  353. typedef __m256d glm_f64vec4;
  354. typedef glm_f64vec4 glm_dvec4;
  355. #endif
  356. #if GLM_ARCH & GLM_ARCH_AVX2_BIT
  357. typedef __m256i glm_i64vec4;
  358. typedef __m256i glm_u64vec4;
  359. #endif
  360. #if GLM_ARCH & GLM_ARCH_NEON_BIT
  361. typedef float32x4_t glm_f32vec4;
  362. typedef int32x4_t glm_i32vec4;
  363. typedef uint32x4_t glm_u32vec4;
  364. #endif