qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Stefan Weil <sw@weilnetz.de>
Cc: Jia Liu <proljc@gmail.com>,
	qemu-devel@nongnu.org, Blue Swirl <blauwirbel@gmail.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Michael Walle <michael@walle.cc>,
	Paul Brook <paul@codesourcery.com>,
	Anthony Liguori <anthony@codemonkey.ws>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	Aurelien Jarno <aurelien@aurel32.net>
Subject: Re: [Qemu-devel] [PATCH v2] Make target_phys_addr_t 64 bits unconditionally
Date: Sun, 07 Oct 2012 12:25:50 +0200	[thread overview]
Message-ID: <507158AE.1050805@redhat.com> (raw)
In-Reply-To: <506DD230.70509@weilnetz.de>

On 10/04/2012 08:15 PM, Stefan Weil wrote:
> Am 04.10.2012 12:36, schrieb Avi Kivity:
>> The hassle and compile time overhead of maintaining both 32-bit and
>> 64-bit
>> capable source isn't worth the tiny performance advantage which is
>> seen on
>> a minority of configurations.  Switch to compiling libhw only once, with
>> target_phys_addr_t unconditionally typedefed to uint64_t.
>>
>> Signed-off-by: Avi Kivity <avi@redhat.com>
> 
> Hi,
> 
> I noticed that you replaced target_phys_addr_t by uint64_t in two lines.

In those two lines, int64_t is more correct than t_p_a_t.  Explanation
below.

> Are there plans to replace target_phys_addr_t everywhere?

Yes, by hw_addr (or hwaddr, or phys, or ...).

> Should new code use uint64_t, or should it continue to use
> target_phys_addr_t?

target_phys_addr_t.

> 
> Using target_phys_addr_t might make support for 128 bit in some years
> easier
> because it allows identifying critical code,

Agree.

> although I think it will be difficult to avoid wrong use of either
> target_phys_addr_t
> or uint64_t as long as both are the same size.

Some languages allow enforcing this, but C doesn't.

> 
> 
>> -#if TARGET_PHYS_ADDR_BITS > 32
>> -    return low | ((target_phys_addr_t)high << 32);
>> -#else
>> -    return low;
>> -#endif
>> +    return low | ((uint64_t)high << 32);
>>

Shifting by 32 is not defined for types that are 32 bits or narrower.
On x86, for example, a shift by 32 of a 32-bit quantity is the identity
operation (where mathematically you would expect the result to be 0, not
the first argument).  Since the context does not guarantee that
target_phys_addr_t is wider than 32 bits, I cast it to a known-wide
type, then (implicitly) cast it back to target_phys_addr_t.

> 
>> -        *raddrp |= (target_phys_addr_t)(tlb->RPN & 0xF) << 32;
>> +        *raddrp |= (uint64_t)(tlb->RPN & 0xF) << 32;
> 

Same applies here, of course.

Since target_phys_addr_t is 64 bits, it would have worked "by accident",
but if we'd have switched back to 32 bits in the future (unlikely but
possible) then I would have introduced a bug here.

-- 
error compiling committee.c: too many arguments to function

  reply	other threads:[~2012-10-07 10:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 10:36 [Qemu-devel] [PATCH v2] Make target_phys_addr_t 64 bits unconditionally Avi Kivity
2012-10-04 10:42 ` Edgar E. Iglesias
2012-10-04 11:42 ` Max Filippov
2012-10-04 13:56 ` Anthony Liguori
2012-10-04 16:54 ` Blue Swirl
2012-10-04 17:08 ` Michael Walle
2012-10-04 18:15 ` Stefan Weil
2012-10-07 10:25   ` Avi Kivity [this message]
2012-10-05  2:10 ` Anthony Liguori
2012-10-05  5:39   ` Stefan Weil
2012-10-05 15:46     ` Blue Swirl
2012-10-05 16:07       ` Anthony Liguori
2012-10-05 16:45 ` Peter Maydell
2012-10-07 13:16   ` Avi Kivity

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=507158AE.1050805@redhat.com \
    --to=avi@redhat.com \
    --cc=anthony@codemonkey.ws \
    --cc=aurelien@aurel32.net \
    --cc=blauwirbel@gmail.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=michael@walle.cc \
    --cc=paul@codesourcery.com \
    --cc=proljc@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=sw@weilnetz.de \
    /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).