Re: Misalignment of local SSE variables in thread function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jonathan Kinsey wrote:
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;
}


I don't remember what was said in the past, but any gcc function which uses SSE parallel instructions must be called from a gcc function which passes a 16-byte aligned stack. So you may be able to overcome it by interposing a wrapper function at the thread entry point (which does not use parallel SSE), with all gcc functions compiled with normal options (not -Os, which sets a smaller value in -mpreferred-stack-alignment). To speculate further, possibly your pthreads library was compiled with options which don't pass 16-byte aligned stack.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux