linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remove abs64()
@ 2011-04-12 21:00 Alexey Dobriyan
  2011-04-12 21:07 ` Randy Dunlap
  2011-04-13 14:27 ` Oleg Nesterov
  0 siblings, 2 replies; 12+ messages in thread
From: Alexey Dobriyan @ 2011-04-12 21:00 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, behlendorf1, oleg

We don't need no stinking abs64() given some GCC extensions
(especially __builtin_choose_expr()).

One abs() implementation is better than two abs() implementations.

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/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -154,7 +154,7 @@ static void vblank_disable_and_save(struct drm_device *dev, int crtc)
 	 * available. In that case we can't account for this and just
 	 * hope for the best.
 	 */
-	if ((vblrc > 0) && (abs64(diff_ns) > 1000000)) {
+	if ((vblrc > 0) && (abs(diff_ns) > 1000000)) {
 		atomic_inc(&dev->_vblank_count[crtc]);
 		smp_mb__after_atomic_inc();
 	}
@@ -1290,7 +1290,7 @@ bool drm_handle_vblank(struct drm_device *dev, int crtc)
 	 * e.g., due to spurious vblank interrupts. We need to
 	 * ignore those for accounting.
 	 */
-	if (abs64(diff_ns) > DRM_REDUNDANT_VBLIRQ_THRESH_NS) {
+	if (abs(diff_ns) > DRM_REDUNDANT_VBLIRQ_THRESH_NS) {
 		/* Store new timestamp in ringbuffer. */
 		vblanktimestamp(dev, crtc, vblcount + 1) = tvblank;
 
--- 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)))));							\
+})
 
 #ifdef CONFIG_PROVE_LOCKING
 void might_fault(void);
--- a/lib/div64.c
+++ b/lib/div64.c
@@ -121,7 +121,7 @@ s64 div64_s64(s64 dividend, s64 divisor)
 {
 	s64 quot, t;
 
-	quot = div64_u64(abs64(dividend), abs64(divisor));
+	quot = div64_u64(abs(dividend), abs(divisor));
 	t = (dividend ^ divisor) >> 63;
 
 	return (quot ^ t) - t;

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:00 [PATCH] remove abs64() Alexey Dobriyan
@ 2011-04-12 21:07 ` Randy Dunlap
  2011-04-12 21:10   ` Andrew Morton
  2011-04-12 21:14   ` Alexey Dobriyan
  2011-04-13 14:27 ` Oleg Nesterov
  1 sibling, 2 replies; 12+ messages in thread
From: Randy Dunlap @ 2011-04-12 21:07 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, behlendorf1, oleg

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:07 ` Randy Dunlap
@ 2011-04-12 21:10   ` Andrew Morton
  2011-04-12 21:16     ` Alexey Dobriyan
  2011-04-12 21:14   ` Alexey Dobriyan
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2011-04-12 21:10 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: Alexey Dobriyan, linux-kernel, behlendorf1, oleg

On Tue, 12 Apr 2011 14:07:26 -0700
Randy Dunlap <rdunlap@xenotime.net> wrote:

> > --- 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?

I think so.

It's a bit concerning that it changes the return type of abs().

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:07 ` Randy Dunlap
  2011-04-12 21:10   ` Andrew Morton
@ 2011-04-12 21:14   ` Alexey Dobriyan
  1 sibling, 0 replies; 12+ messages in thread
From: Alexey Dobriyan @ 2011-04-12 21:14 UTC (permalink / raw)
  To: Randy Dunlap; +Cc: akpm, linux-kernel, behlendorf1, oleg

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.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:10   ` Andrew Morton
@ 2011-04-12 21:16     ` Alexey Dobriyan
  2011-04-12 21:33       ` Andrew Morton
  0 siblings, 1 reply; 12+ messages in thread
From: Alexey Dobriyan @ 2011-04-12 21:16 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Randy Dunlap, linux-kernel, behlendorf1, oleg

On Tue, Apr 12, 2011 at 02:10:40PM -0700, Andrew Morton wrote:
> On Tue, 12 Apr 2011 14:07:26 -0700
> Randy Dunlap <rdunlap@xenotime.net> wrote:
> 
> > > +	__builtin_choose_expr(						\
> > > +		__builtin_types_compatible_p(typeof(_x), long long),	\
> > > +		(unsigned long long)({ _x < 0 ? -_x : _x; }),		\
> > > +	_x)))));							\
> > > +})
> > 
> > that is better?
> 
> I think so.
> 
> It's a bit concerning that it changes the return type of abs().

