This is the mail archive of the gcc-bugs@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]

[Bug c/12105] Local Variabels on "Out-of-phase" Alignment on x86


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12105



------- Additional Comments From steffen at boerm dot net  2003-09-10 14:07 -------
Subject:  New: Local Variabels on "Out-of-phase" Alignment on x86


Hi.

I ran into the same problem when trying to use SSE in my programs. I
fixed it by using an inline assembler hack:

  asm("movl %esp,%eax");
  asm("andl $15,%eax");
  asm("subl %esp,%eax");

Putting this fragment at the beginning of main() makes sure that the
stack pointer is correctly aligned for all functions called from main(),
so all local variables are aligned properly and SSE works just fine.

Of course, this is not the optimal way of doing it, just a quick'n'dirty
workaround. Inlining, for example, will break it.
Using "-fomit-frame-pointer" should break it also.
I guess the safest way of using my hack would be to use an extremely
short main() function that calls "fixedmain()" function that does the
real work and is somehow protected against being inlined. As soon as
fixedmain() is reached, all registers have the values they are supposed
to have and inlining should work as usual.

I guess that the best way of fixing this permanently would be to make
sure that the startup code in some crt*.o file corrects the stack
pointer before calling main(). Then all problems should disappear.

Best regards,
Steffen 8-)


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