https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93806

--- Comment #46 from Vincent Lefèvre <vincent-gcc at vinc17 dot net> ---
(In reply to Alexander Cherepanov from comment #45)
> (In reply to Vincent Lefèvre from comment #44)
> > (In reply to Alexander Cherepanov from comment #43)
> > > GCC on x86-64 uses the binary encoding for the significand.
> > 
> > In general, yes. This includes the 32-bit ABI under Linux. But it seems to
> > be different under MS-Windows, at least with MinGW using the 32-bit ABI:
> > according to my tests of MPFR,
[...]
> > i.e. GCC uses DPD instead of the usual BID.
> 
> Strange, I tried mingw from stable Debian on x86-64 and see it behaving the
> same way as the native gcc:

Sorry, I've looked at the code (the detection is done by the configure script),
and in case of cross-compiling, MPFR just assumes that this is DPD. I confirm
that this is actually BID. So MPFR's guess is wrong. It appears that this does
not currently have any consequence on the MPFR build and the tests, so that the
issue remained unnoticed.

> > In C, it is valid to choose any possible encoding. Concerning the IEEE 754
> > conformance, this depends on the bindings. But IEEE 754 does not define the
> > ternary operator. It depends whether C considers encodings before or
> > possibly after optimizations (in the C specification, this does not matter,
> > but when IEEE 754 is taken into account, there may be more restrictions).
> 
> The ternary operator is not important, let's replace it with `if`:
> 
> ----------------------------------------------------------------------
> #include <math.h>
> 
> _Decimal32 f(_Decimal32 x)
> {
>     _Decimal32 inf = (_Decimal32)INFINITY + 0;
> 
>     if (x == inf)
>         return inf;
>     else
>         return x;
> }
> ----------------------------------------------------------------------
> 
> This is optimized into just `return x;`.

I'm still wondering whether the optimization is valid, since this affects only
the encoding, not the value, and in general, C allows the encoding to change
when accessing an object. I don't know whether the C2x draft says something
special about the decimal formats.

> N2478, a recent draft of C2x, lists bindings in F.3 and "convertFormat -
> different formats" corresponds to "cast and implicit conversions". Is this
> enough?

But ditto, is optimization that just modifies the encoding allowed?

Reply via email to