I haven't read every abs() user, but, yes, sizeof(abs()) silently
changing is the issue.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:16     ` Alexey Dobriyan
@ 2011-04-12 21:33       ` Andrew Morton
  2011-04-12 21:40         ` Randy Dunlap
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2011-04-12 21:33 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: Randy Dunlap, linux-kernel, behlendorf1, oleg

On Wed, 13 Apr 2011 00:16:58 +0300
Alexey Dobriyan <adobriyan@gmail.com> wrote:

> On Tue, Apr 12, 2011 at 02:10:40PM -0700, Andrew Morton wrote:
> > On Tue, 12 Apr 2011 14:07:26 -0700
> > Randy Dunlap <rdunlap@xenotime.net> wrote:
> > 
> > > > +	__builtin_choose_expr(						\
> > > > +		__builtin_types_compatible_p(typeof(_x), long long),	\
> > > > +		(unsigned long long)({ _x < 0 ? -_x : _x; }),		\
> > > > +	_x)))));							\
> > > > +})
> > > 
> > > that is better?
> > 
> > I think so.
> > 
> > It's a bit concerning that it changes the return type of abs().
> 
> I haven't read every abs() user, but, yes, sizeof(abs()) silently
> changing is the issue.

It changes signedness_of(abs(signed_expr)) as well.  That changes the
signedness of expressions which use abs() and on and on.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:33       ` Andrew Morton
@ 2011-04-12 21:40         ` Randy Dunlap
  0 siblings, 0 replies; 12+ messages in thread
From: Randy Dunlap @ 2011-04-12 21:40 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alexey Dobriyan, linux-kernel, behlendorf1, oleg

On Tue, 12 Apr 2011 14:33:40 -0700 Andrew Morton wrote:

> On Wed, 13 Apr 2011 00:16:58 +0300
> Alexey Dobriyan <adobriyan@gmail.com> wrote:
> 
> > On Tue, Apr 12, 2011 at 02:10:40PM -0700, Andrew Morton wrote:
> > > On Tue, 12 Apr 2011 14:07:26 -0700
> > > Randy Dunlap <rdunlap@xenotime.net> wrote:
> > > 
> > > > > +	__builtin_choose_expr(						\
> > > > > +		__builtin_types_compatible_p(typeof(_x), long long),	\
> > > > > +		(unsigned long long)({ _x < 0 ? -_x : _x; }),		\
> > > > > +	_x)))));							\
> > > > > +})
> > > > 
> > > > that is better?
> > > 
> > > I think so.
> > > 
> > > It's a bit concerning that it changes the return type of abs().
> > 
> > I haven't read every abs() user, but, yes, sizeof(abs()) silently
> > changing is the issue.
> 
> It changes signedness_of(abs(signed_expr)) as well.  That changes the
> signedness of expressions which use abs() and on and on.
> --

thanks for the further explanations.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-12 21:00 [PATCH] remove abs64() Alexey Dobriyan
  2011-04-12 21:07 ` Randy Dunlap
@ 2011-04-13 14:27 ` Oleg Nesterov
  2011-04-13 18:48   ` Andrew Morton
  1 sibling, 1 reply; 12+ messages in thread
From: Oleg Nesterov @ 2011-04-13 14:27 UTC (permalink / raw)
  To: Alexey Dobriyan; +Cc: akpm, linux-kernel, behlendorf1

On 04/13, Alexey Dobriyan wrote:
>
> +#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)))));							\
> +})

Personally I agree.

But, we have some stupid users which do something like abs(u32_value)
and expecting that abs() should treat this value as "signed".

Oleg.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-13 14:27 ` Oleg Nesterov
@ 2011-04-13 18:48   ` Andrew Morton
  2011-04-13 20:20     ` Oleg Nesterov
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2011-04-13 18:48 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Alexey Dobriyan, linux-kernel, behlendorf1

On Wed, 13 Apr 2011 16:27:03 +0200
Oleg Nesterov <oleg@redhat.com> wrote:

> On 04/13, Alexey Dobriyan wrote:
> >
> > +#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)))));							\
> > +})
> 
> Personally I agree.
> 
> But, we have some stupid users which do something like abs(u32_value)
> and expecting that abs() should treat this value as "signed".
> 

um, yes, I'd forgotten that one.  That's a show-stopper.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-13 18:48   ` Andrew Morton
@ 2011-04-13 20:20     ` Oleg Nesterov
  2011-04-13 20:26       ` Andrew Morton
  0 siblings, 1 reply; 12+ messages in thread
From: Oleg Nesterov @ 2011-04-13 20:20 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Alexey Dobriyan, linux-kernel, behlendorf1

