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, 95, 96, 97, 1998 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. */
28 /* To enable support of XFmode extended real floating point, define
29 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
31 To support cross compilation between IEEE, VAX and IBM floating
32 point formats, define REAL_ARITHMETIC in the tm.h file.
34 In either case the machine files (tm.h) must not contain any code
35 that tries to use host floating point arithmetic to convert
36 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
37 etc. In cross-compile situations a REAL_VALUE_TYPE may not
38 be intelligible to the host computer's native arithmetic.
40 The emulator defaults to the host's floating point format so that
41 its decimal conversion functions can be used if desired (see
44 The first part of this file interfaces gcc to a floating point
45 arithmetic suite that was not written with gcc in mind. Avoid
46 changing the low-level arithmetic routines unless you have suitable
47 test programs available. A special version of the PARANOIA floating
48 point arithmetic tester, modified for this purpose, can be found on
49 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
50 XFmode and TFmode transcendental functions, can be obtained by ftp from
51 netlib.att.com: netlib/cephes. */
53 /* Type of computer arithmetic.
54 Only one of DEC, IBM, IEEE, or UNK should get defined.
56 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
57 to big-endian IEEE floating-point data structure. This definition
58 should work in SFmode `float' type and DFmode `double' type on
59 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
60 has been defined to be 96, then IEEE also invokes the particular
61 XFmode (`long double' type) data structure used by the Motorola
62 680x0 series processors.
64 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
65 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
66 has been defined to be 96, then IEEE also invokes the particular
67 XFmode `long double' data structure used by the Intel 80x86 series
70 `DEC' refers specifically to the Digital Equipment Corp PDP-11
71 and VAX floating point data structure. This model currently
72 supports no type wider than DFmode.
74 `IBM' refers specifically to the IBM System/370 and compatible
75 floating point data structure. This model currently supports
76 no type wider than DFmode. The IBM conversions were contributed by
77 frank@atom.ansto.gov.au (Frank Crawford).
79 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
80 then `long double' and `double' are both implemented, but they
81 both mean DFmode. In this case, the software floating-point
82 support available here is activated by writing
83 #define REAL_ARITHMETIC
86 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
87 and may deactivate XFmode since `long double' is used to refer
90 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
91 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
92 separate the floating point unit's endian-ness from that of
93 the integer addressing. This permits one to define a big-endian
94 FPU on a little-endian machine (e.g., ARM). An extension to
95 BYTES_BIG_ENDIAN may be required for some machines in the future.
96 These optional macros may be defined in tm.h. In real.h, they
97 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
98 them for any normal host or target machine on which the floats
99 and the integers have the same endian-ness. */
102 /* The following converts gcc macros into the ones used by this file. */
104 /* REAL_ARITHMETIC defined means that macros in real.h are
105 defined to call emulator functions. */
106 #ifdef REAL_ARITHMETIC
108 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
109 /* PDP-11, Pro350, VAX: */
111 #else /* it's not VAX */
112 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
113 /* IBM System/370 style */
115 #else /* it's also not an IBM */
116 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
117 /* TMS320C3x/C4x style */
119 #else /* it's also not a C4X */
120 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
122 #else /* it's not IEEE either */
123 /* UNKnown arithmetic. We don't support this and can't go on. */
124 unknown arithmetic type
126 #endif /* not IEEE */
131 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
134 /* REAL_ARITHMETIC not defined means that the *host's* data
135 structure will be used. It may differ by endian-ness from the
136 target machine's structure and will get its ends swapped
137 accordingly (but not here). Probably only the decimal <-> binary
138 functions in this file will actually be used in this case. */
140 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
142 #else /* it's not VAX */
143 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
144 /* IBM System/370 style */
146 #else /* it's also not an IBM */
147 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
149 #else /* it's not IEEE either */
150 unknown arithmetic type
152 #endif /* not IEEE */
156 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
158 #endif /* REAL_ARITHMETIC not defined */
160 /* Define INFINITY for support of infinity.
161 Define NANS for support of Not-a-Number's (NaN's). */
162 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
167 /* Support of NaNs requires support of infinity. */
174 /* Find a host integer type that is at least 16 bits wide,
175 and another type at least twice whatever that size is. */
177 #if HOST_BITS_PER_CHAR >= 16
178 #define EMUSHORT char
179 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
180 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
182 #if HOST_BITS_PER_SHORT >= 16
183 #define EMUSHORT short
184 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
185 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
187 #if HOST_BITS_PER_INT >= 16
189 #define EMUSHORT_SIZE HOST_BITS_PER_INT
190 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
192 #if HOST_BITS_PER_LONG >= 16
193 #define EMUSHORT long
194 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
195 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
197 /* You will have to modify this program to have a smaller unit size. */
198 #define EMU_NON_COMPILE
204 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
205 #define EMULONG short
207 #if HOST_BITS_PER_INT >= EMULONG_SIZE
210 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
213 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
214 #define EMULONG long long int
216 /* You will have to modify this program to have a smaller unit size. */
217 #define EMU_NON_COMPILE
224 /* The host interface doesn't work if no 16-bit size exists. */
225 #if EMUSHORT_SIZE != 16
226 #define EMU_NON_COMPILE
229 /* OK to continue compilation. */
230 #ifndef EMU_NON_COMPILE
232 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
233 In GET_REAL and PUT_REAL, r and e are pointers.
234 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
235 in memory, with no holes. */
237 #if LONG_DOUBLE_TYPE_SIZE == 96
238 /* Number of 16 bit words in external e type format */
240 #define MAXDECEXP 4932
241 #define MINDECEXP -4956
242 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
243 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
244 #else /* no XFmode */
245 #if LONG_DOUBLE_TYPE_SIZE == 128
247 #define MAXDECEXP 4932
248 #define MINDECEXP -4977
249 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
250 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
253 #define MAXDECEXP 4932
254 #define MINDECEXP -4956
255 #ifdef REAL_ARITHMETIC
256 /* Emulator uses target format internally
257 but host stores it in host endian-ness. */
259 #define GET_REAL(r,e) \
261 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
262 e53toe ((unsigned EMUSHORT *) (r), (e)); \
265 unsigned EMUSHORT w[4]; \
266 w[3] = ((EMUSHORT *) r)[0]; \
267 w[2] = ((EMUSHORT *) r)[1]; \
268 w[1] = ((EMUSHORT *) r)[2]; \
269 w[0] = ((EMUSHORT *) r)[3]; \
274 #define PUT_REAL(e,r) \
276 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
277 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
280 unsigned EMUSHORT w[4]; \
282 *((EMUSHORT *) r) = w[3]; \
283 *((EMUSHORT *) r + 1) = w[2]; \
284 *((EMUSHORT *) r + 2) = w[1]; \
285 *((EMUSHORT *) r + 3) = w[0]; \
289 #else /* not REAL_ARITHMETIC */
291 /* emulator uses host format */
292 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
293 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
295 #endif /* not REAL_ARITHMETIC */
296 #endif /* not TFmode */
297 #endif /* not XFmode */
300 /* Number of 16 bit words in internal format */
303 /* Array offset to exponent */
306 /* Array offset to high guard word */
309 /* Number of bits of precision */
310 #define NBITS ((NI-4)*16)
312 /* Maximum number of decimal digits in ASCII conversion
315 #define NDEC (NBITS*8/27)
317 /* The exponent of 1.0 */
318 #define EXONE (0x3fff)
320 extern int extra_warnings
;
321 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
322 extern unsigned EMUSHORT elog2
[], esqrt2
[];
324 static void endian
PROTO((unsigned EMUSHORT
*, long *,
326 static void eclear
PROTO((unsigned EMUSHORT
*));
327 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
329 static void eabs
PROTO((unsigned EMUSHORT
*));
331 static void eneg
PROTO((unsigned EMUSHORT
*));
332 static int eisneg
PROTO((unsigned EMUSHORT
*));
333 static int eisinf
PROTO((unsigned EMUSHORT
*));
334 static int eisnan
PROTO((unsigned EMUSHORT
*));
335 static void einfin
PROTO((unsigned EMUSHORT
*));
336 static void enan
PROTO((unsigned EMUSHORT
*, int));
337 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
338 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
339 static void ecleaz
PROTO((unsigned EMUSHORT
*));
340 static void ecleazs
PROTO((unsigned EMUSHORT
*));
341 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
342 static void einan
PROTO((unsigned EMUSHORT
*));
343 static int eiisnan
PROTO((unsigned EMUSHORT
*));
344 static int eiisneg
PROTO((unsigned EMUSHORT
*));
346 static void eiinfin
PROTO((unsigned EMUSHORT
*));
348 static int eiisinf
PROTO((unsigned EMUSHORT
*));
349 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
350 static void eshdn1
PROTO((unsigned EMUSHORT
*));
351 static void eshup1
PROTO((unsigned EMUSHORT
*));
352 static void eshdn8
PROTO((unsigned EMUSHORT
*));
353 static void eshup8
PROTO((unsigned EMUSHORT
*));
354 static void eshup6
PROTO((unsigned EMUSHORT
*));
355 static void eshdn6
PROTO((unsigned EMUSHORT
*));
356 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
357 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
358 static void m16m
PROTO((unsigned int, unsigned short *,
360 static int edivm
PROTO((unsigned short *, unsigned short *));
361 static int emulm
PROTO((unsigned short *, unsigned short *));
362 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
363 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
364 unsigned EMUSHORT
*));
365 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
366 unsigned EMUSHORT
*));
367 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
368 unsigned EMUSHORT
*));
369 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
370 unsigned EMUSHORT
*));
371 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
372 unsigned EMUSHORT
*));
373 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
378 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
380 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
381 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
384 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
387 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
389 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
390 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
391 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
392 unsigned EMUSHORT
*));
393 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
394 unsigned EMUSHORT
*));
395 static int eshift
PROTO((unsigned EMUSHORT
*, int));
396 static int enormlz
PROTO((unsigned EMUSHORT
*));
398 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
399 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
400 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
401 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
403 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
404 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
405 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
406 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
407 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
408 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
409 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
410 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
413 unsigned EMUSHORT
*));
415 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
417 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
418 unsigned EMUSHORT
*));
420 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
421 static void mtherr
PROTO((char *, int));
423 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
424 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
425 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
428 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
430 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
432 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
436 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
438 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
440 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
443 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
445 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
446 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
447 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
448 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
449 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
452 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
453 swapping ends if required, into output array of longs. The
454 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
458 unsigned EMUSHORT e
[];
460 enum machine_mode mode
;
464 if (REAL_WORDS_BIG_ENDIAN
)
469 /* Swap halfwords in the fourth long. */
470 th
= (unsigned long) e
[6] & 0xffff;
471 t
= (unsigned long) e
[7] & 0xffff;
476 /* Swap halfwords in the third long. */
477 th
= (unsigned long) e
[4] & 0xffff;
478 t
= (unsigned long) e
[5] & 0xffff;
481 /* fall into the double case */
484 /* Swap halfwords in the second word. */
485 th
= (unsigned long) e
[2] & 0xffff;
486 t
= (unsigned long) e
[3] & 0xffff;
489 /* fall into the float case */
493 /* Swap halfwords in the first word. */
494 th
= (unsigned long) e
[0] & 0xffff;
495 t
= (unsigned long) e
[1] & 0xffff;
506 /* Pack the output array without swapping. */
511 /* Pack the fourth long. */
512 th
= (unsigned long) e
[7] & 0xffff;
513 t
= (unsigned long) e
[6] & 0xffff;
518 /* Pack the third long.
519 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
521 th
= (unsigned long) e
[5] & 0xffff;
522 t
= (unsigned long) e
[4] & 0xffff;
525 /* fall into the double case */
528 /* Pack the second long */
529 th
= (unsigned long) e
[3] & 0xffff;
530 t
= (unsigned long) e
[2] & 0xffff;
533 /* fall into the float case */
537 /* Pack the first long */
538 th
= (unsigned long) e
[1] & 0xffff;
539 t
= (unsigned long) e
[0] & 0xffff;
551 /* This is the implementation of the REAL_ARITHMETIC macro. */
554 earith (value
, icode
, r1
, r2
)
555 REAL_VALUE_TYPE
*value
;
560 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
566 /* Return NaN input back to the caller. */
569 PUT_REAL (d1
, value
);
574 PUT_REAL (d2
, value
);
578 code
= (enum tree_code
) icode
;
586 esub (d2
, d1
, v
); /* d1 - d2 */
594 #ifndef REAL_INFINITY
595 if (ecmp (d2
, ezero
) == 0)
598 enan (v
, eisneg (d1
) ^ eisneg (d2
));
605 ediv (d2
, d1
, v
); /* d1/d2 */
608 case MIN_EXPR
: /* min (d1,d2) */
609 if (ecmp (d1
, d2
) < 0)
615 case MAX_EXPR
: /* max (d1,d2) */
616 if (ecmp (d1
, d2
) > 0)
629 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
630 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
636 unsigned EMUSHORT f
[NE
], g
[NE
];
652 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
653 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
659 unsigned EMUSHORT f
[NE
], g
[NE
];
661 unsigned HOST_WIDE_INT l
;
675 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
676 binary, rounding off as indicated by the machine_mode argument. Then it
677 promotes the rounded value to REAL_VALUE_TYPE. */
684 unsigned EMUSHORT tem
[NE
], e
[NE
];
718 /* Expansion of REAL_NEGATE. */
724 unsigned EMUSHORT e
[NE
];
734 /* Round real toward zero to HOST_WIDE_INT;
735 implements REAL_VALUE_FIX (x). */
741 unsigned EMUSHORT f
[NE
], g
[NE
];
748 warning ("conversion from NaN to int");
756 /* Round real toward zero to unsigned HOST_WIDE_INT
757 implements REAL_VALUE_UNSIGNED_FIX (x).
758 Negative input returns zero. */
760 unsigned HOST_WIDE_INT
764 unsigned EMUSHORT f
[NE
], g
[NE
];
765 unsigned HOST_WIDE_INT l
;
771 warning ("conversion from NaN to unsigned int");
780 /* REAL_VALUE_FROM_INT macro. */
783 ereal_from_int (d
, i
, j
, mode
)
786 enum machine_mode mode
;
788 unsigned EMUSHORT df
[NE
], dg
[NE
];
789 HOST_WIDE_INT low
, high
;
792 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
799 /* complement and add 1 */
806 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
807 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
809 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
814 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
815 Avoid double-rounding errors later by rounding off now from the
816 extra-wide internal format to the requested precision. */
817 switch (GET_MODE_BITSIZE (mode
))
847 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
850 ereal_from_uint (d
, i
, j
, mode
)
852 unsigned HOST_WIDE_INT i
, j
;
853 enum machine_mode mode
;
855 unsigned EMUSHORT df
[NE
], dg
[NE
];
856 unsigned HOST_WIDE_INT low
, high
;
858 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
862 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
868 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
869 Avoid double-rounding errors later by rounding off now from the
870 extra-wide internal format to the requested precision. */
871 switch (GET_MODE_BITSIZE (mode
))
901 /* REAL_VALUE_TO_INT macro. */
904 ereal_to_int (low
, high
, rr
)
905 HOST_WIDE_INT
*low
, *high
;
908 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
915 warning ("conversion from NaN to int");
921 /* convert positive value */
928 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
929 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
930 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
931 emul (df
, dh
, dg
); /* fractional part is the low word */
932 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
935 /* complement and add 1 */
945 /* REAL_VALUE_LDEXP macro. */
952 unsigned EMUSHORT e
[NE
], y
[NE
];
965 /* These routines are conditionally compiled because functions
966 of the same names may be defined in fold-const.c. */
968 #ifdef REAL_ARITHMETIC
970 /* Check for infinity in a REAL_VALUE_TYPE. */
976 unsigned EMUSHORT e
[NE
];
986 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
992 unsigned EMUSHORT e
[NE
];
1003 /* Check for a negative REAL_VALUE_TYPE number.
1004 This just checks the sign bit, so that -0 counts as negative. */
1010 return ereal_isneg (x
);
1013 /* Expansion of REAL_VALUE_TRUNCATE.
1014 The result is in floating point, rounded to nearest or even. */
1017 real_value_truncate (mode
, arg
)
1018 enum machine_mode mode
;
1019 REAL_VALUE_TYPE arg
;
1021 unsigned EMUSHORT e
[NE
], t
[NE
];
1057 /* If an unsupported type was requested, presume that
1058 the machine files know something useful to do with
1059 the unmodified value. */
1068 /* Try to change R into its exact multiplicative inverse in machine mode
1069 MODE. Return nonzero function value if successful. */
1072 exact_real_inverse (mode
, r
)
1073 enum machine_mode mode
;
1076 unsigned EMUSHORT e
[NE
], einv
[NE
];
1077 REAL_VALUE_TYPE rinv
;
1082 /* Test for input in range. Don't transform IEEE special values. */
1083 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1086 /* Test for a power of 2: all significand bits zero except the MSB.
1087 We are assuming the target has binary (or hex) arithmetic. */
1088 if (e
[NE
- 2] != 0x8000)
1091 for (i
= 0; i
< NE
- 2; i
++)
1097 /* Compute the inverse and truncate it to the required mode. */
1098 ediv (e
, eone
, einv
);
1099 PUT_REAL (einv
, &rinv
);
1100 rinv
= real_value_truncate (mode
, rinv
);
1102 #ifdef CHECK_FLOAT_VALUE
1103 /* This check is not redundant. It may, for example, flush
1104 a supposedly IEEE denormal value to zero. */
1106 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1109 GET_REAL (&rinv
, einv
);
1111 /* Check the bits again, because the truncation might have
1112 generated an arbitrary saturation value on overflow. */
1113 if (einv
[NE
- 2] != 0x8000)
1116 for (i
= 0; i
< NE
- 2; i
++)
1122 /* Fail if the computed inverse is out of range. */
1123 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1126 /* Output the reciprocal and return success flag. */
1130 #endif /* REAL_ARITHMETIC defined */
1132 /* Used for debugging--print the value of R in human-readable format
1141 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1142 fprintf (stderr
, "%s", dstr
);
1146 /* The following routines convert REAL_VALUE_TYPE to the various floating
1147 point formats that are meaningful to supported computers.
1149 The results are returned in 32-bit pieces, each piece stored in a `long'.
1150 This is so they can be printed by statements like
1152 fprintf (file, "%lx, %lx", L[0], L[1]);
1154 that will work on both narrow- and wide-word host computers. */
1156 /* Convert R to a 128-bit long double precision value. The output array L
1157 contains four 32-bit pieces of the result, in the order they would appear
1165 unsigned EMUSHORT e
[NE
];
1169 endian (e
, l
, TFmode
);
1172 /* Convert R to a double extended precision value. The output array L
1173 contains three 32-bit pieces of the result, in the order they would
1174 appear in memory. */
1181 unsigned EMUSHORT e
[NE
];
1185 endian (e
, l
, XFmode
);
1188 /* Convert R to a double precision value. The output array L contains two
1189 32-bit pieces of the result, in the order they would appear in memory. */
1196 unsigned EMUSHORT e
[NE
];
1200 endian (e
, l
, DFmode
);
1203 /* Convert R to a single precision float value stored in the least-significant
1204 bits of a `long'. */
1210 unsigned EMUSHORT e
[NE
];
1215 endian (e
, &l
, SFmode
);
1219 /* Convert X to a decimal ASCII string S for output to an assembly
1220 language file. Note, there is no standard way to spell infinity or
1221 a NaN, so these values may require special treatment in the tm.h
1225 ereal_to_decimal (x
, s
)
1229 unsigned EMUSHORT e
[NE
];
1235 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1236 or -2 if either is a NaN. */
1240 REAL_VALUE_TYPE x
, y
;
1242 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1246 return (ecmp (ex
, ey
));
1249 /* Return 1 if the sign bit of X is set, else return 0. */
1255 unsigned EMUSHORT ex
[NE
];
1258 return (eisneg (ex
));
1261 /* End of REAL_ARITHMETIC interface */
1264 Extended precision IEEE binary floating point arithmetic routines
1266 Numbers are stored in C language as arrays of 16-bit unsigned
1267 short integers. The arguments of the routines are pointers to
1270 External e type data structure, similar to Intel 8087 chip
1271 temporary real format but possibly with a larger significand:
1273 NE-1 significand words (least significant word first,
1274 most significant bit is normally set)
1275 exponent (value = EXONE for 1.0,
1276 top bit is the sign)
1279 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1281 ei[0] sign word (0 for positive, 0xffff for negative)
1282 ei[1] biased exponent (value = EXONE for the number 1.0)
1283 ei[2] high guard word (always zero after normalization)
1285 to ei[NI-2] significand (NI-4 significand words,
1286 most significant word first,
1287 most significant bit is set)
1288 ei[NI-1] low guard word (0x8000 bit is rounding place)
1292 Routines for external format e-type numbers
1294 asctoe (string, e) ASCII string to extended double e type
1295 asctoe64 (string, &d) ASCII string to long double
1296 asctoe53 (string, &d) ASCII string to double
1297 asctoe24 (string, &f) ASCII string to single
1298 asctoeg (string, e, prec) ASCII string to specified precision
1299 e24toe (&f, e) IEEE single precision to e type
1300 e53toe (&d, e) IEEE double precision to e type
1301 e64toe (&d, e) IEEE long double precision to e type
1302 e113toe (&d, e) 128-bit long double precision to e type
1304 eabs (e) absolute value
1306 eadd (a, b, c) c = b + a
1308 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1309 -1 if a < b, -2 if either a or b is a NaN.
1310 ediv (a, b, c) c = b / a
1311 efloor (a, b) truncate to integer, toward -infinity
1312 efrexp (a, exp, s) extract exponent and significand
1313 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1314 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1315 einfin (e) set e to infinity, leaving its sign alone
1316 eldexp (a, n, b) multiply by 2**n
1318 emul (a, b, c) c = b * a
1321 eround (a, b) b = nearest integer value to a
1323 esub (a, b, c) c = b - a
1325 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1326 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1327 e64toasc (&d, str, n) 80-bit long double to ASCII string
1328 e113toasc (&d, str, n) 128-bit long double to ASCII string
1330 etoasc (e, str, n) e to ASCII string, n digits after decimal
1331 etoe24 (e, &f) convert e type to IEEE single precision
1332 etoe53 (e, &d) convert e type to IEEE double precision
1333 etoe64 (e, &d) convert e type to IEEE long double precision
1334 ltoe (&l, e) HOST_WIDE_INT to e type
1335 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1336 eisneg (e) 1 if sign bit of e != 0, else 0
1337 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1338 or is infinite (IEEE)
1339 eisnan (e) 1 if e is a NaN
1342 Routines for internal format exploded e-type numbers
1344 eaddm (ai, bi) add significands, bi = bi + ai
1346 ecleazs (ei) set ei = 0 but leave its sign alone
1347 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1348 edivm (ai, bi) divide significands, bi = bi / ai
1349 emdnorm (ai,l,s,exp) normalize and round off
1350 emovi (a, ai) convert external a to internal ai
1351 emovo (ai, a) convert internal ai to external a
1352 emovz (ai, bi) bi = ai, low guard word of bi = 0
1353 emulm (ai, bi) multiply significands, bi = bi * ai
1354 enormlz (ei) left-justify the significand
1355 eshdn1 (ai) shift significand and guards down 1 bit
1356 eshdn8 (ai) shift down 8 bits
1357 eshdn6 (ai) shift down 16 bits
1358 eshift (ai, n) shift ai n bits up (or down if n < 0)
1359 eshup1 (ai) shift significand and guards up 1 bit
1360 eshup8 (ai) shift up 8 bits
1361 eshup6 (ai) shift up 16 bits
1362 esubm (ai, bi) subtract significands, bi = bi - ai
1363 eiisinf (ai) 1 if infinite
1364 eiisnan (ai) 1 if a NaN
1365 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1366 einan (ai) set ai = NaN
1368 eiinfin (ai) set ai = infinity
1371 The result is always normalized and rounded to NI-4 word precision
1372 after each arithmetic operation.
1374 Exception flags are NOT fully supported.
1376 Signaling NaN's are NOT supported; they are treated the same
1379 Define INFINITY for support of infinity; otherwise a
1380 saturation arithmetic is implemented.
1382 Define NANS for support of Not-a-Number items; otherwise the
1383 arithmetic will never produce a NaN output, and might be confused
1385 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1386 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1387 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1390 Denormals are always supported here where appropriate (e.g., not
1391 for conversion to DEC numbers). */
1393 /* Definitions for error codes that are passed to the common error handling
1396 For Digital Equipment PDP-11 and VAX computers, certain
1397 IBM systems, and others that use numbers with a 56-bit
1398 significand, the symbol DEC should be defined. In this
1399 mode, most floating point constants are given as arrays
1400 of octal integers to eliminate decimal to binary conversion
1401 errors that might be introduced by the compiler.
1403 For computers, such as IBM PC, that follow the IEEE
1404 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1405 Std 754-1985), the symbol IEEE should be defined.
1406 These numbers have 53-bit significands. In this mode, constants
1407 are provided as arrays of hexadecimal 16 bit integers.
1408 The endian-ness of generated values is controlled by
1409 REAL_WORDS_BIG_ENDIAN.
1411 To accommodate other types of computer arithmetic, all
1412 constants are also provided in a normal decimal radix
1413 which one can hope are correctly converted to a suitable
1414 format by the available C language compiler. To invoke
1415 this mode, the symbol UNK is defined.
1417 An important difference among these modes is a predefined
1418 set of machine arithmetic constants for each. The numbers
1419 MACHEP (the machine roundoff error), MAXNUM (largest number
1420 represented), and several other parameters are preset by
1421 the configuration symbol. Check the file const.c to
1422 ensure that these values are correct for your computer.
1424 For ANSI C compatibility, define ANSIC equal to 1. Currently
1425 this affects only the atan2 function and others that use it. */
1427 /* Constant definitions for math error conditions. */
1429 #define DOMAIN 1 /* argument domain error */
1430 #define SING 2 /* argument singularity */
1431 #define OVERFLOW 3 /* overflow range error */
1432 #define UNDERFLOW 4 /* underflow range error */
1433 #define TLOSS 5 /* total loss of precision */
1434 #define PLOSS 6 /* partial loss of precision */
1435 #define INVALID 7 /* NaN-producing operation */
1437 /* e type constants used by high precision check routines */
1439 #if LONG_DOUBLE_TYPE_SIZE == 128
1441 unsigned EMUSHORT ezero
[NE
] =
1442 {0x0000, 0x0000, 0x0000, 0x0000,
1443 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1444 extern unsigned EMUSHORT ezero
[];
1447 unsigned EMUSHORT ehalf
[NE
] =
1448 {0x0000, 0x0000, 0x0000, 0x0000,
1449 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1450 extern unsigned EMUSHORT ehalf
[];
1453 unsigned EMUSHORT eone
[NE
] =
1454 {0x0000, 0x0000, 0x0000, 0x0000,
1455 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1456 extern unsigned EMUSHORT eone
[];
1459 unsigned EMUSHORT etwo
[NE
] =
1460 {0x0000, 0x0000, 0x0000, 0x0000,
1461 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1462 extern unsigned EMUSHORT etwo
[];
1465 unsigned EMUSHORT e32
[NE
] =
1466 {0x0000, 0x0000, 0x0000, 0x0000,
1467 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1468 extern unsigned EMUSHORT e32
[];
1470 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1471 unsigned EMUSHORT elog2
[NE
] =
1472 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1473 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1474 extern unsigned EMUSHORT elog2
[];
1476 /* 1.41421356237309504880168872420969807856967187537695E0 */
1477 unsigned EMUSHORT esqrt2
[NE
] =
1478 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1479 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1480 extern unsigned EMUSHORT esqrt2
[];
1482 /* 3.14159265358979323846264338327950288419716939937511E0 */
1483 unsigned EMUSHORT epi
[NE
] =
1484 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1485 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1486 extern unsigned EMUSHORT epi
[];
1489 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1490 unsigned EMUSHORT ezero
[NE
] =
1491 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1492 unsigned EMUSHORT ehalf
[NE
] =
1493 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1494 unsigned EMUSHORT eone
[NE
] =
1495 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1496 unsigned EMUSHORT etwo
[NE
] =
1497 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1498 unsigned EMUSHORT e32
[NE
] =
1499 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1500 unsigned EMUSHORT elog2
[NE
] =
1501 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1502 unsigned EMUSHORT esqrt2
[NE
] =
1503 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1504 unsigned EMUSHORT epi
[NE
] =
1505 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1508 /* Control register for rounding precision.
1509 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1514 /* Clear out entire e-type number X. */
1518 register unsigned EMUSHORT
*x
;
1522 for (i
= 0; i
< NE
; i
++)
1526 /* Move e-type number from A to B. */
1530 register unsigned EMUSHORT
*a
, *b
;
1534 for (i
= 0; i
< NE
; i
++)
1540 /* Absolute value of e-type X. */
1544 unsigned EMUSHORT x
[];
1546 /* sign is top bit of last word of external format */
1547 x
[NE
- 1] &= 0x7fff;
1551 /* Negate the e-type number X. */
1555 unsigned EMUSHORT x
[];
1558 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1561 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1565 unsigned EMUSHORT x
[];
1568 if (x
[NE
- 1] & 0x8000)
1574 /* Return 1 if e-type number X is infinity, else return zero. */
1578 unsigned EMUSHORT x
[];
1585 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1591 /* Check if e-type number is not a number. The bit pattern is one that we
1592 defined, so we know for sure how to detect it. */
1596 unsigned EMUSHORT x
[];
1601 /* NaN has maximum exponent */
1602 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1604 /* ... and non-zero significand field. */
1605 for (i
= 0; i
< NE
- 1; i
++)
1615 /* Fill e-type number X with infinity pattern (IEEE)
1616 or largest possible number (non-IEEE). */
1620 register unsigned EMUSHORT
*x
;
1625 for (i
= 0; i
< NE
- 1; i
++)
1629 for (i
= 0; i
< NE
- 1; i
++)
1657 /* Output an e-type NaN.
1658 This generates Intel's quiet NaN pattern for extended real.
1659 The exponent is 7fff, the leading mantissa word is c000. */
1663 register unsigned EMUSHORT
*x
;
1668 for (i
= 0; i
< NE
- 2; i
++)
1671 *x
= (sign
<< 15) | 0x7fff;
1674 /* Move in an e-type number A, converting it to exploded e-type B. */
1678 unsigned EMUSHORT
*a
, *b
;
1680 register unsigned EMUSHORT
*p
, *q
;
1684 p
= a
+ (NE
- 1); /* point to last word of external number */
1685 /* get the sign bit */
1690 /* get the exponent */
1692 *q
++ &= 0x7fff; /* delete the sign bit */
1694 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1700 for (i
= 3; i
< NI
; i
++)
1706 for (i
= 2; i
< NI
; i
++)
1712 /* clear high guard word */
1714 /* move in the significand */
1715 for (i
= 0; i
< NE
- 1; i
++)
1717 /* clear low guard word */
1721 /* Move out exploded e-type number A, converting it to e type B. */
1725 unsigned EMUSHORT
*a
, *b
;
1727 register unsigned EMUSHORT
*p
, *q
;
1728 unsigned EMUSHORT i
;
1732 q
= b
+ (NE
- 1); /* point to output exponent */
1733 /* combine sign and exponent */
1736 *q
-- = *p
++ | 0x8000;
1740 if (*(p
- 1) == 0x7fff)
1745 enan (b
, eiisneg (a
));
1753 /* skip over guard word */
1755 /* move the significand */
1756 for (j
= 0; j
< NE
- 1; j
++)
1760 /* Clear out exploded e-type number XI. */
1764 register unsigned EMUSHORT
*xi
;
1768 for (i
= 0; i
< NI
; i
++)
1772 /* Clear out exploded e-type XI, but don't touch the sign. */
1776 register unsigned EMUSHORT
*xi
;
1781 for (i
= 0; i
< NI
- 1; i
++)
1785 /* Move exploded e-type number from A to B. */
1789 register unsigned EMUSHORT
*a
, *b
;
1793 for (i
= 0; i
< NI
- 1; i
++)
1795 /* clear low guard word */
1799 /* Generate exploded e-type NaN.
1800 The explicit pattern for this is maximum exponent and
1801 top two significant bits set. */
1805 unsigned EMUSHORT x
[];
1813 /* Return nonzero if exploded e-type X is a NaN. */
1817 unsigned EMUSHORT x
[];
1821 if ((x
[E
] & 0x7fff) == 0x7fff)
1823 for (i
= M
+ 1; i
< NI
; i
++)
1832 /* Return nonzero if sign of exploded e-type X is nonzero. */
1836 unsigned EMUSHORT x
[];
1843 /* Fill exploded e-type X with infinity pattern.
1844 This has maximum exponent and significand all zeros. */
1848 unsigned EMUSHORT x
[];
1856 /* Return nonzero if exploded e-type X is infinite. */
1860 unsigned EMUSHORT x
[];
1867 if ((x
[E
] & 0x7fff) == 0x7fff)
1873 /* Compare significands of numbers in internal exploded e-type format.
1874 Guard words are included in the comparison.
1882 register unsigned EMUSHORT
*a
, *b
;
1886 a
+= M
; /* skip up to significand area */
1888 for (i
= M
; i
< NI
; i
++)
1896 if (*(--a
) > *(--b
))
1902 /* Shift significand of exploded e-type X down by 1 bit. */
1906 register unsigned EMUSHORT
*x
;
1908 register unsigned EMUSHORT bits
;
1911 x
+= M
; /* point to significand area */
1914 for (i
= M
; i
< NI
; i
++)
1926 /* Shift significand of exploded e-type X up by 1 bit. */
1930 register unsigned EMUSHORT
*x
;
1932 register unsigned EMUSHORT bits
;
1938 for (i
= M
; i
< NI
; i
++)
1951 /* Shift significand of exploded e-type X down by 8 bits. */
1955 register unsigned EMUSHORT
*x
;
1957 register unsigned EMUSHORT newbyt
, oldbyt
;
1962 for (i
= M
; i
< NI
; i
++)
1972 /* Shift significand of exploded e-type X up by 8 bits. */
1976 register unsigned EMUSHORT
*x
;
1979 register unsigned EMUSHORT newbyt
, oldbyt
;
1984 for (i
= M
; i
< NI
; i
++)
1994 /* Shift significand of exploded e-type X up by 16 bits. */
1998 register unsigned EMUSHORT
*x
;
2001 register unsigned EMUSHORT
*p
;
2006 for (i
= M
; i
< NI
- 1; i
++)
2012 /* Shift significand of exploded e-type X down by 16 bits. */
2016 register unsigned EMUSHORT
*x
;
2019 register unsigned EMUSHORT
*p
;
2024 for (i
= M
; i
< NI
- 1; i
++)
2030 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2034 unsigned EMUSHORT
*x
, *y
;
2036 register unsigned EMULONG a
;
2043 for (i
= M
; i
< NI
; i
++)
2045 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2050 *y
= (unsigned EMUSHORT
) a
;
2056 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2060 unsigned EMUSHORT
*x
, *y
;
2069 for (i
= M
; i
< NI
; i
++)
2071 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2076 *y
= (unsigned EMUSHORT
) a
;
2083 static unsigned EMUSHORT equot
[NI
];
2087 /* Radix 2 shift-and-add versions of multiply and divide */
2090 /* Divide significands */
2094 unsigned EMUSHORT den
[], num
[];
2097 register unsigned EMUSHORT
*p
, *q
;
2098 unsigned EMUSHORT j
;
2104 for (i
= M
; i
< NI
; i
++)
2109 /* Use faster compare and subtraction if denominator has only 15 bits of
2115 for (i
= M
+ 3; i
< NI
; i
++)
2120 if ((den
[M
+ 1] & 1) != 0)
2128 for (i
= 0; i
< NBITS
+ 2; i
++)
2146 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2147 bit + 1 roundoff bit. */
2152 for (i
= 0; i
< NBITS
+ 2; i
++)
2154 if (ecmpm (den
, num
) <= 0)
2157 j
= 1; /* quotient bit = 1 */
2171 /* test for nonzero remainder after roundoff bit */
2174 for (i
= M
; i
< NI
; i
++)
2182 for (i
= 0; i
< NI
; i
++)
2188 /* Multiply significands */
2192 unsigned EMUSHORT a
[], b
[];
2194 unsigned EMUSHORT
*p
, *q
;
2199 for (i
= M
; i
< NI
; i
++)
2204 while (*p
== 0) /* significand is not supposed to be zero */
2209 if ((*p
& 0xff) == 0)
2217 for (i
= 0; i
< k
; i
++)
2221 /* remember if there were any nonzero bits shifted out */
2228 for (i
= 0; i
< NI
; i
++)
2231 /* return flag for lost nonzero bits */
2237 /* Radix 65536 versions of multiply and divide. */
2239 /* Multiply significand of e-type number B
2240 by 16-bit quantity A, return e-type result to C. */
2245 unsigned EMUSHORT b
[], c
[];
2247 register unsigned EMUSHORT
*pp
;
2248 register unsigned EMULONG carry
;
2249 unsigned EMUSHORT
*ps
;
2250 unsigned EMUSHORT p
[NI
];
2251 unsigned EMULONG aa
, m
;
2260 for (i
=M
+1; i
<NI
; i
++)
2270 m
= (unsigned EMULONG
) aa
* *ps
--;
2271 carry
= (m
& 0xffff) + *pp
;
2272 *pp
-- = (unsigned EMUSHORT
)carry
;
2273 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2274 *pp
= (unsigned EMUSHORT
)carry
;
2275 *(pp
-1) = carry
>> 16;
2278 for (i
=M
; i
<NI
; i
++)
2282 /* Divide significands of exploded e-types NUM / DEN. Neither the
2283 numerator NUM nor the denominator DEN is permitted to have its high guard
2288 unsigned EMUSHORT den
[], num
[];
2291 register unsigned EMUSHORT
*p
;
2292 unsigned EMULONG tnum
;
2293 unsigned EMUSHORT j
, tdenm
, tquot
;
2294 unsigned EMUSHORT tprod
[NI
+1];
2300 for (i
=M
; i
<NI
; i
++)
2306 for (i
=M
; i
<NI
; i
++)
2308 /* Find trial quotient digit (the radix is 65536). */
2309 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2311 /* Do not execute the divide instruction if it will overflow. */
2312 if ((tdenm
* 0xffffL
) < tnum
)
2315 tquot
= tnum
/ tdenm
;
2316 /* Multiply denominator by trial quotient digit. */
2317 m16m ((unsigned int)tquot
, den
, tprod
);
2318 /* The quotient digit may have been overestimated. */
2319 if (ecmpm (tprod
, num
) > 0)
2323 if (ecmpm (tprod
, num
) > 0)
2333 /* test for nonzero remainder after roundoff bit */
2336 for (i
=M
; i
<NI
; i
++)
2343 for (i
=0; i
<NI
; i
++)
2349 /* Multiply significands of exploded e-type A and B, result in B. */
2353 unsigned EMUSHORT a
[], b
[];
2355 unsigned EMUSHORT
*p
, *q
;
2356 unsigned EMUSHORT pprod
[NI
];
2357 unsigned EMUSHORT j
;
2362 for (i
=M
; i
<NI
; i
++)
2368 for (i
=M
+1; i
<NI
; i
++)
2376 m16m ((unsigned int) *p
--, b
, pprod
);
2377 eaddm(pprod
, equot
);
2383 for (i
=0; i
<NI
; i
++)
2386 /* return flag for lost nonzero bits */
2392 /* Normalize and round off.
2394 The internal format number to be rounded is S.
2395 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2397 Input SUBFLG indicates whether the number was obtained
2398 by a subtraction operation. In that case if LOST is nonzero
2399 then the number is slightly smaller than indicated.
2401 Input EXP is the biased exponent, which may be negative.
2402 the exponent field of S is ignored but is replaced by
2403 EXP as adjusted by normalization and rounding.
2405 Input RCNTRL is the rounding control. If it is nonzero, the
2406 returned value will be rounded to RNDPRC bits.
2408 For future reference: In order for emdnorm to round off denormal
2409 significands at the right point, the input exponent must be
2410 adjusted to be the actual value it would have after conversion to
2411 the final floating point type. This adjustment has been
2412 implemented for all type conversions (etoe53, etc.) and decimal
2413 conversions, but not for the arithmetic functions (eadd, etc.).
2414 Data types having standard 15-bit exponents are not affected by
2415 this, but SFmode and DFmode are affected. For example, ediv with
2416 rndprc = 24 will not round correctly to 24-bit precision if the
2417 result is denormal. */
2419 static int rlast
= -1;
2421 static unsigned EMUSHORT rmsk
= 0;
2422 static unsigned EMUSHORT rmbit
= 0;
2423 static unsigned EMUSHORT rebit
= 0;
2425 static unsigned EMUSHORT rbit
[NI
];
2428 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2429 unsigned EMUSHORT s
[];
2436 unsigned EMUSHORT r
;
2441 /* a blank significand could mean either zero or infinity. */
2454 if ((j
> NBITS
) && (exp
< 32767))
2462 if (exp
> (EMULONG
) (-NBITS
- 1))
2475 /* Round off, unless told not to by rcntrl. */
2478 /* Set up rounding parameters if the control register changed. */
2479 if (rndprc
!= rlast
)
2486 rw
= NI
- 1; /* low guard word */
2509 /* For DEC or IBM arithmetic */
2526 /* For C4x arithmetic */
2547 /* Shift down 1 temporarily if the data structure has an implied
2548 most significant bit and the number is denormal.
2549 Intel long double denormals also lose one bit of precision. */
2550 if ((exp
<= 0) && (rndprc
!= NBITS
)
2551 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2553 lost
|= s
[NI
- 1] & 1;
2556 /* Clear out all bits below the rounding bit,
2557 remembering in r if any were nonzero. */
2571 if ((r
& rmbit
) != 0)
2576 { /* round to even */
2577 if ((s
[re
] & rebit
) == 0)
2589 /* Undo the temporary shift for denormal values. */
2590 if ((exp
<= 0) && (rndprc
!= NBITS
)
2591 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2596 { /* overflow on roundoff */
2609 for (i
= 2; i
< NI
- 1; i
++)
2612 warning ("floating point overflow");
2616 for (i
= M
+ 1; i
< NI
- 1; i
++)
2619 if ((rndprc
< 64) || (rndprc
== 113))
2634 s
[1] = (unsigned EMUSHORT
) exp
;
2637 /* Subtract. C = B - A, all e type numbers. */
2639 static int subflg
= 0;
2643 unsigned EMUSHORT
*a
, *b
, *c
;
2657 /* Infinity minus infinity is a NaN.
2658 Test for subtracting infinities of the same sign. */
2659 if (eisinf (a
) && eisinf (b
)
2660 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2662 mtherr ("esub", INVALID
);
2671 /* Add. C = A + B, all e type. */
2675 unsigned EMUSHORT
*a
, *b
, *c
;
2679 /* NaN plus anything is a NaN. */
2690 /* Infinity minus infinity is a NaN.
2691 Test for adding infinities of opposite signs. */
2692 if (eisinf (a
) && eisinf (b
)
2693 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2695 mtherr ("esub", INVALID
);
2704 /* Arithmetic common to both addition and subtraction. */
2708 unsigned EMUSHORT
*a
, *b
, *c
;
2710 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2712 EMULONG lt
, lta
, ltb
;
2733 /* compare exponents */
2738 { /* put the larger number in bi */
2748 if (lt
< (EMULONG
) (-NBITS
- 1))
2749 goto done
; /* answer same as larger addend */
2751 lost
= eshift (ai
, k
); /* shift the smaller number down */
2755 /* exponents were the same, so must compare significands */
2758 { /* the numbers are identical in magnitude */
2759 /* if different signs, result is zero */
2765 /* if same sign, result is double */
2766 /* double denormalized tiny number */
2767 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2772 /* add 1 to exponent unless both are zero! */
2773 for (j
= 1; j
< NI
- 1; j
++)
2789 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2793 { /* put the larger number in bi */
2809 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2815 /* Divide: C = B/A, all e type. */
2819 unsigned EMUSHORT
*a
, *b
, *c
;
2821 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2823 EMULONG lt
, lta
, ltb
;
2825 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2826 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2827 sign
= eisneg(a
) ^ eisneg(b
);
2830 /* Return any NaN input. */
2841 /* Zero over zero, or infinity over infinity, is a NaN. */
2842 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2843 || (eisinf (a
) && eisinf (b
)))
2845 mtherr ("ediv", INVALID
);
2850 /* Infinity over anything else is infinity. */
2857 /* Anything else over infinity is zero. */
2869 { /* See if numerator is zero. */
2870 for (i
= 1; i
< NI
- 1; i
++)
2874 ltb
-= enormlz (bi
);
2884 { /* possible divide by zero */
2885 for (i
= 1; i
< NI
- 1; i
++)
2889 lta
-= enormlz (ai
);
2893 /* Divide by zero is not an invalid operation.
2894 It is a divide-by-zero operation! */
2896 mtherr ("ediv", SING
);
2902 /* calculate exponent */
2903 lt
= ltb
- lta
+ EXONE
;
2904 emdnorm (bi
, i
, 0, lt
, 64);
2911 && (ecmp (c
, ezero
) != 0)
2914 *(c
+(NE
-1)) |= 0x8000;
2916 *(c
+(NE
-1)) &= ~0x8000;
2919 /* Multiply e-types A and B, return e-type product C. */
2923 unsigned EMUSHORT
*a
, *b
, *c
;
2925 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2927 EMULONG lt
, lta
, ltb
;
2929 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2930 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2931 sign
= eisneg(a
) ^ eisneg(b
);
2934 /* NaN times anything is the same NaN. */
2945 /* Zero times infinity is a NaN. */
2946 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2947 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2949 mtherr ("emul", INVALID
);
2954 /* Infinity times anything else is infinity. */
2956 if (eisinf (a
) || eisinf (b
))
2968 for (i
= 1; i
< NI
- 1; i
++)
2972 lta
-= enormlz (ai
);
2983 for (i
= 1; i
< NI
- 1; i
++)
2987 ltb
-= enormlz (bi
);
2996 /* Multiply significands */
2998 /* calculate exponent */
2999 lt
= lta
+ ltb
- (EXONE
- 1);
3000 emdnorm (bi
, j
, 0, lt
, 64);
3007 && (ecmp (c
, ezero
) != 0)
3010 *(c
+(NE
-1)) |= 0x8000;
3012 *(c
+(NE
-1)) &= ~0x8000;
3015 /* Convert double precision PE to e-type Y. */
3019 unsigned EMUSHORT
*pe
, *y
;
3028 ibmtoe (pe
, y
, DFmode
);
3033 c4xtoe (pe
, y
, HFmode
);
3036 register unsigned EMUSHORT r
;
3037 register unsigned EMUSHORT
*e
, *p
;
3038 unsigned EMUSHORT yy
[NI
];
3042 denorm
= 0; /* flag if denormalized number */
3044 if (! REAL_WORDS_BIG_ENDIAN
)
3050 yy
[M
] = (r
& 0x0f) | 0x10;
3051 r
&= ~0x800f; /* strip sign and 4 significand bits */
3056 if (! REAL_WORDS_BIG_ENDIAN
)
3058 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3059 || (pe
[1] != 0) || (pe
[0] != 0))
3061 enan (y
, yy
[0] != 0);
3067 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3068 || (pe
[2] != 0) || (pe
[3] != 0))
3070 enan (y
, yy
[0] != 0);
3081 #endif /* INFINITY */
3083 /* If zero exponent, then the significand is denormalized.
3084 So take back the understood high significand bit. */
3095 if (! REAL_WORDS_BIG_ENDIAN
)
3112 /* If zero exponent, then normalize the significand. */
3113 if ((k
= enormlz (yy
)) > NBITS
)
3116 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3119 #endif /* not C4X */
3120 #endif /* not IBM */
3121 #endif /* not DEC */
3124 /* Convert double extended precision float PE to e type Y. */
3128 unsigned EMUSHORT
*pe
, *y
;
3130 unsigned EMUSHORT yy
[NI
];
3131 unsigned EMUSHORT
*e
, *p
, *q
;
3136 for (i
= 0; i
< NE
- 5; i
++)
3138 /* This precision is not ordinarily supported on DEC or IBM. */
3140 for (i
= 0; i
< 5; i
++)
3144 p
= &yy
[0] + (NE
- 1);
3147 for (i
= 0; i
< 5; i
++)
3151 if (! REAL_WORDS_BIG_ENDIAN
)
3153 for (i
= 0; i
< 5; i
++)
3156 /* For denormal long double Intel format, shift significand up one
3157 -- but only if the top significand bit is zero. A top bit of 1
3158 is "pseudodenormal" when the exponent is zero. */
3159 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3161 unsigned EMUSHORT temp
[NI
];
3171 p
= &yy
[0] + (NE
- 1);
3172 #ifdef ARM_EXTENDED_IEEE_FORMAT
3173 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3174 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3180 for (i
= 0; i
< 4; i
++)
3185 /* Point to the exponent field and check max exponent cases. */
3187 if ((*p
& 0x7fff) == 0x7fff)
3190 if (! REAL_WORDS_BIG_ENDIAN
)
3192 for (i
= 0; i
< 4; i
++)
3194 if ((i
!= 3 && pe
[i
] != 0)
3195 /* Anything but 0x8000 here, including 0, is a NaN. */
3196 || (i
== 3 && pe
[i
] != 0x8000))
3198 enan (y
, (*p
& 0x8000) != 0);
3205 #ifdef ARM_EXTENDED_IEEE_FORMAT
3206 for (i
= 2; i
<= 5; i
++)
3210 enan (y
, (*p
& 0x8000) != 0);
3215 /* In Motorola extended precision format, the most significant
3216 bit of an infinity mantissa could be either 1 or 0. It is
3217 the lower order bits that tell whether the value is a NaN. */
3218 if ((pe
[2] & 0x7fff) != 0)
3221 for (i
= 3; i
<= 5; i
++)
3226 enan (y
, (*p
& 0x8000) != 0);
3230 #endif /* not ARM */
3239 #endif /* INFINITY */
3242 for (i
= 0; i
< NE
; i
++)
3246 /* Convert 128-bit long double precision float PE to e type Y. */
3250 unsigned EMUSHORT
*pe
, *y
;
3252 register unsigned EMUSHORT r
;
3253 unsigned EMUSHORT
*e
, *p
;
3254 unsigned EMUSHORT yy
[NI
];
3261 if (! REAL_WORDS_BIG_ENDIAN
)
3273 if (! REAL_WORDS_BIG_ENDIAN
)
3275 for (i
= 0; i
< 7; i
++)
3279 enan (y
, yy
[0] != 0);
3286 for (i
= 1; i
< 8; i
++)
3290 enan (y
, yy
[0] != 0);
3302 #endif /* INFINITY */
3306 if (! REAL_WORDS_BIG_ENDIAN
)
3308 for (i
= 0; i
< 7; i
++)
3314 for (i
= 0; i
< 7; i
++)
3318 /* If denormal, remove the implied bit; else shift down 1. */
3331 /* Convert single precision float PE to e type Y. */
3335 unsigned EMUSHORT
*pe
, *y
;
3339 ibmtoe (pe
, y
, SFmode
);
3345 c4xtoe (pe
, y
, QFmode
);
3349 register unsigned EMUSHORT r
;
3350 register unsigned EMUSHORT
*e
, *p
;
3351 unsigned EMUSHORT yy
[NI
];
3355 denorm
= 0; /* flag if denormalized number */
3358 if (! REAL_WORDS_BIG_ENDIAN
)
3368 yy
[M
] = (r
& 0x7f) | 0200;
3369 r
&= ~0x807f; /* strip sign and 7 significand bits */
3374 if (REAL_WORDS_BIG_ENDIAN
)
3376 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3378 enan (y
, yy
[0] != 0);
3384 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3386 enan (y
, yy
[0] != 0);
3397 #endif /* INFINITY */
3399 /* If zero exponent, then the significand is denormalized.
3400 So take back the understood high significand bit. */
3413 if (! REAL_WORDS_BIG_ENDIAN
)
3423 { /* if zero exponent, then normalize the significand */
3424 if ((k
= enormlz (yy
)) > NBITS
)
3427 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3430 #endif /* not C4X */
3431 #endif /* not IBM */
3434 /* Convert e-type X to IEEE 128-bit long double format E. */
3438 unsigned EMUSHORT
*x
, *e
;
3440 unsigned EMUSHORT xi
[NI
];
3447 make_nan (e
, eisneg (x
), TFmode
);
3452 exp
= (EMULONG
) xi
[E
];
3457 /* round off to nearest or even */
3460 emdnorm (xi
, 0, 0, exp
, 64);
3466 /* Convert exploded e-type X, that has already been rounded to
3467 113-bit precision, to IEEE 128-bit long double format Y. */
3471 unsigned EMUSHORT
*a
, *b
;
3473 register unsigned EMUSHORT
*p
, *q
;
3474 unsigned EMUSHORT i
;
3479 make_nan (b
, eiisneg (a
), TFmode
);
3484 if (REAL_WORDS_BIG_ENDIAN
)
3487 q
= b
+ 7; /* point to output exponent */
3489 /* If not denormal, delete the implied bit. */
3494 /* combine sign and exponent */
3496 if (REAL_WORDS_BIG_ENDIAN
)
3499 *q
++ = *p
++ | 0x8000;
3506 *q
-- = *p
++ | 0x8000;
3510 /* skip over guard word */
3512 /* move the significand */
3513 if (REAL_WORDS_BIG_ENDIAN
)
3515 for (i
= 0; i
< 7; i
++)
3520 for (i
= 0; i
< 7; i
++)
3525 /* Convert e-type X to IEEE double extended format E. */
3529 unsigned EMUSHORT
*x
, *e
;
3531 unsigned EMUSHORT xi
[NI
];
3538 make_nan (e
, eisneg (x
), XFmode
);
3543 /* adjust exponent for offset */
3544 exp
= (EMULONG
) xi
[E
];
3549 /* round off to nearest or even */
3552 emdnorm (xi
, 0, 0, exp
, 64);
3558 /* Convert exploded e-type X, that has already been rounded to
3559 64-bit precision, to IEEE double extended format Y. */
3563 unsigned EMUSHORT
*a
, *b
;
3565 register unsigned EMUSHORT
*p
, *q
;
3566 unsigned EMUSHORT i
;
3571 make_nan (b
, eiisneg (a
), XFmode
);
3575 /* Shift denormal long double Intel format significand down one bit. */
3576 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3586 if (REAL_WORDS_BIG_ENDIAN
)
3590 q
= b
+ 4; /* point to output exponent */
3591 #if LONG_DOUBLE_TYPE_SIZE == 96
3592 /* Clear the last two bytes of 12-byte Intel format */
3598 /* combine sign and exponent */
3602 *q
++ = *p
++ | 0x8000;
3609 *q
-- = *p
++ | 0x8000;
3614 if (REAL_WORDS_BIG_ENDIAN
)
3616 #ifdef ARM_EXTENDED_IEEE_FORMAT
3617 /* The exponent is in the lowest 15 bits of the first word. */
3618 *q
++ = i
? 0x8000 : 0;
3622 *q
++ = *p
++ | 0x8000;
3631 *q
-- = *p
++ | 0x8000;
3636 /* skip over guard word */
3638 /* move the significand */
3640 for (i
= 0; i
< 4; i
++)
3644 for (i
= 0; i
< 4; i
++)
3648 if (REAL_WORDS_BIG_ENDIAN
)
3650 for (i
= 0; i
< 4; i
++)
3658 /* Intel long double infinity significand. */
3666 for (i
= 0; i
< 4; i
++)
3672 /* e type to double precision. */
3675 /* Convert e-type X to DEC-format double E. */
3679 unsigned EMUSHORT
*x
, *e
;
3681 etodec (x
, e
); /* see etodec.c */
3684 /* Convert exploded e-type X, that has already been rounded to
3685 56-bit double precision, to DEC double Y. */
3689 unsigned EMUSHORT
*x
, *y
;
3696 /* Convert e-type X to IBM 370-format double E. */
3700 unsigned EMUSHORT
*x
, *e
;
3702 etoibm (x
, e
, DFmode
);
3705 /* Convert exploded e-type X, that has already been rounded to
3706 56-bit precision, to IBM 370 double Y. */
3710 unsigned EMUSHORT
*x
, *y
;
3712 toibm (x
, y
, DFmode
);
3715 #else /* it's neither DEC nor IBM */
3717 /* Convert e-type X to C4X-format double E. */
3721 unsigned EMUSHORT
*x
, *e
;
3723 etoc4x (x
, e
, HFmode
);
3726 /* Convert exploded e-type X, that has already been rounded to
3727 56-bit precision, to IBM 370 double Y. */
3731 unsigned EMUSHORT
*x
, *y
;
3733 toc4x (x
, y
, HFmode
);
3736 #else /* it's neither DEC nor IBM nor C4X */
3738 /* Convert e-type X to IEEE double E. */
3742 unsigned EMUSHORT
*x
, *e
;
3744 unsigned EMUSHORT xi
[NI
];
3751 make_nan (e
, eisneg (x
), DFmode
);
3756 /* adjust exponent for offsets */
3757 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3762 /* round off to nearest or even */
3765 emdnorm (xi
, 0, 0, exp
, 64);
3771 /* Convert exploded e-type X, that has already been rounded to
3772 53-bit precision, to IEEE double Y. */
3776 unsigned EMUSHORT
*x
, *y
;
3778 unsigned EMUSHORT i
;
3779 unsigned EMUSHORT
*p
;
3784 make_nan (y
, eiisneg (x
), DFmode
);
3790 if (! REAL_WORDS_BIG_ENDIAN
)
3793 *y
= 0; /* output high order */
3795 *y
= 0x8000; /* output sign bit */
3798 if (i
>= (unsigned int) 2047)
3800 /* Saturate at largest number less than infinity. */
3803 if (! REAL_WORDS_BIG_ENDIAN
)
3817 *y
|= (unsigned EMUSHORT
) 0x7fef;
3818 if (! REAL_WORDS_BIG_ENDIAN
)
3843 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3844 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3845 if (! REAL_WORDS_BIG_ENDIAN
)
3860 #endif /* not C4X */
3861 #endif /* not IBM */
3862 #endif /* not DEC */
3866 /* e type to single precision. */
3869 /* Convert e-type X to IBM 370 float E. */
3873 unsigned EMUSHORT
*x
, *e
;
3875 etoibm (x
, e
, SFmode
);
3878 /* Convert exploded e-type X, that has already been rounded to
3879 float precision, to IBM 370 float Y. */
3883 unsigned EMUSHORT
*x
, *y
;
3885 toibm (x
, y
, SFmode
);
3891 /* Convert e-type X to C4X float E. */
3895 unsigned EMUSHORT
*x
, *e
;
3897 etoc4x (x
, e
, QFmode
);
3900 /* Convert exploded e-type X, that has already been rounded to
3901 float precision, to IBM 370 float Y. */
3905 unsigned EMUSHORT
*x
, *y
;
3907 toc4x (x
, y
, QFmode
);
3912 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3916 unsigned EMUSHORT
*x
, *e
;
3919 unsigned EMUSHORT xi
[NI
];
3925 make_nan (e
, eisneg (x
), SFmode
);
3930 /* adjust exponent for offsets */
3931 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3936 /* round off to nearest or even */
3939 emdnorm (xi
, 0, 0, exp
, 64);
3945 /* Convert exploded e-type X, that has already been rounded to
3946 float precision, to IEEE float Y. */
3950 unsigned EMUSHORT
*x
, *y
;
3952 unsigned EMUSHORT i
;
3953 unsigned EMUSHORT
*p
;
3958 make_nan (y
, eiisneg (x
), SFmode
);
3964 if (! REAL_WORDS_BIG_ENDIAN
)
3970 *y
= 0; /* output high order */
3972 *y
= 0x8000; /* output sign bit */
3975 /* Handle overflow cases. */
3979 *y
|= (unsigned EMUSHORT
) 0x7f80;
3984 if (! REAL_WORDS_BIG_ENDIAN
)
3992 #else /* no INFINITY */
3993 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3998 if (! REAL_WORDS_BIG_ENDIAN
)
4009 #endif /* no INFINITY */
4021 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4022 /* High order output already has sign bit set. */
4028 if (! REAL_WORDS_BIG_ENDIAN
)
4037 #endif /* not C4X */
4038 #endif /* not IBM */
4040 /* Compare two e type numbers.
4044 -2 if either a or b is a NaN. */
4048 unsigned EMUSHORT
*a
, *b
;
4050 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4051 register unsigned EMUSHORT
*p
, *q
;
4056 if (eisnan (a
) || eisnan (b
))
4065 { /* the signs are different */
4067 for (i
= 1; i
< NI
- 1; i
++)
4081 /* both are the same sign */
4096 return (0); /* equality */
4100 if (*(--p
) > *(--q
))
4101 return (msign
); /* p is bigger */
4103 return (-msign
); /* p is littler */
4107 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4111 unsigned EMUSHORT
*x
, *y
;
4118 /* Convert HOST_WIDE_INT LP to e type Y. */
4123 unsigned EMUSHORT
*y
;
4125 unsigned EMUSHORT yi
[NI
];
4126 unsigned HOST_WIDE_INT ll
;
4132 /* make it positive */
4133 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4134 yi
[0] = 0xffff; /* put correct sign in the e type number */
4138 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4140 /* move the long integer to yi significand area */
4141 #if HOST_BITS_PER_WIDE_INT == 64
4142 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4143 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4144 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4145 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4146 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4148 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4149 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4150 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4153 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4154 ecleaz (yi
); /* it was zero */
4156 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4157 emovo (yi
, y
); /* output the answer */
4160 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4164 unsigned HOST_WIDE_INT
*lp
;
4165 unsigned EMUSHORT
*y
;
4167 unsigned EMUSHORT yi
[NI
];
4168 unsigned HOST_WIDE_INT ll
;
4174 /* move the long integer to ayi significand area */
4175 #if HOST_BITS_PER_WIDE_INT == 64
4176 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4177 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4178 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4179 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4180 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4182 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4183 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4184 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4187 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4188 ecleaz (yi
); /* it was zero */
4190 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4191 emovo (yi
, y
); /* output the answer */
4195 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4196 part FRAC of e-type (packed internal format) floating point input X.
4197 The integer output I has the sign of the input, except that
4198 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4199 The output e-type fraction FRAC is the positive fractional
4204 unsigned EMUSHORT
*x
;
4206 unsigned EMUSHORT
*frac
;
4208 unsigned EMUSHORT xi
[NI
];
4210 unsigned HOST_WIDE_INT ll
;
4213 k
= (int) xi
[E
] - (EXONE
- 1);
4216 /* if exponent <= 0, integer = 0 and real output is fraction */
4221 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4223 /* long integer overflow: output large integer
4224 and correct fraction */
4226 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4229 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4230 /* In this case, let it overflow and convert as if unsigned. */
4231 euifrac (x
, &ll
, frac
);
4232 *i
= (HOST_WIDE_INT
) ll
;
4235 /* In other cases, return the largest positive integer. */
4236 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4241 warning ("overflow on truncation to integer");
4245 /* Shift more than 16 bits: first shift up k-16 mod 16,
4246 then shift up by 16's. */
4247 j
= k
- ((k
>> 4) << 4);
4254 ll
= (ll
<< 16) | xi
[M
];
4256 while ((k
-= 16) > 0);
4263 /* shift not more than 16 bits */
4265 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4272 if ((k
= enormlz (xi
)) > NBITS
)
4275 xi
[E
] -= (unsigned EMUSHORT
) k
;
4281 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4282 FRAC of e-type X. A negative input yields integer output = 0 but
4283 correct fraction. */
4286 euifrac (x
, i
, frac
)
4287 unsigned EMUSHORT
*x
;
4288 unsigned HOST_WIDE_INT
*i
;
4289 unsigned EMUSHORT
*frac
;
4291 unsigned HOST_WIDE_INT ll
;
4292 unsigned EMUSHORT xi
[NI
];
4296 k
= (int) xi
[E
] - (EXONE
- 1);
4299 /* if exponent <= 0, integer = 0 and argument is fraction */
4304 if (k
> HOST_BITS_PER_WIDE_INT
)
4306 /* Long integer overflow: output large integer
4307 and correct fraction.
4308 Note, the BSD microvax compiler says that ~(0UL)
4309 is a syntax error. */
4313 warning ("overflow on truncation to unsigned integer");
4317 /* Shift more than 16 bits: first shift up k-16 mod 16,
4318 then shift up by 16's. */
4319 j
= k
- ((k
>> 4) << 4);
4326 ll
= (ll
<< 16) | xi
[M
];
4328 while ((k
-= 16) > 0);
4333 /* shift not more than 16 bits */
4335 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4338 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4344 if ((k
= enormlz (xi
)) > NBITS
)
4347 xi
[E
] -= (unsigned EMUSHORT
) k
;
4352 /* Shift the significand of exploded e-type X up or down by SC bits. */
4356 unsigned EMUSHORT
*x
;
4359 unsigned EMUSHORT lost
;
4360 unsigned EMUSHORT
*p
;
4373 lost
|= *p
; /* remember lost bits */
4414 return ((int) lost
);
4417 /* Shift normalize the significand area of exploded e-type X.
4418 Return the shift count (up = positive). */
4422 unsigned EMUSHORT x
[];
4424 register unsigned EMUSHORT
*p
;
4433 return (0); /* already normalized */
4439 /* With guard word, there are NBITS+16 bits available.
4440 Return true if all are zero. */
4444 /* see if high byte is zero */
4445 while ((*p
& 0xff00) == 0)
4450 /* now shift 1 bit at a time */
4451 while ((*p
& 0x8000) == 0)
4457 mtherr ("enormlz", UNDERFLOW
);
4463 /* Normalize by shifting down out of the high guard word
4464 of the significand */
4479 mtherr ("enormlz", OVERFLOW
);
4486 /* Powers of ten used in decimal <-> binary conversions. */
4491 #if LONG_DOUBLE_TYPE_SIZE == 128
4492 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4494 {0x6576, 0x4a92, 0x804a, 0x153f,
4495 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4496 {0x6a32, 0xce52, 0x329a, 0x28ce,
4497 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4498 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4499 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4500 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4501 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4502 {0x851e, 0xeab7, 0x98fe, 0x901b,
4503 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4504 {0x0235, 0x0137, 0x36b1, 0x336c,
4505 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4506 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4507 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4508 {0x0000, 0x0000, 0x0000, 0x0000,
4509 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4510 {0x0000, 0x0000, 0x0000, 0x0000,
4511 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4512 {0x0000, 0x0000, 0x0000, 0x0000,
4513 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4514 {0x0000, 0x0000, 0x0000, 0x0000,
4515 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4516 {0x0000, 0x0000, 0x0000, 0x0000,
4517 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4518 {0x0000, 0x0000, 0x0000, 0x0000,
4519 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4522 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4524 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4525 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4526 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4527 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4528 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4529 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4530 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4531 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4532 {0xa23e, 0x5308, 0xfefb, 0x1155,
4533 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4534 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4535 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4536 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4537 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4538 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4539 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4540 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4541 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4542 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4543 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4544 {0xc155, 0xa4a8, 0x404e, 0x6113,
4545 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4546 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4547 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4548 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4549 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4552 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4553 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4555 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4556 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4557 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4558 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4559 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4560 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4561 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4562 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4563 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4564 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4565 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4566 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4567 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4570 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4572 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4573 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4574 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4575 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4576 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4577 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4578 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4579 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4580 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4581 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4582 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4583 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4584 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4589 /* Convert float value X to ASCII string STRING with NDIG digits after
4590 the decimal point. */
4593 e24toasc (x
, string
, ndigs
)
4594 unsigned EMUSHORT x
[];
4598 unsigned EMUSHORT w
[NI
];
4601 etoasc (w
, string
, ndigs
);
4604 /* Convert double value X to ASCII string STRING with NDIG digits after
4605 the decimal point. */
4608 e53toasc (x
, string
, ndigs
)
4609 unsigned EMUSHORT x
[];
4613 unsigned EMUSHORT w
[NI
];
4616 etoasc (w
, string
, ndigs
);
4619 /* Convert double extended value X to ASCII string STRING with NDIG digits
4620 after the decimal point. */
4623 e64toasc (x
, string
, ndigs
)
4624 unsigned EMUSHORT x
[];
4628 unsigned EMUSHORT w
[NI
];
4631 etoasc (w
, string
, ndigs
);
4634 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4635 after the decimal point. */
4638 e113toasc (x
, string
, ndigs
)
4639 unsigned EMUSHORT x
[];
4643 unsigned EMUSHORT w
[NI
];
4646 etoasc (w
, string
, ndigs
);
4650 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4651 the decimal point. */
4653 static char wstring
[80]; /* working storage for ASCII output */
4656 etoasc (x
, string
, ndigs
)
4657 unsigned EMUSHORT x
[];
4662 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4663 unsigned EMUSHORT
*p
, *r
, *ten
;
4664 unsigned EMUSHORT sign
;
4665 int i
, j
, k
, expon
, rndsav
;
4667 unsigned EMUSHORT m
;
4678 sprintf (wstring
, " NaN ");
4682 rndprc
= NBITS
; /* set to full precision */
4683 emov (x
, y
); /* retain external format */
4684 if (y
[NE
- 1] & 0x8000)
4687 y
[NE
- 1] &= 0x7fff;
4694 ten
= &etens
[NTEN
][0];
4696 /* Test for zero exponent */
4699 for (k
= 0; k
< NE
- 1; k
++)
4702 goto tnzro
; /* denormalized number */
4704 goto isone
; /* valid all zeros */
4708 /* Test for infinity. */
4709 if (y
[NE
- 1] == 0x7fff)
4712 sprintf (wstring
, " -Infinity ");
4714 sprintf (wstring
, " Infinity ");
4718 /* Test for exponent nonzero but significand denormalized.
4719 * This is an error condition.
4721 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4723 mtherr ("etoasc", DOMAIN
);
4724 sprintf (wstring
, "NaN");
4728 /* Compare to 1.0 */
4737 { /* Number is greater than 1 */
4738 /* Convert significand to an integer and strip trailing decimal zeros. */
4740 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4742 p
= &etens
[NTEN
- 4][0];
4748 for (j
= 0; j
< NE
- 1; j
++)
4761 /* Rescale from integer significand */
4762 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4764 /* Find power of 10 */
4768 /* An unordered compare result shouldn't happen here. */
4769 while (ecmp (ten
, u
) <= 0)
4771 if (ecmp (p
, u
) <= 0)
4784 { /* Number is less than 1.0 */
4785 /* Pad significand with trailing decimal zeros. */
4788 while ((y
[NE
- 2] & 0x8000) == 0)
4797 for (i
= 0; i
< NDEC
+ 1; i
++)
4799 if ((w
[NI
- 1] & 0x7) != 0)
4801 /* multiply by 10 */
4814 if (eone
[NE
- 1] <= u
[1])
4826 while (ecmp (eone
, w
) > 0)
4828 if (ecmp (p
, w
) >= 0)
4843 /* Find the first (leading) digit. */
4849 digit
= equot
[NI
- 1];
4850 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4858 digit
= equot
[NI
- 1];
4866 /* Examine number of digits requested by caller. */
4884 *s
++ = (char)digit
+ '0';
4887 /* Generate digits after the decimal point. */
4888 for (k
= 0; k
<= ndigs
; k
++)
4890 /* multiply current number by 10, without normalizing */
4897 *s
++ = (char) equot
[NI
- 1] + '0';
4899 digit
= equot
[NI
- 1];
4902 /* round off the ASCII string */
4905 /* Test for critical rounding case in ASCII output. */
4909 if (ecmp (t
, ezero
) != 0)
4910 goto roun
; /* round to nearest */
4911 if ((*(s
- 1) & 1) == 0)
4912 goto doexp
; /* round to even */
4914 /* Round up and propagate carry-outs */
4918 /* Carry out to most significant digit? */
4925 /* Most significant digit carries to 10? */
4933 /* Round up and carry out from less significant digits */
4945 sprintf (ss, "e+%d", expon);
4947 sprintf (ss, "e%d", expon);
4949 sprintf (ss
, "e%d", expon
);
4952 /* copy out the working string */
4955 while (*ss
== ' ') /* strip possible leading space */
4957 while ((*s
++ = *ss
++) != '\0')
4962 /* Convert ASCII string to floating point.
4964 Numeric input is a free format decimal number of any length, with
4965 or without decimal point. Entering E after the number followed by an
4966 integer number causes the second number to be interpreted as a power of
4967 10 to be multiplied by the first number (i.e., "scientific" notation). */
4969 /* Convert ASCII string S to single precision float value Y. */
4974 unsigned EMUSHORT
*y
;
4980 /* Convert ASCII string S to double precision value Y. */
4985 unsigned EMUSHORT
*y
;
4987 #if defined(DEC) || defined(IBM)
4999 /* Convert ASCII string S to double extended value Y. */
5004 unsigned EMUSHORT
*y
;
5009 /* Convert ASCII string S to 128-bit long double Y. */
5014 unsigned EMUSHORT
*y
;
5016 asctoeg (s
, y
, 113);
5019 /* Convert ASCII string S to e type Y. */
5024 unsigned EMUSHORT
*y
;
5026 asctoeg (s
, y
, NBITS
);
5029 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5033 asctoeg (ss
, y
, oprec
)
5035 unsigned EMUSHORT
*y
;
5038 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5039 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5040 int k
, trail
, c
, rndsav
;
5042 unsigned EMUSHORT nsign
, *p
;
5043 char *sp
, *s
, *lstr
;
5045 /* Copy the input string. */
5046 lstr
= (char *) alloca (strlen (ss
) + 1);
5048 while (*s
== ' ') /* skip leading spaces */
5051 while ((*sp
++ = *s
++) != '\0')
5056 rndprc
= NBITS
; /* Set to full precision */
5069 if ((k
>= 0) && (k
<= 9))
5071 /* Ignore leading zeros */
5072 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5074 /* Identify and strip trailing zeros after the decimal point. */
5075 if ((trail
== 0) && (decflg
!= 0))
5078 while ((*sp
>= '0') && (*sp
<= '9'))
5080 /* Check for syntax error */
5082 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
5083 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5094 /* If enough digits were given to more than fill up the yy register,
5095 continuing until overflow into the high guard word yy[2]
5096 guarantees that there will be a roundoff bit at the top
5097 of the low guard word after normalization. */
5102 nexp
+= 1; /* count digits after decimal point */
5103 eshup1 (yy
); /* multiply current number by 10 */
5109 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5114 /* Mark any lost non-zero digit. */
5116 /* Count lost digits before the decimal point. */
5131 case '.': /* decimal point */
5161 mtherr ("asctoe", DOMAIN
);
5170 /* Exponent interpretation */
5172 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5173 for (k
= 0; k
< NI
; k
++)
5184 /* check for + or - */
5192 while ((*s
>= '0') && (*s
<= '9'))
5196 if (exp
> -(MINDECEXP
))
5206 if (exp
> MAXDECEXP
)
5210 yy
[E
] = 0x7fff; /* infinity */
5213 if (exp
< MINDECEXP
)
5222 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5223 while ((nexp
> 0) && (yy
[2] == 0))
5235 if ((k
= enormlz (yy
)) > NBITS
)
5240 lexp
= (EXONE
- 1 + NBITS
) - k
;
5241 emdnorm (yy
, lost
, 0, lexp
, 64);
5243 /* Convert to external format:
5245 Multiply by 10**nexp. If precision is 64 bits,
5246 the maximum relative error incurred in forming 10**n
5247 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5248 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5249 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5264 /* Punt. Can't handle this without 2 divides. */
5265 emovi (etens
[0], tt
);
5272 p
= &etens
[NTEN
][0];
5282 while (exp
<= MAXP
);
5300 /* Round and convert directly to the destination type */
5302 lexp
-= EXONE
- 0x3ff;
5304 else if (oprec
== 24 || oprec
== 32)
5305 lexp
-= (EXONE
- 0x7f);
5308 else if (oprec
== 24 || oprec
== 56)
5309 lexp
-= EXONE
- (0x41 << 2);
5311 else if (oprec
== 24)
5312 lexp
-= EXONE
- 0177;
5316 else if (oprec
== 56)
5317 lexp
-= EXONE
- 0201;
5320 emdnorm (yy
, k
, 0, lexp
, 64);
5330 todec (yy
, y
); /* see etodec.c */
5335 toibm (yy
, y
, DFmode
);
5340 toc4x (yy
, y
, HFmode
);
5364 /* Return Y = largest integer not greater than X (truncated toward minus
5367 static unsigned EMUSHORT bmask
[] =
5390 unsigned EMUSHORT x
[], y
[];
5392 register unsigned EMUSHORT
*p
;
5394 unsigned EMUSHORT f
[NE
];
5396 emov (x
, f
); /* leave in external format */
5397 expon
= (int) f
[NE
- 1];
5398 e
= (expon
& 0x7fff) - (EXONE
- 1);
5404 /* number of bits to clear out */
5416 /* clear the remaining bits */
5418 /* truncate negatives toward minus infinity */
5421 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5423 for (i
= 0; i
< NE
- 1; i
++)
5436 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5437 For example, 1.1 = 0.55 * 2^1. */
5441 unsigned EMUSHORT x
[];
5443 unsigned EMUSHORT s
[];
5445 unsigned EMUSHORT xi
[NI
];
5449 /* Handle denormalized numbers properly using long integer exponent. */
5450 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5458 *exp
= (int) (li
- 0x3ffe);
5462 /* Return e type Y = X * 2^PWR2. */
5466 unsigned EMUSHORT x
[];
5468 unsigned EMUSHORT y
[];
5470 unsigned EMUSHORT xi
[NI
];
5478 emdnorm (xi
, i
, i
, li
, 64);
5484 /* C = remainder after dividing B by A, all e type values.
5485 Least significant integer quotient bits left in EQUOT. */
5489 unsigned EMUSHORT a
[], b
[], c
[];
5491 unsigned EMUSHORT den
[NI
], num
[NI
];
5495 || (ecmp (a
, ezero
) == 0)
5503 if (ecmp (a
, ezero
) == 0)
5505 mtherr ("eremain", SING
);
5511 eiremain (den
, num
);
5512 /* Sign of remainder = sign of quotient */
5521 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5522 remainder in NUM. */
5526 unsigned EMUSHORT den
[], num
[];
5529 unsigned EMUSHORT j
;
5532 ld
-= enormlz (den
);
5534 ln
-= enormlz (num
);
5538 if (ecmpm (den
, num
) <= 0)
5550 emdnorm (num
, 0, 0, ln
, 0);
5553 /* Report an error condition CODE encountered in function NAME.
5554 CODE is one of the following:
5556 Mnemonic Value Significance
5558 DOMAIN 1 argument domain error
5559 SING 2 function singularity
5560 OVERFLOW 3 overflow range error
5561 UNDERFLOW 4 underflow range error
5562 TLOSS 5 total loss of precision
5563 PLOSS 6 partial loss of precision
5564 INVALID 7 NaN - producing operation
5565 EDOM 33 Unix domain error code
5566 ERANGE 34 Unix range error code
5568 The order of appearance of the following messages is bound to the
5569 error codes defined above. */
5572 static char *ermsg
[NMSGS
] =
5574 "unknown", /* error code 0 */
5575 "domain", /* error code 1 */
5576 "singularity", /* et seq. */
5579 "total loss of precision",
5580 "partial loss of precision",
5594 /* The string passed by the calling program is supposed to be the
5595 name of the function in which the error occurred.
5596 The code argument selects which error message string will be printed. */
5598 if ((code
<= 0) || (code
>= NMSGS
))
5600 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5603 /* Set global error message word */
5608 /* Convert DEC double precision D to e type E. */
5612 unsigned EMUSHORT
*d
;
5613 unsigned EMUSHORT
*e
;
5615 unsigned EMUSHORT y
[NI
];
5616 register unsigned EMUSHORT r
, *p
;
5618 ecleaz (y
); /* start with a zero */
5619 p
= y
; /* point to our number */
5620 r
= *d
; /* get DEC exponent word */
5621 if (*d
& (unsigned int) 0x8000)
5622 *p
= 0xffff; /* fill in our sign */
5623 ++p
; /* bump pointer to our exponent word */
5624 r
&= 0x7fff; /* strip the sign bit */
5625 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5629 r
>>= 7; /* shift exponent word down 7 bits */
5630 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5631 /* add our e type exponent offset */
5632 *p
++ = r
; /* to form our exponent */
5634 r
= *d
++; /* now do the high order mantissa */
5635 r
&= 0177; /* strip off the DEC exponent and sign bits */
5636 r
|= 0200; /* the DEC understood high order mantissa bit */
5637 *p
++ = r
; /* put result in our high guard word */
5639 *p
++ = *d
++; /* fill in the rest of our mantissa */
5643 eshdn8 (y
); /* shift our mantissa down 8 bits */
5648 /* Convert e type X to DEC double precision D. */
5652 unsigned EMUSHORT
*x
, *d
;
5654 unsigned EMUSHORT xi
[NI
];
5659 /* Adjust exponent for offsets. */
5660 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5661 /* Round off to nearest or even. */
5664 emdnorm (xi
, 0, 0, exp
, 64);
5669 /* Convert exploded e-type X, that has already been rounded to
5670 56-bit precision, to DEC format double Y. */
5674 unsigned EMUSHORT
*x
, *y
;
5676 unsigned EMUSHORT i
;
5677 unsigned EMUSHORT
*p
;
5716 /* Convert IBM single/double precision to e type. */
5720 unsigned EMUSHORT
*d
;
5721 unsigned EMUSHORT
*e
;
5722 enum machine_mode mode
;
5724 unsigned EMUSHORT y
[NI
];
5725 register unsigned EMUSHORT r
, *p
;
5728 ecleaz (y
); /* start with a zero */
5729 p
= y
; /* point to our number */
5730 r
= *d
; /* get IBM exponent word */
5731 if (*d
& (unsigned int) 0x8000)
5732 *p
= 0xffff; /* fill in our sign */
5733 ++p
; /* bump pointer to our exponent word */
5734 r
&= 0x7f00; /* strip the sign bit */
5735 r
>>= 6; /* shift exponent word down 6 bits */
5736 /* in fact shift by 8 right and 2 left */
5737 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5738 /* add our e type exponent offset */
5739 *p
++ = r
; /* to form our exponent */
5741 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5742 /* strip off the IBM exponent and sign bits */
5743 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5745 *p
++ = *d
++; /* fill in the rest of our mantissa */
5750 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5753 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5754 /* handle change in RADIX */
5760 /* Convert e type to IBM single/double precision. */
5764 unsigned EMUSHORT
*x
, *d
;
5765 enum machine_mode mode
;
5767 unsigned EMUSHORT xi
[NI
];
5772 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5773 /* round off to nearest or even */
5776 emdnorm (xi
, 0, 0, exp
, 64);
5778 toibm (xi
, d
, mode
);
5783 unsigned EMUSHORT
*x
, *y
;
5784 enum machine_mode mode
;
5786 unsigned EMUSHORT i
;
5787 unsigned EMUSHORT
*p
;
5837 /* Convert C4X single/double precision to e type. */
5841 unsigned EMUSHORT
*d
;
5842 unsigned EMUSHORT
*e
;
5843 enum machine_mode mode
;
5845 unsigned EMUSHORT y
[NI
];
5853 /* Short-circuit the zero case. */
5854 if ((d
[0] == 0x8000)
5856 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5867 ecleaz (y
); /* start with a zero */
5868 r
= d
[0]; /* get sign/exponent part */
5869 if (r
& (unsigned int) 0x0080)
5871 y
[0] = 0xffff; /* fill in our sign */
5879 r
>>= 8; /* Shift exponent word down 8 bits. */
5880 if (r
& 0x80) /* Make the exponent negative if it is. */
5882 r
= r
| (~0 & ~0xff);
5887 /* Now do the high order mantissa. We don't "or" on the high bit
5888 because it is 2 (not 1) and is handled a little differently
5893 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5895 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5905 /* Now do the two's complement on the data. */
5907 carry
= 1; /* Initially add 1 for the two's complement. */
5908 for (i
=size
+ M
; i
> M
; i
--)
5910 if (carry
&& (y
[i
] == 0x0000))
5912 /* We overflowed into the next word, carry is the same. */
5913 y
[i
] = carry
? 0x0000 : 0xffff;
5917 /* No overflow, just invert and add carry. */
5918 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5933 /* Add our e type exponent offset to form our exponent. */
5937 /* Now do the high order mantissa strip off the exponent and sign
5938 bits and add the high 1 bit. */
5939 y
[M
] = d
[0] & 0x7f | 0x80;
5942 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5944 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5954 /* Convert e type to C4X single/double precision. */
5958 unsigned EMUSHORT
*x
, *d
;
5959 enum machine_mode mode
;
5961 unsigned EMUSHORT xi
[NI
];
5967 /* Adjust exponent for offsets. */
5968 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5970 /* Round off to nearest or even. */
5972 rndprc
= mode
== QFmode
? 24 : 32;
5973 emdnorm (xi
, 0, 0, exp
, 64);
5975 toc4x (xi
, d
, mode
);
5980 unsigned EMUSHORT
*x
, *y
;
5981 enum machine_mode mode
;
5988 /* Short-circuit the zero case */
5989 if ((x
[0] == 0) /* Zero exponent and sign */
5991 && (x
[M
] == 0) /* The rest is for zero mantissa */
5993 /* Only check for double if necessary */
5994 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
5996 /* We have a zero. Put it into the output and return. */
6009 /* Negative number require a two's complement conversion of the
6015 i
= ((int) x
[1]) - 0x7f;
6017 /* Now add 1 to the inverted data to do the two's complement. */
6027 x
[v
] = carry
? 0x0000 : 0xffff;
6031 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6037 /* The following is a special case. The C4X negative float requires
6038 a zero in the high bit (because the format is (2 - x) x 2^m), so
6039 if a one is in that bit, we have to shift left one to get rid
6040 of it. This only occurs if the number is -1 x 2^m. */
6041 if (x
[M
+1] & 0x8000)
6043 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6044 high sign bit and shift the exponent. */
6051 i
= ((int) x
[1]) - 0x7f;
6054 if ((i
< -128) || (i
> 127))
6069 y
[0] |= ((i
& 0xff) << 8);
6073 y
[0] |= x
[M
] & 0x7f;
6083 /* Output a binary NaN bit pattern in the target machine's format. */
6085 /* If special NaN bit patterns are required, define them in tm.h
6086 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6092 unsigned EMUSHORT TFbignan
[8] =
6093 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6094 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6102 unsigned EMUSHORT XFbignan
[6] =
6103 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6104 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6112 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6113 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6121 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6122 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6128 make_nan (nan
, sign
, mode
)
6129 unsigned EMUSHORT
*nan
;
6131 enum machine_mode mode
;
6134 unsigned EMUSHORT
*p
;
6138 /* Possibly the `reserved operand' patterns on a VAX can be
6139 used like NaN's, but probably not in the same way as IEEE. */
6140 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6143 if (REAL_WORDS_BIG_ENDIAN
)
6151 if (REAL_WORDS_BIG_ENDIAN
)
6159 if (REAL_WORDS_BIG_ENDIAN
)
6168 if (REAL_WORDS_BIG_ENDIAN
)
6178 if (REAL_WORDS_BIG_ENDIAN
)
6179 *nan
++ = (sign
<< 15) | *p
++;
6182 if (! REAL_WORDS_BIG_ENDIAN
)
6183 *nan
= (sign
<< 15) | *p
;
6186 /* This is the inverse of the function `etarsingle' invoked by
6187 REAL_VALUE_TO_TARGET_SINGLE. */
6190 ereal_unto_float (f
)
6194 unsigned EMUSHORT s
[2];
6195 unsigned EMUSHORT e
[NE
];
6197 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6198 This is the inverse operation to what the function `endian' does. */
6199 if (REAL_WORDS_BIG_ENDIAN
)
6201 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6202 s
[1] = (unsigned EMUSHORT
) f
;
6206 s
[0] = (unsigned EMUSHORT
) f
;
6207 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6209 /* Convert and promote the target float to E-type. */
6211 /* Output E-type to REAL_VALUE_TYPE. */
6217 /* This is the inverse of the function `etardouble' invoked by
6218 REAL_VALUE_TO_TARGET_DOUBLE. */
6221 ereal_unto_double (d
)
6225 unsigned EMUSHORT s
[4];
6226 unsigned EMUSHORT e
[NE
];
6228 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6229 if (REAL_WORDS_BIG_ENDIAN
)
6231 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6232 s
[1] = (unsigned EMUSHORT
) d
[0];
6233 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6234 s
[3] = (unsigned EMUSHORT
) d
[1];
6238 /* Target float words are little-endian. */
6239 s
[0] = (unsigned EMUSHORT
) d
[0];
6240 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6241 s
[2] = (unsigned EMUSHORT
) d
[1];
6242 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6244 /* Convert target double to E-type. */
6246 /* Output E-type to REAL_VALUE_TYPE. */
6252 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6253 This is somewhat like ereal_unto_float, but the input types
6254 for these are different. */
6257 ereal_from_float (f
)
6261 unsigned EMUSHORT s
[2];
6262 unsigned EMUSHORT e
[NE
];
6264 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6265 This is the inverse operation to what the function `endian' does. */
6266 if (REAL_WORDS_BIG_ENDIAN
)
6268 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6269 s
[1] = (unsigned EMUSHORT
) f
;
6273 s
[0] = (unsigned EMUSHORT
) f
;
6274 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6276 /* Convert and promote the target float to E-type. */
6278 /* Output E-type to REAL_VALUE_TYPE. */
6284 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6285 This is somewhat like ereal_unto_double, but the input types
6286 for these are different.
6288 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6289 data format, with no holes in the bit packing. The first element
6290 of the input array holds the bits that would come first in the
6291 target computer's memory. */
6294 ereal_from_double (d
)
6298 unsigned EMUSHORT s
[4];
6299 unsigned EMUSHORT e
[NE
];
6301 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6302 if (REAL_WORDS_BIG_ENDIAN
)
6304 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6305 s
[1] = (unsigned EMUSHORT
) d
[0];
6306 #if HOST_BITS_PER_WIDE_INT == 32
6307 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6308 s
[3] = (unsigned EMUSHORT
) d
[1];
6310 /* In this case the entire target double is contained in the
6311 first array element. The second element of the input is
6313 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6314 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6319 /* Target float words are little-endian. */
6320 s
[0] = (unsigned EMUSHORT
) d
[0];
6321 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6322 #if HOST_BITS_PER_WIDE_INT == 32
6323 s
[2] = (unsigned EMUSHORT
) d
[1];
6324 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6326 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6327 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6330 /* Convert target double to E-type. */
6332 /* Output E-type to REAL_VALUE_TYPE. */
6339 /* Convert target computer unsigned 64-bit integer to e-type.
6340 The endian-ness of DImode follows the convention for integers,
6341 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6345 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6346 unsigned EMUSHORT
*e
;
6348 unsigned EMUSHORT yi
[NI
];
6352 if (WORDS_BIG_ENDIAN
)
6354 for (k
= M
; k
< M
+ 4; k
++)
6359 for (k
= M
+ 3; k
>= M
; k
--)
6362 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6363 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6364 ecleaz (yi
); /* it was zero */
6366 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6370 /* Convert target computer signed 64-bit integer to e-type. */
6374 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6375 unsigned EMUSHORT
*e
;
6377 unsigned EMULONG acc
;
6378 unsigned EMUSHORT yi
[NI
];
6379 unsigned EMUSHORT carry
;
6383 if (WORDS_BIG_ENDIAN
)
6385 for (k
= M
; k
< M
+ 4; k
++)
6390 for (k
= M
+ 3; k
>= M
; k
--)
6393 /* Take absolute value */
6399 for (k
= M
+ 3; k
>= M
; k
--)
6401 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6408 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6409 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6410 ecleaz (yi
); /* it was zero */
6412 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6419 /* Convert e-type to unsigned 64-bit int. */
6423 unsigned EMUSHORT
*x
;
6424 unsigned EMUSHORT
*i
;
6426 unsigned EMUSHORT xi
[NI
];
6435 k
= (int) xi
[E
] - (EXONE
- 1);
6438 for (j
= 0; j
< 4; j
++)
6444 for (j
= 0; j
< 4; j
++)
6447 warning ("overflow on truncation to integer");
6452 /* Shift more than 16 bits: first shift up k-16 mod 16,
6453 then shift up by 16's. */
6454 j
= k
- ((k
>> 4) << 4);
6458 if (WORDS_BIG_ENDIAN
)
6469 if (WORDS_BIG_ENDIAN
)
6474 while ((k
-= 16) > 0);
6478 /* shift not more than 16 bits */
6483 if (WORDS_BIG_ENDIAN
)
6502 /* Convert e-type to signed 64-bit int. */
6506 unsigned EMUSHORT
*x
;
6507 unsigned EMUSHORT
*i
;
6509 unsigned EMULONG acc
;
6510 unsigned EMUSHORT xi
[NI
];
6511 unsigned EMUSHORT carry
;
6512 unsigned EMUSHORT
*isave
;
6516 k
= (int) xi
[E
] - (EXONE
- 1);
6519 for (j
= 0; j
< 4; j
++)
6525 for (j
= 0; j
< 4; j
++)
6528 warning ("overflow on truncation to integer");
6534 /* Shift more than 16 bits: first shift up k-16 mod 16,
6535 then shift up by 16's. */
6536 j
= k
- ((k
>> 4) << 4);
6540 if (WORDS_BIG_ENDIAN
)
6551 if (WORDS_BIG_ENDIAN
)
6556 while ((k
-= 16) > 0);
6560 /* shift not more than 16 bits */
6563 if (WORDS_BIG_ENDIAN
)
6579 /* Negate if negative */
6583 if (WORDS_BIG_ENDIAN
)
6585 for (k
= 0; k
< 4; k
++)
6587 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6588 if (WORDS_BIG_ENDIAN
)
6600 /* Longhand square root routine. */
6603 static int esqinited
= 0;
6604 static unsigned short sqrndbit
[NI
];
6608 unsigned EMUSHORT
*x
, *y
;
6610 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6612 int i
, j
, k
, n
, nlups
;
6617 sqrndbit
[NI
- 2] = 1;
6620 /* Check for arg <= 0 */
6621 i
= ecmp (x
, ezero
);
6626 mtherr ("esqrt", DOMAIN
);
6642 /* Bring in the arg and renormalize if it is denormal. */
6644 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6648 /* Divide exponent by 2 */
6650 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6652 /* Adjust if exponent odd */
6662 n
= 8; /* get 8 bits of result per inner loop */
6668 /* bring in next word of arg */
6670 num
[NI
- 1] = xx
[j
+ 3];
6671 /* Do additional bit on last outer loop, for roundoff. */
6674 for (i
= 0; i
< n
; i
++)
6676 /* Next 2 bits of arg */
6679 /* Shift up answer */
6681 /* Make trial divisor */
6682 for (k
= 0; k
< NI
; k
++)
6685 eaddm (sqrndbit
, temp
);
6686 /* Subtract and insert answer bit if it goes in */
6687 if (ecmpm (temp
, num
) <= 0)
6697 /* Adjust for extra, roundoff loop done. */
6698 exp
+= (NBITS
- 1) - rndprc
;
6700 /* Sticky bit = 1 if the remainder is nonzero. */
6702 for (i
= 3; i
< NI
; i
++)
6705 /* Renormalize and round off. */
6706 emdnorm (sq
, k
, 0, exp
, 64);
6710 #endif /* EMU_NON_COMPILE not defined */
6712 /* Return the binary precision of the significand for a given
6713 floating point mode. The mode can hold an integer value
6714 that many bits wide, without losing any bits. */
6717 significand_size (mode
)
6718 enum machine_mode mode
;
6721 /* Don't test the modes, but their sizes, lest this
6722 code won't work for BITS_PER_UNIT != 8 . */
6724 switch (GET_MODE_BITSIZE (mode
))
6728 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6735 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6738 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6741 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6744 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT