platform.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. Copyright (c) 2013 Daniele Bartolini, Michele Rossi
  3. Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
  4. Permission is hereby granted, free of charge, to any person
  5. obtaining a copy of this software and associated documentation
  6. files (the "Software"), to deal in the Software without
  7. restriction, including without limitation the rights to use,
  8. copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the
  10. Software is furnished to do so, subject to the following
  11. conditions:
  12. The above copyright notice and this permission notice shall be
  13. included in all copies or substantial portions of the Software.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16. OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  18. HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. // Adapted from Branimir Karadžić's platform.h (https://github.com/bkaradzic/bx)
  24. #pragma once
  25. #define CROWN_VERSION_MAJOR "0"
  26. #define CROWN_VERSION_MINOR "1"
  27. #define CROWN_VERSION_MICRO "13"
  28. #define CROWN_COMPILER_CLANG 0
  29. #define CROWN_COMPILER_GCC 0
  30. #define CROWN_COMPILER_MSVC 0
  31. #define CROWN_PLATFORM_ANDROID 0
  32. #define CROWN_PLATFORM_IOS 0
  33. #define CROWN_PLATFORM_LINUX 0
  34. #define CROWN_PLATFORM_OSX 0
  35. #define CROWN_PLATFORM_WINDOWS 0
  36. #define CROWN_CPU_ARM 0
  37. #define CROWN_CPU_JIT 0
  38. #define CROWN_CPU_MIPS 0
  39. #define CROWN_CPU_PPC 0
  40. #define CROWN_CPU_X86 0
  41. #define CROWN_ARCH_32BIT 0
  42. #define CROWN_ARCH_64BIT 0
  43. #define CROWN_CPU_ENDIAN_BIG 0
  44. #define CROWN_CPU_ENDIAN_LITTLE 0
  45. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Compilers
  46. #if defined(_MSC_VER)
  47. #undef CROWN_COMPILER_MSVC
  48. #define CROWN_COMPILER_MSVC 1
  49. #elif defined(__clang__)
  50. // clang defines __GNUC__
  51. #undef CROWN_COMPILER_CLANG
  52. #define CROWN_COMPILER_CLANG 1
  53. #elif defined(__GNUC__)
  54. #undef CROWN_COMPILER_GCC
  55. #define CROWN_COMPILER_GCC 1
  56. #else
  57. #error "CROWN_COMPILER_* is not defined!"
  58. #endif
  59. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Operating_Systems
  60. #if defined(_WIN32) || defined(_WIN64)
  61. #undef CROWN_PLATFORM_WINDOWS
  62. // http://msdn.microsoft.com/en-us/library/6sehtctf.aspx
  63. #if !defined(WINVER) && !defined(_WIN32_WINNT)
  64. // Windows Server 2003 with SP1, Windows XP with SP2 and above
  65. #define WINVER 0x0502
  66. #define _WIN32_WINNT 0x0502
  67. #endif // !defined(WINVER) && !defined(_WIN32_WINNT)
  68. #define CROWN_PLATFORM_WINDOWS 1
  69. #elif defined(__ANDROID__)
  70. // Android compiler defines __linux__
  71. #undef CROWN_PLATFORM_ANDROID
  72. #define CROWN_PLATFORM_ANDROID 1
  73. #elif defined(__linux__)
  74. #undef CROWN_PLATFORM_LINUX
  75. #define CROWN_PLATFORM_LINUX 1
  76. #elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__)
  77. #undef CROWN_PLATFORM_IOS
  78. #define CROWN_PLATFORM_IOS 1
  79. #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
  80. #undef CROWN_PLATFORM_OSX
  81. #define CROWN_PLATFORM_OSX 1
  82. #else
  83. # error "CROWN_PLATFORM_* is not defined!"
  84. #endif
  85. #define CROWN_PLATFORM_POSIX (CROWN_PLATFORM_ANDROID \
  86. || CROWN_PLATFORM_IOS \
  87. || CROWN_PLATFORM_LINUX \
  88. || CROWN_PLATFORM_OSX)
  89. // http://sourceforge.net/apps/mediawiki/predef/index.php?title=Architectures
  90. #if defined(__arm__)
  91. #undef CROWN_CPU_ARM
  92. #define CROWN_CPU_ARM 1
  93. #define CROWN_CACHE_LINE_SIZE 64
  94. #elif defined(__MIPSEL__) || defined(__mips_isa_rev) // defined(mips)
  95. #undef CROWN_CPU_MIPS
  96. #define CROWN_CPU_MIPS 1
  97. #define CROWN_CACHE_LINE_SIZE 64
  98. #elif defined(_M_PPC) || defined(__powerpc__) || defined(__powerpc64__)
  99. #undef CROWN_CPU_PPC
  100. #define CROWN_CPU_PPC 1
  101. #define CROWN_CACHE_LINE_SIZE 128
  102. #elif defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__x86_64__)
  103. #undef CROWN_CPU_X86
  104. #define CROWN_CPU_X86 1
  105. #define CROWN_CACHE_LINE_SIZE 64
  106. #else // PNaCl doesn't have CPU defined.
  107. #undef CROWN_CPU_JIT
  108. #define CROWN_CPU_JIT 1
  109. #define CROWN_CACHE_LINE_SIZE 64
  110. #endif //
  111. #if defined(__x86_64__) || defined(_M_X64) || defined(__64BIT__) || defined(__powerpc64__) || defined(__ppc64__)
  112. #undef CROWN_ARCH_64BIT
  113. #define CROWN_ARCH_64BIT 64
  114. #else
  115. #undef CROWN_ARCH_32BIT
  116. #define CROWN_ARCH_32BIT 32
  117. #endif //
  118. #if CROWN_CPU_PPC
  119. #undef CROWN_CPU_ENDIAN_BIG
  120. #define CROWN_CPU_ENDIAN_BIG 1
  121. #else
  122. #undef CROWN_CPU_ENDIAN_LITTLE
  123. #define CROWN_CPU_ENDIAN_LITTLE 1
  124. #endif
  125. #if CROWN_COMPILER_GCC
  126. #define CROWN_COMPILER_NAME "GCC"
  127. #elif CROWN_COMPILER_MSVC
  128. #define CROWN_COMPILER_NAME "MSVC"
  129. #endif
  130. #if CROWN_PLATFORM_ANDROID
  131. #define CROWN_PLATFORM_NAME "Android"
  132. #elif CROWN_PLATFORM_IOS
  133. #define CROWN_PLATFORM_NAME "iOS"
  134. #elif CROWN_PLATFORM_LINUX
  135. #define CROWN_PLATFORM_NAME "Linux"
  136. #elif CROWN_PLATFORM_OSX
  137. #define CROWN_PLATFORM_NAME "OSX"
  138. #elif CROWN_PLATFORM_WINDOWS
  139. #define CROWN_PLATFORM_NAME "Windows"
  140. #endif // CROWN_PLATFORM_
  141. #if CROWN_CPU_ARM
  142. #define CROWN_CPU_NAME "ARM"
  143. #elif CROWN_CPU_MIPS
  144. #define CROWN_CPU_NAME "MIPS"
  145. #elif CROWN_CPU_PPC
  146. #define CROWN_CPU_NAME "PowerPC"
  147. #elif CROWN_CPU_JIT
  148. #define CROWN_CPU_NAME "JIT-VM"
  149. #elif CROWN_CPU_X86
  150. #define CROWN_CPU_NAME "x86"
  151. #endif // CROWN_CPU_
  152. #if CROWN_ARCH_32BIT
  153. #define CROWN_ARCH_NAME "32-bit"
  154. #elif CROWN_ARCH_64BIT
  155. #define CROWN_ARCH_NAME "64-bit"
  156. #endif // CROWN_ARCH_