public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* 2.4.0-test10-pre6: Use of abs()
@ 2000-10-28 16:29 Horst von Brand
  2000-10-30 14:01 ` Martin Dalecki
  0 siblings, 1 reply; 9+ messages in thread
From: Horst von Brand @ 2000-10-28 16:29 UTC (permalink / raw)
  To: linux-kernel

Red Hat 7.0, i686, gcc-20001027 (Yes, I know. Just to flush out bugs on
both sides).

abs() is used at least in:

arch/i386/kernel/time.c
drivers/md/raid1.c
drivers/sound/sb_ess.c

gcc warns about use of a non-declared function each time.

No definition for the function is to be found (grep over all include/ comes
up clean, except for extern definitions in asm-{mips,ppc}; ditto for lib/).
Presumably gcc is using a builtin (it doesn't show up in System.map). Is
this the desired state of affairs? Should a include/linux/stdlib.h be
added, containing (for now, to be expanded later as needed, like
include/linux/stddef.h):

#ifndef _LINUX_STDLIB_H
#define _LINUX_STDLIB_H

extern int abs(int);

#endif
-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Vin~a del Mar, Chile                               +56 32 672616
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-10-30 14:01 ` Martin Dalecki
@ 2000-10-30 13:19   ` Jakub Jelinek
  2000-10-30 16:14     ` Martin Dalecki
  0 siblings, 1 reply; 9+ messages in thread
From: Jakub Jelinek @ 2000-10-30 13:19 UTC (permalink / raw)
  To: Martin Dalecki; +Cc: Horst von Brand, linux-kernel

