[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110412211452.GA20135@p183>
Date: Wed, 13 Apr 2011 00:14:53 +0300
From: Alexey Dobriyan <adobriyan@...il.com>
To: Randy Dunlap <rdunlap@...otime.net>
Cc: akpm@...ux-foundation.org, linux-kernel@...r.kernel.org,
behlendorf1@...l.gov, oleg@...hat.com
Subject: Re: [PATCH] remove abs64()
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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists