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
98 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT at the same
99 time enables 80387-style 80-bit floats in a 128-bit padded
100 image, as seen on IA-64.
102 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
103 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
104 separate the floating point unit's endian-ness from that of
105 the integer addressing. This permits one to define a big-endian
106 FPU on a little-endian machine (e.g., ARM). An extension to
107 BYTES_BIG_ENDIAN may be required for some machines in the future.
108 These optional macros may be defined in tm.h. In real.h, they
109 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
110 them for any normal host or target machine on which the floats
111 and the integers have the same endian-ness. */
114 /* The following converts gcc macros into the ones used by this file. */
116 /* REAL_ARITHMETIC defined means that macros in real.h are
117 defined to call emulator functions. */
118 #ifdef REAL_ARITHMETIC
120 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
121 /* PDP-11, Pro350, VAX: */
123 #else /* it's not VAX */
124 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
125 /* IBM System/370 style */
127 #else /* it's also not an IBM */
128 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
129 /* TMS320C3x/C4x style */
131 #else /* it's also not a C4X */
132 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
134 #else /* it's not IEEE either */
135 /* UNKnown arithmetic. We don't support this and can't go on. */
136 unknown arithmetic type
138 #endif /* not IEEE */
143 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
146 /* REAL_ARITHMETIC not defined means that the *host's* data
147 structure will be used. It may differ by endian-ness from the
148 target machine's structure and will get its ends swapped
149 accordingly (but not here). Probably only the decimal <-> binary
150 functions in this file will actually be used in this case. */
152 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
154 #else /* it's not VAX */
155 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
156 /* IBM System/370 style */
158 #else /* it's also not an IBM */
159 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
161 #else /* it's not IEEE either */
162 unknown arithmetic type
164 #endif /* not IEEE */
168 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
170 #endif /* REAL_ARITHMETIC not defined */
172 /* Define INFINITY for support of infinity.
173 Define NANS for support of Not-a-Number's (NaN's). */
174 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
179 /* Support of NaNs requires support of infinity. */
186 /* Find a host integer type that is at least 16 bits wide,
187 and another type at least twice whatever that size is. */
189 #if HOST_BITS_PER_CHAR >= 16
190 #define EMUSHORT char
191 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
194 #if HOST_BITS_PER_SHORT >= 16
195 #define EMUSHORT short
196 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
197 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
199 #if HOST_BITS_PER_INT >= 16
201 #define EMUSHORT_SIZE HOST_BITS_PER_INT
202 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
204 #if HOST_BITS_PER_LONG >= 16
205 #define EMUSHORT long
206 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
207 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
209 /* You will have to modify this program to have a smaller unit size. */
210 #define EMU_NON_COMPILE
216 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
217 #define EMULONG short
219 #if HOST_BITS_PER_INT >= EMULONG_SIZE
222 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
225 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
226 #define EMULONG long long int
228 /* You will have to modify this program to have a smaller unit size. */
229 #define EMU_NON_COMPILE
236 /* The host interface doesn't work if no 16-bit size exists. */
237 #if EMUSHORT_SIZE != 16
238 #define EMU_NON_COMPILE
241 /* OK to continue compilation. */
242 #ifndef EMU_NON_COMPILE
244 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
245 In GET_REAL and PUT_REAL, r and e are pointers.
246 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
247 in memory, with no holes. */
249 #if MAX_LONG_DOUBLE_TYPE_SIZE == 96 || \
250 (defined(INTEL_EXTENDED_IEEE_FORMAT) && MAX_LONG_DOUBLE_TYPE_SIZE == 128)
251 /* Number of 16 bit words in external e type format */
253 # define MAXDECEXP 4932
254 # define MINDECEXP -4956
255 # define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
256 # define PUT_REAL(e,r) \
258 memcpy ((char *)(r), (char *)(e), 2*NE); \
259 if (2*NE < sizeof(*r)) \
260 memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
262 # else /* no XFmode */
263 # if MAX_LONG_DOUBLE_TYPE_SIZE == 128
265 # define MAXDECEXP 4932
266 # define MINDECEXP -4977
267 # define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
268 # define PUT_REAL(e,r) \
270 memcpy ((char *)(r), (char *)(e), 2*NE); \
271 if (2*NE < sizeof(*r)) \
272 memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
276 #define MAXDECEXP 4932
277 #define MINDECEXP -4956
278 #ifdef REAL_ARITHMETIC
279 /* Emulator uses target format internally
280 but host stores it in host endian-ness. */
282 #define GET_REAL(r,e) \
284 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
285 e53toe ((unsigned EMUSHORT *) (r), (e)); \
288 unsigned EMUSHORT w[4]; \
289 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
290 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
291 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
292 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
297 #define PUT_REAL(e,r) \
299 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
300 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
303 unsigned EMUSHORT w[4]; \
305 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
306 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
307 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
308 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
312 #else /* not REAL_ARITHMETIC */
314 /* emulator uses host format */
315 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
316 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
318 #endif /* not REAL_ARITHMETIC */
319 #endif /* not TFmode */
320 #endif /* not XFmode */
323 /* Number of 16 bit words in internal format */
326 /* Array offset to exponent */
329 /* Array offset to high guard word */
332 /* Number of bits of precision */
333 #define NBITS ((NI-4)*16)
335 /* Maximum number of decimal digits in ASCII conversion
338 #define NDEC (NBITS*8/27)
340 /* The exponent of 1.0 */
341 #define EXONE (0x3fff)
343 #if defined(HOST_EBCDIC)
344 /* bit 8 is significant in EBCDIC */
345 #define CHARMASK 0xff
347 #define CHARMASK 0x7f
350 extern int extra_warnings
;
351 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
352 extern unsigned EMUSHORT elog2
[], esqrt2
[];
354 static void endian
PARAMS ((unsigned EMUSHORT
*, long *,
356 static void eclear
PARAMS ((unsigned EMUSHORT
*));
357 static void emov
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
359 static void eabs
PARAMS ((unsigned EMUSHORT
*));
361 static void eneg
PARAMS ((unsigned EMUSHORT
*));
362 static int eisneg
PARAMS ((unsigned EMUSHORT
*));
363 static int eisinf
PARAMS ((unsigned EMUSHORT
*));
364 static int eisnan
PARAMS ((unsigned EMUSHORT
*));
365 static void einfin
PARAMS ((unsigned EMUSHORT
*));
367 static void enan
PARAMS ((unsigned EMUSHORT
*, int));
368 static void einan
PARAMS ((unsigned EMUSHORT
*));
369 static int eiisnan
PARAMS ((unsigned EMUSHORT
*));
370 static int eiisneg
PARAMS ((unsigned EMUSHORT
*));
371 static void make_nan
PARAMS ((unsigned EMUSHORT
*, int, enum machine_mode
));
373 static void emovi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void emovo
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void ecleaz
PARAMS ((unsigned EMUSHORT
*));
376 static void ecleazs
PARAMS ((unsigned EMUSHORT
*));
377 static void emovz
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void eiinfin
PARAMS ((unsigned EMUSHORT
*));
382 static int eiisinf
PARAMS ((unsigned EMUSHORT
*));
384 static int ecmpm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static void eshdn1
PARAMS ((unsigned EMUSHORT
*));
386 static void eshup1
PARAMS ((unsigned EMUSHORT
*));
387 static void eshdn8
PARAMS ((unsigned EMUSHORT
*));
388 static void eshup8
PARAMS ((unsigned EMUSHORT
*));
389 static void eshup6
PARAMS ((unsigned EMUSHORT
*));
390 static void eshdn6
PARAMS ((unsigned EMUSHORT
*));
391 static void eaddm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
392 static void esubm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static void m16m
PARAMS ((unsigned int, unsigned short *,
395 static int edivm
PARAMS ((unsigned short *, unsigned short *));
396 static int emulm
PARAMS ((unsigned short *, unsigned short *));
397 static void emdnorm
PARAMS ((unsigned EMUSHORT
*, int, int, EMULONG
, int));
398 static void esub
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
399 unsigned EMUSHORT
*));
400 static void eadd
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
401 unsigned EMUSHORT
*));
402 static void eadd1
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
403 unsigned EMUSHORT
*));
404 static void ediv
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
405 unsigned EMUSHORT
*));
406 static void emul
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
407 unsigned EMUSHORT
*));
408 static void e53toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
409 static void e64toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
410 static void e113toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
411 static void e24toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void etoe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void toe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
414 static void etoe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
415 static void toe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void etoe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
417 static void toe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
418 static void etoe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
419 static void toe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static int ecmp
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
422 static void eround
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
424 static void ltoe
PARAMS ((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
425 static void ultoe
PARAMS ((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
426 static void eifrac
PARAMS ((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
427 unsigned EMUSHORT
*));
428 static void euifrac
PARAMS ((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
429 unsigned EMUSHORT
*));
430 static int eshift
PARAMS ((unsigned EMUSHORT
*, int));
431 static int enormlz
PARAMS ((unsigned EMUSHORT
*));
433 static void e24toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
434 static void e53toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
435 static void e64toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
436 static void e113toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
438 static void etoasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
439 static void asctoe24
PARAMS ((const char *, unsigned EMUSHORT
*));
440 static void asctoe53
PARAMS ((const char *, unsigned EMUSHORT
*));
441 static void asctoe64
PARAMS ((const char *, unsigned EMUSHORT
*));
442 static void asctoe113
PARAMS ((const char *, unsigned EMUSHORT
*));
443 static void asctoe
PARAMS ((const char *, unsigned EMUSHORT
*));
444 static void asctoeg
PARAMS ((const char *, unsigned EMUSHORT
*, int));
445 static void efloor
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
447 static void efrexp
PARAMS ((unsigned EMUSHORT
*, int *,
448 unsigned EMUSHORT
*));
450 static void eldexp
PARAMS ((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
452 static void eremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
453 unsigned EMUSHORT
*));
455 static void eiremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
456 static void mtherr
PARAMS ((const char *, int));
458 static void dectoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
459 static void etodec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
460 static void todec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
463 static void ibmtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
465 static void etoibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
467 static void toibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
471 static void c4xtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
473 static void etoc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
475 static void toc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
479 static void uditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
480 static void ditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
481 static void etoudi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
482 static void etodi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
483 static void esqrt
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
486 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
487 swapping ends if required, into output array of longs. The
488 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
492 unsigned EMUSHORT e
[];
494 enum machine_mode mode
;
498 if (REAL_WORDS_BIG_ENDIAN
)
503 #ifndef INTEL_EXTENDED_IEEE_FORMAT
504 /* Swap halfwords in the fourth long. */
505 th
= (unsigned long) e
[6] & 0xffff;
506 t
= (unsigned long) e
[7] & 0xffff;
512 /* Swap halfwords in the third long. */
513 th
= (unsigned long) e
[4] & 0xffff;
514 t
= (unsigned long) e
[5] & 0xffff;
517 /* fall into the double case */
520 /* Swap halfwords in the second word. */
521 th
= (unsigned long) e
[2] & 0xffff;
522 t
= (unsigned long) e
[3] & 0xffff;
525 /* fall into the float case */
529 /* Swap halfwords in the first word. */
530 th
= (unsigned long) e
[0] & 0xffff;
531 t
= (unsigned long) e
[1] & 0xffff;
542 /* Pack the output array without swapping. */
547 #ifndef INTEL_EXTENDED_IEEE_FORMAT
548 /* Pack the fourth long. */
549 th
= (unsigned long) e
[7] & 0xffff;
550 t
= (unsigned long) e
[6] & 0xffff;
556 /* Pack the third long.
557 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
559 th
= (unsigned long) e
[5] & 0xffff;
560 t
= (unsigned long) e
[4] & 0xffff;
563 /* fall into the double case */
566 /* Pack the second long */
567 th
= (unsigned long) e
[3] & 0xffff;
568 t
= (unsigned long) e
[2] & 0xffff;
571 /* fall into the float case */
575 /* Pack the first long */
576 th
= (unsigned long) e
[1] & 0xffff;
577 t
= (unsigned long) e
[0] & 0xffff;
589 /* This is the implementation of the REAL_ARITHMETIC macro. */
592 earith (value
, icode
, r1
, r2
)
593 REAL_VALUE_TYPE
*value
;
598 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
604 /* Return NaN input back to the caller. */
607 PUT_REAL (d1
, value
);
612 PUT_REAL (d2
, value
);
616 code
= (enum tree_code
) icode
;
624 esub (d2
, d1
, v
); /* d1 - d2 */
632 #ifndef REAL_INFINITY
633 if (ecmp (d2
, ezero
) == 0)
636 enan (v
, eisneg (d1
) ^ eisneg (d2
));
643 ediv (d2
, d1
, v
); /* d1/d2 */
646 case MIN_EXPR
: /* min (d1,d2) */
647 if (ecmp (d1
, d2
) < 0)
653 case MAX_EXPR
: /* max (d1,d2) */
654 if (ecmp (d1
, d2
) > 0)
667 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
668 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
674 unsigned EMUSHORT f
[NE
], g
[NE
];
690 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
691 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
697 unsigned EMUSHORT f
[NE
], g
[NE
];
699 unsigned HOST_WIDE_INT l
;
713 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
714 string to binary, rounding off as indicated by the machine_mode argument.
715 Then it promotes the rounded value to REAL_VALUE_TYPE. */
722 unsigned EMUSHORT tem
[NE
], e
[NE
];
748 #ifndef INTEL_EXTENDED_IEEE_FORMAT
768 /* Expansion of REAL_NEGATE. */
774 unsigned EMUSHORT e
[NE
];
784 /* Round real toward zero to HOST_WIDE_INT;
785 implements REAL_VALUE_FIX (x). */
791 unsigned EMUSHORT f
[NE
], g
[NE
];
798 warning ("conversion from NaN to int");
806 /* Round real toward zero to unsigned HOST_WIDE_INT
807 implements REAL_VALUE_UNSIGNED_FIX (x).
808 Negative input returns zero. */
810 unsigned HOST_WIDE_INT
814 unsigned EMUSHORT f
[NE
], g
[NE
];
815 unsigned HOST_WIDE_INT l
;
821 warning ("conversion from NaN to unsigned int");
830 /* REAL_VALUE_FROM_INT macro. */
833 ereal_from_int (d
, i
, j
, mode
)
836 enum machine_mode mode
;
838 unsigned EMUSHORT df
[NE
], dg
[NE
];
839 HOST_WIDE_INT low
, high
;
842 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
849 /* complement and add 1 */
856 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
857 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
859 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
864 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
865 Avoid double-rounding errors later by rounding off now from the
866 extra-wide internal format to the requested precision. */
867 switch (GET_MODE_BITSIZE (mode
))
885 #ifndef INTEL_EXTENDED_IEEE_FORMAT
902 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
905 ereal_from_uint (d
, i
, j
, mode
)
907 unsigned HOST_WIDE_INT i
, j
;
908 enum machine_mode mode
;
910 unsigned EMUSHORT df
[NE
], dg
[NE
];
911 unsigned HOST_WIDE_INT low
, high
;
913 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
917 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
923 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
924 Avoid double-rounding errors later by rounding off now from the
925 extra-wide internal format to the requested precision. */
926 switch (GET_MODE_BITSIZE (mode
))
944 #ifndef INTEL_EXTENDED_IEEE_FORMAT
961 /* REAL_VALUE_TO_INT macro. */
964 ereal_to_int (low
, high
, rr
)
965 HOST_WIDE_INT
*low
, *high
;
968 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
975 warning ("conversion from NaN to int");
981 /* convert positive value */
988 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
989 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
990 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
991 emul (df
, dh
, dg
); /* fractional part is the low word */
992 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
995 /* complement and add 1 */
1005 /* REAL_VALUE_LDEXP macro. */
1012 unsigned EMUSHORT e
[NE
], y
[NE
];
1025 /* These routines are conditionally compiled because functions
1026 of the same names may be defined in fold-const.c. */
1028 #ifdef REAL_ARITHMETIC
1030 /* Check for infinity in a REAL_VALUE_TYPE. */
1034 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1037 unsigned EMUSHORT e
[NE
];
1040 return (eisinf (e
));
1046 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1050 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1053 unsigned EMUSHORT e
[NE
];
1056 return (eisnan (e
));
1063 /* Check for a negative REAL_VALUE_TYPE number.
1064 This just checks the sign bit, so that -0 counts as negative. */
1070 return ereal_isneg (x
);
1073 /* Expansion of REAL_VALUE_TRUNCATE.
1074 The result is in floating point, rounded to nearest or even. */
1077 real_value_truncate (mode
, arg
)
1078 enum machine_mode mode
;
1079 REAL_VALUE_TYPE arg
;
1081 unsigned EMUSHORT e
[NE
], t
[NE
];
1093 #ifndef INTEL_EXTENDED_IEEE_FORMAT
1130 /* If an unsupported type was requested, presume that
1131 the machine files know something useful to do with
1132 the unmodified value. */
1141 /* Try to change R into its exact multiplicative inverse in machine mode
1142 MODE. Return nonzero function value if successful. */
1145 exact_real_inverse (mode
, r
)
1146 enum machine_mode mode
;
1149 unsigned EMUSHORT e
[NE
], einv
[NE
];
1150 REAL_VALUE_TYPE rinv
;
1155 /* Test for input in range. Don't transform IEEE special values. */
1156 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1159 /* Test for a power of 2: all significand bits zero except the MSB.
1160 We are assuming the target has binary (or hex) arithmetic. */
1161 if (e
[NE
- 2] != 0x8000)
1164 for (i
= 0; i
< NE
- 2; i
++)
1170 /* Compute the inverse and truncate it to the required mode. */
1171 ediv (e
, eone
, einv
);
1172 PUT_REAL (einv
, &rinv
);
1173 rinv
= real_value_truncate (mode
, rinv
);
1175 #ifdef CHECK_FLOAT_VALUE
1176 /* This check is not redundant. It may, for example, flush
1177 a supposedly IEEE denormal value to zero. */
1179 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1182 GET_REAL (&rinv
, einv
);
1184 /* Check the bits again, because the truncation might have
1185 generated an arbitrary saturation value on overflow. */
1186 if (einv
[NE
- 2] != 0x8000)
1189 for (i
= 0; i
< NE
- 2; i
++)
1195 /* Fail if the computed inverse is out of range. */
1196 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1199 /* Output the reciprocal and return success flag. */
1203 #endif /* REAL_ARITHMETIC defined */
1205 /* Used for debugging--print the value of R in human-readable format
1214 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1215 fprintf (stderr
, "%s", dstr
);
1219 /* The following routines convert REAL_VALUE_TYPE to the various floating
1220 point formats that are meaningful to supported computers.
1222 The results are returned in 32-bit pieces, each piece stored in a `long'.
1223 This is so they can be printed by statements like
1225 fprintf (file, "%lx, %lx", L[0], L[1]);
1227 that will work on both narrow- and wide-word host computers. */
1229 /* Convert R to a 128-bit long double precision value. The output array L
1230 contains four 32-bit pieces of the result, in the order they would appear
1238 unsigned EMUSHORT e
[NE
];
1242 endian (e
, l
, TFmode
);
1245 /* Convert R to a double extended precision value. The output array L
1246 contains three 32-bit pieces of the result, in the order they would
1247 appear in memory. */
1254 unsigned EMUSHORT e
[NE
];
1258 endian (e
, l
, XFmode
);
1261 /* Convert R to a double precision value. The output array L contains two
1262 32-bit pieces of the result, in the order they would appear in memory. */
1269 unsigned EMUSHORT e
[NE
];
1273 endian (e
, l
, DFmode
);
1276 /* Convert R to a single precision float value stored in the least-significant
1277 bits of a `long'. */
1283 unsigned EMUSHORT e
[NE
];
1288 endian (e
, &l
, SFmode
);
1292 /* Convert X to a decimal ASCII string S for output to an assembly
1293 language file. Note, there is no standard way to spell infinity or
1294 a NaN, so these values may require special treatment in the tm.h
1298 ereal_to_decimal (x
, s
)
1302 unsigned EMUSHORT e
[NE
];
1308 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1309 or -2 if either is a NaN. */
1313 REAL_VALUE_TYPE x
, y
;
1315 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1319 return (ecmp (ex
, ey
));
1322 /* Return 1 if the sign bit of X is set, else return 0. */
1328 unsigned EMUSHORT ex
[NE
];
1331 return (eisneg (ex
));
1334 /* End of REAL_ARITHMETIC interface */
1337 Extended precision IEEE binary floating point arithmetic routines
1339 Numbers are stored in C language as arrays of 16-bit unsigned
1340 short integers. The arguments of the routines are pointers to
1343 External e type data structure, similar to Intel 8087 chip
1344 temporary real format but possibly with a larger significand:
1346 NE-1 significand words (least significant word first,
1347 most significant bit is normally set)
1348 exponent (value = EXONE for 1.0,
1349 top bit is the sign)
1352 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1354 ei[0] sign word (0 for positive, 0xffff for negative)
1355 ei[1] biased exponent (value = EXONE for the number 1.0)
1356 ei[2] high guard word (always zero after normalization)
1358 to ei[NI-2] significand (NI-4 significand words,
1359 most significant word first,
1360 most significant bit is set)
1361 ei[NI-1] low guard word (0x8000 bit is rounding place)
1365 Routines for external format e-type numbers
1367 asctoe (string, e) ASCII string to extended double e type
1368 asctoe64 (string, &d) ASCII string to long double
1369 asctoe53 (string, &d) ASCII string to double
1370 asctoe24 (string, &f) ASCII string to single
1371 asctoeg (string, e, prec) ASCII string to specified precision
1372 e24toe (&f, e) IEEE single precision to e type
1373 e53toe (&d, e) IEEE double precision to e type
1374 e64toe (&d, e) IEEE long double precision to e type
1375 e113toe (&d, e) 128-bit long double precision to e type
1377 eabs (e) absolute value
1379 eadd (a, b, c) c = b + a
1381 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1382 -1 if a < b, -2 if either a or b is a NaN.
1383 ediv (a, b, c) c = b / a
1384 efloor (a, b) truncate to integer, toward -infinity
1385 efrexp (a, exp, s) extract exponent and significand
1386 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1387 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1388 einfin (e) set e to infinity, leaving its sign alone
1389 eldexp (a, n, b) multiply by 2**n
1391 emul (a, b, c) c = b * a
1394 eround (a, b) b = nearest integer value to a
1396 esub (a, b, c) c = b - a
1398 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1399 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1400 e64toasc (&d, str, n) 80-bit long double to ASCII string
1401 e113toasc (&d, str, n) 128-bit long double to ASCII string
1403 etoasc (e, str, n) e to ASCII string, n digits after decimal
1404 etoe24 (e, &f) convert e type to IEEE single precision
1405 etoe53 (e, &d) convert e type to IEEE double precision
1406 etoe64 (e, &d) convert e type to IEEE long double precision
1407 ltoe (&l, e) HOST_WIDE_INT to e type
1408 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1409 eisneg (e) 1 if sign bit of e != 0, else 0
1410 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1411 or is infinite (IEEE)
1412 eisnan (e) 1 if e is a NaN
1415 Routines for internal format exploded e-type numbers
1417 eaddm (ai, bi) add significands, bi = bi + ai
1419 ecleazs (ei) set ei = 0 but leave its sign alone
1420 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1421 edivm (ai, bi) divide significands, bi = bi / ai
1422 emdnorm (ai,l,s,exp) normalize and round off
1423 emovi (a, ai) convert external a to internal ai
1424 emovo (ai, a) convert internal ai to external a
1425 emovz (ai, bi) bi = ai, low guard word of bi = 0
1426 emulm (ai, bi) multiply significands, bi = bi * ai
1427 enormlz (ei) left-justify the significand
1428 eshdn1 (ai) shift significand and guards down 1 bit
1429 eshdn8 (ai) shift down 8 bits
1430 eshdn6 (ai) shift down 16 bits
1431 eshift (ai, n) shift ai n bits up (or down if n < 0)
1432 eshup1 (ai) shift significand and guards up 1 bit
1433 eshup8 (ai) shift up 8 bits
1434 eshup6 (ai) shift up 16 bits
1435 esubm (ai, bi) subtract significands, bi = bi - ai
1436 eiisinf (ai) 1 if infinite
1437 eiisnan (ai) 1 if a NaN
1438 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1439 einan (ai) set ai = NaN
1441 eiinfin (ai) set ai = infinity
1444 The result is always normalized and rounded to NI-4 word precision
1445 after each arithmetic operation.
1447 Exception flags are NOT fully supported.
1449 Signaling NaN's are NOT supported; they are treated the same
1452 Define INFINITY for support of infinity; otherwise a
1453 saturation arithmetic is implemented.
1455 Define NANS for support of Not-a-Number items; otherwise the
1456 arithmetic will never produce a NaN output, and might be confused
1458 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1459 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1460 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1463 Denormals are always supported here where appropriate (e.g., not
1464 for conversion to DEC numbers). */
1466 /* Definitions for error codes that are passed to the common error handling
1469 For Digital Equipment PDP-11 and VAX computers, certain
1470 IBM systems, and others that use numbers with a 56-bit
1471 significand, the symbol DEC should be defined. In this
1472 mode, most floating point constants are given as arrays
1473 of octal integers to eliminate decimal to binary conversion
1474 errors that might be introduced by the compiler.
1476 For computers, such as IBM PC, that follow the IEEE
1477 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1478 Std 754-1985), the symbol IEEE should be defined.
1479 These numbers have 53-bit significands. In this mode, constants
1480 are provided as arrays of hexadecimal 16 bit integers.
1481 The endian-ness of generated values is controlled by
1482 REAL_WORDS_BIG_ENDIAN.
1484 To accommodate other types of computer arithmetic, all
1485 constants are also provided in a normal decimal radix
1486 which one can hope are correctly converted to a suitable
1487 format by the available C language compiler. To invoke
1488 this mode, the symbol UNK is defined.
1490 An important difference among these modes is a predefined
1491 set of machine arithmetic constants for each. The numbers
1492 MACHEP (the machine roundoff error), MAXNUM (largest number
1493 represented), and several other parameters are preset by
1494 the configuration symbol. Check the file const.c to
1495 ensure that these values are correct for your computer.
1497 For ANSI C compatibility, define ANSIC equal to 1. Currently
1498 this affects only the atan2 function and others that use it. */
1500 /* Constant definitions for math error conditions. */
1502 #define DOMAIN 1 /* argument domain error */
1503 #define SING 2 /* argument singularity */
1504 #define OVERFLOW 3 /* overflow range error */
1505 #define UNDERFLOW 4 /* underflow range error */
1506 #define TLOSS 5 /* total loss of precision */
1507 #define PLOSS 6 /* partial loss of precision */
1508 #define INVALID 7 /* NaN-producing operation */
1510 /* e type constants used by high precision check routines */
1512 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !defined(INTEL_EXTENDED_IEEE_FORMAT)
1514 unsigned EMUSHORT ezero
[NE
] =
1515 {0x0000, 0x0000, 0x0000, 0x0000,
1516 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1517 extern unsigned EMUSHORT ezero
[];
1520 unsigned EMUSHORT ehalf
[NE
] =
1521 {0x0000, 0x0000, 0x0000, 0x0000,
1522 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1523 extern unsigned EMUSHORT ehalf
[];
1526 unsigned EMUSHORT eone
[NE
] =
1527 {0x0000, 0x0000, 0x0000, 0x0000,
1528 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1529 extern unsigned EMUSHORT eone
[];
1532 unsigned EMUSHORT etwo
[NE
] =
1533 {0x0000, 0x0000, 0x0000, 0x0000,
1534 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1535 extern unsigned EMUSHORT etwo
[];
1538 unsigned EMUSHORT e32
[NE
] =
1539 {0x0000, 0x0000, 0x0000, 0x0000,
1540 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1541 extern unsigned EMUSHORT e32
[];
1543 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1544 unsigned EMUSHORT elog2
[NE
] =
1545 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1546 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1547 extern unsigned EMUSHORT elog2
[];
1549 /* 1.41421356237309504880168872420969807856967187537695E0 */
1550 unsigned EMUSHORT esqrt2
[NE
] =
1551 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1552 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1553 extern unsigned EMUSHORT esqrt2
[];
1555 /* 3.14159265358979323846264338327950288419716939937511E0 */
1556 unsigned EMUSHORT epi
[NE
] =
1557 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1558 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1559 extern unsigned EMUSHORT epi
[];
1562 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1563 unsigned EMUSHORT ezero
[NE
] =
1564 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1565 unsigned EMUSHORT ehalf
[NE
] =
1566 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1567 unsigned EMUSHORT eone
[NE
] =
1568 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1569 unsigned EMUSHORT etwo
[NE
] =
1570 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1571 unsigned EMUSHORT e32
[NE
] =
1572 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1573 unsigned EMUSHORT elog2
[NE
] =
1574 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1575 unsigned EMUSHORT esqrt2
[NE
] =
1576 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1577 unsigned EMUSHORT epi
[NE
] =
1578 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1581 /* Control register for rounding precision.
1582 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1587 /* Clear out entire e-type number X. */
1591 register unsigned EMUSHORT
*x
;
1595 for (i
= 0; i
< NE
; i
++)
1599 /* Move e-type number from A to B. */
1603 register unsigned EMUSHORT
*a
, *b
;
1607 for (i
= 0; i
< NE
; i
++)
1613 /* Absolute value of e-type X. */
1617 unsigned EMUSHORT x
[];
1619 /* sign is top bit of last word of external format */
1620 x
[NE
- 1] &= 0x7fff;
1624 /* Negate the e-type number X. */
1628 unsigned EMUSHORT x
[];
1631 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1634 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1638 unsigned EMUSHORT x
[];
1641 if (x
[NE
- 1] & 0x8000)
1647 /* Return 1 if e-type number X is infinity, else return zero. */
1651 unsigned EMUSHORT x
[];
1658 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1664 /* Check if e-type number is not a number. The bit pattern is one that we
1665 defined, so we know for sure how to detect it. */
1669 unsigned EMUSHORT x
[] ATTRIBUTE_UNUSED
;
1674 /* NaN has maximum exponent */
1675 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1677 /* ... and non-zero significand field. */
1678 for (i
= 0; i
< NE
- 1; i
++)
1688 /* Fill e-type number X with infinity pattern (IEEE)
1689 or largest possible number (non-IEEE). */
1693 register unsigned EMUSHORT
*x
;
1698 for (i
= 0; i
< NE
- 1; i
++)
1702 for (i
= 0; i
< NE
- 1; i
++)
1730 /* Output an e-type NaN.
1731 This generates Intel's quiet NaN pattern for extended real.
1732 The exponent is 7fff, the leading mantissa word is c000. */
1737 register unsigned EMUSHORT
*x
;
1742 for (i
= 0; i
< NE
- 2; i
++)
1745 *x
= (sign
<< 15) | 0x7fff;
1749 /* Move in an e-type number A, converting it to exploded e-type B. */
1753 unsigned EMUSHORT
*a
, *b
;
1755 register unsigned EMUSHORT
*p
, *q
;
1759 p
= a
+ (NE
- 1); /* point to last word of external number */
1760 /* get the sign bit */
1765 /* get the exponent */
1767 *q
++ &= 0x7fff; /* delete the sign bit */
1769 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1775 for (i
= 3; i
< NI
; i
++)
1781 for (i
= 2; i
< NI
; i
++)
1787 /* clear high guard word */
1789 /* move in the significand */
1790 for (i
= 0; i
< NE
- 1; i
++)
1792 /* clear low guard word */
1796 /* Move out exploded e-type number A, converting it to e type B. */
1800 unsigned EMUSHORT
*a
, *b
;
1802 register unsigned EMUSHORT
*p
, *q
;
1803 unsigned EMUSHORT i
;
1807 q
= b
+ (NE
- 1); /* point to output exponent */
1808 /* combine sign and exponent */
1811 *q
-- = *p
++ | 0x8000;
1815 if (*(p
- 1) == 0x7fff)
1820 enan (b
, eiisneg (a
));
1828 /* skip over guard word */
1830 /* move the significand */
1831 for (j
= 0; j
< NE
- 1; j
++)
1835 /* Clear out exploded e-type number XI. */
1839 register unsigned EMUSHORT
*xi
;
1843 for (i
= 0; i
< NI
; i
++)
1847 /* Clear out exploded e-type XI, but don't touch the sign. */
1851 register unsigned EMUSHORT
*xi
;
1856 for (i
= 0; i
< NI
- 1; i
++)
1860 /* Move exploded e-type number from A to B. */
1864 register unsigned EMUSHORT
*a
, *b
;
1868 for (i
= 0; i
< NI
- 1; i
++)
1870 /* clear low guard word */
1874 /* Generate exploded e-type NaN.
1875 The explicit pattern for this is maximum exponent and
1876 top two significant bits set. */
1881 unsigned EMUSHORT x
[];
1890 /* Return nonzero if exploded e-type X is a NaN. */
1895 unsigned EMUSHORT x
[];
1899 if ((x
[E
] & 0x7fff) == 0x7fff)
1901 for (i
= M
+ 1; i
< NI
; i
++)
1911 /* Return nonzero if sign of exploded e-type X is nonzero. */
1916 unsigned EMUSHORT x
[];
1924 /* Fill exploded e-type X with infinity pattern.
1925 This has maximum exponent and significand all zeros. */
1929 unsigned EMUSHORT x
[];
1937 /* Return nonzero if exploded e-type X is infinite. */
1942 unsigned EMUSHORT x
[];
1949 if ((x
[E
] & 0x7fff) == 0x7fff)
1953 #endif /* INFINITY */
1955 /* Compare significands of numbers in internal exploded e-type format.
1956 Guard words are included in the comparison.
1964 register unsigned EMUSHORT
*a
, *b
;
1968 a
+= M
; /* skip up to significand area */
1970 for (i
= M
; i
< NI
; i
++)
1978 if (*(--a
) > *(--b
))
1984 /* Shift significand of exploded e-type X down by 1 bit. */
1988 register unsigned EMUSHORT
*x
;
1990 register unsigned EMUSHORT bits
;
1993 x
+= M
; /* point to significand area */
1996 for (i
= M
; i
< NI
; i
++)
2008 /* Shift significand of exploded e-type X up by 1 bit. */
2012 register unsigned EMUSHORT
*x
;
2014 register unsigned EMUSHORT bits
;
2020 for (i
= M
; i
< NI
; i
++)
2033 /* Shift significand of exploded e-type X down by 8 bits. */
2037 register unsigned EMUSHORT
*x
;
2039 register unsigned EMUSHORT newbyt
, oldbyt
;
2044 for (i
= M
; i
< NI
; i
++)
2054 /* Shift significand of exploded e-type X up by 8 bits. */
2058 register unsigned EMUSHORT
*x
;
2061 register unsigned EMUSHORT newbyt
, oldbyt
;
2066 for (i
= M
; i
< NI
; i
++)
2076 /* Shift significand of exploded e-type X up by 16 bits. */
2080 register unsigned EMUSHORT
*x
;
2083 register unsigned EMUSHORT
*p
;
2088 for (i
= M
; i
< NI
- 1; i
++)
2094 /* Shift significand of exploded e-type X down by 16 bits. */
2098 register unsigned EMUSHORT
*x
;
2101 register unsigned EMUSHORT
*p
;
2106 for (i
= M
; i
< NI
- 1; i
++)
2112 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2116 unsigned EMUSHORT
*x
, *y
;
2118 register unsigned EMULONG a
;
2125 for (i
= M
; i
< NI
; i
++)
2127 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2132 *y
= (unsigned EMUSHORT
) a
;
2138 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2142 unsigned EMUSHORT
*x
, *y
;
2151 for (i
= M
; i
< NI
; i
++)
2153 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2158 *y
= (unsigned EMUSHORT
) a
;
2165 static unsigned EMUSHORT equot
[NI
];
2169 /* Radix 2 shift-and-add versions of multiply and divide */
2172 /* Divide significands */
2176 unsigned EMUSHORT den
[], num
[];
2179 register unsigned EMUSHORT
*p
, *q
;
2180 unsigned EMUSHORT j
;
2186 for (i
= M
; i
< NI
; i
++)
2191 /* Use faster compare and subtraction if denominator has only 15 bits of
2197 for (i
= M
+ 3; i
< NI
; i
++)
2202 if ((den
[M
+ 1] & 1) != 0)
2210 for (i
= 0; i
< NBITS
+ 2; i
++)
2228 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2229 bit + 1 roundoff bit. */
2234 for (i
= 0; i
< NBITS
+ 2; i
++)
2236 if (ecmpm (den
, num
) <= 0)
2239 j
= 1; /* quotient bit = 1 */
2253 /* test for nonzero remainder after roundoff bit */
2256 for (i
= M
; i
< NI
; i
++)
2264 for (i
= 0; i
< NI
; i
++)
2270 /* Multiply significands */
2274 unsigned EMUSHORT a
[], b
[];
2276 unsigned EMUSHORT
*p
, *q
;
2281 for (i
= M
; i
< NI
; i
++)
2286 while (*p
== 0) /* significand is not supposed to be zero */
2291 if ((*p
& 0xff) == 0)
2299 for (i
= 0; i
< k
; i
++)
2303 /* remember if there were any nonzero bits shifted out */
2310 for (i
= 0; i
< NI
; i
++)
2313 /* return flag for lost nonzero bits */
2319 /* Radix 65536 versions of multiply and divide. */
2321 /* Multiply significand of e-type number B
2322 by 16-bit quantity A, return e-type result to C. */
2327 unsigned EMUSHORT b
[], c
[];
2329 register unsigned EMUSHORT
*pp
;
2330 register unsigned EMULONG carry
;
2331 unsigned EMUSHORT
*ps
;
2332 unsigned EMUSHORT p
[NI
];
2333 unsigned EMULONG aa
, m
;
2342 for (i
=M
+1; i
<NI
; i
++)
2352 m
= (unsigned EMULONG
) aa
* *ps
--;
2353 carry
= (m
& 0xffff) + *pp
;
2354 *pp
-- = (unsigned EMUSHORT
)carry
;
2355 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2356 *pp
= (unsigned EMUSHORT
)carry
;
2357 *(pp
-1) = carry
>> 16;
2360 for (i
=M
; i
<NI
; i
++)
2364 /* Divide significands of exploded e-types NUM / DEN. Neither the
2365 numerator NUM nor the denominator DEN is permitted to have its high guard
2370 unsigned EMUSHORT den
[], num
[];
2373 register unsigned EMUSHORT
*p
;
2374 unsigned EMULONG tnum
;
2375 unsigned EMUSHORT j
, tdenm
, tquot
;
2376 unsigned EMUSHORT tprod
[NI
+1];
2382 for (i
=M
; i
<NI
; i
++)
2388 for (i
=M
; i
<NI
; i
++)
2390 /* Find trial quotient digit (the radix is 65536). */
2391 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2393 /* Do not execute the divide instruction if it will overflow. */
2394 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2397 tquot
= tnum
/ tdenm
;
2398 /* Multiply denominator by trial quotient digit. */
2399 m16m ((unsigned int)tquot
, den
, tprod
);
2400 /* The quotient digit may have been overestimated. */
2401 if (ecmpm (tprod
, num
) > 0)
2405 if (ecmpm (tprod
, num
) > 0)
2415 /* test for nonzero remainder after roundoff bit */
2418 for (i
=M
; i
<NI
; i
++)
2425 for (i
=0; i
<NI
; i
++)
2431 /* Multiply significands of exploded e-type A and B, result in B. */
2435 unsigned EMUSHORT a
[], b
[];
2437 unsigned EMUSHORT
*p
, *q
;
2438 unsigned EMUSHORT pprod
[NI
];
2439 unsigned EMUSHORT j
;
2444 for (i
=M
; i
<NI
; i
++)
2450 for (i
=M
+1; i
<NI
; i
++)
2458 m16m ((unsigned int) *p
--, b
, pprod
);
2459 eaddm(pprod
, equot
);
2465 for (i
=0; i
<NI
; i
++)
2468 /* return flag for lost nonzero bits */
2474 /* Normalize and round off.
2476 The internal format number to be rounded is S.
2477 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2479 Input SUBFLG indicates whether the number was obtained
2480 by a subtraction operation. In that case if LOST is nonzero
2481 then the number is slightly smaller than indicated.
2483 Input EXP is the biased exponent, which may be negative.
2484 the exponent field of S is ignored but is replaced by
2485 EXP as adjusted by normalization and rounding.
2487 Input RCNTRL is the rounding control. If it is nonzero, the
2488 returned value will be rounded to RNDPRC bits.
2490 For future reference: In order for emdnorm to round off denormal
2491 significands at the right point, the input exponent must be
2492 adjusted to be the actual value it would have after conversion to
2493 the final floating point type. This adjustment has been
2494 implemented for all type conversions (etoe53, etc.) and decimal
2495 conversions, but not for the arithmetic functions (eadd, etc.).
2496 Data types having standard 15-bit exponents are not affected by
2497 this, but SFmode and DFmode are affected. For example, ediv with
2498 rndprc = 24 will not round correctly to 24-bit precision if the
2499 result is denormal. */
2501 static int rlast
= -1;
2503 static unsigned EMUSHORT rmsk
= 0;
2504 static unsigned EMUSHORT rmbit
= 0;
2505 static unsigned EMUSHORT rebit
= 0;
2507 static unsigned EMUSHORT rbit
[NI
];
2510 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2511 unsigned EMUSHORT s
[];
2518 unsigned EMUSHORT r
;
2523 /* a blank significand could mean either zero or infinity. */
2536 if ((j
> NBITS
) && (exp
< 32767))
2544 if (exp
> (EMULONG
) (-NBITS
- 1))
2557 /* Round off, unless told not to by rcntrl. */
2560 /* Set up rounding parameters if the control register changed. */
2561 if (rndprc
!= rlast
)
2568 rw
= NI
- 1; /* low guard word */
2591 /* For DEC or IBM arithmetic */
2608 /* For C4x arithmetic */
2629 /* Shift down 1 temporarily if the data structure has an implied
2630 most significant bit and the number is denormal.
2631 Intel long double denormals also lose one bit of precision. */
2632 if ((exp
<= 0) && (rndprc
!= NBITS
)
2633 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2635 lost
|= s
[NI
- 1] & 1;
2638 /* Clear out all bits below the rounding bit,
2639 remembering in r if any were nonzero. */
2653 if ((r
& rmbit
) != 0)
2659 { /* round to even */
2660 if ((s
[re
] & rebit
) == 0)
2673 /* Undo the temporary shift for denormal values. */
2674 if ((exp
<= 0) && (rndprc
!= NBITS
)
2675 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2680 { /* overflow on roundoff */
2693 for (i
= 2; i
< NI
- 1; i
++)
2696 warning ("floating point overflow");
2700 for (i
= M
+ 1; i
< NI
- 1; i
++)
2703 if ((rndprc
< 64) || (rndprc
== 113))
2718 s
[1] = (unsigned EMUSHORT
) exp
;
2721 /* Subtract. C = B - A, all e type numbers. */
2723 static int subflg
= 0;
2727 unsigned EMUSHORT
*a
, *b
, *c
;
2741 /* Infinity minus infinity is a NaN.
2742 Test for subtracting infinities of the same sign. */
2743 if (eisinf (a
) && eisinf (b
)
2744 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2746 mtherr ("esub", INVALID
);
2755 /* Add. C = A + B, all e type. */
2759 unsigned EMUSHORT
*a
, *b
, *c
;
2763 /* NaN plus anything is a NaN. */
2774 /* Infinity minus infinity is a NaN.
2775 Test for adding infinities of opposite signs. */
2776 if (eisinf (a
) && eisinf (b
)
2777 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2779 mtherr ("esub", INVALID
);
2788 /* Arithmetic common to both addition and subtraction. */
2792 unsigned EMUSHORT
*a
, *b
, *c
;
2794 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2796 EMULONG lt
, lta
, ltb
;
2817 /* compare exponents */
2822 { /* put the larger number in bi */
2832 if (lt
< (EMULONG
) (-NBITS
- 1))
2833 goto done
; /* answer same as larger addend */
2835 lost
= eshift (ai
, k
); /* shift the smaller number down */
2839 /* exponents were the same, so must compare significands */
2842 { /* the numbers are identical in magnitude */
2843 /* if different signs, result is zero */
2849 /* if same sign, result is double */
2850 /* double denormalized tiny number */
2851 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2856 /* add 1 to exponent unless both are zero! */
2857 for (j
= 1; j
< NI
- 1; j
++)
2873 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2877 { /* put the larger number in bi */
2893 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2899 /* Divide: C = B/A, all e type. */
2903 unsigned EMUSHORT
*a
, *b
, *c
;
2905 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2907 EMULONG lt
, lta
, ltb
;
2909 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2910 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2911 sign
= eisneg(a
) ^ eisneg(b
);
2914 /* Return any NaN input. */
2925 /* Zero over zero, or infinity over infinity, is a NaN. */
2926 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2927 || (eisinf (a
) && eisinf (b
)))
2929 mtherr ("ediv", INVALID
);
2934 /* Infinity over anything else is infinity. */
2941 /* Anything else over infinity is zero. */
2953 { /* See if numerator is zero. */
2954 for (i
= 1; i
< NI
- 1; i
++)
2958 ltb
-= enormlz (bi
);
2968 { /* possible divide by zero */
2969 for (i
= 1; i
< NI
- 1; i
++)
2973 lta
-= enormlz (ai
);
2977 /* Divide by zero is not an invalid operation.
2978 It is a divide-by-zero operation! */
2980 mtherr ("ediv", SING
);
2986 /* calculate exponent */
2987 lt
= ltb
- lta
+ EXONE
;
2988 emdnorm (bi
, i
, 0, lt
, 64);
2995 && (ecmp (c
, ezero
) != 0)
2998 *(c
+(NE
-1)) |= 0x8000;
3000 *(c
+(NE
-1)) &= ~0x8000;
3003 /* Multiply e-types A and B, return e-type product C. */
3007 unsigned EMUSHORT
*a
, *b
, *c
;
3009 unsigned EMUSHORT ai
[NI
], bi
[NI
];
3011 EMULONG lt
, lta
, ltb
;
3013 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3014 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3015 sign
= eisneg(a
) ^ eisneg(b
);
3018 /* NaN times anything is the same NaN. */
3029 /* Zero times infinity is a NaN. */
3030 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3031 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3033 mtherr ("emul", INVALID
);
3038 /* Infinity times anything else is infinity. */
3040 if (eisinf (a
) || eisinf (b
))
3052 for (i
= 1; i
< NI
- 1; i
++)
3056 lta
-= enormlz (ai
);
3067 for (i
= 1; i
< NI
- 1; i
++)
3071 ltb
-= enormlz (bi
);
3080 /* Multiply significands */
3082 /* calculate exponent */
3083 lt
= lta
+ ltb
- (EXONE
- 1);
3084 emdnorm (bi
, j
, 0, lt
, 64);
3091 && (ecmp (c
, ezero
) != 0)
3094 *(c
+(NE
-1)) |= 0x8000;
3096 *(c
+(NE
-1)) &= ~0x8000;
3099 /* Convert double precision PE to e-type Y. */
3103 unsigned EMUSHORT
*pe
, *y
;
3112 ibmtoe (pe
, y
, DFmode
);
3117 c4xtoe (pe
, y
, HFmode
);
3120 register unsigned EMUSHORT r
;
3121 register unsigned EMUSHORT
*e
, *p
;
3122 unsigned EMUSHORT yy
[NI
];
3126 denorm
= 0; /* flag if denormalized number */
3128 if (! REAL_WORDS_BIG_ENDIAN
)
3134 yy
[M
] = (r
& 0x0f) | 0x10;
3135 r
&= ~0x800f; /* strip sign and 4 significand bits */
3140 if (! REAL_WORDS_BIG_ENDIAN
)
3142 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3143 || (pe
[1] != 0) || (pe
[0] != 0))
3145 enan (y
, yy
[0] != 0);
3151 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3152 || (pe
[2] != 0) || (pe
[3] != 0))
3154 enan (y
, yy
[0] != 0);
3165 #endif /* INFINITY */
3167 /* If zero exponent, then the significand is denormalized.
3168 So take back the understood high significand bit. */
3179 if (! REAL_WORDS_BIG_ENDIAN
)
3196 /* If zero exponent, then normalize the significand. */
3197 if ((k
= enormlz (yy
)) > NBITS
)
3200 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3203 #endif /* not C4X */
3204 #endif /* not IBM */
3205 #endif /* not DEC */
3208 /* Convert double extended precision float PE to e type Y. */
3212 unsigned EMUSHORT
*pe
, *y
;
3214 unsigned EMUSHORT yy
[NI
];
3215 unsigned EMUSHORT
*e
, *p
, *q
;
3220 for (i
= 0; i
< NE
- 5; i
++)
3222 /* This precision is not ordinarily supported on DEC or IBM. */
3224 for (i
= 0; i
< 5; i
++)
3228 p
= &yy
[0] + (NE
- 1);
3231 for (i
= 0; i
< 5; i
++)
3235 if (! REAL_WORDS_BIG_ENDIAN
)
3237 for (i
= 0; i
< 5; i
++)
3240 /* For denormal long double Intel format, shift significand up one
3241 -- but only if the top significand bit is zero. A top bit of 1
3242 is "pseudodenormal" when the exponent is zero. */
3243 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3245 unsigned EMUSHORT temp
[NI
];
3255 p
= &yy
[0] + (NE
- 1);
3256 #ifdef ARM_EXTENDED_IEEE_FORMAT
3257 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3258 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3264 for (i
= 0; i
< 4; i
++)
3269 /* Point to the exponent field and check max exponent cases. */
3271 if ((*p
& 0x7fff) == 0x7fff)
3274 if (! REAL_WORDS_BIG_ENDIAN
)
3276 for (i
= 0; i
< 4; i
++)
3278 if ((i
!= 3 && pe
[i
] != 0)
3279 /* Anything but 0x8000 here, including 0, is a NaN. */
3280 || (i
== 3 && pe
[i
] != 0x8000))
3282 enan (y
, (*p
& 0x8000) != 0);
3289 #ifdef ARM_EXTENDED_IEEE_FORMAT
3290 for (i
= 2; i
<= 5; i
++)
3294 enan (y
, (*p
& 0x8000) != 0);
3299 /* In Motorola extended precision format, the most significant
3300 bit of an infinity mantissa could be either 1 or 0. It is
3301 the lower order bits that tell whether the value is a NaN. */
3302 if ((pe
[2] & 0x7fff) != 0)
3305 for (i
= 3; i
<= 5; i
++)
3310 enan (y
, (*p
& 0x8000) != 0);
3314 #endif /* not ARM */
3323 #endif /* INFINITY */
3326 for (i
= 0; i
< NE
; i
++)
3330 /* Convert 128-bit long double precision float PE to e type Y. */
3334 unsigned EMUSHORT
*pe
, *y
;
3336 register unsigned EMUSHORT r
;
3337 unsigned EMUSHORT
*e
, *p
;
3338 unsigned EMUSHORT yy
[NI
];
3345 if (! REAL_WORDS_BIG_ENDIAN
)
3357 if (! REAL_WORDS_BIG_ENDIAN
)
3359 for (i
= 0; i
< 7; i
++)
3363 enan (y
, yy
[0] != 0);
3370 for (i
= 1; i
< 8; i
++)
3374 enan (y
, yy
[0] != 0);
3386 #endif /* INFINITY */
3390 if (! REAL_WORDS_BIG_ENDIAN
)
3392 for (i
= 0; i
< 7; i
++)
3398 for (i
= 0; i
< 7; i
++)
3402 /* If denormal, remove the implied bit; else shift down 1. */
3415 /* Convert single precision float PE to e type Y. */
3419 unsigned EMUSHORT
*pe
, *y
;
3423 ibmtoe (pe
, y
, SFmode
);
3429 c4xtoe (pe
, y
, QFmode
);
3433 register unsigned EMUSHORT r
;
3434 register unsigned EMUSHORT
*e
, *p
;
3435 unsigned EMUSHORT yy
[NI
];
3439 denorm
= 0; /* flag if denormalized number */
3442 if (! REAL_WORDS_BIG_ENDIAN
)
3452 yy
[M
] = (r
& 0x7f) | 0200;
3453 r
&= ~0x807f; /* strip sign and 7 significand bits */
3458 if (REAL_WORDS_BIG_ENDIAN
)
3460 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3462 enan (y
, yy
[0] != 0);
3468 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3470 enan (y
, yy
[0] != 0);
3481 #endif /* INFINITY */
3483 /* If zero exponent, then the significand is denormalized.
3484 So take back the understood high significand bit. */
3497 if (! REAL_WORDS_BIG_ENDIAN
)
3507 { /* if zero exponent, then normalize the significand */
3508 if ((k
= enormlz (yy
)) > NBITS
)
3511 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3514 #endif /* not C4X */
3515 #endif /* not IBM */
3518 /* Convert e-type X to IEEE 128-bit long double format E. */
3522 unsigned EMUSHORT
*x
, *e
;
3524 unsigned EMUSHORT xi
[NI
];
3531 make_nan (e
, eisneg (x
), TFmode
);
3536 exp
= (EMULONG
) xi
[E
];
3541 /* round off to nearest or even */
3544 emdnorm (xi
, 0, 0, exp
, 64);
3552 /* Convert exploded e-type X, that has already been rounded to
3553 113-bit precision, to IEEE 128-bit long double format Y. */
3557 unsigned EMUSHORT
*a
, *b
;
3559 register unsigned EMUSHORT
*p
, *q
;
3560 unsigned EMUSHORT i
;
3565 make_nan (b
, eiisneg (a
), TFmode
);
3570 if (REAL_WORDS_BIG_ENDIAN
)
3573 q
= b
+ 7; /* point to output exponent */
3575 /* If not denormal, delete the implied bit. */
3580 /* combine sign and exponent */
3582 if (REAL_WORDS_BIG_ENDIAN
)
3585 *q
++ = *p
++ | 0x8000;
3592 *q
-- = *p
++ | 0x8000;
3596 /* skip over guard word */
3598 /* move the significand */
3599 if (REAL_WORDS_BIG_ENDIAN
)
3601 for (i
= 0; i
< 7; i
++)
3606 for (i
= 0; i
< 7; i
++)
3611 /* Convert e-type X to IEEE double extended format E. */
3615 unsigned EMUSHORT
*x
, *e
;
3617 unsigned EMUSHORT xi
[NI
];
3624 make_nan (e
, eisneg (x
), XFmode
);
3629 /* adjust exponent for offset */
3630 exp
= (EMULONG
) xi
[E
];
3635 /* round off to nearest or even */
3638 emdnorm (xi
, 0, 0, exp
, 64);
3646 /* Convert exploded e-type X, that has already been rounded to
3647 64-bit precision, to IEEE double extended format Y. */
3651 unsigned EMUSHORT
*a
, *b
;
3653 register unsigned EMUSHORT
*p
, *q
;
3654 unsigned EMUSHORT i
;
3659 make_nan (b
, eiisneg (a
), XFmode
);
3663 /* Shift denormal long double Intel format significand down one bit. */
3664 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3674 if (REAL_WORDS_BIG_ENDIAN
)
3678 q
= b
+ 4; /* point to output exponent */
3679 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3680 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3681 always there, and there are never more bytes, even when we are using
3682 INTEL_EXTENDED_IEEE_FORMAT. */
3687 /* combine sign and exponent */
3691 *q
++ = *p
++ | 0x8000;
3698 *q
-- = *p
++ | 0x8000;
3703 if (REAL_WORDS_BIG_ENDIAN
)
3705 #ifdef ARM_EXTENDED_IEEE_FORMAT
3706 /* The exponent is in the lowest 15 bits of the first word. */
3707 *q
++ = i
? 0x8000 : 0;
3711 *q
++ = *p
++ | 0x8000;
3720 *q
-- = *p
++ | 0x8000;
3725 /* skip over guard word */
3727 /* move the significand */
3729 for (i
= 0; i
< 4; i
++)
3733 for (i
= 0; i
< 4; i
++)
3737 if (REAL_WORDS_BIG_ENDIAN
)
3739 for (i
= 0; i
< 4; i
++)
3747 /* Intel long double infinity significand. */
3755 for (i
= 0; i
< 4; i
++)
3761 /* e type to double precision. */
3764 /* Convert e-type X to DEC-format double E. */
3768 unsigned EMUSHORT
*x
, *e
;
3770 etodec (x
, e
); /* see etodec.c */
3773 /* Convert exploded e-type X, that has already been rounded to
3774 56-bit double precision, to DEC double Y. */
3778 unsigned EMUSHORT
*x
, *y
;
3785 /* Convert e-type X to IBM 370-format double E. */
3789 unsigned EMUSHORT
*x
, *e
;
3791 etoibm (x
, e
, DFmode
);
3794 /* Convert exploded e-type X, that has already been rounded to
3795 56-bit precision, to IBM 370 double Y. */
3799 unsigned EMUSHORT
*x
, *y
;
3801 toibm (x
, y
, DFmode
);
3804 #else /* it's neither DEC nor IBM */
3806 /* Convert e-type X to C4X-format long double E. */
3810 unsigned EMUSHORT
*x
, *e
;
3812 etoc4x (x
, e
, HFmode
);
3815 /* Convert exploded e-type X, that has already been rounded to
3816 56-bit precision, to IBM 370 double Y. */
3820 unsigned EMUSHORT
*x
, *y
;
3822 toc4x (x
, y
, HFmode
);
3825 #else /* it's neither DEC nor IBM nor C4X */
3827 /* Convert e-type X to IEEE double E. */
3831 unsigned EMUSHORT
*x
, *e
;
3833 unsigned EMUSHORT xi
[NI
];
3840 make_nan (e
, eisneg (x
), DFmode
);
3845 /* adjust exponent for offsets */
3846 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3851 /* round off to nearest or even */
3854 emdnorm (xi
, 0, 0, exp
, 64);
3862 /* Convert exploded e-type X, that has already been rounded to
3863 53-bit precision, to IEEE double Y. */
3867 unsigned EMUSHORT
*x
, *y
;
3869 unsigned EMUSHORT i
;
3870 unsigned EMUSHORT
*p
;
3875 make_nan (y
, eiisneg (x
), DFmode
);
3881 if (! REAL_WORDS_BIG_ENDIAN
)
3884 *y
= 0; /* output high order */
3886 *y
= 0x8000; /* output sign bit */
3889 if (i
>= (unsigned int) 2047)
3891 /* Saturate at largest number less than infinity. */
3894 if (! REAL_WORDS_BIG_ENDIAN
)
3908 *y
|= (unsigned EMUSHORT
) 0x7fef;
3909 if (! REAL_WORDS_BIG_ENDIAN
)
3934 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3935 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3936 if (! REAL_WORDS_BIG_ENDIAN
)
3951 #endif /* not C4X */
3952 #endif /* not IBM */
3953 #endif /* not DEC */
3957 /* e type to single precision. */
3960 /* Convert e-type X to IBM 370 float E. */
3964 unsigned EMUSHORT
*x
, *e
;
3966 etoibm (x
, e
, SFmode
);
3969 /* Convert exploded e-type X, that has already been rounded to
3970 float precision, to IBM 370 float Y. */
3974 unsigned EMUSHORT
*x
, *y
;
3976 toibm (x
, y
, SFmode
);
3982 /* Convert e-type X to C4X float E. */
3986 unsigned EMUSHORT
*x
, *e
;
3988 etoc4x (x
, e
, QFmode
);
3991 /* Convert exploded e-type X, that has already been rounded to
3992 float precision, to IBM 370 float Y. */
3996 unsigned EMUSHORT
*x
, *y
;
3998 toc4x (x
, y
, QFmode
);
4003 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
4007 unsigned EMUSHORT
*x
, *e
;
4010 unsigned EMUSHORT xi
[NI
];
4016 make_nan (e
, eisneg (x
), SFmode
);
4021 /* adjust exponent for offsets */
4022 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
4027 /* round off to nearest or even */
4030 emdnorm (xi
, 0, 0, exp
, 64);
4038 /* Convert exploded e-type X, that has already been rounded to
4039 float precision, to IEEE float Y. */
4043 unsigned EMUSHORT
*x
, *y
;
4045 unsigned EMUSHORT i
;
4046 unsigned EMUSHORT
*p
;
4051 make_nan (y
, eiisneg (x
), SFmode
);
4057 if (! REAL_WORDS_BIG_ENDIAN
)
4063 *y
= 0; /* output high order */
4065 *y
= 0x8000; /* output sign bit */
4068 /* Handle overflow cases. */
4072 *y
|= (unsigned EMUSHORT
) 0x7f80;
4077 if (! REAL_WORDS_BIG_ENDIAN
)
4085 #else /* no INFINITY */
4086 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4091 if (! REAL_WORDS_BIG_ENDIAN
)
4102 #endif /* no INFINITY */
4114 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4115 /* High order output already has sign bit set. */
4121 if (! REAL_WORDS_BIG_ENDIAN
)
4130 #endif /* not C4X */
4131 #endif /* not IBM */
4133 /* Compare two e type numbers.
4137 -2 if either a or b is a NaN. */
4141 unsigned EMUSHORT
*a
, *b
;
4143 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4144 register unsigned EMUSHORT
*p
, *q
;
4149 if (eisnan (a
) || eisnan (b
))
4158 { /* the signs are different */
4160 for (i
= 1; i
< NI
- 1; i
++)
4174 /* both are the same sign */
4189 return (0); /* equality */
4193 if (*(--p
) > *(--q
))
4194 return (msign
); /* p is bigger */
4196 return (-msign
); /* p is littler */
4200 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4204 unsigned EMUSHORT
*x
, *y
;
4211 /* Convert HOST_WIDE_INT LP to e type Y. */
4216 unsigned EMUSHORT
*y
;
4218 unsigned EMUSHORT yi
[NI
];
4219 unsigned HOST_WIDE_INT ll
;
4225 /* make it positive */
4226 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4227 yi
[0] = 0xffff; /* put correct sign in the e type number */
4231 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4233 /* move the long integer to yi significand area */
4234 #if HOST_BITS_PER_WIDE_INT == 64
4235 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4236 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4237 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4238 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4239 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4241 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4242 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4243 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4246 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4247 ecleaz (yi
); /* it was zero */
4249 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4250 emovo (yi
, y
); /* output the answer */
4253 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4257 unsigned HOST_WIDE_INT
*lp
;
4258 unsigned EMUSHORT
*y
;
4260 unsigned EMUSHORT yi
[NI
];
4261 unsigned HOST_WIDE_INT ll
;
4267 /* move the long integer to ayi significand area */
4268 #if HOST_BITS_PER_WIDE_INT == 64
4269 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4270 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4271 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4272 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4273 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4275 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4276 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4277 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4280 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4281 ecleaz (yi
); /* it was zero */
4283 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4284 emovo (yi
, y
); /* output the answer */
4288 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4289 part FRAC of e-type (packed internal format) floating point input X.
4290 The integer output I has the sign of the input, except that
4291 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4292 The output e-type fraction FRAC is the positive fractional
4297 unsigned EMUSHORT
*x
;
4299 unsigned EMUSHORT
*frac
;
4301 unsigned EMUSHORT xi
[NI
];
4303 unsigned HOST_WIDE_INT ll
;
4306 k
= (int) xi
[E
] - (EXONE
- 1);
4309 /* if exponent <= 0, integer = 0 and real output is fraction */
4314 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4316 /* long integer overflow: output large integer
4317 and correct fraction */
4319 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4322 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4323 /* In this case, let it overflow and convert as if unsigned. */
4324 euifrac (x
, &ll
, frac
);
4325 *i
= (HOST_WIDE_INT
) ll
;
4328 /* In other cases, return the largest positive integer. */
4329 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4334 warning ("overflow on truncation to integer");
4338 /* Shift more than 16 bits: first shift up k-16 mod 16,
4339 then shift up by 16's. */
4340 j
= k
- ((k
>> 4) << 4);
4347 ll
= (ll
<< 16) | xi
[M
];
4349 while ((k
-= 16) > 0);
4356 /* shift not more than 16 bits */
4358 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4365 if ((k
= enormlz (xi
)) > NBITS
)
4368 xi
[E
] -= (unsigned EMUSHORT
) k
;
4374 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4375 FRAC of e-type X. A negative input yields integer output = 0 but
4376 correct fraction. */
4379 euifrac (x
, i
, frac
)
4380 unsigned EMUSHORT
*x
;
4381 unsigned HOST_WIDE_INT
*i
;
4382 unsigned EMUSHORT
*frac
;
4384 unsigned HOST_WIDE_INT ll
;
4385 unsigned EMUSHORT xi
[NI
];
4389 k
= (int) xi
[E
] - (EXONE
- 1);
4392 /* if exponent <= 0, integer = 0 and argument is fraction */
4397 if (k
> HOST_BITS_PER_WIDE_INT
)
4399 /* Long integer overflow: output large integer
4400 and correct fraction.
4401 Note, the BSD microvax compiler says that ~(0UL)
4402 is a syntax error. */
4406 warning ("overflow on truncation to unsigned integer");
4410 /* Shift more than 16 bits: first shift up k-16 mod 16,
4411 then shift up by 16's. */
4412 j
= k
- ((k
>> 4) << 4);
4419 ll
= (ll
<< 16) | xi
[M
];
4421 while ((k
-= 16) > 0);
4426 /* shift not more than 16 bits */
4428 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4431 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4437 if ((k
= enormlz (xi
)) > NBITS
)
4440 xi
[E
] -= (unsigned EMUSHORT
) k
;
4445 /* Shift the significand of exploded e-type X up or down by SC bits. */
4449 unsigned EMUSHORT
*x
;
4452 unsigned EMUSHORT lost
;
4453 unsigned EMUSHORT
*p
;
4466 lost
|= *p
; /* remember lost bits */
4507 return ((int) lost
);
4510 /* Shift normalize the significand area of exploded e-type X.
4511 Return the shift count (up = positive). */
4515 unsigned EMUSHORT x
[];
4517 register unsigned EMUSHORT
*p
;
4526 return (0); /* already normalized */
4532 /* With guard word, there are NBITS+16 bits available.
4533 Return true if all are zero. */
4537 /* see if high byte is zero */
4538 while ((*p
& 0xff00) == 0)
4543 /* now shift 1 bit at a time */
4544 while ((*p
& 0x8000) == 0)
4550 mtherr ("enormlz", UNDERFLOW
);
4556 /* Normalize by shifting down out of the high guard word
4557 of the significand */
4572 mtherr ("enormlz", OVERFLOW
);
4579 /* Powers of ten used in decimal <-> binary conversions. */
4584 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !defined(INTEL_EXTENDED_IEEE_FORMAT)
4585 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4587 {0x6576, 0x4a92, 0x804a, 0x153f,
4588 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4589 {0x6a32, 0xce52, 0x329a, 0x28ce,
4590 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4591 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4592 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4593 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4594 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4595 {0x851e, 0xeab7, 0x98fe, 0x901b,
4596 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4597 {0x0235, 0x0137, 0x36b1, 0x336c,
4598 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4599 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4600 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4601 {0x0000, 0x0000, 0x0000, 0x0000,
4602 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4603 {0x0000, 0x0000, 0x0000, 0x0000,
4604 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4605 {0x0000, 0x0000, 0x0000, 0x0000,
4606 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4607 {0x0000, 0x0000, 0x0000, 0x0000,
4608 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4609 {0x0000, 0x0000, 0x0000, 0x0000,
4610 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4611 {0x0000, 0x0000, 0x0000, 0x0000,
4612 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4615 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4617 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4618 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4619 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4620 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4621 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4622 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4623 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4624 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4625 {0xa23e, 0x5308, 0xfefb, 0x1155,
4626 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4627 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4628 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4629 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4630 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4631 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4632 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4633 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4634 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4635 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4636 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4637 {0xc155, 0xa4a8, 0x404e, 0x6113,
4638 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4639 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4640 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4641 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4642 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4645 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4646 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4648 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4649 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4650 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4651 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4652 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4653 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4654 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4655 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4656 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4657 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4658 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4659 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4660 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4663 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4665 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4666 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4667 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4668 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4669 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4670 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4671 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4672 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4673 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4674 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4675 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4676 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4677 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4682 /* Convert float value X to ASCII string STRING with NDIG digits after
4683 the decimal point. */
4686 e24toasc (x
, string
, ndigs
)
4687 unsigned EMUSHORT x
[];
4691 unsigned EMUSHORT w
[NI
];
4694 etoasc (w
, string
, ndigs
);
4697 /* Convert double value X to ASCII string STRING with NDIG digits after
4698 the decimal point. */
4701 e53toasc (x
, string
, ndigs
)
4702 unsigned EMUSHORT x
[];
4706 unsigned EMUSHORT w
[NI
];
4709 etoasc (w
, string
, ndigs
);
4712 /* Convert double extended value X to ASCII string STRING with NDIG digits
4713 after the decimal point. */
4716 e64toasc (x
, string
, ndigs
)
4717 unsigned EMUSHORT x
[];
4721 unsigned EMUSHORT w
[NI
];
4724 etoasc (w
, string
, ndigs
);
4727 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4728 after the decimal point. */
4731 e113toasc (x
, string
, ndigs
)
4732 unsigned EMUSHORT x
[];
4736 unsigned EMUSHORT w
[NI
];
4739 etoasc (w
, string
, ndigs
);
4743 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4744 the decimal point. */
4746 static char wstring
[80]; /* working storage for ASCII output */
4749 etoasc (x
, string
, ndigs
)
4750 unsigned EMUSHORT x
[];
4755 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4756 unsigned EMUSHORT
*p
, *r
, *ten
;
4757 unsigned EMUSHORT sign
;
4758 int i
, j
, k
, expon
, rndsav
;
4760 unsigned EMUSHORT m
;
4771 sprintf (wstring
, " NaN ");
4775 rndprc
= NBITS
; /* set to full precision */
4776 emov (x
, y
); /* retain external format */
4777 if (y
[NE
- 1] & 0x8000)
4780 y
[NE
- 1] &= 0x7fff;
4787 ten
= &etens
[NTEN
][0];
4789 /* Test for zero exponent */
4792 for (k
= 0; k
< NE
- 1; k
++)
4795 goto tnzro
; /* denormalized number */
4797 goto isone
; /* valid all zeros */
4801 /* Test for infinity. */
4802 if (y
[NE
- 1] == 0x7fff)
4805 sprintf (wstring
, " -Infinity ");
4807 sprintf (wstring
, " Infinity ");
4811 /* Test for exponent nonzero but significand denormalized.
4812 * This is an error condition.
4814 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4816 mtherr ("etoasc", DOMAIN
);
4817 sprintf (wstring
, "NaN");
4821 /* Compare to 1.0 */
4830 { /* Number is greater than 1 */
4831 /* Convert significand to an integer and strip trailing decimal zeros. */
4833 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4835 p
= &etens
[NTEN
- 4][0];
4841 for (j
= 0; j
< NE
- 1; j
++)
4854 /* Rescale from integer significand */
4855 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4857 /* Find power of 10 */
4861 /* An unordered compare result shouldn't happen here. */
4862 while (ecmp (ten
, u
) <= 0)
4864 if (ecmp (p
, u
) <= 0)
4877 { /* Number is less than 1.0 */
4878 /* Pad significand with trailing decimal zeros. */
4881 while ((y
[NE
- 2] & 0x8000) == 0)
4890 for (i
= 0; i
< NDEC
+ 1; i
++)
4892 if ((w
[NI
- 1] & 0x7) != 0)
4894 /* multiply by 10 */
4907 if (eone
[NE
- 1] <= u
[1])
4919 while (ecmp (eone
, w
) > 0)
4921 if (ecmp (p
, w
) >= 0)
4936 /* Find the first (leading) digit. */
4942 digit
= equot
[NI
- 1];
4943 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4951 digit
= equot
[NI
- 1];
4959 /* Examine number of digits requested by caller. */
4977 *s
++ = (char)digit
+ '0';
4980 /* Generate digits after the decimal point. */
4981 for (k
= 0; k
<= ndigs
; k
++)
4983 /* multiply current number by 10, without normalizing */
4990 *s
++ = (char) equot
[NI
- 1] + '0';
4992 digit
= equot
[NI
- 1];
4995 /* round off the ASCII string */
4998 /* Test for critical rounding case in ASCII output. */
5002 if (ecmp (t
, ezero
) != 0)
5003 goto roun
; /* round to nearest */
5005 if ((*(s
- 1) & 1) == 0)
5006 goto doexp
; /* round to even */
5009 /* Round up and propagate carry-outs */
5013 /* Carry out to most significant digit? */
5020 /* Most significant digit carries to 10? */
5028 /* Round up and carry out from less significant digits */
5040 sprintf (ss, "e+%d", expon);
5042 sprintf (ss, "e%d", expon);
5044 sprintf (ss
, "e%d", expon
);
5047 /* copy out the working string */
5050 while (*ss
== ' ') /* strip possible leading space */
5052 while ((*s
++ = *ss
++) != '\0')
5057 /* Convert ASCII string to floating point.
5059 Numeric input is a free format decimal number of any length, with
5060 or without decimal point. Entering E after the number followed by an
5061 integer number causes the second number to be interpreted as a power of
5062 10 to be multiplied by the first number (i.e., "scientific" notation). */
5064 /* Convert ASCII string S to single precision float value Y. */
5069 unsigned EMUSHORT
*y
;
5075 /* Convert ASCII string S to double precision value Y. */
5080 unsigned EMUSHORT
*y
;
5082 #if defined(DEC) || defined(IBM)
5094 /* Convert ASCII string S to double extended value Y. */
5099 unsigned EMUSHORT
*y
;
5104 /* Convert ASCII string S to 128-bit long double Y. */
5109 unsigned EMUSHORT
*y
;
5111 asctoeg (s
, y
, 113);
5114 /* Convert ASCII string S to e type Y. */
5119 unsigned EMUSHORT
*y
;
5121 asctoeg (s
, y
, NBITS
);
5124 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5125 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5128 asctoeg (ss
, y
, oprec
)
5130 unsigned EMUSHORT
*y
;
5133 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5134 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5135 int k
, trail
, c
, rndsav
;
5137 unsigned EMUSHORT nsign
, *p
;
5138 char *sp
, *s
, *lstr
;
5141 /* Copy the input string. */
5142 lstr
= (char *) alloca (strlen (ss
) + 1);
5144 while (*ss
== ' ') /* skip leading spaces */
5148 while ((*sp
++ = *ss
++) != '\0')
5152 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5159 rndprc
= NBITS
; /* Set to full precision */
5171 if (*s
>= '0' && *s
<= '9')
5173 else if (*s
>= 'a' && *s
<= 'f')
5177 if ((k
>= 0) && (k
< base
))
5179 /* Ignore leading zeros */
5180 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5182 /* Identify and strip trailing zeros after the decimal point. */
5183 if ((trail
== 0) && (decflg
!= 0))
5186 while ((*sp
>= '0' && *sp
<= '9')
5187 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5188 || (*sp
>= 'A' && *sp
<= 'F'))))
5190 /* Check for syntax error */
5192 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5193 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5195 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5197 goto unexpected_char_error
;
5206 /* If enough digits were given to more than fill up the yy register,
5207 continuing until overflow into the high guard word yy[2]
5208 guarantees that there will be a roundoff bit at the top
5209 of the low guard word after normalization. */
5216 nexp
+= 4; /* count digits after decimal point */
5218 eshup1 (yy
); /* multiply current number by 16 */
5226 nexp
+= 1; /* count digits after decimal point */
5228 eshup1 (yy
); /* multiply current number by 10 */
5234 /* Insert the current digit. */
5236 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5241 /* Mark any lost non-zero digit. */
5243 /* Count lost digits before the decimal point. */
5265 case '.': /* decimal point */
5267 goto unexpected_char_error
;
5273 goto unexpected_char_error
;
5278 goto unexpected_char_error
;
5291 unexpected_char_error
:
5295 mtherr ("asctoe", DOMAIN
);
5304 /* Exponent interpretation */
5306 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5307 for (k
= 0; k
< NI
; k
++)
5318 /* check for + or - */
5326 while ((*s
>= '0') && (*s
<= '9'))
5335 if ((exp
> MAXDECEXP
) && (base
== 10))
5339 yy
[E
] = 0x7fff; /* infinity */
5342 if ((exp
< MINDECEXP
) && (base
== 10))
5352 /* Base 16 hexadecimal floating constant. */
5353 if ((k
= enormlz (yy
)) > NBITS
)
5358 /* Adjust the exponent. NEXP is the number of hex digits,
5359 EXP is a power of 2. */
5360 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5370 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5371 while ((nexp
> 0) && (yy
[2] == 0))
5383 if ((k
= enormlz (yy
)) > NBITS
)
5388 lexp
= (EXONE
- 1 + NBITS
) - k
;
5389 emdnorm (yy
, lost
, 0, lexp
, 64);
5392 /* Convert to external format:
5394 Multiply by 10**nexp. If precision is 64 bits,
5395 the maximum relative error incurred in forming 10**n
5396 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5397 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5398 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5413 /* Punt. Can't handle this without 2 divides. */
5414 emovi (etens
[0], tt
);
5421 p
= &etens
[NTEN
][0];
5431 while (exp
<= MAXP
);
5450 /* Round and convert directly to the destination type */
5452 lexp
-= EXONE
- 0x3ff;
5454 else if (oprec
== 24 || oprec
== 32)
5455 lexp
-= (EXONE
- 0x7f);
5458 else if (oprec
== 24 || oprec
== 56)
5459 lexp
-= EXONE
- (0x41 << 2);
5461 else if (oprec
== 24)
5462 lexp
-= EXONE
- 0177;
5466 else if (oprec
== 56)
5467 lexp
-= EXONE
- 0201;
5470 emdnorm (yy
, lost
, 0, lexp
, 64);
5480 todec (yy
, y
); /* see etodec.c */
5485 toibm (yy
, y
, DFmode
);
5490 toc4x (yy
, y
, HFmode
);
5514 /* Return Y = largest integer not greater than X (truncated toward minus
5517 static unsigned EMUSHORT bmask
[] =
5540 unsigned EMUSHORT x
[], y
[];
5542 register unsigned EMUSHORT
*p
;
5544 unsigned EMUSHORT f
[NE
];
5546 emov (x
, f
); /* leave in external format */
5547 expon
= (int) f
[NE
- 1];
5548 e
= (expon
& 0x7fff) - (EXONE
- 1);
5554 /* number of bits to clear out */
5566 /* clear the remaining bits */
5568 /* truncate negatives toward minus infinity */
5571 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5573 for (i
= 0; i
< NE
- 1; i
++)
5586 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5587 For example, 1.1 = 0.55 * 2^1. */
5591 unsigned EMUSHORT x
[];
5593 unsigned EMUSHORT s
[];
5595 unsigned EMUSHORT xi
[NI
];
5599 /* Handle denormalized numbers properly using long integer exponent. */
5600 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5608 *exp
= (int) (li
- 0x3ffe);
5612 /* Return e type Y = X * 2^PWR2. */
5616 unsigned EMUSHORT x
[];
5618 unsigned EMUSHORT y
[];
5620 unsigned EMUSHORT xi
[NI
];
5628 emdnorm (xi
, i
, i
, li
, 64);
5634 /* C = remainder after dividing B by A, all e type values.
5635 Least significant integer quotient bits left in EQUOT. */
5639 unsigned EMUSHORT a
[], b
[], c
[];
5641 unsigned EMUSHORT den
[NI
], num
[NI
];
5645 || (ecmp (a
, ezero
) == 0)
5653 if (ecmp (a
, ezero
) == 0)
5655 mtherr ("eremain", SING
);
5661 eiremain (den
, num
);
5662 /* Sign of remainder = sign of quotient */
5671 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5672 remainder in NUM. */
5676 unsigned EMUSHORT den
[], num
[];
5679 unsigned EMUSHORT j
;
5682 ld
-= enormlz (den
);
5684 ln
-= enormlz (num
);
5688 if (ecmpm (den
, num
) <= 0)
5700 emdnorm (num
, 0, 0, ln
, 0);
5703 /* Report an error condition CODE encountered in function NAME.
5705 Mnemonic Value Significance
5707 DOMAIN 1 argument domain error
5708 SING 2 function singularity
5709 OVERFLOW 3 overflow range error
5710 UNDERFLOW 4 underflow range error
5711 TLOSS 5 total loss of precision
5712 PLOSS 6 partial loss of precision
5713 INVALID 7 NaN - producing operation
5714 EDOM 33 Unix domain error code
5715 ERANGE 34 Unix range error code
5717 The order of appearance of the following messages is bound to the
5718 error codes defined above. */
5728 /* The string passed by the calling program is supposed to be the
5729 name of the function in which the error occurred.
5730 The code argument selects which error message string will be printed. */
5732 if (strcmp (name
, "esub") == 0)
5733 name
= "subtraction";
5734 else if (strcmp (name
, "ediv") == 0)
5736 else if (strcmp (name
, "emul") == 0)
5737 name
= "multiplication";
5738 else if (strcmp (name
, "enormlz") == 0)
5739 name
= "normalization";
5740 else if (strcmp (name
, "etoasc") == 0)
5741 name
= "conversion to text";
5742 else if (strcmp (name
, "asctoe") == 0)
5744 else if (strcmp (name
, "eremain") == 0)
5746 else if (strcmp (name
, "esqrt") == 0)
5747 name
= "square root";
5752 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5753 case SING
: warning ("%s: function singularity" , name
); break;
5754 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5755 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5756 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5757 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5758 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5763 /* Set global error message word */
5768 /* Convert DEC double precision D to e type E. */
5772 unsigned EMUSHORT
*d
;
5773 unsigned EMUSHORT
*e
;
5775 unsigned EMUSHORT y
[NI
];
5776 register unsigned EMUSHORT r
, *p
;
5778 ecleaz (y
); /* start with a zero */
5779 p
= y
; /* point to our number */
5780 r
= *d
; /* get DEC exponent word */
5781 if (*d
& (unsigned int) 0x8000)
5782 *p
= 0xffff; /* fill in our sign */
5783 ++p
; /* bump pointer to our exponent word */
5784 r
&= 0x7fff; /* strip the sign bit */
5785 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5789 r
>>= 7; /* shift exponent word down 7 bits */
5790 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5791 /* add our e type exponent offset */
5792 *p
++ = r
; /* to form our exponent */
5794 r
= *d
++; /* now do the high order mantissa */
5795 r
&= 0177; /* strip off the DEC exponent and sign bits */
5796 r
|= 0200; /* the DEC understood high order mantissa bit */
5797 *p
++ = r
; /* put result in our high guard word */
5799 *p
++ = *d
++; /* fill in the rest of our mantissa */
5803 eshdn8 (y
); /* shift our mantissa down 8 bits */
5808 /* Convert e type X to DEC double precision D. */
5812 unsigned EMUSHORT
*x
, *d
;
5814 unsigned EMUSHORT xi
[NI
];
5819 /* Adjust exponent for offsets. */
5820 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5821 /* Round off to nearest or even. */
5824 emdnorm (xi
, 0, 0, exp
, 64);
5829 /* Convert exploded e-type X, that has already been rounded to
5830 56-bit precision, to DEC format double Y. */
5834 unsigned EMUSHORT
*x
, *y
;
5836 unsigned EMUSHORT i
;
5837 unsigned EMUSHORT
*p
;
5876 /* Convert IBM single/double precision to e type. */
5880 unsigned EMUSHORT
*d
;
5881 unsigned EMUSHORT
*e
;
5882 enum machine_mode mode
;
5884 unsigned EMUSHORT y
[NI
];
5885 register unsigned EMUSHORT r
, *p
;
5887 ecleaz (y
); /* start with a zero */
5888 p
= y
; /* point to our number */
5889 r
= *d
; /* get IBM exponent word */
5890 if (*d
& (unsigned int) 0x8000)
5891 *p
= 0xffff; /* fill in our sign */
5892 ++p
; /* bump pointer to our exponent word */
5893 r
&= 0x7f00; /* strip the sign bit */
5894 r
>>= 6; /* shift exponent word down 6 bits */
5895 /* in fact shift by 8 right and 2 left */
5896 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5897 /* add our e type exponent offset */
5898 *p
++ = r
; /* to form our exponent */
5900 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5901 /* strip off the IBM exponent and sign bits */
5902 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5904 *p
++ = *d
++; /* fill in the rest of our mantissa */
5909 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5912 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5913 /* handle change in RADIX */
5919 /* Convert e type to IBM single/double precision. */
5923 unsigned EMUSHORT
*x
, *d
;
5924 enum machine_mode mode
;
5926 unsigned EMUSHORT xi
[NI
];
5931 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5932 /* round off to nearest or even */
5935 emdnorm (xi
, 0, 0, exp
, 64);
5937 toibm (xi
, d
, mode
);
5942 unsigned EMUSHORT
*x
, *y
;
5943 enum machine_mode mode
;
5945 unsigned EMUSHORT i
;
5946 unsigned EMUSHORT
*p
;
5996 /* Convert C4X single/double precision to e type. */
6000 unsigned EMUSHORT
*d
;
6001 unsigned EMUSHORT
*e
;
6002 enum machine_mode mode
;
6004 unsigned EMUSHORT y
[NI
];
6011 /* Short-circuit the zero case. */
6012 if ((d
[0] == 0x8000)
6014 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
6025 ecleaz (y
); /* start with a zero */
6026 r
= d
[0]; /* get sign/exponent part */
6027 if (r
& (unsigned int) 0x0080)
6029 y
[0] = 0xffff; /* fill in our sign */
6037 r
>>= 8; /* Shift exponent word down 8 bits. */
6038 if (r
& 0x80) /* Make the exponent negative if it is. */
6040 r
= r
| (~0 & ~0xff);
6045 /* Now do the high order mantissa. We don't "or" on the high bit
6046 because it is 2 (not 1) and is handled a little differently
6051 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6053 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6063 /* Now do the two's complement on the data. */
6065 carry
= 1; /* Initially add 1 for the two's complement. */
6066 for (i
=size
+ M
; i
> M
; i
--)
6068 if (carry
&& (y
[i
] == 0x0000))
6070 /* We overflowed into the next word, carry is the same. */
6071 y
[i
] = carry
? 0x0000 : 0xffff;
6075 /* No overflow, just invert and add carry. */
6076 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6091 /* Add our e type exponent offset to form our exponent. */
6095 /* Now do the high order mantissa strip off the exponent and sign
6096 bits and add the high 1 bit. */
6097 y
[M
] = (d
[0] & 0x7f) | 0x80;
6100 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6102 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6112 /* Convert e type to C4X single/double precision. */
6116 unsigned EMUSHORT
*x
, *d
;
6117 enum machine_mode mode
;
6119 unsigned EMUSHORT xi
[NI
];
6125 /* Adjust exponent for offsets. */
6126 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6128 /* Round off to nearest or even. */
6130 rndprc
= mode
== QFmode
? 24 : 32;
6131 emdnorm (xi
, 0, 0, exp
, 64);
6133 toc4x (xi
, d
, mode
);
6138 unsigned EMUSHORT
*x
, *y
;
6139 enum machine_mode mode
;
6145 /* Short-circuit the zero case */
6146 if ((x
[0] == 0) /* Zero exponent and sign */
6148 && (x
[M
] == 0) /* The rest is for zero mantissa */
6150 /* Only check for double if necessary */
6151 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6153 /* We have a zero. Put it into the output and return. */
6166 /* Negative number require a two's complement conversion of the
6172 i
= ((int) x
[1]) - 0x7f;
6174 /* Now add 1 to the inverted data to do the two's complement. */
6184 x
[v
] = carry
? 0x0000 : 0xffff;
6188 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6194 /* The following is a special case. The C4X negative float requires
6195 a zero in the high bit (because the format is (2 - x) x 2^m), so
6196 if a one is in that bit, we have to shift left one to get rid
6197 of it. This only occurs if the number is -1 x 2^m. */
6198 if (x
[M
+1] & 0x8000)
6200 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6201 high sign bit and shift the exponent. */
6208 i
= ((int) x
[1]) - 0x7f;
6211 if ((i
< -128) || (i
> 127))
6226 y
[0] |= ((i
& 0xff) << 8);
6230 y
[0] |= x
[M
] & 0x7f;
6240 /* Output a binary NaN bit pattern in the target machine's format. */
6242 /* If special NaN bit patterns are required, define them in tm.h
6243 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6249 unsigned EMUSHORT TFbignan
[8] =
6250 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6251 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6259 unsigned EMUSHORT XFbignan
[6] =
6260 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6261 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6269 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6270 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6278 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6279 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6286 make_nan (nan
, sign
, mode
)
6287 unsigned EMUSHORT
*nan
;
6289 enum machine_mode mode
;
6292 unsigned EMUSHORT
*p
;
6296 /* Possibly the `reserved operand' patterns on a VAX can be
6297 used like NaN's, but probably not in the same way as IEEE. */
6298 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6300 #ifndef INTEL_EXTENDED_IEEE_FORMAT
6302 if (REAL_WORDS_BIG_ENDIAN
)
6312 if (REAL_WORDS_BIG_ENDIAN
)
6320 if (REAL_WORDS_BIG_ENDIAN
)
6329 if (REAL_WORDS_BIG_ENDIAN
)
6339 if (REAL_WORDS_BIG_ENDIAN
)
6340 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6343 if (! REAL_WORDS_BIG_ENDIAN
)
6344 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6348 /* This is the inverse of the function `etarsingle' invoked by
6349 REAL_VALUE_TO_TARGET_SINGLE. */
6352 ereal_unto_float (f
)
6356 unsigned EMUSHORT s
[2];
6357 unsigned EMUSHORT e
[NE
];
6359 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6360 This is the inverse operation to what the function `endian' does. */
6361 if (REAL_WORDS_BIG_ENDIAN
)
6363 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6364 s
[1] = (unsigned EMUSHORT
) f
;
6368 s
[0] = (unsigned EMUSHORT
) f
;
6369 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6371 /* Convert and promote the target float to E-type. */
6373 /* Output E-type to REAL_VALUE_TYPE. */
6379 /* This is the inverse of the function `etardouble' invoked by
6380 REAL_VALUE_TO_TARGET_DOUBLE. */
6383 ereal_unto_double (d
)
6387 unsigned EMUSHORT s
[4];
6388 unsigned EMUSHORT e
[NE
];
6390 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6391 if (REAL_WORDS_BIG_ENDIAN
)
6393 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6394 s
[1] = (unsigned EMUSHORT
) d
[0];
6395 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6396 s
[3] = (unsigned EMUSHORT
) d
[1];
6400 /* Target float words are little-endian. */
6401 s
[0] = (unsigned EMUSHORT
) d
[0];
6402 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6403 s
[2] = (unsigned EMUSHORT
) d
[1];
6404 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6406 /* Convert target double to E-type. */
6408 /* Output E-type to REAL_VALUE_TYPE. */
6414 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6415 This is somewhat like ereal_unto_float, but the input types
6416 for these are different. */
6419 ereal_from_float (f
)
6423 unsigned EMUSHORT s
[2];
6424 unsigned EMUSHORT e
[NE
];
6426 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6427 This is the inverse operation to what the function `endian' does. */
6428 if (REAL_WORDS_BIG_ENDIAN
)
6430 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6431 s
[1] = (unsigned EMUSHORT
) f
;
6435 s
[0] = (unsigned EMUSHORT
) f
;
6436 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6438 /* Convert and promote the target float to E-type. */
6440 /* Output E-type to REAL_VALUE_TYPE. */
6446 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6447 This is somewhat like ereal_unto_double, but the input types
6448 for these are different.
6450 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6451 data format, with no holes in the bit packing. The first element
6452 of the input array holds the bits that would come first in the
6453 target computer's memory. */
6456 ereal_from_double (d
)
6460 unsigned EMUSHORT s
[4];
6461 unsigned EMUSHORT e
[NE
];
6463 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6464 if (REAL_WORDS_BIG_ENDIAN
)
6466 #if HOST_BITS_PER_WIDE_INT == 32
6467 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6468 s
[1] = (unsigned EMUSHORT
) d
[0];
6469 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6470 s
[3] = (unsigned EMUSHORT
) d
[1];
6472 /* In this case the entire target double is contained in the
6473 first array element. The second element of the input is
6475 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6476 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6477 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6478 s
[3] = (unsigned EMUSHORT
) d
[0];
6483 /* Target float words are little-endian. */
6484 s
[0] = (unsigned EMUSHORT
) d
[0];
6485 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6486 #if HOST_BITS_PER_WIDE_INT == 32
6487 s
[2] = (unsigned EMUSHORT
) d
[1];
6488 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6490 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6491 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6494 /* Convert target double to E-type. */
6496 /* Output E-type to REAL_VALUE_TYPE. */
6503 /* Convert target computer unsigned 64-bit integer to e-type.
6504 The endian-ness of DImode follows the convention for integers,
6505 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6509 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6510 unsigned EMUSHORT
*e
;
6512 unsigned EMUSHORT yi
[NI
];
6516 if (WORDS_BIG_ENDIAN
)
6518 for (k
= M
; k
< M
+ 4; k
++)
6523 for (k
= M
+ 3; k
>= M
; k
--)
6526 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6527 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6528 ecleaz (yi
); /* it was zero */
6530 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6534 /* Convert target computer signed 64-bit integer to e-type. */
6538 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6539 unsigned EMUSHORT
*e
;
6541 unsigned EMULONG acc
;
6542 unsigned EMUSHORT yi
[NI
];
6543 unsigned EMUSHORT carry
;
6547 if (WORDS_BIG_ENDIAN
)
6549 for (k
= M
; k
< M
+ 4; k
++)
6554 for (k
= M
+ 3; k
>= M
; k
--)
6557 /* Take absolute value */
6563 for (k
= M
+ 3; k
>= M
; k
--)
6565 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6572 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6573 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6574 ecleaz (yi
); /* it was zero */
6576 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6583 /* Convert e-type to unsigned 64-bit int. */
6587 unsigned EMUSHORT
*x
;
6588 unsigned EMUSHORT
*i
;
6590 unsigned EMUSHORT xi
[NI
];
6599 k
= (int) xi
[E
] - (EXONE
- 1);
6602 for (j
= 0; j
< 4; j
++)
6608 for (j
= 0; j
< 4; j
++)
6611 warning ("overflow on truncation to integer");
6616 /* Shift more than 16 bits: first shift up k-16 mod 16,
6617 then shift up by 16's. */
6618 j
= k
- ((k
>> 4) << 4);
6622 if (WORDS_BIG_ENDIAN
)
6633 if (WORDS_BIG_ENDIAN
)
6638 while ((k
-= 16) > 0);
6642 /* shift not more than 16 bits */
6647 if (WORDS_BIG_ENDIAN
)
6666 /* Convert e-type to signed 64-bit int. */
6670 unsigned EMUSHORT
*x
;
6671 unsigned EMUSHORT
*i
;
6673 unsigned EMULONG acc
;
6674 unsigned EMUSHORT xi
[NI
];
6675 unsigned EMUSHORT carry
;
6676 unsigned EMUSHORT
*isave
;
6680 k
= (int) xi
[E
] - (EXONE
- 1);
6683 for (j
= 0; j
< 4; j
++)
6689 for (j
= 0; j
< 4; j
++)
6692 warning ("overflow on truncation to integer");
6698 /* Shift more than 16 bits: first shift up k-16 mod 16,
6699 then shift up by 16's. */
6700 j
= k
- ((k
>> 4) << 4);
6704 if (WORDS_BIG_ENDIAN
)
6715 if (WORDS_BIG_ENDIAN
)
6720 while ((k
-= 16) > 0);
6724 /* shift not more than 16 bits */
6727 if (WORDS_BIG_ENDIAN
)
6743 /* Negate if negative */
6747 if (WORDS_BIG_ENDIAN
)
6749 for (k
= 0; k
< 4; k
++)
6751 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6752 if (WORDS_BIG_ENDIAN
)
6764 /* Longhand square root routine. */
6767 static int esqinited
= 0;
6768 static unsigned short sqrndbit
[NI
];
6772 unsigned EMUSHORT
*x
, *y
;
6774 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6776 int i
, j
, k
, n
, nlups
;
6781 sqrndbit
[NI
- 2] = 1;
6784 /* Check for arg <= 0 */
6785 i
= ecmp (x
, ezero
);
6790 mtherr ("esqrt", DOMAIN
);
6806 /* Bring in the arg and renormalize if it is denormal. */
6808 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6812 /* Divide exponent by 2 */
6814 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6816 /* Adjust if exponent odd */
6826 n
= 8; /* get 8 bits of result per inner loop */
6832 /* bring in next word of arg */
6834 num
[NI
- 1] = xx
[j
+ 3];
6835 /* Do additional bit on last outer loop, for roundoff. */
6838 for (i
= 0; i
< n
; i
++)
6840 /* Next 2 bits of arg */
6843 /* Shift up answer */
6845 /* Make trial divisor */
6846 for (k
= 0; k
< NI
; k
++)
6849 eaddm (sqrndbit
, temp
);
6850 /* Subtract and insert answer bit if it goes in */
6851 if (ecmpm (temp
, num
) <= 0)
6861 /* Adjust for extra, roundoff loop done. */
6862 exp
+= (NBITS
- 1) - rndprc
;
6864 /* Sticky bit = 1 if the remainder is nonzero. */
6866 for (i
= 3; i
< NI
; i
++)
6869 /* Renormalize and round off. */
6870 emdnorm (sq
, k
, 0, exp
, 64);
6874 #endif /* EMU_NON_COMPILE not defined */
6876 /* Return the binary precision of the significand for a given
6877 floating point mode. The mode can hold an integer value
6878 that many bits wide, without losing any bits. */
6881 significand_size (mode
)
6882 enum machine_mode mode
;
6885 /* Don't test the modes, but their sizes, lest this
6886 code won't work for BITS_PER_UNIT != 8 . */
6888 switch (GET_MODE_BITSIZE (mode
))
6892 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6899 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6902 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6905 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6908 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6921 #ifndef INTEL_EXTENDED_IEEE_FORMAT