platform.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #pragma once
  2. // ya style breaks indentation in ifdef's and code becomes unreadable
  3. // clang-format off
  4. // What OS ?
  5. // our definition has the form _{osname}_
  6. #if defined(_WIN64)
  7. #define _win64_
  8. #define _win32_
  9. #elif defined(__WIN32__) || defined(_WIN32) // _WIN32 is also defined by the 64-bit compiler for backward compatibility
  10. #define _win32_
  11. #else
  12. #define _unix_
  13. #if defined(__sun__) || defined(sun) || defined(sparc) || defined(__sparc)
  14. #define _sun_
  15. #endif
  16. #if defined(__hpux__)
  17. #define _hpux_
  18. #endif
  19. #if defined(__linux__)
  20. // Stands for "Linux" in the means of Linux kernel (i. e. Android is included)
  21. #define _linux_
  22. #endif
  23. #if defined(__FreeBSD__)
  24. #define _freebsd_
  25. #endif
  26. #if defined(__CYGWIN__)
  27. #define _cygwin_
  28. #endif
  29. #if defined(__APPLE__)
  30. #define _darwin_
  31. #endif
  32. #if defined(__ANDROID__)
  33. #define _android_
  34. #endif
  35. #if defined(__EMSCRIPTEN__)
  36. #define _emscripten_
  37. #endif
  38. #endif
  39. #if defined(__IOS__)
  40. #define _ios_
  41. #endif
  42. #if defined(_linux_)
  43. #if defined(_musl_)
  44. // nothing to do
  45. #elif defined(_android_)
  46. // Please do not mix with android-based systems.
  47. // This definition describes Standard Library (libc) type.
  48. #define _bionic_
  49. #else
  50. #define _glibc_
  51. #endif
  52. #endif
  53. #if defined(_darwin_)
  54. #define unix
  55. #define __unix__
  56. #endif
  57. #if defined(_win32_) || defined(_win64_)
  58. #define _win_
  59. #endif
  60. #if defined(__arm__) || defined(__ARM__) || defined(__ARM_NEON) || defined(__aarch64__) || defined(_M_ARM)
  61. #if defined(__arm64) || defined(__arm64__) || defined(__aarch64__)
  62. #define _arm64_
  63. #else
  64. #define _arm32_
  65. #endif
  66. #endif
  67. #if defined(_arm64_) || defined(_arm32_)
  68. #define _arm_
  69. #endif
  70. /* __ia64__ and __x86_64__ - defined by GNU C.
  71. * _M_IA64, _M_X64, _M_AMD64 - defined by Visual Studio.
  72. *
  73. * Microsoft can define _M_IX86, _M_AMD64 (before Visual Studio 8)
  74. * or _M_X64 (starting in Visual Studio 8).
  75. */
  76. #if defined(__x86_64__) || defined(_M_X64)
  77. #define _x86_64_
  78. #endif
  79. #if defined(__i386__) || defined(_M_IX86)
  80. #define _i386_
  81. #endif
  82. #if defined(__ia64__) || defined(_M_IA64)
  83. #define _ia64_
  84. #endif
  85. #if defined(__powerpc__)
  86. #define _ppc_
  87. #endif
  88. #if defined(__powerpc64__)
  89. #define _ppc64_
  90. #endif
  91. #if defined(__wasm64__)
  92. #define _wasm64_
  93. #endif
  94. #if defined(__wasm32__)
  95. #define _wasm32_
  96. #endif
  97. #if !defined(sparc) && !defined(__sparc) && !defined(__hpux__) && !defined(__alpha__) && !defined(_ia64_) && !defined(_x86_64_) && !defined(_arm_) && !defined(_i386_) && !defined(_ppc_) && !defined(_ppc64_) && !defined(_wasm64_) && !defined(_wasm32_)
  98. #error "platform not defined, please, define one"
  99. #endif
  100. #if defined(_x86_64_) || defined(_i386_)
  101. #define _x86_
  102. #endif
  103. #if defined(__MIC__)
  104. #define _mic_
  105. #define _k1om_
  106. #endif
  107. // stdio or MessageBox
  108. #if defined(__CONSOLE__) || defined(_CONSOLE)
  109. #define _console_
  110. #endif
  111. #if (defined(_win_) && !defined(_console_))
  112. #define _windows_
  113. #elif !defined(_console_)
  114. #define _console_
  115. #endif
  116. #if defined(__SSE__) || defined(SSE_ENABLED)
  117. #define _sse_
  118. #endif
  119. #if defined(__SSE2__) || defined(SSE2_ENABLED)
  120. #define _sse2_
  121. #endif
  122. #if defined(__SSE3__) || defined(SSE3_ENABLED)
  123. #define _sse3_
  124. #endif
  125. #if defined(__SSSE3__) || defined(SSSE3_ENABLED)
  126. #define _ssse3_
  127. #endif
  128. #if defined(__SSE4_1__) || defined(SSE41_ENABLED)
  129. #define _sse4_1_
  130. #endif
  131. #if defined(__SSE4_2__) || defined(SSE42_ENABLED)
  132. #define _sse4_2_
  133. #endif
  134. #if defined(__POPCNT__) || defined(POPCNT_ENABLED)
  135. #define _popcnt_
  136. #endif
  137. #if defined(__PCLMUL__) || defined(PCLMUL_ENABLED)
  138. #define _pclmul_
  139. #endif
  140. #if defined(__AES__) || defined(AES_ENABLED)
  141. #define _aes_
  142. #endif
  143. #if defined(__AVX__) || defined(AVX_ENABLED)
  144. #define _avx_
  145. #endif
  146. #if defined(__AVX2__) || defined(AVX2_ENABLED)
  147. #define _avx2_
  148. #endif
  149. #if defined(__FMA__) || defined(FMA_ENABLED)
  150. #define _fma_
  151. #endif
  152. #if defined(__DLL__) || defined(_DLL)
  153. #define _dll_
  154. #endif
  155. // 16, 32 or 64
  156. #if defined(__sparc_v9__) || defined(_x86_64_) || defined(_ia64_) || defined(_arm64_) || defined(_ppc64_) || defined(_wasm64_)
  157. #define _64_
  158. #else
  159. #define _32_
  160. #endif
  161. /* All modern 64-bit Unix systems use scheme LP64 (long, pointers are 64-bit).
  162. * Microsoft uses a different scheme: LLP64 (long long, pointers are 64-bit).
  163. *
  164. * Scheme LP64 LLP64
  165. * char 8 8
  166. * short 16 16
  167. * int 32 32
  168. * long 64 32
  169. * long long 64 64
  170. * pointer 64 64
  171. */
  172. #if defined(_32_)
  173. #define SIZEOF_PTR 4
  174. #elif defined(_64_)
  175. #define SIZEOF_PTR 8
  176. #endif
  177. #define PLATFORM_DATA_ALIGN SIZEOF_PTR
  178. #if !defined(SIZEOF_PTR)
  179. #error todo
  180. #endif
  181. #define SIZEOF_CHAR 1
  182. #define SIZEOF_UNSIGNED_CHAR 1
  183. #define SIZEOF_SHORT 2
  184. #define SIZEOF_UNSIGNED_SHORT 2
  185. #define SIZEOF_INT 4
  186. #define SIZEOF_UNSIGNED_INT 4
  187. #if defined(_32_)
  188. #define SIZEOF_LONG 4
  189. #define SIZEOF_UNSIGNED_LONG 4
  190. #elif defined(_64_)
  191. #if defined(_win_)
  192. #define SIZEOF_LONG 4
  193. #define SIZEOF_UNSIGNED_LONG 4
  194. #else
  195. #define SIZEOF_LONG 8
  196. #define SIZEOF_UNSIGNED_LONG 8
  197. #endif // _win_
  198. #endif // _32_
  199. #if !defined(SIZEOF_LONG)
  200. #error todo
  201. #endif
  202. #define SIZEOF_LONG_LONG 8
  203. #define SIZEOF_UNSIGNED_LONG_LONG 8
  204. // clang-format on