qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 10/21] memory: make section size a 128-bit integ


From: Paolo Bonzini
Subject: Re: [Qemu-devel] [PATCH 10/21] memory: make section size a 128-bit integer
Date: Sun, 02 Jun 2013 16:36:58 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6

Il 02/06/2013 16:18, Peter Maydell ha scritto:
> On 31 May 2013 23:18, Richard Henderson <address@hidden> wrote:
>> On 05/30/2013 02:16 PM, Paolo Bonzini wrote:
>>> +static inline Int128 int128_rshift(Int128 a, int n)
>>> +{
>>> +    return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), (a.hi >> n) };
>>> +}
>>
>> Produces wrong results for n == 0, since (a.hi << 64) is undefined.
> 
> It produces wrong results for shifts by more than 64,
> for that matter.

This should work:

    int64_t h;
    if (!n) {
        return a;
    }
    h = a.hi >> n;
    if (n >= 64) {
        return (Int128) { h, h >> 63 };
    } else {
       return (Int128) { (a.lo >> n) | (a.hi << (64 - n)), h };
    }

Paolo




reply via email to

[Prev in Thread] Current Thread [Next in Thread]