Re: [PATCH] remove abs64()

From: Alexey Dobriyan
Date: Tue Apr 12 2011 - 17:15:04 EST


On Tue, Apr 12, 2011 at 02:07:26PM -0700, Randy Dunlap wrote:
> 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.

Come on, what's so special in 64-bit types?

> > --- a/include/linux/kernel.h
> > +++ b/include/linux/kernel.h

> > -#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; }), \

> that is better?

Infinitely better.
sizeof(abs(x)) == sizeof(x) for one thing.

Implementation is ugly, but, hey, one can't do better in C.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/