]>
gcc.gnu.org Git - gcc.git/blob - gcc/real.c
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. */
27 /* To enable support of XFmode extended real floating point, define
28 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
30 To support cross compilation between IEEE, VAX and IBM floating
31 point formats, define REAL_ARITHMETIC in the tm.h file.
33 In either case the machine files (tm.h) must not contain any code
34 that tries to use host floating point arithmetic to convert
35 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
36 etc. In cross-compile situations a REAL_VALUE_TYPE may not
37 be intelligible to the host computer's native arithmetic.
39 The emulator defaults to the host's floating point format so that
40 its decimal conversion functions can be used if desired (see
43 The first part of this file interfaces gcc to a floating point
44 arithmetic suite that was not written with gcc in mind. Avoid
45 changing the low-level arithmetic routines unless you have suitable
46 test programs available. A special version of the PARANOIA floating
47 point arithmetic tester, modified for this purpose, can be found on
48 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
49 XFmode and TFmode transcendental functions, can be obtained by ftp from
50 netlib.att.com: netlib/cephes. */
52 /* Type of computer arithmetic.
53 Only one of DEC, IBM, IEEE, or UNK should get defined.
55 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
56 to big-endian IEEE floating-point data structure. This definition
57 should work in SFmode `float' type and DFmode `double' type on
58 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
59 has been defined to be 96, then IEEE also invokes the particular
60 XFmode (`long double' type) data structure used by the Motorola
61 680x0 series processors.
63 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
64 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
65 has been defined to be 96, then IEEE also invokes the particular
66 XFmode `long double' data structure used by the Intel 80x86 series
69 `DEC' refers specifically to the Digital Equipment Corp PDP-11
70 and VAX floating point data structure. This model currently
71 supports no type wider than DFmode.
73 `IBM' refers specifically to the IBM System/370 and compatible
74 floating point data structure. This model currently supports
75 no type wider than DFmode. The IBM conversions were contributed by
76 frank@atom.ansto.gov.au (Frank Crawford).
78 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
79 then `long double' and `double' are both implemented, but they
80 both mean DFmode. In this case, the software floating-point
81 support available here is activated by writing
82 #define REAL_ARITHMETIC
85 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
86 and may deactivate XFmode since `long double' is used to refer
89 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
90 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
91 separate the floating point unit's endian-ness from that of
92 the integer addressing. This permits one to define a big-endian
93 FPU on a little-endian machine (e.g., ARM). An extension to
94 BYTES_BIG_ENDIAN may be required for some machines in the future.
95 These optional macros may be defined in tm.h. In real.h, they
96 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
97 them for any normal host or target machine on which the floats
98 and the integers have the same endian-ness. */
101 /* The following converts gcc macros into the ones used by this file. */
103 /* REAL_ARITHMETIC defined means that macros in real.h are
104 defined to call emulator functions. */
105 #ifdef REAL_ARITHMETIC
107 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
108 /* PDP-11, Pro350, VAX: */
110 #else /* it's not VAX */
111 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
112 /* IBM System/370 style */
114 #else /* it's also not an IBM */
115 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
116 /* TMS320C3x/C4x style */
118 #else /* it's also not a C4X */
119 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
121 #else /* it's not IEEE either */
122 /* UNKnown arithmetic. We don't support this and can't go on. */
123 unknown arithmetic type
125 #endif /* not IEEE */
130 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
133 /* REAL_ARITHMETIC not defined means that the *host's* data
134 structure will be used. It may differ by endian-ness from the
135 target machine's structure and will get its ends swapped
136 accordingly (but not here). Probably only the decimal <-> binary
137 functions in this file will actually be used in this case. */
139 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
141 #else /* it's not VAX */
142 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
143 /* IBM System/370 style */
145 #else /* it's also not an IBM */
146 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
148 #else /* it's not IEEE either */
149 unknown arithmetic type
151 #endif /* not IEEE */
155 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
157 #endif /* REAL_ARITHMETIC not defined */
159 /* Define INFINITY for support of infinity.
160 Define NANS for support of Not-a-Number's (NaN's). */
161 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
166 /* Support of NaNs requires support of infinity. */
173 /* Find a host integer type that is at least 16 bits wide,
174 and another type at least twice whatever that size is. */
176 #if HOST_BITS_PER_CHAR >= 16
177 #define EMUSHORT char
178 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
179 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
181 #if HOST_BITS_PER_SHORT >= 16
182 #define EMUSHORT short
183 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
184 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
186 #if HOST_BITS_PER_INT >= 16
188 #define EMUSHORT_SIZE HOST_BITS_PER_INT
189 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
191 #if HOST_BITS_PER_LONG >= 16
192 #define EMUSHORT long
193 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
194 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
196 /* You will have to modify this program to have a smaller unit size. */
197 #define EMU_NON_COMPILE
203 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
204 #define EMULONG short
206 #if HOST_BITS_PER_INT >= EMULONG_SIZE
209 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
212 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
213 #define EMULONG long long int
215 /* You will have to modify this program to have a smaller unit size. */
216 #define EMU_NON_COMPILE
223 /* The host interface doesn't work if no 16-bit size exists. */
224 #if EMUSHORT_SIZE != 16
225 #define EMU_NON_COMPILE
228 /* OK to continue compilation. */
229 #ifndef EMU_NON_COMPILE
231 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
232 In GET_REAL and PUT_REAL, r and e are pointers.
233 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
234 in memory, with no holes. */
236 #if LONG_DOUBLE_TYPE_SIZE == 96
237 /* Number of 16 bit words in external e type format */
239 #define MAXDECEXP 4932
240 #define MINDECEXP -4956
241 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
242 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
243 #else /* no XFmode */
244 #if LONG_DOUBLE_TYPE_SIZE == 128
246 #define MAXDECEXP 4932
247 #define MINDECEXP -4977
248 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
249 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
252 #define MAXDECEXP 4932
253 #define MINDECEXP -4956
254 #ifdef REAL_ARITHMETIC
255 /* Emulator uses target format internally
256 but host stores it in host endian-ness. */
258 #define GET_REAL(r,e) \
260 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
261 e53toe ((unsigned EMUSHORT *) (r), (e)); \
264 unsigned EMUSHORT w[4]; \
265 w[3] = ((EMUSHORT *) r)[0]; \
266 w[2] = ((EMUSHORT *) r)[1]; \
267 w[1] = ((EMUSHORT *) r)[2]; \
268 w[0] = ((EMUSHORT *) r)[3]; \
273 #define PUT_REAL(e,r) \
275 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
276 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
279 unsigned EMUSHORT w[4]; \
281 *((EMUSHORT *) r) = w[3]; \
282 *((EMUSHORT *) r + 1) = w[2]; \
283 *((EMUSHORT *) r + 2) = w[1]; \
284 *((EMUSHORT *) r + 3) = w[0]; \
288 #else /* not REAL_ARITHMETIC */
290 /* emulator uses host format */
291 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
292 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
294 #endif /* not REAL_ARITHMETIC */
295 #endif /* not TFmode */
296 #endif /* not XFmode */
299 /* Number of 16 bit words in internal format */
302 /* Array offset to exponent */
305 /* Array offset to high guard word */
308 /* Number of bits of precision */
309 #define NBITS ((NI-4)*16)
311 /* Maximum number of decimal digits in ASCII conversion
314 #define NDEC (NBITS*8/27)
316 /* The exponent of 1.0 */
317 #define EXONE (0x3fff)
319 extern int extra_warnings
;
320 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
321 extern unsigned EMUSHORT elog2
[], esqrt2
[];
323 static void endian
PROTO((unsigned EMUSHORT
*, long *,
325 static void eclear
PROTO((unsigned EMUSHORT
*));
326 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
327 static void eabs
PROTO((unsigned EMUSHORT
*));
328 static void eneg
PROTO((unsigned EMUSHORT
*));
329 static int eisneg
PROTO((unsigned EMUSHORT
*));
330 static int eisinf
PROTO((unsigned EMUSHORT
*));
331 static int eisnan
PROTO((unsigned EMUSHORT
*));
332 static void einfin
PROTO((unsigned EMUSHORT
*));
333 static void enan
PROTO((unsigned EMUSHORT
*, int));
334 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
335 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
336 static void ecleaz
PROTO((unsigned EMUSHORT
*));
337 static void ecleazs
PROTO((unsigned EMUSHORT
*));
338 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
339 static void einan
PROTO((unsigned EMUSHORT
*));
340 static int eiisnan
PROTO((unsigned EMUSHORT
*));
341 static int eiisneg
PROTO((unsigned EMUSHORT
*));
342 static void eiinfin
PROTO((unsigned EMUSHORT
*));
343 static int eiisinf
PROTO((unsigned EMUSHORT
*));
344 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
345 static void eshdn1
PROTO((unsigned EMUSHORT
*));
346 static void eshup1
PROTO((unsigned EMUSHORT
*));
347 static void eshdn8
PROTO((unsigned EMUSHORT
*));
348 static void eshup8
PROTO((unsigned EMUSHORT
*));
349 static void eshup6
PROTO((unsigned EMUSHORT
*));
350 static void eshdn6
PROTO((unsigned EMUSHORT
*));
351 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
352 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
353 static void m16m
PROTO((unsigned int, unsigned short *,
355 static int edivm
PROTO((unsigned short *, unsigned short *));
356 static int emulm
PROTO((unsigned short *, unsigned short *));
357 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
358 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
359 unsigned EMUSHORT
*));
360 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
361 unsigned EMUSHORT
*));
362 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
363 unsigned EMUSHORT
*));
364 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
365 unsigned EMUSHORT
*));
366 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
367 unsigned EMUSHORT
*));
368 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
369 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
370 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
371 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
372 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
373 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
378 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
380 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
381 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
383 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
384 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
385 unsigned EMUSHORT
*));
386 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
387 unsigned EMUSHORT
*));
388 static int eshift
PROTO((unsigned EMUSHORT
*, int));
389 static int enormlz
PROTO((unsigned EMUSHORT
*));
390 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
391 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
392 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
393 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
394 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
395 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
396 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
397 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
398 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
399 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
400 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
401 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
403 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
404 unsigned EMUSHORT
*));
406 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
408 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
409 unsigned EMUSHORT
*));
411 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void mtherr
PROTO((char *, int));
414 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
415 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
419 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
421 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
423 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
427 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
429 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
431 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
434 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
436 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
437 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
438 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
439 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
440 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
443 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
444 swapping ends if required, into output array of longs. The
445 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
449 unsigned EMUSHORT e
[];
451 enum machine_mode mode
;
455 if (REAL_WORDS_BIG_ENDIAN
)
460 /* Swap halfwords in the fourth long. */
461 th
= (unsigned long) e
[6] & 0xffff;
462 t
= (unsigned long) e
[7] & 0xffff;
467 /* Swap halfwords in the third long. */
468 th
= (unsigned long) e
[4] & 0xffff;
469 t
= (unsigned long) e
[5] & 0xffff;
472 /* fall into the double case */
475 /* Swap halfwords in the second word. */
476 th
= (unsigned long) e
[2] & 0xffff;
477 t
= (unsigned long) e
[3] & 0xffff;
480 /* fall into the float case */
484 /* Swap halfwords in the first word. */
485 th
= (unsigned long) e
[0] & 0xffff;
486 t
= (unsigned long) e
[1] & 0xffff;
497 /* Pack the output array without swapping. */
502 /* Pack the fourth long. */
503 th
= (unsigned long) e
[7] & 0xffff;
504 t
= (unsigned long) e
[6] & 0xffff;
509 /* Pack the third long.
510 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
512 th
= (unsigned long) e
[5] & 0xffff;
513 t
= (unsigned long) e
[4] & 0xffff;
516 /* fall into the double case */
519 /* Pack the second long */
520 th
= (unsigned long) e
[3] & 0xffff;
521 t
= (unsigned long) e
[2] & 0xffff;
524 /* fall into the float case */
528 /* Pack the first long */
529 th
= (unsigned long) e
[1] & 0xffff;
530 t
= (unsigned long) e
[0] & 0xffff;
542 /* This is the implementation of the REAL_ARITHMETIC macro. */
545 earith (value
, icode
, r1
, r2
)
546 REAL_VALUE_TYPE
*value
;
551 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
557 /* Return NaN input back to the caller. */
560 PUT_REAL (d1
, value
);
565 PUT_REAL (d2
, value
);
569 code
= (enum tree_code
) icode
;
577 esub (d2
, d1
, v
); /* d1 - d2 */
585 #ifndef REAL_INFINITY
586 if (ecmp (d2
, ezero
) == 0)
589 enan (v
, eisneg (d1
) ^ eisneg (d2
));
596 ediv (d2
, d1
, v
); /* d1/d2 */
599 case MIN_EXPR
: /* min (d1,d2) */
600 if (ecmp (d1
, d2
) < 0)
606 case MAX_EXPR
: /* max (d1,d2) */
607 if (ecmp (d1
, d2
) > 0)
620 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
621 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
627 unsigned EMUSHORT f
[NE
], g
[NE
];
643 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
644 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
650 unsigned EMUSHORT f
[NE
], g
[NE
];
652 unsigned HOST_WIDE_INT l
;
666 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
667 binary, rounding off as indicated by the machine_mode argument. Then it
668 promotes the rounded value to REAL_VALUE_TYPE. */
675 unsigned EMUSHORT tem
[NE
], e
[NE
];
709 /* Expansion of REAL_NEGATE. */
715 unsigned EMUSHORT e
[NE
];
725 /* Round real toward zero to HOST_WIDE_INT;
726 implements REAL_VALUE_FIX (x). */
732 unsigned EMUSHORT f
[NE
], g
[NE
];
739 warning ("conversion from NaN to int");
747 /* Round real toward zero to unsigned HOST_WIDE_INT
748 implements REAL_VALUE_UNSIGNED_FIX (x).
749 Negative input returns zero. */
751 unsigned HOST_WIDE_INT
755 unsigned EMUSHORT f
[NE
], g
[NE
];
756 unsigned HOST_WIDE_INT l
;
762 warning ("conversion from NaN to unsigned int");
771 /* REAL_VALUE_FROM_INT macro. */
774 ereal_from_int (d
, i
, j
, mode
)
777 enum machine_mode mode
;
779 unsigned EMUSHORT df
[NE
], dg
[NE
];
780 HOST_WIDE_INT low
, high
;
783 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
790 /* complement and add 1 */
797 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
798 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
800 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
805 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
806 Avoid double-rounding errors later by rounding off now from the
807 extra-wide internal format to the requested precision. */
808 switch (GET_MODE_BITSIZE (mode
))
838 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
841 ereal_from_uint (d
, i
, j
, mode
)
843 unsigned HOST_WIDE_INT i
, j
;
844 enum machine_mode mode
;
846 unsigned EMUSHORT df
[NE
], dg
[NE
];
847 unsigned HOST_WIDE_INT low
, high
;
849 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
853 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
859 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
860 Avoid double-rounding errors later by rounding off now from the
861 extra-wide internal format to the requested precision. */
862 switch (GET_MODE_BITSIZE (mode
))
892 /* REAL_VALUE_TO_INT macro. */
895 ereal_to_int (low
, high
, rr
)
896 HOST_WIDE_INT
*low
, *high
;
899 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
906 warning ("conversion from NaN to int");
912 /* convert positive value */
919 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
920 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
921 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
922 emul (df
, dh
, dg
); /* fractional part is the low word */
923 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
926 /* complement and add 1 */
936 /* REAL_VALUE_LDEXP macro. */
943 unsigned EMUSHORT e
[NE
], y
[NE
];
956 /* These routines are conditionally compiled because functions
957 of the same names may be defined in fold-const.c. */
959 #ifdef REAL_ARITHMETIC
961 /* Check for infinity in a REAL_VALUE_TYPE. */
967 unsigned EMUSHORT e
[NE
];
977 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
983 unsigned EMUSHORT e
[NE
];
994 /* Check for a negative REAL_VALUE_TYPE number.
995 This just checks the sign bit, so that -0 counts as negative. */
1001 return ereal_isneg (x
);
1004 /* Expansion of REAL_VALUE_TRUNCATE.
1005 The result is in floating point, rounded to nearest or even. */
1008 real_value_truncate (mode
, arg
)
1009 enum machine_mode mode
;
1010 REAL_VALUE_TYPE arg
;
1012 unsigned EMUSHORT e
[NE
], t
[NE
];
1048 /* If an unsupported type was requested, presume that
1049 the machine files know something useful to do with
1050 the unmodified value. */
1059 /* Try to change R into its exact multiplicative inverse in machine mode
1060 MODE. Return nonzero function value if successful. */
1063 exact_real_inverse (mode
, r
)
1064 enum machine_mode mode
;
1067 unsigned EMUSHORT e
[NE
], einv
[NE
];
1068 REAL_VALUE_TYPE rinv
;
1073 /* Test for input in range. Don't transform IEEE special values. */
1074 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1077 /* Test for a power of 2: all significand bits zero except the MSB.
1078 We are assuming the target has binary (or hex) arithmetic. */
1079 if (e
[NE
- 2] != 0x8000)
1082 for (i
= 0; i
< NE
- 2; i
++)
1088 /* Compute the inverse and truncate it to the required mode. */
1089 ediv (e
, eone
, einv
);
1090 PUT_REAL (einv
, &rinv
);
1091 rinv
= real_value_truncate (mode
, rinv
);
1093 #ifdef CHECK_FLOAT_VALUE
1094 /* This check is not redundant. It may, for example, flush
1095 a supposedly IEEE denormal value to zero. */
1097 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1100 GET_REAL (&rinv
, einv
);
1102 /* Check the bits again, because the truncation might have
1103 generated an arbitrary saturation value on overflow. */
1104 if (einv
[NE
- 2] != 0x8000)
1107 for (i
= 0; i
< NE
- 2; i
++)
1113 /* Fail if the computed inverse is out of range. */
1114 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1117 /* Output the reciprocal and return success flag. */
1121 #endif /* REAL_ARITHMETIC defined */
1123 /* Used for debugging--print the value of R in human-readable format
1132 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1133 fprintf (stderr
, "%s", dstr
);
1137 /* The following routines convert REAL_VALUE_TYPE to the various floating
1138 point formats that are meaningful to supported computers.
1140 The results are returned in 32-bit pieces, each piece stored in a `long'.
1141 This is so they can be printed by statements like
1143 fprintf (file, "%lx, %lx", L[0], L[1]);
1145 that will work on both narrow- and wide-word host computers. */
1147 /* Convert R to a 128-bit long double precision value. The output array L
1148 contains four 32-bit pieces of the result, in the order they would appear
1156 unsigned EMUSHORT e
[NE
];
1160 endian (e
, l
, TFmode
);
1163 /* Convert R to a double extended precision value. The output array L
1164 contains three 32-bit pieces of the result, in the order they would
1165 appear in memory. */
1172 unsigned EMUSHORT e
[NE
];
1176 endian (e
, l
, XFmode
);
1179 /* Convert R to a double precision value. The output array L contains two
1180 32-bit pieces of the result, in the order they would appear in memory. */
1187 unsigned EMUSHORT e
[NE
];
1191 endian (e
, l
, DFmode
);
1194 /* Convert R to a single precision float value stored in the least-significant
1195 bits of a `long'. */
1201 unsigned EMUSHORT e
[NE
];
1206 endian (e
, &l
, SFmode
);
1210 /* Convert X to a decimal ASCII string S for output to an assembly
1211 language file. Note, there is no standard way to spell infinity or
1212 a NaN, so these values may require special treatment in the tm.h
1216 ereal_to_decimal (x
, s
)
1220 unsigned EMUSHORT e
[NE
];
1226 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1227 or -2 if either is a NaN. */
1231 REAL_VALUE_TYPE x
, y
;
1233 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1237 return (ecmp (ex
, ey
));
1240 /* Return 1 if the sign bit of X is set, else return 0. */
1246 unsigned EMUSHORT ex
[NE
];
1249 return (eisneg (ex
));
1252 /* End of REAL_ARITHMETIC interface */
1255 Extended precision IEEE binary floating point arithmetic routines
1257 Numbers are stored in C language as arrays of 16-bit unsigned
1258 short integers. The arguments of the routines are pointers to
1261 External e type data structure, similar to Intel 8087 chip
1262 temporary real format but possibly with a larger significand:
1264 NE-1 significand words (least significant word first,
1265 most significant bit is normally set)
1266 exponent (value = EXONE for 1.0,
1267 top bit is the sign)
1270 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1272 ei[0] sign word (0 for positive, 0xffff for negative)
1273 ei[1] biased exponent (value = EXONE for the number 1.0)
1274 ei[2] high guard word (always zero after normalization)
1276 to ei[NI-2] significand (NI-4 significand words,
1277 most significant word first,
1278 most significant bit is set)
1279 ei[NI-1] low guard word (0x8000 bit is rounding place)
1283 Routines for external format e-type numbers
1285 asctoe (string, e) ASCII string to extended double e type
1286 asctoe64 (string, &d) ASCII string to long double
1287 asctoe53 (string, &d) ASCII string to double
1288 asctoe24 (string, &f) ASCII string to single
1289 asctoeg (string, e, prec) ASCII string to specified precision
1290 e24toe (&f, e) IEEE single precision to e type
1291 e53toe (&d, e) IEEE double precision to e type
1292 e64toe (&d, e) IEEE long double precision to e type
1293 e113toe (&d, e) 128-bit long double precision to e type
1294 eabs (e) absolute value
1295 eadd (a, b, c) c = b + a
1297 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1298 -1 if a < b, -2 if either a or b is a NaN.
1299 ediv (a, b, c) c = b / a
1300 efloor (a, b) truncate to integer, toward -infinity
1301 efrexp (a, exp, s) extract exponent and significand
1302 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1303 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1304 einfin (e) set e to infinity, leaving its sign alone
1305 eldexp (a, n, b) multiply by 2**n
1307 emul (a, b, c) c = b * a
1309 eround (a, b) b = nearest integer value to a
1310 esub (a, b, c) c = b - a
1311 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1312 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1313 e64toasc (&d, str, n) 80-bit long double to ASCII string
1314 e113toasc (&d, str, n) 128-bit long double to ASCII string
1315 etoasc (e, str, n) e to ASCII string, n digits after decimal
1316 etoe24 (e, &f) convert e type to IEEE single precision
1317 etoe53 (e, &d) convert e type to IEEE double precision
1318 etoe64 (e, &d) convert e type to IEEE long double precision
1319 ltoe (&l, e) HOST_WIDE_INT to e type
1320 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1321 eisneg (e) 1 if sign bit of e != 0, else 0
1322 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1323 or is infinite (IEEE)
1324 eisnan (e) 1 if e is a NaN
1327 Routines for internal format exploded e-type numbers
1329 eaddm (ai, bi) add significands, bi = bi + ai
1331 ecleazs (ei) set ei = 0 but leave its sign alone
1332 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1333 edivm (ai, bi) divide significands, bi = bi / ai
1334 emdnorm (ai,l,s,exp) normalize and round off
1335 emovi (a, ai) convert external a to internal ai
1336 emovo (ai, a) convert internal ai to external a
1337 emovz (ai, bi) bi = ai, low guard word of bi = 0
1338 emulm (ai, bi) multiply significands, bi = bi * ai
1339 enormlz (ei) left-justify the significand
1340 eshdn1 (ai) shift significand and guards down 1 bit
1341 eshdn8 (ai) shift down 8 bits
1342 eshdn6 (ai) shift down 16 bits
1343 eshift (ai, n) shift ai n bits up (or down if n < 0)
1344 eshup1 (ai) shift significand and guards up 1 bit
1345 eshup8 (ai) shift up 8 bits
1346 eshup6 (ai) shift up 16 bits
1347 esubm (ai, bi) subtract significands, bi = bi - ai
1348 eiisinf (ai) 1 if infinite
1349 eiisnan (ai) 1 if a NaN
1350 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1351 einan (ai) set ai = NaN
1352 eiinfin (ai) set ai = infinity
1354 The result is always normalized and rounded to NI-4 word precision
1355 after each arithmetic operation.
1357 Exception flags are NOT fully supported.
1359 Signaling NaN's are NOT supported; they are treated the same
1362 Define INFINITY for support of infinity; otherwise a
1363 saturation arithmetic is implemented.
1365 Define NANS for support of Not-a-Number items; otherwise the
1366 arithmetic will never produce a NaN output, and might be confused
1368 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1369 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1370 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1373 Denormals are always supported here where appropriate (e.g., not
1374 for conversion to DEC numbers). */
1376 /* Definitions for error codes that are passed to the common error handling
1379 For Digital Equipment PDP-11 and VAX computers, certain
1380 IBM systems, and others that use numbers with a 56-bit
1381 significand, the symbol DEC should be defined. In this
1382 mode, most floating point constants are given as arrays
1383 of octal integers to eliminate decimal to binary conversion
1384 errors that might be introduced by the compiler.
1386 For computers, such as IBM PC, that follow the IEEE
1387 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1388 Std 754-1985), the symbol IEEE should be defined.
1389 These numbers have 53-bit significands. In this mode, constants
1390 are provided as arrays of hexadecimal 16 bit integers.
1391 The endian-ness of generated values is controlled by
1392 REAL_WORDS_BIG_ENDIAN.
1394 To accommodate other types of computer arithmetic, all
1395 constants are also provided in a normal decimal radix
1396 which one can hope are correctly converted to a suitable
1397 format by the available C language compiler. To invoke
1398 this mode, the symbol UNK is defined.
1400 An important difference among these modes is a predefined
1401 set of machine arithmetic constants for each. The numbers
1402 MACHEP (the machine roundoff error), MAXNUM (largest number
1403 represented), and several other parameters are preset by
1404 the configuration symbol. Check the file const.c to
1405 ensure that these values are correct for your computer.
1407 For ANSI C compatibility, define ANSIC equal to 1. Currently
1408 this affects only the atan2 function and others that use it. */
1410 /* Constant definitions for math error conditions. */
1412 #define DOMAIN 1 /* argument domain error */
1413 #define SING 2 /* argument singularity */
1414 #define OVERFLOW 3 /* overflow range error */
1415 #define UNDERFLOW 4 /* underflow range error */
1416 #define TLOSS 5 /* total loss of precision */
1417 #define PLOSS 6 /* partial loss of precision */
1418 #define INVALID 7 /* NaN-producing operation */
1420 /* e type constants used by high precision check routines */
1422 #if LONG_DOUBLE_TYPE_SIZE == 128
1424 unsigned EMUSHORT ezero
[NE
] =
1425 {0x0000, 0x0000, 0x0000, 0x0000,
1426 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1427 extern unsigned EMUSHORT ezero
[];
1430 unsigned EMUSHORT ehalf
[NE
] =
1431 {0x0000, 0x0000, 0x0000, 0x0000,
1432 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1433 extern unsigned EMUSHORT ehalf
[];
1436 unsigned EMUSHORT eone
[NE
] =
1437 {0x0000, 0x0000, 0x0000, 0x0000,
1438 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1439 extern unsigned EMUSHORT eone
[];
1442 unsigned EMUSHORT etwo
[NE
] =
1443 {0x0000, 0x0000, 0x0000, 0x0000,
1444 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1445 extern unsigned EMUSHORT etwo
[];
1448 unsigned EMUSHORT e32
[NE
] =
1449 {0x0000, 0x0000, 0x0000, 0x0000,
1450 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1451 extern unsigned EMUSHORT e32
[];
1453 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1454 unsigned EMUSHORT elog2
[NE
] =
1455 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1456 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1457 extern unsigned EMUSHORT elog2
[];
1459 /* 1.41421356237309504880168872420969807856967187537695E0 */
1460 unsigned EMUSHORT esqrt2
[NE
] =
1461 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1462 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1463 extern unsigned EMUSHORT esqrt2
[];
1465 /* 3.14159265358979323846264338327950288419716939937511E0 */
1466 unsigned EMUSHORT epi
[NE
] =
1467 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1468 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1469 extern unsigned EMUSHORT epi
[];
1472 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1473 unsigned EMUSHORT ezero
[NE
] =
1474 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1475 unsigned EMUSHORT ehalf
[NE
] =
1476 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1477 unsigned EMUSHORT eone
[NE
] =
1478 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1479 unsigned EMUSHORT etwo
[NE
] =
1480 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1481 unsigned EMUSHORT e32
[NE
] =
1482 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1483 unsigned EMUSHORT elog2
[NE
] =
1484 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1485 unsigned EMUSHORT esqrt2
[NE
] =
1486 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1487 unsigned EMUSHORT epi
[NE
] =
1488 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1491 /* Control register for rounding precision.
1492 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1497 /* Clear out entire e-type number X. */
1501 register unsigned EMUSHORT
*x
;
1505 for (i
= 0; i
< NE
; i
++)
1509 /* Move e-type number from A to B. */
1513 register unsigned EMUSHORT
*a
, *b
;
1517 for (i
= 0; i
< NE
; i
++)
1522 /* Absolute value of e-type X. */
1526 unsigned EMUSHORT x
[];
1528 /* sign is top bit of last word of external format */
1529 x
[NE
- 1] &= 0x7fff;
1532 /* Negate the e-type number X. */
1536 unsigned EMUSHORT x
[];
1539 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1542 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1546 unsigned EMUSHORT x
[];
1549 if (x
[NE
- 1] & 0x8000)
1555 /* Return 1 if e-type number X is infinity, else return zero. */
1559 unsigned EMUSHORT x
[];
1566 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1572 /* Check if e-type number is not a number. The bit pattern is one that we
1573 defined, so we know for sure how to detect it. */
1577 unsigned EMUSHORT x
[];
1582 /* NaN has maximum exponent */
1583 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1585 /* ... and non-zero significand field. */
1586 for (i
= 0; i
< NE
- 1; i
++)
1596 /* Fill e-type number X with infinity pattern (IEEE)
1597 or largest possible number (non-IEEE). */
1601 register unsigned EMUSHORT
*x
;
1606 for (i
= 0; i
< NE
- 1; i
++)
1610 for (i
= 0; i
< NE
- 1; i
++)
1638 /* Output an e-type NaN.
1639 This generates Intel's quiet NaN pattern for extended real.
1640 The exponent is 7fff, the leading mantissa word is c000. */
1644 register unsigned EMUSHORT
*x
;
1649 for (i
= 0; i
< NE
- 2; i
++)
1652 *x
= (sign
<< 15) | 0x7fff;
1655 /* Move in an e-type number A, converting it to exploded e-type B. */
1659 unsigned EMUSHORT
*a
, *b
;
1661 register unsigned EMUSHORT
*p
, *q
;
1665 p
= a
+ (NE
- 1); /* point to last word of external number */
1666 /* get the sign bit */
1671 /* get the exponent */
1673 *q
++ &= 0x7fff; /* delete the sign bit */
1675 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1681 for (i
= 3; i
< NI
; i
++)
1687 for (i
= 2; i
< NI
; i
++)
1693 /* clear high guard word */
1695 /* move in the significand */
1696 for (i
= 0; i
< NE
- 1; i
++)
1698 /* clear low guard word */
1702 /* Move out exploded e-type number A, converting it to e type B. */
1706 unsigned EMUSHORT
*a
, *b
;
1708 register unsigned EMUSHORT
*p
, *q
;
1709 unsigned EMUSHORT i
;
1713 q
= b
+ (NE
- 1); /* point to output exponent */
1714 /* combine sign and exponent */
1717 *q
-- = *p
++ | 0x8000;
1721 if (*(p
- 1) == 0x7fff)
1726 enan (b
, eiisneg (a
));
1734 /* skip over guard word */
1736 /* move the significand */
1737 for (j
= 0; j
< NE
- 1; j
++)
1741 /* Clear out exploded e-type number XI. */
1745 register unsigned EMUSHORT
*xi
;
1749 for (i
= 0; i
< NI
; i
++)
1753 /* Clear out exploded e-type XI, but don't touch the sign. */
1757 register unsigned EMUSHORT
*xi
;
1762 for (i
= 0; i
< NI
- 1; i
++)
1766 /* Move exploded e-type number from A to B. */
1770 register unsigned EMUSHORT
*a
, *b
;
1774 for (i
= 0; i
< NI
- 1; i
++)
1776 /* clear low guard word */
1780 /* Generate exploded e-type NaN.
1781 The explicit pattern for this is maximum exponent and
1782 top two significant bits set. */
1786 unsigned EMUSHORT x
[];
1794 /* Return nonzero if exploded e-type X is a NaN. */
1798 unsigned EMUSHORT x
[];
1802 if ((x
[E
] & 0x7fff) == 0x7fff)
1804 for (i
= M
+ 1; i
< NI
; i
++)
1813 /* Return nonzero if sign of exploded e-type X is nonzero. */
1817 unsigned EMUSHORT x
[];
1823 /* Fill exploded e-type X with infinity pattern.
1824 This has maximum exponent and significand all zeros. */
1828 unsigned EMUSHORT x
[];
1835 /* Return nonzero if exploded e-type X is infinite. */
1839 unsigned EMUSHORT x
[];
1846 if ((x
[E
] & 0x7fff) == 0x7fff)
1852 /* Compare significands of numbers in internal exploded e-type format.
1853 Guard words are included in the comparison.
1861 register unsigned EMUSHORT
*a
, *b
;
1865 a
+= M
; /* skip up to significand area */
1867 for (i
= M
; i
< NI
; i
++)
1875 if (*(--a
) > *(--b
))
1881 /* Shift significand of exploded e-type X down by 1 bit. */
1885 register unsigned EMUSHORT
*x
;
1887 register unsigned EMUSHORT bits
;
1890 x
+= M
; /* point to significand area */
1893 for (i
= M
; i
< NI
; i
++)
1905 /* Shift significand of exploded e-type X up by 1 bit. */
1909 register unsigned EMUSHORT
*x
;
1911 register unsigned EMUSHORT bits
;
1917 for (i
= M
; i
< NI
; i
++)
1930 /* Shift significand of exploded e-type X down by 8 bits. */
1934 register unsigned EMUSHORT
*x
;
1936 register unsigned EMUSHORT newbyt
, oldbyt
;
1941 for (i
= M
; i
< NI
; i
++)
1951 /* Shift significand of exploded e-type X up by 8 bits. */
1955 register unsigned EMUSHORT
*x
;
1958 register unsigned EMUSHORT newbyt
, oldbyt
;
1963 for (i
= M
; i
< NI
; i
++)
1973 /* Shift significand of exploded e-type X up by 16 bits. */
1977 register unsigned EMUSHORT
*x
;
1980 register unsigned EMUSHORT
*p
;
1985 for (i
= M
; i
< NI
- 1; i
++)
1991 /* Shift significand of exploded e-type X down by 16 bits. */
1995 register unsigned EMUSHORT
*x
;
1998 register unsigned EMUSHORT
*p
;
2003 for (i
= M
; i
< NI
- 1; i
++)
2009 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2013 unsigned EMUSHORT
*x
, *y
;
2015 register unsigned EMULONG a
;
2022 for (i
= M
; i
< NI
; i
++)
2024 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2029 *y
= (unsigned EMUSHORT
) a
;
2035 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2039 unsigned EMUSHORT
*x
, *y
;
2048 for (i
= M
; i
< NI
; i
++)
2050 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2055 *y
= (unsigned EMUSHORT
) a
;
2062 static unsigned EMUSHORT equot
[NI
];
2066 /* Radix 2 shift-and-add versions of multiply and divide */
2069 /* Divide significands */
2073 unsigned EMUSHORT den
[], num
[];
2076 register unsigned EMUSHORT
*p
, *q
;
2077 unsigned EMUSHORT j
;
2083 for (i
= M
; i
< NI
; i
++)
2088 /* Use faster compare and subtraction if denominator has only 15 bits of
2094 for (i
= M
+ 3; i
< NI
; i
++)
2099 if ((den
[M
+ 1] & 1) != 0)
2107 for (i
= 0; i
< NBITS
+ 2; i
++)
2125 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2126 bit + 1 roundoff bit. */
2131 for (i
= 0; i
< NBITS
+ 2; i
++)
2133 if (ecmpm (den
, num
) <= 0)
2136 j
= 1; /* quotient bit = 1 */
2150 /* test for nonzero remainder after roundoff bit */
2153 for (i
= M
; i
< NI
; i
++)
2161 for (i
= 0; i
< NI
; i
++)
2167 /* Multiply significands */
2171 unsigned EMUSHORT a
[], b
[];
2173 unsigned EMUSHORT
*p
, *q
;
2178 for (i
= M
; i
< NI
; i
++)
2183 while (*p
== 0) /* significand is not supposed to be zero */
2188 if ((*p
& 0xff) == 0)
2196 for (i
= 0; i
< k
; i
++)
2200 /* remember if there were any nonzero bits shifted out */
2207 for (i
= 0; i
< NI
; i
++)
2210 /* return flag for lost nonzero bits */
2216 /* Radix 65536 versions of multiply and divide. */
2218 /* Multiply significand of e-type number B
2219 by 16-bit quantity A, return e-type result to C. */
2224 unsigned EMUSHORT b
[], c
[];
2226 register unsigned EMUSHORT
*pp
;
2227 register unsigned EMULONG carry
;
2228 unsigned EMUSHORT
*ps
;
2229 unsigned EMUSHORT p
[NI
];
2230 unsigned EMULONG aa
, m
;
2239 for (i
=M
+1; i
<NI
; i
++)
2249 m
= (unsigned EMULONG
) aa
* *ps
--;
2250 carry
= (m
& 0xffff) + *pp
;
2251 *pp
-- = (unsigned EMUSHORT
)carry
;
2252 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2253 *pp
= (unsigned EMUSHORT
)carry
;
2254 *(pp
-1) = carry
>> 16;
2257 for (i
=M
; i
<NI
; i
++)
2261 /* Divide significands of exploded e-types NUM / DEN. Neither the
2262 numerator NUM nor the denominator DEN is permitted to have its high guard
2267 unsigned EMUSHORT den
[], num
[];
2270 register unsigned EMUSHORT
*p
;
2271 unsigned EMULONG tnum
;
2272 unsigned EMUSHORT j
, tdenm
, tquot
;
2273 unsigned EMUSHORT tprod
[NI
+1];
2279 for (i
=M
; i
<NI
; i
++)
2285 for (i
=M
; i
<NI
; i
++)
2287 /* Find trial quotient digit (the radix is 65536). */
2288 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2290 /* Do not execute the divide instruction if it will overflow. */
2291 if ((tdenm
* 0xffffL
) < tnum
)
2294 tquot
= tnum
/ tdenm
;
2295 /* Multiply denominator by trial quotient digit. */
2296 m16m ((unsigned int)tquot
, den
, tprod
);
2297 /* The quotient digit may have been overestimated. */
2298 if (ecmpm (tprod
, num
) > 0)
2302 if (ecmpm (tprod
, num
) > 0)
2312 /* test for nonzero remainder after roundoff bit */
2315 for (i
=M
; i
<NI
; i
++)
2322 for (i
=0; i
<NI
; i
++)
2328 /* Multiply significands of exploded e-type A and B, result in B. */
2332 unsigned EMUSHORT a
[], b
[];
2334 unsigned EMUSHORT
*p
, *q
;
2335 unsigned EMUSHORT pprod
[NI
];
2336 unsigned EMUSHORT j
;
2341 for (i
=M
; i
<NI
; i
++)
2347 for (i
=M
+1; i
<NI
; i
++)
2355 m16m ((unsigned int) *p
--, b
, pprod
);
2356 eaddm(pprod
, equot
);
2362 for (i
=0; i
<NI
; i
++)
2365 /* return flag for lost nonzero bits */
2371 /* Normalize and round off.
2373 The internal format number to be rounded is S.
2374 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2376 Input SUBFLG indicates whether the number was obtained
2377 by a subtraction operation. In that case if LOST is nonzero
2378 then the number is slightly smaller than indicated.
2380 Input EXP is the biased exponent, which may be negative.
2381 the exponent field of S is ignored but is replaced by
2382 EXP as adjusted by normalization and rounding.
2384 Input RCNTRL is the rounding control. If it is nonzero, the
2385 returned value will be rounded to RNDPRC bits.
2387 For future reference: In order for emdnorm to round off denormal
2388 significands at the right point, the input exponent must be
2389 adjusted to be the actual value it would have after conversion to
2390 the final floating point type. This adjustment has been
2391 implemented for all type conversions (etoe53, etc.) and decimal
2392 conversions, but not for the arithmetic functions (eadd, etc.).
2393 Data types having standard 15-bit exponents are not affected by
2394 this, but SFmode and DFmode are affected. For example, ediv with
2395 rndprc = 24 will not round correctly to 24-bit precision if the
2396 result is denormal. */
2398 static int rlast
= -1;
2400 static unsigned EMUSHORT rmsk
= 0;
2401 static unsigned EMUSHORT rmbit
= 0;
2402 static unsigned EMUSHORT rebit
= 0;
2404 static unsigned EMUSHORT rbit
[NI
];
2407 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2408 unsigned EMUSHORT s
[];
2415 unsigned EMUSHORT r
;
2420 /* a blank significand could mean either zero or infinity. */
2433 if ((j
> NBITS
) && (exp
< 32767))
2441 if (exp
> (EMULONG
) (-NBITS
- 1))
2454 /* Round off, unless told not to by rcntrl. */
2457 /* Set up rounding parameters if the control register changed. */
2458 if (rndprc
!= rlast
)
2465 rw
= NI
- 1; /* low guard word */
2488 /* For DEC or IBM arithmetic */
2505 /* For C4x arithmetic */
2526 /* Shift down 1 temporarily if the data structure has an implied
2527 most significant bit and the number is denormal.
2528 Intel long double denormals also lose one bit of precision. */
2529 if ((exp
<= 0) && (rndprc
!= NBITS
)
2530 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2532 lost
|= s
[NI
- 1] & 1;
2535 /* Clear out all bits below the rounding bit,
2536 remembering in r if any were nonzero. */
2550 if ((r
& rmbit
) != 0)
2555 { /* round to even */
2556 if ((s
[re
] & rebit
) == 0)
2568 /* Undo the temporary shift for denormal values. */
2569 if ((exp
<= 0) && (rndprc
!= NBITS
)
2570 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2575 { /* overflow on roundoff */
2588 for (i
= 2; i
< NI
- 1; i
++)
2591 warning ("floating point overflow");
2595 for (i
= M
+ 1; i
< NI
- 1; i
++)
2598 if ((rndprc
< 64) || (rndprc
== 113))
2613 s
[1] = (unsigned EMUSHORT
) exp
;
2616 /* Subtract. C = B - A, all e type numbers. */
2618 static int subflg
= 0;
2622 unsigned EMUSHORT
*a
, *b
, *c
;
2636 /* Infinity minus infinity is a NaN.
2637 Test for subtracting infinities of the same sign. */
2638 if (eisinf (a
) && eisinf (b
)
2639 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2641 mtherr ("esub", INVALID
);
2650 /* Add. C = A + B, all e type. */
2654 unsigned EMUSHORT
*a
, *b
, *c
;
2658 /* NaN plus anything is a NaN. */
2669 /* Infinity minus infinity is a NaN.
2670 Test for adding infinities of opposite signs. */
2671 if (eisinf (a
) && eisinf (b
)
2672 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2674 mtherr ("esub", INVALID
);
2683 /* Arithmetic common to both addition and subtraction. */
2687 unsigned EMUSHORT
*a
, *b
, *c
;
2689 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2691 EMULONG lt
, lta
, ltb
;
2712 /* compare exponents */
2717 { /* put the larger number in bi */
2727 if (lt
< (EMULONG
) (-NBITS
- 1))
2728 goto done
; /* answer same as larger addend */
2730 lost
= eshift (ai
, k
); /* shift the smaller number down */
2734 /* exponents were the same, so must compare significands */
2737 { /* the numbers are identical in magnitude */
2738 /* if different signs, result is zero */
2744 /* if same sign, result is double */
2745 /* double denormalized tiny number */
2746 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2751 /* add 1 to exponent unless both are zero! */
2752 for (j
= 1; j
< NI
- 1; j
++)
2768 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2772 { /* put the larger number in bi */
2788 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2794 /* Divide: C = B/A, all e type. */
2798 unsigned EMUSHORT
*a
, *b
, *c
;
2800 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2802 EMULONG lt
, lta
, ltb
;
2804 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2805 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2806 sign
= eisneg(a
) ^ eisneg(b
);
2809 /* Return any NaN input. */
2820 /* Zero over zero, or infinity over infinity, is a NaN. */
2821 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2822 || (eisinf (a
) && eisinf (b
)))
2824 mtherr ("ediv", INVALID
);
2829 /* Infinity over anything else is infinity. */
2836 /* Anything else over infinity is zero. */
2848 { /* See if numerator is zero. */
2849 for (i
= 1; i
< NI
- 1; i
++)
2853 ltb
-= enormlz (bi
);
2863 { /* possible divide by zero */
2864 for (i
= 1; i
< NI
- 1; i
++)
2868 lta
-= enormlz (ai
);
2872 /* Divide by zero is not an invalid operation.
2873 It is a divide-by-zero operation! */
2875 mtherr ("ediv", SING
);
2881 /* calculate exponent */
2882 lt
= ltb
- lta
+ EXONE
;
2883 emdnorm (bi
, i
, 0, lt
, 64);
2890 && (ecmp (c
, ezero
) != 0)
2893 *(c
+(NE
-1)) |= 0x8000;
2895 *(c
+(NE
-1)) &= ~0x8000;
2898 /* Multiply e-types A and B, return e-type product C. */
2902 unsigned EMUSHORT
*a
, *b
, *c
;
2904 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2906 EMULONG lt
, lta
, ltb
;
2908 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2909 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2910 sign
= eisneg(a
) ^ eisneg(b
);
2913 /* NaN times anything is the same NaN. */
2924 /* Zero times infinity is a NaN. */
2925 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2926 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2928 mtherr ("emul", INVALID
);
2933 /* Infinity times anything else is infinity. */
2935 if (eisinf (a
) || eisinf (b
))
2947 for (i
= 1; i
< NI
- 1; i
++)
2951 lta
-= enormlz (ai
);
2962 for (i
= 1; i
< NI
- 1; i
++)
2966 ltb
-= enormlz (bi
);
2975 /* Multiply significands */
2977 /* calculate exponent */
2978 lt
= lta
+ ltb
- (EXONE
- 1);
2979 emdnorm (bi
, j
, 0, lt
, 64);
2986 && (ecmp (c
, ezero
) != 0)
2989 *(c
+(NE
-1)) |= 0x8000;
2991 *(c
+(NE
-1)) &= ~0x8000;
2994 /* Convert double precision PE to e-type Y. */
2998 unsigned EMUSHORT
*pe
, *y
;
3007 ibmtoe (pe
, y
, DFmode
);
3012 c4xtoe (pe
, y
, HFmode
);
3015 register unsigned EMUSHORT r
;
3016 register unsigned EMUSHORT
*e
, *p
;
3017 unsigned EMUSHORT yy
[NI
];
3021 denorm
= 0; /* flag if denormalized number */
3023 if (! REAL_WORDS_BIG_ENDIAN
)
3029 yy
[M
] = (r
& 0x0f) | 0x10;
3030 r
&= ~0x800f; /* strip sign and 4 significand bits */
3035 if (! REAL_WORDS_BIG_ENDIAN
)
3037 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3038 || (pe
[1] != 0) || (pe
[0] != 0))
3040 enan (y
, yy
[0] != 0);
3046 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3047 || (pe
[2] != 0) || (pe
[3] != 0))
3049 enan (y
, yy
[0] != 0);
3060 #endif /* INFINITY */
3062 /* If zero exponent, then the significand is denormalized.
3063 So take back the understood high significand bit. */
3074 if (! REAL_WORDS_BIG_ENDIAN
)
3091 /* If zero exponent, then normalize the significand. */
3092 if ((k
= enormlz (yy
)) > NBITS
)
3095 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3098 #endif /* not C4X */
3099 #endif /* not IBM */
3100 #endif /* not DEC */
3103 /* Convert double extended precision float PE to e type Y. */
3107 unsigned EMUSHORT
*pe
, *y
;
3109 unsigned EMUSHORT yy
[NI
];
3110 unsigned EMUSHORT
*e
, *p
, *q
;
3115 for (i
= 0; i
< NE
- 5; i
++)
3117 /* This precision is not ordinarily supported on DEC or IBM. */
3119 for (i
= 0; i
< 5; i
++)
3123 p
= &yy
[0] + (NE
- 1);
3126 for (i
= 0; i
< 5; i
++)
3130 if (! REAL_WORDS_BIG_ENDIAN
)
3132 for (i
= 0; i
< 5; i
++)
3135 /* For denormal long double Intel format, shift significand up one
3136 -- but only if the top significand bit is zero. A top bit of 1
3137 is "pseudodenormal" when the exponent is zero. */
3138 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3140 unsigned EMUSHORT temp
[NI
];
3150 p
= &yy
[0] + (NE
- 1);
3151 #ifdef ARM_EXTENDED_IEEE_FORMAT
3152 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3153 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3159 for (i
= 0; i
< 4; i
++)
3164 /* Point to the exponent field and check max exponent cases. */
3166 if ((*p
& 0x7fff) == 0x7fff)
3169 if (! REAL_WORDS_BIG_ENDIAN
)
3171 for (i
= 0; i
< 4; i
++)
3173 if ((i
!= 3 && pe
[i
] != 0)
3174 /* Anything but 0x8000 here, including 0, is a NaN. */
3175 || (i
== 3 && pe
[i
] != 0x8000))
3177 enan (y
, (*p
& 0x8000) != 0);
3184 #ifdef ARM_EXTENDED_IEEE_FORMAT
3185 for (i
= 2; i
<= 5; i
++)
3189 enan (y
, (*p
& 0x8000) != 0);
3194 /* In Motorola extended precision format, the most significant
3195 bit of an infinity mantissa could be either 1 or 0. It is
3196 the lower order bits that tell whether the value is a NaN. */
3197 if ((pe
[2] & 0x7fff) != 0)
3200 for (i
= 3; i
<= 5; i
++)
3205 enan (y
, (*p
& 0x8000) != 0);
3209 #endif /* not ARM */
3218 #endif /* INFINITY */
3221 for (i
= 0; i
< NE
; i
++)
3225 /* Convert 128-bit long double precision float PE to e type Y. */
3229 unsigned EMUSHORT
*pe
, *y
;
3231 register unsigned EMUSHORT r
;
3232 unsigned EMUSHORT
*e
, *p
;
3233 unsigned EMUSHORT yy
[NI
];
3240 if (! REAL_WORDS_BIG_ENDIAN
)
3252 if (! REAL_WORDS_BIG_ENDIAN
)
3254 for (i
= 0; i
< 7; i
++)
3258 enan (y
, yy
[0] != 0);
3265 for (i
= 1; i
< 8; i
++)
3269 enan (y
, yy
[0] != 0);
3281 #endif /* INFINITY */
3285 if (! REAL_WORDS_BIG_ENDIAN
)
3287 for (i
= 0; i
< 7; i
++)
3293 for (i
= 0; i
< 7; i
++)
3297 /* If denormal, remove the implied bit; else shift down 1. */
3310 /* Convert single precision float PE to e type Y. */
3314 unsigned EMUSHORT
*pe
, *y
;
3318 ibmtoe (pe
, y
, SFmode
);
3324 c4xtoe (pe
, y
, QFmode
);
3328 register unsigned EMUSHORT r
;
3329 register unsigned EMUSHORT
*e
, *p
;
3330 unsigned EMUSHORT yy
[NI
];
3334 denorm
= 0; /* flag if denormalized number */
3337 if (! REAL_WORDS_BIG_ENDIAN
)
3347 yy
[M
] = (r
& 0x7f) | 0200;
3348 r
&= ~0x807f; /* strip sign and 7 significand bits */
3353 if (REAL_WORDS_BIG_ENDIAN
)
3355 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3357 enan (y
, yy
[0] != 0);
3363 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3365 enan (y
, yy
[0] != 0);
3376 #endif /* INFINITY */
3378 /* If zero exponent, then the significand is denormalized.
3379 So take back the understood high significand bit. */
3392 if (! REAL_WORDS_BIG_ENDIAN
)
3402 { /* if zero exponent, then normalize the significand */
3403 if ((k
= enormlz (yy
)) > NBITS
)
3406 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3409 #endif /* not C4X */
3410 #endif /* not IBM */
3413 /* Convert e-type X to IEEE 128-bit long double format E. */
3417 unsigned EMUSHORT
*x
, *e
;
3419 unsigned EMUSHORT xi
[NI
];
3426 make_nan (e
, eisneg (x
), TFmode
);
3431 exp
= (EMULONG
) xi
[E
];
3436 /* round off to nearest or even */
3439 emdnorm (xi
, 0, 0, exp
, 64);
3445 /* Convert exploded e-type X, that has already been rounded to
3446 113-bit precision, to IEEE 128-bit long double format Y. */
3450 unsigned EMUSHORT
*a
, *b
;
3452 register unsigned EMUSHORT
*p
, *q
;
3453 unsigned EMUSHORT i
;
3458 make_nan (b
, eiisneg (a
), TFmode
);
3463 if (REAL_WORDS_BIG_ENDIAN
)
3466 q
= b
+ 7; /* point to output exponent */
3468 /* If not denormal, delete the implied bit. */
3473 /* combine sign and exponent */
3475 if (REAL_WORDS_BIG_ENDIAN
)
3478 *q
++ = *p
++ | 0x8000;
3485 *q
-- = *p
++ | 0x8000;
3489 /* skip over guard word */
3491 /* move the significand */
3492 if (REAL_WORDS_BIG_ENDIAN
)
3494 for (i
= 0; i
< 7; i
++)
3499 for (i
= 0; i
< 7; i
++)
3504 /* Convert e-type X to IEEE double extended format E. */
3508 unsigned EMUSHORT
*x
, *e
;
3510 unsigned EMUSHORT xi
[NI
];
3517 make_nan (e
, eisneg (x
), XFmode
);
3522 /* adjust exponent for offset */
3523 exp
= (EMULONG
) xi
[E
];
3528 /* round off to nearest or even */
3531 emdnorm (xi
, 0, 0, exp
, 64);
3537 /* Convert exploded e-type X, that has already been rounded to
3538 64-bit precision, to IEEE double extended format Y. */
3542 unsigned EMUSHORT
*a
, *b
;
3544 register unsigned EMUSHORT
*p
, *q
;
3545 unsigned EMUSHORT i
;
3550 make_nan (b
, eiisneg (a
), XFmode
);
3554 /* Shift denormal long double Intel format significand down one bit. */
3555 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3565 if (REAL_WORDS_BIG_ENDIAN
)
3569 q
= b
+ 4; /* point to output exponent */
3570 #if LONG_DOUBLE_TYPE_SIZE == 96
3571 /* Clear the last two bytes of 12-byte Intel format */
3577 /* combine sign and exponent */
3581 *q
++ = *p
++ | 0x8000;
3588 *q
-- = *p
++ | 0x8000;
3593 if (REAL_WORDS_BIG_ENDIAN
)
3595 #ifdef ARM_EXTENDED_IEEE_FORMAT
3596 /* The exponent is in the lowest 15 bits of the first word. */
3597 *q
++ = i
? 0x8000 : 0;
3601 *q
++ = *p
++ | 0x8000;
3610 *q
-- = *p
++ | 0x8000;
3615 /* skip over guard word */
3617 /* move the significand */
3619 for (i
= 0; i
< 4; i
++)
3623 for (i
= 0; i
< 4; i
++)
3627 if (REAL_WORDS_BIG_ENDIAN
)
3629 for (i
= 0; i
< 4; i
++)
3637 /* Intel long double infinity significand. */
3645 for (i
= 0; i
< 4; i
++)
3651 /* e type to double precision. */
3654 /* Convert e-type X to DEC-format double E. */
3658 unsigned EMUSHORT
*x
, *e
;
3660 etodec (x
, e
); /* see etodec.c */
3663 /* Convert exploded e-type X, that has already been rounded to
3664 56-bit double precision, to DEC double Y. */
3668 unsigned EMUSHORT
*x
, *y
;
3675 /* Convert e-type X to IBM 370-format double E. */
3679 unsigned EMUSHORT
*x
, *e
;
3681 etoibm (x
, e
, DFmode
);
3684 /* Convert exploded e-type X, that has already been rounded to
3685 56-bit precision, to IBM 370 double Y. */
3689 unsigned EMUSHORT
*x
, *y
;
3691 toibm (x
, y
, DFmode
);
3694 #else /* it's neither DEC nor IBM */
3696 /* Convert e-type X to C4X-format double E. */
3700 unsigned EMUSHORT
*x
, *e
;
3702 etoc4x (x
, e
, HFmode
);
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 toc4x (x
, y
, HFmode
);
3715 #else /* it's neither DEC nor IBM nor C4X */
3717 /* Convert e-type X to IEEE double E. */
3721 unsigned EMUSHORT
*x
, *e
;
3723 unsigned EMUSHORT xi
[NI
];
3730 make_nan (e
, eisneg (x
), DFmode
);
3735 /* adjust exponent for offsets */
3736 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3741 /* round off to nearest or even */
3744 emdnorm (xi
, 0, 0, exp
, 64);
3750 /* Convert exploded e-type X, that has already been rounded to
3751 53-bit precision, to IEEE double Y. */
3755 unsigned EMUSHORT
*x
, *y
;
3757 unsigned EMUSHORT i
;
3758 unsigned EMUSHORT
*p
;
3763 make_nan (y
, eiisneg (x
), DFmode
);
3769 if (! REAL_WORDS_BIG_ENDIAN
)
3772 *y
= 0; /* output high order */
3774 *y
= 0x8000; /* output sign bit */
3777 if (i
>= (unsigned int) 2047)
3779 /* Saturate at largest number less than infinity. */
3782 if (! REAL_WORDS_BIG_ENDIAN
)
3796 *y
|= (unsigned EMUSHORT
) 0x7fef;
3797 if (! REAL_WORDS_BIG_ENDIAN
)
3822 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3823 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3824 if (! REAL_WORDS_BIG_ENDIAN
)
3839 #endif /* not C4X */
3840 #endif /* not IBM */
3841 #endif /* not DEC */
3845 /* e type to single precision. */
3848 /* Convert e-type X to IBM 370 float E. */
3852 unsigned EMUSHORT
*x
, *e
;
3854 etoibm (x
, e
, SFmode
);
3857 /* Convert exploded e-type X, that has already been rounded to
3858 float precision, to IBM 370 float Y. */
3862 unsigned EMUSHORT
*x
, *y
;
3864 toibm (x
, y
, SFmode
);
3870 /* Convert e-type X to C4X float E. */
3874 unsigned EMUSHORT
*x
, *e
;
3876 etoc4x (x
, e
, QFmode
);
3879 /* Convert exploded e-type X, that has already been rounded to
3880 float precision, to IBM 370 float Y. */
3884 unsigned EMUSHORT
*x
, *y
;
3886 toc4x (x
, y
, QFmode
);
3891 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3895 unsigned EMUSHORT
*x
, *e
;
3898 unsigned EMUSHORT xi
[NI
];
3904 make_nan (e
, eisneg (x
), SFmode
);
3909 /* adjust exponent for offsets */
3910 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3915 /* round off to nearest or even */
3918 emdnorm (xi
, 0, 0, exp
, 64);
3924 /* Convert exploded e-type X, that has already been rounded to
3925 float precision, to IEEE float Y. */
3929 unsigned EMUSHORT
*x
, *y
;
3931 unsigned EMUSHORT i
;
3932 unsigned EMUSHORT
*p
;
3937 make_nan (y
, eiisneg (x
), SFmode
);
3943 if (! REAL_WORDS_BIG_ENDIAN
)
3949 *y
= 0; /* output high order */
3951 *y
= 0x8000; /* output sign bit */
3954 /* Handle overflow cases. */
3958 *y
|= (unsigned EMUSHORT
) 0x7f80;
3963 if (! REAL_WORDS_BIG_ENDIAN
)
3971 #else /* no INFINITY */
3972 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3977 if (! REAL_WORDS_BIG_ENDIAN
)
3988 #endif /* no INFINITY */
4000 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4001 /* High order output already has sign bit set. */
4007 if (! REAL_WORDS_BIG_ENDIAN
)
4016 #endif /* not C4X */
4017 #endif /* not IBM */
4019 /* Compare two e type numbers.
4023 -2 if either a or b is a NaN. */
4027 unsigned EMUSHORT
*a
, *b
;
4029 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4030 register unsigned EMUSHORT
*p
, *q
;
4035 if (eisnan (a
) || eisnan (b
))
4044 { /* the signs are different */
4046 for (i
= 1; i
< NI
- 1; i
++)
4060 /* both are the same sign */
4075 return (0); /* equality */
4079 if (*(--p
) > *(--q
))
4080 return (msign
); /* p is bigger */
4082 return (-msign
); /* p is littler */
4085 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4089 unsigned EMUSHORT
*x
, *y
;
4095 /* Convert HOST_WIDE_INT LP to e type Y. */
4100 unsigned EMUSHORT
*y
;
4102 unsigned EMUSHORT yi
[NI
];
4103 unsigned HOST_WIDE_INT ll
;
4109 /* make it positive */
4110 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4111 yi
[0] = 0xffff; /* put correct sign in the e type number */
4115 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4117 /* move the long integer to yi significand area */
4118 #if HOST_BITS_PER_WIDE_INT == 64
4119 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4120 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4121 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4122 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4123 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4125 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4126 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4127 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4130 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4131 ecleaz (yi
); /* it was zero */
4133 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4134 emovo (yi
, y
); /* output the answer */
4137 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4141 unsigned HOST_WIDE_INT
*lp
;
4142 unsigned EMUSHORT
*y
;
4144 unsigned EMUSHORT yi
[NI
];
4145 unsigned HOST_WIDE_INT ll
;
4151 /* move the long integer to ayi significand area */
4152 #if HOST_BITS_PER_WIDE_INT == 64
4153 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4154 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4155 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4156 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4157 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4159 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4160 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4161 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4164 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4165 ecleaz (yi
); /* it was zero */
4167 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4168 emovo (yi
, y
); /* output the answer */
4172 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4173 part FRAC of e-type (packed internal format) floating point input X.
4174 The integer output I has the sign of the input, except that
4175 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4176 The output e-type fraction FRAC is the positive fractional
4181 unsigned EMUSHORT
*x
;
4183 unsigned EMUSHORT
*frac
;
4185 unsigned EMUSHORT xi
[NI
];
4187 unsigned HOST_WIDE_INT ll
;
4190 k
= (int) xi
[E
] - (EXONE
- 1);
4193 /* if exponent <= 0, integer = 0 and real output is fraction */
4198 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4200 /* long integer overflow: output large integer
4201 and correct fraction */
4203 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4206 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4207 /* In this case, let it overflow and convert as if unsigned. */
4208 euifrac (x
, &ll
, frac
);
4209 *i
= (HOST_WIDE_INT
) ll
;
4212 /* In other cases, return the largest positive integer. */
4213 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4218 warning ("overflow on truncation to integer");
4222 /* Shift more than 16 bits: first shift up k-16 mod 16,
4223 then shift up by 16's. */
4224 j
= k
- ((k
>> 4) << 4);
4231 ll
= (ll
<< 16) | xi
[M
];
4233 while ((k
-= 16) > 0);
4240 /* shift not more than 16 bits */
4242 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4249 if ((k
= enormlz (xi
)) > NBITS
)
4252 xi
[E
] -= (unsigned EMUSHORT
) k
;
4258 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4259 FRAC of e-type X. A negative input yields integer output = 0 but
4260 correct fraction. */
4263 euifrac (x
, i
, frac
)
4264 unsigned EMUSHORT
*x
;
4265 unsigned HOST_WIDE_INT
*i
;
4266 unsigned EMUSHORT
*frac
;
4268 unsigned HOST_WIDE_INT ll
;
4269 unsigned EMUSHORT xi
[NI
];
4273 k
= (int) xi
[E
] - (EXONE
- 1);
4276 /* if exponent <= 0, integer = 0 and argument is fraction */
4281 if (k
> HOST_BITS_PER_WIDE_INT
)
4283 /* Long integer overflow: output large integer
4284 and correct fraction.
4285 Note, the BSD microvax compiler says that ~(0UL)
4286 is a syntax error. */
4290 warning ("overflow on truncation to unsigned integer");
4294 /* Shift more than 16 bits: first shift up k-16 mod 16,
4295 then shift up by 16's. */
4296 j
= k
- ((k
>> 4) << 4);
4303 ll
= (ll
<< 16) | xi
[M
];
4305 while ((k
-= 16) > 0);
4310 /* shift not more than 16 bits */
4312 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4315 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4321 if ((k
= enormlz (xi
)) > NBITS
)
4324 xi
[E
] -= (unsigned EMUSHORT
) k
;
4329 /* Shift the significand of exploded e-type X up or down by SC bits. */
4333 unsigned EMUSHORT
*x
;
4336 unsigned EMUSHORT lost
;
4337 unsigned EMUSHORT
*p
;
4350 lost
|= *p
; /* remember lost bits */
4391 return ((int) lost
);
4394 /* Shift normalize the significand area of exploded e-type X.
4395 Return the shift count (up = positive). */
4399 unsigned EMUSHORT x
[];
4401 register unsigned EMUSHORT
*p
;
4410 return (0); /* already normalized */
4416 /* With guard word, there are NBITS+16 bits available.
4417 Return true if all are zero. */
4421 /* see if high byte is zero */
4422 while ((*p
& 0xff00) == 0)
4427 /* now shift 1 bit at a time */
4428 while ((*p
& 0x8000) == 0)
4434 mtherr ("enormlz", UNDERFLOW
);
4440 /* Normalize by shifting down out of the high guard word
4441 of the significand */
4456 mtherr ("enormlz", OVERFLOW
);
4463 /* Powers of ten used in decimal <-> binary conversions. */
4468 #if LONG_DOUBLE_TYPE_SIZE == 128
4469 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4471 {0x6576, 0x4a92, 0x804a, 0x153f,
4472 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4473 {0x6a32, 0xce52, 0x329a, 0x28ce,
4474 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4475 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4476 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4477 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4478 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4479 {0x851e, 0xeab7, 0x98fe, 0x901b,
4480 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4481 {0x0235, 0x0137, 0x36b1, 0x336c,
4482 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4483 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4484 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4485 {0x0000, 0x0000, 0x0000, 0x0000,
4486 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4487 {0x0000, 0x0000, 0x0000, 0x0000,
4488 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4489 {0x0000, 0x0000, 0x0000, 0x0000,
4490 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4491 {0x0000, 0x0000, 0x0000, 0x0000,
4492 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4493 {0x0000, 0x0000, 0x0000, 0x0000,
4494 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4495 {0x0000, 0x0000, 0x0000, 0x0000,
4496 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4499 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4501 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4502 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4503 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4504 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4505 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4506 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4507 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4508 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4509 {0xa23e, 0x5308, 0xfefb, 0x1155,
4510 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4511 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4512 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4513 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4514 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4515 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4516 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4517 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4518 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4519 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4520 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4521 {0xc155, 0xa4a8, 0x404e, 0x6113,
4522 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4523 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4524 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4525 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4526 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4529 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4530 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4532 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4533 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4534 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4535 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4536 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4537 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4538 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4539 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4540 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4541 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4542 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4543 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4544 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4547 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4549 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4550 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4551 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4552 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4553 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4554 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4555 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4556 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4557 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4558 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4559 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4560 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4561 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4565 /* Convert float value X to ASCII string STRING with NDIG digits after
4566 the decimal point. */
4569 e24toasc (x
, string
, ndigs
)
4570 unsigned EMUSHORT x
[];
4574 unsigned EMUSHORT w
[NI
];
4577 etoasc (w
, string
, ndigs
);
4580 /* Convert double value X to ASCII string STRING with NDIG digits after
4581 the decimal point. */
4584 e53toasc (x
, string
, ndigs
)
4585 unsigned EMUSHORT x
[];
4589 unsigned EMUSHORT w
[NI
];
4592 etoasc (w
, string
, ndigs
);
4595 /* Convert double extended value X to ASCII string STRING with NDIG digits
4596 after the decimal point. */
4599 e64toasc (x
, string
, ndigs
)
4600 unsigned EMUSHORT x
[];
4604 unsigned EMUSHORT w
[NI
];
4607 etoasc (w
, string
, ndigs
);
4610 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4611 after the decimal point. */
4614 e113toasc (x
, string
, ndigs
)
4615 unsigned EMUSHORT x
[];
4619 unsigned EMUSHORT w
[NI
];
4622 etoasc (w
, string
, ndigs
);
4625 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4626 the decimal point. */
4628 static char wstring
[80]; /* working storage for ASCII output */
4631 etoasc (x
, string
, ndigs
)
4632 unsigned EMUSHORT x
[];
4637 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4638 unsigned EMUSHORT
*p
, *r
, *ten
;
4639 unsigned EMUSHORT sign
;
4640 int i
, j
, k
, expon
, rndsav
;
4642 unsigned EMUSHORT m
;
4653 sprintf (wstring
, " NaN ");
4657 rndprc
= NBITS
; /* set to full precision */
4658 emov (x
, y
); /* retain external format */
4659 if (y
[NE
- 1] & 0x8000)
4662 y
[NE
- 1] &= 0x7fff;
4669 ten
= &etens
[NTEN
][0];
4671 /* Test for zero exponent */
4674 for (k
= 0; k
< NE
- 1; k
++)
4677 goto tnzro
; /* denormalized number */
4679 goto isone
; /* valid all zeros */
4683 /* Test for infinity. */
4684 if (y
[NE
- 1] == 0x7fff)
4687 sprintf (wstring
, " -Infinity ");
4689 sprintf (wstring
, " Infinity ");
4693 /* Test for exponent nonzero but significand denormalized.
4694 * This is an error condition.
4696 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4698 mtherr ("etoasc", DOMAIN
);
4699 sprintf (wstring
, "NaN");
4703 /* Compare to 1.0 */
4712 { /* Number is greater than 1 */
4713 /* Convert significand to an integer and strip trailing decimal zeros. */
4715 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4717 p
= &etens
[NTEN
- 4][0];
4723 for (j
= 0; j
< NE
- 1; j
++)
4736 /* Rescale from integer significand */
4737 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4739 /* Find power of 10 */
4743 /* An unordered compare result shouldn't happen here. */
4744 while (ecmp (ten
, u
) <= 0)
4746 if (ecmp (p
, u
) <= 0)
4759 { /* Number is less than 1.0 */
4760 /* Pad significand with trailing decimal zeros. */
4763 while ((y
[NE
- 2] & 0x8000) == 0)
4772 for (i
= 0; i
< NDEC
+ 1; i
++)
4774 if ((w
[NI
- 1] & 0x7) != 0)
4776 /* multiply by 10 */
4789 if (eone
[NE
- 1] <= u
[1])
4801 while (ecmp (eone
, w
) > 0)
4803 if (ecmp (p
, w
) >= 0)
4818 /* Find the first (leading) digit. */
4824 digit
= equot
[NI
- 1];
4825 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4833 digit
= equot
[NI
- 1];
4841 /* Examine number of digits requested by caller. */
4859 *s
++ = (char)digit
+ '0';
4862 /* Generate digits after the decimal point. */
4863 for (k
= 0; k
<= ndigs
; k
++)
4865 /* multiply current number by 10, without normalizing */
4872 *s
++ = (char) equot
[NI
- 1] + '0';
4874 digit
= equot
[NI
- 1];
4877 /* round off the ASCII string */
4880 /* Test for critical rounding case in ASCII output. */
4884 if (ecmp (t
, ezero
) != 0)
4885 goto roun
; /* round to nearest */
4886 if ((*(s
- 1) & 1) == 0)
4887 goto doexp
; /* round to even */
4889 /* Round up and propagate carry-outs */
4893 /* Carry out to most significant digit? */
4900 /* Most significant digit carries to 10? */
4908 /* Round up and carry out from less significant digits */
4920 sprintf (ss, "e+%d", expon);
4922 sprintf (ss, "e%d", expon);
4924 sprintf (ss
, "e%d", expon
);
4927 /* copy out the working string */
4930 while (*ss
== ' ') /* strip possible leading space */
4932 while ((*s
++ = *ss
++) != '\0')
4937 /* Convert ASCII string to floating point.
4939 Numeric input is a free format decimal number of any length, with
4940 or without decimal point. Entering E after the number followed by an
4941 integer number causes the second number to be interpreted as a power of
4942 10 to be multiplied by the first number (i.e., "scientific" notation). */
4944 /* Convert ASCII string S to single precision float value Y. */
4949 unsigned EMUSHORT
*y
;
4955 /* Convert ASCII string S to double precision value Y. */
4960 unsigned EMUSHORT
*y
;
4962 #if defined(DEC) || defined(IBM)
4974 /* Convert ASCII string S to double extended value Y. */
4979 unsigned EMUSHORT
*y
;
4984 /* Convert ASCII string S to 128-bit long double Y. */
4989 unsigned EMUSHORT
*y
;
4991 asctoeg (s
, y
, 113);
4994 /* Convert ASCII string S to e type Y. */
4999 unsigned EMUSHORT
*y
;
5001 asctoeg (s
, y
, NBITS
);
5004 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5008 asctoeg (ss
, y
, oprec
)
5010 unsigned EMUSHORT
*y
;
5013 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5014 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5015 int k
, trail
, c
, rndsav
;
5017 unsigned EMUSHORT nsign
, *p
;
5018 char *sp
, *s
, *lstr
;
5020 /* Copy the input string. */
5021 lstr
= (char *) alloca (strlen (ss
) + 1);
5023 while (*s
== ' ') /* skip leading spaces */
5026 while ((*sp
++ = *s
++) != '\0')
5031 rndprc
= NBITS
; /* Set to full precision */
5044 if ((k
>= 0) && (k
<= 9))
5046 /* Ignore leading zeros */
5047 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5049 /* Identify and strip trailing zeros after the decimal point. */
5050 if ((trail
== 0) && (decflg
!= 0))
5053 while ((*sp
>= '0') && (*sp
<= '9'))
5055 /* Check for syntax error */
5057 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
5058 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5069 /* If enough digits were given to more than fill up the yy register,
5070 continuing until overflow into the high guard word yy[2]
5071 guarantees that there will be a roundoff bit at the top
5072 of the low guard word after normalization. */
5077 nexp
+= 1; /* count digits after decimal point */
5078 eshup1 (yy
); /* multiply current number by 10 */
5084 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5089 /* Mark any lost non-zero digit. */
5091 /* Count lost digits before the decimal point. */
5106 case '.': /* decimal point */
5136 mtherr ("asctoe", DOMAIN
);
5145 /* Exponent interpretation */
5147 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5148 for (k
= 0; k
< NI
; k
++)
5159 /* check for + or - */
5167 while ((*s
>= '0') && (*s
<= '9'))
5171 if (exp
> -(MINDECEXP
))
5181 if (exp
> MAXDECEXP
)
5185 yy
[E
] = 0x7fff; /* infinity */
5188 if (exp
< MINDECEXP
)
5197 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5198 while ((nexp
> 0) && (yy
[2] == 0))
5210 if ((k
= enormlz (yy
)) > NBITS
)
5215 lexp
= (EXONE
- 1 + NBITS
) - k
;
5216 emdnorm (yy
, lost
, 0, lexp
, 64);
5218 /* Convert to external format:
5220 Multiply by 10**nexp. If precision is 64 bits,
5221 the maximum relative error incurred in forming 10**n
5222 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5223 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5224 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5239 /* Punt. Can't handle this without 2 divides. */
5240 emovi (etens
[0], tt
);
5247 p
= &etens
[NTEN
][0];
5257 while (exp
<= MAXP
);
5275 /* Round and convert directly to the destination type */
5277 lexp
-= EXONE
- 0x3ff;
5279 else if (oprec
== 24 || oprec
== 32)
5280 lexp
-= (EXONE
- 0x7f);
5283 else if (oprec
== 24 || oprec
== 56)
5284 lexp
-= EXONE
- (0x41 << 2);
5286 else if (oprec
== 24)
5287 lexp
-= EXONE
- 0177;
5291 else if (oprec
== 56)
5292 lexp
-= EXONE
- 0201;
5295 emdnorm (yy
, k
, 0, lexp
, 64);
5305 todec (yy
, y
); /* see etodec.c */
5310 toibm (yy
, y
, DFmode
);
5315 toc4x (yy
, y
, HFmode
);
5339 /* Return Y = largest integer not greater than X (truncated toward minus
5342 static unsigned EMUSHORT bmask
[] =
5365 unsigned EMUSHORT x
[], y
[];
5367 register unsigned EMUSHORT
*p
;
5369 unsigned EMUSHORT f
[NE
];
5371 emov (x
, f
); /* leave in external format */
5372 expon
= (int) f
[NE
- 1];
5373 e
= (expon
& 0x7fff) - (EXONE
- 1);
5379 /* number of bits to clear out */
5391 /* clear the remaining bits */
5393 /* truncate negatives toward minus infinity */
5396 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5398 for (i
= 0; i
< NE
- 1; i
++)
5411 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5412 For example, 1.1 = 0.55 * 2^1. */
5416 unsigned EMUSHORT x
[];
5418 unsigned EMUSHORT s
[];
5420 unsigned EMUSHORT xi
[NI
];
5424 /* Handle denormalized numbers properly using long integer exponent. */
5425 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5433 *exp
= (int) (li
- 0x3ffe);
5437 /* Return e type Y = X * 2^PWR2. */
5441 unsigned EMUSHORT x
[];
5443 unsigned EMUSHORT y
[];
5445 unsigned EMUSHORT xi
[NI
];
5453 emdnorm (xi
, i
, i
, li
, 64);
5459 /* C = remainder after dividing B by A, all e type values.
5460 Least significant integer quotient bits left in EQUOT. */
5464 unsigned EMUSHORT a
[], b
[], c
[];
5466 unsigned EMUSHORT den
[NI
], num
[NI
];
5470 || (ecmp (a
, ezero
) == 0)
5478 if (ecmp (a
, ezero
) == 0)
5480 mtherr ("eremain", SING
);
5486 eiremain (den
, num
);
5487 /* Sign of remainder = sign of quotient */
5496 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5497 remainder in NUM. */
5501 unsigned EMUSHORT den
[], num
[];
5504 unsigned EMUSHORT j
;
5507 ld
-= enormlz (den
);
5509 ln
-= enormlz (num
);
5513 if (ecmpm (den
, num
) <= 0)
5525 emdnorm (num
, 0, 0, ln
, 0);
5528 /* Report an error condition CODE encountered in function NAME.
5529 CODE is one of the following:
5531 Mnemonic Value Significance
5533 DOMAIN 1 argument domain error
5534 SING 2 function singularity
5535 OVERFLOW 3 overflow range error
5536 UNDERFLOW 4 underflow range error
5537 TLOSS 5 total loss of precision
5538 PLOSS 6 partial loss of precision
5539 INVALID 7 NaN - producing operation
5540 EDOM 33 Unix domain error code
5541 ERANGE 34 Unix range error code
5543 The order of appearance of the following messages is bound to the
5544 error codes defined above. */
5547 static char *ermsg
[NMSGS
] =
5549 "unknown", /* error code 0 */
5550 "domain", /* error code 1 */
5551 "singularity", /* et seq. */
5554 "total loss of precision",
5555 "partial loss of precision",
5569 /* The string passed by the calling program is supposed to be the
5570 name of the function in which the error occurred.
5571 The code argument selects which error message string will be printed. */
5573 if ((code
<= 0) || (code
>= NMSGS
))
5575 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5578 /* Set global error message word */
5583 /* Convert DEC double precision D to e type E. */
5587 unsigned EMUSHORT
*d
;
5588 unsigned EMUSHORT
*e
;
5590 unsigned EMUSHORT y
[NI
];
5591 register unsigned EMUSHORT r
, *p
;
5593 ecleaz (y
); /* start with a zero */
5594 p
= y
; /* point to our number */
5595 r
= *d
; /* get DEC exponent word */
5596 if (*d
& (unsigned int) 0x8000)
5597 *p
= 0xffff; /* fill in our sign */
5598 ++p
; /* bump pointer to our exponent word */
5599 r
&= 0x7fff; /* strip the sign bit */
5600 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5604 r
>>= 7; /* shift exponent word down 7 bits */
5605 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5606 /* add our e type exponent offset */
5607 *p
++ = r
; /* to form our exponent */
5609 r
= *d
++; /* now do the high order mantissa */
5610 r
&= 0177; /* strip off the DEC exponent and sign bits */
5611 r
|= 0200; /* the DEC understood high order mantissa bit */
5612 *p
++ = r
; /* put result in our high guard word */
5614 *p
++ = *d
++; /* fill in the rest of our mantissa */
5618 eshdn8 (y
); /* shift our mantissa down 8 bits */
5623 /* Convert e type X to DEC double precision D. */
5627 unsigned EMUSHORT
*x
, *d
;
5629 unsigned EMUSHORT xi
[NI
];
5634 /* Adjust exponent for offsets. */
5635 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5636 /* Round off to nearest or even. */
5639 emdnorm (xi
, 0, 0, exp
, 64);
5644 /* Convert exploded e-type X, that has already been rounded to
5645 56-bit precision, to DEC format double Y. */
5649 unsigned EMUSHORT
*x
, *y
;
5651 unsigned EMUSHORT i
;
5652 unsigned EMUSHORT
*p
;
5691 /* Convert IBM single/double precision to e type. */
5695 unsigned EMUSHORT
*d
;
5696 unsigned EMUSHORT
*e
;
5697 enum machine_mode mode
;
5699 unsigned EMUSHORT y
[NI
];
5700 register unsigned EMUSHORT r
, *p
;
5703 ecleaz (y
); /* start with a zero */
5704 p
= y
; /* point to our number */
5705 r
= *d
; /* get IBM exponent word */
5706 if (*d
& (unsigned int) 0x8000)
5707 *p
= 0xffff; /* fill in our sign */
5708 ++p
; /* bump pointer to our exponent word */
5709 r
&= 0x7f00; /* strip the sign bit */
5710 r
>>= 6; /* shift exponent word down 6 bits */
5711 /* in fact shift by 8 right and 2 left */
5712 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5713 /* add our e type exponent offset */
5714 *p
++ = r
; /* to form our exponent */
5716 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5717 /* strip off the IBM exponent and sign bits */
5718 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5720 *p
++ = *d
++; /* fill in the rest of our mantissa */
5725 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5728 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5729 /* handle change in RADIX */
5735 /* Convert e type to IBM single/double precision. */
5739 unsigned EMUSHORT
*x
, *d
;
5740 enum machine_mode mode
;
5742 unsigned EMUSHORT xi
[NI
];
5747 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5748 /* round off to nearest or even */
5751 emdnorm (xi
, 0, 0, exp
, 64);
5753 toibm (xi
, d
, mode
);
5758 unsigned EMUSHORT
*x
, *y
;
5759 enum machine_mode mode
;
5761 unsigned EMUSHORT i
;
5762 unsigned EMUSHORT
*p
;
5812 /* Convert C4X single/double precision to e type. */
5816 unsigned EMUSHORT
*d
;
5817 unsigned EMUSHORT
*e
;
5818 enum machine_mode mode
;
5820 unsigned EMUSHORT y
[NI
];
5828 /* Short-circuit the zero case. */
5829 if ((d
[0] == 0x8000)
5831 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5842 ecleaz (y
); /* start with a zero */
5843 r
= d
[0]; /* get sign/exponent part */
5844 if (r
& (unsigned int) 0x0080)
5846 y
[0] = 0xffff; /* fill in our sign */
5854 r
>>= 8; /* Shift exponent word down 8 bits. */
5855 if (r
& 0x80) /* Make the exponent negative if it is. */
5857 r
= r
| (~0 & ~0xff);
5862 /* Now do the high order mantissa. We don't "or" on the high bit
5863 because it is 2 (not 1) and is handled a little differently
5868 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5870 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5880 /* Now do the two's complement on the data. */
5882 carry
= 1; /* Initially add 1 for the two's complement. */
5883 for (i
=size
+ M
; i
> M
; i
--)
5885 if (carry
&& (y
[i
] == 0x0000))
5887 /* We overflowed into the next word, carry is the same. */
5888 y
[i
] = carry
? 0x0000 : 0xffff;
5892 /* No overflow, just invert and add carry. */
5893 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5908 /* Add our e type exponent offset to form our exponent. */
5912 /* Now do the high order mantissa strip off the exponent and sign
5913 bits and add the high 1 bit. */
5914 y
[M
] = d
[0] & 0x7f | 0x80;
5917 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5919 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5929 /* Convert e type to C4X single/double precision. */
5933 unsigned EMUSHORT
*x
, *d
;
5934 enum machine_mode mode
;
5936 unsigned EMUSHORT xi
[NI
];
5942 /* Adjust exponent for offsets. */
5943 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5945 /* Round off to nearest or even. */
5947 rndprc
= mode
== QFmode
? 24 : 32;
5948 emdnorm (xi
, 0, 0, exp
, 64);
5950 toc4x (xi
, d
, mode
);
5955 unsigned EMUSHORT
*x
, *y
;
5956 enum machine_mode mode
;
5963 /* Short-circuit the zero case */
5964 if ((x
[0] == 0) /* Zero exponent and sign */
5966 && (x
[M
] == 0) /* The rest is for zero mantissa */
5968 /* Only check for double if necessary */
5969 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
5971 /* We have a zero. Put it into the output and return. */
5984 /* Negative number require a two's complement conversion of the
5990 i
= ((int) x
[1]) - 0x7f;
5992 /* Now add 1 to the inverted data to do the two's complement. */
6002 x
[v
] = carry
? 0x0000 : 0xffff;
6006 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6012 /* The following is a special case. The C4X negative float requires
6013 a zero in the high bit (because the format is (2 - x) x 2^m), so
6014 if a one is in that bit, we have to shift left one to get rid
6015 of it. This only occurs if the number is -1 x 2^m. */
6016 if (x
[M
+1] & 0x8000)
6018 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6019 high sign bit and shift the exponent. */
6026 i
= ((int) x
[1]) - 0x7f;
6029 if ((i
< -128) || (i
> 127))
6044 y
[0] |= ((i
& 0xff) << 8);
6048 y
[0] |= x
[M
] & 0x7f;
6058 /* Output a binary NaN bit pattern in the target machine's format. */
6060 /* If special NaN bit patterns are required, define them in tm.h
6061 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6067 unsigned EMUSHORT TFbignan
[8] =
6068 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6069 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6077 unsigned EMUSHORT XFbignan
[6] =
6078 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6079 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6087 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6088 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6096 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6097 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6103 make_nan (nan
, sign
, mode
)
6104 unsigned EMUSHORT
*nan
;
6106 enum machine_mode mode
;
6109 unsigned EMUSHORT
*p
;
6113 /* Possibly the `reserved operand' patterns on a VAX can be
6114 used like NaN's, but probably not in the same way as IEEE. */
6115 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6118 if (REAL_WORDS_BIG_ENDIAN
)
6126 if (REAL_WORDS_BIG_ENDIAN
)
6134 if (REAL_WORDS_BIG_ENDIAN
)
6143 if (REAL_WORDS_BIG_ENDIAN
)
6153 if (REAL_WORDS_BIG_ENDIAN
)
6154 *nan
++ = (sign
<< 15) | *p
++;
6157 if (! REAL_WORDS_BIG_ENDIAN
)
6158 *nan
= (sign
<< 15) | *p
;
6161 /* This is the inverse of the function `etarsingle' invoked by
6162 REAL_VALUE_TO_TARGET_SINGLE. */
6165 ereal_unto_float (f
)
6169 unsigned EMUSHORT s
[2];
6170 unsigned EMUSHORT e
[NE
];
6172 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6173 This is the inverse operation to what the function `endian' does. */
6174 if (REAL_WORDS_BIG_ENDIAN
)
6176 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6177 s
[1] = (unsigned EMUSHORT
) f
;
6181 s
[0] = (unsigned EMUSHORT
) f
;
6182 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6184 /* Convert and promote the target float to E-type. */
6186 /* Output E-type to REAL_VALUE_TYPE. */
6192 /* This is the inverse of the function `etardouble' invoked by
6193 REAL_VALUE_TO_TARGET_DOUBLE. */
6196 ereal_unto_double (d
)
6200 unsigned EMUSHORT s
[4];
6201 unsigned EMUSHORT e
[NE
];
6203 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6204 if (REAL_WORDS_BIG_ENDIAN
)
6206 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6207 s
[1] = (unsigned EMUSHORT
) d
[0];
6208 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6209 s
[3] = (unsigned EMUSHORT
) d
[1];
6213 /* Target float words are little-endian. */
6214 s
[0] = (unsigned EMUSHORT
) d
[0];
6215 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6216 s
[2] = (unsigned EMUSHORT
) d
[1];
6217 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6219 /* Convert target double to E-type. */
6221 /* Output E-type to REAL_VALUE_TYPE. */
6227 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6228 This is somewhat like ereal_unto_float, but the input types
6229 for these are different. */
6232 ereal_from_float (f
)
6236 unsigned EMUSHORT s
[2];
6237 unsigned EMUSHORT e
[NE
];
6239 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6240 This is the inverse operation to what the function `endian' does. */
6241 if (REAL_WORDS_BIG_ENDIAN
)
6243 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6244 s
[1] = (unsigned EMUSHORT
) f
;
6248 s
[0] = (unsigned EMUSHORT
) f
;
6249 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6251 /* Convert and promote the target float to E-type. */
6253 /* Output E-type to REAL_VALUE_TYPE. */
6259 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6260 This is somewhat like ereal_unto_double, but the input types
6261 for these are different.
6263 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6264 data format, with no holes in the bit packing. The first element
6265 of the input array holds the bits that would come first in the
6266 target computer's memory. */
6269 ereal_from_double (d
)
6273 unsigned EMUSHORT s
[4];
6274 unsigned EMUSHORT e
[NE
];
6276 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6277 if (REAL_WORDS_BIG_ENDIAN
)
6279 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6280 s
[1] = (unsigned EMUSHORT
) d
[0];
6281 #if HOST_BITS_PER_WIDE_INT == 32
6282 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6283 s
[3] = (unsigned EMUSHORT
) d
[1];
6285 /* In this case the entire target double is contained in the
6286 first array element. The second element of the input is
6288 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6289 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6294 /* Target float words are little-endian. */
6295 s
[0] = (unsigned EMUSHORT
) d
[0];
6296 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6297 #if HOST_BITS_PER_WIDE_INT == 32
6298 s
[2] = (unsigned EMUSHORT
) d
[1];
6299 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6301 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6302 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6305 /* Convert target double to E-type. */
6307 /* Output E-type to REAL_VALUE_TYPE. */
6314 /* Convert target computer unsigned 64-bit integer to e-type.
6315 The endian-ness of DImode follows the convention for integers,
6316 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6320 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6321 unsigned EMUSHORT
*e
;
6323 unsigned EMUSHORT yi
[NI
];
6327 if (WORDS_BIG_ENDIAN
)
6329 for (k
= M
; k
< M
+ 4; k
++)
6334 for (k
= M
+ 3; k
>= M
; k
--)
6337 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6338 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6339 ecleaz (yi
); /* it was zero */
6341 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6345 /* Convert target computer signed 64-bit integer to e-type. */
6349 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6350 unsigned EMUSHORT
*e
;
6352 unsigned EMULONG acc
;
6353 unsigned EMUSHORT yi
[NI
];
6354 unsigned EMUSHORT carry
;
6358 if (WORDS_BIG_ENDIAN
)
6360 for (k
= M
; k
< M
+ 4; k
++)
6365 for (k
= M
+ 3; k
>= M
; k
--)
6368 /* Take absolute value */
6374 for (k
= M
+ 3; k
>= M
; k
--)
6376 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6383 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6384 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6385 ecleaz (yi
); /* it was zero */
6387 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6394 /* Convert e-type to unsigned 64-bit int. */
6398 unsigned EMUSHORT
*x
;
6399 unsigned EMUSHORT
*i
;
6401 unsigned EMUSHORT xi
[NI
];
6410 k
= (int) xi
[E
] - (EXONE
- 1);
6413 for (j
= 0; j
< 4; j
++)
6419 for (j
= 0; j
< 4; j
++)
6422 warning ("overflow on truncation to integer");
6427 /* Shift more than 16 bits: first shift up k-16 mod 16,
6428 then shift up by 16's. */
6429 j
= k
- ((k
>> 4) << 4);
6433 if (WORDS_BIG_ENDIAN
)
6444 if (WORDS_BIG_ENDIAN
)
6449 while ((k
-= 16) > 0);
6453 /* shift not more than 16 bits */
6458 if (WORDS_BIG_ENDIAN
)
6477 /* Convert e-type to signed 64-bit int. */
6481 unsigned EMUSHORT
*x
;
6482 unsigned EMUSHORT
*i
;
6484 unsigned EMULONG acc
;
6485 unsigned EMUSHORT xi
[NI
];
6486 unsigned EMUSHORT carry
;
6487 unsigned EMUSHORT
*isave
;
6491 k
= (int) xi
[E
] - (EXONE
- 1);
6494 for (j
= 0; j
< 4; j
++)
6500 for (j
= 0; j
< 4; j
++)
6503 warning ("overflow on truncation to integer");
6509 /* Shift more than 16 bits: first shift up k-16 mod 16,
6510 then shift up by 16's. */
6511 j
= k
- ((k
>> 4) << 4);
6515 if (WORDS_BIG_ENDIAN
)
6526 if (WORDS_BIG_ENDIAN
)
6531 while ((k
-= 16) > 0);
6535 /* shift not more than 16 bits */
6538 if (WORDS_BIG_ENDIAN
)
6554 /* Negate if negative */
6558 if (WORDS_BIG_ENDIAN
)
6560 for (k
= 0; k
< 4; k
++)
6562 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6563 if (WORDS_BIG_ENDIAN
)
6575 /* Longhand square root routine. */
6578 static int esqinited
= 0;
6579 static unsigned short sqrndbit
[NI
];
6583 unsigned EMUSHORT
*x
, *y
;
6585 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6587 int i
, j
, k
, n
, nlups
;
6592 sqrndbit
[NI
- 2] = 1;
6595 /* Check for arg <= 0 */
6596 i
= ecmp (x
, ezero
);
6601 mtherr ("esqrt", DOMAIN
);
6617 /* Bring in the arg and renormalize if it is denormal. */
6619 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6623 /* Divide exponent by 2 */
6625 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6627 /* Adjust if exponent odd */
6637 n
= 8; /* get 8 bits of result per inner loop */
6643 /* bring in next word of arg */
6645 num
[NI
- 1] = xx
[j
+ 3];
6646 /* Do additional bit on last outer loop, for roundoff. */
6649 for (i
= 0; i
< n
; i
++)
6651 /* Next 2 bits of arg */
6654 /* Shift up answer */
6656 /* Make trial divisor */
6657 for (k
= 0; k
< NI
; k
++)
6660 eaddm (sqrndbit
, temp
);
6661 /* Subtract and insert answer bit if it goes in */
6662 if (ecmpm (temp
, num
) <= 0)
6672 /* Adjust for extra, roundoff loop done. */
6673 exp
+= (NBITS
- 1) - rndprc
;
6675 /* Sticky bit = 1 if the remainder is nonzero. */
6677 for (i
= 3; i
< NI
; i
++)
6680 /* Renormalize and round off. */
6681 emdnorm (sq
, k
, 0, exp
, 64);
6685 #endif /* EMU_NON_COMPILE not defined */
6687 /* Return the binary precision of the significand for a given
6688 floating point mode. The mode can hold an integer value
6689 that many bits wide, without losing any bits. */
6692 significand_size (mode
)
6693 enum machine_mode mode
;
6696 /* Don't test the modes, but their sizes, lest this
6697 code won't work for BITS_PER_UNIT != 8 . */
6699 switch (GET_MODE_BITSIZE (mode
))
6703 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6710 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6713 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6716 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6719 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
This page took 0.347261 seconds and 5 git commands to generate.