qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v2 14/22] target-mips: add Addressing and PC-rel


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH v2 14/22] target-mips: add Addressing and PC-relative instructions
Date: Tue, 24 Jun 2014 07:24:37 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 06/24/2014 03:00 AM, Peter Maydell wrote:
> On 24 June 2014 10:50, Leon Alrae <address@hidden> wrote:
>> On 20/06/2014 21:50, Aurelien Jarno wrote:
>>> I do wonder if we shouldn't use sextract32() instead of open coding that
>>> now that it is available:
>>>
>>>                offset = sextract32(ctx->opcode, 0, 19) << 3;
>>
>> This looks better, thanks for the suggestion (but since the offset's
>> size is 18, third argument will be 18, not 19).
> 
> This is undefined behaviour in C because of the shift into
> the sign bit. Better to shift first and then signextend:
> 
>     offset = sextract32(ctx->opcode << 3, 0, 21);

Not true.  Because we know from the extract that the value has 13 copies of the
sign bit.  Shifting by 3 isn't going to cause problems.  It's shifting a
*different* bit into the sign position that's (one's compliment) undefined.


r~

PS: Honestly, all these compilers/sanitizers should grow a "No One's
Compliment" switch to disable all the stupid stuff.



reply via email to

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