Lines Matching +full:max +full:- +full:len

1 /* SPDX-License-Identifier: GPL-2.0 */
11 * min()/max()/clamp() macros must accomplish several things:
13 * - Avoid multiple evaluations of the arguments (so side-effects like
14 * "x++" happen only once) when non-constant.
15 * - Perform signed v unsigned type-checking (to generate compile
17 * - Unsigned char/short are always promoted to signed int and can be
19 * - Unsigned arguments can be compared against non-negative signed constants.
20 * - Comparison of a signed argument against an unsigned constant fails
31 * In particular, statically non-negative signed integer expressions
53 * Check whether a signed value is always non-negative.
58 * On 64-bit any integer or pointer type can safely be cast to 'long long'.
59 * But on 32-bit we need to avoid warnings about casting pointers to integers
60 * of different sizes without truncating 64-bit values so 'long' or 'long long'
63 * This does not work for 128-bit signed integers since the cast would truncate
101 * min - return minimum of two values of the same or compatible types
108 * max - return maximum of two values of the same or compatible types
112 #define max(x, y) __careful_cmp(max, x, y) macro
115 * umin - return minimum of two non-negative values
124 * umax - return maximum of two non-negative values
129 __careful_cmp(max, (x) + 0u + 0ul + 0ull, (y) + 0u + 0ul + 0ull)
138 * min3 - return minimum of three values
147 * max3 - return maximum of three values
153 __careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
156 * min_t - return minimum of two values, using the specified type
164 * max_t - return maximum of two values, using the specified type
169 #define max_t(type, x, y) __cmp_once(max, type, x, y)
172 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
198 * clamp - return a value clamped to a given range with typechecking
209 * clamp_t - return a value clamped to a given range using a given type
221 * clamp_val - return a value clamped to a given range using val's type
235 * In the following legit use-case where the "array" passed is a simple pointer,
237 * --- 8< ---
241 * --- 8< ---
250 #define __minmax_array(op, array, len) ({ \ argument
252 typeof(len) __len = (len); \
253 __unqual_scalar_typeof(__array[0]) __element = __array[--__len];\
254 while (__len--) \
259 * min_array - return minimum of values present in an array
261 * @len: array length
263 * Note that @len must not be zero (empty array).
265 #define min_array(array, len) __minmax_array(min, array, len) argument
268 * max_array - return maximum of values present in an array
270 * @len: array length
272 * Note that @len must not be zero (empty array).
274 #define max_array(array, len) __minmax_array(max, array, len) argument
276 static inline bool in_range64(u64 val, u64 start, u64 len) in in_range64() argument
278 return (val - start) < len; in in_range64()
281 static inline bool in_range32(u32 val, u32 start, u32 len) in in_range32() argument
283 return (val - start) < len; in in_range32()
287 * in_range - Determine if a value lies within a range.
290 * @len: Number of values in range.
292 * This is more efficient than "if (start <= val && val < (start + len))".
293 * It also gives a different answer if @start + @len overflows the size of
295 * which behaviour you want, or prove that start + len never overflow.
298 #define in_range(val, start, len) \ argument
299 ((sizeof(start) | sizeof(len) | sizeof(val)) <= sizeof(u32) ? \
300 in_range32(val, start, len) : in_range64(val, start, len))
303 * swap - swap values of @a and @b
315 #define MAX(a, b) __cmp(max, a, b) macro
317 #define MAX_T(type, a, b) __cmp(max, (type)(a), (type)(b))