On 04/13, Andrew Morton wrote:
>
> On Wed, 13 Apr 2011 16:27:03 +0200
> Oleg Nesterov <oleg@redhat.com> wrote:
>
> > On 04/13, Alexey Dobriyan wrote:
> > >
> > > +#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)))));							\
> > > +})
> >
> > Personally I agree.
> >
> > But, we have some stupid users which do something like abs(u32_value)
> > and expecting that abs() should treat this value as "signed".
> >
>
> um, yes, I'd forgotten that one.  That's a show-stopper.

May be we can demand to fix them?

I agree with Alexey, it is a bit ugly to have abs() and abs64(), and abs()
itself doesn't look very nice.

What if we simply add

	BUILD_BUG_ON( (typeof(_x)-1) > 0 );

into abs()?

After that it would be trivial to find the offenders and fix them,

	- abs(unsigned_int)
	+ abs((int) unsigned_int)

Oleg.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-13 20:20     ` Oleg Nesterov
@ 2011-04-13 20:26       ` Andrew Morton
  2011-04-13 20:36         ` Alexey Dobriyan
  0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2011-04-13 20:26 UTC (permalink / raw)
  To: Oleg Nesterov; +Cc: Alexey Dobriyan, linux-kernel, behlendorf1

On Wed, 13 Apr 2011 22:20:31 +0200
Oleg Nesterov <oleg@redhat.com> wrote:

> > > But, we have some stupid users which do something like abs(u32_value)
> > > and expecting that abs() should treat this value as "signed".
> > >
> >
> > um, yes, I'd forgotten that one.  That's a show-stopper.
> 
> May be we can demand to fix them?
> 
> I agree with Alexey, it is a bit ugly to have abs() and abs64(), and abs()
> itself doesn't look very nice.
> 
> What if we simply add
> 
> 	BUILD_BUG_ON( (typeof(_x)-1) > 0 );
> 
> into abs()?
> 
> After that it would be trivial to find the offenders and fix them,
> 
> 	- abs(unsigned_int)
> 	+ abs((int) unsigned_int)

Something like that.  But it should be done before we change abs(), to
avoid nasty breakage in obscure places.

Or we rework the abs() implementation so that the abs(unsigned)
behavior is unchanged.

There will remain the problem that the abs() return value's signedness
has changed.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] remove abs64()
  2011-04-13 20:26       ` Andrew Morton
@ 2011-04-13 20:36         ` Alexey Dobriyan
  0 siblings, 0 replies; 12+ messages in thread
From: Alexey Dobriyan @ 2011-04-13 20:36 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Oleg Nesterov, linux-kernel, behlendorf1

On Wed, Apr 13, 2011 at 01:26:29PM -0700, Andrew Morton wrote:
> On Wed, 13 Apr 2011 22:20:31 +0200
> Oleg Nesterov <oleg@redhat.com> wrote:
> 
> > > > But, we have some stupid users which do something like abs(u32_value)
> > > > and expecting that abs() should treat this value as "signed".
> > > >
> > >
> > > um, yes, I'd forgotten that one.  That's a show-stopper.
> > 
> > May be we can demand to fix them?
> > 
> > I agree with Alexey, it is a bit ugly to have abs() and abs64(), and abs()
> > itself doesn't look very nice.
> > 
> > What if we simply add
> > 
> > 	BUILD_BUG_ON( (typeof(_x)-1) > 0 );
> > 
> > into abs()?
> > 
> > After that it would be trivial to find the offenders and fix them,
> > 
> > 	- abs(unsigned_int)
> > 	+ abs((int) unsigned_int)
> 
> Something like that.  But it should be done before we change abs(), to
> avoid nasty breakage in obscure places.
> 
> Or we rework the abs() implementation so that the abs(unsigned)
> behavior is unchanged.
> 
> There will remain the problem that the abs() return value's signedness
> has changed.

Maybe I can sneak in kabs() ang gradually convert?

Reading abs(3) manpage, it returns int minumum, so semantic change
notice would be nice.

Anyway patch as posted was buggy in the following sense:

	_b_t_c_p(char, signed char) == 0

		AND
	
	_b_t_c_p(char, unsigned char) == 0

so if char is signed, it doesn't work.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-04-13 20:36 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-12 21:00 [PATCH] remove abs64() Alexey Dobriyan
2011-04-12 21:07 ` Randy Dunlap
2011-04-12 21:10   ` Andrew Morton
2011-04-12 21:16     ` Alexey Dobriyan
2011-04-12 21:33       ` Andrew Morton
2011-04-12 21:40         ` Randy Dunlap
2011-04-12 21:14   ` Alexey Dobriyan
2011-04-13 14:27 ` Oleg Nesterov
2011-04-13 18:48   ` Andrew Morton
2011-04-13 20:20     ` Oleg Nesterov
2011-04-13 20:26       ` Andrew Morton
2011-04-13 20:36         ` Alexey Dobriyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).