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

Re: Misalignment of local SSE variables in thread function


Jonathan Kinsey wrote:
Tim Prince wrote:
Jonathan Kinsey wrote:
Tim Prince wrote:
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.
Thanks for the reply - no help though:

By a wrapper function, if you mean for f() to call say g() - this makes
no difference (command line: gcc -msse test.c -otest.exe).

gcc doesn't seem to recognize -mpreferred-stack-alignment=8 as a valid
option.

I'm not using pthreads, so it's not that either.


Sorry, you should have checked me. 'info gcc'
-mpreferred-stack-boundary=4 (2^4 == 16) is needed, and would be set
by options other than -O2. So, not specifying any relevant options
should be OK, but the function you call first in the thread must not
have any sse, if this is the problem.
I guess I don't understand where you got your function to start a thread.

I found -mpreferred-stack-boundary and -falign-functions options, I think they both default to 4, so it's not relevant to set these (I'm not using any optimizations).

I'll take a look at the assembly code and see if anything is different
(between gcc and msvc) for the thread function.  It looks like gcc is
getting the stack four bytes off alignment in the thread function for
some reason.




If your function gets a mis-aligned stack, that is not the fault of gcc. However, if your gcc function passes a mis-aligned stack, when you use the correct options, that is a bug.
gcc is more idealistic than commercial compilers which incur the additional overhead of adjusting the stack everywhere it is needed.
You may be missing important input because of your strange e-mail formatting; many people on this list will have blocked e-mail with html stuff. I have tbird set to filter out html but display text.



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