|
51 | 51 | * only need to be careful to not cause warnings for |
52 | 52 | * pointer use. |
53 | 53 | */ |
54 | | -#define __signed_type_use(x,ux) (2+__is_nonneg(x,ux)) |
55 | | -#define __unsigned_type_use(x,ux) (1+2*(sizeof(ux)<4)) |
56 | | -#define __sign_use(x,ux) (is_signed_type(typeof(ux))? \ |
57 | | - __signed_type_use(x,ux):__unsigned_type_use(x,ux)) |
| 54 | +#define __signed_type_use(x, ux) (2 + __is_nonneg(x, ux)) |
| 55 | +#define __unsigned_type_use(x, ux) (1 + 2 * (sizeof(ux) < 4)) |
| 56 | +#define __sign_use(x, ux) (is_signed_type(typeof(ux)) ? \ |
| 57 | + __signed_type_use(x, ux) : __unsigned_type_use(x, ux)) |
58 | 58 |
|
59 | 59 | /* |
60 | 60 | * To avoid warnings about casting pointers to integers |
|
74 | 74 | #ifdef CONFIG_64BIT |
75 | 75 | #define __signed_type(ux) long |
76 | 76 | #else |
77 | | - #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux)>4,1LL,1L)) |
| 77 | + #define __signed_type(ux) typeof(__builtin_choose_expr(sizeof(ux) > 4, 1LL, 1L)) |
78 | 78 | #endif |
79 | | -#define __is_nonneg(x,ux) statically_true((__signed_type(ux))(x)>=0) |
| 79 | +#define __is_nonneg(x, ux) statically_true((__signed_type(ux))(x) >= 0) |
80 | 80 |
|
81 | | -#define __types_ok(x,y,ux,uy) \ |
82 | | - (__sign_use(x,ux) & __sign_use(y,uy)) |
| 81 | +#define __types_ok(x, y, ux, uy) \ |
| 82 | + (__sign_use(x, ux) & __sign_use(y, uy)) |
83 | 83 |
|
84 | | -#define __types_ok3(x,y,z,ux,uy,uz) \ |
85 | | - (__sign_use(x,ux) & __sign_use(y,uy) & __sign_use(z,uz)) |
| 84 | +#define __types_ok3(x, y, z, ux, uy, uz) \ |
| 85 | + (__sign_use(x, ux) & __sign_use(y, uy) & __sign_use(z, uz)) |
86 | 86 |
|
87 | 87 | #define __cmp_op_min < |
88 | 88 | #define __cmp_op_max > |
|
97 | 97 |
|
98 | 98 | #define __careful_cmp_once(op, x, y, ux, uy) ({ \ |
99 | 99 | __auto_type ux = (x); __auto_type uy = (y); \ |
100 | | - BUILD_BUG_ON_MSG(!__types_ok(x,y,ux,uy), \ |
| 100 | + BUILD_BUG_ON_MSG(!__types_ok(x, y, ux, uy), \ |
101 | 101 | #op"("#x", "#y") signedness error"); \ |
102 | 102 | __cmp(op, ux, uy); }) |
103 | 103 |
|
|
114 | 114 | static_assert(__builtin_choose_expr(__is_constexpr((lo) > (hi)), \ |
115 | 115 | (lo) <= (hi), true), \ |
116 | 116 | "clamp() low limit " #lo " greater than high limit " #hi); \ |
117 | | - BUILD_BUG_ON_MSG(!__types_ok3(val,lo,hi,uval,ulo,uhi), \ |
| 117 | + BUILD_BUG_ON_MSG(!__types_ok3(val, lo, hi, uval, ulo, uhi), \ |
118 | 118 | "clamp("#val", "#lo", "#hi") signedness error"); \ |
119 | 119 | __clamp(uval, ulo, uhi); }) |
120 | 120 |
|
|
154 | 154 |
|
155 | 155 | #define __careful_op3(op, x, y, z, ux, uy, uz) ({ \ |
156 | 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), \ |
| 157 | + BUILD_BUG_ON_MSG(!__types_ok3(x, y, z, ux, uy, uz), \ |
158 | 158 | #op"3("#x", "#y", "#z") signedness error"); \ |
159 | 159 | __cmp(op, ux, __cmp(op, uy, uz)); }) |
160 | 160 |
|
@@ -326,9 +326,9 @@ static inline bool in_range32(u32 val, u32 start, u32 len) |
326 | 326 | * Use these carefully: no type checking, and uses the arguments |
327 | 327 | * multiple times. Use for obvious constants only. |
328 | 328 | */ |
329 | | -#define MIN(a,b) __cmp(min,a,b) |
330 | | -#define MAX(a,b) __cmp(max,a,b) |
331 | | -#define MIN_T(type,a,b) __cmp(min,(type)(a),(type)(b)) |
332 | | -#define MAX_T(type,a,b) __cmp(max,(type)(a),(type)(b)) |
| 329 | +#define MIN(a, b) __cmp(min, a, b) |
| 330 | +#define MAX(a, b) __cmp(max, a, b) |
| 331 | +#define MIN_T(type, a, b) __cmp(min, (type)(a), (type)(b)) |
| 332 | +#define MAX_T(type, a, b) __cmp(max, (type)(a), (type)(b)) |
333 | 333 |
|
334 | 334 | #endif /* _LINUX_MINMAX_H */ |
0 commit comments