From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 1757 invoked from network); 23 Jun 1999 15:55:31 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 23 Jun 1999 15:55:31 -0000 Received: from delta.ds2.pg.gda.pl (macro@delta.ds2.pg.gda.pl [153.19.170.1]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id KAA04590 for ; Wed, 23 Jun 1999 10:56:07 -0400 Received: from localhost (macro@localhost) by delta.ds2.pg.gda.pl (8.8.8/8.8.8) with SMTP id QAA17417 for ; Wed, 23 Jun 1999 16:55:31 +0200 (MET DST) Date: Wed, 23 Jun 1999 16:55:31 +0200 (MET DST) From: "Maciej W. Rozycki" To: axp-list@redhat.com Subject: Re: problem with unaligned access on Alpha In-Reply-To: <41256799.00395D39.00@saturn.aladdin.de> Message-ID: Organization: Technical University of Gdansk MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Wed, 23 Jun 1999, Christian Groessler wrote: > But it also happens with egcs-1.1.2 (on NetBSD, but I don't think this > makes a difference). > > OK, now that I know whats the problem I can avoid the unaligned access and > fix the program. But I initially relied on unaligned accesses being > signalled > by the kernel, and now that the compiler works around unaligned accesses > (in a buggy way) makes it much more difficult to get alignment-unaware > (intel) > apps running on Alpha.... Well, unless you interchange non-byte data between architectures all accesses should be aligned by the compiler. If you cast between types of different alignments, you may make the compiler be aware of wrong alignment by casting the type to an unaligned one. E.g. you may cast unaligned "int32_t" to "struct { int32_t __attribute__((packed)); }" (it's not written formally but it should give you the idea); I'm told it works with egcs 1.1.2 which will add a necessary code to fetch the whole object properly. If you interchange non-byte data between architectures then you have to take care of different endianness anyway and you can simply apply alignment fixes to all places where you swap bytes for correct endianness. This is what I did in the program I am currently porting to multi-arch. I also observed the compiler behaviour you described. I believe it's a bug unless egcs people have a proof it's a feature. I think the most reasonable (i.e. performance-wise) solution is to change the unaligned load to the aligned one and let the kernel trap it. Given the compiler can be told explicitly to handle unaligned data this solution seems to be the right one. Have you reported the bug to egcs folks? -- + Maciej W. Rozycki, Technical University of Gdansk, Poland + +--------------------------------------------------------------+ + e-mail: macro@ds2.pg.gda.pl, PGP key available +