util.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. This file is part of ethash.
  3. ethash is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. ethash is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with ethash. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. /** @file util.h
  15. * @author Tim Hughes <tim@twistedfury.com>
  16. * @date 2015
  17. */
  18. #pragma once
  19. #include <stdint.h>
  20. #include "compiler.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #ifdef _MSC_VER
  25. void debugf(char const* str, ...);
  26. #else
  27. #define debugf printf
  28. #endif
  29. static inline uint32_t min_u32(uint32_t a, uint32_t b)
  30. {
  31. return a < b ? a : b;
  32. }
  33. static inline uint32_t clamp_u32(uint32_t x, uint32_t min_, uint32_t max_)
  34. {
  35. return x < min_ ? min_ : (x > max_ ? max_ : x);
  36. }
  37. #ifdef __cplusplus
  38. }
  39. #endif