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 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 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 extern int extra_warnings
;
341 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
342 extern unsigned EMUSHORT elog2
[], esqrt2
[];
344 static void endian
PARAMS ((unsigned EMUSHORT
*, long *,
346 static void eclear
PARAMS ((unsigned EMUSHORT
*));
347 static void emov
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
349 static void eabs
PARAMS ((unsigned EMUSHORT
*));
351 static void eneg
PARAMS ((unsigned EMUSHORT
*));
352 static int eisneg
PARAMS ((unsigned EMUSHORT
*));
353 static int eisinf
PARAMS ((unsigned EMUSHORT
*));
354 static int eisnan
PARAMS ((unsigned EMUSHORT
*));
355 static void einfin
PARAMS ((unsigned EMUSHORT
*));
357 static void enan
PARAMS ((unsigned EMUSHORT
*, int));
358 static void einan
PARAMS ((unsigned EMUSHORT
*));
359 static int eiisnan
PARAMS ((unsigned EMUSHORT
*));
360 static int eiisneg
PARAMS ((unsigned EMUSHORT
*));
361 static void make_nan
PARAMS ((unsigned EMUSHORT
*, int, enum machine_mode
));
363 static void emovi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
364 static void emovo
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
365 static void ecleaz
PARAMS ((unsigned EMUSHORT
*));
366 static void ecleazs
PARAMS ((unsigned EMUSHORT
*));
367 static void emovz
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
369 static void eiinfin
PARAMS ((unsigned EMUSHORT
*));
372 static int eiisinf
PARAMS ((unsigned EMUSHORT
*));
374 static int ecmpm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void eshdn1
PARAMS ((unsigned EMUSHORT
*));
376 static void eshup1
PARAMS ((unsigned EMUSHORT
*));
377 static void eshdn8
PARAMS ((unsigned EMUSHORT
*));
378 static void eshup8
PARAMS ((unsigned EMUSHORT
*));
379 static void eshup6
PARAMS ((unsigned EMUSHORT
*));
380 static void eshdn6
PARAMS ((unsigned EMUSHORT
*));
381 static void eaddm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
382 static void esubm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void m16m
PARAMS ((unsigned int, unsigned short *,
385 static int edivm
PARAMS ((unsigned short *, unsigned short *));
386 static int emulm
PARAMS ((unsigned short *, unsigned short *));
387 static void emdnorm
PARAMS ((unsigned EMUSHORT
*, int, int, EMULONG
, int));
388 static void esub
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
389 unsigned EMUSHORT
*));
390 static void eadd
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
391 unsigned EMUSHORT
*));
392 static void eadd1
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
393 unsigned EMUSHORT
*));
394 static void ediv
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
395 unsigned EMUSHORT
*));
396 static void emul
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
397 unsigned EMUSHORT
*));
398 static void e53toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
399 static void e64toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
400 static void e113toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
401 static void e24toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
402 static void etoe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
403 static void toe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
404 static void etoe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
405 static void toe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
406 static void etoe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
407 static void toe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
408 static void etoe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
409 static void toe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
410 static int ecmp
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void eround
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
414 static void ltoe
PARAMS ((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
415 static void ultoe
PARAMS ((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
416 static void eifrac
PARAMS ((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
417 unsigned EMUSHORT
*));
418 static void euifrac
PARAMS ((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
419 unsigned EMUSHORT
*));
420 static int eshift
PARAMS ((unsigned EMUSHORT
*, int));
421 static int enormlz
PARAMS ((unsigned EMUSHORT
*));
423 static void e24toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
424 static void e53toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
425 static void e64toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
426 static void e113toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
428 static void etoasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
429 static void asctoe24
PARAMS ((const char *, unsigned EMUSHORT
*));
430 static void asctoe53
PARAMS ((const char *, unsigned EMUSHORT
*));
431 static void asctoe64
PARAMS ((const char *, unsigned EMUSHORT
*));
432 static void asctoe113
PARAMS ((const char *, unsigned EMUSHORT
*));
433 static void asctoe
PARAMS ((const char *, unsigned EMUSHORT
*));
434 static void asctoeg
PARAMS ((const char *, unsigned EMUSHORT
*, int));
435 static void efloor
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
437 static void efrexp
PARAMS ((unsigned EMUSHORT
*, int *,
438 unsigned EMUSHORT
*));
440 static void eldexp
PARAMS ((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
442 static void eremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
443 unsigned EMUSHORT
*));
445 static void eiremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
446 static void mtherr
PARAMS ((const char *, int));
448 static void dectoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
449 static void etodec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
450 static void todec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
453 static void ibmtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
455 static void etoibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
457 static void toibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
461 static void c4xtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
463 static void etoc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
465 static void toc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
469 static void uditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
470 static void ditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
471 static void etoudi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
472 static void etodi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
473 static void esqrt
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
476 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
477 swapping ends if required, into output array of longs. The
478 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
482 unsigned EMUSHORT e
[];
484 enum machine_mode mode
;
488 if (REAL_WORDS_BIG_ENDIAN
)
493 /* Swap halfwords in the fourth long. */
494 th
= (unsigned long) e
[6] & 0xffff;
495 t
= (unsigned long) e
[7] & 0xffff;
500 /* Swap halfwords in the third long. */
501 th
= (unsigned long) e
[4] & 0xffff;
502 t
= (unsigned long) e
[5] & 0xffff;
505 /* fall into the double case */
508 /* Swap halfwords in the second word. */
509 th
= (unsigned long) e
[2] & 0xffff;
510 t
= (unsigned long) e
[3] & 0xffff;
513 /* fall into the float case */
517 /* Swap halfwords in the first word. */
518 th
= (unsigned long) e
[0] & 0xffff;
519 t
= (unsigned long) e
[1] & 0xffff;
530 /* Pack the output array without swapping. */
535 /* Pack the fourth long. */
536 th
= (unsigned long) e
[7] & 0xffff;
537 t
= (unsigned long) e
[6] & 0xffff;
542 /* Pack the third long.
543 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
545 th
= (unsigned long) e
[5] & 0xffff;
546 t
= (unsigned long) e
[4] & 0xffff;
549 /* fall into the double case */
552 /* Pack the second long */
553 th
= (unsigned long) e
[3] & 0xffff;
554 t
= (unsigned long) e
[2] & 0xffff;
557 /* fall into the float case */
561 /* Pack the first long */
562 th
= (unsigned long) e
[1] & 0xffff;
563 t
= (unsigned long) e
[0] & 0xffff;
575 /* This is the implementation of the REAL_ARITHMETIC macro. */
578 earith (value
, icode
, r1
, r2
)
579 REAL_VALUE_TYPE
*value
;
584 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
590 /* Return NaN input back to the caller. */
593 PUT_REAL (d1
, value
);
598 PUT_REAL (d2
, value
);
602 code
= (enum tree_code
) icode
;
610 esub (d2
, d1
, v
); /* d1 - d2 */
618 #ifndef REAL_INFINITY
619 if (ecmp (d2
, ezero
) == 0)
622 enan (v
, eisneg (d1
) ^ eisneg (d2
));
629 ediv (d2
, d1
, v
); /* d1/d2 */
632 case MIN_EXPR
: /* min (d1,d2) */
633 if (ecmp (d1
, d2
) < 0)
639 case MAX_EXPR
: /* max (d1,d2) */
640 if (ecmp (d1
, d2
) > 0)
653 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
654 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
660 unsigned EMUSHORT f
[NE
], g
[NE
];
676 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
677 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
683 unsigned EMUSHORT f
[NE
], g
[NE
];
685 unsigned HOST_WIDE_INT l
;
699 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
700 string to binary, rounding off as indicated by the machine_mode argument.
701 Then it promotes the rounded value to REAL_VALUE_TYPE. */
708 unsigned EMUSHORT tem
[NE
], e
[NE
];
751 /* Expansion of REAL_NEGATE. */
757 unsigned EMUSHORT e
[NE
];
767 /* Round real toward zero to HOST_WIDE_INT;
768 implements REAL_VALUE_FIX (x). */
774 unsigned EMUSHORT f
[NE
], g
[NE
];
781 warning ("conversion from NaN to int");
789 /* Round real toward zero to unsigned HOST_WIDE_INT
790 implements REAL_VALUE_UNSIGNED_FIX (x).
791 Negative input returns zero. */
793 unsigned HOST_WIDE_INT
797 unsigned EMUSHORT f
[NE
], g
[NE
];
798 unsigned HOST_WIDE_INT l
;
804 warning ("conversion from NaN to unsigned int");
813 /* REAL_VALUE_FROM_INT macro. */
816 ereal_from_int (d
, i
, j
, mode
)
819 enum machine_mode mode
;
821 unsigned EMUSHORT df
[NE
], dg
[NE
];
822 HOST_WIDE_INT low
, high
;
825 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
832 /* complement and add 1 */
839 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
840 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
842 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
847 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
848 Avoid double-rounding errors later by rounding off now from the
849 extra-wide internal format to the requested precision. */
850 switch (GET_MODE_BITSIZE (mode
))
880 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
883 ereal_from_uint (d
, i
, j
, mode
)
885 unsigned HOST_WIDE_INT i
, j
;
886 enum machine_mode mode
;
888 unsigned EMUSHORT df
[NE
], dg
[NE
];
889 unsigned HOST_WIDE_INT low
, high
;
891 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
895 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
901 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
902 Avoid double-rounding errors later by rounding off now from the
903 extra-wide internal format to the requested precision. */
904 switch (GET_MODE_BITSIZE (mode
))
934 /* REAL_VALUE_TO_INT macro. */
937 ereal_to_int (low
, high
, rr
)
938 HOST_WIDE_INT
*low
, *high
;
941 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
948 warning ("conversion from NaN to int");
954 /* convert positive value */
961 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
962 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
963 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
964 emul (df
, dh
, dg
); /* fractional part is the low word */
965 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
968 /* complement and add 1 */
978 /* REAL_VALUE_LDEXP macro. */
985 unsigned EMUSHORT e
[NE
], y
[NE
];
998 /* These routines are conditionally compiled because functions
999 of the same names may be defined in fold-const.c. */
1001 #ifdef REAL_ARITHMETIC
1003 /* Check for infinity in a REAL_VALUE_TYPE. */
1007 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1010 unsigned EMUSHORT e
[NE
];
1013 return (eisinf (e
));
1019 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1023 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1026 unsigned EMUSHORT e
[NE
];
1029 return (eisnan (e
));
1036 /* Check for a negative REAL_VALUE_TYPE number.
1037 This just checks the sign bit, so that -0 counts as negative. */
1043 return ereal_isneg (x
);
1046 /* Expansion of REAL_VALUE_TRUNCATE.
1047 The result is in floating point, rounded to nearest or even. */
1050 real_value_truncate (mode
, arg
)
1051 enum machine_mode mode
;
1052 REAL_VALUE_TYPE arg
;
1054 unsigned EMUSHORT e
[NE
], t
[NE
];
1100 /* If an unsupported type was requested, presume that
1101 the machine files know something useful to do with
1102 the unmodified value. */
1111 /* Try to change R into its exact multiplicative inverse in machine mode
1112 MODE. Return nonzero function value if successful. */
1115 exact_real_inverse (mode
, r
)
1116 enum machine_mode mode
;
1119 unsigned EMUSHORT e
[NE
], einv
[NE
];
1120 REAL_VALUE_TYPE rinv
;
1125 /* Test for input in range. Don't transform IEEE special values. */
1126 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1129 /* Test for a power of 2: all significand bits zero except the MSB.
1130 We are assuming the target has binary (or hex) arithmetic. */
1131 if (e
[NE
- 2] != 0x8000)
1134 for (i
= 0; i
< NE
- 2; i
++)
1140 /* Compute the inverse and truncate it to the required mode. */
1141 ediv (e
, eone
, einv
);
1142 PUT_REAL (einv
, &rinv
);
1143 rinv
= real_value_truncate (mode
, rinv
);
1145 #ifdef CHECK_FLOAT_VALUE
1146 /* This check is not redundant. It may, for example, flush
1147 a supposedly IEEE denormal value to zero. */
1149 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1152 GET_REAL (&rinv
, einv
);
1154 /* Check the bits again, because the truncation might have
1155 generated an arbitrary saturation value on overflow. */
1156 if (einv
[NE
- 2] != 0x8000)
1159 for (i
= 0; i
< NE
- 2; i
++)
1165 /* Fail if the computed inverse is out of range. */
1166 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1169 /* Output the reciprocal and return success flag. */
1173 #endif /* REAL_ARITHMETIC defined */
1175 /* Used for debugging--print the value of R in human-readable format
1184 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1185 fprintf (stderr
, "%s", dstr
);
1189 /* The following routines convert REAL_VALUE_TYPE to the various floating
1190 point formats that are meaningful to supported computers.
1192 The results are returned in 32-bit pieces, each piece stored in a `long'.
1193 This is so they can be printed by statements like
1195 fprintf (file, "%lx, %lx", L[0], L[1]);
1197 that will work on both narrow- and wide-word host computers. */
1199 /* Convert R to a 128-bit long double precision value. The output array L
1200 contains four 32-bit pieces of the result, in the order they would appear
1208 unsigned EMUSHORT e
[NE
];
1212 endian (e
, l
, TFmode
);
1215 /* Convert R to a double extended precision value. The output array L
1216 contains three 32-bit pieces of the result, in the order they would
1217 appear in memory. */
1224 unsigned EMUSHORT e
[NE
];
1228 endian (e
, l
, XFmode
);
1231 /* Convert R to a double precision value. The output array L contains two
1232 32-bit pieces of the result, in the order they would appear in memory. */
1239 unsigned EMUSHORT e
[NE
];
1243 endian (e
, l
, DFmode
);
1246 /* Convert R to a single precision float value stored in the least-significant
1247 bits of a `long'. */
1253 unsigned EMUSHORT e
[NE
];
1258 endian (e
, &l
, SFmode
);
1262 /* Convert X to a decimal ASCII string S for output to an assembly
1263 language file. Note, there is no standard way to spell infinity or
1264 a NaN, so these values may require special treatment in the tm.h
1268 ereal_to_decimal (x
, s
)
1272 unsigned EMUSHORT e
[NE
];
1278 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1279 or -2 if either is a NaN. */
1283 REAL_VALUE_TYPE x
, y
;
1285 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1289 return (ecmp (ex
, ey
));
1292 /* Return 1 if the sign bit of X is set, else return 0. */
1298 unsigned EMUSHORT ex
[NE
];
1301 return (eisneg (ex
));
1304 /* End of REAL_ARITHMETIC interface */
1307 Extended precision IEEE binary floating point arithmetic routines
1309 Numbers are stored in C language as arrays of 16-bit unsigned
1310 short integers. The arguments of the routines are pointers to
1313 External e type data structure, similar to Intel 8087 chip
1314 temporary real format but possibly with a larger significand:
1316 NE-1 significand words (least significant word first,
1317 most significant bit is normally set)
1318 exponent (value = EXONE for 1.0,
1319 top bit is the sign)
1322 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1324 ei[0] sign word (0 for positive, 0xffff for negative)
1325 ei[1] biased exponent (value = EXONE for the number 1.0)
1326 ei[2] high guard word (always zero after normalization)
1328 to ei[NI-2] significand (NI-4 significand words,
1329 most significant word first,
1330 most significant bit is set)
1331 ei[NI-1] low guard word (0x8000 bit is rounding place)
1335 Routines for external format e-type numbers
1337 asctoe (string, e) ASCII string to extended double e type
1338 asctoe64 (string, &d) ASCII string to long double
1339 asctoe53 (string, &d) ASCII string to double
1340 asctoe24 (string, &f) ASCII string to single
1341 asctoeg (string, e, prec) ASCII string to specified precision
1342 e24toe (&f, e) IEEE single precision to e type
1343 e53toe (&d, e) IEEE double precision to e type
1344 e64toe (&d, e) IEEE long double precision to e type
1345 e113toe (&d, e) 128-bit long double precision to e type
1347 eabs (e) absolute value
1349 eadd (a, b, c) c = b + a
1351 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1352 -1 if a < b, -2 if either a or b is a NaN.
1353 ediv (a, b, c) c = b / a
1354 efloor (a, b) truncate to integer, toward -infinity
1355 efrexp (a, exp, s) extract exponent and significand
1356 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1357 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1358 einfin (e) set e to infinity, leaving its sign alone
1359 eldexp (a, n, b) multiply by 2**n
1361 emul (a, b, c) c = b * a
1364 eround (a, b) b = nearest integer value to a
1366 esub (a, b, c) c = b - a
1368 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1369 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1370 e64toasc (&d, str, n) 80-bit long double to ASCII string
1371 e113toasc (&d, str, n) 128-bit long double to ASCII string
1373 etoasc (e, str, n) e to ASCII string, n digits after decimal
1374 etoe24 (e, &f) convert e type to IEEE single precision
1375 etoe53 (e, &d) convert e type to IEEE double precision
1376 etoe64 (e, &d) convert e type to IEEE long double precision
1377 ltoe (&l, e) HOST_WIDE_INT to e type
1378 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1379 eisneg (e) 1 if sign bit of e != 0, else 0
1380 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1381 or is infinite (IEEE)
1382 eisnan (e) 1 if e is a NaN
1385 Routines for internal format exploded e-type numbers
1387 eaddm (ai, bi) add significands, bi = bi + ai
1389 ecleazs (ei) set ei = 0 but leave its sign alone
1390 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1391 edivm (ai, bi) divide significands, bi = bi / ai
1392 emdnorm (ai,l,s,exp) normalize and round off
1393 emovi (a, ai) convert external a to internal ai
1394 emovo (ai, a) convert internal ai to external a
1395 emovz (ai, bi) bi = ai, low guard word of bi = 0
1396 emulm (ai, bi) multiply significands, bi = bi * ai
1397 enormlz (ei) left-justify the significand
1398 eshdn1 (ai) shift significand and guards down 1 bit
1399 eshdn8 (ai) shift down 8 bits
1400 eshdn6 (ai) shift down 16 bits
1401 eshift (ai, n) shift ai n bits up (or down if n < 0)
1402 eshup1 (ai) shift significand and guards up 1 bit
1403 eshup8 (ai) shift up 8 bits
1404 eshup6 (ai) shift up 16 bits
1405 esubm (ai, bi) subtract significands, bi = bi - ai
1406 eiisinf (ai) 1 if infinite
1407 eiisnan (ai) 1 if a NaN
1408 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1409 einan (ai) set ai = NaN
1411 eiinfin (ai) set ai = infinity
1414 The result is always normalized and rounded to NI-4 word precision
1415 after each arithmetic operation.
1417 Exception flags are NOT fully supported.
1419 Signaling NaN's are NOT supported; they are treated the same
1422 Define INFINITY for support of infinity; otherwise a
1423 saturation arithmetic is implemented.
1425 Define NANS for support of Not-a-Number items; otherwise the
1426 arithmetic will never produce a NaN output, and might be confused
1428 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1429 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1430 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1433 Denormals are always supported here where appropriate (e.g., not
1434 for conversion to DEC numbers). */
1436 /* Definitions for error codes that are passed to the common error handling
1439 For Digital Equipment PDP-11 and VAX computers, certain
1440 IBM systems, and others that use numbers with a 56-bit
1441 significand, the symbol DEC should be defined. In this
1442 mode, most floating point constants are given as arrays
1443 of octal integers to eliminate decimal to binary conversion
1444 errors that might be introduced by the compiler.
1446 For computers, such as IBM PC, that follow the IEEE
1447 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1448 Std 754-1985), the symbol IEEE should be defined.
1449 These numbers have 53-bit significands. In this mode, constants
1450 are provided as arrays of hexadecimal 16 bit integers.
1451 The endian-ness of generated values is controlled by
1452 REAL_WORDS_BIG_ENDIAN.
1454 To accommodate other types of computer arithmetic, all
1455 constants are also provided in a normal decimal radix
1456 which one can hope are correctly converted to a suitable
1457 format by the available C language compiler. To invoke
1458 this mode, the symbol UNK is defined.
1460 An important difference among these modes is a predefined
1461 set of machine arithmetic constants for each. The numbers
1462 MACHEP (the machine roundoff error), MAXNUM (largest number
1463 represented), and several other parameters are preset by
1464 the configuration symbol. Check the file const.c to
1465 ensure that these values are correct for your computer.
1467 For ANSI C compatibility, define ANSIC equal to 1. Currently
1468 this affects only the atan2 function and others that use it. */
1470 /* Constant definitions for math error conditions. */
1472 #define DOMAIN 1 /* argument domain error */
1473 #define SING 2 /* argument singularity */
1474 #define OVERFLOW 3 /* overflow range error */
1475 #define UNDERFLOW 4 /* underflow range error */
1476 #define TLOSS 5 /* total loss of precision */
1477 #define PLOSS 6 /* partial loss of precision */
1478 #define INVALID 7 /* NaN-producing operation */
1480 /* e type constants used by high precision check routines */
1482 #if LONG_DOUBLE_TYPE_SIZE == 128
1484 unsigned EMUSHORT ezero
[NE
] =
1485 {0x0000, 0x0000, 0x0000, 0x0000,
1486 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1487 extern unsigned EMUSHORT ezero
[];
1490 unsigned EMUSHORT ehalf
[NE
] =
1491 {0x0000, 0x0000, 0x0000, 0x0000,
1492 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1493 extern unsigned EMUSHORT ehalf
[];
1496 unsigned EMUSHORT eone
[NE
] =
1497 {0x0000, 0x0000, 0x0000, 0x0000,
1498 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1499 extern unsigned EMUSHORT eone
[];
1502 unsigned EMUSHORT etwo
[NE
] =
1503 {0x0000, 0x0000, 0x0000, 0x0000,
1504 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1505 extern unsigned EMUSHORT etwo
[];
1508 unsigned EMUSHORT e32
[NE
] =
1509 {0x0000, 0x0000, 0x0000, 0x0000,
1510 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1511 extern unsigned EMUSHORT e32
[];
1513 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1514 unsigned EMUSHORT elog2
[NE
] =
1515 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1516 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1517 extern unsigned EMUSHORT elog2
[];
1519 /* 1.41421356237309504880168872420969807856967187537695E0 */
1520 unsigned EMUSHORT esqrt2
[NE
] =
1521 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1522 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1523 extern unsigned EMUSHORT esqrt2
[];
1525 /* 3.14159265358979323846264338327950288419716939937511E0 */
1526 unsigned EMUSHORT epi
[NE
] =
1527 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1528 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1529 extern unsigned EMUSHORT epi
[];
1532 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1533 unsigned EMUSHORT ezero
[NE
] =
1534 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1535 unsigned EMUSHORT ehalf
[NE
] =
1536 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1537 unsigned EMUSHORT eone
[NE
] =
1538 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1539 unsigned EMUSHORT etwo
[NE
] =
1540 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1541 unsigned EMUSHORT e32
[NE
] =
1542 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1543 unsigned EMUSHORT elog2
[NE
] =
1544 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1545 unsigned EMUSHORT esqrt2
[NE
] =
1546 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1547 unsigned EMUSHORT epi
[NE
] =
1548 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1551 /* Control register for rounding precision.
1552 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1557 /* Clear out entire e-type number X. */
1561 register unsigned EMUSHORT
*x
;
1565 for (i
= 0; i
< NE
; i
++)
1569 /* Move e-type number from A to B. */
1573 register unsigned EMUSHORT
*a
, *b
;
1577 for (i
= 0; i
< NE
; i
++)
1583 /* Absolute value of e-type X. */
1587 unsigned EMUSHORT x
[];
1589 /* sign is top bit of last word of external format */
1590 x
[NE
- 1] &= 0x7fff;
1594 /* Negate the e-type number X. */
1598 unsigned EMUSHORT x
[];
1601 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1604 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1608 unsigned EMUSHORT x
[];
1611 if (x
[NE
- 1] & 0x8000)
1617 /* Return 1 if e-type number X is infinity, else return zero. */
1621 unsigned EMUSHORT x
[];
1628 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1634 /* Check if e-type number is not a number. The bit pattern is one that we
1635 defined, so we know for sure how to detect it. */
1639 unsigned EMUSHORT x
[] ATTRIBUTE_UNUSED
;
1644 /* NaN has maximum exponent */
1645 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1647 /* ... and non-zero significand field. */
1648 for (i
= 0; i
< NE
- 1; i
++)
1658 /* Fill e-type number X with infinity pattern (IEEE)
1659 or largest possible number (non-IEEE). */
1663 register unsigned EMUSHORT
*x
;
1668 for (i
= 0; i
< NE
- 1; i
++)
1672 for (i
= 0; i
< NE
- 1; i
++)
1700 /* Output an e-type NaN.
1701 This generates Intel's quiet NaN pattern for extended real.
1702 The exponent is 7fff, the leading mantissa word is c000. */
1707 register unsigned EMUSHORT
*x
;
1712 for (i
= 0; i
< NE
- 2; i
++)
1715 *x
= (sign
<< 15) | 0x7fff;
1719 /* Move in an e-type number A, converting it to exploded e-type B. */
1723 unsigned EMUSHORT
*a
, *b
;
1725 register unsigned EMUSHORT
*p
, *q
;
1729 p
= a
+ (NE
- 1); /* point to last word of external number */
1730 /* get the sign bit */
1735 /* get the exponent */
1737 *q
++ &= 0x7fff; /* delete the sign bit */
1739 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1745 for (i
= 3; i
< NI
; i
++)
1751 for (i
= 2; i
< NI
; i
++)
1757 /* clear high guard word */
1759 /* move in the significand */
1760 for (i
= 0; i
< NE
- 1; i
++)
1762 /* clear low guard word */
1766 /* Move out exploded e-type number A, converting it to e type B. */
1770 unsigned EMUSHORT
*a
, *b
;
1772 register unsigned EMUSHORT
*p
, *q
;
1773 unsigned EMUSHORT i
;
1777 q
= b
+ (NE
- 1); /* point to output exponent */
1778 /* combine sign and exponent */
1781 *q
-- = *p
++ | 0x8000;
1785 if (*(p
- 1) == 0x7fff)
1790 enan (b
, eiisneg (a
));
1798 /* skip over guard word */
1800 /* move the significand */
1801 for (j
= 0; j
< NE
- 1; j
++)
1805 /* Clear out exploded e-type number XI. */
1809 register unsigned EMUSHORT
*xi
;
1813 for (i
= 0; i
< NI
; i
++)
1817 /* Clear out exploded e-type XI, but don't touch the sign. */
1821 register unsigned EMUSHORT
*xi
;
1826 for (i
= 0; i
< NI
- 1; i
++)
1830 /* Move exploded e-type number from A to B. */
1834 register unsigned EMUSHORT
*a
, *b
;
1838 for (i
= 0; i
< NI
- 1; i
++)
1840 /* clear low guard word */
1844 /* Generate exploded e-type NaN.
1845 The explicit pattern for this is maximum exponent and
1846 top two significant bits set. */
1851 unsigned EMUSHORT x
[];
1860 /* Return nonzero if exploded e-type X is a NaN. */
1865 unsigned EMUSHORT x
[];
1869 if ((x
[E
] & 0x7fff) == 0x7fff)
1871 for (i
= M
+ 1; i
< NI
; i
++)
1881 /* Return nonzero if sign of exploded e-type X is nonzero. */
1886 unsigned EMUSHORT x
[];
1894 /* Fill exploded e-type X with infinity pattern.
1895 This has maximum exponent and significand all zeros. */
1899 unsigned EMUSHORT x
[];
1907 /* Return nonzero if exploded e-type X is infinite. */
1912 unsigned EMUSHORT x
[];
1919 if ((x
[E
] & 0x7fff) == 0x7fff)
1923 #endif /* INFINITY */
1925 /* Compare significands of numbers in internal exploded e-type format.
1926 Guard words are included in the comparison.
1934 register unsigned EMUSHORT
*a
, *b
;
1938 a
+= M
; /* skip up to significand area */
1940 for (i
= M
; i
< NI
; i
++)
1948 if (*(--a
) > *(--b
))
1954 /* Shift significand of exploded e-type X down by 1 bit. */
1958 register unsigned EMUSHORT
*x
;
1960 register unsigned EMUSHORT bits
;
1963 x
+= M
; /* point to significand area */
1966 for (i
= M
; i
< NI
; i
++)
1978 /* Shift significand of exploded e-type X up by 1 bit. */
1982 register unsigned EMUSHORT
*x
;
1984 register unsigned EMUSHORT bits
;
1990 for (i
= M
; i
< NI
; i
++)
2003 /* Shift significand of exploded e-type X down by 8 bits. */
2007 register unsigned EMUSHORT
*x
;
2009 register unsigned EMUSHORT newbyt
, oldbyt
;
2014 for (i
= M
; i
< NI
; i
++)
2024 /* Shift significand of exploded e-type X up by 8 bits. */
2028 register unsigned EMUSHORT
*x
;
2031 register unsigned EMUSHORT newbyt
, oldbyt
;
2036 for (i
= M
; i
< NI
; i
++)
2046 /* Shift significand of exploded e-type X up by 16 bits. */
2050 register unsigned EMUSHORT
*x
;
2053 register unsigned EMUSHORT
*p
;
2058 for (i
= M
; i
< NI
- 1; i
++)
2064 /* Shift significand of exploded e-type X down by 16 bits. */
2068 register unsigned EMUSHORT
*x
;
2071 register unsigned EMUSHORT
*p
;
2076 for (i
= M
; i
< NI
- 1; i
++)
2082 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2086 unsigned EMUSHORT
*x
, *y
;
2088 register unsigned EMULONG a
;
2095 for (i
= M
; i
< NI
; i
++)
2097 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2102 *y
= (unsigned EMUSHORT
) a
;
2108 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2112 unsigned EMUSHORT
*x
, *y
;
2121 for (i
= M
; i
< NI
; i
++)
2123 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2128 *y
= (unsigned EMUSHORT
) a
;
2135 static unsigned EMUSHORT equot
[NI
];
2139 /* Radix 2 shift-and-add versions of multiply and divide */
2142 /* Divide significands */
2146 unsigned EMUSHORT den
[], num
[];
2149 register unsigned EMUSHORT
*p
, *q
;
2150 unsigned EMUSHORT j
;
2156 for (i
= M
; i
< NI
; i
++)
2161 /* Use faster compare and subtraction if denominator has only 15 bits of
2167 for (i
= M
+ 3; i
< NI
; i
++)
2172 if ((den
[M
+ 1] & 1) != 0)
2180 for (i
= 0; i
< NBITS
+ 2; i
++)
2198 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2199 bit + 1 roundoff bit. */
2204 for (i
= 0; i
< NBITS
+ 2; i
++)
2206 if (ecmpm (den
, num
) <= 0)
2209 j
= 1; /* quotient bit = 1 */
2223 /* test for nonzero remainder after roundoff bit */
2226 for (i
= M
; i
< NI
; i
++)
2234 for (i
= 0; i
< NI
; i
++)
2240 /* Multiply significands */
2244 unsigned EMUSHORT a
[], b
[];
2246 unsigned EMUSHORT
*p
, *q
;
2251 for (i
= M
; i
< NI
; i
++)
2256 while (*p
== 0) /* significand is not supposed to be zero */
2261 if ((*p
& 0xff) == 0)
2269 for (i
= 0; i
< k
; i
++)
2273 /* remember if there were any nonzero bits shifted out */
2280 for (i
= 0; i
< NI
; i
++)
2283 /* return flag for lost nonzero bits */
2289 /* Radix 65536 versions of multiply and divide. */
2291 /* Multiply significand of e-type number B
2292 by 16-bit quantity A, return e-type result to C. */
2297 unsigned EMUSHORT b
[], c
[];
2299 register unsigned EMUSHORT
*pp
;
2300 register unsigned EMULONG carry
;
2301 unsigned EMUSHORT
*ps
;
2302 unsigned EMUSHORT p
[NI
];
2303 unsigned EMULONG aa
, m
;
2312 for (i
=M
+1; i
<NI
; i
++)
2322 m
= (unsigned EMULONG
) aa
* *ps
--;
2323 carry
= (m
& 0xffff) + *pp
;
2324 *pp
-- = (unsigned EMUSHORT
)carry
;
2325 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2326 *pp
= (unsigned EMUSHORT
)carry
;
2327 *(pp
-1) = carry
>> 16;
2330 for (i
=M
; i
<NI
; i
++)
2334 /* Divide significands of exploded e-types NUM / DEN. Neither the
2335 numerator NUM nor the denominator DEN is permitted to have its high guard
2340 unsigned EMUSHORT den
[], num
[];
2343 register unsigned EMUSHORT
*p
;
2344 unsigned EMULONG tnum
;
2345 unsigned EMUSHORT j
, tdenm
, tquot
;
2346 unsigned EMUSHORT tprod
[NI
+1];
2352 for (i
=M
; i
<NI
; i
++)
2358 for (i
=M
; i
<NI
; i
++)
2360 /* Find trial quotient digit (the radix is 65536). */
2361 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2363 /* Do not execute the divide instruction if it will overflow. */
2364 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2367 tquot
= tnum
/ tdenm
;
2368 /* Multiply denominator by trial quotient digit. */
2369 m16m ((unsigned int)tquot
, den
, tprod
);
2370 /* The quotient digit may have been overestimated. */
2371 if (ecmpm (tprod
, num
) > 0)
2375 if (ecmpm (tprod
, num
) > 0)
2385 /* test for nonzero remainder after roundoff bit */
2388 for (i
=M
; i
<NI
; i
++)
2395 for (i
=0; i
<NI
; i
++)
2401 /* Multiply significands of exploded e-type A and B, result in B. */
2405 unsigned EMUSHORT a
[], b
[];
2407 unsigned EMUSHORT
*p
, *q
;
2408 unsigned EMUSHORT pprod
[NI
];
2409 unsigned EMUSHORT j
;
2414 for (i
=M
; i
<NI
; i
++)
2420 for (i
=M
+1; i
<NI
; i
++)
2428 m16m ((unsigned int) *p
--, b
, pprod
);
2429 eaddm(pprod
, equot
);
2435 for (i
=0; i
<NI
; i
++)
2438 /* return flag for lost nonzero bits */
2444 /* Normalize and round off.
2446 The internal format number to be rounded is S.
2447 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2449 Input SUBFLG indicates whether the number was obtained
2450 by a subtraction operation. In that case if LOST is nonzero
2451 then the number is slightly smaller than indicated.
2453 Input EXP is the biased exponent, which may be negative.
2454 the exponent field of S is ignored but is replaced by
2455 EXP as adjusted by normalization and rounding.
2457 Input RCNTRL is the rounding control. If it is nonzero, the
2458 returned value will be rounded to RNDPRC bits.
2460 For future reference: In order for emdnorm to round off denormal
2461 significands at the right point, the input exponent must be
2462 adjusted to be the actual value it would have after conversion to
2463 the final floating point type. This adjustment has been
2464 implemented for all type conversions (etoe53, etc.) and decimal
2465 conversions, but not for the arithmetic functions (eadd, etc.).
2466 Data types having standard 15-bit exponents are not affected by
2467 this, but SFmode and DFmode are affected. For example, ediv with
2468 rndprc = 24 will not round correctly to 24-bit precision if the
2469 result is denormal. */
2471 static int rlast
= -1;
2473 static unsigned EMUSHORT rmsk
= 0;
2474 static unsigned EMUSHORT rmbit
= 0;
2475 static unsigned EMUSHORT rebit
= 0;
2477 static unsigned EMUSHORT rbit
[NI
];
2480 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2481 unsigned EMUSHORT s
[];
2488 unsigned EMUSHORT r
;
2493 /* a blank significand could mean either zero or infinity. */
2506 if ((j
> NBITS
) && (exp
< 32767))
2514 if (exp
> (EMULONG
) (-NBITS
- 1))
2527 /* Round off, unless told not to by rcntrl. */
2530 /* Set up rounding parameters if the control register changed. */
2531 if (rndprc
!= rlast
)
2538 rw
= NI
- 1; /* low guard word */
2561 /* For DEC or IBM arithmetic */
2578 /* For C4x arithmetic */
2599 /* Shift down 1 temporarily if the data structure has an implied
2600 most significant bit and the number is denormal.
2601 Intel long double denormals also lose one bit of precision. */
2602 if ((exp
<= 0) && (rndprc
!= NBITS
)
2603 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2605 lost
|= s
[NI
- 1] & 1;
2608 /* Clear out all bits below the rounding bit,
2609 remembering in r if any were nonzero. */
2623 if ((r
& rmbit
) != 0)
2629 { /* round to even */
2630 if ((s
[re
] & rebit
) == 0)
2643 /* Undo the temporary shift for denormal values. */
2644 if ((exp
<= 0) && (rndprc
!= NBITS
)
2645 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2650 { /* overflow on roundoff */
2663 for (i
= 2; i
< NI
- 1; i
++)
2666 warning ("floating point overflow");
2670 for (i
= M
+ 1; i
< NI
- 1; i
++)
2673 if ((rndprc
< 64) || (rndprc
== 113))
2688 s
[1] = (unsigned EMUSHORT
) exp
;
2691 /* Subtract. C = B - A, all e type numbers. */
2693 static int subflg
= 0;
2697 unsigned EMUSHORT
*a
, *b
, *c
;
2711 /* Infinity minus infinity is a NaN.
2712 Test for subtracting infinities of the same sign. */
2713 if (eisinf (a
) && eisinf (b
)
2714 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2716 mtherr ("esub", INVALID
);
2725 /* Add. C = A + B, all e type. */
2729 unsigned EMUSHORT
*a
, *b
, *c
;
2733 /* NaN plus anything is a NaN. */
2744 /* Infinity minus infinity is a NaN.
2745 Test for adding infinities of opposite signs. */
2746 if (eisinf (a
) && eisinf (b
)
2747 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2749 mtherr ("esub", INVALID
);
2758 /* Arithmetic common to both addition and subtraction. */
2762 unsigned EMUSHORT
*a
, *b
, *c
;
2764 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2766 EMULONG lt
, lta
, ltb
;
2787 /* compare exponents */
2792 { /* put the larger number in bi */
2802 if (lt
< (EMULONG
) (-NBITS
- 1))
2803 goto done
; /* answer same as larger addend */
2805 lost
= eshift (ai
, k
); /* shift the smaller number down */
2809 /* exponents were the same, so must compare significands */
2812 { /* the numbers are identical in magnitude */
2813 /* if different signs, result is zero */
2819 /* if same sign, result is double */
2820 /* double denormalized tiny number */
2821 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2826 /* add 1 to exponent unless both are zero! */
2827 for (j
= 1; j
< NI
- 1; j
++)
2843 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2847 { /* put the larger number in bi */
2863 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2869 /* Divide: C = B/A, all e type. */
2873 unsigned EMUSHORT
*a
, *b
, *c
;
2875 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2877 EMULONG lt
, lta
, ltb
;
2879 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2880 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2881 sign
= eisneg(a
) ^ eisneg(b
);
2884 /* Return any NaN input. */
2895 /* Zero over zero, or infinity over infinity, is a NaN. */
2896 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2897 || (eisinf (a
) && eisinf (b
)))
2899 mtherr ("ediv", INVALID
);
2904 /* Infinity over anything else is infinity. */
2911 /* Anything else over infinity is zero. */
2923 { /* See if numerator is zero. */
2924 for (i
= 1; i
< NI
- 1; i
++)
2928 ltb
-= enormlz (bi
);
2938 { /* possible divide by zero */
2939 for (i
= 1; i
< NI
- 1; i
++)
2943 lta
-= enormlz (ai
);
2947 /* Divide by zero is not an invalid operation.
2948 It is a divide-by-zero operation! */
2950 mtherr ("ediv", SING
);
2956 /* calculate exponent */
2957 lt
= ltb
- lta
+ EXONE
;
2958 emdnorm (bi
, i
, 0, lt
, 64);
2965 && (ecmp (c
, ezero
) != 0)
2968 *(c
+(NE
-1)) |= 0x8000;
2970 *(c
+(NE
-1)) &= ~0x8000;
2973 /* Multiply e-types A and B, return e-type product C. */
2977 unsigned EMUSHORT
*a
, *b
, *c
;
2979 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2981 EMULONG lt
, lta
, ltb
;
2983 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2984 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2985 sign
= eisneg(a
) ^ eisneg(b
);
2988 /* NaN times anything is the same NaN. */
2999 /* Zero times infinity is a NaN. */
3000 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3001 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3003 mtherr ("emul", INVALID
);
3008 /* Infinity times anything else is infinity. */
3010 if (eisinf (a
) || eisinf (b
))
3022 for (i
= 1; i
< NI
- 1; i
++)
3026 lta
-= enormlz (ai
);
3037 for (i
= 1; i
< NI
- 1; i
++)
3041 ltb
-= enormlz (bi
);
3050 /* Multiply significands */
3052 /* calculate exponent */
3053 lt
= lta
+ ltb
- (EXONE
- 1);
3054 emdnorm (bi
, j
, 0, lt
, 64);
3061 && (ecmp (c
, ezero
) != 0)
3064 *(c
+(NE
-1)) |= 0x8000;
3066 *(c
+(NE
-1)) &= ~0x8000;
3069 /* Convert double precision PE to e-type Y. */
3073 unsigned EMUSHORT
*pe
, *y
;
3082 ibmtoe (pe
, y
, DFmode
);
3087 c4xtoe (pe
, y
, HFmode
);
3090 register unsigned EMUSHORT r
;
3091 register unsigned EMUSHORT
*e
, *p
;
3092 unsigned EMUSHORT yy
[NI
];
3096 denorm
= 0; /* flag if denormalized number */
3098 if (! REAL_WORDS_BIG_ENDIAN
)
3104 yy
[M
] = (r
& 0x0f) | 0x10;
3105 r
&= ~0x800f; /* strip sign and 4 significand bits */
3110 if (! REAL_WORDS_BIG_ENDIAN
)
3112 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3113 || (pe
[1] != 0) || (pe
[0] != 0))
3115 enan (y
, yy
[0] != 0);
3121 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3122 || (pe
[2] != 0) || (pe
[3] != 0))
3124 enan (y
, yy
[0] != 0);
3135 #endif /* INFINITY */
3137 /* If zero exponent, then the significand is denormalized.
3138 So take back the understood high significand bit. */
3149 if (! REAL_WORDS_BIG_ENDIAN
)
3166 /* If zero exponent, then normalize the significand. */
3167 if ((k
= enormlz (yy
)) > NBITS
)
3170 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3173 #endif /* not C4X */
3174 #endif /* not IBM */
3175 #endif /* not DEC */
3178 /* Convert double extended precision float PE to e type Y. */
3182 unsigned EMUSHORT
*pe
, *y
;
3184 unsigned EMUSHORT yy
[NI
];
3185 unsigned EMUSHORT
*e
, *p
, *q
;
3190 for (i
= 0; i
< NE
- 5; i
++)
3192 /* This precision is not ordinarily supported on DEC or IBM. */
3194 for (i
= 0; i
< 5; i
++)
3198 p
= &yy
[0] + (NE
- 1);
3201 for (i
= 0; i
< 5; i
++)
3205 if (! REAL_WORDS_BIG_ENDIAN
)
3207 for (i
= 0; i
< 5; i
++)
3210 /* For denormal long double Intel format, shift significand up one
3211 -- but only if the top significand bit is zero. A top bit of 1
3212 is "pseudodenormal" when the exponent is zero. */
3213 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3215 unsigned EMUSHORT temp
[NI
];
3225 p
= &yy
[0] + (NE
- 1);
3226 #ifdef ARM_EXTENDED_IEEE_FORMAT
3227 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3228 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3234 for (i
= 0; i
< 4; i
++)
3239 /* Point to the exponent field and check max exponent cases. */
3241 if ((*p
& 0x7fff) == 0x7fff)
3244 if (! REAL_WORDS_BIG_ENDIAN
)
3246 for (i
= 0; i
< 4; i
++)
3248 if ((i
!= 3 && pe
[i
] != 0)
3249 /* Anything but 0x8000 here, including 0, is a NaN. */
3250 || (i
== 3 && pe
[i
] != 0x8000))
3252 enan (y
, (*p
& 0x8000) != 0);
3259 #ifdef ARM_EXTENDED_IEEE_FORMAT
3260 for (i
= 2; i
<= 5; i
++)
3264 enan (y
, (*p
& 0x8000) != 0);
3269 /* In Motorola extended precision format, the most significant
3270 bit of an infinity mantissa could be either 1 or 0. It is
3271 the lower order bits that tell whether the value is a NaN. */
3272 if ((pe
[2] & 0x7fff) != 0)
3275 for (i
= 3; i
<= 5; i
++)
3280 enan (y
, (*p
& 0x8000) != 0);
3284 #endif /* not ARM */
3293 #endif /* INFINITY */
3296 for (i
= 0; i
< NE
; i
++)
3300 /* Convert 128-bit long double precision float PE to e type Y. */
3304 unsigned EMUSHORT
*pe
, *y
;
3306 register unsigned EMUSHORT r
;
3307 unsigned EMUSHORT
*e
, *p
;
3308 unsigned EMUSHORT yy
[NI
];
3315 if (! REAL_WORDS_BIG_ENDIAN
)
3327 if (! REAL_WORDS_BIG_ENDIAN
)
3329 for (i
= 0; i
< 7; i
++)
3333 enan (y
, yy
[0] != 0);
3340 for (i
= 1; i
< 8; i
++)
3344 enan (y
, yy
[0] != 0);
3356 #endif /* INFINITY */
3360 if (! REAL_WORDS_BIG_ENDIAN
)
3362 for (i
= 0; i
< 7; i
++)
3368 for (i
= 0; i
< 7; i
++)
3372 /* If denormal, remove the implied bit; else shift down 1. */
3385 /* Convert single precision float PE to e type Y. */
3389 unsigned EMUSHORT
*pe
, *y
;
3393 ibmtoe (pe
, y
, SFmode
);
3399 c4xtoe (pe
, y
, QFmode
);
3403 register unsigned EMUSHORT r
;
3404 register unsigned EMUSHORT
*e
, *p
;
3405 unsigned EMUSHORT yy
[NI
];
3409 denorm
= 0; /* flag if denormalized number */
3412 if (! REAL_WORDS_BIG_ENDIAN
)
3422 yy
[M
] = (r
& 0x7f) | 0200;
3423 r
&= ~0x807f; /* strip sign and 7 significand bits */
3428 if (REAL_WORDS_BIG_ENDIAN
)
3430 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3432 enan (y
, yy
[0] != 0);
3438 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3440 enan (y
, yy
[0] != 0);
3451 #endif /* INFINITY */
3453 /* If zero exponent, then the significand is denormalized.
3454 So take back the understood high significand bit. */
3467 if (! REAL_WORDS_BIG_ENDIAN
)
3477 { /* if zero exponent, then normalize the significand */
3478 if ((k
= enormlz (yy
)) > NBITS
)
3481 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3484 #endif /* not C4X */
3485 #endif /* not IBM */
3488 /* Convert e-type X to IEEE 128-bit long double format E. */
3492 unsigned EMUSHORT
*x
, *e
;
3494 unsigned EMUSHORT xi
[NI
];
3501 make_nan (e
, eisneg (x
), TFmode
);
3506 exp
= (EMULONG
) xi
[E
];
3511 /* round off to nearest or even */
3514 emdnorm (xi
, 0, 0, exp
, 64);
3522 /* Convert exploded e-type X, that has already been rounded to
3523 113-bit precision, to IEEE 128-bit long double format Y. */
3527 unsigned EMUSHORT
*a
, *b
;
3529 register unsigned EMUSHORT
*p
, *q
;
3530 unsigned EMUSHORT i
;
3535 make_nan (b
, eiisneg (a
), TFmode
);
3540 if (REAL_WORDS_BIG_ENDIAN
)
3543 q
= b
+ 7; /* point to output exponent */
3545 /* If not denormal, delete the implied bit. */
3550 /* combine sign and exponent */
3552 if (REAL_WORDS_BIG_ENDIAN
)
3555 *q
++ = *p
++ | 0x8000;
3562 *q
-- = *p
++ | 0x8000;
3566 /* skip over guard word */
3568 /* move the significand */
3569 if (REAL_WORDS_BIG_ENDIAN
)
3571 for (i
= 0; i
< 7; i
++)
3576 for (i
= 0; i
< 7; i
++)
3581 /* Convert e-type X to IEEE double extended format E. */
3585 unsigned EMUSHORT
*x
, *e
;
3587 unsigned EMUSHORT xi
[NI
];
3594 make_nan (e
, eisneg (x
), XFmode
);
3599 /* adjust exponent for offset */
3600 exp
= (EMULONG
) xi
[E
];
3605 /* round off to nearest or even */
3608 emdnorm (xi
, 0, 0, exp
, 64);
3616 /* Convert exploded e-type X, that has already been rounded to
3617 64-bit precision, to IEEE double extended format Y. */
3621 unsigned EMUSHORT
*a
, *b
;
3623 register unsigned EMUSHORT
*p
, *q
;
3624 unsigned EMUSHORT i
;
3629 make_nan (b
, eiisneg (a
), XFmode
);
3633 /* Shift denormal long double Intel format significand down one bit. */
3634 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3644 if (REAL_WORDS_BIG_ENDIAN
)
3648 q
= b
+ 4; /* point to output exponent */
3649 #if LONG_DOUBLE_TYPE_SIZE == 96
3650 /* Clear the last two bytes of 12-byte Intel format */
3656 /* combine sign and exponent */
3660 *q
++ = *p
++ | 0x8000;
3667 *q
-- = *p
++ | 0x8000;
3672 if (REAL_WORDS_BIG_ENDIAN
)
3674 #ifdef ARM_EXTENDED_IEEE_FORMAT
3675 /* The exponent is in the lowest 15 bits of the first word. */
3676 *q
++ = i
? 0x8000 : 0;
3680 *q
++ = *p
++ | 0x8000;
3689 *q
-- = *p
++ | 0x8000;
3694 /* skip over guard word */
3696 /* move the significand */
3698 for (i
= 0; i
< 4; i
++)
3702 for (i
= 0; i
< 4; i
++)
3706 if (REAL_WORDS_BIG_ENDIAN
)
3708 for (i
= 0; i
< 4; i
++)
3716 /* Intel long double infinity significand. */
3724 for (i
= 0; i
< 4; i
++)
3730 /* e type to double precision. */
3733 /* Convert e-type X to DEC-format double E. */
3737 unsigned EMUSHORT
*x
, *e
;
3739 etodec (x
, e
); /* see etodec.c */
3742 /* Convert exploded e-type X, that has already been rounded to
3743 56-bit double precision, to DEC double Y. */
3747 unsigned EMUSHORT
*x
, *y
;
3754 /* Convert e-type X to IBM 370-format double E. */
3758 unsigned EMUSHORT
*x
, *e
;
3760 etoibm (x
, e
, DFmode
);
3763 /* Convert exploded e-type X, that has already been rounded to
3764 56-bit precision, to IBM 370 double Y. */
3768 unsigned EMUSHORT
*x
, *y
;
3770 toibm (x
, y
, DFmode
);
3773 #else /* it's neither DEC nor IBM */
3775 /* Convert e-type X to C4X-format long double E. */
3779 unsigned EMUSHORT
*x
, *e
;
3781 etoc4x (x
, e
, HFmode
);
3784 /* Convert exploded e-type X, that has already been rounded to
3785 56-bit precision, to IBM 370 double Y. */
3789 unsigned EMUSHORT
*x
, *y
;
3791 toc4x (x
, y
, HFmode
);
3794 #else /* it's neither DEC nor IBM nor C4X */
3796 /* Convert e-type X to IEEE double E. */
3800 unsigned EMUSHORT
*x
, *e
;
3802 unsigned EMUSHORT xi
[NI
];
3809 make_nan (e
, eisneg (x
), DFmode
);
3814 /* adjust exponent for offsets */
3815 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3820 /* round off to nearest or even */
3823 emdnorm (xi
, 0, 0, exp
, 64);
3831 /* Convert exploded e-type X, that has already been rounded to
3832 53-bit precision, to IEEE double Y. */
3836 unsigned EMUSHORT
*x
, *y
;
3838 unsigned EMUSHORT i
;
3839 unsigned EMUSHORT
*p
;
3844 make_nan (y
, eiisneg (x
), DFmode
);
3850 if (! REAL_WORDS_BIG_ENDIAN
)
3853 *y
= 0; /* output high order */
3855 *y
= 0x8000; /* output sign bit */
3858 if (i
>= (unsigned int) 2047)
3860 /* Saturate at largest number less than infinity. */
3863 if (! REAL_WORDS_BIG_ENDIAN
)
3877 *y
|= (unsigned EMUSHORT
) 0x7fef;
3878 if (! REAL_WORDS_BIG_ENDIAN
)
3903 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3904 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3905 if (! REAL_WORDS_BIG_ENDIAN
)
3920 #endif /* not C4X */
3921 #endif /* not IBM */
3922 #endif /* not DEC */
3926 /* e type to single precision. */
3929 /* Convert e-type X to IBM 370 float E. */
3933 unsigned EMUSHORT
*x
, *e
;
3935 etoibm (x
, e
, SFmode
);
3938 /* Convert exploded e-type X, that has already been rounded to
3939 float precision, to IBM 370 float Y. */
3943 unsigned EMUSHORT
*x
, *y
;
3945 toibm (x
, y
, SFmode
);
3951 /* Convert e-type X to C4X float E. */
3955 unsigned EMUSHORT
*x
, *e
;
3957 etoc4x (x
, e
, QFmode
);
3960 /* Convert exploded e-type X, that has already been rounded to
3961 float precision, to IBM 370 float Y. */
3965 unsigned EMUSHORT
*x
, *y
;
3967 toc4x (x
, y
, QFmode
);
3972 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3976 unsigned EMUSHORT
*x
, *e
;
3979 unsigned EMUSHORT xi
[NI
];
3985 make_nan (e
, eisneg (x
), SFmode
);
3990 /* adjust exponent for offsets */
3991 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3996 /* round off to nearest or even */
3999 emdnorm (xi
, 0, 0, exp
, 64);
4007 /* Convert exploded e-type X, that has already been rounded to
4008 float precision, to IEEE float Y. */
4012 unsigned EMUSHORT
*x
, *y
;
4014 unsigned EMUSHORT i
;
4015 unsigned EMUSHORT
*p
;
4020 make_nan (y
, eiisneg (x
), SFmode
);
4026 if (! REAL_WORDS_BIG_ENDIAN
)
4032 *y
= 0; /* output high order */
4034 *y
= 0x8000; /* output sign bit */
4037 /* Handle overflow cases. */
4041 *y
|= (unsigned EMUSHORT
) 0x7f80;
4046 if (! REAL_WORDS_BIG_ENDIAN
)
4054 #else /* no INFINITY */
4055 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4060 if (! REAL_WORDS_BIG_ENDIAN
)
4071 #endif /* no INFINITY */
4083 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4084 /* High order output already has sign bit set. */
4090 if (! REAL_WORDS_BIG_ENDIAN
)
4099 #endif /* not C4X */
4100 #endif /* not IBM */
4102 /* Compare two e type numbers.
4106 -2 if either a or b is a NaN. */
4110 unsigned EMUSHORT
*a
, *b
;
4112 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4113 register unsigned EMUSHORT
*p
, *q
;
4118 if (eisnan (a
) || eisnan (b
))
4127 { /* the signs are different */
4129 for (i
= 1; i
< NI
- 1; i
++)
4143 /* both are the same sign */
4158 return (0); /* equality */
4162 if (*(--p
) > *(--q
))
4163 return (msign
); /* p is bigger */
4165 return (-msign
); /* p is littler */
4169 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4173 unsigned EMUSHORT
*x
, *y
;
4180 /* Convert HOST_WIDE_INT LP to e type Y. */
4185 unsigned EMUSHORT
*y
;
4187 unsigned EMUSHORT yi
[NI
];
4188 unsigned HOST_WIDE_INT ll
;
4194 /* make it positive */
4195 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4196 yi
[0] = 0xffff; /* put correct sign in the e type number */
4200 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4202 /* move the long integer to yi significand area */
4203 #if HOST_BITS_PER_WIDE_INT == 64
4204 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4205 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4206 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4207 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4208 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4210 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4211 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4212 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4215 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4216 ecleaz (yi
); /* it was zero */
4218 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4219 emovo (yi
, y
); /* output the answer */
4222 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4226 unsigned HOST_WIDE_INT
*lp
;
4227 unsigned EMUSHORT
*y
;
4229 unsigned EMUSHORT yi
[NI
];
4230 unsigned HOST_WIDE_INT ll
;
4236 /* move the long integer to ayi significand area */
4237 #if HOST_BITS_PER_WIDE_INT == 64
4238 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4239 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4240 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4241 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4242 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4244 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4245 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4246 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4249 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4250 ecleaz (yi
); /* it was zero */
4252 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4253 emovo (yi
, y
); /* output the answer */
4257 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4258 part FRAC of e-type (packed internal format) floating point input X.
4259 The integer output I has the sign of the input, except that
4260 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4261 The output e-type fraction FRAC is the positive fractional
4266 unsigned EMUSHORT
*x
;
4268 unsigned EMUSHORT
*frac
;
4270 unsigned EMUSHORT xi
[NI
];
4272 unsigned HOST_WIDE_INT ll
;
4275 k
= (int) xi
[E
] - (EXONE
- 1);
4278 /* if exponent <= 0, integer = 0 and real output is fraction */
4283 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4285 /* long integer overflow: output large integer
4286 and correct fraction */
4288 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4291 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4292 /* In this case, let it overflow and convert as if unsigned. */
4293 euifrac (x
, &ll
, frac
);
4294 *i
= (HOST_WIDE_INT
) ll
;
4297 /* In other cases, return the largest positive integer. */
4298 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4303 warning ("overflow on truncation to integer");
4307 /* Shift more than 16 bits: first shift up k-16 mod 16,
4308 then shift up by 16's. */
4309 j
= k
- ((k
>> 4) << 4);
4316 ll
= (ll
<< 16) | xi
[M
];
4318 while ((k
-= 16) > 0);
4325 /* shift not more than 16 bits */
4327 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4334 if ((k
= enormlz (xi
)) > NBITS
)
4337 xi
[E
] -= (unsigned EMUSHORT
) k
;
4343 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4344 FRAC of e-type X. A negative input yields integer output = 0 but
4345 correct fraction. */
4348 euifrac (x
, i
, frac
)
4349 unsigned EMUSHORT
*x
;
4350 unsigned HOST_WIDE_INT
*i
;
4351 unsigned EMUSHORT
*frac
;
4353 unsigned HOST_WIDE_INT ll
;
4354 unsigned EMUSHORT xi
[NI
];
4358 k
= (int) xi
[E
] - (EXONE
- 1);
4361 /* if exponent <= 0, integer = 0 and argument is fraction */
4366 if (k
> HOST_BITS_PER_WIDE_INT
)
4368 /* Long integer overflow: output large integer
4369 and correct fraction.
4370 Note, the BSD microvax compiler says that ~(0UL)
4371 is a syntax error. */
4375 warning ("overflow on truncation to unsigned integer");
4379 /* Shift more than 16 bits: first shift up k-16 mod 16,
4380 then shift up by 16's. */
4381 j
= k
- ((k
>> 4) << 4);
4388 ll
= (ll
<< 16) | xi
[M
];
4390 while ((k
-= 16) > 0);
4395 /* shift not more than 16 bits */
4397 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4400 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4406 if ((k
= enormlz (xi
)) > NBITS
)
4409 xi
[E
] -= (unsigned EMUSHORT
) k
;
4414 /* Shift the significand of exploded e-type X up or down by SC bits. */
4418 unsigned EMUSHORT
*x
;
4421 unsigned EMUSHORT lost
;
4422 unsigned EMUSHORT
*p
;
4435 lost
|= *p
; /* remember lost bits */
4476 return ((int) lost
);
4479 /* Shift normalize the significand area of exploded e-type X.
4480 Return the shift count (up = positive). */
4484 unsigned EMUSHORT x
[];
4486 register unsigned EMUSHORT
*p
;
4495 return (0); /* already normalized */
4501 /* With guard word, there are NBITS+16 bits available.
4502 Return true if all are zero. */
4506 /* see if high byte is zero */
4507 while ((*p
& 0xff00) == 0)
4512 /* now shift 1 bit at a time */
4513 while ((*p
& 0x8000) == 0)
4519 mtherr ("enormlz", UNDERFLOW
);
4525 /* Normalize by shifting down out of the high guard word
4526 of the significand */
4541 mtherr ("enormlz", OVERFLOW
);
4548 /* Powers of ten used in decimal <-> binary conversions. */
4553 #if LONG_DOUBLE_TYPE_SIZE == 128
4554 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4556 {0x6576, 0x4a92, 0x804a, 0x153f,
4557 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4558 {0x6a32, 0xce52, 0x329a, 0x28ce,
4559 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4560 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4561 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4562 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4563 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4564 {0x851e, 0xeab7, 0x98fe, 0x901b,
4565 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4566 {0x0235, 0x0137, 0x36b1, 0x336c,
4567 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4568 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4569 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4570 {0x0000, 0x0000, 0x0000, 0x0000,
4571 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4572 {0x0000, 0x0000, 0x0000, 0x0000,
4573 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4574 {0x0000, 0x0000, 0x0000, 0x0000,
4575 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4576 {0x0000, 0x0000, 0x0000, 0x0000,
4577 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4578 {0x0000, 0x0000, 0x0000, 0x0000,
4579 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4580 {0x0000, 0x0000, 0x0000, 0x0000,
4581 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4584 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4586 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4587 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4588 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4589 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4590 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4591 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4592 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4593 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4594 {0xa23e, 0x5308, 0xfefb, 0x1155,
4595 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4596 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4597 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4598 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4599 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4600 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4601 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4602 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4603 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4604 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4605 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4606 {0xc155, 0xa4a8, 0x404e, 0x6113,
4607 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4608 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4609 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4610 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4611 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4614 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4615 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4617 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4618 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4619 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4620 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4621 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4622 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4623 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4624 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4625 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4626 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4627 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4628 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4629 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4632 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4634 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4635 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4636 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4637 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4638 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4639 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4640 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4641 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4642 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4643 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4644 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4645 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4646 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4651 /* Convert float value X to ASCII string STRING with NDIG digits after
4652 the decimal point. */
4655 e24toasc (x
, string
, ndigs
)
4656 unsigned EMUSHORT x
[];
4660 unsigned EMUSHORT w
[NI
];
4663 etoasc (w
, string
, ndigs
);
4666 /* Convert double value X to ASCII string STRING with NDIG digits after
4667 the decimal point. */
4670 e53toasc (x
, string
, ndigs
)
4671 unsigned EMUSHORT x
[];
4675 unsigned EMUSHORT w
[NI
];
4678 etoasc (w
, string
, ndigs
);
4681 /* Convert double extended value X to ASCII string STRING with NDIG digits
4682 after the decimal point. */
4685 e64toasc (x
, string
, ndigs
)
4686 unsigned EMUSHORT x
[];
4690 unsigned EMUSHORT w
[NI
];
4693 etoasc (w
, string
, ndigs
);
4696 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4697 after the decimal point. */
4700 e113toasc (x
, string
, ndigs
)
4701 unsigned EMUSHORT x
[];
4705 unsigned EMUSHORT w
[NI
];
4708 etoasc (w
, string
, ndigs
);
4712 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4713 the decimal point. */
4715 static char wstring
[80]; /* working storage for ASCII output */
4718 etoasc (x
, string
, ndigs
)
4719 unsigned EMUSHORT x
[];
4724 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4725 unsigned EMUSHORT
*p
, *r
, *ten
;
4726 unsigned EMUSHORT sign
;
4727 int i
, j
, k
, expon
, rndsav
;
4729 unsigned EMUSHORT m
;
4740 sprintf (wstring
, " NaN ");
4744 rndprc
= NBITS
; /* set to full precision */
4745 emov (x
, y
); /* retain external format */
4746 if (y
[NE
- 1] & 0x8000)
4749 y
[NE
- 1] &= 0x7fff;
4756 ten
= &etens
[NTEN
][0];
4758 /* Test for zero exponent */
4761 for (k
= 0; k
< NE
- 1; k
++)
4764 goto tnzro
; /* denormalized number */
4766 goto isone
; /* valid all zeros */
4770 /* Test for infinity. */
4771 if (y
[NE
- 1] == 0x7fff)
4774 sprintf (wstring
, " -Infinity ");
4776 sprintf (wstring
, " Infinity ");
4780 /* Test for exponent nonzero but significand denormalized.
4781 * This is an error condition.
4783 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4785 mtherr ("etoasc", DOMAIN
);
4786 sprintf (wstring
, "NaN");
4790 /* Compare to 1.0 */
4799 { /* Number is greater than 1 */
4800 /* Convert significand to an integer and strip trailing decimal zeros. */
4802 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4804 p
= &etens
[NTEN
- 4][0];
4810 for (j
= 0; j
< NE
- 1; j
++)
4823 /* Rescale from integer significand */
4824 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4826 /* Find power of 10 */
4830 /* An unordered compare result shouldn't happen here. */
4831 while (ecmp (ten
, u
) <= 0)
4833 if (ecmp (p
, u
) <= 0)
4846 { /* Number is less than 1.0 */
4847 /* Pad significand with trailing decimal zeros. */
4850 while ((y
[NE
- 2] & 0x8000) == 0)
4859 for (i
= 0; i
< NDEC
+ 1; i
++)
4861 if ((w
[NI
- 1] & 0x7) != 0)
4863 /* multiply by 10 */
4876 if (eone
[NE
- 1] <= u
[1])
4888 while (ecmp (eone
, w
) > 0)
4890 if (ecmp (p
, w
) >= 0)
4905 /* Find the first (leading) digit. */
4911 digit
= equot
[NI
- 1];
4912 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4920 digit
= equot
[NI
- 1];
4928 /* Examine number of digits requested by caller. */
4946 *s
++ = (char)digit
+ '0';
4949 /* Generate digits after the decimal point. */
4950 for (k
= 0; k
<= ndigs
; k
++)
4952 /* multiply current number by 10, without normalizing */
4959 *s
++ = (char) equot
[NI
- 1] + '0';
4961 digit
= equot
[NI
- 1];
4964 /* round off the ASCII string */
4967 /* Test for critical rounding case in ASCII output. */
4971 if (ecmp (t
, ezero
) != 0)
4972 goto roun
; /* round to nearest */
4974 if ((*(s
- 1) & 1) == 0)
4975 goto doexp
; /* round to even */
4978 /* Round up and propagate carry-outs */
4982 /* Carry out to most significant digit? */
4989 /* Most significant digit carries to 10? */
4997 /* Round up and carry out from less significant digits */
5009 sprintf (ss, "e+%d", expon);
5011 sprintf (ss, "e%d", expon);
5013 sprintf (ss
, "e%d", expon
);
5016 /* copy out the working string */
5019 while (*ss
== ' ') /* strip possible leading space */
5021 while ((*s
++ = *ss
++) != '\0')
5026 /* Convert ASCII string to floating point.
5028 Numeric input is a free format decimal number of any length, with
5029 or without decimal point. Entering E after the number followed by an
5030 integer number causes the second number to be interpreted as a power of
5031 10 to be multiplied by the first number (i.e., "scientific" notation). */
5033 /* Convert ASCII string S to single precision float value Y. */
5038 unsigned EMUSHORT
*y
;
5044 /* Convert ASCII string S to double precision value Y. */
5049 unsigned EMUSHORT
*y
;
5051 #if defined(DEC) || defined(IBM)
5063 /* Convert ASCII string S to double extended value Y. */
5068 unsigned EMUSHORT
*y
;
5073 /* Convert ASCII string S to 128-bit long double Y. */
5078 unsigned EMUSHORT
*y
;
5080 asctoeg (s
, y
, 113);
5083 /* Convert ASCII string S to e type Y. */
5088 unsigned EMUSHORT
*y
;
5090 asctoeg (s
, y
, NBITS
);
5093 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5094 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5097 asctoeg (ss
, y
, oprec
)
5099 unsigned EMUSHORT
*y
;
5102 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5103 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5104 int k
, trail
, c
, rndsav
;
5106 unsigned EMUSHORT nsign
, *p
;
5107 char *sp
, *s
, *lstr
;
5110 /* Copy the input string. */
5111 lstr
= (char *) alloca (strlen (ss
) + 1);
5113 while (*ss
== ' ') /* skip leading spaces */
5117 while ((*sp
++ = *ss
++) != '\0')
5121 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5128 rndprc
= NBITS
; /* Set to full precision */
5140 if (*s
>= '0' && *s
<= '9')
5146 if ((k
>= 0) && (k
< base
))
5148 /* Ignore leading zeros */
5149 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5151 /* Identify and strip trailing zeros after the decimal point. */
5152 if ((trail
== 0) && (decflg
!= 0))
5155 while ((*sp
>= '0' && *sp
<= '9')
5156 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5157 || (*sp
>= 'A' && *sp
<= 'F'))))
5159 /* Check for syntax error */
5161 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5162 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5164 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5175 /* If enough digits were given to more than fill up the yy register,
5176 continuing until overflow into the high guard word yy[2]
5177 guarantees that there will be a roundoff bit at the top
5178 of the low guard word after normalization. */
5185 nexp
+= 4; /* count digits after decimal point */
5187 eshup1 (yy
); /* multiply current number by 16 */
5195 nexp
+= 1; /* count digits after decimal point */
5197 eshup1 (yy
); /* multiply current number by 10 */
5203 /* Insert the current digit. */
5205 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5210 /* Mark any lost non-zero digit. */
5212 /* Count lost digits before the decimal point. */
5234 case '.': /* decimal point */
5264 mtherr ("asctoe", DOMAIN
);
5273 /* Exponent interpretation */
5275 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5276 for (k
= 0; k
< NI
; k
++)
5287 /* check for + or - */
5295 while ((*s
>= '0') && (*s
<= '9'))
5304 if ((exp
> MAXDECEXP
) && (base
== 10))
5308 yy
[E
] = 0x7fff; /* infinity */
5311 if ((exp
< MINDECEXP
) && (base
== 10))
5321 /* Base 16 hexadecimal floating constant. */
5322 if ((k
= enormlz (yy
)) > NBITS
)
5327 /* Adjust the exponent. NEXP is the number of hex digits,
5328 EXP is a power of 2. */
5329 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5339 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5340 while ((nexp
> 0) && (yy
[2] == 0))
5352 if ((k
= enormlz (yy
)) > NBITS
)
5357 lexp
= (EXONE
- 1 + NBITS
) - k
;
5358 emdnorm (yy
, lost
, 0, lexp
, 64);
5361 /* Convert to external format:
5363 Multiply by 10**nexp. If precision is 64 bits,
5364 the maximum relative error incurred in forming 10**n
5365 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5366 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5367 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5382 /* Punt. Can't handle this without 2 divides. */
5383 emovi (etens
[0], tt
);
5390 p
= &etens
[NTEN
][0];
5400 while (exp
<= MAXP
);
5419 /* Round and convert directly to the destination type */
5421 lexp
-= EXONE
- 0x3ff;
5423 else if (oprec
== 24 || oprec
== 32)
5424 lexp
-= (EXONE
- 0x7f);
5427 else if (oprec
== 24 || oprec
== 56)
5428 lexp
-= EXONE
- (0x41 << 2);
5430 else if (oprec
== 24)
5431 lexp
-= EXONE
- 0177;
5435 else if (oprec
== 56)
5436 lexp
-= EXONE
- 0201;
5439 emdnorm (yy
, lost
, 0, lexp
, 64);
5449 todec (yy
, y
); /* see etodec.c */
5454 toibm (yy
, y
, DFmode
);
5459 toc4x (yy
, y
, HFmode
);
5483 /* Return Y = largest integer not greater than X (truncated toward minus
5486 static unsigned EMUSHORT bmask
[] =
5509 unsigned EMUSHORT x
[], y
[];
5511 register unsigned EMUSHORT
*p
;
5513 unsigned EMUSHORT f
[NE
];
5515 emov (x
, f
); /* leave in external format */
5516 expon
= (int) f
[NE
- 1];
5517 e
= (expon
& 0x7fff) - (EXONE
- 1);
5523 /* number of bits to clear out */
5535 /* clear the remaining bits */
5537 /* truncate negatives toward minus infinity */
5540 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5542 for (i
= 0; i
< NE
- 1; i
++)
5555 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5556 For example, 1.1 = 0.55 * 2^1. */
5560 unsigned EMUSHORT x
[];
5562 unsigned EMUSHORT s
[];
5564 unsigned EMUSHORT xi
[NI
];
5568 /* Handle denormalized numbers properly using long integer exponent. */
5569 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5577 *exp
= (int) (li
- 0x3ffe);
5581 /* Return e type Y = X * 2^PWR2. */
5585 unsigned EMUSHORT x
[];
5587 unsigned EMUSHORT y
[];
5589 unsigned EMUSHORT xi
[NI
];
5597 emdnorm (xi
, i
, i
, li
, 64);
5603 /* C = remainder after dividing B by A, all e type values.
5604 Least significant integer quotient bits left in EQUOT. */
5608 unsigned EMUSHORT a
[], b
[], c
[];
5610 unsigned EMUSHORT den
[NI
], num
[NI
];
5614 || (ecmp (a
, ezero
) == 0)
5622 if (ecmp (a
, ezero
) == 0)
5624 mtherr ("eremain", SING
);
5630 eiremain (den
, num
);
5631 /* Sign of remainder = sign of quotient */
5640 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5641 remainder in NUM. */
5645 unsigned EMUSHORT den
[], num
[];
5648 unsigned EMUSHORT j
;
5651 ld
-= enormlz (den
);
5653 ln
-= enormlz (num
);
5657 if (ecmpm (den
, num
) <= 0)
5669 emdnorm (num
, 0, 0, ln
, 0);
5672 /* Report an error condition CODE encountered in function NAME.
5674 Mnemonic Value Significance
5676 DOMAIN 1 argument domain error
5677 SING 2 function singularity
5678 OVERFLOW 3 overflow range error
5679 UNDERFLOW 4 underflow range error
5680 TLOSS 5 total loss of precision
5681 PLOSS 6 partial loss of precision
5682 INVALID 7 NaN - producing operation
5683 EDOM 33 Unix domain error code
5684 ERANGE 34 Unix range error code
5686 The order of appearance of the following messages is bound to the
5687 error codes defined above. */
5697 /* The string passed by the calling program is supposed to be the
5698 name of the function in which the error occurred.
5699 The code argument selects which error message string will be printed. */
5701 if (strcmp (name
, "esub") == 0)
5702 name
= "subtraction";
5703 else if (strcmp (name
, "ediv") == 0)
5705 else if (strcmp (name
, "emul") == 0)
5706 name
= "multiplication";
5707 else if (strcmp (name
, "enormlz") == 0)
5708 name
= "normalization";
5709 else if (strcmp (name
, "etoasc") == 0)
5710 name
= "conversion to text";
5711 else if (strcmp (name
, "asctoe") == 0)
5713 else if (strcmp (name
, "eremain") == 0)
5715 else if (strcmp (name
, "esqrt") == 0)
5716 name
= "square root";
5721 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5722 case SING
: warning ("%s: function singularity" , name
); break;
5723 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5724 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5725 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5726 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5727 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5732 /* Set global error message word */
5737 /* Convert DEC double precision D to e type E. */
5741 unsigned EMUSHORT
*d
;
5742 unsigned EMUSHORT
*e
;
5744 unsigned EMUSHORT y
[NI
];
5745 register unsigned EMUSHORT r
, *p
;
5747 ecleaz (y
); /* start with a zero */
5748 p
= y
; /* point to our number */
5749 r
= *d
; /* get DEC exponent word */
5750 if (*d
& (unsigned int) 0x8000)
5751 *p
= 0xffff; /* fill in our sign */
5752 ++p
; /* bump pointer to our exponent word */
5753 r
&= 0x7fff; /* strip the sign bit */
5754 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5758 r
>>= 7; /* shift exponent word down 7 bits */
5759 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5760 /* add our e type exponent offset */
5761 *p
++ = r
; /* to form our exponent */
5763 r
= *d
++; /* now do the high order mantissa */
5764 r
&= 0177; /* strip off the DEC exponent and sign bits */
5765 r
|= 0200; /* the DEC understood high order mantissa bit */
5766 *p
++ = r
; /* put result in our high guard word */
5768 *p
++ = *d
++; /* fill in the rest of our mantissa */
5772 eshdn8 (y
); /* shift our mantissa down 8 bits */
5777 /* Convert e type X to DEC double precision D. */
5781 unsigned EMUSHORT
*x
, *d
;
5783 unsigned EMUSHORT xi
[NI
];
5788 /* Adjust exponent for offsets. */
5789 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5790 /* Round off to nearest or even. */
5793 emdnorm (xi
, 0, 0, exp
, 64);
5798 /* Convert exploded e-type X, that has already been rounded to
5799 56-bit precision, to DEC format double Y. */
5803 unsigned EMUSHORT
*x
, *y
;
5805 unsigned EMUSHORT i
;
5806 unsigned EMUSHORT
*p
;
5845 /* Convert IBM single/double precision to e type. */
5849 unsigned EMUSHORT
*d
;
5850 unsigned EMUSHORT
*e
;
5851 enum machine_mode mode
;
5853 unsigned EMUSHORT y
[NI
];
5854 register unsigned EMUSHORT r
, *p
;
5856 ecleaz (y
); /* start with a zero */
5857 p
= y
; /* point to our number */
5858 r
= *d
; /* get IBM exponent word */
5859 if (*d
& (unsigned int) 0x8000)
5860 *p
= 0xffff; /* fill in our sign */
5861 ++p
; /* bump pointer to our exponent word */
5862 r
&= 0x7f00; /* strip the sign bit */
5863 r
>>= 6; /* shift exponent word down 6 bits */
5864 /* in fact shift by 8 right and 2 left */
5865 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5866 /* add our e type exponent offset */
5867 *p
++ = r
; /* to form our exponent */
5869 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5870 /* strip off the IBM exponent and sign bits */
5871 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5873 *p
++ = *d
++; /* fill in the rest of our mantissa */
5878 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5881 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5882 /* handle change in RADIX */
5888 /* Convert e type to IBM single/double precision. */
5892 unsigned EMUSHORT
*x
, *d
;
5893 enum machine_mode mode
;
5895 unsigned EMUSHORT xi
[NI
];
5900 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5901 /* round off to nearest or even */
5904 emdnorm (xi
, 0, 0, exp
, 64);
5906 toibm (xi
, d
, mode
);
5911 unsigned EMUSHORT
*x
, *y
;
5912 enum machine_mode mode
;
5914 unsigned EMUSHORT i
;
5915 unsigned EMUSHORT
*p
;
5965 /* Convert C4X single/double precision to e type. */
5969 unsigned EMUSHORT
*d
;
5970 unsigned EMUSHORT
*e
;
5971 enum machine_mode mode
;
5973 unsigned EMUSHORT y
[NI
];
5980 /* Short-circuit the zero case. */
5981 if ((d
[0] == 0x8000)
5983 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5994 ecleaz (y
); /* start with a zero */
5995 r
= d
[0]; /* get sign/exponent part */
5996 if (r
& (unsigned int) 0x0080)
5998 y
[0] = 0xffff; /* fill in our sign */
6006 r
>>= 8; /* Shift exponent word down 8 bits. */
6007 if (r
& 0x80) /* Make the exponent negative if it is. */
6009 r
= r
| (~0 & ~0xff);
6014 /* Now do the high order mantissa. We don't "or" on the high bit
6015 because it is 2 (not 1) and is handled a little differently
6020 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6022 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6032 /* Now do the two's complement on the data. */
6034 carry
= 1; /* Initially add 1 for the two's complement. */
6035 for (i
=size
+ M
; i
> M
; i
--)
6037 if (carry
&& (y
[i
] == 0x0000))
6039 /* We overflowed into the next word, carry is the same. */
6040 y
[i
] = carry
? 0x0000 : 0xffff;
6044 /* No overflow, just invert and add carry. */
6045 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6060 /* Add our e type exponent offset to form our exponent. */
6064 /* Now do the high order mantissa strip off the exponent and sign
6065 bits and add the high 1 bit. */
6066 y
[M
] = (d
[0] & 0x7f) | 0x80;
6069 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6071 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6081 /* Convert e type to C4X single/double precision. */
6085 unsigned EMUSHORT
*x
, *d
;
6086 enum machine_mode mode
;
6088 unsigned EMUSHORT xi
[NI
];
6094 /* Adjust exponent for offsets. */
6095 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6097 /* Round off to nearest or even. */
6099 rndprc
= mode
== QFmode
? 24 : 32;
6100 emdnorm (xi
, 0, 0, exp
, 64);
6102 toc4x (xi
, d
, mode
);
6107 unsigned EMUSHORT
*x
, *y
;
6108 enum machine_mode mode
;
6114 /* Short-circuit the zero case */
6115 if ((x
[0] == 0) /* Zero exponent and sign */
6117 && (x
[M
] == 0) /* The rest is for zero mantissa */
6119 /* Only check for double if necessary */
6120 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6122 /* We have a zero. Put it into the output and return. */
6135 /* Negative number require a two's complement conversion of the
6141 i
= ((int) x
[1]) - 0x7f;
6143 /* Now add 1 to the inverted data to do the two's complement. */
6153 x
[v
] = carry
? 0x0000 : 0xffff;
6157 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6163 /* The following is a special case. The C4X negative float requires
6164 a zero in the high bit (because the format is (2 - x) x 2^m), so
6165 if a one is in that bit, we have to shift left one to get rid
6166 of it. This only occurs if the number is -1 x 2^m. */
6167 if (x
[M
+1] & 0x8000)
6169 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6170 high sign bit and shift the exponent. */
6177 i
= ((int) x
[1]) - 0x7f;
6180 if ((i
< -128) || (i
> 127))
6195 y
[0] |= ((i
& 0xff) << 8);
6199 y
[0] |= x
[M
] & 0x7f;
6209 /* Output a binary NaN bit pattern in the target machine's format. */
6211 /* If special NaN bit patterns are required, define them in tm.h
6212 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6218 unsigned EMUSHORT TFbignan
[8] =
6219 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6220 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6228 unsigned EMUSHORT XFbignan
[6] =
6229 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6230 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6238 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6239 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6247 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6248 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6255 make_nan (nan
, sign
, mode
)
6256 unsigned EMUSHORT
*nan
;
6258 enum machine_mode mode
;
6261 unsigned EMUSHORT
*p
;
6265 /* Possibly the `reserved operand' patterns on a VAX can be
6266 used like NaN's, but probably not in the same way as IEEE. */
6267 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6270 if (REAL_WORDS_BIG_ENDIAN
)
6278 if (REAL_WORDS_BIG_ENDIAN
)
6286 if (REAL_WORDS_BIG_ENDIAN
)
6295 if (REAL_WORDS_BIG_ENDIAN
)
6305 if (REAL_WORDS_BIG_ENDIAN
)
6306 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6309 if (! REAL_WORDS_BIG_ENDIAN
)
6310 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6314 /* This is the inverse of the function `etarsingle' invoked by
6315 REAL_VALUE_TO_TARGET_SINGLE. */
6318 ereal_unto_float (f
)
6322 unsigned EMUSHORT s
[2];
6323 unsigned EMUSHORT e
[NE
];
6325 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6326 This is the inverse operation to what the function `endian' does. */
6327 if (REAL_WORDS_BIG_ENDIAN
)
6329 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6330 s
[1] = (unsigned EMUSHORT
) f
;
6334 s
[0] = (unsigned EMUSHORT
) f
;
6335 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6337 /* Convert and promote the target float to E-type. */
6339 /* Output E-type to REAL_VALUE_TYPE. */
6345 /* This is the inverse of the function `etardouble' invoked by
6346 REAL_VALUE_TO_TARGET_DOUBLE. */
6349 ereal_unto_double (d
)
6353 unsigned EMUSHORT s
[4];
6354 unsigned EMUSHORT e
[NE
];
6356 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6357 if (REAL_WORDS_BIG_ENDIAN
)
6359 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6360 s
[1] = (unsigned EMUSHORT
) d
[0];
6361 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6362 s
[3] = (unsigned EMUSHORT
) d
[1];
6366 /* Target float words are little-endian. */
6367 s
[0] = (unsigned EMUSHORT
) d
[0];
6368 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6369 s
[2] = (unsigned EMUSHORT
) d
[1];
6370 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6372 /* Convert target double to E-type. */
6374 /* Output E-type to REAL_VALUE_TYPE. */
6380 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6381 This is somewhat like ereal_unto_float, but the input types
6382 for these are different. */
6385 ereal_from_float (f
)
6389 unsigned EMUSHORT s
[2];
6390 unsigned EMUSHORT e
[NE
];
6392 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6393 This is the inverse operation to what the function `endian' does. */
6394 if (REAL_WORDS_BIG_ENDIAN
)
6396 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6397 s
[1] = (unsigned EMUSHORT
) f
;
6401 s
[0] = (unsigned EMUSHORT
) f
;
6402 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6404 /* Convert and promote the target float to E-type. */
6406 /* Output E-type to REAL_VALUE_TYPE. */
6412 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6413 This is somewhat like ereal_unto_double, but the input types
6414 for these are different.
6416 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6417 data format, with no holes in the bit packing. The first element
6418 of the input array holds the bits that would come first in the
6419 target computer's memory. */
6422 ereal_from_double (d
)
6426 unsigned EMUSHORT s
[4];
6427 unsigned EMUSHORT e
[NE
];
6429 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6430 if (REAL_WORDS_BIG_ENDIAN
)
6432 #if HOST_BITS_PER_WIDE_INT == 32
6433 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6434 s
[1] = (unsigned EMUSHORT
) d
[0];
6435 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6436 s
[3] = (unsigned EMUSHORT
) d
[1];
6438 /* In this case the entire target double is contained in the
6439 first array element. The second element of the input is
6441 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6442 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6443 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6444 s
[3] = (unsigned EMUSHORT
) d
[0];
6449 /* Target float words are little-endian. */
6450 s
[0] = (unsigned EMUSHORT
) d
[0];
6451 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6452 #if HOST_BITS_PER_WIDE_INT == 32
6453 s
[2] = (unsigned EMUSHORT
) d
[1];
6454 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6456 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6457 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6460 /* Convert target double to E-type. */
6462 /* Output E-type to REAL_VALUE_TYPE. */
6469 /* Convert target computer unsigned 64-bit integer to e-type.
6470 The endian-ness of DImode follows the convention for integers,
6471 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6475 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6476 unsigned EMUSHORT
*e
;
6478 unsigned EMUSHORT yi
[NI
];
6482 if (WORDS_BIG_ENDIAN
)
6484 for (k
= M
; k
< M
+ 4; k
++)
6489 for (k
= M
+ 3; k
>= M
; k
--)
6492 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6493 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6494 ecleaz (yi
); /* it was zero */
6496 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6500 /* Convert target computer signed 64-bit integer to e-type. */
6504 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6505 unsigned EMUSHORT
*e
;
6507 unsigned EMULONG acc
;
6508 unsigned EMUSHORT yi
[NI
];
6509 unsigned EMUSHORT carry
;
6513 if (WORDS_BIG_ENDIAN
)
6515 for (k
= M
; k
< M
+ 4; k
++)
6520 for (k
= M
+ 3; k
>= M
; k
--)
6523 /* Take absolute value */
6529 for (k
= M
+ 3; k
>= M
; k
--)
6531 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6538 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6539 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6540 ecleaz (yi
); /* it was zero */
6542 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6549 /* Convert e-type to unsigned 64-bit int. */
6553 unsigned EMUSHORT
*x
;
6554 unsigned EMUSHORT
*i
;
6556 unsigned EMUSHORT xi
[NI
];
6565 k
= (int) xi
[E
] - (EXONE
- 1);
6568 for (j
= 0; j
< 4; j
++)
6574 for (j
= 0; j
< 4; j
++)
6577 warning ("overflow on truncation to integer");
6582 /* Shift more than 16 bits: first shift up k-16 mod 16,
6583 then shift up by 16's. */
6584 j
= k
- ((k
>> 4) << 4);
6588 if (WORDS_BIG_ENDIAN
)
6599 if (WORDS_BIG_ENDIAN
)
6604 while ((k
-= 16) > 0);
6608 /* shift not more than 16 bits */
6613 if (WORDS_BIG_ENDIAN
)
6632 /* Convert e-type to signed 64-bit int. */
6636 unsigned EMUSHORT
*x
;
6637 unsigned EMUSHORT
*i
;
6639 unsigned EMULONG acc
;
6640 unsigned EMUSHORT xi
[NI
];
6641 unsigned EMUSHORT carry
;
6642 unsigned EMUSHORT
*isave
;
6646 k
= (int) xi
[E
] - (EXONE
- 1);
6649 for (j
= 0; j
< 4; j
++)
6655 for (j
= 0; j
< 4; j
++)
6658 warning ("overflow on truncation to integer");
6664 /* Shift more than 16 bits: first shift up k-16 mod 16,
6665 then shift up by 16's. */
6666 j
= k
- ((k
>> 4) << 4);
6670 if (WORDS_BIG_ENDIAN
)
6681 if (WORDS_BIG_ENDIAN
)
6686 while ((k
-= 16) > 0);
6690 /* shift not more than 16 bits */
6693 if (WORDS_BIG_ENDIAN
)
6709 /* Negate if negative */
6713 if (WORDS_BIG_ENDIAN
)
6715 for (k
= 0; k
< 4; k
++)
6717 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6718 if (WORDS_BIG_ENDIAN
)
6730 /* Longhand square root routine. */
6733 static int esqinited
= 0;
6734 static unsigned short sqrndbit
[NI
];
6738 unsigned EMUSHORT
*x
, *y
;
6740 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6742 int i
, j
, k
, n
, nlups
;
6747 sqrndbit
[NI
- 2] = 1;
6750 /* Check for arg <= 0 */
6751 i
= ecmp (x
, ezero
);
6756 mtherr ("esqrt", DOMAIN
);
6772 /* Bring in the arg and renormalize if it is denormal. */
6774 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6778 /* Divide exponent by 2 */
6780 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6782 /* Adjust if exponent odd */
6792 n
= 8; /* get 8 bits of result per inner loop */
6798 /* bring in next word of arg */
6800 num
[NI
- 1] = xx
[j
+ 3];
6801 /* Do additional bit on last outer loop, for roundoff. */
6804 for (i
= 0; i
< n
; i
++)
6806 /* Next 2 bits of arg */
6809 /* Shift up answer */
6811 /* Make trial divisor */
6812 for (k
= 0; k
< NI
; k
++)
6815 eaddm (sqrndbit
, temp
);
6816 /* Subtract and insert answer bit if it goes in */
6817 if (ecmpm (temp
, num
) <= 0)
6827 /* Adjust for extra, roundoff loop done. */
6828 exp
+= (NBITS
- 1) - rndprc
;
6830 /* Sticky bit = 1 if the remainder is nonzero. */
6832 for (i
= 3; i
< NI
; i
++)
6835 /* Renormalize and round off. */
6836 emdnorm (sq
, k
, 0, exp
, 64);
6840 #endif /* EMU_NON_COMPILE not defined */
6842 /* Return the binary precision of the significand for a given
6843 floating point mode. The mode can hold an integer value
6844 that many bits wide, without losing any bits. */
6847 significand_size (mode
)
6848 enum machine_mode mode
;
6851 /* Don't test the modes, but their sizes, lest this
6852 code won't work for BITS_PER_UNIT != 8 . */
6854 switch (GET_MODE_BITSIZE (mode
))
6858 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6865 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6868 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6871 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6874 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT