From: Peter Maydell <peter.maydell@linaro.org>
To: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com>
Cc: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
"Sergey Fedorov" <serge.fdrv@gmail.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"QEMU Developers" <qemu-devel@nongnu.org>,
"Alexander Graf" <agraf@suse.de>
Subject: Re: [Qemu-devel] [PATCH v4 1/6] target-arm: Add CNTVOFF_EL2
Date: Mon, 15 Jun 2015 11:51:36 +0100 [thread overview]
Message-ID: <CAFEAcA9FdPbK+76uJrERmwSCbZJAnKK66RoEdHVP5Bg7Vw3y2A@mail.gmail.com> (raw)
In-Reply-To: <20150615005200.GP17878@toto>
On 15 June 2015 at 01:52, Edgar E. Iglesias <edgar.iglesias@xilinx.com> wrote:
> On Fri, Jun 12, 2015 at 05:44:24PM +0100, Peter Maydell wrote:
>> On 5 June 2015 at 11:33, Edgar E. Iglesias <edgar.iglesias@gmail.com> wrote:
>> > + int istatus = (int64_t) (count - offset - gt->cval) >= 0;
>>
>> This is wrong. Consider the case where:
>> count is 0x1000,0000,0000,0002 (it's a really large unsigned number)
>> offset is zero
>> cval is 1
>>
>> The ARM ARM required calculation gives you
>> 0x1000,0000,0000,0002 - 1 >= 0
>> ie 0x1000,0000,0000,0001 >= 0
>> which is true. (Note that ARM ARM pseudocode works with infinite
>> precision integers, not 2s-complement.)
>>
>> With your code:
>> (count - offset - gt->cval) is 0x1000,0000,0000,0001
>> Cast to an int64_t this is negative (top bit is set)
>> Comparison against 0 is done as a signed value, and returns false.
>>
>> This is exactly the tricky case which is why we must do this as unsigned
>> arithmetic.
>>
>> What you want is
>> int istatus = count - offset >= gt->cval;
>>
>> which comes out to
>> 0x1000,0000,0000,0002 >= 1
>> which is true.
>>
>> (That's the code we had before, but just "use 'count - offset' rather than
>> 'count'".)
>
> Thanks, I've changed it to what you suggest allthough I'm probably missing
> something cause I'm still finding the spec confusing :S
If we had 128 bit integers we could do it your way, only casting
to int128_t rather than int64_t (which would be approximating the
pseudocode's infinite-precision signed integers with 128-bit ints,
which works because we know we don't have anything out of that
range). The tricky stuff with uint64_t is just because we don't
want to have to go to 128-bit arithmetic if we can avoid it.
As I say the thing it's easy to forget when reading ARM ARM
pseudocode is that the integer and real data types are true
mathematical integers and reals, not the limited-width uint32_t,
uint64_t, float and double types the CPU actually deals with.
There's always a conversion to/from bitstring somewhere along
the line.
(Appendix J9 has a description of the pseudocode data types and
syntax.)
-- PMM
next prev parent reply other threads:[~2015-06-15 10:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-05 10:33 [Qemu-devel] [PATCH v4 0/6] arm: Steps towards EL2 support round 3 Edgar E. Iglesias
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 1/6] target-arm: Add CNTVOFF_EL2 Edgar E. Iglesias
2015-06-12 16:44 ` Peter Maydell
2015-06-15 0:52 ` Edgar E. Iglesias
2015-06-15 10:51 ` Peter Maydell [this message]
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 2/6] target-arm: Add CNTHCTL_EL2 Edgar E. Iglesias
2015-06-12 16:51 ` Peter Maydell
2015-06-15 1:03 ` Edgar E. Iglesias
2015-06-15 7:29 ` Peter Maydell
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 3/6] target-arm: Pass timeridx as argument to various timer functions Edgar E. Iglesias
2015-06-12 16:54 ` Peter Maydell
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 4/6] target-arm: Add the Hypervisor timer Edgar E. Iglesias
2015-06-12 17:00 ` Peter Maydell
2015-06-15 1:29 ` Edgar E. Iglesias
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 5/6] hw/arm/virt: Replace magic IRQ constants with macros Edgar E. Iglesias
2015-06-12 17:02 ` Peter Maydell
2015-06-05 10:33 ` [Qemu-devel] [PATCH v4 6/6] hw/arm/virt: Connect the Hypervisor timer Edgar E. Iglesias
2015-06-12 17: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=CAFEAcA9FdPbK+76uJrERmwSCbZJAnKK66RoEdHVP5Bg7Vw3y2A@mail.gmail.com \
--to=peter.maydell@linaro.org \
--cc=agraf@suse.de \
--cc=alex.bennee@linaro.org \
--cc=edgar.iglesias@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=qemu-devel@nongnu.org \
--cc=serge.fdrv@gmail.com \
/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).