When GCC uses MPFR in the middle-end, it sets the precision of the MPFR
variables used for intermediate calculations to the "p" field of the
target float format.  We need the precision of the MPFR variables to be
exactly the same number of bits as the target float format so we can
determine when the results are "exact" and therefore can ignore rounding
issues.  At the very least, the MPFR precision shouldn't be less than the
target float format's precision.

But the "p" field in struct real_format is equivalent to MPFR's precision
only when the target's float base "b" (or FLT_RADIX) is 2.

I went through the various float formats to check the "b" field. Luckily
in most cases the base is in fact 2.  One case where it's not is for the
i370 real_format structs which use base==16.  I believe these formats
aren't ever used any more because the i370 support was removed.

In case i370 support is revived or a format not using base==2 is
introduced, I could proactively fix the MPFR precision setting for any
base that is a power of 2 by multiplying the target float precision by
log2(base).  In the i370 case I would multiply by log2(16) which is 4.
When base==2, then the log2(2) is 1 so the multiplication simplifies to
the current existing behavior.

The second case where base is not 2 is for the decimal float formats which
use base==10.  I don't know how or if these formats interact with builtins
and MPFR.  But a simple solution would be to punt if base is not a power
of 2 and let the builtin evaluate to a library call.

I'm not sure if these issues come up for fortran in prior releases.  I
think i370 was removed before 4.0/f95 and decimal floats were added in
4.2, which is not yet released.

Thoughts?

                Thanks,
                --Kaveh
--
Kaveh R. Ghazi                  [EMAIL PROTECTED]

Reply via email to