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, 94-99, 2000 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 /* To enable support of XFmode extended real floating point, define
30 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
32 To support cross compilation between IEEE, VAX and IBM floating
33 point formats, define REAL_ARITHMETIC in the tm.h file.
35 In either case the machine files (tm.h) must not contain any code
36 that tries to use host floating point arithmetic to convert
37 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
38 etc. In cross-compile situations a REAL_VALUE_TYPE may not
39 be intelligible to the host computer's native arithmetic.
41 The emulator defaults to the host's floating point format so that
42 its decimal conversion functions can be used if desired (see
45 The first part of this file interfaces gcc to a floating point
46 arithmetic suite that was not written with gcc in mind. Avoid
47 changing the low-level arithmetic routines unless you have suitable
48 test programs available. A special version of the PARANOIA floating
49 point arithmetic tester, modified for this purpose, can be found on
50 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
51 XFmode and TFmode transcendental functions, can be obtained by ftp from
52 netlib.att.com: netlib/cephes. */
54 /* Type of computer arithmetic.
55 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
57 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
58 to big-endian IEEE floating-point data structure. This definition
59 should work in SFmode `float' type and DFmode `double' type on
60 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
61 has been defined to be 96, then IEEE also invokes the particular
62 XFmode (`long double' type) data structure used by the Motorola
63 680x0 series processors.
65 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
66 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
67 has been defined to be 96, then IEEE also invokes the particular
68 XFmode `long double' data structure used by the Intel 80x86 series
71 `DEC' refers specifically to the Digital Equipment Corp PDP-11
72 and VAX floating point data structure. This model currently
73 supports no type wider than DFmode.
75 `IBM' refers specifically to the IBM System/370 and compatible
76 floating point data structure. This model currently supports
77 no type wider than DFmode. The IBM conversions were contributed by
78 frank@atom.ansto.gov.au (Frank Crawford).
80 `C4X' refers specifically to the floating point format used on
81 Texas Instruments TMS320C3x and TMS320C4x digital signal
82 processors. This supports QFmode (32-bit float, double) and HFmode
83 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
84 floats, C4x floats are not rounded to be even. The C4x conversions
85 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
86 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
88 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
89 then `long double' and `double' are both implemented, but they
90 both mean DFmode. In this case, the software floating-point
91 support available here is activated by writing
92 #define REAL_ARITHMETIC
95 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
96 and may deactivate XFmode since `long double' is used to refer
99 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
100 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
101 separate the floating point unit's endian-ness from that of
102 the integer addressing. This permits one to define a big-endian
103 FPU on a little-endian machine (e.g., ARM). An extension to
104 BYTES_BIG_ENDIAN may be required for some machines in the future.
105 These optional macros may be defined in tm.h. In real.h, they
106 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
107 them for any normal host or target machine on which the floats
108 and the integers have the same endian-ness. */
111 /* The following converts gcc macros into the ones used by this file. */
113 /* REAL_ARITHMETIC defined means that macros in real.h are
114 defined to call emulator functions. */
115 #ifdef REAL_ARITHMETIC
117 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
118 /* PDP-11, Pro350, VAX: */
120 #else /* it's not VAX */
121 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
122 /* IBM System/370 style */
124 #else /* it's also not an IBM */
125 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
126 /* TMS320C3x/C4x style */
128 #else /* it's also not a C4X */
129 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
131 #else /* it's not IEEE either */
132 /* UNKnown arithmetic. We don't support this and can't go on. */
133 unknown arithmetic type
135 #endif /* not IEEE */
140 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
143 /* REAL_ARITHMETIC not defined means that the *host's* data
144 structure will be used. It may differ by endian-ness from the
145 target machine's structure and will get its ends swapped
146 accordingly (but not here). Probably only the decimal <-> binary
147 functions in this file will actually be used in this case. */
149 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
151 #else /* it's not VAX */
152 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
153 /* IBM System/370 style */
155 #else /* it's also not an IBM */
156 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
158 #else /* it's not IEEE either */
159 unknown arithmetic type
161 #endif /* not IEEE */
165 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
167 #endif /* REAL_ARITHMETIC not defined */
169 /* Define INFINITY for support of infinity.
170 Define NANS for support of Not-a-Number's (NaN's). */
171 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
176 /* Support of NaNs requires support of infinity. */
183 /* Find a host integer type that is at least 16 bits wide,
184 and another type at least twice whatever that size is. */
186 #if HOST_BITS_PER_CHAR >= 16
187 #define EMUSHORT char
188 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
189 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
191 #if HOST_BITS_PER_SHORT >= 16
192 #define EMUSHORT short
193 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
194 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
196 #if HOST_BITS_PER_INT >= 16
198 #define EMUSHORT_SIZE HOST_BITS_PER_INT
199 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
201 #if HOST_BITS_PER_LONG >= 16
202 #define EMUSHORT long
203 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
204 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
206 /* You will have to modify this program to have a smaller unit size. */
207 #define EMU_NON_COMPILE
213 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
214 #define EMULONG short
216 #if HOST_BITS_PER_INT >= EMULONG_SIZE
219 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
222 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
223 #define EMULONG long long int
225 /* You will have to modify this program to have a smaller unit size. */
226 #define EMU_NON_COMPILE
233 /* The host interface doesn't work if no 16-bit size exists. */
234 #if EMUSHORT_SIZE != 16
235 #define EMU_NON_COMPILE
238 /* OK to continue compilation. */
239 #ifndef EMU_NON_COMPILE
241 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
242 In GET_REAL and PUT_REAL, r and e are pointers.
243 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
244 in memory, with no holes. */
246 #if LONG_DOUBLE_TYPE_SIZE == 96
247 /* Number of 16 bit words in external e type format */
249 #define MAXDECEXP 4932
250 #define MINDECEXP -4956
251 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
252 #define PUT_REAL(e,r) \
254 if (2*NE < sizeof(*r)) \
255 bzero((char *)r, sizeof(*r)); \
256 bcopy ((char *) e, (char *) r, 2*NE); \
258 #else /* no XFmode */
259 #if LONG_DOUBLE_TYPE_SIZE == 128
261 #define MAXDECEXP 4932
262 #define MINDECEXP -4977
263 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
264 #define PUT_REAL(e,r) \
266 if (2*NE < sizeof(*r)) \
267 bzero((char *)r, sizeof(*r)); \
268 bcopy ((char *) e, (char *) r, 2*NE); \
272 #define MAXDECEXP 4932
273 #define MINDECEXP -4956
274 #ifdef REAL_ARITHMETIC
275 /* Emulator uses target format internally
276 but host stores it in host endian-ness. */
278 #define GET_REAL(r,e) \
280 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
281 e53toe ((unsigned EMUSHORT *) (r), (e)); \
284 unsigned EMUSHORT w[4]; \
285 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
286 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
287 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
288 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
293 #define PUT_REAL(e,r) \
295 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
296 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
299 unsigned EMUSHORT w[4]; \
301 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
302 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
303 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
304 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
308 #else /* not REAL_ARITHMETIC */
310 /* emulator uses host format */
311 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
312 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
314 #endif /* not REAL_ARITHMETIC */
315 #endif /* not TFmode */
316 #endif /* not XFmode */
319 /* Number of 16 bit words in internal format */
322 /* Array offset to exponent */
325 /* Array offset to high guard word */
328 /* Number of bits of precision */
329 #define NBITS ((NI-4)*16)
331 /* Maximum number of decimal digits in ASCII conversion
334 #define NDEC (NBITS*8/27)
336 /* The exponent of 1.0 */
337 #define EXONE (0x3fff)
339 extern int extra_warnings
;
340 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
341 extern unsigned EMUSHORT elog2
[], esqrt2
[];
343 static void endian
PARAMS ((unsigned EMUSHORT
*, long *,
345 static void eclear
PARAMS ((unsigned EMUSHORT
*));
346 static void emov
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
348 static void eabs
PARAMS ((unsigned EMUSHORT
*));
350 static void eneg
PARAMS ((unsigned EMUSHORT
*));
351 static int eisneg
PARAMS ((unsigned EMUSHORT
*));
352 static int eisinf
PARAMS ((unsigned EMUSHORT
*));
353 static int eisnan
PARAMS ((unsigned EMUSHORT
*));
354 static void einfin
PARAMS ((unsigned EMUSHORT
*));
356 static void enan
PARAMS ((unsigned EMUSHORT
*, int));
357 static void einan
PARAMS ((unsigned EMUSHORT
*));
358 static int eiisnan
PARAMS ((unsigned EMUSHORT
*));
359 static int eiisneg
PARAMS ((unsigned EMUSHORT
*));
360 static void make_nan
PARAMS ((unsigned EMUSHORT
*, int, enum machine_mode
));
362 static void emovi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
363 static void emovo
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
364 static void ecleaz
PARAMS ((unsigned EMUSHORT
*));
365 static void ecleazs
PARAMS ((unsigned EMUSHORT
*));
366 static void emovz
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
368 static void eiinfin
PARAMS ((unsigned EMUSHORT
*));
371 static int eiisinf
PARAMS ((unsigned EMUSHORT
*));
373 static int ecmpm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void eshdn1
PARAMS ((unsigned EMUSHORT
*));
375 static void eshup1
PARAMS ((unsigned EMUSHORT
*));
376 static void eshdn8
PARAMS ((unsigned EMUSHORT
*));
377 static void eshup8
PARAMS ((unsigned EMUSHORT
*));
378 static void eshup6
PARAMS ((unsigned EMUSHORT
*));
379 static void eshdn6
PARAMS ((unsigned EMUSHORT
*));
380 static void eaddm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
381 static void esubm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void m16m
PARAMS ((unsigned int, unsigned short *,
384 static int edivm
PARAMS ((unsigned short *, unsigned short *));
385 static int emulm
PARAMS ((unsigned short *, unsigned short *));
386 static void emdnorm
PARAMS ((unsigned EMUSHORT
*, int, int, EMULONG
, int));
387 static void esub
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
388 unsigned EMUSHORT
*));
389 static void eadd
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
390 unsigned EMUSHORT
*));
391 static void eadd1
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
392 unsigned EMUSHORT
*));
393 static void ediv
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
394 unsigned EMUSHORT
*));
395 static void emul
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
396 unsigned EMUSHORT
*));
397 static void e53toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
398 static void e64toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
399 static void e113toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
400 static void e24toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
401 static void etoe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
402 static void toe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
403 static void etoe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
404 static void toe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
405 static void etoe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
406 static void toe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
407 static void etoe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
408 static void toe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
409 static int ecmp
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
411 static void eround
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void ltoe
PARAMS ((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
414 static void ultoe
PARAMS ((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
415 static void eifrac
PARAMS ((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
416 unsigned EMUSHORT
*));
417 static void euifrac
PARAMS ((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
418 unsigned EMUSHORT
*));
419 static int eshift
PARAMS ((unsigned EMUSHORT
*, int));
420 static int enormlz
PARAMS ((unsigned EMUSHORT
*));
422 static void e24toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
423 static void e53toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
424 static void e64toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
425 static void e113toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
427 static void etoasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
428 static void asctoe24
PARAMS ((const char *, unsigned EMUSHORT
*));
429 static void asctoe53
PARAMS ((const char *, unsigned EMUSHORT
*));
430 static void asctoe64
PARAMS ((const char *, unsigned EMUSHORT
*));
431 static void asctoe113
PARAMS ((const char *, unsigned EMUSHORT
*));
432 static void asctoe
PARAMS ((const char *, unsigned EMUSHORT
*));
433 static void asctoeg
PARAMS ((const char *, unsigned EMUSHORT
*, int));
434 static void efloor
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
436 static void efrexp
PARAMS ((unsigned EMUSHORT
*, int *,
437 unsigned EMUSHORT
*));
439 static void eldexp
PARAMS ((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
441 static void eremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
442 unsigned EMUSHORT
*));
444 static void eiremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
445 static void mtherr
PARAMS ((const char *, int));
447 static void dectoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
448 static void etodec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
449 static void todec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
452 static void ibmtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
454 static void etoibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
456 static void toibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
460 static void c4xtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
462 static void etoc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
464 static void toc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
468 static void uditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
469 static void ditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
470 static void etoudi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
471 static void etodi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
472 static void esqrt
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
475 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
476 swapping ends if required, into output array of longs. The
477 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
481 unsigned EMUSHORT e
[];
483 enum machine_mode mode
;
487 if (REAL_WORDS_BIG_ENDIAN
)
492 /* Swap halfwords in the fourth long. */
493 th
= (unsigned long) e
[6] & 0xffff;
494 t
= (unsigned long) e
[7] & 0xffff;
499 /* Swap halfwords in the third long. */
500 th
= (unsigned long) e
[4] & 0xffff;
501 t
= (unsigned long) e
[5] & 0xffff;
504 /* fall into the double case */
507 /* Swap halfwords in the second word. */
508 th
= (unsigned long) e
[2] & 0xffff;
509 t
= (unsigned long) e
[3] & 0xffff;
512 /* fall into the float case */
516 /* Swap halfwords in the first word. */
517 th
= (unsigned long) e
[0] & 0xffff;
518 t
= (unsigned long) e
[1] & 0xffff;
529 /* Pack the output array without swapping. */
534 /* Pack the fourth long. */
535 th
= (unsigned long) e
[7] & 0xffff;
536 t
= (unsigned long) e
[6] & 0xffff;
541 /* Pack the third long.
542 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
544 th
= (unsigned long) e
[5] & 0xffff;
545 t
= (unsigned long) e
[4] & 0xffff;
548 /* fall into the double case */
551 /* Pack the second long */
552 th
= (unsigned long) e
[3] & 0xffff;
553 t
= (unsigned long) e
[2] & 0xffff;
556 /* fall into the float case */
560 /* Pack the first long */
561 th
= (unsigned long) e
[1] & 0xffff;
562 t
= (unsigned long) e
[0] & 0xffff;
574 /* This is the implementation of the REAL_ARITHMETIC macro. */
577 earith (value
, icode
, r1
, r2
)
578 REAL_VALUE_TYPE
*value
;
583 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
589 /* Return NaN input back to the caller. */
592 PUT_REAL (d1
, value
);
597 PUT_REAL (d2
, value
);
601 code
= (enum tree_code
) icode
;
609 esub (d2
, d1
, v
); /* d1 - d2 */
617 #ifndef REAL_INFINITY
618 if (ecmp (d2
, ezero
) == 0)
621 enan (v
, eisneg (d1
) ^ eisneg (d2
));
628 ediv (d2
, d1
, v
); /* d1/d2 */
631 case MIN_EXPR
: /* min (d1,d2) */
632 if (ecmp (d1
, d2
) < 0)
638 case MAX_EXPR
: /* max (d1,d2) */
639 if (ecmp (d1
, d2
) > 0)
652 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
653 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
659 unsigned EMUSHORT f
[NE
], g
[NE
];
675 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
676 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
682 unsigned EMUSHORT f
[NE
], g
[NE
];
684 unsigned HOST_WIDE_INT l
;
698 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
699 string to binary, rounding off as indicated by the machine_mode argument.
700 Then it promotes the rounded value to REAL_VALUE_TYPE. */
707 unsigned EMUSHORT tem
[NE
], e
[NE
];
750 /* Expansion of REAL_NEGATE. */
756 unsigned EMUSHORT e
[NE
];
766 /* Round real toward zero to HOST_WIDE_INT;
767 implements REAL_VALUE_FIX (x). */
773 unsigned EMUSHORT f
[NE
], g
[NE
];
780 warning ("conversion from NaN to int");
788 /* Round real toward zero to unsigned HOST_WIDE_INT
789 implements REAL_VALUE_UNSIGNED_FIX (x).
790 Negative input returns zero. */
792 unsigned HOST_WIDE_INT
796 unsigned EMUSHORT f
[NE
], g
[NE
];
797 unsigned HOST_WIDE_INT l
;
803 warning ("conversion from NaN to unsigned int");
812 /* REAL_VALUE_FROM_INT macro. */
815 ereal_from_int (d
, i
, j
, mode
)
818 enum machine_mode mode
;
820 unsigned EMUSHORT df
[NE
], dg
[NE
];
821 HOST_WIDE_INT low
, high
;
824 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
831 /* complement and add 1 */
838 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
839 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
841 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
846 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
847 Avoid double-rounding errors later by rounding off now from the
848 extra-wide internal format to the requested precision. */
849 switch (GET_MODE_BITSIZE (mode
))
879 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
882 ereal_from_uint (d
, i
, j
, mode
)
884 unsigned HOST_WIDE_INT i
, j
;
885 enum machine_mode mode
;
887 unsigned EMUSHORT df
[NE
], dg
[NE
];
888 unsigned HOST_WIDE_INT low
, high
;
890 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
894 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
900 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
901 Avoid double-rounding errors later by rounding off now from the
902 extra-wide internal format to the requested precision. */
903 switch (GET_MODE_BITSIZE (mode
))
933 /* REAL_VALUE_TO_INT macro. */
936 ereal_to_int (low
, high
, rr
)
937 HOST_WIDE_INT
*low
, *high
;
940 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
947 warning ("conversion from NaN to int");
953 /* convert positive value */
960 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
961 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
962 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
963 emul (df
, dh
, dg
); /* fractional part is the low word */
964 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
967 /* complement and add 1 */
977 /* REAL_VALUE_LDEXP macro. */
984 unsigned EMUSHORT e
[NE
], y
[NE
];
997 /* These routines are conditionally compiled because functions
998 of the same names may be defined in fold-const.c. */
1000 #ifdef REAL_ARITHMETIC
1002 /* Check for infinity in a REAL_VALUE_TYPE. */
1006 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1009 unsigned EMUSHORT e
[NE
];
1012 return (eisinf (e
));
1018 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1022 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1025 unsigned EMUSHORT e
[NE
];
1028 return (eisnan (e
));
1035 /* Check for a negative REAL_VALUE_TYPE number.
1036 This just checks the sign bit, so that -0 counts as negative. */
1042 return ereal_isneg (x
);
1045 /* Expansion of REAL_VALUE_TRUNCATE.
1046 The result is in floating point, rounded to nearest or even. */
1049 real_value_truncate (mode
, arg
)
1050 enum machine_mode mode
;
1051 REAL_VALUE_TYPE arg
;
1053 unsigned EMUSHORT e
[NE
], t
[NE
];
1099 /* If an unsupported type was requested, presume that
1100 the machine files know something useful to do with
1101 the unmodified value. */
1110 /* Try to change R into its exact multiplicative inverse in machine mode
1111 MODE. Return nonzero function value if successful. */
1114 exact_real_inverse (mode
, r
)
1115 enum machine_mode mode
;
1118 unsigned EMUSHORT e
[NE
], einv
[NE
];
1119 REAL_VALUE_TYPE rinv
;
1124 /* Test for input in range. Don't transform IEEE special values. */
1125 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1128 /* Test for a power of 2: all significand bits zero except the MSB.
1129 We are assuming the target has binary (or hex) arithmetic. */
1130 if (e
[NE
- 2] != 0x8000)
1133 for (i
= 0; i
< NE
- 2; i
++)
1139 /* Compute the inverse and truncate it to the required mode. */
1140 ediv (e
, eone
, einv
);
1141 PUT_REAL (einv
, &rinv
);
1142 rinv
= real_value_truncate (mode
, rinv
);
1144 #ifdef CHECK_FLOAT_VALUE
1145 /* This check is not redundant. It may, for example, flush
1146 a supposedly IEEE denormal value to zero. */
1148 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1151 GET_REAL (&rinv
, einv
);
1153 /* Check the bits again, because the truncation might have
1154 generated an arbitrary saturation value on overflow. */
1155 if (einv
[NE
- 2] != 0x8000)
1158 for (i
= 0; i
< NE
- 2; i
++)
1164 /* Fail if the computed inverse is out of range. */
1165 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1168 /* Output the reciprocal and return success flag. */
1172 #endif /* REAL_ARITHMETIC defined */
1174 /* Used for debugging--print the value of R in human-readable format
1183 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1184 fprintf (stderr
, "%s", dstr
);
1188 /* The following routines convert REAL_VALUE_TYPE to the various floating
1189 point formats that are meaningful to supported computers.
1191 The results are returned in 32-bit pieces, each piece stored in a `long'.
1192 This is so they can be printed by statements like
1194 fprintf (file, "%lx, %lx", L[0], L[1]);
1196 that will work on both narrow- and wide-word host computers. */
1198 /* Convert R to a 128-bit long double precision value. The output array L
1199 contains four 32-bit pieces of the result, in the order they would appear
1207 unsigned EMUSHORT e
[NE
];
1211 endian (e
, l
, TFmode
);
1214 /* Convert R to a double extended precision value. The output array L
1215 contains three 32-bit pieces of the result, in the order they would
1216 appear in memory. */
1223 unsigned EMUSHORT e
[NE
];
1227 endian (e
, l
, XFmode
);
1230 /* Convert R to a double precision value. The output array L contains two
1231 32-bit pieces of the result, in the order they would appear in memory. */
1238 unsigned EMUSHORT e
[NE
];
1242 endian (e
, l
, DFmode
);
1245 /* Convert R to a single precision float value stored in the least-significant
1246 bits of a `long'. */
1252 unsigned EMUSHORT e
[NE
];
1257 endian (e
, &l
, SFmode
);
1261 /* Convert X to a decimal ASCII string S for output to an assembly
1262 language file. Note, there is no standard way to spell infinity or
1263 a NaN, so these values may require special treatment in the tm.h
1267 ereal_to_decimal (x
, s
)
1271 unsigned EMUSHORT e
[NE
];
1277 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1278 or -2 if either is a NaN. */
1282 REAL_VALUE_TYPE x
, y
;
1284 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1288 return (ecmp (ex
, ey
));
1291 /* Return 1 if the sign bit of X is set, else return 0. */
1297 unsigned EMUSHORT ex
[NE
];
1300 return (eisneg (ex
));
1303 /* End of REAL_ARITHMETIC interface */
1306 Extended precision IEEE binary floating point arithmetic routines
1308 Numbers are stored in C language as arrays of 16-bit unsigned
1309 short integers. The arguments of the routines are pointers to
1312 External e type data structure, similar to Intel 8087 chip
1313 temporary real format but possibly with a larger significand:
1315 NE-1 significand words (least significant word first,
1316 most significant bit is normally set)
1317 exponent (value = EXONE for 1.0,
1318 top bit is the sign)
1321 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1323 ei[0] sign word (0 for positive, 0xffff for negative)
1324 ei[1] biased exponent (value = EXONE for the number 1.0)
1325 ei[2] high guard word (always zero after normalization)
1327 to ei[NI-2] significand (NI-4 significand words,
1328 most significant word first,
1329 most significant bit is set)
1330 ei[NI-1] low guard word (0x8000 bit is rounding place)
1334 Routines for external format e-type numbers
1336 asctoe (string, e) ASCII string to extended double e type
1337 asctoe64 (string, &d) ASCII string to long double
1338 asctoe53 (string, &d) ASCII string to double
1339 asctoe24 (string, &f) ASCII string to single
1340 asctoeg (string, e, prec) ASCII string to specified precision
1341 e24toe (&f, e) IEEE single precision to e type
1342 e53toe (&d, e) IEEE double precision to e type
1343 e64toe (&d, e) IEEE long double precision to e type
1344 e113toe (&d, e) 128-bit long double precision to e type
1346 eabs (e) absolute value
1348 eadd (a, b, c) c = b + a
1350 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1351 -1 if a < b, -2 if either a or b is a NaN.
1352 ediv (a, b, c) c = b / a
1353 efloor (a, b) truncate to integer, toward -infinity
1354 efrexp (a, exp, s) extract exponent and significand
1355 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1356 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1357 einfin (e) set e to infinity, leaving its sign alone
1358 eldexp (a, n, b) multiply by 2**n
1360 emul (a, b, c) c = b * a
1363 eround (a, b) b = nearest integer value to a
1365 esub (a, b, c) c = b - a
1367 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1368 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1369 e64toasc (&d, str, n) 80-bit long double to ASCII string
1370 e113toasc (&d, str, n) 128-bit long double to ASCII string
1372 etoasc (e, str, n) e to ASCII string, n digits after decimal
1373 etoe24 (e, &f) convert e type to IEEE single precision
1374 etoe53 (e, &d) convert e type to IEEE double precision
1375 etoe64 (e, &d) convert e type to IEEE long double precision
1376 ltoe (&l, e) HOST_WIDE_INT to e type
1377 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1378 eisneg (e) 1 if sign bit of e != 0, else 0
1379 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1380 or is infinite (IEEE)
1381 eisnan (e) 1 if e is a NaN
1384 Routines for internal format exploded e-type numbers
1386 eaddm (ai, bi) add significands, bi = bi + ai
1388 ecleazs (ei) set ei = 0 but leave its sign alone
1389 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1390 edivm (ai, bi) divide significands, bi = bi / ai
1391 emdnorm (ai,l,s,exp) normalize and round off
1392 emovi (a, ai) convert external a to internal ai
1393 emovo (ai, a) convert internal ai to external a
1394 emovz (ai, bi) bi = ai, low guard word of bi = 0
1395 emulm (ai, bi) multiply significands, bi = bi * ai
1396 enormlz (ei) left-justify the significand
1397 eshdn1 (ai) shift significand and guards down 1 bit
1398 eshdn8 (ai) shift down 8 bits
1399 eshdn6 (ai) shift down 16 bits
1400 eshift (ai, n) shift ai n bits up (or down if n < 0)
1401 eshup1 (ai) shift significand and guards up 1 bit
1402 eshup8 (ai) shift up 8 bits
1403 eshup6 (ai) shift up 16 bits
1404 esubm (ai, bi) subtract significands, bi = bi - ai
1405 eiisinf (ai) 1 if infinite
1406 eiisnan (ai) 1 if a NaN
1407 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1408 einan (ai) set ai = NaN
1410 eiinfin (ai) set ai = infinity
1413 The result is always normalized and rounded to NI-4 word precision
1414 after each arithmetic operation.
1416 Exception flags are NOT fully supported.
1418 Signaling NaN's are NOT supported; they are treated the same
1421 Define INFINITY for support of infinity; otherwise a
1422 saturation arithmetic is implemented.
1424 Define NANS for support of Not-a-Number items; otherwise the
1425 arithmetic will never produce a NaN output, and might be confused
1427 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1428 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1429 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1432 Denormals are always supported here where appropriate (e.g., not
1433 for conversion to DEC numbers). */
1435 /* Definitions for error codes that are passed to the common error handling
1438 For Digital Equipment PDP-11 and VAX computers, certain
1439 IBM systems, and others that use numbers with a 56-bit
1440 significand, the symbol DEC should be defined. In this
1441 mode, most floating point constants are given as arrays
1442 of octal integers to eliminate decimal to binary conversion
1443 errors that might be introduced by the compiler.
1445 For computers, such as IBM PC, that follow the IEEE
1446 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1447 Std 754-1985), the symbol IEEE should be defined.
1448 These numbers have 53-bit significands. In this mode, constants
1449 are provided as arrays of hexadecimal 16 bit integers.
1450 The endian-ness of generated values is controlled by
1451 REAL_WORDS_BIG_ENDIAN.
1453 To accommodate other types of computer arithmetic, all
1454 constants are also provided in a normal decimal radix
1455 which one can hope are correctly converted to a suitable
1456 format by the available C language compiler. To invoke
1457 this mode, the symbol UNK is defined.
1459 An important difference among these modes is a predefined
1460 set of machine arithmetic constants for each. The numbers
1461 MACHEP (the machine roundoff error), MAXNUM (largest number
1462 represented), and several other parameters are preset by
1463 the configuration symbol. Check the file const.c to
1464 ensure that these values are correct for your computer.
1466 For ANSI C compatibility, define ANSIC equal to 1. Currently
1467 this affects only the atan2 function and others that use it. */
1469 /* Constant definitions for math error conditions. */
1471 #define DOMAIN 1 /* argument domain error */
1472 #define SING 2 /* argument singularity */
1473 #define OVERFLOW 3 /* overflow range error */
1474 #define UNDERFLOW 4 /* underflow range error */
1475 #define TLOSS 5 /* total loss of precision */
1476 #define PLOSS 6 /* partial loss of precision */
1477 #define INVALID 7 /* NaN-producing operation */
1479 /* e type constants used by high precision check routines */
1481 #if LONG_DOUBLE_TYPE_SIZE == 128
1483 unsigned EMUSHORT ezero
[NE
] =
1484 {0x0000, 0x0000, 0x0000, 0x0000,
1485 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1486 extern unsigned EMUSHORT ezero
[];
1489 unsigned EMUSHORT ehalf
[NE
] =
1490 {0x0000, 0x0000, 0x0000, 0x0000,
1491 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1492 extern unsigned EMUSHORT ehalf
[];
1495 unsigned EMUSHORT eone
[NE
] =
1496 {0x0000, 0x0000, 0x0000, 0x0000,
1497 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1498 extern unsigned EMUSHORT eone
[];
1501 unsigned EMUSHORT etwo
[NE
] =
1502 {0x0000, 0x0000, 0x0000, 0x0000,
1503 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1504 extern unsigned EMUSHORT etwo
[];
1507 unsigned EMUSHORT e32
[NE
] =
1508 {0x0000, 0x0000, 0x0000, 0x0000,
1509 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1510 extern unsigned EMUSHORT e32
[];
1512 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1513 unsigned EMUSHORT elog2
[NE
] =
1514 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1515 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1516 extern unsigned EMUSHORT elog2
[];
1518 /* 1.41421356237309504880168872420969807856967187537695E0 */
1519 unsigned EMUSHORT esqrt2
[NE
] =
1520 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1521 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1522 extern unsigned EMUSHORT esqrt2
[];
1524 /* 3.14159265358979323846264338327950288419716939937511E0 */
1525 unsigned EMUSHORT epi
[NE
] =
1526 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1527 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1528 extern unsigned EMUSHORT epi
[];
1531 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1532 unsigned EMUSHORT ezero
[NE
] =
1533 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1534 unsigned EMUSHORT ehalf
[NE
] =
1535 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1536 unsigned EMUSHORT eone
[NE
] =
1537 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1538 unsigned EMUSHORT etwo
[NE
] =
1539 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1540 unsigned EMUSHORT e32
[NE
] =
1541 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1542 unsigned EMUSHORT elog2
[NE
] =
1543 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1544 unsigned EMUSHORT esqrt2
[NE
] =
1545 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1546 unsigned EMUSHORT epi
[NE
] =
1547 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1550 /* Control register for rounding precision.
1551 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1556 /* Clear out entire e-type number X. */
1560 register unsigned EMUSHORT
*x
;
1564 for (i
= 0; i
< NE
; i
++)
1568 /* Move e-type number from A to B. */
1572 register unsigned EMUSHORT
*a
, *b
;
1576 for (i
= 0; i
< NE
; i
++)
1582 /* Absolute value of e-type X. */
1586 unsigned EMUSHORT x
[];
1588 /* sign is top bit of last word of external format */
1589 x
[NE
- 1] &= 0x7fff;
1593 /* Negate the e-type number X. */
1597 unsigned EMUSHORT x
[];
1600 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1603 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1607 unsigned EMUSHORT x
[];
1610 if (x
[NE
- 1] & 0x8000)
1616 /* Return 1 if e-type number X is infinity, else return zero. */
1620 unsigned EMUSHORT x
[];
1627 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1633 /* Check if e-type number is not a number. The bit pattern is one that we
1634 defined, so we know for sure how to detect it. */
1638 unsigned EMUSHORT x
[] ATTRIBUTE_UNUSED
;
1643 /* NaN has maximum exponent */
1644 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1646 /* ... and non-zero significand field. */
1647 for (i
= 0; i
< NE
- 1; i
++)
1657 /* Fill e-type number X with infinity pattern (IEEE)
1658 or largest possible number (non-IEEE). */
1662 register unsigned EMUSHORT
*x
;
1667 for (i
= 0; i
< NE
- 1; i
++)
1671 for (i
= 0; i
< NE
- 1; i
++)
1699 /* Output an e-type NaN.
1700 This generates Intel's quiet NaN pattern for extended real.
1701 The exponent is 7fff, the leading mantissa word is c000. */
1706 register unsigned EMUSHORT
*x
;
1711 for (i
= 0; i
< NE
- 2; i
++)
1714 *x
= (sign
<< 15) | 0x7fff;
1718 /* Move in an e-type number A, converting it to exploded e-type B. */
1722 unsigned EMUSHORT
*a
, *b
;
1724 register unsigned EMUSHORT
*p
, *q
;
1728 p
= a
+ (NE
- 1); /* point to last word of external number */
1729 /* get the sign bit */
1734 /* get the exponent */
1736 *q
++ &= 0x7fff; /* delete the sign bit */
1738 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1744 for (i
= 3; i
< NI
; i
++)
1750 for (i
= 2; i
< NI
; i
++)
1756 /* clear high guard word */
1758 /* move in the significand */
1759 for (i
= 0; i
< NE
- 1; i
++)
1761 /* clear low guard word */
1765 /* Move out exploded e-type number A, converting it to e type B. */
1769 unsigned EMUSHORT
*a
, *b
;
1771 register unsigned EMUSHORT
*p
, *q
;
1772 unsigned EMUSHORT i
;
1776 q
= b
+ (NE
- 1); /* point to output exponent */
1777 /* combine sign and exponent */
1780 *q
-- = *p
++ | 0x8000;
1784 if (*(p
- 1) == 0x7fff)
1789 enan (b
, eiisneg (a
));
1797 /* skip over guard word */
1799 /* move the significand */
1800 for (j
= 0; j
< NE
- 1; j
++)
1804 /* Clear out exploded e-type number XI. */
1808 register unsigned EMUSHORT
*xi
;
1812 for (i
= 0; i
< NI
; i
++)
1816 /* Clear out exploded e-type XI, but don't touch the sign. */
1820 register unsigned EMUSHORT
*xi
;
1825 for (i
= 0; i
< NI
- 1; i
++)
1829 /* Move exploded e-type number from A to B. */
1833 register unsigned EMUSHORT
*a
, *b
;
1837 for (i
= 0; i
< NI
- 1; i
++)
1839 /* clear low guard word */
1843 /* Generate exploded e-type NaN.
1844 The explicit pattern for this is maximum exponent and
1845 top two significant bits set. */
1850 unsigned EMUSHORT x
[];
1859 /* Return nonzero if exploded e-type X is a NaN. */
1864 unsigned EMUSHORT x
[];
1868 if ((x
[E
] & 0x7fff) == 0x7fff)
1870 for (i
= M
+ 1; i
< NI
; i
++)
1880 /* Return nonzero if sign of exploded e-type X is nonzero. */
1885 unsigned EMUSHORT x
[];
1893 /* Fill exploded e-type X with infinity pattern.
1894 This has maximum exponent and significand all zeros. */
1898 unsigned EMUSHORT x
[];
1906 /* Return nonzero if exploded e-type X is infinite. */
1911 unsigned EMUSHORT x
[];
1918 if ((x
[E
] & 0x7fff) == 0x7fff)
1922 #endif /* INFINITY */
1924 /* Compare significands of numbers in internal exploded e-type format.
1925 Guard words are included in the comparison.
1933 register unsigned EMUSHORT
*a
, *b
;
1937 a
+= M
; /* skip up to significand area */
1939 for (i
= M
; i
< NI
; i
++)
1947 if (*(--a
) > *(--b
))
1953 /* Shift significand of exploded e-type X down by 1 bit. */
1957 register unsigned EMUSHORT
*x
;
1959 register unsigned EMUSHORT bits
;
1962 x
+= M
; /* point to significand area */
1965 for (i
= M
; i
< NI
; i
++)
1977 /* Shift significand of exploded e-type X up by 1 bit. */
1981 register unsigned EMUSHORT
*x
;
1983 register unsigned EMUSHORT bits
;
1989 for (i
= M
; i
< NI
; i
++)
2002 /* Shift significand of exploded e-type X down by 8 bits. */
2006 register unsigned EMUSHORT
*x
;
2008 register unsigned EMUSHORT newbyt
, oldbyt
;
2013 for (i
= M
; i
< NI
; i
++)
2023 /* Shift significand of exploded e-type X up by 8 bits. */
2027 register unsigned EMUSHORT
*x
;
2030 register unsigned EMUSHORT newbyt
, oldbyt
;
2035 for (i
= M
; i
< NI
; i
++)
2045 /* Shift significand of exploded e-type X up by 16 bits. */
2049 register unsigned EMUSHORT
*x
;
2052 register unsigned EMUSHORT
*p
;
2057 for (i
= M
; i
< NI
- 1; i
++)
2063 /* Shift significand of exploded e-type X down by 16 bits. */
2067 register unsigned EMUSHORT
*x
;
2070 register unsigned EMUSHORT
*p
;
2075 for (i
= M
; i
< NI
- 1; i
++)
2081 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2085 unsigned EMUSHORT
*x
, *y
;
2087 register unsigned EMULONG a
;
2094 for (i
= M
; i
< NI
; i
++)
2096 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2101 *y
= (unsigned EMUSHORT
) a
;
2107 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2111 unsigned EMUSHORT
*x
, *y
;
2120 for (i
= M
; i
< NI
; i
++)
2122 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2127 *y
= (unsigned EMUSHORT
) a
;
2134 static unsigned EMUSHORT equot
[NI
];
2138 /* Radix 2 shift-and-add versions of multiply and divide */
2141 /* Divide significands */
2145 unsigned EMUSHORT den
[], num
[];
2148 register unsigned EMUSHORT
*p
, *q
;
2149 unsigned EMUSHORT j
;
2155 for (i
= M
; i
< NI
; i
++)
2160 /* Use faster compare and subtraction if denominator has only 15 bits of
2166 for (i
= M
+ 3; i
< NI
; i
++)
2171 if ((den
[M
+ 1] & 1) != 0)
2179 for (i
= 0; i
< NBITS
+ 2; i
++)
2197 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2198 bit + 1 roundoff bit. */
2203 for (i
= 0; i
< NBITS
+ 2; i
++)
2205 if (ecmpm (den
, num
) <= 0)
2208 j
= 1; /* quotient bit = 1 */
2222 /* test for nonzero remainder after roundoff bit */
2225 for (i
= M
; i
< NI
; i
++)
2233 for (i
= 0; i
< NI
; i
++)
2239 /* Multiply significands */
2243 unsigned EMUSHORT a
[], b
[];
2245 unsigned EMUSHORT
*p
, *q
;
2250 for (i
= M
; i
< NI
; i
++)
2255 while (*p
== 0) /* significand is not supposed to be zero */
2260 if ((*p
& 0xff) == 0)
2268 for (i
= 0; i
< k
; i
++)
2272 /* remember if there were any nonzero bits shifted out */
2279 for (i
= 0; i
< NI
; i
++)
2282 /* return flag for lost nonzero bits */
2288 /* Radix 65536 versions of multiply and divide. */
2290 /* Multiply significand of e-type number B
2291 by 16-bit quantity A, return e-type result to C. */
2296 unsigned EMUSHORT b
[], c
[];
2298 register unsigned EMUSHORT
*pp
;
2299 register unsigned EMULONG carry
;
2300 unsigned EMUSHORT
*ps
;
2301 unsigned EMUSHORT p
[NI
];
2302 unsigned EMULONG aa
, m
;
2311 for (i
=M
+1; i
<NI
; i
++)
2321 m
= (unsigned EMULONG
) aa
* *ps
--;
2322 carry
= (m
& 0xffff) + *pp
;
2323 *pp
-- = (unsigned EMUSHORT
)carry
;
2324 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2325 *pp
= (unsigned EMUSHORT
)carry
;
2326 *(pp
-1) = carry
>> 16;
2329 for (i
=M
; i
<NI
; i
++)
2333 /* Divide significands of exploded e-types NUM / DEN. Neither the
2334 numerator NUM nor the denominator DEN is permitted to have its high guard
2339 unsigned EMUSHORT den
[], num
[];
2342 register unsigned EMUSHORT
*p
;
2343 unsigned EMULONG tnum
;
2344 unsigned EMUSHORT j
, tdenm
, tquot
;
2345 unsigned EMUSHORT tprod
[NI
+1];
2351 for (i
=M
; i
<NI
; i
++)
2357 for (i
=M
; i
<NI
; i
++)
2359 /* Find trial quotient digit (the radix is 65536). */
2360 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2362 /* Do not execute the divide instruction if it will overflow. */
2363 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2366 tquot
= tnum
/ tdenm
;
2367 /* Multiply denominator by trial quotient digit. */
2368 m16m ((unsigned int)tquot
, den
, tprod
);
2369 /* The quotient digit may have been overestimated. */
2370 if (ecmpm (tprod
, num
) > 0)
2374 if (ecmpm (tprod
, num
) > 0)
2384 /* test for nonzero remainder after roundoff bit */
2387 for (i
=M
; i
<NI
; i
++)
2394 for (i
=0; i
<NI
; i
++)
2400 /* Multiply significands of exploded e-type A and B, result in B. */
2404 unsigned EMUSHORT a
[], b
[];
2406 unsigned EMUSHORT
*p
, *q
;
2407 unsigned EMUSHORT pprod
[NI
];
2408 unsigned EMUSHORT j
;
2413 for (i
=M
; i
<NI
; i
++)
2419 for (i
=M
+1; i
<NI
; i
++)
2427 m16m ((unsigned int) *p
--, b
, pprod
);
2428 eaddm(pprod
, equot
);
2434 for (i
=0; i
<NI
; i
++)
2437 /* return flag for lost nonzero bits */
2443 /* Normalize and round off.
2445 The internal format number to be rounded is S.
2446 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2448 Input SUBFLG indicates whether the number was obtained
2449 by a subtraction operation. In that case if LOST is nonzero
2450 then the number is slightly smaller than indicated.
2452 Input EXP is the biased exponent, which may be negative.
2453 the exponent field of S is ignored but is replaced by
2454 EXP as adjusted by normalization and rounding.
2456 Input RCNTRL is the rounding control. If it is nonzero, the
2457 returned value will be rounded to RNDPRC bits.
2459 For future reference: In order for emdnorm to round off denormal
2460 significands at the right point, the input exponent must be
2461 adjusted to be the actual value it would have after conversion to
2462 the final floating point type. This adjustment has been
2463 implemented for all type conversions (etoe53, etc.) and decimal
2464 conversions, but not for the arithmetic functions (eadd, etc.).
2465 Data types having standard 15-bit exponents are not affected by
2466 this, but SFmode and DFmode are affected. For example, ediv with
2467 rndprc = 24 will not round correctly to 24-bit precision if the
2468 result is denormal. */
2470 static int rlast
= -1;
2472 static unsigned EMUSHORT rmsk
= 0;
2473 static unsigned EMUSHORT rmbit
= 0;
2474 static unsigned EMUSHORT rebit
= 0;
2476 static unsigned EMUSHORT rbit
[NI
];
2479 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2480 unsigned EMUSHORT s
[];
2487 unsigned EMUSHORT r
;
2492 /* a blank significand could mean either zero or infinity. */
2505 if ((j
> NBITS
) && (exp
< 32767))
2513 if (exp
> (EMULONG
) (-NBITS
- 1))
2526 /* Round off, unless told not to by rcntrl. */
2529 /* Set up rounding parameters if the control register changed. */
2530 if (rndprc
!= rlast
)
2537 rw
= NI
- 1; /* low guard word */
2560 /* For DEC or IBM arithmetic */
2577 /* For C4x arithmetic */
2598 /* Shift down 1 temporarily if the data structure has an implied
2599 most significant bit and the number is denormal.
2600 Intel long double denormals also lose one bit of precision. */
2601 if ((exp
<= 0) && (rndprc
!= NBITS
)
2602 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2604 lost
|= s
[NI
- 1] & 1;
2607 /* Clear out all bits below the rounding bit,
2608 remembering in r if any were nonzero. */
2622 if ((r
& rmbit
) != 0)
2628 { /* round to even */
2629 if ((s
[re
] & rebit
) == 0)
2642 /* Undo the temporary shift for denormal values. */
2643 if ((exp
<= 0) && (rndprc
!= NBITS
)
2644 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2649 { /* overflow on roundoff */
2662 for (i
= 2; i
< NI
- 1; i
++)
2665 warning ("floating point overflow");
2669 for (i
= M
+ 1; i
< NI
- 1; i
++)
2672 if ((rndprc
< 64) || (rndprc
== 113))
2687 s
[1] = (unsigned EMUSHORT
) exp
;
2690 /* Subtract. C = B - A, all e type numbers. */
2692 static int subflg
= 0;
2696 unsigned EMUSHORT
*a
, *b
, *c
;
2710 /* Infinity minus infinity is a NaN.
2711 Test for subtracting infinities of the same sign. */
2712 if (eisinf (a
) && eisinf (b
)
2713 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2715 mtherr ("esub", INVALID
);
2724 /* Add. C = A + B, all e type. */
2728 unsigned EMUSHORT
*a
, *b
, *c
;
2732 /* NaN plus anything is a NaN. */
2743 /* Infinity minus infinity is a NaN.
2744 Test for adding infinities of opposite signs. */
2745 if (eisinf (a
) && eisinf (b
)
2746 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2748 mtherr ("esub", INVALID
);
2757 /* Arithmetic common to both addition and subtraction. */
2761 unsigned EMUSHORT
*a
, *b
, *c
;
2763 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2765 EMULONG lt
, lta
, ltb
;
2786 /* compare exponents */
2791 { /* put the larger number in bi */
2801 if (lt
< (EMULONG
) (-NBITS
- 1))
2802 goto done
; /* answer same as larger addend */
2804 lost
= eshift (ai
, k
); /* shift the smaller number down */
2808 /* exponents were the same, so must compare significands */
2811 { /* the numbers are identical in magnitude */
2812 /* if different signs, result is zero */
2818 /* if same sign, result is double */
2819 /* double denormalized tiny number */
2820 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2825 /* add 1 to exponent unless both are zero! */
2826 for (j
= 1; j
< NI
- 1; j
++)
2842 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2846 { /* put the larger number in bi */
2862 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2868 /* Divide: C = B/A, all e type. */
2872 unsigned EMUSHORT
*a
, *b
, *c
;
2874 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2876 EMULONG lt
, lta
, ltb
;
2878 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2879 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2880 sign
= eisneg(a
) ^ eisneg(b
);
2883 /* Return any NaN input. */
2894 /* Zero over zero, or infinity over infinity, is a NaN. */
2895 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2896 || (eisinf (a
) && eisinf (b
)))
2898 mtherr ("ediv", INVALID
);
2903 /* Infinity over anything else is infinity. */
2910 /* Anything else over infinity is zero. */
2922 { /* See if numerator is zero. */
2923 for (i
= 1; i
< NI
- 1; i
++)
2927 ltb
-= enormlz (bi
);
2937 { /* possible divide by zero */
2938 for (i
= 1; i
< NI
- 1; i
++)
2942 lta
-= enormlz (ai
);
2946 /* Divide by zero is not an invalid operation.
2947 It is a divide-by-zero operation! */
2949 mtherr ("ediv", SING
);
2955 /* calculate exponent */
2956 lt
= ltb
- lta
+ EXONE
;
2957 emdnorm (bi
, i
, 0, lt
, 64);
2964 && (ecmp (c
, ezero
) != 0)
2967 *(c
+(NE
-1)) |= 0x8000;
2969 *(c
+(NE
-1)) &= ~0x8000;
2972 /* Multiply e-types A and B, return e-type product C. */
2976 unsigned EMUSHORT
*a
, *b
, *c
;
2978 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2980 EMULONG lt
, lta
, ltb
;
2982 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2983 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2984 sign
= eisneg(a
) ^ eisneg(b
);
2987 /* NaN times anything is the same NaN. */
2998 /* Zero times infinity is a NaN. */
2999 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3000 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3002 mtherr ("emul", INVALID
);
3007 /* Infinity times anything else is infinity. */
3009 if (eisinf (a
) || eisinf (b
))
3021 for (i
= 1; i
< NI
- 1; i
++)
3025 lta
-= enormlz (ai
);
3036 for (i
= 1; i
< NI
- 1; i
++)
3040 ltb
-= enormlz (bi
);
3049 /* Multiply significands */
3051 /* calculate exponent */
3052 lt
= lta
+ ltb
- (EXONE
- 1);
3053 emdnorm (bi
, j
, 0, lt
, 64);
3060 && (ecmp (c
, ezero
) != 0)
3063 *(c
+(NE
-1)) |= 0x8000;
3065 *(c
+(NE
-1)) &= ~0x8000;
3068 /* Convert double precision PE to e-type Y. */
3072 unsigned EMUSHORT
*pe
, *y
;
3081 ibmtoe (pe
, y
, DFmode
);
3086 c4xtoe (pe
, y
, HFmode
);
3089 register unsigned EMUSHORT r
;
3090 register unsigned EMUSHORT
*e
, *p
;
3091 unsigned EMUSHORT yy
[NI
];
3095 denorm
= 0; /* flag if denormalized number */
3097 if (! REAL_WORDS_BIG_ENDIAN
)
3103 yy
[M
] = (r
& 0x0f) | 0x10;
3104 r
&= ~0x800f; /* strip sign and 4 significand bits */
3109 if (! REAL_WORDS_BIG_ENDIAN
)
3111 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3112 || (pe
[1] != 0) || (pe
[0] != 0))
3114 enan (y
, yy
[0] != 0);
3120 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3121 || (pe
[2] != 0) || (pe
[3] != 0))
3123 enan (y
, yy
[0] != 0);
3134 #endif /* INFINITY */
3136 /* If zero exponent, then the significand is denormalized.
3137 So take back the understood high significand bit. */
3148 if (! REAL_WORDS_BIG_ENDIAN
)
3165 /* If zero exponent, then normalize the significand. */
3166 if ((k
= enormlz (yy
)) > NBITS
)
3169 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3172 #endif /* not C4X */
3173 #endif /* not IBM */
3174 #endif /* not DEC */
3177 /* Convert double extended precision float PE to e type Y. */
3181 unsigned EMUSHORT
*pe
, *y
;
3183 unsigned EMUSHORT yy
[NI
];
3184 unsigned EMUSHORT
*e
, *p
, *q
;
3189 for (i
= 0; i
< NE
- 5; i
++)
3191 /* This precision is not ordinarily supported on DEC or IBM. */
3193 for (i
= 0; i
< 5; i
++)
3197 p
= &yy
[0] + (NE
- 1);
3200 for (i
= 0; i
< 5; i
++)
3204 if (! REAL_WORDS_BIG_ENDIAN
)
3206 for (i
= 0; i
< 5; i
++)
3209 /* For denormal long double Intel format, shift significand up one
3210 -- but only if the top significand bit is zero. A top bit of 1
3211 is "pseudodenormal" when the exponent is zero. */
3212 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3214 unsigned EMUSHORT temp
[NI
];
3224 p
= &yy
[0] + (NE
- 1);
3225 #ifdef ARM_EXTENDED_IEEE_FORMAT
3226 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3227 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3233 for (i
= 0; i
< 4; i
++)
3238 /* Point to the exponent field and check max exponent cases. */
3240 if ((*p
& 0x7fff) == 0x7fff)
3243 if (! REAL_WORDS_BIG_ENDIAN
)
3245 for (i
= 0; i
< 4; i
++)
3247 if ((i
!= 3 && pe
[i
] != 0)
3248 /* Anything but 0x8000 here, including 0, is a NaN. */
3249 || (i
== 3 && pe
[i
] != 0x8000))
3251 enan (y
, (*p
& 0x8000) != 0);
3258 #ifdef ARM_EXTENDED_IEEE_FORMAT
3259 for (i
= 2; i
<= 5; i
++)
3263 enan (y
, (*p
& 0x8000) != 0);
3268 /* In Motorola extended precision format, the most significant
3269 bit of an infinity mantissa could be either 1 or 0. It is
3270 the lower order bits that tell whether the value is a NaN. */
3271 if ((pe
[2] & 0x7fff) != 0)
3274 for (i
= 3; i
<= 5; i
++)
3279 enan (y
, (*p
& 0x8000) != 0);
3283 #endif /* not ARM */
3292 #endif /* INFINITY */
3295 for (i
= 0; i
< NE
; i
++)
3299 /* Convert 128-bit long double precision float PE to e type Y. */
3303 unsigned EMUSHORT
*pe
, *y
;
3305 register unsigned EMUSHORT r
;
3306 unsigned EMUSHORT
*e
, *p
;
3307 unsigned EMUSHORT yy
[NI
];
3314 if (! REAL_WORDS_BIG_ENDIAN
)
3326 if (! REAL_WORDS_BIG_ENDIAN
)
3328 for (i
= 0; i
< 7; i
++)
3332 enan (y
, yy
[0] != 0);
3339 for (i
= 1; i
< 8; i
++)
3343 enan (y
, yy
[0] != 0);
3355 #endif /* INFINITY */
3359 if (! REAL_WORDS_BIG_ENDIAN
)
3361 for (i
= 0; i
< 7; i
++)
3367 for (i
= 0; i
< 7; i
++)
3371 /* If denormal, remove the implied bit; else shift down 1. */
3384 /* Convert single precision float PE to e type Y. */
3388 unsigned EMUSHORT
*pe
, *y
;
3392 ibmtoe (pe
, y
, SFmode
);
3398 c4xtoe (pe
, y
, QFmode
);
3402 register unsigned EMUSHORT r
;
3403 register unsigned EMUSHORT
*e
, *p
;
3404 unsigned EMUSHORT yy
[NI
];
3408 denorm
= 0; /* flag if denormalized number */
3411 if (! REAL_WORDS_BIG_ENDIAN
)
3421 yy
[M
] = (r
& 0x7f) | 0200;
3422 r
&= ~0x807f; /* strip sign and 7 significand bits */
3427 if (REAL_WORDS_BIG_ENDIAN
)
3429 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3431 enan (y
, yy
[0] != 0);
3437 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3439 enan (y
, yy
[0] != 0);
3450 #endif /* INFINITY */
3452 /* If zero exponent, then the significand is denormalized.
3453 So take back the understood high significand bit. */
3466 if (! REAL_WORDS_BIG_ENDIAN
)
3476 { /* if zero exponent, then normalize the significand */
3477 if ((k
= enormlz (yy
)) > NBITS
)
3480 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3483 #endif /* not C4X */
3484 #endif /* not IBM */
3487 /* Convert e-type X to IEEE 128-bit long double format E. */
3491 unsigned EMUSHORT
*x
, *e
;
3493 unsigned EMUSHORT xi
[NI
];
3500 make_nan (e
, eisneg (x
), TFmode
);
3505 exp
= (EMULONG
) xi
[E
];
3510 /* round off to nearest or even */
3513 emdnorm (xi
, 0, 0, exp
, 64);
3521 /* Convert exploded e-type X, that has already been rounded to
3522 113-bit precision, to IEEE 128-bit long double format Y. */
3526 unsigned EMUSHORT
*a
, *b
;
3528 register unsigned EMUSHORT
*p
, *q
;
3529 unsigned EMUSHORT i
;
3534 make_nan (b
, eiisneg (a
), TFmode
);
3539 if (REAL_WORDS_BIG_ENDIAN
)
3542 q
= b
+ 7; /* point to output exponent */
3544 /* If not denormal, delete the implied bit. */
3549 /* combine sign and exponent */
3551 if (REAL_WORDS_BIG_ENDIAN
)
3554 *q
++ = *p
++ | 0x8000;
3561 *q
-- = *p
++ | 0x8000;
3565 /* skip over guard word */
3567 /* move the significand */
3568 if (REAL_WORDS_BIG_ENDIAN
)
3570 for (i
= 0; i
< 7; i
++)
3575 for (i
= 0; i
< 7; i
++)
3580 /* Convert e-type X to IEEE double extended format E. */
3584 unsigned EMUSHORT
*x
, *e
;
3586 unsigned EMUSHORT xi
[NI
];
3593 make_nan (e
, eisneg (x
), XFmode
);
3598 /* adjust exponent for offset */
3599 exp
= (EMULONG
) xi
[E
];
3604 /* round off to nearest or even */
3607 emdnorm (xi
, 0, 0, exp
, 64);
3615 /* Convert exploded e-type X, that has already been rounded to
3616 64-bit precision, to IEEE double extended format Y. */
3620 unsigned EMUSHORT
*a
, *b
;
3622 register unsigned EMUSHORT
*p
, *q
;
3623 unsigned EMUSHORT i
;
3628 make_nan (b
, eiisneg (a
), XFmode
);
3632 /* Shift denormal long double Intel format significand down one bit. */
3633 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3643 if (REAL_WORDS_BIG_ENDIAN
)
3647 q
= b
+ 4; /* point to output exponent */
3648 #if LONG_DOUBLE_TYPE_SIZE == 96
3649 /* Clear the last two bytes of 12-byte Intel format */
3655 /* combine sign and exponent */
3659 *q
++ = *p
++ | 0x8000;
3666 *q
-- = *p
++ | 0x8000;
3671 if (REAL_WORDS_BIG_ENDIAN
)
3673 #ifdef ARM_EXTENDED_IEEE_FORMAT
3674 /* The exponent is in the lowest 15 bits of the first word. */
3675 *q
++ = i
? 0x8000 : 0;
3679 *q
++ = *p
++ | 0x8000;
3688 *q
-- = *p
++ | 0x8000;
3693 /* skip over guard word */
3695 /* move the significand */
3697 for (i
= 0; i
< 4; i
++)
3701 for (i
= 0; i
< 4; i
++)
3705 if (REAL_WORDS_BIG_ENDIAN
)
3707 for (i
= 0; i
< 4; i
++)
3715 /* Intel long double infinity significand. */
3723 for (i
= 0; i
< 4; i
++)
3729 /* e type to double precision. */
3732 /* Convert e-type X to DEC-format double E. */
3736 unsigned EMUSHORT
*x
, *e
;
3738 etodec (x
, e
); /* see etodec.c */
3741 /* Convert exploded e-type X, that has already been rounded to
3742 56-bit double precision, to DEC double Y. */
3746 unsigned EMUSHORT
*x
, *y
;
3753 /* Convert e-type X to IBM 370-format double E. */
3757 unsigned EMUSHORT
*x
, *e
;
3759 etoibm (x
, e
, DFmode
);
3762 /* Convert exploded e-type X, that has already been rounded to
3763 56-bit precision, to IBM 370 double Y. */
3767 unsigned EMUSHORT
*x
, *y
;
3769 toibm (x
, y
, DFmode
);
3772 #else /* it's neither DEC nor IBM */
3774 /* Convert e-type X to C4X-format long double E. */
3778 unsigned EMUSHORT
*x
, *e
;
3780 etoc4x (x
, e
, HFmode
);
3783 /* Convert exploded e-type X, that has already been rounded to
3784 56-bit precision, to IBM 370 double Y. */
3788 unsigned EMUSHORT
*x
, *y
;
3790 toc4x (x
, y
, HFmode
);
3793 #else /* it's neither DEC nor IBM nor C4X */
3795 /* Convert e-type X to IEEE double E. */
3799 unsigned EMUSHORT
*x
, *e
;
3801 unsigned EMUSHORT xi
[NI
];
3808 make_nan (e
, eisneg (x
), DFmode
);
3813 /* adjust exponent for offsets */
3814 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3819 /* round off to nearest or even */
3822 emdnorm (xi
, 0, 0, exp
, 64);
3830 /* Convert exploded e-type X, that has already been rounded to
3831 53-bit precision, to IEEE double Y. */
3835 unsigned EMUSHORT
*x
, *y
;
3837 unsigned EMUSHORT i
;
3838 unsigned EMUSHORT
*p
;
3843 make_nan (y
, eiisneg (x
), DFmode
);
3849 if (! REAL_WORDS_BIG_ENDIAN
)
3852 *y
= 0; /* output high order */
3854 *y
= 0x8000; /* output sign bit */
3857 if (i
>= (unsigned int) 2047)
3859 /* Saturate at largest number less than infinity. */
3862 if (! REAL_WORDS_BIG_ENDIAN
)
3876 *y
|= (unsigned EMUSHORT
) 0x7fef;
3877 if (! REAL_WORDS_BIG_ENDIAN
)
3902 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3903 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3904 if (! REAL_WORDS_BIG_ENDIAN
)
3919 #endif /* not C4X */
3920 #endif /* not IBM */
3921 #endif /* not DEC */
3925 /* e type to single precision. */
3928 /* Convert e-type X to IBM 370 float E. */
3932 unsigned EMUSHORT
*x
, *e
;
3934 etoibm (x
, e
, SFmode
);
3937 /* Convert exploded e-type X, that has already been rounded to
3938 float precision, to IBM 370 float Y. */
3942 unsigned EMUSHORT
*x
, *y
;
3944 toibm (x
, y
, SFmode
);
3950 /* Convert e-type X to C4X float E. */
3954 unsigned EMUSHORT
*x
, *e
;
3956 etoc4x (x
, e
, QFmode
);
3959 /* Convert exploded e-type X, that has already been rounded to
3960 float precision, to IBM 370 float Y. */
3964 unsigned EMUSHORT
*x
, *y
;
3966 toc4x (x
, y
, QFmode
);
3971 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3975 unsigned EMUSHORT
*x
, *e
;
3978 unsigned EMUSHORT xi
[NI
];
3984 make_nan (e
, eisneg (x
), SFmode
);
3989 /* adjust exponent for offsets */
3990 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3995 /* round off to nearest or even */
3998 emdnorm (xi
, 0, 0, exp
, 64);
4006 /* Convert exploded e-type X, that has already been rounded to
4007 float precision, to IEEE float Y. */
4011 unsigned EMUSHORT
*x
, *y
;
4013 unsigned EMUSHORT i
;
4014 unsigned EMUSHORT
*p
;
4019 make_nan (y
, eiisneg (x
), SFmode
);
4025 if (! REAL_WORDS_BIG_ENDIAN
)
4031 *y
= 0; /* output high order */
4033 *y
= 0x8000; /* output sign bit */
4036 /* Handle overflow cases. */
4040 *y
|= (unsigned EMUSHORT
) 0x7f80;
4045 if (! REAL_WORDS_BIG_ENDIAN
)
4053 #else /* no INFINITY */
4054 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4059 if (! REAL_WORDS_BIG_ENDIAN
)
4070 #endif /* no INFINITY */
4082 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4083 /* High order output already has sign bit set. */
4089 if (! REAL_WORDS_BIG_ENDIAN
)
4098 #endif /* not C4X */
4099 #endif /* not IBM */
4101 /* Compare two e type numbers.
4105 -2 if either a or b is a NaN. */
4109 unsigned EMUSHORT
*a
, *b
;
4111 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4112 register unsigned EMUSHORT
*p
, *q
;
4117 if (eisnan (a
) || eisnan (b
))
4126 { /* the signs are different */
4128 for (i
= 1; i
< NI
- 1; i
++)
4142 /* both are the same sign */
4157 return (0); /* equality */
4161 if (*(--p
) > *(--q
))
4162 return (msign
); /* p is bigger */
4164 return (-msign
); /* p is littler */
4168 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4172 unsigned EMUSHORT
*x
, *y
;
4179 /* Convert HOST_WIDE_INT LP to e type Y. */
4184 unsigned EMUSHORT
*y
;
4186 unsigned EMUSHORT yi
[NI
];
4187 unsigned HOST_WIDE_INT ll
;
4193 /* make it positive */
4194 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4195 yi
[0] = 0xffff; /* put correct sign in the e type number */
4199 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4201 /* move the long integer to yi significand area */
4202 #if HOST_BITS_PER_WIDE_INT == 64
4203 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4204 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4205 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4206 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4207 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4209 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4210 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4211 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4214 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4215 ecleaz (yi
); /* it was zero */
4217 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4218 emovo (yi
, y
); /* output the answer */
4221 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4225 unsigned HOST_WIDE_INT
*lp
;
4226 unsigned EMUSHORT
*y
;
4228 unsigned EMUSHORT yi
[NI
];
4229 unsigned HOST_WIDE_INT ll
;
4235 /* move the long integer to ayi significand area */
4236 #if HOST_BITS_PER_WIDE_INT == 64
4237 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4238 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4239 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4240 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4241 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4243 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4244 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4245 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4248 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4249 ecleaz (yi
); /* it was zero */
4251 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4252 emovo (yi
, y
); /* output the answer */
4256 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4257 part FRAC of e-type (packed internal format) floating point input X.
4258 The integer output I has the sign of the input, except that
4259 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4260 The output e-type fraction FRAC is the positive fractional
4265 unsigned EMUSHORT
*x
;
4267 unsigned EMUSHORT
*frac
;
4269 unsigned EMUSHORT xi
[NI
];
4271 unsigned HOST_WIDE_INT ll
;
4274 k
= (int) xi
[E
] - (EXONE
- 1);
4277 /* if exponent <= 0, integer = 0 and real output is fraction */
4282 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4284 /* long integer overflow: output large integer
4285 and correct fraction */
4287 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4290 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4291 /* In this case, let it overflow and convert as if unsigned. */
4292 euifrac (x
, &ll
, frac
);
4293 *i
= (HOST_WIDE_INT
) ll
;
4296 /* In other cases, return the largest positive integer. */
4297 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4302 warning ("overflow on truncation to integer");
4306 /* Shift more than 16 bits: first shift up k-16 mod 16,
4307 then shift up by 16's. */
4308 j
= k
- ((k
>> 4) << 4);
4315 ll
= (ll
<< 16) | xi
[M
];
4317 while ((k
-= 16) > 0);
4324 /* shift not more than 16 bits */
4326 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4333 if ((k
= enormlz (xi
)) > NBITS
)
4336 xi
[E
] -= (unsigned EMUSHORT
) k
;
4342 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4343 FRAC of e-type X. A negative input yields integer output = 0 but
4344 correct fraction. */
4347 euifrac (x
, i
, frac
)
4348 unsigned EMUSHORT
*x
;
4349 unsigned HOST_WIDE_INT
*i
;
4350 unsigned EMUSHORT
*frac
;
4352 unsigned HOST_WIDE_INT ll
;
4353 unsigned EMUSHORT xi
[NI
];
4357 k
= (int) xi
[E
] - (EXONE
- 1);
4360 /* if exponent <= 0, integer = 0 and argument is fraction */
4365 if (k
> HOST_BITS_PER_WIDE_INT
)
4367 /* Long integer overflow: output large integer
4368 and correct fraction.
4369 Note, the BSD microvax compiler says that ~(0UL)
4370 is a syntax error. */
4374 warning ("overflow on truncation to unsigned integer");
4378 /* Shift more than 16 bits: first shift up k-16 mod 16,
4379 then shift up by 16's. */
4380 j
= k
- ((k
>> 4) << 4);
4387 ll
= (ll
<< 16) | xi
[M
];
4389 while ((k
-= 16) > 0);
4394 /* shift not more than 16 bits */
4396 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4399 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4405 if ((k
= enormlz (xi
)) > NBITS
)
4408 xi
[E
] -= (unsigned EMUSHORT
) k
;
4413 /* Shift the significand of exploded e-type X up or down by SC bits. */
4417 unsigned EMUSHORT
*x
;
4420 unsigned EMUSHORT lost
;
4421 unsigned EMUSHORT
*p
;
4434 lost
|= *p
; /* remember lost bits */
4475 return ((int) lost
);
4478 /* Shift normalize the significand area of exploded e-type X.
4479 Return the shift count (up = positive). */
4483 unsigned EMUSHORT x
[];
4485 register unsigned EMUSHORT
*p
;
4494 return (0); /* already normalized */
4500 /* With guard word, there are NBITS+16 bits available.
4501 Return true if all are zero. */
4505 /* see if high byte is zero */
4506 while ((*p
& 0xff00) == 0)
4511 /* now shift 1 bit at a time */
4512 while ((*p
& 0x8000) == 0)
4518 mtherr ("enormlz", UNDERFLOW
);
4524 /* Normalize by shifting down out of the high guard word
4525 of the significand */
4540 mtherr ("enormlz", OVERFLOW
);
4547 /* Powers of ten used in decimal <-> binary conversions. */
4552 #if LONG_DOUBLE_TYPE_SIZE == 128
4553 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4555 {0x6576, 0x4a92, 0x804a, 0x153f,
4556 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4557 {0x6a32, 0xce52, 0x329a, 0x28ce,
4558 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4559 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4560 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4561 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4562 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4563 {0x851e, 0xeab7, 0x98fe, 0x901b,
4564 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4565 {0x0235, 0x0137, 0x36b1, 0x336c,
4566 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4567 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4568 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4569 {0x0000, 0x0000, 0x0000, 0x0000,
4570 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4571 {0x0000, 0x0000, 0x0000, 0x0000,
4572 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4573 {0x0000, 0x0000, 0x0000, 0x0000,
4574 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4575 {0x0000, 0x0000, 0x0000, 0x0000,
4576 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4577 {0x0000, 0x0000, 0x0000, 0x0000,
4578 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4579 {0x0000, 0x0000, 0x0000, 0x0000,
4580 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4583 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4585 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4586 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4587 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4588 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4589 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4590 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4591 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4592 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4593 {0xa23e, 0x5308, 0xfefb, 0x1155,
4594 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4595 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4596 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4597 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4598 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4599 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4600 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4601 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4602 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4603 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4604 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4605 {0xc155, 0xa4a8, 0x404e, 0x6113,
4606 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4607 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4608 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4609 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4610 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4613 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4614 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4616 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4617 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4618 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4619 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4620 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4621 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4622 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4623 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4624 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4625 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4626 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4627 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4628 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4631 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4633 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4634 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4635 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4636 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4637 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4638 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4639 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4640 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4641 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4642 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4643 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4644 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4645 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4650 /* Convert float value X to ASCII string STRING with NDIG digits after
4651 the decimal point. */
4654 e24toasc (x
, string
, ndigs
)
4655 unsigned EMUSHORT x
[];
4659 unsigned EMUSHORT w
[NI
];
4662 etoasc (w
, string
, ndigs
);
4665 /* Convert double value X to ASCII string STRING with NDIG digits after
4666 the decimal point. */
4669 e53toasc (x
, string
, ndigs
)
4670 unsigned EMUSHORT x
[];
4674 unsigned EMUSHORT w
[NI
];
4677 etoasc (w
, string
, ndigs
);
4680 /* Convert double extended value X to ASCII string STRING with NDIG digits
4681 after the decimal point. */
4684 e64toasc (x
, string
, ndigs
)
4685 unsigned EMUSHORT x
[];
4689 unsigned EMUSHORT w
[NI
];
4692 etoasc (w
, string
, ndigs
);
4695 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4696 after the decimal point. */
4699 e113toasc (x
, string
, ndigs
)
4700 unsigned EMUSHORT x
[];
4704 unsigned EMUSHORT w
[NI
];
4707 etoasc (w
, string
, ndigs
);
4711 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4712 the decimal point. */
4714 static char wstring
[80]; /* working storage for ASCII output */
4717 etoasc (x
, string
, ndigs
)
4718 unsigned EMUSHORT x
[];
4723 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4724 unsigned EMUSHORT
*p
, *r
, *ten
;
4725 unsigned EMUSHORT sign
;
4726 int i
, j
, k
, expon
, rndsav
;
4728 unsigned EMUSHORT m
;
4739 sprintf (wstring
, " NaN ");
4743 rndprc
= NBITS
; /* set to full precision */
4744 emov (x
, y
); /* retain external format */
4745 if (y
[NE
- 1] & 0x8000)
4748 y
[NE
- 1] &= 0x7fff;
4755 ten
= &etens
[NTEN
][0];
4757 /* Test for zero exponent */
4760 for (k
= 0; k
< NE
- 1; k
++)
4763 goto tnzro
; /* denormalized number */
4765 goto isone
; /* valid all zeros */
4769 /* Test for infinity. */
4770 if (y
[NE
- 1] == 0x7fff)
4773 sprintf (wstring
, " -Infinity ");
4775 sprintf (wstring
, " Infinity ");
4779 /* Test for exponent nonzero but significand denormalized.
4780 * This is an error condition.
4782 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4784 mtherr ("etoasc", DOMAIN
);
4785 sprintf (wstring
, "NaN");
4789 /* Compare to 1.0 */
4798 { /* Number is greater than 1 */
4799 /* Convert significand to an integer and strip trailing decimal zeros. */
4801 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4803 p
= &etens
[NTEN
- 4][0];
4809 for (j
= 0; j
< NE
- 1; j
++)
4822 /* Rescale from integer significand */
4823 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4825 /* Find power of 10 */
4829 /* An unordered compare result shouldn't happen here. */
4830 while (ecmp (ten
, u
) <= 0)
4832 if (ecmp (p
, u
) <= 0)
4845 { /* Number is less than 1.0 */
4846 /* Pad significand with trailing decimal zeros. */
4849 while ((y
[NE
- 2] & 0x8000) == 0)
4858 for (i
= 0; i
< NDEC
+ 1; i
++)
4860 if ((w
[NI
- 1] & 0x7) != 0)
4862 /* multiply by 10 */
4875 if (eone
[NE
- 1] <= u
[1])
4887 while (ecmp (eone
, w
) > 0)
4889 if (ecmp (p
, w
) >= 0)
4904 /* Find the first (leading) digit. */
4910 digit
= equot
[NI
- 1];
4911 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4919 digit
= equot
[NI
- 1];
4927 /* Examine number of digits requested by caller. */
4945 *s
++ = (char)digit
+ '0';
4948 /* Generate digits after the decimal point. */
4949 for (k
= 0; k
<= ndigs
; k
++)
4951 /* multiply current number by 10, without normalizing */
4958 *s
++ = (char) equot
[NI
- 1] + '0';
4960 digit
= equot
[NI
- 1];
4963 /* round off the ASCII string */
4966 /* Test for critical rounding case in ASCII output. */
4970 if (ecmp (t
, ezero
) != 0)
4971 goto roun
; /* round to nearest */
4973 if ((*(s
- 1) & 1) == 0)
4974 goto doexp
; /* round to even */
4977 /* Round up and propagate carry-outs */
4981 /* Carry out to most significant digit? */
4988 /* Most significant digit carries to 10? */
4996 /* Round up and carry out from less significant digits */
5008 sprintf (ss, "e+%d", expon);
5010 sprintf (ss, "e%d", expon);
5012 sprintf (ss
, "e%d", expon
);
5015 /* copy out the working string */
5018 while (*ss
== ' ') /* strip possible leading space */
5020 while ((*s
++ = *ss
++) != '\0')
5025 /* Convert ASCII string to floating point.
5027 Numeric input is a free format decimal number of any length, with
5028 or without decimal point. Entering E after the number followed by an
5029 integer number causes the second number to be interpreted as a power of
5030 10 to be multiplied by the first number (i.e., "scientific" notation). */
5032 /* Convert ASCII string S to single precision float value Y. */
5037 unsigned EMUSHORT
*y
;
5043 /* Convert ASCII string S to double precision value Y. */
5048 unsigned EMUSHORT
*y
;
5050 #if defined(DEC) || defined(IBM)
5062 /* Convert ASCII string S to double extended value Y. */
5067 unsigned EMUSHORT
*y
;
5072 /* Convert ASCII string S to 128-bit long double Y. */
5077 unsigned EMUSHORT
*y
;
5079 asctoeg (s
, y
, 113);
5082 /* Convert ASCII string S to e type Y. */
5087 unsigned EMUSHORT
*y
;
5089 asctoeg (s
, y
, NBITS
);
5092 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5093 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5096 asctoeg (ss
, y
, oprec
)
5098 unsigned EMUSHORT
*y
;
5101 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5102 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5103 int k
, trail
, c
, rndsav
;
5105 unsigned EMUSHORT nsign
, *p
;
5106 char *sp
, *s
, *lstr
;
5109 /* Copy the input string. */
5110 lstr
= (char *) alloca (strlen (ss
) + 1);
5112 while (*ss
== ' ') /* skip leading spaces */
5116 while ((*sp
++ = *ss
++) != '\0')
5120 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5127 rndprc
= NBITS
; /* Set to full precision */
5139 if (*s
>= '0' && *s
<= '9')
5145 if ((k
>= 0) && (k
< base
))
5147 /* Ignore leading zeros */
5148 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5150 /* Identify and strip trailing zeros after the decimal point. */
5151 if ((trail
== 0) && (decflg
!= 0))
5154 while ((*sp
>= '0' && *sp
<= '9')
5155 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5156 || (*sp
>= 'A' && *sp
<= 'F'))))
5158 /* Check for syntax error */
5160 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5161 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5163 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5174 /* If enough digits were given to more than fill up the yy register,
5175 continuing until overflow into the high guard word yy[2]
5176 guarantees that there will be a roundoff bit at the top
5177 of the low guard word after normalization. */
5184 nexp
+= 4; /* count digits after decimal point */
5186 eshup1 (yy
); /* multiply current number by 16 */
5194 nexp
+= 1; /* count digits after decimal point */
5196 eshup1 (yy
); /* multiply current number by 10 */
5202 /* Insert the current digit. */
5204 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5209 /* Mark any lost non-zero digit. */
5211 /* Count lost digits before the decimal point. */
5233 case '.': /* decimal point */
5263 mtherr ("asctoe", DOMAIN
);
5272 /* Exponent interpretation */
5274 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5275 for (k
= 0; k
< NI
; k
++)
5286 /* check for + or - */
5294 while ((*s
>= '0') && (*s
<= '9'))
5303 if ((exp
> MAXDECEXP
) && (base
== 10))
5307 yy
[E
] = 0x7fff; /* infinity */
5310 if ((exp
< MINDECEXP
) && (base
== 10))
5320 /* Base 16 hexadecimal floating constant. */
5321 if ((k
= enormlz (yy
)) > NBITS
)
5326 /* Adjust the exponent. NEXP is the number of hex digits,
5327 EXP is a power of 2. */
5328 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5338 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5339 while ((nexp
> 0) && (yy
[2] == 0))
5351 if ((k
= enormlz (yy
)) > NBITS
)
5356 lexp
= (EXONE
- 1 + NBITS
) - k
;
5357 emdnorm (yy
, lost
, 0, lexp
, 64);
5360 /* Convert to external format:
5362 Multiply by 10**nexp. If precision is 64 bits,
5363 the maximum relative error incurred in forming 10**n
5364 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5365 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5366 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5381 /* Punt. Can't handle this without 2 divides. */
5382 emovi (etens
[0], tt
);
5389 p
= &etens
[NTEN
][0];
5399 while (exp
<= MAXP
);
5418 /* Round and convert directly to the destination type */
5420 lexp
-= EXONE
- 0x3ff;
5422 else if (oprec
== 24 || oprec
== 32)
5423 lexp
-= (EXONE
- 0x7f);
5426 else if (oprec
== 24 || oprec
== 56)
5427 lexp
-= EXONE
- (0x41 << 2);
5429 else if (oprec
== 24)
5430 lexp
-= EXONE
- 0177;
5434 else if (oprec
== 56)
5435 lexp
-= EXONE
- 0201;
5438 emdnorm (yy
, lost
, 0, lexp
, 64);
5448 todec (yy
, y
); /* see etodec.c */
5453 toibm (yy
, y
, DFmode
);
5458 toc4x (yy
, y
, HFmode
);
5482 /* Return Y = largest integer not greater than X (truncated toward minus
5485 static unsigned EMUSHORT bmask
[] =
5508 unsigned EMUSHORT x
[], y
[];
5510 register unsigned EMUSHORT
*p
;
5512 unsigned EMUSHORT f
[NE
];
5514 emov (x
, f
); /* leave in external format */
5515 expon
= (int) f
[NE
- 1];
5516 e
= (expon
& 0x7fff) - (EXONE
- 1);
5522 /* number of bits to clear out */
5534 /* clear the remaining bits */
5536 /* truncate negatives toward minus infinity */
5539 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5541 for (i
= 0; i
< NE
- 1; i
++)
5554 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5555 For example, 1.1 = 0.55 * 2^1. */
5559 unsigned EMUSHORT x
[];
5561 unsigned EMUSHORT s
[];
5563 unsigned EMUSHORT xi
[NI
];
5567 /* Handle denormalized numbers properly using long integer exponent. */
5568 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5576 *exp
= (int) (li
- 0x3ffe);
5580 /* Return e type Y = X * 2^PWR2. */
5584 unsigned EMUSHORT x
[];
5586 unsigned EMUSHORT y
[];
5588 unsigned EMUSHORT xi
[NI
];
5596 emdnorm (xi
, i
, i
, li
, 64);
5602 /* C = remainder after dividing B by A, all e type values.
5603 Least significant integer quotient bits left in EQUOT. */
5607 unsigned EMUSHORT a
[], b
[], c
[];
5609 unsigned EMUSHORT den
[NI
], num
[NI
];
5613 || (ecmp (a
, ezero
) == 0)
5621 if (ecmp (a
, ezero
) == 0)
5623 mtherr ("eremain", SING
);
5629 eiremain (den
, num
);
5630 /* Sign of remainder = sign of quotient */
5639 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5640 remainder in NUM. */
5644 unsigned EMUSHORT den
[], num
[];
5647 unsigned EMUSHORT j
;
5650 ld
-= enormlz (den
);
5652 ln
-= enormlz (num
);
5656 if (ecmpm (den
, num
) <= 0)
5668 emdnorm (num
, 0, 0, ln
, 0);
5671 /* Report an error condition CODE encountered in function NAME.
5673 Mnemonic Value Significance
5675 DOMAIN 1 argument domain error
5676 SING 2 function singularity
5677 OVERFLOW 3 overflow range error
5678 UNDERFLOW 4 underflow range error
5679 TLOSS 5 total loss of precision
5680 PLOSS 6 partial loss of precision
5681 INVALID 7 NaN - producing operation
5682 EDOM 33 Unix domain error code
5683 ERANGE 34 Unix range error code
5685 The order of appearance of the following messages is bound to the
5686 error codes defined above. */
5696 /* The string passed by the calling program is supposed to be the
5697 name of the function in which the error occurred.
5698 The code argument selects which error message string will be printed. */
5700 if (strcmp (name
, "esub") == 0)
5701 name
= "subtraction";
5702 else if (strcmp (name
, "ediv") == 0)
5704 else if (strcmp (name
, "emul") == 0)
5705 name
= "multiplication";
5706 else if (strcmp (name
, "enormlz") == 0)
5707 name
= "normalization";
5708 else if (strcmp (name
, "etoasc") == 0)
5709 name
= "conversion to text";
5710 else if (strcmp (name
, "asctoe") == 0)
5712 else if (strcmp (name
, "eremain") == 0)
5714 else if (strcmp (name
, "esqrt") == 0)
5715 name
= "square root";
5720 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5721 case SING
: warning ("%s: function singularity" , name
); break;
5722 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5723 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5724 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5725 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5726 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5731 /* Set global error message word */
5736 /* Convert DEC double precision D to e type E. */
5740 unsigned EMUSHORT
*d
;
5741 unsigned EMUSHORT
*e
;
5743 unsigned EMUSHORT y
[NI
];
5744 register unsigned EMUSHORT r
, *p
;
5746 ecleaz (y
); /* start with a zero */
5747 p
= y
; /* point to our number */
5748 r
= *d
; /* get DEC exponent word */
5749 if (*d
& (unsigned int) 0x8000)
5750 *p
= 0xffff; /* fill in our sign */
5751 ++p
; /* bump pointer to our exponent word */
5752 r
&= 0x7fff; /* strip the sign bit */
5753 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5757 r
>>= 7; /* shift exponent word down 7 bits */
5758 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5759 /* add our e type exponent offset */
5760 *p
++ = r
; /* to form our exponent */
5762 r
= *d
++; /* now do the high order mantissa */
5763 r
&= 0177; /* strip off the DEC exponent and sign bits */
5764 r
|= 0200; /* the DEC understood high order mantissa bit */
5765 *p
++ = r
; /* put result in our high guard word */
5767 *p
++ = *d
++; /* fill in the rest of our mantissa */
5771 eshdn8 (y
); /* shift our mantissa down 8 bits */
5776 /* Convert e type X to DEC double precision D. */
5780 unsigned EMUSHORT
*x
, *d
;
5782 unsigned EMUSHORT xi
[NI
];
5787 /* Adjust exponent for offsets. */
5788 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5789 /* Round off to nearest or even. */
5792 emdnorm (xi
, 0, 0, exp
, 64);
5797 /* Convert exploded e-type X, that has already been rounded to
5798 56-bit precision, to DEC format double Y. */
5802 unsigned EMUSHORT
*x
, *y
;
5804 unsigned EMUSHORT i
;
5805 unsigned EMUSHORT
*p
;
5844 /* Convert IBM single/double precision to e type. */
5848 unsigned EMUSHORT
*d
;
5849 unsigned EMUSHORT
*e
;
5850 enum machine_mode mode
;
5852 unsigned EMUSHORT y
[NI
];
5853 register unsigned EMUSHORT r
, *p
;
5855 ecleaz (y
); /* start with a zero */
5856 p
= y
; /* point to our number */
5857 r
= *d
; /* get IBM exponent word */
5858 if (*d
& (unsigned int) 0x8000)
5859 *p
= 0xffff; /* fill in our sign */
5860 ++p
; /* bump pointer to our exponent word */
5861 r
&= 0x7f00; /* strip the sign bit */
5862 r
>>= 6; /* shift exponent word down 6 bits */
5863 /* in fact shift by 8 right and 2 left */
5864 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5865 /* add our e type exponent offset */
5866 *p
++ = r
; /* to form our exponent */
5868 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5869 /* strip off the IBM exponent and sign bits */
5870 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5872 *p
++ = *d
++; /* fill in the rest of our mantissa */
5877 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5880 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5881 /* handle change in RADIX */
5887 /* Convert e type to IBM single/double precision. */
5891 unsigned EMUSHORT
*x
, *d
;
5892 enum machine_mode mode
;
5894 unsigned EMUSHORT xi
[NI
];
5899 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5900 /* round off to nearest or even */
5903 emdnorm (xi
, 0, 0, exp
, 64);
5905 toibm (xi
, d
, mode
);
5910 unsigned EMUSHORT
*x
, *y
;
5911 enum machine_mode mode
;
5913 unsigned EMUSHORT i
;
5914 unsigned EMUSHORT
*p
;
5964 /* Convert C4X single/double precision to e type. */
5968 unsigned EMUSHORT
*d
;
5969 unsigned EMUSHORT
*e
;
5970 enum machine_mode mode
;
5972 unsigned EMUSHORT y
[NI
];
5979 /* Short-circuit the zero case. */
5980 if ((d
[0] == 0x8000)
5982 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5993 ecleaz (y
); /* start with a zero */
5994 r
= d
[0]; /* get sign/exponent part */
5995 if (r
& (unsigned int) 0x0080)
5997 y
[0] = 0xffff; /* fill in our sign */
6005 r
>>= 8; /* Shift exponent word down 8 bits. */
6006 if (r
& 0x80) /* Make the exponent negative if it is. */
6008 r
= r
| (~0 & ~0xff);
6013 /* Now do the high order mantissa. We don't "or" on the high bit
6014 because it is 2 (not 1) and is handled a little differently
6019 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6021 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6031 /* Now do the two's complement on the data. */
6033 carry
= 1; /* Initially add 1 for the two's complement. */
6034 for (i
=size
+ M
; i
> M
; i
--)
6036 if (carry
&& (y
[i
] == 0x0000))
6038 /* We overflowed into the next word, carry is the same. */
6039 y
[i
] = carry
? 0x0000 : 0xffff;
6043 /* No overflow, just invert and add carry. */
6044 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6059 /* Add our e type exponent offset to form our exponent. */
6063 /* Now do the high order mantissa strip off the exponent and sign
6064 bits and add the high 1 bit. */
6065 y
[M
] = (d
[0] & 0x7f) | 0x80;
6068 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6070 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6080 /* Convert e type to C4X single/double precision. */
6084 unsigned EMUSHORT
*x
, *d
;
6085 enum machine_mode mode
;
6087 unsigned EMUSHORT xi
[NI
];
6093 /* Adjust exponent for offsets. */
6094 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6096 /* Round off to nearest or even. */
6098 rndprc
= mode
== QFmode
? 24 : 32;
6099 emdnorm (xi
, 0, 0, exp
, 64);
6101 toc4x (xi
, d
, mode
);
6106 unsigned EMUSHORT
*x
, *y
;
6107 enum machine_mode mode
;
6113 /* Short-circuit the zero case */
6114 if ((x
[0] == 0) /* Zero exponent and sign */
6116 && (x
[M
] == 0) /* The rest is for zero mantissa */
6118 /* Only check for double if necessary */
6119 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6121 /* We have a zero. Put it into the output and return. */
6134 /* Negative number require a two's complement conversion of the
6140 i
= ((int) x
[1]) - 0x7f;
6142 /* Now add 1 to the inverted data to do the two's complement. */
6152 x
[v
] = carry
? 0x0000 : 0xffff;
6156 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6162 /* The following is a special case. The C4X negative float requires
6163 a zero in the high bit (because the format is (2 - x) x 2^m), so
6164 if a one is in that bit, we have to shift left one to get rid
6165 of it. This only occurs if the number is -1 x 2^m. */
6166 if (x
[M
+1] & 0x8000)
6168 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6169 high sign bit and shift the exponent. */
6176 i
= ((int) x
[1]) - 0x7f;
6179 if ((i
< -128) || (i
> 127))
6194 y
[0] |= ((i
& 0xff) << 8);
6198 y
[0] |= x
[M
] & 0x7f;
6208 /* Output a binary NaN bit pattern in the target machine's format. */
6210 /* If special NaN bit patterns are required, define them in tm.h
6211 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6217 unsigned EMUSHORT TFbignan
[8] =
6218 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6219 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6227 unsigned EMUSHORT XFbignan
[6] =
6228 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6229 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6237 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6238 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6246 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6247 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6254 make_nan (nan
, sign
, mode
)
6255 unsigned EMUSHORT
*nan
;
6257 enum machine_mode mode
;
6260 unsigned EMUSHORT
*p
;
6264 /* Possibly the `reserved operand' patterns on a VAX can be
6265 used like NaN's, but probably not in the same way as IEEE. */
6266 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6269 if (REAL_WORDS_BIG_ENDIAN
)
6277 if (REAL_WORDS_BIG_ENDIAN
)
6285 if (REAL_WORDS_BIG_ENDIAN
)
6294 if (REAL_WORDS_BIG_ENDIAN
)
6304 if (REAL_WORDS_BIG_ENDIAN
)
6305 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6308 if (! REAL_WORDS_BIG_ENDIAN
)
6309 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6313 /* This is the inverse of the function `etarsingle' invoked by
6314 REAL_VALUE_TO_TARGET_SINGLE. */
6317 ereal_unto_float (f
)
6321 unsigned EMUSHORT s
[2];
6322 unsigned EMUSHORT e
[NE
];
6324 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6325 This is the inverse operation to what the function `endian' does. */
6326 if (REAL_WORDS_BIG_ENDIAN
)
6328 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6329 s
[1] = (unsigned EMUSHORT
) f
;
6333 s
[0] = (unsigned EMUSHORT
) f
;
6334 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6336 /* Convert and promote the target float to E-type. */
6338 /* Output E-type to REAL_VALUE_TYPE. */
6344 /* This is the inverse of the function `etardouble' invoked by
6345 REAL_VALUE_TO_TARGET_DOUBLE. */
6348 ereal_unto_double (d
)
6352 unsigned EMUSHORT s
[4];
6353 unsigned EMUSHORT e
[NE
];
6355 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6356 if (REAL_WORDS_BIG_ENDIAN
)
6358 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6359 s
[1] = (unsigned EMUSHORT
) d
[0];
6360 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6361 s
[3] = (unsigned EMUSHORT
) d
[1];
6365 /* Target float words are little-endian. */
6366 s
[0] = (unsigned EMUSHORT
) d
[0];
6367 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6368 s
[2] = (unsigned EMUSHORT
) d
[1];
6369 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6371 /* Convert target double to E-type. */
6373 /* Output E-type to REAL_VALUE_TYPE. */
6379 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6380 This is somewhat like ereal_unto_float, but the input types
6381 for these are different. */
6384 ereal_from_float (f
)
6388 unsigned EMUSHORT s
[2];
6389 unsigned EMUSHORT e
[NE
];
6391 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6392 This is the inverse operation to what the function `endian' does. */
6393 if (REAL_WORDS_BIG_ENDIAN
)
6395 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6396 s
[1] = (unsigned EMUSHORT
) f
;
6400 s
[0] = (unsigned EMUSHORT
) f
;
6401 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6403 /* Convert and promote the target float to E-type. */
6405 /* Output E-type to REAL_VALUE_TYPE. */
6411 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6412 This is somewhat like ereal_unto_double, but the input types
6413 for these are different.
6415 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6416 data format, with no holes in the bit packing. The first element
6417 of the input array holds the bits that would come first in the
6418 target computer's memory. */
6421 ereal_from_double (d
)
6425 unsigned EMUSHORT s
[4];
6426 unsigned EMUSHORT e
[NE
];
6428 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6429 if (REAL_WORDS_BIG_ENDIAN
)
6431 #if HOST_BITS_PER_WIDE_INT == 32
6432 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6433 s
[1] = (unsigned EMUSHORT
) d
[0];
6434 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6435 s
[3] = (unsigned EMUSHORT
) d
[1];
6437 /* In this case the entire target double is contained in the
6438 first array element. The second element of the input is
6440 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6441 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6442 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6443 s
[3] = (unsigned EMUSHORT
) d
[0];
6448 /* Target float words are little-endian. */
6449 s
[0] = (unsigned EMUSHORT
) d
[0];
6450 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6451 #if HOST_BITS_PER_WIDE_INT == 32
6452 s
[2] = (unsigned EMUSHORT
) d
[1];
6453 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6455 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6456 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6459 /* Convert target double to E-type. */
6461 /* Output E-type to REAL_VALUE_TYPE. */
6468 /* Convert target computer unsigned 64-bit integer to e-type.
6469 The endian-ness of DImode follows the convention for integers,
6470 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6474 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6475 unsigned EMUSHORT
*e
;
6477 unsigned EMUSHORT yi
[NI
];
6481 if (WORDS_BIG_ENDIAN
)
6483 for (k
= M
; k
< M
+ 4; k
++)
6488 for (k
= M
+ 3; k
>= M
; k
--)
6491 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6492 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6493 ecleaz (yi
); /* it was zero */
6495 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6499 /* Convert target computer signed 64-bit integer to e-type. */
6503 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6504 unsigned EMUSHORT
*e
;
6506 unsigned EMULONG acc
;
6507 unsigned EMUSHORT yi
[NI
];
6508 unsigned EMUSHORT carry
;
6512 if (WORDS_BIG_ENDIAN
)
6514 for (k
= M
; k
< M
+ 4; k
++)
6519 for (k
= M
+ 3; k
>= M
; k
--)
6522 /* Take absolute value */
6528 for (k
= M
+ 3; k
>= M
; k
--)
6530 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6537 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6538 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6539 ecleaz (yi
); /* it was zero */
6541 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6548 /* Convert e-type to unsigned 64-bit int. */
6552 unsigned EMUSHORT
*x
;
6553 unsigned EMUSHORT
*i
;
6555 unsigned EMUSHORT xi
[NI
];
6564 k
= (int) xi
[E
] - (EXONE
- 1);
6567 for (j
= 0; j
< 4; j
++)
6573 for (j
= 0; j
< 4; j
++)
6576 warning ("overflow on truncation to integer");
6581 /* Shift more than 16 bits: first shift up k-16 mod 16,
6582 then shift up by 16's. */
6583 j
= k
- ((k
>> 4) << 4);
6587 if (WORDS_BIG_ENDIAN
)
6598 if (WORDS_BIG_ENDIAN
)
6603 while ((k
-= 16) > 0);
6607 /* shift not more than 16 bits */
6612 if (WORDS_BIG_ENDIAN
)
6631 /* Convert e-type to signed 64-bit int. */
6635 unsigned EMUSHORT
*x
;
6636 unsigned EMUSHORT
*i
;
6638 unsigned EMULONG acc
;
6639 unsigned EMUSHORT xi
[NI
];
6640 unsigned EMUSHORT carry
;
6641 unsigned EMUSHORT
*isave
;
6645 k
= (int) xi
[E
] - (EXONE
- 1);
6648 for (j
= 0; j
< 4; j
++)
6654 for (j
= 0; j
< 4; j
++)
6657 warning ("overflow on truncation to integer");
6663 /* Shift more than 16 bits: first shift up k-16 mod 16,
6664 then shift up by 16's. */
6665 j
= k
- ((k
>> 4) << 4);
6669 if (WORDS_BIG_ENDIAN
)
6680 if (WORDS_BIG_ENDIAN
)
6685 while ((k
-= 16) > 0);
6689 /* shift not more than 16 bits */
6692 if (WORDS_BIG_ENDIAN
)
6708 /* Negate if negative */
6712 if (WORDS_BIG_ENDIAN
)
6714 for (k
= 0; k
< 4; k
++)
6716 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6717 if (WORDS_BIG_ENDIAN
)
6729 /* Longhand square root routine. */
6732 static int esqinited
= 0;
6733 static unsigned short sqrndbit
[NI
];
6737 unsigned EMUSHORT
*x
, *y
;
6739 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6741 int i
, j
, k
, n
, nlups
;
6746 sqrndbit
[NI
- 2] = 1;
6749 /* Check for arg <= 0 */
6750 i
= ecmp (x
, ezero
);
6755 mtherr ("esqrt", DOMAIN
);
6771 /* Bring in the arg and renormalize if it is denormal. */
6773 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6777 /* Divide exponent by 2 */
6779 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6781 /* Adjust if exponent odd */
6791 n
= 8; /* get 8 bits of result per inner loop */
6797 /* bring in next word of arg */
6799 num
[NI
- 1] = xx
[j
+ 3];
6800 /* Do additional bit on last outer loop, for roundoff. */
6803 for (i
= 0; i
< n
; i
++)
6805 /* Next 2 bits of arg */
6808 /* Shift up answer */
6810 /* Make trial divisor */
6811 for (k
= 0; k
< NI
; k
++)
6814 eaddm (sqrndbit
, temp
);
6815 /* Subtract and insert answer bit if it goes in */
6816 if (ecmpm (temp
, num
) <= 0)
6826 /* Adjust for extra, roundoff loop done. */
6827 exp
+= (NBITS
- 1) - rndprc
;
6829 /* Sticky bit = 1 if the remainder is nonzero. */
6831 for (i
= 3; i
< NI
; i
++)
6834 /* Renormalize and round off. */
6835 emdnorm (sq
, k
, 0, exp
, 64);
6839 #endif /* EMU_NON_COMPILE not defined */
6841 /* Return the binary precision of the significand for a given
6842 floating point mode. The mode can hold an integer value
6843 that many bits wide, without losing any bits. */
6846 significand_size (mode
)
6847 enum machine_mode mode
;
6850 /* Don't test the modes, but their sizes, lest this
6851 code won't work for BITS_PER_UNIT != 8 . */
6853 switch (GET_MODE_BITSIZE (mode
))
6857 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6864 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6867 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6870 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6873 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT