qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: "Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [RFC PATCH] target/i386: avoid copying junk to extended ZMMReg fields
Date: Mon, 11 Apr 2022 18:56:14 +0200	[thread overview]
Message-ID: <6d38ebc0-e472-38e1-5791-de7976e709e3@redhat.com> (raw)
In-Reply-To: <CAFEAcA-j2jkdoy09aogzgFVPXYH2Mn7yHXJCZyoZ=DETMMZMVg@mail.gmail.com>

On 4/11/22 17:18, Peter Maydell wrote:
> Looking a bit more closely, this won't work on big-endian
> hosts, because there we want to copy across the last 16
> bytes of the struct, not the first 16. So I think we need
> some more macro magic:
> 
> #if SHIFT == 0
> #define COPY_REG(DEST, SRC) (DEST) = (SRC)
> #else
> #define COPY_REG(DEST, SRC) do { \
>      (DEST).Q(0) = (SRC).Q(0);    \
>      (DEST).Q(1) = (SRC).Q(1);    \
>    } while (0)
> #endif
> 
> and then use COPY_REG(*d, r);

Right, I have written something similar after seeing your response to
the bug.

> We could probably try to write endian-specific flavours of
> memcpy() invocation, but "do two 64-bit word copies" is what
> the compiler would hopefully turn the memcpy into anyway :-)

Yeah, I actually wrote the memcpy() invocation because I was going to
look at AVX later this year, which of course you couldn't know. :)
What I came up after stealing parts of your nice comment is the
following:

/*
  * Copy the relevant parts of a Reg value around. In the case where
  * sizeof(Reg) > SIZE, these helpers operate only on the lower bytes of
  * a 64 byte ZMMReg, so we must copy only those and keep the top bytes
  * untouched in the guest-visible destination destination register.
  * Note that the "lower bytes" are placed last in memory on big-endian
  * hosts, which store the vector backwards in memory.  In that case the
  * copy *starts* at B(SIZE - 1) and ends at B(0), the opposite of
  * the little-endian case.
  */
#ifdef HOST_WORDS_BIGENDIAN
#define MOVE(d, r) memcpy(&((d).B(SIZE - 1)), &(d).B(SIZE - 1), SIZE)
#else
#define MOVE(d, r) memcpy(&(d).B(0), &(r).B(0), SIZE)
#endif

I'll still your nice comment and submit a patch later when 7.1 opens.

Paolo


  reply	other threads:[~2022-04-11 16:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11 14:56 [RFC PATCH] target/i386: avoid copying junk to extended ZMMReg fields Alex Bennée
2022-04-11 15:18 ` Peter Maydell
2022-04-11 16:56   ` Paolo Bonzini [this message]
2022-04-11 17:21     ` Peter Maydell

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=6d38ebc0-e472-38e1-5791-de7976e709e3@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=peter.maydell@linaro.org \
    --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 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).