All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 3/3] move unaligned memory access functions to bswap.h
Date: Mon, 06 Jun 2011 14:56:57 -0500	[thread overview]
Message-ID: <4DED3109.1070902@twiddle.net> (raw)
In-Reply-To: <1307370348-28400-4-git-send-email-pbonzini@redhat.com>

Patches 1-3:
Reviewed-by: Richard Henderson <rth@twiddle.net>

That said,

On 06/06/2011 09:25 AM, Paolo Bonzini wrote:
> +/* conservative code for little endian unaligned accesses */
> +static inline int lduw_le_p(const void *ptr)
> +{
> +#ifdef _ARCH_PPC
> +    int val;
> +    __asm__ __volatile__ ("lhbrx %0,0,%1" : "=r" (val) : "r" (ptr));
> +    return val;
> +#else
> +    const uint8_t *p = ptr;
> +    return p[0] | (p[1] << 8);
> +#endif
> +}

Can we add a patch 4/3 that removes this sort of hard-coded
assembly stuff in favour of generic gcc code.  E.g.

static inline int lduw_le_p(const void *ptr)
{
  struct pack { uint16_t x __attribute__((packed)); };
  const struct pack *p = ptr;
  uint16_t ret;

  ret = p->x;
  ret = le_bswap(ret, 16);

  return ret;
}

One could fairly well macroize all 6 instances.

The compiler knows that ppc and i386 can do the unaligned loads.
The compiler *should* be able to match the bswap_N patterns, and
thus also fold the unaligned load with the bswap for ppc.

I can confirm that gcc head does in fact do the right thing for
ppc32/64 here, as well as for i386/x86_64.  I don't have previous
versions of gcc checked out atm...

I havn't checked, but this *ought* to enable the load-asi bswap
instruction for sparcv9.  I also havn't checked what happens for
a target like sparcv8 that lacks both unaligned load and bswap,
to see that we don't simply double the number of shifts.  However,
I'd be tempted to file that as a gcc missed optimization bug.


r~

  reply	other threads:[~2011-06-06 19:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-06 14:25 [Qemu-devel] [PATCH v2 0/3] make endian-independent unaligned memory access functions available to libhw Paolo Bonzini
2011-06-06 14:25 ` [Qemu-devel] [PATCH v2 1/3] move WORDS_ALIGNED to qemu-common.h Paolo Bonzini
2011-06-06 17:15   ` Andreas Färber
2011-06-06 20:24     ` Paolo Bonzini
2011-06-06 22:15     ` Richard Henderson
2011-06-07  9:17       ` Paolo Bonzini
2011-06-06 14:25 ` [Qemu-devel] [PATCH v2 2/3] softfloat: change default nan definitions to variables Paolo Bonzini
2011-06-06 14:25 ` [Qemu-devel] [PATCH v2 3/3] move unaligned memory access functions to bswap.h Paolo Bonzini
2011-06-06 19:56   ` Richard Henderson [this message]
2011-06-06 20:27     ` Paolo Bonzini
2011-06-06 22:05       ` Richard Henderson
2011-06-06 23:07     ` malc
2011-06-07 16:54       ` Richard Henderson
2011-06-07 17:29         ` malc
2011-07-06 13:29 ` [Qemu-devel] [PATCH v2 0/3] make endian-independent unaligned memory access functions available to libhw Paolo Bonzini

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=4DED3109.1070902@twiddle.net \
    --to=rth@twiddle.net \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.