1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 /* To enable support of XFmode extended real floating point, define
29 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
31 To support cross compilation between IEEE, VAX and IBM floating
32 point formats, define REAL_ARITHMETIC in the tm.h file.
34 In either case the machine files (tm.h) must not contain any code
35 that tries to use host floating point arithmetic to convert
36 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
37 etc. In cross-compile situations a REAL_VALUE_TYPE may not
38 be intelligible to the host computer's native arithmetic.
40 The emulator defaults to the host's floating point format so that
41 its decimal conversion functions can be used if desired (see
44 The first part of this file interfaces gcc to a floating point
45 arithmetic suite that was not written with gcc in mind. Avoid
46 changing the low-level arithmetic routines unless you have suitable
47 test programs available. A special version of the PARANOIA floating
48 point arithmetic tester, modified for this purpose, can be found on
49 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
50 XFmode and TFmode transcendental functions, can be obtained by ftp from
51 netlib.att.com: netlib/cephes. */
53 /* Type of computer arithmetic.
54 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
56 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
57 to big-endian IEEE floating-point data structure. This definition
58 should work in SFmode `float' type and DFmode `double' type on
59 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
60 has been defined to be 96, then IEEE also invokes the particular
61 XFmode (`long double' type) data structure used by the Motorola
62 680x0 series processors.
64 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
65 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
66 has been defined to be 96, then IEEE also invokes the particular
67 XFmode `long double' data structure used by the Intel 80x86 series
70 `DEC' refers specifically to the Digital Equipment Corp PDP-11
71 and VAX floating point data structure. This model currently
72 supports no type wider than DFmode.
74 `IBM' refers specifically to the IBM System/370 and compatible
75 floating point data structure. This model currently supports
76 no type wider than DFmode. The IBM conversions were contributed by
77 frank@atom.ansto.gov.au (Frank Crawford).
79 `C4X' refers specifically to the floating point format used on
80 Texas Instruments TMS320C3x and TMS320C4x digital signal
81 processors. This supports QFmode (32-bit float, double) and HFmode
82 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
83 floats, C4x floats are not rounded to be even. The C4x conversions
84 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
85 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
87 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
88 then `long double' and `double' are both implemented, but they
89 both mean DFmode. In this case, the software floating-point
90 support available here is activated by writing
91 #define REAL_ARITHMETIC
94 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
95 and may deactivate XFmode since `long double' is used to refer
98 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
99 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
100 separate the floating point unit's endian-ness from that of
101 the integer addressing. This permits one to define a big-endian
102 FPU on a little-endian machine (e.g., ARM). An extension to
103 BYTES_BIG_ENDIAN may be required for some machines in the future.
104 These optional macros may be defined in tm.h. In real.h, they
105 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
106 them for any normal host or target machine on which the floats
107 and the integers have the same endian-ness. */
110 /* The following converts gcc macros into the ones used by this file. */
112 /* REAL_ARITHMETIC defined means that macros in real.h are
113 defined to call emulator functions. */
114 #ifdef REAL_ARITHMETIC
116 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
117 /* PDP-11, Pro350, VAX: */
119 #else /* it's not VAX */
120 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
121 /* IBM System/370 style */
123 #else /* it's also not an IBM */
124 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
125 /* TMS320C3x/C4x style */
127 #else /* it's also not a C4X */
128 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
130 #else /* it's not IEEE either */
131 /* UNKnown arithmetic. We don't support this and can't go on. */
132 unknown arithmetic type
134 #endif /* not IEEE */
139 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
142 /* REAL_ARITHMETIC not defined means that the *host's* data
143 structure will be used. It may differ by endian-ness from the
144 target machine's structure and will get its ends swapped
145 accordingly (but not here). Probably only the decimal <-> binary
146 functions in this file will actually be used in this case. */
148 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
150 #else /* it's not VAX */
151 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
152 /* IBM System/370 style */
154 #else /* it's also not an IBM */
155 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
157 #else /* it's not IEEE either */
158 unknown arithmetic type
160 #endif /* not IEEE */
164 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
166 #endif /* REAL_ARITHMETIC not defined */
168 /* Define INFINITY for support of infinity.
169 Define NANS for support of Not-a-Number's (NaN's). */
170 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
175 /* Support of NaNs requires support of infinity. */
182 /* Find a host integer type that is at least 16 bits wide,
183 and another type at least twice whatever that size is. */
185 #if HOST_BITS_PER_CHAR >= 16
186 #define EMUSHORT char
187 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
188 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
190 #if HOST_BITS_PER_SHORT >= 16
191 #define EMUSHORT short
192 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
193 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
195 #if HOST_BITS_PER_INT >= 16
197 #define EMUSHORT_SIZE HOST_BITS_PER_INT
198 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
200 #if HOST_BITS_PER_LONG >= 16
201 #define EMUSHORT long
202 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
203 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
205 /* You will have to modify this program to have a smaller unit size. */
206 #define EMU_NON_COMPILE
212 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
213 #define EMULONG short
215 #if HOST_BITS_PER_INT >= EMULONG_SIZE
218 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
221 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
222 #define EMULONG long long int
224 /* You will have to modify this program to have a smaller unit size. */
225 #define EMU_NON_COMPILE
232 /* The host interface doesn't work if no 16-bit size exists. */
233 #if EMUSHORT_SIZE != 16
234 #define EMU_NON_COMPILE
237 /* OK to continue compilation. */
238 #ifndef EMU_NON_COMPILE
240 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
241 In GET_REAL and PUT_REAL, r and e are pointers.
242 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
243 in memory, with no holes. */
245 #if LONG_DOUBLE_TYPE_SIZE == 96
246 /* Number of 16 bit words in external e type format */
248 #define MAXDECEXP 4932
249 #define MINDECEXP -4956
250 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
251 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
252 #else /* no XFmode */
253 #if LONG_DOUBLE_TYPE_SIZE == 128
255 #define MAXDECEXP 4932
256 #define MINDECEXP -4977
257 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
258 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
261 #define MAXDECEXP 4932
262 #define MINDECEXP -4956
263 #ifdef REAL_ARITHMETIC
264 /* Emulator uses target format internally
265 but host stores it in host endian-ness. */
267 #define GET_REAL(r,e) \
269 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
270 e53toe ((unsigned EMUSHORT *) (r), (e)); \
273 unsigned EMUSHORT w[4]; \
274 w[3] = ((EMUSHORT *) r)[0]; \
275 w[2] = ((EMUSHORT *) r)[1]; \
276 w[1] = ((EMUSHORT *) r)[2]; \
277 w[0] = ((EMUSHORT *) r)[3]; \
282 #define PUT_REAL(e,r) \
284 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
285 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
288 unsigned EMUSHORT w[4]; \
290 *((EMUSHORT *) r) = w[3]; \
291 *((EMUSHORT *) r + 1) = w[2]; \
292 *((EMUSHORT *) r + 2) = w[1]; \
293 *((EMUSHORT *) r + 3) = w[0]; \
297 #else /* not REAL_ARITHMETIC */
299 /* emulator uses host format */
300 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
301 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
303 #endif /* not REAL_ARITHMETIC */
304 #endif /* not TFmode */
305 #endif /* not XFmode */
308 /* Number of 16 bit words in internal format */
311 /* Array offset to exponent */
314 /* Array offset to high guard word */
317 /* Number of bits of precision */
318 #define NBITS ((NI-4)*16)
320 /* Maximum number of decimal digits in ASCII conversion
323 #define NDEC (NBITS*8/27)
325 /* The exponent of 1.0 */
326 #define EXONE (0x3fff)
328 extern int extra_warnings
;
329 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
330 extern unsigned EMUSHORT elog2
[], esqrt2
[];
332 static void endian
PROTO((unsigned EMUSHORT
*, long *,
334 static void eclear
PROTO((unsigned EMUSHORT
*));
335 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
337 static void eabs
PROTO((unsigned EMUSHORT
*));
339 static void eneg
PROTO((unsigned EMUSHORT
*));
340 static int eisneg
PROTO((unsigned EMUSHORT
*));
341 static int eisinf
PROTO((unsigned EMUSHORT
*));
342 static int eisnan
PROTO((unsigned EMUSHORT
*));
343 static void einfin
PROTO((unsigned EMUSHORT
*));
344 static void enan
PROTO((unsigned EMUSHORT
*, int));
345 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
346 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
347 static void ecleaz
PROTO((unsigned EMUSHORT
*));
348 static void ecleazs
PROTO((unsigned EMUSHORT
*));
349 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
350 static void einan
PROTO((unsigned EMUSHORT
*));
351 static int eiisnan
PROTO((unsigned EMUSHORT
*));
352 static int eiisneg
PROTO((unsigned EMUSHORT
*));
354 static void eiinfin
PROTO((unsigned EMUSHORT
*));
356 static int eiisinf
PROTO((unsigned EMUSHORT
*));
357 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
358 static void eshdn1
PROTO((unsigned EMUSHORT
*));
359 static void eshup1
PROTO((unsigned EMUSHORT
*));
360 static void eshdn8
PROTO((unsigned EMUSHORT
*));
361 static void eshup8
PROTO((unsigned EMUSHORT
*));
362 static void eshup6
PROTO((unsigned EMUSHORT
*));
363 static void eshdn6
PROTO((unsigned EMUSHORT
*));
364 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
365 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
366 static void m16m
PROTO((unsigned int, unsigned short *,
368 static int edivm
PROTO((unsigned short *, unsigned short *));
369 static int emulm
PROTO((unsigned short *, unsigned short *));
370 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
371 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
372 unsigned EMUSHORT
*));
373 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
374 unsigned EMUSHORT
*));
375 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
376 unsigned EMUSHORT
*));
377 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
378 unsigned EMUSHORT
*));
379 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
380 unsigned EMUSHORT
*));
381 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
384 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
386 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
387 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
388 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
389 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
390 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
391 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
392 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
395 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
397 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
398 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
399 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
400 unsigned EMUSHORT
*));
401 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
402 unsigned EMUSHORT
*));
403 static int eshift
PROTO((unsigned EMUSHORT
*, int));
404 static int enormlz
PROTO((unsigned EMUSHORT
*));
406 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
407 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
408 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
409 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
411 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
412 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
413 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
414 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
415 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
416 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
417 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
418 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
421 unsigned EMUSHORT
*));
423 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
425 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
426 unsigned EMUSHORT
*));
428 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
429 static void mtherr
PROTO((char *, int));
431 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
432 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
433 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
436 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
438 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
440 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
444 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
446 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
448 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
451 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
453 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
454 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
455 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
456 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
457 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
460 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
461 swapping ends if required, into output array of longs. The
462 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
466 unsigned EMUSHORT e
[];
468 enum machine_mode mode
;
472 if (REAL_WORDS_BIG_ENDIAN
)
477 /* Swap halfwords in the fourth long. */
478 th
= (unsigned long) e
[6] & 0xffff;
479 t
= (unsigned long) e
[7] & 0xffff;
484 /* Swap halfwords in the third long. */
485 th
= (unsigned long) e
[4] & 0xffff;
486 t
= (unsigned long) e
[5] & 0xffff;
489 /* fall into the double case */
492 /* Swap halfwords in the second word. */
493 th
= (unsigned long) e
[2] & 0xffff;
494 t
= (unsigned long) e
[3] & 0xffff;
497 /* fall into the float case */
501 /* Swap halfwords in the first word. */
502 th
= (unsigned long) e
[0] & 0xffff;
503 t
= (unsigned long) e
[1] & 0xffff;
514 /* Pack the output array without swapping. */
519 /* Pack the fourth long. */
520 th
= (unsigned long) e
[7] & 0xffff;
521 t
= (unsigned long) e
[6] & 0xffff;
526 /* Pack the third long.
527 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
529 th
= (unsigned long) e
[5] & 0xffff;
530 t
= (unsigned long) e
[4] & 0xffff;
533 /* fall into the double case */
536 /* Pack the second long */
537 th
= (unsigned long) e
[3] & 0xffff;
538 t
= (unsigned long) e
[2] & 0xffff;
541 /* fall into the float case */
545 /* Pack the first long */
546 th
= (unsigned long) e
[1] & 0xffff;
547 t
= (unsigned long) e
[0] & 0xffff;
559 /* This is the implementation of the REAL_ARITHMETIC macro. */
562 earith (value
, icode
, r1
, r2
)
563 REAL_VALUE_TYPE
*value
;
568 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
574 /* Return NaN input back to the caller. */
577 PUT_REAL (d1
, value
);
582 PUT_REAL (d2
, value
);
586 code
= (enum tree_code
) icode
;
594 esub (d2
, d1
, v
); /* d1 - d2 */
602 #ifndef REAL_INFINITY
603 if (ecmp (d2
, ezero
) == 0)
606 enan (v
, eisneg (d1
) ^ eisneg (d2
));
613 ediv (d2
, d1
, v
); /* d1/d2 */
616 case MIN_EXPR
: /* min (d1,d2) */
617 if (ecmp (d1
, d2
) < 0)
623 case MAX_EXPR
: /* max (d1,d2) */
624 if (ecmp (d1
, d2
) > 0)
637 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
638 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
644 unsigned EMUSHORT f
[NE
], g
[NE
];
660 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
661 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
667 unsigned EMUSHORT f
[NE
], g
[NE
];
669 unsigned HOST_WIDE_INT l
;
683 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
684 binary, rounding off as indicated by the machine_mode argument. Then it
685 promotes the rounded value to REAL_VALUE_TYPE. */
692 unsigned EMUSHORT tem
[NE
], e
[NE
];
735 /* Expansion of REAL_NEGATE. */
741 unsigned EMUSHORT e
[NE
];
751 /* Round real toward zero to HOST_WIDE_INT;
752 implements REAL_VALUE_FIX (x). */
758 unsigned EMUSHORT f
[NE
], g
[NE
];
765 warning ("conversion from NaN to int");
773 /* Round real toward zero to unsigned HOST_WIDE_INT
774 implements REAL_VALUE_UNSIGNED_FIX (x).
775 Negative input returns zero. */
777 unsigned HOST_WIDE_INT
781 unsigned EMUSHORT f
[NE
], g
[NE
];
782 unsigned HOST_WIDE_INT l
;
788 warning ("conversion from NaN to unsigned int");
797 /* REAL_VALUE_FROM_INT macro. */
800 ereal_from_int (d
, i
, j
, mode
)
803 enum machine_mode mode
;
805 unsigned EMUSHORT df
[NE
], dg
[NE
];
806 HOST_WIDE_INT low
, high
;
809 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
816 /* complement and add 1 */
823 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
824 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
826 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
831 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
832 Avoid double-rounding errors later by rounding off now from the
833 extra-wide internal format to the requested precision. */
834 switch (GET_MODE_BITSIZE (mode
))
864 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
867 ereal_from_uint (d
, i
, j
, mode
)
869 unsigned HOST_WIDE_INT i
, j
;
870 enum machine_mode mode
;
872 unsigned EMUSHORT df
[NE
], dg
[NE
];
873 unsigned HOST_WIDE_INT low
, high
;
875 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
879 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
885 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
886 Avoid double-rounding errors later by rounding off now from the
887 extra-wide internal format to the requested precision. */
888 switch (GET_MODE_BITSIZE (mode
))
918 /* REAL_VALUE_TO_INT macro. */
921 ereal_to_int (low
, high
, rr
)
922 HOST_WIDE_INT
*low
, *high
;
925 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
932 warning ("conversion from NaN to int");
938 /* convert positive value */
945 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
946 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
947 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
948 emul (df
, dh
, dg
); /* fractional part is the low word */
949 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
952 /* complement and add 1 */
962 /* REAL_VALUE_LDEXP macro. */
969 unsigned EMUSHORT e
[NE
], y
[NE
];
982 /* These routines are conditionally compiled because functions
983 of the same names may be defined in fold-const.c. */
985 #ifdef REAL_ARITHMETIC
987 /* Check for infinity in a REAL_VALUE_TYPE. */
993 unsigned EMUSHORT e
[NE
];
1003 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1009 unsigned EMUSHORT e
[NE
];
1013 return (eisnan (e
));
1020 /* Check for a negative REAL_VALUE_TYPE number.
1021 This just checks the sign bit, so that -0 counts as negative. */
1027 return ereal_isneg (x
);
1030 /* Expansion of REAL_VALUE_TRUNCATE.
1031 The result is in floating point, rounded to nearest or even. */
1034 real_value_truncate (mode
, arg
)
1035 enum machine_mode mode
;
1036 REAL_VALUE_TYPE arg
;
1038 unsigned EMUSHORT e
[NE
], t
[NE
];
1084 /* If an unsupported type was requested, presume that
1085 the machine files know something useful to do with
1086 the unmodified value. */
1095 /* Try to change R into its exact multiplicative inverse in machine mode
1096 MODE. Return nonzero function value if successful. */
1099 exact_real_inverse (mode
, r
)
1100 enum machine_mode mode
;
1103 unsigned EMUSHORT e
[NE
], einv
[NE
];
1104 REAL_VALUE_TYPE rinv
;
1109 /* Test for input in range. Don't transform IEEE special values. */
1110 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1113 /* Test for a power of 2: all significand bits zero except the MSB.
1114 We are assuming the target has binary (or hex) arithmetic. */
1115 if (e
[NE
- 2] != 0x8000)
1118 for (i
= 0; i
< NE
- 2; i
++)
1124 /* Compute the inverse and truncate it to the required mode. */
1125 ediv (e
, eone
, einv
);
1126 PUT_REAL (einv
, &rinv
);
1127 rinv
= real_value_truncate (mode
, rinv
);
1129 #ifdef CHECK_FLOAT_VALUE
1130 /* This check is not redundant. It may, for example, flush
1131 a supposedly IEEE denormal value to zero. */
1133 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1136 GET_REAL (&rinv
, einv
);
1138 /* Check the bits again, because the truncation might have
1139 generated an arbitrary saturation value on overflow. */
1140 if (einv
[NE
- 2] != 0x8000)
1143 for (i
= 0; i
< NE
- 2; i
++)
1149 /* Fail if the computed inverse is out of range. */
1150 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1153 /* Output the reciprocal and return success flag. */
1157 #endif /* REAL_ARITHMETIC defined */
1159 /* Used for debugging--print the value of R in human-readable format
1168 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1169 fprintf (stderr
, "%s", dstr
);
1173 /* The following routines convert REAL_VALUE_TYPE to the various floating
1174 point formats that are meaningful to supported computers.
1176 The results are returned in 32-bit pieces, each piece stored in a `long'.
1177 This is so they can be printed by statements like
1179 fprintf (file, "%lx, %lx", L[0], L[1]);
1181 that will work on both narrow- and wide-word host computers. */
1183 /* Convert R to a 128-bit long double precision value. The output array L
1184 contains four 32-bit pieces of the result, in the order they would appear
1192 unsigned EMUSHORT e
[NE
];
1196 endian (e
, l
, TFmode
);
1199 /* Convert R to a double extended precision value. The output array L
1200 contains three 32-bit pieces of the result, in the order they would
1201 appear in memory. */
1208 unsigned EMUSHORT e
[NE
];
1212 endian (e
, l
, XFmode
);
1215 /* Convert R to a double precision value. The output array L contains two
1216 32-bit pieces of the result, in the order they would appear in memory. */
1223 unsigned EMUSHORT e
[NE
];
1227 endian (e
, l
, DFmode
);
1230 /* Convert R to a single precision float value stored in the least-significant
1231 bits of a `long'. */
1237 unsigned EMUSHORT e
[NE
];
1242 endian (e
, &l
, SFmode
);
1246 /* Convert X to a decimal ASCII string S for output to an assembly
1247 language file. Note, there is no standard way to spell infinity or
1248 a NaN, so these values may require special treatment in the tm.h
1252 ereal_to_decimal (x
, s
)
1256 unsigned EMUSHORT e
[NE
];
1262 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1263 or -2 if either is a NaN. */
1267 REAL_VALUE_TYPE x
, y
;
1269 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1273 return (ecmp (ex
, ey
));
1276 /* Return 1 if the sign bit of X is set, else return 0. */
1282 unsigned EMUSHORT ex
[NE
];
1285 return (eisneg (ex
));
1288 /* End of REAL_ARITHMETIC interface */
1291 Extended precision IEEE binary floating point arithmetic routines
1293 Numbers are stored in C language as arrays of 16-bit unsigned
1294 short integers. The arguments of the routines are pointers to
1297 External e type data structure, similar to Intel 8087 chip
1298 temporary real format but possibly with a larger significand:
1300 NE-1 significand words (least significant word first,
1301 most significant bit is normally set)
1302 exponent (value = EXONE for 1.0,
1303 top bit is the sign)
1306 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1308 ei[0] sign word (0 for positive, 0xffff for negative)
1309 ei[1] biased exponent (value = EXONE for the number 1.0)
1310 ei[2] high guard word (always zero after normalization)
1312 to ei[NI-2] significand (NI-4 significand words,
1313 most significant word first,
1314 most significant bit is set)
1315 ei[NI-1] low guard word (0x8000 bit is rounding place)
1319 Routines for external format e-type numbers
1321 asctoe (string, e) ASCII string to extended double e type
1322 asctoe64 (string, &d) ASCII string to long double
1323 asctoe53 (string, &d) ASCII string to double
1324 asctoe24 (string, &f) ASCII string to single
1325 asctoeg (string, e, prec) ASCII string to specified precision
1326 e24toe (&f, e) IEEE single precision to e type
1327 e53toe (&d, e) IEEE double precision to e type
1328 e64toe (&d, e) IEEE long double precision to e type
1329 e113toe (&d, e) 128-bit long double precision to e type
1331 eabs (e) absolute value
1333 eadd (a, b, c) c = b + a
1335 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1336 -1 if a < b, -2 if either a or b is a NaN.
1337 ediv (a, b, c) c = b / a
1338 efloor (a, b) truncate to integer, toward -infinity
1339 efrexp (a, exp, s) extract exponent and significand
1340 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1341 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1342 einfin (e) set e to infinity, leaving its sign alone
1343 eldexp (a, n, b) multiply by 2**n
1345 emul (a, b, c) c = b * a
1348 eround (a, b) b = nearest integer value to a
1350 esub (a, b, c) c = b - a
1352 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1353 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1354 e64toasc (&d, str, n) 80-bit long double to ASCII string
1355 e113toasc (&d, str, n) 128-bit long double to ASCII string
1357 etoasc (e, str, n) e to ASCII string, n digits after decimal
1358 etoe24 (e, &f) convert e type to IEEE single precision
1359 etoe53 (e, &d) convert e type to IEEE double precision
1360 etoe64 (e, &d) convert e type to IEEE long double precision
1361 ltoe (&l, e) HOST_WIDE_INT to e type
1362 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1363 eisneg (e) 1 if sign bit of e != 0, else 0
1364 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1365 or is infinite (IEEE)
1366 eisnan (e) 1 if e is a NaN
1369 Routines for internal format exploded e-type numbers
1371 eaddm (ai, bi) add significands, bi = bi + ai
1373 ecleazs (ei) set ei = 0 but leave its sign alone
1374 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1375 edivm (ai, bi) divide significands, bi = bi / ai
1376 emdnorm (ai,l,s,exp) normalize and round off
1377 emovi (a, ai) convert external a to internal ai
1378 emovo (ai, a) convert internal ai to external a
1379 emovz (ai, bi) bi = ai, low guard word of bi = 0
1380 emulm (ai, bi) multiply significands, bi = bi * ai
1381 enormlz (ei) left-justify the significand
1382 eshdn1 (ai) shift significand and guards down 1 bit
1383 eshdn8 (ai) shift down 8 bits
1384 eshdn6 (ai) shift down 16 bits
1385 eshift (ai, n) shift ai n bits up (or down if n < 0)
1386 eshup1 (ai) shift significand and guards up 1 bit
1387 eshup8 (ai) shift up 8 bits
1388 eshup6 (ai) shift up 16 bits
1389 esubm (ai, bi) subtract significands, bi = bi - ai
1390 eiisinf (ai) 1 if infinite
1391 eiisnan (ai) 1 if a NaN
1392 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1393 einan (ai) set ai = NaN
1395 eiinfin (ai) set ai = infinity
1398 The result is always normalized and rounded to NI-4 word precision
1399 after each arithmetic operation.
1401 Exception flags are NOT fully supported.
1403 Signaling NaN's are NOT supported; they are treated the same
1406 Define INFINITY for support of infinity; otherwise a
1407 saturation arithmetic is implemented.
1409 Define NANS for support of Not-a-Number items; otherwise the
1410 arithmetic will never produce a NaN output, and might be confused
1412 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1413 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1414 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1417 Denormals are always supported here where appropriate (e.g., not
1418 for conversion to DEC numbers). */
1420 /* Definitions for error codes that are passed to the common error handling
1423 For Digital Equipment PDP-11 and VAX computers, certain
1424 IBM systems, and others that use numbers with a 56-bit
1425 significand, the symbol DEC should be defined. In this
1426 mode, most floating point constants are given as arrays
1427 of octal integers to eliminate decimal to binary conversion
1428 errors that might be introduced by the compiler.
1430 For computers, such as IBM PC, that follow the IEEE
1431 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1432 Std 754-1985), the symbol IEEE should be defined.
1433 These numbers have 53-bit significands. In this mode, constants
1434 are provided as arrays of hexadecimal 16 bit integers.
1435 The endian-ness of generated values is controlled by
1436 REAL_WORDS_BIG_ENDIAN.
1438 To accommodate other types of computer arithmetic, all
1439 constants are also provided in a normal decimal radix
1440 which one can hope are correctly converted to a suitable
1441 format by the available C language compiler. To invoke
1442 this mode, the symbol UNK is defined.
1444 An important difference among these modes is a predefined
1445 set of machine arithmetic constants for each. The numbers
1446 MACHEP (the machine roundoff error), MAXNUM (largest number
1447 represented), and several other parameters are preset by
1448 the configuration symbol. Check the file const.c to
1449 ensure that these values are correct for your computer.
1451 For ANSI C compatibility, define ANSIC equal to 1. Currently
1452 this affects only the atan2 function and others that use it. */
1454 /* Constant definitions for math error conditions. */
1456 #define DOMAIN 1 /* argument domain error */
1457 #define SING 2 /* argument singularity */
1458 #define OVERFLOW 3 /* overflow range error */
1459 #define UNDERFLOW 4 /* underflow range error */
1460 #define TLOSS 5 /* total loss of precision */
1461 #define PLOSS 6 /* partial loss of precision */
1462 #define INVALID 7 /* NaN-producing operation */
1464 /* e type constants used by high precision check routines */
1466 #if LONG_DOUBLE_TYPE_SIZE == 128
1468 unsigned EMUSHORT ezero
[NE
] =
1469 {0x0000, 0x0000, 0x0000, 0x0000,
1470 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1471 extern unsigned EMUSHORT ezero
[];
1474 unsigned EMUSHORT ehalf
[NE
] =
1475 {0x0000, 0x0000, 0x0000, 0x0000,
1476 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1477 extern unsigned EMUSHORT ehalf
[];
1480 unsigned EMUSHORT eone
[NE
] =
1481 {0x0000, 0x0000, 0x0000, 0x0000,
1482 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1483 extern unsigned EMUSHORT eone
[];
1486 unsigned EMUSHORT etwo
[NE
] =
1487 {0x0000, 0x0000, 0x0000, 0x0000,
1488 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1489 extern unsigned EMUSHORT etwo
[];
1492 unsigned EMUSHORT e32
[NE
] =
1493 {0x0000, 0x0000, 0x0000, 0x0000,
1494 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1495 extern unsigned EMUSHORT e32
[];
1497 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1498 unsigned EMUSHORT elog2
[NE
] =
1499 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1500 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1501 extern unsigned EMUSHORT elog2
[];
1503 /* 1.41421356237309504880168872420969807856967187537695E0 */
1504 unsigned EMUSHORT esqrt2
[NE
] =
1505 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1506 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1507 extern unsigned EMUSHORT esqrt2
[];
1509 /* 3.14159265358979323846264338327950288419716939937511E0 */
1510 unsigned EMUSHORT epi
[NE
] =
1511 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1512 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1513 extern unsigned EMUSHORT epi
[];
1516 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1517 unsigned EMUSHORT ezero
[NE
] =
1518 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1519 unsigned EMUSHORT ehalf
[NE
] =
1520 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1521 unsigned EMUSHORT eone
[NE
] =
1522 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1523 unsigned EMUSHORT etwo
[NE
] =
1524 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1525 unsigned EMUSHORT e32
[NE
] =
1526 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1527 unsigned EMUSHORT elog2
[NE
] =
1528 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1529 unsigned EMUSHORT esqrt2
[NE
] =
1530 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1531 unsigned EMUSHORT epi
[NE
] =
1532 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1535 /* Control register for rounding precision.
1536 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1541 /* Clear out entire e-type number X. */
1545 register unsigned EMUSHORT
*x
;
1549 for (i
= 0; i
< NE
; i
++)
1553 /* Move e-type number from A to B. */
1557 register unsigned EMUSHORT
*a
, *b
;
1561 for (i
= 0; i
< NE
; i
++)
1567 /* Absolute value of e-type X. */
1571 unsigned EMUSHORT x
[];
1573 /* sign is top bit of last word of external format */
1574 x
[NE
- 1] &= 0x7fff;
1578 /* Negate the e-type number X. */
1582 unsigned EMUSHORT x
[];
1585 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1588 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1592 unsigned EMUSHORT x
[];
1595 if (x
[NE
- 1] & 0x8000)
1601 /* Return 1 if e-type number X is infinity, else return zero. */
1605 unsigned EMUSHORT x
[];
1612 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1618 /* Check if e-type number is not a number. The bit pattern is one that we
1619 defined, so we know for sure how to detect it. */
1623 unsigned EMUSHORT x
[];
1628 /* NaN has maximum exponent */
1629 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1631 /* ... and non-zero significand field. */
1632 for (i
= 0; i
< NE
- 1; i
++)
1642 /* Fill e-type number X with infinity pattern (IEEE)
1643 or largest possible number (non-IEEE). */
1647 register unsigned EMUSHORT
*x
;
1652 for (i
= 0; i
< NE
- 1; i
++)
1656 for (i
= 0; i
< NE
- 1; i
++)
1684 /* Output an e-type NaN.
1685 This generates Intel's quiet NaN pattern for extended real.
1686 The exponent is 7fff, the leading mantissa word is c000. */
1690 register unsigned EMUSHORT
*x
;
1695 for (i
= 0; i
< NE
- 2; i
++)
1698 *x
= (sign
<< 15) | 0x7fff;
1701 /* Move in an e-type number A, converting it to exploded e-type B. */
1705 unsigned EMUSHORT
*a
, *b
;
1707 register unsigned EMUSHORT
*p
, *q
;
1711 p
= a
+ (NE
- 1); /* point to last word of external number */
1712 /* get the sign bit */
1717 /* get the exponent */
1719 *q
++ &= 0x7fff; /* delete the sign bit */
1721 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1727 for (i
= 3; i
< NI
; i
++)
1733 for (i
= 2; i
< NI
; i
++)
1739 /* clear high guard word */
1741 /* move in the significand */
1742 for (i
= 0; i
< NE
- 1; i
++)
1744 /* clear low guard word */
1748 /* Move out exploded e-type number A, converting it to e type B. */
1752 unsigned EMUSHORT
*a
, *b
;
1754 register unsigned EMUSHORT
*p
, *q
;
1755 unsigned EMUSHORT i
;
1759 q
= b
+ (NE
- 1); /* point to output exponent */
1760 /* combine sign and exponent */
1763 *q
-- = *p
++ | 0x8000;
1767 if (*(p
- 1) == 0x7fff)
1772 enan (b
, eiisneg (a
));
1780 /* skip over guard word */
1782 /* move the significand */
1783 for (j
= 0; j
< NE
- 1; j
++)
1787 /* Clear out exploded e-type number XI. */
1791 register unsigned EMUSHORT
*xi
;
1795 for (i
= 0; i
< NI
; i
++)
1799 /* Clear out exploded e-type XI, but don't touch the sign. */
1803 register unsigned EMUSHORT
*xi
;
1808 for (i
= 0; i
< NI
- 1; i
++)
1812 /* Move exploded e-type number from A to B. */
1816 register unsigned EMUSHORT
*a
, *b
;
1820 for (i
= 0; i
< NI
- 1; i
++)
1822 /* clear low guard word */
1826 /* Generate exploded e-type NaN.
1827 The explicit pattern for this is maximum exponent and
1828 top two significant bits set. */
1832 unsigned EMUSHORT x
[];
1840 /* Return nonzero if exploded e-type X is a NaN. */
1844 unsigned EMUSHORT x
[];
1848 if ((x
[E
] & 0x7fff) == 0x7fff)
1850 for (i
= M
+ 1; i
< NI
; i
++)
1859 /* Return nonzero if sign of exploded e-type X is nonzero. */
1863 unsigned EMUSHORT x
[];
1870 /* Fill exploded e-type X with infinity pattern.
1871 This has maximum exponent and significand all zeros. */
1875 unsigned EMUSHORT x
[];
1883 /* Return nonzero if exploded e-type X is infinite. */
1887 unsigned EMUSHORT x
[];
1894 if ((x
[E
] & 0x7fff) == 0x7fff)
1900 /* Compare significands of numbers in internal exploded e-type format.
1901 Guard words are included in the comparison.
1909 register unsigned EMUSHORT
*a
, *b
;
1913 a
+= M
; /* skip up to significand area */
1915 for (i
= M
; i
< NI
; i
++)
1923 if (*(--a
) > *(--b
))
1929 /* Shift significand of exploded e-type X down by 1 bit. */
1933 register unsigned EMUSHORT
*x
;
1935 register unsigned EMUSHORT bits
;
1938 x
+= M
; /* point to significand area */
1941 for (i
= M
; i
< NI
; i
++)
1953 /* Shift significand of exploded e-type X up by 1 bit. */
1957 register unsigned EMUSHORT
*x
;
1959 register unsigned EMUSHORT bits
;
1965 for (i
= M
; i
< NI
; i
++)
1978 /* Shift significand of exploded e-type X down by 8 bits. */
1982 register unsigned EMUSHORT
*x
;
1984 register unsigned EMUSHORT newbyt
, oldbyt
;
1989 for (i
= M
; i
< NI
; i
++)
1999 /* Shift significand of exploded e-type X up by 8 bits. */
2003 register unsigned EMUSHORT
*x
;
2006 register unsigned EMUSHORT newbyt
, oldbyt
;
2011 for (i
= M
; i
< NI
; i
++)
2021 /* Shift significand of exploded e-type X up by 16 bits. */
2025 register unsigned EMUSHORT
*x
;
2028 register unsigned EMUSHORT
*p
;
2033 for (i
= M
; i
< NI
- 1; i
++)
2039 /* Shift significand of exploded e-type X down by 16 bits. */
2043 register unsigned EMUSHORT
*x
;
2046 register unsigned EMUSHORT
*p
;
2051 for (i
= M
; i
< NI
- 1; i
++)
2057 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2061 unsigned EMUSHORT
*x
, *y
;
2063 register unsigned EMULONG a
;
2070 for (i
= M
; i
< NI
; i
++)
2072 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2077 *y
= (unsigned EMUSHORT
) a
;
2083 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2087 unsigned EMUSHORT
*x
, *y
;
2096 for (i
= M
; i
< NI
; i
++)
2098 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2103 *y
= (unsigned EMUSHORT
) a
;
2110 static unsigned EMUSHORT equot
[NI
];
2114 /* Radix 2 shift-and-add versions of multiply and divide */
2117 /* Divide significands */
2121 unsigned EMUSHORT den
[], num
[];
2124 register unsigned EMUSHORT
*p
, *q
;
2125 unsigned EMUSHORT j
;
2131 for (i
= M
; i
< NI
; i
++)
2136 /* Use faster compare and subtraction if denominator has only 15 bits of
2142 for (i
= M
+ 3; i
< NI
; i
++)
2147 if ((den
[M
+ 1] & 1) != 0)
2155 for (i
= 0; i
< NBITS
+ 2; i
++)
2173 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2174 bit + 1 roundoff bit. */
2179 for (i
= 0; i
< NBITS
+ 2; i
++)
2181 if (ecmpm (den
, num
) <= 0)
2184 j
= 1; /* quotient bit = 1 */
2198 /* test for nonzero remainder after roundoff bit */
2201 for (i
= M
; i
< NI
; i
++)
2209 for (i
= 0; i
< NI
; i
++)
2215 /* Multiply significands */
2219 unsigned EMUSHORT a
[], b
[];
2221 unsigned EMUSHORT
*p
, *q
;
2226 for (i
= M
; i
< NI
; i
++)
2231 while (*p
== 0) /* significand is not supposed to be zero */
2236 if ((*p
& 0xff) == 0)
2244 for (i
= 0; i
< k
; i
++)
2248 /* remember if there were any nonzero bits shifted out */
2255 for (i
= 0; i
< NI
; i
++)
2258 /* return flag for lost nonzero bits */
2264 /* Radix 65536 versions of multiply and divide. */
2266 /* Multiply significand of e-type number B
2267 by 16-bit quantity A, return e-type result to C. */
2272 unsigned EMUSHORT b
[], c
[];
2274 register unsigned EMUSHORT
*pp
;
2275 register unsigned EMULONG carry
;
2276 unsigned EMUSHORT
*ps
;
2277 unsigned EMUSHORT p
[NI
];
2278 unsigned EMULONG aa
, m
;
2287 for (i
=M
+1; i
<NI
; i
++)
2297 m
= (unsigned EMULONG
) aa
* *ps
--;
2298 carry
= (m
& 0xffff) + *pp
;
2299 *pp
-- = (unsigned EMUSHORT
)carry
;
2300 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2301 *pp
= (unsigned EMUSHORT
)carry
;
2302 *(pp
-1) = carry
>> 16;
2305 for (i
=M
; i
<NI
; i
++)
2309 /* Divide significands of exploded e-types NUM / DEN. Neither the
2310 numerator NUM nor the denominator DEN is permitted to have its high guard
2315 unsigned EMUSHORT den
[], num
[];
2318 register unsigned EMUSHORT
*p
;
2319 unsigned EMULONG tnum
;
2320 unsigned EMUSHORT j
, tdenm
, tquot
;
2321 unsigned EMUSHORT tprod
[NI
+1];
2327 for (i
=M
; i
<NI
; i
++)
2333 for (i
=M
; i
<NI
; i
++)
2335 /* Find trial quotient digit (the radix is 65536). */
2336 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2338 /* Do not execute the divide instruction if it will overflow. */
2339 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2342 tquot
= tnum
/ tdenm
;
2343 /* Multiply denominator by trial quotient digit. */
2344 m16m ((unsigned int)tquot
, den
, tprod
);
2345 /* The quotient digit may have been overestimated. */
2346 if (ecmpm (tprod
, num
) > 0)
2350 if (ecmpm (tprod
, num
) > 0)
2360 /* test for nonzero remainder after roundoff bit */
2363 for (i
=M
; i
<NI
; i
++)
2370 for (i
=0; i
<NI
; i
++)
2376 /* Multiply significands of exploded e-type A and B, result in B. */
2380 unsigned EMUSHORT a
[], b
[];
2382 unsigned EMUSHORT
*p
, *q
;
2383 unsigned EMUSHORT pprod
[NI
];
2384 unsigned EMUSHORT j
;
2389 for (i
=M
; i
<NI
; i
++)
2395 for (i
=M
+1; i
<NI
; i
++)
2403 m16m ((unsigned int) *p
--, b
, pprod
);
2404 eaddm(pprod
, equot
);
2410 for (i
=0; i
<NI
; i
++)
2413 /* return flag for lost nonzero bits */
2419 /* Normalize and round off.
2421 The internal format number to be rounded is S.
2422 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2424 Input SUBFLG indicates whether the number was obtained
2425 by a subtraction operation. In that case if LOST is nonzero
2426 then the number is slightly smaller than indicated.
2428 Input EXP is the biased exponent, which may be negative.
2429 the exponent field of S is ignored but is replaced by
2430 EXP as adjusted by normalization and rounding.
2432 Input RCNTRL is the rounding control. If it is nonzero, the
2433 returned value will be rounded to RNDPRC bits.
2435 For future reference: In order for emdnorm to round off denormal
2436 significands at the right point, the input exponent must be
2437 adjusted to be the actual value it would have after conversion to
2438 the final floating point type. This adjustment has been
2439 implemented for all type conversions (etoe53, etc.) and decimal
2440 conversions, but not for the arithmetic functions (eadd, etc.).
2441 Data types having standard 15-bit exponents are not affected by
2442 this, but SFmode and DFmode are affected. For example, ediv with
2443 rndprc = 24 will not round correctly to 24-bit precision if the
2444 result is denormal. */
2446 static int rlast
= -1;
2448 static unsigned EMUSHORT rmsk
= 0;
2449 static unsigned EMUSHORT rmbit
= 0;
2450 static unsigned EMUSHORT rebit
= 0;
2452 static unsigned EMUSHORT rbit
[NI
];
2455 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2456 unsigned EMUSHORT s
[];
2463 unsigned EMUSHORT r
;
2468 /* a blank significand could mean either zero or infinity. */
2481 if ((j
> NBITS
) && (exp
< 32767))
2489 if (exp
> (EMULONG
) (-NBITS
- 1))
2502 /* Round off, unless told not to by rcntrl. */
2505 /* Set up rounding parameters if the control register changed. */
2506 if (rndprc
!= rlast
)
2513 rw
= NI
- 1; /* low guard word */
2536 /* For DEC or IBM arithmetic */
2553 /* For C4x arithmetic */
2574 /* Shift down 1 temporarily if the data structure has an implied
2575 most significant bit and the number is denormal.
2576 Intel long double denormals also lose one bit of precision. */
2577 if ((exp
<= 0) && (rndprc
!= NBITS
)
2578 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2580 lost
|= s
[NI
- 1] & 1;
2583 /* Clear out all bits below the rounding bit,
2584 remembering in r if any were nonzero. */
2598 if ((r
& rmbit
) != 0)
2604 { /* round to even */
2605 if ((s
[re
] & rebit
) == 0)
2618 /* Undo the temporary shift for denormal values. */
2619 if ((exp
<= 0) && (rndprc
!= NBITS
)
2620 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2625 { /* overflow on roundoff */
2638 for (i
= 2; i
< NI
- 1; i
++)
2641 warning ("floating point overflow");
2645 for (i
= M
+ 1; i
< NI
- 1; i
++)
2648 if ((rndprc
< 64) || (rndprc
== 113))
2663 s
[1] = (unsigned EMUSHORT
) exp
;
2666 /* Subtract. C = B - A, all e type numbers. */
2668 static int subflg
= 0;
2672 unsigned EMUSHORT
*a
, *b
, *c
;
2686 /* Infinity minus infinity is a NaN.
2687 Test for subtracting infinities of the same sign. */
2688 if (eisinf (a
) && eisinf (b
)
2689 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2691 mtherr ("esub", INVALID
);
2700 /* Add. C = A + B, all e type. */
2704 unsigned EMUSHORT
*a
, *b
, *c
;
2708 /* NaN plus anything is a NaN. */
2719 /* Infinity minus infinity is a NaN.
2720 Test for adding infinities of opposite signs. */
2721 if (eisinf (a
) && eisinf (b
)
2722 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2724 mtherr ("esub", INVALID
);
2733 /* Arithmetic common to both addition and subtraction. */
2737 unsigned EMUSHORT
*a
, *b
, *c
;
2739 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2741 EMULONG lt
, lta
, ltb
;
2762 /* compare exponents */
2767 { /* put the larger number in bi */
2777 if (lt
< (EMULONG
) (-NBITS
- 1))
2778 goto done
; /* answer same as larger addend */
2780 lost
= eshift (ai
, k
); /* shift the smaller number down */
2784 /* exponents were the same, so must compare significands */
2787 { /* the numbers are identical in magnitude */
2788 /* if different signs, result is zero */
2794 /* if same sign, result is double */
2795 /* double denormalized tiny number */
2796 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2801 /* add 1 to exponent unless both are zero! */
2802 for (j
= 1; j
< NI
- 1; j
++)
2818 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2822 { /* put the larger number in bi */
2838 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2844 /* Divide: C = B/A, all e type. */
2848 unsigned EMUSHORT
*a
, *b
, *c
;
2850 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2852 EMULONG lt
, lta
, ltb
;
2854 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2855 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2856 sign
= eisneg(a
) ^ eisneg(b
);
2859 /* Return any NaN input. */
2870 /* Zero over zero, or infinity over infinity, is a NaN. */
2871 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2872 || (eisinf (a
) && eisinf (b
)))
2874 mtherr ("ediv", INVALID
);
2879 /* Infinity over anything else is infinity. */
2886 /* Anything else over infinity is zero. */
2898 { /* See if numerator is zero. */
2899 for (i
= 1; i
< NI
- 1; i
++)
2903 ltb
-= enormlz (bi
);
2913 { /* possible divide by zero */
2914 for (i
= 1; i
< NI
- 1; i
++)
2918 lta
-= enormlz (ai
);
2922 /* Divide by zero is not an invalid operation.
2923 It is a divide-by-zero operation! */
2925 mtherr ("ediv", SING
);
2931 /* calculate exponent */
2932 lt
= ltb
- lta
+ EXONE
;
2933 emdnorm (bi
, i
, 0, lt
, 64);
2940 && (ecmp (c
, ezero
) != 0)
2943 *(c
+(NE
-1)) |= 0x8000;
2945 *(c
+(NE
-1)) &= ~0x8000;
2948 /* Multiply e-types A and B, return e-type product C. */
2952 unsigned EMUSHORT
*a
, *b
, *c
;
2954 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2956 EMULONG lt
, lta
, ltb
;
2958 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2959 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2960 sign
= eisneg(a
) ^ eisneg(b
);
2963 /* NaN times anything is the same NaN. */
2974 /* Zero times infinity is a NaN. */
2975 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2976 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2978 mtherr ("emul", INVALID
);
2983 /* Infinity times anything else is infinity. */
2985 if (eisinf (a
) || eisinf (b
))
2997 for (i
= 1; i
< NI
- 1; i
++)
3001 lta
-= enormlz (ai
);
3012 for (i
= 1; i
< NI
- 1; i
++)
3016 ltb
-= enormlz (bi
);
3025 /* Multiply significands */
3027 /* calculate exponent */
3028 lt
= lta
+ ltb
- (EXONE
- 1);
3029 emdnorm (bi
, j
, 0, lt
, 64);
3036 && (ecmp (c
, ezero
) != 0)
3039 *(c
+(NE
-1)) |= 0x8000;
3041 *(c
+(NE
-1)) &= ~0x8000;
3044 /* Convert double precision PE to e-type Y. */
3048 unsigned EMUSHORT
*pe
, *y
;
3057 ibmtoe (pe
, y
, DFmode
);
3062 c4xtoe (pe
, y
, HFmode
);
3065 register unsigned EMUSHORT r
;
3066 register unsigned EMUSHORT
*e
, *p
;
3067 unsigned EMUSHORT yy
[NI
];
3071 denorm
= 0; /* flag if denormalized number */
3073 if (! REAL_WORDS_BIG_ENDIAN
)
3079 yy
[M
] = (r
& 0x0f) | 0x10;
3080 r
&= ~0x800f; /* strip sign and 4 significand bits */
3085 if (! REAL_WORDS_BIG_ENDIAN
)
3087 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3088 || (pe
[1] != 0) || (pe
[0] != 0))
3090 enan (y
, yy
[0] != 0);
3096 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3097 || (pe
[2] != 0) || (pe
[3] != 0))
3099 enan (y
, yy
[0] != 0);
3110 #endif /* INFINITY */
3112 /* If zero exponent, then the significand is denormalized.
3113 So take back the understood high significand bit. */
3124 if (! REAL_WORDS_BIG_ENDIAN
)
3141 /* If zero exponent, then normalize the significand. */
3142 if ((k
= enormlz (yy
)) > NBITS
)
3145 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3148 #endif /* not C4X */
3149 #endif /* not IBM */
3150 #endif /* not DEC */
3153 /* Convert double extended precision float PE to e type Y. */
3157 unsigned EMUSHORT
*pe
, *y
;
3159 unsigned EMUSHORT yy
[NI
];
3160 unsigned EMUSHORT
*e
, *p
, *q
;
3165 for (i
= 0; i
< NE
- 5; i
++)
3167 /* This precision is not ordinarily supported on DEC or IBM. */
3169 for (i
= 0; i
< 5; i
++)
3173 p
= &yy
[0] + (NE
- 1);
3176 for (i
= 0; i
< 5; i
++)
3180 if (! REAL_WORDS_BIG_ENDIAN
)
3182 for (i
= 0; i
< 5; i
++)
3185 /* For denormal long double Intel format, shift significand up one
3186 -- but only if the top significand bit is zero. A top bit of 1
3187 is "pseudodenormal" when the exponent is zero. */
3188 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3190 unsigned EMUSHORT temp
[NI
];
3200 p
= &yy
[0] + (NE
- 1);
3201 #ifdef ARM_EXTENDED_IEEE_FORMAT
3202 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3203 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3209 for (i
= 0; i
< 4; i
++)
3214 /* Point to the exponent field and check max exponent cases. */
3216 if ((*p
& 0x7fff) == 0x7fff)
3219 if (! REAL_WORDS_BIG_ENDIAN
)
3221 for (i
= 0; i
< 4; i
++)
3223 if ((i
!= 3 && pe
[i
] != 0)
3224 /* Anything but 0x8000 here, including 0, is a NaN. */
3225 || (i
== 3 && pe
[i
] != 0x8000))
3227 enan (y
, (*p
& 0x8000) != 0);
3234 #ifdef ARM_EXTENDED_IEEE_FORMAT
3235 for (i
= 2; i
<= 5; i
++)
3239 enan (y
, (*p
& 0x8000) != 0);
3244 /* In Motorola extended precision format, the most significant
3245 bit of an infinity mantissa could be either 1 or 0. It is
3246 the lower order bits that tell whether the value is a NaN. */
3247 if ((pe
[2] & 0x7fff) != 0)
3250 for (i
= 3; i
<= 5; i
++)
3255 enan (y
, (*p
& 0x8000) != 0);
3259 #endif /* not ARM */
3268 #endif /* INFINITY */
3271 for (i
= 0; i
< NE
; i
++)
3275 /* Convert 128-bit long double precision float PE to e type Y. */
3279 unsigned EMUSHORT
*pe
, *y
;
3281 register unsigned EMUSHORT r
;
3282 unsigned EMUSHORT
*e
, *p
;
3283 unsigned EMUSHORT yy
[NI
];
3290 if (! REAL_WORDS_BIG_ENDIAN
)
3302 if (! REAL_WORDS_BIG_ENDIAN
)
3304 for (i
= 0; i
< 7; i
++)
3308 enan (y
, yy
[0] != 0);
3315 for (i
= 1; i
< 8; i
++)
3319 enan (y
, yy
[0] != 0);
3331 #endif /* INFINITY */
3335 if (! REAL_WORDS_BIG_ENDIAN
)
3337 for (i
= 0; i
< 7; i
++)
3343 for (i
= 0; i
< 7; i
++)
3347 /* If denormal, remove the implied bit; else shift down 1. */
3360 /* Convert single precision float PE to e type Y. */
3364 unsigned EMUSHORT
*pe
, *y
;
3368 ibmtoe (pe
, y
, SFmode
);
3374 c4xtoe (pe
, y
, QFmode
);
3378 register unsigned EMUSHORT r
;
3379 register unsigned EMUSHORT
*e
, *p
;
3380 unsigned EMUSHORT yy
[NI
];
3384 denorm
= 0; /* flag if denormalized number */
3387 if (! REAL_WORDS_BIG_ENDIAN
)
3397 yy
[M
] = (r
& 0x7f) | 0200;
3398 r
&= ~0x807f; /* strip sign and 7 significand bits */
3403 if (REAL_WORDS_BIG_ENDIAN
)
3405 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3407 enan (y
, yy
[0] != 0);
3413 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3415 enan (y
, yy
[0] != 0);
3426 #endif /* INFINITY */
3428 /* If zero exponent, then the significand is denormalized.
3429 So take back the understood high significand bit. */
3442 if (! REAL_WORDS_BIG_ENDIAN
)
3452 { /* if zero exponent, then normalize the significand */
3453 if ((k
= enormlz (yy
)) > NBITS
)
3456 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3459 #endif /* not C4X */
3460 #endif /* not IBM */
3463 /* Convert e-type X to IEEE 128-bit long double format E. */
3467 unsigned EMUSHORT
*x
, *e
;
3469 unsigned EMUSHORT xi
[NI
];
3476 make_nan (e
, eisneg (x
), TFmode
);
3481 exp
= (EMULONG
) xi
[E
];
3486 /* round off to nearest or even */
3489 emdnorm (xi
, 0, 0, exp
, 64);
3495 /* Convert exploded e-type X, that has already been rounded to
3496 113-bit precision, to IEEE 128-bit long double format Y. */
3500 unsigned EMUSHORT
*a
, *b
;
3502 register unsigned EMUSHORT
*p
, *q
;
3503 unsigned EMUSHORT i
;
3508 make_nan (b
, eiisneg (a
), TFmode
);
3513 if (REAL_WORDS_BIG_ENDIAN
)
3516 q
= b
+ 7; /* point to output exponent */
3518 /* If not denormal, delete the implied bit. */
3523 /* combine sign and exponent */
3525 if (REAL_WORDS_BIG_ENDIAN
)
3528 *q
++ = *p
++ | 0x8000;
3535 *q
-- = *p
++ | 0x8000;
3539 /* skip over guard word */
3541 /* move the significand */
3542 if (REAL_WORDS_BIG_ENDIAN
)
3544 for (i
= 0; i
< 7; i
++)
3549 for (i
= 0; i
< 7; i
++)
3554 /* Convert e-type X to IEEE double extended format E. */
3558 unsigned EMUSHORT
*x
, *e
;
3560 unsigned EMUSHORT xi
[NI
];
3567 make_nan (e
, eisneg (x
), XFmode
);
3572 /* adjust exponent for offset */
3573 exp
= (EMULONG
) xi
[E
];
3578 /* round off to nearest or even */
3581 emdnorm (xi
, 0, 0, exp
, 64);
3587 /* Convert exploded e-type X, that has already been rounded to
3588 64-bit precision, to IEEE double extended format Y. */
3592 unsigned EMUSHORT
*a
, *b
;
3594 register unsigned EMUSHORT
*p
, *q
;
3595 unsigned EMUSHORT i
;
3600 make_nan (b
, eiisneg (a
), XFmode
);
3604 /* Shift denormal long double Intel format significand down one bit. */
3605 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3615 if (REAL_WORDS_BIG_ENDIAN
)
3619 q
= b
+ 4; /* point to output exponent */
3620 #if LONG_DOUBLE_TYPE_SIZE == 96
3621 /* Clear the last two bytes of 12-byte Intel format */
3627 /* combine sign and exponent */
3631 *q
++ = *p
++ | 0x8000;
3638 *q
-- = *p
++ | 0x8000;
3643 if (REAL_WORDS_BIG_ENDIAN
)
3645 #ifdef ARM_EXTENDED_IEEE_FORMAT
3646 /* The exponent is in the lowest 15 bits of the first word. */
3647 *q
++ = i
? 0x8000 : 0;
3651 *q
++ = *p
++ | 0x8000;
3660 *q
-- = *p
++ | 0x8000;
3665 /* skip over guard word */
3667 /* move the significand */
3669 for (i
= 0; i
< 4; i
++)
3673 for (i
= 0; i
< 4; i
++)
3677 if (REAL_WORDS_BIG_ENDIAN
)
3679 for (i
= 0; i
< 4; i
++)
3687 /* Intel long double infinity significand. */
3695 for (i
= 0; i
< 4; i
++)
3701 /* e type to double precision. */
3704 /* Convert e-type X to DEC-format double E. */
3708 unsigned EMUSHORT
*x
, *e
;
3710 etodec (x
, e
); /* see etodec.c */
3713 /* Convert exploded e-type X, that has already been rounded to
3714 56-bit double precision, to DEC double Y. */
3718 unsigned EMUSHORT
*x
, *y
;
3725 /* Convert e-type X to IBM 370-format double E. */
3729 unsigned EMUSHORT
*x
, *e
;
3731 etoibm (x
, e
, DFmode
);
3734 /* Convert exploded e-type X, that has already been rounded to
3735 56-bit precision, to IBM 370 double Y. */
3739 unsigned EMUSHORT
*x
, *y
;
3741 toibm (x
, y
, DFmode
);
3744 #else /* it's neither DEC nor IBM */
3746 /* Convert e-type X to C4X-format long double E. */
3750 unsigned EMUSHORT
*x
, *e
;
3752 etoc4x (x
, e
, HFmode
);
3755 /* Convert exploded e-type X, that has already been rounded to
3756 56-bit precision, to IBM 370 double Y. */
3760 unsigned EMUSHORT
*x
, *y
;
3762 toc4x (x
, y
, HFmode
);
3765 #else /* it's neither DEC nor IBM nor C4X */
3767 /* Convert e-type X to IEEE double E. */
3771 unsigned EMUSHORT
*x
, *e
;
3773 unsigned EMUSHORT xi
[NI
];
3780 make_nan (e
, eisneg (x
), DFmode
);
3785 /* adjust exponent for offsets */
3786 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3791 /* round off to nearest or even */
3794 emdnorm (xi
, 0, 0, exp
, 64);
3800 /* Convert exploded e-type X, that has already been rounded to
3801 53-bit precision, to IEEE double Y. */
3805 unsigned EMUSHORT
*x
, *y
;
3807 unsigned EMUSHORT i
;
3808 unsigned EMUSHORT
*p
;
3813 make_nan (y
, eiisneg (x
), DFmode
);
3819 if (! REAL_WORDS_BIG_ENDIAN
)
3822 *y
= 0; /* output high order */
3824 *y
= 0x8000; /* output sign bit */
3827 if (i
>= (unsigned int) 2047)
3829 /* Saturate at largest number less than infinity. */
3832 if (! REAL_WORDS_BIG_ENDIAN
)
3846 *y
|= (unsigned EMUSHORT
) 0x7fef;
3847 if (! REAL_WORDS_BIG_ENDIAN
)
3872 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3873 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3874 if (! REAL_WORDS_BIG_ENDIAN
)
3889 #endif /* not C4X */
3890 #endif /* not IBM */
3891 #endif /* not DEC */
3895 /* e type to single precision. */
3898 /* Convert e-type X to IBM 370 float E. */
3902 unsigned EMUSHORT
*x
, *e
;
3904 etoibm (x
, e
, SFmode
);
3907 /* Convert exploded e-type X, that has already been rounded to
3908 float precision, to IBM 370 float Y. */
3912 unsigned EMUSHORT
*x
, *y
;
3914 toibm (x
, y
, SFmode
);
3920 /* Convert e-type X to C4X float E. */
3924 unsigned EMUSHORT
*x
, *e
;
3926 etoc4x (x
, e
, QFmode
);
3929 /* Convert exploded e-type X, that has already been rounded to
3930 float precision, to IBM 370 float Y. */
3934 unsigned EMUSHORT
*x
, *y
;
3936 toc4x (x
, y
, QFmode
);
3941 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3945 unsigned EMUSHORT
*x
, *e
;
3948 unsigned EMUSHORT xi
[NI
];
3954 make_nan (e
, eisneg (x
), SFmode
);
3959 /* adjust exponent for offsets */
3960 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3965 /* round off to nearest or even */
3968 emdnorm (xi
, 0, 0, exp
, 64);
3974 /* Convert exploded e-type X, that has already been rounded to
3975 float precision, to IEEE float Y. */
3979 unsigned EMUSHORT
*x
, *y
;
3981 unsigned EMUSHORT i
;
3982 unsigned EMUSHORT
*p
;
3987 make_nan (y
, eiisneg (x
), SFmode
);
3993 if (! REAL_WORDS_BIG_ENDIAN
)
3999 *y
= 0; /* output high order */
4001 *y
= 0x8000; /* output sign bit */
4004 /* Handle overflow cases. */
4008 *y
|= (unsigned EMUSHORT
) 0x7f80;
4013 if (! REAL_WORDS_BIG_ENDIAN
)
4021 #else /* no INFINITY */
4022 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4027 if (! REAL_WORDS_BIG_ENDIAN
)
4038 #endif /* no INFINITY */
4050 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4051 /* High order output already has sign bit set. */
4057 if (! REAL_WORDS_BIG_ENDIAN
)
4066 #endif /* not C4X */
4067 #endif /* not IBM */
4069 /* Compare two e type numbers.
4073 -2 if either a or b is a NaN. */
4077 unsigned EMUSHORT
*a
, *b
;
4079 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4080 register unsigned EMUSHORT
*p
, *q
;
4085 if (eisnan (a
) || eisnan (b
))
4094 { /* the signs are different */
4096 for (i
= 1; i
< NI
- 1; i
++)
4110 /* both are the same sign */
4125 return (0); /* equality */
4129 if (*(--p
) > *(--q
))
4130 return (msign
); /* p is bigger */
4132 return (-msign
); /* p is littler */
4136 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4140 unsigned EMUSHORT
*x
, *y
;
4147 /* Convert HOST_WIDE_INT LP to e type Y. */
4152 unsigned EMUSHORT
*y
;
4154 unsigned EMUSHORT yi
[NI
];
4155 unsigned HOST_WIDE_INT ll
;
4161 /* make it positive */
4162 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4163 yi
[0] = 0xffff; /* put correct sign in the e type number */
4167 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4169 /* move the long integer to yi significand area */
4170 #if HOST_BITS_PER_WIDE_INT == 64
4171 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4172 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4173 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4174 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4175 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4177 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4178 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4179 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4182 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4183 ecleaz (yi
); /* it was zero */
4185 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4186 emovo (yi
, y
); /* output the answer */
4189 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4193 unsigned HOST_WIDE_INT
*lp
;
4194 unsigned EMUSHORT
*y
;
4196 unsigned EMUSHORT yi
[NI
];
4197 unsigned HOST_WIDE_INT ll
;
4203 /* move the long integer to ayi significand area */
4204 #if HOST_BITS_PER_WIDE_INT == 64
4205 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4206 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4207 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4208 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4209 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4211 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4212 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4213 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4216 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4217 ecleaz (yi
); /* it was zero */
4219 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4220 emovo (yi
, y
); /* output the answer */
4224 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4225 part FRAC of e-type (packed internal format) floating point input X.
4226 The integer output I has the sign of the input, except that
4227 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4228 The output e-type fraction FRAC is the positive fractional
4233 unsigned EMUSHORT
*x
;
4235 unsigned EMUSHORT
*frac
;
4237 unsigned EMUSHORT xi
[NI
];
4239 unsigned HOST_WIDE_INT ll
;
4242 k
= (int) xi
[E
] - (EXONE
- 1);
4245 /* if exponent <= 0, integer = 0 and real output is fraction */
4250 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4252 /* long integer overflow: output large integer
4253 and correct fraction */
4255 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4258 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4259 /* In this case, let it overflow and convert as if unsigned. */
4260 euifrac (x
, &ll
, frac
);
4261 *i
= (HOST_WIDE_INT
) ll
;
4264 /* In other cases, return the largest positive integer. */
4265 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4270 warning ("overflow on truncation to integer");
4274 /* Shift more than 16 bits: first shift up k-16 mod 16,
4275 then shift up by 16's. */
4276 j
= k
- ((k
>> 4) << 4);
4283 ll
= (ll
<< 16) | xi
[M
];
4285 while ((k
-= 16) > 0);
4292 /* shift not more than 16 bits */
4294 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4301 if ((k
= enormlz (xi
)) > NBITS
)
4304 xi
[E
] -= (unsigned EMUSHORT
) k
;
4310 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4311 FRAC of e-type X. A negative input yields integer output = 0 but
4312 correct fraction. */
4315 euifrac (x
, i
, frac
)
4316 unsigned EMUSHORT
*x
;
4317 unsigned HOST_WIDE_INT
*i
;
4318 unsigned EMUSHORT
*frac
;
4320 unsigned HOST_WIDE_INT ll
;
4321 unsigned EMUSHORT xi
[NI
];
4325 k
= (int) xi
[E
] - (EXONE
- 1);
4328 /* if exponent <= 0, integer = 0 and argument is fraction */
4333 if (k
> HOST_BITS_PER_WIDE_INT
)
4335 /* Long integer overflow: output large integer
4336 and correct fraction.
4337 Note, the BSD microvax compiler says that ~(0UL)
4338 is a syntax error. */
4342 warning ("overflow on truncation to unsigned integer");
4346 /* Shift more than 16 bits: first shift up k-16 mod 16,
4347 then shift up by 16's. */
4348 j
= k
- ((k
>> 4) << 4);
4355 ll
= (ll
<< 16) | xi
[M
];
4357 while ((k
-= 16) > 0);
4362 /* shift not more than 16 bits */
4364 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4367 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4373 if ((k
= enormlz (xi
)) > NBITS
)
4376 xi
[E
] -= (unsigned EMUSHORT
) k
;
4381 /* Shift the significand of exploded e-type X up or down by SC bits. */
4385 unsigned EMUSHORT
*x
;
4388 unsigned EMUSHORT lost
;
4389 unsigned EMUSHORT
*p
;
4402 lost
|= *p
; /* remember lost bits */
4443 return ((int) lost
);
4446 /* Shift normalize the significand area of exploded e-type X.
4447 Return the shift count (up = positive). */
4451 unsigned EMUSHORT x
[];
4453 register unsigned EMUSHORT
*p
;
4462 return (0); /* already normalized */
4468 /* With guard word, there are NBITS+16 bits available.
4469 Return true if all are zero. */
4473 /* see if high byte is zero */
4474 while ((*p
& 0xff00) == 0)
4479 /* now shift 1 bit at a time */
4480 while ((*p
& 0x8000) == 0)
4486 mtherr ("enormlz", UNDERFLOW
);
4492 /* Normalize by shifting down out of the high guard word
4493 of the significand */
4508 mtherr ("enormlz", OVERFLOW
);
4515 /* Powers of ten used in decimal <-> binary conversions. */
4520 #if LONG_DOUBLE_TYPE_SIZE == 128
4521 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4523 {0x6576, 0x4a92, 0x804a, 0x153f,
4524 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4525 {0x6a32, 0xce52, 0x329a, 0x28ce,
4526 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4527 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4528 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4529 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4530 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4531 {0x851e, 0xeab7, 0x98fe, 0x901b,
4532 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4533 {0x0235, 0x0137, 0x36b1, 0x336c,
4534 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4535 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4536 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4537 {0x0000, 0x0000, 0x0000, 0x0000,
4538 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4539 {0x0000, 0x0000, 0x0000, 0x0000,
4540 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4541 {0x0000, 0x0000, 0x0000, 0x0000,
4542 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4543 {0x0000, 0x0000, 0x0000, 0x0000,
4544 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4545 {0x0000, 0x0000, 0x0000, 0x0000,
4546 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4547 {0x0000, 0x0000, 0x0000, 0x0000,
4548 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4551 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4553 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4554 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4555 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4556 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4557 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4558 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4559 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4560 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4561 {0xa23e, 0x5308, 0xfefb, 0x1155,
4562 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4563 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4564 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4565 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4566 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4567 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4568 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4569 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4570 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4571 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4572 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4573 {0xc155, 0xa4a8, 0x404e, 0x6113,
4574 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4575 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4576 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4577 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4578 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4581 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4582 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4584 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4585 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4586 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4587 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4588 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4589 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4590 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4591 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4592 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4593 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4594 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4595 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4596 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4599 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4601 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4602 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4603 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4604 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4605 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4606 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4607 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4608 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4609 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4610 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4611 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4612 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4613 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4618 /* Convert float value X to ASCII string STRING with NDIG digits after
4619 the decimal point. */
4622 e24toasc (x
, string
, ndigs
)
4623 unsigned EMUSHORT x
[];
4627 unsigned EMUSHORT w
[NI
];
4630 etoasc (w
, string
, ndigs
);
4633 /* Convert double value X to ASCII string STRING with NDIG digits after
4634 the decimal point. */
4637 e53toasc (x
, string
, ndigs
)
4638 unsigned EMUSHORT x
[];
4642 unsigned EMUSHORT w
[NI
];
4645 etoasc (w
, string
, ndigs
);
4648 /* Convert double extended value X to ASCII string STRING with NDIG digits
4649 after the decimal point. */
4652 e64toasc (x
, string
, ndigs
)
4653 unsigned EMUSHORT x
[];
4657 unsigned EMUSHORT w
[NI
];
4660 etoasc (w
, string
, ndigs
);
4663 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4664 after the decimal point. */
4667 e113toasc (x
, string
, ndigs
)
4668 unsigned EMUSHORT x
[];
4672 unsigned EMUSHORT w
[NI
];
4675 etoasc (w
, string
, ndigs
);
4679 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4680 the decimal point. */
4682 static char wstring
[80]; /* working storage for ASCII output */
4685 etoasc (x
, string
, ndigs
)
4686 unsigned EMUSHORT x
[];
4691 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4692 unsigned EMUSHORT
*p
, *r
, *ten
;
4693 unsigned EMUSHORT sign
;
4694 int i
, j
, k
, expon
, rndsav
;
4696 unsigned EMUSHORT m
;
4707 sprintf (wstring
, " NaN ");
4711 rndprc
= NBITS
; /* set to full precision */
4712 emov (x
, y
); /* retain external format */
4713 if (y
[NE
- 1] & 0x8000)
4716 y
[NE
- 1] &= 0x7fff;
4723 ten
= &etens
[NTEN
][0];
4725 /* Test for zero exponent */
4728 for (k
= 0; k
< NE
- 1; k
++)
4731 goto tnzro
; /* denormalized number */
4733 goto isone
; /* valid all zeros */
4737 /* Test for infinity. */
4738 if (y
[NE
- 1] == 0x7fff)
4741 sprintf (wstring
, " -Infinity ");
4743 sprintf (wstring
, " Infinity ");
4747 /* Test for exponent nonzero but significand denormalized.
4748 * This is an error condition.
4750 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4752 mtherr ("etoasc", DOMAIN
);
4753 sprintf (wstring
, "NaN");
4757 /* Compare to 1.0 */
4766 { /* Number is greater than 1 */
4767 /* Convert significand to an integer and strip trailing decimal zeros. */
4769 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4771 p
= &etens
[NTEN
- 4][0];
4777 for (j
= 0; j
< NE
- 1; j
++)
4790 /* Rescale from integer significand */
4791 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4793 /* Find power of 10 */
4797 /* An unordered compare result shouldn't happen here. */
4798 while (ecmp (ten
, u
) <= 0)
4800 if (ecmp (p
, u
) <= 0)
4813 { /* Number is less than 1.0 */
4814 /* Pad significand with trailing decimal zeros. */
4817 while ((y
[NE
- 2] & 0x8000) == 0)
4826 for (i
= 0; i
< NDEC
+ 1; i
++)
4828 if ((w
[NI
- 1] & 0x7) != 0)
4830 /* multiply by 10 */
4843 if (eone
[NE
- 1] <= u
[1])
4855 while (ecmp (eone
, w
) > 0)
4857 if (ecmp (p
, w
) >= 0)
4872 /* Find the first (leading) digit. */
4878 digit
= equot
[NI
- 1];
4879 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4887 digit
= equot
[NI
- 1];
4895 /* Examine number of digits requested by caller. */
4913 *s
++ = (char)digit
+ '0';
4916 /* Generate digits after the decimal point. */
4917 for (k
= 0; k
<= ndigs
; k
++)
4919 /* multiply current number by 10, without normalizing */
4926 *s
++ = (char) equot
[NI
- 1] + '0';
4928 digit
= equot
[NI
- 1];
4931 /* round off the ASCII string */
4934 /* Test for critical rounding case in ASCII output. */
4938 if (ecmp (t
, ezero
) != 0)
4939 goto roun
; /* round to nearest */
4941 if ((*(s
- 1) & 1) == 0)
4942 goto doexp
; /* round to even */
4945 /* Round up and propagate carry-outs */
4949 /* Carry out to most significant digit? */
4956 /* Most significant digit carries to 10? */
4964 /* Round up and carry out from less significant digits */
4976 sprintf (ss, "e+%d", expon);
4978 sprintf (ss, "e%d", expon);
4980 sprintf (ss
, "e%d", expon
);
4983 /* copy out the working string */
4986 while (*ss
== ' ') /* strip possible leading space */
4988 while ((*s
++ = *ss
++) != '\0')
4993 /* Convert ASCII string to floating point.
4995 Numeric input is a free format decimal number of any length, with
4996 or without decimal point. Entering E after the number followed by an
4997 integer number causes the second number to be interpreted as a power of
4998 10 to be multiplied by the first number (i.e., "scientific" notation). */
5000 /* Convert ASCII string S to single precision float value Y. */
5005 unsigned EMUSHORT
*y
;
5011 /* Convert ASCII string S to double precision value Y. */
5016 unsigned EMUSHORT
*y
;
5018 #if defined(DEC) || defined(IBM)
5030 /* Convert ASCII string S to double extended value Y. */
5035 unsigned EMUSHORT
*y
;
5040 /* Convert ASCII string S to 128-bit long double Y. */
5045 unsigned EMUSHORT
*y
;
5047 asctoeg (s
, y
, 113);
5050 /* Convert ASCII string S to e type Y. */
5055 unsigned EMUSHORT
*y
;
5057 asctoeg (s
, y
, NBITS
);
5060 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5064 asctoeg (ss
, y
, oprec
)
5066 unsigned EMUSHORT
*y
;
5069 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5070 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5071 int k
, trail
, c
, rndsav
;
5073 unsigned EMUSHORT nsign
, *p
;
5074 char *sp
, *s
, *lstr
;
5076 /* Copy the input string. */
5077 lstr
= (char *) alloca (strlen (ss
) + 1);
5079 while (*s
== ' ') /* skip leading spaces */
5082 while ((*sp
++ = *s
++) != '\0')
5087 rndprc
= NBITS
; /* Set to full precision */
5100 if ((k
>= 0) && (k
<= 9))
5102 /* Ignore leading zeros */
5103 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5105 /* Identify and strip trailing zeros after the decimal point. */
5106 if ((trail
== 0) && (decflg
!= 0))
5109 while ((*sp
>= '0') && (*sp
<= '9'))
5111 /* Check for syntax error */
5113 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
5114 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5125 /* If enough digits were given to more than fill up the yy register,
5126 continuing until overflow into the high guard word yy[2]
5127 guarantees that there will be a roundoff bit at the top
5128 of the low guard word after normalization. */
5133 nexp
+= 1; /* count digits after decimal point */
5134 eshup1 (yy
); /* multiply current number by 10 */
5140 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5145 /* Mark any lost non-zero digit. */
5147 /* Count lost digits before the decimal point. */
5162 case '.': /* decimal point */
5192 mtherr ("asctoe", DOMAIN
);
5201 /* Exponent interpretation */
5203 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5204 for (k
= 0; k
< NI
; k
++)
5215 /* check for + or - */
5223 while ((*s
>= '0') && (*s
<= '9'))
5227 if (exp
> -(MINDECEXP
))
5237 if (exp
> MAXDECEXP
)
5241 yy
[E
] = 0x7fff; /* infinity */
5244 if (exp
< MINDECEXP
)
5253 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5254 while ((nexp
> 0) && (yy
[2] == 0))
5266 if ((k
= enormlz (yy
)) > NBITS
)
5271 lexp
= (EXONE
- 1 + NBITS
) - k
;
5272 emdnorm (yy
, lost
, 0, lexp
, 64);
5274 /* Convert to external format:
5276 Multiply by 10**nexp. If precision is 64 bits,
5277 the maximum relative error incurred in forming 10**n
5278 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5279 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5280 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5295 /* Punt. Can't handle this without 2 divides. */
5296 emovi (etens
[0], tt
);
5303 p
= &etens
[NTEN
][0];
5313 while (exp
<= MAXP
);
5331 /* Round and convert directly to the destination type */
5333 lexp
-= EXONE
- 0x3ff;
5335 else if (oprec
== 24 || oprec
== 32)
5336 lexp
-= (EXONE
- 0x7f);
5339 else if (oprec
== 24 || oprec
== 56)
5340 lexp
-= EXONE
- (0x41 << 2);
5342 else if (oprec
== 24)
5343 lexp
-= EXONE
- 0177;
5347 else if (oprec
== 56)
5348 lexp
-= EXONE
- 0201;
5351 emdnorm (yy
, k
, 0, lexp
, 64);
5361 todec (yy
, y
); /* see etodec.c */
5366 toibm (yy
, y
, DFmode
);
5371 toc4x (yy
, y
, HFmode
);
5395 /* Return Y = largest integer not greater than X (truncated toward minus
5398 static unsigned EMUSHORT bmask
[] =
5421 unsigned EMUSHORT x
[], y
[];
5423 register unsigned EMUSHORT
*p
;
5425 unsigned EMUSHORT f
[NE
];
5427 emov (x
, f
); /* leave in external format */
5428 expon
= (int) f
[NE
- 1];
5429 e
= (expon
& 0x7fff) - (EXONE
- 1);
5435 /* number of bits to clear out */
5447 /* clear the remaining bits */
5449 /* truncate negatives toward minus infinity */
5452 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5454 for (i
= 0; i
< NE
- 1; i
++)
5467 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5468 For example, 1.1 = 0.55 * 2^1. */
5472 unsigned EMUSHORT x
[];
5474 unsigned EMUSHORT s
[];
5476 unsigned EMUSHORT xi
[NI
];
5480 /* Handle denormalized numbers properly using long integer exponent. */
5481 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5489 *exp
= (int) (li
- 0x3ffe);
5493 /* Return e type Y = X * 2^PWR2. */
5497 unsigned EMUSHORT x
[];
5499 unsigned EMUSHORT y
[];
5501 unsigned EMUSHORT xi
[NI
];
5509 emdnorm (xi
, i
, i
, li
, 64);
5515 /* C = remainder after dividing B by A, all e type values.
5516 Least significant integer quotient bits left in EQUOT. */
5520 unsigned EMUSHORT a
[], b
[], c
[];
5522 unsigned EMUSHORT den
[NI
], num
[NI
];
5526 || (ecmp (a
, ezero
) == 0)
5534 if (ecmp (a
, ezero
) == 0)
5536 mtherr ("eremain", SING
);
5542 eiremain (den
, num
);
5543 /* Sign of remainder = sign of quotient */
5552 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5553 remainder in NUM. */
5557 unsigned EMUSHORT den
[], num
[];
5560 unsigned EMUSHORT j
;
5563 ld
-= enormlz (den
);
5565 ln
-= enormlz (num
);
5569 if (ecmpm (den
, num
) <= 0)
5581 emdnorm (num
, 0, 0, ln
, 0);
5584 /* Report an error condition CODE encountered in function NAME.
5585 CODE is one of the following:
5587 Mnemonic Value Significance
5589 DOMAIN 1 argument domain error
5590 SING 2 function singularity
5591 OVERFLOW 3 overflow range error
5592 UNDERFLOW 4 underflow range error
5593 TLOSS 5 total loss of precision
5594 PLOSS 6 partial loss of precision
5595 INVALID 7 NaN - producing operation
5596 EDOM 33 Unix domain error code
5597 ERANGE 34 Unix range error code
5599 The order of appearance of the following messages is bound to the
5600 error codes defined above. */
5603 static char *ermsg
[NMSGS
] =
5605 "unknown", /* error code 0 */
5606 "domain", /* error code 1 */
5607 "singularity", /* et seq. */
5610 "total loss of precision",
5611 "partial loss of precision",
5625 /* The string passed by the calling program is supposed to be the
5626 name of the function in which the error occurred.
5627 The code argument selects which error message string will be printed. */
5629 if ((code
<= 0) || (code
>= NMSGS
))
5631 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5634 /* Set global error message word */
5639 /* Convert DEC double precision D to e type E. */
5643 unsigned EMUSHORT
*d
;
5644 unsigned EMUSHORT
*e
;
5646 unsigned EMUSHORT y
[NI
];
5647 register unsigned EMUSHORT r
, *p
;
5649 ecleaz (y
); /* start with a zero */
5650 p
= y
; /* point to our number */
5651 r
= *d
; /* get DEC exponent word */
5652 if (*d
& (unsigned int) 0x8000)
5653 *p
= 0xffff; /* fill in our sign */
5654 ++p
; /* bump pointer to our exponent word */
5655 r
&= 0x7fff; /* strip the sign bit */
5656 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5660 r
>>= 7; /* shift exponent word down 7 bits */
5661 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5662 /* add our e type exponent offset */
5663 *p
++ = r
; /* to form our exponent */
5665 r
= *d
++; /* now do the high order mantissa */
5666 r
&= 0177; /* strip off the DEC exponent and sign bits */
5667 r
|= 0200; /* the DEC understood high order mantissa bit */
5668 *p
++ = r
; /* put result in our high guard word */
5670 *p
++ = *d
++; /* fill in the rest of our mantissa */
5674 eshdn8 (y
); /* shift our mantissa down 8 bits */
5679 /* Convert e type X to DEC double precision D. */
5683 unsigned EMUSHORT
*x
, *d
;
5685 unsigned EMUSHORT xi
[NI
];
5690 /* Adjust exponent for offsets. */
5691 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5692 /* Round off to nearest or even. */
5695 emdnorm (xi
, 0, 0, exp
, 64);
5700 /* Convert exploded e-type X, that has already been rounded to
5701 56-bit precision, to DEC format double Y. */
5705 unsigned EMUSHORT
*x
, *y
;
5707 unsigned EMUSHORT i
;
5708 unsigned EMUSHORT
*p
;
5747 /* Convert IBM single/double precision to e type. */
5751 unsigned EMUSHORT
*d
;
5752 unsigned EMUSHORT
*e
;
5753 enum machine_mode mode
;
5755 unsigned EMUSHORT y
[NI
];
5756 register unsigned EMUSHORT r
, *p
;
5759 ecleaz (y
); /* start with a zero */
5760 p
= y
; /* point to our number */
5761 r
= *d
; /* get IBM exponent word */
5762 if (*d
& (unsigned int) 0x8000)
5763 *p
= 0xffff; /* fill in our sign */
5764 ++p
; /* bump pointer to our exponent word */
5765 r
&= 0x7f00; /* strip the sign bit */
5766 r
>>= 6; /* shift exponent word down 6 bits */
5767 /* in fact shift by 8 right and 2 left */
5768 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5769 /* add our e type exponent offset */
5770 *p
++ = r
; /* to form our exponent */
5772 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5773 /* strip off the IBM exponent and sign bits */
5774 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5776 *p
++ = *d
++; /* fill in the rest of our mantissa */
5781 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5784 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5785 /* handle change in RADIX */
5791 /* Convert e type to IBM single/double precision. */
5795 unsigned EMUSHORT
*x
, *d
;
5796 enum machine_mode mode
;
5798 unsigned EMUSHORT xi
[NI
];
5803 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5804 /* round off to nearest or even */
5807 emdnorm (xi
, 0, 0, exp
, 64);
5809 toibm (xi
, d
, mode
);
5814 unsigned EMUSHORT
*x
, *y
;
5815 enum machine_mode mode
;
5817 unsigned EMUSHORT i
;
5818 unsigned EMUSHORT
*p
;
5868 /* Convert C4X single/double precision to e type. */
5872 unsigned EMUSHORT
*d
;
5873 unsigned EMUSHORT
*e
;
5874 enum machine_mode mode
;
5876 unsigned EMUSHORT y
[NI
];
5883 /* Short-circuit the zero case. */
5884 if ((d
[0] == 0x8000)
5886 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5897 ecleaz (y
); /* start with a zero */
5898 r
= d
[0]; /* get sign/exponent part */
5899 if (r
& (unsigned int) 0x0080)
5901 y
[0] = 0xffff; /* fill in our sign */
5909 r
>>= 8; /* Shift exponent word down 8 bits. */
5910 if (r
& 0x80) /* Make the exponent negative if it is. */
5912 r
= r
| (~0 & ~0xff);
5917 /* Now do the high order mantissa. We don't "or" on the high bit
5918 because it is 2 (not 1) and is handled a little differently
5923 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5925 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5935 /* Now do the two's complement on the data. */
5937 carry
= 1; /* Initially add 1 for the two's complement. */
5938 for (i
=size
+ M
; i
> M
; i
--)
5940 if (carry
&& (y
[i
] == 0x0000))
5942 /* We overflowed into the next word, carry is the same. */
5943 y
[i
] = carry
? 0x0000 : 0xffff;
5947 /* No overflow, just invert and add carry. */
5948 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5963 /* Add our e type exponent offset to form our exponent. */
5967 /* Now do the high order mantissa strip off the exponent and sign
5968 bits and add the high 1 bit. */
5969 y
[M
] = (d
[0] & 0x7f) | 0x80;
5972 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5974 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5984 /* Convert e type to C4X single/double precision. */
5988 unsigned EMUSHORT
*x
, *d
;
5989 enum machine_mode mode
;
5991 unsigned EMUSHORT xi
[NI
];
5997 /* Adjust exponent for offsets. */
5998 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6000 /* Round off to nearest or even. */
6002 rndprc
= mode
== QFmode
? 24 : 32;
6003 emdnorm (xi
, 0, 0, exp
, 64);
6005 toc4x (xi
, d
, mode
);
6010 unsigned EMUSHORT
*x
, *y
;
6011 enum machine_mode mode
;
6017 /* Short-circuit the zero case */
6018 if ((x
[0] == 0) /* Zero exponent and sign */
6020 && (x
[M
] == 0) /* The rest is for zero mantissa */
6022 /* Only check for double if necessary */
6023 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6025 /* We have a zero. Put it into the output and return. */
6038 /* Negative number require a two's complement conversion of the
6044 i
= ((int) x
[1]) - 0x7f;
6046 /* Now add 1 to the inverted data to do the two's complement. */
6056 x
[v
] = carry
? 0x0000 : 0xffff;
6060 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6066 /* The following is a special case. The C4X negative float requires
6067 a zero in the high bit (because the format is (2 - x) x 2^m), so
6068 if a one is in that bit, we have to shift left one to get rid
6069 of it. This only occurs if the number is -1 x 2^m. */
6070 if (x
[M
+1] & 0x8000)
6072 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6073 high sign bit and shift the exponent. */
6080 i
= ((int) x
[1]) - 0x7f;
6083 if ((i
< -128) || (i
> 127))
6098 y
[0] |= ((i
& 0xff) << 8);
6102 y
[0] |= x
[M
] & 0x7f;
6112 /* Output a binary NaN bit pattern in the target machine's format. */
6114 /* If special NaN bit patterns are required, define them in tm.h
6115 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6121 unsigned EMUSHORT TFbignan
[8] =
6122 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6123 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6131 unsigned EMUSHORT XFbignan
[6] =
6132 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6133 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6141 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6142 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6150 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6151 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6157 make_nan (nan
, sign
, mode
)
6158 unsigned EMUSHORT
*nan
;
6160 enum machine_mode mode
;
6163 unsigned EMUSHORT
*p
;
6167 /* Possibly the `reserved operand' patterns on a VAX can be
6168 used like NaN's, but probably not in the same way as IEEE. */
6169 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6172 if (REAL_WORDS_BIG_ENDIAN
)
6180 if (REAL_WORDS_BIG_ENDIAN
)
6188 if (REAL_WORDS_BIG_ENDIAN
)
6197 if (REAL_WORDS_BIG_ENDIAN
)
6207 if (REAL_WORDS_BIG_ENDIAN
)
6208 *nan
++ = (sign
<< 15) | *p
++;
6211 if (! REAL_WORDS_BIG_ENDIAN
)
6212 *nan
= (sign
<< 15) | *p
;
6215 /* This is the inverse of the function `etarsingle' invoked by
6216 REAL_VALUE_TO_TARGET_SINGLE. */
6219 ereal_unto_float (f
)
6223 unsigned EMUSHORT s
[2];
6224 unsigned EMUSHORT e
[NE
];
6226 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6227 This is the inverse operation to what the function `endian' does. */
6228 if (REAL_WORDS_BIG_ENDIAN
)
6230 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6231 s
[1] = (unsigned EMUSHORT
) f
;
6235 s
[0] = (unsigned EMUSHORT
) f
;
6236 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6238 /* Convert and promote the target float to E-type. */
6240 /* Output E-type to REAL_VALUE_TYPE. */
6246 /* This is the inverse of the function `etardouble' invoked by
6247 REAL_VALUE_TO_TARGET_DOUBLE. */
6250 ereal_unto_double (d
)
6254 unsigned EMUSHORT s
[4];
6255 unsigned EMUSHORT e
[NE
];
6257 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6258 if (REAL_WORDS_BIG_ENDIAN
)
6260 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6261 s
[1] = (unsigned EMUSHORT
) d
[0];
6262 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6263 s
[3] = (unsigned EMUSHORT
) d
[1];
6267 /* Target float words are little-endian. */
6268 s
[0] = (unsigned EMUSHORT
) d
[0];
6269 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6270 s
[2] = (unsigned EMUSHORT
) d
[1];
6271 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6273 /* Convert target double to E-type. */
6275 /* Output E-type to REAL_VALUE_TYPE. */
6281 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6282 This is somewhat like ereal_unto_float, but the input types
6283 for these are different. */
6286 ereal_from_float (f
)
6290 unsigned EMUSHORT s
[2];
6291 unsigned EMUSHORT e
[NE
];
6293 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6294 This is the inverse operation to what the function `endian' does. */
6295 if (REAL_WORDS_BIG_ENDIAN
)
6297 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6298 s
[1] = (unsigned EMUSHORT
) f
;
6302 s
[0] = (unsigned EMUSHORT
) f
;
6303 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6305 /* Convert and promote the target float to E-type. */
6307 /* Output E-type to REAL_VALUE_TYPE. */
6313 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6314 This is somewhat like ereal_unto_double, but the input types
6315 for these are different.
6317 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6318 data format, with no holes in the bit packing. The first element
6319 of the input array holds the bits that would come first in the
6320 target computer's memory. */
6323 ereal_from_double (d
)
6327 unsigned EMUSHORT s
[4];
6328 unsigned EMUSHORT e
[NE
];
6330 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6331 if (REAL_WORDS_BIG_ENDIAN
)
6333 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6334 s
[1] = (unsigned EMUSHORT
) d
[0];
6335 #if HOST_BITS_PER_WIDE_INT == 32
6336 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6337 s
[3] = (unsigned EMUSHORT
) d
[1];
6339 /* In this case the entire target double is contained in the
6340 first array element. The second element of the input is
6342 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6343 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6348 /* Target float words are little-endian. */
6349 s
[0] = (unsigned EMUSHORT
) d
[0];
6350 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6351 #if HOST_BITS_PER_WIDE_INT == 32
6352 s
[2] = (unsigned EMUSHORT
) d
[1];
6353 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6355 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6356 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6359 /* Convert target double to E-type. */
6361 /* Output E-type to REAL_VALUE_TYPE. */
6368 /* Convert target computer unsigned 64-bit integer to e-type.
6369 The endian-ness of DImode follows the convention for integers,
6370 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6374 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6375 unsigned EMUSHORT
*e
;
6377 unsigned EMUSHORT yi
[NI
];
6381 if (WORDS_BIG_ENDIAN
)
6383 for (k
= M
; k
< M
+ 4; k
++)
6388 for (k
= M
+ 3; k
>= M
; k
--)
6391 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6392 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6393 ecleaz (yi
); /* it was zero */
6395 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6399 /* Convert target computer signed 64-bit integer to e-type. */
6403 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6404 unsigned EMUSHORT
*e
;
6406 unsigned EMULONG acc
;
6407 unsigned EMUSHORT yi
[NI
];
6408 unsigned EMUSHORT carry
;
6412 if (WORDS_BIG_ENDIAN
)
6414 for (k
= M
; k
< M
+ 4; k
++)
6419 for (k
= M
+ 3; k
>= M
; k
--)
6422 /* Take absolute value */
6428 for (k
= M
+ 3; k
>= M
; k
--)
6430 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6437 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6438 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6439 ecleaz (yi
); /* it was zero */
6441 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6448 /* Convert e-type to unsigned 64-bit int. */
6452 unsigned EMUSHORT
*x
;
6453 unsigned EMUSHORT
*i
;
6455 unsigned EMUSHORT xi
[NI
];
6464 k
= (int) xi
[E
] - (EXONE
- 1);
6467 for (j
= 0; j
< 4; j
++)
6473 for (j
= 0; j
< 4; j
++)
6476 warning ("overflow on truncation to integer");
6481 /* Shift more than 16 bits: first shift up k-16 mod 16,
6482 then shift up by 16's. */
6483 j
= k
- ((k
>> 4) << 4);
6487 if (WORDS_BIG_ENDIAN
)
6498 if (WORDS_BIG_ENDIAN
)
6503 while ((k
-= 16) > 0);
6507 /* shift not more than 16 bits */
6512 if (WORDS_BIG_ENDIAN
)
6531 /* Convert e-type to signed 64-bit int. */
6535 unsigned EMUSHORT
*x
;
6536 unsigned EMUSHORT
*i
;
6538 unsigned EMULONG acc
;
6539 unsigned EMUSHORT xi
[NI
];
6540 unsigned EMUSHORT carry
;
6541 unsigned EMUSHORT
*isave
;
6545 k
= (int) xi
[E
] - (EXONE
- 1);
6548 for (j
= 0; j
< 4; j
++)
6554 for (j
= 0; j
< 4; j
++)
6557 warning ("overflow on truncation to integer");
6563 /* Shift more than 16 bits: first shift up k-16 mod 16,
6564 then shift up by 16's. */
6565 j
= k
- ((k
>> 4) << 4);
6569 if (WORDS_BIG_ENDIAN
)
6580 if (WORDS_BIG_ENDIAN
)
6585 while ((k
-= 16) > 0);
6589 /* shift not more than 16 bits */
6592 if (WORDS_BIG_ENDIAN
)
6608 /* Negate if negative */
6612 if (WORDS_BIG_ENDIAN
)
6614 for (k
= 0; k
< 4; k
++)
6616 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6617 if (WORDS_BIG_ENDIAN
)
6629 /* Longhand square root routine. */
6632 static int esqinited
= 0;
6633 static unsigned short sqrndbit
[NI
];
6637 unsigned EMUSHORT
*x
, *y
;
6639 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6641 int i
, j
, k
, n
, nlups
;
6646 sqrndbit
[NI
- 2] = 1;
6649 /* Check for arg <= 0 */
6650 i
= ecmp (x
, ezero
);
6655 mtherr ("esqrt", DOMAIN
);
6671 /* Bring in the arg and renormalize if it is denormal. */
6673 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6677 /* Divide exponent by 2 */
6679 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6681 /* Adjust if exponent odd */
6691 n
= 8; /* get 8 bits of result per inner loop */
6697 /* bring in next word of arg */
6699 num
[NI
- 1] = xx
[j
+ 3];
6700 /* Do additional bit on last outer loop, for roundoff. */
6703 for (i
= 0; i
< n
; i
++)
6705 /* Next 2 bits of arg */
6708 /* Shift up answer */
6710 /* Make trial divisor */
6711 for (k
= 0; k
< NI
; k
++)
6714 eaddm (sqrndbit
, temp
);
6715 /* Subtract and insert answer bit if it goes in */
6716 if (ecmpm (temp
, num
) <= 0)
6726 /* Adjust for extra, roundoff loop done. */
6727 exp
+= (NBITS
- 1) - rndprc
;
6729 /* Sticky bit = 1 if the remainder is nonzero. */
6731 for (i
= 3; i
< NI
; i
++)
6734 /* Renormalize and round off. */
6735 emdnorm (sq
, k
, 0, exp
, 64);
6739 #endif /* EMU_NON_COMPILE not defined */
6741 /* Return the binary precision of the significand for a given
6742 floating point mode. The mode can hold an integer value
6743 that many bits wide, without losing any bits. */
6746 significand_size (mode
)
6747 enum machine_mode mode
;
6750 /* Don't test the modes, but their sizes, lest this
6751 code won't work for BITS_PER_UNIT != 8 . */
6753 switch (GET_MODE_BITSIZE (mode
))
6757 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6764 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6767 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6770 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6773 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT