Lines Matching +full:min +full:- +full:len
1 /* SPDX-License-Identifier: GPL-2.0 */
9 * min()/max()/clamp() macros must accomplish three things:
11 * - avoid multiple evaluations of the arguments (so side-effects like
12 * "x++" happen only once) when non-constant.
13 * - perform strict type-checking (to generate warnings instead of
16 * - retain result as a constant expressions when called with only
64 * min - return minimum of two values of the same or compatible types
68 #define min(x, y) __careful_cmp(x, y, <) macro
71 * max - return maximum of two values of the same or compatible types
78 * min3 - return minimum of three values
83 #define min3(x, y, z) min((typeof(x))min(x, y), z)
86 * max3 - return maximum of three values
94 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
101 __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
104 * clamp - return a value clamped to a given range with strict typechecking
118 * Or not use min/max/clamp at all, of course.
122 * min_t - return minimum of two values, using the specified type
130 * max_t - return maximum of two values, using the specified type
139 * _Generic(foo, type-name: association, ..., default: association) performs a
141 * Do not use the const keyword in the type-name as it will not match the
160 * In the following legit use-case where the "array" passed is a simple pointer,
162 * --- 8< ---
165 * min = min_array(buff, nb_items);
166 * --- 8< ---
175 #define __minmax_array(op, array, len) ({ \ argument
177 typeof(len) __len = (len); \
178 __unconst_integer_typeof(__array[0]) __element = __array[--__len]; \
179 while (__len--) \
184 * min_array - return minimum of values present in an array
186 * @len: array length
188 * Note that @len must not be zero (empty array).
190 #define min_array(array, len) __minmax_array(min, array, len) argument
193 * max_array - return maximum of values present in an array
195 * @len: array length
197 * Note that @len must not be zero (empty array).
199 #define max_array(array, len) __minmax_array(max, array, len) argument
202 * clamp_t - return a value clamped to a given range using a given type
214 * clamp_val - return a value clamped to a given range using val's type
226 static inline bool in_range64(u64 val, u64 start, u64 len) in in_range64() argument
228 return (val - start) < len; in in_range64()
231 static inline bool in_range32(u32 val, u32 start, u32 len) in in_range32() argument
233 return (val - start) < len; in in_range32()
237 * in_range - Determine if a value lies within a range.
240 * @len: Number of values in range.
242 * This is more efficient than "if (start <= val && val < (start + len))".
243 * It also gives a different answer if @start + @len overflows the size of
245 * which behaviour you want, or prove that start + len never overflow.
248 #define in_range(val, start, len) \ argument
249 ((sizeof(start) | sizeof(len) | sizeof(val)) <= sizeof(u32) ? \
250 in_range32(val, start, len) : in_range64(val, start, len))
253 * swap - swap values of @a and @b