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 To support cross compilation between IEEE, VAX and IBM floating
34 point formats, define REAL_ARITHMETIC in the tm.h file.
36 In either case the machine files (tm.h) must not contain any code
37 that tries to use host floating point arithmetic to convert
38 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
39 etc. In cross-compile situations a REAL_VALUE_TYPE may not
40 be intelligible to the host computer's native arithmetic.
42 The emulator defaults to the host's floating point format so that
43 its decimal conversion functions can be used if desired (see
46 The first part of this file interfaces gcc to a floating point
47 arithmetic suite that was not written with gcc in mind. Avoid
48 changing the low-level arithmetic routines unless you have suitable
49 test programs available. A special version of the PARANOIA floating
50 point arithmetic tester, modified for this purpose, can be found on
51 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
52 XFmode and TFmode transcendental functions, can be obtained by ftp from
53 netlib.att.com: netlib/cephes. */
55 /* Type of computer arithmetic.
56 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
58 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
59 to big-endian IEEE floating-point data structure. This definition
60 should work in SFmode `float' type and DFmode `double' type on
61 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
62 has been defined to be 96, then IEEE also invokes the particular
63 XFmode (`long double' type) data structure used by the Motorola
64 680x0 series processors.
66 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
67 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
68 has been defined to be 96, then IEEE also invokes the particular
69 XFmode `long double' data structure used by the Intel 80x86 series
72 `DEC' refers specifically to the Digital Equipment Corp PDP-11
73 and VAX floating point data structure. This model currently
74 supports no type wider than DFmode.
76 `IBM' refers specifically to the IBM System/370 and compatible
77 floating point data structure. This model currently supports
78 no type wider than DFmode. The IBM conversions were contributed by
79 frank@atom.ansto.gov.au (Frank Crawford).
81 `C4X' refers specifically to the floating point format used on
82 Texas Instruments TMS320C3x and TMS320C4x digital signal
83 processors. This supports QFmode (32-bit float, double) and HFmode
84 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
85 floats, C4x floats are not rounded to be even. The C4x conversions
86 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
87 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
89 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
90 then `long double' and `double' are both implemented, but they
91 both mean DFmode. In this case, the software floating-point
92 support available here is activated by writing
93 #define REAL_ARITHMETIC
96 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
97 and may deactivate XFmode since `long double' is used to refer
98 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT to non-zero
99 at the same time enables 80387-style 80-bit floats in a 128-bit
100 padded image, as seen on IA-64.
102 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
103 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
104 separate the floating point unit's endian-ness from that of
105 the integer addressing. This permits one to define a big-endian
106 FPU on a little-endian machine (e.g., ARM). An extension to
107 BYTES_BIG_ENDIAN may be required for some machines in the future.
108 These optional macros may be defined in tm.h. In real.h, they
109 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
110 them for any normal host or target machine on which the floats
111 and the integers have the same endian-ness. */
114 /* The following converts gcc macros into the ones used by this file. */
116 /* REAL_ARITHMETIC defined means that macros in real.h are
117 defined to call emulator functions. */
118 #ifdef REAL_ARITHMETIC
120 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
121 /* PDP-11, Pro350, VAX: */
123 #else /* it's not VAX */
124 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
125 /* IBM System/370 style */
127 #else /* it's also not an IBM */
128 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
129 /* TMS320C3x/C4x style */
131 #else /* it's also not a C4X */
132 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
134 #else /* it's not IEEE either */
135 /* UNKnown arithmetic. We don't support this and can't go on. */
136 unknown arithmetic type
138 #endif /* not IEEE */
143 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
146 /* REAL_ARITHMETIC not defined means that the *host's* data
147 structure will be used. It may differ by endian-ness from the
148 target machine's structure and will get its ends swapped
149 accordingly (but not here). Probably only the decimal <-> binary
150 functions in this file will actually be used in this case. */
152 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
154 #else /* it's not VAX */
155 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
156 /* IBM System/370 style */
158 #else /* it's also not an IBM */
159 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
161 #else /* it's not IEEE either */
162 unknown arithmetic type
164 #endif /* not IEEE */
168 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
170 #endif /* REAL_ARITHMETIC not defined */
172 /* Define INFINITY for support of infinity.
173 Define NANS for support of Not-a-Number's (NaN's). */
174 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
179 /* Support of NaNs requires support of infinity. */
186 /* Find a host integer type that is at least 16 bits wide,
187 and another type at least twice whatever that size is. */
189 #if HOST_BITS_PER_CHAR >= 16
190 #define EMUSHORT char
191 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
194 #if HOST_BITS_PER_SHORT >= 16
195 #define EMUSHORT short
196 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
197 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
199 #if HOST_BITS_PER_INT >= 16
201 #define EMUSHORT_SIZE HOST_BITS_PER_INT
202 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
204 #if HOST_BITS_PER_LONG >= 16
205 #define EMUSHORT long
206 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
207 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
209 /* You will have to modify this program to have a smaller unit size. */
210 #define EMU_NON_COMPILE
216 /* If no 16-bit type has been found and the compiler is GCC, try HImode. */
217 #if defined(__GNUC__) && EMUSHORT_SIZE != 16
218 typedef int HItype
__attribute__ ((mode (HI
)));
219 typedef unsigned int UHItype
__attribute__ ((mode (HI
)));
223 #define EMUSHORT HItype
224 #define UEMUSHORT UHItype
225 #define EMUSHORT_SIZE 16
226 #define EMULONG_SIZE 32
228 #define UEMUSHORT unsigned EMUSHORT
231 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
232 #define EMULONG short
234 #if HOST_BITS_PER_INT >= EMULONG_SIZE
237 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
240 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
241 #define EMULONG long long int
243 /* You will have to modify this program to have a smaller unit size. */
244 #define EMU_NON_COMPILE
251 /* The host interface doesn't work if no 16-bit size exists. */
252 #if EMUSHORT_SIZE != 16
253 #define EMU_NON_COMPILE
256 /* OK to continue compilation. */
257 #ifndef EMU_NON_COMPILE
259 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
260 In GET_REAL and PUT_REAL, r and e are pointers.
261 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
262 in memory, with no holes. */
264 #if MAX_LONG_DOUBLE_TYPE_SIZE == 96 || \
265 ((INTEL_EXTENDED_IEEE_FORMAT != 0) && MAX_LONG_DOUBLE_TYPE_SIZE == 128)
266 /* Number of 16 bit words in external e type format */
268 # define MAXDECEXP 4932
269 # define MINDECEXP -4956
270 # define GET_REAL(r,e) memcpy ((e), (r), 2*NE)
271 # define PUT_REAL(e,r) \
273 memcpy ((r), (e), 2*NE); \
274 if (2*NE < sizeof (*r)) \
275 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
277 # else /* no XFmode */
278 # if MAX_LONG_DOUBLE_TYPE_SIZE == 128
280 # define MAXDECEXP 4932
281 # define MINDECEXP -4977
282 # define GET_REAL(r,e) memcpy ((e), (r), 2*NE)
283 # define PUT_REAL(e,r) \
285 memcpy ((r), (e), 2*NE); \
286 if (2*NE < sizeof (*r)) \
287 memset ((char *) (r) + 2*NE, 0, sizeof (*r) - 2*NE); \
291 #define MAXDECEXP 4932
292 #define MINDECEXP -4956
293 #ifdef REAL_ARITHMETIC
294 /* Emulator uses target format internally
295 but host stores it in host endian-ness. */
297 #define GET_REAL(r,e) \
299 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
300 e53toe ((const UEMUSHORT *) (r), (e)); \
304 memcpy (&w[3], ((const EMUSHORT *) r), sizeof (EMUSHORT)); \
305 memcpy (&w[2], ((const EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
306 memcpy (&w[1], ((const EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
307 memcpy (&w[0], ((const EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
312 #define PUT_REAL(e,r) \
314 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
315 etoe53 ((e), (UEMUSHORT *) (r)); \
320 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
321 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
322 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
323 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
327 #else /* not REAL_ARITHMETIC */
329 /* emulator uses host format */
330 #define GET_REAL(r,e) e53toe ((const UEMUSHORT *) (r), (e))
331 #define PUT_REAL(e,r) etoe53 ((e), (UEMUSHORT *) (r))
333 #endif /* not REAL_ARITHMETIC */
334 #endif /* not TFmode */
335 #endif /* not XFmode */
338 /* Number of 16 bit words in internal format */
341 /* Array offset to exponent */
344 /* Array offset to high guard word */
347 /* Number of bits of precision */
348 #define NBITS ((NI-4)*16)
350 /* Maximum number of decimal digits in ASCII conversion
353 #define NDEC (NBITS*8/27)
355 /* The exponent of 1.0 */
356 #define EXONE (0x3fff)
358 #if defined(HOST_EBCDIC)
359 /* bit 8 is significant in EBCDIC */
360 #define CHARMASK 0xff
362 #define CHARMASK 0x7f
365 extern int extra_warnings
;
366 extern const UEMUSHORT ezero
[NE
], ehalf
[NE
], eone
[NE
], etwo
[NE
];
367 extern const UEMUSHORT elog2
[NE
], esqrt2
[NE
];
369 static void endian
PARAMS ((const UEMUSHORT
*, long *,
371 static void eclear
PARAMS ((UEMUSHORT
*));
372 static void emov
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
374 static void eabs
PARAMS ((UEMUSHORT
*));
376 static void eneg
PARAMS ((UEMUSHORT
*));
377 static int eisneg
PARAMS ((const UEMUSHORT
*));
378 static int eisinf
PARAMS ((const UEMUSHORT
*));
379 static int eisnan
PARAMS ((const UEMUSHORT
*));
380 static void einfin
PARAMS ((UEMUSHORT
*));
382 static void enan
PARAMS ((UEMUSHORT
*, int));
383 static void einan
PARAMS ((UEMUSHORT
*));
384 static int eiisnan
PARAMS ((const UEMUSHORT
*));
385 static int eiisneg
PARAMS ((const UEMUSHORT
*));
386 static void make_nan
PARAMS ((UEMUSHORT
*, int, enum machine_mode
));
388 static void emovi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
389 static void emovo
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
390 static void ecleaz
PARAMS ((UEMUSHORT
*));
391 static void ecleazs
PARAMS ((UEMUSHORT
*));
392 static void emovz
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
394 static void eiinfin
PARAMS ((UEMUSHORT
*));
397 static int eiisinf
PARAMS ((const UEMUSHORT
*));
399 static int ecmpm
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
400 static void eshdn1
PARAMS ((UEMUSHORT
*));
401 static void eshup1
PARAMS ((UEMUSHORT
*));
402 static void eshdn8
PARAMS ((UEMUSHORT
*));
403 static void eshup8
PARAMS ((UEMUSHORT
*));
404 static void eshup6
PARAMS ((UEMUSHORT
*));
405 static void eshdn6
PARAMS ((UEMUSHORT
*));
406 static void eaddm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));\f
407 static void esubm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
408 static void m16m
PARAMS ((unsigned int, const UEMUSHORT
*, UEMUSHORT
*));
409 static int edivm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
410 static int emulm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
411 static void emdnorm
PARAMS ((UEMUSHORT
*, int, int, EMULONG
, int));
412 static void esub
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
414 static void eadd
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
416 static void eadd1
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
418 static void ediv
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
420 static void emul
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
422 static void e53toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
423 static void e64toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
424 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
425 static void e113toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
427 static void e24toe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
428 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
429 static void etoe113
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
430 static void toe113
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
432 static void etoe64
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
433 static void toe64
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
434 static void etoe53
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
435 static void toe53
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
436 static void etoe24
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
437 static void toe24
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
438 static int ecmp
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*));
440 static void eround
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
442 static void ltoe
PARAMS ((const HOST_WIDE_INT
*, UEMUSHORT
*));
443 static void ultoe
PARAMS ((const unsigned HOST_WIDE_INT
*, UEMUSHORT
*));
444 static void eifrac
PARAMS ((const UEMUSHORT
*, HOST_WIDE_INT
*,
446 static void euifrac
PARAMS ((const UEMUSHORT
*, unsigned HOST_WIDE_INT
*,
448 static int eshift
PARAMS ((UEMUSHORT
*, int));
449 static int enormlz
PARAMS ((UEMUSHORT
*));
451 static void e24toasc
PARAMS ((const UEMUSHORT
*, char *, int));
452 static void e53toasc
PARAMS ((const UEMUSHORT
*, char *, int));
453 static void e64toasc
PARAMS ((const UEMUSHORT
*, char *, int));
454 static void e113toasc
PARAMS ((const UEMUSHORT
*, char *, int));
456 static void etoasc
PARAMS ((const UEMUSHORT
*, char *, int));
457 static void asctoe24
PARAMS ((const char *, UEMUSHORT
*));
458 static void asctoe53
PARAMS ((const char *, UEMUSHORT
*));
459 static void asctoe64
PARAMS ((const char *, UEMUSHORT
*));
460 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
461 static void asctoe113
PARAMS ((const char *, UEMUSHORT
*));
463 static void asctoe
PARAMS ((const char *, UEMUSHORT
*));
464 static void asctoeg
PARAMS ((const char *, UEMUSHORT
*, int));
465 static void efloor
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
467 static void efrexp
PARAMS ((const UEMUSHORT
*, int *,
470 static void eldexp
PARAMS ((const UEMUSHORT
*, int, UEMUSHORT
*));
472 static void eremain
PARAMS ((const UEMUSHORT
*, const UEMUSHORT
*,
475 static void eiremain
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
476 static void mtherr
PARAMS ((const char *, int));
478 static void dectoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
479 static void etodec
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
480 static void todec
PARAMS ((UEMUSHORT
*, UEMUSHORT
*));
483 static void ibmtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
485 static void etoibm
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
487 static void toibm
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
491 static void c4xtoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
493 static void etoc4x
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*,
495 static void toc4x
PARAMS ((UEMUSHORT
*, UEMUSHORT
*,
499 static void uditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
500 static void ditoe
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
501 static void etoudi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
502 static void etodi
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
503 static void esqrt
PARAMS ((const UEMUSHORT
*, UEMUSHORT
*));
506 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
507 swapping ends if required, into output array of longs. The
508 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
514 enum machine_mode mode
;
518 if (REAL_WORDS_BIG_ENDIAN
)
523 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
524 /* Swap halfwords in the fourth long. */
525 th
= (unsigned long) e
[6] & 0xffff;
526 t
= (unsigned long) e
[7] & 0xffff;
535 /* Swap halfwords in the third long. */
536 th
= (unsigned long) e
[4] & 0xffff;
537 t
= (unsigned long) e
[5] & 0xffff;
543 /* Swap halfwords in the second word. */
544 th
= (unsigned long) e
[2] & 0xffff;
545 t
= (unsigned long) e
[3] & 0xffff;
552 /* Swap halfwords in the first word. */
553 th
= (unsigned long) e
[0] & 0xffff;
554 t
= (unsigned long) e
[1] & 0xffff;
565 /* Pack the output array without swapping. */
570 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
571 /* Pack the fourth long. */
572 th
= (unsigned long) e
[7] & 0xffff;
573 t
= (unsigned long) e
[6] & 0xffff;
582 /* Pack the third long.
583 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
585 th
= (unsigned long) e
[5] & 0xffff;
586 t
= (unsigned long) e
[4] & 0xffff;
592 /* Pack the second long */
593 th
= (unsigned long) e
[3] & 0xffff;
594 t
= (unsigned long) e
[2] & 0xffff;
601 /* Pack the first long */
602 th
= (unsigned long) e
[1] & 0xffff;
603 t
= (unsigned long) e
[0] & 0xffff;
615 /* This is the implementation of the REAL_ARITHMETIC macro. */
618 earith (value
, icode
, r1
, r2
)
619 REAL_VALUE_TYPE
*value
;
624 UEMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
630 /* Return NaN input back to the caller. */
633 PUT_REAL (d1
, value
);
638 PUT_REAL (d2
, value
);
642 code
= (enum tree_code
) icode
;
650 esub (d2
, d1
, v
); /* d1 - d2 */
658 #ifndef REAL_INFINITY
659 if (ecmp (d2
, ezero
) == 0)
662 enan (v
, eisneg (d1
) ^ eisneg (d2
));
669 ediv (d2
, d1
, v
); /* d1/d2 */
672 case MIN_EXPR
: /* min (d1,d2) */
673 if (ecmp (d1
, d2
) < 0)
679 case MAX_EXPR
: /* max (d1,d2) */
680 if (ecmp (d1
, d2
) > 0)
693 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
694 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
700 UEMUSHORT f
[NE
], g
[NE
];
716 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
717 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
723 UEMUSHORT f
[NE
], g
[NE
];
725 unsigned HOST_WIDE_INT l
;
739 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
740 string to binary, rounding off as indicated by the machine_mode argument.
741 Then it promotes the rounded value to REAL_VALUE_TYPE. */
748 UEMUSHORT tem
[NE
], e
[NE
];
774 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
794 /* Expansion of REAL_NEGATE. */
810 /* Round real toward zero to HOST_WIDE_INT;
811 implements REAL_VALUE_FIX (x). */
817 UEMUSHORT f
[NE
], g
[NE
];
824 warning ("conversion from NaN to int");
832 /* Round real toward zero to unsigned HOST_WIDE_INT
833 implements REAL_VALUE_UNSIGNED_FIX (x).
834 Negative input returns zero. */
836 unsigned HOST_WIDE_INT
840 UEMUSHORT f
[NE
], g
[NE
];
841 unsigned HOST_WIDE_INT l
;
847 warning ("conversion from NaN to unsigned int");
856 /* REAL_VALUE_FROM_INT macro. */
859 ereal_from_int (d
, i
, j
, mode
)
862 enum machine_mode mode
;
864 UEMUSHORT df
[NE
], dg
[NE
];
865 HOST_WIDE_INT low
, high
;
868 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
875 /* complement and add 1 */
882 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
883 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
885 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
890 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
891 Avoid double-rounding errors later by rounding off now from the
892 extra-wide internal format to the requested precision. */
893 switch (GET_MODE_BITSIZE (mode
))
911 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
928 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
931 ereal_from_uint (d
, i
, j
, mode
)
933 unsigned HOST_WIDE_INT i
, j
;
934 enum machine_mode mode
;
936 UEMUSHORT df
[NE
], dg
[NE
];
937 unsigned HOST_WIDE_INT low
, high
;
939 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
943 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
949 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
950 Avoid double-rounding errors later by rounding off now from the
951 extra-wide internal format to the requested precision. */
952 switch (GET_MODE_BITSIZE (mode
))
970 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
987 /* REAL_VALUE_TO_INT macro. */
990 ereal_to_int (low
, high
, rr
)
991 HOST_WIDE_INT
*low
, *high
;
994 UEMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
1001 warning ("conversion from NaN to int");
1007 /* convert positive value */
1014 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
1015 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
1016 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
1017 emul (df
, dh
, dg
); /* fractional part is the low word */
1018 euifrac (dg
, (unsigned HOST_WIDE_INT
*) low
, dh
);
1021 /* complement and add 1 */
1031 /* REAL_VALUE_LDEXP macro. */
1038 UEMUSHORT e
[NE
], y
[NE
];
1051 /* These routines are conditionally compiled because functions
1052 of the same names may be defined in fold-const.c. */
1054 #ifdef REAL_ARITHMETIC
1056 /* Check for infinity in a REAL_VALUE_TYPE. */
1060 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1066 return (eisinf (e
));
1072 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1076 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1082 return (eisnan (e
));
1089 /* Check for a negative REAL_VALUE_TYPE number.
1090 This just checks the sign bit, so that -0 counts as negative. */
1096 return ereal_isneg (x
);
1099 /* Expansion of REAL_VALUE_TRUNCATE.
1100 The result is in floating point, rounded to nearest or even. */
1103 real_value_truncate (mode
, arg
)
1104 enum machine_mode mode
;
1105 REAL_VALUE_TYPE arg
;
1107 UEMUSHORT e
[NE
], t
[NE
];
1119 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
1156 /* If an unsupported type was requested, presume that
1157 the machine files know something useful to do with
1158 the unmodified value. */
1167 /* Try to change R into its exact multiplicative inverse in machine mode
1168 MODE. Return nonzero function value if successful. */
1171 exact_real_inverse (mode
, r
)
1172 enum machine_mode mode
;
1175 UEMUSHORT e
[NE
], einv
[NE
];
1176 REAL_VALUE_TYPE rinv
;
1181 /* Test for input in range. Don't transform IEEE special values. */
1182 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1185 /* Test for a power of 2: all significand bits zero except the MSB.
1186 We are assuming the target has binary (or hex) arithmetic. */
1187 if (e
[NE
- 2] != 0x8000)
1190 for (i
= 0; i
< NE
- 2; i
++)
1196 /* Compute the inverse and truncate it to the required mode. */
1197 ediv (e
, eone
, einv
);
1198 PUT_REAL (einv
, &rinv
);
1199 rinv
= real_value_truncate (mode
, rinv
);
1201 #ifdef CHECK_FLOAT_VALUE
1202 /* This check is not redundant. It may, for example, flush
1203 a supposedly IEEE denormal value to zero. */
1205 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1208 GET_REAL (&rinv
, einv
);
1210 /* Check the bits again, because the truncation might have
1211 generated an arbitrary saturation value on overflow. */
1212 if (einv
[NE
- 2] != 0x8000)
1215 for (i
= 0; i
< NE
- 2; i
++)
1221 /* Fail if the computed inverse is out of range. */
1222 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1225 /* Output the reciprocal and return success flag. */
1229 #endif /* REAL_ARITHMETIC defined */
1231 /* Used for debugging--print the value of R in human-readable format
1240 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1241 fprintf (stderr
, "%s", dstr
);
1245 /* The following routines convert REAL_VALUE_TYPE to the various floating
1246 point formats that are meaningful to supported computers.
1248 The results are returned in 32-bit pieces, each piece stored in a `long'.
1249 This is so they can be printed by statements like
1251 fprintf (file, "%lx, %lx", L[0], L[1]);
1253 that will work on both narrow- and wide-word host computers. */
1255 /* Convert R to a 128-bit long double precision value. The output array L
1256 contains four 32-bit pieces of the result, in the order they would appear
1267 #if INTEL_EXTENDED_IEEE_FORMAT == 0
1272 endian (e
, l
, TFmode
);
1275 /* Convert R to a double extended precision value. The output array L
1276 contains three 32-bit pieces of the result, in the order they would
1277 appear in memory. */
1288 endian (e
, l
, XFmode
);
1291 /* Convert R to a double precision value. The output array L contains two
1292 32-bit pieces of the result, in the order they would appear in memory. */
1303 endian (e
, l
, DFmode
);
1306 /* Convert R to a single precision float value stored in the least-significant
1307 bits of a `long'. */
1318 endian (e
, &l
, SFmode
);
1322 /* Convert X to a decimal ASCII string S for output to an assembly
1323 language file. Note, there is no standard way to spell infinity or
1324 a NaN, so these values may require special treatment in the tm.h
1328 ereal_to_decimal (x
, s
)
1338 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1339 or -2 if either is a NaN. */
1343 REAL_VALUE_TYPE x
, y
;
1345 UEMUSHORT ex
[NE
], ey
[NE
];
1349 return (ecmp (ex
, ey
));
1352 /* Return 1 if the sign bit of X is set, else return 0. */
1361 return (eisneg (ex
));
1364 /* End of REAL_ARITHMETIC interface */
1367 Extended precision IEEE binary floating point arithmetic routines
1369 Numbers are stored in C language as arrays of 16-bit unsigned
1370 short integers. The arguments of the routines are pointers to
1373 External e type data structure, similar to Intel 8087 chip
1374 temporary real format but possibly with a larger significand:
1376 NE-1 significand words (least significant word first,
1377 most significant bit is normally set)
1378 exponent (value = EXONE for 1.0,
1379 top bit is the sign)
1382 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1384 ei[0] sign word (0 for positive, 0xffff for negative)
1385 ei[1] biased exponent (value = EXONE for the number 1.0)
1386 ei[2] high guard word (always zero after normalization)
1388 to ei[NI-2] significand (NI-4 significand words,
1389 most significant word first,
1390 most significant bit is set)
1391 ei[NI-1] low guard word (0x8000 bit is rounding place)
1395 Routines for external format e-type numbers
1397 asctoe (string, e) ASCII string to extended double e type
1398 asctoe64 (string, &d) ASCII string to long double
1399 asctoe53 (string, &d) ASCII string to double
1400 asctoe24 (string, &f) ASCII string to single
1401 asctoeg (string, e, prec) ASCII string to specified precision
1402 e24toe (&f, e) IEEE single precision to e type
1403 e53toe (&d, e) IEEE double precision to e type
1404 e64toe (&d, e) IEEE long double precision to e type
1405 e113toe (&d, e) 128-bit long double precision to e type
1407 eabs (e) absolute value
1409 eadd (a, b, c) c = b + a
1411 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1412 -1 if a < b, -2 if either a or b is a NaN.
1413 ediv (a, b, c) c = b / a
1414 efloor (a, b) truncate to integer, toward -infinity
1415 efrexp (a, exp, s) extract exponent and significand
1416 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1417 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1418 einfin (e) set e to infinity, leaving its sign alone
1419 eldexp (a, n, b) multiply by 2**n
1421 emul (a, b, c) c = b * a
1424 eround (a, b) b = nearest integer value to a
1426 esub (a, b, c) c = b - a
1428 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1429 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1430 e64toasc (&d, str, n) 80-bit long double to ASCII string
1431 e113toasc (&d, str, n) 128-bit long double to ASCII string
1433 etoasc (e, str, n) e to ASCII string, n digits after decimal
1434 etoe24 (e, &f) convert e type to IEEE single precision
1435 etoe53 (e, &d) convert e type to IEEE double precision
1436 etoe64 (e, &d) convert e type to IEEE long double precision
1437 ltoe (&l, e) HOST_WIDE_INT to e type
1438 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1439 eisneg (e) 1 if sign bit of e != 0, else 0
1440 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1441 or is infinite (IEEE)
1442 eisnan (e) 1 if e is a NaN
1445 Routines for internal format exploded e-type numbers
1447 eaddm (ai, bi) add significands, bi = bi + ai
1449 ecleazs (ei) set ei = 0 but leave its sign alone
1450 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1451 edivm (ai, bi) divide significands, bi = bi / ai
1452 emdnorm (ai,l,s,exp) normalize and round off
1453 emovi (a, ai) convert external a to internal ai
1454 emovo (ai, a) convert internal ai to external a
1455 emovz (ai, bi) bi = ai, low guard word of bi = 0
1456 emulm (ai, bi) multiply significands, bi = bi * ai
1457 enormlz (ei) left-justify the significand
1458 eshdn1 (ai) shift significand and guards down 1 bit
1459 eshdn8 (ai) shift down 8 bits
1460 eshdn6 (ai) shift down 16 bits
1461 eshift (ai, n) shift ai n bits up (or down if n < 0)
1462 eshup1 (ai) shift significand and guards up 1 bit
1463 eshup8 (ai) shift up 8 bits
1464 eshup6 (ai) shift up 16 bits
1465 esubm (ai, bi) subtract significands, bi = bi - ai
1466 eiisinf (ai) 1 if infinite
1467 eiisnan (ai) 1 if a NaN
1468 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1469 einan (ai) set ai = NaN
1471 eiinfin (ai) set ai = infinity
1474 The result is always normalized and rounded to NI-4 word precision
1475 after each arithmetic operation.
1477 Exception flags are NOT fully supported.
1479 Signaling NaN's are NOT supported; they are treated the same
1482 Define INFINITY for support of infinity; otherwise a
1483 saturation arithmetic is implemented.
1485 Define NANS for support of Not-a-Number items; otherwise the
1486 arithmetic will never produce a NaN output, and might be confused
1488 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1489 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1490 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1493 Denormals are always supported here where appropriate (e.g., not
1494 for conversion to DEC numbers). */
1496 /* Definitions for error codes that are passed to the common error handling
1499 For Digital Equipment PDP-11 and VAX computers, certain
1500 IBM systems, and others that use numbers with a 56-bit
1501 significand, the symbol DEC should be defined. In this
1502 mode, most floating point constants are given as arrays
1503 of octal integers to eliminate decimal to binary conversion
1504 errors that might be introduced by the compiler.
1506 For computers, such as IBM PC, that follow the IEEE
1507 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1508 Std 754-1985), the symbol IEEE should be defined.
1509 These numbers have 53-bit significands. In this mode, constants
1510 are provided as arrays of hexadecimal 16 bit integers.
1511 The endian-ness of generated values is controlled by
1512 REAL_WORDS_BIG_ENDIAN.
1514 To accommodate other types of computer arithmetic, all
1515 constants are also provided in a normal decimal radix
1516 which one can hope are correctly converted to a suitable
1517 format by the available C language compiler. To invoke
1518 this mode, the symbol UNK is defined.
1520 An important difference among these modes is a predefined
1521 set of machine arithmetic constants for each. The numbers
1522 MACHEP (the machine roundoff error), MAXNUM (largest number
1523 represented), and several other parameters are preset by
1524 the configuration symbol. Check the file const.c to
1525 ensure that these values are correct for your computer.
1527 For ANSI C compatibility, define ANSIC equal to 1. Currently
1528 this affects only the atan2 function and others that use it. */
1530 /* Constant definitions for math error conditions. */
1532 #define DOMAIN 1 /* argument domain error */
1533 #define SING 2 /* argument singularity */
1534 #define OVERFLOW 3 /* overflow range error */
1535 #define UNDERFLOW 4 /* underflow range error */
1536 #define TLOSS 5 /* total loss of precision */
1537 #define PLOSS 6 /* partial loss of precision */
1538 #define INVALID 7 /* NaN-producing operation */
1540 /* e type constants used by high precision check routines */
1542 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
1544 const UEMUSHORT ezero
[NE
] =
1545 {0x0000, 0x0000, 0x0000, 0x0000,
1546 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1549 const UEMUSHORT ehalf
[NE
] =
1550 {0x0000, 0x0000, 0x0000, 0x0000,
1551 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1554 const UEMUSHORT eone
[NE
] =
1555 {0x0000, 0x0000, 0x0000, 0x0000,
1556 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1559 const UEMUSHORT etwo
[NE
] =
1560 {0x0000, 0x0000, 0x0000, 0x0000,
1561 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1564 const UEMUSHORT e32
[NE
] =
1565 {0x0000, 0x0000, 0x0000, 0x0000,
1566 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1568 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1569 const UEMUSHORT elog2
[NE
] =
1570 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1571 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1573 /* 1.41421356237309504880168872420969807856967187537695E0 */
1574 const UEMUSHORT esqrt2
[NE
] =
1575 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1576 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1578 /* 3.14159265358979323846264338327950288419716939937511E0 */
1579 const UEMUSHORT epi
[NE
] =
1580 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1581 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1584 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1585 const UEMUSHORT ezero
[NE
] =
1586 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1587 const UEMUSHORT ehalf
[NE
] =
1588 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1589 const UEMUSHORT eone
[NE
] =
1590 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1591 const UEMUSHORT etwo
[NE
] =
1592 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1593 const UEMUSHORT e32
[NE
] =
1594 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1595 const UEMUSHORT elog2
[NE
] =
1596 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1597 const UEMUSHORT esqrt2
[NE
] =
1598 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1599 const UEMUSHORT epi
[NE
] =
1600 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1603 /* Control register for rounding precision.
1604 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1609 /* Clear out entire e-type number X. */
1617 for (i
= 0; i
< NE
; i
++)
1621 /* Move e-type number from A to B. */
1630 for (i
= 0; i
< NE
; i
++)
1636 /* Absolute value of e-type X. */
1642 /* sign is top bit of last word of external format */
1643 x
[NE
- 1] &= 0x7fff;
1647 /* Negate the e-type number X. */
1654 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1657 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1661 const UEMUSHORT x
[];
1664 if (x
[NE
- 1] & 0x8000)
1670 /* Return 1 if e-type number X is infinity, else return zero. */
1674 const UEMUSHORT x
[];
1681 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1687 /* Check if e-type number is not a number. The bit pattern is one that we
1688 defined, so we know for sure how to detect it. */
1692 const UEMUSHORT x
[] ATTRIBUTE_UNUSED
;
1697 /* NaN has maximum exponent */
1698 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1700 /* ... and non-zero significand field. */
1701 for (i
= 0; i
< NE
- 1; i
++)
1711 /* Fill e-type number X with infinity pattern (IEEE)
1712 or largest possible number (non-IEEE). */
1721 for (i
= 0; i
< NE
- 1; i
++)
1725 for (i
= 0; i
< NE
- 1; i
++)
1753 /* Output an e-type NaN.
1754 This generates Intel's quiet NaN pattern for extended real.
1755 The exponent is 7fff, the leading mantissa word is c000. */
1765 for (i
= 0; i
< NE
- 2; i
++)
1768 *x
= (sign
<< 15) | 0x7fff;
1772 /* Move in an e-type number A, converting it to exploded e-type B. */
1784 p
= a
+ (NE
- 1); /* point to last word of external number */
1785 /* get the sign bit */
1790 /* get the exponent */
1792 *q
++ &= 0x7fff; /* delete the sign bit */
1794 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1800 for (i
= 3; i
< NI
; i
++)
1806 for (i
= 2; i
< NI
; i
++)
1812 /* clear high guard word */
1814 /* move in the significand */
1815 for (i
= 0; i
< NE
- 1; i
++)
1817 /* clear low guard word */
1821 /* Move out exploded e-type number A, converting it to e type B. */
1834 q
= b
+ (NE
- 1); /* point to output exponent */
1835 /* combine sign and exponent */
1838 *q
-- = *p
++ | 0x8000;
1842 if (*(p
- 1) == 0x7fff)
1847 enan (b
, eiisneg (a
));
1855 /* skip over guard word */
1857 /* move the significand */
1858 for (j
= 0; j
< NE
- 1; j
++)
1862 /* Clear out exploded e-type number XI. */
1870 for (i
= 0; i
< NI
; i
++)
1874 /* Clear out exploded e-type XI, but don't touch the sign. */
1883 for (i
= 0; i
< NI
- 1; i
++)
1887 /* Move exploded e-type number from A to B. */
1896 for (i
= 0; i
< NI
- 1; i
++)
1898 /* clear low guard word */
1902 /* Generate exploded e-type NaN.
1903 The explicit pattern for this is maximum exponent and
1904 top two significant bits set. */
1918 /* Return nonzero if exploded e-type X is a NaN. */
1923 const UEMUSHORT x
[];
1927 if ((x
[E
] & 0x7fff) == 0x7fff)
1929 for (i
= M
+ 1; i
< NI
; i
++)
1939 /* Return nonzero if sign of exploded e-type X is nonzero. */
1944 const UEMUSHORT x
[];
1952 /* Fill exploded e-type X with infinity pattern.
1953 This has maximum exponent and significand all zeros. */
1965 /* Return nonzero if exploded e-type X is infinite. */
1970 const UEMUSHORT x
[];
1977 if ((x
[E
] & 0x7fff) == 0x7fff)
1981 #endif /* INFINITY */
1983 /* Compare significands of numbers in internal exploded e-type format.
1984 Guard words are included in the comparison.
1992 const UEMUSHORT
*a
, *b
;
1996 a
+= M
; /* skip up to significand area */
1998 for (i
= M
; i
< NI
; i
++)
2006 if (*(--a
) > *(--b
))
2012 /* Shift significand of exploded e-type X down by 1 bit. */
2021 x
+= M
; /* point to significand area */
2024 for (i
= M
; i
< NI
; i
++)
2036 /* Shift significand of exploded e-type X up by 1 bit. */
2048 for (i
= M
; i
< NI
; i
++)
2061 /* Shift significand of exploded e-type X down by 8 bits. */
2067 UEMUSHORT newbyt
, oldbyt
;
2072 for (i
= M
; i
< NI
; i
++)
2082 /* Shift significand of exploded e-type X up by 8 bits. */
2089 UEMUSHORT newbyt
, oldbyt
;
2094 for (i
= M
; i
< NI
; i
++)
2104 /* Shift significand of exploded e-type X up by 16 bits. */
2116 for (i
= M
; i
< NI
- 1; i
++)
2122 /* Shift significand of exploded e-type X down by 16 bits. */
2134 for (i
= M
; i
< NI
- 1; i
++)
2140 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2154 for (i
= M
; i
< NI
; i
++)
2156 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2167 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2181 for (i
= M
; i
< NI
; i
++)
2183 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2195 static UEMUSHORT equot
[NI
];
2199 /* Radix 2 shift-and-add versions of multiply and divide */
2202 /* Divide significands */
2206 UEMUSHORT den
[], num
[];
2216 for (i
= M
; i
< NI
; i
++)
2221 /* Use faster compare and subtraction if denominator has only 15 bits of
2227 for (i
= M
+ 3; i
< NI
; i
++)
2232 if ((den
[M
+ 1] & 1) != 0)
2240 for (i
= 0; i
< NBITS
+ 2; i
++)
2258 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2259 bit + 1 roundoff bit. */
2264 for (i
= 0; i
< NBITS
+ 2; i
++)
2266 if (ecmpm (den
, num
) <= 0)
2269 j
= 1; /* quotient bit = 1 */
2283 /* test for nonzero remainder after roundoff bit */
2286 for (i
= M
; i
< NI
; i
++)
2294 for (i
= 0; i
< NI
; i
++)
2300 /* Multiply significands */
2311 for (i
= M
; i
< NI
; i
++)
2316 while (*p
== 0) /* significand is not supposed to be zero */
2321 if ((*p
& 0xff) == 0)
2329 for (i
= 0; i
< k
; i
++)
2333 /* remember if there were any nonzero bits shifted out */
2340 for (i
= 0; i
< NI
; i
++)
2343 /* return flag for lost nonzero bits */
2349 /* Radix 65536 versions of multiply and divide. */
2351 /* Multiply significand of e-type number B
2352 by 16-bit quantity A, return e-type result to C. */
2357 const UEMUSHORT b
[];
2361 unsigned EMULONG carry
;
2362 const UEMUSHORT
*ps
;
2364 unsigned EMULONG aa
, m
;
2373 for (i
=M
+1; i
<NI
; i
++)
2383 m
= (unsigned EMULONG
) aa
* *ps
--;
2384 carry
= (m
& 0xffff) + *pp
;
2385 *pp
-- = (UEMUSHORT
) carry
;
2386 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2387 *pp
= (UEMUSHORT
) carry
;
2388 *(pp
-1) = carry
>> 16;
2391 for (i
=M
; i
<NI
; i
++)
2395 /* Divide significands of exploded e-types NUM / DEN. Neither the
2396 numerator NUM nor the denominator DEN is permitted to have its high guard
2401 const UEMUSHORT den
[];
2406 unsigned EMULONG tnum
;
2407 UEMUSHORT j
, tdenm
, tquot
;
2408 UEMUSHORT tprod
[NI
+1];
2414 for (i
=M
; i
<NI
; i
++)
2420 for (i
=M
; i
<NI
; i
++)
2422 /* Find trial quotient digit (the radix is 65536). */
2423 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2425 /* Do not execute the divide instruction if it will overflow. */
2426 if ((tdenm
* (unsigned long) 0xffff) < tnum
)
2429 tquot
= tnum
/ tdenm
;
2430 /* Multiply denominator by trial quotient digit. */
2431 m16m ((unsigned int) tquot
, den
, tprod
);
2432 /* The quotient digit may have been overestimated. */
2433 if (ecmpm (tprod
, num
) > 0)
2437 if (ecmpm (tprod
, num
) > 0)
2447 /* test for nonzero remainder after roundoff bit */
2450 for (i
=M
; i
<NI
; i
++)
2457 for (i
=0; i
<NI
; i
++)
2463 /* Multiply significands of exploded e-type A and B, result in B. */
2467 const UEMUSHORT a
[];
2472 UEMUSHORT pprod
[NI
];
2478 for (i
=M
; i
<NI
; i
++)
2484 for (i
=M
+1; i
<NI
; i
++)
2492 m16m ((unsigned int) *p
--, b
, pprod
);
2493 eaddm (pprod
, equot
);
2499 for (i
=0; i
<NI
; i
++)
2502 /* return flag for lost nonzero bits */
2508 /* Normalize and round off.
2510 The internal format number to be rounded is S.
2511 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2513 Input SUBFLG indicates whether the number was obtained
2514 by a subtraction operation. In that case if LOST is nonzero
2515 then the number is slightly smaller than indicated.
2517 Input EXP is the biased exponent, which may be negative.
2518 the exponent field of S is ignored but is replaced by
2519 EXP as adjusted by normalization and rounding.
2521 Input RCNTRL is the rounding control. If it is nonzero, the
2522 returned value will be rounded to RNDPRC bits.
2524 For future reference: In order for emdnorm to round off denormal
2525 significands at the right point, the input exponent must be
2526 adjusted to be the actual value it would have after conversion to
2527 the final floating point type. This adjustment has been
2528 implemented for all type conversions (etoe53, etc.) and decimal
2529 conversions, but not for the arithmetic functions (eadd, etc.).
2530 Data types having standard 15-bit exponents are not affected by
2531 this, but SFmode and DFmode are affected. For example, ediv with
2532 rndprc = 24 will not round correctly to 24-bit precision if the
2533 result is denormal. */
2535 static int rlast
= -1;
2537 static UEMUSHORT rmsk
= 0;
2538 static UEMUSHORT rmbit
= 0;
2539 static UEMUSHORT rebit
= 0;
2541 static UEMUSHORT rbit
[NI
];
2544 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2557 /* a blank significand could mean either zero or infinity. */
2570 if ((j
> NBITS
) && (exp
< 32767))
2578 if (exp
> (EMULONG
) (-NBITS
- 1))
2591 /* Round off, unless told not to by rcntrl. */
2594 /* Set up rounding parameters if the control register changed. */
2595 if (rndprc
!= rlast
)
2602 rw
= NI
- 1; /* low guard word */
2625 /* For DEC or IBM arithmetic */
2642 /* For C4x arithmetic */
2663 /* Shift down 1 temporarily if the data structure has an implied
2664 most significant bit and the number is denormal.
2665 Intel long double denormals also lose one bit of precision. */
2666 if ((exp
<= 0) && (rndprc
!= NBITS
)
2667 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2669 lost
|= s
[NI
- 1] & 1;
2672 /* Clear out all bits below the rounding bit,
2673 remembering in r if any were nonzero. */
2687 if ((r
& rmbit
) != 0)
2693 { /* round to even */
2694 if ((s
[re
] & rebit
) == 0)
2707 /* Undo the temporary shift for denormal values. */
2708 if ((exp
<= 0) && (rndprc
!= NBITS
)
2709 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2714 { /* overflow on roundoff */
2727 for (i
= 2; i
< NI
- 1; i
++)
2730 warning ("floating point overflow");
2734 for (i
= M
+ 1; i
< NI
- 1; i
++)
2737 if ((rndprc
< 64) || (rndprc
== 113))
2752 s
[1] = (UEMUSHORT
) exp
;
2755 /* Subtract. C = B - A, all e type numbers. */
2757 static int subflg
= 0;
2761 const UEMUSHORT
*a
, *b
;
2776 /* Infinity minus infinity is a NaN.
2777 Test for subtracting infinities of the same sign. */
2778 if (eisinf (a
) && eisinf (b
)
2779 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2781 mtherr ("esub", INVALID
);
2790 /* Add. C = A + B, all e type. */
2794 const UEMUSHORT
*a
, *b
;
2799 /* NaN plus anything is a NaN. */
2810 /* Infinity minus infinity is a NaN.
2811 Test for adding infinities of opposite signs. */
2812 if (eisinf (a
) && eisinf (b
)
2813 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2815 mtherr ("esub", INVALID
);
2824 /* Arithmetic common to both addition and subtraction. */
2828 const UEMUSHORT
*a
, *b
;
2831 UEMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2833 EMULONG lt
, lta
, ltb
;
2854 /* compare exponents */
2859 { /* put the larger number in bi */
2869 if (lt
< (EMULONG
) (-NBITS
- 1))
2870 goto done
; /* answer same as larger addend */
2872 lost
= eshift (ai
, k
); /* shift the smaller number down */
2876 /* exponents were the same, so must compare significands */
2879 { /* the numbers are identical in magnitude */
2880 /* if different signs, result is zero */
2886 /* if same sign, result is double */
2887 /* double denormalized tiny number */
2888 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2893 /* add 1 to exponent unless both are zero! */
2894 for (j
= 1; j
< NI
- 1; j
++)
2910 bi
[E
] = (UEMUSHORT
) ltb
;
2914 { /* put the larger number in bi */
2930 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2936 /* Divide: C = B/A, all e type. */
2940 const UEMUSHORT
*a
, *b
;
2943 UEMUSHORT ai
[NI
], bi
[NI
];
2945 EMULONG lt
, lta
, ltb
;
2947 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2948 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2949 sign
= eisneg (a
) ^ eisneg (b
);
2952 /* Return any NaN input. */
2963 /* Zero over zero, or infinity over infinity, is a NaN. */
2964 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2965 || (eisinf (a
) && eisinf (b
)))
2967 mtherr ("ediv", INVALID
);
2972 /* Infinity over anything else is infinity. */
2979 /* Anything else over infinity is zero. */
2991 { /* See if numerator is zero. */
2992 for (i
= 1; i
< NI
- 1; i
++)
2996 ltb
-= enormlz (bi
);
3006 { /* possible divide by zero */
3007 for (i
= 1; i
< NI
- 1; i
++)
3011 lta
-= enormlz (ai
);
3015 /* Divide by zero is not an invalid operation.
3016 It is a divide-by-zero operation! */
3018 mtherr ("ediv", SING
);
3024 /* calculate exponent */
3025 lt
= ltb
- lta
+ EXONE
;
3026 emdnorm (bi
, i
, 0, lt
, 64);
3033 && (ecmp (c
, ezero
) != 0)
3036 *(c
+(NE
-1)) |= 0x8000;
3038 *(c
+(NE
-1)) &= ~0x8000;
3041 /* Multiply e-types A and B, return e-type product C. */
3045 const UEMUSHORT
*a
, *b
;
3048 UEMUSHORT ai
[NI
], bi
[NI
];
3050 EMULONG lt
, lta
, ltb
;
3052 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3053 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3054 sign
= eisneg (a
) ^ eisneg (b
);
3057 /* NaN times anything is the same NaN. */
3068 /* Zero times infinity is a NaN. */
3069 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3070 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3072 mtherr ("emul", INVALID
);
3077 /* Infinity times anything else is infinity. */
3079 if (eisinf (a
) || eisinf (b
))
3091 for (i
= 1; i
< NI
- 1; i
++)
3095 lta
-= enormlz (ai
);
3106 for (i
= 1; i
< NI
- 1; i
++)
3110 ltb
-= enormlz (bi
);
3119 /* Multiply significands */
3121 /* calculate exponent */
3122 lt
= lta
+ ltb
- (EXONE
- 1);
3123 emdnorm (bi
, j
, 0, lt
, 64);
3130 && (ecmp (c
, ezero
) != 0)
3133 *(c
+(NE
-1)) |= 0x8000;
3135 *(c
+(NE
-1)) &= ~0x8000;
3138 /* Convert double precision PE to e-type Y. */
3142 const UEMUSHORT
*pe
;
3152 ibmtoe (pe
, y
, DFmode
);
3157 c4xtoe (pe
, y
, HFmode
);
3167 denorm
= 0; /* flag if denormalized number */
3169 if (! REAL_WORDS_BIG_ENDIAN
)
3175 yy
[M
] = (r
& 0x0f) | 0x10;
3176 r
&= ~0x800f; /* strip sign and 4 significand bits */
3181 if (! REAL_WORDS_BIG_ENDIAN
)
3183 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3184 || (pe
[1] != 0) || (pe
[0] != 0))
3186 enan (y
, yy
[0] != 0);
3192 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3193 || (pe
[2] != 0) || (pe
[3] != 0))
3195 enan (y
, yy
[0] != 0);
3206 #endif /* INFINITY */
3208 /* If zero exponent, then the significand is denormalized.
3209 So take back the understood high significand bit. */
3220 if (! REAL_WORDS_BIG_ENDIAN
)
3237 /* If zero exponent, then normalize the significand. */
3238 if ((k
= enormlz (yy
)) > NBITS
)
3241 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3244 #endif /* not C4X */
3245 #endif /* not IBM */
3246 #endif /* not DEC */
3249 /* Convert double extended precision float PE to e type Y. */
3253 const UEMUSHORT
*pe
;
3263 for (i
= 0; i
< NE
- 5; i
++)
3265 /* This precision is not ordinarily supported on DEC or IBM. */
3267 for (i
= 0; i
< 5; i
++)
3271 p
= &yy
[0] + (NE
- 1);
3274 for (i
= 0; i
< 5; i
++)
3278 if (! REAL_WORDS_BIG_ENDIAN
)
3280 for (i
= 0; i
< 5; i
++)
3283 /* For denormal long double Intel format, shift significand up one
3284 -- but only if the top significand bit is zero. A top bit of 1
3285 is "pseudodenormal" when the exponent is zero. */
3286 if ((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3298 p
= &yy
[0] + (NE
- 1);
3299 #ifdef ARM_EXTENDED_IEEE_FORMAT
3300 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3301 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3307 for (i
= 0; i
< 4; i
++)
3312 /* Point to the exponent field and check max exponent cases. */
3314 if ((*p
& 0x7fff) == 0x7fff)
3317 if (! REAL_WORDS_BIG_ENDIAN
)
3319 for (i
= 0; i
< 4; i
++)
3321 if ((i
!= 3 && pe
[i
] != 0)
3322 /* Anything but 0x8000 here, including 0, is a NaN. */
3323 || (i
== 3 && pe
[i
] != 0x8000))
3325 enan (y
, (*p
& 0x8000) != 0);
3332 #ifdef ARM_EXTENDED_IEEE_FORMAT
3333 for (i
= 2; i
<= 5; i
++)
3337 enan (y
, (*p
& 0x8000) != 0);
3342 /* In Motorola extended precision format, the most significant
3343 bit of an infinity mantissa could be either 1 or 0. It is
3344 the lower order bits that tell whether the value is a NaN. */
3345 if ((pe
[2] & 0x7fff) != 0)
3348 for (i
= 3; i
<= 5; i
++)
3353 enan (y
, (*p
& 0x8000) != 0);
3357 #endif /* not ARM */
3366 #endif /* INFINITY */
3369 for (i
= 0; i
< NE
; i
++)
3373 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3374 /* Convert 128-bit long double precision float PE to e type Y. */
3378 const UEMUSHORT
*pe
;
3391 if (! REAL_WORDS_BIG_ENDIAN
)
3403 if (! REAL_WORDS_BIG_ENDIAN
)
3405 for (i
= 0; i
< 7; i
++)
3409 enan (y
, yy
[0] != 0);
3416 for (i
= 1; i
< 8; i
++)
3420 enan (y
, yy
[0] != 0);
3432 #endif /* INFINITY */
3436 if (! REAL_WORDS_BIG_ENDIAN
)
3438 for (i
= 0; i
< 7; i
++)
3444 for (i
= 0; i
< 7; i
++)
3448 /* If denormal, remove the implied bit; else shift down 1. */
3462 /* Convert single precision float PE to e type Y. */
3466 const UEMUSHORT
*pe
;
3471 ibmtoe (pe
, y
, SFmode
);
3477 c4xtoe (pe
, y
, QFmode
);
3488 denorm
= 0; /* flag if denormalized number */
3491 if (! REAL_WORDS_BIG_ENDIAN
)
3501 yy
[M
] = (r
& 0x7f) | 0200;
3502 r
&= ~0x807f; /* strip sign and 7 significand bits */
3507 if (REAL_WORDS_BIG_ENDIAN
)
3509 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3511 enan (y
, yy
[0] != 0);
3517 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3519 enan (y
, yy
[0] != 0);
3530 #endif /* INFINITY */
3532 /* If zero exponent, then the significand is denormalized.
3533 So take back the understood high significand bit. */
3546 if (! REAL_WORDS_BIG_ENDIAN
)
3556 { /* if zero exponent, then normalize the significand */
3557 if ((k
= enormlz (yy
)) > NBITS
)
3560 yy
[E
] -= (UEMUSHORT
) (k
- 1);
3563 #endif /* not C4X */
3564 #endif /* not IBM */
3567 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
3568 /* Convert e-type X to IEEE 128-bit long double format E. */
3582 make_nan (e
, eisneg (x
), TFmode
);
3587 exp
= (EMULONG
) xi
[E
];
3592 /* round off to nearest or even */
3595 emdnorm (xi
, 0, 0, exp
, 64);
3603 /* Convert exploded e-type X, that has already been rounded to
3604 113-bit precision, to IEEE 128-bit long double format Y. */
3616 make_nan (b
, eiisneg (a
), TFmode
);
3621 if (REAL_WORDS_BIG_ENDIAN
)
3624 q
= b
+ 7; /* point to output exponent */
3626 /* If not denormal, delete the implied bit. */
3631 /* combine sign and exponent */
3633 if (REAL_WORDS_BIG_ENDIAN
)
3636 *q
++ = *p
++ | 0x8000;
3643 *q
-- = *p
++ | 0x8000;
3647 /* skip over guard word */
3649 /* move the significand */
3650 if (REAL_WORDS_BIG_ENDIAN
)
3652 for (i
= 0; i
< 7; i
++)
3657 for (i
= 0; i
< 7; i
++)
3663 /* Convert e-type X to IEEE double extended format E. */
3677 make_nan (e
, eisneg (x
), XFmode
);
3682 /* adjust exponent for offset */
3683 exp
= (EMULONG
) xi
[E
];
3688 /* round off to nearest or even */
3691 emdnorm (xi
, 0, 0, exp
, 64);
3699 /* Convert exploded e-type X, that has already been rounded to
3700 64-bit precision, to IEEE double extended format Y. */
3712 make_nan (b
, eiisneg (a
), XFmode
);
3716 /* Shift denormal long double Intel format significand down one bit. */
3717 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3727 if (REAL_WORDS_BIG_ENDIAN
)
3731 q
= b
+ 4; /* point to output exponent */
3732 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3733 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3734 always there, and there are never more bytes, even when we are using
3735 INTEL_EXTENDED_IEEE_FORMAT. */
3740 /* combine sign and exponent */
3744 *q
++ = *p
++ | 0x8000;
3751 *q
-- = *p
++ | 0x8000;
3756 if (REAL_WORDS_BIG_ENDIAN
)
3758 #ifdef ARM_EXTENDED_IEEE_FORMAT
3759 /* The exponent is in the lowest 15 bits of the first word. */
3760 *q
++ = i
? 0x8000 : 0;
3764 *q
++ = *p
++ | 0x8000;
3773 *q
-- = *p
++ | 0x8000;
3778 /* skip over guard word */
3780 /* move the significand */
3782 for (i
= 0; i
< 4; i
++)
3786 for (i
= 0; i
< 4; i
++)
3790 if (REAL_WORDS_BIG_ENDIAN
)
3792 for (i
= 0; i
< 4; i
++)
3800 /* Intel long double infinity significand. */
3808 for (i
= 0; i
< 4; i
++)
3814 /* e type to double precision. */
3817 /* Convert e-type X to DEC-format double E. */
3824 etodec (x
, e
); /* see etodec.c */
3827 /* Convert exploded e-type X, that has already been rounded to
3828 56-bit double precision, to DEC double Y. */
3839 /* Convert e-type X to IBM 370-format double E. */
3846 etoibm (x
, e
, DFmode
);
3849 /* Convert exploded e-type X, that has already been rounded to
3850 56-bit precision, to IBM 370 double Y. */
3856 toibm (x
, y
, DFmode
);
3859 #else /* it's neither DEC nor IBM */
3861 /* Convert e-type X to C4X-format long double E. */
3868 etoc4x (x
, e
, HFmode
);
3871 /* Convert exploded e-type X, that has already been rounded to
3872 56-bit precision, to IBM 370 double Y. */
3878 toc4x (x
, y
, HFmode
);
3881 #else /* it's neither DEC nor IBM nor C4X */
3883 /* Convert e-type X to IEEE double E. */
3897 make_nan (e
, eisneg (x
), DFmode
);
3902 /* adjust exponent for offsets */
3903 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3908 /* round off to nearest or even */
3911 emdnorm (xi
, 0, 0, exp
, 64);
3919 /* Convert exploded e-type X, that has already been rounded to
3920 53-bit precision, to IEEE double Y. */
3932 make_nan (y
, eiisneg (x
), DFmode
);
3938 if (! REAL_WORDS_BIG_ENDIAN
)
3941 *y
= 0; /* output high order */
3943 *y
= 0x8000; /* output sign bit */
3946 if (i
>= (unsigned int) 2047)
3948 /* Saturate at largest number less than infinity. */
3951 if (! REAL_WORDS_BIG_ENDIAN
)
3965 *y
|= (UEMUSHORT
) 0x7fef;
3966 if (! REAL_WORDS_BIG_ENDIAN
)
3991 i
|= *p
++ & (UEMUSHORT
) 0x0f; /* *p = xi[M] */
3992 *y
|= (UEMUSHORT
) i
; /* high order output already has sign bit set */
3993 if (! REAL_WORDS_BIG_ENDIAN
)
4008 #endif /* not C4X */
4009 #endif /* not IBM */
4010 #endif /* not DEC */
4014 /* e type to single precision. */
4017 /* Convert e-type X to IBM 370 float E. */
4024 etoibm (x
, e
, SFmode
);
4027 /* Convert exploded e-type X, that has already been rounded to
4028 float precision, to IBM 370 float Y. */
4034 toibm (x
, y
, SFmode
);
4040 /* Convert e-type X to C4X float E. */
4047 etoc4x (x
, e
, QFmode
);
4050 /* Convert exploded e-type X, that has already been rounded to
4051 float precision, to IBM 370 float Y. */
4057 toc4x (x
, y
, QFmode
);
4062 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
4076 make_nan (e
, eisneg (x
), SFmode
);
4081 /* adjust exponent for offsets */
4082 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
4087 /* round off to nearest or even */
4090 emdnorm (xi
, 0, 0, exp
, 64);
4098 /* Convert exploded e-type X, that has already been rounded to
4099 float precision, to IEEE float Y. */
4111 make_nan (y
, eiisneg (x
), SFmode
);
4117 if (! REAL_WORDS_BIG_ENDIAN
)
4123 *y
= 0; /* output high order */
4125 *y
= 0x8000; /* output sign bit */
4128 /* Handle overflow cases. */
4132 *y
|= (UEMUSHORT
) 0x7f80;
4137 if (! REAL_WORDS_BIG_ENDIAN
)
4145 #else /* no INFINITY */
4146 *y
|= (UEMUSHORT
) 0x7f7f;
4151 if (! REAL_WORDS_BIG_ENDIAN
)
4162 #endif /* no INFINITY */
4174 i
|= *p
++ & (UEMUSHORT
) 0x7f; /* *p = xi[M] */
4175 /* High order output already has sign bit set. */
4181 if (! REAL_WORDS_BIG_ENDIAN
)
4190 #endif /* not C4X */
4191 #endif /* not IBM */
4193 /* Compare two e type numbers.
4197 -2 if either a or b is a NaN. */
4201 const UEMUSHORT
*a
, *b
;
4203 UEMUSHORT ai
[NI
], bi
[NI
];
4209 if (eisnan (a
) || eisnan (b
))
4218 { /* the signs are different */
4220 for (i
= 1; i
< NI
- 1; i
++)
4234 /* both are the same sign */
4249 return (0); /* equality */
4253 if (*(--p
) > *(--q
))
4254 return (msign
); /* p is bigger */
4256 return (-msign
); /* p is littler */
4260 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4272 /* Convert HOST_WIDE_INT LP to e type Y. */
4276 const HOST_WIDE_INT
*lp
;
4280 unsigned HOST_WIDE_INT ll
;
4286 /* make it positive */
4287 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4288 yi
[0] = 0xffff; /* put correct sign in the e type number */
4292 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4294 /* move the long integer to yi significand area */
4295 #if HOST_BITS_PER_WIDE_INT == 64
4296 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4297 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4298 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4299 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4300 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4302 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4303 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4304 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4307 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4308 ecleaz (yi
); /* it was zero */
4310 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
4311 emovo (yi
, y
); /* output the answer */
4314 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4318 const unsigned HOST_WIDE_INT
*lp
;
4322 unsigned HOST_WIDE_INT ll
;
4328 /* move the long integer to ayi significand area */
4329 #if HOST_BITS_PER_WIDE_INT == 64
4330 yi
[M
] = (UEMUSHORT
) (ll
>> 48);
4331 yi
[M
+ 1] = (UEMUSHORT
) (ll
>> 32);
4332 yi
[M
+ 2] = (UEMUSHORT
) (ll
>> 16);
4333 yi
[M
+ 3] = (UEMUSHORT
) ll
;
4334 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4336 yi
[M
] = (UEMUSHORT
) (ll
>> 16);
4337 yi
[M
+ 1] = (UEMUSHORT
) ll
;
4338 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4341 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4342 ecleaz (yi
); /* it was zero */
4344 yi
[E
] -= (UEMUSHORT
) k
; /* subtract shift count from exponent */
4345 emovo (yi
, y
); /* output the answer */
4349 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4350 part FRAC of e-type (packed internal format) floating point input X.
4351 The integer output I has the sign of the input, except that
4352 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4353 The output e-type fraction FRAC is the positive fractional
4364 unsigned HOST_WIDE_INT ll
;
4367 k
= (int) xi
[E
] - (EXONE
- 1);
4370 /* if exponent <= 0, integer = 0 and real output is fraction */
4375 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4377 /* long integer overflow: output large integer
4378 and correct fraction */
4380 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4383 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4384 /* In this case, let it overflow and convert as if unsigned. */
4385 euifrac (x
, &ll
, frac
);
4386 *i
= (HOST_WIDE_INT
) ll
;
4389 /* In other cases, return the largest positive integer. */
4390 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4395 warning ("overflow on truncation to integer");
4399 /* Shift more than 16 bits: first shift up k-16 mod 16,
4400 then shift up by 16's. */
4401 j
= k
- ((k
>> 4) << 4);
4408 ll
= (ll
<< 16) | xi
[M
];
4410 while ((k
-= 16) > 0);
4417 /* shift not more than 16 bits */
4419 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4426 if ((k
= enormlz (xi
)) > NBITS
)
4429 xi
[E
] -= (UEMUSHORT
) k
;
4435 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4436 FRAC of e-type X. A negative input yields integer output = 0 but
4437 correct fraction. */
4440 euifrac (x
, i
, frac
)
4442 unsigned HOST_WIDE_INT
*i
;
4445 unsigned HOST_WIDE_INT ll
;
4450 k
= (int) xi
[E
] - (EXONE
- 1);
4453 /* if exponent <= 0, integer = 0 and argument is fraction */
4458 if (k
> HOST_BITS_PER_WIDE_INT
)
4460 /* Long integer overflow: output large integer
4461 and correct fraction.
4462 Note, the BSD MicroVAX compiler says that ~(0UL)
4463 is a syntax error. */
4467 warning ("overflow on truncation to unsigned integer");
4471 /* Shift more than 16 bits: first shift up k-16 mod 16,
4472 then shift up by 16's. */
4473 j
= k
- ((k
>> 4) << 4);
4480 ll
= (ll
<< 16) | xi
[M
];
4482 while ((k
-= 16) > 0);
4487 /* shift not more than 16 bits */
4489 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4492 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4498 if ((k
= enormlz (xi
)) > NBITS
)
4501 xi
[E
] -= (UEMUSHORT
) k
;
4506 /* Shift the significand of exploded e-type X up or down by SC bits. */
4527 lost
|= *p
; /* remember lost bits */
4568 return ((int) lost
);
4571 /* Shift normalize the significand area of exploded e-type X.
4572 Return the shift count (up = positive). */
4587 return (0); /* already normalized */
4593 /* With guard word, there are NBITS+16 bits available.
4594 Return true if all are zero. */
4598 /* see if high byte is zero */
4599 while ((*p
& 0xff00) == 0)
4604 /* now shift 1 bit at a time */
4605 while ((*p
& 0x8000) == 0)
4611 mtherr ("enormlz", UNDERFLOW
);
4617 /* Normalize by shifting down out of the high guard word
4618 of the significand */
4633 mtherr ("enormlz", OVERFLOW
);
4640 /* Powers of ten used in decimal <-> binary conversions. */
4645 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && (INTEL_EXTENDED_IEEE_FORMAT == 0)
4646 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4648 {0x6576, 0x4a92, 0x804a, 0x153f,
4649 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4650 {0x6a32, 0xce52, 0x329a, 0x28ce,
4651 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4652 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4653 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4654 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4655 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4656 {0x851e, 0xeab7, 0x98fe, 0x901b,
4657 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4658 {0x0235, 0x0137, 0x36b1, 0x336c,
4659 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4660 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4661 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4662 {0x0000, 0x0000, 0x0000, 0x0000,
4663 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4664 {0x0000, 0x0000, 0x0000, 0x0000,
4665 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4666 {0x0000, 0x0000, 0x0000, 0x0000,
4667 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4668 {0x0000, 0x0000, 0x0000, 0x0000,
4669 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4670 {0x0000, 0x0000, 0x0000, 0x0000,
4671 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4672 {0x0000, 0x0000, 0x0000, 0x0000,
4673 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4676 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4678 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4679 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4680 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4681 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4682 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4683 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4684 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4685 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4686 {0xa23e, 0x5308, 0xfefb, 0x1155,
4687 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4688 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4689 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4690 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4691 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4692 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4693 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4694 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4695 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4696 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4697 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4698 {0xc155, 0xa4a8, 0x404e, 0x6113,
4699 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4700 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4701 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4702 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4703 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4706 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4707 static const UEMUSHORT etens
[NTEN
+ 1][NE
] =
4709 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4710 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4711 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4712 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4713 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4714 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4715 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4716 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4717 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4718 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4719 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4720 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4721 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4724 static const UEMUSHORT emtens
[NTEN
+ 1][NE
] =
4726 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4727 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4728 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4729 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4730 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4731 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4732 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4733 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4734 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4735 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4736 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4737 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4738 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4743 /* Convert float value X to ASCII string STRING with NDIG digits after
4744 the decimal point. */
4747 e24toasc (x
, string
, ndigs
)
4748 const UEMUSHORT x
[];
4755 etoasc (w
, string
, ndigs
);
4758 /* Convert double value X to ASCII string STRING with NDIG digits after
4759 the decimal point. */
4762 e53toasc (x
, string
, ndigs
)
4763 const UEMUSHORT x
[];
4770 etoasc (w
, string
, ndigs
);
4773 /* Convert double extended value X to ASCII string STRING with NDIG digits
4774 after the decimal point. */
4777 e64toasc (x
, string
, ndigs
)
4778 const UEMUSHORT x
[];
4785 etoasc (w
, string
, ndigs
);
4788 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4789 after the decimal point. */
4792 e113toasc (x
, string
, ndigs
)
4793 const UEMUSHORT x
[];
4800 etoasc (w
, string
, ndigs
);
4804 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4805 the decimal point. */
4807 static char wstring
[80]; /* working storage for ASCII output */
4810 etoasc (x
, string
, ndigs
)
4811 const UEMUSHORT x
[];
4816 UEMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4817 const UEMUSHORT
*p
, *r
, *ten
;
4819 int i
, j
, k
, expon
, rndsav
;
4832 sprintf (wstring
, " NaN ");
4836 rndprc
= NBITS
; /* set to full precision */
4837 emov (x
, y
); /* retain external format */
4838 if (y
[NE
- 1] & 0x8000)
4841 y
[NE
- 1] &= 0x7fff;
4848 ten
= &etens
[NTEN
][0];
4850 /* Test for zero exponent */
4853 for (k
= 0; k
< NE
- 1; k
++)
4856 goto tnzro
; /* denormalized number */
4858 goto isone
; /* valid all zeros */
4862 /* Test for infinity. */
4863 if (y
[NE
- 1] == 0x7fff)
4866 sprintf (wstring
, " -Infinity ");
4868 sprintf (wstring
, " Infinity ");
4872 /* Test for exponent nonzero but significand denormalized.
4873 * This is an error condition.
4875 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4877 mtherr ("etoasc", DOMAIN
);
4878 sprintf (wstring
, "NaN");
4882 /* Compare to 1.0 */
4891 { /* Number is greater than 1 */
4892 /* Convert significand to an integer and strip trailing decimal zeros. */
4894 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4896 p
= &etens
[NTEN
- 4][0];
4902 for (j
= 0; j
< NE
- 1; j
++)
4915 /* Rescale from integer significand */
4916 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4918 /* Find power of 10 */
4922 /* An unordered compare result shouldn't happen here. */
4923 while (ecmp (ten
, u
) <= 0)
4925 if (ecmp (p
, u
) <= 0)
4938 { /* Number is less than 1.0 */
4939 /* Pad significand with trailing decimal zeros. */
4942 while ((y
[NE
- 2] & 0x8000) == 0)
4951 for (i
= 0; i
< NDEC
+ 1; i
++)
4953 if ((w
[NI
- 1] & 0x7) != 0)
4955 /* multiply by 10 */
4968 if (eone
[NE
- 1] <= u
[1])
4980 while (ecmp (eone
, w
) > 0)
4982 if (ecmp (p
, w
) >= 0)
4997 /* Find the first (leading) digit. */
5003 digit
= equot
[NI
- 1];
5004 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
5012 digit
= equot
[NI
- 1];
5020 /* Examine number of digits requested by caller. */
5038 *s
++ = (char) digit
+ '0';
5041 /* Generate digits after the decimal point. */
5042 for (k
= 0; k
<= ndigs
; k
++)
5044 /* multiply current number by 10, without normalizing */
5051 *s
++ = (char) equot
[NI
- 1] + '0';
5053 digit
= equot
[NI
- 1];
5056 /* round off the ASCII string */
5059 /* Test for critical rounding case in ASCII output. */
5063 if (ecmp (t
, ezero
) != 0)
5064 goto roun
; /* round to nearest */
5066 if ((*(s
- 1) & 1) == 0)
5067 goto doexp
; /* round to even */
5070 /* Round up and propagate carry-outs */
5074 /* Carry out to most significant digit? */
5081 /* Most significant digit carries to 10? */
5089 /* Round up and carry out from less significant digits */
5101 sprintf (ss, "e+%d", expon);
5103 sprintf (ss, "e%d", expon);
5105 sprintf (ss
, "e%d", expon
);
5108 /* copy out the working string */
5111 while (*ss
== ' ') /* strip possible leading space */
5113 while ((*s
++ = *ss
++) != '\0')
5118 /* Convert ASCII string to floating point.
5120 Numeric input is a free format decimal number of any length, with
5121 or without decimal point. Entering E after the number followed by an
5122 integer number causes the second number to be interpreted as a power of
5123 10 to be multiplied by the first number (i.e., "scientific" notation). */
5125 /* Convert ASCII string S to single precision float value Y. */
5136 /* Convert ASCII string S to double precision value Y. */
5143 #if defined(DEC) || defined(IBM)
5155 /* Convert ASCII string S to double extended value Y. */
5165 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5166 /* Convert ASCII string S to 128-bit long double Y. */
5173 asctoeg (s
, y
, 113);
5177 /* Convert ASCII string S to e type Y. */
5184 asctoeg (s
, y
, NBITS
);
5187 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5188 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
5191 asctoeg (ss
, y
, oprec
)
5196 UEMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5197 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5198 int i
, k
, trail
, c
, rndsav
;
5201 char *sp
, *s
, *lstr
;
5204 /* Copy the input string. */
5205 lstr
= (char *) alloca (strlen (ss
) + 1);
5207 while (*ss
== ' ') /* skip leading spaces */
5211 while ((*sp
++ = *ss
++) != '\0')
5215 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5222 rndprc
= NBITS
; /* Set to full precision */
5235 if ((k
>= 0) && (k
< base
))
5237 /* Ignore leading zeros */
5238 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5240 /* Identify and strip trailing zeros after the decimal point. */
5241 if ((trail
== 0) && (decflg
!= 0))
5244 while (ISDIGIT (*sp
) || (base
== 16 && ISXDIGIT (*sp
)))
5246 /* Check for syntax error */
5248 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5249 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5251 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5253 goto unexpected_char_error
;
5262 /* If enough digits were given to more than fill up the yy register,
5263 continuing until overflow into the high guard word yy[2]
5264 guarantees that there will be a roundoff bit at the top
5265 of the low guard word after normalization. */
5272 nexp
+= 4; /* count digits after decimal point */
5274 eshup1 (yy
); /* multiply current number by 16 */
5282 nexp
+= 1; /* count digits after decimal point */
5284 eshup1 (yy
); /* multiply current number by 10 */
5290 /* Insert the current digit. */
5292 xt
[NI
- 2] = (UEMUSHORT
) k
;
5297 /* Mark any lost non-zero digit. */
5299 /* Count lost digits before the decimal point. */
5321 case '.': /* decimal point */
5323 goto unexpected_char_error
;
5329 goto unexpected_char_error
;
5334 goto unexpected_char_error
;
5347 unexpected_char_error
:
5351 mtherr ("asctoe", DOMAIN
);
5360 /* Exponent interpretation */
5362 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5363 for (k
= 0; k
< NI
; k
++)
5374 /* check for + or - */
5382 while (ISDIGIT (*s
))
5391 if ((exp
> MAXDECEXP
) && (base
== 10))
5395 yy
[E
] = 0x7fff; /* infinity */
5398 if ((exp
< MINDECEXP
) && (base
== 10))
5408 /* Base 16 hexadecimal floating constant. */
5409 if ((k
= enormlz (yy
)) > NBITS
)
5414 /* Adjust the exponent. NEXP is the number of hex digits,
5415 EXP is a power of 2. */
5416 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5426 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5427 while ((nexp
> 0) && (yy
[2] == 0))
5439 if ((k
= enormlz (yy
)) > NBITS
)
5444 lexp
= (EXONE
- 1 + NBITS
) - k
;
5445 emdnorm (yy
, lost
, 0, lexp
, 64);
5448 /* Convert to external format:
5450 Multiply by 10**nexp. If precision is 64 bits,
5451 the maximum relative error incurred in forming 10**n
5452 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5453 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5454 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5469 /* Punt. Can't handle this without 2 divides. */
5470 emovi (etens
[0], tt
);
5483 emul (etens
[i
], xt
, xt
);
5487 while (exp
<= MAXP
);
5506 /* Round and convert directly to the destination type */
5508 lexp
-= EXONE
- 0x3ff;
5510 else if (oprec
== 24 || oprec
== 32)
5511 lexp
-= (EXONE
- 0x7f);
5514 else if (oprec
== 24 || oprec
== 56)
5515 lexp
-= EXONE
- (0x41 << 2);
5517 else if (oprec
== 24)
5518 lexp
-= EXONE
- 0177;
5522 else if (oprec
== 56)
5523 lexp
-= EXONE
- 0201;
5526 emdnorm (yy
, lost
, 0, lexp
, 64);
5536 todec (yy
, y
); /* see etodec.c */
5541 toibm (yy
, y
, DFmode
);
5546 toc4x (yy
, y
, HFmode
);
5559 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
5572 /* Return Y = largest integer not greater than X (truncated toward minus
5575 static const UEMUSHORT bmask
[] =
5598 const UEMUSHORT x
[];
5605 emov (x
, f
); /* leave in external format */
5606 expon
= (int) f
[NE
- 1];
5607 e
= (expon
& 0x7fff) - (EXONE
- 1);
5613 /* number of bits to clear out */
5625 /* clear the remaining bits */
5627 /* truncate negatives toward minus infinity */
5630 if ((UEMUSHORT
) expon
& (UEMUSHORT
) 0x8000)
5632 for (i
= 0; i
< NE
- 1; i
++)
5645 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5646 For example, 1.1 = 0.55 * 2^1. */
5650 const UEMUSHORT x
[];
5658 /* Handle denormalized numbers properly using long integer exponent. */
5659 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5667 *exp
= (int) (li
- 0x3ffe);
5671 /* Return e type Y = X * 2^PWR2. */
5675 const UEMUSHORT x
[];
5687 emdnorm (xi
, i
, i
, li
, 64);
5693 /* C = remainder after dividing B by A, all e type values.
5694 Least significant integer quotient bits left in EQUOT. */
5698 const UEMUSHORT a
[], b
[];
5701 UEMUSHORT den
[NI
], num
[NI
];
5705 || (ecmp (a
, ezero
) == 0)
5713 if (ecmp (a
, ezero
) == 0)
5715 mtherr ("eremain", SING
);
5721 eiremain (den
, num
);
5722 /* Sign of remainder = sign of quotient */
5731 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5732 remainder in NUM. */
5736 UEMUSHORT den
[], num
[];
5742 ld
-= enormlz (den
);
5744 ln
-= enormlz (num
);
5748 if (ecmpm (den
, num
) <= 0)
5760 emdnorm (num
, 0, 0, ln
, 0);
5763 /* Report an error condition CODE encountered in function NAME.
5765 Mnemonic Value Significance
5767 DOMAIN 1 argument domain error
5768 SING 2 function singularity
5769 OVERFLOW 3 overflow range error
5770 UNDERFLOW 4 underflow range error
5771 TLOSS 5 total loss of precision
5772 PLOSS 6 partial loss of precision
5773 INVALID 7 NaN - producing operation
5774 EDOM 33 Unix domain error code
5775 ERANGE 34 Unix range error code
5777 The order of appearance of the following messages is bound to the
5778 error codes defined above. */
5788 /* The string passed by the calling program is supposed to be the
5789 name of the function in which the error occurred.
5790 The code argument selects which error message string will be printed. */
5792 if (strcmp (name
, "esub") == 0)
5793 name
= "subtraction";
5794 else if (strcmp (name
, "ediv") == 0)
5796 else if (strcmp (name
, "emul") == 0)
5797 name
= "multiplication";
5798 else if (strcmp (name
, "enormlz") == 0)
5799 name
= "normalization";
5800 else if (strcmp (name
, "etoasc") == 0)
5801 name
= "conversion to text";
5802 else if (strcmp (name
, "asctoe") == 0)
5804 else if (strcmp (name
, "eremain") == 0)
5806 else if (strcmp (name
, "esqrt") == 0)
5807 name
= "square root";
5812 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5813 case SING
: warning ("%s: function singularity" , name
); break;
5814 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5815 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5816 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5817 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5818 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5823 /* Set global error message word */
5828 /* Convert DEC double precision D to e type E. */
5838 ecleaz (y
); /* start with a zero */
5839 p
= y
; /* point to our number */
5840 r
= *d
; /* get DEC exponent word */
5841 if (*d
& (unsigned int) 0x8000)
5842 *p
= 0xffff; /* fill in our sign */
5843 ++p
; /* bump pointer to our exponent word */
5844 r
&= 0x7fff; /* strip the sign bit */
5845 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5849 r
>>= 7; /* shift exponent word down 7 bits */
5850 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5851 /* add our e type exponent offset */
5852 *p
++ = r
; /* to form our exponent */
5854 r
= *d
++; /* now do the high order mantissa */
5855 r
&= 0177; /* strip off the DEC exponent and sign bits */
5856 r
|= 0200; /* the DEC understood high order mantissa bit */
5857 *p
++ = r
; /* put result in our high guard word */
5859 *p
++ = *d
++; /* fill in the rest of our mantissa */
5863 eshdn8 (y
); /* shift our mantissa down 8 bits */
5868 /* Convert e type X to DEC double precision D. */
5880 /* Adjust exponent for offsets. */
5881 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5882 /* Round off to nearest or even. */
5885 emdnorm (xi
, 0, 0, exp
, 64);
5890 /* Convert exploded e-type X, that has already been rounded to
5891 56-bit precision, to DEC format double Y. */
5937 /* Convert IBM single/double precision to e type. */
5943 enum machine_mode mode
;
5948 ecleaz (y
); /* start with a zero */
5949 p
= y
; /* point to our number */
5950 r
= *d
; /* get IBM exponent word */
5951 if (*d
& (unsigned int) 0x8000)
5952 *p
= 0xffff; /* fill in our sign */
5953 ++p
; /* bump pointer to our exponent word */
5954 r
&= 0x7f00; /* strip the sign bit */
5955 r
>>= 6; /* shift exponent word down 6 bits */
5956 /* in fact shift by 8 right and 2 left */
5957 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5958 /* add our e type exponent offset */
5959 *p
++ = r
; /* to form our exponent */
5961 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5962 /* strip off the IBM exponent and sign bits */
5963 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5965 *p
++ = *d
++; /* fill in the rest of our mantissa */
5970 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5973 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5974 /* handle change in RADIX */
5980 /* Convert e type to IBM single/double precision. */
5986 enum machine_mode mode
;
5993 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5994 /* round off to nearest or even */
5997 emdnorm (xi
, 0, 0, exp
, 64);
5999 toibm (xi
, d
, mode
);
6005 enum machine_mode mode
;
6058 /* Convert C4X single/double precision to e type. */
6064 enum machine_mode mode
;
6082 /* Short-circuit the zero case. */
6083 if ((dn
[0] == 0x8000)
6084 && (dn
[1] == 0x0000)
6085 && ((mode
== QFmode
) || ((dn
[2] == 0x0000) && (dn
[3] == 0x0000))))
6096 ecleaz (y
); /* start with a zero */
6097 r
= dn
[0]; /* get sign/exponent part */
6098 if (r
& (unsigned int) 0x0080)
6100 y
[0] = 0xffff; /* fill in our sign */
6106 r
>>= 8; /* Shift exponent word down 8 bits. */
6107 if (r
& 0x80) /* Make the exponent negative if it is. */
6108 r
= r
| (~0 & ~0xff);
6112 /* Now do the high order mantissa. We don't "or" on the high bit
6113 because it is 2 (not 1) and is handled a little differently
6115 y
[M
] = dn
[0] & 0x7f;
6118 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6120 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6128 /* Now do the two's complement on the data. */
6130 carry
= 1; /* Initially add 1 for the two's complement. */
6131 for (i
=size
+ M
; i
> M
; i
--)
6133 if (carry
&& (y
[i
] == 0x0000))
6134 /* We overflowed into the next word, carry is the same. */
6135 y
[i
] = carry
? 0x0000 : 0xffff;
6138 /* No overflow, just invert and add carry. */
6139 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6154 /* Add our e type exponent offset to form our exponent. */
6158 /* Now do the high order mantissa strip off the exponent and sign
6159 bits and add the high 1 bit. */
6160 y
[M
] = (dn
[0] & 0x7f) | 0x80;
6163 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6165 y
[M
+2] = dn
[2]; /* Fill in the rest of our mantissa. */
6175 /* Convert e type to C4X single/double precision. */
6181 enum machine_mode mode
;
6189 /* Adjust exponent for offsets. */
6190 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6192 /* Round off to nearest or even. */
6194 rndprc
= mode
== QFmode
? 24 : 32;
6195 emdnorm (xi
, 0, 0, exp
, 64);
6197 toc4x (xi
, d
, mode
);
6203 enum machine_mode mode
;
6209 /* Short-circuit the zero case */
6210 if ((x
[0] == 0) /* Zero exponent and sign */
6212 && (x
[M
] == 0) /* The rest is for zero mantissa */
6214 /* Only check for double if necessary */
6215 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6217 /* We have a zero. Put it into the output and return. */
6230 /* Negative number require a two's complement conversion of the
6236 i
= ((int) x
[1]) - 0x7f;
6238 /* Now add 1 to the inverted data to do the two's complement. */
6247 x
[v
] = carry
? 0x0000 : 0xffff;
6250 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6256 /* The following is a special case. The C4X negative float requires
6257 a zero in the high bit (because the format is (2 - x) x 2^m), so
6258 if a one is in that bit, we have to shift left one to get rid
6259 of it. This only occurs if the number is -1 x 2^m. */
6260 if (x
[M
+1] & 0x8000)
6262 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6263 high sign bit and shift the exponent. */
6269 i
= ((int) x
[1]) - 0x7f;
6271 if ((i
< -128) || (i
> 127))
6279 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6280 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6288 y
[0] |= ((i
& 0xff) << 8);
6292 y
[0] |= x
[M
] & 0x7f;
6298 y
[3] = (y
[1] << 8) | ((y
[2] >> 8) & 0xff);
6299 y
[2] = (y
[0] << 8) | ((y
[1] >> 8) & 0xff);
6304 /* Output a binary NaN bit pattern in the target machine's format. */
6306 /* If special NaN bit patterns are required, define them in tm.h
6307 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6313 static const UEMUSHORT TFbignan
[8] =
6314 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6315 static const UEMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6323 static const UEMUSHORT XFbignan
[6] =
6324 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6325 static const UEMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6333 static const UEMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6334 static const UEMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6342 static const UEMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6343 static const UEMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6350 make_nan (nan
, sign
, mode
)
6353 enum machine_mode mode
;
6360 /* Possibly the `reserved operand' patterns on a VAX can be
6361 used like NaN's, but probably not in the same way as IEEE. */
6362 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6364 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)
6366 if (REAL_WORDS_BIG_ENDIAN
)
6376 if (REAL_WORDS_BIG_ENDIAN
)
6384 if (REAL_WORDS_BIG_ENDIAN
)
6393 if (REAL_WORDS_BIG_ENDIAN
)
6403 if (REAL_WORDS_BIG_ENDIAN
)
6404 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6407 if (! REAL_WORDS_BIG_ENDIAN
)
6408 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6412 /* This is the inverse of the function `etarsingle' invoked by
6413 REAL_VALUE_TO_TARGET_SINGLE. */
6416 ereal_unto_float (f
)
6423 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6424 This is the inverse operation to what the function `endian' does. */
6425 if (REAL_WORDS_BIG_ENDIAN
)
6427 s
[0] = (UEMUSHORT
) (f
>> 16);
6428 s
[1] = (UEMUSHORT
) f
;
6432 s
[0] = (UEMUSHORT
) f
;
6433 s
[1] = (UEMUSHORT
) (f
>> 16);
6435 /* Convert and promote the target float to E-type. */
6437 /* Output E-type to REAL_VALUE_TYPE. */
6443 /* This is the inverse of the function `etardouble' invoked by
6444 REAL_VALUE_TO_TARGET_DOUBLE. */
6447 ereal_unto_double (d
)
6454 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6455 if (REAL_WORDS_BIG_ENDIAN
)
6457 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6458 s
[1] = (UEMUSHORT
) d
[0];
6459 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6460 s
[3] = (UEMUSHORT
) d
[1];
6464 /* Target float words are little-endian. */
6465 s
[0] = (UEMUSHORT
) d
[0];
6466 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6467 s
[2] = (UEMUSHORT
) d
[1];
6468 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6470 /* Convert target double to E-type. */
6472 /* Output E-type to REAL_VALUE_TYPE. */
6478 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6479 This is somewhat like ereal_unto_float, but the input types
6480 for these are different. */
6483 ereal_from_float (f
)
6490 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6491 This is the inverse operation to what the function `endian' does. */
6492 if (REAL_WORDS_BIG_ENDIAN
)
6494 s
[0] = (UEMUSHORT
) (f
>> 16);
6495 s
[1] = (UEMUSHORT
) f
;
6499 s
[0] = (UEMUSHORT
) f
;
6500 s
[1] = (UEMUSHORT
) (f
>> 16);
6502 /* Convert and promote the target float to E-type. */
6504 /* Output E-type to REAL_VALUE_TYPE. */
6510 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6511 This is somewhat like ereal_unto_double, but the input types
6512 for these are different.
6514 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6515 data format, with no holes in the bit packing. The first element
6516 of the input array holds the bits that would come first in the
6517 target computer's memory. */
6520 ereal_from_double (d
)
6527 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6528 if (REAL_WORDS_BIG_ENDIAN
)
6530 #if HOST_BITS_PER_WIDE_INT == 32
6531 s
[0] = (UEMUSHORT
) (d
[0] >> 16);
6532 s
[1] = (UEMUSHORT
) d
[0];
6533 s
[2] = (UEMUSHORT
) (d
[1] >> 16);
6534 s
[3] = (UEMUSHORT
) d
[1];
6536 /* In this case the entire target double is contained in the
6537 first array element. The second element of the input is
6539 s
[0] = (UEMUSHORT
) (d
[0] >> 48);
6540 s
[1] = (UEMUSHORT
) (d
[0] >> 32);
6541 s
[2] = (UEMUSHORT
) (d
[0] >> 16);
6542 s
[3] = (UEMUSHORT
) d
[0];
6547 /* Target float words are little-endian. */
6548 s
[0] = (UEMUSHORT
) d
[0];
6549 s
[1] = (UEMUSHORT
) (d
[0] >> 16);
6550 #if HOST_BITS_PER_WIDE_INT == 32
6551 s
[2] = (UEMUSHORT
) d
[1];
6552 s
[3] = (UEMUSHORT
) (d
[1] >> 16);
6554 s
[2] = (UEMUSHORT
) (d
[0] >> 32);
6555 s
[3] = (UEMUSHORT
) (d
[0] >> 48);
6558 /* Convert target double to E-type. */
6560 /* Output E-type to REAL_VALUE_TYPE. */
6567 /* Convert target computer unsigned 64-bit integer to e-type.
6568 The endian-ness of DImode follows the convention for integers,
6569 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6573 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6580 if (WORDS_BIG_ENDIAN
)
6582 for (k
= M
; k
< M
+ 4; k
++)
6587 for (k
= M
+ 3; k
>= M
; k
--)
6590 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6591 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6592 ecleaz (yi
); /* it was zero */
6594 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6598 /* Convert target computer signed 64-bit integer to e-type. */
6602 const UEMUSHORT
*di
; /* Address of the 64-bit int. */
6605 unsigned EMULONG acc
;
6611 if (WORDS_BIG_ENDIAN
)
6613 for (k
= M
; k
< M
+ 4; k
++)
6618 for (k
= M
+ 3; k
>= M
; k
--)
6621 /* Take absolute value */
6627 for (k
= M
+ 3; k
>= M
; k
--)
6629 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6636 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6637 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6638 ecleaz (yi
); /* it was zero */
6640 yi
[E
] -= (UEMUSHORT
) k
;/* subtract shift count from exponent */
6647 /* Convert e-type to unsigned 64-bit int. */
6663 k
= (int) xi
[E
] - (EXONE
- 1);
6666 for (j
= 0; j
< 4; j
++)
6672 for (j
= 0; j
< 4; j
++)
6675 warning ("overflow on truncation to integer");
6680 /* Shift more than 16 bits: first shift up k-16 mod 16,
6681 then shift up by 16's. */
6682 j
= k
- ((k
>> 4) << 4);
6686 if (WORDS_BIG_ENDIAN
)
6697 if (WORDS_BIG_ENDIAN
)
6702 while ((k
-= 16) > 0);
6706 /* shift not more than 16 bits */
6711 if (WORDS_BIG_ENDIAN
)
6730 /* Convert e-type to signed 64-bit int. */
6737 unsigned EMULONG acc
;
6744 k
= (int) xi
[E
] - (EXONE
- 1);
6747 for (j
= 0; j
< 4; j
++)
6753 for (j
= 0; j
< 4; j
++)
6756 warning ("overflow on truncation to integer");
6762 /* Shift more than 16 bits: first shift up k-16 mod 16,
6763 then shift up by 16's. */
6764 j
= k
- ((k
>> 4) << 4);
6768 if (WORDS_BIG_ENDIAN
)
6779 if (WORDS_BIG_ENDIAN
)
6784 while ((k
-= 16) > 0);
6788 /* shift not more than 16 bits */
6791 if (WORDS_BIG_ENDIAN
)
6807 /* Negate if negative */
6811 if (WORDS_BIG_ENDIAN
)
6813 for (k
= 0; k
< 4; k
++)
6815 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6816 if (WORDS_BIG_ENDIAN
)
6828 /* Longhand square root routine. */
6831 static int esqinited
= 0;
6832 static unsigned short sqrndbit
[NI
];
6839 UEMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6841 int i
, j
, k
, n
, nlups
;
6846 sqrndbit
[NI
- 2] = 1;
6849 /* Check for arg <= 0 */
6850 i
= ecmp (x
, ezero
);
6855 mtherr ("esqrt", DOMAIN
);
6871 /* Bring in the arg and renormalize if it is denormal. */
6873 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6877 /* Divide exponent by 2 */
6879 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6881 /* Adjust if exponent odd */
6891 n
= 8; /* get 8 bits of result per inner loop */
6897 /* bring in next word of arg */
6899 num
[NI
- 1] = xx
[j
+ 3];
6900 /* Do additional bit on last outer loop, for roundoff. */
6903 for (i
= 0; i
< n
; i
++)
6905 /* Next 2 bits of arg */
6908 /* Shift up answer */
6910 /* Make trial divisor */
6911 for (k
= 0; k
< NI
; k
++)
6914 eaddm (sqrndbit
, temp
);
6915 /* Subtract and insert answer bit if it goes in */
6916 if (ecmpm (temp
, num
) <= 0)
6926 /* Adjust for extra, roundoff loop done. */
6927 exp
+= (NBITS
- 1) - rndprc
;
6929 /* Sticky bit = 1 if the remainder is nonzero. */
6931 for (i
= 3; i
< NI
; i
++)
6934 /* Renormalize and round off. */
6935 emdnorm (sq
, k
, 0, exp
, 64);
6939 #endif /* EMU_NON_COMPILE not defined */
6941 /* Return the binary precision of the significand for a given
6942 floating point mode. The mode can hold an integer value
6943 that many bits wide, without losing any bits. */
6946 significand_size (mode
)
6947 enum machine_mode mode
;
6950 /* Don't test the modes, but their sizes, lest this
6951 code won't work for BITS_PER_UNIT != 8 . */
6953 switch (GET_MODE_BITSIZE (mode
))
6957 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6964 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6967 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6970 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6973 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6986 #if (INTEL_EXTENDED_IEEE_FORMAT == 0)