Re: [PATCH] removal of "static foo = 0"

Michael Meissner
2000-11-27T18:31:08Z

On Mon, Nov 27, 2000 at 09:41:39AM +0100, Werner Almesberger wrote:
> Adam J. Richter wrote:
> > At the moment, I have started daydreaming about instead
> > writing an "elf squeezer" to do this and other space optimizations
> > by modifying objdump.
>
> Hmm, this would require that gcc never calculates the location of an
> explicitly initialized static variable based on the address of another
> one. E.g. in
>
> static int a = 0, b = 0, c = 0, d = 0;
>
> ...
> ... a+b+c+d ...
> ...
>
> egcs-2.91.66 indeed doesn't seem to make this optimization on i386.
> (Maybe the pointer increment or pointer offset solution would
> actually be slower - didn't check.) But I'm not sure if this is also
> true for other versions/architectures, or other code constructs.

Jeff Law played with a similar optimization about 1-2 years ago, and eventually
deleted all of the code because there were problems with the code. It would
help some of our platforms (but not the x86) to access all variables in the
same section via a common pointer. This is because on those systems, it often
times takes 2-3 instructions to access global/static variables. Global
variables you have more problems visiblity and such.

--
Michael Meissner, Red Hat, Inc.
PMB 198, 174 Littleton Road #3, Westford, Massachusetts 01886, USA
Work: meissner@redhat.com phone: +1 978-486-9304
Non-work: meissner@spectacle-pond.org fax: +1 978-692-4482