This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] i386.c string alignment - no alignment for < 32 bytes, else to 32 bytes



John

thanks.

> > gcc has a bug with string alignment on the x86.  For short strings,
> > it doesn't align at all.  For strings longer than 32 bytes,
> > it needlessly aligns them to 32 bytes. NB: this is only on the x86.
> 
> This is per the recommendations of the "Intel Architecture
> Optimization Manual".

I checked in the IA Optimization Manual, p 2-12.  It says:

    Alignment Rules and Guidelines
    ...
      Data
    ...
        Align 8-bit data at any address.
    ...
        A 32-byte or greater data structure or array should be aligned
        so the beginning of each structure or array element is aligned
        in a way that its base address is a multiple of thirty-two.

Let's take the second case first.  Applying this rule to *all* 32-byte
strings is trading off a trivial amount of optimization for memory.
These constants are not dynamically allocated objects, they are static
constants rarely used.  Format strings might be the heroic exception.
It is just wasted space.  I think the IAOM has an implicit
"if you want *this particular* piece of data to be fast".
For these strings, most of the time you don't care,
especially for compiler generated strings.

BTW, the decl stuff I mentioned might appropriately handle the
exceptional cases.

In the first case, well, I think you're right.  A case could be made
for 4-byte alignment allowing builtins more leeway for code generation
but I think that falls into the exceptional case category.  To be
clear,
4-byte alignment only helps on the Pentium if the underlying code
knows and can take adavantage of it.

The general case should be no alignment unless the compiler knows
from context, not just length, that the data would benefit from
being aligned.

I've appended a modified patch omitting the 32-byte alignment
of longer strings.  It still allows 32-byte alignment of decl's.


Chris Sears
cbsears_sf@yahoo.com

__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

Attachment: i386.c.PATCH
Description: i386.c.PATCH


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]