1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /* To enable support of XFmode extended real floating point, define
32 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
34 To support cross compilation between IEEE, VAX and IBM floating
35 point formats, define REAL_ARITHMETIC in the tm.h file.
37 In either case the machine files (tm.h) must not contain any code
38 that tries to use host floating point arithmetic to convert
39 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
40 etc. In cross-compile situations a REAL_VALUE_TYPE may not
41 be intelligible to the host computer's native arithmetic.
43 The emulator defaults to the host's floating point format so that
44 its decimal conversion functions can be used if desired (see
47 The first part of this file interfaces gcc to ieee.c, which is a
48 floating point arithmetic suite that was not written with gcc in
49 mind. The interface is followed by ieee.c itself and related
50 items. Avoid changing ieee.c unless you have suitable test
51 programs available. A special version of the PARANOIA floating
52 point arithmetic tester, modified for this purpose, can be found
53 on usc.edu : /pub/C-numanal/ieeetest.zoo. Some tutorial
54 information on ieee.c is given in my book: S. L. Moshier,
55 _Methods and Programs for Mathematical Functions_, Prentice-Hall
56 or Simon & Schuster Int'l, 1989. A library of XFmode elementary
57 transcendental functions can be obtained by ftp from
58 research.att.com: netlib/cephes/ldouble.shar.Z */
60 /* Type of computer arithmetic.
61 Only one of DEC, IBM, MIEEE, IBMPC, or UNK should get defined.
63 `MIEEE' refers generically to big-endian IEEE floating-point data
64 structure. This definition should work in SFmode `float' type and
65 DFmode `double' type on virtually all big-endian IEEE machines.
66 If LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then MIEEE
67 also invokes the particular XFmode (`long double' type) data
68 structure used by the Motorola 680x0 series processors.
70 `IBMPC' refers generally to little-endian IEEE machines. In this
71 case, if LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then
72 IBMPC also invokes the particular XFmode `long double' data
73 structure used by the Intel 80x86 series processors.
75 `DEC' refers specifically to the Digital Equipment Corp PDP-11
76 and VAX floating point data structure. This model currently
77 supports no type wider than DFmode.
79 `IBM' refers specifically to the IBM System/370 and compatible
80 floating point data structure. This model currently supports
81 no type wider than DFmode. The IBM conversions were contributed by
82 frank@atom.ansto.gov.au (Frank Crawford).
84 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
85 then `long double' and `double' are both implemented, but they
86 both mean DFmode. In this case, the software floating-point
87 support available here is activated by writing
88 #define REAL_ARITHMETIC
91 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
92 and may deactivate XFmode since `long double' is used to refer
95 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
96 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
97 separate the floating point unit's endian-ness from that of
98 the integer addressing. This permits one to define a big-endian
99 FPU on a little-endian machine (e.g., ARM). An extension to
100 BYTES_BIG_ENDIAN may be required for some machines in the future.
101 These optional macros may be defined in tm.h. In real.h, they
102 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
103 them for any normal host or target machine on which the floats
104 and the integers have the same endian-ness. */
107 /* The following converts gcc macros into the ones used by this file. */
109 /* REAL_ARITHMETIC defined means that macros in real.h are
110 defined to call emulator functions. */
111 #ifdef REAL_ARITHMETIC
113 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
114 /* PDP-11, Pro350, VAX: */
116 #else /* it's not VAX */
117 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
118 /* IBM System/370 style */
120 #else /* it's also not an IBM */
121 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
122 #if FLOAT_WORDS_BIG_ENDIAN
123 /* Motorola IEEE, high order words come first (Sun workstation): */
125 #else /* not big-endian */
126 /* Intel IEEE, low order words come first:
129 #endif /* big-endian */
130 #else /* it's not IEEE either */
131 /* UNKnown arithmetic. We don't support this and can't go on. */
132 unknown arithmetic type
134 #endif /* not IEEE */
139 /* REAL_ARITHMETIC not defined means that the *host's* data
140 structure will be used. It may differ by endian-ness from the
141 target machine's structure and will get its ends swapped
142 accordingly (but not here). Probably only the decimal <-> binary
143 functions in this file will actually be used in this case. */
145 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
147 #else /* it's not VAX */
148 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
149 /* IBM System/370 style */
151 #else /* it's also not an IBM */
152 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
153 #if HOST_FLOAT_WORDS_BIG_ENDIAN
155 #else /* not big-endian */
157 #endif /* big-endian */
158 #else /* it's not IEEE either */
159 unknown arithmetic type
161 #endif /* not IEEE */
165 #endif /* REAL_ARITHMETIC not defined */
167 /* Define INFINITY for support of infinity.
168 Define NANS for support of Not-a-Number's (NaN's). */
169 #if !defined(DEC) && !defined(IBM)
174 /* Support of NaNs requires support of infinity. */
181 /* Find a host integer type that is at least 16 bits wide,
182 and another type at least twice whatever that size is. */
184 #if HOST_BITS_PER_CHAR >= 16
185 #define EMUSHORT char
186 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
187 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
189 #if HOST_BITS_PER_SHORT >= 16
190 #define EMUSHORT short
191 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
194 #if HOST_BITS_PER_INT >= 16
196 #define EMUSHORT_SIZE HOST_BITS_PER_INT
197 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
199 #if HOST_BITS_PER_LONG >= 16
200 #define EMUSHORT long
201 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
202 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
204 /* You will have to modify this program to have a smaller unit size. */
205 #define EMU_NON_COMPILE
211 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
212 #define EMULONG short
214 #if HOST_BITS_PER_INT >= EMULONG_SIZE
217 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
220 #if HOST_BITS_PER_LONG_LONG >= EMULONG_SIZE
221 #define EMULONG long long int
223 /* You will have to modify this program to have a smaller unit size. */
224 #define EMU_NON_COMPILE
231 /* The host interface doesn't work if no 16-bit size exists. */
232 #if EMUSHORT_SIZE != 16
233 #define EMU_NON_COMPILE
236 /* OK to continue compilation. */
237 #ifndef EMU_NON_COMPILE
239 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
240 In GET_REAL and PUT_REAL, r and e are pointers.
241 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
242 in memory, with no holes. */
244 #if LONG_DOUBLE_TYPE_SIZE == 96
245 /* Number of 16 bit words in external e type format */
247 #define MAXDECEXP 4932
248 #define MINDECEXP -4956
249 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
250 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
251 #else /* no XFmode */
252 #if LONG_DOUBLE_TYPE_SIZE == 128
254 #define MAXDECEXP 4932
255 #define MINDECEXP -4977
256 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
257 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
260 #define MAXDECEXP 4932
261 #define MINDECEXP -4956
262 #ifdef REAL_ARITHMETIC
263 /* Emulator uses target format internally
264 but host stores it in host endian-ness. */
266 #if HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN
267 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT*) (r), (e))
268 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
270 #else /* endian-ness differs */
271 /* emulator uses target endian-ness internally */
272 #define GET_REAL(r,e) \
273 do { unsigned EMUSHORT w[4]; \
274 w[3] = ((EMUSHORT *) r)[0]; \
275 w[2] = ((EMUSHORT *) r)[1]; \
276 w[1] = ((EMUSHORT *) r)[2]; \
277 w[0] = ((EMUSHORT *) r)[3]; \
278 e53toe (w, (e)); } while (0)
280 #define PUT_REAL(e,r) \
281 do { unsigned EMUSHORT w[4]; \
283 *((EMUSHORT *) r) = w[3]; \
284 *((EMUSHORT *) r + 1) = w[2]; \
285 *((EMUSHORT *) r + 2) = w[1]; \
286 *((EMUSHORT *) r + 3) = w[0]; } while (0)
288 #endif /* endian-ness differs */
290 #else /* not REAL_ARITHMETIC */
292 /* emulator uses host format */
293 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
294 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
296 #endif /* not REAL_ARITHMETIC */
297 #endif /* not TFmode */
298 #endif /* no XFmode */
301 /* Number of 16 bit words in internal format */
304 /* Array offset to exponent */
307 /* Array offset to high guard word */
310 /* Number of bits of precision */
311 #define NBITS ((NI-4)*16)
313 /* Maximum number of decimal digits in ASCII conversion
316 #define NDEC (NBITS*8/27)
318 /* The exponent of 1.0 */
319 #define EXONE (0x3fff)
321 extern int extra_warnings;
322 extern unsigned EMUSHORT ezero[], ehalf[], eone[], etwo[];
323 extern unsigned EMUSHORT elog2[], esqrt2[];
325 static void endian PROTO((unsigned EMUSHORT *, long *,
327 static void eclear PROTO((unsigned EMUSHORT *));
328 static void emov PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
329 static void eabs PROTO((unsigned EMUSHORT *));
330 static void eneg PROTO((unsigned EMUSHORT *));
331 static int eisneg PROTO((unsigned EMUSHORT *));
332 static int eisinf PROTO((unsigned EMUSHORT *));
333 static int eisnan PROTO((unsigned EMUSHORT *));
334 static void einfin PROTO((unsigned EMUSHORT *));
335 static void enan PROTO((unsigned EMUSHORT *, int));
336 static void emovi PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
337 static void emovo PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
338 static void ecleaz PROTO((unsigned EMUSHORT *));
339 static void ecleazs PROTO((unsigned EMUSHORT *));
340 static void emovz PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
341 static void einan PROTO((unsigned EMUSHORT *));
342 static int eiisnan PROTO((unsigned EMUSHORT *));
343 static int eiisneg PROTO((unsigned EMUSHORT *));
344 static void eiinfin PROTO((unsigned EMUSHORT *));
345 static int eiisinf PROTO((unsigned EMUSHORT *));
346 static int ecmpm PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
347 static void eshdn1 PROTO((unsigned EMUSHORT *));
348 static void eshup1 PROTO((unsigned EMUSHORT *));
349 static void eshdn8 PROTO((unsigned EMUSHORT *));
350 static void eshup8 PROTO((unsigned EMUSHORT *));
351 static void eshup6 PROTO((unsigned EMUSHORT *));
352 static void eshdn6 PROTO((unsigned EMUSHORT *));
353 static void eaddm PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
\f
354 static void esubm PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
355 static void m16m PROTO((unsigned int, unsigned short *,
357 static int edivm PROTO((unsigned short *, unsigned short *));
358 static int emulm PROTO((unsigned short *, unsigned short *));
359 static void emdnorm PROTO((unsigned EMUSHORT *, int, int, EMULONG, int));
360 static void esub PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
361 unsigned EMUSHORT *));
362 static void eadd PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
363 unsigned EMUSHORT *));
364 static void eadd1 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
365 unsigned EMUSHORT *));
366 static void ediv PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
367 unsigned EMUSHORT *));
368 static void emul PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
369 unsigned EMUSHORT *));
370 static void e53toe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
371 static void e64toe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
372 static void e113toe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
373 static void e24toe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
374 static void etoe113 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
375 static void toe113 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
376 static void etoe64 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
377 static void toe64 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
378 static void etoe53 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
379 static void toe53 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
380 static void etoe24 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
381 static void toe24 PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
382 static int ecmp PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
383 static void eround PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
384 static void ltoe PROTO((HOST_WIDE_INT *, unsigned EMUSHORT *));
385 static void ultoe PROTO((unsigned HOST_WIDE_INT *, unsigned EMUSHORT *));
386 static void eifrac PROTO((unsigned EMUSHORT *, HOST_WIDE_INT *,
387 unsigned EMUSHORT *));
388 static void euifrac PROTO((unsigned EMUSHORT *, unsigned HOST_WIDE_INT *,
389 unsigned EMUSHORT *));
390 static int eshift PROTO((unsigned EMUSHORT *, int));
391 static int enormlz PROTO((unsigned EMUSHORT *));
392 static void e24toasc PROTO((unsigned EMUSHORT *, char *, int));
393 static void e53toasc PROTO((unsigned EMUSHORT *, char *, int));
394 static void e64toasc PROTO((unsigned EMUSHORT *, char *, int));
395 static void e113toasc PROTO((unsigned EMUSHORT *, char *, int));
396 static void etoasc PROTO((unsigned EMUSHORT *, char *, int));
397 static void asctoe24 PROTO((char *, unsigned EMUSHORT *));
398 static void asctoe53 PROTO((char *, unsigned EMUSHORT *));
399 static void asctoe64 PROTO((char *, unsigned EMUSHORT *));
400 static void asctoe113 PROTO((char *, unsigned EMUSHORT *));
401 static void asctoe PROTO((char *, unsigned EMUSHORT *));
402 static void asctoeg PROTO((char *, unsigned EMUSHORT *, int));
403 static void efloor PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
404 static void efrexp PROTO((unsigned EMUSHORT *, int *,
405 unsigned EMUSHORT *));
406 static void eldexp PROTO((unsigned EMUSHORT *, int, unsigned EMUSHORT *));
407 static void eremain PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
408 unsigned EMUSHORT *));
409 static void eiremain PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
410 static void mtherr PROTO((char *, int));
411 static void dectoe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
412 static void etodec PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
413 static void todec PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
414 static void ibmtoe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
416 static void etoibm PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
418 static void toibm PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *,
420 static void make_nan PROTO((unsigned EMUSHORT *, int, enum machine_mode));
421 static void uditoe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
422 static void ditoe PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
423 static void etoudi PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
424 static void etodi PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
425 static void esqrt PROTO((unsigned EMUSHORT *, unsigned EMUSHORT *));
427 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
428 swapping ends if required, into output array of longs. The
429 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
433 unsigned EMUSHORT e[];
435 enum machine_mode mode;
439 #if FLOAT_WORDS_BIG_ENDIAN
444 /* Swap halfwords in the fourth long. */
445 th = (unsigned long) e[6] & 0xffff;
446 t = (unsigned long) e[7] & 0xffff;
452 /* Swap halfwords in the third long. */
453 th = (unsigned long) e[4] & 0xffff;
454 t = (unsigned long) e[5] & 0xffff;
457 /* fall into the double case */
461 /* swap halfwords in the second word */
462 th = (unsigned long) e[2] & 0xffff;
463 t = (unsigned long) e[3] & 0xffff;
466 /* fall into the float case */
471 /* swap halfwords in the first word */
472 th = (unsigned long) e[0] & 0xffff;
473 t = (unsigned long) e[1] & 0xffff;
484 /* Pack the output array without swapping. */
491 /* Pack the fourth long. */
492 th = (unsigned long) e[7] & 0xffff;
493 t = (unsigned long) e[6] & 0xffff;
499 /* Pack the third long.
500 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
502 th = (unsigned long) e[5] & 0xffff;
503 t = (unsigned long) e[4] & 0xffff;
506 /* fall into the double case */
510 /* pack the second long */
511 th = (unsigned long) e[3] & 0xffff;
512 t = (unsigned long) e[2] & 0xffff;
515 /* fall into the float case */
520 /* pack the first long */
521 th = (unsigned long) e[1] & 0xffff;
522 t = (unsigned long) e[0] & 0xffff;
535 /* This is the implementation of the REAL_ARITHMETIC macro. */
538 earith (value, icode, r1, r2)
539 REAL_VALUE_TYPE *value;
544 unsigned EMUSHORT d1[NE], d2[NE], v[NE];
550 /* Return NaN input back to the caller. */
553 PUT_REAL (d1, value);
558 PUT_REAL (d2, value);
562 code = (enum tree_code) icode;
570 esub (d2, d1, v); /* d1 - d2 */
578 #ifndef REAL_INFINITY
579 if (ecmp (d2, ezero) == 0)
582 enan (v, eisneg (d1) ^ eisneg (d2));
589 ediv (d2, d1, v); /* d1/d2 */
592 case MIN_EXPR: /* min (d1,d2) */
593 if (ecmp (d1, d2) < 0)
599 case MAX_EXPR: /* max (d1,d2) */
600 if (ecmp (d1, d2) > 0)
613 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
614 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
620 unsigned EMUSHORT f[NE], g[NE];
636 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
637 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
643 unsigned EMUSHORT f[NE], g[NE];
645 unsigned HOST_WIDE_INT l;
659 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
660 binary, rounding off as indicated by the machine_mode argument. Then it
661 promotes the rounded value to REAL_VALUE_TYPE. */
668 unsigned EMUSHORT tem[NE], e[NE];
698 /* Expansion of REAL_NEGATE. */
704 unsigned EMUSHORT e[NE];
714 /* Round real toward zero to HOST_WIDE_INT;
715 implements REAL_VALUE_FIX (x). */
721 unsigned EMUSHORT f[NE], g[NE];
728 warning ("conversion from NaN to int");
736 /* Round real toward zero to unsigned HOST_WIDE_INT
737 implements REAL_VALUE_UNSIGNED_FIX (x).
738 Negative input returns zero. */
740 unsigned HOST_WIDE_INT
744 unsigned EMUSHORT f[NE], g[NE];
745 unsigned HOST_WIDE_INT l;
751 warning ("conversion from NaN to unsigned int");
760 /* REAL_VALUE_FROM_INT macro. */
763 ereal_from_int (d, i, j)
767 unsigned EMUSHORT df[NE], dg[NE];
768 HOST_WIDE_INT low, high;
776 /* complement and add 1 */
783 eldexp (eone, HOST_BITS_PER_WIDE_INT, df);
784 ultoe ((unsigned HOST_WIDE_INT *) &high, dg);
786 ultoe ((unsigned HOST_WIDE_INT *) &low, df);
794 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
797 ereal_from_uint (d, i, j)
799 unsigned HOST_WIDE_INT i, j;
801 unsigned EMUSHORT df[NE], dg[NE];
802 unsigned HOST_WIDE_INT low, high;
806 eldexp (eone, HOST_BITS_PER_WIDE_INT, df);
815 /* REAL_VALUE_TO_INT macro. */
818 ereal_to_int (low, high, rr)
819 HOST_WIDE_INT *low, *high;
822 unsigned EMUSHORT d[NE], df[NE], dg[NE], dh[NE];
829 warning ("conversion from NaN to int");
835 /* convert positive value */
842 eldexp (eone, HOST_BITS_PER_WIDE_INT, df);
843 ediv (df, d, dg); /* dg = d / 2^32 is the high word */
844 euifrac (dg, (unsigned HOST_WIDE_INT *) high, dh);
845 emul (df, dh, dg); /* fractional part is the low word */
846 euifrac (dg, (unsigned HOST_WIDE_INT *)low, dh);
849 /* complement and add 1 */
859 /* REAL_VALUE_LDEXP macro. */
866 unsigned EMUSHORT e[NE], y[NE];
879 /* These routines are conditionally compiled because functions
880 of the same names may be defined in fold-const.c. */
882 #ifdef REAL_ARITHMETIC
884 /* Check for infinity in a REAL_VALUE_TYPE. */
890 unsigned EMUSHORT e[NE];
901 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
907 unsigned EMUSHORT e[NE];
918 /* Check for a negative REAL_VALUE_TYPE number.
919 This just checks the sign bit, so that -0 counts as negative. */
925 return ereal_isneg (x);
928 /* Expansion of REAL_VALUE_TRUNCATE.
929 The result is in floating point, rounded to nearest or even. */
932 real_value_truncate (mode, arg)
933 enum machine_mode mode;
936 unsigned EMUSHORT e[NE], t[NE];
972 /* If an unsupported type was requested, presume that
973 the machine files know something useful to do with
974 the unmodified value. */
983 #endif /* REAL_ARITHMETIC defined */
985 /* Used for debugging--print the value of R in human-readable format
994 REAL_VALUE_TO_DECIMAL (r, "%.20g", dstr);
995 fprintf (stderr, "%s", dstr);
999 /* Target values are arrays of host longs. A long is guaranteed
1000 to be at least 32 bits wide. */
1002 /* 128-bit long double */
1009 unsigned EMUSHORT e[NE];
1013 endian (e, l, TFmode);
1016 /* 80-bit long double */
1023 unsigned EMUSHORT e[NE];
1027 endian (e, l, XFmode);
1035 unsigned EMUSHORT e[NE];
1039 endian (e, l, DFmode);
1046 unsigned EMUSHORT e[NE];
1051 endian (e, &l, SFmode);
1056 ereal_to_decimal (x, s)
1060 unsigned EMUSHORT e[NE];
1068 REAL_VALUE_TYPE x, y;
1070 unsigned EMUSHORT ex[NE], ey[NE];
1074 return (ecmp (ex, ey));
1081 unsigned EMUSHORT ex[NE];
1084 return (eisneg (ex));
1087 /* End of REAL_ARITHMETIC interface */
1090 Extended precision IEEE binary floating point arithmetic routines
1092 Numbers are stored in C language as arrays of 16-bit unsigned
1093 short integers. The arguments of the routines are pointers to
1096 External e type data structure, simulates Intel 8087 chip
1097 temporary real format but possibly with a larger significand:
1099 NE-1 significand words (least significant word first,
1100 most significant bit is normally set)
1101 exponent (value = EXONE for 1.0,
1102 top bit is the sign)
1105 Internal data structure of a number (a "word" is 16 bits):
1107 ei[0] sign word (0 for positive, 0xffff for negative)
1108 ei[1] biased exponent (value = EXONE for the number 1.0)
1109 ei[2] high guard word (always zero after normalization)
1111 to ei[NI-2] significand (NI-4 significand words,
1112 most significant word first,
1113 most significant bit is set)
1114 ei[NI-1] low guard word (0x8000 bit is rounding place)
1118 Routines for external format numbers
1120 asctoe (string, e) ASCII string to extended double e type
1121 asctoe64 (string, &d) ASCII string to long double
1122 asctoe53 (string, &d) ASCII string to double
1123 asctoe24 (string, &f) ASCII string to single
1124 asctoeg (string, e, prec) ASCII string to specified precision
1125 e24toe (&f, e) IEEE single precision to e type
1126 e53toe (&d, e) IEEE double precision to e type
1127 e64toe (&d, e) IEEE long double precision to e type
1128 e113toe (&d, e) 128-bit long double precision to e type
1129 eabs (e) absolute value
1130 eadd (a, b, c) c = b + a
1132 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1133 -1 if a < b, -2 if either a or b is a NaN.
1134 ediv (a, b, c) c = b / a
1135 efloor (a, b) truncate to integer, toward -infinity
1136 efrexp (a, exp, s) extract exponent and significand
1137 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1138 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1139 einfin (e) set e to infinity, leaving its sign alone
1140 eldexp (a, n, b) multiply by 2**n
1142 emul (a, b, c) c = b * a
1144 eround (a, b) b = nearest integer value to a
1145 esub (a, b, c) c = b - a
1146 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1147 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1148 e64toasc (&d, str, n) 80-bit long double to ASCII string
1149 e113toasc (&d, str, n) 128-bit long double to ASCII string
1150 etoasc (e, str, n) e to ASCII string, n digits after decimal
1151 etoe24 (e, &f) convert e type to IEEE single precision
1152 etoe53 (e, &d) convert e type to IEEE double precision
1153 etoe64 (e, &d) convert e type to IEEE long double precision
1154 ltoe (&l, e) HOST_WIDE_INT to e type
1155 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1156 eisneg (e) 1 if sign bit of e != 0, else 0
1157 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1158 or is infinite (IEEE)
1159 eisnan (e) 1 if e is a NaN
1162 Routines for internal format numbers
1164 eaddm (ai, bi) add significands, bi = bi + ai
1166 ecleazs (ei) set ei = 0 but leave its sign alone
1167 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1168 edivm (ai, bi) divide significands, bi = bi / ai
1169 emdnorm (ai,l,s,exp) normalize and round off
1170 emovi (a, ai) convert external a to internal ai
1171 emovo (ai, a) convert internal ai to external a
1172 emovz (ai, bi) bi = ai, low guard word of bi = 0
1173 emulm (ai, bi) multiply significands, bi = bi * ai
1174 enormlz (ei) left-justify the significand
1175 eshdn1 (ai) shift significand and guards down 1 bit
1176 eshdn8 (ai) shift down 8 bits
1177 eshdn6 (ai) shift down 16 bits
1178 eshift (ai, n) shift ai n bits up (or down if n < 0)
1179 eshup1 (ai) shift significand and guards up 1 bit
1180 eshup8 (ai) shift up 8 bits
1181 eshup6 (ai) shift up 16 bits
1182 esubm (ai, bi) subtract significands, bi = bi - ai
1183 eiisinf (ai) 1 if infinite
1184 eiisnan (ai) 1 if a NaN
1185 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1186 einan (ai) set ai = NaN
1187 eiinfin (ai) set ai = infinity
1189 The result is always normalized and rounded to NI-4 word precision
1190 after each arithmetic operation.
1192 Exception flags are NOT fully supported.
1194 Signaling NaN's are NOT supported; they are treated the same
1197 Define INFINITY for support of infinity; otherwise a
1198 saturation arithmetic is implemented.
1200 Define NANS for support of Not-a-Number items; otherwise the
1201 arithmetic will never produce a NaN output, and might be confused
1203 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1204 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1205 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1208 Denormals are always supported here where appropriate (e.g., not
1209 for conversion to DEC numbers). */
1211 /* Definitions for error codes that are passed to the common error handling
1214 For Digital Equipment PDP-11 and VAX computers, certain
1215 IBM systems, and others that use numbers with a 56-bit
1216 significand, the symbol DEC should be defined. In this
1217 mode, most floating point constants are given as arrays
1218 of octal integers to eliminate decimal to binary conversion
1219 errors that might be introduced by the compiler.
1221 For computers, such as IBM PC, that follow the IEEE
1222 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1223 Std 754-1985), the symbol IBMPC or MIEEE should be defined.
1224 These numbers have 53-bit significands. In this mode, constants
1225 are provided as arrays of hexadecimal 16 bit integers.
1227 To accommodate other types of computer arithmetic, all
1228 constants are also provided in a normal decimal radix
1229 which one can hope are correctly converted to a suitable
1230 format by the available C language compiler. To invoke
1231 this mode, the symbol UNK is defined.
1233 An important difference among these modes is a predefined
1234 set of machine arithmetic constants for each. The numbers
1235 MACHEP (the machine roundoff error), MAXNUM (largest number
1236 represented), and several other parameters are preset by
1237 the configuration symbol. Check the file const.c to
1238 ensure that these values are correct for your computer.
1240 For ANSI C compatibility, define ANSIC equal to 1. Currently
1241 this affects only the atan2 function and others that use it. */
1243 /* Constant definitions for math error conditions. */
1245 #define DOMAIN 1 /* argument domain error */
1246 #define SING 2 /* argument singularity */
1247 #define OVERFLOW 3 /* overflow range error */
1248 #define UNDERFLOW 4 /* underflow range error */
1249 #define TLOSS 5 /* total loss of precision */
1250 #define PLOSS 6 /* partial loss of precision */
1251 #define INVALID 7 /* NaN-producing operation */
1253 /* e type constants used by high precision check routines */
1255 #if LONG_DOUBLE_TYPE_SIZE == 128
1257 unsigned EMUSHORT ezero[NE] =
1258 {0x0000, 0x0000, 0x0000, 0x0000,
1259 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1260 extern unsigned EMUSHORT ezero[];
1263 unsigned EMUSHORT ehalf[NE] =
1264 {0x0000, 0x0000, 0x0000, 0x0000,
1265 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1266 extern unsigned EMUSHORT ehalf[];
1269 unsigned EMUSHORT eone[NE] =
1270 {0x0000, 0x0000, 0x0000, 0x0000,
1271 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1272 extern unsigned EMUSHORT eone[];
1275 unsigned EMUSHORT etwo[NE] =
1276 {0x0000, 0x0000, 0x0000, 0x0000,
1277 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1278 extern unsigned EMUSHORT etwo[];
1281 unsigned EMUSHORT e32[NE] =
1282 {0x0000, 0x0000, 0x0000, 0x0000,
1283 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1284 extern unsigned EMUSHORT e32[];
1286 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1287 unsigned EMUSHORT elog2[NE] =
1288 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1289 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1290 extern unsigned EMUSHORT elog2[];
1292 /* 1.41421356237309504880168872420969807856967187537695E0 */
1293 unsigned EMUSHORT esqrt2[NE] =
1294 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1295 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1296 extern unsigned EMUSHORT esqrt2[];
1298 /* 3.14159265358979323846264338327950288419716939937511E0 */
1299 unsigned EMUSHORT epi[NE] =
1300 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1301 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1302 extern unsigned EMUSHORT epi[];
1305 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1306 unsigned EMUSHORT ezero[NE] =
1307 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1308 unsigned EMUSHORT ehalf[NE] =
1309 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1310 unsigned EMUSHORT eone[NE] =
1311 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1312 unsigned EMUSHORT etwo[NE] =
1313 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1314 unsigned EMUSHORT e32[NE] =
1315 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1316 unsigned EMUSHORT elog2[NE] =
1317 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1318 unsigned EMUSHORT esqrt2[NE] =
1319 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1320 unsigned EMUSHORT epi[NE] =
1321 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1326 /* Control register for rounding precision.
1327 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1332 /* Clear out entire external format number. */
1336 register unsigned EMUSHORT *x;
1340 for (i = 0; i < NE; i++)
1346 /* Move external format number from a to b. */
1350 register unsigned EMUSHORT *a, *b;
1354 for (i = 0; i < NE; i++)
1359 /* Absolute value of external format number. */
1363 unsigned EMUSHORT x[];
1365 /* sign is top bit of last word of external format */
1366 x[NE - 1] &= 0x7fff;
1369 /* Negate external format number. */
1373 unsigned EMUSHORT x[];
1376 x[NE - 1] ^= 0x8000; /* Toggle the sign bit */
1381 /* Return 1 if sign bit of external format number is nonzero, else zero. */
1385 unsigned EMUSHORT x[];
1388 if (x[NE - 1] & 0x8000)
1395 /* Return 1 if external format number is infinity, else return zero. */
1399 unsigned EMUSHORT x[];
1406 if ((x[NE - 1] & 0x7fff) == 0x7fff)
1413 /* Check if e-type number is not a number. The bit pattern is one that we
1414 defined, so we know for sure how to detect it. */
1418 unsigned EMUSHORT x[];
1423 /* NaN has maximum exponent */
1424 if ((x[NE - 1] & 0x7fff) != 0x7fff)
1426 /* ... and non-zero significand field. */
1427 for (i = 0; i < NE - 1; i++)
1437 /* Fill external format number with infinity pattern (IEEE)
1438 or largest possible number (non-IEEE). */
1442 register unsigned EMUSHORT *x;
1447 for (i = 0; i < NE - 1; i++)
1451 for (i = 0; i < NE - 1; i++)
1480 /* Output an e-type NaN.
1481 This generates Intel's quiet NaN pattern for extended real.
1482 The exponent is 7fff, the leading mantissa word is c000. */
1486 register unsigned EMUSHORT *x;
1491 for (i = 0; i < NE - 2; i++)
1494 *x = (sign << 15) | 0x7fff;
1498 /* Move in external format number, converting it to internal format. */
1502 unsigned EMUSHORT *a, *b;
1504 register unsigned EMUSHORT *p, *q;
1508 p = a + (NE - 1); /* point to last word of external number */
1509 /* get the sign bit */
1514 /* get the exponent */
1516 *q++ &= 0x7fff; /* delete the sign bit */
1518 if ((*(q - 1) & 0x7fff) == 0x7fff)
1524 for (i = 3; i < NI; i++)
1530 for (i = 2; i < NI; i++)
1536 /* clear high guard word */
1538 /* move in the significand */
1539 for (i = 0; i < NE - 1; i++)
1541 /* clear low guard word */
1546 /* Move internal format number out, converting it to external format. */
1550 unsigned EMUSHORT *a, *b;
1552 register unsigned EMUSHORT *p, *q;
1553 unsigned EMUSHORT i;
1557 q = b + (NE - 1); /* point to output exponent */
1558 /* combine sign and exponent */
1561 *q-- = *p++ | 0x8000;
1565 if (*(p - 1) == 0x7fff)
1570 enan (b, eiisneg (a));
1578 /* skip over guard word */
1580 /* move the significand */
1581 for (j = 0; j < NE - 1; j++)
1585 /* Clear out internal format number. */
1589 register unsigned EMUSHORT *xi;
1593 for (i = 0; i < NI; i++)
1598 /* Same, but don't touch the sign. */
1602 register unsigned EMUSHORT *xi;
1607 for (i = 0; i < NI - 1; i++)
1613 /* Move internal format number from a to b. */
1617 register unsigned EMUSHORT *a, *b;
1621 for (i = 0; i < NI - 1; i++)
1623 /* clear low guard word */
1627 /* Generate internal format NaN.
1628 The explicit pattern for this is maximum exponent and
1629 top two significant bits set. */
1633 unsigned EMUSHORT x[];
1641 /* Return nonzero if internal format number is a NaN. */
1645 unsigned EMUSHORT x[];
1649 if ((x[E] & 0x7fff) == 0x7fff)
1651 for (i = M + 1; i < NI; i++)
1660 /* Return nonzero if sign of internal format number is nonzero. */
1664 unsigned EMUSHORT x[];
1670 /* Fill internal format number with infinity pattern.
1671 This has maximum exponent and significand all zeros. */
1675 unsigned EMUSHORT x[];
1682 /* Return nonzero if internal format number is infinite. */
1686 unsigned EMUSHORT x[];
1693 if ((x[E] & 0x7fff) == 0x7fff)
1699 /* Compare significands of numbers in internal format.
1700 Guard words are included in the comparison.
1708 register unsigned EMUSHORT *a, *b;
1712 a += M; /* skip up to significand area */
1714 for (i = M; i < NI; i++)
1722 if (*(--a) > *(--b))
1729 /* Shift significand down by 1 bit. */
1733 register unsigned EMUSHORT *x;
1735 register unsigned EMUSHORT bits;
1738 x += M; /* point to significand area */
1741 for (i = M; i < NI; i++)
1755 /* Shift significand up by 1 bit. */
1759 register unsigned EMUSHORT *x;
1761 register unsigned EMUSHORT bits;
1767 for (i = M; i < NI; i++)
1780 /* Shift significand down by 8 bits. */
1784 register unsigned EMUSHORT *x;
1786 register unsigned EMUSHORT newbyt, oldbyt;
1791 for (i = M; i < NI; i++)
1801 /* Shift significand up by 8 bits. */
1805 register unsigned EMUSHORT *x;
1808 register unsigned EMUSHORT newbyt, oldbyt;
1813 for (i = M; i < NI; i++)
1823 /* Shift significand up by 16 bits. */
1827 register unsigned EMUSHORT *x;
1830 register unsigned EMUSHORT *p;
1835 for (i = M; i < NI - 1; i++)
1841 /* Shift significand down by 16 bits. */
1845 register unsigned EMUSHORT *x;
1848 register unsigned EMUSHORT *p;
1853 for (i = M; i < NI - 1; i++)
1859 /* Add significands. x + y replaces y. */
1863 unsigned EMUSHORT *x, *y;
1865 register unsigned EMULONG a;
1872 for (i = M; i < NI; i++)
1874 a = (unsigned EMULONG) (*x) + (unsigned EMULONG) (*y) + carry;
1879 *y = (unsigned EMUSHORT) a;
1885 /* Subtract significands. y - x replaces y. */
1889 unsigned EMUSHORT *x, *y;
1898 for (i = M; i < NI; i++)
1900 a = (unsigned EMULONG) (*y) - (unsigned EMULONG) (*x) - carry;
1905 *y = (unsigned EMUSHORT) a;
1912 static unsigned EMUSHORT equot[NI];
1916 /* Radix 2 shift-and-add versions of multiply and divide */
1919 /* Divide significands */
1923 unsigned EMUSHORT den[], num[];
1926 register unsigned EMUSHORT *p, *q;
1927 unsigned EMUSHORT j;
1933 for (i = M; i < NI; i++)
1938 /* Use faster compare and subtraction if denominator has only 15 bits of
1944 for (i = M + 3; i < NI; i++)
1949 if ((den[M + 1] & 1) != 0)
1957 for (i = 0; i < NBITS + 2; i++)
1975 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
1976 bit + 1 roundoff bit. */
1981 for (i = 0; i < NBITS + 2; i++)
1983 if (ecmpm (den, num) <= 0)
1986 j = 1; /* quotient bit = 1 */
2000 /* test for nonzero remainder after roundoff bit */
2003 for (i = M; i < NI; i++)
2011 for (i = 0; i < NI; i++)
2017 /* Multiply significands */
2020 unsigned EMUSHORT a[], b[];
2022 unsigned EMUSHORT *p, *q;
2027 for (i = M; i < NI; i++)
2032 while (*p == 0) /* significand is not supposed to be zero */
2037 if ((*p & 0xff) == 0)
2045 for (i = 0; i < k; i++)
2049 /* remember if there were any nonzero bits shifted out */
2056 for (i = 0; i < NI; i++)
2059 /* return flag for lost nonzero bits */
2065 /* Radix 65536 versions of multiply and divide */
2068 /* Multiply significand of e-type number b
2069 by 16-bit quantity a, e-type result to c. */
2074 unsigned short b[], c[];
2076 register unsigned short *pp;
2077 register unsigned long carry;
2079 unsigned short p[NI];
2080 unsigned long aa, m;
2089 for (i=M+1; i<NI; i++)
2099 m = (unsigned long) aa * *ps--;
2100 carry = (m & 0xffff) + *pp;
2101 *pp-- = (unsigned short)carry;
2102 carry = (carry >> 16) + (m >> 16) + *pp;
2103 *pp = (unsigned short)carry;
2104 *(pp-1) = carry >> 16;
2107 for (i=M; i<NI; i++)
2112 /* Divide significands. Neither the numerator nor the denominator
2113 is permitted to have its high guard word nonzero. */
2117 unsigned short den[], num[];
2120 register unsigned short *p;
2122 unsigned short j, tdenm, tquot;
2123 unsigned short tprod[NI+1];
2129 for (i=M; i<NI; i++)
2135 for (i=M; i<NI; i++)
2137 /* Find trial quotient digit (the radix is 65536). */
2138 tnum = (((unsigned long) num[M]) << 16) + num[M+1];
2140 /* Do not execute the divide instruction if it will overflow. */
2141 if ((tdenm * 0xffffL) < tnum)
2144 tquot = tnum / tdenm;
2145 /* Multiply denominator by trial quotient digit. */
2146 m16m ((unsigned int)tquot, den, tprod);
2147 /* The quotient digit may have been overestimated. */
2148 if (ecmpm (tprod, num) > 0)
2152 if (ecmpm (tprod, num) > 0)
2162 /* test for nonzero remainder after roundoff bit */
2165 for (i=M; i<NI; i++)
2172 for (i=0; i<NI; i++)
2180 /* Multiply significands */
2183 unsigned short a[], b[];
2185 unsigned short *p, *q;
2186 unsigned short pprod[NI];
2192 for (i=M; i<NI; i++)
2198 for (i=M+1; i<NI; i++)
2206 m16m ((unsigned int) *p--, b, pprod);
2207 eaddm(pprod, equot);
2213 for (i=0; i<NI; i++)
2216 /* return flag for lost nonzero bits */
2222 /* Normalize and round off.
2224 The internal format number to be rounded is "s".
2225 Input "lost" indicates whether or not the number is exact.
2226 This is the so-called sticky bit.
2228 Input "subflg" indicates whether the number was obtained
2229 by a subtraction operation. In that case if lost is nonzero
2230 then the number is slightly smaller than indicated.
2232 Input "exp" is the biased exponent, which may be negative.
2233 the exponent field of "s" is ignored but is replaced by
2234 "exp" as adjusted by normalization and rounding.
2236 Input "rcntrl" is the rounding control.
2238 For future reference: In order for emdnorm to round off denormal
2239 significands at the right point, the input exponent must be
2240 adjusted to be the actual value it would have after conversion to
2241 the final floating point type. This adjustment has been
2242 implemented for all type conversions (etoe53, etc.) and decimal
2243 conversions, but not for the arithmetic functions (eadd, etc.).
2244 Data types having standard 15-bit exponents are not affected by
2245 this, but SFmode and DFmode are affected. For example, ediv with
2246 rndprc = 24 will not round correctly to 24-bit precision if the
2247 result is denormal. */
2249 static int rlast = -1;
2251 static unsigned EMUSHORT rmsk = 0;
2252 static unsigned EMUSHORT rmbit = 0;
2253 static unsigned EMUSHORT rebit = 0;
2255 static unsigned EMUSHORT rbit[NI];
2258 emdnorm (s, lost, subflg, exp, rcntrl)
2259 unsigned EMUSHORT s[];
2266 unsigned EMUSHORT r;
2271 /* a blank significand could mean either zero or infinity. */
2284 if ((j > NBITS) && (exp < 32767))
2292 if (exp > (EMULONG) (-NBITS - 1))
2305 /* Round off, unless told not to by rcntrl. */
2308 /* Set up rounding parameters if the control register changed. */
2309 if (rndprc != rlast)
2316 rw = NI - 1; /* low guard word */
2336 /* For DEC or IBM arithmetic */
2363 /* Shift down 1 temporarily if the data structure has an implied
2364 most significant bit and the number is denormal. */
2365 if ((exp <= 0) && (rndprc != 64) && (rndprc != NBITS))
2367 lost |= s[NI - 1] & 1;
2370 /* Clear out all bits below the rounding bit,
2371 remembering in r if any were nonzero. */
2385 if ((r & rmbit) != 0)
2390 { /* round to even */
2391 if ((s[re] & rebit) == 0)
2403 if ((exp <= 0) && (rndprc != 64) && (rndprc != NBITS))
2408 { /* overflow on roundoff */
2421 for (i = 2; i < NI - 1; i++)
2424 warning ("floating point overflow");
2428 for (i = M + 1; i < NI - 1; i++)
2431 if ((rndprc < 64) || (rndprc == 113))
2446 s[1] = (unsigned EMUSHORT) exp;
2451 /* Subtract external format numbers. */
2453 static int subflg = 0;
2457 unsigned EMUSHORT *a, *b, *c;
2471 /* Infinity minus infinity is a NaN.
2472 Test for subtracting infinities of the same sign. */
2473 if (eisinf (a) && eisinf (b)
2474 && ((eisneg (a) ^ eisneg (b)) == 0))
2476 mtherr ("esub", INVALID);
2490 unsigned EMUSHORT *a, *b, *c;
2494 /* NaN plus anything is a NaN. */
2505 /* Infinity minus infinity is a NaN.
2506 Test for adding infinities of opposite signs. */
2507 if (eisinf (a) && eisinf (b)
2508 && ((eisneg (a) ^ eisneg (b)) != 0))
2510 mtherr ("esub", INVALID);
2521 unsigned EMUSHORT *a, *b, *c;
2523 unsigned EMUSHORT ai[NI], bi[NI], ci[NI];
2525 EMULONG lt, lta, ltb;
2546 /* compare exponents */
2551 { /* put the larger number in bi */
2561 if (lt < (EMULONG) (-NBITS - 1))
2562 goto done; /* answer same as larger addend */
2564 lost = eshift (ai, k); /* shift the smaller number down */
2568 /* exponents were the same, so must compare significands */
2571 { /* the numbers are identical in magnitude */
2572 /* if different signs, result is zero */
2578 /* if same sign, result is double */
2579 /* double denomalized tiny number */
2580 if ((bi[E] == 0) && ((bi[3] & 0x8000) == 0))
2585 /* add 1 to exponent unless both are zero! */
2586 for (j = 1; j < NI - 1; j++)
2590 /* This could overflow, but let emovo take care of that. */
2595 bi[E] = (unsigned EMUSHORT) ltb;
2599 { /* put the larger number in bi */
2615 emdnorm (bi, lost, subflg, ltb, 64);
2627 unsigned EMUSHORT *a, *b, *c;
2629 unsigned EMUSHORT ai[NI], bi[NI];
2631 EMULONG lt, lta, ltb;
2634 /* Return any NaN input. */
2645 /* Zero over zero, or infinity over infinity, is a NaN. */
2646 if (((ecmp (a, ezero) == 0) && (ecmp (b, ezero) == 0))
2647 || (eisinf (a) && eisinf (b)))
2649 mtherr ("ediv", INVALID);
2650 enan (c, eisneg (a) ^ eisneg (b));
2654 /* Infinity over anything else is infinity. */
2658 if (eisneg (a) ^ eisneg (b))
2659 *(c + (NE - 1)) = 0x8000;
2661 *(c + (NE - 1)) = 0;
2665 /* Anything else over infinity is zero. */
2677 { /* See if numerator is zero. */
2678 for (i = 1; i < NI - 1; i++)
2682 ltb -= enormlz (bi);
2692 { /* possible divide by zero */
2693 for (i = 1; i < NI - 1; i++)
2697 lta -= enormlz (ai);
2702 *(c + (NE - 1)) = 0;
2704 *(c + (NE - 1)) = 0x8000;
2705 /* Divide by zero is not an invalid operation.
2706 It is a divide-by-zero operation! */
2708 mtherr ("ediv", SING);
2714 /* calculate exponent */
2715 lt = ltb - lta + EXONE;
2716 emdnorm (bi, i, 0, lt, 64);
2731 unsigned EMUSHORT *a, *b, *c;
2733 unsigned EMUSHORT ai[NI], bi[NI];
2735 EMULONG lt, lta, ltb;
2738 /* NaN times anything is the same NaN. */
2749 /* Zero times infinity is a NaN. */
2750 if ((eisinf (a) && (ecmp (b, ezero) == 0))
2751 || (eisinf (b) && (ecmp (a, ezero) == 0)))
2753 mtherr ("emul", INVALID);
2754 enan (c, eisneg (a) ^ eisneg (b));
2758 /* Infinity times anything else is infinity. */
2760 if (eisinf (a) || eisinf (b))
2762 if (eisneg (a) ^ eisneg (b))
2763 *(c + (NE - 1)) = 0x8000;
2765 *(c + (NE - 1)) = 0;
2776 for (i = 1; i < NI - 1; i++)
2780 lta -= enormlz (ai);
2791 for (i = 1; i < NI - 1; i++)
2795 ltb -= enormlz (bi);
2804 /* Multiply significands */
2806 /* calculate exponent */
2807 lt = lta + ltb - (EXONE - 1);
2808 emdnorm (bi, j, 0, lt, 64);
2809 /* calculate sign of product */
2820 /* Convert IEEE double precision to e type. */
2824 unsigned EMUSHORT *pe, *y;
2828 dectoe (pe, y); /* see etodec.c */
2833 ibmtoe (pe, y, DFmode);
2836 register unsigned EMUSHORT r;
2837 register unsigned EMUSHORT *e, *p;
2838 unsigned EMUSHORT yy[NI];
2842 denorm = 0; /* flag if denormalized number */
2851 yy[M] = (r & 0x0f) | 0x10;
2852 r &= ~0x800f; /* strip sign and 4 significand bits */
2858 if (((pe[3] & 0xf) != 0) || (pe[2] != 0)
2859 || (pe[1] != 0) || (pe[0] != 0))
2861 enan (y, yy[0] != 0);
2865 if (((pe[0] & 0xf) != 0) || (pe[1] != 0)
2866 || (pe[2] != 0) || (pe[3] != 0))
2868 enan (y, yy[0] != 0);
2879 #endif /* INFINITY */
2881 /* If zero exponent, then the significand is denormalized.
2882 So take back the understood high significand bit. */
2905 { /* if zero exponent, then normalize the significand */
2906 if ((k = enormlz (yy)) > NBITS)
2909 yy[E] -= (unsigned EMUSHORT) (k - 1);
2912 #endif /* not IBM */
2913 #endif /* not DEC */
2918 unsigned EMUSHORT *pe, *y;
2920 unsigned EMUSHORT yy[NI];
2921 unsigned EMUSHORT *e, *p, *q;
2926 for (i = 0; i < NE - 5; i++)
2929 for (i = 0; i < 5; i++)
2932 /* This precision is not ordinarily supported on DEC or IBM. */
2934 for (i = 0; i < 5; i++)
2938 p = &yy[0] + (NE - 1);
2941 for (i = 0; i < 5; i++)
2945 p = &yy[0] + (NE - 1);
2948 for (i = 0; i < 4; i++)
2958 for (i = 0; i < 4; i++)
2962 enan (y, (*p & 0x8000) != 0);
2967 for (i = 1; i <= 4; i++)
2971 enan (y, (*p & 0x8000) != 0);
2983 #endif /* INFINITY */
2984 for (i = 0; i < NE; i++)
2991 unsigned EMUSHORT *pe, *y;
2993 register unsigned EMUSHORT r;
2994 unsigned EMUSHORT *e, *p;
2995 unsigned EMUSHORT yy[NI];
3014 for (i = 0; i < 7; i++)
3018 enan (y, yy[0] != 0);
3023 for (i = 1; i < 8; i++)
3027 enan (y, yy[0] != 0);
3039 #endif /* INFINITY */
3043 for (i = 0; i < 7; i++)
3048 for (i = 0; i < 7; i++)
3051 /* If denormal, remove the implied bit; else shift down 1. */
3065 /* Convert IEEE single precision to e type. */
3069 unsigned EMUSHORT *pe, *y;
3073 ibmtoe (pe, y, SFmode);
3076 register unsigned EMUSHORT r;
3077 register unsigned EMUSHORT *e, *p;
3078 unsigned EMUSHORT yy[NI];
3082 denorm = 0; /* flag if denormalized number */
3094 yy[M] = (r & 0x7f) | 0200;
3095 r &= ~0x807f; /* strip sign and 7 significand bits */
3101 if (((pe[0] & 0x7f) != 0) || (pe[1] != 0))
3103 enan (y, yy[0] != 0);
3107 if (((pe[1] & 0x7f) != 0) || (pe[0] != 0))
3109 enan (y, yy[0] != 0);
3120 #endif /* INFINITY */
3122 /* If zero exponent, then the significand is denormalized.
3123 So take back the understood high significand bit. */
3144 { /* if zero exponent, then normalize the significand */
3145 if ((k = enormlz (yy)) > NBITS)
3148 yy[E] -= (unsigned EMUSHORT) (k - 1);
3151 #endif /* not IBM */
3157 unsigned EMUSHORT *x, *e;
3159 unsigned EMUSHORT xi[NI];
3166 make_nan (e, eisneg (x), TFmode);
3171 exp = (EMULONG) xi[E];
3176 /* round off to nearest or even */
3179 emdnorm (xi, 0, 0, exp, 64);
3185 /* Move out internal format to ieee long double */
3189 unsigned EMUSHORT *a, *b;
3191 register unsigned EMUSHORT *p, *q;
3192 unsigned EMUSHORT i;
3197 make_nan (b, eiisneg (a), TFmode);
3205 q = b + 7; /* point to output exponent */
3208 /* If not denormal, delete the implied bit. */
3213 /* combine sign and exponent */
3217 *q++ = *p++ | 0x8000;
3222 *q-- = *p++ | 0x8000;
3226 /* skip over guard word */
3228 /* move the significand */
3230 for (i = 0; i < 7; i++)
3233 for (i = 0; i < 7; i++)
3240 unsigned EMUSHORT *x, *e;
3242 unsigned EMUSHORT xi[NI];
3249 make_nan (e, eisneg (x), XFmode);
3254 /* adjust exponent for offset */
3255 exp = (EMULONG) xi[E];
3260 /* round off to nearest or even */
3263 emdnorm (xi, 0, 0, exp, 64);
3270 /* Move out internal format to ieee long double. */
3274 unsigned EMUSHORT *a, *b;
3276 register unsigned EMUSHORT *p, *q;
3277 unsigned EMUSHORT i;
3282 make_nan (b, eiisneg (a), XFmode);
3287 #if defined(MIEEE) || defined(IBM)
3290 q = b + 4; /* point to output exponent */
3291 #if LONG_DOUBLE_TYPE_SIZE == 96
3292 /* Clear the last two bytes of 12-byte Intel format */
3297 /* combine sign and exponent */
3299 #if defined(MIEEE) || defined(IBM)
3301 *q++ = *p++ | 0x8000;
3307 *q-- = *p++ | 0x8000;
3311 /* skip over guard word */
3313 /* move the significand */
3314 #if defined(MIEEE) || defined(IBM)
3315 for (i = 0; i < 4; i++)
3318 for (i = 0; i < 4; i++)
3324 /* e type to IEEE double precision. */
3330 unsigned EMUSHORT *x, *e;
3332 etodec (x, e); /* see etodec.c */
3337 unsigned EMUSHORT *x, *y;
3347 unsigned EMUSHORT *x, *e;
3349 etoibm (x, e, DFmode);
3354 unsigned EMUSHORT *x, *y;
3356 toibm (x, y, DFmode);
3359 #else /* it's neither DEC nor IBM */
3363 unsigned EMUSHORT *x, *e;
3365 unsigned EMUSHORT xi[NI];
3372 make_nan (e, eisneg (x), DFmode);
3377 /* adjust exponent for offsets */
3378 exp = (EMULONG) xi[E] - (EXONE - 0x3ff);
3383 /* round off to nearest or even */
3386 emdnorm (xi, 0, 0, exp, 64);
3395 unsigned EMUSHORT *x, *y;
3397 unsigned EMUSHORT i;
3398 unsigned EMUSHORT *p;
3403 make_nan (y, eiisneg (x), DFmode);
3411 *y = 0; /* output high order */
3413 *y = 0x8000; /* output sign bit */
3416 if (i >= (unsigned int) 2047)
3417 { /* Saturate at largest number less than infinity. */
3432 *y |= (unsigned EMUSHORT) 0x7fef;
3456 i |= *p++ & (unsigned EMUSHORT) 0x0f; /* *p = xi[M] */
3457 *y |= (unsigned EMUSHORT) i; /* high order output already has sign bit set */
3471 #endif /* not IBM */
3472 #endif /* not DEC */
3476 /* e type to IEEE single precision. */
3482 unsigned EMUSHORT *x, *e;
3484 etoibm (x, e, SFmode);
3489 unsigned EMUSHORT *x, *y;
3491 toibm (x, y, SFmode);
3498 unsigned EMUSHORT *x, *e;
3501 unsigned EMUSHORT xi[NI];
3507 make_nan (e, eisneg (x), SFmode);
3512 /* adjust exponent for offsets */
3513 exp = (EMULONG) xi[E] - (EXONE - 0177);
3518 /* round off to nearest or even */
3521 emdnorm (xi, 0, 0, exp, 64);
3529 unsigned EMUSHORT *x, *y;
3531 unsigned EMUSHORT i;
3532 unsigned EMUSHORT *p;
3537 make_nan (y, eiisneg (x), SFmode);
3548 *y = 0; /* output high order */
3550 *y = 0x8000; /* output sign bit */
3553 /* Handle overflow cases. */
3557 *y |= (unsigned EMUSHORT) 0x7f80;
3568 #else /* no INFINITY */
3569 *y |= (unsigned EMUSHORT) 0x7f7f;
3583 #endif /* no INFINITY */
3595 i |= *p++ & (unsigned EMUSHORT) 0x7f; /* *p = xi[M] */
3596 *y |= i; /* high order output already has sign bit set */
3608 #endif /* not IBM */
3610 /* Compare two e type numbers.
3614 -2 if either a or b is a NaN. */
3618 unsigned EMUSHORT *a, *b;
3620 unsigned EMUSHORT ai[NI], bi[NI];
3621 register unsigned EMUSHORT *p, *q;
3626 if (eisnan (a) || eisnan (b))
3635 { /* the signs are different */
3637 for (i = 1; i < NI - 1; i++)
3651 /* both are the same sign */
3666 return (0); /* equality */
3672 if (*(--p) > *(--q))
3673 return (msign); /* p is bigger */
3675 return (-msign); /* p is littler */
3681 /* Find nearest integer to x = floor (x + 0.5). */
3685 unsigned EMUSHORT *x, *y;
3694 /* Convert HOST_WIDE_INT to e type. */
3699 unsigned EMUSHORT *y;
3701 unsigned EMUSHORT yi[NI];
3702 unsigned HOST_WIDE_INT ll;
3708 /* make it positive */
3709 ll = (unsigned HOST_WIDE_INT) (-(*lp));
3710 yi[0] = 0xffff; /* put correct sign in the e type number */
3714 ll = (unsigned HOST_WIDE_INT) (*lp);
3716 /* move the long integer to yi significand area */
3717 #if HOST_BITS_PER_WIDE_INT == 64
3718 yi[M] = (unsigned EMUSHORT) (ll >> 48);
3719 yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
3720 yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
3721 yi[M + 3] = (unsigned EMUSHORT) ll;
3722 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
3724 yi[M] = (unsigned EMUSHORT) (ll >> 16);
3725 yi[M + 1] = (unsigned EMUSHORT) ll;
3726 yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
3729 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
3730 ecleaz (yi); /* it was zero */
3732 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
3733 emovo (yi, y); /* output the answer */
3736 /* Convert unsigned HOST_WIDE_INT to e type. */
3740 unsigned HOST_WIDE_INT *lp;
3741 unsigned EMUSHORT *y;
3743 unsigned EMUSHORT yi[NI];
3744 unsigned HOST_WIDE_INT ll;
3750 /* move the long integer to ayi significand area */
3751 #if HOST_BITS_PER_WIDE_INT == 64
3752 yi[M] = (unsigned EMUSHORT) (ll >> 48);
3753 yi[M + 1] = (unsigned EMUSHORT) (ll >> 32);
3754 yi[M + 2] = (unsigned EMUSHORT) (ll >> 16);
3755 yi[M + 3] = (unsigned EMUSHORT) ll;
3756 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
3758 yi[M] = (unsigned EMUSHORT) (ll >> 16);
3759 yi[M + 1] = (unsigned EMUSHORT) ll;
3760 yi[E] = EXONE + 15; /* exponent if normalize shift count were 0 */
3763 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
3764 ecleaz (yi); /* it was zero */
3766 yi[E] -= (unsigned EMUSHORT) k; /* subtract shift count from exponent */
3767 emovo (yi, y); /* output the answer */
3771 /* Find signed HOST_WIDE_INT integer and floating point fractional
3772 parts of e-type (packed internal format) floating point input X.
3773 The integer output I has the sign of the input, except that
3774 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
3775 The output e-type fraction FRAC is the positive fractional
3780 unsigned EMUSHORT *x;
3782 unsigned EMUSHORT *frac;
3784 unsigned EMUSHORT xi[NI];
3786 unsigned HOST_WIDE_INT ll;
3789 k = (int) xi[E] - (EXONE - 1);
3792 /* if exponent <= 0, integer = 0 and real output is fraction */
3797 if (k > (HOST_BITS_PER_WIDE_INT - 1))
3799 /* long integer overflow: output large integer
3800 and correct fraction */
3802 *i = ((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1);
3805 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
3806 /* In this case, let it overflow and convert as if unsigned. */
3807 euifrac (x, &ll, frac);
3808 *i = (HOST_WIDE_INT) ll;
3811 /* In other cases, return the largest positive integer. */
3812 *i = (((unsigned HOST_WIDE_INT) 1) << (HOST_BITS_PER_WIDE_INT - 1)) - 1;
3817 warning ("overflow on truncation to integer");
3821 /* Shift more than 16 bits: first shift up k-16 mod 16,
3822 then shift up by 16's. */
3823 j = k - ((k >> 4) << 4);
3830 ll = (ll << 16) | xi[M];
3832 while ((k -= 16) > 0);
3839 /* shift not more than 16 bits */
3841 *i = (HOST_WIDE_INT) xi[M] & 0xffff;
3848 if ((k = enormlz (xi)) > NBITS)
3851 xi[E] -= (unsigned EMUSHORT) k;
3857 /* Find unsigned HOST_WIDE_INT integer and floating point fractional parts.
3858 A negative e type input yields integer output = 0
3859 but correct fraction. */
3862 euifrac (x, i, frac)
3863 unsigned EMUSHORT *x;
3864 unsigned HOST_WIDE_INT *i;
3865 unsigned EMUSHORT *frac;
3867 unsigned HOST_WIDE_INT ll;
3868 unsigned EMUSHORT xi[NI];
3872 k = (int) xi[E] - (EXONE - 1);
3875 /* if exponent <= 0, integer = 0 and argument is fraction */
3880 if (k > HOST_BITS_PER_WIDE_INT)
3882 /* Long integer overflow: output large integer
3883 and correct fraction.
3884 Note, the BSD microvax compiler says that ~(0UL)
3885 is a syntax error. */
3889 warning ("overflow on truncation to unsigned integer");
3893 /* Shift more than 16 bits: first shift up k-16 mod 16,
3894 then shift up by 16's. */
3895 j = k - ((k >> 4) << 4);
3902 ll = (ll << 16) | xi[M];
3904 while ((k -= 16) > 0);
3909 /* shift not more than 16 bits */
3911 *i = (HOST_WIDE_INT) xi[M] & 0xffff;
3914 if (xi[0]) /* A negative value yields unsigned integer 0. */
3920 if ((k = enormlz (xi)) > NBITS)
3923 xi[E] -= (unsigned EMUSHORT) k;
3930 /* Shift significand area up or down by the number of bits given by SC. */
3934 unsigned EMUSHORT *x;
3937 unsigned EMUSHORT lost;
3938 unsigned EMUSHORT *p;
3951 lost |= *p; /* remember lost bits */
3992 return ((int) lost);
3997 /* Shift normalize the significand area pointed to by argument.
3998 Shift count (up = positive) is returned. */
4002 unsigned EMUSHORT x[];
4004 register unsigned EMUSHORT *p;
4013 return (0); /* already normalized */
4019 /* With guard word, there are NBITS+16 bits available.
4020 Return true if all are zero. */
4024 /* see if high byte is zero */
4025 while ((*p & 0xff00) == 0)
4030 /* now shift 1 bit at a time */
4031 while ((*p & 0x8000) == 0)
4037 mtherr ("enormlz", UNDERFLOW);
4043 /* Normalize by shifting down out of the high guard word
4044 of the significand */
4059 mtherr ("enormlz", OVERFLOW);
4069 /* Convert e type number to decimal format ASCII string.
4070 The constants are for 64 bit precision. */
4075 #if LONG_DOUBLE_TYPE_SIZE == 128
4076 static unsigned EMUSHORT etens[NTEN + 1][NE] =
4078 {0x6576, 0x4a92, 0x804a, 0x153f,
4079 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4080 {0x6a32, 0xce52, 0x329a, 0x28ce,
4081 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4082 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4083 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4084 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4085 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4086 {0x851e, 0xeab7, 0x98fe, 0x901b,
4087 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4088 {0x0235, 0x0137, 0x36b1, 0x336c,
4089 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4090 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4091 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4092 {0x0000, 0x0000, 0x0000, 0x0000,
4093 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4094 {0x0000, 0x0000, 0x0000, 0x0000,
4095 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4096 {0x0000, 0x0000, 0x0000, 0x0000,
4097 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4098 {0x0000, 0x0000, 0x0000, 0x0000,
4099 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4100 {0x0000, 0x0000, 0x0000, 0x0000,
4101 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4102 {0x0000, 0x0000, 0x0000, 0x0000,
4103 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4106 static unsigned EMUSHORT emtens[NTEN + 1][NE] =
4108 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4109 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4110 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4111 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4112 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4113 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4114 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4115 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4116 {0xa23e, 0x5308, 0xfefb, 0x1155,
4117 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4118 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4119 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4120 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4121 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4122 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4123 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4124 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4125 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4126 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4127 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4128 {0xc155, 0xa4a8, 0x404e, 0x6113,
4129 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4130 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4131 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4132 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4133 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4136 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4137 static unsigned EMUSHORT etens[NTEN + 1][NE] =
4139 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4140 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4141 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4142 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4143 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4144 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4145 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4146 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4147 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4148 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4149 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4150 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4151 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4154 static unsigned EMUSHORT emtens[NTEN + 1][NE] =
4156 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4157 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4158 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4159 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4160 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4161 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4162 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4163 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4164 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4165 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4166 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4167 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4168 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4173 e24toasc (x, string, ndigs)
4174 unsigned EMUSHORT x[];
4178 unsigned EMUSHORT w[NI];
4181 etoasc (w, string, ndigs);
4186 e53toasc (x, string, ndigs)
4187 unsigned EMUSHORT x[];
4191 unsigned EMUSHORT w[NI];
4194 etoasc (w, string, ndigs);
4199 e64toasc (x, string, ndigs)
4200 unsigned EMUSHORT x[];
4204 unsigned EMUSHORT w[NI];
4207 etoasc (w, string, ndigs);
4211 e113toasc (x, string, ndigs)
4212 unsigned EMUSHORT x[];
4216 unsigned EMUSHORT w[NI];
4219 etoasc (w, string, ndigs);
4223 static char wstring[80]; /* working storage for ASCII output */
4226 etoasc (x, string, ndigs)
4227 unsigned EMUSHORT x[];
4232 unsigned EMUSHORT y[NI], t[NI], u[NI], w[NI];
4233 unsigned EMUSHORT *p, *r, *ten;
4234 unsigned EMUSHORT sign;
4235 int i, j, k, expon, rndsav;
4237 unsigned EMUSHORT m;
4248 sprintf (wstring, " NaN ");
4252 rndprc = NBITS; /* set to full precision */
4253 emov (x, y); /* retain external format */
4254 if (y[NE - 1] & 0x8000)
4257 y[NE - 1] &= 0x7fff;
4264 ten = &etens[NTEN][0];
4266 /* Test for zero exponent */
4269 for (k = 0; k < NE - 1; k++)
4272 goto tnzro; /* denormalized number */
4274 goto isone; /* legal all zeros */
4278 /* Test for infinity. */
4279 if (y[NE - 1] == 0x7fff)
4282 sprintf (wstring, " -Infinity ");
4284 sprintf (wstring, " Infinity ");
4288 /* Test for exponent nonzero but significand denormalized.
4289 * This is an error condition.
4291 if ((y[NE - 1] != 0) && ((y[NE - 2] & 0x8000) == 0))
4293 mtherr ("etoasc", DOMAIN);
4294 sprintf (wstring, "NaN");
4298 /* Compare to 1.0 */
4307 { /* Number is greater than 1 */
4308 /* Convert significand to an integer and strip trailing decimal zeros. */
4310 u[NE - 1] = EXONE + NBITS - 1;
4312 p = &etens[NTEN - 4][0];
4318 for (j = 0; j < NE - 1; j++)
4331 /* Rescale from integer significand */
4332 u[NE - 1] += y[NE - 1] - (unsigned int) (EXONE + NBITS - 1);
4334 /* Find power of 10 */
4338 /* An unordered compare result shouldn't happen here. */
4339 while (ecmp (ten, u) <= 0)
4341 if (ecmp (p, u) <= 0)
4354 { /* Number is less than 1.0 */
4355 /* Pad significand with trailing decimal zeros. */
4358 while ((y[NE - 2] & 0x8000) == 0)
4367 for (i = 0; i < NDEC + 1; i++)
4369 if ((w[NI - 1] & 0x7) != 0)
4371 /* multiply by 10 */
4384 if (eone[NE - 1] <= u[1])
4396 while (ecmp (eone, w) > 0)
4398 if (ecmp (p, w) >= 0)
4413 /* Find the first (leading) digit. */
4419 digit = equot[NI - 1];
4420 while ((digit == 0) && (ecmp (y, ezero) != 0))
4428 digit = equot[NI - 1];
4436 /* Examine number of digits requested by caller. */
4454 *s++ = (char)digit + '0';
4457 /* Generate digits after the decimal point. */
4458 for (k = 0; k <= ndigs; k++)
4460 /* multiply current number by 10, without normalizing */
4467 *s++ = (char) equot[NI - 1] + '0';
4469 digit = equot[NI - 1];
4472 /* round off the ASCII string */
4475 /* Test for critical rounding case in ASCII output. */
4479 if (ecmp (t, ezero) != 0)
4480 goto roun; /* round to nearest */
4481 if ((*(s - 1) & 1) == 0)
4482 goto doexp; /* round to even */
4484 /* Round up and propagate carry-outs */
4488 /* Carry out to most significant digit? */
4495 /* Most significant digit carries to 10? */
4503 /* Round up and carry out from less significant digits */
4515 sprintf (ss, "e+%d", expon);
4517 sprintf (ss, "e%d", expon);
4519 sprintf (ss, "e%d", expon);
4522 /* copy out the working string */
4525 while (*ss == ' ') /* strip possible leading space */
4527 while ((*s++ = *ss++) != '\0')
4532 /* Convert ASCII string to quadruple precision floating point
4534 Numeric input is free field decimal number with max of 15 digits with or
4535 without decimal point entered as ASCII from teletype. Entering E after
4536 the number followed by a second number causes the second number to be
4537 interpreted as a power of 10 to be multiplied by the first number
4538 (i.e., "scientific" notation). */
4540 /* ASCII to single */
4545 unsigned EMUSHORT *y;
4551 /* ASCII to double */
4556 unsigned EMUSHORT *y;
4558 #if defined(DEC) || defined(IBM)
4566 /* ASCII to long double */
4571 unsigned EMUSHORT *y;
4576 /* ASCII to 128-bit long double */
4581 unsigned EMUSHORT *y;
4583 asctoeg (s, y, 113);
4586 /* ASCII to super double */
4591 unsigned EMUSHORT *y;
4593 asctoeg (s, y, NBITS);
4597 /* ASCII to e type, with specified rounding precision = oprec. */
4600 asctoeg (ss, y, oprec)
4602 unsigned EMUSHORT *y;
4605 unsigned EMUSHORT yy[NI], xt[NI], tt[NI];
4606 int esign, decflg, sgnflg, nexp, exp, prec, lost;
4607 int k, trail, c, rndsav;
4609 unsigned EMUSHORT nsign, *p;
4610 char *sp, *s, *lstr;
4612 /* Copy the input string. */
4613 lstr = (char *) alloca (strlen (ss) + 1);
4615 while (*s == ' ') /* skip leading spaces */
4618 while ((*sp++ = *s++) != '\0')
4623 rndprc = NBITS; /* Set to full precision */
4636 if ((k >= 0) && (k <= 9))
4638 /* Ignore leading zeros */
4639 if ((prec == 0) && (decflg == 0) && (k == 0))
4641 /* Identify and strip trailing zeros after the decimal point. */
4642 if ((trail == 0) && (decflg != 0))
4645 while ((*sp >= '0') && (*sp <= '9'))
4647 /* Check for syntax error */
4649 if ((c != 'e') && (c != 'E') && (c != '\0')
4650 && (c != '\n') && (c != '\r') && (c != ' ')
4661 /* If enough digits were given to more than fill up the yy register,
4662 continuing until overflow into the high guard word yy[2]
4663 guarantees that there will be a roundoff bit at the top
4664 of the low guard word after normalization. */
4669 nexp += 1; /* count digits after decimal point */
4670 eshup1 (yy); /* multiply current number by 10 */
4676 xt[NI - 2] = (unsigned EMUSHORT) k;
4681 /* Mark any lost non-zero digit. */
4683 /* Count lost digits before the decimal point. */
4698 case '.': /* decimal point */
4728 mtherr ("asctoe", DOMAIN);
4737 /* Exponent interpretation */
4743 /* check for + or - */
4751 while ((*s >= '0') && (*s <= '9'))
4755 if (exp > -(MINDECEXP))
4765 if (exp > MAXDECEXP)
4769 yy[E] = 0x7fff; /* infinity */
4772 if (exp < MINDECEXP)
4781 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
4782 while ((nexp > 0) && (yy[2] == 0))
4794 if ((k = enormlz (yy)) > NBITS)
4799 lexp = (EXONE - 1 + NBITS) - k;
4800 emdnorm (yy, lost, 0, lexp, 64);
4802 /* Convert to external format:
4804 Multiply by 10**nexp. If precision is 64 bits,
4805 the maximum relative error incurred in forming 10**n
4806 for 0 <= n <= 324 is 8.2e-20, at 10**180.
4807 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
4808 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
4823 /* Punt. Can't handle this without 2 divides. */
4824 emovi (etens[0], tt);
4831 p = &etens[NTEN][0];
4841 while (exp <= MAXP);
4859 /* Round and convert directly to the destination type */
4861 lexp -= EXONE - 0x3ff;
4863 else if (oprec == 24 || oprec == 56)
4864 lexp -= EXONE - (0x41 << 2);
4866 else if (oprec == 24)
4867 lexp -= EXONE - 0177;
4870 else if (oprec == 56)
4871 lexp -= EXONE - 0201;
4874 emdnorm (yy, k, 0, lexp, 64);
4884 todec (yy, y); /* see etodec.c */
4889 toibm (yy, y, DFmode);
4912 /* y = largest integer not greater than x (truncated toward minus infinity) */
4914 static unsigned EMUSHORT bmask[] =
4937 unsigned EMUSHORT x[], y[];
4939 register unsigned EMUSHORT *p;
4941 unsigned EMUSHORT f[NE];
4943 emov (x, f); /* leave in external format */
4944 expon = (int) f[NE - 1];
4945 e = (expon & 0x7fff) - (EXONE - 1);
4951 /* number of bits to clear out */
4963 /* clear the remaining bits */
4965 /* truncate negatives toward minus infinity */
4968 if ((unsigned EMUSHORT) expon & (unsigned EMUSHORT) 0x8000)
4970 for (i = 0; i < NE - 1; i++)
4982 /* Returns s and exp such that s * 2**exp = x and .5 <= s < 1.
4983 For example, 1.1 = 0.55 * 2**1
4984 Handles denormalized numbers properly using long integer exp. */
4988 unsigned EMUSHORT x[];
4990 unsigned EMUSHORT s[];
4992 unsigned EMUSHORT xi[NI];
4996 li = (EMULONG) ((EMUSHORT) xi[1]);
5004 *exp = (int) (li - 0x3ffe);
5009 /* Return y = x * 2**pwr2. */
5013 unsigned EMUSHORT x[];
5015 unsigned EMUSHORT y[];
5017 unsigned EMUSHORT xi[NI];
5025 emdnorm (xi, i, i, li, 64);
5030 /* c = remainder after dividing b by a
5031 Least significant integer quotient bits left in equot[]. */
5035 unsigned EMUSHORT a[], b[], c[];
5037 unsigned EMUSHORT den[NI], num[NI];
5041 || (ecmp (a, ezero) == 0)
5049 if (ecmp (a, ezero) == 0)
5051 mtherr ("eremain", SING);
5057 eiremain (den, num);
5058 /* Sign of remainder = sign of quotient */
5068 unsigned EMUSHORT den[], num[];
5071 unsigned EMUSHORT j;
5074 ld -= enormlz (den);
5076 ln -= enormlz (num);
5080 if (ecmpm (den, num) <= 0)
5094 emdnorm (num, 0, 0, ln, 0);
5097 /* This routine may be called to report one of the following
5098 error conditions (in the include file mconf.h).
5100 Mnemonic Value Significance
5102 DOMAIN 1 argument domain error
5103 SING 2 function singularity
5104 OVERFLOW 3 overflow range error
5105 UNDERFLOW 4 underflow range error
5106 TLOSS 5 total loss of precision
5107 PLOSS 6 partial loss of precision
5108 INVALID 7 NaN - producing operation
5109 EDOM 33 Unix domain error code
5110 ERANGE 34 Unix range error code
5112 The default version of the file prints the function name,
5113 passed to it by the pointer fctnam, followed by the
5114 error condition. The display is directed to the standard
5115 output device. The routine then returns to the calling
5116 program. Users may wish to modify the program to abort by
5117 calling exit under severe error conditions such as domain
5120 Since all error conditions pass control to this function,
5121 the display may be easily changed, eliminated, or directed
5122 to an error logging device. */
5124 /* Note: the order of appearance of the following messages is bound to the
5125 error codes defined above. */
5128 static char *ermsg[NMSGS] =
5130 "unknown", /* error code 0 */
5131 "domain", /* error code 1 */
5132 "singularity", /* et seq. */
5135 "total loss of precision",
5136 "partial loss of precision",
5150 /* Display string passed by calling program, which is supposed to be the
5151 name of the function in which the error occurred.
5153 Display error message defined by the code argument. */
5155 if ((code <= 0) || (code >= NMSGS))
5157 sprintf (errstr, " %s %s error", name, ermsg[code]);
5160 /* Set global error message word */
5165 /* Convert DEC double precision to e type. */
5169 unsigned EMUSHORT *d;
5170 unsigned EMUSHORT *e;
5172 unsigned EMUSHORT y[NI];
5173 register unsigned EMUSHORT r, *p;
5175 ecleaz (y); /* start with a zero */
5176 p = y; /* point to our number */
5177 r = *d; /* get DEC exponent word */
5178 if (*d & (unsigned int) 0x8000)
5179 *p = 0xffff; /* fill in our sign */
5180 ++p; /* bump pointer to our exponent word */
5181 r &= 0x7fff; /* strip the sign bit */
5182 if (r == 0) /* answer = 0 if high order DEC word = 0 */
5186 r >>= 7; /* shift exponent word down 7 bits */
5187 r += EXONE - 0201; /* subtract DEC exponent offset */
5188 /* add our e type exponent offset */
5189 *p++ = r; /* to form our exponent */
5191 r = *d++; /* now do the high order mantissa */
5192 r &= 0177; /* strip off the DEC exponent and sign bits */
5193 r |= 0200; /* the DEC understood high order mantissa bit */
5194 *p++ = r; /* put result in our high guard word */
5196 *p++ = *d++; /* fill in the rest of our mantissa */
5200 eshdn8 (y); /* shift our mantissa down 8 bits */
5208 ; convert e type to DEC double precision
5216 unsigned EMUSHORT *x, *d;
5218 unsigned EMUSHORT xi[NI];
5223 exp = (EMULONG) xi[E] - (EXONE - 0201); /* adjust exponent for offsets */
5224 /* round off to nearest or even */
5227 emdnorm (xi, 0, 0, exp, 64);
5234 unsigned EMUSHORT *x, *y;
5236 unsigned EMUSHORT i;
5237 unsigned EMUSHORT *p;
5276 /* Convert IBM single/double precision to e type. */
5280 unsigned EMUSHORT *d;
5281 unsigned EMUSHORT *e;
5282 enum machine_mode mode;
5284 unsigned EMUSHORT y[NI];
5285 register unsigned EMUSHORT r, *p;
5288 ecleaz (y); /* start with a zero */
5289 p = y; /* point to our number */
5290 r = *d; /* get IBM exponent word */
5291 if (*d & (unsigned int) 0x8000)
5292 *p = 0xffff; /* fill in our sign */
5293 ++p; /* bump pointer to our exponent word */
5294 r &= 0x7f00; /* strip the sign bit */
5295 r >>= 6; /* shift exponent word down 6 bits */
5296 /* in fact shift by 8 right and 2 left */
5297 r += EXONE - (0x41 << 2); /* subtract IBM exponent offset */
5298 /* add our e type exponent offset */
5299 *p++ = r; /* to form our exponent */
5301 *p++ = *d++ & 0xff; /* now do the high order mantissa */
5302 /* strip off the IBM exponent and sign bits */
5303 if (mode != SFmode) /* there are only 2 words in SFmode */
5305 *p++ = *d++; /* fill in the rest of our mantissa */
5310 if (y[M] == 0 && y[M+1] == 0 && y[M+2] == 0 && y[M+3] == 0)
5313 y[E] -= 5 + enormlz (y); /* now normalise the mantissa */
5314 /* handle change in RADIX */
5320 /* Convert e type to IBM single/double precision. */
5324 unsigned EMUSHORT *x, *d;
5325 enum machine_mode mode;
5327 unsigned EMUSHORT xi[NI];
5332 exp = (EMULONG) xi[E] - (EXONE - (0x41 << 2)); /* adjust exponent for offsets */
5333 /* round off to nearest or even */
5336 emdnorm (xi, 0, 0, exp, 64);
5338 toibm (xi, d, mode);
5343 unsigned EMUSHORT *x, *y;
5344 enum machine_mode mode;
5346 unsigned EMUSHORT i;
5347 unsigned EMUSHORT *p;
5395 /* Output a binary NaN bit pattern in the target machine's format. */
5397 /* If special NaN bit patterns are required, define them in tm.h
5398 as arrays of unsigned 16-bit shorts. Otherwise, use the default
5404 unsigned EMUSHORT TFnan[8] =
5405 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5408 unsigned EMUSHORT TFnan[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
5416 unsigned EMUSHORT XFnan[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5419 unsigned EMUSHORT XFnan[6] = {0, 0, 0, 0xc000, 0xffff, 0};
5427 unsigned EMUSHORT DFnan[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
5430 unsigned EMUSHORT DFnan[4] = {0, 0, 0, 0xfff8};
5438 unsigned EMUSHORT SFnan[2] = {0x7fff, 0xffff};
5441 unsigned EMUSHORT SFnan[2] = {0, 0xffc0};
5447 make_nan (nan, sign, mode)
5448 unsigned EMUSHORT *nan;
5450 enum machine_mode mode;
5453 unsigned EMUSHORT *p;
5457 /* Possibly the `reserved operand' patterns on a VAX can be
5458 used like NaN's, but probably not in the same way as IEEE. */
5459 #if !defined(DEC) && !defined(IBM)
5482 *nan++ = (sign << 15) | *p++;
5487 *nan = (sign << 15) | *p;
5491 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
5492 This is the inverse of the function `etarsingle' invoked by
5493 REAL_VALUE_TO_TARGET_SINGLE. */
5496 ereal_from_float (f)
5500 unsigned EMUSHORT s[2];
5501 unsigned EMUSHORT e[NE];
5503 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
5504 This is the inverse operation to what the function `endian' does. */
5505 #if FLOAT_WORDS_BIG_ENDIAN
5506 s[0] = (unsigned EMUSHORT) (f >> 16);
5507 s[1] = (unsigned EMUSHORT) f;
5509 s[0] = (unsigned EMUSHORT) f;
5510 s[1] = (unsigned EMUSHORT) (f >> 16);
5512 /* Convert and promote the target float to E-type. */
5514 /* Output E-type to REAL_VALUE_TYPE. */
5520 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
5521 This is the inverse of the function `etardouble' invoked by
5522 REAL_VALUE_TO_TARGET_DOUBLE.
5524 The DFmode is stored as an array of HOST_WIDE_INT in the target's
5525 data format, with no holes in the bit packing. The first element
5526 of the input array holds the bits that would come first in the
5527 target computer's memory. */
5530 ereal_from_double (d)
5534 unsigned EMUSHORT s[4];
5535 unsigned EMUSHORT e[NE];
5537 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
5538 #if FLOAT_WORDS_BIG_ENDIAN
5539 s[0] = (unsigned EMUSHORT) (d[0] >> 16);
5540 s[1] = (unsigned EMUSHORT) d[0];
5541 #if HOST_BITS_PER_WIDE_INT == 32
5542 s[2] = (unsigned EMUSHORT) (d[1] >> 16);
5543 s[3] = (unsigned EMUSHORT) d[1];
5545 /* In this case the entire target double is contained in the
5546 first array element. The second element of the input is ignored. */
5547 s[2] = (unsigned EMUSHORT) (d[0] >> 48);
5548 s[3] = (unsigned EMUSHORT) (d[0] >> 32);
5551 /* Target float words are little-endian. */
5552 s[0] = (unsigned EMUSHORT) d[0];
5553 s[1] = (unsigned EMUSHORT) (d[0] >> 16);
5554 #if HOST_BITS_PER_WIDE_INT == 32
5555 s[2] = (unsigned EMUSHORT) d[1];
5556 s[3] = (unsigned EMUSHORT) (d[1] >> 16);
5558 s[2] = (unsigned EMUSHORT) (d[0] >> 32);
5559 s[3] = (unsigned EMUSHORT) (d[0] >> 48);
5562 /* Convert target double to E-type. */
5564 /* Output E-type to REAL_VALUE_TYPE. */
5570 /* Convert target computer unsigned 64-bit integer to e-type.
5571 The endian-ness of DImode follows the convention for integers,
5572 so we use WORDS_BIG_ENDIAN here, not FLOAT_WORDS_BIG_ENDIAN. */
5576 unsigned EMUSHORT *di; /* Address of the 64-bit int. */
5577 unsigned EMUSHORT *e;
5579 unsigned EMUSHORT yi[NI];
5583 #if WORDS_BIG_ENDIAN
5584 for (k = M; k < M + 4; k++)
5587 for (k = M + 3; k >= M; k--)
5590 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
5591 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
5592 ecleaz (yi); /* it was zero */
5594 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
5598 /* Convert target computer signed 64-bit integer to e-type. */
5602 unsigned EMUSHORT *di; /* Address of the 64-bit int. */
5603 unsigned EMUSHORT *e;
5605 unsigned EMULONG acc;
5606 unsigned EMUSHORT yi[NI];
5607 unsigned EMUSHORT carry;
5611 #if WORDS_BIG_ENDIAN
5612 for (k = M; k < M + 4; k++)
5615 for (k = M + 3; k >= M; k--)
5618 /* Take absolute value */
5624 for (k = M + 3; k >= M; k--)
5626 acc = (unsigned EMULONG) (~yi[k] & 0xffff) + carry;
5633 yi[E] = EXONE + 47; /* exponent if normalize shift count were 0 */
5634 if ((k = enormlz (yi)) > NBITS)/* normalize the significand */
5635 ecleaz (yi); /* it was zero */
5637 yi[E] -= (unsigned EMUSHORT) k;/* subtract shift count from exponent */
5644 /* Convert e-type to unsigned 64-bit int. */
5648 unsigned EMUSHORT *x;
5649 unsigned EMUSHORT *i;
5651 unsigned EMUSHORT xi[NI];
5660 k = (int) xi[E] - (EXONE - 1);
5663 for (j = 0; j < 4; j++)
5669 for (j = 0; j < 4; j++)
5672 warning ("overflow on truncation to integer");
5677 /* Shift more than 16 bits: first shift up k-16 mod 16,
5678 then shift up by 16's. */
5679 j = k - ((k >> 4) << 4);
5683 #if WORDS_BIG_ENDIAN
5693 #if WORDS_BIG_ENDIAN
5699 while ((k -= 16) > 0);
5703 /* shift not more than 16 bits */
5708 #if WORDS_BIG_ENDIAN
5724 /* Convert e-type to signed 64-bit int. */
5728 unsigned EMUSHORT *x;
5729 unsigned EMUSHORT *i;
5731 unsigned EMULONG acc;
5732 unsigned EMUSHORT xi[NI];
5733 unsigned EMUSHORT carry;
5734 unsigned EMUSHORT *isave;
5738 k = (int) xi[E] - (EXONE - 1);
5741 for (j = 0; j < 4; j++)
5747 for (j = 0; j < 4; j++)
5750 warning ("overflow on truncation to integer");
5756 /* Shift more than 16 bits: first shift up k-16 mod 16,
5757 then shift up by 16's. */
5758 j = k - ((k >> 4) << 4);
5762 #if WORDS_BIG_ENDIAN
5772 #if WORDS_BIG_ENDIAN
5778 while ((k -= 16) > 0);
5782 /* shift not more than 16 bits */
5785 #if WORDS_BIG_ENDIAN
5798 /* Negate if negative */
5802 #if WORDS_BIG_ENDIAN
5805 for (k = 0; k < 4; k++)
5807 acc = (unsigned EMULONG) (~(*isave) & 0xffff) + carry;
5808 #if WORDS_BIG_ENDIAN
5821 /* Longhand square root routine. */
5824 static int esqinited = 0;
5825 static unsigned short sqrndbit[NI];
5829 unsigned EMUSHORT *x, *y;
5831 unsigned EMUSHORT temp[NI], num[NI], sq[NI], xx[NI];
5833 int i, j, k, n, nlups;
5838 sqrndbit[NI - 2] = 1;
5841 /* Check for arg <= 0 */
5842 i = ecmp (x, ezero);
5847 mtherr ("esqrt", DOMAIN);
5863 /* Bring in the arg and renormalize if it is denormal. */
5865 m = (EMULONG) xx[1]; /* local long word exponent */
5869 /* Divide exponent by 2 */
5871 exp = (unsigned short) ((m / 2) + 0x3ffe);
5873 /* Adjust if exponent odd */
5883 n = 8; /* get 8 bits of result per inner loop */
5889 /* bring in next word of arg */
5891 num[NI - 1] = xx[j + 3];
5892 /* Do additional bit on last outer loop, for roundoff. */
5895 for (i = 0; i < n; i++)
5897 /* Next 2 bits of arg */
5900 /* Shift up answer */
5902 /* Make trial divisor */
5903 for (k = 0; k < NI; k++)
5906 eaddm (sqrndbit, temp);
5907 /* Subtract and insert answer bit if it goes in */
5908 if (ecmpm (temp, num) <= 0)
5918 /* Adjust for extra, roundoff loop done. */
5919 exp += (NBITS - 1) - rndprc;
5921 /* Sticky bit = 1 if the remainder is nonzero. */
5923 for (i = 3; i < NI; i++)
5926 /* Renormalize and round off. */
5927 emdnorm (sq, k, 0, exp, 64);
5930 #endif /* EMU_NON_COMPILE not defined */
5932 /* Return the binary precision of the significand for a given
5933 floating point mode. The mode can hold an integer value
5934 that many bits wide, without losing any bits. */
5937 significand_size (mode)
5938 enum machine_mode mode;
5947 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
5950 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
5953 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT