utils.h 890 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #ifdef __cplusplus
  6. #define PK_INLINE inline
  7. #else
  8. #define PK_INLINE static inline
  9. #endif
  10. #define PK_REGION(name) 1
  11. #define PK_SLICE_LOOP(i, start, stop, step) for(int i = start; step > 0 ? i < stop : i > stop; i += step)
  12. // global constants
  13. #define PK_HEX_TABLE "0123456789abcdef"
  14. extern const char* kPlatformStrings[];
  15. #ifdef _MSC_VER
  16. #define PK_UNREACHABLE() __assume(0);
  17. #else
  18. #define PK_UNREACHABLE() __builtin_unreachable();
  19. #endif
  20. #define PK_FATAL_ERROR(...) { fprintf(stderr, __VA_ARGS__); abort(); }
  21. #define PK_MIN(a, b) ((a) < (b) ? (a) : (b))
  22. #define PK_MAX(a, b) ((a) > (b) ? (a) : (b))
  23. // NARGS
  24. #define PK_NARGS_SEQ(_1, _2, _3, _4, N, ...) N
  25. #define PK_NARGS(...) PK_NARGS_SEQ(__VA_ARGS__, 4, 3, 2, 1, 0)
  26. #define PK_NPTRS(...) PK_NARGS_SEQ(__VA_ARGS__, int****, int***, int**, int*, int)
  27. #ifdef __cplusplus
  28. }
  29. #endif