1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000, 2002 Free Software Foundation, Inc.
5 Contributed by Stephen L. Moshier (moshier@world.std.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
31 /* To enable support of XFmode extended real floating point, define
32 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
34 Machine files (tm.h etc) must not contain any code
35 that tries to use host floating point arithmetic to convert
36 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
37 etc. In cross-compile situations a REAL_VALUE_TYPE may not
38 be intelligible to the host computer's native arithmetic.
40 The first part of this file interfaces gcc to a floating point
41 arithmetic suite that was not written with gcc in mind. Avoid
42 changing the low-level arithmetic routines unless you have suitable
43 test programs available. A special version of the PARANOIA floating
44 point arithmetic tester, modified for this purpose, can be found on
45 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
46 XFmode and TFmode transcendental functions, can be obtained by ftp from
47 netlib.att.com: netlib/cephes. */
49 /* Type of computer arithmetic.
50 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
52 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
53 to big-endian IEEE floating-point data structure. This definition
54 should work in SFmode `float' type and DFmode `double' type on
55 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
56 has been defined to be 96, then IEEE also invokes the particular
57 XFmode (`long double' type) data structure used by the Motorola
58 680x0 series processors.
60 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
61 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
62 has been defined to be 96, then IEEE also invokes the particular
63 XFmode `long double' data structure used by the Intel 80x86 series
66 `DEC' refers specifically to the Digital Equipment Corp PDP-11
67 and VAX floating point data structure. This model currently
68 supports no type wider than DFmode.
70 `IBM' refers specifically to the IBM System/370 and compatible
71 floating point data structure. This model currently supports
72 no type wider than DFmode. The IBM conversions were contributed by
73 frank@atom.ansto.gov.au (Frank Crawford).
75 `C4X' refers specifically to the floating point format used on
76 Texas Instruments TMS320C3x and TMS320C4x digital signal
77 processors. This supports QFmode (32-bit float, double) and HFmode
78 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
79 floats, C4x floats are not rounded to be even. The C4x conversions
80 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
81 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
83 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
84 then `long double' and `double' are both implemented, but they
87 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
88 and may deactivate XFmode since `long double' is used to refer
89 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
90 at the same time enables 80387-style 80-bit floats in a 128-bit
91 padded image, as seen on IA-64.
93 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
94 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
95 separate the floating point unit's endian-ness from that of
96 the integer addressing. This permits one to define a big-endian
97 FPU on a little-endian machine (e.g., ARM). An extension to
98 BYTES_BIG_ENDIAN may be required for some machines in the future.
99 These optional macros may be defined in tm.h. In real.h, they
100 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
101 them for any normal host or target machine on which the floats
102 and the integers have the same endian-ness. */
105 /* The following converts gcc macros into the ones used by this file. */
107 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
108 /* PDP-11, Pro350, VAX: */
110 #else /* it's not VAX */
111 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
112 /* IBM System/370 style */
114 #else /* it's also not an IBM */
115 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
116 /* TMS320C3x/C4x style */
118 #else /* it's also not a C4X */
119 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
121 #else /* it's not IEEE either */
122 /* UNKnown arithmetic. We don't support this and can't go on. */
123 unknown arithmetic type
125 #endif /* not IEEE */
130 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
132 /* Define INFINITY for support of infinity.
133 Define NANS for support of Not-a-Number's (NaN's). */
134 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
139 /* Support of NaNs requires support of infinity. */
146 /* Find a host integer type that is at least 16 bits wide,
147 and another type at least twice whatever that size is. */
149 #if HOST_BITS_PER_CHAR >= 16
150 #define EMUSHORT char
151 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
152 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
154 #if HOST_BITS_PER_SHORT >= 16
155 #define EMUSHORT short
156 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
157 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
159 #if HOST_BITS_PER_INT >= 16
161 #define EMUSHORT_SIZE HOST_BITS_PER_INT
162 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
164 #if HOST_BITS_PER_LONG >= 16
165 #define EMUSHORT long
166 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
167 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
169 #error "You will have to modify this program to have a smaller unit size."
175 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
176 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
177 typedef int HItype
__attribute__ ((mode (HI
)));
178 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
182 #define EMUSHORT HItype
183 #define UEMUSHORT UHItype
184 #define EMUSHORT_SIZE 16
185 #define EMULONG_SIZE 32
187 #define UEMUSHORT unsigned EMUSHORT
190 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
191 #define EMULONG short
193 #if HOST_BITS_PER_INT >= EMULONG_SIZE
196 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
199 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
200 #define EMULONG long long int
202 #error "You will have to modify this program to have a smaller unit size."
208 #if EMUSHORT_SIZE != 16
209 #error "The host interface doesn't work if no 16-bit size exists."
212 /* Calculate the size of the generic "e" type. This always has
213 identical in-memory size to REAL_VALUE_TYPE. The sizes are supposed
214 to be the same as well, but when REAL_VALUE_TYPE_SIZE is not evenly
215 divisible by HOST_BITS_PER_WIDE_INT we have some padding in
217 There are only two supported sizes: ten and six 16-bit words (160
220 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
223 # define MAXDECEXP 4932
224 # define MINDECEXP -4977
227 # define MAXDECEXP 4932
228 # define MINDECEXP -4956
231 /* Fail compilation if 2*NE is not the appropriate size.
232 If HOST_BITS_PER_WIDE_INT is 64, we're going to have padding
233 at the end of the array, because neither 96 nor 160 is
234 evenly divisible by 64. */
235 struct compile_test_dummy
{
236 char twice_NE_must_equal_sizeof_REAL_VALUE_TYPE
237 [(sizeof (REAL_VALUE_TYPE
) >= 2*NE
) ? 1 : -1];
240 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
241 In GET_REAL and PUT_REAL, r and e are pointers.
242 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
243 in memory, with no holes. */
244 #define GET_REAL(r, e) memcpy ((e), (r), 2*NE)
245 #define PUT_REAL(e, r) \
247 memcpy (r, e, 2*NE); \
248 if (2*NE < sizeof (*r)) \
249 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
252 /* Number of 16 bit words in internal format */
255 /* Array offset to exponent */
258 /* Array offset to high guard word */
261 /* Number of bits of precision */
262 #define NBITS ((NI-4)*16)
264 /* Maximum number of decimal digits in ASCII conversion
267 #define NDEC (NBITS*8/27)
269 /* The exponent of 1.0 */
270 #define EXONE (0x3fff)
272 #if defined(HOST_EBCDIC)
273 /* bit 8 is significant in EBCDIC */
274 #define CHARMASK 0xff
276 #define CHARMASK 0x7f
279 extern int extra_warnings
;
280 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
281 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
283 static void endian
PARAMS ((const UEMUSHORT
*, long *,
285 static void eclear
PARAMS ((UEMUSHORT
*));
286 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
288 static void eabs
PARAMS ((UEMUSHORT
*));
290 static void eneg
PARAMS ((UEMUSHORT
*));
291 static int eisneg
PARAMS ((const UEMUSHORT
*));
292 static int eisinf
PARAMS ((const UEMUSHORT
*));
293 static int eisnan
PARAMS ((const UEMUSHORT
*));
294 static void einfin
PARAMS ((UEMUSHORT
*));
296 static void enan
PARAMS ((UEMUSHORT
*, int));
297 static void einan
PARAMS ((UEMUSHORT
*));
298 static int eiisnan
PARAMS ((const UEMUSHORT
*));
299 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
301 static int eiisneg
PARAMS ((const UEMUSHORT
*));
302 static void saturate
PARAMS ((UEMUSHORT
*, int, int, int));
303 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
304 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
305 static void ecleaz
PARAMS ((UEMUSHORT
*));
306 static void ecleazs
PARAMS ((UEMUSHORT
*));
307 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
309 static void eiinfin
PARAMS ((UEMUSHORT
*));
312 static int eiisinf
PARAMS ((const UEMUSHORT
*));
314 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
315 static void eshdn1
PARAMS ((UEMUSHORT
*));
316 static void eshup1
PARAMS ((UEMUSHORT
*));
317 static void eshdn8
PARAMS ((UEMUSHORT
*));
318 static void eshup8
PARAMS ((UEMUSHORT
*));
319 static void eshup6
PARAMS ((UEMUSHORT
*));
320 static void eshdn6
PARAMS ((UEMUSHORT
*));
321 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
322 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
323 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
324 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
325 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
326 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
327 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
329 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
331 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
333 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
335 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
337 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
338 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
339 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
340 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
342 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
343 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
344 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
345 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
347 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
348 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
349 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
350 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
351 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
352 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
353 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
355 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
357 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
358 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
359 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
361 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
363 static int eshift
PARAMS ((UEMUSHORT
*, int));
364 static int enormlz
PARAMS ((UEMUSHORT
*));
366 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
367 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
368 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
369 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
371 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
372 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
373 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
374 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
375 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
376 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
378 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
379 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
380 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
382 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
385 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
387 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
390 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
391 static void mtherr
PARAMS ((const char *, int));
393 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
394 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
395 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
398 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
400 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
402 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
406 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
408 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
410 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
414 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
415 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
416 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
417 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
418 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
421 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
422 swapping ends if required, into output array of longs. The
423 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
429 enum machine_mode mode
;
433 if (REAL_WORDS_BIG_ENDIAN
)
438 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
439 /* Swap halfwords in the fourth long. */
440 th
= (unsigned long) e
[6] & 0xffff;
441 t
= (unsigned long) e
[7] & 0xffff;
450 /* Swap halfwords in the third long. */
451 th
= (unsigned long) e
[4] & 0xffff;
452 t
= (unsigned long) e
[5] & 0xffff;
458 /* Swap halfwords in the second word. */
459 th
= (unsigned long) e
[2] & 0xffff;
460 t
= (unsigned long) e
[3] & 0xffff;
467 /* Swap halfwords in the first word. */
468 th
= (unsigned long) e
[0] & 0xffff;
469 t
= (unsigned long) e
[1] & 0xffff;
480 /* Pack the output array without swapping. */
485 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
486 /* Pack the fourth long. */
487 th
= (unsigned long) e
[7] & 0xffff;
488 t
= (unsigned long) e
[6] & 0xffff;
497 /* Pack the third long.
498 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
500 th
= (unsigned long) e
[5] & 0xffff;
501 t
= (unsigned long) e
[4] & 0xffff;
507 /* Pack the second long */
508 th
= (unsigned long) e
[3] & 0xffff;
509 t
= (unsigned long) e
[2] & 0xffff;
516 /* Pack the first long */
517 th
= (unsigned long) e
[1] & 0xffff;
518 t
= (unsigned long) e
[0] & 0xffff;
530 /* This is the implementation of the REAL_ARITHMETIC macro. */
533 earith (value
, icode
, r1
, r2
)
534 REAL_VALUE_TYPE
*value
;
539 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
545 /* Return NaN input back to the caller. */
548 PUT_REAL (d1
, value
);
553 PUT_REAL (d2
, value
);
557 code
= (enum tree_code
) icode
;
565 esub (d2
, d1
, v
); /* d1 - d2 */
574 if (ecmp (d2
, ezero
) == 0)
577 ediv (d2
, d1
, v
); /* d1/d2 */
580 case MIN_EXPR
: /* min (d1,d2) */
581 if (ecmp (d1
, d2
) < 0)
587 case MAX_EXPR
: /* max (d1,d2) */
588 if (ecmp (d1
, d2
) > 0)
601 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
602 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
608 UEMUSHORT f
[NE
], g
[NE
];
624 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
625 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
631 UEMUSHORT f
[NE
], g
[NE
];
633 unsigned HOST_WIDE_INT l
;
647 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
648 string to binary, rounding off as indicated by the machine_mode argument.
649 Then it promotes the rounded value to REAL_VALUE_TYPE. */
656 UEMUSHORT tem
[NE
], e
[NE
];
682 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
702 /* Expansion of REAL_NEGATE. */
718 /* Round real toward zero to HOST_WIDE_INT;
719 implements REAL_VALUE_FIX (x). */
725 UEMUSHORT f
[NE
], g
[NE
];
732 warning ("conversion from NaN to int");
740 /* Round real toward zero to unsigned HOST_WIDE_INT
741 implements REAL_VALUE_UNSIGNED_FIX (x).
742 Negative input returns zero. */
744 unsigned HOST_WIDE_INT
748 UEMUSHORT f
[NE
], g
[NE
];
749 unsigned HOST_WIDE_INT l
;
755 warning ("conversion from NaN to unsigned int");
764 /* REAL_VALUE_FROM_INT macro. */
767 ereal_from_int (d
, i
, j
, mode
)
770 enum machine_mode mode
;
772 UEMUSHORT df
[NE
], dg
[NE
];
773 HOST_WIDE_INT low
, high
;
776 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
783 /* complement and add 1 */
790 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
791 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
793 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
798 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
799 Avoid double-rounding errors later by rounding off now from the
800 extra-wide internal format to the requested precision. */
801 switch (GET_MODE_BITSIZE (mode
))
819 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
836 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
839 ereal_from_uint (d
, i
, j
, mode
)
841 unsigned HOST_WIDE_INT i
, j
;
842 enum machine_mode mode
;
844 UEMUSHORT df
[NE
], dg
[NE
];
845 unsigned HOST_WIDE_INT low
, high
;
847 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
851 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
857 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
858 Avoid double-rounding errors later by rounding off now from the
859 extra-wide internal format to the requested precision. */
860 switch (GET_MODE_BITSIZE (mode
))
878 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
895 /* REAL_VALUE_TO_INT macro. */
898 ereal_to_int (low
, high
, rr
)
899 HOST_WIDE_INT
*low
, *high
;
902 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
909 warning ("conversion from NaN to int");
915 /* convert positive value */
922 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
923 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
924 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
925 emul (df
, dh
, dg
); /* fractional part is the low word */
926 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
929 /* complement and add 1 */
939 /* REAL_VALUE_LDEXP macro. */
946 UEMUSHORT e
[NE
], y
[NE
];
959 /* Check for infinity in a REAL_VALUE_TYPE. */
963 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
975 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
979 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
992 /* Check for a negative REAL_VALUE_TYPE number.
993 This just checks the sign bit, so that -0 counts as negative. */
999 return ereal_isneg (x
);
1002 /* Expansion of REAL_VALUE_TRUNCATE.
1003 The result is in floating point, rounded to nearest or even. */
1006 real_value_truncate (mode
, arg
)
1007 enum machine_mode mode
;
1008 REAL_VALUE_TYPE arg
;
1010 UEMUSHORT e
[NE
], t
[NE
];
1022 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1059 /* If an unsupported type was requested, presume that
1060 the machine files know something useful to do with
1061 the unmodified value. */
1070 /* Return true if ARG can be represented exactly in MODE. */
1073 exact_real_truncate (mode
, arg
)
1074 enum machine_mode mode
;
1075 REAL_VALUE_TYPE
*arg
;
1077 REAL_VALUE_TYPE trunc
;
1079 if (target_isnan (*arg
))
1082 trunc
= real_value_truncate (mode
, *arg
);
1083 return ereal_cmp (*arg
, trunc
) == 0;
1086 /* Try to change R into its exact multiplicative inverse in machine mode
1087 MODE. Return nonzero function value if successful. */
1090 exact_real_inverse (mode
, r
)
1091 enum machine_mode mode
;
1094 UEMUSHORT e
[NE
], einv
[NE
];
1095 REAL_VALUE_TYPE rinv
;
1100 /* Test for input in range. Don't transform IEEE special values. */
1101 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1104 /* Test for a power of 2: all significand bits zero except the MSB.
1105 We are assuming the target has binary (or hex) arithmetic. */
1106 if (e
[NE
- 2] != 0x8000)
1109 for (i
= 0; i
< NE
- 2; i
++)
1115 /* Compute the inverse and truncate it to the required mode. */
1116 ediv (e
, eone
, einv
);
1117 PUT_REAL (einv
, &rinv
);
1118 rinv
= real_value_truncate (mode
, rinv
);
1120 #ifdef CHECK_FLOAT_VALUE
1121 /* This check is not redundant. It may, for example, flush
1122 a supposedly IEEE denormal value to zero. */
1124 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1127 GET_REAL (&rinv
, einv
);
1129 /* Check the bits again, because the truncation might have
1130 generated an arbitrary saturation value on overflow. */
1131 if (einv
[NE
- 2] != 0x8000)
1134 for (i
= 0; i
< NE
- 2; i
++)
1140 /* Fail if the computed inverse is out of range. */
1141 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1144 /* Output the reciprocal and return success flag. */
1149 /* Used for debugging--print the value of R in human-readable format
1158 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1159 fprintf (stderr
, "%s", dstr
);
1163 /* The following routines convert REAL_VALUE_TYPE to the various floating
1164 point formats that are meaningful to supported computers.
1166 The results are returned in 32-bit pieces, each piece stored in a `long'.
1167 This is so they can be printed by statements like
1169 fprintf (file, "%lx, %lx", L[0], L[1]);
1171 that will work on both narrow- and wide-word host computers. */
1173 /* Convert R to a 128-bit long double precision value. The output array L
1174 contains four 32-bit pieces of the result, in the order they would appear
1185 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1190 endian (e
, l
, TFmode
);
1193 /* Convert R to a double extended precision value. The output array L
1194 contains three 32-bit pieces of the result, in the order they would
1195 appear in memory. */
1206 endian (e
, l
, XFmode
);
1209 /* Convert R to a double precision value. The output array L contains two
1210 32-bit pieces of the result, in the order they would appear in memory. */
1221 endian (e
, l
, DFmode
);
1224 /* Convert R to a single precision float value stored in the least-significant
1225 bits of a `long'. */
1236 endian (e
, &l
, SFmode
);
1240 /* Convert X to a decimal ASCII string S for output to an assembly
1241 language file. Note, there is no standard way to spell infinity or
1242 a NaN, so these values may require special treatment in the tm.h
1246 ereal_to_decimal (x
, s
)
1256 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1257 or -2 if either is a NaN. */
1261 REAL_VALUE_TYPE x
, y
;
1263 UEMUSHORT ex
[NE
], ey
[NE
];
1267 return (ecmp (ex
, ey
));
1270 /* Return 1 if the sign bit of X is set, else return 0. */
1279 return (eisneg (ex
));
1284 Extended precision IEEE binary floating point arithmetic routines
1286 Numbers are stored in C language as arrays of 16-bit unsigned
1287 short integers. The arguments of the routines are pointers to
1290 External e type data structure, similar to Intel 8087 chip
1291 temporary real format but possibly with a larger significand:
1293 NE-1 significand words (least significant word first,
1294 most significant bit is normally set)
1295 exponent (value = EXONE for 1.0,
1296 top bit is the sign)
1299 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1301 ei[0] sign word (0 for positive, 0xffff for negative)
1302 ei[1] biased exponent (value = EXONE for the number 1.0)
1303 ei[2] high guard word (always zero after normalization)
1305 to ei[NI-2] significand (NI-4 significand words,
1306 most significant word first,
1307 most significant bit is set)
1308 ei[NI-1] low guard word (0x8000 bit is rounding place)
1312 Routines for external format e-type numbers
1314 asctoe (string, e) ASCII string to extended double e type
1315 asctoe64 (string, &d) ASCII string to long double
1316 asctoe53 (string, &d) ASCII string to double
1317 asctoe24 (string, &f) ASCII string to single
1318 asctoeg (string, e, prec) ASCII string to specified precision
1319 e24toe (&f, e) IEEE single precision to e type
1320 e53toe (&d, e) IEEE double precision to e type
1321 e64toe (&d, e) IEEE long double precision to e type
1322 e113toe (&d, e) 128-bit long double precision to e type
1324 eabs (e) absolute value
1326 eadd (a, b, c) c = b + a
1328 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1329 -1 if a < b, -2 if either a or b is a NaN.
1330 ediv (a, b, c) c = b / a
1331 efloor (a, b) truncate to integer, toward -infinity
1332 efrexp (a, exp, s) extract exponent and significand
1333 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1334 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1335 einfin (e) set e to infinity, leaving its sign alone
1336 eldexp (a, n, b) multiply by 2**n
1338 emul (a, b, c) c = b * a
1341 eround (a, b) b = nearest integer value to a
1343 esub (a, b, c) c = b - a
1345 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1346 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1347 e64toasc (&d, str, n) 80-bit long double to ASCII string
1348 e113toasc (&d, str, n) 128-bit long double to ASCII string
1350 etoasc (e, str, n) e to ASCII string, n digits after decimal
1351 etoe24 (e, &f) convert e type to IEEE single precision
1352 etoe53 (e, &d) convert e type to IEEE double precision
1353 etoe64 (e, &d) convert e type to IEEE long double precision
1354 ltoe (&l, e) HOST_WIDE_INT to e type
1355 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1356 eisneg (e) 1 if sign bit of e != 0, else 0
1357 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1358 or is infinite (IEEE)
1359 eisnan (e) 1 if e is a NaN
1362 Routines for internal format exploded e-type numbers
1364 eaddm (ai, bi) add significands, bi = bi + ai
1366 ecleazs (ei) set ei = 0 but leave its sign alone
1367 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1368 edivm (ai, bi) divide significands, bi = bi / ai
1369 emdnorm (ai,l,s,exp) normalize and round off
1370 emovi (a, ai) convert external a to internal ai
1371 emovo (ai, a) convert internal ai to external a
1372 emovz (ai, bi) bi = ai, low guard word of bi = 0
1373 emulm (ai, bi) multiply significands, bi = bi * ai
1374 enormlz (ei) left-justify the significand
1375 eshdn1 (ai) shift significand and guards down 1 bit
1376 eshdn8 (ai) shift down 8 bits
1377 eshdn6 (ai) shift down 16 bits
1378 eshift (ai, n) shift ai n bits up (or down if n < 0)
1379 eshup1 (ai) shift significand and guards up 1 bit
1380 eshup8 (ai) shift up 8 bits
1381 eshup6 (ai) shift up 16 bits
1382 esubm (ai, bi) subtract significands, bi = bi - ai
1383 eiisinf (ai) 1 if infinite
1384 eiisnan (ai) 1 if a NaN
1385 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1386 einan (ai) set ai = NaN
1388 eiinfin (ai) set ai = infinity
1391 The result is always normalized and rounded to NI-4 word precision
1392 after each arithmetic operation.
1394 Exception flags are NOT fully supported.
1396 Signaling NaN's are NOT supported; they are treated the same
1399 Define INFINITY for support of infinity; otherwise a
1400 saturation arithmetic is implemented.
1402 Define NANS for support of Not-a-Number items; otherwise the
1403 arithmetic will never produce a NaN output, and might be confused
1405 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1406 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1407 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1410 Denormals are always supported here where appropriate (e.g., not
1411 for conversion to DEC numbers). */
1413 /* Definitions for error codes that are passed to the common error handling
1416 For Digital Equipment PDP-11 and VAX computers, certain
1417 IBM systems, and others that use numbers with a 56-bit
1418 significand, the symbol DEC should be defined. In this
1419 mode, most floating point constants are given as arrays
1420 of octal integers to eliminate decimal to binary conversion
1421 errors that might be introduced by the compiler.
1423 For computers, such as IBM PC, that follow the IEEE
1424 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1425 Std 754-1985), the symbol IEEE should be defined.
1426 These numbers have 53-bit significands. In this mode, constants
1427 are provided as arrays of hexadecimal 16 bit integers.
1428 The endian-ness of generated values is controlled by
1429 REAL_WORDS_BIG_ENDIAN.
1431 To accommodate other types of computer arithmetic, all
1432 constants are also provided in a normal decimal radix
1433 which one can hope are correctly converted to a suitable
1434 format by the available C language compiler. To invoke
1435 this mode, the symbol UNK is defined.
1437 An important difference among these modes is a predefined
1438 set of machine arithmetic constants for each. The numbers
1439 MACHEP (the machine roundoff error), MAXNUM (largest number
1440 represented), and several other parameters are preset by
1441 the configuration symbol. Check the file const.c to
1442 ensure that these values are correct for your computer.
1444 For ANSI C compatibility, define ANSIC equal to 1. Currently
1445 this affects only the atan2 function and others that use it. */
1447 /* Constant definitions for math error conditions. */
1449 #define DOMAIN 1 /* argument domain error */
1450 #define SING 2 /* argument singularity */
1451 #define OVERFLOW 3 /* overflow range error */
1452 #define UNDERFLOW 4 /* underflow range error */
1453 #define TLOSS 5 /* total loss of precision */
1454 #define PLOSS 6 /* partial loss of precision */
1455 #define INVALID 7 /* NaN-producing operation */
1457 /* e type constants used by high precision check routines */
1459 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1461 const UEMUSHORT ezero
[NE
] =
1462 {0x0000, 0x0000, 0x0000, 0x0000,
1463 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1466 const UEMUSHORT ehalf
[NE
] =
1467 {0x0000, 0x0000, 0x0000, 0x0000,
1468 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1471 const UEMUSHORT eone
[NE
] =
1472 {0x0000, 0x0000, 0x0000, 0x0000,
1473 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1476 const UEMUSHORT etwo
[NE
] =
1477 {0x0000, 0x0000, 0x0000, 0x0000,
1478 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1481 const UEMUSHORT e32
[NE
] =
1482 {0x0000, 0x0000, 0x0000, 0x0000,
1483 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1485 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1486 const UEMUSHORT elog2
[NE
] =
1487 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1488 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1490 /* 1.41421356237309504880168872420969807856967187537695E0 */
1491 const UEMUSHORT esqrt2
[NE
] =
1492 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1493 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1495 /* 3.14159265358979323846264338327950288419716939937511E0 */
1496 const UEMUSHORT epi
[NE
] =
1497 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1498 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1501 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1502 const UEMUSHORT ezero
[NE
] =
1503 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1504 const UEMUSHORT ehalf
[NE
] =
1505 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1506 const UEMUSHORT eone
[NE
] =
1507 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1508 const UEMUSHORT etwo
[NE
] =
1509 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1510 const UEMUSHORT e32
[NE
] =
1511 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1512 const UEMUSHORT elog2
[NE
] =
1513 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1514 const UEMUSHORT esqrt2
[NE
] =
1515 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1516 const UEMUSHORT epi
[NE
] =
1517 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1520 /* Control register for rounding precision.
1521 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1526 /* Clear out entire e-type number X. */
1534 for (i
= 0; i
< NE
; i
++)
1538 /* Move e-type number from A to B. */
1547 for (i
= 0; i
< NE
; i
++)
1553 /* Absolute value of e-type X. */
1559 /* sign is top bit of last word of external format */
1560 x
[NE
- 1] &= 0x7fff;
1564 /* Negate the e-type number X. */
1571 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1574 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1578 const UEMUSHORT x
[];
1581 if (x
[NE
- 1] & 0x8000)
1587 /* Return 1 if e-type number X is infinity, else return zero. */
1591 const UEMUSHORT x
[];
1598 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1604 /* Check if e-type number is not a number. The bit pattern is one that we
1605 defined, so we know for sure how to detect it. */
1609 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1614 /* NaN has maximum exponent */
1615 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1617 /* ... and non-zero significand field. */
1618 for (i
= 0; i
< NE
- 1; i
++)
1628 /* Fill e-type number X with infinity pattern (IEEE)
1629 or largest possible number (non-IEEE). */
1638 for (i
= 0; i
< NE
- 1; i
++)
1642 for (i
= 0; i
< NE
- 1; i
++)
1670 /* Output an e-type NaN.
1671 This generates Intel's quiet NaN pattern for extended real.
1672 The exponent is 7fff, the leading mantissa word is c000. */
1682 for (i
= 0; i
< NE
- 2; i
++)
1685 *x
= (sign
<< 15) | 0x7fff;
1689 /* Move in an e-type number A, converting it to exploded e-type B. */
1701 p
= a
+ (NE
- 1); /* point to last word of external number */
1702 /* get the sign bit */
1707 /* get the exponent */
1709 *q
++ &= 0x7fff; /* delete the sign bit */
1711 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1717 for (i
= 3; i
< NI
; i
++)
1723 for (i
= 2; i
< NI
; i
++)
1729 /* clear high guard word */
1731 /* move in the significand */
1732 for (i
= 0; i
< NE
- 1; i
++)
1734 /* clear low guard word */
1738 /* Move out exploded e-type number A, converting it to e type B. */
1751 q
= b
+ (NE
- 1); /* point to output exponent */
1752 /* combine sign and exponent */
1755 *q
-- = *p
++ | 0x8000;
1759 if (*(p
- 1) == 0x7fff)
1764 enan (b
, eiisneg (a
));
1772 /* skip over guard word */
1774 /* move the significand */
1775 for (j
= 0; j
< NE
- 1; j
++)
1779 /* Clear out exploded e-type number XI. */
1787 for (i
= 0; i
< NI
; i
++)
1791 /* Clear out exploded e-type XI, but don't touch the sign. */
1800 for (i
= 0; i
< NI
- 1; i
++)
1804 /* Move exploded e-type number from A to B. */
1813 for (i
= 0; i
< NI
- 1; i
++)
1815 /* clear low guard word */
1819 /* Generate exploded e-type NaN.
1820 The explicit pattern for this is maximum exponent and
1821 top two significant bits set. */
1835 /* Return nonzero if exploded e-type X is a NaN. */
1840 const UEMUSHORT x
[];
1844 if ((x
[E
] & 0x7fff) == 0x7fff)
1846 for (i
= M
+ 1; i
< NI
; i
++)
1856 /* Return nonzero if sign of exploded e-type X is nonzero. */
1860 const UEMUSHORT x
[];
1867 /* Fill exploded e-type X with infinity pattern.
1868 This has maximum exponent and significand all zeros. */
1880 /* Return nonzero if exploded e-type X is infinite. */
1885 const UEMUSHORT x
[];
1892 if ((x
[E
] & 0x7fff) == 0x7fff)
1896 #endif /* INFINITY */
1898 /* Compare significands of numbers in internal exploded e-type format.
1899 Guard words are included in the comparison.
1907 const UEMUSHORT
*a
, *b
;
1911 a
+= M
; /* skip up to significand area */
1913 for (i
= M
; i
< NI
; i
++)
1921 if (*(--a
) > *(--b
))
1927 /* Shift significand of exploded e-type X down by 1 bit. */
1936 x
+= M
; /* point to significand area */
1939 for (i
= M
; i
< NI
; i
++)
1951 /* Shift significand of exploded e-type X up by 1 bit. */
1963 for (i
= M
; i
< NI
; i
++)
1976 /* Shift significand of exploded e-type X down by 8 bits. */
1982 UEMUSHORT newbyt
, oldbyt
;
1987 for (i
= M
; i
< NI
; i
++)
1997 /* Shift significand of exploded e-type X up by 8 bits. */
2004 UEMUSHORT newbyt
, oldbyt
;
2009 for (i
= M
; i
< NI
; i
++)
2019 /* Shift significand of exploded e-type X up by 16 bits. */
2031 for (i
= M
; i
< NI
- 1; i
++)
2037 /* Shift significand of exploded e-type X down by 16 bits. */
2049 for (i
= M
; i
< NI
- 1; i
++)
2055 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2069 for (i
= M
; i
< NI
; i
++)
2071 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2082 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2096 for (i
= M
; i
< NI
; i
++)
2098 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2110 static UEMUSHORT equot
[NI
];
2114 /* Radix 2 shift-and-add versions of multiply and divide */
2117 /* Divide significands */
2121 UEMUSHORT den
[], num
[];
2131 for (i
= M
; i
< NI
; i
++)
2136 /* Use faster compare and subtraction if denominator has only 15 bits of
2142 for (i
= M
+ 3; i
< NI
; i
++)
2147 if ((den
[M
+ 1] & 1) != 0)
2155 for (i
= 0; i
< NBITS
+ 2; i
++)
2173 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2174 bit + 1 roundoff bit. */
2179 for (i
= 0; i
< NBITS
+ 2; i
++)
2181 if (ecmpm (den
, num
) <= 0)
2184 j
= 1; /* quotient bit = 1 */
2198 /* test for nonzero remainder after roundoff bit */
2201 for (i
= M
; i
< NI
; i
++)
2209 for (i
= 0; i
< NI
; i
++)
2215 /* Multiply significands */
2226 for (i
= M
; i
< NI
; i
++)
2231 while (*p
== 0) /* significand is not supposed to be zero */
2236 if ((*p
& 0xff) == 0)
2244 for (i
= 0; i
< k
; i
++)
2248 /* remember if there were any nonzero bits shifted out */
2255 for (i
= 0; i
< NI
; i
++)
2258 /* return flag for lost nonzero bits */
2264 /* Radix 65536 versions of multiply and divide. */
2266 /* Multiply significand of e-type number B
2267 by 16-bit quantity A, return e-type result to C. */
2272 const UEMUSHORT b
[];
2276 unsigned EMULONG carry
;
2277 const UEMUSHORT
*ps
;
2279 unsigned EMULONG aa
, m
;
2288 for (i
=M
+1; i
<NI
; i
++)
2298 m
= (unsigned EMULONG
) aa
* *ps
--;
2299 carry
= (m
& 0xffff) + *pp
;
2300 *pp
-- = (UEMUSHORT
) carry
;
2301 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2302 *pp
= (UEMUSHORT
) carry
;
2303 *(pp
-1) = carry
>> 16;
2306 for (i
=M
; i
<NI
; i
++)
2310 /* Divide significands of exploded e-types NUM / DEN. Neither the
2311 numerator NUM nor the denominator DEN is permitted to have its high guard
2316 const UEMUSHORT den
[];
2321 unsigned EMULONG tnum
;
2322 UEMUSHORT j
, tdenm
, tquot
;
2323 UEMUSHORT tprod
[NI
+1];
2329 for (i
=M
; i
<NI
; i
++)
2335 for (i
=M
; i
<NI
; i
++)
2337 /* Find trial quotient digit (the radix is 65536). */
2338 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2340 /* Do not execute the divide instruction if it will overflow. */
2341 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2344 tquot
= tnum
/ tdenm
;
2345 /* Multiply denominator by trial quotient digit. */
2346 m16m ((unsigned int) tquot
, den
, tprod
);
2347 /* The quotient digit may have been overestimated. */
2348 if (ecmpm (tprod
, num
) > 0)
2352 if (ecmpm (tprod
, num
) > 0)
2362 /* test for nonzero remainder after roundoff bit */
2365 for (i
=M
; i
<NI
; i
++)
2372 for (i
=0; i
<NI
; i
++)
2378 /* Multiply significands of exploded e-type A and B, result in B. */
2382 const UEMUSHORT a
[];
2387 UEMUSHORT pprod
[NI
];
2393 for (i
=M
; i
<NI
; i
++)
2399 for (i
=M
+1; i
<NI
; i
++)
2407 m16m ((unsigned int) *p
--, b
, pprod
);
2408 eaddm (pprod
, equot
);
2414 for (i
=0; i
<NI
; i
++)
2417 /* return flag for lost nonzero bits */
2423 /* Normalize and round off.
2425 The internal format number to be rounded is S.
2426 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2428 Input SUBFLG indicates whether the number was obtained
2429 by a subtraction operation. In that case if LOST is nonzero
2430 then the number is slightly smaller than indicated.
2432 Input EXP is the biased exponent, which may be negative.
2433 the exponent field of S is ignored but is replaced by
2434 EXP as adjusted by normalization and rounding.
2436 Input RCNTRL is the rounding control. If it is nonzero, the
2437 returned value will be rounded to RNDPRC bits.
2439 For future reference: In order for emdnorm to round off denormal
2440 significands at the right point, the input exponent must be
2441 adjusted to be the actual value it would have after conversion to
2442 the final floating point type. This adjustment has been
2443 implemented for all type conversions (etoe53, etc.) and decimal
2444 conversions, but not for the arithmetic functions (eadd, etc.).
2445 Data types having standard 15-bit exponents are not affected by
2446 this, but SFmode and DFmode are affected. For example, ediv with
2447 rndprc = 24 will not round correctly to 24-bit precision if the
2448 result is denormal. */
2450 static int rlast
= -1;
2452 static UEMUSHORT rmsk
= 0;
2453 static UEMUSHORT rmbit
= 0;
2454 static UEMUSHORT rebit
= 0;
2456 static UEMUSHORT rbit
[NI
];
2459 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2472 /* a blank significand could mean either zero or infinity. */
2485 if ((j
> NBITS
) && (exp
< 32767))
2493 if (exp
> (EMULONG
) (-NBITS
- 1))
2506 /* Round off, unless told not to by rcntrl. */
2509 /* Set up rounding parameters if the control register changed. */
2510 if (rndprc
!= rlast
)
2517 rw
= NI
- 1; /* low guard word */
2540 /* For DEC or IBM arithmetic */
2557 /* For C4x arithmetic */
2578 /* Shift down 1 temporarily if the data structure has an implied
2579 most significant bit and the number is denormal.
2580 Intel long double denormals also lose one bit of precision. */
2581 if ((exp
<= 0) && (rndprc
!= NBITS
)
2582 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2584 lost
|= s
[NI
- 1] & 1;
2587 /* Clear out all bits below the rounding bit,
2588 remembering in r if any were nonzero. */
2602 if ((r
& rmbit
) != 0)
2608 { /* round to even */
2609 if ((s
[re
] & rebit
) == 0)
2622 /* Undo the temporary shift for denormal values. */
2623 if ((exp
<= 0) && (rndprc
!= NBITS
)
2624 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2629 { /* overflow on roundoff */
2642 for (i
= 2; i
< NI
- 1; i
++)
2645 warning ("floating point overflow");
2649 for (i
= M
+ 1; i
< NI
- 1; i
++)
2652 if ((rndprc
< 64) || (rndprc
== 113))
2667 s
[1] = (UEMUSHORT
) exp
;
2670 /* Subtract. C = B - A, all e type numbers. */
2672 static int subflg
= 0;
2676 const UEMUSHORT
*a
, *b
;
2691 /* Infinity minus infinity is a NaN.
2692 Test for subtracting infinities of the same sign. */
2693 if (eisinf (a
) && eisinf (b
)
2694 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2696 mtherr ("esub", INVALID
);
2705 /* Add. C = A + B, all e type. */
2709 const UEMUSHORT
*a
, *b
;
2714 /* NaN plus anything is a NaN. */
2725 /* Infinity minus infinity is a NaN.
2726 Test for adding infinities of opposite signs. */
2727 if (eisinf (a
) && eisinf (b
)
2728 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2730 mtherr ("esub", INVALID
);
2739 /* Arithmetic common to both addition and subtraction. */
2743 const UEMUSHORT
*a
, *b
;
2746 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2748 EMULONG lt
, lta
, ltb
;
2769 /* compare exponents */
2774 { /* put the larger number in bi */
2784 if (lt
< (EMULONG
) (-NBITS
- 1))
2785 goto done
; /* answer same as larger addend */
2787 lost
= eshift (ai
, k
); /* shift the smaller number down */
2791 /* exponents were the same, so must compare significands */
2794 { /* the numbers are identical in magnitude */
2795 /* if different signs, result is zero */
2801 /* if same sign, result is double */
2802 /* double denormalized tiny number */
2803 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2808 /* add 1 to exponent unless both are zero! */
2809 for (j
= 1; j
< NI
- 1; j
++)
2825 bi
[E
] = (UEMUSHORT
) ltb
;
2829 { /* put the larger number in bi */
2845 emdnorm (bi
, lost
, subflg
, ltb
, !ROUND_TOWARDS_ZERO
);
2851 /* Divide: C = B/A, all e type. */
2855 const UEMUSHORT
*a
, *b
;
2858 UEMUSHORT ai
[NI
], bi
[NI
];
2860 EMULONG lt
, lta
, ltb
;
2862 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2863 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2864 sign
= eisneg (a
) ^ eisneg (b
);
2867 /* Return any NaN input. */
2878 /* Zero over zero, or infinity over infinity, is a NaN. */
2879 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2880 || (eisinf (a
) && eisinf (b
)))
2882 mtherr ("ediv", INVALID
);
2887 /* Infinity over anything else is infinity. */
2894 /* Anything else over infinity is zero. */
2906 { /* See if numerator is zero. */
2907 for (i
= 1; i
< NI
- 1; i
++)
2911 ltb
-= enormlz (bi
);
2921 { /* possible divide by zero */
2922 for (i
= 1; i
< NI
- 1; i
++)
2926 lta
-= enormlz (ai
);
2930 /* Divide by zero is not an invalid operation.
2931 It is a divide-by-zero operation! */
2933 mtherr ("ediv", SING
);
2939 /* calculate exponent */
2940 lt
= ltb
- lta
+ EXONE
;
2941 emdnorm (bi
, i
, 0, lt
, !ROUND_TOWARDS_ZERO
);
2948 && (ecmp (c
, ezero
) != 0)
2951 *(c
+(NE
-1)) |= 0x8000;
2953 *(c
+(NE
-1)) &= ~0x8000;
2956 /* Multiply e-types A and B, return e-type product C. */
2960 const UEMUSHORT
*a
, *b
;
2963 UEMUSHORT ai
[NI
], bi
[NI
];
2965 EMULONG lt
, lta
, ltb
;
2967 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2968 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2969 sign
= eisneg (a
) ^ eisneg (b
);
2972 /* NaN times anything is the same NaN. */
2983 /* Zero times infinity is a NaN. */
2984 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2985 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2987 mtherr ("emul", INVALID
);
2992 /* Infinity times anything else is infinity. */
2994 if (eisinf (a
) || eisinf (b
))
3006 for (i
= 1; i
< NI
- 1; i
++)
3010 lta
-= enormlz (ai
);
3021 for (i
= 1; i
< NI
- 1; i
++)
3025 ltb
-= enormlz (bi
);
3034 /* Multiply significands */
3036 /* calculate exponent */
3037 lt
= lta
+ ltb
- (EXONE
- 1);
3038 emdnorm (bi
, j
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3045 && (ecmp (c
, ezero
) != 0)
3048 *(c
+(NE
-1)) |= 0x8000;
3050 *(c
+(NE
-1)) &= ~0x8000;
3053 /* Convert double precision PE to e-type Y. */
3057 const UEMUSHORT
*pe
;
3067 ibmtoe (pe
, y
, DFmode
);
3072 c4xtoe (pe
, y
, HFmode
);
3082 denorm
= 0; /* flag if denormalized number */
3084 if (! REAL_WORDS_BIG_ENDIAN
)
3090 yy
[M
] = (r
& 0x0f) | 0x10;
3091 r
&= ~0x800f; /* strip sign and 4 significand bits */
3096 if (! REAL_WORDS_BIG_ENDIAN
)
3098 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3099 || (pe
[1] != 0) || (pe
[0] != 0))
3101 enan (y
, yy
[0] != 0);
3107 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3108 || (pe
[2] != 0) || (pe
[3] != 0))
3110 enan (y
, yy
[0] != 0);
3121 #endif /* INFINITY */
3123 /* If zero exponent, then the significand is denormalized.
3124 So take back the understood high significand bit. */
3135 if (! REAL_WORDS_BIG_ENDIAN
)
3152 /* If zero exponent, then normalize the significand. */
3153 if ((k
= enormlz (yy
)) > NBITS
)
3156 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3159 #endif /* not C4X */
3160 #endif /* not IBM */
3161 #endif /* not DEC */
3164 /* Convert double extended precision float PE to e type Y. */
3168 const UEMUSHORT
*pe
;
3178 for (i
= 0; i
< NE
- 5; i
++)
3180 /* This precision is not ordinarily supported on DEC or IBM. */
3182 for (i
= 0; i
< 5; i
++)
3186 p
= &yy
[0] + (NE
- 1);
3189 for (i
= 0; i
< 5; i
++)
3193 if (! REAL_WORDS_BIG_ENDIAN
)
3195 for (i
= 0; i
< 5; i
++)
3198 /* For denormal long double Intel format, shift significand up one
3199 -- but only if the top significand bit is zero. A top bit of 1
3200 is "pseudodenormal" when the exponent is zero. */
3201 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3213 p
= &yy
[0] + (NE
- 1);
3214 #ifdef ARM_EXTENDED_IEEE_FORMAT
3215 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3216 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3222 for (i
= 0; i
< 4; i
++)
3227 /* Point to the exponent field and check max exponent cases. */
3229 if ((*p
& 0x7fff) == 0x7fff)
3232 if (! REAL_WORDS_BIG_ENDIAN
)
3234 for (i
= 0; i
< 4; i
++)
3236 if ((i
!= 3 && pe
[i
] != 0)
3237 /* Anything but 0x8000 here, including 0, is a NaN. */
3238 || (i
== 3 && pe
[i
] != 0x8000))
3240 enan (y
, (*p
& 0x8000) != 0);
3247 #ifdef ARM_EXTENDED_IEEE_FORMAT
3248 for (i
= 2; i
<= 5; i
++)
3252 enan (y
, (*p
& 0x8000) != 0);
3257 /* In Motorola extended precision format, the most significant
3258 bit of an infinity mantissa could be either 1 or 0. It is
3259 the lower order bits that tell whether the value is a NaN. */
3260 if ((pe
[2] & 0x7fff) != 0)
3263 for (i
= 3; i
<= 5; i
++)
3268 enan (y
, (*p
& 0x8000) != 0);
3272 #endif /* not ARM */
3281 #endif /* INFINITY */
3284 for (i
= 0; i
< NE
; i
++)
3288 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3289 /* Convert 128-bit long double precision float PE to e type Y. */
3293 const UEMUSHORT
*pe
;
3306 if (! REAL_WORDS_BIG_ENDIAN
)
3318 if (! REAL_WORDS_BIG_ENDIAN
)
3320 for (i
= 0; i
< 7; i
++)
3324 enan (y
, yy
[0] != 0);
3331 for (i
= 1; i
< 8; i
++)
3335 enan (y
, yy
[0] != 0);
3347 #endif /* INFINITY */
3351 if (! REAL_WORDS_BIG_ENDIAN
)
3353 for (i
= 0; i
< 7; i
++)
3359 for (i
= 0; i
< 7; i
++)
3363 /* If denormal, remove the implied bit; else shift down 1. */
3377 /* Convert single precision float PE to e type Y. */
3381 const UEMUSHORT
*pe
;
3386 ibmtoe (pe
, y
, SFmode
);
3392 c4xtoe (pe
, y
, QFmode
);
3403 denorm
= 0; /* flag if denormalized number */
3406 if (! REAL_WORDS_BIG_ENDIAN
)
3416 yy
[M
] = (r
& 0x7f) | 0200;
3417 r
&= ~0x807f; /* strip sign and 7 significand bits */
3419 if (!LARGEST_EXPONENT_IS_NORMAL (32) && r
== 0x7f80)
3422 if (REAL_WORDS_BIG_ENDIAN
)
3424 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3426 enan (y
, yy
[0] != 0);
3432 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3434 enan (y
, yy
[0] != 0);
3445 #endif /* INFINITY */
3447 /* If zero exponent, then the significand is denormalized.
3448 So take back the understood high significand bit. */
3461 if (! REAL_WORDS_BIG_ENDIAN
)
3471 { /* if zero exponent, then normalize the significand */
3472 if ((k
= enormlz (yy
)) > NBITS
)
3475 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3478 #endif /* not C4X */
3479 #endif /* not IBM */
3482 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3483 /* Convert e-type X to IEEE 128-bit long double format E. */
3497 make_nan (e
, eisneg (x
), TFmode
);
3502 exp
= (EMULONG
) xi
[E
];
3507 /* round off to nearest or even */
3510 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3518 /* Convert exploded e-type X, that has already been rounded to
3519 113-bit precision, to IEEE 128-bit long double format Y. */
3531 make_nan (b
, eiisneg (a
), TFmode
);
3536 if (REAL_WORDS_BIG_ENDIAN
)
3539 q
= b
+ 7; /* point to output exponent */
3541 /* If not denormal, delete the implied bit. */
3546 /* combine sign and exponent */
3548 if (REAL_WORDS_BIG_ENDIAN
)
3551 *q
++ = *p
++ | 0x8000;
3558 *q
-- = *p
++ | 0x8000;
3562 /* skip over guard word */
3564 /* move the significand */
3565 if (REAL_WORDS_BIG_ENDIAN
)
3567 for (i
= 0; i
< 7; i
++)
3572 for (i
= 0; i
< 7; i
++)
3578 /* Convert e-type X to IEEE double extended format E. */
3592 make_nan (e
, eisneg (x
), XFmode
);
3597 /* adjust exponent for offset */
3598 exp
= (EMULONG
) xi
[E
];
3603 /* round off to nearest or even */
3606 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3614 /* Convert exploded e-type X, that has already been rounded to
3615 64-bit precision, to IEEE double extended format Y. */
3627 make_nan (b
, eiisneg (a
), XFmode
);
3631 /* Shift denormal long double Intel format significand down one bit. */
3632 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3642 if (REAL_WORDS_BIG_ENDIAN
)
3646 q
= b
+ 4; /* point to output exponent */
3647 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3648 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3649 always there, and there are never more bytes, even when we are using
3650 INTEL_EXTENDED_IEEE_FORMAT. */
3655 /* combine sign and exponent */
3659 *q
++ = *p
++ | 0x8000;
3666 *q
-- = *p
++ | 0x8000;
3671 if (REAL_WORDS_BIG_ENDIAN
)
3673 #ifdef ARM_EXTENDED_IEEE_FORMAT
3674 /* The exponent is in the lowest 15 bits of the first word. */
3675 *q
++ = i
? 0x8000 : 0;
3679 *q
++ = *p
++ | 0x8000;
3688 *q
-- = *p
++ | 0x8000;
3693 /* skip over guard word */
3695 /* move the significand */
3697 for (i
= 0; i
< 4; i
++)
3701 for (i
= 0; i
< 4; i
++)
3705 if (REAL_WORDS_BIG_ENDIAN
)
3707 for (i
= 0; i
< 4; i
++)
3715 /* Intel long double infinity significand. */
3723 for (i
= 0; i
< 4; i
++)
3729 /* e type to double precision. */
3732 /* Convert e-type X to DEC-format double E. */
3739 etodec (x
, e
); /* see etodec.c */
3742 /* Convert exploded e-type X, that has already been rounded to
3743 56-bit double precision, to DEC double Y. */
3754 /* Convert e-type X to IBM 370-format double E. */
3761 etoibm (x
, e
, DFmode
);
3764 /* Convert exploded e-type X, that has already been rounded to
3765 56-bit precision, to IBM 370 double Y. */
3771 toibm (x
, y
, DFmode
);
3774 #else /* it's neither DEC nor IBM */
3776 /* Convert e-type X to C4X-format long double E. */
3783 etoc4x (x
, e
, HFmode
);
3786 /* Convert exploded e-type X, that has already been rounded to
3787 56-bit precision, to IBM 370 double Y. */
3793 toc4x (x
, y
, HFmode
);
3796 #else /* it's neither DEC nor IBM nor C4X */
3798 /* Convert e-type X to IEEE double E. */
3812 make_nan (e
, eisneg (x
), DFmode
);
3817 /* adjust exponent for offsets */
3818 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3823 /* round off to nearest or even */
3826 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3834 /* Convert exploded e-type X, that has already been rounded to
3835 53-bit precision, to IEEE double Y. */
3847 make_nan (y
, eiisneg (x
), DFmode
);
3851 if (LARGEST_EXPONENT_IS_NORMAL (64) && x
[1] > 2047)
3853 saturate (y
, eiisneg (x
), 64, 1);
3858 if (! REAL_WORDS_BIG_ENDIAN
)
3861 *y
= 0; /* output high order */
3863 *y
= 0x8000; /* output sign bit */
3866 if (i
>= (unsigned int) 2047)
3868 /* Saturate at largest number less than infinity. */
3871 if (! REAL_WORDS_BIG_ENDIAN
)
3885 *y
|= (UEMUSHORT
) 0x7fef;
3886 if (! REAL_WORDS_BIG_ENDIAN
)
3911 i
|= *p
++ & (UEMUSHORT
) 0x0f; /* *p = xi[M] */
3912 *y
|= (UEMUSHORT
) i
; /* high order output already has sign bit set */
3913 if (! REAL_WORDS_BIG_ENDIAN
)
3928 #endif /* not C4X */
3929 #endif /* not IBM */
3930 #endif /* not DEC */
3934 /* e type to single precision. */
3937 /* Convert e-type X to IBM 370 float E. */
3944 etoibm (x
, e
, SFmode
);
3947 /* Convert exploded e-type X, that has already been rounded to
3948 float precision, to IBM 370 float Y. */
3954 toibm (x
, y
, SFmode
);
3960 /* Convert e-type X to C4X float E. */
3967 etoc4x (x
, e
, QFmode
);
3970 /* Convert exploded e-type X, that has already been rounded to
3971 float precision, to IBM 370 float Y. */
3977 toc4x (x
, y
, QFmode
);
3982 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3996 make_nan (e
, eisneg (x
), SFmode
);
4001 /* adjust exponent for offsets */
4002 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
4007 /* round off to nearest or even */
4010 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
4018 /* Convert exploded e-type X, that has already been rounded to
4019 float precision, to IEEE float Y. */
4031 make_nan (y
, eiisneg (x
), SFmode
);
4035 if (LARGEST_EXPONENT_IS_NORMAL (32) && x
[1] > 255)
4037 saturate (y
, eiisneg (x
), 32, 1);
4042 if (! REAL_WORDS_BIG_ENDIAN
)
4048 *y
= 0; /* output high order */
4050 *y
= 0x8000; /* output sign bit */
4053 /* Handle overflow cases. */
4054 if (!LARGEST_EXPONENT_IS_NORMAL (32) && i
>= 255)
4057 *y
|= (UEMUSHORT
) 0x7f80;
4062 if (! REAL_WORDS_BIG_ENDIAN
)
4070 #else /* no INFINITY */
4071 *y
|= (UEMUSHORT
) 0x7f7f;
4076 if (! REAL_WORDS_BIG_ENDIAN
)
4087 #endif /* no INFINITY */
4099 i
|= *p
++ & (UEMUSHORT
) 0x7f; /* *p = xi[M] */
4100 /* High order output already has sign bit set. */
4106 if (! REAL_WORDS_BIG_ENDIAN
)
4115 #endif /* not C4X */
4116 #endif /* not IBM */
4118 /* Compare two e type numbers.
4122 -2 if either a or b is a NaN. */
4126 const UEMUSHORT
*a
, *b
;
4128 UEMUSHORT ai
[NI
], bi
[NI
];
4134 if (eisnan (a
) || eisnan (b
))
4143 { /* the signs are different */
4145 for (i
= 1; i
< NI
- 1; i
++)
4159 /* both are the same sign */
4174 return (0); /* equality */
4178 if (*(--p
) > *(--q
))
4179 return (msign
); /* p is bigger */
4181 return (-msign
); /* p is littler */
4185 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4197 /* Convert HOST_WIDE_INT LP to e type Y. */
4201 const HOST_WIDE_INT
*lp
;
4205 unsigned HOST_WIDE_INT ll
;
4211 /* make it positive */
4212 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4213 yi
[0] = 0xffff; /* put correct sign in the e type number */
4217 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4219 /* move the long integer to yi significand area */
4220 #if HOST_BITS_PER_WIDE_INT == 64
4221 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4222 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4223 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4224 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4225 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4227 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4228 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4229 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4232 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4233 ecleaz (yi
); /* it was zero */
4235 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4236 emovo (yi
, y
); /* output the answer */
4239 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4243 const unsigned HOST_WIDE_INT
*lp
;
4247 unsigned HOST_WIDE_INT ll
;
4253 /* move the long integer to ayi significand area */
4254 #if HOST_BITS_PER_WIDE_INT == 64
4255 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4256 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4257 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4258 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4259 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4261 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4262 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4263 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4266 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4267 ecleaz (yi
); /* it was zero */
4269 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4270 emovo (yi
, y
); /* output the answer */
4274 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4275 part FRAC of e-type (packed internal format) floating point input X.
4276 The integer output I has the sign of the input, except that
4277 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4278 The output e-type fraction FRAC is the positive fractional
4289 unsigned HOST_WIDE_INT ll
;
4292 k
= (int) xi
[E
] - (EXONE
- 1);
4295 /* if exponent <= 0, integer = 0 and real output is fraction */
4300 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4302 /* long integer overflow: output large integer
4303 and correct fraction */
4305 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4308 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4309 /* In this case, let it overflow and convert as if unsigned. */
4310 euifrac (x
, &ll
, frac
);
4311 *i
= (HOST_WIDE_INT
) ll
;
4314 /* In other cases, return the largest positive integer. */
4315 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4320 warning ("overflow on truncation to integer");
4324 /* Shift more than 16 bits: first shift up k-16 mod 16,
4325 then shift up by 16's. */
4326 j
= k
- ((k
>> 4) << 4);
4333 ll
= (ll
<< 16) | xi
[M
];
4335 while ((k
-= 16) > 0);
4342 /* shift not more than 16 bits */
4344 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4351 if ((k
= enormlz (xi
)) > NBITS
)
4354 xi
[E
] -= (UEMUSHORT
) k
;
4360 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4361 FRAC of e-type X. A negative input yields integer output = 0 but
4362 correct fraction. */
4365 euifrac (x
, i
, frac
)
4367 unsigned HOST_WIDE_INT
*i
;
4370 unsigned HOST_WIDE_INT ll
;
4375 k
= (int) xi
[E
] - (EXONE
- 1);
4378 /* if exponent <= 0, integer = 0 and argument is fraction */
4383 if (k
> HOST_BITS_PER_WIDE_INT
)
4385 /* Long integer overflow: output large integer
4386 and correct fraction.
4387 Note, the BSD MicroVAX compiler says that ~(0UL)
4388 is a syntax error. */
4392 warning ("overflow on truncation to unsigned integer");
4396 /* Shift more than 16 bits: first shift up k-16 mod 16,
4397 then shift up by 16's. */
4398 j
= k
- ((k
>> 4) << 4);
4405 ll
= (ll
<< 16) | xi
[M
];
4407 while ((k
-= 16) > 0);
4412 /* shift not more than 16 bits */
4414 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4417 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4423 if ((k
= enormlz (xi
)) > NBITS
)
4426 xi
[E
] -= (UEMUSHORT
) k
;
4431 /* Shift the significand of exploded e-type X up or down by SC bits. */
4452 lost
|= *p
; /* remember lost bits */
4493 return ((int) lost
);
4496 /* Shift normalize the significand area of exploded e-type X.
4497 Return the shift count (up = positive). */
4512 return (0); /* already normalized */
4518 /* With guard word, there are NBITS+16 bits available.
4519 Return true if all are zero. */
4523 /* see if high byte is zero */
4524 while ((*p
& 0xff00) == 0)
4529 /* now shift 1 bit at a time */
4530 while ((*p
& 0x8000) == 0)
4536 mtherr ("enormlz", UNDERFLOW
);
4542 /* Normalize by shifting down out of the high guard word
4543 of the significand */
4558 mtherr ("enormlz", OVERFLOW
);
4565 /* Powers of ten used in decimal <-> binary conversions. */
4570 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4571 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4573 {0x6576, 0x4a92, 0x804a, 0x153f,
4574 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4575 {0x6a32, 0xce52, 0x329a, 0x28ce,
4576 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4577 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4578 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4579 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4580 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4581 {0x851e, 0xeab7, 0x98fe, 0x901b,
4582 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4583 {0x0235, 0x0137, 0x36b1, 0x336c,
4584 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4585 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4586 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4587 {0x0000, 0x0000, 0x0000, 0x0000,
4588 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4589 {0x0000, 0x0000, 0x0000, 0x0000,
4590 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4591 {0x0000, 0x0000, 0x0000, 0x0000,
4592 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4593 {0x0000, 0x0000, 0x0000, 0x0000,
4594 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4595 {0x0000, 0x0000, 0x0000, 0x0000,
4596 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4597 {0x0000, 0x0000, 0x0000, 0x0000,
4598 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4601 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4603 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4604 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4605 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4606 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4607 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4608 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4609 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4610 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4611 {0xa23e, 0x5308, 0xfefb, 0x1155,
4612 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4613 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4614 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4615 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4616 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4617 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4618 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4619 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4620 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4621 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4622 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4623 {0xc155, 0xa4a8, 0x404e, 0x6113,
4624 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4625 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4626 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4627 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4628 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4631 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4632 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4634 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4635 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4636 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4637 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4638 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4639 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4640 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4641 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4642 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4643 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4644 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4645 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4646 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4649 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4651 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4652 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4653 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4654 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4655 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4656 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4657 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4658 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4659 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4660 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4661 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4662 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4663 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4668 /* Convert float value X to ASCII string STRING with NDIG digits after
4669 the decimal point. */
4672 e24toasc (x
, string
, ndigs
)
4673 const UEMUSHORT x
[];
4680 etoasc (w
, string
, ndigs
);
4683 /* Convert double value X to ASCII string STRING with NDIG digits after
4684 the decimal point. */
4687 e53toasc (x
, string
, ndigs
)
4688 const UEMUSHORT x
[];
4695 etoasc (w
, string
, ndigs
);
4698 /* Convert double extended value X to ASCII string STRING with NDIG digits
4699 after the decimal point. */
4702 e64toasc (x
, string
, ndigs
)
4703 const UEMUSHORT x
[];
4710 etoasc (w
, string
, ndigs
);
4713 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4714 after the decimal point. */
4717 e113toasc (x
, string
, ndigs
)
4718 const UEMUSHORT x
[];
4725 etoasc (w
, string
, ndigs
);
4729 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4730 the decimal point. */
4732 static char wstring
[80]; /* working storage for ASCII output */
4735 etoasc (x
, string
, ndigs
)
4736 const UEMUSHORT x
[];
4741 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4742 const UEMUSHORT
*p
, *r
, *ten
;
4744 int i
, j
, k
, expon
, rndsav
;
4757 sprintf (wstring
, " NaN ");
4761 rndprc
= NBITS
; /* set to full precision */
4762 emov (x
, y
); /* retain external format */
4763 if (y
[NE
- 1] & 0x8000)
4766 y
[NE
- 1] &= 0x7fff;
4773 ten
= &etens
[NTEN
][0];
4775 /* Test for zero exponent */
4778 for (k
= 0; k
< NE
- 1; k
++)
4781 goto tnzro
; /* denormalized number */
4783 goto isone
; /* valid all zeros */
4787 /* Test for infinity. */
4788 if (y
[NE
- 1] == 0x7fff)
4791 sprintf (wstring
, " -Infinity ");
4793 sprintf (wstring
, " Infinity ");
4797 /* Test for exponent nonzero but significand denormalized.
4798 * This is an error condition.
4800 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4802 mtherr ("etoasc", DOMAIN
);
4803 sprintf (wstring
, "NaN");
4807 /* Compare to 1.0 */
4816 { /* Number is greater than 1 */
4817 /* Convert significand to an integer and strip trailing decimal zeros. */
4819 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4821 p
= &etens
[NTEN
- 4][0];
4827 for (j
= 0; j
< NE
- 1; j
++)
4840 /* Rescale from integer significand */
4841 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4843 /* Find power of 10 */
4847 /* An unordered compare result shouldn't happen here. */
4848 while (ecmp (ten
, u
) <= 0)
4850 if (ecmp (p
, u
) <= 0)
4863 { /* Number is less than 1.0 */
4864 /* Pad significand with trailing decimal zeros. */
4867 while ((y
[NE
- 2] & 0x8000) == 0)
4876 for (i
= 0; i
< NDEC
+ 1; i
++)
4878 if ((w
[NI
- 1] & 0x7) != 0)
4880 /* multiply by 10 */
4893 if (eone
[NE
- 1] <= u
[1])
4905 while (ecmp (eone
, w
) > 0)
4907 if (ecmp (p
, w
) >= 0)
4922 /* Find the first (leading) digit. */
4928 digit
= equot
[NI
- 1];
4929 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4937 digit
= equot
[NI
- 1];
4945 /* Examine number of digits requested by caller. */
4963 *s
++ = (char) digit
+ '0';
4966 /* Generate digits after the decimal point. */
4967 for (k
= 0; k
<= ndigs
; k
++)
4969 /* multiply current number by 10, without normalizing */
4976 *s
++ = (char) equot
[NI
- 1] + '0';
4978 digit
= equot
[NI
- 1];
4981 /* round off the ASCII string */
4984 /* Test for critical rounding case in ASCII output. */
4988 if (ecmp (t
, ezero
) != 0)
4989 goto roun
; /* round to nearest */
4991 if ((*(s
- 1) & 1) == 0)
4992 goto doexp
; /* round to even */
4995 /* Round up and propagate carry-outs */
4999 /* Carry out to most significant digit? */
5006 /* Most significant digit carries to 10? */
5014 /* Round up and carry out from less significant digits */
5024 /* Strip trailing zeros, but leave at least one. */
5025 while (ss
[-1] == '0' && ss
[-2] != '.')
5027 sprintf (ss
, "e%d", expon
);
5030 /* copy out the working string */
5033 while (*ss
== ' ') /* strip possible leading space */
5035 while ((*s
++ = *ss
++) != '\0')
5040 /* Convert ASCII string to floating point.
5042 Numeric input is a free format decimal number of any length, with
5043 or without decimal point. Entering E after the number followed by an
5044 integer number causes the second number to be interpreted as a power of
5045 10 to be multiplied by the first number (i.e., "scientific" notation). */
5047 /* Convert ASCII string S to single precision float value Y. */
5058 /* Convert ASCII string S to double precision value Y. */
5065 #if defined(DEC) || defined(IBM)
5077 /* Convert ASCII string S to double extended value Y. */
5087 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5088 /* Convert ASCII string S to 128-bit long double Y. */
5095 asctoeg (s
, y
, 113);
5099 /* Convert ASCII string S to e type Y. */
5106 asctoeg (s
, y
, NBITS
);
5109 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5110 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
5113 asctoeg (ss
, y
, oprec
)
5118 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5119 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5120 int i
, k
, trail
, c
, rndsav
;
5123 char *sp
, *s
, *lstr
;
5126 /* Copy the input string. */
5127 lstr
= (char *) alloca (strlen (ss
) + 1);
5129 while (*ss
== ' ') /* skip leading spaces */
5133 while ((*sp
++ = *ss
++) != '\0')
5137 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5144 rndprc
= NBITS
; /* Set to full precision */
5157 if ((k
>= 0) && (k
< base
))
5159 /* Ignore leading zeros */
5160 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5162 /* Identify and strip trailing zeros after the decimal point. */
5163 if ((trail
== 0) && (decflg
!= 0))
5166 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
5168 /* Check for syntax error */
5170 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5171 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5173 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5175 goto unexpected_char_error
;
5184 /* If enough digits were given to more than fill up the yy register,
5185 continuing until overflow into the high guard word yy[2]
5186 guarantees that there will be a roundoff bit at the top
5187 of the low guard word after normalization. */
5194 nexp
+= 4; /* count digits after decimal point */
5196 eshup1 (yy
); /* multiply current number by 16 */
5204 nexp
+= 1; /* count digits after decimal point */
5206 eshup1 (yy
); /* multiply current number by 10 */
5212 /* Insert the current digit. */
5214 xt
[NI
- 2] = (UEMUSHORT
) k
;
5219 /* Mark any lost non-zero digit. */
5221 /* Count lost digits before the decimal point. */
5243 case '.': /* decimal point */
5245 goto unexpected_char_error
;
5251 goto unexpected_char_error
;
5256 goto unexpected_char_error
;
5269 unexpected_char_error
:
5273 mtherr ("asctoe", DOMAIN
);
5282 /* Exponent interpretation */
5284 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5285 for (k
= 0; k
< NI
; k
++)
5296 /* check for + or - */
5304 while (ISDIGIT (*s
))
5313 if ((exp
> MAXDECEXP
) && (base
== 10))
5317 yy
[E
] = 0x7fff; /* infinity */
5320 if ((exp
< MINDECEXP
) && (base
== 10))
5330 /* Base 16 hexadecimal floating constant. */
5331 if ((k
= enormlz (yy
)) > NBITS
)
5336 /* Adjust the exponent. NEXP is the number of hex digits,
5337 EXP is a power of 2. */
5338 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5348 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5349 while ((nexp
> 0) && (yy
[2] == 0))
5361 if ((k
= enormlz (yy
)) > NBITS
)
5366 lexp
= (EXONE
- 1 + NBITS
) - k
;
5367 emdnorm (yy
, lost
, 0, lexp
, 64);
5370 /* Convert to external format:
5372 Multiply by 10**nexp. If precision is 64 bits,
5373 the maximum relative error incurred in forming 10**n
5374 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5375 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5376 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5391 /* Punt. Can't handle this without 2 divides. */
5392 emovi (etens
[0], tt
);
5405 emul (etens
[i
], xt
, xt
);
5409 while (exp
<= MAXP
);
5428 /* Round and convert directly to the destination type */
5430 lexp
-= EXONE
- 0x3ff;
5432 else if (oprec
== 24 || oprec
== 32)
5433 lexp
-= (EXONE
- 0x7f);
5436 else if (oprec
== 24 || oprec
== 56)
5437 lexp
-= EXONE
- (0x41 << 2);
5439 else if (oprec
== 24)
5440 lexp
-= EXONE
- 0177;
5444 else if (oprec
== 56)
5445 lexp
-= EXONE
- 0201;
5448 emdnorm (yy
, lost
, 0, lexp
, 64);
5458 todec (yy
, y
); /* see etodec.c */
5463 toibm (yy
, y
, DFmode
);
5468 toc4x (yy
, y
, HFmode
);
5481 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5494 /* Return Y = largest integer not greater than X (truncated toward minus
5497 static const UEMUSHORT bmask
[] =
5520 const UEMUSHORT x
[];
5527 emov (x
, f
); /* leave in external format */
5528 expon
= (int) f
[NE
- 1];
5529 e
= (expon
& 0x7fff) - (EXONE
- 1);
5535 /* number of bits to clear out */
5547 /* clear the remaining bits */
5549 /* truncate negatives toward minus infinity */
5552 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5554 for (i
= 0; i
< NE
- 1; i
++)
5567 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5568 For example, 1.1 = 0.55 * 2^1. */
5572 const UEMUSHORT x
[];
5580 /* Handle denormalized numbers properly using long integer exponent. */
5581 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5589 *exp
= (int) (li
- 0x3ffe);
5593 /* Return e type Y = X * 2^PWR2. */
5597 const UEMUSHORT x
[];
5609 emdnorm (xi
, i
, i
, li
, !ROUND_TOWARDS_ZERO
);
5615 /* C = remainder after dividing B by A, all e type values.
5616 Least significant integer quotient bits left in EQUOT. */
5620 const UEMUSHORT a
[], b
[];
5623 UEMUSHORT den
[NI
], num
[NI
];
5627 || (ecmp (a
, ezero
) == 0)
5635 if (ecmp (a
, ezero
) == 0)
5637 mtherr ("eremain", SING
);
5643 eiremain (den
, num
);
5644 /* Sign of remainder = sign of quotient */
5653 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5654 remainder in NUM. */
5658 UEMUSHORT den
[], num
[];
5664 ld
-= enormlz (den
);
5666 ln
-= enormlz (num
);
5670 if (ecmpm (den
, num
) <= 0)
5682 emdnorm (num
, 0, 0, ln
, 0);
5685 /* Report an error condition CODE encountered in function NAME.
5687 Mnemonic Value Significance
5689 DOMAIN 1 argument domain error
5690 SING 2 function singularity
5691 OVERFLOW 3 overflow range error
5692 UNDERFLOW 4 underflow range error
5693 TLOSS 5 total loss of precision
5694 PLOSS 6 partial loss of precision
5695 INVALID 7 NaN - producing operation
5696 EDOM 33 Unix domain error code
5697 ERANGE 34 Unix range error code
5699 The order of appearance of the following messages is bound to the
5700 error codes defined above. */
5710 /* The string passed by the calling program is supposed to be the
5711 name of the function in which the error occurred.
5712 The code argument selects which error message string will be printed. */
5714 if (strcmp (name
, "esub") == 0)
5715 name
= "subtraction";
5716 else if (strcmp (name
, "ediv") == 0)
5718 else if (strcmp (name
, "emul") == 0)
5719 name
= "multiplication";
5720 else if (strcmp (name
, "enormlz") == 0)
5721 name
= "normalization";
5722 else if (strcmp (name
, "etoasc") == 0)
5723 name
= "conversion to text";
5724 else if (strcmp (name
, "asctoe") == 0)
5726 else if (strcmp (name
, "eremain") == 0)
5728 else if (strcmp (name
, "esqrt") == 0)
5729 name
= "square root";
5734 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5735 case SING
: warning ("%s: function singularity" , name
); break;
5736 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5737 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5738 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5739 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5740 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5745 /* Set global error message word */
5750 /* Convert DEC double precision D to e type E. */
5760 ecleaz (y
); /* start with a zero */
5761 p
= y
; /* point to our number */
5762 r
= *d
; /* get DEC exponent word */
5763 if (*d
& (unsigned int) 0x8000)
5764 *p
= 0xffff; /* fill in our sign */
5765 ++p
; /* bump pointer to our exponent word */
5766 r
&= 0x7fff; /* strip the sign bit */
5767 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5771 r
>>= 7; /* shift exponent word down 7 bits */
5772 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5773 /* add our e type exponent offset */
5774 *p
++ = r
; /* to form our exponent */
5776 r
= *d
++; /* now do the high order mantissa */
5777 r
&= 0177; /* strip off the DEC exponent and sign bits */
5778 r
|= 0200; /* the DEC understood high order mantissa bit */
5779 *p
++ = r
; /* put result in our high guard word */
5781 *p
++ = *d
++; /* fill in the rest of our mantissa */
5785 eshdn8 (y
); /* shift our mantissa down 8 bits */
5790 /* Convert e type X to DEC double precision D. */
5802 /* Adjust exponent for offsets. */
5803 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5804 /* Round off to nearest or even. */
5807 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5812 /* Convert exploded e-type X, that has already been rounded to
5813 56-bit precision, to DEC format double Y. */
5859 /* Convert IBM single/double precision to e type. */
5865 enum machine_mode mode
;
5870 ecleaz (y
); /* start with a zero */
5871 p
= y
; /* point to our number */
5872 r
= *d
; /* get IBM exponent word */
5873 if (*d
& (unsigned int) 0x8000)
5874 *p
= 0xffff; /* fill in our sign */
5875 ++p
; /* bump pointer to our exponent word */
5876 r
&= 0x7f00; /* strip the sign bit */
5877 r
>>= 6; /* shift exponent word down 6 bits */
5878 /* in fact shift by 8 right and 2 left */
5879 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5880 /* add our e type exponent offset */
5881 *p
++ = r
; /* to form our exponent */
5883 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5884 /* strip off the IBM exponent and sign bits */
5885 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5887 *p
++ = *d
++; /* fill in the rest of our mantissa */
5892 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5895 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5896 /* handle change in RADIX */
5902 /* Convert e type to IBM single/double precision. */
5908 enum machine_mode mode
;
5915 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5916 /* round off to nearest or even */
5919 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5921 toibm (xi
, d
, mode
);
5927 enum machine_mode mode
;
5980 /* Convert C4X single/double precision to e type. */
5986 enum machine_mode mode
;
6004 /* Short-circuit the zero case. */
6005 if ((dn
[0] == 0x8000)
6006 && (dn
[1] == 0x0000)
6007 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
6018 ecleaz (y
); /* start with a zero */
6019 r
= dn
[0]; /* get sign/exponent part */
6020 if (r
& (unsigned int) 0x0080)
6022 y
[0] = 0xffff; /* fill in our sign */
6028 r
>>= 8; /* Shift exponent word down 8 bits. */
6029 if (r
& 0x80) /* Make the exponent negative if it is. */
6030 r
= r
| (~0 & ~0xff);
6034 /* Now do the high order mantissa. We don't "or" on the high bit
6035 because it is 2 (not 1) and is handled a little differently
6037 y
[M
] = dn
[0] & 0x7f;
6040 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6042 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6050 /* Now do the two's complement on the data. */
6052 carry
= 1; /* Initially add 1 for the two's complement. */
6053 for (i
=size
+ M
; i
> M
; i
--)
6055 if (carry
&& (y
[i
] == 0x0000))
6056 /* We overflowed into the next word, carry is the same. */
6057 y
[i
] = carry
? 0x0000 : 0xffff;
6060 /* No overflow, just invert and add carry. */
6061 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6076 /* Add our e type exponent offset to form our exponent. */
6080 /* Now do the high order mantissa strip off the exponent and sign
6081 bits and add the high 1 bit. */
6082 y
[M
] = (dn
[0] & 0x7f) | 0x80;
6085 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6087 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6097 /* Convert e type to C4X single/double precision. */
6103 enum machine_mode mode
;
6111 /* Adjust exponent for offsets. */
6112 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6114 /* Round off to nearest or even. */
6116 rndprc
= mode
== QFmode
? 24 : 32;
6117 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
6119 toc4x (xi
, d
, mode
);
6125 enum machine_mode mode
;
6131 /* Short-circuit the zero case */
6132 if ((x
[0] == 0) /* Zero exponent and sign */
6134 && (x
[M
] == 0) /* The rest is for zero mantissa */
6136 /* Only check for double if necessary */
6137 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6139 /* We have a zero. Put it into the output and return. */
6152 /* Negative number require a two's complement conversion of the
6158 i
= ((int) x
[1]) - 0x7f;
6160 /* Now add 1 to the inverted data to do the two's complement. */
6169 x
[v
] = carry
? 0x0000 : 0xffff;
6172 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6178 /* The following is a special case. The C4X negative float requires
6179 a zero in the high bit (because the format is (2 - x) x 2^m), so
6180 if a one is in that bit, we have to shift left one to get rid
6181 of it. This only occurs if the number is -1 x 2^m. */
6182 if (x
[M
+1] & 0x8000)
6184 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6185 high sign bit and shift the exponent. */
6191 i
= ((int) x
[1]) - 0x7f;
6193 if ((i
< -128) || (i
> 127))
6201 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6202 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6210 y
[0] |= ((i
& 0xff) << 8);
6214 y
[0] |= x
[M
] & 0x7f;
6220 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6221 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6226 /* Output a binary NaN bit pattern in the target machine's format. */
6228 /* If special NaN bit patterns are required, define them in tm.h
6229 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6235 static const UEMUSHORT TFbignan
[8] =
6236 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6237 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6245 static const UEMUSHORT XFbignan
[6] =
6246 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6247 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6255 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6256 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6264 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6265 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6272 make_nan (nan
, sign
, mode
)
6275 enum machine_mode mode
;
6281 size
= GET_MODE_BITSIZE (mode
);
6282 if (LARGEST_EXPONENT_IS_NORMAL (size
))
6284 warning ("%d-bit floats cannot hold NaNs", size
);
6285 saturate (nan
, sign
, size
, 0);
6290 /* Possibly the `reserved operand' patterns on a VAX can be
6291 used like NaN's, but probably not in the same way as IEEE. */
6292 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6294 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6296 if (REAL_WORDS_BIG_ENDIAN
)
6306 if (REAL_WORDS_BIG_ENDIAN
)
6314 if (REAL_WORDS_BIG_ENDIAN
)
6323 if (REAL_WORDS_BIG_ENDIAN
)
6333 if (REAL_WORDS_BIG_ENDIAN
)
6334 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6337 if (! REAL_WORDS_BIG_ENDIAN
)
6338 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6343 /* Create a saturation value for a SIZE-bit float, assuming that
6344 LARGEST_EXPONENT_IS_NORMAL (SIZE).
6346 If SIGN is true, fill X with the most negative value, otherwise fill
6347 it with the most positive value. WARN is true if the function should
6348 warn about overflow. */
6351 saturate (x
, sign
, size
, warn
)
6353 int sign
, size
, warn
;
6357 if (warn
&& extra_warnings
)
6358 warning ("value exceeds the range of a %d-bit float", size
);
6360 /* Create the most negative value. */
6361 for (i
= 0; i
< size
/ EMUSHORT_SIZE
; i
++)
6364 /* Make it positive, if necessary. */
6366 x
[REAL_WORDS_BIG_ENDIAN
? 0 : i
- 1] = 0x7fff;
6370 /* This is the inverse of the function `etarsingle' invoked by
6371 REAL_VALUE_TO_TARGET_SINGLE. */
6374 ereal_unto_float (f
)
6381 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6382 This is the inverse operation to what the function `endian' does. */
6383 if (REAL_WORDS_BIG_ENDIAN
)
6385 s
[0] = (UEMUSHORT
) (f
>> 16);
6386 s
[1] = (UEMUSHORT
) f
;
6390 s
[0] = (UEMUSHORT
) f
;
6391 s
[1] = (UEMUSHORT
) (f
>> 16);
6393 /* Convert and promote the target float to E-type. */
6395 /* Output E-type to REAL_VALUE_TYPE. */
6401 /* This is the inverse of the function `etardouble' invoked by
6402 REAL_VALUE_TO_TARGET_DOUBLE. */
6405 ereal_unto_double (d
)
6412 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6413 if (REAL_WORDS_BIG_ENDIAN
)
6415 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6416 s
[1] = (UEMUSHORT
) d
[0];
6417 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6418 s
[3] = (UEMUSHORT
) d
[1];
6422 /* Target float words are little-endian. */
6423 s
[0] = (UEMUSHORT
) d
[0];
6424 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6425 s
[2] = (UEMUSHORT
) d
[1];
6426 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6428 /* Convert target double to E-type. */
6430 /* Output E-type to REAL_VALUE_TYPE. */
6436 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6437 This is somewhat like ereal_unto_float, but the input types
6438 for these are different. */
6441 ereal_from_float (f
)
6448 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6449 This is the inverse operation to what the function `endian' does. */
6450 if (REAL_WORDS_BIG_ENDIAN
)
6452 s
[0] = (UEMUSHORT
) (f
>> 16);
6453 s
[1] = (UEMUSHORT
) f
;
6457 s
[0] = (UEMUSHORT
) f
;
6458 s
[1] = (UEMUSHORT
) (f
>> 16);
6460 /* Convert and promote the target float to E-type. */
6462 /* Output E-type to REAL_VALUE_TYPE. */
6468 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6469 This is somewhat like ereal_unto_double, but the input types
6470 for these are different.
6472 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6473 data format, with no holes in the bit packing. The first element
6474 of the input array holds the bits that would come first in the
6475 target computer's memory. */
6478 ereal_from_double (d
)
6485 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6486 if (REAL_WORDS_BIG_ENDIAN
)
6488 #if HOST_BITS_PER_WIDE_INT == 32
6489 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6490 s
[1] = (UEMUSHORT
) d
[0];
6491 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6492 s
[3] = (UEMUSHORT
) d
[1];
6494 /* In this case the entire target double is contained in the
6495 first array element. The second element of the input is
6497 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6498 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6499 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6500 s
[3] = (UEMUSHORT
) d
[0];
6505 /* Target float words are little-endian. */
6506 s
[0] = (UEMUSHORT
) d
[0];
6507 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6508 #if HOST_BITS_PER_WIDE_INT == 32
6509 s
[2] = (UEMUSHORT
) d
[1];
6510 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6512 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6513 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6516 /* Convert target double to E-type. */
6518 /* Output E-type to REAL_VALUE_TYPE. */
6525 /* Convert target computer unsigned 64-bit integer to e-type.
6526 The endian-ness of DImode follows the convention for integers,
6527 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6531 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6538 if (WORDS_BIG_ENDIAN
)
6540 for (k
= M
; k
< M
+ 4; k
++)
6545 for (k
= M
+ 3; k
>= M
; k
--)
6548 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6549 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6550 ecleaz (yi
); /* it was zero */
6552 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6556 /* Convert target computer signed 64-bit integer to e-type. */
6560 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6563 unsigned EMULONG acc
;
6569 if (WORDS_BIG_ENDIAN
)
6571 for (k
= M
; k
< M
+ 4; k
++)
6576 for (k
= M
+ 3; k
>= M
; k
--)
6579 /* Take absolute value */
6585 for (k
= M
+ 3; k
>= M
; k
--)
6587 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6594 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6595 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6596 ecleaz (yi
); /* it was zero */
6598 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6605 /* Convert e-type to unsigned 64-bit int. */
6621 k
= (int) xi
[E
] - (EXONE
- 1);
6624 for (j
= 0; j
< 4; j
++)
6630 for (j
= 0; j
< 4; j
++)
6633 warning ("overflow on truncation to integer");
6638 /* Shift more than 16 bits: first shift up k-16 mod 16,
6639 then shift up by 16's. */
6640 j
= k
- ((k
>> 4) << 4);
6644 if (WORDS_BIG_ENDIAN
)
6655 if (WORDS_BIG_ENDIAN
)
6660 while ((k
-= 16) > 0);
6664 /* shift not more than 16 bits */
6669 if (WORDS_BIG_ENDIAN
)
6688 /* Convert e-type to signed 64-bit int. */
6695 unsigned EMULONG acc
;
6702 k
= (int) xi
[E
] - (EXONE
- 1);
6705 for (j
= 0; j
< 4; j
++)
6711 for (j
= 0; j
< 4; j
++)
6714 warning ("overflow on truncation to integer");
6720 /* Shift more than 16 bits: first shift up k-16 mod 16,
6721 then shift up by 16's. */
6722 j
= k
- ((k
>> 4) << 4);
6726 if (WORDS_BIG_ENDIAN
)
6737 if (WORDS_BIG_ENDIAN
)
6742 while ((k
-= 16) > 0);
6746 /* shift not more than 16 bits */
6749 if (WORDS_BIG_ENDIAN
)
6765 /* Negate if negative */
6769 if (WORDS_BIG_ENDIAN
)
6771 for (k
= 0; k
< 4; k
++)
6773 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6774 if (WORDS_BIG_ENDIAN
)
6786 /* Longhand square root routine. */
6789 static int esqinited
= 0;
6790 static unsigned short sqrndbit
[NI
];
6797 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6799 int i
, j
, k
, n
, nlups
;
6804 sqrndbit
[NI
- 2] = 1;
6807 /* Check for arg <= 0 */
6808 i
= ecmp (x
, ezero
);
6813 mtherr ("esqrt", DOMAIN
);
6829 /* Bring in the arg and renormalize if it is denormal. */
6831 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6835 /* Divide exponent by 2 */
6837 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6839 /* Adjust if exponent odd */
6849 n
= 8; /* get 8 bits of result per inner loop */
6855 /* bring in next word of arg */
6857 num
[NI
- 1] = xx
[j
+ 3];
6858 /* Do additional bit on last outer loop, for roundoff. */
6861 for (i
= 0; i
< n
; i
++)
6863 /* Next 2 bits of arg */
6866 /* Shift up answer */
6868 /* Make trial divisor */
6869 for (k
= 0; k
< NI
; k
++)
6872 eaddm (sqrndbit
, temp
);
6873 /* Subtract and insert answer bit if it goes in */
6874 if (ecmpm (temp
, num
) <= 0)
6884 /* Adjust for extra, roundoff loop done. */
6885 exp
+= (NBITS
- 1) - rndprc
;
6887 /* Sticky bit = 1 if the remainder is nonzero. */
6889 for (i
= 3; i
< NI
; i
++)
6892 /* Renormalize and round off. */
6893 emdnorm (sq
, k
, 0, exp
, !ROUND_TOWARDS_ZERO
);
6898 /* Return the binary precision of the significand for a given
6899 floating point mode. The mode can hold an integer value
6900 that many bits wide, without losing any bits. */
6903 significand_size (mode
)
6904 enum machine_mode mode
;
6907 /* Don't test the modes, but their sizes, lest this
6908 code won't work for BITS_PER_UNIT != 8 . */
6910 switch (GET_MODE_BITSIZE (mode
))
6914 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6921 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6924 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6927 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6930 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6943 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)