[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once |
Date: |
Wed, 24 Jun 2020 15:19:48 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 |
On 6/24/20 2:13 PM, Eric Blake wrote:
> On 6/24/20 5:50 AM, Paolo Bonzini wrote:
>> From: Eric Blake <eblake@redhat.com>
>>
>> I'm not aware of any immediate bugs in qemu where a second runtime
>> evalution of the arguments to MIN() or MAX() causes a problem, but
>
> evaluation
>
>> Update the MIN/MAX macros to only evaluate their argument once at
>> runtime;
>
>> Use of MIN when MIN_CONST is needed:
>>
>> In file included from /home/eblake/qemu/qemu-img.c:25:
>> /home/eblake/qemu/include/qemu/osdep.h:249:5: error: braced-group
>> within expression allowed only inside a function
>> 249 | ({ \
>> | ^
>> /home/eblake/qemu/qemu-img.c:92:12: note: in expansion of macro ‘MIN’
>
> UTF-8 mojibake in the commit message ;(
Oh, this is not a git-publish bug:
https://github.com/bonzini/qemu/commit/6f9ff58baae
>
>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>>
>> Message-Id: <20200604215236.2798244-1-eblake@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>
>> +#define MIN_CONST(a, b) \
>> + __builtin_choose_expr( \
>> + __builtin_constant_p(a) && __builtin_constant_p(b), \
>> + (a) < (b) ? (a) : (b), \
>> + ((void)0))
>
> This one is correct...
>
>> +#undef MAX
>> +#define MAX(a, b) \
>> + ({ \
>> + typeof(1 ? (a) : (b)) _a = (a), _b = (b); \
>> + _a > _b ? _a : _b; \
>> + })
>> +#define MAX_CONST(a, b) \
>> + __builtin_choose_expr( \
>> + __builtin_constant_p(a) && __builtin_constant_p(b), \
>> + (a) > (b) ? (a) : (b), \
>> + __builtin_unreachable())
>
> ...but this one should also use ((void)0), to match the commit message.
>
>> +
>> +/* Minimum function that returns zero only if both values are zero.
>> * Intended for use with unsigned values only. */
>
> And checkpatch complains about the formatting here.
>
> Ah well. I had all these things fixed in my tree, but failed to post a
> v5. Not worth holding up this pull request in isolation, but if there
> are any other build issues, I'll post a v5 of this patch, otherwise a
> followup.
>
- [PULL 20/31] target/i386: reimplement fprem, fprem1 using floatx80 operations, (continued)
- [PULL 20/31] target/i386: reimplement fprem, fprem1 using floatx80 operations, Paolo Bonzini, 2020/06/24
- [PULL 19/31] softfloat: return low bits of quotient from floatx80_modrem, Paolo Bonzini, 2020/06/24
- [PULL 24/31] target/i386: Add notes for versioned CPU models, Paolo Bonzini, 2020/06/24
- [PULL 17/31] softfloat: do not return pseudo-denormal from floatx80 remainder, Paolo Bonzini, 2020/06/24
- [PULL 23/31] target/i386: reimplement fpatan using floatx80 operations, Paolo Bonzini, 2020/06/24
- [PULL 27/31] kvm: i386: allow TSC to differ by NTP correction bounds without TSC scaling, Paolo Bonzini, 2020/06/24
- [PULL 21/31] target/i386: reimplement fyl2xp1 using floatx80 operations, Paolo Bonzini, 2020/06/24
- [PULL 25/31] osdep: Make MIN/MAX evaluate arguments only once, Paolo Bonzini, 2020/06/24
- [PULL 22/31] target/i386: reimplement fyl2x using floatx80 operations, Paolo Bonzini, 2020/06/24
- [PULL 30/31] ibex_uart: fix XOR-as-pow, Paolo Bonzini, 2020/06/24
- [PULL 28/31] hyperv: vmbus: Remove the 2nd IRQ, Paolo Bonzini, 2020/06/24
- [PULL 29/31] vmport: move compat properties to hw_compat_5_0, Paolo Bonzini, 2020/06/24
- [PULL 31/31] i386: Mask SVM features if nested SVM is disabled, Paolo Bonzini, 2020/06/24
- [PULL 26/31] numa: forbid '-numa node, mem' for 5.1 and newer machine types, Paolo Bonzini, 2020/06/24
- [PULL 07/31] replay: synchronize on every virtual timer callback, Paolo Bonzini, 2020/06/24
- Re: [PULL 00/31] Misc patches for 2020-06-24, no-reply, 2020/06/24
- Re: [PULL 00/31] Misc patches for 2020-06-24, Peter Maydell, 2020/06/25