1999, 2000 Free Software Foundation, Inc.
Contributed by Stephen L. Moshier (moshier@world.std.com).
-This file is part of GNU CC.
+This file is part of GCC.
-GNU CC is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
-GNU CC is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
You should have received a copy of the GNU General Public License
-along with GNU CC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+along with GCC; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
#include "config.h"
#include "system.h"
The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
and may deactivate XFmode since `long double' is used to refer
- to both modes.
+ to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
+ at the same time enables 80387-style 80-bit floats in a 128-bit
+ padded image, as seen on IA-64.
The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
in memory, with no holes. */
-#if MAX_LONG_DOUBLE_TYPE_SIZE == 96
+#if MAX_LONG_DOUBLE_TYPE_SIZE == 96 || \
+ ((INTEL_EXTENDED_IEEE_FORMAT != 0) && MAX_LONG_DOUBLE_TYPE_SIZE == 128)
/* Number of 16 bit words in external e type format */
-#define NE 6
-#define MAXDECEXP 4932
-#define MINDECEXP -4956
-#define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
-#define PUT_REAL(e,r) \
-do { \
- if (2*NE < sizeof(*r)) \
- bzero((char *)r, sizeof(*r)); \
- bcopy ((char *) e, (char *) r, 2*NE); \
-} while (0)
-#else /* no XFmode */
-#if MAX_LONG_DOUBLE_TYPE_SIZE == 128
-#define NE 10
-#define MAXDECEXP 4932
-#define MINDECEXP -4977
-#define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
-#define PUT_REAL(e,r) \
-do { \
- if (2*NE < sizeof(*r)) \
- bzero((char *)r, sizeof(*r)); \
- bcopy ((char *) e, (char *) r, 2*NE); \
-} while (0)
+# define NE 6
+# define MAXDECEXP 4932
+# define MINDECEXP -4956
+# define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
+# define PUT_REAL(e,r) \
+ do { \
+ memcpy ((char *)(r), (char *)(e), 2*NE); \
+ if (2*NE < sizeof(*r)) \
+ memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
+ } while (0)
+# else /* no XFmode */
+# if MAX_LONG_DOUBLE_TYPE_SIZE == 128
+# define NE 10
+# define MAXDECEXP 4932
+# define MINDECEXP -4977
+# define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
+# define PUT_REAL(e,r) \
+ do { \
+ memcpy ((char *)(r), (char *)(e), 2*NE); \
+ if (2*NE < sizeof(*r)) \
+ memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
+ } while (0)
#else
#define NE 6
#define MAXDECEXP 4932
/* The exponent of 1.0 */
#define EXONE (0x3fff)
+#if defined(HOST_EBCDIC)
+/* bit 8 is significant in EBCDIC */
+#define CHARMASK 0xff
+#else
+#define CHARMASK 0x7f
+#endif
+
extern int extra_warnings;
extern unsigned EMUSHORT ezero[], ehalf[], eone[], etwo[];
extern unsigned EMUSHORT elog2[], esqrt2[];
unsigned EMUSHORT *));
static void e53toe PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
static void e64toe PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
static void e113toe PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
+#endif
static void e24toe PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
static void etoe113 PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
static void toe113 PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
static void asctoe24 PARAMS ((const char *, unsigned EMUSHORT *));
static void asctoe53 PARAMS ((const char *, unsigned EMUSHORT *));
static void asctoe64 PARAMS ((const char *, unsigned EMUSHORT *));
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
static void asctoe113 PARAMS ((const char *, unsigned EMUSHORT *));
+#endif
static void asctoe PARAMS ((const char *, unsigned EMUSHORT *));
static void asctoeg PARAMS ((const char *, unsigned EMUSHORT *, int));
static void efloor PARAMS ((unsigned EMUSHORT *, unsigned EMUSHORT *));
switch (mode)
{
case TFmode:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
/* Swap halfwords in the fourth long. */
th = (unsigned long) e[6] & 0xffff;
t = (unsigned long) e[7] & 0xffff;
t |= th << 16;
x[3] = (long) t;
+#endif
case XFmode:
/* Swap halfwords in the third long. */
switch (mode)
{
case TFmode:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
/* Pack the fourth long. */
th = (unsigned long) e[7] & 0xffff;
t = (unsigned long) e[6] & 0xffff;
t |= th << 16;
x[3] = (long) t;
+#endif
case XFmode:
/* Pack the third long.
e53toe (tem, e);
break;
- case XFmode:
- asctoe64 (s, tem);
- e64toe (tem, e);
- break;
-
case TFmode:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
asctoe113 (s, tem);
e113toe (tem, e);
break;
+#endif
+ /* FALLTHRU */
+
+ case XFmode:
+ asctoe64 (s, tem);
+ e64toe (tem, e);
+ break;
default:
asctoe (s, e);
break;
case 128:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
etoe113 (dg, df);
e113toe (df, dg);
+#else
+ etoe64 (dg, df);
+ e64toe (df, dg);
+#endif
break;
default:
break;
case 128:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
etoe113 (dg, df);
e113toe (df, dg);
+#else
+ etoe64 (dg, df);
+ e64toe (df, dg);
+#endif
break;
default:
switch (mode)
{
case TFmode:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
etoe113 (e, t);
e113toe (t, t);
break;
+#endif
+ /* FALLTHRU */
case XFmode:
etoe64 (e, t);
/* e type constants used by high precision check routines */
-#if MAX_LONG_DOUBLE_TYPE_SIZE == 128
+#if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
/* 0.0 */
unsigned EMUSHORT ezero[NE] =
{0x0000, 0x0000, 0x0000, 0x0000,
*q++ = *p++;
}
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
/* Convert 128-bit long double precision float PE to e type Y. */
static void
}
emovo (yy, y);
}
+#endif
/* Convert single precision float PE to e type Y. */
else
{
q = b + 4; /* point to output exponent */
-#if MAX_LONG_DOUBLE_TYPE_SIZE == 96
- /* Clear the last two bytes of 12-byte Intel format */
+ /* Clear the last two bytes of 12-byte Intel format. q is pointing
+ into an array of size 6 (e.g. x[NE]), so the last two bytes are
+ always there, and there are never more bytes, even when we are using
+ INTEL_EXTENDED_IEEE_FORMAT. */
*(q+1) = 0;
-#endif
}
#endif
{
/* Long integer overflow: output large integer
and correct fraction.
- Note, the BSD microvax compiler says that ~(0UL)
+ Note, the BSD MicroVAX compiler says that ~(0UL)
is a syntax error. */
*i = ~(0L);
eshift (xi, k);
#define NTEN 12
#define MAXP 4096
-#if MAX_LONG_DOUBLE_TYPE_SIZE == 128
+#if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
static unsigned EMUSHORT etens[NTEN + 1][NE] =
{
{0x6576, 0x4a92, 0x804a, 0x153f,
/* Round up and propagate carry-outs */
roun:
--s;
- k = *s & 0x7f;
+ k = *s & CHARMASK;
/* Carry out to most significant digit? */
if (k == '.')
{
asctoeg (s, y, 64);
}
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
/* Convert ASCII string S to 128-bit long double Y. */
static void
{
asctoeg (s, y, 113);
}
+#endif
/* Convert ASCII string S to e type Y. */
}
/* Convert ASCII string SS to e type Y, with a specified rounding precision
- of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
+ of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
static void
asctoeg (ss, y, oprec)
{
unsigned EMUSHORT yy[NI], xt[NI], tt[NI];
int esign, decflg, sgnflg, nexp, exp, prec, lost;
- int k, trail, c, rndsav;
+ int i, k, trail, c, rndsav;
EMULONG lexp;
- unsigned EMUSHORT nsign, *p;
+ unsigned EMUSHORT nsign;
char *sp, *s, *lstr;
int base = 10;
nxtcom:
if (*s >= '0' && *s <= '9')
k = *s - '0';
- else if (*s >= 'a')
+ else if (*s >= 'a' && *s <= 'f')
k = 10 + *s - 'a';
else
k = 10 + *s - 'A';
|| (*sp >= 'A' && *sp <= 'F'))))
++sp;
/* Check for syntax error */
- c = *sp & 0x7f;
+ c = *sp & CHARMASK;
if ((base != 10 || ((c != 'e') && (c != 'E')))
&& (base != 16 || ((c != 'p') && (c != 'P')))
&& (c != '\0')
&& (c != '\n') && (c != '\r') && (c != ' ')
&& (c != ','))
- goto error;
+ goto unexpected_char_error;
--sp;
while (*sp == '0')
*sp-- = 'z';
goto expnt;
case '.': /* decimal point */
if (decflg)
- goto error;
+ goto unexpected_char_error;
++decflg;
break;
case '-':
nsign = 0xffff;
if (sgnflg)
- goto error;
+ goto unexpected_char_error;
++sgnflg;
break;
case '+':
if (sgnflg)
- goto error;
+ goto unexpected_char_error;
++sgnflg;
break;
case ',':
case 'I':
goto infinite;
default:
- error:
+ unexpected_char_error:
#ifdef NANS
einan (yy);
#else
/* Exponent interpretation */
expnt:
- /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
+ /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
for (k = 0; k < NI; k++)
{
if (yy[k] != 0)
nexp -= 4096;
}
}
- p = &etens[NTEN][0];
emov (eone, xt);
exp = 1;
+ i = NTEN;
do
{
if (exp & nexp)
- emul (p, xt, xt);
- p -= NE;
+ emul (etens[i], xt, xt);
+ i--;
exp = exp + exp;
}
while (exp <= MAXP);
int i;
int carry;
- /* Short-circuit the zero case. */
+ /* Short-circuit the zero case. */
if ((d[0] == 0x8000)
&& (d[1] == 0x0000)
&& ((mode == QFmode) || ((d[2] == 0x0000) && (d[3] == 0x0000))))
}
r >>= 8; /* Shift exponent word down 8 bits. */
- if (r & 0x80) /* Make the exponent negative if it is. */
+ if (r & 0x80) /* Make the exponent negative if it is. */
{
r = r | (~0 & ~0xff);
}
/* Now do the two's complement on the data. */
- carry = 1; /* Initially add 1 for the two's complement. */
+ carry = 1; /* Initially add 1 for the two's complement. */
for (i=size + M; i > M; i--)
{
if (carry && (y[i] == 0x0000))
emovi (x, xi);
- /* Adjust exponent for offsets. */
+ /* Adjust exponent for offsets. */
exp = (EMULONG) xi[E] - (EXONE - 0x7f);
- /* Round off to nearest or even. */
+ /* Round off to nearest or even. */
rndsav = rndprc;
rndprc = mode == QFmode ? 24 : 32;
emdnorm (xi, 0, 0, exp, 64);
/* Only check for double if necessary */
&& ((mode == QFmode) || ((x[M+2] == 0) && (x[M+3] == 0))))
{
- /* We have a zero. Put it into the output and return. */
+ /* We have a zero. Put it into the output and return. */
*y++ = 0x8000;
*y++ = 0x0000;
if (mode != QFmode)
*y = 0;
/* Negative number require a two's complement conversion of the
- mantissa. */
+ mantissa. */
if (x[0])
{
*y = 0x0080;
i = ((int) x[1]) - 0x7f;
- /* Now add 1 to the inverted data to do the two's complement. */
+ /* Now add 1 to the inverted data to do the two's complement. */
if (mode != QFmode)
v = 4 + M;
else
/* The following is a special case. The C4X negative float requires
a zero in the high bit (because the format is (2 - x) x 2^m), so
if a one is in that bit, we have to shift left one to get rid
- of it. This only occurs if the number is -1 x 2^m. */
+ of it. This only occurs if the number is -1 x 2^m. */
if (x[M+1] & 0x8000)
{
/* This is the case of -1 x 2^m, we have to rid ourselves of the
- high sign bit and shift the exponent. */
+ high sign bit and shift the exponent. */
eshift(x, 1);
i--;
}
used like NaN's, but probably not in the same way as IEEE. */
#if !defined(DEC) && !defined(IBM) && !defined(C4X)
case TFmode:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
n = 8;
if (REAL_WORDS_BIG_ENDIAN)
p = TFbignan;
else
p = TFlittlenan;
break;
+#endif
+ /* FALLTHRU */
case XFmode:
n = 6;
s[0] = (unsigned EMUSHORT) f;
s[1] = (unsigned EMUSHORT) (f >> 16);
}
- /* Convert and promote the target float to E-type. */
+ /* Convert and promote the target float to E-type. */
e24toe (s, e);
- /* Output E-type to REAL_VALUE_TYPE. */
+ /* Output E-type to REAL_VALUE_TYPE. */
PUT_REAL (e, &r);
return r;
}
s[2] = (unsigned EMUSHORT) d[1];
s[3] = (unsigned EMUSHORT) (d[1] >> 16);
}
- /* Convert target double to E-type. */
+ /* Convert target double to E-type. */
e53toe (s, e);
- /* Output E-type to REAL_VALUE_TYPE. */
+ /* Output E-type to REAL_VALUE_TYPE. */
PUT_REAL (e, &r);
return r;
}
floating point mode. The mode can hold an integer value
that many bits wide, without losing any bits. */
-int
+unsigned int
significand_size (mode)
enum machine_mode mode;
{
case 96:
return 64;
+
case 128:
+#if (INTEL_EXTENDED_IEEE_FORMAT == 0)
return 113;
+#else
+ return 64;
+#endif
default:
abort ();