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
30 /* To enable support of XFmode extended real floating point, define
31 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
33 Machine files (tm.h etc) must not contain any code
34 that tries to use host floating point arithmetic to convert
35 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
36 etc. In cross-compile situations a REAL_VALUE_TYPE may not
37 be intelligible to the host computer's native arithmetic.
39 The first part of this file interfaces gcc to a floating point
40 arithmetic suite that was not written with gcc in mind. Avoid
41 changing the low-level arithmetic routines unless you have suitable
42 test programs available. A special version of the PARANOIA floating
43 point arithmetic tester, modified for this purpose, can be found on
44 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
45 XFmode and TFmode transcendental functions, can be obtained by ftp from
46 netlib.att.com: netlib/cephes. */
48 /* Type of computer arithmetic.
49 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
51 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
52 to big-endian IEEE floating-point data structure. This definition
53 should work in SFmode `float' type and DFmode `double' type on
54 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
55 has been defined to be 96, then IEEE also invokes the particular
56 XFmode (`long double' type) data structure used by the Motorola
57 680x0 series processors.
59 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
60 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
61 has been defined to be 96, then IEEE also invokes the particular
62 XFmode `long double' data structure used by the Intel 80x86 series
65 `DEC' refers specifically to the Digital Equipment Corp PDP-11
66 and VAX floating point data structure. This model currently
67 supports no type wider than DFmode.
69 `IBM' refers specifically to the IBM System/370 and compatible
70 floating point data structure. This model currently supports
71 no type wider than DFmode. The IBM conversions were contributed by
72 frank@atom.ansto.gov.au (Frank Crawford).
74 `C4X' refers specifically to the floating point format used on
75 Texas Instruments TMS320C3x and TMS320C4x digital signal
76 processors. This supports QFmode (32-bit float, double) and HFmode
77 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
78 floats, C4x floats are not rounded to be even. The C4x conversions
79 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
80 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
82 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
83 then `long double' and `double' are both implemented, but they
86 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
87 and may deactivate XFmode since `long double' is used to refer
88 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
89 at the same time enables 80387-style 80-bit floats in a 128-bit
90 padded image, as seen on IA-64.
92 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
93 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
94 separate the floating point unit's endian-ness from that of
95 the integer addressing. This permits one to define a big-endian
96 FPU on a little-endian machine (e.g., ARM). An extension to
97 BYTES_BIG_ENDIAN may be required for some machines in the future.
98 These optional macros may be defined in tm.h. In real.h, they
99 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
100 them for any normal host or target machine on which the floats
101 and the integers have the same endian-ness. */
104 /* The following converts gcc macros into the ones used by this file. */
106 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
107 /* PDP-11, Pro350, VAX: */
109 #else /* it's not VAX */
110 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
111 /* IBM System/370 style */
113 #else /* it's also not an IBM */
114 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
115 /* TMS320C3x/C4x style */
117 #else /* it's also not a C4X */
118 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
120 #else /* it's not IEEE either */
121 /* UNKnown arithmetic. We don't support this and can't go on. */
122 unknown arithmetic type
124 #endif /* not IEEE */
129 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
131 /* Define INFINITY for support of infinity.
132 Define NANS for support of Not-a-Number's (NaN's). */
133 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
138 /* Support of NaNs requires support of infinity. */
145 /* Find a host integer type that is at least 16 bits wide,
146 and another type at least twice whatever that size is. */
148 #if HOST_BITS_PER_CHAR >= 16
149 #define EMUSHORT char
150 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
151 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
153 #if HOST_BITS_PER_SHORT >= 16
154 #define EMUSHORT short
155 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
156 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
158 #if HOST_BITS_PER_INT >= 16
160 #define EMUSHORT_SIZE HOST_BITS_PER_INT
161 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
163 #if HOST_BITS_PER_LONG >= 16
164 #define EMUSHORT long
165 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
166 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
168 #error "You will have to modify this program to have a smaller unit size."
174 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
175 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
176 typedef int HItype
__attribute__ ((mode (HI
)));
177 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
181 #define EMUSHORT HItype
182 #define UEMUSHORT UHItype
183 #define EMUSHORT_SIZE 16
184 #define EMULONG_SIZE 32
186 #define UEMUSHORT unsigned EMUSHORT
189 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
190 #define EMULONG short
192 #if HOST_BITS_PER_INT >= EMULONG_SIZE
195 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
198 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
199 #define EMULONG long long int
201 #error "You will have to modify this program to have a smaller unit size."
207 #if EMUSHORT_SIZE != 16
208 #error "The host interface doesn't work if no 16-bit size exists."
211 /* Calculate the size of the generic "e" type. This always has
212 identical in-memory size to REAL_VALUE_TYPE. The sizes are supposed
213 to be the same as well, but when REAL_VALUE_TYPE_SIZE is not evenly
214 divisible by HOST_BITS_PER_WIDE_INT we have some padding in
216 There are only two supported sizes: ten and six 16-bit words (160
219 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !INTEL_EXTENDED_IEEE_FORMAT
222 # define MAXDECEXP 4932
223 # define MINDECEXP -4977
226 # define MAXDECEXP 4932
227 # define MINDECEXP -4956
230 /* Fail compilation if 2*NE is not the appropriate size.
231 If HOST_BITS_PER_WIDE_INT is 64, we're going to have padding
232 at the end of the array, because neither 96 nor 160 is
233 evenly divisible by 64. */
234 struct compile_test_dummy
{
235 char twice_NE_must_equal_sizeof_REAL_VALUE_TYPE
236 [(sizeof (REAL_VALUE_TYPE
) >= 2*NE
) ? 1 : -1];
239 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
240 In GET_REAL and PUT_REAL, r and e are pointers.
241 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
242 in memory, with no holes. */
243 #define GET_REAL(r, e) memcpy ((e), (r), 2*NE)
244 #define PUT_REAL(e, r) \
246 memcpy (r, e, 2*NE); \
247 if (2*NE < sizeof (*r)) \
248 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
251 /* Number of 16 bit words in internal format */
254 /* Array offset to exponent */
257 /* Array offset to high guard word */
260 /* Number of bits of precision */
261 #define NBITS ((NI-4)*16)
263 /* Maximum number of decimal digits in ASCII conversion
266 #define NDEC (NBITS*8/27)
268 /* The exponent of 1.0 */
269 #define EXONE (0x3fff)
271 #if defined(HOST_EBCDIC)
272 /* bit 8 is significant in EBCDIC */
273 #define CHARMASK 0xff
275 #define CHARMASK 0x7f
278 extern int extra_warnings
;
279 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
280 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
282 static void endian
PARAMS ((const UEMUSHORT
*, long *,
284 static void eclear
PARAMS ((UEMUSHORT
*));
285 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
287 static void eabs
PARAMS ((UEMUSHORT
*));
289 static void eneg
PARAMS ((UEMUSHORT
*));
290 static int eisneg
PARAMS ((const UEMUSHORT
*));
291 static int eisinf
PARAMS ((const UEMUSHORT
*));
292 static int eisnan
PARAMS ((const UEMUSHORT
*));
293 static void einfin
PARAMS ((UEMUSHORT
*));
295 static void enan
PARAMS ((UEMUSHORT
*, int));
296 static void einan
PARAMS ((UEMUSHORT
*));
297 static int eiisnan
PARAMS ((const UEMUSHORT
*));
298 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
300 static int eiisneg
PARAMS ((const UEMUSHORT
*));
301 static void saturate
PARAMS ((UEMUSHORT
*, int, int, int));
302 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
303 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
304 static void ecleaz
PARAMS ((UEMUSHORT
*));
305 static void ecleazs
PARAMS ((UEMUSHORT
*));
306 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
308 static void eiinfin
PARAMS ((UEMUSHORT
*));
311 static int eiisinf
PARAMS ((const UEMUSHORT
*));
313 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
314 static void eshdn1
PARAMS ((UEMUSHORT
*));
315 static void eshup1
PARAMS ((UEMUSHORT
*));
316 static void eshdn8
PARAMS ((UEMUSHORT
*));
317 static void eshup8
PARAMS ((UEMUSHORT
*));
318 static void eshup6
PARAMS ((UEMUSHORT
*));
319 static void eshdn6
PARAMS ((UEMUSHORT
*));
320 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
321 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
322 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
323 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
324 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
325 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
326 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
328 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
330 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
332 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
334 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
336 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
337 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
338 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
339 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
341 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
342 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
343 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
344 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
346 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
347 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
348 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
349 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
350 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
351 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
352 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
354 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
356 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
357 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
358 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
360 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
362 static int eshift
PARAMS ((UEMUSHORT
*, int));
363 static int enormlz
PARAMS ((UEMUSHORT
*));
365 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
366 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
367 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
368 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
370 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
371 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
372 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
373 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
374 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
375 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
377 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
378 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
379 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
381 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
384 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
386 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
389 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
390 static void mtherr
PARAMS ((const char *, int));
392 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
393 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
394 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
397 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
399 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
401 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
405 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
407 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
409 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
413 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
414 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
415 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
416 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
417 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
420 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
421 swapping ends if required, into output array of longs. The
422 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
428 enum machine_mode mode
;
432 if (REAL_WORDS_BIG_ENDIAN
)
437 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
438 /* Swap halfwords in the fourth long. */
439 th
= (unsigned long) e
[6] & 0xffff;
440 t
= (unsigned long) e
[7] & 0xffff;
449 /* Swap halfwords in the third long. */
450 th
= (unsigned long) e
[4] & 0xffff;
451 t
= (unsigned long) e
[5] & 0xffff;
457 /* Swap halfwords in the second word. */
458 th
= (unsigned long) e
[2] & 0xffff;
459 t
= (unsigned long) e
[3] & 0xffff;
466 /* Swap halfwords in the first word. */
467 th
= (unsigned long) e
[0] & 0xffff;
468 t
= (unsigned long) e
[1] & 0xffff;
479 /* Pack the output array without swapping. */
484 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
485 /* Pack the fourth long. */
486 th
= (unsigned long) e
[7] & 0xffff;
487 t
= (unsigned long) e
[6] & 0xffff;
496 /* Pack the third long.
497 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
499 th
= (unsigned long) e
[5] & 0xffff;
500 t
= (unsigned long) e
[4] & 0xffff;
506 /* Pack the second long */
507 th
= (unsigned long) e
[3] & 0xffff;
508 t
= (unsigned long) e
[2] & 0xffff;
515 /* Pack the first long */
516 th
= (unsigned long) e
[1] & 0xffff;
517 t
= (unsigned long) e
[0] & 0xffff;
529 /* This is the implementation of the REAL_ARITHMETIC macro. */
532 earith (value
, icode
, r1
, r2
)
533 REAL_VALUE_TYPE
*value
;
538 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
544 /* Return NaN input back to the caller. */
547 PUT_REAL (d1
, value
);
552 PUT_REAL (d2
, value
);
556 code
= (enum tree_code
) icode
;
564 esub (d2
, d1
, v
); /* d1 - d2 */
573 if (ecmp (d2
, ezero
) == 0)
576 ediv (d2
, d1
, v
); /* d1/d2 */
579 case MIN_EXPR
: /* min (d1,d2) */
580 if (ecmp (d1
, d2
) < 0)
586 case MAX_EXPR
: /* max (d1,d2) */
587 if (ecmp (d1
, d2
) > 0)
600 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
601 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
607 UEMUSHORT f
[NE
], g
[NE
];
623 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
624 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
630 UEMUSHORT f
[NE
], g
[NE
];
632 unsigned HOST_WIDE_INT l
;
646 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
647 string to binary, rounding off as indicated by the machine_mode argument.
648 Then it promotes the rounded value to REAL_VALUE_TYPE. */
655 UEMUSHORT tem
[NE
], e
[NE
];
681 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
701 /* Expansion of REAL_NEGATE. */
717 /* Round real toward zero to HOST_WIDE_INT;
718 implements REAL_VALUE_FIX (x). */
724 UEMUSHORT f
[NE
], g
[NE
];
731 warning ("conversion from NaN to int");
739 /* Round real toward zero to unsigned HOST_WIDE_INT
740 implements REAL_VALUE_UNSIGNED_FIX (x).
741 Negative input returns zero. */
743 unsigned HOST_WIDE_INT
747 UEMUSHORT f
[NE
], g
[NE
];
748 unsigned HOST_WIDE_INT l
;
754 warning ("conversion from NaN to unsigned int");
763 /* REAL_VALUE_FROM_INT macro. */
766 ereal_from_int (d
, i
, j
, mode
)
769 enum machine_mode mode
;
771 UEMUSHORT df
[NE
], dg
[NE
];
772 HOST_WIDE_INT low
, high
;
775 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
782 /* complement and add 1 */
789 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
790 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
792 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
797 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
798 Avoid double-rounding errors later by rounding off now from the
799 extra-wide internal format to the requested precision. */
800 switch (GET_MODE_BITSIZE (mode
))
818 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
835 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
838 ereal_from_uint (d
, i
, j
, mode
)
840 unsigned HOST_WIDE_INT i
, j
;
841 enum machine_mode mode
;
843 UEMUSHORT df
[NE
], dg
[NE
];
844 unsigned HOST_WIDE_INT low
, high
;
846 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
850 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
856 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
857 Avoid double-rounding errors later by rounding off now from the
858 extra-wide internal format to the requested precision. */
859 switch (GET_MODE_BITSIZE (mode
))
877 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
894 /* REAL_VALUE_TO_INT macro. */
897 ereal_to_int (low
, high
, rr
)
898 HOST_WIDE_INT
*low
, *high
;
901 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
908 warning ("conversion from NaN to int");
914 /* convert positive value */
921 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
922 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
923 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
924 emul (df
, dh
, dg
); /* fractional part is the low word */
925 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
928 /* complement and add 1 */
938 /* REAL_VALUE_LDEXP macro. */
945 UEMUSHORT e
[NE
], y
[NE
];
958 /* Check for infinity in a REAL_VALUE_TYPE. */
962 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
974 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
978 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
991 /* Check for a negative REAL_VALUE_TYPE number.
992 This just checks the sign bit, so that -0 counts as negative. */
998 return ereal_isneg (x
);
1001 /* Expansion of REAL_VALUE_TRUNCATE.
1002 The result is in floating point, rounded to nearest or even. */
1005 real_value_truncate (mode
, arg
)
1006 enum machine_mode mode
;
1007 REAL_VALUE_TYPE arg
;
1009 UEMUSHORT e
[NE
], t
[NE
];
1021 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1058 /* If an unsupported type was requested, presume that
1059 the machine files know something useful to do with
1060 the unmodified value. */
1069 /* Try to change R into its exact multiplicative inverse in machine mode
1070 MODE. Return nonzero function value if successful. */
1073 exact_real_inverse (mode
, r
)
1074 enum machine_mode mode
;
1077 UEMUSHORT e
[NE
], einv
[NE
];
1078 REAL_VALUE_TYPE rinv
;
1083 /* Test for input in range. Don't transform IEEE special values. */
1084 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1087 /* Test for a power of 2: all significand bits zero except the MSB.
1088 We are assuming the target has binary (or hex) arithmetic. */
1089 if (e
[NE
- 2] != 0x8000)
1092 for (i
= 0; i
< NE
- 2; i
++)
1098 /* Compute the inverse and truncate it to the required mode. */
1099 ediv (e
, eone
, einv
);
1100 PUT_REAL (einv
, &rinv
);
1101 rinv
= real_value_truncate (mode
, rinv
);
1103 #ifdef CHECK_FLOAT_VALUE
1104 /* This check is not redundant. It may, for example, flush
1105 a supposedly IEEE denormal value to zero. */
1107 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1110 GET_REAL (&rinv
, einv
);
1112 /* Check the bits again, because the truncation might have
1113 generated an arbitrary saturation value on overflow. */
1114 if (einv
[NE
- 2] != 0x8000)
1117 for (i
= 0; i
< NE
- 2; i
++)
1123 /* Fail if the computed inverse is out of range. */
1124 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1127 /* Output the reciprocal and return success flag. */
1132 /* Used for debugging--print the value of R in human-readable format
1141 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1142 fprintf (stderr
, "%s", dstr
);
1146 /* The following routines convert REAL_VALUE_TYPE to the various floating
1147 point formats that are meaningful to supported computers.
1149 The results are returned in 32-bit pieces, each piece stored in a `long'.
1150 This is so they can be printed by statements like
1152 fprintf (file, "%lx, %lx", L[0], L[1]);
1154 that will work on both narrow- and wide-word host computers. */
1156 /* Convert R to a 128-bit long double precision value. The output array L
1157 contains four 32-bit pieces of the result, in the order they would appear
1168 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1173 endian (e
, l
, TFmode
);
1176 /* Convert R to a double extended precision value. The output array L
1177 contains three 32-bit pieces of the result, in the order they would
1178 appear in memory. */
1189 endian (e
, l
, XFmode
);
1192 /* Convert R to a double precision value. The output array L contains two
1193 32-bit pieces of the result, in the order they would appear in memory. */
1204 endian (e
, l
, DFmode
);
1207 /* Convert R to a single precision float value stored in the least-significant
1208 bits of a `long'. */
1219 endian (e
, &l
, SFmode
);
1223 /* Convert X to a decimal ASCII string S for output to an assembly
1224 language file. Note, there is no standard way to spell infinity or
1225 a NaN, so these values may require special treatment in the tm.h
1229 ereal_to_decimal (x
, s
)
1239 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1240 or -2 if either is a NaN. */
1244 REAL_VALUE_TYPE x
, y
;
1246 UEMUSHORT ex
[NE
], ey
[NE
];
1250 return (ecmp (ex
, ey
));
1253 /* Return 1 if the sign bit of X is set, else return 0. */
1262 return (eisneg (ex
));
1267 Extended precision IEEE binary floating point arithmetic routines
1269 Numbers are stored in C language as arrays of 16-bit unsigned
1270 short integers. The arguments of the routines are pointers to
1273 External e type data structure, similar to Intel 8087 chip
1274 temporary real format but possibly with a larger significand:
1276 NE-1 significand words (least significant word first,
1277 most significant bit is normally set)
1278 exponent (value = EXONE for 1.0,
1279 top bit is the sign)
1282 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1284 ei[0] sign word (0 for positive, 0xffff for negative)
1285 ei[1] biased exponent (value = EXONE for the number 1.0)
1286 ei[2] high guard word (always zero after normalization)
1288 to ei[NI-2] significand (NI-4 significand words,
1289 most significant word first,
1290 most significant bit is set)
1291 ei[NI-1] low guard word (0x8000 bit is rounding place)
1295 Routines for external format e-type numbers
1297 asctoe (string, e) ASCII string to extended double e type
1298 asctoe64 (string, &d) ASCII string to long double
1299 asctoe53 (string, &d) ASCII string to double
1300 asctoe24 (string, &f) ASCII string to single
1301 asctoeg (string, e, prec) ASCII string to specified precision
1302 e24toe (&f, e) IEEE single precision to e type
1303 e53toe (&d, e) IEEE double precision to e type
1304 e64toe (&d, e) IEEE long double precision to e type
1305 e113toe (&d, e) 128-bit long double precision to e type
1307 eabs (e) absolute value
1309 eadd (a, b, c) c = b + a
1311 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1312 -1 if a < b, -2 if either a or b is a NaN.
1313 ediv (a, b, c) c = b / a
1314 efloor (a, b) truncate to integer, toward -infinity
1315 efrexp (a, exp, s) extract exponent and significand
1316 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1317 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1318 einfin (e) set e to infinity, leaving its sign alone
1319 eldexp (a, n, b) multiply by 2**n
1321 emul (a, b, c) c = b * a
1324 eround (a, b) b = nearest integer value to a
1326 esub (a, b, c) c = b - a
1328 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1329 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1330 e64toasc (&d, str, n) 80-bit long double to ASCII string
1331 e113toasc (&d, str, n) 128-bit long double to ASCII string
1333 etoasc (e, str, n) e to ASCII string, n digits after decimal
1334 etoe24 (e, &f) convert e type to IEEE single precision
1335 etoe53 (e, &d) convert e type to IEEE double precision
1336 etoe64 (e, &d) convert e type to IEEE long double precision
1337 ltoe (&l, e) HOST_WIDE_INT to e type
1338 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1339 eisneg (e) 1 if sign bit of e != 0, else 0
1340 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1341 or is infinite (IEEE)
1342 eisnan (e) 1 if e is a NaN
1345 Routines for internal format exploded e-type numbers
1347 eaddm (ai, bi) add significands, bi = bi + ai
1349 ecleazs (ei) set ei = 0 but leave its sign alone
1350 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1351 edivm (ai, bi) divide significands, bi = bi / ai
1352 emdnorm (ai,l,s,exp) normalize and round off
1353 emovi (a, ai) convert external a to internal ai
1354 emovo (ai, a) convert internal ai to external a
1355 emovz (ai, bi) bi = ai, low guard word of bi = 0
1356 emulm (ai, bi) multiply significands, bi = bi * ai
1357 enormlz (ei) left-justify the significand
1358 eshdn1 (ai) shift significand and guards down 1 bit
1359 eshdn8 (ai) shift down 8 bits
1360 eshdn6 (ai) shift down 16 bits
1361 eshift (ai, n) shift ai n bits up (or down if n < 0)
1362 eshup1 (ai) shift significand and guards up 1 bit
1363 eshup8 (ai) shift up 8 bits
1364 eshup6 (ai) shift up 16 bits
1365 esubm (ai, bi) subtract significands, bi = bi - ai
1366 eiisinf (ai) 1 if infinite
1367 eiisnan (ai) 1 if a NaN
1368 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1369 einan (ai) set ai = NaN
1371 eiinfin (ai) set ai = infinity
1374 The result is always normalized and rounded to NI-4 word precision
1375 after each arithmetic operation.
1377 Exception flags are NOT fully supported.
1379 Signaling NaN's are NOT supported; they are treated the same
1382 Define INFINITY for support of infinity; otherwise a
1383 saturation arithmetic is implemented.
1385 Define NANS for support of Not-a-Number items; otherwise the
1386 arithmetic will never produce a NaN output, and might be confused
1388 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1389 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1390 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1393 Denormals are always supported here where appropriate (e.g., not
1394 for conversion to DEC numbers). */
1396 /* Definitions for error codes that are passed to the common error handling
1399 For Digital Equipment PDP-11 and VAX computers, certain
1400 IBM systems, and others that use numbers with a 56-bit
1401 significand, the symbol DEC should be defined. In this
1402 mode, most floating point constants are given as arrays
1403 of octal integers to eliminate decimal to binary conversion
1404 errors that might be introduced by the compiler.
1406 For computers, such as IBM PC, that follow the IEEE
1407 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1408 Std 754-1985), the symbol IEEE should be defined.
1409 These numbers have 53-bit significands. In this mode, constants
1410 are provided as arrays of hexadecimal 16 bit integers.
1411 The endian-ness of generated values is controlled by
1412 REAL_WORDS_BIG_ENDIAN.
1414 To accommodate other types of computer arithmetic, all
1415 constants are also provided in a normal decimal radix
1416 which one can hope are correctly converted to a suitable
1417 format by the available C language compiler. To invoke
1418 this mode, the symbol UNK is defined.
1420 An important difference among these modes is a predefined
1421 set of machine arithmetic constants for each. The numbers
1422 MACHEP (the machine roundoff error), MAXNUM (largest number
1423 represented), and several other parameters are preset by
1424 the configuration symbol. Check the file const.c to
1425 ensure that these values are correct for your computer.
1427 For ANSI C compatibility, define ANSIC equal to 1. Currently
1428 this affects only the atan2 function and others that use it. */
1430 /* Constant definitions for math error conditions. */
1432 #define DOMAIN 1 /* argument domain error */
1433 #define SING 2 /* argument singularity */
1434 #define OVERFLOW 3 /* overflow range error */
1435 #define UNDERFLOW 4 /* underflow range error */
1436 #define TLOSS 5 /* total loss of precision */
1437 #define PLOSS 6 /* partial loss of precision */
1438 #define INVALID 7 /* NaN-producing operation */
1440 /* e type constants used by high precision check routines */
1442 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1444 const UEMUSHORT ezero
[NE
] =
1445 {0x0000, 0x0000, 0x0000, 0x0000,
1446 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1449 const UEMUSHORT ehalf
[NE
] =
1450 {0x0000, 0x0000, 0x0000, 0x0000,
1451 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1454 const UEMUSHORT eone
[NE
] =
1455 {0x0000, 0x0000, 0x0000, 0x0000,
1456 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1459 const UEMUSHORT etwo
[NE
] =
1460 {0x0000, 0x0000, 0x0000, 0x0000,
1461 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1464 const UEMUSHORT e32
[NE
] =
1465 {0x0000, 0x0000, 0x0000, 0x0000,
1466 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1468 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1469 const UEMUSHORT elog2
[NE
] =
1470 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1471 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1473 /* 1.41421356237309504880168872420969807856967187537695E0 */
1474 const UEMUSHORT esqrt2
[NE
] =
1475 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1476 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1478 /* 3.14159265358979323846264338327950288419716939937511E0 */
1479 const UEMUSHORT epi
[NE
] =
1480 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1481 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1484 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1485 const UEMUSHORT ezero
[NE
] =
1486 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1487 const UEMUSHORT ehalf
[NE
] =
1488 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1489 const UEMUSHORT eone
[NE
] =
1490 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1491 const UEMUSHORT etwo
[NE
] =
1492 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1493 const UEMUSHORT e32
[NE
] =
1494 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1495 const UEMUSHORT elog2
[NE
] =
1496 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1497 const UEMUSHORT esqrt2
[NE
] =
1498 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1499 const UEMUSHORT epi
[NE
] =
1500 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1503 /* Control register for rounding precision.
1504 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1509 /* Clear out entire e-type number X. */
1517 for (i
= 0; i
< NE
; i
++)
1521 /* Move e-type number from A to B. */
1530 for (i
= 0; i
< NE
; i
++)
1536 /* Absolute value of e-type X. */
1542 /* sign is top bit of last word of external format */
1543 x
[NE
- 1] &= 0x7fff;
1547 /* Negate the e-type number X. */
1554 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1557 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1561 const UEMUSHORT x
[];
1564 if (x
[NE
- 1] & 0x8000)
1570 /* Return 1 if e-type number X is infinity, else return zero. */
1574 const UEMUSHORT x
[];
1581 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1587 /* Check if e-type number is not a number. The bit pattern is one that we
1588 defined, so we know for sure how to detect it. */
1592 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1597 /* NaN has maximum exponent */
1598 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1600 /* ... and non-zero significand field. */
1601 for (i
= 0; i
< NE
- 1; i
++)
1611 /* Fill e-type number X with infinity pattern (IEEE)
1612 or largest possible number (non-IEEE). */
1621 for (i
= 0; i
< NE
- 1; i
++)
1625 for (i
= 0; i
< NE
- 1; i
++)
1653 /* Output an e-type NaN.
1654 This generates Intel's quiet NaN pattern for extended real.
1655 The exponent is 7fff, the leading mantissa word is c000. */
1665 for (i
= 0; i
< NE
- 2; i
++)
1668 *x
= (sign
<< 15) | 0x7fff;
1672 /* Move in an e-type number A, converting it to exploded e-type B. */
1684 p
= a
+ (NE
- 1); /* point to last word of external number */
1685 /* get the sign bit */
1690 /* get the exponent */
1692 *q
++ &= 0x7fff; /* delete the sign bit */
1694 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1700 for (i
= 3; i
< NI
; i
++)
1706 for (i
= 2; i
< NI
; i
++)
1712 /* clear high guard word */
1714 /* move in the significand */
1715 for (i
= 0; i
< NE
- 1; i
++)
1717 /* clear low guard word */
1721 /* Move out exploded e-type number A, converting it to e type B. */
1734 q
= b
+ (NE
- 1); /* point to output exponent */
1735 /* combine sign and exponent */
1738 *q
-- = *p
++ | 0x8000;
1742 if (*(p
- 1) == 0x7fff)
1747 enan (b
, eiisneg (a
));
1755 /* skip over guard word */
1757 /* move the significand */
1758 for (j
= 0; j
< NE
- 1; j
++)
1762 /* Clear out exploded e-type number XI. */
1770 for (i
= 0; i
< NI
; i
++)
1774 /* Clear out exploded e-type XI, but don't touch the sign. */
1783 for (i
= 0; i
< NI
- 1; i
++)
1787 /* Move exploded e-type number from A to B. */
1796 for (i
= 0; i
< NI
- 1; i
++)
1798 /* clear low guard word */
1802 /* Generate exploded e-type NaN.
1803 The explicit pattern for this is maximum exponent and
1804 top two significant bits set. */
1818 /* Return nonzero if exploded e-type X is a NaN. */
1823 const UEMUSHORT x
[];
1827 if ((x
[E
] & 0x7fff) == 0x7fff)
1829 for (i
= M
+ 1; i
< NI
; i
++)
1839 /* Return nonzero if sign of exploded e-type X is nonzero. */
1843 const UEMUSHORT x
[];
1850 /* Fill exploded e-type X with infinity pattern.
1851 This has maximum exponent and significand all zeros. */
1863 /* Return nonzero if exploded e-type X is infinite. */
1868 const UEMUSHORT x
[];
1875 if ((x
[E
] & 0x7fff) == 0x7fff)
1879 #endif /* INFINITY */
1881 /* Compare significands of numbers in internal exploded e-type format.
1882 Guard words are included in the comparison.
1890 const UEMUSHORT
*a
, *b
;
1894 a
+= M
; /* skip up to significand area */
1896 for (i
= M
; i
< NI
; i
++)
1904 if (*(--a
) > *(--b
))
1910 /* Shift significand of exploded e-type X down by 1 bit. */
1919 x
+= M
; /* point to significand area */
1922 for (i
= M
; i
< NI
; i
++)
1934 /* Shift significand of exploded e-type X up by 1 bit. */
1946 for (i
= M
; i
< NI
; i
++)
1959 /* Shift significand of exploded e-type X down by 8 bits. */
1965 UEMUSHORT newbyt
, oldbyt
;
1970 for (i
= M
; i
< NI
; i
++)
1980 /* Shift significand of exploded e-type X up by 8 bits. */
1987 UEMUSHORT newbyt
, oldbyt
;
1992 for (i
= M
; i
< NI
; i
++)
2002 /* Shift significand of exploded e-type X up by 16 bits. */
2014 for (i
= M
; i
< NI
- 1; i
++)
2020 /* Shift significand of exploded e-type X down by 16 bits. */
2032 for (i
= M
; i
< NI
- 1; i
++)
2038 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2052 for (i
= M
; i
< NI
; i
++)
2054 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2065 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2079 for (i
= M
; i
< NI
; i
++)
2081 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2093 static UEMUSHORT equot
[NI
];
2097 /* Radix 2 shift-and-add versions of multiply and divide */
2100 /* Divide significands */
2104 UEMUSHORT den
[], num
[];
2114 for (i
= M
; i
< NI
; i
++)
2119 /* Use faster compare and subtraction if denominator has only 15 bits of
2125 for (i
= M
+ 3; i
< NI
; i
++)
2130 if ((den
[M
+ 1] & 1) != 0)
2138 for (i
= 0; i
< NBITS
+ 2; i
++)
2156 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2157 bit + 1 roundoff bit. */
2162 for (i
= 0; i
< NBITS
+ 2; i
++)
2164 if (ecmpm (den
, num
) <= 0)
2167 j
= 1; /* quotient bit = 1 */
2181 /* test for nonzero remainder after roundoff bit */
2184 for (i
= M
; i
< NI
; i
++)
2192 for (i
= 0; i
< NI
; i
++)
2198 /* Multiply significands */
2209 for (i
= M
; i
< NI
; i
++)
2214 while (*p
== 0) /* significand is not supposed to be zero */
2219 if ((*p
& 0xff) == 0)
2227 for (i
= 0; i
< k
; i
++)
2231 /* remember if there were any nonzero bits shifted out */
2238 for (i
= 0; i
< NI
; i
++)
2241 /* return flag for lost nonzero bits */
2247 /* Radix 65536 versions of multiply and divide. */
2249 /* Multiply significand of e-type number B
2250 by 16-bit quantity A, return e-type result to C. */
2255 const UEMUSHORT b
[];
2259 unsigned EMULONG carry
;
2260 const UEMUSHORT
*ps
;
2262 unsigned EMULONG aa
, m
;
2271 for (i
=M
+1; i
<NI
; i
++)
2281 m
= (unsigned EMULONG
) aa
* *ps
--;
2282 carry
= (m
& 0xffff) + *pp
;
2283 *pp
-- = (UEMUSHORT
) carry
;
2284 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2285 *pp
= (UEMUSHORT
) carry
;
2286 *(pp
-1) = carry
>> 16;
2289 for (i
=M
; i
<NI
; i
++)
2293 /* Divide significands of exploded e-types NUM / DEN. Neither the
2294 numerator NUM nor the denominator DEN is permitted to have its high guard
2299 const UEMUSHORT den
[];
2304 unsigned EMULONG tnum
;
2305 UEMUSHORT j
, tdenm
, tquot
;
2306 UEMUSHORT tprod
[NI
+1];
2312 for (i
=M
; i
<NI
; i
++)
2318 for (i
=M
; i
<NI
; i
++)
2320 /* Find trial quotient digit (the radix is 65536). */
2321 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2323 /* Do not execute the divide instruction if it will overflow. */
2324 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2327 tquot
= tnum
/ tdenm
;
2328 /* Multiply denominator by trial quotient digit. */
2329 m16m ((unsigned int) tquot
, den
, tprod
);
2330 /* The quotient digit may have been overestimated. */
2331 if (ecmpm (tprod
, num
) > 0)
2335 if (ecmpm (tprod
, num
) > 0)
2345 /* test for nonzero remainder after roundoff bit */
2348 for (i
=M
; i
<NI
; i
++)
2355 for (i
=0; i
<NI
; i
++)
2361 /* Multiply significands of exploded e-type A and B, result in B. */
2365 const UEMUSHORT a
[];
2370 UEMUSHORT pprod
[NI
];
2376 for (i
=M
; i
<NI
; i
++)
2382 for (i
=M
+1; i
<NI
; i
++)
2390 m16m ((unsigned int) *p
--, b
, pprod
);
2391 eaddm (pprod
, equot
);
2397 for (i
=0; i
<NI
; i
++)
2400 /* return flag for lost nonzero bits */
2406 /* Normalize and round off.
2408 The internal format number to be rounded is S.
2409 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2411 Input SUBFLG indicates whether the number was obtained
2412 by a subtraction operation. In that case if LOST is nonzero
2413 then the number is slightly smaller than indicated.
2415 Input EXP is the biased exponent, which may be negative.
2416 the exponent field of S is ignored but is replaced by
2417 EXP as adjusted by normalization and rounding.
2419 Input RCNTRL is the rounding control. If it is nonzero, the
2420 returned value will be rounded to RNDPRC bits.
2422 For future reference: In order for emdnorm to round off denormal
2423 significands at the right point, the input exponent must be
2424 adjusted to be the actual value it would have after conversion to
2425 the final floating point type. This adjustment has been
2426 implemented for all type conversions (etoe53, etc.) and decimal
2427 conversions, but not for the arithmetic functions (eadd, etc.).
2428 Data types having standard 15-bit exponents are not affected by
2429 this, but SFmode and DFmode are affected. For example, ediv with
2430 rndprc = 24 will not round correctly to 24-bit precision if the
2431 result is denormal. */
2433 static int rlast
= -1;
2435 static UEMUSHORT rmsk
= 0;
2436 static UEMUSHORT rmbit
= 0;
2437 static UEMUSHORT rebit
= 0;
2439 static UEMUSHORT rbit
[NI
];
2442 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2455 /* a blank significand could mean either zero or infinity. */
2468 if ((j
> NBITS
) && (exp
< 32767))
2476 if (exp
> (EMULONG
) (-NBITS
- 1))
2489 /* Round off, unless told not to by rcntrl. */
2492 /* Set up rounding parameters if the control register changed. */
2493 if (rndprc
!= rlast
)
2500 rw
= NI
- 1; /* low guard word */
2523 /* For DEC or IBM arithmetic */
2540 /* For C4x arithmetic */
2561 /* Shift down 1 temporarily if the data structure has an implied
2562 most significant bit and the number is denormal.
2563 Intel long double denormals also lose one bit of precision. */
2564 if ((exp
<= 0) && (rndprc
!= NBITS
)
2565 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2567 lost
|= s
[NI
- 1] & 1;
2570 /* Clear out all bits below the rounding bit,
2571 remembering in r if any were nonzero. */
2585 if ((r
& rmbit
) != 0)
2591 { /* round to even */
2592 if ((s
[re
] & rebit
) == 0)
2605 /* Undo the temporary shift for denormal values. */
2606 if ((exp
<= 0) && (rndprc
!= NBITS
)
2607 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2612 { /* overflow on roundoff */
2625 for (i
= 2; i
< NI
- 1; i
++)
2628 warning ("floating point overflow");
2632 for (i
= M
+ 1; i
< NI
- 1; i
++)
2635 if ((rndprc
< 64) || (rndprc
== 113))
2650 s
[1] = (UEMUSHORT
) exp
;
2653 /* Subtract. C = B - A, all e type numbers. */
2655 static int subflg
= 0;
2659 const UEMUSHORT
*a
, *b
;
2674 /* Infinity minus infinity is a NaN.
2675 Test for subtracting infinities of the same sign. */
2676 if (eisinf (a
) && eisinf (b
)
2677 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2679 mtherr ("esub", INVALID
);
2688 /* Add. C = A + B, all e type. */
2692 const UEMUSHORT
*a
, *b
;
2697 /* NaN plus anything is a NaN. */
2708 /* Infinity minus infinity is a NaN.
2709 Test for adding infinities of opposite signs. */
2710 if (eisinf (a
) && eisinf (b
)
2711 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2713 mtherr ("esub", INVALID
);
2722 /* Arithmetic common to both addition and subtraction. */
2726 const UEMUSHORT
*a
, *b
;
2729 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2731 EMULONG lt
, lta
, ltb
;
2752 /* compare exponents */
2757 { /* put the larger number in bi */
2767 if (lt
< (EMULONG
) (-NBITS
- 1))
2768 goto done
; /* answer same as larger addend */
2770 lost
= eshift (ai
, k
); /* shift the smaller number down */
2774 /* exponents were the same, so must compare significands */
2777 { /* the numbers are identical in magnitude */
2778 /* if different signs, result is zero */
2784 /* if same sign, result is double */
2785 /* double denormalized tiny number */
2786 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2791 /* add 1 to exponent unless both are zero! */
2792 for (j
= 1; j
< NI
- 1; j
++)
2808 bi
[E
] = (UEMUSHORT
) ltb
;
2812 { /* put the larger number in bi */
2828 emdnorm (bi
, lost
, subflg
, ltb
, !ROUND_TOWARDS_ZERO
);
2834 /* Divide: C = B/A, all e type. */
2838 const UEMUSHORT
*a
, *b
;
2841 UEMUSHORT ai
[NI
], bi
[NI
];
2843 EMULONG lt
, lta
, ltb
;
2845 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2846 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2847 sign
= eisneg (a
) ^ eisneg (b
);
2850 /* Return any NaN input. */
2861 /* Zero over zero, or infinity over infinity, is a NaN. */
2862 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2863 || (eisinf (a
) && eisinf (b
)))
2865 mtherr ("ediv", INVALID
);
2870 /* Infinity over anything else is infinity. */
2877 /* Anything else over infinity is zero. */
2889 { /* See if numerator is zero. */
2890 for (i
= 1; i
< NI
- 1; i
++)
2894 ltb
-= enormlz (bi
);
2904 { /* possible divide by zero */
2905 for (i
= 1; i
< NI
- 1; i
++)
2909 lta
-= enormlz (ai
);
2913 /* Divide by zero is not an invalid operation.
2914 It is a divide-by-zero operation! */
2916 mtherr ("ediv", SING
);
2922 /* calculate exponent */
2923 lt
= ltb
- lta
+ EXONE
;
2924 emdnorm (bi
, i
, 0, lt
, !ROUND_TOWARDS_ZERO
);
2931 && (ecmp (c
, ezero
) != 0)
2934 *(c
+(NE
-1)) |= 0x8000;
2936 *(c
+(NE
-1)) &= ~0x8000;
2939 /* Multiply e-types A and B, return e-type product C. */
2943 const UEMUSHORT
*a
, *b
;
2946 UEMUSHORT ai
[NI
], bi
[NI
];
2948 EMULONG lt
, lta
, ltb
;
2950 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2951 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2952 sign
= eisneg (a
) ^ eisneg (b
);
2955 /* NaN times anything is the same NaN. */
2966 /* Zero times infinity is a NaN. */
2967 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2968 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2970 mtherr ("emul", INVALID
);
2975 /* Infinity times anything else is infinity. */
2977 if (eisinf (a
) || eisinf (b
))
2989 for (i
= 1; i
< NI
- 1; i
++)
2993 lta
-= enormlz (ai
);
3004 for (i
= 1; i
< NI
- 1; i
++)
3008 ltb
-= enormlz (bi
);
3017 /* Multiply significands */
3019 /* calculate exponent */
3020 lt
= lta
+ ltb
- (EXONE
- 1);
3021 emdnorm (bi
, j
, 0, lt
, !ROUND_TOWARDS_ZERO
);
3028 && (ecmp (c
, ezero
) != 0)
3031 *(c
+(NE
-1)) |= 0x8000;
3033 *(c
+(NE
-1)) &= ~0x8000;
3036 /* Convert double precision PE to e-type Y. */
3040 const UEMUSHORT
*pe
;
3050 ibmtoe (pe
, y
, DFmode
);
3055 c4xtoe (pe
, y
, HFmode
);
3065 denorm
= 0; /* flag if denormalized number */
3067 if (! REAL_WORDS_BIG_ENDIAN
)
3073 yy
[M
] = (r
& 0x0f) | 0x10;
3074 r
&= ~0x800f; /* strip sign and 4 significand bits */
3079 if (! REAL_WORDS_BIG_ENDIAN
)
3081 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3082 || (pe
[1] != 0) || (pe
[0] != 0))
3084 enan (y
, yy
[0] != 0);
3090 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3091 || (pe
[2] != 0) || (pe
[3] != 0))
3093 enan (y
, yy
[0] != 0);
3104 #endif /* INFINITY */
3106 /* If zero exponent, then the significand is denormalized.
3107 So take back the understood high significand bit. */
3118 if (! REAL_WORDS_BIG_ENDIAN
)
3135 /* If zero exponent, then normalize the significand. */
3136 if ((k
= enormlz (yy
)) > NBITS
)
3139 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3142 #endif /* not C4X */
3143 #endif /* not IBM */
3144 #endif /* not DEC */
3147 /* Convert double extended precision float PE to e type Y. */
3151 const UEMUSHORT
*pe
;
3161 for (i
= 0; i
< NE
- 5; i
++)
3163 /* This precision is not ordinarily supported on DEC or IBM. */
3165 for (i
= 0; i
< 5; i
++)
3169 p
= &yy
[0] + (NE
- 1);
3172 for (i
= 0; i
< 5; i
++)
3176 if (! REAL_WORDS_BIG_ENDIAN
)
3178 for (i
= 0; i
< 5; i
++)
3181 /* For denormal long double Intel format, shift significand up one
3182 -- but only if the top significand bit is zero. A top bit of 1
3183 is "pseudodenormal" when the exponent is zero. */
3184 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3196 p
= &yy
[0] + (NE
- 1);
3197 #ifdef ARM_EXTENDED_IEEE_FORMAT
3198 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3199 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3205 for (i
= 0; i
< 4; i
++)
3210 /* Point to the exponent field and check max exponent cases. */
3212 if ((*p
& 0x7fff) == 0x7fff)
3215 if (! REAL_WORDS_BIG_ENDIAN
)
3217 for (i
= 0; i
< 4; i
++)
3219 if ((i
!= 3 && pe
[i
] != 0)
3220 /* Anything but 0x8000 here, including 0, is a NaN. */
3221 || (i
== 3 && pe
[i
] != 0x8000))
3223 enan (y
, (*p
& 0x8000) != 0);
3230 #ifdef ARM_EXTENDED_IEEE_FORMAT
3231 for (i
= 2; i
<= 5; i
++)
3235 enan (y
, (*p
& 0x8000) != 0);
3240 /* In Motorola extended precision format, the most significant
3241 bit of an infinity mantissa could be either 1 or 0. It is
3242 the lower order bits that tell whether the value is a NaN. */
3243 if ((pe
[2] & 0x7fff) != 0)
3246 for (i
= 3; i
<= 5; i
++)
3251 enan (y
, (*p
& 0x8000) != 0);
3255 #endif /* not ARM */
3264 #endif /* INFINITY */
3267 for (i
= 0; i
< NE
; i
++)
3271 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3272 /* Convert 128-bit long double precision float PE to e type Y. */
3276 const UEMUSHORT
*pe
;
3289 if (! REAL_WORDS_BIG_ENDIAN
)
3301 if (! REAL_WORDS_BIG_ENDIAN
)
3303 for (i
= 0; i
< 7; i
++)
3307 enan (y
, yy
[0] != 0);
3314 for (i
= 1; i
< 8; i
++)
3318 enan (y
, yy
[0] != 0);
3330 #endif /* INFINITY */
3334 if (! REAL_WORDS_BIG_ENDIAN
)
3336 for (i
= 0; i
< 7; i
++)
3342 for (i
= 0; i
< 7; i
++)
3346 /* If denormal, remove the implied bit; else shift down 1. */
3360 /* Convert single precision float PE to e type Y. */
3364 const UEMUSHORT
*pe
;
3369 ibmtoe (pe
, y
, SFmode
);
3375 c4xtoe (pe
, y
, QFmode
);
3386 denorm
= 0; /* flag if denormalized number */
3389 if (! REAL_WORDS_BIG_ENDIAN
)
3399 yy
[M
] = (r
& 0x7f) | 0200;
3400 r
&= ~0x807f; /* strip sign and 7 significand bits */
3402 if (!LARGEST_EXPONENT_IS_NORMAL (32) && r
== 0x7f80)
3405 if (REAL_WORDS_BIG_ENDIAN
)
3407 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3409 enan (y
, yy
[0] != 0);
3415 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3417 enan (y
, yy
[0] != 0);
3428 #endif /* INFINITY */
3430 /* If zero exponent, then the significand is denormalized.
3431 So take back the understood high significand bit. */
3444 if (! REAL_WORDS_BIG_ENDIAN
)
3454 { /* if zero exponent, then normalize the significand */
3455 if ((k
= enormlz (yy
)) > NBITS
)
3458 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3461 #endif /* not C4X */
3462 #endif /* not IBM */
3465 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3466 /* Convert e-type X to IEEE 128-bit long double format E. */
3480 make_nan (e
, eisneg (x
), TFmode
);
3485 exp
= (EMULONG
) xi
[E
];
3490 /* round off to nearest or even */
3493 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3501 /* Convert exploded e-type X, that has already been rounded to
3502 113-bit precision, to IEEE 128-bit long double format Y. */
3514 make_nan (b
, eiisneg (a
), TFmode
);
3519 if (REAL_WORDS_BIG_ENDIAN
)
3522 q
= b
+ 7; /* point to output exponent */
3524 /* If not denormal, delete the implied bit. */
3529 /* combine sign and exponent */
3531 if (REAL_WORDS_BIG_ENDIAN
)
3534 *q
++ = *p
++ | 0x8000;
3541 *q
-- = *p
++ | 0x8000;
3545 /* skip over guard word */
3547 /* move the significand */
3548 if (REAL_WORDS_BIG_ENDIAN
)
3550 for (i
= 0; i
< 7; i
++)
3555 for (i
= 0; i
< 7; i
++)
3561 /* Convert e-type X to IEEE double extended format E. */
3575 make_nan (e
, eisneg (x
), XFmode
);
3580 /* adjust exponent for offset */
3581 exp
= (EMULONG
) xi
[E
];
3586 /* round off to nearest or even */
3589 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3597 /* Convert exploded e-type X, that has already been rounded to
3598 64-bit precision, to IEEE double extended format Y. */
3610 make_nan (b
, eiisneg (a
), XFmode
);
3614 /* Shift denormal long double Intel format significand down one bit. */
3615 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3625 if (REAL_WORDS_BIG_ENDIAN
)
3629 q
= b
+ 4; /* point to output exponent */
3630 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3631 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3632 always there, and there are never more bytes, even when we are using
3633 INTEL_EXTENDED_IEEE_FORMAT. */
3638 /* combine sign and exponent */
3642 *q
++ = *p
++ | 0x8000;
3649 *q
-- = *p
++ | 0x8000;
3654 if (REAL_WORDS_BIG_ENDIAN
)
3656 #ifdef ARM_EXTENDED_IEEE_FORMAT
3657 /* The exponent is in the lowest 15 bits of the first word. */
3658 *q
++ = i
? 0x8000 : 0;
3662 *q
++ = *p
++ | 0x8000;
3671 *q
-- = *p
++ | 0x8000;
3676 /* skip over guard word */
3678 /* move the significand */
3680 for (i
= 0; i
< 4; i
++)
3684 for (i
= 0; i
< 4; i
++)
3688 if (REAL_WORDS_BIG_ENDIAN
)
3690 for (i
= 0; i
< 4; i
++)
3698 /* Intel long double infinity significand. */
3706 for (i
= 0; i
< 4; i
++)
3712 /* e type to double precision. */
3715 /* Convert e-type X to DEC-format double E. */
3722 etodec (x
, e
); /* see etodec.c */
3725 /* Convert exploded e-type X, that has already been rounded to
3726 56-bit double precision, to DEC double Y. */
3737 /* Convert e-type X to IBM 370-format double E. */
3744 etoibm (x
, e
, DFmode
);
3747 /* Convert exploded e-type X, that has already been rounded to
3748 56-bit precision, to IBM 370 double Y. */
3754 toibm (x
, y
, DFmode
);
3757 #else /* it's neither DEC nor IBM */
3759 /* Convert e-type X to C4X-format long double E. */
3766 etoc4x (x
, e
, HFmode
);
3769 /* Convert exploded e-type X, that has already been rounded to
3770 56-bit precision, to IBM 370 double Y. */
3776 toc4x (x
, y
, HFmode
);
3779 #else /* it's neither DEC nor IBM nor C4X */
3781 /* Convert e-type X to IEEE double E. */
3795 make_nan (e
, eisneg (x
), DFmode
);
3800 /* adjust exponent for offsets */
3801 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3806 /* round off to nearest or even */
3809 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
3817 /* Convert exploded e-type X, that has already been rounded to
3818 53-bit precision, to IEEE double Y. */
3830 make_nan (y
, eiisneg (x
), DFmode
);
3834 if (LARGEST_EXPONENT_IS_NORMAL (64) && x
[1] > 2047)
3836 saturate (y
, eiisneg (x
), 64, 1);
3841 if (! REAL_WORDS_BIG_ENDIAN
)
3844 *y
= 0; /* output high order */
3846 *y
= 0x8000; /* output sign bit */
3849 if (i
>= (unsigned int) 2047)
3851 /* Saturate at largest number less than infinity. */
3854 if (! REAL_WORDS_BIG_ENDIAN
)
3868 *y
|= (UEMUSHORT
) 0x7fef;
3869 if (! REAL_WORDS_BIG_ENDIAN
)
3894 i
|= *p
++ & (UEMUSHORT
) 0x0f; /* *p = xi[M] */
3895 *y
|= (UEMUSHORT
) i
; /* high order output already has sign bit set */
3896 if (! REAL_WORDS_BIG_ENDIAN
)
3911 #endif /* not C4X */
3912 #endif /* not IBM */
3913 #endif /* not DEC */
3917 /* e type to single precision. */
3920 /* Convert e-type X to IBM 370 float E. */
3927 etoibm (x
, e
, SFmode
);
3930 /* Convert exploded e-type X, that has already been rounded to
3931 float precision, to IBM 370 float Y. */
3937 toibm (x
, y
, SFmode
);
3943 /* Convert e-type X to C4X float E. */
3950 etoc4x (x
, e
, QFmode
);
3953 /* Convert exploded e-type X, that has already been rounded to
3954 float precision, to IBM 370 float Y. */
3960 toc4x (x
, y
, QFmode
);
3965 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3979 make_nan (e
, eisneg (x
), SFmode
);
3984 /* adjust exponent for offsets */
3985 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3990 /* round off to nearest or even */
3993 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
4001 /* Convert exploded e-type X, that has already been rounded to
4002 float precision, to IEEE float Y. */
4014 make_nan (y
, eiisneg (x
), SFmode
);
4018 if (LARGEST_EXPONENT_IS_NORMAL (32) && x
[1] > 255)
4020 saturate (y
, eiisneg (x
), 32, 1);
4025 if (! REAL_WORDS_BIG_ENDIAN
)
4031 *y
= 0; /* output high order */
4033 *y
= 0x8000; /* output sign bit */
4036 /* Handle overflow cases. */
4037 if (!LARGEST_EXPONENT_IS_NORMAL (32) && i
>= 255)
4040 *y
|= (UEMUSHORT
) 0x7f80;
4045 if (! REAL_WORDS_BIG_ENDIAN
)
4053 #else /* no INFINITY */
4054 *y
|= (UEMUSHORT
) 0x7f7f;
4059 if (! REAL_WORDS_BIG_ENDIAN
)
4070 #endif /* no INFINITY */
4082 i
|= *p
++ & (UEMUSHORT
) 0x7f; /* *p = xi[M] */
4083 /* High order output already has sign bit set. */
4089 if (! REAL_WORDS_BIG_ENDIAN
)
4098 #endif /* not C4X */
4099 #endif /* not IBM */
4101 /* Compare two e type numbers.
4105 -2 if either a or b is a NaN. */
4109 const UEMUSHORT
*a
, *b
;
4111 UEMUSHORT ai
[NI
], bi
[NI
];
4117 if (eisnan (a
) || eisnan (b
))
4126 { /* the signs are different */
4128 for (i
= 1; i
< NI
- 1; i
++)
4142 /* both are the same sign */
4157 return (0); /* equality */
4161 if (*(--p
) > *(--q
))
4162 return (msign
); /* p is bigger */
4164 return (-msign
); /* p is littler */
4168 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4180 /* Convert HOST_WIDE_INT LP to e type Y. */
4184 const HOST_WIDE_INT
*lp
;
4188 unsigned HOST_WIDE_INT ll
;
4194 /* make it positive */
4195 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4196 yi
[0] = 0xffff; /* put correct sign in the e type number */
4200 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4202 /* move the long integer to yi significand area */
4203 #if HOST_BITS_PER_WIDE_INT == 64
4204 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4205 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4206 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4207 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4208 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4210 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4211 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4212 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4215 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4216 ecleaz (yi
); /* it was zero */
4218 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4219 emovo (yi
, y
); /* output the answer */
4222 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4226 const unsigned HOST_WIDE_INT
*lp
;
4230 unsigned HOST_WIDE_INT ll
;
4236 /* move the long integer to ayi significand area */
4237 #if HOST_BITS_PER_WIDE_INT == 64
4238 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4239 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4240 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4241 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4242 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4244 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4245 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4246 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4249 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4250 ecleaz (yi
); /* it was zero */
4252 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4253 emovo (yi
, y
); /* output the answer */
4257 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4258 part FRAC of e-type (packed internal format) floating point input X.
4259 The integer output I has the sign of the input, except that
4260 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4261 The output e-type fraction FRAC is the positive fractional
4272 unsigned HOST_WIDE_INT ll
;
4275 k
= (int) xi
[E
] - (EXONE
- 1);
4278 /* if exponent <= 0, integer = 0 and real output is fraction */
4283 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4285 /* long integer overflow: output large integer
4286 and correct fraction */
4288 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4291 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4292 /* In this case, let it overflow and convert as if unsigned. */
4293 euifrac (x
, &ll
, frac
);
4294 *i
= (HOST_WIDE_INT
) ll
;
4297 /* In other cases, return the largest positive integer. */
4298 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4303 warning ("overflow on truncation to integer");
4307 /* Shift more than 16 bits: first shift up k-16 mod 16,
4308 then shift up by 16's. */
4309 j
= k
- ((k
>> 4) << 4);
4316 ll
= (ll
<< 16) | xi
[M
];
4318 while ((k
-= 16) > 0);
4325 /* shift not more than 16 bits */
4327 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4334 if ((k
= enormlz (xi
)) > NBITS
)
4337 xi
[E
] -= (UEMUSHORT
) k
;
4343 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4344 FRAC of e-type X. A negative input yields integer output = 0 but
4345 correct fraction. */
4348 euifrac (x
, i
, frac
)
4350 unsigned HOST_WIDE_INT
*i
;
4353 unsigned HOST_WIDE_INT ll
;
4358 k
= (int) xi
[E
] - (EXONE
- 1);
4361 /* if exponent <= 0, integer = 0 and argument is fraction */
4366 if (k
> HOST_BITS_PER_WIDE_INT
)
4368 /* Long integer overflow: output large integer
4369 and correct fraction.
4370 Note, the BSD MicroVAX compiler says that ~(0UL)
4371 is a syntax error. */
4375 warning ("overflow on truncation to unsigned integer");
4379 /* Shift more than 16 bits: first shift up k-16 mod 16,
4380 then shift up by 16's. */
4381 j
= k
- ((k
>> 4) << 4);
4388 ll
= (ll
<< 16) | xi
[M
];
4390 while ((k
-= 16) > 0);
4395 /* shift not more than 16 bits */
4397 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4400 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4406 if ((k
= enormlz (xi
)) > NBITS
)
4409 xi
[E
] -= (UEMUSHORT
) k
;
4414 /* Shift the significand of exploded e-type X up or down by SC bits. */
4435 lost
|= *p
; /* remember lost bits */
4476 return ((int) lost
);
4479 /* Shift normalize the significand area of exploded e-type X.
4480 Return the shift count (up = positive). */
4495 return (0); /* already normalized */
4501 /* With guard word, there are NBITS+16 bits available.
4502 Return true if all are zero. */
4506 /* see if high byte is zero */
4507 while ((*p
& 0xff00) == 0)
4512 /* now shift 1 bit at a time */
4513 while ((*p
& 0x8000) == 0)
4519 mtherr ("enormlz", UNDERFLOW
);
4525 /* Normalize by shifting down out of the high guard word
4526 of the significand */
4541 mtherr ("enormlz", OVERFLOW
);
4548 /* Powers of ten used in decimal <-> binary conversions. */
4553 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4554 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4556 {0x6576, 0x4a92, 0x804a, 0x153f,
4557 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4558 {0x6a32, 0xce52, 0x329a, 0x28ce,
4559 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4560 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4561 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4562 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4563 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4564 {0x851e, 0xeab7, 0x98fe, 0x901b,
4565 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4566 {0x0235, 0x0137, 0x36b1, 0x336c,
4567 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4568 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4569 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4570 {0x0000, 0x0000, 0x0000, 0x0000,
4571 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4572 {0x0000, 0x0000, 0x0000, 0x0000,
4573 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4574 {0x0000, 0x0000, 0x0000, 0x0000,
4575 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4576 {0x0000, 0x0000, 0x0000, 0x0000,
4577 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4578 {0x0000, 0x0000, 0x0000, 0x0000,
4579 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4580 {0x0000, 0x0000, 0x0000, 0x0000,
4581 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4584 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4586 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4587 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4588 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4589 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4590 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4591 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4592 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4593 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4594 {0xa23e, 0x5308, 0xfefb, 0x1155,
4595 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4596 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4597 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4598 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4599 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4600 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4601 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4602 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4603 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4604 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4605 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4606 {0xc155, 0xa4a8, 0x404e, 0x6113,
4607 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4608 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4609 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4610 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4611 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4614 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4615 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4617 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4618 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4619 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4620 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4621 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4622 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4623 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4624 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4625 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4626 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4627 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4628 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4629 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4632 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4634 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4635 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4636 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4637 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4638 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4639 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4640 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4641 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4642 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4643 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4644 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4645 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4646 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4651 /* Convert float value X to ASCII string STRING with NDIG digits after
4652 the decimal point. */
4655 e24toasc (x
, string
, ndigs
)
4656 const UEMUSHORT x
[];
4663 etoasc (w
, string
, ndigs
);
4666 /* Convert double value X to ASCII string STRING with NDIG digits after
4667 the decimal point. */
4670 e53toasc (x
, string
, ndigs
)
4671 const UEMUSHORT x
[];
4678 etoasc (w
, string
, ndigs
);
4681 /* Convert double extended value X to ASCII string STRING with NDIG digits
4682 after the decimal point. */
4685 e64toasc (x
, string
, ndigs
)
4686 const UEMUSHORT x
[];
4693 etoasc (w
, string
, ndigs
);
4696 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4697 after the decimal point. */
4700 e113toasc (x
, string
, ndigs
)
4701 const UEMUSHORT x
[];
4708 etoasc (w
, string
, ndigs
);
4712 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4713 the decimal point. */
4715 static char wstring
[80]; /* working storage for ASCII output */
4718 etoasc (x
, string
, ndigs
)
4719 const UEMUSHORT x
[];
4724 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4725 const UEMUSHORT
*p
, *r
, *ten
;
4727 int i
, j
, k
, expon
, rndsav
;
4740 sprintf (wstring
, " NaN ");
4744 rndprc
= NBITS
; /* set to full precision */
4745 emov (x
, y
); /* retain external format */
4746 if (y
[NE
- 1] & 0x8000)
4749 y
[NE
- 1] &= 0x7fff;
4756 ten
= &etens
[NTEN
][0];
4758 /* Test for zero exponent */
4761 for (k
= 0; k
< NE
- 1; k
++)
4764 goto tnzro
; /* denormalized number */
4766 goto isone
; /* valid all zeros */
4770 /* Test for infinity. */
4771 if (y
[NE
- 1] == 0x7fff)
4774 sprintf (wstring
, " -Infinity ");
4776 sprintf (wstring
, " Infinity ");
4780 /* Test for exponent nonzero but significand denormalized.
4781 * This is an error condition.
4783 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4785 mtherr ("etoasc", DOMAIN
);
4786 sprintf (wstring
, "NaN");
4790 /* Compare to 1.0 */
4799 { /* Number is greater than 1 */
4800 /* Convert significand to an integer and strip trailing decimal zeros. */
4802 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4804 p
= &etens
[NTEN
- 4][0];
4810 for (j
= 0; j
< NE
- 1; j
++)
4823 /* Rescale from integer significand */
4824 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4826 /* Find power of 10 */
4830 /* An unordered compare result shouldn't happen here. */
4831 while (ecmp (ten
, u
) <= 0)
4833 if (ecmp (p
, u
) <= 0)
4846 { /* Number is less than 1.0 */
4847 /* Pad significand with trailing decimal zeros. */
4850 while ((y
[NE
- 2] & 0x8000) == 0)
4859 for (i
= 0; i
< NDEC
+ 1; i
++)
4861 if ((w
[NI
- 1] & 0x7) != 0)
4863 /* multiply by 10 */
4876 if (eone
[NE
- 1] <= u
[1])
4888 while (ecmp (eone
, w
) > 0)
4890 if (ecmp (p
, w
) >= 0)
4905 /* Find the first (leading) digit. */
4911 digit
= equot
[NI
- 1];
4912 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4920 digit
= equot
[NI
- 1];
4928 /* Examine number of digits requested by caller. */
4946 *s
++ = (char) digit
+ '0';
4949 /* Generate digits after the decimal point. */
4950 for (k
= 0; k
<= ndigs
; k
++)
4952 /* multiply current number by 10, without normalizing */
4959 *s
++ = (char) equot
[NI
- 1] + '0';
4961 digit
= equot
[NI
- 1];
4964 /* round off the ASCII string */
4967 /* Test for critical rounding case in ASCII output. */
4971 if (ecmp (t
, ezero
) != 0)
4972 goto roun
; /* round to nearest */
4974 if ((*(s
- 1) & 1) == 0)
4975 goto doexp
; /* round to even */
4978 /* Round up and propagate carry-outs */
4982 /* Carry out to most significant digit? */
4989 /* Most significant digit carries to 10? */
4997 /* Round up and carry out from less significant digits */
5007 /* Strip trailing zeros, but leave at least one. */
5008 while (ss
[-1] == '0' && ss
[-2] != '.')
5010 sprintf (ss
, "e%d", expon
);
5013 /* copy out the working string */
5016 while (*ss
== ' ') /* strip possible leading space */
5018 while ((*s
++ = *ss
++) != '\0')
5023 /* Convert ASCII string to floating point.
5025 Numeric input is a free format decimal number of any length, with
5026 or without decimal point. Entering E after the number followed by an
5027 integer number causes the second number to be interpreted as a power of
5028 10 to be multiplied by the first number (i.e., "scientific" notation). */
5030 /* Convert ASCII string S to single precision float value Y. */
5041 /* Convert ASCII string S to double precision value Y. */
5048 #if defined(DEC) || defined(IBM)
5060 /* Convert ASCII string S to double extended value Y. */
5070 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5071 /* Convert ASCII string S to 128-bit long double Y. */
5078 asctoeg (s
, y
, 113);
5082 /* Convert ASCII string S to e type Y. */
5089 asctoeg (s
, y
, NBITS
);
5092 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5093 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
5096 asctoeg (ss
, y
, oprec
)
5101 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5102 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5103 int i
, k
, trail
, c
, rndsav
;
5106 char *sp
, *s
, *lstr
;
5109 /* Copy the input string. */
5110 lstr
= (char *) alloca (strlen (ss
) + 1);
5112 while (*ss
== ' ') /* skip leading spaces */
5116 while ((*sp
++ = *ss
++) != '\0')
5120 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5127 rndprc
= NBITS
; /* Set to full precision */
5140 if ((k
>= 0) && (k
< base
))
5142 /* Ignore leading zeros */
5143 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5145 /* Identify and strip trailing zeros after the decimal point. */
5146 if ((trail
== 0) && (decflg
!= 0))
5149 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
5151 /* Check for syntax error */
5153 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5154 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5156 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5158 goto unexpected_char_error
;
5167 /* If enough digits were given to more than fill up the yy register,
5168 continuing until overflow into the high guard word yy[2]
5169 guarantees that there will be a roundoff bit at the top
5170 of the low guard word after normalization. */
5177 nexp
+= 4; /* count digits after decimal point */
5179 eshup1 (yy
); /* multiply current number by 16 */
5187 nexp
+= 1; /* count digits after decimal point */
5189 eshup1 (yy
); /* multiply current number by 10 */
5195 /* Insert the current digit. */
5197 xt
[NI
- 2] = (UEMUSHORT
) k
;
5202 /* Mark any lost non-zero digit. */
5204 /* Count lost digits before the decimal point. */
5226 case '.': /* decimal point */
5228 goto unexpected_char_error
;
5234 goto unexpected_char_error
;
5239 goto unexpected_char_error
;
5252 unexpected_char_error
:
5256 mtherr ("asctoe", DOMAIN
);
5265 /* Exponent interpretation */
5267 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5268 for (k
= 0; k
< NI
; k
++)
5279 /* check for + or - */
5287 while (ISDIGIT (*s
))
5296 if ((exp
> MAXDECEXP
) && (base
== 10))
5300 yy
[E
] = 0x7fff; /* infinity */
5303 if ((exp
< MINDECEXP
) && (base
== 10))
5313 /* Base 16 hexadecimal floating constant. */
5314 if ((k
= enormlz (yy
)) > NBITS
)
5319 /* Adjust the exponent. NEXP is the number of hex digits,
5320 EXP is a power of 2. */
5321 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5331 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5332 while ((nexp
> 0) && (yy
[2] == 0))
5344 if ((k
= enormlz (yy
)) > NBITS
)
5349 lexp
= (EXONE
- 1 + NBITS
) - k
;
5350 emdnorm (yy
, lost
, 0, lexp
, 64);
5353 /* Convert to external format:
5355 Multiply by 10**nexp. If precision is 64 bits,
5356 the maximum relative error incurred in forming 10**n
5357 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5358 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5359 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5374 /* Punt. Can't handle this without 2 divides. */
5375 emovi (etens
[0], tt
);
5388 emul (etens
[i
], xt
, xt
);
5392 while (exp
<= MAXP
);
5411 /* Round and convert directly to the destination type */
5413 lexp
-= EXONE
- 0x3ff;
5415 else if (oprec
== 24 || oprec
== 32)
5416 lexp
-= (EXONE
- 0x7f);
5419 else if (oprec
== 24 || oprec
== 56)
5420 lexp
-= EXONE
- (0x41 << 2);
5422 else if (oprec
== 24)
5423 lexp
-= EXONE
- 0177;
5427 else if (oprec
== 56)
5428 lexp
-= EXONE
- 0201;
5431 emdnorm (yy
, lost
, 0, lexp
, 64);
5441 todec (yy
, y
); /* see etodec.c */
5446 toibm (yy
, y
, DFmode
);
5451 toc4x (yy
, y
, HFmode
);
5464 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5477 /* Return Y = largest integer not greater than X (truncated toward minus
5480 static const UEMUSHORT bmask
[] =
5503 const UEMUSHORT x
[];
5510 emov (x
, f
); /* leave in external format */
5511 expon
= (int) f
[NE
- 1];
5512 e
= (expon
& 0x7fff) - (EXONE
- 1);
5518 /* number of bits to clear out */
5530 /* clear the remaining bits */
5532 /* truncate negatives toward minus infinity */
5535 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5537 for (i
= 0; i
< NE
- 1; i
++)
5550 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5551 For example, 1.1 = 0.55 * 2^1. */
5555 const UEMUSHORT x
[];
5563 /* Handle denormalized numbers properly using long integer exponent. */
5564 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5572 *exp
= (int) (li
- 0x3ffe);
5576 /* Return e type Y = X * 2^PWR2. */
5580 const UEMUSHORT x
[];
5592 emdnorm (xi
, i
, i
, li
, !ROUND_TOWARDS_ZERO
);
5598 /* C = remainder after dividing B by A, all e type values.
5599 Least significant integer quotient bits left in EQUOT. */
5603 const UEMUSHORT a
[], b
[];
5606 UEMUSHORT den
[NI
], num
[NI
];
5610 || (ecmp (a
, ezero
) == 0)
5618 if (ecmp (a
, ezero
) == 0)
5620 mtherr ("eremain", SING
);
5626 eiremain (den
, num
);
5627 /* Sign of remainder = sign of quotient */
5636 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5637 remainder in NUM. */
5641 UEMUSHORT den
[], num
[];
5647 ld
-= enormlz (den
);
5649 ln
-= enormlz (num
);
5653 if (ecmpm (den
, num
) <= 0)
5665 emdnorm (num
, 0, 0, ln
, 0);
5668 /* Report an error condition CODE encountered in function NAME.
5670 Mnemonic Value Significance
5672 DOMAIN 1 argument domain error
5673 SING 2 function singularity
5674 OVERFLOW 3 overflow range error
5675 UNDERFLOW 4 underflow range error
5676 TLOSS 5 total loss of precision
5677 PLOSS 6 partial loss of precision
5678 INVALID 7 NaN - producing operation
5679 EDOM 33 Unix domain error code
5680 ERANGE 34 Unix range error code
5682 The order of appearance of the following messages is bound to the
5683 error codes defined above. */
5693 /* The string passed by the calling program is supposed to be the
5694 name of the function in which the error occurred.
5695 The code argument selects which error message string will be printed. */
5697 if (strcmp (name
, "esub") == 0)
5698 name
= "subtraction";
5699 else if (strcmp (name
, "ediv") == 0)
5701 else if (strcmp (name
, "emul") == 0)
5702 name
= "multiplication";
5703 else if (strcmp (name
, "enormlz") == 0)
5704 name
= "normalization";
5705 else if (strcmp (name
, "etoasc") == 0)
5706 name
= "conversion to text";
5707 else if (strcmp (name
, "asctoe") == 0)
5709 else if (strcmp (name
, "eremain") == 0)
5711 else if (strcmp (name
, "esqrt") == 0)
5712 name
= "square root";
5717 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5718 case SING
: warning ("%s: function singularity" , name
); break;
5719 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5720 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5721 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5722 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5723 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5728 /* Set global error message word */
5733 /* Convert DEC double precision D to e type E. */
5743 ecleaz (y
); /* start with a zero */
5744 p
= y
; /* point to our number */
5745 r
= *d
; /* get DEC exponent word */
5746 if (*d
& (unsigned int) 0x8000)
5747 *p
= 0xffff; /* fill in our sign */
5748 ++p
; /* bump pointer to our exponent word */
5749 r
&= 0x7fff; /* strip the sign bit */
5750 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5754 r
>>= 7; /* shift exponent word down 7 bits */
5755 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5756 /* add our e type exponent offset */
5757 *p
++ = r
; /* to form our exponent */
5759 r
= *d
++; /* now do the high order mantissa */
5760 r
&= 0177; /* strip off the DEC exponent and sign bits */
5761 r
|= 0200; /* the DEC understood high order mantissa bit */
5762 *p
++ = r
; /* put result in our high guard word */
5764 *p
++ = *d
++; /* fill in the rest of our mantissa */
5768 eshdn8 (y
); /* shift our mantissa down 8 bits */
5773 /* Convert e type X to DEC double precision D. */
5785 /* Adjust exponent for offsets. */
5786 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5787 /* Round off to nearest or even. */
5790 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5795 /* Convert exploded e-type X, that has already been rounded to
5796 56-bit precision, to DEC format double Y. */
5842 /* Convert IBM single/double precision to e type. */
5848 enum machine_mode mode
;
5853 ecleaz (y
); /* start with a zero */
5854 p
= y
; /* point to our number */
5855 r
= *d
; /* get IBM exponent word */
5856 if (*d
& (unsigned int) 0x8000)
5857 *p
= 0xffff; /* fill in our sign */
5858 ++p
; /* bump pointer to our exponent word */
5859 r
&= 0x7f00; /* strip the sign bit */
5860 r
>>= 6; /* shift exponent word down 6 bits */
5861 /* in fact shift by 8 right and 2 left */
5862 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5863 /* add our e type exponent offset */
5864 *p
++ = r
; /* to form our exponent */
5866 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5867 /* strip off the IBM exponent and sign bits */
5868 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5870 *p
++ = *d
++; /* fill in the rest of our mantissa */
5875 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5878 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5879 /* handle change in RADIX */
5885 /* Convert e type to IBM single/double precision. */
5891 enum machine_mode mode
;
5898 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5899 /* round off to nearest or even */
5902 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
5904 toibm (xi
, d
, mode
);
5910 enum machine_mode mode
;
5963 /* Convert C4X single/double precision to e type. */
5969 enum machine_mode mode
;
5987 /* Short-circuit the zero case. */
5988 if ((dn
[0] == 0x8000)
5989 && (dn
[1] == 0x0000)
5990 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
6001 ecleaz (y
); /* start with a zero */
6002 r
= dn
[0]; /* get sign/exponent part */
6003 if (r
& (unsigned int) 0x0080)
6005 y
[0] = 0xffff; /* fill in our sign */
6011 r
>>= 8; /* Shift exponent word down 8 bits. */
6012 if (r
& 0x80) /* Make the exponent negative if it is. */
6013 r
= r
| (~0 & ~0xff);
6017 /* Now do the high order mantissa. We don't "or" on the high bit
6018 because it is 2 (not 1) and is handled a little differently
6020 y
[M
] = dn
[0] & 0x7f;
6023 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6025 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6033 /* Now do the two's complement on the data. */
6035 carry
= 1; /* Initially add 1 for the two's complement. */
6036 for (i
=size
+ M
; i
> M
; i
--)
6038 if (carry
&& (y
[i
] == 0x0000))
6039 /* We overflowed into the next word, carry is the same. */
6040 y
[i
] = carry
? 0x0000 : 0xffff;
6043 /* No overflow, just invert and add carry. */
6044 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6059 /* Add our e type exponent offset to form our exponent. */
6063 /* Now do the high order mantissa strip off the exponent and sign
6064 bits and add the high 1 bit. */
6065 y
[M
] = (dn
[0] & 0x7f) | 0x80;
6068 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6070 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6080 /* Convert e type to C4X single/double precision. */
6086 enum machine_mode mode
;
6094 /* Adjust exponent for offsets. */
6095 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6097 /* Round off to nearest or even. */
6099 rndprc
= mode
== QFmode
? 24 : 32;
6100 emdnorm (xi
, 0, 0, exp
, !ROUND_TOWARDS_ZERO
);
6102 toc4x (xi
, d
, mode
);
6108 enum machine_mode mode
;
6114 /* Short-circuit the zero case */
6115 if ((x
[0] == 0) /* Zero exponent and sign */
6117 && (x
[M
] == 0) /* The rest is for zero mantissa */
6119 /* Only check for double if necessary */
6120 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6122 /* We have a zero. Put it into the output and return. */
6135 /* Negative number require a two's complement conversion of the
6141 i
= ((int) x
[1]) - 0x7f;
6143 /* Now add 1 to the inverted data to do the two's complement. */
6152 x
[v
] = carry
? 0x0000 : 0xffff;
6155 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6161 /* The following is a special case. The C4X negative float requires
6162 a zero in the high bit (because the format is (2 - x) x 2^m), so
6163 if a one is in that bit, we have to shift left one to get rid
6164 of it. This only occurs if the number is -1 x 2^m. */
6165 if (x
[M
+1] & 0x8000)
6167 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6168 high sign bit and shift the exponent. */
6174 i
= ((int) x
[1]) - 0x7f;
6176 if ((i
< -128) || (i
> 127))
6184 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6185 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6193 y
[0] |= ((i
& 0xff) << 8);
6197 y
[0] |= x
[M
] & 0x7f;
6203 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6204 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6209 /* Output a binary NaN bit pattern in the target machine's format. */
6211 /* If special NaN bit patterns are required, define them in tm.h
6212 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6218 static const UEMUSHORT TFbignan
[8] =
6219 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6220 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6228 static const UEMUSHORT XFbignan
[6] =
6229 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6230 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6238 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6239 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6247 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6248 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6255 make_nan (nan
, sign
, mode
)
6258 enum machine_mode mode
;
6264 size
= GET_MODE_BITSIZE (mode
);
6265 if (LARGEST_EXPONENT_IS_NORMAL (size
))
6267 warning ("%d-bit floats cannot hold NaNs", size
);
6268 saturate (nan
, sign
, size
, 0);
6273 /* Possibly the `reserved operand' patterns on a VAX can be
6274 used like NaN's, but probably not in the same way as IEEE. */
6275 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6277 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6279 if (REAL_WORDS_BIG_ENDIAN
)
6289 if (REAL_WORDS_BIG_ENDIAN
)
6297 if (REAL_WORDS_BIG_ENDIAN
)
6306 if (REAL_WORDS_BIG_ENDIAN
)
6316 if (REAL_WORDS_BIG_ENDIAN
)
6317 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6320 if (! REAL_WORDS_BIG_ENDIAN
)
6321 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6326 /* Create a saturation value for a SIZE-bit float, assuming that
6327 LARGEST_EXPONENT_IS_NORMAL (SIZE).
6329 If SIGN is true, fill X with the most negative value, otherwise fill
6330 it with the most positive value. WARN is true if the function should
6331 warn about overflow. */
6334 saturate (x
, sign
, size
, warn
)
6336 int sign
, size
, warn
;
6340 if (warn
&& extra_warnings
)
6341 warning ("value exceeds the range of a %d-bit float", size
);
6343 /* Create the most negative value. */
6344 for (i
= 0; i
< size
/ EMUSHORT_SIZE
; i
++)
6347 /* Make it positive, if necessary. */
6349 x
[REAL_WORDS_BIG_ENDIAN
? 0 : i
- 1] = 0x7fff;
6353 /* This is the inverse of the function `etarsingle' invoked by
6354 REAL_VALUE_TO_TARGET_SINGLE. */
6357 ereal_unto_float (f
)
6364 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6365 This is the inverse operation to what the function `endian' does. */
6366 if (REAL_WORDS_BIG_ENDIAN
)
6368 s
[0] = (UEMUSHORT
) (f
>> 16);
6369 s
[1] = (UEMUSHORT
) f
;
6373 s
[0] = (UEMUSHORT
) f
;
6374 s
[1] = (UEMUSHORT
) (f
>> 16);
6376 /* Convert and promote the target float to E-type. */
6378 /* Output E-type to REAL_VALUE_TYPE. */
6384 /* This is the inverse of the function `etardouble' invoked by
6385 REAL_VALUE_TO_TARGET_DOUBLE. */
6388 ereal_unto_double (d
)
6395 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6396 if (REAL_WORDS_BIG_ENDIAN
)
6398 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6399 s
[1] = (UEMUSHORT
) d
[0];
6400 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6401 s
[3] = (UEMUSHORT
) d
[1];
6405 /* Target float words are little-endian. */
6406 s
[0] = (UEMUSHORT
) d
[0];
6407 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6408 s
[2] = (UEMUSHORT
) d
[1];
6409 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6411 /* Convert target double to E-type. */
6413 /* Output E-type to REAL_VALUE_TYPE. */
6419 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6420 This is somewhat like ereal_unto_float, but the input types
6421 for these are different. */
6424 ereal_from_float (f
)
6431 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6432 This is the inverse operation to what the function `endian' does. */
6433 if (REAL_WORDS_BIG_ENDIAN
)
6435 s
[0] = (UEMUSHORT
) (f
>> 16);
6436 s
[1] = (UEMUSHORT
) f
;
6440 s
[0] = (UEMUSHORT
) f
;
6441 s
[1] = (UEMUSHORT
) (f
>> 16);
6443 /* Convert and promote the target float to E-type. */
6445 /* Output E-type to REAL_VALUE_TYPE. */
6451 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6452 This is somewhat like ereal_unto_double, but the input types
6453 for these are different.
6455 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6456 data format, with no holes in the bit packing. The first element
6457 of the input array holds the bits that would come first in the
6458 target computer's memory. */
6461 ereal_from_double (d
)
6468 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6469 if (REAL_WORDS_BIG_ENDIAN
)
6471 #if HOST_BITS_PER_WIDE_INT == 32
6472 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6473 s
[1] = (UEMUSHORT
) d
[0];
6474 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6475 s
[3] = (UEMUSHORT
) d
[1];
6477 /* In this case the entire target double is contained in the
6478 first array element. The second element of the input is
6480 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6481 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6482 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6483 s
[3] = (UEMUSHORT
) d
[0];
6488 /* Target float words are little-endian. */
6489 s
[0] = (UEMUSHORT
) d
[0];
6490 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6491 #if HOST_BITS_PER_WIDE_INT == 32
6492 s
[2] = (UEMUSHORT
) d
[1];
6493 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6495 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6496 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6499 /* Convert target double to E-type. */
6501 /* Output E-type to REAL_VALUE_TYPE. */
6508 /* Convert target computer unsigned 64-bit integer to e-type.
6509 The endian-ness of DImode follows the convention for integers,
6510 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6514 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6521 if (WORDS_BIG_ENDIAN
)
6523 for (k
= M
; k
< M
+ 4; k
++)
6528 for (k
= M
+ 3; k
>= M
; k
--)
6531 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6532 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6533 ecleaz (yi
); /* it was zero */
6535 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6539 /* Convert target computer signed 64-bit integer to e-type. */
6543 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6546 unsigned EMULONG acc
;
6552 if (WORDS_BIG_ENDIAN
)
6554 for (k
= M
; k
< M
+ 4; k
++)
6559 for (k
= M
+ 3; k
>= M
; k
--)
6562 /* Take absolute value */
6568 for (k
= M
+ 3; k
>= M
; k
--)
6570 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6577 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6578 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6579 ecleaz (yi
); /* it was zero */
6581 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6588 /* Convert e-type to unsigned 64-bit int. */
6604 k
= (int) xi
[E
] - (EXONE
- 1);
6607 for (j
= 0; j
< 4; j
++)
6613 for (j
= 0; j
< 4; j
++)
6616 warning ("overflow on truncation to integer");
6621 /* Shift more than 16 bits: first shift up k-16 mod 16,
6622 then shift up by 16's. */
6623 j
= k
- ((k
>> 4) << 4);
6627 if (WORDS_BIG_ENDIAN
)
6638 if (WORDS_BIG_ENDIAN
)
6643 while ((k
-= 16) > 0);
6647 /* shift not more than 16 bits */
6652 if (WORDS_BIG_ENDIAN
)
6671 /* Convert e-type to signed 64-bit int. */
6678 unsigned EMULONG acc
;
6685 k
= (int) xi
[E
] - (EXONE
- 1);
6688 for (j
= 0; j
< 4; j
++)
6694 for (j
= 0; j
< 4; j
++)
6697 warning ("overflow on truncation to integer");
6703 /* Shift more than 16 bits: first shift up k-16 mod 16,
6704 then shift up by 16's. */
6705 j
= k
- ((k
>> 4) << 4);
6709 if (WORDS_BIG_ENDIAN
)
6720 if (WORDS_BIG_ENDIAN
)
6725 while ((k
-= 16) > 0);
6729 /* shift not more than 16 bits */
6732 if (WORDS_BIG_ENDIAN
)
6748 /* Negate if negative */
6752 if (WORDS_BIG_ENDIAN
)
6754 for (k
= 0; k
< 4; k
++)
6756 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6757 if (WORDS_BIG_ENDIAN
)
6769 /* Longhand square root routine. */
6772 static int esqinited
= 0;
6773 static unsigned short sqrndbit
[NI
];
6780 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6782 int i
, j
, k
, n
, nlups
;
6787 sqrndbit
[NI
- 2] = 1;
6790 /* Check for arg <= 0 */
6791 i
= ecmp (x
, ezero
);
6796 mtherr ("esqrt", DOMAIN
);
6812 /* Bring in the arg and renormalize if it is denormal. */
6814 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6818 /* Divide exponent by 2 */
6820 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6822 /* Adjust if exponent odd */
6832 n
= 8; /* get 8 bits of result per inner loop */
6838 /* bring in next word of arg */
6840 num
[NI
- 1] = xx
[j
+ 3];
6841 /* Do additional bit on last outer loop, for roundoff. */
6844 for (i
= 0; i
< n
; i
++)
6846 /* Next 2 bits of arg */
6849 /* Shift up answer */
6851 /* Make trial divisor */
6852 for (k
= 0; k
< NI
; k
++)
6855 eaddm (sqrndbit
, temp
);
6856 /* Subtract and insert answer bit if it goes in */
6857 if (ecmpm (temp
, num
) <= 0)
6867 /* Adjust for extra, roundoff loop done. */
6868 exp
+= (NBITS
- 1) - rndprc
;
6870 /* Sticky bit = 1 if the remainder is nonzero. */
6872 for (i
= 3; i
< NI
; i
++)
6875 /* Renormalize and round off. */
6876 emdnorm (sq
, k
, 0, exp
, !ROUND_TOWARDS_ZERO
);
6881 /* Return the binary precision of the significand for a given
6882 floating point mode. The mode can hold an integer value
6883 that many bits wide, without losing any bits. */
6886 significand_size (mode
)
6887 enum machine_mode mode
;
6890 /* Don't test the modes, but their sizes, lest this
6891 code won't work for BITS_PER_UNIT != 8 . */
6893 switch (GET_MODE_BITSIZE (mode
))
6897 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6904 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6907 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6910 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6913 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6926 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)