diff options
author | Dmitry Shmidt <dimitrysh@google.com> | 2016-10-10 12:43:03 -0700 |
---|---|---|
committer | Dmitry Shmidt <dimitrysh@google.com> | 2016-10-10 12:43:03 -0700 |
commit | 09f6247a9ccaffcc9af1e4a9038e14ecdb76a79d (patch) | |
tree | f28f9f114c1aab70185f424ec2be689d1e6cbd3b /include/linux/kernel.h | |
parent | 8760f8e3d9806a940d759c9e12fff7eb7130b9ab (diff) | |
parent | d19e48fe5da7b83d02ed4aec3567f08ae02a168c (diff) |
Merge tag 'v4.4.23' into android-4.4.y
This is the 4.4.23 stable release
Diffstat (limited to 'include/linux/kernel.h')
-rw-r--r-- | include/linux/kernel.h | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 924853d33a13..e571e592e53a 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h @@ -202,26 +202,26 @@ extern int _cond_resched(void); /** * abs - return absolute value of an argument - * @x: the value. If it is unsigned type, it is converted to signed type first - * (s64, long or int depending on its size). + * @x: the value. If it is unsigned type, it is converted to signed type first. + * char is treated as if it was signed (regardless of whether it really is) + * but the macro's return type is preserved as char. * - * Return: an absolute value of x. If x is 64-bit, macro's return type is s64, - * otherwise it is signed long. + * Return: an absolute value of x. */ -#define abs(x) __builtin_choose_expr(sizeof(x) == sizeof(s64), ({ \ - s64 __x = (x); \ - (__x < 0) ? -__x : __x; \ - }), ({ \ - long ret; \ - if (sizeof(x) == sizeof(long)) { \ - long __x = (x); \ - ret = (__x < 0) ? -__x : __x; \ - } else { \ - int __x = (x); \ - ret = (__x < 0) ? -__x : __x; \ - } \ - ret; \ - })) +#define abs(x) __abs_choose_expr(x, long long, \ + __abs_choose_expr(x, long, \ + __abs_choose_expr(x, int, \ + __abs_choose_expr(x, short, \ + __abs_choose_expr(x, char, \ + __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(x), char), \ + (char)({ signed char __x = (x); __x<0?-__x:__x; }), \ + ((void)0))))))) + +#define __abs_choose_expr(x, type, other) __builtin_choose_expr( \ + __builtin_types_compatible_p(typeof(x), signed type) || \ + __builtin_types_compatible_p(typeof(x), unsigned type), \ + ({ signed type __x = (x); __x < 0 ? -__x : __x; }), other) /** * reciprocal_scale - "scale" a value into range [0, ep_ro) |