2
0

port.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 features and build options. */
  6. #ifndef BROTLI_COMMON_PORT_H_
  7. #define BROTLI_COMMON_PORT_H_
  8. /* Compatibility with non-clang compilers. */
  9. #ifndef __has_builtin
  10. #define __has_builtin(x) 0
  11. #endif
  12. #ifndef __has_attribute
  13. #define __has_attribute(x) 0
  14. #endif
  15. #ifndef __has_feature
  16. #define __has_feature(x) 0
  17. #endif
  18. #if defined(__GNUC__) && defined(__GNUC_MINOR__)
  19. #define BROTLI_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
  20. #else
  21. #define BROTLI_GCC_VERSION 0
  22. #endif
  23. #if defined(__ICC)
  24. #define BROTLI_ICC_VERSION __ICC
  25. #else
  26. #define BROTLI_ICC_VERSION 0
  27. #endif
  28. #if defined(BROTLI_BUILD_MODERN_COMPILER)
  29. #define BROTLI_MODERN_COMPILER 1
  30. #elif BROTLI_GCC_VERSION > 300 || BROTLI_ICC_VERSION >= 1600
  31. #define BROTLI_MODERN_COMPILER 1
  32. #else
  33. #define BROTLI_MODERN_COMPILER 0
  34. #endif
  35. /* Define "PREDICT_TRUE" and "PREDICT_FALSE" macros for capable compilers.
  36. To apply compiler hint, enclose the branching condition into macros, like this:
  37. if (PREDICT_TRUE(zero == 0)) {
  38. // main execution path
  39. } else {
  40. // compiler should place this code outside of main execution path
  41. }
  42. OR:
  43. if (PREDICT_FALSE(something_rare_or_unexpected_happens)) {
  44. // compiler should place this code outside of main execution path
  45. }
  46. */
  47. #if BROTLI_MODERN_COMPILER || __has_builtin(__builtin_expect)
  48. #define PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
  49. #define PREDICT_FALSE(x) (__builtin_expect(x, 0))
  50. #else
  51. #define PREDICT_FALSE(x) (x)
  52. #define PREDICT_TRUE(x) (x)
  53. #endif
  54. #if BROTLI_MODERN_COMPILER || __has_attribute(always_inline)
  55. #define ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
  56. #else
  57. #define ATTRIBUTE_ALWAYS_INLINE
  58. #endif
  59. #if defined(_WIN32) || defined(__CYGWIN__)
  60. #define ATTRIBUTE_VISIBILITY_HIDDEN
  61. #elif BROTLI_MODERN_COMPILER || __has_attribute(visibility)
  62. #define ATTRIBUTE_VISIBILITY_HIDDEN __attribute__ ((visibility ("hidden")))
  63. #else
  64. #define ATTRIBUTE_VISIBILITY_HIDDEN
  65. #endif
  66. #ifndef BROTLI_INTERNAL
  67. #define BROTLI_INTERNAL ATTRIBUTE_VISIBILITY_HIDDEN
  68. #endif
  69. #ifndef _MSC_VER
  70. #if defined(__cplusplus) || !defined(__STRICT_ANSI__) || \
  71. __STDC_VERSION__ >= 199901L
  72. #define BROTLI_INLINE inline ATTRIBUTE_ALWAYS_INLINE
  73. #else
  74. #define BROTLI_INLINE
  75. #endif
  76. #else /* _MSC_VER */
  77. #define BROTLI_INLINE __forceinline
  78. #endif /* _MSC_VER */
  79. #if BROTLI_MODERN_COMPILER || __has_attribute(noinline)
  80. #define BROTLI_NOINLINE __attribute__((noinline))
  81. #else
  82. #define BROTLI_NOINLINE
  83. #endif
  84. #define BROTLI_UNUSED(X) (void)(X)
  85. #endif /* BROTLI_COMMON_PORT_H_ */