All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <rth@twiddle.net>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org, patches@linaro.org
Subject: Re: [Qemu-devel] [RFC] bitops: Provide sext32() and sext64() for signextending bitfields
Date: Thu, 27 Jun 2013 09:35:19 -0700	[thread overview]
Message-ID: <51CC69C7.6020207@twiddle.net> (raw)
In-Reply-To: <1372348062-4516-1-git-send-email-peter.maydell@linaro.org>

On 06/27/2013 08:47 AM, Peter Maydell wrote:
> A common operation in instruction decoding is to take a field
> from an instruction that represents a signed integer in some
> arbitrary number of bits, and sign extend it into a C signed
> integer type for manipulation. Provide new functions sext32()
> and sext64() to abstract away the bit manipulation.
> 
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I think we've vaguely tossed around the idea of a function to
> abstract away the concept of doing a signextension before,
> so here's an RFC...
> 
> Does the API look right? The other approach I thought of would
> be to have functions sextract32()/sextract64() which work like
> the existing extract{32,64} but return signed (and sign
> extended) values, but providing the raw sign-extension separately
> seemed more flexible. (If we want the sextract ops then we could
> implement them as sext32(extract32(value, start, length), length).)

Seems sensible.

I've been wondering if we should provide tcg-op.h helpers for the
same thing -- even without introducing new tcg opcodes yet -- just
for clarity in the translators.

Though of course, the hosts that tend to provide deposit opcodes
also tend to provide extract opcodes...

> This implementation continues to rely on the behaviour of right-shift
> of signed integers (as do most of the places which open-code this
> operation today; see also HACKING section 6). If we decide in future
> that we'd rather do this in a strictly-portable way we'll have a
> single place we need to change.

Fair enough.  The patch itself looks good.


r~

  reply	other threads:[~2013-06-27 16:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-27 15:47 [Qemu-devel] [RFC] bitops: Provide sext32() and sext64() for signextending bitfields Peter Maydell
2013-06-27 16:35 ` Richard Henderson [this message]
2013-06-27 17:58 ` Markus Armbruster
2013-06-27 18:03   ` 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=51CC69C7.6020207@twiddle.net \
    --to=rth@twiddle.net \
    --cc=patches@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 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.