const.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /* const.h: Macros for dealing with constants. */
  3. #pragma once
  4. #ifndef _UAPI_LINUX_CONST_H
  5. #define _UAPI_LINUX_CONST_H
  6. /* Some constant macros are used in both assembler and
  7. * C code. Therefore we cannot annotate them always with
  8. * 'UL' and other type specifiers unilaterally. We
  9. * use the following macros to deal with this.
  10. *
  11. * Similarly, _AT() will cast an expression with a type in C, but
  12. * leave it unchanged in asm.
  13. */
  14. #ifdef __ASSEMBLY__
  15. #define _AC(X,Y) X
  16. #define _AT(T,X) X
  17. #else
  18. #define __AC(X,Y) (X##Y)
  19. #define _AC(X,Y) __AC(X,Y)
  20. #define _AT(T,X) ((T)(X))
  21. #endif
  22. #define _UL(x) (_AC(x, UL))
  23. #define _ULL(x) (_AC(x, ULL))
  24. #define _BITUL(x) (_UL(1) << (x))
  25. #define _BITULL(x) (_ULL(1) << (x))
  26. #define __ALIGN_KERNEL(x, a) __ALIGN_KERNEL_MASK(x, (__typeof__(x))(a) - 1)
  27. #define __ALIGN_KERNEL_MASK(x, mask) (((x) + (mask)) & ~(mask))
  28. #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
  29. /*
  30. * This returns a constant expression while determining if an argument is
  31. * a constant expression, most importantly without evaluating the argument.
  32. * Glory to Martin Uecker <[email protected]>
  33. */
  34. #define __is_constexpr(x) \
  35. (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
  36. #endif /* _UAPI_LINUX_CONST_H */