This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Misalignment of local SSE variables in thread function
- From: Danny Smith <dannysmith at clear dot net dot nz>
- To: jon_kinsey at hotmail dot com
- Cc: GCC-help at gcc dot gnu dot org
- Date: Fri, 19 Jan 2007 06:53:06 +1300
- Subject: RE: Misalignment of local SSE variables in thread function
>
> * From: Jonathan Kinsey <jon_kinsey at hotmail dot com>
> * To: gcc-help at gcc dot gnu dot org
> * Date: Wed, 17 Jan 2007 14:47:39 +0000
> * Subject: Misalignment of local SSE variables in thread function
>
> This is a problem that I've seen in the archives and is marked as not
> being a problem with gcc. I'm not sure what the solution is though,
the
> simple test below runs fine using the Microsoft compiler (on windows)
> and fails using gcc (3.4.5) compiler. There is no pthreads or glib
code
> here.
>
> The output shows that the second call to f(), in the thread, has a
> misaligned s variable (which will crash in a SSE call).
>
> Jon
>
> #include <stdio.h>
> #include <process.h>
> #include <windows.h>
> #include <xmmintrin.h>
> void f(void *p)
> {
> __m128 s;
> printf("%d\n", ((int)&s) % 16);
> }
>
> int main(int argc, char ** argv)
> {
> f(0);
> _beginthread(f, 0, 0);
>
> Sleep(2000);
> return 0;
> }
With gcc 4.1, add this attribute to definition to force 16-byte
alignmnent:
void __attribute__ ((force_align_arg_pointer)) f (void * p) {...}
Search GCC's bugzilla. This bug has been reported before.
Finally, with 3.4.5, look up the mingw bug report archives were this
problem this discussed. and a workaround (using a wrapper function to
force align) suggested.
Danny