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 /* Make sure that the endianness is correct for IBM and DEC. */
134 #undef LARGEST_EXPONENT_IS_NORMAL
135 #define LARGEST_EXPONENT_IS_NORMAL(x) 1
136 #undef REAL_WORDS_BIG_ENDIAN
137 /* Strangely enough, DEC float most closely resembles big endian IEEE */
138 #define REAL_WORDS_BIG_ENDIAN 1
139 /* ... but the halfwords are reversed from IEEE big endian. */
140 #ifndef VAX_HALFWORD_ORDER
141 #define VAX_HALFWORD_ORDER 1
145 #if !REAL_WORDS_BIG_ENDIAN
146 #error "Little-endian representations are not supported for IBM."
151 #if defined(DEC) && !defined (TARGET_G_FLOAT)
152 #define TARGET_G_FLOAT 0
155 #ifndef VAX_HALFWORD_ORDER
156 #define VAX_HALFWORD_ORDER 0
159 /* Define INFINITY for support of infinity.
160 Define NANS for support of Not-a-Number's (NaN's). */
161 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
166 /* Support of NaNs requires support of infinity. */
173 /* Find a host integer type that is at least 16 bits wide,
174 and another type at least twice whatever that size is. */
176 #if HOST_BITS_PER_CHAR >= 16
177 #define EMUSHORT char
178 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
179 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
181 #if HOST_BITS_PER_SHORT >= 16
182 #define EMUSHORT short
183 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
184 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
186 #if HOST_BITS_PER_INT >= 16
188 #define EMUSHORT_SIZE HOST_BITS_PER_INT
189 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
191 #if HOST_BITS_PER_LONG >= 16
192 #define EMUSHORT long
193 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
194 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
196 #error "You will have to modify this program to have a smaller unit size."
202 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
203 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
204 typedef int HItype
__attribute__ ((mode (HI
)));
205 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
209 #define EMUSHORT HItype
210 #define UEMUSHORT UHItype
211 #define EMUSHORT_SIZE 16
212 #define EMULONG_SIZE 32
214 #define UEMUSHORT unsigned EMUSHORT
217 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
218 #define EMULONG short
220 #if HOST_BITS_PER_INT >= EMULONG_SIZE
223 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
226 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
227 #define EMULONG long long int
229 #error "You will have to modify this program to have a smaller unit size."
235 #if EMUSHORT_SIZE != 16
236 #error "The host interface doesn't work if no 16-bit size exists."
239 /* Calculate the size of the generic "e" type. This always has
240 identical in-memory size to REAL_VALUE_TYPE. The sizes are supposed
241 to be the same as well, but when REAL_VALUE_TYPE_SIZE is not evenly
242 divisible by HOST_BITS_PER_WIDE_INT we have some padding in
244 There are only two supported sizes: ten and six 16-bit words (160
247 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
250 # define MAXDECEXP 4932
251 # define MINDECEXP -4977
254 # define MAXDECEXP 4932
255 # define MINDECEXP -4956
258 /* Fail compilation if 2*NE is not the appropriate size.
259 If HOST_BITS_PER_WIDE_INT is 64, we're going to have padding
260 at the end of the array, because neither 96 nor 160 is
261 evenly divisible by 64. */
262 struct compile_test_dummy
{
263 char twice_NE_must_equal_sizeof_REAL_VALUE_TYPE
264 [(sizeof (REAL_VALUE_TYPE
) >= 2*NE
) ? 1 : -1];
267 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
268 In GET_REAL and PUT_REAL, r and e are pointers.
269 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
270 in memory, with no holes. */
271 #define GET_REAL(r, e) memcpy ((e), (r), 2*NE)
272 #define PUT_REAL(e, r) \
274 memcpy (r, e, 2*NE); \
275 if (2*NE < sizeof (*r)) \
276 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
279 /* Number of 16 bit words in internal format */
282 /* Array offset to exponent */
285 /* Array offset to high guard word */
288 /* Number of bits of precision */
289 #define NBITS ((NI-4)*16)
291 /* Maximum number of decimal digits in ASCII conversion
294 #define NDEC (NBITS*8/27)
296 /* The exponent of 1.0 */
297 #define EXONE (0x3fff)
299 #if defined(HOST_EBCDIC)
300 /* bit 8 is significant in EBCDIC */
301 #define CHARMASK 0xff
303 #define CHARMASK 0x7f
306 /* Information about the various IEEE precisions. At the moment, we only
307 support exponents of 15 bits or less. */
313 /* Size of the exponent in bits. */
316 /* Overall size of the value in bits. */
319 /* Mode used for representing the value. */
320 enum machine_mode mode
;
322 /* Exponent adjustment for offsets. */
327 /* IEEE float (24 bits). */
328 static const struct ieee_format ieee_24
=
337 /* IEEE double (53 bits). */
338 static const struct ieee_format ieee_53
=
349 /* IEEE extended double (64 bits). */
350 static const struct ieee_format ieee_64
=
359 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
360 /* IEEE long double (113 bits). */
361 static const struct ieee_format ieee_113
=
369 #endif /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
372 /* DEC F float (24 bits). */
373 static const struct ieee_format dec_f
=
382 /* DEC D float (56 bits). */
383 static const struct ieee_format dec_d
=
392 /* DEC G float (53 bits). */
393 static const struct ieee_format dec_g
=
403 /* DEC H float (113 bits). (not yet used) */
404 static const struct ieee_format dec_h
=
415 extern int extra_warnings
;
416 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
417 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
419 static void endian
PARAMS ((const UEMUSHORT
*, long *,
421 static void eclear
PARAMS ((UEMUSHORT
*));
422 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
424 static void eabs
PARAMS ((UEMUSHORT
*));
426 static void eneg
PARAMS ((UEMUSHORT
*));
427 static int eisneg
PARAMS ((const UEMUSHORT
*));
428 static int eisinf
PARAMS ((const UEMUSHORT
*));
429 static int eisnan
PARAMS ((const UEMUSHORT
*));
430 static void einfin
PARAMS ((UEMUSHORT
*));
432 static void enan
PARAMS ((UEMUSHORT
*, int));
433 static void einan
PARAMS ((UEMUSHORT
*));
434 static int eiisnan
PARAMS ((const UEMUSHORT
*));
435 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
437 static int eiisneg
PARAMS ((const UEMUSHORT
*));
438 static void saturate
PARAMS ((UEMUSHORT
*, int, int, int));
439 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
440 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
441 static void ecleaz
PARAMS ((UEMUSHORT
*));
442 static void ecleazs
PARAMS ((UEMUSHORT
*));
443 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
445 static void eiinfin
PARAMS ((UEMUSHORT
*));
448 static int eiisinf
PARAMS ((const UEMUSHORT
*));
450 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
451 static void eshdn1
PARAMS ((UEMUSHORT
*));
452 static void eshup1
PARAMS ((UEMUSHORT
*));
453 static void eshdn8
PARAMS ((UEMUSHORT
*));
454 static void eshup8
PARAMS ((UEMUSHORT
*));
455 static void eshup6
PARAMS ((UEMUSHORT
*));
456 static void eshdn6
PARAMS ((UEMUSHORT
*));
457 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
458 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
459 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
460 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
461 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
462 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
463 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
465 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
467 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
469 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
471 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
473 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
474 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
475 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
476 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
478 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
479 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
480 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
481 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
483 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
484 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
485 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
486 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
487 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
488 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
489 static void ieeetoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
490 const struct ieee_format
*));
491 static void etoieee
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
492 const struct ieee_format
*));
493 static void toieee
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
494 const struct ieee_format
*));
495 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
497 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
499 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
500 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
501 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
503 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
505 static int eshift
PARAMS ((UEMUSHORT
*, int));
506 static int enormlz
PARAMS ((UEMUSHORT
*));
508 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
509 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
510 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
511 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
513 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
514 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
515 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
516 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
517 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
518 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
520 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
521 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
522 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
524 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
527 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
529 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
532 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
533 static void mtherr
PARAMS ((const char *, int));
535 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
536 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
537 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
540 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
542 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
544 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
548 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
550 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
552 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
556 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
557 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
558 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
559 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
560 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
563 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
564 swapping ends if required, into output array of longs. The
565 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
571 enum machine_mode mode
;
575 if (REAL_WORDS_BIG_ENDIAN
&& !VAX_HALFWORD_ORDER
)
580 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
581 /* Swap halfwords in the fourth long. */
582 th
= (unsigned long) e
[6] & 0xffff;
583 t
= (unsigned long) e
[7] & 0xffff;
592 /* Swap halfwords in the third long. */
593 th
= (unsigned long) e
[4] & 0xffff;
594 t
= (unsigned long) e
[5] & 0xffff;
600 /* Swap halfwords in the second word. */
601 th
= (unsigned long) e
[2] & 0xffff;
602 t
= (unsigned long) e
[3] & 0xffff;
609 /* Swap halfwords in the first word. */
610 th
= (unsigned long) e
[0] & 0xffff;
611 t
= (unsigned long) e
[1] & 0xffff;
622 /* Pack the output array without swapping. */
627 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
628 /* Pack the fourth long. */
629 th
= (unsigned long) e
[7] & 0xffff;
630 t
= (unsigned long) e
[6] & 0xffff;
639 /* Pack the third long.
640 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
642 th
= (unsigned long) e
[5] & 0xffff;
643 t
= (unsigned long) e
[4] & 0xffff;
649 /* Pack the second long */
650 th
= (unsigned long) e
[3] & 0xffff;
651 t
= (unsigned long) e
[2] & 0xffff;
658 /* Pack the first long */
659 th
= (unsigned long) e
[1] & 0xffff;
660 t
= (unsigned long) e
[0] & 0xffff;
672 /* This is the implementation of the REAL_ARITHMETIC macro. */
675 earith (value
, icode
, r1
, r2
)
676 REAL_VALUE_TYPE
*value
;
681 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
687 /* Return NaN input back to the caller. */
690 PUT_REAL (d1
, value
);
695 PUT_REAL (d2
, value
);
699 code
= (enum tree_code
) icode
;
707 esub (d2
, d1
, v
); /* d1 - d2 */
716 if (ecmp (d2
, ezero
) == 0)
719 ediv (d2
, d1
, v
); /* d1/d2 */
722 case MIN_EXPR
: /* min (d1,d2) */
723 if (ecmp (d1
, d2
) < 0)
729 case MAX_EXPR
: /* max (d1,d2) */
730 if (ecmp (d1
, d2
) > 0)
743 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
744 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
750 UEMUSHORT f
[NE
], g
[NE
];
766 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
767 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
773 UEMUSHORT f
[NE
], g
[NE
];
775 unsigned HOST_WIDE_INT l
;
789 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
790 string to binary, rounding off as indicated by the machine_mode argument.
791 Then it promotes the rounded value to REAL_VALUE_TYPE. */
798 UEMUSHORT tem
[NE
], e
[NE
];
824 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
844 /* Expansion of REAL_NEGATE. */
860 /* Round real toward zero to HOST_WIDE_INT;
861 implements REAL_VALUE_FIX (x). */
867 UEMUSHORT f
[NE
], g
[NE
];
874 warning ("conversion from NaN to int");
882 /* Round real toward zero to unsigned HOST_WIDE_INT
883 implements REAL_VALUE_UNSIGNED_FIX (x).
884 Negative input returns zero. */
886 unsigned HOST_WIDE_INT
890 UEMUSHORT f
[NE
], g
[NE
];
891 unsigned HOST_WIDE_INT l
;
897 warning ("conversion from NaN to unsigned int");
906 /* REAL_VALUE_FROM_INT macro. */
909 ereal_from_int (d
, i
, j
, mode
)
912 enum machine_mode mode
;
914 UEMUSHORT df
[NE
], dg
[NE
];
915 HOST_WIDE_INT low
, high
;
918 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
925 /* complement and add 1 */
932 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
933 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
935 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
940 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
941 Avoid double-rounding errors later by rounding off now from the
942 extra-wide internal format to the requested precision. */
943 switch (GET_MODE_BITSIZE (mode
))
961 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
978 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
981 ereal_from_uint (d
, i
, j
, mode
)
983 unsigned HOST_WIDE_INT i
, j
;
984 enum machine_mode mode
;
986 UEMUSHORT df
[NE
], dg
[NE
];
987 unsigned HOST_WIDE_INT low
, high
;
989 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
993 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
999 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
1000 Avoid double-rounding errors later by rounding off now from the
1001 extra-wide internal format to the requested precision. */
1002 switch (GET_MODE_BITSIZE (mode
))
1020 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1037 /* REAL_VALUE_TO_INT macro. */
1040 ereal_to_int (low
, high
, rr
)
1041 HOST_WIDE_INT
*low
, *high
;
1044 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
1051 warning ("conversion from NaN to int");
1057 /* convert positive value */
1064 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
1065 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
1066 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
1067 emul (df
, dh
, dg
); /* fractional part is the low word */
1068 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
1071 /* complement and add 1 */
1081 /* REAL_VALUE_LDEXP macro. */
1088 UEMUSHORT e
[NE
], y
[NE
];
1101 /* Check for infinity in a REAL_VALUE_TYPE. */
1105 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1111 return (eisinf (e
));
1117 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1121 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1127 return (eisnan (e
));
1134 /* Check for a negative REAL_VALUE_TYPE number.
1135 This just checks the sign bit, so that -0 counts as negative. */
1141 return ereal_isneg (x
);
1144 /* Expansion of REAL_VALUE_TRUNCATE.
1145 The result is in floating point, rounded to nearest or even. */
1148 real_value_truncate (mode
, arg
)
1149 enum machine_mode mode
;
1150 REAL_VALUE_TYPE arg
;
1152 UEMUSHORT e
[NE
], t
[NE
];
1164 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1201 /* If an unsupported type was requested, presume that
1202 the machine files know something useful to do with
1203 the unmodified value. */
1212 /* Return true if ARG can be represented exactly in MODE. */
1215 exact_real_truncate (mode
, arg
)
1216 enum machine_mode mode
;
1217 REAL_VALUE_TYPE
*arg
;
1219 REAL_VALUE_TYPE trunc
;
1221 if (target_isnan (*arg
))
1224 trunc
= real_value_truncate (mode
, *arg
);
1225 return ereal_cmp (*arg
, trunc
) == 0;
1228 /* Try to change R into its exact multiplicative inverse in machine mode
1229 MODE. Return nonzero function value if successful. */
1232 exact_real_inverse (mode
, r
)
1233 enum machine_mode mode
;
1236 UEMUSHORT e
[NE
], einv
[NE
];
1237 REAL_VALUE_TYPE rinv
;
1242 /* Test for input in range. Don't transform IEEE special values. */
1243 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1246 /* Test for a power of 2: all significand bits zero except the MSB.
1247 We are assuming the target has binary (or hex) arithmetic. */
1248 if (e
[NE
- 2] != 0x8000)
1251 for (i
= 0; i
< NE
- 2; i
++)
1257 /* Compute the inverse and truncate it to the required mode. */
1258 ediv (e
, eone
, einv
);
1259 PUT_REAL (einv
, &rinv
);
1260 rinv
= real_value_truncate (mode
, rinv
);
1262 #ifdef CHECK_FLOAT_VALUE
1263 /* This check is not redundant. It may, for example, flush
1264 a supposedly IEEE denormal value to zero. */
1266 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1269 GET_REAL (&rinv
, einv
);
1271 /* Check the bits again, because the truncation might have
1272 generated an arbitrary saturation value on overflow. */
1273 if (einv
[NE
- 2] != 0x8000)
1276 for (i
= 0; i
< NE
- 2; i
++)
1282 /* Fail if the computed inverse is out of range. */
1283 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1286 /* Output the reciprocal and return success flag. */
1291 /* Used for debugging--print the value of R in human-readable format
1300 REAL_VALUE_TO_DECIMAL (r
, dstr
, -1);
1301 fprintf (stderr
, "%s", dstr
);
1305 /* The following routines convert REAL_VALUE_TYPE to the various floating
1306 point formats that are meaningful to supported computers.
1308 The results are returned in 32-bit pieces, each piece stored in a `long'.
1309 This is so they can be printed by statements like
1311 fprintf (file, "%lx, %lx", L[0], L[1]);
1313 that will work on both narrow- and wide-word host computers. */
1315 /* Convert R to a 128-bit long double precision value. The output array L
1316 contains four 32-bit pieces of the result, in the order they would appear
1327 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1332 endian (e
, l
, TFmode
);
1335 /* Convert R to a double extended precision value. The output array L
1336 contains three 32-bit pieces of the result, in the order they would
1337 appear in memory. */
1348 endian (e
, l
, XFmode
);
1351 /* Convert R to a double precision value. The output array L contains two
1352 32-bit pieces of the result, in the order they would appear in memory. */
1363 endian (e
, l
, DFmode
);
1366 /* Convert R to a single precision float value stored in the least-significant
1367 bits of a `long'. */
1378 endian (e
, &l
, SFmode
);
1382 /* Convert X to a decimal ASCII string S for output to an assembly
1383 language file. Note, there is no standard way to spell infinity or
1384 a NaN, so these values may require special treatment in the tm.h
1387 The argument DIGITS is the number of decimal digits to print,
1388 or -1 to indicate "enough", i.e. DECIMAL_DIG for for the target. */
1391 ereal_to_decimal (x
, s
, digits
)
1399 /* Find DECIMAL_DIG for the target. */
1401 switch (TARGET_FLOAT_FORMAT
)
1403 case IEEE_FLOAT_FORMAT
:
1404 switch (LONG_DOUBLE_TYPE_SIZE
)
1413 if (!INTEL_EXTENDED_IEEE_FORMAT
)
1428 case VAX_FLOAT_FORMAT
:
1429 digits
= 18; /* D_FLOAT */
1432 case IBM_FLOAT_FORMAT
:
1436 case C4X_FLOAT_FORMAT
:
1444 /* etoasc interprets digits as places after the decimal point.
1445 We interpret digits as total decimal digits, which IMO is
1446 more useful. Since the output will have one digit before
1447 the point, subtract one. */
1448 etoasc (e
, s
, digits
- 1);
1451 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1452 or -2 if either is a NaN. */
1456 REAL_VALUE_TYPE x
, y
;
1458 UEMUSHORT ex
[NE
], ey
[NE
];
1462 return (ecmp (ex
, ey
));
1465 /* Return 1 if the sign bit of X is set, else return 0. */
1474 return (eisneg (ex
));
1479 Extended precision IEEE binary floating point arithmetic routines
1481 Numbers are stored in C language as arrays of 16-bit unsigned
1482 short integers. The arguments of the routines are pointers to
1485 External e type data structure, similar to Intel 8087 chip
1486 temporary real format but possibly with a larger significand:
1488 NE-1 significand words (least significant word first,
1489 most significant bit is normally set)
1490 exponent (value = EXONE for 1.0,
1491 top bit is the sign)
1494 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1496 ei[0] sign word (0 for positive, 0xffff for negative)
1497 ei[1] biased exponent (value = EXONE for the number 1.0)
1498 ei[2] high guard word (always zero after normalization)
1500 to ei[NI-2] significand (NI-4 significand words,
1501 most significant word first,
1502 most significant bit is set)
1503 ei[NI-1] low guard word (0x8000 bit is rounding place)
1507 Routines for external format e-type numbers
1509 asctoe (string, e) ASCII string to extended double e type
1510 asctoe64 (string, &d) ASCII string to long double
1511 asctoe53 (string, &d) ASCII string to double
1512 asctoe24 (string, &f) ASCII string to single
1513 asctoeg (string, e, prec) ASCII string to specified precision
1514 e24toe (&f, e) IEEE single precision to e type
1515 e53toe (&d, e) IEEE double precision to e type
1516 e64toe (&d, e) IEEE long double precision to e type
1517 e113toe (&d, e) 128-bit long double precision to e type
1519 eabs (e) absolute value
1521 eadd (a, b, c) c = b + a
1523 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1524 -1 if a < b, -2 if either a or b is a NaN.
1525 ediv (a, b, c) c = b / a
1526 efloor (a, b) truncate to integer, toward -infinity
1527 efrexp (a, exp, s) extract exponent and significand
1528 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1529 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1530 einfin (e) set e to infinity, leaving its sign alone
1531 eldexp (a, n, b) multiply by 2**n
1533 emul (a, b, c) c = b * a
1536 eround (a, b) b = nearest integer value to a
1538 esub (a, b, c) c = b - a
1540 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1541 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1542 e64toasc (&d, str, n) 80-bit long double to ASCII string
1543 e113toasc (&d, str, n) 128-bit long double to ASCII string
1545 etoasc (e, str, n) e to ASCII string, n digits after decimal
1546 etoe24 (e, &f) convert e type to IEEE single precision
1547 etoe53 (e, &d) convert e type to IEEE double precision
1548 etoe64 (e, &d) convert e type to IEEE long double precision
1549 ltoe (&l, e) HOST_WIDE_INT to e type
1550 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1551 eisneg (e) 1 if sign bit of e != 0, else 0
1552 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1553 or is infinite (IEEE)
1554 eisnan (e) 1 if e is a NaN
1557 Routines for internal format exploded e-type numbers
1559 eaddm (ai, bi) add significands, bi = bi + ai
1561 ecleazs (ei) set ei = 0 but leave its sign alone
1562 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1563 edivm (ai, bi) divide significands, bi = bi / ai
1564 emdnorm (ai,l,s,exp) normalize and round off
1565 emovi (a, ai) convert external a to internal ai
1566 emovo (ai, a) convert internal ai to external a
1567 emovz (ai, bi) bi = ai, low guard word of bi = 0
1568 emulm (ai, bi) multiply significands, bi = bi * ai
1569 enormlz (ei) left-justify the significand
1570 eshdn1 (ai) shift significand and guards down 1 bit
1571 eshdn8 (ai) shift down 8 bits
1572 eshdn6 (ai) shift down 16 bits
1573 eshift (ai, n) shift ai n bits up (or down if n < 0)
1574 eshup1 (ai) shift significand and guards up 1 bit
1575 eshup8 (ai) shift up 8 bits
1576 eshup6 (ai) shift up 16 bits
1577 esubm (ai, bi) subtract significands, bi = bi - ai
1578 eiisinf (ai) 1 if infinite
1579 eiisnan (ai) 1 if a NaN
1580 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1581 einan (ai) set ai = NaN
1583 eiinfin (ai) set ai = infinity
1586 The result is always normalized and rounded to NI-4 word precision
1587 after each arithmetic operation.
1589 Exception flags are NOT fully supported.
1591 Signaling NaN's are NOT supported; they are treated the same
1594 Define INFINITY for support of infinity; otherwise a
1595 saturation arithmetic is implemented.
1597 Define NANS for support of Not-a-Number items; otherwise the
1598 arithmetic will never produce a NaN output, and might be confused
1600 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1601 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1602 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1605 Denormals are always supported here where appropriate (e.g., not
1606 for conversion to DEC numbers). */
1608 /* Definitions for error codes that are passed to the common error handling
1611 For Digital Equipment PDP-11 and VAX computers, certain
1612 IBM systems, and others that use numbers with a 56-bit
1613 significand, the symbol DEC should be defined. In this
1614 mode, most floating point constants are given as arrays
1615 of octal integers to eliminate decimal to binary conversion
1616 errors that might be introduced by the compiler.
1618 For computers, such as IBM PC, that follow the IEEE
1619 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1620 Std 754-1985), the symbol IEEE should be defined.
1621 These numbers have 53-bit significands. In this mode, constants
1622 are provided as arrays of hexadecimal 16 bit integers.
1623 The endian-ness of generated values is controlled by
1624 REAL_WORDS_BIG_ENDIAN.
1626 To accommodate other types of computer arithmetic, all
1627 constants are also provided in a normal decimal radix
1628 which one can hope are correctly converted to a suitable
1629 format by the available C language compiler. To invoke
1630 this mode, the symbol UNK is defined.
1632 An important difference among these modes is a predefined
1633 set of machine arithmetic constants for each. The numbers
1634 MACHEP (the machine roundoff error), MAXNUM (largest number
1635 represented), and several other parameters are preset by
1636 the configuration symbol. Check the file const.c to
1637 ensure that these values are correct for your computer.
1639 For ANSI C compatibility, define ANSIC equal to 1. Currently
1640 this affects only the atan2 function and others that use it. */
1642 /* Constant definitions for math error conditions. */
1644 #define DOMAIN 1 /* argument domain error */
1645 #define SING 2 /* argument singularity */
1646 #define OVERFLOW 3 /* overflow range error */
1647 #define UNDERFLOW 4 /* underflow range error */
1648 #define TLOSS 5 /* total loss of precision */
1649 #define PLOSS 6 /* partial loss of precision */
1650 #define INVALID 7 /* NaN-producing operation */
1652 /* e type constants used by high precision check routines */
1654 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1656 const UEMUSHORT ezero
[NE
] =
1657 {0x0000, 0x0000, 0x0000, 0x0000,
1658 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1661 const UEMUSHORT ehalf
[NE
] =
1662 {0x0000, 0x0000, 0x0000, 0x0000,
1663 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1666 const UEMUSHORT eone
[NE
] =
1667 {0x0000, 0x0000, 0x0000, 0x0000,
1668 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1671 const UEMUSHORT etwo
[NE
] =
1672 {0x0000, 0x0000, 0x0000, 0x0000,
1673 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1676 const UEMUSHORT e32
[NE
] =
1677 {0x0000, 0x0000, 0x0000, 0x0000,
1678 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1680 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1681 const UEMUSHORT elog2
[NE
] =
1682 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1683 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1685 /* 1.41421356237309504880168872420969807856967187537695E0 */
1686 const UEMUSHORT esqrt2
[NE
] =
1687 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1688 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1690 /* 3.14159265358979323846264338327950288419716939937511E0 */
1691 const UEMUSHORT epi
[NE
] =
1692 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1693 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1696 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1697 const UEMUSHORT ezero
[NE
] =
1698 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1699 const UEMUSHORT ehalf
[NE
] =
1700 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1701 const UEMUSHORT eone
[NE
] =
1702 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1703 const UEMUSHORT etwo
[NE
] =
1704 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1705 const UEMUSHORT e32
[NE
] =
1706 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1707 const UEMUSHORT elog2
[NE
] =
1708 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1709 const UEMUSHORT esqrt2
[NE
] =
1710 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1711 const UEMUSHORT epi
[NE
] =
1712 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1715 /* Control register for rounding precision.
1716 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1721 /* Clear out entire e-type number X. */
1729 for (i
= 0; i
< NE
; i
++)
1733 /* Move e-type number from A to B. */
1742 for (i
= 0; i
< NE
; i
++)
1748 /* Absolute value of e-type X. */
1754 /* sign is top bit of last word of external format */
1755 x
[NE
- 1] &= 0x7fff;
1759 /* Negate the e-type number X. */
1766 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1769 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1773 const UEMUSHORT x
[];
1776 if (x
[NE
- 1] & 0x8000)
1782 /* Return 1 if e-type number X is infinity, else return zero. */
1786 const UEMUSHORT x
[];
1793 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1799 /* Check if e-type number is not a number. The bit pattern is one that we
1800 defined, so we know for sure how to detect it. */
1804 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1809 /* NaN has maximum exponent */
1810 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1812 /* ... and non-zero significand field. */
1813 for (i
= 0; i
< NE
- 1; i
++)
1823 /* Fill e-type number X with infinity pattern (IEEE)
1824 or largest possible number (non-IEEE). */
1833 for (i
= 0; i
< NE
- 1; i
++)
1837 for (i
= 0; i
< NE
- 1; i
++)
1865 /* Similar, except return it as a REAL_VALUE_TYPE. */
1869 enum machine_mode mode
;
1886 if (!INTEL_EXTENDED_IEEE_FORMAT
)
1909 /* Output an e-type NaN.
1910 This generates Intel's quiet NaN pattern for extended real.
1911 The exponent is 7fff, the leading mantissa word is c000. */
1921 for (i
= 0; i
< NE
- 2; i
++)
1924 *x
= (sign
<< 15) | 0x7fff;
1928 /* Move in an e-type number A, converting it to exploded e-type B. */
1940 p
= a
+ (NE
- 1); /* point to last word of external number */
1941 /* get the sign bit */
1946 /* get the exponent */
1948 *q
++ &= 0x7fff; /* delete the sign bit */
1950 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1956 for (i
= 3; i
< NI
; i
++)
1962 for (i
= 2; i
< NI
; i
++)
1968 /* clear high guard word */
1970 /* move in the significand */
1971 for (i
= 0; i
< NE
- 1; i
++)
1973 /* clear low guard word */
1977 /* Move out exploded e-type number A, converting it to e type B. */
1990 q
= b
+ (NE
- 1); /* point to output exponent */
1991 /* combine sign and exponent */
1994 *q
-- = *p
++ | 0x8000;
1998 if (*(p
- 1) == 0x7fff)
2003 enan (b
, eiisneg (a
));
2011 /* skip over guard word */
2013 /* move the significand */
2014 for (j
= 0; j
< NE
- 1; j
++)
2018 /* Clear out exploded e-type number XI. */
2026 for (i
= 0; i
< NI
; i
++)
2030 /* Clear out exploded e-type XI, but don't touch the sign. */
2039 for (i
= 0; i
< NI
- 1; i
++)
2043 /* Move exploded e-type number from A to B. */
2052 for (i
= 0; i
< NI
- 1; i
++)
2054 /* clear low guard word */
2058 /* Generate exploded e-type NaN.
2059 The explicit pattern for this is maximum exponent and
2060 top two significant bits set. */
2074 /* Return nonzero if exploded e-type X is a NaN. */
2079 const UEMUSHORT x
[];
2083 if ((x
[E
] & 0x7fff) == 0x7fff)
2085 for (i
= M
+ 1; i
< NI
; i
++)
2095 /* Return nonzero if sign of exploded e-type X is nonzero. */
2099 const UEMUSHORT x
[];
2106 /* Fill exploded e-type X with infinity pattern.
2107 This has maximum exponent and significand all zeros. */
2119 /* Return nonzero if exploded e-type X is infinite. */
2124 const UEMUSHORT x
[];
2131 if ((x
[E
] & 0x7fff) == 0x7fff)
2135 #endif /* INFINITY */
2137 /* Compare significands of numbers in internal exploded e-type format.
2138 Guard words are included in the comparison.
2146 const UEMUSHORT
*a
, *b
;
2150 a
+= M
; /* skip up to significand area */
2152 for (i
= M
; i
< NI
; i
++)
2160 if (*(--a
) > *(--b
))
2166 /* Shift significand of exploded e-type X down by 1 bit. */
2175 x
+= M
; /* point to significand area */
2178 for (i
= M
; i
< NI
; i
++)
2190 /* Shift significand of exploded e-type X up by 1 bit. */
2202 for (i
= M
; i
< NI
; i
++)
2215 /* Shift significand of exploded e-type X down by 8 bits. */
2221 UEMUSHORT newbyt
, oldbyt
;
2226 for (i
= M
; i
< NI
; i
++)
2236 /* Shift significand of exploded e-type X up by 8 bits. */
2243 UEMUSHORT newbyt
, oldbyt
;
2248 for (i
= M
; i
< NI
; i
++)
2258 /* Shift significand of exploded e-type X up by 16 bits. */
2270 for (i
= M
; i
< NI
- 1; i
++)
2276 /* Shift significand of exploded e-type X down by 16 bits. */
2288 for (i
= M
; i
< NI
- 1; i
++)
2294 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2308 for (i
= M
; i
< NI
; i
++)
2310 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2321 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2335 for (i
= M
; i
< NI
; i
++)
2337 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2349 static UEMUSHORT equot
[NI
];
2353 /* Radix 2 shift-and-add versions of multiply and divide */
2356 /* Divide significands */
2360 UEMUSHORT den
[], num
[];
2370 for (i
= M
; i
< NI
; i
++)
2375 /* Use faster compare and subtraction if denominator has only 15 bits of
2381 for (i
= M
+ 3; i
< NI
; i
++)
2386 if ((den
[M
+ 1] & 1) != 0)
2394 for (i
= 0; i
< NBITS
+ 2; i
++)
2412 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2413 bit + 1 roundoff bit. */
2418 for (i
= 0; i
< NBITS
+ 2; i
++)
2420 if (ecmpm (den
, num
) <= 0)
2423 j
= 1; /* quotient bit = 1 */
2437 /* test for nonzero remainder after roundoff bit */
2440 for (i
= M
; i
< NI
; i
++)
2448 for (i
= 0; i
< NI
; i
++)
2454 /* Multiply significands */
2465 for (i
= M
; i
< NI
; i
++)
2470 while (*p
== 0) /* significand is not supposed to be zero */
2475 if ((*p
& 0xff) == 0)
2483 for (i
= 0; i
< k
; i
++)
2487 /* remember if there were any nonzero bits shifted out */
2494 for (i
= 0; i
< NI
; i
++)
2497 /* return flag for lost nonzero bits */
2503 /* Radix 65536 versions of multiply and divide. */
2505 /* Multiply significand of e-type number B
2506 by 16-bit quantity A, return e-type result to C. */
2511 const UEMUSHORT b
[];
2515 unsigned EMULONG carry
;
2516 const UEMUSHORT
*ps
;
2518 unsigned EMULONG aa
, m
;
2527 for (i
=M
+1; i
<NI
; i
++)
2537 m
= (unsigned EMULONG
) aa
* *ps
--;
2538 carry
= (m
& 0xffff) + *pp
;
2539 *pp
-- = (UEMUSHORT
) carry
;
2540 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2541 *pp
= (UEMUSHORT
) carry
;
2542 *(pp
-1) = carry
>> 16;
2545 for (i
=M
; i
<NI
; i
++)
2549 /* Divide significands of exploded e-types NUM / DEN. Neither the
2550 numerator NUM nor the denominator DEN is permitted to have its high guard
2555 const UEMUSHORT den
[];
2560 unsigned EMULONG tnum
;
2561 UEMUSHORT j
, tdenm
, tquot
;
2562 UEMUSHORT tprod
[NI
+1];
2568 for (i
=M
; i
<NI
; i
++)
2574 for (i
=M
; i
<NI
; i
++)
2576 /* Find trial quotient digit (the radix is 65536). */
2577 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2579 /* Do not execute the divide instruction if it will overflow. */
2580 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2583 tquot
= tnum
/ tdenm
;
2584 /* Multiply denominator by trial quotient digit. */
2585 m16m ((unsigned int) tquot
, den
, tprod
);
2586 /* The quotient digit may have been overestimated. */
2587 if (ecmpm (tprod
, num
) > 0)
2591 if (ecmpm (tprod
, num
) > 0)
2601 /* test for nonzero remainder after roundoff bit */
2604 for (i
=M
; i
<NI
; i
++)
2611 for (i
=0; i
<NI
; i
++)
2617 /* Multiply significands of exploded e-type A and B, result in B. */
2621 const UEMUSHORT a
[];
2626 UEMUSHORT pprod
[NI
];
2632 for (i
=M
; i
<NI
; i
++)
2638 for (i
=M
+1; i
<NI
; i
++)
2646 m16m ((unsigned int) *p
--, b
, pprod
);
2647 eaddm (pprod
, equot
);
2653 for (i
=0; i
<NI
; i
++)
2656 /* return flag for lost nonzero bits */
2662 /* Normalize and round off.
2664 The internal format number to be rounded is S.
2665 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2667 Input SUBFLG indicates whether the number was obtained
2668 by a subtraction operation. In that case if LOST is nonzero
2669 then the number is slightly smaller than indicated.
2671 Input EXP is the biased exponent, which may be negative.
2672 the exponent field of S is ignored but is replaced by
2673 EXP as adjusted by normalization and rounding.
2675 Input RCNTRL is the rounding control. If it is nonzero, the
2676 returned value will be rounded to RNDPRC bits.
2678 For future reference: In order for emdnorm to round off denormal
2679 significands at the right point, the input exponent must be
2680 adjusted to be the actual value it would have after conversion to
2681 the final floating point type. This adjustment has been
2682 implemented for all type conversions (etoe53, etc.) and decimal
2683 conversions, but not for the arithmetic functions (eadd, etc.).
2684 Data types having standard 15-bit exponents are not affected by
2685 this, but SFmode and DFmode are affected. For example, ediv with
2686 rndprc = 24 will not round correctly to 24-bit precision if the
2687 result is denormal. */
2689 static int rlast
= -1;
2691 static UEMUSHORT rmsk
= 0;
2692 static UEMUSHORT rmbit
= 0;
2693 static UEMUSHORT rebit
= 0;
2695 static UEMUSHORT rbit
[NI
];
2698 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2701 int subflg ATTRIBUTE_UNUSED
;
2711 /* a blank significand could mean either zero or infinity. */
2724 if ((j
> NBITS
) && (exp
< 32767))
2732 if (exp
> (EMULONG
) (-NBITS
- 1))
2745 /* Round off, unless told not to by rcntrl. */
2748 /* Set up rounding parameters if the control register changed. */
2749 if (rndprc
!= rlast
)
2756 rw
= NI
- 1; /* low guard word */
2779 /* For DEC or IBM arithmetic */
2796 /* For C4x arithmetic */
2817 /* Shift down 1 temporarily if the data structure has an implied
2818 most significant bit and the number is denormal.
2819 Intel long double denormals also lose one bit of precision. */
2820 if ((exp
<= 0) && (rndprc
!= NBITS
)
2821 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2823 lost
|= s
[NI
- 1] & 1;
2826 /* Clear out all bits below the rounding bit,
2827 remembering in r if any were nonzero. */
2841 if ((r
& rmbit
) != 0)
2847 { /* round to even */
2848 if ((s
[re
] & rebit
) == 0)
2863 /* Undo the temporary shift for denormal values. */
2864 if ((exp
<= 0) && (rndprc
!= NBITS
)
2865 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2870 { /* overflow on roundoff */
2883 for (i
= 2; i
< NI
- 1; i
++)
2886 warning ("floating point overflow");
2890 for (i
= M
+ 1; i
< NI
- 1; i
++)
2893 if ((rndprc
< 64) || (rndprc
== 113))
2908 s
[1] = (UEMUSHORT
) exp
;
2911 /* Subtract. C = B - A, all e type numbers. */
2913 static int subflg
= 0;
2917 const UEMUSHORT
*a
, *b
;
2932 /* Infinity minus infinity is a NaN.
2933 Test for subtracting infinities of the same sign. */
2934 if (eisinf (a
) && eisinf (b
)
2935 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2937 mtherr ("esub", INVALID
);
2946 /* Add. C = A + B, all e type. */
2950 const UEMUSHORT
*a
, *b
;
2955 /* NaN plus anything is a NaN. */
2966 /* Infinity minus infinity is a NaN.
2967 Test for adding infinities of opposite signs. */
2968 if (eisinf (a
) && eisinf (b
)
2969 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2971 mtherr ("esub", INVALID
);
2980 /* Arithmetic common to both addition and subtraction. */
2984 const UEMUSHORT
*a
, *b
;
2987 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2989 EMULONG lt
, lta
, ltb
;
3010 /* compare exponents */
3015 { /* put the larger number in bi */
3025 if (lt
< (EMULONG
) (-NBITS
- 1))
3026 goto done
; /* answer same as larger addend */
3028 lost
= eshift (ai
, k
); /* shift the smaller number down */
3032 /* exponents were the same, so must compare significands */
3035 { /* the numbers are identical in magnitude */
3036 /* if different signs, result is zero */
3042 /* if same sign, result is double */
3043 /* double denormalized tiny number */
3044 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
3049 /* add 1 to exponent unless both are zero! */
3050 for (j
= 1; j
< NI
- 1; j
++)
3066 bi
[E
] = (UEMUSHORT
) ltb
;
3070 { /* put the larger number in bi */
3086 emdnorm (bi
, lost
, subflg
, ltb
, !ROUND_TOWARDS_ZERO
);
3092 /* Divide: C = B/A, all e type. */
3096 const UEMUSHORT
*a
, *b
;
3099 UEMUSHORT ai
[NI
], bi
[NI
];
3101 EMULONG lt
, lta
, ltb
;
3103 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3104 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3105 sign
= eisneg (a
) ^ eisneg (b
);
3108 /* Return any NaN input. */
3119 /* Zero over zero, or infinity over infinity, is a NaN. */
3120 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
3121 || (eisinf (a
) && eisinf (b
)))
3123 mtherr ("ediv", INVALID
);
3128 /* Infinity over anything else is infinity. */
3135 /* Anything else over infinity is zero. */
3147 { /* See if numerator is zero. */
3148 for (i
= 1; i
< NI
- 1; i
++)
3152 ltb
-= enormlz (bi
);
3162 { /* possible divide by zero */
3163 for (i
= 1; i
< NI
- 1; i
++)
3167 lta
-= enormlz (ai
);
3171 /* Divide by zero is not an invalid operation.
3172 It is a divide-by-zero operation! */
3174 mtherr ("ediv", SING
);
3180 /* calculate exponent */
3181 lt
= ltb
- lta
+ EXONE
;
3182 emdnorm (bi
, i
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3189 && (ecmp (c
, ezero
) != 0)
3192 *(c
+(NE
-1)) |= 0x8000;
3194 *(c
+(NE
-1)) &= ~0x8000;
3197 /* Multiply e-types A and B, return e-type product C. */
3201 const UEMUSHORT
*a
, *b
;
3204 UEMUSHORT ai
[NI
], bi
[NI
];
3206 EMULONG lt
, lta
, ltb
;
3208 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3209 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3210 sign
= eisneg (a
) ^ eisneg (b
);
3213 /* NaN times anything is the same NaN. */
3224 /* Zero times infinity is a NaN. */
3225 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3226 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3228 mtherr ("emul", INVALID
);
3233 /* Infinity times anything else is infinity. */
3235 if (eisinf (a
) || eisinf (b
))
3247 for (i
= 1; i
< NI
- 1; i
++)
3251 lta
-= enormlz (ai
);
3262 for (i
= 1; i
< NI
- 1; i
++)
3266 ltb
-= enormlz (bi
);
3275 /* Multiply significands */
3277 /* calculate exponent */
3278 lt
= lta
+ ltb
- (EXONE
- 1);
3279 emdnorm (bi
, j
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3286 && (ecmp (c
, ezero
) != 0)
3289 *(c
+(NE
-1)) |= 0x8000;
3291 *(c
+(NE
-1)) &= ~0x8000;
3294 /* Convert double precision PE to e-type Y. */
3298 const UEMUSHORT
*pe
;
3308 ibmtoe (pe
, y
, DFmode
);
3313 c4xtoe (pe
, y
, HFmode
);
3317 ieeetoe (pe
, y
, &ieee_53
);
3319 #endif /* not C4X */
3320 #endif /* not IBM */
3321 #endif /* not DEC */
3324 /* Convert double extended precision float PE to e type Y. */
3328 const UEMUSHORT
*pe
;
3338 for (i
= 0; i
< NE
- 5; i
++)
3341 /* REAL_WORDS_BIG_ENDIAN is always 0 for DEC and 1 for IBM.
3342 This precision is not ordinarily supported on DEC or IBM. */
3343 if (! REAL_WORDS_BIG_ENDIAN
)
3345 for (i
= 0; i
< 5; i
++)
3349 /* For denormal long double Intel format, shift significand up one
3350 -- but only if the top significand bit is zero. A top bit of 1
3351 is "pseudodenormal" when the exponent is zero. */
3352 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3365 p
= &yy
[0] + (NE
- 1);
3368 for (i
= 0; i
< 4; i
++)
3371 #endif /* not C4X */
3373 /* Point to the exponent field and check max exponent cases. */
3375 if ((*p
& 0x7fff) == 0x7fff)
3378 if (! REAL_WORDS_BIG_ENDIAN
)
3380 for (i
= 0; i
< 4; i
++)
3382 if ((i
!= 3 && pe
[i
] != 0)
3383 /* Anything but 0x8000 here, including 0, is a NaN. */
3384 || (i
== 3 && pe
[i
] != 0x8000))
3386 enan (y
, (*p
& 0x8000) != 0);
3393 /* In Motorola extended precision format, the most significant
3394 bit of an infinity mantissa could be either 1 or 0. It is
3395 the lower order bits that tell whether the value is a NaN. */
3396 if ((pe
[2] & 0x7fff) != 0)
3399 for (i
= 3; i
<= 5; i
++)
3404 enan (y
, (*p
& 0x8000) != 0);
3416 #endif /* INFINITY */
3419 for (i
= 0; i
< NE
; i
++)
3423 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3424 /* Convert 128-bit long double precision float PE to e type Y. */
3428 const UEMUSHORT
*pe
;
3431 ieeetoe (pe
, y
, &ieee_113
);
3433 #endif /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
3435 /* Convert single precision float PE to e type Y. */
3439 const UEMUSHORT
*pe
;
3444 ibmtoe (pe
, y
, SFmode
);
3450 c4xtoe (pe
, y
, QFmode
);
3455 ieeetoe (pe
, y
, &dec_f
);
3459 ieeetoe (pe
, y
, &ieee_24
);
3461 #endif /* not DEC */
3462 #endif /* not C4X */
3463 #endif /* not IBM */
3466 /* Convert machine format float of specified format PE to e type Y. */
3469 ieeetoe (pe
, y
, fmt
)
3470 const UEMUSHORT
*pe
;
3472 const struct ieee_format
*fmt
;
3479 int shortsm1
= fmt
->bits
/ 16 - 1;
3481 int expmask
= (1 << fmt
->expbits
) - 1;
3483 int expshift
= (fmt
->precision
- 1) & 0x0f;
3484 int highbit
= 1 << expshift
;
3489 if (! REAL_WORDS_BIG_ENDIAN
)
3495 yy
[M
] = (r
& (highbit
- 1)) | highbit
;
3496 r
= (r
& 0x7fff) >> expshift
;
3498 if (!LARGEST_EXPONENT_IS_NORMAL (fmt
->precision
) && r
== expmask
)
3501 /* First check the word where high order mantissa and exponent live */
3502 if ((*e
& (highbit
- 1)) != 0)
3504 enan (y
, yy
[0] != 0);
3507 if (! REAL_WORDS_BIG_ENDIAN
)
3509 for (i
= 0; i
< shortsm1
; i
++)
3513 enan (y
, yy
[0] != 0);
3520 for (i
= 1; i
< shortsm1
+ 1; i
++)
3524 enan (y
, yy
[0] != 0);
3536 #endif /* INFINITY */
3537 /* If zero exponent, then the significand is denormalized.
3538 So take back the understood high significand bit. */
3544 r
+= fmt
->adjustment
;
3547 if (! REAL_WORDS_BIG_ENDIAN
)
3549 for (i
= 0; i
< shortsm1
; i
++)
3555 for (i
= 0; i
< shortsm1
; i
++)
3558 if (fmt
->precision
== 113)
3560 /* denorm is left alone in 113 bit format */
3566 eshift (yy
, -(expshift
+ 1));
3568 { /* if zero exponent, then normalize the significand */
3569 if ((k
= enormlz (yy
)) > NBITS
)
3572 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3578 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3579 /* Convert e-type X to IEEE 128-bit long double format E. */
3586 etoieee (x
, e
, &ieee_113
);
3589 /* Convert exploded e-type X, that has already been rounded to
3590 113-bit precision, to IEEE 128-bit long double format Y. */
3596 toieee (x
, y
, &ieee_113
);
3599 #endif /* INTEL_EXTENDED_IEEE_FORMAT == 0 */
3601 /* Convert e-type X to IEEE double extended format E. */
3608 etoieee (x
, e
, &ieee_64
);
3611 /* Convert exploded e-type X, that has already been rounded to
3612 64-bit precision, to IEEE double extended format Y. */
3618 toieee (x
, y
, &ieee_64
);
3621 /* e type to double precision. */
3624 /* Convert e-type X to DEC-format double E. */
3634 /* Convert exploded e-type X, that has already been rounded to
3635 56-bit double precision, to DEC double Y. */
3646 /* Convert e-type X to IBM 370-format double E. */
3653 etoibm (x
, e
, DFmode
);
3656 /* Convert exploded e-type X, that has already been rounded to
3657 56-bit precision, to IBM 370 double Y. */
3663 toibm (x
, y
, DFmode
);
3666 #else /* it's neither DEC nor IBM */
3668 /* Convert e-type X to C4X-format long double E. */
3675 etoc4x (x
, e
, HFmode
);
3678 /* Convert exploded e-type X, that has already been rounded to
3679 56-bit precision, to IBM 370 double Y. */
3685 toc4x (x
, y
, HFmode
);
3688 #else /* it's neither DEC nor IBM nor C4X */
3690 /* Convert e-type X to IEEE double E. */
3697 etoieee (x
, e
, &ieee_53
);
3700 /* Convert exploded e-type X, that has already been rounded to
3701 53-bit precision, to IEEE double Y. */
3707 toieee (x
, y
, &ieee_53
);
3710 #endif /* not C4X */
3711 #endif /* not IBM */
3712 #endif /* not DEC */
3716 /* e type to single precision. */
3719 /* Convert e-type X to IBM 370 float E. */
3726 etoibm (x
, e
, SFmode
);
3729 /* Convert exploded e-type X, that has already been rounded to
3730 float precision, to IBM 370 float Y. */
3736 toibm (x
, y
, SFmode
);
3739 #else /* it's not IBM */
3742 /* Convert e-type X to C4X float E. */
3749 etoc4x (x
, e
, QFmode
);
3752 /* Convert exploded e-type X, that has already been rounded to
3753 float precision, to IBM 370 float Y. */
3759 toc4x (x
, y
, QFmode
);
3762 #else /* it's neither IBM nor C4X */
3766 /* Convert e-type X to DEC F-float E. */
3773 etoieee (x
, e
, &dec_f
);
3776 /* Convert exploded e-type X, that has already been rounded to
3777 float precision, to DEC F-float Y. */
3783 toieee (x
, y
, &dec_f
);
3788 /* Convert e-type X to IEEE float E. */
3795 etoieee (x
, e
, &ieee_24
);
3798 /* Convert exploded e-type X, that has already been rounded to
3799 float precision, to IEEE float Y. */
3805 toieee (x
, y
, &ieee_24
);
3808 #endif /* not DEC */
3809 #endif /* not C4X */
3810 #endif /* not IBM */
3813 /* Convert e-type X to the IEEE format described by FMT. */
3819 const struct ieee_format
*fmt
;
3828 make_nan (e
, eisneg (x
), fmt
->mode
);
3839 /* Adjust exponent for offset. */
3840 exp
= (EMULONG
) xi
[E
] - fmt
->adjustment
;
3842 /* Round off to nearest or even. */
3844 rndprc
= fmt
->precision
;
3845 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3850 toieee (xi
, e
, fmt
);
3853 /* Convert exploded e-type X, that has already been rounded to
3854 the necessary precision, to the IEEE format described by FMT. */
3859 const struct ieee_format
*fmt
;
3866 maxexp
= (1 << fmt
->expbits
) - 1;
3867 words
= (fmt
->bits
- fmt
->expbits
) / EMUSHORT_SIZE
;
3872 make_nan (y
, eiisneg (x
), fmt
->mode
);
3877 if (fmt
->expbits
< 15
3878 && LARGEST_EXPONENT_IS_NORMAL (fmt
->bits
)
3881 saturate (y
, eiisneg (x
), fmt
->bits
, 1);
3885 /* Point to the exponent. */
3886 if (REAL_WORDS_BIG_ENDIAN
)
3891 /* Copy the sign. */
3897 if (fmt
->expbits
< 15
3898 && !LARGEST_EXPONENT_IS_NORMAL (fmt
->bits
)
3901 /* Saturate at largest number less that infinity. */
3904 *q
|= maxexp
<< (15 - fmt
->expbits
);
3907 *q
|= (maxexp
<< (15 - fmt
->expbits
)) - 1;
3911 if (!REAL_WORDS_BIG_ENDIAN
)
3913 for (i
= 0; i
< words
; i
++)
3918 for (i
= 0; i
< words
; i
++)
3921 #if defined(INFINITY) && defined(ERANGE)
3927 /* If denormal and DEC float, return zero (DEC has no denormals) */
3931 for (i
= 0; i
< fmt
->bits
/ EMUSHORT_SIZE
; i
++)
3937 /* Delete the implied bit unless denormal, except for
3938 64-bit precision. */
3939 if (fmt
->precision
!= 64 && x
[E
] != 0)
3944 /* Shift denormal double extended Intel format significand down
3946 if (fmt
->precision
== 64 && x
[E
] == 0 && ! REAL_WORDS_BIG_ENDIAN
)
3949 if (fmt
->expbits
< 15)
3951 /* Shift the significand. */
3952 eshift (x
, 15 - fmt
->expbits
);
3954 /* Combine the exponent and upper bits of the significand. */
3955 *q
|= x
[E
] << (15 - fmt
->expbits
);
3956 *q
|= x
[M
] & (UEMUSHORT
) ~((maxexp
<< (15 - fmt
->expbits
)) | 0x8000);
3960 /* Copy the exponent. */
3964 /* Add padding after the exponent. At the moment, this is only necessary for
3965 64-bit precision; in this case, the padding is 16 bits. */
3966 if (fmt
->precision
== 64)
3971 if (REAL_WORDS_BIG_ENDIAN
)
3975 /* Copy the significand. */
3976 if (REAL_WORDS_BIG_ENDIAN
)
3978 for (i
= 0; i
< words
; i
++)
3979 *(++q
) = x
[i
+ M
+ 1];
3982 else if (fmt
->precision
== 64 && eiisinf (x
))
3984 /* Intel double extended infinity significand. */
3993 for (i
= 0; i
< words
; i
++)
3994 *(--q
) = x
[i
+ M
+ 1];
3999 /* Compare two e type numbers.
4003 -2 if either a or b is a NaN. */
4007 const UEMUSHORT
*a
, *b
;
4009 UEMUSHORT ai
[NI
], bi
[NI
];
4015 if (eisnan (a
) || eisnan (b
))
4024 { /* the signs are different */
4026 for (i
= 1; i
< NI
- 1; i
++)
4040 /* both are the same sign */
4055 return (0); /* equality */
4059 if (*(--p
) > *(--q
))
4060 return (msign
); /* p is bigger */
4062 return (-msign
); /* p is littler */
4066 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4078 /* Convert HOST_WIDE_INT LP to e type Y. */
4082 const HOST_WIDE_INT
*lp
;
4086 unsigned HOST_WIDE_INT ll
;
4092 /* make it positive */
4093 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4094 yi
[0] = 0xffff; /* put correct sign in the e type number */
4098 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4100 /* move the long integer to yi significand area */
4101 #if HOST_BITS_PER_WIDE_INT == 64
4102 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4103 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4104 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4105 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4106 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4108 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4109 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4110 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4113 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4114 ecleaz (yi
); /* it was zero */
4116 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4117 emovo (yi
, y
); /* output the answer */
4120 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4124 const unsigned HOST_WIDE_INT
*lp
;
4128 unsigned HOST_WIDE_INT ll
;
4134 /* move the long integer to ayi significand area */
4135 #if HOST_BITS_PER_WIDE_INT == 64
4136 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4137 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4138 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4139 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4140 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4142 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4143 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4144 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4147 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4148 ecleaz (yi
); /* it was zero */
4150 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4151 emovo (yi
, y
); /* output the answer */
4155 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4156 part FRAC of e-type (packed internal format) floating point input X.
4157 The integer output I has the sign of the input, except that
4158 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4159 The output e-type fraction FRAC is the positive fractional
4170 unsigned HOST_WIDE_INT ll
;
4173 k
= (int) xi
[E
] - (EXONE
- 1);
4176 /* if exponent <= 0, integer = 0 and real output is fraction */
4181 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4183 /* long integer overflow: output large integer
4184 and correct fraction */
4186 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4189 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4190 /* In this case, let it overflow and convert as if unsigned. */
4191 euifrac (x
, &ll
, frac
);
4192 *i
= (HOST_WIDE_INT
) ll
;
4195 /* In other cases, return the largest positive integer. */
4196 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4201 warning ("overflow on truncation to integer");
4205 /* Shift more than 16 bits: first shift up k-16 mod 16,
4206 then shift up by 16's. */
4207 j
= k
- ((k
>> 4) << 4);
4214 ll
= (ll
<< 16) | xi
[M
];
4216 while ((k
-= 16) > 0);
4223 /* shift not more than 16 bits */
4225 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4232 if ((k
= enormlz (xi
)) > NBITS
)
4235 xi
[E
] -= (UEMUSHORT
) k
;
4241 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4242 FRAC of e-type X. A negative input yields integer output = 0 but
4243 correct fraction. */
4246 euifrac (x
, i
, frac
)
4248 unsigned HOST_WIDE_INT
*i
;
4251 unsigned HOST_WIDE_INT ll
;
4256 k
= (int) xi
[E
] - (EXONE
- 1);
4259 /* if exponent <= 0, integer = 0 and argument is fraction */
4264 if (k
> HOST_BITS_PER_WIDE_INT
)
4266 /* Long integer overflow: output large integer
4267 and correct fraction.
4268 Note, the BSD MicroVAX compiler says that ~(0UL)
4269 is a syntax error. */
4273 warning ("overflow on truncation to unsigned integer");
4277 /* Shift more than 16 bits: first shift up k-16 mod 16,
4278 then shift up by 16's. */
4279 j
= k
- ((k
>> 4) << 4);
4286 ll
= (ll
<< 16) | xi
[M
];
4288 while ((k
-= 16) > 0);
4293 /* shift not more than 16 bits */
4295 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4298 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4304 if ((k
= enormlz (xi
)) > NBITS
)
4307 xi
[E
] -= (UEMUSHORT
) k
;
4312 /* Shift the significand of exploded e-type X up or down by SC bits. */
4333 lost
|= *p
; /* remember lost bits */
4374 return ((int) lost
);
4377 /* Shift normalize the significand area of exploded e-type X.
4378 Return the shift count (up = positive). */
4393 return (0); /* already normalized */
4399 /* With guard word, there are NBITS+16 bits available.
4400 Return true if all are zero. */
4404 /* see if high byte is zero */
4405 while ((*p
& 0xff00) == 0)
4410 /* now shift 1 bit at a time */
4411 while ((*p
& 0x8000) == 0)
4417 mtherr ("enormlz", UNDERFLOW
);
4423 /* Normalize by shifting down out of the high guard word
4424 of the significand */
4439 mtherr ("enormlz", OVERFLOW
);
4446 /* Powers of ten used in decimal <-> binary conversions. */
4451 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4452 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4454 {0x6576, 0x4a92, 0x804a, 0x153f,
4455 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4456 {0x6a32, 0xce52, 0x329a, 0x28ce,
4457 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4458 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4459 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4460 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4461 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4462 {0x851e, 0xeab7, 0x98fe, 0x901b,
4463 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4464 {0x0235, 0x0137, 0x36b1, 0x336c,
4465 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4466 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4467 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4468 {0x0000, 0x0000, 0x0000, 0x0000,
4469 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4470 {0x0000, 0x0000, 0x0000, 0x0000,
4471 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4472 {0x0000, 0x0000, 0x0000, 0x0000,
4473 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4474 {0x0000, 0x0000, 0x0000, 0x0000,
4475 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4476 {0x0000, 0x0000, 0x0000, 0x0000,
4477 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4478 {0x0000, 0x0000, 0x0000, 0x0000,
4479 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4482 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4484 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4485 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4486 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4487 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4488 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4489 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4490 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4491 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4492 {0xa23e, 0x5308, 0xfefb, 0x1155,
4493 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4494 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4495 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4496 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4497 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4498 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4499 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4500 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4501 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4502 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4503 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4504 {0xc155, 0xa4a8, 0x404e, 0x6113,
4505 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4506 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4507 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4508 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4509 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4512 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4513 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4515 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4516 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4517 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4518 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4519 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4520 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4521 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4522 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4523 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4524 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4525 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4526 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4527 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4530 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4532 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4533 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4534 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4535 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4536 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4537 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4538 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4539 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4540 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4541 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4542 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4543 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4544 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4549 /* Convert float value X to ASCII string STRING with NDIG digits after
4550 the decimal point. */
4553 e24toasc (x
, string
, ndigs
)
4554 const UEMUSHORT x
[];
4561 etoasc (w
, string
, ndigs
);
4564 /* Convert double value X to ASCII string STRING with NDIG digits after
4565 the decimal point. */
4568 e53toasc (x
, string
, ndigs
)
4569 const UEMUSHORT x
[];
4576 etoasc (w
, string
, ndigs
);
4579 /* Convert double extended value X to ASCII string STRING with NDIG digits
4580 after the decimal point. */
4583 e64toasc (x
, string
, ndigs
)
4584 const UEMUSHORT x
[];
4591 etoasc (w
, string
, ndigs
);
4594 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4595 after the decimal point. */
4598 e113toasc (x
, string
, ndigs
)
4599 const UEMUSHORT x
[];
4606 etoasc (w
, string
, ndigs
);
4610 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4611 the decimal point. */
4613 static char wstring
[80]; /* working storage for ASCII output */
4616 etoasc (x
, string
, ndigs
)
4617 const UEMUSHORT x
[];
4622 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4623 const UEMUSHORT
*p
, *r
, *ten
;
4625 int i
, j
, k
, expon
, rndsav
;
4638 sprintf (wstring
, " NaN ");
4642 rndprc
= NBITS
; /* set to full precision */
4643 emov (x
, y
); /* retain external format */
4644 if (y
[NE
- 1] & 0x8000)
4647 y
[NE
- 1] &= 0x7fff;
4654 ten
= &etens
[NTEN
][0];
4656 /* Test for zero exponent */
4659 for (k
= 0; k
< NE
- 1; k
++)
4662 goto tnzro
; /* denormalized number */
4664 goto isone
; /* valid all zeros */
4668 /* Test for infinity. */
4669 if (y
[NE
- 1] == 0x7fff)
4672 sprintf (wstring
, " -Infinity ");
4674 sprintf (wstring
, " Infinity ");
4678 /* Test for exponent nonzero but significand denormalized.
4679 * This is an error condition.
4681 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4683 mtherr ("etoasc", DOMAIN
);
4684 sprintf (wstring
, "NaN");
4688 /* Compare to 1.0 */
4697 { /* Number is greater than 1 */
4698 /* Convert significand to an integer and strip trailing decimal zeros. */
4700 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4702 p
= &etens
[NTEN
- 4][0];
4708 for (j
= 0; j
< NE
- 1; j
++)
4721 /* Rescale from integer significand */
4722 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4724 /* Find power of 10 */
4728 /* An unordered compare result shouldn't happen here. */
4729 while (ecmp (ten
, u
) <= 0)
4731 if (ecmp (p
, u
) <= 0)
4744 { /* Number is less than 1.0 */
4745 /* Pad significand with trailing decimal zeros. */
4748 while ((y
[NE
- 2] & 0x8000) == 0)
4757 for (i
= 0; i
< NDEC
+ 1; i
++)
4759 if ((w
[NI
- 1] & 0x7) != 0)
4761 /* multiply by 10 */
4774 if (eone
[NE
- 1] <= u
[1])
4786 while (ecmp (eone
, w
) > 0)
4788 if (ecmp (p
, w
) >= 0)
4803 /* Find the first (leading) digit. */
4809 digit
= equot
[NI
- 1];
4810 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4818 digit
= equot
[NI
- 1];
4826 /* Examine number of digits requested by caller. */
4844 *s
++ = (char) digit
+ '0';
4847 /* Generate digits after the decimal point. */
4848 for (k
= 0; k
<= ndigs
; k
++)
4850 /* multiply current number by 10, without normalizing */
4857 *s
++ = (char) equot
[NI
- 1] + '0';
4859 digit
= equot
[NI
- 1];
4862 /* round off the ASCII string */
4865 /* Test for critical rounding case in ASCII output. */
4869 if (ecmp (t
, ezero
) != 0)
4870 goto roun
; /* round to nearest */
4872 if ((*(s
- 1) & 1) == 0)
4873 goto doexp
; /* round to even */
4876 /* Round up and propagate carry-outs */
4880 /* Carry out to most significant digit? */
4887 /* Most significant digit carries to 10? */
4895 /* Round up and carry out from less significant digits */
4905 /* Strip trailing zeros, but leave at least one. */
4906 while (ss
[-1] == '0' && ss
[-2] != '.')
4908 sprintf (ss
, "e%d", expon
);
4911 /* copy out the working string */
4914 while (*ss
== ' ') /* strip possible leading space */
4916 while ((*s
++ = *ss
++) != '\0')
4921 /* Convert ASCII string to floating point.
4923 Numeric input is a free format decimal number of any length, with
4924 or without decimal point. Entering E after the number followed by an
4925 integer number causes the second number to be interpreted as a power of
4926 10 to be multiplied by the first number (i.e., "scientific" notation). */
4928 /* Convert ASCII string S to single precision float value Y. */
4939 /* Convert ASCII string S to double precision value Y. */
4946 #if defined(DEC) || defined(IBM)
4958 /* Convert ASCII string S to double extended value Y. */
4968 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
4969 /* Convert ASCII string S to 128-bit long double Y. */
4976 asctoeg (s
, y
, 113);
4980 /* Convert ASCII string S to e type Y. */
4987 asctoeg (s
, y
, NBITS
);
4990 /* Convert ASCII string SS to e type Y, with a specified rounding precision
4991 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
4994 asctoeg (ss
, y
, oprec
)
4999 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5000 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5001 int i
, k
, trail
, c
, rndsav
;
5004 char *sp
, *s
, *lstr
;
5007 /* Copy the input string. */
5008 lstr
= (char *) alloca (strlen (ss
) + 1);
5010 while (*ss
== ' ') /* skip leading spaces */
5014 while ((*sp
++ = *ss
++) != '\0')
5018 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5025 rndprc
= NBITS
; /* Set to full precision */
5038 if ((k
>= 0) && (k
< base
))
5040 /* Ignore leading zeros */
5041 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5043 /* Identify and strip trailing zeros after the decimal point. */
5044 if ((trail
== 0) && (decflg
!= 0))
5047 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
5049 /* Check for syntax error */
5051 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5052 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5054 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5056 goto unexpected_char_error
;
5065 /* If enough digits were given to more than fill up the yy register,
5066 continuing until overflow into the high guard word yy[2]
5067 guarantees that there will be a roundoff bit at the top
5068 of the low guard word after normalization. */
5075 nexp
+= 4; /* count digits after decimal point */
5077 eshup1 (yy
); /* multiply current number by 16 */
5085 nexp
+= 1; /* count digits after decimal point */
5087 eshup1 (yy
); /* multiply current number by 10 */
5093 /* Insert the current digit. */
5095 xt
[NI
- 2] = (UEMUSHORT
) k
;
5100 /* Mark any lost non-zero digit. */
5102 /* Count lost digits before the decimal point. */
5124 case '.': /* decimal point */
5126 goto unexpected_char_error
;
5132 goto unexpected_char_error
;
5137 goto unexpected_char_error
;
5150 unexpected_char_error
:
5154 mtherr ("asctoe", DOMAIN
);
5163 /* Exponent interpretation */
5165 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5166 for (k
= 0; k
< NI
; k
++)
5177 /* check for + or - */
5185 while (ISDIGIT (*s
))
5194 if ((exp
> MAXDECEXP
) && (base
== 10))
5198 yy
[E
] = 0x7fff; /* infinity */
5201 if ((exp
< MINDECEXP
) && (base
== 10))
5211 /* Base 16 hexadecimal floating constant. */
5212 if ((k
= enormlz (yy
)) > NBITS
)
5217 /* Adjust the exponent. NEXP is the number of hex digits,
5218 EXP is a power of 2. */
5219 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5229 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5230 while ((nexp
> 0) && (yy
[2] == 0))
5242 if ((k
= enormlz (yy
)) > NBITS
)
5247 lexp
= (EXONE
- 1 + NBITS
) - k
;
5248 emdnorm (yy
, lost
, 0, lexp
, 64);
5251 /* Convert to external format:
5253 Multiply by 10**nexp. If precision is 64 bits,
5254 the maximum relative error incurred in forming 10**n
5255 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5256 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5257 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5272 /* Punt. Can't handle this without 2 divides. */
5273 emovi (etens
[0], tt
);
5286 emul (etens
[i
], xt
, xt
);
5290 while (exp
<= MAXP
);
5309 /* Round and convert directly to the destination type */
5311 lexp
-= EXONE
- 0x3ff;
5313 else if (oprec
== 24 || oprec
== 32)
5314 lexp
-= (EXONE
- 0x7f);
5317 else if (oprec
== 24 || oprec
== 56)
5318 lexp
-= EXONE
- (0x41 << 2);
5321 else if (oprec
== 24)
5322 lexp
-= dec_f
.adjustment
;
5323 else if (oprec
== 56)
5326 lexp
-= dec_g
.adjustment
;
5328 lexp
-= dec_d
.adjustment
;
5331 else if (oprec
== 24)
5332 lexp
-= EXONE
- 0177;
5337 emdnorm (yy
, lost
, 0, lexp
, 64);
5352 toibm (yy
, y
, DFmode
);
5357 toc4x (yy
, y
, HFmode
);
5370 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5383 /* Return Y = largest integer not greater than X (truncated toward minus
5386 static const UEMUSHORT bmask
[] =
5409 const UEMUSHORT x
[];
5416 emov (x
, f
); /* leave in external format */
5417 expon
= (int) f
[NE
- 1];
5418 e
= (expon
& 0x7fff) - (EXONE
- 1);
5424 /* number of bits to clear out */
5436 /* clear the remaining bits */
5438 /* truncate negatives toward minus infinity */
5441 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5443 for (i
= 0; i
< NE
- 1; i
++)
5456 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5457 For example, 1.1 = 0.55 * 2^1. */
5461 const UEMUSHORT x
[];
5469 /* Handle denormalized numbers properly using long integer exponent. */
5470 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5478 *exp
= (int) (li
- 0x3ffe);
5482 /* Return e type Y = X * 2^PWR2. */
5486 const UEMUSHORT x
[];
5498 emdnorm (xi
, i
, i
, li
, !ROUND_TOWARDS_ZERO
);
5504 /* C = remainder after dividing B by A, all e type values.
5505 Least significant integer quotient bits left in EQUOT. */
5509 const UEMUSHORT a
[], b
[];
5512 UEMUSHORT den
[NI
], num
[NI
];
5516 || (ecmp (a
, ezero
) == 0)
5524 if (ecmp (a
, ezero
) == 0)
5526 mtherr ("eremain", SING
);
5532 eiremain (den
, num
);
5533 /* Sign of remainder = sign of quotient */
5542 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5543 remainder in NUM. */
5547 UEMUSHORT den
[], num
[];
5553 ld
-= enormlz (den
);
5555 ln
-= enormlz (num
);
5559 if (ecmpm (den
, num
) <= 0)
5571 emdnorm (num
, 0, 0, ln
, 0);
5574 /* Report an error condition CODE encountered in function NAME.
5576 Mnemonic Value Significance
5578 DOMAIN 1 argument domain error
5579 SING 2 function singularity
5580 OVERFLOW 3 overflow range error
5581 UNDERFLOW 4 underflow range error
5582 TLOSS 5 total loss of precision
5583 PLOSS 6 partial loss of precision
5584 INVALID 7 NaN - producing operation
5585 EDOM 33 Unix domain error code
5586 ERANGE 34 Unix range error code
5588 The order of appearance of the following messages is bound to the
5589 error codes defined above. */
5599 /* The string passed by the calling program is supposed to be the
5600 name of the function in which the error occurred.
5601 The code argument selects which error message string will be printed. */
5603 if (strcmp (name
, "esub") == 0)
5604 name
= "subtraction";
5605 else if (strcmp (name
, "ediv") == 0)
5607 else if (strcmp (name
, "emul") == 0)
5608 name
= "multiplication";
5609 else if (strcmp (name
, "enormlz") == 0)
5610 name
= "normalization";
5611 else if (strcmp (name
, "etoasc") == 0)
5612 name
= "conversion to text";
5613 else if (strcmp (name
, "asctoe") == 0)
5615 else if (strcmp (name
, "eremain") == 0)
5617 else if (strcmp (name
, "esqrt") == 0)
5618 name
= "square root";
5623 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5624 case SING
: warning ("%s: function singularity" , name
); break;
5625 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5626 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5627 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5628 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5629 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5634 /* Set global error message word */
5639 /* Convert DEC double precision D to e type E. */
5647 ieeetoe (d
, e
, &dec_g
);
5649 ieeetoe (d
, e
, &dec_d
);
5652 /* Convert e type X to DEC double precision D. */
5662 const struct ieee_format
*fmt
;
5670 /* Adjust exponent for offsets. */
5671 exp
= (EMULONG
) xi
[E
] - fmt
->adjustment
;
5672 /* Round off to nearest or even. */
5674 rndprc
= fmt
->precision
;
5675 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5680 /* Convert exploded e-type X, that has already been rounded to
5681 56-bit precision, to DEC format double Y. */
5688 toieee (x
, y
, &dec_g
);
5690 toieee (x
, y
, &dec_d
);
5695 /* Convert IBM single/double precision to e type. */
5701 enum machine_mode mode
;
5706 ecleaz (y
); /* start with a zero */
5707 p
= y
; /* point to our number */
5708 r
= *d
; /* get IBM exponent word */
5709 if (*d
& (unsigned int) 0x8000)
5710 *p
= 0xffff; /* fill in our sign */
5711 ++p
; /* bump pointer to our exponent word */
5712 r
&= 0x7f00; /* strip the sign bit */
5713 r
>>= 6; /* shift exponent word down 6 bits */
5714 /* in fact shift by 8 right and 2 left */
5715 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5716 /* add our e type exponent offset */
5717 *p
++ = r
; /* to form our exponent */
5719 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5720 /* strip off the IBM exponent and sign bits */
5721 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5723 *p
++ = *d
++; /* fill in the rest of our mantissa */
5728 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5731 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5732 /* handle change in RADIX */
5738 /* Convert e type to IBM single/double precision. */
5744 enum machine_mode mode
;
5751 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5752 /* round off to nearest or even */
5755 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5757 toibm (xi
, d
, mode
);
5763 enum machine_mode mode
;
5816 /* Convert C4X single/double precision to e type. */
5822 enum machine_mode mode
;
5840 /* Short-circuit the zero case. */
5841 if ((dn
[0] == 0x8000)
5842 && (dn
[1] == 0x0000)
5843 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
5854 ecleaz (y
); /* start with a zero */
5855 r
= dn
[0]; /* get sign/exponent part */
5856 if (r
& (unsigned int) 0x0080)
5858 y
[0] = 0xffff; /* fill in our sign */
5864 r
>>= 8; /* Shift exponent word down 8 bits. */
5865 if (r
& 0x80) /* Make the exponent negative if it is. */
5866 r
= r
| (~0 & ~0xff);
5870 /* Now do the high order mantissa. We don't "or" on the high bit
5871 because it is 2 (not 1) and is handled a little differently
5873 y
[M
] = dn
[0] & 0x7f;
5876 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5878 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
5886 /* Now do the two's complement on the data. */
5888 carry
= 1; /* Initially add 1 for the two's complement. */
5889 for (i
=size
+ M
; i
> M
; i
--)
5891 if (carry
&& (y
[i
] == 0x0000))
5892 /* We overflowed into the next word, carry is the same. */
5893 y
[i
] = carry
? 0x0000 : 0xffff;
5896 /* No overflow, just invert and add carry. */
5897 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5912 /* Add our e type exponent offset to form our exponent. */
5916 /* Now do the high order mantissa strip off the exponent and sign
5917 bits and add the high 1 bit. */
5918 y
[M
] = (dn
[0] & 0x7f) | 0x80;
5921 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5923 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
5933 /* Convert e type to C4X single/double precision. */
5939 enum machine_mode mode
;
5947 /* Adjust exponent for offsets. */
5948 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5950 /* Round off to nearest or even. */
5952 rndprc
= mode
== QFmode
? 24 : 32;
5953 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5955 toc4x (xi
, d
, mode
);
5961 enum machine_mode mode
;
5967 /* Short-circuit the zero case */
5968 if ((x
[0] == 0) /* Zero exponent and sign */
5970 && (x
[M
] == 0) /* The rest is for zero mantissa */
5972 /* Only check for double if necessary */
5973 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
5975 /* We have a zero. Put it into the output and return. */
5988 /* Negative number require a two's complement conversion of the
5994 i
= ((int) x
[1]) - 0x7f;
5996 /* Now add 1 to the inverted data to do the two's complement. */
6005 x
[v
] = carry
? 0x0000 : 0xffff;
6008 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6014 /* The following is a special case. The C4X negative float requires
6015 a zero in the high bit (because the format is (2 - x) x 2^m), so
6016 if a one is in that bit, we have to shift left one to get rid
6017 of it. This only occurs if the number is -1 x 2^m. */
6018 if (x
[M
+1] & 0x8000)
6020 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6021 high sign bit and shift the exponent. */
6027 i
= ((int) x
[1]) - 0x7f;
6029 if ((i
< -128) || (i
> 127))
6037 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6038 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6046 y
[0] |= ((i
& 0xff) << 8);
6050 y
[0] |= x
[M
] & 0x7f;
6056 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6057 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6062 /* Output a binary NaN bit pattern in the target machine's format. */
6064 /* If special NaN bit patterns are required, define them in tm.h
6065 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6070 #if defined (IEEE) && (INTEL_EXTENDED_IEEE_FORMAT == 0)
6071 static const UEMUSHORT TFbignan
[8] =
6072 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6073 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6081 static const UEMUSHORT XFbignan
[6] =
6082 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6083 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6091 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6092 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6100 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6101 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6108 make_nan (nan
, sign
, mode
)
6111 enum machine_mode mode
;
6117 size
= GET_MODE_BITSIZE (mode
);
6118 if (LARGEST_EXPONENT_IS_NORMAL (size
))
6120 warning ("%d-bit floats cannot hold NaNs", size
);
6121 saturate (nan
, sign
, size
, 0);
6126 /* Possibly the `reserved operand' patterns on a VAX can be
6127 used like NaN's, but probably not in the same way as IEEE. */
6128 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6130 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6132 if (REAL_WORDS_BIG_ENDIAN
)
6142 if (REAL_WORDS_BIG_ENDIAN
)
6150 if (REAL_WORDS_BIG_ENDIAN
)
6159 if (REAL_WORDS_BIG_ENDIAN
)
6169 if (REAL_WORDS_BIG_ENDIAN
)
6170 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6173 if (! REAL_WORDS_BIG_ENDIAN
)
6174 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6179 /* Create a saturation value for a SIZE-bit float, assuming that
6180 LARGEST_EXPONENT_IS_NORMAL (SIZE).
6182 If SIGN is true, fill X with the most negative value, otherwise fill
6183 it with the most positive value. WARN is true if the function should
6184 warn about overflow. */
6187 saturate (x
, sign
, size
, warn
)
6189 int sign
, size
, warn
;
6193 if (warn
&& extra_warnings
)
6194 warning ("value exceeds the range of a %d-bit float", size
);
6196 /* Create the most negative value. */
6197 for (i
= 0; i
< size
/ EMUSHORT_SIZE
; i
++)
6200 /* Make it positive, if necessary. */
6202 x
[REAL_WORDS_BIG_ENDIAN
? 0 : i
- 1] = 0x7fff;
6206 /* This is the inverse of the function `etarsingle' invoked by
6207 REAL_VALUE_TO_TARGET_SINGLE. */
6210 ereal_unto_float (f
)
6217 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6218 This is the inverse operation to what the function `endian' does. */
6219 if (REAL_WORDS_BIG_ENDIAN
)
6221 s
[0] = (UEMUSHORT
) (f
>> 16);
6222 s
[1] = (UEMUSHORT
) f
;
6226 s
[0] = (UEMUSHORT
) f
;
6227 s
[1] = (UEMUSHORT
) (f
>> 16);
6229 /* Convert and promote the target float to E-type. */
6231 /* Output E-type to REAL_VALUE_TYPE. */
6237 /* This is the inverse of the function `etardouble' invoked by
6238 REAL_VALUE_TO_TARGET_DOUBLE. */
6241 ereal_unto_double (d
)
6248 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6249 if (REAL_WORDS_BIG_ENDIAN
)
6251 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6252 s
[1] = (UEMUSHORT
) d
[0];
6253 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6254 s
[3] = (UEMUSHORT
) d
[1];
6258 /* Target float words are little-endian. */
6259 s
[0] = (UEMUSHORT
) d
[0];
6260 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6261 s
[2] = (UEMUSHORT
) d
[1];
6262 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6264 /* Convert target double to E-type. */
6266 /* Output E-type to REAL_VALUE_TYPE. */
6272 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6273 This is somewhat like ereal_unto_float, but the input types
6274 for these are different. */
6277 ereal_from_float (f
)
6284 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6285 This is the inverse operation to what the function `endian' does. */
6286 if (REAL_WORDS_BIG_ENDIAN
)
6288 s
[0] = (UEMUSHORT
) (f
>> 16);
6289 s
[1] = (UEMUSHORT
) f
;
6293 s
[0] = (UEMUSHORT
) f
;
6294 s
[1] = (UEMUSHORT
) (f
>> 16);
6296 /* Convert and promote the target float to E-type. */
6298 /* Output E-type to REAL_VALUE_TYPE. */
6304 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6305 This is somewhat like ereal_unto_double, but the input types
6306 for these are different.
6308 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6309 data format, with no holes in the bit packing. The first element
6310 of the input array holds the bits that would come first in the
6311 target computer's memory. */
6314 ereal_from_double (d
)
6321 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6322 if (REAL_WORDS_BIG_ENDIAN
)
6324 #if HOST_BITS_PER_WIDE_INT == 32
6325 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6326 s
[1] = (UEMUSHORT
) d
[0];
6327 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6328 s
[3] = (UEMUSHORT
) d
[1];
6330 /* In this case the entire target double is contained in the
6331 first array element. The second element of the input is
6333 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6334 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6335 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6336 s
[3] = (UEMUSHORT
) d
[0];
6341 /* Target float words are little-endian. */
6342 s
[0] = (UEMUSHORT
) d
[0];
6343 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6344 #if HOST_BITS_PER_WIDE_INT == 32
6345 s
[2] = (UEMUSHORT
) d
[1];
6346 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6348 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6349 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6352 /* Convert target double to E-type. */
6354 /* Output E-type to REAL_VALUE_TYPE. */
6361 /* Convert target computer unsigned 64-bit integer to e-type.
6362 The endian-ness of DImode follows the convention for integers,
6363 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6367 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6374 if (WORDS_BIG_ENDIAN
)
6376 for (k
= M
; k
< M
+ 4; k
++)
6381 for (k
= M
+ 3; k
>= M
; k
--)
6384 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6385 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6386 ecleaz (yi
); /* it was zero */
6388 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6392 /* Convert target computer signed 64-bit integer to e-type. */
6396 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6399 unsigned EMULONG acc
;
6405 if (WORDS_BIG_ENDIAN
)
6407 for (k
= M
; k
< M
+ 4; k
++)
6412 for (k
= M
+ 3; k
>= M
; k
--)
6415 /* Take absolute value */
6421 for (k
= M
+ 3; k
>= M
; k
--)
6423 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6430 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6431 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6432 ecleaz (yi
); /* it was zero */
6434 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6441 /* Convert e-type to unsigned 64-bit int. */
6457 k
= (int) xi
[E
] - (EXONE
- 1);
6460 for (j
= 0; j
< 4; j
++)
6466 for (j
= 0; j
< 4; j
++)
6469 warning ("overflow on truncation to integer");
6474 /* Shift more than 16 bits: first shift up k-16 mod 16,
6475 then shift up by 16's. */
6476 j
= k
- ((k
>> 4) << 4);
6480 if (WORDS_BIG_ENDIAN
)
6491 if (WORDS_BIG_ENDIAN
)
6496 while ((k
-= 16) > 0);
6500 /* shift not more than 16 bits */
6505 if (WORDS_BIG_ENDIAN
)
6524 /* Convert e-type to signed 64-bit int. */
6531 unsigned EMULONG acc
;
6538 k
= (int) xi
[E
] - (EXONE
- 1);
6541 for (j
= 0; j
< 4; j
++)
6547 for (j
= 0; j
< 4; j
++)
6550 warning ("overflow on truncation to integer");
6556 /* Shift more than 16 bits: first shift up k-16 mod 16,
6557 then shift up by 16's. */
6558 j
= k
- ((k
>> 4) << 4);
6562 if (WORDS_BIG_ENDIAN
)
6573 if (WORDS_BIG_ENDIAN
)
6578 while ((k
-= 16) > 0);
6582 /* shift not more than 16 bits */
6585 if (WORDS_BIG_ENDIAN
)
6601 /* Negate if negative */
6605 if (WORDS_BIG_ENDIAN
)
6607 for (k
= 0; k
< 4; k
++)
6609 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6610 if (WORDS_BIG_ENDIAN
)
6622 /* Longhand square root routine. */
6625 static int esqinited
= 0;
6626 static unsigned short sqrndbit
[NI
];
6633 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6635 int i
, j
, k
, n
, nlups
;
6640 sqrndbit
[NI
- 2] = 1;
6643 /* Check for arg <= 0 */
6644 i
= ecmp (x
, ezero
);
6649 mtherr ("esqrt", DOMAIN
);
6665 /* Bring in the arg and renormalize if it is denormal. */
6667 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6671 /* Divide exponent by 2 */
6673 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6675 /* Adjust if exponent odd */
6685 n
= 8; /* get 8 bits of result per inner loop */
6691 /* bring in next word of arg */
6693 num
[NI
- 1] = xx
[j
+ 3];
6694 /* Do additional bit on last outer loop, for roundoff. */
6697 for (i
= 0; i
< n
; i
++)
6699 /* Next 2 bits of arg */
6702 /* Shift up answer */
6704 /* Make trial divisor */
6705 for (k
= 0; k
< NI
; k
++)
6708 eaddm (sqrndbit
, temp
);
6709 /* Subtract and insert answer bit if it goes in */
6710 if (ecmpm (temp
, num
) <= 0)
6720 /* Adjust for extra, roundoff loop done. */
6721 exp
+= (NBITS
- 1) - rndprc
;
6723 /* Sticky bit = 1 if the remainder is nonzero. */
6725 for (i
= 3; i
< NI
; i
++)
6728 /* Renormalize and round off. */
6729 emdnorm (sq
, k
, 0, exp
, !ROUND_TOWARDS_ZERO
);
6734 /* Return the binary precision of the significand for a given
6735 floating point mode. The mode can hold an integer value
6736 that many bits wide, without losing any bits. */
6739 significand_size (mode
)
6740 enum machine_mode mode
;
6743 /* Don't test the modes, but their sizes, lest this
6744 code won't work for BITS_PER_UNIT != 8 . */
6746 switch (GET_MODE_BITSIZE (mode
))
6767 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)