public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: x*alloc optimizations
@ 1998-05-18 18:06 Michael Meissner
  1998-05-20  7:09 ` Jim Meyering
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-18 18:06 UTC (permalink / raw)
  To: drepper; +Cc: egcs

| law@cygnus.com (Jeffrey A Law) writes:
|
| > I quickly scanned your patch for any problems this creates, but didn't
| > find any.  However, we should probably fix xrealloc to avoid losing if
| > a zero sized request is made.
|
| But please fix this system dependent.  I.e., add a configure test for
| this non-ISO C behaviour and don't let normal systems do the same work
| twice (since their realloc implementation again checks for NULL).

This is an unneeded micro-optimization.  I would rather burn the 2-3
instructions for every xmalloc call than add a bunch of configure support and
ifdefs to complicate the code.  Especially for Canadian crosses where you can't
test the behavior of the runtime system.  Another problem is that when GCC
configured it, malloc/calloc/realloc behaved in one fashion, but when the user
put the binary compiler on his/her system, the system malloc in the shared
library now behaves differently.

--
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)


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

* Re: x*alloc optimizations
  1998-05-18 18:06 x*alloc optimizations Michael Meissner
@ 1998-05-20  7:09 ` Jim Meyering
  0 siblings, 0 replies; 12+ messages in thread
From: Jim Meyering @ 1998-05-20  7:09 UTC (permalink / raw)
  To: Michael Meissner; +Cc: drepper, egcs

Michael Meissner <meissner@cygnus.com> writes:
| This is an unneeded micro-optimization.  I would rather burn the 2-3
| instructions for every xmalloc call than add a bunch of configure support and
| ifdefs to complicate the code.  Especially for Canadian crosses where you can't
| test the behavior of the runtime system.  Another problem is that when GCC
| configured it, malloc/calloc/realloc behaved in one fashion, but when the user
| put the binary compiler on his/her system, the system malloc in the shared
| library now behaves differently.

