qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent@vivier.eu>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: Riku Voipio <riku.voipio@iki.fi>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 1/2] linux-user: Define target alignment size
Date: Sun, 13 Feb 2011 18:12:41 +0100	[thread overview]
Message-ID: <1297617161.3211.19.camel@Quad> (raw)
In-Reply-To: <AANLkTimoopmUwoRXakLD0zH_n8sj=-SHmxcnriBXGQYL@mail.gmail.com>

Le dimanche 13 février 2011 à 10:24 +0200, Blue Swirl a écrit :
> On Sun, Feb 13, 2011 at 4:22 AM, Laurent Vivier <laurent@vivier.eu> 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...
> 
> For Sparc32 (I think also sparc32plus), the default is OK.
> 
> 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 <stdio.h>

typedef int target_int __attribute__((aligned(2)));

struct {
        char Z;
        target_int A;
} B;

int main(void)
{
        B.A = 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 

-- 
--------------------- laurent@vivier.eu ----------------------
"Tout ce qui est impossible reste à accomplir"    Jules Verne
"Things are only impossible until they're not" Jean-Luc Picard

  reply	other threads:[~2011-02-13 17:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-13  2:22 [Qemu-devel] [PATCH 0/2][v3] correct core dump format Laurent Vivier
2011-02-13  2:22 ` [Qemu-devel] [PATCH 1/2] linux-user: Define target alignment size Laurent Vivier
2011-02-13  8:24   ` Blue Swirl
2011-02-13 17:12     ` Laurent Vivier [this message]
2011-02-13  2:22 ` [Qemu-devel] [PATCH 2/2] linux-user: correct core dump format Laurent Vivier

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=1297617161.3211.19.camel@Quad \
    --to=laurent@vivier.eu \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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 NNTP newsgroup(s).