From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=49797 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PofVI-0004Ef-7p for qemu-devel@nongnu.org; Sun, 13 Feb 2011 12:12:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PofVG-0005dn-4h for qemu-devel@nongnu.org; Sun, 13 Feb 2011 12:12:55 -0500 Received: from moutng.kundenserver.de ([212.227.17.8]:54152) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PofVF-0005cY-Pq for qemu-devel@nongnu.org; Sun, 13 Feb 2011 12:12:54 -0500 Subject: Re: [Qemu-devel] [PATCH 1/2] linux-user: Define target alignment size From: Laurent Vivier In-Reply-To: References: <1297563761-2786-1-git-send-email-laurent@vivier.eu> <1297563761-2786-2-git-send-email-laurent@vivier.eu> Content-Type: text/plain; charset="UTF-8" Date: Sun, 13 Feb 2011 18:12:41 +0100 Message-ID: <1297617161.3211.19.camel@Quad> Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: Riku Voipio , qemu-devel@nongnu.org Le dimanche 13 f=C3=A9vrier 2011 =C3=A0 10:24 +0200, Blue Swirl a =C3=A9cri= t : > On Sun, Feb 13, 2011 at 4:22 AM, Laurent Vivier wrote= : > > Datatype alignment can be found using following application: > > > > int main(void) > > { > > printf("alignof(short) %ld\n", __alignof__(short)); > > printf("alignof(int) %ld\n", __alignof__(int)); > > printf("alignof(long) %ld\n", __alignof__(long)); > > printf("alignof(long long) %ld\n", __alignof__(long long)); > > } > > > > This patch includes following alignments: > > > > i386 > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > x86_64 > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 8 > > alignof(long long) 8 > > > > arm > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 4 > > > > m68k (680x0) > > > > alignof(short) 2 > > alignof(int) 2 > > alignof(long) 2 > > alignof(long long) 2 > > > > mips > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > ppc > > > > alignof(short) 2 > > alignof(int) 4 > > alignof(long) 4 > > alignof(long long) 8 > > > > for other targets, use by default (2,4,4,8). > > > > Please, update for your favorite target... >=20 > For Sparc32 (I think also sparc32plus), the default is OK. >=20 > For Sparc64, please use 2, 4, 8, 8. I'd guess other 64 bit platforms > (Alpha, MIPS64, PPC64 etc) should use the same. OK, I update my patch. > Does GCC produce correct code using the attributes on strictly aligned > host, when the target is less strictly aligned? It seems it is OK. I did some tests into a mips-linux-user chroot (sparc one is broken ;-) ) : mips is a strictly aligned host, from gcc/config/mips/mips.h: #define STRICT_ALIGNMENT 1 aligments are: alignof(short) 2 alignof(int) 4 alignof(long) 4 alignof(long long) 8 We try to align int on 2. #include typedef int target_int __attribute__((aligned(2))); struct { char Z; target_int A; } B; int main(void) { B.A =3D 0xdeadbeaf; printf("%d: %x\n", __alignof__(B.A), B.A); } ./test_align 2: deadbeaf disass: lw $2,%got(B)($28) li $3,-559087616 # 0xffffffffdead0000 ori $3,$3,0xbeaf swl $3,2($2) swr $3,5($2) normal case: lw $3,%got(B)($28) li $2,-559087616 # 0xffffffffdead0000 ori $2,$2,0xbeaf sw $2,4($3) So, gcc seems smart enough to split the memory access in several ones compatible with the strict alignment rules. > Should the alignment of floating point variables be specified as well? At the moment it seems useless. > The strict alignment required for doubles is 4, but recommended > alignment is 8, I'm not sure which one is used for structures > containing doubles. if necessary, some tests will be helpfull. Thank you for your comments. Regards, Laurent=20 --=20 --------------------- laurent@vivier.eu ---------------------- "Tout ce qui est impossible reste =C3=A0 accomplir" Jules Verne "Things are only impossible until they're not" Jean-Luc Picard