Misalignment of local SSE variables in thread function

Jonathan Kinsey jon_kinsey@hotmail.com
Thu Jan 18 16:21:00 GMT 2007


Andrew Haley wrote:
> Brian Dessent writes:
>  > Jonathan Kinsey wrote:
>  > 
>  > > Thanks for the link, unfortunately it doesn't work _beginthread just
>  > > calls _beginthreadex - unless there is a alignment argument I didn't see
>  > > (I tried it anyway and no luck).
>  > > 
>  > > If you read the end of the post at the link it says that it doesn't fix
>  > > a SSE problem that someone was having - at least I'm not on my own...
>  > 
>  > I did read that but I hoped it was someone having unrelated problems.  I
>  > guess it's not.
>  > 
>  > So, neither CreateThread nor MSVCRT align the stack, so I guess you'll
>  > have to do it yourself.  You should be able to do this with something
>  > like:
>  > 
>  >   asm  __volatile__  ("andl $-16, %%esp" : : : "%esp");
>  > 
>  > at the beginning of your thread function.
> 
> Ouch.  I don't think that would work.
> 
>  > You could probably do this in a wrapper-function that calls your
>  > actual thread function too.
> 
> That sounds like a much better idea, although it may well also be
> problematic.
> 
> A pure assembly function that did the adjustment and called your
> actual thread function would be the best idea.

It does work in the simple test.  I imagine it may cause problems with
stack over/under writes?

I'll try it in the actual code that caused the initial problem and see
what happens...

Jon



More information about the Gcc-help mailing list