lkml.org 
[lkml]   [2011]   [Apr]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] remove abs64()
On Wed, 13 Apr 2011 00:00:45 +0300 Alexey Dobriyan wrote:

> We don't need no stinking abs64() given some GCC extensions
> (especially __builtin_choose_expr()).
>
> One abs() implementation is better than two abs() implementations.

questionable.

> New abs() doesn't expand type needlessly.
>
> Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
> ---
>
> drivers/gpu/drm/drm_irq.c | 4 ++--
> include/linux/kernel.h | 43 +++++++++++++++++++++----------------------
> lib/div64.c | 2 +-
> 3 files changed, 24 insertions(+), 25 deletions(-)


> --- a/include/linux/kernel.h
> +++ b/include/linux/kernel.h
> @@ -143,28 +143,27 @@ extern int _cond_resched(void);
>
> #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0)
>
> -/*
> - * abs() handles unsigned and signed longs, ints, shorts and chars. For all
> - * input types abs() returns a signed long.
> - * abs() should not be used for 64-bit types (s64, u64, long long) - use abs64()
> - * for those.
> - */
> -#define abs(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 abs64(x) ({ \
> - s64 __x = (x); \
> - (__x < 0) ? -__x : __x; \
> - })
> +#define abs(x) \
> +({ \
> + typeof(x) _x = (x); \
> + \
> + __builtin_choose_expr( \
> + __builtin_types_compatible_p(typeof(_x), signed char), \
> + (unsigned char)({ _x < 0 ? -_x : _x; }), \
> + __builtin_choose_expr( \
> + __builtin_types_compatible_p(typeof(_x), short), \
> + (unsigned short)({ _x < 0 ? -_x : _x; }), \
> + __builtin_choose_expr( \
> + __builtin_types_compatible_p(typeof(_x), int), \
> + (unsigned int)({ _x < 0 ? -_x : _x; }), \
> + __builtin_choose_expr( \
> + __builtin_types_compatible_p(typeof(_x), long), \
> + (unsigned long)({ _x < 0 ? -_x : _x; }), \
> + __builtin_choose_expr( \
> + __builtin_types_compatible_p(typeof(_x), long long), \
> + (unsigned long long)({ _x < 0 ? -_x : _x; }), \
> + _x))))); \
> +})

that is better?

---
~Randy

\
 
 \ /
  Last update: 2011-04-12 23:09    [from the cache]
©2003-2014 Jasper Spaans. Advertise on this site