Lines Matching +full:hi +full:- +full:z

1 /* SPDX-License-Identifier: GPL-2.0 */
13 * - Avoid multiple evaluations of the arguments (so side-effects like
14 * "x++" happen only once) when non-constant.
15 * - Retain result as a constant expressions when called with only
18 * - Perform signed v unsigned type-checking (to generate compile
20 * - Unsigned char/short are always promoted to signed int and can be
22 * - Unsigned arguments can be compared against non-negative signed constants.
23 * - Comparison of a signed argument against an unsigned constant fails
34 * In particular, statically non-negative signed integer
63 * On 64-bit we can just always use 'long', since any
66 * This does not work for 128-bit signed integers since
84 #define __types_ok3(x,y,z,ux,uy,uz) \ argument
85 (__sign_use(x,ux) & __sign_use(y,uy) & __sign_use(z,uz))
107 #define __clamp(val, lo, hi) \ argument
108 ((val) >= (hi) ? (hi) : ((val) <= (lo) ? (lo) : (val)))
110 #define __clamp_once(val, lo, hi, uval, ulo, uhi) ({ \ argument
113 __auto_type uhi = (hi); \
114 static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \
115 (lo) <= (hi), true), \
116 "clamp() low limit " #lo " greater than high limit " #hi); \
117 BUILD_BUG_ON_MSG(!__types_ok3(val,lo,hi,uval,ulo,uhi), \
118 "clamp("#val", "#lo", "#hi") signedness error"); \
121 #define __careful_clamp(val, lo, hi) \ argument
122 __clamp_once(val, lo, hi, __UNIQUE_ID(v_), __UNIQUE_ID(l_), __UNIQUE_ID(h_))
125 * min - return minimum of two values of the same or compatible types
132 * max - return maximum of two values of the same or compatible types
139 * umin - return minimum of two non-negative values
148 * umax - return maximum of two non-negative values
155 #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ argument
156 __auto_type ux = (x); __auto_type uy = (y);__auto_type uz = (z);\
157 BUILD_BUG_ON_MSG(!__types_ok3(x,y,z,ux,uy,uz), \
158 #op"3("#x", "#y", "#z") signedness error"); \
162 * min3 - return minimum of three values
165 * @z: third value
167 #define min3(x, y, z) \ argument
168 __careful_op3(min, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
171 * max3 - return maximum of three values
174 * @z: third value
176 #define max3(x, y, z) \ argument
177 __careful_op3(max, x, y, z, __UNIQUE_ID(x_), __UNIQUE_ID(y_), __UNIQUE_ID(z_))
180 * min_not_zero - return the minimum that is _not_ zero, unless both are zero
190 * clamp - return a value clamped to a given range with strict typechecking
193 * @hi: highest allowable value
195 * This macro does strict typechecking of @lo/@hi to make sure they are of the
198 #define clamp(val, lo, hi) __careful_clamp(val, lo, hi) argument
208 * min_t - return minimum of two values, using the specified type
216 * max_t - return maximum of two values, using the specified type
225 * In the following legit use-case where the "array" passed is a simple pointer,
227 * --- 8< ---
231 * --- 8< ---
243 __unqual_scalar_typeof(__array[0]) __element = __array[--__len];\
244 while (__len--) \
249 * min_array - return minimum of values present in an array
258 * max_array - return maximum of values present in an array
267 * clamp_t - return a value clamped to a given range using a given type
271 * @hi: maximum allowable value
276 #define clamp_t(type, val, lo, hi) __careful_clamp((type)(val), (type)(lo), (type)(hi)) argument
279 * clamp_val - return a value clamped to a given range using val's type
282 * @hi: maximum allowable value
286 * type and @lo and @hi are literals that will otherwise be assigned a signed
289 #define clamp_val(val, lo, hi) clamp_t(typeof(val), val, lo, hi) argument
293 return (val - start) < len; in in_range64()
298 return (val - start) < len; in in_range32()
302 * in_range - Determine if a value lies within a range.
318 * swap - swap values of @a and @b