From: Richard Henderson <rth@twiddle.net>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Jovanovic, Petar" <petarj@mips.com>, Jia Liu <proljc@gmail.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v12 09/14] target-mips: Add ASE DSP bit/manipulation instructions
Date: Wed, 31 Oct 2012 16:26:43 +1100 [thread overview]
Message-ID: <5090B693.4080604@twiddle.net> (raw)
In-Reply-To: <CAFEAcA9KfZ86FK1reu-q1YNor2p4-doq9+1zEmM9xd9RxKk3_A@mail.gmail.com>
On 2012-10-31 01:44, Peter Maydell wrote:
> On 30 October 2012 15:34, Jia Liu <proljc@gmail.com> wrote:
>> On Mon, Oct 29, 2012 at 9:40 PM, Jovanovic, Petar <petarj@mips.com> wrote:
>>>> imm = (int16_t)(imm << 6) >> 6;
>>>
>>> result of a bitwise shift of a signed type and a negative vlaue is
>>> implementation-defined, so you can not rely on that.
>>>
>>
>> I think it will take a 10bits signed value sign extend into 16bits
>> signed value, and I've tested it with negative values, it working
>> well.
>
> You cannot rely on the behaviour of a specific compiler implementation
> as evidence that a piece of code is correct. C has a standard which
> defines what is and is not valid.
Indeed. The only portable way is
val = ((val & (sign | (sign - 1))) ^ sign) - sign
with all unsigned types, and "sign" set to the sign bit.
>
> Having said that, right shift of negative signed integers is one of
> those bits of implementation defined behaviour which we allow ourselves
> to rely on in QEMU because all the platforms we care about behave
> that way. (That integers are 2s complement representation is another.)
Also very true. I don't like seeing the code in question though.
We've several implementations of sign-extend-to-N-bits functions
throughout qemu; we ought to unify them.
r~
next prev parent reply other threads:[~2012-10-31 5:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-27 22:58 [Qemu-devel] [PATCH v12 09/14] target-mips: Add ASE DSP bit/manipulation instructions Jovanovic, Petar
2012-10-29 12:36 ` Jia Liu
2012-10-29 13:40 ` Jovanovic, Petar
2012-10-30 14:34 ` Jia Liu
2012-10-30 14:44 ` Peter Maydell
2012-10-31 5:26 ` Richard Henderson [this message]
2012-10-31 13:29 ` Jia Liu
2012-10-31 19:20 ` Aurelien Jarno
2012-11-01 0:34 ` Jia Liu
2012-11-06 3:50 ` Jovanovic, Petar
2012-11-06 7:40 ` Aurelien Jarno
2012-10-30 14:51 ` Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2012-10-24 14:17 [Qemu-devel] [PATCH v12 00/14] QEMU MIPS ASE DSP support Jia Liu
2012-10-24 14:17 ` [Qemu-devel] [PATCH v12 09/14] target-mips: Add ASE DSP bit/manipulation instructions Jia Liu
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=5090B693.4080604@twiddle.net \
--to=rth@twiddle.net \
--cc=petarj@mips.com \
--cc=peter.maydell@linaro.org \
--cc=proljc@gmail.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 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).