@@ -28,7 +28,7 @@
/* Allow unsigned compares against non-negative signed constants. */
#define __is_ok_unsigned(x) \
- ((is_unsigned_type(typeof(x)) ? 0 : __if_constexpr(x, (x) + 0, -1)) >= 0)
+ ((is_unsigned_type(typeof(x)) ? 0 : __if_constexpr(x, x, -1)) >= 0)
/* Check for signed after promoting unsigned char/short to int */
#define __is_ok_signed(x) is_signed_type(typeof((x) + 0))
@@ -69,22 +69,26 @@
*/
#define max(x, y) __careful_cmp(max, x, y)
+/*
+ * Zero extend a non-negative value to 64bits.
+ * Undefined for negative values.
+ * The extension to 64 bits is often optimised away.
+ */
+#define __zero_extend(x) ((x) + 0u + 0ul + 0ull)
+
/**
* umin - return minimum of two non-negative values
- * Signed types are zero extended to match a larger unsigned type.
* @x: first value
* @y: second value
*/
-#define umin(x, y) \
- __careful_cmp(min, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
+#define umin(x, y) __careful_cmp(min, __zero_extend(x), __zero_extend(y))
/**
* umax - return maximum of two non-negative values
* @x: first value
* @y: second value
*/
-#define umax(x, y) \
- __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
+#define umax(x, y) __careful_cmp(max, __zero_extend(x), __zero_extend(y))
/**
* min3 - return minimum of three values
The '+ 0u + 0ul + 0ull' to zero extend to 64bit on both 32bit and 64bit systems was replicated 4 times. Factor out and then join up some 'not overlong' lines. Signed-off-by: David Laight <david.laight@aculab.com> --- include/linux/minmax.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)