This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: STRICT_ALIGNMENT is too strict for m68k
- To: Jim Wilson <wilson at cygnus dot com>
- Subject: Re: STRICT_ALIGNMENT is too strict for m68k
- From: Kamil Iskra <kamil at dwd dot interkom dot pl>
- Date: Sat, 16 May 1998 21:18:04 +0200 (CEST)
- cc: Greg McGary <gkm at eng dot ascend dot com>, egcs at cygnus dot com
On Fri, 15 May 1998, Jim Wilson wrote:
> It would be a very nice improvement if STRICT_ALIGNMENT were made to
> be conditional on the CPU implementation.
> Changing the value of STRICT_ALIGNMENT changes the ABI. In particular,
> it will affect structure layout.
Is that really so? According to tm.texi:
@item STRICT_ALIGNMENT
Define this macro to be the value 1 if instructions will fail to work
if given data not on the nominal alignment. If instructions will merely
go slower in that case, define this macro as 0.
Clearly, there is no mention of any influence on the structure alignment,
but only on the choice of instructions to generate for unaligned access.
I just installed the following patch in my local 1.0.2 tree:
Sat May 16 21:12:39 1998 Kamil Iskra <iskra@student.uci.agh.edu.pl>
* m68k.h (STRICT_ALIGNMENT): Depend on TARGET_68020.
--- egcs/gcc/config/m68k/m68k.h.orig Tue Mar 17 16:06:24 1998
+++ egcs/gcc/config/m68k/m68k.h Sat May 16 20:36:38 1998
@@ -289,7 +289,7 @@
/* Set this nonzero if move instructions will actually fail to work
when given unaligned data. */
-#define STRICT_ALIGNMENT 1
+#define STRICT_ALIGNMENT (! TARGET_68020)
/* Maximum power of 2 that code can be aligned to. */
#define MAX_CODE_ALIGN 2 /* 4 byte alignment */
I compiled the following testcase:
#include <stddef.h>
#include <stdio.h>
struct A
{
char a;
short b;
int c;
} str;
char a;
short b;
int c;
int main(void)
{
printf("sizeof(struct A): %d\n", sizeof(struct A));
printf("offsetof(struct A, a): %d\n", offsetof(struct A, a));
printf("offsetof(struct A, b): %d\n", offsetof(struct A, b));
printf("offsetof(struct A, c): %d\n", offsetof(struct A, c));
str.a=a;
str.b=b;
str.c=c;
}
The results generated were the same for executables generated with the
compiler with unmodified STRICT_ALIGNMENT and with the patched one. The
case of -fpack-struct was also tested, and the patched compiler generated
better code. Therefore, I think that the patch given above is correct and
useful, and as such should be applied.
/ Kamil Iskra AmigaOS Linux/i386 Linux/m68k \
| GeekGadgets GCC maintainer UNIX system administrator |
| iskra@student.uci.agh.edu.pl kiskra@ernie.icslab.agh.edu.pl |
\ kamil@dwd.interkom.pl http://student.uci.agh.edu.pl/~iskra /