int32_minmax.inc 415 B

123456789101112131415161718192021
  1. /* $OpenBSD: int32_minmax.inc,v 1.1 2020/12/30 14:13:28 tobhe Exp $ */
  2. /*
  3. * Public Domain, Authors:
  4. * - Daniel J. Bernstein
  5. * - Chitchanok Chuengsatiansup
  6. * - Tanja Lange
  7. * - Christine van Vredendaal
  8. */
  9. #define int32_MINMAX(a,b) \
  10. do { \
  11. int64_t ab = (int64_t)b ^ (int64_t)a; \
  12. int64_t c = (int64_t)b - (int64_t)a; \
  13. c ^= ab & (c ^ b); \
  14. c >>= 31; \
  15. c &= ab; \
  16. a ^= c; \
  17. b ^= c; \
  18. } while(0)