From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [i386] Enable -mstackrealign with SSE on 32-bit Windows
Date: Tue, 15 Dec 2015 08:42:00 -0000 [thread overview]
Message-ID: <5969976.Bvae8NF9fS@polaris> (raw)
[-- Attachment #1: Type: text/plain, Size: 888 bytes --]
Hi,
even the latest versions of Windows still guarantee only a 4-byte alignment of
the stack in 32-bit mode, which doesn't play nice with some SSE instructions.
That's why some projects enable -mstackrealign by default on 32-bit Windows:
https://bugzilla.mozilla.org/show_bug.cgi?id=631252
This eliminates an entire class of bugs which are sometimes hard to reproduce.
The attached patch automatically enables it when SSE instructions are used.
That's a good compromise IMO because the default configuration of the compiler
on this platform doesn't enable SSE so should presumably not be modified.
Tested on i686-pc-mingw32, OK for the mainline?
2015-12-15 Eric Botcazou <ebotcazou@adacore.com>
* config/i386/cygming.h (STACK_REALIGN_DEFAULT): Define.
2015-12-15 Eric Botcazou <ebotcazou@adacore.com>
* gcc.target/i386/stack-realign-win.c: New test.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 652 bytes --]
Index: config/i386/cygming.h
===================================================================
--- config/i386/cygming.h (revision 231605)
+++ config/i386/cygming.h (working copy)
@@ -39,6 +39,11 @@ along with GCC; see the file COPYING3.
#undef MAX_STACK_ALIGNMENT
#define MAX_STACK_ALIGNMENT (TARGET_SEH ? 128 : MAX_OFILE_ALIGNMENT)
+/* 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
+
/* Support hooks for SEH. */
#undef TARGET_ASM_UNWIND_EMIT
#define TARGET_ASM_UNWIND_EMIT i386_pe_seh_unwind_emit
[-- Attachment #3: stack-realign-win.c --]
[-- Type: text/x-csrc, Size: 649 bytes --]
/* { dg-do compile { target *-*-mingw* *-*-cygwin* } } */
/* { dg-require-effective-target ia32 } */
/* { dg-options "-msse -O" } */
extern void abort (void);
typedef float __m128 __attribute__ ((__vector_size__ (16), __may_alias__));
static __m128
load_m128 (float *e)
{
return * (__m128 *) e;
}
typedef union
{
__m128 x;
float a[4];
} union128;
void test (void)
{
union128 u;
float e[4] __attribute__ ((aligned (16)))
= {2134.3343, 1234.635654, 1.2234, 876.8976};
int i;
u.x = load_m128 (e);
for (i = 0; i < 4; i++)
if (u.a[i] != e[i])
abort ();
}
/* { dg-final { scan-assembler "andl\\t\\$-16, %esp" } } */
reply other threads:[~2015-12-15 8:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5969976.Bvae8NF9fS@polaris \
--to=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).