psmedley / gcc

GNU General Public License v2.0
7 stars 1 forks source link

Fix automatic data alignment for SSE #28

Open dmik opened 6 years ago

dmik commented 6 years ago

We have numerous cases when GCC (at least 4.9.2) implicitly generates SSE/SSE2 instructions (e.g. when using -O3 -march=pentium4) but doesn't align arguments for them on the 16-byte boundary as required by the x86 specification. In case of stack-based memory this can be forced globally with -mstackrealign but it's a clear abuse of this option and it also doesn't help when arguments are from the dynamic memory or from global data segments. Such memory may only be aligned on per-variable basis using special GCC variable attribute to force fixed alignment but this is usually not an acceptable solution either. Such an alignment should be done automatically whenever GCC generates SSE/SSE2 and not doing so looks like a bug in our port (as on other platforms it works w/o any additional hassle).

A good test case is FIrefox. See https://github.com/bitwiseworks/mozilla-os2/issues/266#issuecomment-384941566 and below. But perhaps a simple test case for testing purposes should be written when working on this problem.

psmedley commented 6 years ago

Pretty sure this is addressed in newer GCC builds. If I get a chance I'll dig out what changed - it may be able to be backported to 4.9.x

psmedley commented 6 years ago

This patch (an adaptation of) should fix for GCC 4.9.x https://patchwork.ozlabs.org/patch/592839/

ie adding:

define STACK_REALIGN_DEFAULT 1 to emx.h

dmik commented 6 years ago

Paul, thanks for your findings! Though I can't say I like this solution. First, it's no different from using -mstackrealign on the command line directly which I find to be abusive still. This creates additional overhead everywhere while it's necessary in just a few places. Second, it still won't solve the alignment problem for non-stack memory (global data and dynamic heap). There should be a different approach.

Can you check which other platforms use STACK_REALIGN_DEFAULT in recent GCC besides Solaris?

psmedley commented 6 years ago

More recent versions of GCC use: / 32-bit Windows aligns the stack on a 4-byte boundary but SSE instructions may require 16-byte alignment. /

undef STACK_REALIGN_DEFAULT

define STACK_REALIGN_DEFAULT TARGET_SSE

This is used by cygminw (and I copied it for EMX)

Above is from GCC 6.3.0 - I don't have a GCC 5.x tree locally any more to confirm when it was introduced.

dmik commented 6 years ago

Okay, I wonder then how they solve it on Linux and other platforms where -mstackrealign is not used at all. And for global/heap data (remember, we have a real-life case like that in Firefox).

dryeo commented 6 years ago

On 05/18/18 03:00 PM, psmedley wrote:

Pretty sure this is addressed in newer GCC builds. If I get a chance I'll dig out what changed - it may be able to be backported to 4.9.x

It fails the same with GCC 5.1.0.

psmedley commented 6 years ago

Dave, not sure which gcc version for os2 I fixed it in, my comment was mid-2016, so I guess I fixed it for os2 somewhere around then :)

Cheers,

Paul

On Sat., 19 May 2018, 08:59 Dave Yeo, notifications@github.com wrote:

On 05/18/18 03:00 PM, psmedley wrote:

Pretty sure this is addressed in newer GCC builds. If I get a chance I'll dig out what changed - it may be able to be backported to 4.9.x

It fails the same with GCC 5.1.0.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/psmedley/gcc/issues/28#issuecomment-390357570, or mute the thread https://github.com/notifications/unsubscribe-auth/AA-cct0UxsPAK5EDdv2PEGqhc12N1NaGks5tz1lXgaJpZM4UFJz1 .