I admit it may not be worth it, but it can be done without
complicating the code.  Uses of *alloc functions don't change
at all, and the only ifdefs I added (when I did this for fileutils)
were in the replacement lib/*alloc.c functions.  The m4 tests assume
*alloc are broken when cross compiling.

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

* Re: x*alloc optimizations
  1998-05-20 19:03 ` Ulrich Drepper
@ 1998-05-21  0:51   ` Richard Henderson
  0 siblings, 0 replies; 12+ messages in thread
From: Richard Henderson @ 1998-05-21  0:51 UTC (permalink / raw)
  To: Ulrich Drepper, Michael Meissner; +Cc: meyering, egcs

On Wed, May 20, 1998 at 12:29:19PM -0700, Ulrich Drepper wrote:
> Come on!  This is no arbitrary test.  This is the test for ISO C
> compliance and no vendor will dare to make an compliant library
> suddenly uncompliant.

No, Mike has a point.  The issue is not that one would suddenly make
the library non-compliant, but that a compiler built for OS version
X.Y.1 might not work on X.Y.0 because it was the .1 that fixed the ISO bug.


r~

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

* Re: x*alloc optimizations
@ 1998-05-20 19:03 Michael Meissner
  1998-05-20 19:03 ` Ulrich Drepper
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-20 19:03 UTC (permalink / raw)
  To: meissner, meyering; +Cc: drepper, egcs

| Michael Meissner <meissner@cygnus.com> writes:
| | This is an unneeded micro-optimization.  I would rather burn the 2-3
| | instructions for every xmalloc call than add a bunch of configure support and
| | ifdefs to complicate the code.  Especially for Canadian crosses where you can't
| | test the behavior of the runtime system.  Another problem is that when GCC
| | configured it, malloc/calloc/realloc behaved in one fashion, but when the user
| | put the binary compiler on his/her system, the system malloc in the shared
| | library now behaves differently.
|
| I admit it may not be worth it, but it can be done without
| complicating the code.  Uses of *alloc functions don't change
| at all, and the only ifdefs I added (when I did this for fileutils)
| were in the replacement lib/*alloc.c functions.  The m4 tests assume
| *alloc are broken when cross compiling.

While linux gnulibc{1,2} may or may not change the behavior of malloc, I have
witnessed this at OSF, where one revision of OSF/1 had malloc do one behavior
(crash on NULL pointer to realloc or return NULL, I forget which), and the next
revision did another behavior (return unique pointer).  I as supplier of
compiler binaries then would have my releases not work, if I built the compiler
on one revision, and had users on the other revision tried to use the
compiler.  Depending on a configure test for malloc/realloc behavior is utterly
dangerous for providers of binary software.

--
Michael Meissner, Cygnus Solutions (Massachusetts office)
4th floor, 955 Massachusetts Avenue, Cambridge, MA 02139, USA
meissner@cygnus.com,	617-354-5416 (office),	617-354-7161 (fax)


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

* Re: x*alloc optimizations
  1998-05-20 12:48 Michael Meissner
@ 1998-05-20 19:03 ` Ulrich Drepper
  0 siblings, 0 replies; 12+ messages in thread
From: Ulrich Drepper @ 1998-05-20 19:03 UTC (permalink / raw)
  To: Michael Meissner; +Cc: egcs

Michael Meissner <meissner@cygnus.com> writes:

> There are loads of uncomplaint systems.

Agreed, and this is what Jim's macros are testing for.  I commented on
your comment that relying on realloc(NULL,size) is unsafe since some
vendor might change the behaviour.

> Also ISO C has two different behaviors (return NULL or return a
> unique pointer).  If you test for one, a system vendor may change
> his/her implementation to do the other behavior without breaking ISO
> C conformance.

But this isn't what we are testing for.  This is uninteresting here.
All the macros do is to test whether

	realloc(NULL, size) == malloc(size)

as demanded by ISO C and the "worst" which could happen is that one
more vendors sees the light and changes the non-ISO C behaviour.

-- Uli
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

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

* Re: x*alloc optimizations
  1998-05-20 19:03 Michael Meissner
@ 1998-05-20 19:03 ` Ulrich Drepper
  1998-05-21  0:51   ` Richard Henderson
  0 siblings, 1 reply; 12+ messages in thread
From: Ulrich Drepper @ 1998-05-20 19:03 UTC (permalink / raw)
  To: Michael Meissner; +Cc: meyering, egcs

Michael Meissner <meissner@cygnus.com> writes:

> I as supplier of compiler binaries then would have my releases not
> work, if I built the compiler on one revision, and had users on the
> other revision tried to use the compiler.  Depending on a configure
> test for malloc/realloc behavior is utterly dangerous for providers
> of binary software.

Come on!  This is no arbitrary test.  This is the test for ISO C
compliance and no vendor will dare to make an compliant library
suddenly uncompliant.

-- Uli
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

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

* Re: x*alloc optimizations
@ 1998-05-20 12:48 Michael Meissner
  1998-05-20 19:03 ` Ulrich Drepper
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Meissner @ 1998-05-20 12:48 UTC (permalink / raw)
  To: drepper; +Cc: egcs

| Michael Meissner <meissner@cygnus.com> writes:
|
| > I as supplier of compiler binaries then would have my releases not
| > work, if I built the compiler on one revision, and had users on the
| > other revision tried to use the compiler.  Depending on a configure
| > test for malloc/realloc behavior is utterly dangerous for providers
| > of binary software.
|
| Come on!  This is no arbitrary test.  This is the test for ISO C
| compliance and no vendor will dare to make an compliant library
| suddenly uncompliant.

There are loads of uncomplaint systems.  Also ISO C has two different
behaviors (return NULL or return a unique pointer).  If you test for one, a
system vendor may change his/her implementation to do the other behavior
without breaking ISO C conformance.

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

* Re: x*alloc optimizations
  1998-05-18 22:49     ` Jeffrey A Law
@ 1998-05-20  8:42       ` Jim Meyering
  0 siblings, 0 replies; 12+ messages in thread
From: Jim Meyering @ 1998-05-20  8:42 UTC (permalink / raw)
  To: law; +Cc: Ulrich Drepper, egcs

Jeffrey A Law <law@cygnus.com> writes:

|   In message < r2af8fzfwu.fsf@happy.cygnus.com >you write:
|   > law@cygnus.com (Jeffrey A Law) writes:
|   >
|   > > I quickly scanned your patch for any problems this creates, but didn't
|   > > find any.  However, we should probably fix xrealloc to avoid losing if
|   > > a zero sized request is made.
|   >
|   > But please fix this system dependent.  I.e., add a configure test for
|   > this non-ISO C behaviour and don't let normal systems do the same work
|   > twice (since their realloc implementation again checks for NULL).
| The amount of time saved by this optimization is likely to be so
| small that it's dwarfed by the time to write an autoconf test make
| sure it does the right thing, and get it checked in.  :-)
|
| IMHO, it's not worth the effort.

In case anyone decides to do this, you don't have to
write the autoconf tests;  I already did it for fileutils:

  ftp://alpha.gnu.org/gnu/fileutils-3.16n.tar.gz

see these files:

  lib/malloc.c
  lib/realloc.c
  m4/malloc.m4
  m4/realloc.m4

I don't know if it was worth the effort, but I'm happier :-)

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

* Re: x*alloc optimizations
  1998-05-18  9:58   ` Ulrich Drepper
@ 1998-05-18 22:49     ` Jeffrey A Law
  1998-05-20  8:42       ` Jim Meyering
  0 siblings, 1 reply; 12+ messages in thread
From: Jeffrey A Law @ 1998-05-18 22:49 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: egcs

  In message < r2af8fzfwu.fsf@happy.cygnus.com >you write:
  > law@cygnus.com (Jeffrey A Law) writes:
  > 
  > > I quickly scanned your patch for any problems this creates, but didn't
  > > find any.  However, we should probably fix xrealloc to avoid losing if
  > > a zero sized request is made.
  > 
  > But please fix this system dependent.  I.e., add a configure test for
  > this non-ISO C behaviour and don't let normal systems do the same work
  > twice (since their realloc implementation again checks for NULL).
The amount of time saved by this optimization is likely to be so
small that it's dwarfed by the time to write an autoconf test make
sure it does the right thing, and get it checked in.  :-)

IMHO, it's not worth the effort.

jeff

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

* Re: x*alloc optimizations
       [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
@ 1998-05-18  9:58   ` Ulrich Drepper
  1998-05-18 22:49     ` Jeffrey A Law
  0 siblings, 1 reply; 12+ messages in thread
From: Ulrich Drepper @ 1998-05-18  9:58 UTC (permalink / raw)
  To: egcs

law@cygnus.com (Jeffrey A Law) writes:

> I quickly scanned your patch for any problems this creates, but didn't
> find any.  However, we should probably fix xrealloc to avoid losing if
> a zero sized request is made.

But please fix this system dependent.  I.e., add a configure test for
this non-ISO C behaviour and don't let normal systems do the same work
twice (since their realloc implementation again checks for NULL).

-- Uli
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

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

* Re: x*alloc optimizations
  1998-05-16 22:35 Richard Henderson
@ 1998-05-18  2:09 ` Jeffrey A Law
       [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
  1 sibling, 0 replies; 12+ messages in thread
From: Jeffrey A Law @ 1998-05-18  2:09 UTC (permalink / raw)
  To: Richard Henderson; +Cc: egcs

  In message < 19980516145345.A680@dot.cygnus.com >you write:
  > Two things.  
  > 
  >   (1) Since we define xrealloc, we can trust it to do the right thing
  >       when given a NULL initial argument.  
  > 
  >   (2) Using calloc instead of malloc+bzero can be more efficient.  At
  >       least glibc's calloc knows that space newly acquired from the
  >       system is already zero.  This is particularaly relevant to the
  >       large memory blocks gcc tends to allocate during optimization.
The only potential problem I see is xrealloc doesn't check for a zero
length size parameter like xmalloc (and the new xcalloc).

I quickly scanned your patch for any problems this creates, but didn't
find any.  However, we should probably fix xrealloc to avoid losing if
a zero sized request is made.

Otherwise it looks fine to me.

jeff


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

* x*alloc optimizations
@ 1998-05-16 22:35 Richard Henderson
  1998-05-18  2:09 ` Jeffrey A Law
       [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Henderson @ 1998-05-16 22:35 UTC (permalink / raw)
  To: egcs

Two things.  

  (1) Since we define xrealloc, we can trust it to do the right thing
      when given a NULL initial argument.  

  (2) Using calloc instead of malloc+bzero can be more efficient.  At
      least glibc's calloc knows that space newly acquired from the
      system is already zero.  This is particularaly relevant to the
      large memory blocks gcc tends to allocate during optimization.


r~

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

end of thread, other threads:[~1998-05-21  0:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-05-18 18:06 x*alloc optimizations Michael Meissner
1998-05-20  7:09 ` Jim Meyering
  -- strict thread matches above, loose matches on Subject: below --
1998-05-20 19:03 Michael Meissner
1998-05-20 19:03 ` Ulrich Drepper
1998-05-21  0:51   ` Richard Henderson
1998-05-20 12:48 Michael Meissner
1998-05-20 19:03 ` Ulrich Drepper
1998-05-16 22:35 Richard Henderson
1998-05-18  2:09 ` Jeffrey A Law
     [not found] ` <25274.895468839.cygnus.egcs@hurl.cygnus.com>
1998-05-18  9:58   ` Ulrich Drepper
1998-05-18 22:49     ` Jeffrey A Law
1998-05-20  8:42       ` Jim Meyering

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 read-only IMAP folder(s) and NNTP newsgroup(s).