compiler.h 947 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __LINUX_COMPILER_H
  3. #define __LINUX_COMPILER_H
  4. #include "../compiler_types.h"
  5. #define likely(x) __builtin_expect(!!(x), 1)
  6. #define unlikely(x) __builtin_expect(!!(x), 0)
  7. #define likely_notrace(x) likely(x)
  8. #define unlikely_notrace(x) unlikely(x)
  9. #ifndef __ASSEMBLY__
  10. /**
  11. * offset_to_ptr - convert a relative memory offset to an absolute pointer
  12. * @off: the address of the 32-bit offset value
  13. */
  14. static inline void *offset_to_ptr(const int *off)
  15. {
  16. return (void *)((unsigned long)off + *off);
  17. }
  18. #endif /* __ASSEMBLY__ */
  19. /*
  20. * Whether 'type' is a signed type or an unsigned type. Supports scalar types,
  21. * bool and also pointer types.
  22. */
  23. #define is_signed_type(type) (((type)(-1)) < (__force type)1)
  24. #define is_unsigned_type(type) (!is_signed_type(type))
  25. #ifndef __UNIQUE_ID
  26. #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
  27. #endif
  28. #endif /* __LINUX_COMPILER_H */