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]

Re: __attribute__((aligned(16)) on x86


On Jul 28, 2001, "Ryan T. Sammartino" <ryants@home.com> wrote:

> I'm afraid I don't see the connection between glibc and
> __attribute__((aligned())).

> When I have something on the stack that is aligned to a certain
> boundary, I expect the compiler to do something like:

> sub 8, %esp
> and -16, %esp
> add 4, %esp
> <now put variables on the stack>

AFAIK, GCC doesn't do anything like this.  It *maintains* the stack
aligned to a certain ABI-specified alignment, but it doesn't introduce
additional alignment.  Therefore, if the start-up code doesn't get the
stack aligned as specified in the ABI GCC is following, it will remain
unaligned throughout the execution of the application.

Doing it this way is a matter of efficiency: by only modifying the
stack pointer such that it remains aligned means you can save some
`and's and `add's.

> Aligning the stack is no good, since if I do something like:

> char c;
> vector v1;

> my vector will be misaligned by sizeof(char).

Nope; GCC knows how the stack must be aligned, and it will add padding
to stack frames to make sure the stack pointer remains aligned.

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist    *Please* write to mailing lists, not to me


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