Re: [PATCH v3 03/22] host-utils: introduce uabs64()

2021-10-21 Thread Richard Henderson

On 10/21/21 3:34 PM, Eduardo Habkost wrote:

On Thu, Oct 21, 2021 at 4:04 PM Richard Henderson
 wrote:


On 9/10/21 4:26 AM, Luis Pires wrote:

Introduce uabs64(), a function that returns the absolute value of
a 64-bit int as an unsigned value. This avoids the undefined behavior
for common abs implementations, where abs of the most negative value is
undefined.


I do question the comment there wrt undefined. We compile with -fwrapv, which 
means that
*no* overflow is undefined; we always have properly truncated twos-compliment 
values.


Can we really assume that -fwrapv would make llabs(LLONG_MIN) not
undefined? We would be calling a function compiled by somebody else
(possibly without -fwrapv).


Fair enough.

r~



Re: [PATCH v3 03/22] host-utils: introduce uabs64()

2021-10-21 Thread Eduardo Habkost
On Thu, Oct 21, 2021 at 4:04 PM Richard Henderson
 wrote:
>
> On 9/10/21 4:26 AM, Luis Pires wrote:
> > Introduce uabs64(), a function that returns the absolute value of
> > a 64-bit int as an unsigned value. This avoids the undefined behavior
> > for common abs implementations, where abs of the most negative value is
> > undefined.
>
> I do question the comment there wrt undefined. We compile with -fwrapv, which 
> means that
> *no* overflow is undefined; we always have properly truncated twos-compliment 
> values.

Can we really assume that -fwrapv would make llabs(LLONG_MIN) not
undefined? We would be calling a function compiled by somebody else
(possibly without -fwrapv).

--
Eduardo




Re: [PATCH v3 03/22] host-utils: introduce uabs64()

2021-10-21 Thread Richard Henderson

On 9/10/21 4:26 AM, Luis Pires wrote:

Introduce uabs64(), a function that returns the absolute value of
a 64-bit int as an unsigned value. This avoids the undefined behavior
for common abs implementations, where abs of the most negative value is
undefined.


I do question the comment there wrt undefined. We compile with -fwrapv, which means that 
*no* overflow is undefined; we always have properly truncated twos-compliment values.



r~