u64.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* uint64_t-like operations that work even on hosts lacking uint64_t
  2. Copyright (C) 2006, 2009-2022 Free Software Foundation, Inc.
  3. This file is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Lesser General Public License as
  5. published by the Free Software Foundation; either version 2.1 of the
  6. License, or (at your option) any later version.
  7. This file 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 Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>. */
  13. /* Written by Paul Eggert. */
  14. #pragma once
  15. #include <stdint.h>
  16. #ifndef _GL_U64_INLINE
  17. #define _GL_U64_INLINE _GL_INLINE
  18. #endif
  19. /* Return X rotated left by N bits, where 0 < N < 64. */
  20. #define u64rol(x, n) u64or(u64shl(x, n), u64shr(x, 64 - (n)))
  21. /* Native implementations are trivial. See below for comments on what
  22. these operations do. */
  23. typedef uint64_t u64;
  24. #define u64hilo(hi, lo) ((u64)(((u64)(hi) << 32) + (lo)))
  25. #define u64init(hi, lo) u64hilo(hi, lo)
  26. #define u64lo(x) ((u64)(x))
  27. #define u64size(x) u64lo(x)
  28. #define u64lt(x, y) ((x) < (y))
  29. #define u64and(x, y) ((x) & (y))
  30. #define u64or(x, y) ((x) | (y))
  31. #define u64xor(x, y) ((x) ^ (y))
  32. #define u64plus(x, y) ((x) + (y))
  33. #define u64shl(x, n) ((x) << (n))
  34. #define u64shr(x, n) ((x) >> (n))