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 Free Software Foundation, Inc.
5 Contributed by Stephen L. Moshier (moshier@world.std.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
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
100 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
101 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
102 separate the floating point unit's endian-ness from that of
103 the integer addressing. This permits one to define a big-endian
104 FPU on a little-endian machine (e.g., ARM). An extension to
105 BYTES_BIG_ENDIAN may be required for some machines in the future.
106 These optional macros may be defined in tm.h. In real.h, they
107 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
108 them for any normal host or target machine on which the floats
109 and the integers have the same endian-ness. */
112 /* The following converts gcc macros into the ones used by this file. */
114 /* REAL_ARITHMETIC defined means that macros in real.h are
115 defined to call emulator functions. */
116 #ifdef REAL_ARITHMETIC
118 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
119 /* PDP-11, Pro350, VAX: */
121 #else /* it's not VAX */
122 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
123 /* IBM System/370 style */
125 #else /* it's also not an IBM */
126 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
127 /* TMS320C3x/C4x style */
129 #else /* it's also not a C4X */
130 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
132 #else /* it's not IEEE either */
133 /* UNKnown arithmetic. We don't support this and can't go on. */
134 unknown arithmetic type
136 #endif /* not IEEE */
141 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
144 /* REAL_ARITHMETIC not defined means that the *host's* data
145 structure will be used. It may differ by endian-ness from the
146 target machine's structure and will get its ends swapped
147 accordingly (but not here). Probably only the decimal <-> binary
148 functions in this file will actually be used in this case. */
150 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
152 #else /* it's not VAX */
153 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
154 /* IBM System/370 style */
156 #else /* it's also not an IBM */
157 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
159 #else /* it's not IEEE either */
160 unknown arithmetic type
162 #endif /* not IEEE */
166 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
168 #endif /* REAL_ARITHMETIC not defined */
170 /* Define INFINITY for support of infinity.
171 Define NANS for support of Not-a-Number's (NaN's). */
172 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
177 /* Support of NaNs requires support of infinity. */
184 /* Find a host integer type that is at least 16 bits wide,
185 and another type at least twice whatever that size is. */
187 #if HOST_BITS_PER_CHAR >= 16
188 #define EMUSHORT char
189 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
190 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
192 #if HOST_BITS_PER_SHORT >= 16
193 #define EMUSHORT short
194 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
195 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
197 #if HOST_BITS_PER_INT >= 16
199 #define EMUSHORT_SIZE HOST_BITS_PER_INT
200 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
202 #if HOST_BITS_PER_LONG >= 16
203 #define EMUSHORT long
204 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
205 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
207 /* You will have to modify this program to have a smaller unit size. */
208 #define EMU_NON_COMPILE
214 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
215 #define EMULONG short
217 #if HOST_BITS_PER_INT >= EMULONG_SIZE
220 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
223 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
224 #define EMULONG long long int
226 /* You will have to modify this program to have a smaller unit size. */
227 #define EMU_NON_COMPILE
234 /* The host interface doesn't work if no 16-bit size exists. */
235 #if EMUSHORT_SIZE != 16
236 #define EMU_NON_COMPILE
239 /* OK to continue compilation. */
240 #ifndef EMU_NON_COMPILE
242 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
243 In GET_REAL and PUT_REAL, r and e are pointers.
244 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
245 in memory, with no holes. */
247 #if MAX_LONG_DOUBLE_TYPE_SIZE == 96
248 /* Number of 16 bit words in external e type format */
250 #define MAXDECEXP 4932
251 #define MINDECEXP -4956
252 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
253 #define PUT_REAL(e,r) \
255 if (2*NE < sizeof(*r)) \
256 bzero((char *)r, sizeof(*r)); \
257 bcopy ((char *) e, (char *) r, 2*NE); \
259 #else /* no XFmode */
260 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128
262 #define MAXDECEXP 4932
263 #define MINDECEXP -4977
264 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
265 #define PUT_REAL(e,r) \
267 if (2*NE < sizeof(*r)) \
268 bzero((char *)r, sizeof(*r)); \
269 bcopy ((char *) e, (char *) r, 2*NE); \
273 #define MAXDECEXP 4932
274 #define MINDECEXP -4956
275 #ifdef REAL_ARITHMETIC
276 /* Emulator uses target format internally
277 but host stores it in host endian-ness. */
279 #define GET_REAL(r,e) \
281 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
282 e53toe ((unsigned EMUSHORT *) (r), (e)); \
285 unsigned EMUSHORT w[4]; \
286 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
287 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
288 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
289 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
294 #define PUT_REAL(e,r) \
296 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
297 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
300 unsigned EMUSHORT w[4]; \
302 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
303 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
304 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
305 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
309 #else /* not REAL_ARITHMETIC */
311 /* emulator uses host format */
312 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
313 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
315 #endif /* not REAL_ARITHMETIC */
316 #endif /* not TFmode */
317 #endif /* not XFmode */
320 /* Number of 16 bit words in internal format */
323 /* Array offset to exponent */
326 /* Array offset to high guard word */
329 /* Number of bits of precision */
330 #define NBITS ((NI-4)*16)
332 /* Maximum number of decimal digits in ASCII conversion
335 #define NDEC (NBITS*8/27)
337 /* The exponent of 1.0 */
338 #define EXONE (0x3fff)
340 #if defined(HOST_EBCDIC)
341 /* bit 8 is significant in EBCDIC */
342 #define CHARMASK 0xff
344 #define CHARMASK 0x7f
347 extern int extra_warnings
;
348 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
349 extern unsigned EMUSHORT elog2
[], esqrt2
[];
351 static void endian
PARAMS ((unsigned EMUSHORT
*, long *,
353 static void eclear
PARAMS ((unsigned EMUSHORT
*));
354 static void emov
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
356 static void eabs
PARAMS ((unsigned EMUSHORT
*));
358 static void eneg
PARAMS ((unsigned EMUSHORT
*));
359 static int eisneg
PARAMS ((unsigned EMUSHORT
*));
360 static int eisinf
PARAMS ((unsigned EMUSHORT
*));
361 static int eisnan
PARAMS ((unsigned EMUSHORT
*));
362 static void einfin
PARAMS ((unsigned EMUSHORT
*));
364 static void enan
PARAMS ((unsigned EMUSHORT
*, int));
365 static void einan
PARAMS ((unsigned EMUSHORT
*));
366 static int eiisnan
PARAMS ((unsigned EMUSHORT
*));
367 static int eiisneg
PARAMS ((unsigned EMUSHORT
*));
368 static void make_nan
PARAMS ((unsigned EMUSHORT
*, int, enum machine_mode
));
370 static void emovi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
371 static void emovo
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
372 static void ecleaz
PARAMS ((unsigned EMUSHORT
*));
373 static void ecleazs
PARAMS ((unsigned EMUSHORT
*));
374 static void emovz
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void eiinfin
PARAMS ((unsigned EMUSHORT
*));
379 static int eiisinf
PARAMS ((unsigned EMUSHORT
*));
381 static int ecmpm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void eshdn1
PARAMS ((unsigned EMUSHORT
*));
383 static void eshup1
PARAMS ((unsigned EMUSHORT
*));
384 static void eshdn8
PARAMS ((unsigned EMUSHORT
*));
385 static void eshup8
PARAMS ((unsigned EMUSHORT
*));
386 static void eshup6
PARAMS ((unsigned EMUSHORT
*));
387 static void eshdn6
PARAMS ((unsigned EMUSHORT
*));
388 static void eaddm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
389 static void esubm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
390 static void m16m
PARAMS ((unsigned int, unsigned short *,
392 static int edivm
PARAMS ((unsigned short *, unsigned short *));
393 static int emulm
PARAMS ((unsigned short *, unsigned short *));
394 static void emdnorm
PARAMS ((unsigned EMUSHORT
*, int, int, EMULONG
, int));
395 static void esub
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
396 unsigned EMUSHORT
*));
397 static void eadd
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
398 unsigned EMUSHORT
*));
399 static void eadd1
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
400 unsigned EMUSHORT
*));
401 static void ediv
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
402 unsigned EMUSHORT
*));
403 static void emul
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
404 unsigned EMUSHORT
*));
405 static void e53toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
406 static void e64toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
407 static void e113toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
408 static void e24toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
409 static void etoe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
410 static void toe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
411 static void etoe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void toe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void etoe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
414 static void toe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
415 static void etoe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void toe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
417 static int ecmp
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
419 static void eround
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
421 static void ltoe
PARAMS ((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
422 static void ultoe
PARAMS ((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
423 static void eifrac
PARAMS ((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
424 unsigned EMUSHORT
*));
425 static void euifrac
PARAMS ((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
426 unsigned EMUSHORT
*));
427 static int eshift
PARAMS ((unsigned EMUSHORT
*, int));
428 static int enormlz
PARAMS ((unsigned EMUSHORT
*));
430 static void e24toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
431 static void e53toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
432 static void e64toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
433 static void e113toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
435 static void etoasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
436 static void asctoe24
PARAMS ((const char *, unsigned EMUSHORT
*));
437 static void asctoe53
PARAMS ((const char *, unsigned EMUSHORT
*));
438 static void asctoe64
PARAMS ((const char *, unsigned EMUSHORT
*));
439 static void asctoe113
PARAMS ((const char *, unsigned EMUSHORT
*));
440 static void asctoe
PARAMS ((const char *, unsigned EMUSHORT
*));
441 static void asctoeg
PARAMS ((const char *, unsigned EMUSHORT
*, int));
442 static void efloor
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
444 static void efrexp
PARAMS ((unsigned EMUSHORT
*, int *,
445 unsigned EMUSHORT
*));
447 static void eldexp
PARAMS ((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
449 static void eremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
450 unsigned EMUSHORT
*));
452 static void eiremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
453 static void mtherr
PARAMS ((const char *, int));
455 static void dectoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
456 static void etodec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
457 static void todec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
460 static void ibmtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
462 static void etoibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
464 static void toibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
468 static void c4xtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
470 static void etoc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
472 static void toc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
476 static void uditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
477 static void ditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
478 static void etoudi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
479 static void etodi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
480 static void esqrt
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
483 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
484 swapping ends if required, into output array of longs. The
485 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
489 unsigned EMUSHORT e
[];
491 enum machine_mode mode
;
495 if (REAL_WORDS_BIG_ENDIAN
)
500 /* Swap halfwords in the fourth long. */
501 th
= (unsigned long) e
[6] & 0xffff;
502 t
= (unsigned long) e
[7] & 0xffff;
507 /* Swap halfwords in the third long. */
508 th
= (unsigned long) e
[4] & 0xffff;
509 t
= (unsigned long) e
[5] & 0xffff;
512 /* fall into the double case */
515 /* Swap halfwords in the second word. */
516 th
= (unsigned long) e
[2] & 0xffff;
517 t
= (unsigned long) e
[3] & 0xffff;
520 /* fall into the float case */
524 /* Swap halfwords in the first word. */
525 th
= (unsigned long) e
[0] & 0xffff;
526 t
= (unsigned long) e
[1] & 0xffff;
537 /* Pack the output array without swapping. */
542 /* Pack the fourth long. */
543 th
= (unsigned long) e
[7] & 0xffff;
544 t
= (unsigned long) e
[6] & 0xffff;
549 /* Pack the third long.
550 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
552 th
= (unsigned long) e
[5] & 0xffff;
553 t
= (unsigned long) e
[4] & 0xffff;
556 /* fall into the double case */
559 /* Pack the second long */
560 th
= (unsigned long) e
[3] & 0xffff;
561 t
= (unsigned long) e
[2] & 0xffff;
564 /* fall into the float case */
568 /* Pack the first long */
569 th
= (unsigned long) e
[1] & 0xffff;
570 t
= (unsigned long) e
[0] & 0xffff;
582 /* This is the implementation of the REAL_ARITHMETIC macro. */
585 earith (value
, icode
, r1
, r2
)
586 REAL_VALUE_TYPE
*value
;
591 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
597 /* Return NaN input back to the caller. */
600 PUT_REAL (d1
, value
);
605 PUT_REAL (d2
, value
);
609 code
= (enum tree_code
) icode
;
617 esub (d2
, d1
, v
); /* d1 - d2 */
625 #ifndef REAL_INFINITY
626 if (ecmp (d2
, ezero
) == 0)
629 enan (v
, eisneg (d1
) ^ eisneg (d2
));
636 ediv (d2
, d1
, v
); /* d1/d2 */
639 case MIN_EXPR
: /* min (d1,d2) */
640 if (ecmp (d1
, d2
) < 0)
646 case MAX_EXPR
: /* max (d1,d2) */
647 if (ecmp (d1
, d2
) > 0)
660 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
661 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
667 unsigned EMUSHORT f
[NE
], g
[NE
];
683 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
684 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
690 unsigned EMUSHORT f
[NE
], g
[NE
];
692 unsigned HOST_WIDE_INT l
;
706 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
707 string to binary, rounding off as indicated by the machine_mode argument.
708 Then it promotes the rounded value to REAL_VALUE_TYPE. */
715 unsigned EMUSHORT tem
[NE
], e
[NE
];
758 /* Expansion of REAL_NEGATE. */
764 unsigned EMUSHORT e
[NE
];
774 /* Round real toward zero to HOST_WIDE_INT;
775 implements REAL_VALUE_FIX (x). */
781 unsigned EMUSHORT f
[NE
], g
[NE
];
788 warning ("conversion from NaN to int");
796 /* Round real toward zero to unsigned HOST_WIDE_INT
797 implements REAL_VALUE_UNSIGNED_FIX (x).
798 Negative input returns zero. */
800 unsigned HOST_WIDE_INT
804 unsigned EMUSHORT f
[NE
], g
[NE
];
805 unsigned HOST_WIDE_INT l
;
811 warning ("conversion from NaN to unsigned int");
820 /* REAL_VALUE_FROM_INT macro. */
823 ereal_from_int (d
, i
, j
, mode
)
826 enum machine_mode mode
;
828 unsigned EMUSHORT df
[NE
], dg
[NE
];
829 HOST_WIDE_INT low
, high
;
832 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
839 /* complement and add 1 */
846 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
847 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
849 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
854 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
855 Avoid double-rounding errors later by rounding off now from the
856 extra-wide internal format to the requested precision. */
857 switch (GET_MODE_BITSIZE (mode
))
887 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
890 ereal_from_uint (d
, i
, j
, mode
)
892 unsigned HOST_WIDE_INT i
, j
;
893 enum machine_mode mode
;
895 unsigned EMUSHORT df
[NE
], dg
[NE
];
896 unsigned HOST_WIDE_INT low
, high
;
898 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
902 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
908 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
909 Avoid double-rounding errors later by rounding off now from the
910 extra-wide internal format to the requested precision. */
911 switch (GET_MODE_BITSIZE (mode
))
941 /* REAL_VALUE_TO_INT macro. */
944 ereal_to_int (low
, high
, rr
)
945 HOST_WIDE_INT
*low
, *high
;
948 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
955 warning ("conversion from NaN to int");
961 /* convert positive value */
968 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
969 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
970 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
971 emul (df
, dh
, dg
); /* fractional part is the low word */
972 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
975 /* complement and add 1 */
985 /* REAL_VALUE_LDEXP macro. */
992 unsigned EMUSHORT e
[NE
], y
[NE
];
1005 /* These routines are conditionally compiled because functions
1006 of the same names may be defined in fold-const.c. */
1008 #ifdef REAL_ARITHMETIC
1010 /* Check for infinity in a REAL_VALUE_TYPE. */
1014 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1017 unsigned EMUSHORT e
[NE
];
1020 return (eisinf (e
));
1026 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1030 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1033 unsigned EMUSHORT e
[NE
];
1036 return (eisnan (e
));
1043 /* Check for a negative REAL_VALUE_TYPE number.
1044 This just checks the sign bit, so that -0 counts as negative. */
1050 return ereal_isneg (x
);
1053 /* Expansion of REAL_VALUE_TRUNCATE.
1054 The result is in floating point, rounded to nearest or even. */
1057 real_value_truncate (mode
, arg
)
1058 enum machine_mode mode
;
1059 REAL_VALUE_TYPE arg
;
1061 unsigned EMUSHORT e
[NE
], t
[NE
];
1107 /* If an unsupported type was requested, presume that
1108 the machine files know something useful to do with
1109 the unmodified value. */
1118 /* Try to change R into its exact multiplicative inverse in machine mode
1119 MODE. Return nonzero function value if successful. */
1122 exact_real_inverse (mode
, r
)
1123 enum machine_mode mode
;
1126 unsigned EMUSHORT e
[NE
], einv
[NE
];
1127 REAL_VALUE_TYPE rinv
;
1132 /* Test for input in range. Don't transform IEEE special values. */
1133 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1136 /* Test for a power of 2: all significand bits zero except the MSB.
1137 We are assuming the target has binary (or hex) arithmetic. */
1138 if (e
[NE
- 2] != 0x8000)
1141 for (i
= 0; i
< NE
- 2; i
++)
1147 /* Compute the inverse and truncate it to the required mode. */
1148 ediv (e
, eone
, einv
);
1149 PUT_REAL (einv
, &rinv
);
1150 rinv
= real_value_truncate (mode
, rinv
);
1152 #ifdef CHECK_FLOAT_VALUE
1153 /* This check is not redundant. It may, for example, flush
1154 a supposedly IEEE denormal value to zero. */
1156 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1159 GET_REAL (&rinv
, einv
);
1161 /* Check the bits again, because the truncation might have
1162 generated an arbitrary saturation value on overflow. */
1163 if (einv
[NE
- 2] != 0x8000)
1166 for (i
= 0; i
< NE
- 2; i
++)
1172 /* Fail if the computed inverse is out of range. */
1173 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1176 /* Output the reciprocal and return success flag. */
1180 #endif /* REAL_ARITHMETIC defined */
1182 /* Used for debugging--print the value of R in human-readable format
1191 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1192 fprintf (stderr
, "%s", dstr
);
1196 /* The following routines convert REAL_VALUE_TYPE to the various floating
1197 point formats that are meaningful to supported computers.
1199 The results are returned in 32-bit pieces, each piece stored in a `long'.
1200 This is so they can be printed by statements like
1202 fprintf (file, "%lx, %lx", L[0], L[1]);
1204 that will work on both narrow- and wide-word host computers. */
1206 /* Convert R to a 128-bit long double precision value. The output array L
1207 contains four 32-bit pieces of the result, in the order they would appear
1215 unsigned EMUSHORT e
[NE
];
1219 endian (e
, l
, TFmode
);
1222 /* Convert R to a double extended precision value. The output array L
1223 contains three 32-bit pieces of the result, in the order they would
1224 appear in memory. */
1231 unsigned EMUSHORT e
[NE
];
1235 endian (e
, l
, XFmode
);
1238 /* Convert R to a double precision value. The output array L contains two
1239 32-bit pieces of the result, in the order they would appear in memory. */
1246 unsigned EMUSHORT e
[NE
];
1250 endian (e
, l
, DFmode
);
1253 /* Convert R to a single precision float value stored in the least-significant
1254 bits of a `long'. */
1260 unsigned EMUSHORT e
[NE
];
1265 endian (e
, &l
, SFmode
);
1269 /* Convert X to a decimal ASCII string S for output to an assembly
1270 language file. Note, there is no standard way to spell infinity or
1271 a NaN, so these values may require special treatment in the tm.h
1275 ereal_to_decimal (x
, s
)
1279 unsigned EMUSHORT e
[NE
];
1285 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1286 or -2 if either is a NaN. */
1290 REAL_VALUE_TYPE x
, y
;
1292 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1296 return (ecmp (ex
, ey
));
1299 /* Return 1 if the sign bit of X is set, else return 0. */
1305 unsigned EMUSHORT ex
[NE
];
1308 return (eisneg (ex
));
1311 /* End of REAL_ARITHMETIC interface */
1314 Extended precision IEEE binary floating point arithmetic routines
1316 Numbers are stored in C language as arrays of 16-bit unsigned
1317 short integers. The arguments of the routines are pointers to
1320 External e type data structure, similar to Intel 8087 chip
1321 temporary real format but possibly with a larger significand:
1323 NE-1 significand words (least significant word first,
1324 most significant bit is normally set)
1325 exponent (value = EXONE for 1.0,
1326 top bit is the sign)
1329 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1331 ei[0] sign word (0 for positive, 0xffff for negative)
1332 ei[1] biased exponent (value = EXONE for the number 1.0)
1333 ei[2] high guard word (always zero after normalization)
1335 to ei[NI-2] significand (NI-4 significand words,
1336 most significant word first,
1337 most significant bit is set)
1338 ei[NI-1] low guard word (0x8000 bit is rounding place)
1342 Routines for external format e-type numbers
1344 asctoe (string, e) ASCII string to extended double e type
1345 asctoe64 (string, &d) ASCII string to long double
1346 asctoe53 (string, &d) ASCII string to double
1347 asctoe24 (string, &f) ASCII string to single
1348 asctoeg (string, e, prec) ASCII string to specified precision
1349 e24toe (&f, e) IEEE single precision to e type
1350 e53toe (&d, e) IEEE double precision to e type
1351 e64toe (&d, e) IEEE long double precision to e type
1352 e113toe (&d, e) 128-bit long double precision to e type
1354 eabs (e) absolute value
1356 eadd (a, b, c) c = b + a
1358 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1359 -1 if a < b, -2 if either a or b is a NaN.
1360 ediv (a, b, c) c = b / a
1361 efloor (a, b) truncate to integer, toward -infinity
1362 efrexp (a, exp, s) extract exponent and significand
1363 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1364 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1365 einfin (e) set e to infinity, leaving its sign alone
1366 eldexp (a, n, b) multiply by 2**n
1368 emul (a, b, c) c = b * a
1371 eround (a, b) b = nearest integer value to a
1373 esub (a, b, c) c = b - a
1375 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1376 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1377 e64toasc (&d, str, n) 80-bit long double to ASCII string
1378 e113toasc (&d, str, n) 128-bit long double to ASCII string
1380 etoasc (e, str, n) e to ASCII string, n digits after decimal
1381 etoe24 (e, &f) convert e type to IEEE single precision
1382 etoe53 (e, &d) convert e type to IEEE double precision
1383 etoe64 (e, &d) convert e type to IEEE long double precision
1384 ltoe (&l, e) HOST_WIDE_INT to e type
1385 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1386 eisneg (e) 1 if sign bit of e != 0, else 0
1387 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1388 or is infinite (IEEE)
1389 eisnan (e) 1 if e is a NaN
1392 Routines for internal format exploded e-type numbers
1394 eaddm (ai, bi) add significands, bi = bi + ai
1396 ecleazs (ei) set ei = 0 but leave its sign alone
1397 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1398 edivm (ai, bi) divide significands, bi = bi / ai
1399 emdnorm (ai,l,s,exp) normalize and round off
1400 emovi (a, ai) convert external a to internal ai
1401 emovo (ai, a) convert internal ai to external a
1402 emovz (ai, bi) bi = ai, low guard word of bi = 0
1403 emulm (ai, bi) multiply significands, bi = bi * ai
1404 enormlz (ei) left-justify the significand
1405 eshdn1 (ai) shift significand and guards down 1 bit
1406 eshdn8 (ai) shift down 8 bits
1407 eshdn6 (ai) shift down 16 bits
1408 eshift (ai, n) shift ai n bits up (or down if n < 0)
1409 eshup1 (ai) shift significand and guards up 1 bit
1410 eshup8 (ai) shift up 8 bits
1411 eshup6 (ai) shift up 16 bits
1412 esubm (ai, bi) subtract significands, bi = bi - ai
1413 eiisinf (ai) 1 if infinite
1414 eiisnan (ai) 1 if a NaN
1415 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1416 einan (ai) set ai = NaN
1418 eiinfin (ai) set ai = infinity
1421 The result is always normalized and rounded to NI-4 word precision
1422 after each arithmetic operation.
1424 Exception flags are NOT fully supported.
1426 Signaling NaN's are NOT supported; they are treated the same
1429 Define INFINITY for support of infinity; otherwise a
1430 saturation arithmetic is implemented.
1432 Define NANS for support of Not-a-Number items; otherwise the
1433 arithmetic will never produce a NaN output, and might be confused
1435 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1436 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1437 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1440 Denormals are always supported here where appropriate (e.g., not
1441 for conversion to DEC numbers). */
1443 /* Definitions for error codes that are passed to the common error handling
1446 For Digital Equipment PDP-11 and VAX computers, certain
1447 IBM systems, and others that use numbers with a 56-bit
1448 significand, the symbol DEC should be defined. In this
1449 mode, most floating point constants are given as arrays
1450 of octal integers to eliminate decimal to binary conversion
1451 errors that might be introduced by the compiler.
1453 For computers, such as IBM PC, that follow the IEEE
1454 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1455 Std 754-1985), the symbol IEEE should be defined.
1456 These numbers have 53-bit significands. In this mode, constants
1457 are provided as arrays of hexadecimal 16 bit integers.
1458 The endian-ness of generated values is controlled by
1459 REAL_WORDS_BIG_ENDIAN.
1461 To accommodate other types of computer arithmetic, all
1462 constants are also provided in a normal decimal radix
1463 which one can hope are correctly converted to a suitable
1464 format by the available C language compiler. To invoke
1465 this mode, the symbol UNK is defined.
1467 An important difference among these modes is a predefined
1468 set of machine arithmetic constants for each. The numbers
1469 MACHEP (the machine roundoff error), MAXNUM (largest number
1470 represented), and several other parameters are preset by
1471 the configuration symbol. Check the file const.c to
1472 ensure that these values are correct for your computer.
1474 For ANSI C compatibility, define ANSIC equal to 1. Currently
1475 this affects only the atan2 function and others that use it. */
1477 /* Constant definitions for math error conditions. */
1479 #define DOMAIN 1 /* argument domain error */
1480 #define SING 2 /* argument singularity */
1481 #define OVERFLOW 3 /* overflow range error */
1482 #define UNDERFLOW 4 /* underflow range error */
1483 #define TLOSS 5 /* total loss of precision */
1484 #define PLOSS 6 /* partial loss of precision */
1485 #define INVALID 7 /* NaN-producing operation */
1487 /* e type constants used by high precision check routines */
1489 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128
1491 unsigned EMUSHORT ezero
[NE
] =
1492 {0x0000, 0x0000, 0x0000, 0x0000,
1493 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1494 extern unsigned EMUSHORT ezero
[];
1497 unsigned EMUSHORT ehalf
[NE
] =
1498 {0x0000, 0x0000, 0x0000, 0x0000,
1499 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1500 extern unsigned EMUSHORT ehalf
[];
1503 unsigned EMUSHORT eone
[NE
] =
1504 {0x0000, 0x0000, 0x0000, 0x0000,
1505 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1506 extern unsigned EMUSHORT eone
[];
1509 unsigned EMUSHORT etwo
[NE
] =
1510 {0x0000, 0x0000, 0x0000, 0x0000,
1511 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1512 extern unsigned EMUSHORT etwo
[];
1515 unsigned EMUSHORT e32
[NE
] =
1516 {0x0000, 0x0000, 0x0000, 0x0000,
1517 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1518 extern unsigned EMUSHORT e32
[];
1520 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1521 unsigned EMUSHORT elog2
[NE
] =
1522 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1523 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1524 extern unsigned EMUSHORT elog2
[];
1526 /* 1.41421356237309504880168872420969807856967187537695E0 */
1527 unsigned EMUSHORT esqrt2
[NE
] =
1528 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1529 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1530 extern unsigned EMUSHORT esqrt2
[];
1532 /* 3.14159265358979323846264338327950288419716939937511E0 */
1533 unsigned EMUSHORT epi
[NE
] =
1534 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1535 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1536 extern unsigned EMUSHORT epi
[];
1539 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1540 unsigned EMUSHORT ezero
[NE
] =
1541 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1542 unsigned EMUSHORT ehalf
[NE
] =
1543 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1544 unsigned EMUSHORT eone
[NE
] =
1545 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1546 unsigned EMUSHORT etwo
[NE
] =
1547 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1548 unsigned EMUSHORT e32
[NE
] =
1549 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1550 unsigned EMUSHORT elog2
[NE
] =
1551 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1552 unsigned EMUSHORT esqrt2
[NE
] =
1553 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1554 unsigned EMUSHORT epi
[NE
] =
1555 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1558 /* Control register for rounding precision.
1559 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1564 /* Clear out entire e-type number X. */
1568 register unsigned EMUSHORT
*x
;
1572 for (i
= 0; i
< NE
; i
++)
1576 /* Move e-type number from A to B. */
1580 register unsigned EMUSHORT
*a
, *b
;
1584 for (i
= 0; i
< NE
; i
++)
1590 /* Absolute value of e-type X. */
1594 unsigned EMUSHORT x
[];
1596 /* sign is top bit of last word of external format */
1597 x
[NE
- 1] &= 0x7fff;
1601 /* Negate the e-type number X. */
1605 unsigned EMUSHORT x
[];
1608 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1611 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1615 unsigned EMUSHORT x
[];
1618 if (x
[NE
- 1] & 0x8000)
1624 /* Return 1 if e-type number X is infinity, else return zero. */
1628 unsigned EMUSHORT x
[];
1635 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1641 /* Check if e-type number is not a number. The bit pattern is one that we
1642 defined, so we know for sure how to detect it. */
1646 unsigned EMUSHORT x
[] ATTRIBUTE_UNUSED
;
1651 /* NaN has maximum exponent */
1652 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1654 /* ... and non-zero significand field. */
1655 for (i
= 0; i
< NE
- 1; i
++)
1665 /* Fill e-type number X with infinity pattern (IEEE)
1666 or largest possible number (non-IEEE). */
1670 register unsigned EMUSHORT
*x
;
1675 for (i
= 0; i
< NE
- 1; i
++)
1679 for (i
= 0; i
< NE
- 1; i
++)
1707 /* Output an e-type NaN.
1708 This generates Intel's quiet NaN pattern for extended real.
1709 The exponent is 7fff, the leading mantissa word is c000. */
1714 register unsigned EMUSHORT
*x
;
1719 for (i
= 0; i
< NE
- 2; i
++)
1722 *x
= (sign
<< 15) | 0x7fff;
1726 /* Move in an e-type number A, converting it to exploded e-type B. */
1730 unsigned EMUSHORT
*a
, *b
;
1732 register unsigned EMUSHORT
*p
, *q
;
1736 p
= a
+ (NE
- 1); /* point to last word of external number */
1737 /* get the sign bit */
1742 /* get the exponent */
1744 *q
++ &= 0x7fff; /* delete the sign bit */
1746 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1752 for (i
= 3; i
< NI
; i
++)
1758 for (i
= 2; i
< NI
; i
++)
1764 /* clear high guard word */
1766 /* move in the significand */
1767 for (i
= 0; i
< NE
- 1; i
++)
1769 /* clear low guard word */
1773 /* Move out exploded e-type number A, converting it to e type B. */
1777 unsigned EMUSHORT
*a
, *b
;
1779 register unsigned EMUSHORT
*p
, *q
;
1780 unsigned EMUSHORT i
;
1784 q
= b
+ (NE
- 1); /* point to output exponent */
1785 /* combine sign and exponent */
1788 *q
-- = *p
++ | 0x8000;
1792 if (*(p
- 1) == 0x7fff)
1797 enan (b
, eiisneg (a
));
1805 /* skip over guard word */
1807 /* move the significand */
1808 for (j
= 0; j
< NE
- 1; j
++)
1812 /* Clear out exploded e-type number XI. */
1816 register unsigned EMUSHORT
*xi
;
1820 for (i
= 0; i
< NI
; i
++)
1824 /* Clear out exploded e-type XI, but don't touch the sign. */
1828 register unsigned EMUSHORT
*xi
;
1833 for (i
= 0; i
< NI
- 1; i
++)
1837 /* Move exploded e-type number from A to B. */
1841 register unsigned EMUSHORT
*a
, *b
;
1845 for (i
= 0; i
< NI
- 1; i
++)
1847 /* clear low guard word */
1851 /* Generate exploded e-type NaN.
1852 The explicit pattern for this is maximum exponent and
1853 top two significant bits set. */
1858 unsigned EMUSHORT x
[];
1867 /* Return nonzero if exploded e-type X is a NaN. */
1872 unsigned EMUSHORT x
[];
1876 if ((x
[E
] & 0x7fff) == 0x7fff)
1878 for (i
= M
+ 1; i
< NI
; i
++)
1888 /* Return nonzero if sign of exploded e-type X is nonzero. */
1893 unsigned EMUSHORT x
[];
1901 /* Fill exploded e-type X with infinity pattern.
1902 This has maximum exponent and significand all zeros. */
1906 unsigned EMUSHORT x
[];
1914 /* Return nonzero if exploded e-type X is infinite. */
1919 unsigned EMUSHORT x
[];
1926 if ((x
[E
] & 0x7fff) == 0x7fff)
1930 #endif /* INFINITY */
1932 /* Compare significands of numbers in internal exploded e-type format.
1933 Guard words are included in the comparison.
1941 register unsigned EMUSHORT
*a
, *b
;
1945 a
+= M
; /* skip up to significand area */
1947 for (i
= M
; i
< NI
; i
++)
1955 if (*(--a
) > *(--b
))
1961 /* Shift significand of exploded e-type X down by 1 bit. */
1965 register unsigned EMUSHORT
*x
;
1967 register unsigned EMUSHORT bits
;
1970 x
+= M
; /* point to significand area */
1973 for (i
= M
; i
< NI
; i
++)
1985 /* Shift significand of exploded e-type X up by 1 bit. */
1989 register unsigned EMUSHORT
*x
;
1991 register unsigned EMUSHORT bits
;
1997 for (i
= M
; i
< NI
; i
++)
2010 /* Shift significand of exploded e-type X down by 8 bits. */
2014 register unsigned EMUSHORT
*x
;
2016 register unsigned EMUSHORT newbyt
, oldbyt
;
2021 for (i
= M
; i
< NI
; i
++)
2031 /* Shift significand of exploded e-type X up by 8 bits. */
2035 register unsigned EMUSHORT
*x
;
2038 register unsigned EMUSHORT newbyt
, oldbyt
;
2043 for (i
= M
; i
< NI
; i
++)
2053 /* Shift significand of exploded e-type X up by 16 bits. */
2057 register unsigned EMUSHORT
*x
;
2060 register unsigned EMUSHORT
*p
;
2065 for (i
= M
; i
< NI
- 1; i
++)
2071 /* Shift significand of exploded e-type X down by 16 bits. */
2075 register unsigned EMUSHORT
*x
;
2078 register unsigned EMUSHORT
*p
;
2083 for (i
= M
; i
< NI
- 1; i
++)
2089 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2093 unsigned EMUSHORT
*x
, *y
;
2095 register unsigned EMULONG a
;
2102 for (i
= M
; i
< NI
; i
++)
2104 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2109 *y
= (unsigned EMUSHORT
) a
;
2115 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2119 unsigned EMUSHORT
*x
, *y
;
2128 for (i
= M
; i
< NI
; i
++)
2130 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2135 *y
= (unsigned EMUSHORT
) a
;
2142 static unsigned EMUSHORT equot
[NI
];
2146 /* Radix 2 shift-and-add versions of multiply and divide */
2149 /* Divide significands */
2153 unsigned EMUSHORT den
[], num
[];
2156 register unsigned EMUSHORT
*p
, *q
;
2157 unsigned EMUSHORT j
;
2163 for (i
= M
; i
< NI
; i
++)
2168 /* Use faster compare and subtraction if denominator has only 15 bits of
2174 for (i
= M
+ 3; i
< NI
; i
++)
2179 if ((den
[M
+ 1] & 1) != 0)
2187 for (i
= 0; i
< NBITS
+ 2; i
++)
2205 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2206 bit + 1 roundoff bit. */
2211 for (i
= 0; i
< NBITS
+ 2; i
++)
2213 if (ecmpm (den
, num
) <= 0)
2216 j
= 1; /* quotient bit = 1 */
2230 /* test for nonzero remainder after roundoff bit */
2233 for (i
= M
; i
< NI
; i
++)
2241 for (i
= 0; i
< NI
; i
++)
2247 /* Multiply significands */
2251 unsigned EMUSHORT a
[], b
[];
2253 unsigned EMUSHORT
*p
, *q
;
2258 for (i
= M
; i
< NI
; i
++)
2263 while (*p
== 0) /* significand is not supposed to be zero */
2268 if ((*p
& 0xff) == 0)
2276 for (i
= 0; i
< k
; i
++)
2280 /* remember if there were any nonzero bits shifted out */
2287 for (i
= 0; i
< NI
; i
++)
2290 /* return flag for lost nonzero bits */
2296 /* Radix 65536 versions of multiply and divide. */
2298 /* Multiply significand of e-type number B
2299 by 16-bit quantity A, return e-type result to C. */
2304 unsigned EMUSHORT b
[], c
[];
2306 register unsigned EMUSHORT
*pp
;
2307 register unsigned EMULONG carry
;
2308 unsigned EMUSHORT
*ps
;
2309 unsigned EMUSHORT p
[NI
];
2310 unsigned EMULONG aa
, m
;
2319 for (i
=M
+1; i
<NI
; i
++)
2329 m
= (unsigned EMULONG
) aa
* *ps
--;
2330 carry
= (m
& 0xffff) + *pp
;
2331 *pp
-- = (unsigned EMUSHORT
)carry
;
2332 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2333 *pp
= (unsigned EMUSHORT
)carry
;
2334 *(pp
-1) = carry
>> 16;
2337 for (i
=M
; i
<NI
; i
++)
2341 /* Divide significands of exploded e-types NUM / DEN. Neither the
2342 numerator NUM nor the denominator DEN is permitted to have its high guard
2347 unsigned EMUSHORT den
[], num
[];
2350 register unsigned EMUSHORT
*p
;
2351 unsigned EMULONG tnum
;
2352 unsigned EMUSHORT j
, tdenm
, tquot
;
2353 unsigned EMUSHORT tprod
[NI
+1];
2359 for (i
=M
; i
<NI
; i
++)
2365 for (i
=M
; i
<NI
; i
++)
2367 /* Find trial quotient digit (the radix is 65536). */
2368 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2370 /* Do not execute the divide instruction if it will overflow. */
2371 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2374 tquot
= tnum
/ tdenm
;
2375 /* Multiply denominator by trial quotient digit. */
2376 m16m ((unsigned int)tquot
, den
, tprod
);
2377 /* The quotient digit may have been overestimated. */
2378 if (ecmpm (tprod
, num
) > 0)
2382 if (ecmpm (tprod
, num
) > 0)
2392 /* test for nonzero remainder after roundoff bit */
2395 for (i
=M
; i
<NI
; i
++)
2402 for (i
=0; i
<NI
; i
++)
2408 /* Multiply significands of exploded e-type A and B, result in B. */
2412 unsigned EMUSHORT a
[], b
[];
2414 unsigned EMUSHORT
*p
, *q
;
2415 unsigned EMUSHORT pprod
[NI
];
2416 unsigned EMUSHORT j
;
2421 for (i
=M
; i
<NI
; i
++)
2427 for (i
=M
+1; i
<NI
; i
++)
2435 m16m ((unsigned int) *p
--, b
, pprod
);
2436 eaddm(pprod
, equot
);
2442 for (i
=0; i
<NI
; i
++)
2445 /* return flag for lost nonzero bits */
2451 /* Normalize and round off.
2453 The internal format number to be rounded is S.
2454 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2456 Input SUBFLG indicates whether the number was obtained
2457 by a subtraction operation. In that case if LOST is nonzero
2458 then the number is slightly smaller than indicated.
2460 Input EXP is the biased exponent, which may be negative.
2461 the exponent field of S is ignored but is replaced by
2462 EXP as adjusted by normalization and rounding.
2464 Input RCNTRL is the rounding control. If it is nonzero, the
2465 returned value will be rounded to RNDPRC bits.
2467 For future reference: In order for emdnorm to round off denormal
2468 significands at the right point, the input exponent must be
2469 adjusted to be the actual value it would have after conversion to
2470 the final floating point type. This adjustment has been
2471 implemented for all type conversions (etoe53, etc.) and decimal
2472 conversions, but not for the arithmetic functions (eadd, etc.).
2473 Data types having standard 15-bit exponents are not affected by
2474 this, but SFmode and DFmode are affected. For example, ediv with
2475 rndprc = 24 will not round correctly to 24-bit precision if the
2476 result is denormal. */
2478 static int rlast
= -1;
2480 static unsigned EMUSHORT rmsk
= 0;
2481 static unsigned EMUSHORT rmbit
= 0;
2482 static unsigned EMUSHORT rebit
= 0;
2484 static unsigned EMUSHORT rbit
[NI
];
2487 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2488 unsigned EMUSHORT s
[];
2495 unsigned EMUSHORT r
;
2500 /* a blank significand could mean either zero or infinity. */
2513 if ((j
> NBITS
) && (exp
< 32767))
2521 if (exp
> (EMULONG
) (-NBITS
- 1))
2534 /* Round off, unless told not to by rcntrl. */
2537 /* Set up rounding parameters if the control register changed. */
2538 if (rndprc
!= rlast
)
2545 rw
= NI
- 1; /* low guard word */
2568 /* For DEC or IBM arithmetic */
2585 /* For C4x arithmetic */
2606 /* Shift down 1 temporarily if the data structure has an implied
2607 most significant bit and the number is denormal.
2608 Intel long double denormals also lose one bit of precision. */
2609 if ((exp
<= 0) && (rndprc
!= NBITS
)
2610 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2612 lost
|= s
[NI
- 1] & 1;
2615 /* Clear out all bits below the rounding bit,
2616 remembering in r if any were nonzero. */
2630 if ((r
& rmbit
) != 0)
2636 { /* round to even */
2637 if ((s
[re
] & rebit
) == 0)
2650 /* Undo the temporary shift for denormal values. */
2651 if ((exp
<= 0) && (rndprc
!= NBITS
)
2652 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2657 { /* overflow on roundoff */
2670 for (i
= 2; i
< NI
- 1; i
++)
2673 warning ("floating point overflow");
2677 for (i
= M
+ 1; i
< NI
- 1; i
++)
2680 if ((rndprc
< 64) || (rndprc
== 113))
2695 s
[1] = (unsigned EMUSHORT
) exp
;
2698 /* Subtract. C = B - A, all e type numbers. */
2700 static int subflg
= 0;
2704 unsigned EMUSHORT
*a
, *b
, *c
;
2718 /* Infinity minus infinity is a NaN.
2719 Test for subtracting infinities of the same sign. */
2720 if (eisinf (a
) && eisinf (b
)
2721 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2723 mtherr ("esub", INVALID
);
2732 /* Add. C = A + B, all e type. */
2736 unsigned EMUSHORT
*a
, *b
, *c
;
2740 /* NaN plus anything is a NaN. */
2751 /* Infinity minus infinity is a NaN.
2752 Test for adding infinities of opposite signs. */
2753 if (eisinf (a
) && eisinf (b
)
2754 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2756 mtherr ("esub", INVALID
);
2765 /* Arithmetic common to both addition and subtraction. */
2769 unsigned EMUSHORT
*a
, *b
, *c
;
2771 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2773 EMULONG lt
, lta
, ltb
;
2794 /* compare exponents */
2799 { /* put the larger number in bi */
2809 if (lt
< (EMULONG
) (-NBITS
- 1))
2810 goto done
; /* answer same as larger addend */
2812 lost
= eshift (ai
, k
); /* shift the smaller number down */
2816 /* exponents were the same, so must compare significands */
2819 { /* the numbers are identical in magnitude */
2820 /* if different signs, result is zero */
2826 /* if same sign, result is double */
2827 /* double denormalized tiny number */
2828 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2833 /* add 1 to exponent unless both are zero! */
2834 for (j
= 1; j
< NI
- 1; j
++)
2850 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2854 { /* put the larger number in bi */
2870 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2876 /* Divide: C = B/A, all e type. */
2880 unsigned EMUSHORT
*a
, *b
, *c
;
2882 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2884 EMULONG lt
, lta
, ltb
;
2886 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2887 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2888 sign
= eisneg(a
) ^ eisneg(b
);
2891 /* Return any NaN input. */
2902 /* Zero over zero, or infinity over infinity, is a NaN. */
2903 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2904 || (eisinf (a
) && eisinf (b
)))
2906 mtherr ("ediv", INVALID
);
2911 /* Infinity over anything else is infinity. */
2918 /* Anything else over infinity is zero. */
2930 { /* See if numerator is zero. */
2931 for (i
= 1; i
< NI
- 1; i
++)
2935 ltb
-= enormlz (bi
);
2945 { /* possible divide by zero */
2946 for (i
= 1; i
< NI
- 1; i
++)
2950 lta
-= enormlz (ai
);
2954 /* Divide by zero is not an invalid operation.
2955 It is a divide-by-zero operation! */
2957 mtherr ("ediv", SING
);
2963 /* calculate exponent */
2964 lt
= ltb
- lta
+ EXONE
;
2965 emdnorm (bi
, i
, 0, lt
, 64);
2972 && (ecmp (c
, ezero
) != 0)
2975 *(c
+(NE
-1)) |= 0x8000;
2977 *(c
+(NE
-1)) &= ~0x8000;
2980 /* Multiply e-types A and B, return e-type product C. */
2984 unsigned EMUSHORT
*a
, *b
, *c
;
2986 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2988 EMULONG lt
, lta
, ltb
;
2990 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2991 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2992 sign
= eisneg(a
) ^ eisneg(b
);
2995 /* NaN times anything is the same NaN. */
3006 /* Zero times infinity is a NaN. */
3007 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3008 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3010 mtherr ("emul", INVALID
);
3015 /* Infinity times anything else is infinity. */
3017 if (eisinf (a
) || eisinf (b
))
3029 for (i
= 1; i
< NI
- 1; i
++)
3033 lta
-= enormlz (ai
);
3044 for (i
= 1; i
< NI
- 1; i
++)
3048 ltb
-= enormlz (bi
);
3057 /* Multiply significands */
3059 /* calculate exponent */
3060 lt
= lta
+ ltb
- (EXONE
- 1);
3061 emdnorm (bi
, j
, 0, lt
, 64);
3068 && (ecmp (c
, ezero
) != 0)
3071 *(c
+(NE
-1)) |= 0x8000;
3073 *(c
+(NE
-1)) &= ~0x8000;
3076 /* Convert double precision PE to e-type Y. */
3080 unsigned EMUSHORT
*pe
, *y
;
3089 ibmtoe (pe
, y
, DFmode
);
3094 c4xtoe (pe
, y
, HFmode
);
3097 register unsigned EMUSHORT r
;
3098 register unsigned EMUSHORT
*e
, *p
;
3099 unsigned EMUSHORT yy
[NI
];
3103 denorm
= 0; /* flag if denormalized number */
3105 if (! REAL_WORDS_BIG_ENDIAN
)
3111 yy
[M
] = (r
& 0x0f) | 0x10;
3112 r
&= ~0x800f; /* strip sign and 4 significand bits */
3117 if (! REAL_WORDS_BIG_ENDIAN
)
3119 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3120 || (pe
[1] != 0) || (pe
[0] != 0))
3122 enan (y
, yy
[0] != 0);
3128 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3129 || (pe
[2] != 0) || (pe
[3] != 0))
3131 enan (y
, yy
[0] != 0);
3142 #endif /* INFINITY */
3144 /* If zero exponent, then the significand is denormalized.
3145 So take back the understood high significand bit. */
3156 if (! REAL_WORDS_BIG_ENDIAN
)
3173 /* If zero exponent, then normalize the significand. */
3174 if ((k
= enormlz (yy
)) > NBITS
)
3177 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3180 #endif /* not C4X */
3181 #endif /* not IBM */
3182 #endif /* not DEC */
3185 /* Convert double extended precision float PE to e type Y. */
3189 unsigned EMUSHORT
*pe
, *y
;
3191 unsigned EMUSHORT yy
[NI
];
3192 unsigned EMUSHORT
*e
, *p
, *q
;
3197 for (i
= 0; i
< NE
- 5; i
++)
3199 /* This precision is not ordinarily supported on DEC or IBM. */
3201 for (i
= 0; i
< 5; i
++)
3205 p
= &yy
[0] + (NE
- 1);
3208 for (i
= 0; i
< 5; i
++)
3212 if (! REAL_WORDS_BIG_ENDIAN
)
3214 for (i
= 0; i
< 5; i
++)
3217 /* For denormal long double Intel format, shift significand up one
3218 -- but only if the top significand bit is zero. A top bit of 1
3219 is "pseudodenormal" when the exponent is zero. */
3220 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3222 unsigned EMUSHORT temp
[NI
];
3232 p
= &yy
[0] + (NE
- 1);
3233 #ifdef ARM_EXTENDED_IEEE_FORMAT
3234 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3235 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3241 for (i
= 0; i
< 4; i
++)
3246 /* Point to the exponent field and check max exponent cases. */
3248 if ((*p
& 0x7fff) == 0x7fff)
3251 if (! REAL_WORDS_BIG_ENDIAN
)
3253 for (i
= 0; i
< 4; i
++)
3255 if ((i
!= 3 && pe
[i
] != 0)
3256 /* Anything but 0x8000 here, including 0, is a NaN. */
3257 || (i
== 3 && pe
[i
] != 0x8000))
3259 enan (y
, (*p
& 0x8000) != 0);
3266 #ifdef ARM_EXTENDED_IEEE_FORMAT
3267 for (i
= 2; i
<= 5; i
++)
3271 enan (y
, (*p
& 0x8000) != 0);
3276 /* In Motorola extended precision format, the most significant
3277 bit of an infinity mantissa could be either 1 or 0. It is
3278 the lower order bits that tell whether the value is a NaN. */
3279 if ((pe
[2] & 0x7fff) != 0)
3282 for (i
= 3; i
<= 5; i
++)
3287 enan (y
, (*p
& 0x8000) != 0);
3291 #endif /* not ARM */
3300 #endif /* INFINITY */
3303 for (i
= 0; i
< NE
; i
++)
3307 /* Convert 128-bit long double precision float PE to e type Y. */
3311 unsigned EMUSHORT
*pe
, *y
;
3313 register unsigned EMUSHORT r
;
3314 unsigned EMUSHORT
*e
, *p
;
3315 unsigned EMUSHORT yy
[NI
];
3322 if (! REAL_WORDS_BIG_ENDIAN
)
3334 if (! REAL_WORDS_BIG_ENDIAN
)
3336 for (i
= 0; i
< 7; i
++)
3340 enan (y
, yy
[0] != 0);
3347 for (i
= 1; i
< 8; i
++)
3351 enan (y
, yy
[0] != 0);
3363 #endif /* INFINITY */
3367 if (! REAL_WORDS_BIG_ENDIAN
)
3369 for (i
= 0; i
< 7; i
++)
3375 for (i
= 0; i
< 7; i
++)
3379 /* If denormal, remove the implied bit; else shift down 1. */
3392 /* Convert single precision float PE to e type Y. */
3396 unsigned EMUSHORT
*pe
, *y
;
3400 ibmtoe (pe
, y
, SFmode
);
3406 c4xtoe (pe
, y
, QFmode
);
3410 register unsigned EMUSHORT r
;
3411 register unsigned EMUSHORT
*e
, *p
;
3412 unsigned EMUSHORT yy
[NI
];
3416 denorm
= 0; /* flag if denormalized number */
3419 if (! REAL_WORDS_BIG_ENDIAN
)
3429 yy
[M
] = (r
& 0x7f) | 0200;
3430 r
&= ~0x807f; /* strip sign and 7 significand bits */
3435 if (REAL_WORDS_BIG_ENDIAN
)
3437 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3439 enan (y
, yy
[0] != 0);
3445 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3447 enan (y
, yy
[0] != 0);
3458 #endif /* INFINITY */
3460 /* If zero exponent, then the significand is denormalized.
3461 So take back the understood high significand bit. */
3474 if (! REAL_WORDS_BIG_ENDIAN
)
3484 { /* if zero exponent, then normalize the significand */
3485 if ((k
= enormlz (yy
)) > NBITS
)
3488 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3491 #endif /* not C4X */
3492 #endif /* not IBM */
3495 /* Convert e-type X to IEEE 128-bit long double format E. */
3499 unsigned EMUSHORT
*x
, *e
;
3501 unsigned EMUSHORT xi
[NI
];
3508 make_nan (e
, eisneg (x
), TFmode
);
3513 exp
= (EMULONG
) xi
[E
];
3518 /* round off to nearest or even */
3521 emdnorm (xi
, 0, 0, exp
, 64);
3529 /* Convert exploded e-type X, that has already been rounded to
3530 113-bit precision, to IEEE 128-bit long double format Y. */
3534 unsigned EMUSHORT
*a
, *b
;
3536 register unsigned EMUSHORT
*p
, *q
;
3537 unsigned EMUSHORT i
;
3542 make_nan (b
, eiisneg (a
), TFmode
);
3547 if (REAL_WORDS_BIG_ENDIAN
)
3550 q
= b
+ 7; /* point to output exponent */
3552 /* If not denormal, delete the implied bit. */
3557 /* combine sign and exponent */
3559 if (REAL_WORDS_BIG_ENDIAN
)
3562 *q
++ = *p
++ | 0x8000;
3569 *q
-- = *p
++ | 0x8000;
3573 /* skip over guard word */
3575 /* move the significand */
3576 if (REAL_WORDS_BIG_ENDIAN
)
3578 for (i
= 0; i
< 7; i
++)
3583 for (i
= 0; i
< 7; i
++)
3588 /* Convert e-type X to IEEE double extended format E. */
3592 unsigned EMUSHORT
*x
, *e
;
3594 unsigned EMUSHORT xi
[NI
];
3601 make_nan (e
, eisneg (x
), XFmode
);
3606 /* adjust exponent for offset */
3607 exp
= (EMULONG
) xi
[E
];
3612 /* round off to nearest or even */
3615 emdnorm (xi
, 0, 0, exp
, 64);
3623 /* Convert exploded e-type X, that has already been rounded to
3624 64-bit precision, to IEEE double extended format Y. */
3628 unsigned EMUSHORT
*a
, *b
;
3630 register unsigned EMUSHORT
*p
, *q
;
3631 unsigned EMUSHORT i
;
3636 make_nan (b
, eiisneg (a
), XFmode
);
3640 /* Shift denormal long double Intel format significand down one bit. */
3641 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3651 if (REAL_WORDS_BIG_ENDIAN
)
3655 q
= b
+ 4; /* point to output exponent */
3656 /* The purpose of this conditional is to avoid scribbling beyond
3657 the end of a long double, in case the type is only 80 bits wide. */
3658 if (LONG_DOUBLE_TYPE_SIZE
== 96)
3660 /* Clear the last two bytes of 12-byte Intel format */
3666 /* combine sign and exponent */
3670 *q
++ = *p
++ | 0x8000;
3677 *q
-- = *p
++ | 0x8000;
3682 if (REAL_WORDS_BIG_ENDIAN
)
3684 #ifdef ARM_EXTENDED_IEEE_FORMAT
3685 /* The exponent is in the lowest 15 bits of the first word. */
3686 *q
++ = i
? 0x8000 : 0;
3690 *q
++ = *p
++ | 0x8000;
3699 *q
-- = *p
++ | 0x8000;
3704 /* skip over guard word */
3706 /* move the significand */
3708 for (i
= 0; i
< 4; i
++)
3712 for (i
= 0; i
< 4; i
++)
3716 if (REAL_WORDS_BIG_ENDIAN
)
3718 for (i
= 0; i
< 4; i
++)
3726 /* Intel long double infinity significand. */
3734 for (i
= 0; i
< 4; i
++)
3740 /* e type to double precision. */
3743 /* Convert e-type X to DEC-format double E. */
3747 unsigned EMUSHORT
*x
, *e
;
3749 etodec (x
, e
); /* see etodec.c */
3752 /* Convert exploded e-type X, that has already been rounded to
3753 56-bit double precision, to DEC double Y. */
3757 unsigned EMUSHORT
*x
, *y
;
3764 /* Convert e-type X to IBM 370-format double E. */
3768 unsigned EMUSHORT
*x
, *e
;
3770 etoibm (x
, e
, DFmode
);
3773 /* Convert exploded e-type X, that has already been rounded to
3774 56-bit precision, to IBM 370 double Y. */
3778 unsigned EMUSHORT
*x
, *y
;
3780 toibm (x
, y
, DFmode
);
3783 #else /* it's neither DEC nor IBM */
3785 /* Convert e-type X to C4X-format long double E. */
3789 unsigned EMUSHORT
*x
, *e
;
3791 etoc4x (x
, e
, HFmode
);
3794 /* Convert exploded e-type X, that has already been rounded to
3795 56-bit precision, to IBM 370 double Y. */
3799 unsigned EMUSHORT
*x
, *y
;
3801 toc4x (x
, y
, HFmode
);
3804 #else /* it's neither DEC nor IBM nor C4X */
3806 /* Convert e-type X to IEEE double E. */
3810 unsigned EMUSHORT
*x
, *e
;
3812 unsigned EMUSHORT xi
[NI
];
3819 make_nan (e
, eisneg (x
), DFmode
);
3824 /* adjust exponent for offsets */
3825 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3830 /* round off to nearest or even */
3833 emdnorm (xi
, 0, 0, exp
, 64);
3841 /* Convert exploded e-type X, that has already been rounded to
3842 53-bit precision, to IEEE double Y. */
3846 unsigned EMUSHORT
*x
, *y
;
3848 unsigned EMUSHORT i
;
3849 unsigned EMUSHORT
*p
;
3854 make_nan (y
, eiisneg (x
), DFmode
);
3860 if (! REAL_WORDS_BIG_ENDIAN
)
3863 *y
= 0; /* output high order */
3865 *y
= 0x8000; /* output sign bit */
3868 if (i
>= (unsigned int) 2047)
3870 /* Saturate at largest number less than infinity. */
3873 if (! REAL_WORDS_BIG_ENDIAN
)
3887 *y
|= (unsigned EMUSHORT
) 0x7fef;
3888 if (! REAL_WORDS_BIG_ENDIAN
)
3913 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3914 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3915 if (! REAL_WORDS_BIG_ENDIAN
)
3930 #endif /* not C4X */
3931 #endif /* not IBM */
3932 #endif /* not DEC */
3936 /* e type to single precision. */
3939 /* Convert e-type X to IBM 370 float E. */
3943 unsigned EMUSHORT
*x
, *e
;
3945 etoibm (x
, e
, SFmode
);
3948 /* Convert exploded e-type X, that has already been rounded to
3949 float precision, to IBM 370 float Y. */
3953 unsigned EMUSHORT
*x
, *y
;
3955 toibm (x
, y
, SFmode
);
3961 /* Convert e-type X to C4X float E. */
3965 unsigned EMUSHORT
*x
, *e
;
3967 etoc4x (x
, e
, QFmode
);
3970 /* Convert exploded e-type X, that has already been rounded to
3971 float precision, to IBM 370 float Y. */
3975 unsigned EMUSHORT
*x
, *y
;
3977 toc4x (x
, y
, QFmode
);
3982 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3986 unsigned EMUSHORT
*x
, *e
;
3989 unsigned EMUSHORT xi
[NI
];
3995 make_nan (e
, eisneg (x
), SFmode
);
4000 /* adjust exponent for offsets */
4001 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
4006 /* round off to nearest or even */
4009 emdnorm (xi
, 0, 0, exp
, 64);
4017 /* Convert exploded e-type X, that has already been rounded to
4018 float precision, to IEEE float Y. */
4022 unsigned EMUSHORT
*x
, *y
;
4024 unsigned EMUSHORT i
;
4025 unsigned EMUSHORT
*p
;
4030 make_nan (y
, eiisneg (x
), SFmode
);
4036 if (! REAL_WORDS_BIG_ENDIAN
)
4042 *y
= 0; /* output high order */
4044 *y
= 0x8000; /* output sign bit */
4047 /* Handle overflow cases. */
4051 *y
|= (unsigned EMUSHORT
) 0x7f80;
4056 if (! REAL_WORDS_BIG_ENDIAN
)
4064 #else /* no INFINITY */
4065 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4070 if (! REAL_WORDS_BIG_ENDIAN
)
4081 #endif /* no INFINITY */
4093 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4094 /* High order output already has sign bit set. */
4100 if (! REAL_WORDS_BIG_ENDIAN
)
4109 #endif /* not C4X */
4110 #endif /* not IBM */
4112 /* Compare two e type numbers.
4116 -2 if either a or b is a NaN. */
4120 unsigned EMUSHORT
*a
, *b
;
4122 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4123 register unsigned EMUSHORT
*p
, *q
;
4128 if (eisnan (a
) || eisnan (b
))
4137 { /* the signs are different */
4139 for (i
= 1; i
< NI
- 1; i
++)
4153 /* both are the same sign */
4168 return (0); /* equality */
4172 if (*(--p
) > *(--q
))
4173 return (msign
); /* p is bigger */
4175 return (-msign
); /* p is littler */
4179 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4183 unsigned EMUSHORT
*x
, *y
;
4190 /* Convert HOST_WIDE_INT LP to e type Y. */
4195 unsigned EMUSHORT
*y
;
4197 unsigned EMUSHORT yi
[NI
];
4198 unsigned HOST_WIDE_INT ll
;
4204 /* make it positive */
4205 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4206 yi
[0] = 0xffff; /* put correct sign in the e type number */
4210 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4212 /* move the long integer to yi significand area */
4213 #if HOST_BITS_PER_WIDE_INT == 64
4214 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4215 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4216 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4217 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4218 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4220 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4221 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4222 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4225 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4226 ecleaz (yi
); /* it was zero */
4228 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4229 emovo (yi
, y
); /* output the answer */
4232 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4236 unsigned HOST_WIDE_INT
*lp
;
4237 unsigned EMUSHORT
*y
;
4239 unsigned EMUSHORT yi
[NI
];
4240 unsigned HOST_WIDE_INT ll
;
4246 /* move the long integer to ayi significand area */
4247 #if HOST_BITS_PER_WIDE_INT == 64
4248 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4249 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4250 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4251 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4252 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4254 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4255 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4256 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4259 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4260 ecleaz (yi
); /* it was zero */
4262 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4263 emovo (yi
, y
); /* output the answer */
4267 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4268 part FRAC of e-type (packed internal format) floating point input X.
4269 The integer output I has the sign of the input, except that
4270 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4271 The output e-type fraction FRAC is the positive fractional
4276 unsigned EMUSHORT
*x
;
4278 unsigned EMUSHORT
*frac
;
4280 unsigned EMUSHORT xi
[NI
];
4282 unsigned HOST_WIDE_INT ll
;
4285 k
= (int) xi
[E
] - (EXONE
- 1);
4288 /* if exponent <= 0, integer = 0 and real output is fraction */
4293 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4295 /* long integer overflow: output large integer
4296 and correct fraction */
4298 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4301 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4302 /* In this case, let it overflow and convert as if unsigned. */
4303 euifrac (x
, &ll
, frac
);
4304 *i
= (HOST_WIDE_INT
) ll
;
4307 /* In other cases, return the largest positive integer. */
4308 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4313 warning ("overflow on truncation to integer");
4317 /* Shift more than 16 bits: first shift up k-16 mod 16,
4318 then shift up by 16's. */
4319 j
= k
- ((k
>> 4) << 4);
4326 ll
= (ll
<< 16) | xi
[M
];
4328 while ((k
-= 16) > 0);
4335 /* shift not more than 16 bits */
4337 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4344 if ((k
= enormlz (xi
)) > NBITS
)
4347 xi
[E
] -= (unsigned EMUSHORT
) k
;
4353 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4354 FRAC of e-type X. A negative input yields integer output = 0 but
4355 correct fraction. */
4358 euifrac (x
, i
, frac
)
4359 unsigned EMUSHORT
*x
;
4360 unsigned HOST_WIDE_INT
*i
;
4361 unsigned EMUSHORT
*frac
;
4363 unsigned HOST_WIDE_INT ll
;
4364 unsigned EMUSHORT xi
[NI
];
4368 k
= (int) xi
[E
] - (EXONE
- 1);
4371 /* if exponent <= 0, integer = 0 and argument is fraction */
4376 if (k
> HOST_BITS_PER_WIDE_INT
)
4378 /* Long integer overflow: output large integer
4379 and correct fraction.
4380 Note, the BSD microvax compiler says that ~(0UL)
4381 is a syntax error. */
4385 warning ("overflow on truncation to unsigned integer");
4389 /* Shift more than 16 bits: first shift up k-16 mod 16,
4390 then shift up by 16's. */
4391 j
= k
- ((k
>> 4) << 4);
4398 ll
= (ll
<< 16) | xi
[M
];
4400 while ((k
-= 16) > 0);
4405 /* shift not more than 16 bits */
4407 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4410 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4416 if ((k
= enormlz (xi
)) > NBITS
)
4419 xi
[E
] -= (unsigned EMUSHORT
) k
;
4424 /* Shift the significand of exploded e-type X up or down by SC bits. */
4428 unsigned EMUSHORT
*x
;
4431 unsigned EMUSHORT lost
;
4432 unsigned EMUSHORT
*p
;
4445 lost
|= *p
; /* remember lost bits */
4486 return ((int) lost
);
4489 /* Shift normalize the significand area of exploded e-type X.
4490 Return the shift count (up = positive). */
4494 unsigned EMUSHORT x
[];
4496 register unsigned EMUSHORT
*p
;
4505 return (0); /* already normalized */
4511 /* With guard word, there are NBITS+16 bits available.
4512 Return true if all are zero. */
4516 /* see if high byte is zero */
4517 while ((*p
& 0xff00) == 0)
4522 /* now shift 1 bit at a time */
4523 while ((*p
& 0x8000) == 0)
4529 mtherr ("enormlz", UNDERFLOW
);
4535 /* Normalize by shifting down out of the high guard word
4536 of the significand */
4551 mtherr ("enormlz", OVERFLOW
);
4558 /* Powers of ten used in decimal <-> binary conversions. */
4563 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128
4564 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4566 {0x6576, 0x4a92, 0x804a, 0x153f,
4567 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4568 {0x6a32, 0xce52, 0x329a, 0x28ce,
4569 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4570 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4571 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4572 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4573 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4574 {0x851e, 0xeab7, 0x98fe, 0x901b,
4575 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4576 {0x0235, 0x0137, 0x36b1, 0x336c,
4577 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4578 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4579 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4580 {0x0000, 0x0000, 0x0000, 0x0000,
4581 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4582 {0x0000, 0x0000, 0x0000, 0x0000,
4583 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4584 {0x0000, 0x0000, 0x0000, 0x0000,
4585 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4586 {0x0000, 0x0000, 0x0000, 0x0000,
4587 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4588 {0x0000, 0x0000, 0x0000, 0x0000,
4589 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4590 {0x0000, 0x0000, 0x0000, 0x0000,
4591 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4594 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4596 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4597 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4598 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4599 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4600 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4601 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4602 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4603 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4604 {0xa23e, 0x5308, 0xfefb, 0x1155,
4605 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4606 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4607 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4608 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4609 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4610 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4611 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4612 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4613 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4614 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4615 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4616 {0xc155, 0xa4a8, 0x404e, 0x6113,
4617 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4618 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4619 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4620 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4621 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4624 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4625 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4627 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4628 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4629 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4630 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4631 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4632 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4633 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4634 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4635 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4636 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4637 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4638 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4639 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4642 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4644 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4645 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4646 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4647 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4648 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4649 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4650 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4651 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4652 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4653 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4654 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4655 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4656 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4661 /* Convert float value X to ASCII string STRING with NDIG digits after
4662 the decimal point. */
4665 e24toasc (x
, string
, ndigs
)
4666 unsigned EMUSHORT x
[];
4670 unsigned EMUSHORT w
[NI
];
4673 etoasc (w
, string
, ndigs
);
4676 /* Convert double value X to ASCII string STRING with NDIG digits after
4677 the decimal point. */
4680 e53toasc (x
, string
, ndigs
)
4681 unsigned EMUSHORT x
[];
4685 unsigned EMUSHORT w
[NI
];
4688 etoasc (w
, string
, ndigs
);
4691 /* Convert double extended value X to ASCII string STRING with NDIG digits
4692 after the decimal point. */
4695 e64toasc (x
, string
, ndigs
)
4696 unsigned EMUSHORT x
[];
4700 unsigned EMUSHORT w
[NI
];
4703 etoasc (w
, string
, ndigs
);
4706 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4707 after the decimal point. */
4710 e113toasc (x
, string
, ndigs
)
4711 unsigned EMUSHORT x
[];
4715 unsigned EMUSHORT w
[NI
];
4718 etoasc (w
, string
, ndigs
);
4722 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4723 the decimal point. */
4725 static char wstring
[80]; /* working storage for ASCII output */
4728 etoasc (x
, string
, ndigs
)
4729 unsigned EMUSHORT x
[];
4734 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4735 unsigned EMUSHORT
*p
, *r
, *ten
;
4736 unsigned EMUSHORT sign
;
4737 int i
, j
, k
, expon
, rndsav
;
4739 unsigned EMUSHORT m
;
4750 sprintf (wstring
, " NaN ");
4754 rndprc
= NBITS
; /* set to full precision */
4755 emov (x
, y
); /* retain external format */
4756 if (y
[NE
- 1] & 0x8000)
4759 y
[NE
- 1] &= 0x7fff;
4766 ten
= &etens
[NTEN
][0];
4768 /* Test for zero exponent */
4771 for (k
= 0; k
< NE
- 1; k
++)
4774 goto tnzro
; /* denormalized number */
4776 goto isone
; /* valid all zeros */
4780 /* Test for infinity. */
4781 if (y
[NE
- 1] == 0x7fff)
4784 sprintf (wstring
, " -Infinity ");
4786 sprintf (wstring
, " Infinity ");
4790 /* Test for exponent nonzero but significand denormalized.
4791 * This is an error condition.
4793 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4795 mtherr ("etoasc", DOMAIN
);
4796 sprintf (wstring
, "NaN");
4800 /* Compare to 1.0 */
4809 { /* Number is greater than 1 */
4810 /* Convert significand to an integer and strip trailing decimal zeros. */
4812 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4814 p
= &etens
[NTEN
- 4][0];
4820 for (j
= 0; j
< NE
- 1; j
++)
4833 /* Rescale from integer significand */
4834 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4836 /* Find power of 10 */
4840 /* An unordered compare result shouldn't happen here. */
4841 while (ecmp (ten
, u
) <= 0)
4843 if (ecmp (p
, u
) <= 0)
4856 { /* Number is less than 1.0 */
4857 /* Pad significand with trailing decimal zeros. */
4860 while ((y
[NE
- 2] & 0x8000) == 0)
4869 for (i
= 0; i
< NDEC
+ 1; i
++)
4871 if ((w
[NI
- 1] & 0x7) != 0)
4873 /* multiply by 10 */
4886 if (eone
[NE
- 1] <= u
[1])
4898 while (ecmp (eone
, w
) > 0)
4900 if (ecmp (p
, w
) >= 0)
4915 /* Find the first (leading) digit. */
4921 digit
= equot
[NI
- 1];
4922 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4930 digit
= equot
[NI
- 1];
4938 /* Examine number of digits requested by caller. */
4956 *s
++ = (char)digit
+ '0';
4959 /* Generate digits after the decimal point. */
4960 for (k
= 0; k
<= ndigs
; k
++)
4962 /* multiply current number by 10, without normalizing */
4969 *s
++ = (char) equot
[NI
- 1] + '0';
4971 digit
= equot
[NI
- 1];
4974 /* round off the ASCII string */
4977 /* Test for critical rounding case in ASCII output. */
4981 if (ecmp (t
, ezero
) != 0)
4982 goto roun
; /* round to nearest */
4984 if ((*(s
- 1) & 1) == 0)
4985 goto doexp
; /* round to even */
4988 /* Round up and propagate carry-outs */
4992 /* Carry out to most significant digit? */
4999 /* Most significant digit carries to 10? */
5007 /* Round up and carry out from less significant digits */
5019 sprintf (ss, "e+%d", expon);
5021 sprintf (ss, "e%d", expon);
5023 sprintf (ss
, "e%d", expon
);
5026 /* copy out the working string */
5029 while (*ss
== ' ') /* strip possible leading space */
5031 while ((*s
++ = *ss
++) != '\0')
5036 /* Convert ASCII string to floating point.
5038 Numeric input is a free format decimal number of any length, with
5039 or without decimal point. Entering E after the number followed by an
5040 integer number causes the second number to be interpreted as a power of
5041 10 to be multiplied by the first number (i.e., "scientific" notation). */
5043 /* Convert ASCII string S to single precision float value Y. */
5048 unsigned EMUSHORT
*y
;
5054 /* Convert ASCII string S to double precision value Y. */
5059 unsigned EMUSHORT
*y
;
5061 #if defined(DEC) || defined(IBM)
5073 /* Convert ASCII string S to double extended value Y. */
5078 unsigned EMUSHORT
*y
;
5083 /* Convert ASCII string S to 128-bit long double Y. */
5088 unsigned EMUSHORT
*y
;
5090 asctoeg (s
, y
, 113);
5093 /* Convert ASCII string S to e type Y. */
5098 unsigned EMUSHORT
*y
;
5100 asctoeg (s
, y
, NBITS
);
5103 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5104 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5107 asctoeg (ss
, y
, oprec
)
5109 unsigned EMUSHORT
*y
;
5112 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5113 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5114 int k
, trail
, c
, rndsav
;
5116 unsigned EMUSHORT nsign
, *p
;
5117 char *sp
, *s
, *lstr
;
5120 /* Copy the input string. */
5121 lstr
= (char *) alloca (strlen (ss
) + 1);
5123 while (*ss
== ' ') /* skip leading spaces */
5127 while ((*sp
++ = *ss
++) != '\0')
5131 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5138 rndprc
= NBITS
; /* Set to full precision */
5150 if (*s
>= '0' && *s
<= '9')
5152 else if (*s
>= 'a' && *s
<= 'f')
5156 if ((k
>= 0) && (k
< base
))
5158 /* Ignore leading zeros */
5159 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5161 /* Identify and strip trailing zeros after the decimal point. */
5162 if ((trail
== 0) && (decflg
!= 0))
5165 while ((*sp
>= '0' && *sp
<= '9')
5166 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5167 || (*sp
>= 'A' && *sp
<= 'F'))))
5169 /* Check for syntax error */
5171 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5172 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5174 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5185 /* If enough digits were given to more than fill up the yy register,
5186 continuing until overflow into the high guard word yy[2]
5187 guarantees that there will be a roundoff bit at the top
5188 of the low guard word after normalization. */
5195 nexp
+= 4; /* count digits after decimal point */
5197 eshup1 (yy
); /* multiply current number by 16 */
5205 nexp
+= 1; /* count digits after decimal point */
5207 eshup1 (yy
); /* multiply current number by 10 */
5213 /* Insert the current digit. */
5215 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5220 /* Mark any lost non-zero digit. */
5222 /* Count lost digits before the decimal point. */
5244 case '.': /* decimal point */
5274 mtherr ("asctoe", DOMAIN
);
5283 /* Exponent interpretation */
5285 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5286 for (k
= 0; k
< NI
; k
++)
5297 /* check for + or - */
5305 while ((*s
>= '0') && (*s
<= '9'))
5314 if ((exp
> MAXDECEXP
) && (base
== 10))
5318 yy
[E
] = 0x7fff; /* infinity */
5321 if ((exp
< MINDECEXP
) && (base
== 10))
5331 /* Base 16 hexadecimal floating constant. */
5332 if ((k
= enormlz (yy
)) > NBITS
)
5337 /* Adjust the exponent. NEXP is the number of hex digits,
5338 EXP is a power of 2. */
5339 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5349 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5350 while ((nexp
> 0) && (yy
[2] == 0))
5362 if ((k
= enormlz (yy
)) > NBITS
)
5367 lexp
= (EXONE
- 1 + NBITS
) - k
;
5368 emdnorm (yy
, lost
, 0, lexp
, 64);
5371 /* Convert to external format:
5373 Multiply by 10**nexp. If precision is 64 bits,
5374 the maximum relative error incurred in forming 10**n
5375 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5376 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5377 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5392 /* Punt. Can't handle this without 2 divides. */
5393 emovi (etens
[0], tt
);
5400 p
= &etens
[NTEN
][0];
5410 while (exp
<= MAXP
);
5429 /* Round and convert directly to the destination type */
5431 lexp
-= EXONE
- 0x3ff;
5433 else if (oprec
== 24 || oprec
== 32)
5434 lexp
-= (EXONE
- 0x7f);
5437 else if (oprec
== 24 || oprec
== 56)
5438 lexp
-= EXONE
- (0x41 << 2);
5440 else if (oprec
== 24)
5441 lexp
-= EXONE
- 0177;
5445 else if (oprec
== 56)
5446 lexp
-= EXONE
- 0201;
5449 emdnorm (yy
, lost
, 0, lexp
, 64);
5459 todec (yy
, y
); /* see etodec.c */
5464 toibm (yy
, y
, DFmode
);
5469 toc4x (yy
, y
, HFmode
);
5493 /* Return Y = largest integer not greater than X (truncated toward minus
5496 static unsigned EMUSHORT bmask
[] =
5519 unsigned EMUSHORT x
[], y
[];
5521 register unsigned EMUSHORT
*p
;
5523 unsigned EMUSHORT f
[NE
];
5525 emov (x
, f
); /* leave in external format */
5526 expon
= (int) f
[NE
- 1];
5527 e
= (expon
& 0x7fff) - (EXONE
- 1);
5533 /* number of bits to clear out */
5545 /* clear the remaining bits */
5547 /* truncate negatives toward minus infinity */
5550 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5552 for (i
= 0; i
< NE
- 1; i
++)
5565 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5566 For example, 1.1 = 0.55 * 2^1. */
5570 unsigned EMUSHORT x
[];
5572 unsigned EMUSHORT s
[];
5574 unsigned EMUSHORT xi
[NI
];
5578 /* Handle denormalized numbers properly using long integer exponent. */
5579 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5587 *exp
= (int) (li
- 0x3ffe);
5591 /* Return e type Y = X * 2^PWR2. */
5595 unsigned EMUSHORT x
[];
5597 unsigned EMUSHORT y
[];
5599 unsigned EMUSHORT xi
[NI
];
5607 emdnorm (xi
, i
, i
, li
, 64);
5613 /* C = remainder after dividing B by A, all e type values.
5614 Least significant integer quotient bits left in EQUOT. */
5618 unsigned EMUSHORT a
[], b
[], c
[];
5620 unsigned EMUSHORT den
[NI
], num
[NI
];
5624 || (ecmp (a
, ezero
) == 0)
5632 if (ecmp (a
, ezero
) == 0)
5634 mtherr ("eremain", SING
);
5640 eiremain (den
, num
);
5641 /* Sign of remainder = sign of quotient */
5650 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5651 remainder in NUM. */
5655 unsigned EMUSHORT den
[], num
[];
5658 unsigned EMUSHORT j
;
5661 ld
-= enormlz (den
);
5663 ln
-= enormlz (num
);
5667 if (ecmpm (den
, num
) <= 0)
5679 emdnorm (num
, 0, 0, ln
, 0);
5682 /* Report an error condition CODE encountered in function NAME.
5684 Mnemonic Value Significance
5686 DOMAIN 1 argument domain error
5687 SING 2 function singularity
5688 OVERFLOW 3 overflow range error
5689 UNDERFLOW 4 underflow range error
5690 TLOSS 5 total loss of precision
5691 PLOSS 6 partial loss of precision
5692 INVALID 7 NaN - producing operation
5693 EDOM 33 Unix domain error code
5694 ERANGE 34 Unix range error code
5696 The order of appearance of the following messages is bound to the
5697 error codes defined above. */
5707 /* The string passed by the calling program is supposed to be the
5708 name of the function in which the error occurred.
5709 The code argument selects which error message string will be printed. */
5711 if (strcmp (name
, "esub") == 0)
5712 name
= "subtraction";
5713 else if (strcmp (name
, "ediv") == 0)
5715 else if (strcmp (name
, "emul") == 0)
5716 name
= "multiplication";
5717 else if (strcmp (name
, "enormlz") == 0)
5718 name
= "normalization";
5719 else if (strcmp (name
, "etoasc") == 0)
5720 name
= "conversion to text";
5721 else if (strcmp (name
, "asctoe") == 0)
5723 else if (strcmp (name
, "eremain") == 0)
5725 else if (strcmp (name
, "esqrt") == 0)
5726 name
= "square root";
5731 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5732 case SING
: warning ("%s: function singularity" , name
); break;
5733 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5734 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5735 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5736 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5737 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5742 /* Set global error message word */
5747 /* Convert DEC double precision D to e type E. */
5751 unsigned EMUSHORT
*d
;
5752 unsigned EMUSHORT
*e
;
5754 unsigned EMUSHORT y
[NI
];
5755 register unsigned EMUSHORT r
, *p
;
5757 ecleaz (y
); /* start with a zero */
5758 p
= y
; /* point to our number */
5759 r
= *d
; /* get DEC exponent word */
5760 if (*d
& (unsigned int) 0x8000)
5761 *p
= 0xffff; /* fill in our sign */
5762 ++p
; /* bump pointer to our exponent word */
5763 r
&= 0x7fff; /* strip the sign bit */
5764 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5768 r
>>= 7; /* shift exponent word down 7 bits */
5769 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5770 /* add our e type exponent offset */
5771 *p
++ = r
; /* to form our exponent */
5773 r
= *d
++; /* now do the high order mantissa */
5774 r
&= 0177; /* strip off the DEC exponent and sign bits */
5775 r
|= 0200; /* the DEC understood high order mantissa bit */
5776 *p
++ = r
; /* put result in our high guard word */
5778 *p
++ = *d
++; /* fill in the rest of our mantissa */
5782 eshdn8 (y
); /* shift our mantissa down 8 bits */
5787 /* Convert e type X to DEC double precision D. */
5791 unsigned EMUSHORT
*x
, *d
;
5793 unsigned EMUSHORT xi
[NI
];
5798 /* Adjust exponent for offsets. */
5799 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5800 /* Round off to nearest or even. */
5803 emdnorm (xi
, 0, 0, exp
, 64);
5808 /* Convert exploded e-type X, that has already been rounded to
5809 56-bit precision, to DEC format double Y. */
5813 unsigned EMUSHORT
*x
, *y
;
5815 unsigned EMUSHORT i
;
5816 unsigned EMUSHORT
*p
;
5855 /* Convert IBM single/double precision to e type. */
5859 unsigned EMUSHORT
*d
;
5860 unsigned EMUSHORT
*e
;
5861 enum machine_mode mode
;
5863 unsigned EMUSHORT y
[NI
];
5864 register unsigned EMUSHORT r
, *p
;
5866 ecleaz (y
); /* start with a zero */
5867 p
= y
; /* point to our number */
5868 r
= *d
; /* get IBM exponent word */
5869 if (*d
& (unsigned int) 0x8000)
5870 *p
= 0xffff; /* fill in our sign */
5871 ++p
; /* bump pointer to our exponent word */
5872 r
&= 0x7f00; /* strip the sign bit */
5873 r
>>= 6; /* shift exponent word down 6 bits */
5874 /* in fact shift by 8 right and 2 left */
5875 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5876 /* add our e type exponent offset */
5877 *p
++ = r
; /* to form our exponent */
5879 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5880 /* strip off the IBM exponent and sign bits */
5881 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5883 *p
++ = *d
++; /* fill in the rest of our mantissa */
5888 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5891 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5892 /* handle change in RADIX */
5898 /* Convert e type to IBM single/double precision. */
5902 unsigned EMUSHORT
*x
, *d
;
5903 enum machine_mode mode
;
5905 unsigned EMUSHORT xi
[NI
];
5910 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5911 /* round off to nearest or even */
5914 emdnorm (xi
, 0, 0, exp
, 64);
5916 toibm (xi
, d
, mode
);
5921 unsigned EMUSHORT
*x
, *y
;
5922 enum machine_mode mode
;
5924 unsigned EMUSHORT i
;
5925 unsigned EMUSHORT
*p
;
5975 /* Convert C4X single/double precision to e type. */
5979 unsigned EMUSHORT
*d
;
5980 unsigned EMUSHORT
*e
;
5981 enum machine_mode mode
;
5983 unsigned EMUSHORT y
[NI
];
5990 /* Short-circuit the zero case. */
5991 if ((d
[0] == 0x8000)
5993 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
6004 ecleaz (y
); /* start with a zero */
6005 r
= d
[0]; /* get sign/exponent part */
6006 if (r
& (unsigned int) 0x0080)
6008 y
[0] = 0xffff; /* fill in our sign */
6016 r
>>= 8; /* Shift exponent word down 8 bits. */
6017 if (r
& 0x80) /* Make the exponent negative if it is. */
6019 r
= r
| (~0 & ~0xff);
6024 /* Now do the high order mantissa. We don't "or" on the high bit
6025 because it is 2 (not 1) and is handled a little differently
6030 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6032 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6042 /* Now do the two's complement on the data. */
6044 carry
= 1; /* Initially add 1 for the two's complement. */
6045 for (i
=size
+ M
; i
> M
; i
--)
6047 if (carry
&& (y
[i
] == 0x0000))
6049 /* We overflowed into the next word, carry is the same. */
6050 y
[i
] = carry
? 0x0000 : 0xffff;
6054 /* No overflow, just invert and add carry. */
6055 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6070 /* Add our e type exponent offset to form our exponent. */
6074 /* Now do the high order mantissa strip off the exponent and sign
6075 bits and add the high 1 bit. */
6076 y
[M
] = (d
[0] & 0x7f) | 0x80;
6079 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6081 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6091 /* Convert e type to C4X single/double precision. */
6095 unsigned EMUSHORT
*x
, *d
;
6096 enum machine_mode mode
;
6098 unsigned EMUSHORT xi
[NI
];
6104 /* Adjust exponent for offsets. */
6105 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6107 /* Round off to nearest or even. */
6109 rndprc
= mode
== QFmode
? 24 : 32;
6110 emdnorm (xi
, 0, 0, exp
, 64);
6112 toc4x (xi
, d
, mode
);
6117 unsigned EMUSHORT
*x
, *y
;
6118 enum machine_mode mode
;
6124 /* Short-circuit the zero case */
6125 if ((x
[0] == 0) /* Zero exponent and sign */
6127 && (x
[M
] == 0) /* The rest is for zero mantissa */
6129 /* Only check for double if necessary */
6130 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6132 /* We have a zero. Put it into the output and return. */
6145 /* Negative number require a two's complement conversion of the
6151 i
= ((int) x
[1]) - 0x7f;
6153 /* Now add 1 to the inverted data to do the two's complement. */
6163 x
[v
] = carry
? 0x0000 : 0xffff;
6167 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6173 /* The following is a special case. The C4X negative float requires
6174 a zero in the high bit (because the format is (2 - x) x 2^m), so
6175 if a one is in that bit, we have to shift left one to get rid
6176 of it. This only occurs if the number is -1 x 2^m. */
6177 if (x
[M
+1] & 0x8000)
6179 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6180 high sign bit and shift the exponent. */
6187 i
= ((int) x
[1]) - 0x7f;
6190 if ((i
< -128) || (i
> 127))
6205 y
[0] |= ((i
& 0xff) << 8);
6209 y
[0] |= x
[M
] & 0x7f;
6219 /* Output a binary NaN bit pattern in the target machine's format. */
6221 /* If special NaN bit patterns are required, define them in tm.h
6222 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6228 unsigned EMUSHORT TFbignan
[8] =
6229 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6230 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6238 unsigned EMUSHORT XFbignan
[6] =
6239 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6240 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6248 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6249 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6257 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6258 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6265 make_nan (nan
, sign
, mode
)
6266 unsigned EMUSHORT
*nan
;
6268 enum machine_mode mode
;
6271 unsigned EMUSHORT
*p
;
6275 /* Possibly the `reserved operand' patterns on a VAX can be
6276 used like NaN's, but probably not in the same way as IEEE. */
6277 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6280 if (REAL_WORDS_BIG_ENDIAN
)
6288 if (REAL_WORDS_BIG_ENDIAN
)
6296 if (REAL_WORDS_BIG_ENDIAN
)
6305 if (REAL_WORDS_BIG_ENDIAN
)
6315 if (REAL_WORDS_BIG_ENDIAN
)
6316 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6319 if (! REAL_WORDS_BIG_ENDIAN
)
6320 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6324 /* This is the inverse of the function `etarsingle' invoked by
6325 REAL_VALUE_TO_TARGET_SINGLE. */
6328 ereal_unto_float (f
)
6332 unsigned EMUSHORT s
[2];
6333 unsigned EMUSHORT e
[NE
];
6335 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6336 This is the inverse operation to what the function `endian' does. */
6337 if (REAL_WORDS_BIG_ENDIAN
)
6339 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6340 s
[1] = (unsigned EMUSHORT
) f
;
6344 s
[0] = (unsigned EMUSHORT
) f
;
6345 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6347 /* Convert and promote the target float to E-type. */
6349 /* Output E-type to REAL_VALUE_TYPE. */
6355 /* This is the inverse of the function `etardouble' invoked by
6356 REAL_VALUE_TO_TARGET_DOUBLE. */
6359 ereal_unto_double (d
)
6363 unsigned EMUSHORT s
[4];
6364 unsigned EMUSHORT e
[NE
];
6366 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6367 if (REAL_WORDS_BIG_ENDIAN
)
6369 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6370 s
[1] = (unsigned EMUSHORT
) d
[0];
6371 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6372 s
[3] = (unsigned EMUSHORT
) d
[1];
6376 /* Target float words are little-endian. */
6377 s
[0] = (unsigned EMUSHORT
) d
[0];
6378 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6379 s
[2] = (unsigned EMUSHORT
) d
[1];
6380 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6382 /* Convert target double to E-type. */
6384 /* Output E-type to REAL_VALUE_TYPE. */
6390 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6391 This is somewhat like ereal_unto_float, but the input types
6392 for these are different. */
6395 ereal_from_float (f
)
6399 unsigned EMUSHORT s
[2];
6400 unsigned EMUSHORT e
[NE
];
6402 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6403 This is the inverse operation to what the function `endian' does. */
6404 if (REAL_WORDS_BIG_ENDIAN
)
6406 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6407 s
[1] = (unsigned EMUSHORT
) f
;
6411 s
[0] = (unsigned EMUSHORT
) f
;
6412 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6414 /* Convert and promote the target float to E-type. */
6416 /* Output E-type to REAL_VALUE_TYPE. */
6422 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6423 This is somewhat like ereal_unto_double, but the input types
6424 for these are different.
6426 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6427 data format, with no holes in the bit packing. The first element
6428 of the input array holds the bits that would come first in the
6429 target computer's memory. */
6432 ereal_from_double (d
)
6436 unsigned EMUSHORT s
[4];
6437 unsigned EMUSHORT e
[NE
];
6439 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6440 if (REAL_WORDS_BIG_ENDIAN
)
6442 #if HOST_BITS_PER_WIDE_INT == 32
6443 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6444 s
[1] = (unsigned EMUSHORT
) d
[0];
6445 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6446 s
[3] = (unsigned EMUSHORT
) d
[1];
6448 /* In this case the entire target double is contained in the
6449 first array element. The second element of the input is
6451 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6452 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6453 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6454 s
[3] = (unsigned EMUSHORT
) d
[0];
6459 /* Target float words are little-endian. */
6460 s
[0] = (unsigned EMUSHORT
) d
[0];
6461 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6462 #if HOST_BITS_PER_WIDE_INT == 32
6463 s
[2] = (unsigned EMUSHORT
) d
[1];
6464 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6466 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6467 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6470 /* Convert target double to E-type. */
6472 /* Output E-type to REAL_VALUE_TYPE. */
6479 /* Convert target computer unsigned 64-bit integer to e-type.
6480 The endian-ness of DImode follows the convention for integers,
6481 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6485 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6486 unsigned EMUSHORT
*e
;
6488 unsigned EMUSHORT yi
[NI
];
6492 if (WORDS_BIG_ENDIAN
)
6494 for (k
= M
; k
< M
+ 4; k
++)
6499 for (k
= M
+ 3; k
>= M
; k
--)
6502 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6503 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6504 ecleaz (yi
); /* it was zero */
6506 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6510 /* Convert target computer signed 64-bit integer to e-type. */
6514 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6515 unsigned EMUSHORT
*e
;
6517 unsigned EMULONG acc
;
6518 unsigned EMUSHORT yi
[NI
];
6519 unsigned EMUSHORT carry
;
6523 if (WORDS_BIG_ENDIAN
)
6525 for (k
= M
; k
< M
+ 4; k
++)
6530 for (k
= M
+ 3; k
>= M
; k
--)
6533 /* Take absolute value */
6539 for (k
= M
+ 3; k
>= M
; k
--)
6541 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6548 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6549 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6550 ecleaz (yi
); /* it was zero */
6552 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6559 /* Convert e-type to unsigned 64-bit int. */
6563 unsigned EMUSHORT
*x
;
6564 unsigned EMUSHORT
*i
;
6566 unsigned EMUSHORT xi
[NI
];
6575 k
= (int) xi
[E
] - (EXONE
- 1);
6578 for (j
= 0; j
< 4; j
++)
6584 for (j
= 0; j
< 4; j
++)
6587 warning ("overflow on truncation to integer");
6592 /* Shift more than 16 bits: first shift up k-16 mod 16,
6593 then shift up by 16's. */
6594 j
= k
- ((k
>> 4) << 4);
6598 if (WORDS_BIG_ENDIAN
)
6609 if (WORDS_BIG_ENDIAN
)
6614 while ((k
-= 16) > 0);
6618 /* shift not more than 16 bits */
6623 if (WORDS_BIG_ENDIAN
)
6642 /* Convert e-type to signed 64-bit int. */
6646 unsigned EMUSHORT
*x
;
6647 unsigned EMUSHORT
*i
;
6649 unsigned EMULONG acc
;
6650 unsigned EMUSHORT xi
[NI
];
6651 unsigned EMUSHORT carry
;
6652 unsigned EMUSHORT
*isave
;
6656 k
= (int) xi
[E
] - (EXONE
- 1);
6659 for (j
= 0; j
< 4; j
++)
6665 for (j
= 0; j
< 4; j
++)
6668 warning ("overflow on truncation to integer");
6674 /* Shift more than 16 bits: first shift up k-16 mod 16,
6675 then shift up by 16's. */
6676 j
= k
- ((k
>> 4) << 4);
6680 if (WORDS_BIG_ENDIAN
)
6691 if (WORDS_BIG_ENDIAN
)
6696 while ((k
-= 16) > 0);
6700 /* shift not more than 16 bits */
6703 if (WORDS_BIG_ENDIAN
)
6719 /* Negate if negative */
6723 if (WORDS_BIG_ENDIAN
)
6725 for (k
= 0; k
< 4; k
++)
6727 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6728 if (WORDS_BIG_ENDIAN
)
6740 /* Longhand square root routine. */
6743 static int esqinited
= 0;
6744 static unsigned short sqrndbit
[NI
];
6748 unsigned EMUSHORT
*x
, *y
;
6750 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6752 int i
, j
, k
, n
, nlups
;
6757 sqrndbit
[NI
- 2] = 1;
6760 /* Check for arg <= 0 */
6761 i
= ecmp (x
, ezero
);
6766 mtherr ("esqrt", DOMAIN
);
6782 /* Bring in the arg and renormalize if it is denormal. */
6784 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6788 /* Divide exponent by 2 */
6790 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6792 /* Adjust if exponent odd */
6802 n
= 8; /* get 8 bits of result per inner loop */
6808 /* bring in next word of arg */
6810 num
[NI
- 1] = xx
[j
+ 3];
6811 /* Do additional bit on last outer loop, for roundoff. */
6814 for (i
= 0; i
< n
; i
++)
6816 /* Next 2 bits of arg */
6819 /* Shift up answer */
6821 /* Make trial divisor */
6822 for (k
= 0; k
< NI
; k
++)
6825 eaddm (sqrndbit
, temp
);
6826 /* Subtract and insert answer bit if it goes in */
6827 if (ecmpm (temp
, num
) <= 0)
6837 /* Adjust for extra, roundoff loop done. */
6838 exp
+= (NBITS
- 1) - rndprc
;
6840 /* Sticky bit = 1 if the remainder is nonzero. */
6842 for (i
= 3; i
< NI
; i
++)
6845 /* Renormalize and round off. */
6846 emdnorm (sq
, k
, 0, exp
, 64);
6850 #endif /* EMU_NON_COMPILE not defined */
6852 /* Return the binary precision of the significand for a given
6853 floating point mode. The mode can hold an integer value
6854 that many bits wide, without losing any bits. */
6857 significand_size (mode
)
6858 enum machine_mode mode
;
6861 /* Don't test the modes, but their sizes, lest this
6862 code won't work for BITS_PER_UNIT != 8 . */
6864 switch (GET_MODE_BITSIZE (mode
))
6868 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6875 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6878 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6881 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6884 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT