port.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* Copyright 2016 Google Inc. All Rights Reserved.
  2. Distributed under MIT license.
  3. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
  4. */
  5. /* Macros for compiler / platform specific API declarations. */
  6. #ifndef BROTLI_COMMON_PORT_H_
  7. #define BROTLI_COMMON_PORT_H_
  8. /* The following macros were borrowed from https://github.com/nemequ/hedley
  9. * with permission of original author - Evan Nemerson <[email protected]> */
  10. /* >>> >>> >>> hedley macros */
  11. #define BROTLI_MAKE_VERSION(major, minor, revision) \
  12. (((major) * 1000000) + ((minor) * 1000) + (revision))
  13. #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__)
  14. #define BROTLI_GNUC_VERSION \
  15. BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
  16. #elif defined(__GNUC__)
  17. #define BROTLI_GNUC_VERSION BROTLI_MAKE_VERSION(__GNUC__, __GNUC_MINOR__, 0)
  18. #endif
  19. #if defined(BROTLI_GNUC_VERSION)
  20. #define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) \
  21. (BROTLI_GNUC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  22. #else
  23. #define BROTLI_GNUC_VERSION_CHECK(major, minor, patch) (0)
  24. #endif
  25. #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000)
  26. #define BROTLI_MSVC_VERSION \
  27. BROTLI_MAKE_VERSION((_MSC_FULL_VER / 10000000), \
  28. (_MSC_FULL_VER % 10000000) / 100000, \
  29. (_MSC_FULL_VER % 100000) / 100)
  30. #elif defined(_MSC_FULL_VER)
  31. #define BROTLI_MSVC_VERSION \
  32. BROTLI_MAKE_VERSION((_MSC_FULL_VER / 1000000), \
  33. (_MSC_FULL_VER % 1000000) / 10000, \
  34. (_MSC_FULL_VER % 10000) / 10)
  35. #elif defined(_MSC_VER)
  36. #define BROTLI_MSVC_VERSION \
  37. BROTLI_MAKE_VERSION(_MSC_VER / 100, _MSC_VER % 100, 0)
  38. #endif
  39. #if !defined(_MSC_VER)
  40. #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) (0)
  41. #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
  42. #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
  43. (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch)))
  44. #elif defined(_MSC_VER) && (_MSC_VER >= 1200)
  45. #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
  46. (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch)))
  47. #else
  48. #define BROTLI_MSVC_VERSION_CHECK(major, minor, patch) \
  49. (_MSC_VER >= ((major * 100) + (minor)))
  50. #endif
  51. #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE)
  52. #define BROTLI_INTEL_VERSION \
  53. BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, \
  54. __INTEL_COMPILER % 100, \
  55. __INTEL_COMPILER_UPDATE)
  56. #elif defined(__INTEL_COMPILER)
  57. #define BROTLI_INTEL_VERSION \
  58. BROTLI_MAKE_VERSION(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0)
  59. #endif
  60. #if defined(BROTLI_INTEL_VERSION)
  61. #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) \
  62. (BROTLI_INTEL_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  63. #else
  64. #define BROTLI_INTEL_VERSION_CHECK(major, minor, patch) (0)
  65. #endif
  66. #if defined(__PGI) && \
  67. defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__)
  68. #define BROTLI_PGI_VERSION \
  69. BROTLI_MAKE_VERSION(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__)
  70. #endif
  71. #if defined(BROTLI_PGI_VERSION)
  72. #define BROTLI_PGI_VERSION_CHECK(major, minor, patch) \
  73. (BROTLI_PGI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  74. #else
  75. #define BROTLI_PGI_VERSION_CHECK(major, minor, patch) (0)
  76. #endif
  77. #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000)
  78. #define BROTLI_SUNPRO_VERSION \
  79. BROTLI_MAKE_VERSION( \
  80. (((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), \
  81. (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), \
  82. (__SUNPRO_C & 0xf) * 10)
  83. #elif defined(__SUNPRO_C)
  84. #define BROTLI_SUNPRO_VERSION \
  85. BROTLI_MAKE_VERSION((__SUNPRO_C >> 8) & 0xf, \
  86. (__SUNPRO_C >> 4) & 0xf, \
  87. (__SUNPRO_C) & 0xf)
  88. #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000)
  89. #define BROTLI_SUNPRO_VERSION \
  90. BROTLI_MAKE_VERSION( \
  91. (((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), \
  92. (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), \
  93. (__SUNPRO_CC & 0xf) * 10)
  94. #elif defined(__SUNPRO_CC)
  95. #define BROTLI_SUNPRO_VERSION \
  96. BROTLI_MAKE_VERSION((__SUNPRO_CC >> 8) & 0xf, \
  97. (__SUNPRO_CC >> 4) & 0xf, \
  98. (__SUNPRO_CC) & 0xf)
  99. #endif
  100. #if defined(BROTLI_SUNPRO_VERSION)
  101. #define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) \
  102. (BROTLI_SUNPRO_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  103. #else
  104. #define BROTLI_SUNPRO_VERSION_CHECK(major, minor, patch) (0)
  105. #endif
  106. #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION)
  107. #define BROTLI_ARM_VERSION \
  108. BROTLI_MAKE_VERSION((__ARMCOMPILER_VERSION / 1000000), \
  109. (__ARMCOMPILER_VERSION % 1000000) / 10000, \
  110. (__ARMCOMPILER_VERSION % 10000) / 100)
  111. #elif defined(__CC_ARM) && defined(__ARMCC_VERSION)
  112. #define BROTLI_ARM_VERSION \
  113. BROTLI_MAKE_VERSION((__ARMCC_VERSION / 1000000), \
  114. (__ARMCC_VERSION % 1000000) / 10000, \
  115. (__ARMCC_VERSION % 10000) / 100)
  116. #endif
  117. #if defined(BROTLI_ARM_VERSION)
  118. #define BROTLI_ARM_VERSION_CHECK(major, minor, patch) \
  119. (BROTLI_ARM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  120. #else
  121. #define BROTLI_ARM_VERSION_CHECK(major, minor, patch) (0)
  122. #endif
  123. #if defined(__ibmxl__)
  124. #define BROTLI_IBM_VERSION \
  125. BROTLI_MAKE_VERSION(__ibmxl_version__, \
  126. __ibmxl_release__, \
  127. __ibmxl_modification__)
  128. #elif defined(__xlC__) && defined(__xlC_ver__)
  129. #define BROTLI_IBM_VERSION \
  130. BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff)
  131. #elif defined(__xlC__)
  132. #define BROTLI_IBM_VERSION BROTLI_MAKE_VERSION(__xlC__ >> 8, __xlC__ & 0xff, 0)
  133. #endif
  134. #if defined(BROTLI_IBM_VERSION)
  135. #define BROTLI_IBM_VERSION_CHECK(major, minor, patch) \
  136. (BROTLI_IBM_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  137. #else
  138. #define BROTLI_IBM_VERSION_CHECK(major, minor, patch) (0)
  139. #endif
  140. #if defined(__TI_COMPILER_VERSION__)
  141. #define BROTLI_TI_VERSION \
  142. BROTLI_MAKE_VERSION((__TI_COMPILER_VERSION__ / 1000000), \
  143. (__TI_COMPILER_VERSION__ % 1000000) / 1000, \
  144. (__TI_COMPILER_VERSION__ % 1000))
  145. #endif
  146. #if defined(BROTLI_TI_VERSION)
  147. #define BROTLI_TI_VERSION_CHECK(major, minor, patch) \
  148. (BROTLI_TI_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  149. #else
  150. #define BROTLI_TI_VERSION_CHECK(major, minor, patch) (0)
  151. #endif
  152. #if defined(__IAR_SYSTEMS_ICC__)
  153. #if __VER__ > 1000
  154. #define BROTLI_IAR_VERSION \
  155. BROTLI_MAKE_VERSION((__VER__ / 1000000), \
  156. (__VER__ / 1000) % 1000, \
  157. (__VER__ % 1000))
  158. #else
  159. #define BROTLI_IAR_VERSION BROTLI_MAKE_VERSION(VER / 100, __VER__ % 100, 0)
  160. #endif
  161. #endif
  162. #if defined(BROTLI_IAR_VERSION)
  163. #define BROTLI_IAR_VERSION_CHECK(major, minor, patch) \
  164. (BROTLI_IAR_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  165. #else
  166. #define BROTLI_IAR_VERSION_CHECK(major, minor, patch) (0)
  167. #endif
  168. #if defined(__TINYC__)
  169. #define BROTLI_TINYC_VERSION \
  170. BROTLI_MAKE_VERSION(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100)
  171. #endif
  172. #if defined(BROTLI_TINYC_VERSION)
  173. #define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) \
  174. (BROTLI_TINYC_VERSION >= BROTLI_MAKE_VERSION(major, minor, patch))
  175. #else
  176. #define BROTLI_TINYC_VERSION_CHECK(major, minor, patch) (0)
  177. #endif
  178. #if defined(__has_attribute)
  179. #define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
  180. __has_attribute(attribute)
  181. #else
  182. #define BROTLI_GNUC_HAS_ATTRIBUTE(attribute, major, minor, patch) \
  183. BROTLI_GNUC_VERSION_CHECK(major, minor, patch)
  184. #endif
  185. #if defined(__has_builtin)
  186. #define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \
  187. __has_builtin(builtin)
  188. #else
  189. #define BROTLI_GNUC_HAS_BUILTIN(builtin, major, minor, patch) \
  190. BROTLI_GNUC_VERSION_CHECK(major, minor, patch)
  191. #endif
  192. #if defined(__has_feature)
  193. #define BROTLI_HAS_FEATURE(feature) __has_feature(feature)
  194. #else
  195. #define BROTLI_HAS_FEATURE(feature) (0)
  196. #endif
  197. #if defined(_WIN32) || defined(__CYGWIN__)
  198. #define BROTLI_PUBLIC
  199. #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
  200. BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
  201. BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
  202. BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
  203. BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
  204. BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
  205. (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
  206. defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
  207. #define BROTLI_PUBLIC __attribute__ ((visibility ("default")))
  208. #else
  209. #define BROTLI_PUBLIC
  210. #endif
  211. /* BROTLI_INTERNAL could be defined to override visibility, e.g. for tests. */
  212. #if !defined(BROTLI_INTERNAL)
  213. #if defined(_WIN32) || defined(__CYGWIN__)
  214. #define BROTLI_INTERNAL
  215. #elif BROTLI_GNUC_VERSION_CHECK(3, 3, 0) || \
  216. BROTLI_TI_VERSION_CHECK(8, 0, 0) || \
  217. BROTLI_INTEL_VERSION_CHECK(16, 0, 0) || \
  218. BROTLI_ARM_VERSION_CHECK(4, 1, 0) || \
  219. BROTLI_IBM_VERSION_CHECK(13, 1, 0) || \
  220. BROTLI_SUNPRO_VERSION_CHECK(5, 11, 0) || \
  221. (BROTLI_TI_VERSION_CHECK(7, 3, 0) && \
  222. defined(__TI_GNU_ATTRIBUTE_SUPPORT__) && defined(__TI_EABI__))
  223. #define BROTLI_INTERNAL __attribute__ ((visibility ("hidden")))
  224. #else
  225. #define BROTLI_INTERNAL
  226. #endif
  227. #endif
  228. #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
  229. !defined(__STDC_NO_VLA__) && !defined(__cplusplus) && \
  230. !defined(__PGI) && !defined(__PGIC__) && !defined(__TINYC__) && \
  231. !defined(__clang__)
  232. #define BROTLI_ARRAY_PARAM(name) (name)
  233. #else
  234. #define BROTLI_ARRAY_PARAM(name)
  235. #endif
  236. /* <<< <<< <<< end of hedley macros. */
  237. #if defined(BROTLI_SHARED_COMPILATION)
  238. #if defined(_WIN32)
  239. #if defined(BROTLICOMMON_SHARED_COMPILATION)
  240. #define BROTLI_COMMON_API __declspec(dllexport)
  241. #else
  242. #define BROTLI_COMMON_API __declspec(dllimport)
  243. #endif /* BROTLICOMMON_SHARED_COMPILATION */
  244. #if defined(BROTLIDEC_SHARED_COMPILATION)
  245. #define BROTLI_DEC_API __declspec(dllexport)
  246. #else
  247. #define BROTLI_DEC_API __declspec(dllimport)
  248. #endif /* BROTLIDEC_SHARED_COMPILATION */
  249. #if defined(BROTLIENC_SHARED_COMPILATION)
  250. #define BROTLI_ENC_API __declspec(dllexport)
  251. #else
  252. #define BROTLI_ENC_API __declspec(dllimport)
  253. #endif /* BROTLIENC_SHARED_COMPILATION */
  254. #else /* _WIN32 */
  255. #define BROTLI_COMMON_API BROTLI_PUBLIC
  256. #define BROTLI_DEC_API BROTLI_PUBLIC
  257. #define BROTLI_ENC_API BROTLI_PUBLIC
  258. #endif /* _WIN32 */
  259. #else /* BROTLI_SHARED_COMPILATION */
  260. #define BROTLI_COMMON_API
  261. #define BROTLI_DEC_API
  262. #define BROTLI_ENC_API
  263. #endif
  264. #if defined(BROTLI_BUILD_ENC_EXTRA_API)
  265. #define BROTLI_ENC_EXTRA_API BROTLI_ENC_API
  266. #else
  267. #define BROTLI_ENC_EXTRA_API BROTLI_INTERNAL
  268. #endif
  269. #endif /* BROTLI_COMMON_PORT_H_ */