gcc_builtin.h 2.4 KB

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