On Mon, Oct 30, 2000 at 03:01:16PM +0100, Martin Dalecki wrote:
> Horst von Brand wrote:
> > 
> > Red Hat 7.0, i686, gcc-20001027 (Yes, I know. Just to flush out bugs on
> > both sides).
> > 
> > abs() is used at least in:
> > 
> > arch/i386/kernel/time.c
> > drivers/md/raid1.c
> > drivers/sound/sb_ess.c
> > 
> > gcc warns about use of a non-declared function each time.
> > 
> > No definition for the function is to be found (grep over all include/ comes
> > up clean, except for extern definitions in asm-{mips,ppc}; ditto for lib/).
> > Presumably gcc is using a builtin (it doesn't show up in System.map). Is
> > this the desired state of affairs? Should a include/linux/stdlib.h be
> 
> Yes abs will be transformed into an internal function, which will be
> fully
> unrolled due to -O2.

No matter what it should be prototyped in some header. And all uses should
be checked, because abs is 
int abs (int) __attribute__ ((__const__));
and sometimes people use it on `long' instead (such a bug has been fixed in
the kernel some months ago).

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

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-10-28 16:29 2.4.0-test10-pre6: Use of abs() Horst von Brand
@ 2000-10-30 14:01 ` Martin Dalecki
  2000-10-30 13:19   ` Jakub Jelinek
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Dalecki @ 2000-10-30 14:01 UTC (permalink / raw)
  To: Horst von Brand; +Cc: linux-kernel

Horst von Brand wrote:
> 
> Red Hat 7.0, i686, gcc-20001027 (Yes, I know. Just to flush out bugs on
> both sides).
> 
> abs() is used at least in:
> 
> arch/i386/kernel/time.c
> drivers/md/raid1.c
> drivers/sound/sb_ess.c
> 
> gcc warns about use of a non-declared function each time.
> 
> No definition for the function is to be found (grep over all include/ comes
> up clean, except for extern definitions in asm-{mips,ppc}; ditto for lib/).
> Presumably gcc is using a builtin (it doesn't show up in System.map). Is
> this the desired state of affairs? Should a include/linux/stdlib.h be

Yes abs will be transformed into an internal function, which will be
fully
unrolled due to -O2.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-10-30 13:19   ` Jakub Jelinek
@ 2000-10-30 16:14     ` Martin Dalecki
  2000-11-01 14:46       ` tytso
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Dalecki @ 2000-10-30 16:14 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Horst von Brand, linux-kernel

Jakub Jelinek wrote:
> 
> On Mon, Oct 30, 2000 at 03:01:16PM +0100, Martin Dalecki wrote:
> > Horst von Brand wrote:
> > >
> > > Red Hat 7.0, i686, gcc-20001027 (Yes, I know. Just to flush out bugs on
> > > both sides).
> > >
> > > abs() is used at least in:
> > >
> > > arch/i386/kernel/time.c
> > > drivers/md/raid1.c
> > > drivers/sound/sb_ess.c
> > >
> > > gcc warns about use of a non-declared function each time.
> > >
> > > No definition for the function is to be found (grep over all include/ comes
> > > up clean, except for extern definitions in asm-{mips,ppc}; ditto for lib/).
> > > Presumably gcc is using a builtin (it doesn't show up in System.map). Is
> > > this the desired state of affairs? Should a include/linux/stdlib.h be
> >
> > Yes abs will be transformed into an internal function, which will be
> > fully
> > unrolled due to -O2.
> 
> No matter what it should be prototyped in some header. And all uses should
> be checked, because abs is
> int abs (int) __attribute__ ((__const__));
> and sometimes people use it on `long' instead (such a bug has been fixed in
> the kernel some months ago).

Of corse right! BTW. There are tons of places where log2 is calculated
explicitly in kernel which should be replaced with the corresponding
built 
in functions as well (/dev/random code does it). And then If I remember
correctly
there is an attribute which is telling about internal functions
in declarations explicitly as well?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-10-30 16:14     ` Martin Dalecki
@ 2000-11-01 14:46       ` tytso
  2000-11-01 18:22         ` Richard Henderson
  2000-11-02  3:02         ` Theodore Y. Ts'o
  0 siblings, 2 replies; 9+ messages in thread
From: tytso @ 2000-11-01 14:46 UTC (permalink / raw)
  To: Martin Dalecki; +Cc: Jakub Jelinek, Horst von Brand, linux-kernel

On Mon, Oct 30, 2000 at 05:14:34PM +0100, Martin Dalecki wrote:
> Of corse right! BTW. There are tons of places where log2 is calculated
> explicitly in kernel which should be replaced with the corresponding
> built 
> in functions as well (/dev/random code does it). And then If I remember
> correctly
> there is an attribute which is telling about internal functions
> in declarations explicitly as well?

What versions of gcc produce the built-in functions?  And does it do
so for *all* platforms?  (i.e., PPC, Alpha, IA64, etc., etc., etc.)

						- Ted

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

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-11-01 14:46       ` tytso
@ 2000-11-01 18:22         ` Richard Henderson
  2000-11-02 12:14           ` Martin Dalecki
  2000-11-02  3:02         ` Theodore Y. Ts'o
  1 sibling, 1 reply; 9+ messages in thread
From: Richard Henderson @ 2000-11-01 18:22 UTC (permalink / raw)
  To: tytso; +Cc: Martin Dalecki, Jakub Jelinek, Horst von Brand, linux-kernel

On Wed, Nov 01, 2000 at 09:46:19AM -0500, tytso@mit.edu wrote:
> What versions of gcc produce the built-in functions?

2.95 and previous.  In 2.96 somewhere we fixed a bug that
automatically prototypes these builtin functions for you;
ie with current code you get an undeclared function warning.

> And does it do so for *all* platforms?  (i.e., PPC, Alpha,
> IA64, etc., etc., etc.)

Yes.  The thing about abs, though, is that it's "int abs(int)"
which does naughty things with longs on 64-bit targets.  You're
much better off writing (x < 0 ? -x : x) directly.


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

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-11-01 14:46       ` tytso
  2000-11-01 18:22         ` Richard Henderson
@ 2000-11-02  3:02         ` Theodore Y. Ts'o
  1 sibling, 0 replies; 9+ messages in thread
From: Theodore Y. Ts'o @ 2000-11-02  3:02 UTC (permalink / raw)
  To: tytso; +Cc: Martin Dalecki, Jakub Jelinek, Horst von Brand, linux-kernel

   Date: Wed, 1 Nov 2000 09:46:19 -0500
   From: tytso@MIT.EDU

   On Mon, Oct 30, 2000 at 05:14:34PM +0100, Martin Dalecki wrote:
   > Of corse right! BTW. There are tons of places where log2 is calculated
   > explicitly in kernel which should be replaced with the corresponding
   > built 
   > in functions as well (/dev/random code does it). And then If I remember
   > correctly
   > there is an attribute which is telling about internal functions
   > in declarations explicitly as well?


And in the case of /dev/random, since we know something about what the
possible inputs can be, I'm fairly certain that the "int_ln_12bits" used
by /dev/random is probably far better than the general purpose code
which GCC no doubt has to emit....

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

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-11-01 18:22         ` Richard Henderson
@ 2000-11-02 12:14           ` Martin Dalecki
  2000-11-02 19:37             ` Richard Henderson
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Dalecki @ 2000-11-02 12:14 UTC (permalink / raw)
  To: Richard Henderson; +Cc: tytso, Jakub Jelinek, Horst von Brand, linux-kernel

Richard Henderson wrote:
> 
> On Wed, Nov 01, 2000 at 09:46:19AM -0500, tytso@mit.edu wrote:
> > What versions of gcc produce the built-in functions?
> 
> 2.95 and previous.  In 2.96 somewhere we fixed a bug that
> automatically prototypes these builtin functions for you;
> ie with current code you get an undeclared function warning.
> 
> > And does it do so for *all* platforms?  (i.e., PPC, Alpha,
> > IA64, etc., etc., etc.)
> 
> Yes.  The thing about abs, though, is that it's "int abs(int)"
> which does naughty things with longs on 64-bit targets.  You're
> much better off writing (x < 0 ? -x : x) directly.

Thank's for answering it... I was already looking up the GCC source for
an exact answer ;-). However what's the difference in respect of
optimization between unrolling the abs function by hand and
relying on the built in?
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/

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

* Re: 2.4.0-test10-pre6: Use of abs()
  2000-11-02 12:14           ` Martin Dalecki
@ 2000-11-02 19:37             ` Richard Henderson
  0 siblings, 0 replies; 9+ messages in thread
From: Richard Henderson @ 2000-11-02 19:37 UTC (permalink / raw)
  To: Martin Dalecki; +Cc: tytso, Jakub Jelinek, Horst von Brand, linux-kernel

On Thu, Nov 02, 2000 at 01:14:49PM +0100, Martin Dalecki wrote:
> However what's the difference in respect of optimization between
> unrolling the abs function by hand and relying on the built in?

Should be nothing.  The expanded source expression should get
folded immediately to an ABS_EXPR node, at which point you are
at exactly the same point as the builtin would have gotten you.


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

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

end of thread, other threads:[~2000-11-02 19:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-10-28 16:29 2.4.0-test10-pre6: Use of abs() Horst von Brand
2000-10-30 14:01 ` Martin Dalecki
2000-10-30 13:19   ` Jakub Jelinek
2000-10-30 16:14     ` Martin Dalecki
2000-11-01 14:46       ` tytso
2000-11-01 18:22         ` Richard Henderson
2000-11-02 12:14           ` Martin Dalecki
2000-11-02 19:37             ` Richard Henderson
2000-11-02  3:02         ` Theodore Y. Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox