diff --git a/int32_minmax.inc b/int32_minmax.inc new file mode 100644 index 000000000..2f6ff5195 --- /dev/null +++ b/int32_minmax.inc @@ -0,0 +1,20 @@ +/* $OpenBSD: int32_minmax.inc,v 1.1 2020/12/30 14:13:28 tobhe Exp $ */ + +/* + * Public Domain, Authors: + * - Daniel J. Bernstein + * - Chitchanok Chuengsatiansup + * - Tanja Lange + * - Christine van Vredendaal + */ + +#define int32_MINMAX(a,b) \ +do { \ + int64_t ab = (int64_t)b ^ (int64_t)a; \ + int64_t c = (int64_t)b - (int64_t)a; \ + c ^= ab & (c ^ b); \ + c >>= 31; \ + c &= ab; \ + a ^= c; \ + b ^= c; \ +} while(0)