#include "coretypes.h"
#include "tm.h"
#include "tree.h"
+#include "diagnostic-core.h"
#include "toplev.h"
#include "real.h"
+#include "realmpfr.h"
#include "tm_p.h"
#include "dfp.h"
return false;
}
-/* Legacy. Similar, but return the result directly. */
+REAL_VALUE_TYPE
+real_value_negate (const REAL_VALUE_TYPE *op0)
+{
+ REAL_VALUE_TYPE r;
+ real_arithmetic (&r, NEGATE_EXPR, op0, NULL);
+ return r;
+}
REAL_VALUE_TYPE
-real_arithmetic2 (int icode, const REAL_VALUE_TYPE *op0,
- const REAL_VALUE_TYPE *op1)
+real_value_abs (const REAL_VALUE_TYPE *op0)
{
REAL_VALUE_TYPE r;
- real_arithmetic (&r, icode, op0, op1);
+ real_arithmetic (&r, ABS_EXPR, op0, NULL);
return r;
}
if (HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG)
i = r->sig[SIGSZ-1];
- else
+ else
{
gcc_assert (HOST_BITS_PER_WIDE_INT == 2 * HOST_BITS_PER_LONG);
i = r->sig[SIGSZ-1];
case rvc_normal:
if (r->decimal)
- {
+ {
decimal_real_to_integer2 (plow, phigh, r);
return;
}
-
+
exp = REAL_EXP (r);
if (exp <= 0)
goto underflow;
high = t.sig[SIGSZ-1];
low = t.sig[SIGSZ-2];
}
- else
+ else
{
gcc_assert (HOST_BITS_PER_WIDE_INT == 2*HOST_BITS_PER_LONG);
high = t.sig[SIGSZ-1];
/* Initialize R from string S and desired MODE. */
-void
+void
real_from_string3 (REAL_VALUE_TYPE *r, const char *s, enum machine_mode mode)
{
if (DECIMAL_FLOAT_MODE_P (mode))
real_from_string (r, s);
if (mode != VOIDmode)
- real_convert (r, mode, r);
-}
+ real_convert (r, mode, r);
+}
/* Initialize R from the integer pair HIGH+LOW. */
mpfr_exp (m, m, GMP_RNDN);
real_from_mpfr (&value, m, NULL_TREE, GMP_RNDN);
mpfr_clear (m);
-
+
}
return &value;
}
fmt = REAL_MODE_FORMAT (mode);
gcc_assert (fmt);
memset (r, 0, sizeof (*r));
-
+
if (fmt->b == 10)
decimal_real_maxval (r, sign, mode);
else
/* Encode real R into a single precision DFP value in BUF. */
static void
encode_decimal_single (const struct real_format *fmt ATTRIBUTE_UNUSED,
- long *buf ATTRIBUTE_UNUSED,
+ long *buf ATTRIBUTE_UNUSED,
const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
{
encode_decimal32 (fmt, buf, r);
}
/* Decode a single precision DFP value in BUF into a real R. */
-static void
+static void
decode_decimal_single (const struct real_format *fmt ATTRIBUTE_UNUSED,
- REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
+ REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
const long *buf ATTRIBUTE_UNUSED)
{
decode_decimal32 (fmt, r, buf);
}
/* Encode real R into a double precision DFP value in BUF. */
-static void
+static void
encode_decimal_double (const struct real_format *fmt ATTRIBUTE_UNUSED,
- long *buf ATTRIBUTE_UNUSED,
+ long *buf ATTRIBUTE_UNUSED,
const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
{
encode_decimal64 (fmt, buf, r);
}
/* Decode a double precision DFP value in BUF into a real R. */
-static void
+static void
decode_decimal_double (const struct real_format *fmt ATTRIBUTE_UNUSED,
- REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
+ REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
const long *buf ATTRIBUTE_UNUSED)
{
decode_decimal64 (fmt, r, buf);
}
/* Encode real R into a quad precision DFP value in BUF. */
-static void
+static void
encode_decimal_quad (const struct real_format *fmt ATTRIBUTE_UNUSED,
long *buf ATTRIBUTE_UNUSED,
const REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED)
}
/* Decode a quad precision DFP value in BUF into a real R. */
-static void
+static void
decode_decimal_quad (const struct real_format *fmt ATTRIBUTE_UNUSED,
REAL_VALUE_TYPE *r ATTRIBUTE_UNUSED,
const long *buf ATTRIBUTE_UNUSED)
{
encode_decimal_single,
decode_decimal_single,
- 10,
+ 10,
7,
7,
-94,
true,
true,
true,
- true,
+ true,
true,
false
};
true,
true,
true,
- true,
- true,
+ true,
+ true,
true,
false
};
r->sign = x->sign;
}
-/* Convert from REAL_VALUE_TYPE to MPFR. The caller is responsible
- for initializing and clearing the MPFR parameter. */
-
-void
-mpfr_from_real (mpfr_ptr m, const REAL_VALUE_TYPE *r, mp_rnd_t rndmode)
-{
- /* We use a string as an intermediate type. */
- char buf[128];
- int ret;
-
- /* Take care of Infinity and NaN. */
- if (r->cl == rvc_inf)
- {
- mpfr_set_inf (m, r->sign == 1 ? -1 : 1);
- return;
- }
-
- if (r->cl == rvc_nan)
- {
- mpfr_set_nan (m);
- return;
- }
-
- real_to_hexadecimal (buf, r, sizeof (buf), 0, 1);
- /* mpfr_set_str() parses hexadecimal floats from strings in the same
- format that GCC will output them. Nothing extra is needed. */
- ret = mpfr_set_str (m, buf, 16, rndmode);
- gcc_assert (ret == 0);
-}
-
-/* Convert from MPFR to REAL_VALUE_TYPE, for a given type TYPE and rounding
- mode RNDMODE. TYPE is only relevant if M is a NaN. */
-
-void
-real_from_mpfr (REAL_VALUE_TYPE *r, mpfr_srcptr m, tree type, mp_rnd_t rndmode)
-{
- /* We use a string as an intermediate type. */
- char buf[128], *rstr;
- mp_exp_t exp;
-
- /* Take care of Infinity and NaN. */
- if (mpfr_inf_p (m))
- {
- real_inf (r);
- if (mpfr_sgn (m) < 0)
- *r = REAL_VALUE_NEGATE (*r);
- return;
- }
-
- if (mpfr_nan_p (m))
- {
- real_nan (r, "", 1, TYPE_MODE (type));
- return;
- }
-
- rstr = mpfr_get_str (NULL, &exp, 16, 0, m, rndmode);
-
- /* The additional 12 chars add space for the sprintf below. This
- leaves 6 digits for the exponent which is supposedly enough. */
- gcc_assert (rstr != NULL && strlen (rstr) < sizeof (buf) - 12);
-
- /* REAL_VALUE_ATOF expects the exponent for mantissa * 2**exp,
- mpfr_get_str returns the exponent for mantissa * 16**exp, adjust
- for that. */
- exp *= 4;
-
- if (rstr[0] == '-')
- sprintf (buf, "-0x.%sp%d", &rstr[1], (int) exp);
- else
- sprintf (buf, "0x.%sp%d", rstr, (int) exp);
-
- mpfr_free_str (rstr);
-
- real_from_string (r, buf);
-}
-
/* Check whether the real constant value given is an integer. */
bool