This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: __attribute__((aligned(16)) on x86
* Alexandre Oliva <aoliva@redhat.com> [28/07/2001 21:58]:
> AFAIK, GCC doesn't do anything like this.
Right, it doesn't. That's the problem.
> 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.
Well, that's no good, especially when certain alignment is required (as
in doing SSE stuff).
> 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.
I think I'd rather have some extra "and"s and "add"s than a
"Segmentation fault"... weird personal preference of mine.
> > 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.
Sure, the stack pointer might be aligned, but what about the stuff on
the stack, like v1?
Perhaps my original question was unclear, as it seems we've gone off on
some irrelevent tangent.
When I say: __attribute__((aligned(16))), I want every variable of that
type to be on a 16 byte boundary: if I do:
static vector v1;
then gcc does the right thing and emits a .align 16 for that vector.
But if I do:
void foo(void)
{
vector v1;
...
}
then the alignement of v1 is currently left up to the current alignment
of the frame pointer. This is no good, since it is almost always wrong,
and the first SSE instruction I try on that vector blows up.
So my question is: where should I start poking gcc source so that it
emits instructions that guarantee that v1 will be in a memory address
that is divisible by 16? Is it in final.c? Any pointers on how someone
who has never really looked at gcc source code before might get started?
--
Ryan T. Sammartino
http://members.home.net/ryants/
A real gentleman never takes bases unless he really has to.
-- Overheard in an algebra lecture.