gcc_builtin.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #ifndef _TOOLS_LINUX_COMPILER_H_
  2. #define _TOOLS_LINUX_COMPILER_H_
  3. #ifndef __compiletime_error
  4. # define __compiletime_error(message)
  5. #endif
  6. /* Optimization barrier */
  7. /* The "volatile" is due to gcc bugs */
  8. #define barrier() __asm__ __volatile__("": : :"memory")
  9. #ifndef __always_inline
  10. # define __always_inline inline __attribute__((always_inline))
  11. #endif
  12. #ifndef noinline
  13. #define noinline
  14. #endif
  15. /* Are two types/vars the same type (ignoring qualifiers)? */
  16. #ifndef __same_type
  17. # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
  18. #endif
  19. #ifdef __ANDROID__
  20. /*
  21. * FIXME: Big hammer to get rid of tons of:
  22. * "warning: always_inline function might not be inlinable"
  23. *
  24. * At least on android-ndk-r12/platforms/android-24/arch-arm
  25. */
  26. #undef __always_inline
  27. #define __always_inline inline
  28. #endif
  29. #define __user
  30. #define __rcu
  31. #define __read_mostly
  32. #ifndef __attribute_const__
  33. # define __attribute_const__
  34. #endif
  35. #ifndef __maybe_unused
  36. # define __maybe_unused __attribute__((unused))
  37. #endif
  38. #ifndef __used
  39. # define __used __attribute__((__unused__))
  40. #endif
  41. #ifndef __packed
  42. # define __packed __attribute__((__packed__))
  43. #endif
  44. #ifndef __force
  45. # define __force
  46. #endif
  47. #ifndef __weak
  48. # define __weak __attribute__((weak))
  49. #endif
  50. #ifndef likely
  51. # define likely(x) __builtin_expect(!!(x), 1)
  52. #endif
  53. #ifndef unlikely
  54. # define unlikely(x) __builtin_expect(!!(x), 0)
  55. #endif
  56. #ifndef __init
  57. # define __init
  58. #endif
  59. #ifndef noinline
  60. # define noinline
  61. #endif
  62. #define uninitialized_var(x) x = *(&(x))
  63. #ifndef __fallthrough
  64. # define __fallthrough
  65. #endif
  66. #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
  67. #ifndef max
  68. #define max(x, y) ({ \
  69. typeof(x) _max1 = (x); \
  70. typeof(y) _max2 = (y); \
  71. (void) (&_max1 == &_max2); \
  72. _max1 > _max2 ? _max1 : _max2; })
  73. #endif
  74. #ifndef min
  75. #define min(x, y) ({ \
  76. typeof(x) _min1 = (x); \
  77. typeof(y) _min2 = (y); \
  78. (void) (&_min1 == &_min2); \
  79. _min1 < _min2 ? _min1 : _min2; })
  80. #endif
  81. #ifndef roundup
  82. #define roundup(x, y) ( \
  83. { \
  84. const typeof(y) __y = y; \
  85. (((x) + (__y - 1)) / __y) * __y; \
  86. } \
  87. )
  88. #endif
  89. #define __round_mask(x, y) ((__typeof__(x))((y)-1))
  90. #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
  91. #define round_down(x, y) ((x) & ~__round_mask(x, y))
  92. #endif /* _TOOLS_LINUX_COMPILER_H */