1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
27 /* To enable support of XFmode extended real floating point, define
28 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
30 To support cross compilation between IEEE, VAX and IBM floating
31 point formats, define REAL_ARITHMETIC in the tm.h file.
33 In either case the machine files (tm.h) must not contain any code
34 that tries to use host floating point arithmetic to convert
35 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
36 etc. In cross-compile situations a REAL_VALUE_TYPE may not
37 be intelligible to the host computer's native arithmetic.
39 The emulator defaults to the host's floating point format so that
40 its decimal conversion functions can be used if desired (see
43 The first part of this file interfaces gcc to a floating point
44 arithmetic suite that was not written with gcc in mind. Avoid
45 changing the low-level arithmetic routines unless you have suitable
46 test programs available. A special version of the PARANOIA floating
47 point arithmetic tester, modified for this purpose, can be found on
48 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
49 XFmode and TFmode transcendental functions, can be obtained by ftp from
50 netlib.att.com: netlib/cephes. */
52 /* Type of computer arithmetic.
53 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
55 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
56 to big-endian IEEE floating-point data structure. This definition
57 should work in SFmode `float' type and DFmode `double' type on
58 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
59 has been defined to be 96, then IEEE also invokes the particular
60 XFmode (`long double' type) data structure used by the Motorola
61 680x0 series processors.
63 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
64 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
65 has been defined to be 96, then IEEE also invokes the particular
66 XFmode `long double' data structure used by the Intel 80x86 series
69 `DEC' refers specifically to the Digital Equipment Corp PDP-11
70 and VAX floating point data structure. This model currently
71 supports no type wider than DFmode.
73 `IBM' refers specifically to the IBM System/370 and compatible
74 floating point data structure. This model currently supports
75 no type wider than DFmode. The IBM conversions were contributed by
76 frank@atom.ansto.gov.au (Frank Crawford).
78 `C4X' refers specifically to the floating point format used on
79 Texas Instruments TMS320C3x and TMS320C4x digital signal
80 processors. This supports QFmode (32-bit float, double) and HFmode
81 (40-bit long double) where BITS_PER_BYTE is 32.
83 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
84 then `long double' and `double' are both implemented, but they
85 both mean DFmode. In this case, the software floating-point
86 support available here is activated by writing
87 #define REAL_ARITHMETIC
90 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
91 and may deactivate XFmode since `long double' is used to refer
94 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
95 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
96 separate the floating point unit's endian-ness from that of
97 the integer addressing. This permits one to define a big-endian
98 FPU on a little-endian machine (e.g., ARM). An extension to
99 BYTES_BIG_ENDIAN may be required for some machines in the future.
100 These optional macros may be defined in tm.h. In real.h, they
101 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
102 them for any normal host or target machine on which the floats
103 and the integers have the same endian-ness. */
106 /* The following converts gcc macros into the ones used by this file. */
108 /* REAL_ARITHMETIC defined means that macros in real.h are
109 defined to call emulator functions. */
110 #ifdef REAL_ARITHMETIC
112 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
113 /* PDP-11, Pro350, VAX: */
115 #else /* it's not VAX */
116 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
117 /* IBM System/370 style */
119 #else /* it's also not an IBM */
120 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
121 /* TMS320C3x/C4x style */
123 #else /* it's also not a C4X */
124 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
126 #else /* it's not IEEE either */
127 /* UNKnown arithmetic. We don't support this and can't go on. */
128 unknown arithmetic type
130 #endif /* not IEEE */
135 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
138 /* REAL_ARITHMETIC not defined means that the *host's* data
139 structure will be used. It may differ by endian-ness from the
140 target machine's structure and will get its ends swapped
141 accordingly (but not here). Probably only the decimal <-> binary
142 functions in this file will actually be used in this case. */
144 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
146 #else /* it's not VAX */
147 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
148 /* IBM System/370 style */
150 #else /* it's also not an IBM */
151 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
153 #else /* it's not IEEE either */
154 unknown arithmetic type
156 #endif /* not IEEE */
160 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
162 #endif /* REAL_ARITHMETIC not defined */
164 /* Define INFINITY for support of infinity.
165 Define NANS for support of Not-a-Number's (NaN's). */
166 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
171 /* Support of NaNs requires support of infinity. */
178 /* Find a host integer type that is at least 16 bits wide,
179 and another type at least twice whatever that size is. */
181 #if HOST_BITS_PER_CHAR >= 16
182 #define EMUSHORT char
183 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
184 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
186 #if HOST_BITS_PER_SHORT >= 16
187 #define EMUSHORT short
188 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
189 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
191 #if HOST_BITS_PER_INT >= 16
193 #define EMUSHORT_SIZE HOST_BITS_PER_INT
194 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
196 #if HOST_BITS_PER_LONG >= 16
197 #define EMUSHORT long
198 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
199 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
201 /* You will have to modify this program to have a smaller unit size. */
202 #define EMU_NON_COMPILE
208 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
209 #define EMULONG short
211 #if HOST_BITS_PER_INT >= EMULONG_SIZE
214 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
217 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
218 #define EMULONG long long int
220 /* You will have to modify this program to have a smaller unit size. */
221 #define EMU_NON_COMPILE
228 /* The host interface doesn't work if no 16-bit size exists. */
229 #if EMUSHORT_SIZE != 16
230 #define EMU_NON_COMPILE
233 /* OK to continue compilation. */
234 #ifndef EMU_NON_COMPILE
236 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
237 In GET_REAL and PUT_REAL, r and e are pointers.
238 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
239 in memory, with no holes. */
241 #if LONG_DOUBLE_TYPE_SIZE == 96
242 /* Number of 16 bit words in external e type format */
244 #define MAXDECEXP 4932
245 #define MINDECEXP -4956
246 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
247 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
248 #else /* no XFmode */
249 #if LONG_DOUBLE_TYPE_SIZE == 128
251 #define MAXDECEXP 4932
252 #define MINDECEXP -4977
253 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
254 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
257 #define MAXDECEXP 4932
258 #define MINDECEXP -4956
259 #ifdef REAL_ARITHMETIC
260 /* Emulator uses target format internally
261 but host stores it in host endian-ness. */
263 #define GET_REAL(r,e) \
265 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
266 e53toe ((unsigned EMUSHORT *) (r), (e)); \
269 unsigned EMUSHORT w[4]; \
270 w[3] = ((EMUSHORT *) r)[0]; \
271 w[2] = ((EMUSHORT *) r)[1]; \
272 w[1] = ((EMUSHORT *) r)[2]; \
273 w[0] = ((EMUSHORT *) r)[3]; \
278 #define PUT_REAL(e,r) \
280 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
281 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
284 unsigned EMUSHORT w[4]; \
286 *((EMUSHORT *) r) = w[3]; \
287 *((EMUSHORT *) r + 1) = w[2]; \
288 *((EMUSHORT *) r + 2) = w[1]; \
289 *((EMUSHORT *) r + 3) = w[0]; \
293 #else /* not REAL_ARITHMETIC */
295 /* emulator uses host format */
296 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
297 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
299 #endif /* not REAL_ARITHMETIC */
300 #endif /* not TFmode */
301 #endif /* not XFmode */
304 /* Number of 16 bit words in internal format */
307 /* Array offset to exponent */
310 /* Array offset to high guard word */
313 /* Number of bits of precision */
314 #define NBITS ((NI-4)*16)
316 /* Maximum number of decimal digits in ASCII conversion
319 #define NDEC (NBITS*8/27)
321 /* The exponent of 1.0 */
322 #define EXONE (0x3fff)
324 extern int extra_warnings
;
325 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
326 extern unsigned EMUSHORT elog2
[], esqrt2
[];
328 static void endian
PROTO((unsigned EMUSHORT
*, long *,
330 static void eclear
PROTO((unsigned EMUSHORT
*));
331 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
332 static void eabs
PROTO((unsigned EMUSHORT
*));
333 static void eneg
PROTO((unsigned EMUSHORT
*));
334 static int eisneg
PROTO((unsigned EMUSHORT
*));
335 static int eisinf
PROTO((unsigned EMUSHORT
*));
336 static int eisnan
PROTO((unsigned EMUSHORT
*));
337 static void einfin
PROTO((unsigned EMUSHORT
*));
338 static void enan
PROTO((unsigned EMUSHORT
*, int));
339 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
340 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
341 static void ecleaz
PROTO((unsigned EMUSHORT
*));
342 static void ecleazs
PROTO((unsigned EMUSHORT
*));
343 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
344 static void einan
PROTO((unsigned EMUSHORT
*));
345 static int eiisnan
PROTO((unsigned EMUSHORT
*));
346 static int eiisneg
PROTO((unsigned EMUSHORT
*));
347 static void eiinfin
PROTO((unsigned EMUSHORT
*));
348 static int eiisinf
PROTO((unsigned EMUSHORT
*));
349 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
350 static void eshdn1
PROTO((unsigned EMUSHORT
*));
351 static void eshup1
PROTO((unsigned EMUSHORT
*));
352 static void eshdn8
PROTO((unsigned EMUSHORT
*));
353 static void eshup8
PROTO((unsigned EMUSHORT
*));
354 static void eshup6
PROTO((unsigned EMUSHORT
*));
355 static void eshdn6
PROTO((unsigned EMUSHORT
*));
356 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
357 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
358 static void m16m
PROTO((unsigned int, unsigned short *,
360 static int edivm
PROTO((unsigned short *, unsigned short *));
361 static int emulm
PROTO((unsigned short *, unsigned short *));
362 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
363 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
364 unsigned EMUSHORT
*));
365 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
366 unsigned EMUSHORT
*));
367 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
368 unsigned EMUSHORT
*));
369 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
370 unsigned EMUSHORT
*));
371 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
372 unsigned EMUSHORT
*));
373 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
378 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
380 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
381 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
384 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
386 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
387 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
388 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
389 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
390 unsigned EMUSHORT
*));
391 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
392 unsigned EMUSHORT
*));
393 static int eshift
PROTO((unsigned EMUSHORT
*, int));
394 static int enormlz
PROTO((unsigned EMUSHORT
*));
395 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
396 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
397 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
398 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
399 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
400 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
401 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
402 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
403 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
404 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
405 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
406 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
407 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
408 unsigned EMUSHORT
*));
409 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
410 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
411 unsigned EMUSHORT
*));
412 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void mtherr
PROTO((char *, int));
415 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
417 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
422 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
424 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
428 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
430 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
432 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
435 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
436 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
437 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
438 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
439 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
440 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
442 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
443 swapping ends if required, into output array of longs. The
444 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
448 unsigned EMUSHORT e
[];
450 enum machine_mode mode
;
454 if (REAL_WORDS_BIG_ENDIAN
)
459 /* Swap halfwords in the fourth long. */
460 th
= (unsigned long) e
[6] & 0xffff;
461 t
= (unsigned long) e
[7] & 0xffff;
466 /* Swap halfwords in the third long. */
467 th
= (unsigned long) e
[4] & 0xffff;
468 t
= (unsigned long) e
[5] & 0xffff;
471 /* fall into the double case */
474 /* Swap halfwords in the second word. */
475 th
= (unsigned long) e
[2] & 0xffff;
476 t
= (unsigned long) e
[3] & 0xffff;
479 /* fall into the float case */
483 /* Swap halfwords in the first word. */
484 th
= (unsigned long) e
[0] & 0xffff;
485 t
= (unsigned long) e
[1] & 0xffff;
496 /* Pack the output array without swapping. */
501 /* Pack the fourth long. */
502 th
= (unsigned long) e
[7] & 0xffff;
503 t
= (unsigned long) e
[6] & 0xffff;
508 /* Pack the third long.
509 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
511 th
= (unsigned long) e
[5] & 0xffff;
512 t
= (unsigned long) e
[4] & 0xffff;
515 /* fall into the double case */
518 /* Pack the second long */
519 th
= (unsigned long) e
[3] & 0xffff;
520 t
= (unsigned long) e
[2] & 0xffff;
523 /* fall into the float case */
527 /* Pack the first long */
528 th
= (unsigned long) e
[1] & 0xffff;
529 t
= (unsigned long) e
[0] & 0xffff;
541 /* This is the implementation of the REAL_ARITHMETIC macro. */
544 earith (value
, icode
, r1
, r2
)
545 REAL_VALUE_TYPE
*value
;
550 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
556 /* Return NaN input back to the caller. */
559 PUT_REAL (d1
, value
);
564 PUT_REAL (d2
, value
);
568 code
= (enum tree_code
) icode
;
576 esub (d2
, d1
, v
); /* d1 - d2 */
584 #ifndef REAL_INFINITY
585 if (ecmp (d2
, ezero
) == 0)
588 enan (v
, eisneg (d1
) ^ eisneg (d2
));
595 ediv (d2
, d1
, v
); /* d1/d2 */
598 case MIN_EXPR
: /* min (d1,d2) */
599 if (ecmp (d1
, d2
) < 0)
605 case MAX_EXPR
: /* max (d1,d2) */
606 if (ecmp (d1
, d2
) > 0)
619 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
620 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
626 unsigned EMUSHORT f
[NE
], g
[NE
];
642 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
643 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
649 unsigned EMUSHORT f
[NE
], g
[NE
];
651 unsigned HOST_WIDE_INT l
;
665 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
666 string to binary, rounding off as indicated by the machine_mode argument.
667 Then it promotes the rounded value to REAL_VALUE_TYPE. */
674 unsigned EMUSHORT tem
[NE
], e
[NE
];
717 /* Expansion of REAL_NEGATE. */
723 unsigned EMUSHORT e
[NE
];
733 /* Round real toward zero to HOST_WIDE_INT;
734 implements REAL_VALUE_FIX (x). */
740 unsigned EMUSHORT f
[NE
], g
[NE
];
747 warning ("conversion from NaN to int");
755 /* Round real toward zero to unsigned HOST_WIDE_INT
756 implements REAL_VALUE_UNSIGNED_FIX (x).
757 Negative input returns zero. */
759 unsigned HOST_WIDE_INT
763 unsigned EMUSHORT f
[NE
], g
[NE
];
764 unsigned HOST_WIDE_INT l
;
770 warning ("conversion from NaN to unsigned int");
779 /* REAL_VALUE_FROM_INT macro. */
782 ereal_from_int (d
, i
, j
, mode
)
785 enum machine_mode mode
;
787 unsigned EMUSHORT df
[NE
], dg
[NE
];
788 HOST_WIDE_INT low
, high
;
791 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
798 /* complement and add 1 */
805 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
806 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
808 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
813 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
814 Avoid double-rounding errors later by rounding off now from the
815 extra-wide internal format to the requested precision. */
816 switch (GET_MODE_BITSIZE (mode
))
846 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
849 ereal_from_uint (d
, i
, j
, mode
)
851 unsigned HOST_WIDE_INT i
, j
;
852 enum machine_mode mode
;
854 unsigned EMUSHORT df
[NE
], dg
[NE
];
855 unsigned HOST_WIDE_INT low
, high
;
857 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
861 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
867 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
868 Avoid double-rounding errors later by rounding off now from the
869 extra-wide internal format to the requested precision. */
870 switch (GET_MODE_BITSIZE (mode
))
900 /* REAL_VALUE_TO_INT macro. */
903 ereal_to_int (low
, high
, rr
)
904 HOST_WIDE_INT
*low
, *high
;
907 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
914 warning ("conversion from NaN to int");
920 /* convert positive value */
927 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
928 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
929 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
930 emul (df
, dh
, dg
); /* fractional part is the low word */
931 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
934 /* complement and add 1 */
944 /* REAL_VALUE_LDEXP macro. */
951 unsigned EMUSHORT e
[NE
], y
[NE
];
964 /* These routines are conditionally compiled because functions
965 of the same names may be defined in fold-const.c. */
967 #ifdef REAL_ARITHMETIC
969 /* Check for infinity in a REAL_VALUE_TYPE. */
975 unsigned EMUSHORT e
[NE
];
985 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
991 unsigned EMUSHORT e
[NE
];
1002 /* Check for a negative REAL_VALUE_TYPE number.
1003 This just checks the sign bit, so that -0 counts as negative. */
1009 return ereal_isneg (x
);
1012 /* Expansion of REAL_VALUE_TRUNCATE.
1013 The result is in floating point, rounded to nearest or even. */
1016 real_value_truncate (mode
, arg
)
1017 enum machine_mode mode
;
1018 REAL_VALUE_TYPE arg
;
1020 unsigned EMUSHORT e
[NE
], t
[NE
];
1066 /* If an unsupported type was requested, presume that
1067 the machine files know something useful to do with
1068 the unmodified value. */
1077 /* Try to change R into its exact multiplicative inverse in machine mode
1078 MODE. Return nonzero function value if successful. */
1081 exact_real_inverse (mode
, r
)
1082 enum machine_mode mode
;
1085 unsigned EMUSHORT e
[NE
], einv
[NE
];
1086 REAL_VALUE_TYPE rinv
;
1091 /* Test for input in range. Don't transform IEEE special values. */
1092 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1095 /* Test for a power of 2: all significand bits zero except the MSB.
1096 We are assuming the target has binary (or hex) arithmetic. */
1097 if (e
[NE
- 2] != 0x8000)
1100 for (i
= 0; i
< NE
- 2; i
++)
1106 /* Compute the inverse and truncate it to the required mode. */
1107 ediv (e
, eone
, einv
);
1108 PUT_REAL (einv
, &rinv
);
1109 rinv
= real_value_truncate (mode
, rinv
);
1111 #ifdef CHECK_FLOAT_VALUE
1112 /* This check is not redundant. It may, for example, flush
1113 a supposedly IEEE denormal value to zero. */
1115 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1118 GET_REAL (&rinv
, einv
);
1120 /* Check the bits again, because the truncation might have
1121 generated an arbitrary saturation value on overflow. */
1122 if (einv
[NE
- 2] != 0x8000)
1125 for (i
= 0; i
< NE
- 2; i
++)
1131 /* Fail if the computed inverse is out of range. */
1132 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1135 /* Output the reciprocal and return success flag. */
1139 #endif /* REAL_ARITHMETIC defined */
1141 /* Used for debugging--print the value of R in human-readable format
1150 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1151 fprintf (stderr
, "%s", dstr
);
1155 /* The following routines convert REAL_VALUE_TYPE to the various floating
1156 point formats that are meaningful to supported computers.
1158 The results are returned in 32-bit pieces, each piece stored in a `long'.
1159 This is so they can be printed by statements like
1161 fprintf (file, "%lx, %lx", L[0], L[1]);
1163 that will work on both narrow- and wide-word host computers. */
1165 /* Convert R to a 128-bit long double precision value. The output array L
1166 contains four 32-bit pieces of the result, in the order they would appear
1174 unsigned EMUSHORT e
[NE
];
1178 endian (e
, l
, TFmode
);
1181 /* Convert R to a double extended precision value. The output array L
1182 contains three 32-bit pieces of the result, in the order they would
1183 appear in memory. */
1190 unsigned EMUSHORT e
[NE
];
1194 endian (e
, l
, XFmode
);
1197 /* Convert R to a double precision value. The output array L contains two
1198 32-bit pieces of the result, in the order they would appear in memory. */
1205 unsigned EMUSHORT e
[NE
];
1209 endian (e
, l
, DFmode
);
1212 /* Convert R to a single precision float value stored in the least-significant
1213 bits of a `long'. */
1219 unsigned EMUSHORT e
[NE
];
1224 endian (e
, &l
, SFmode
);
1228 /* Convert X to a decimal ASCII string S for output to an assembly
1229 language file. Note, there is no standard way to spell infinity or
1230 a NaN, so these values may require special treatment in the tm.h
1234 ereal_to_decimal (x
, s
)
1238 unsigned EMUSHORT e
[NE
];
1244 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1245 or -2 if either is a NaN. */
1249 REAL_VALUE_TYPE x
, y
;
1251 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1255 return (ecmp (ex
, ey
));
1258 /* Return 1 if the sign bit of X is set, else return 0. */
1264 unsigned EMUSHORT ex
[NE
];
1267 return (eisneg (ex
));
1270 /* End of REAL_ARITHMETIC interface */
1273 Extended precision IEEE binary floating point arithmetic routines
1275 Numbers are stored in C language as arrays of 16-bit unsigned
1276 short integers. The arguments of the routines are pointers to
1279 External e type data structure, similar to Intel 8087 chip
1280 temporary real format but possibly with a larger significand:
1282 NE-1 significand words (least significant word first,
1283 most significant bit is normally set)
1284 exponent (value = EXONE for 1.0,
1285 top bit is the sign)
1288 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1290 ei[0] sign word (0 for positive, 0xffff for negative)
1291 ei[1] biased exponent (value = EXONE for the number 1.0)
1292 ei[2] high guard word (always zero after normalization)
1294 to ei[NI-2] significand (NI-4 significand words,
1295 most significant word first,
1296 most significant bit is set)
1297 ei[NI-1] low guard word (0x8000 bit is rounding place)
1301 Routines for external format e-type numbers
1303 asctoe (string, e) ASCII string to extended double e type
1304 asctoe64 (string, &d) ASCII string to long double
1305 asctoe53 (string, &d) ASCII string to double
1306 asctoe24 (string, &f) ASCII string to single
1307 asctoeg (string, e, prec) ASCII string to specified precision
1308 e24toe (&f, e) IEEE single precision to e type
1309 e53toe (&d, e) IEEE double precision to e type
1310 e64toe (&d, e) IEEE long double precision to e type
1311 e113toe (&d, e) 128-bit long double precision to e type
1312 eabs (e) absolute value
1313 eadd (a, b, c) c = b + a
1315 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1316 -1 if a < b, -2 if either a or b is a NaN.
1317 ediv (a, b, c) c = b / a
1318 efloor (a, b) truncate to integer, toward -infinity
1319 efrexp (a, exp, s) extract exponent and significand
1320 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1321 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1322 einfin (e) set e to infinity, leaving its sign alone
1323 eldexp (a, n, b) multiply by 2**n
1325 emul (a, b, c) c = b * a
1327 eround (a, b) b = nearest integer value to a
1328 esub (a, b, c) c = b - a
1329 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1330 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1331 e64toasc (&d, str, n) 80-bit long double to ASCII string
1332 e113toasc (&d, str, n) 128-bit long double to ASCII string
1333 etoasc (e, str, n) e to ASCII string, n digits after decimal
1334 etoe24 (e, &f) convert e type to IEEE single precision
1335 etoe53 (e, &d) convert e type to IEEE double precision
1336 etoe64 (e, &d) convert e type to IEEE long double precision
1337 ltoe (&l, e) HOST_WIDE_INT to e type
1338 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1339 eisneg (e) 1 if sign bit of e != 0, else 0
1340 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1341 or is infinite (IEEE)
1342 eisnan (e) 1 if e is a NaN
1345 Routines for internal format exploded e-type numbers
1347 eaddm (ai, bi) add significands, bi = bi + ai
1349 ecleazs (ei) set ei = 0 but leave its sign alone
1350 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1351 edivm (ai, bi) divide significands, bi = bi / ai
1352 emdnorm (ai,l,s,exp) normalize and round off
1353 emovi (a, ai) convert external a to internal ai
1354 emovo (ai, a) convert internal ai to external a
1355 emovz (ai, bi) bi = ai, low guard word of bi = 0
1356 emulm (ai, bi) multiply significands, bi = bi * ai
1357 enormlz (ei) left-justify the significand
1358 eshdn1 (ai) shift significand and guards down 1 bit
1359 eshdn8 (ai) shift down 8 bits
1360 eshdn6 (ai) shift down 16 bits
1361 eshift (ai, n) shift ai n bits up (or down if n < 0)
1362 eshup1 (ai) shift significand and guards up 1 bit
1363 eshup8 (ai) shift up 8 bits
1364 eshup6 (ai) shift up 16 bits
1365 esubm (ai, bi) subtract significands, bi = bi - ai
1366 eiisinf (ai) 1 if infinite
1367 eiisnan (ai) 1 if a NaN
1368 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1369 einan (ai) set ai = NaN
1370 eiinfin (ai) set ai = infinity
1372 The result is always normalized and rounded to NI-4 word precision
1373 after each arithmetic operation.
1375 Exception flags are NOT fully supported.
1377 Signaling NaN's are NOT supported; they are treated the same
1380 Define INFINITY for support of infinity; otherwise a
1381 saturation arithmetic is implemented.
1383 Define NANS for support of Not-a-Number items; otherwise the
1384 arithmetic will never produce a NaN output, and might be confused
1386 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1387 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1388 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1391 Denormals are always supported here where appropriate (e.g., not
1392 for conversion to DEC numbers). */
1394 /* Definitions for error codes that are passed to the common error handling
1397 For Digital Equipment PDP-11 and VAX computers, certain
1398 IBM systems, and others that use numbers with a 56-bit
1399 significand, the symbol DEC should be defined. In this
1400 mode, most floating point constants are given as arrays
1401 of octal integers to eliminate decimal to binary conversion
1402 errors that might be introduced by the compiler.
1404 For computers, such as IBM PC, that follow the IEEE
1405 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1406 Std 754-1985), the symbol IEEE should be defined.
1407 These numbers have 53-bit significands. In this mode, constants
1408 are provided as arrays of hexadecimal 16 bit integers.
1409 The endian-ness of generated values is controlled by
1410 REAL_WORDS_BIG_ENDIAN.
1412 To accommodate other types of computer arithmetic, all
1413 constants are also provided in a normal decimal radix
1414 which one can hope are correctly converted to a suitable
1415 format by the available C language compiler. To invoke
1416 this mode, the symbol UNK is defined.
1418 An important difference among these modes is a predefined
1419 set of machine arithmetic constants for each. The numbers
1420 MACHEP (the machine roundoff error), MAXNUM (largest number
1421 represented), and several other parameters are preset by
1422 the configuration symbol. Check the file const.c to
1423 ensure that these values are correct for your computer.
1425 For ANSI C compatibility, define ANSIC equal to 1. Currently
1426 this affects only the atan2 function and others that use it. */
1428 /* Constant definitions for math error conditions. */
1430 #define DOMAIN 1 /* argument domain error */
1431 #define SING 2 /* argument singularity */
1432 #define OVERFLOW 3 /* overflow range error */
1433 #define UNDERFLOW 4 /* underflow range error */
1434 #define TLOSS 5 /* total loss of precision */
1435 #define PLOSS 6 /* partial loss of precision */
1436 #define INVALID 7 /* NaN-producing operation */
1438 /* e type constants used by high precision check routines */
1440 #if LONG_DOUBLE_TYPE_SIZE == 128
1442 unsigned EMUSHORT ezero
[NE
] =
1443 {0x0000, 0x0000, 0x0000, 0x0000,
1444 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1445 extern unsigned EMUSHORT ezero
[];
1448 unsigned EMUSHORT ehalf
[NE
] =
1449 {0x0000, 0x0000, 0x0000, 0x0000,
1450 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1451 extern unsigned EMUSHORT ehalf
[];
1454 unsigned EMUSHORT eone
[NE
] =
1455 {0x0000, 0x0000, 0x0000, 0x0000,
1456 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1457 extern unsigned EMUSHORT eone
[];
1460 unsigned EMUSHORT etwo
[NE
] =
1461 {0x0000, 0x0000, 0x0000, 0x0000,
1462 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1463 extern unsigned EMUSHORT etwo
[];
1466 unsigned EMUSHORT e32
[NE
] =
1467 {0x0000, 0x0000, 0x0000, 0x0000,
1468 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1469 extern unsigned EMUSHORT e32
[];
1471 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1472 unsigned EMUSHORT elog2
[NE
] =
1473 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1474 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1475 extern unsigned EMUSHORT elog2
[];
1477 /* 1.41421356237309504880168872420969807856967187537695E0 */
1478 unsigned EMUSHORT esqrt2
[NE
] =
1479 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1480 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1481 extern unsigned EMUSHORT esqrt2
[];
1483 /* 3.14159265358979323846264338327950288419716939937511E0 */
1484 unsigned EMUSHORT epi
[NE
] =
1485 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1486 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1487 extern unsigned EMUSHORT epi
[];
1490 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1491 unsigned EMUSHORT ezero
[NE
] =
1492 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1493 unsigned EMUSHORT ehalf
[NE
] =
1494 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1495 unsigned EMUSHORT eone
[NE
] =
1496 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1497 unsigned EMUSHORT etwo
[NE
] =
1498 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1499 unsigned EMUSHORT e32
[NE
] =
1500 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1501 unsigned EMUSHORT elog2
[NE
] =
1502 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1503 unsigned EMUSHORT esqrt2
[NE
] =
1504 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1505 unsigned EMUSHORT epi
[NE
] =
1506 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1509 /* Control register for rounding precision.
1510 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1515 /* Clear out entire e-type number X. */
1519 register unsigned EMUSHORT
*x
;
1523 for (i
= 0; i
< NE
; i
++)
1527 /* Move e-type number from A to B. */
1531 register unsigned EMUSHORT
*a
, *b
;
1535 for (i
= 0; i
< NE
; i
++)
1540 /* Absolute value of e-type X. */
1544 unsigned EMUSHORT x
[];
1546 /* sign is top bit of last word of external format */
1547 x
[NE
- 1] &= 0x7fff;
1550 /* Negate the e-type number X. */
1554 unsigned EMUSHORT x
[];
1557 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1560 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1564 unsigned EMUSHORT x
[];
1567 if (x
[NE
- 1] & 0x8000)
1573 /* Return 1 if e-type number X is infinity, else return zero. */
1577 unsigned EMUSHORT x
[];
1584 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1590 /* Check if e-type number is not a number. The bit pattern is one that we
1591 defined, so we know for sure how to detect it. */
1595 unsigned EMUSHORT x
[];
1600 /* NaN has maximum exponent */
1601 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1603 /* ... and non-zero significand field. */
1604 for (i
= 0; i
< NE
- 1; i
++)
1614 /* Fill e-type number X with infinity pattern (IEEE)
1615 or largest possible number (non-IEEE). */
1619 register unsigned EMUSHORT
*x
;
1624 for (i
= 0; i
< NE
- 1; i
++)
1628 for (i
= 0; i
< NE
- 1; i
++)
1656 /* Output an e-type NaN.
1657 This generates Intel's quiet NaN pattern for extended real.
1658 The exponent is 7fff, the leading mantissa word is c000. */
1662 register unsigned EMUSHORT
*x
;
1667 for (i
= 0; i
< NE
- 2; i
++)
1670 *x
= (sign
<< 15) | 0x7fff;
1673 /* Move in an e-type number A, converting it to exploded e-type B. */
1677 unsigned EMUSHORT
*a
, *b
;
1679 register unsigned EMUSHORT
*p
, *q
;
1683 p
= a
+ (NE
- 1); /* point to last word of external number */
1684 /* get the sign bit */
1689 /* get the exponent */
1691 *q
++ &= 0x7fff; /* delete the sign bit */
1693 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1699 for (i
= 3; i
< NI
; i
++)
1705 for (i
= 2; i
< NI
; i
++)
1711 /* clear high guard word */
1713 /* move in the significand */
1714 for (i
= 0; i
< NE
- 1; i
++)
1716 /* clear low guard word */
1720 /* Move out exploded e-type number A, converting it to e type B. */
1724 unsigned EMUSHORT
*a
, *b
;
1726 register unsigned EMUSHORT
*p
, *q
;
1727 unsigned EMUSHORT i
;
1731 q
= b
+ (NE
- 1); /* point to output exponent */
1732 /* combine sign and exponent */
1735 *q
-- = *p
++ | 0x8000;
1739 if (*(p
- 1) == 0x7fff)
1744 enan (b
, eiisneg (a
));
1752 /* skip over guard word */
1754 /* move the significand */
1755 for (j
= 0; j
< NE
- 1; j
++)
1759 /* Clear out exploded e-type number XI. */
1763 register unsigned EMUSHORT
*xi
;
1767 for (i
= 0; i
< NI
; i
++)
1771 /* Clear out exploded e-type XI, but don't touch the sign. */
1775 register unsigned EMUSHORT
*xi
;
1780 for (i
= 0; i
< NI
- 1; i
++)
1784 /* Move exploded e-type number from A to B. */
1788 register unsigned EMUSHORT
*a
, *b
;
1792 for (i
= 0; i
< NI
- 1; i
++)
1794 /* clear low guard word */
1798 /* Generate exploded e-type NaN.
1799 The explicit pattern for this is maximum exponent and
1800 top two significant bits set. */
1804 unsigned EMUSHORT x
[];
1812 /* Return nonzero if exploded e-type X is a NaN. */
1816 unsigned EMUSHORT x
[];
1820 if ((x
[E
] & 0x7fff) == 0x7fff)
1822 for (i
= M
+ 1; i
< NI
; i
++)
1831 /* Return nonzero if sign of exploded e-type X is nonzero. */
1835 unsigned EMUSHORT x
[];
1841 /* Fill exploded e-type X with infinity pattern.
1842 This has maximum exponent and significand all zeros. */
1846 unsigned EMUSHORT x
[];
1853 /* Return nonzero if exploded e-type X is infinite. */
1857 unsigned EMUSHORT x
[];
1864 if ((x
[E
] & 0x7fff) == 0x7fff)
1870 /* Compare significands of numbers in internal exploded e-type format.
1871 Guard words are included in the comparison.
1879 register unsigned EMUSHORT
*a
, *b
;
1883 a
+= M
; /* skip up to significand area */
1885 for (i
= M
; i
< NI
; i
++)
1893 if (*(--a
) > *(--b
))
1899 /* Shift significand of exploded e-type X down by 1 bit. */
1903 register unsigned EMUSHORT
*x
;
1905 register unsigned EMUSHORT bits
;
1908 x
+= M
; /* point to significand area */
1911 for (i
= M
; i
< NI
; i
++)
1923 /* Shift significand of exploded e-type X up by 1 bit. */
1927 register unsigned EMUSHORT
*x
;
1929 register unsigned EMUSHORT bits
;
1935 for (i
= M
; i
< NI
; i
++)
1948 /* Shift significand of exploded e-type X down by 8 bits. */
1952 register unsigned EMUSHORT
*x
;
1954 register unsigned EMUSHORT newbyt
, oldbyt
;
1959 for (i
= M
; i
< NI
; i
++)
1969 /* Shift significand of exploded e-type X up by 8 bits. */
1973 register unsigned EMUSHORT
*x
;
1976 register unsigned EMUSHORT newbyt
, oldbyt
;
1981 for (i
= M
; i
< NI
; i
++)
1991 /* Shift significand of exploded e-type X up by 16 bits. */
1995 register unsigned EMUSHORT
*x
;
1998 register unsigned EMUSHORT
*p
;
2003 for (i
= M
; i
< NI
- 1; i
++)
2009 /* Shift significand of exploded e-type X down by 16 bits. */
2013 register unsigned EMUSHORT
*x
;
2016 register unsigned EMUSHORT
*p
;
2021 for (i
= M
; i
< NI
- 1; i
++)
2027 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2031 unsigned EMUSHORT
*x
, *y
;
2033 register unsigned EMULONG a
;
2040 for (i
= M
; i
< NI
; i
++)
2042 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2047 *y
= (unsigned EMUSHORT
) a
;
2053 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2057 unsigned EMUSHORT
*x
, *y
;
2066 for (i
= M
; i
< NI
; i
++)
2068 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2073 *y
= (unsigned EMUSHORT
) a
;
2080 static unsigned EMUSHORT equot
[NI
];
2084 /* Radix 2 shift-and-add versions of multiply and divide */
2087 /* Divide significands */
2091 unsigned EMUSHORT den
[], num
[];
2094 register unsigned EMUSHORT
*p
, *q
;
2095 unsigned EMUSHORT j
;
2101 for (i
= M
; i
< NI
; i
++)
2106 /* Use faster compare and subtraction if denominator has only 15 bits of
2112 for (i
= M
+ 3; i
< NI
; i
++)
2117 if ((den
[M
+ 1] & 1) != 0)
2125 for (i
= 0; i
< NBITS
+ 2; i
++)
2143 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2144 bit + 1 roundoff bit. */
2149 for (i
= 0; i
< NBITS
+ 2; i
++)
2151 if (ecmpm (den
, num
) <= 0)
2154 j
= 1; /* quotient bit = 1 */
2168 /* test for nonzero remainder after roundoff bit */
2171 for (i
= M
; i
< NI
; i
++)
2179 for (i
= 0; i
< NI
; i
++)
2185 /* Multiply significands */
2189 unsigned EMUSHORT a
[], b
[];
2191 unsigned EMUSHORT
*p
, *q
;
2196 for (i
= M
; i
< NI
; i
++)
2201 while (*p
== 0) /* significand is not supposed to be zero */
2206 if ((*p
& 0xff) == 0)
2214 for (i
= 0; i
< k
; i
++)
2218 /* remember if there were any nonzero bits shifted out */
2225 for (i
= 0; i
< NI
; i
++)
2228 /* return flag for lost nonzero bits */
2234 /* Radix 65536 versions of multiply and divide. */
2236 /* Multiply significand of e-type number B
2237 by 16-bit quantity A, return e-type result to C. */
2242 unsigned EMUSHORT b
[], c
[];
2244 register unsigned EMUSHORT
*pp
;
2245 register unsigned EMULONG carry
;
2246 unsigned EMUSHORT
*ps
;
2247 unsigned EMUSHORT p
[NI
];
2248 unsigned EMULONG aa
, m
;
2257 for (i
=M
+1; i
<NI
; i
++)
2267 m
= (unsigned EMULONG
) aa
* *ps
--;
2268 carry
= (m
& 0xffff) + *pp
;
2269 *pp
-- = (unsigned EMUSHORT
)carry
;
2270 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2271 *pp
= (unsigned EMUSHORT
)carry
;
2272 *(pp
-1) = carry
>> 16;
2275 for (i
=M
; i
<NI
; i
++)
2279 /* Divide significands of exploded e-types NUM / DEN. Neither the
2280 numerator NUM nor the denominator DEN is permitted to have its high guard
2285 unsigned EMUSHORT den
[], num
[];
2288 register unsigned EMUSHORT
*p
;
2289 unsigned EMULONG tnum
;
2290 unsigned EMUSHORT j
, tdenm
, tquot
;
2291 unsigned EMUSHORT tprod
[NI
+1];
2297 for (i
=M
; i
<NI
; i
++)
2303 for (i
=M
; i
<NI
; i
++)
2305 /* Find trial quotient digit (the radix is 65536). */
2306 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2308 /* Do not execute the divide instruction if it will overflow. */
2309 if ((tdenm
* 0xffffL
) < tnum
)
2312 tquot
= tnum
/ tdenm
;
2313 /* Multiply denominator by trial quotient digit. */
2314 m16m ((unsigned int)tquot
, den
, tprod
);
2315 /* The quotient digit may have been overestimated. */
2316 if (ecmpm (tprod
, num
) > 0)
2320 if (ecmpm (tprod
, num
) > 0)
2330 /* test for nonzero remainder after roundoff bit */
2333 for (i
=M
; i
<NI
; i
++)
2340 for (i
=0; i
<NI
; i
++)
2346 /* Multiply significands of exploded e-type A and B, result in B. */
2350 unsigned EMUSHORT a
[], b
[];
2352 unsigned EMUSHORT
*p
, *q
;
2353 unsigned EMUSHORT pprod
[NI
];
2354 unsigned EMUSHORT j
;
2359 for (i
=M
; i
<NI
; i
++)
2365 for (i
=M
+1; i
<NI
; i
++)
2373 m16m ((unsigned int) *p
--, b
, pprod
);
2374 eaddm(pprod
, equot
);
2380 for (i
=0; i
<NI
; i
++)
2383 /* return flag for lost nonzero bits */
2389 /* Normalize and round off.
2391 The internal format number to be rounded is S.
2392 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2394 Input SUBFLG indicates whether the number was obtained
2395 by a subtraction operation. In that case if LOST is nonzero
2396 then the number is slightly smaller than indicated.
2398 Input EXP is the biased exponent, which may be negative.
2399 the exponent field of S is ignored but is replaced by
2400 EXP as adjusted by normalization and rounding.
2402 Input RCNTRL is the rounding control. If it is nonzero, the
2403 returned value will be rounded to RNDPRC bits.
2405 For future reference: In order for emdnorm to round off denormal
2406 significands at the right point, the input exponent must be
2407 adjusted to be the actual value it would have after conversion to
2408 the final floating point type. This adjustment has been
2409 implemented for all type conversions (etoe53, etc.) and decimal
2410 conversions, but not for the arithmetic functions (eadd, etc.).
2411 Data types having standard 15-bit exponents are not affected by
2412 this, but SFmode and DFmode are affected. For example, ediv with
2413 rndprc = 24 will not round correctly to 24-bit precision if the
2414 result is denormal. */
2416 static int rlast
= -1;
2418 static unsigned EMUSHORT rmsk
= 0;
2419 static unsigned EMUSHORT rmbit
= 0;
2420 static unsigned EMUSHORT rebit
= 0;
2422 static unsigned EMUSHORT rbit
[NI
];
2425 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2426 unsigned EMUSHORT s
[];
2433 unsigned EMUSHORT r
;
2438 /* a blank significand could mean either zero or infinity. */
2451 if ((j
> NBITS
) && (exp
< 32767))
2459 if (exp
> (EMULONG
) (-NBITS
- 1))
2472 /* Round off, unless told not to by rcntrl. */
2475 /* Set up rounding parameters if the control register changed. */
2476 if (rndprc
!= rlast
)
2483 rw
= NI
- 1; /* low guard word */
2506 /* For DEC or IBM arithmetic */
2523 /* For C4x arithmetic */
2544 /* Shift down 1 temporarily if the data structure has an implied
2545 most significant bit and the number is denormal.
2546 Intel long double denormals also lose one bit of precision. */
2547 if ((exp
<= 0) && (rndprc
!= NBITS
)
2548 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2550 lost
|= s
[NI
- 1] & 1;
2553 /* Clear out all bits below the rounding bit,
2554 remembering in r if any were nonzero. */
2568 if ((r
& rmbit
) != 0)
2573 { /* round to even */
2574 if ((s
[re
] & rebit
) == 0)
2586 /* Undo the temporary shift for denormal values. */
2587 if ((exp
<= 0) && (rndprc
!= NBITS
)
2588 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2593 { /* overflow on roundoff */
2606 for (i
= 2; i
< NI
- 1; i
++)
2609 warning ("floating point overflow");
2613 for (i
= M
+ 1; i
< NI
- 1; i
++)
2616 if ((rndprc
< 64) || (rndprc
== 113))
2631 s
[1] = (unsigned EMUSHORT
) exp
;
2634 /* Subtract. C = B - A, all e type numbers. */
2636 static int subflg
= 0;
2640 unsigned EMUSHORT
*a
, *b
, *c
;
2654 /* Infinity minus infinity is a NaN.
2655 Test for subtracting infinities of the same sign. */
2656 if (eisinf (a
) && eisinf (b
)
2657 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2659 mtherr ("esub", INVALID
);
2668 /* Add. C = A + B, all e type. */
2672 unsigned EMUSHORT
*a
, *b
, *c
;
2676 /* NaN plus anything is a NaN. */
2687 /* Infinity minus infinity is a NaN.
2688 Test for adding infinities of opposite signs. */
2689 if (eisinf (a
) && eisinf (b
)
2690 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2692 mtherr ("esub", INVALID
);
2701 /* Arithmetic common to both addition and subtraction. */
2705 unsigned EMUSHORT
*a
, *b
, *c
;
2707 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2709 EMULONG lt
, lta
, ltb
;
2730 /* compare exponents */
2735 { /* put the larger number in bi */
2745 if (lt
< (EMULONG
) (-NBITS
- 1))
2746 goto done
; /* answer same as larger addend */
2748 lost
= eshift (ai
, k
); /* shift the smaller number down */
2752 /* exponents were the same, so must compare significands */
2755 { /* the numbers are identical in magnitude */
2756 /* if different signs, result is zero */
2762 /* if same sign, result is double */
2763 /* double denormalized tiny number */
2764 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2769 /* add 1 to exponent unless both are zero! */
2770 for (j
= 1; j
< NI
- 1; j
++)
2786 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2790 { /* put the larger number in bi */
2806 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2812 /* Divide: C = B/A, all e type. */
2816 unsigned EMUSHORT
*a
, *b
, *c
;
2818 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2820 EMULONG lt
, lta
, ltb
;
2822 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2823 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2824 sign
= eisneg(a
) ^ eisneg(b
);
2827 /* Return any NaN input. */
2838 /* Zero over zero, or infinity over infinity, is a NaN. */
2839 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2840 || (eisinf (a
) && eisinf (b
)))
2842 mtherr ("ediv", INVALID
);
2847 /* Infinity over anything else is infinity. */
2854 /* Anything else over infinity is zero. */
2866 { /* See if numerator is zero. */
2867 for (i
= 1; i
< NI
- 1; i
++)
2871 ltb
-= enormlz (bi
);
2881 { /* possible divide by zero */
2882 for (i
= 1; i
< NI
- 1; i
++)
2886 lta
-= enormlz (ai
);
2890 /* Divide by zero is not an invalid operation.
2891 It is a divide-by-zero operation! */
2893 mtherr ("ediv", SING
);
2899 /* calculate exponent */
2900 lt
= ltb
- lta
+ EXONE
;
2901 emdnorm (bi
, i
, 0, lt
, 64);
2908 && (ecmp (c
, ezero
) != 0)
2911 *(c
+(NE
-1)) |= 0x8000;
2913 *(c
+(NE
-1)) &= ~0x8000;
2916 /* Multiply e-types A and B, return e-type product C. */
2920 unsigned EMUSHORT
*a
, *b
, *c
;
2922 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2924 EMULONG lt
, lta
, ltb
;
2926 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2927 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2928 sign
= eisneg(a
) ^ eisneg(b
);
2931 /* NaN times anything is the same NaN. */
2942 /* Zero times infinity is a NaN. */
2943 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2944 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2946 mtherr ("emul", INVALID
);
2951 /* Infinity times anything else is infinity. */
2953 if (eisinf (a
) || eisinf (b
))
2965 for (i
= 1; i
< NI
- 1; i
++)
2969 lta
-= enormlz (ai
);
2980 for (i
= 1; i
< NI
- 1; i
++)
2984 ltb
-= enormlz (bi
);
2993 /* Multiply significands */
2995 /* calculate exponent */
2996 lt
= lta
+ ltb
- (EXONE
- 1);
2997 emdnorm (bi
, j
, 0, lt
, 64);
3004 && (ecmp (c
, ezero
) != 0)
3007 *(c
+(NE
-1)) |= 0x8000;
3009 *(c
+(NE
-1)) &= ~0x8000;
3012 /* Convert double precision PE to e-type Y. */
3016 unsigned EMUSHORT
*pe
, *y
;
3025 ibmtoe (pe
, y
, DFmode
);
3030 c4xtoe (pe
, y
, HFmode
);
3033 register unsigned EMUSHORT r
;
3034 register unsigned EMUSHORT
*e
, *p
;
3035 unsigned EMUSHORT yy
[NI
];
3039 denorm
= 0; /* flag if denormalized number */
3041 if (! REAL_WORDS_BIG_ENDIAN
)
3047 yy
[M
] = (r
& 0x0f) | 0x10;
3048 r
&= ~0x800f; /* strip sign and 4 significand bits */
3053 if (! REAL_WORDS_BIG_ENDIAN
)
3055 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3056 || (pe
[1] != 0) || (pe
[0] != 0))
3058 enan (y
, yy
[0] != 0);
3064 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3065 || (pe
[2] != 0) || (pe
[3] != 0))
3067 enan (y
, yy
[0] != 0);
3078 #endif /* INFINITY */
3080 /* If zero exponent, then the significand is denormalized.
3081 So take back the understood high significand bit. */
3092 if (! REAL_WORDS_BIG_ENDIAN
)
3109 /* If zero exponent, then normalize the significand. */
3110 if ((k
= enormlz (yy
)) > NBITS
)
3113 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3116 #endif /* not C4X */
3117 #endif /* not IBM */
3118 #endif /* not DEC */
3121 /* Convert double extended precision float PE to e type Y. */
3125 unsigned EMUSHORT
*pe
, *y
;
3127 unsigned EMUSHORT yy
[NI
];
3128 unsigned EMUSHORT
*e
, *p
, *q
;
3133 for (i
= 0; i
< NE
- 5; i
++)
3135 /* This precision is not ordinarily supported on DEC or IBM. */
3137 for (i
= 0; i
< 5; i
++)
3141 p
= &yy
[0] + (NE
- 1);
3144 for (i
= 0; i
< 5; i
++)
3148 if (! REAL_WORDS_BIG_ENDIAN
)
3150 for (i
= 0; i
< 5; i
++)
3153 /* For denormal long double Intel format, shift significand up one
3154 -- but only if the top significand bit is zero. A top bit of 1
3155 is "pseudodenormal" when the exponent is zero. */
3156 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3158 unsigned EMUSHORT temp
[NI
];
3168 p
= &yy
[0] + (NE
- 1);
3169 #ifdef ARM_EXTENDED_IEEE_FORMAT
3170 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3171 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3177 for (i
= 0; i
< 4; i
++)
3182 /* Point to the exponent field and check max exponent cases. */
3184 if ((*p
& 0x7fff) == 0x7fff)
3187 if (! REAL_WORDS_BIG_ENDIAN
)
3189 for (i
= 0; i
< 4; i
++)
3191 if ((i
!= 3 && pe
[i
] != 0)
3192 /* Anything but 0x8000 here, including 0, is a NaN. */
3193 || (i
== 3 && pe
[i
] != 0x8000))
3195 enan (y
, (*p
& 0x8000) != 0);
3202 #ifdef ARM_EXTENDED_IEEE_FORMAT
3203 for (i
= 2; i
<= 5; i
++)
3207 enan (y
, (*p
& 0x8000) != 0);
3212 /* In Motorola extended precision format, the most significant
3213 bit of an infinity mantissa could be either 1 or 0. It is
3214 the lower order bits that tell whether the value is a NaN. */
3215 if ((pe
[2] & 0x7fff) != 0)
3218 for (i
= 3; i
<= 5; i
++)
3223 enan (y
, (*p
& 0x8000) != 0);
3227 #endif /* not ARM */
3236 #endif /* INFINITY */
3239 for (i
= 0; i
< NE
; i
++)
3243 /* Convert 128-bit long double precision float PE to e type Y. */
3247 unsigned EMUSHORT
*pe
, *y
;
3249 register unsigned EMUSHORT r
;
3250 unsigned EMUSHORT
*e
, *p
;
3251 unsigned EMUSHORT yy
[NI
];
3258 if (! REAL_WORDS_BIG_ENDIAN
)
3270 if (! REAL_WORDS_BIG_ENDIAN
)
3272 for (i
= 0; i
< 7; i
++)
3276 enan (y
, yy
[0] != 0);
3283 for (i
= 1; i
< 8; i
++)
3287 enan (y
, yy
[0] != 0);
3299 #endif /* INFINITY */
3303 if (! REAL_WORDS_BIG_ENDIAN
)
3305 for (i
= 0; i
< 7; i
++)
3311 for (i
= 0; i
< 7; i
++)
3315 /* If denormal, remove the implied bit; else shift down 1. */
3328 /* Convert single precision float PE to e type Y. */
3332 unsigned EMUSHORT
*pe
, *y
;
3336 ibmtoe (pe
, y
, SFmode
);
3342 c4xtoe (pe
, y
, QFmode
);
3346 register unsigned EMUSHORT r
;
3347 register unsigned EMUSHORT
*e
, *p
;
3348 unsigned EMUSHORT yy
[NI
];
3352 denorm
= 0; /* flag if denormalized number */
3355 if (! REAL_WORDS_BIG_ENDIAN
)
3365 yy
[M
] = (r
& 0x7f) | 0200;
3366 r
&= ~0x807f; /* strip sign and 7 significand bits */
3371 if (REAL_WORDS_BIG_ENDIAN
)
3373 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3375 enan (y
, yy
[0] != 0);
3381 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3383 enan (y
, yy
[0] != 0);
3394 #endif /* INFINITY */
3396 /* If zero exponent, then the significand is denormalized.
3397 So take back the understood high significand bit. */
3410 if (! REAL_WORDS_BIG_ENDIAN
)
3420 { /* if zero exponent, then normalize the significand */
3421 if ((k
= enormlz (yy
)) > NBITS
)
3424 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3427 #endif /* not C4X */
3428 #endif /* not IBM */
3431 /* Convert e-type X to IEEE 128-bit long double format E. */
3435 unsigned EMUSHORT
*x
, *e
;
3437 unsigned EMUSHORT xi
[NI
];
3444 make_nan (e
, eisneg (x
), TFmode
);
3449 exp
= (EMULONG
) xi
[E
];
3454 /* round off to nearest or even */
3457 emdnorm (xi
, 0, 0, exp
, 64);
3463 /* Convert exploded e-type X, that has already been rounded to
3464 113-bit precision, to IEEE 128-bit long double format Y. */
3468 unsigned EMUSHORT
*a
, *b
;
3470 register unsigned EMUSHORT
*p
, *q
;
3471 unsigned EMUSHORT i
;
3476 make_nan (b
, eiisneg (a
), TFmode
);
3481 if (REAL_WORDS_BIG_ENDIAN
)
3484 q
= b
+ 7; /* point to output exponent */
3486 /* If not denormal, delete the implied bit. */
3491 /* combine sign and exponent */
3493 if (REAL_WORDS_BIG_ENDIAN
)
3496 *q
++ = *p
++ | 0x8000;
3503 *q
-- = *p
++ | 0x8000;
3507 /* skip over guard word */
3509 /* move the significand */
3510 if (REAL_WORDS_BIG_ENDIAN
)
3512 for (i
= 0; i
< 7; i
++)
3517 for (i
= 0; i
< 7; i
++)
3522 /* Convert e-type X to IEEE double extended format E. */
3526 unsigned EMUSHORT
*x
, *e
;
3528 unsigned EMUSHORT xi
[NI
];
3535 make_nan (e
, eisneg (x
), XFmode
);
3540 /* adjust exponent for offset */
3541 exp
= (EMULONG
) xi
[E
];
3546 /* round off to nearest or even */
3549 emdnorm (xi
, 0, 0, exp
, 64);
3555 /* Convert exploded e-type X, that has already been rounded to
3556 64-bit precision, to IEEE double extended format Y. */
3560 unsigned EMUSHORT
*a
, *b
;
3562 register unsigned EMUSHORT
*p
, *q
;
3563 unsigned EMUSHORT i
;
3568 make_nan (b
, eiisneg (a
), XFmode
);
3572 /* Shift denormal long double Intel format significand down one bit. */
3573 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3583 if (REAL_WORDS_BIG_ENDIAN
)
3587 q
= b
+ 4; /* point to output exponent */
3588 #if LONG_DOUBLE_TYPE_SIZE == 96
3589 /* Clear the last two bytes of 12-byte Intel format */
3595 /* combine sign and exponent */
3599 *q
++ = *p
++ | 0x8000;
3606 *q
-- = *p
++ | 0x8000;
3611 if (REAL_WORDS_BIG_ENDIAN
)
3613 #ifdef ARM_EXTENDED_IEEE_FORMAT
3614 /* The exponent is in the lowest 15 bits of the first word. */
3615 *q
++ = i
? 0x8000 : 0;
3619 *q
++ = *p
++ | 0x8000;
3628 *q
-- = *p
++ | 0x8000;
3633 /* skip over guard word */
3635 /* move the significand */
3637 for (i
= 0; i
< 4; i
++)
3641 for (i
= 0; i
< 4; i
++)
3645 if (REAL_WORDS_BIG_ENDIAN
)
3647 for (i
= 0; i
< 4; i
++)
3655 /* Intel long double infinity significand. */
3663 for (i
= 0; i
< 4; i
++)
3669 /* e type to double precision. */
3672 /* Convert e-type X to DEC-format double E. */
3676 unsigned EMUSHORT
*x
, *e
;
3678 etodec (x
, e
); /* see etodec.c */
3681 /* Convert exploded e-type X, that has already been rounded to
3682 56-bit double precision, to DEC double Y. */
3686 unsigned EMUSHORT
*x
, *y
;
3693 /* Convert e-type X to IBM 370-format double E. */
3697 unsigned EMUSHORT
*x
, *e
;
3699 etoibm (x
, e
, DFmode
);
3702 /* Convert exploded e-type X, that has already been rounded to
3703 56-bit precision, to IBM 370 double Y. */
3707 unsigned EMUSHORT
*x
, *y
;
3709 toibm (x
, y
, DFmode
);
3712 #else /* it's neither DEC nor IBM */
3714 /* Convert e-type X to C4X-format long double E. */
3718 unsigned EMUSHORT
*x
, *e
;
3720 etoc4x (x
, e
, HFmode
);
3723 /* Convert exploded e-type X, that has already been rounded to
3724 56-bit precision, to IBM 370 double Y. */
3728 unsigned EMUSHORT
*x
, *y
;
3730 toc4x (x
, y
, HFmode
);
3733 #else /* it's neither DEC nor IBM nor C4X */
3735 /* Convert e-type X to IEEE double E. */
3739 unsigned EMUSHORT
*x
, *e
;
3741 unsigned EMUSHORT xi
[NI
];
3748 make_nan (e
, eisneg (x
), DFmode
);
3753 /* adjust exponent for offsets */
3754 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3759 /* round off to nearest or even */
3762 emdnorm (xi
, 0, 0, exp
, 64);
3768 /* Convert exploded e-type X, that has already been rounded to
3769 53-bit precision, to IEEE double Y. */
3773 unsigned EMUSHORT
*x
, *y
;
3775 unsigned EMUSHORT i
;
3776 unsigned EMUSHORT
*p
;
3781 make_nan (y
, eiisneg (x
), DFmode
);
3787 if (! REAL_WORDS_BIG_ENDIAN
)
3790 *y
= 0; /* output high order */
3792 *y
= 0x8000; /* output sign bit */
3795 if (i
>= (unsigned int) 2047)
3797 /* Saturate at largest number less than infinity. */
3800 if (! REAL_WORDS_BIG_ENDIAN
)
3814 *y
|= (unsigned EMUSHORT
) 0x7fef;
3815 if (! REAL_WORDS_BIG_ENDIAN
)
3840 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3841 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3842 if (! REAL_WORDS_BIG_ENDIAN
)
3857 #endif /* not C4X */
3858 #endif /* not IBM */
3859 #endif /* not DEC */
3863 /* e type to single precision. */
3866 /* Convert e-type X to IBM 370 float E. */
3870 unsigned EMUSHORT
*x
, *e
;
3872 etoibm (x
, e
, SFmode
);
3875 /* Convert exploded e-type X, that has already been rounded to
3876 float precision, to IBM 370 float Y. */
3880 unsigned EMUSHORT
*x
, *y
;
3882 toibm (x
, y
, SFmode
);
3888 /* Convert e-type X to C4X float E. */
3892 unsigned EMUSHORT
*x
, *e
;
3894 etoc4x (x
, e
, QFmode
);
3897 /* Convert exploded e-type X, that has already been rounded to
3898 float precision, to IBM 370 float Y. */
3902 unsigned EMUSHORT
*x
, *y
;
3904 toc4x (x
, y
, QFmode
);
3909 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3913 unsigned EMUSHORT
*x
, *e
;
3916 unsigned EMUSHORT xi
[NI
];
3922 make_nan (e
, eisneg (x
), SFmode
);
3927 /* adjust exponent for offsets */
3928 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3933 /* round off to nearest or even */
3936 emdnorm (xi
, 0, 0, exp
, 64);
3942 /* Convert exploded e-type X, that has already been rounded to
3943 float precision, to IEEE float Y. */
3947 unsigned EMUSHORT
*x
, *y
;
3949 unsigned EMUSHORT i
;
3950 unsigned EMUSHORT
*p
;
3955 make_nan (y
, eiisneg (x
), SFmode
);
3961 if (! REAL_WORDS_BIG_ENDIAN
)
3967 *y
= 0; /* output high order */
3969 *y
= 0x8000; /* output sign bit */
3972 /* Handle overflow cases. */
3976 *y
|= (unsigned EMUSHORT
) 0x7f80;
3981 if (! REAL_WORDS_BIG_ENDIAN
)
3989 #else /* no INFINITY */
3990 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3995 if (! REAL_WORDS_BIG_ENDIAN
)
4006 #endif /* no INFINITY */
4018 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4019 /* High order output already has sign bit set. */
4025 if (! REAL_WORDS_BIG_ENDIAN
)
4034 #endif /* not C4X */
4035 #endif /* not IBM */
4037 /* Compare two e type numbers.
4041 -2 if either a or b is a NaN. */
4045 unsigned EMUSHORT
*a
, *b
;
4047 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4048 register unsigned EMUSHORT
*p
, *q
;
4053 if (eisnan (a
) || eisnan (b
))
4062 { /* the signs are different */
4064 for (i
= 1; i
< NI
- 1; i
++)
4078 /* both are the same sign */
4093 return (0); /* equality */
4097 if (*(--p
) > *(--q
))
4098 return (msign
); /* p is bigger */
4100 return (-msign
); /* p is littler */
4103 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4107 unsigned EMUSHORT
*x
, *y
;
4113 /* Convert HOST_WIDE_INT LP to e type Y. */
4118 unsigned EMUSHORT
*y
;
4120 unsigned EMUSHORT yi
[NI
];
4121 unsigned HOST_WIDE_INT ll
;
4127 /* make it positive */
4128 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4129 yi
[0] = 0xffff; /* put correct sign in the e type number */
4133 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4135 /* move the long integer to yi significand area */
4136 #if HOST_BITS_PER_WIDE_INT == 64
4137 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4138 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4139 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4140 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4141 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4143 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4144 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4145 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4148 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4149 ecleaz (yi
); /* it was zero */
4151 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4152 emovo (yi
, y
); /* output the answer */
4155 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4159 unsigned HOST_WIDE_INT
*lp
;
4160 unsigned EMUSHORT
*y
;
4162 unsigned EMUSHORT yi
[NI
];
4163 unsigned HOST_WIDE_INT ll
;
4169 /* move the long integer to ayi 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 */
4190 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4191 part FRAC of e-type (packed internal format) floating point input X.
4192 The integer output I has the sign of the input, except that
4193 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4194 The output e-type fraction FRAC is the positive fractional
4199 unsigned EMUSHORT
*x
;
4201 unsigned EMUSHORT
*frac
;
4203 unsigned EMUSHORT xi
[NI
];
4205 unsigned HOST_WIDE_INT ll
;
4208 k
= (int) xi
[E
] - (EXONE
- 1);
4211 /* if exponent <= 0, integer = 0 and real output is fraction */
4216 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4218 /* long integer overflow: output large integer
4219 and correct fraction */
4221 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4224 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4225 /* In this case, let it overflow and convert as if unsigned. */
4226 euifrac (x
, &ll
, frac
);
4227 *i
= (HOST_WIDE_INT
) ll
;
4230 /* In other cases, return the largest positive integer. */
4231 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4236 warning ("overflow on truncation to integer");
4240 /* Shift more than 16 bits: first shift up k-16 mod 16,
4241 then shift up by 16's. */
4242 j
= k
- ((k
>> 4) << 4);
4249 ll
= (ll
<< 16) | xi
[M
];
4251 while ((k
-= 16) > 0);
4258 /* shift not more than 16 bits */
4260 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4267 if ((k
= enormlz (xi
)) > NBITS
)
4270 xi
[E
] -= (unsigned EMUSHORT
) k
;
4276 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4277 FRAC of e-type X. A negative input yields integer output = 0 but
4278 correct fraction. */
4281 euifrac (x
, i
, frac
)
4282 unsigned EMUSHORT
*x
;
4283 unsigned HOST_WIDE_INT
*i
;
4284 unsigned EMUSHORT
*frac
;
4286 unsigned HOST_WIDE_INT ll
;
4287 unsigned EMUSHORT xi
[NI
];
4291 k
= (int) xi
[E
] - (EXONE
- 1);
4294 /* if exponent <= 0, integer = 0 and argument is fraction */
4299 if (k
> HOST_BITS_PER_WIDE_INT
)
4301 /* Long integer overflow: output large integer
4302 and correct fraction.
4303 Note, the BSD microvax compiler says that ~(0UL)
4304 is a syntax error. */
4308 warning ("overflow on truncation to unsigned integer");
4312 /* Shift more than 16 bits: first shift up k-16 mod 16,
4313 then shift up by 16's. */
4314 j
= k
- ((k
>> 4) << 4);
4321 ll
= (ll
<< 16) | xi
[M
];
4323 while ((k
-= 16) > 0);
4328 /* shift not more than 16 bits */
4330 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4333 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4339 if ((k
= enormlz (xi
)) > NBITS
)
4342 xi
[E
] -= (unsigned EMUSHORT
) k
;
4347 /* Shift the significand of exploded e-type X up or down by SC bits. */
4351 unsigned EMUSHORT
*x
;
4354 unsigned EMUSHORT lost
;
4355 unsigned EMUSHORT
*p
;
4368 lost
|= *p
; /* remember lost bits */
4409 return ((int) lost
);
4412 /* Shift normalize the significand area of exploded e-type X.
4413 Return the shift count (up = positive). */
4417 unsigned EMUSHORT x
[];
4419 register unsigned EMUSHORT
*p
;
4428 return (0); /* already normalized */
4434 /* With guard word, there are NBITS+16 bits available.
4435 Return true if all are zero. */
4439 /* see if high byte is zero */
4440 while ((*p
& 0xff00) == 0)
4445 /* now shift 1 bit at a time */
4446 while ((*p
& 0x8000) == 0)
4452 mtherr ("enormlz", UNDERFLOW
);
4458 /* Normalize by shifting down out of the high guard word
4459 of the significand */
4474 mtherr ("enormlz", OVERFLOW
);
4481 /* Powers of ten used in decimal <-> binary conversions. */
4486 #if LONG_DOUBLE_TYPE_SIZE == 128
4487 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4489 {0x6576, 0x4a92, 0x804a, 0x153f,
4490 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4491 {0x6a32, 0xce52, 0x329a, 0x28ce,
4492 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4493 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4494 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4495 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4496 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4497 {0x851e, 0xeab7, 0x98fe, 0x901b,
4498 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4499 {0x0235, 0x0137, 0x36b1, 0x336c,
4500 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4501 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4502 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4503 {0x0000, 0x0000, 0x0000, 0x0000,
4504 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4505 {0x0000, 0x0000, 0x0000, 0x0000,
4506 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4507 {0x0000, 0x0000, 0x0000, 0x0000,
4508 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4509 {0x0000, 0x0000, 0x0000, 0x0000,
4510 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4511 {0x0000, 0x0000, 0x0000, 0x0000,
4512 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4513 {0x0000, 0x0000, 0x0000, 0x0000,
4514 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4517 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4519 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4520 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4521 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4522 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4523 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4524 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4525 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4526 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4527 {0xa23e, 0x5308, 0xfefb, 0x1155,
4528 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4529 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4530 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4531 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4532 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4533 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4534 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4535 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4536 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4537 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4538 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4539 {0xc155, 0xa4a8, 0x404e, 0x6113,
4540 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4541 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4542 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4543 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4544 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4547 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4548 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4550 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4551 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4552 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4553 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4554 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4555 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4556 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4557 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4558 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4559 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4560 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4561 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4562 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4565 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4567 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4568 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4569 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4570 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4571 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4572 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4573 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4574 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4575 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4576 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4577 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4578 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4579 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4583 /* Convert float value X to ASCII string STRING with NDIG digits after
4584 the decimal point. */
4587 e24toasc (x
, string
, ndigs
)
4588 unsigned EMUSHORT x
[];
4592 unsigned EMUSHORT w
[NI
];
4595 etoasc (w
, string
, ndigs
);
4598 /* Convert double value X to ASCII string STRING with NDIG digits after
4599 the decimal point. */
4602 e53toasc (x
, string
, ndigs
)
4603 unsigned EMUSHORT x
[];
4607 unsigned EMUSHORT w
[NI
];
4610 etoasc (w
, string
, ndigs
);
4613 /* Convert double extended value X to ASCII string STRING with NDIG digits
4614 after the decimal point. */
4617 e64toasc (x
, string
, ndigs
)
4618 unsigned EMUSHORT x
[];
4622 unsigned EMUSHORT w
[NI
];
4625 etoasc (w
, string
, ndigs
);
4628 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4629 after the decimal point. */
4632 e113toasc (x
, string
, ndigs
)
4633 unsigned EMUSHORT x
[];
4637 unsigned EMUSHORT w
[NI
];
4640 etoasc (w
, string
, ndigs
);
4643 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4644 the decimal point. */
4646 static char wstring
[80]; /* working storage for ASCII output */
4649 etoasc (x
, string
, ndigs
)
4650 unsigned EMUSHORT x
[];
4655 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4656 unsigned EMUSHORT
*p
, *r
, *ten
;
4657 unsigned EMUSHORT sign
;
4658 int i
, j
, k
, expon
, rndsav
;
4660 unsigned EMUSHORT m
;
4671 sprintf (wstring
, " NaN ");
4675 rndprc
= NBITS
; /* set to full precision */
4676 emov (x
, y
); /* retain external format */
4677 if (y
[NE
- 1] & 0x8000)
4680 y
[NE
- 1] &= 0x7fff;
4687 ten
= &etens
[NTEN
][0];
4689 /* Test for zero exponent */
4692 for (k
= 0; k
< NE
- 1; k
++)
4695 goto tnzro
; /* denormalized number */
4697 goto isone
; /* valid all zeros */
4701 /* Test for infinity. */
4702 if (y
[NE
- 1] == 0x7fff)
4705 sprintf (wstring
, " -Infinity ");
4707 sprintf (wstring
, " Infinity ");
4711 /* Test for exponent nonzero but significand denormalized.
4712 * This is an error condition.
4714 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4716 mtherr ("etoasc", DOMAIN
);
4717 sprintf (wstring
, "NaN");
4721 /* Compare to 1.0 */
4730 { /* Number is greater than 1 */
4731 /* Convert significand to an integer and strip trailing decimal zeros. */
4733 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4735 p
= &etens
[NTEN
- 4][0];
4741 for (j
= 0; j
< NE
- 1; j
++)
4754 /* Rescale from integer significand */
4755 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4757 /* Find power of 10 */
4761 /* An unordered compare result shouldn't happen here. */
4762 while (ecmp (ten
, u
) <= 0)
4764 if (ecmp (p
, u
) <= 0)
4777 { /* Number is less than 1.0 */
4778 /* Pad significand with trailing decimal zeros. */
4781 while ((y
[NE
- 2] & 0x8000) == 0)
4790 for (i
= 0; i
< NDEC
+ 1; i
++)
4792 if ((w
[NI
- 1] & 0x7) != 0)
4794 /* multiply by 10 */
4807 if (eone
[NE
- 1] <= u
[1])
4819 while (ecmp (eone
, w
) > 0)
4821 if (ecmp (p
, w
) >= 0)
4836 /* Find the first (leading) digit. */
4842 digit
= equot
[NI
- 1];
4843 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4851 digit
= equot
[NI
- 1];
4859 /* Examine number of digits requested by caller. */
4877 *s
++ = (char)digit
+ '0';
4880 /* Generate digits after the decimal point. */
4881 for (k
= 0; k
<= ndigs
; k
++)
4883 /* multiply current number by 10, without normalizing */
4890 *s
++ = (char) equot
[NI
- 1] + '0';
4892 digit
= equot
[NI
- 1];
4895 /* round off the ASCII string */
4898 /* Test for critical rounding case in ASCII output. */
4902 if (ecmp (t
, ezero
) != 0)
4903 goto roun
; /* round to nearest */
4904 if ((*(s
- 1) & 1) == 0)
4905 goto doexp
; /* round to even */
4907 /* Round up and propagate carry-outs */
4911 /* Carry out to most significant digit? */
4918 /* Most significant digit carries to 10? */
4926 /* Round up and carry out from less significant digits */
4938 sprintf (ss, "e+%d", expon);
4940 sprintf (ss, "e%d", expon);
4942 sprintf (ss
, "e%d", expon
);
4945 /* copy out the working string */
4948 while (*ss
== ' ') /* strip possible leading space */
4950 while ((*s
++ = *ss
++) != '\0')
4955 /* Convert ASCII string to floating point.
4957 Numeric input is a free format decimal number of any length, with
4958 or without decimal point. Entering E after the number followed by an
4959 integer number causes the second number to be interpreted as a power of
4960 10 to be multiplied by the first number (i.e., "scientific" notation). */
4962 /* Convert ASCII string S to single precision float value Y. */
4967 unsigned EMUSHORT
*y
;
4973 /* Convert ASCII string S to double precision value Y. */
4978 unsigned EMUSHORT
*y
;
4980 #if defined(DEC) || defined(IBM)
4992 /* Convert ASCII string S to double extended value Y. */
4997 unsigned EMUSHORT
*y
;
5002 /* Convert ASCII string S to 128-bit long double Y. */
5007 unsigned EMUSHORT
*y
;
5009 asctoeg (s
, y
, 113);
5012 /* Convert ASCII string S to e type Y. */
5017 unsigned EMUSHORT
*y
;
5019 asctoeg (s
, y
, NBITS
);
5022 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5023 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5026 asctoeg (ss
, y
, oprec
)
5028 unsigned EMUSHORT
*y
;
5031 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5032 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5033 int k
, trail
, c
, rndsav
;
5035 unsigned EMUSHORT nsign
, *p
;
5036 char *sp
, *s
, *lstr
;
5039 /* Copy the input string. */
5040 lstr
= (char *) alloca (strlen (ss
) + 1);
5043 while (*s
== ' ') /* skip leading spaces */
5046 while ((*sp
++ = *s
++) != '\0')
5051 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5058 rndprc
= NBITS
; /* Set to full precision */
5070 if (*s
>= '0' && *s
<= '9')
5076 if ((k
>= 0) && (k
< base
))
5078 /* Ignore leading zeros */
5079 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5081 /* Identify and strip trailing zeros after the decimal point. */
5082 if ((trail
== 0) && (decflg
!= 0))
5085 while ((*sp
>= '0' && *sp
<= '9')
5086 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5087 || (*sp
>= 'A' && *sp
<= 'F'))))
5089 /* Check for syntax error */
5091 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5092 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5094 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5105 /* If enough digits were given to more than fill up the yy register,
5106 continuing until overflow into the high guard word yy[2]
5107 guarantees that there will be a roundoff bit at the top
5108 of the low guard word after normalization. */
5115 nexp
+= 4; /* count digits after decimal point */
5117 eshup1 (yy
); /* multiply current number by 16 */
5125 nexp
+= 1; /* count digits after decimal point */
5127 eshup1 (yy
); /* multiply current number by 10 */
5134 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5139 /* Mark any lost non-zero digit. */
5141 /* Count lost digits before the decimal point. */
5163 case '.': /* decimal point */
5193 mtherr ("asctoe", DOMAIN
);
5202 /* Exponent interpretation */
5204 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5205 for (k
= 0; k
< NI
; k
++)
5216 /* check for + or - */
5224 while ((*s
>= '0') && (*s
<= '9'))
5233 if ((exp
> MAXDECEXP
) && (base
== 10))
5237 yy
[E
] = 0x7fff; /* infinity */
5240 if ((exp
< MINDECEXP
) && (base
== 10))
5250 /* Base 16 hexadecimal floating constant. */
5251 if ((k
= enormlz (yy
)) > NBITS
)
5256 /* Adjust the exponent. NEXP is the number of hex digits,
5257 EXP is a power of 2. */
5258 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5268 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5269 while ((nexp
> 0) && (yy
[2] == 0))
5281 if ((k
= enormlz (yy
)) > NBITS
)
5286 lexp
= (EXONE
- 1 + NBITS
) - k
;
5287 emdnorm (yy
, lost
, 0, lexp
, 64);
5290 /* Convert to external format:
5292 Multiply by 10**nexp. If precision is 64 bits,
5293 the maximum relative error incurred in forming 10**n
5294 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5295 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5296 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5311 /* Punt. Can't handle this without 2 divides. */
5312 emovi (etens
[0], tt
);
5319 p
= &etens
[NTEN
][0];
5329 while (exp
<= MAXP
);
5348 /* Round and convert directly to the destination type */
5350 lexp
-= EXONE
- 0x3ff;
5352 else if (oprec
== 24 || oprec
== 32)
5353 lexp
-= (EXONE
- 0x7f);
5356 else if (oprec
== 24 || oprec
== 56)
5357 lexp
-= EXONE
- (0x41 << 2);
5359 else if (oprec
== 24)
5360 lexp
-= EXONE
- 0177;
5364 else if (oprec
== 56)
5365 lexp
-= EXONE
- 0201;
5368 emdnorm (yy
, lost
, 0, lexp
, 64);
5378 todec (yy
, y
); /* see etodec.c */
5383 toibm (yy
, y
, DFmode
);
5388 toc4x (yy
, y
, HFmode
);
5412 /* Return Y = largest integer not greater than X (truncated toward minus
5415 static unsigned EMUSHORT bmask
[] =
5438 unsigned EMUSHORT x
[], y
[];
5440 register unsigned EMUSHORT
*p
;
5442 unsigned EMUSHORT f
[NE
];
5444 emov (x
, f
); /* leave in external format */
5445 expon
= (int) f
[NE
- 1];
5446 e
= (expon
& 0x7fff) - (EXONE
- 1);
5452 /* number of bits to clear out */
5464 /* clear the remaining bits */
5466 /* truncate negatives toward minus infinity */
5469 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5471 for (i
= 0; i
< NE
- 1; i
++)
5483 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5484 For example, 1.1 = 0.55 * 2^1. */
5488 unsigned EMUSHORT x
[];
5490 unsigned EMUSHORT s
[];
5492 unsigned EMUSHORT xi
[NI
];
5496 /* Handle denormalized numbers properly using long integer exponent. */
5497 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5505 *exp
= (int) (li
- 0x3ffe);
5508 /* Return e type Y = X * 2^PWR2. */
5512 unsigned EMUSHORT x
[];
5514 unsigned EMUSHORT y
[];
5516 unsigned EMUSHORT xi
[NI
];
5524 emdnorm (xi
, i
, i
, li
, 64);
5529 /* C = remainder after dividing B by A, all e type values.
5530 Least significant integer quotient bits left in EQUOT. */
5534 unsigned EMUSHORT a
[], b
[], c
[];
5536 unsigned EMUSHORT den
[NI
], num
[NI
];
5540 || (ecmp (a
, ezero
) == 0)
5548 if (ecmp (a
, ezero
) == 0)
5550 mtherr ("eremain", SING
);
5556 eiremain (den
, num
);
5557 /* Sign of remainder = sign of quotient */
5565 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5566 remainder in NUM. */
5570 unsigned EMUSHORT den
[], num
[];
5573 unsigned EMUSHORT j
;
5576 ld
-= enormlz (den
);
5578 ln
-= enormlz (num
);
5582 if (ecmpm (den
, num
) <= 0)
5594 emdnorm (num
, 0, 0, ln
, 0);
5597 /* Report an error condition CODE encountered in function NAME. */
5607 /* The string passed by the calling program is supposed to be the
5608 name of the function in which the error occurred.
5609 The code argument selects which error message string will be printed. */
5615 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5616 case SING
: warning ("%s: function singularity" , name
); break;
5617 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5618 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5619 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5620 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5621 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5626 /* Set global error message word */
5631 /* Convert DEC double precision D to e type E. */
5635 unsigned EMUSHORT
*d
;
5636 unsigned EMUSHORT
*e
;
5638 unsigned EMUSHORT y
[NI
];
5639 register unsigned EMUSHORT r
, *p
;
5641 ecleaz (y
); /* start with a zero */
5642 p
= y
; /* point to our number */
5643 r
= *d
; /* get DEC exponent word */
5644 if (*d
& (unsigned int) 0x8000)
5645 *p
= 0xffff; /* fill in our sign */
5646 ++p
; /* bump pointer to our exponent word */
5647 r
&= 0x7fff; /* strip the sign bit */
5648 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5652 r
>>= 7; /* shift exponent word down 7 bits */
5653 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5654 /* add our e type exponent offset */
5655 *p
++ = r
; /* to form our exponent */
5657 r
= *d
++; /* now do the high order mantissa */
5658 r
&= 0177; /* strip off the DEC exponent and sign bits */
5659 r
|= 0200; /* the DEC understood high order mantissa bit */
5660 *p
++ = r
; /* put result in our high guard word */
5662 *p
++ = *d
++; /* fill in the rest of our mantissa */
5666 eshdn8 (y
); /* shift our mantissa down 8 bits */
5671 /* Convert e type X to DEC double precision D. */
5675 unsigned EMUSHORT
*x
, *d
;
5677 unsigned EMUSHORT xi
[NI
];
5682 /* Adjust exponent for offsets. */
5683 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5684 /* Round off to nearest or even. */
5687 emdnorm (xi
, 0, 0, exp
, 64);
5692 /* Convert exploded e-type X, that has already been rounded to
5693 56-bit precision, to DEC format double Y. */
5697 unsigned EMUSHORT
*x
, *y
;
5699 unsigned EMUSHORT i
;
5700 unsigned EMUSHORT
*p
;
5739 /* Convert IBM single/double precision to e type. */
5743 unsigned EMUSHORT
*d
;
5744 unsigned EMUSHORT
*e
;
5745 enum machine_mode mode
;
5747 unsigned EMUSHORT y
[NI
];
5748 register unsigned EMUSHORT r
, *p
;
5751 ecleaz (y
); /* start with a zero */
5752 p
= y
; /* point to our number */
5753 r
= *d
; /* get IBM exponent word */
5754 if (*d
& (unsigned int) 0x8000)
5755 *p
= 0xffff; /* fill in our sign */
5756 ++p
; /* bump pointer to our exponent word */
5757 r
&= 0x7f00; /* strip the sign bit */
5758 r
>>= 6; /* shift exponent word down 6 bits */
5759 /* in fact shift by 8 right and 2 left */
5760 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5761 /* add our e type exponent offset */
5762 *p
++ = r
; /* to form our exponent */
5764 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5765 /* strip off the IBM exponent and sign bits */
5766 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5768 *p
++ = *d
++; /* fill in the rest of our mantissa */
5773 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5776 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5777 /* handle change in RADIX */
5783 /* Convert e type to IBM single/double precision. */
5787 unsigned EMUSHORT
*x
, *d
;
5788 enum machine_mode mode
;
5790 unsigned EMUSHORT xi
[NI
];
5795 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5796 /* round off to nearest or even */
5799 emdnorm (xi
, 0, 0, exp
, 64);
5801 toibm (xi
, d
, mode
);
5806 unsigned EMUSHORT
*x
, *y
;
5807 enum machine_mode mode
;
5809 unsigned EMUSHORT i
;
5810 unsigned EMUSHORT
*p
;
5860 /* Convert C4X single/double precision to e type. */
5864 unsigned EMUSHORT
*d
;
5865 unsigned EMUSHORT
*e
;
5866 enum machine_mode mode
;
5868 unsigned EMUSHORT y
[NI
];
5876 /* Short-circuit the zero case. */
5877 if ((d
[0] == 0x8000)
5879 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5890 ecleaz (y
); /* start with a zero */
5891 r
= d
[0]; /* get sign/exponent part */
5892 if (r
& (unsigned int) 0x0080)
5894 y
[0] = 0xffff; /* fill in our sign */
5902 r
>>= 8; /* Shift exponent word down 8 bits. */
5903 if (r
& 0x80) /* Make the exponent negative if it is. */
5905 r
= r
| (~0 & ~0xff);
5910 /* Now do the high order mantissa. We don't "or" on the high bit
5911 because it is 2 (not 1) and is handled a little differently
5916 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5918 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5928 /* Now do the two's complement on the data. */
5930 carry
= 1; /* Initially add 1 for the two's complement. */
5931 for (i
=size
+ M
; i
> M
; i
--)
5933 if (carry
&& (y
[i
] == 0x0000))
5935 /* We overflowed into the next word, carry is the same. */
5936 y
[i
] = carry
? 0x0000 : 0xffff;
5940 /* No overflow, just invert and add carry. */
5941 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5956 /* Add our e type exponent offset to form our exponent. */
5960 /* Now do the high order mantissa strip off the exponent and sign
5961 bits and add the high 1 bit. */
5962 y
[M
] = d
[0] & 0x7f | 0x80;
5965 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5967 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5977 /* Convert e type to C4X single/double precision. */
5981 unsigned EMUSHORT
*x
, *d
;
5982 enum machine_mode mode
;
5984 unsigned EMUSHORT xi
[NI
];
5990 /* Adjust exponent for offsets. */
5991 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5993 /* Round off to nearest or even. */
5995 rndprc
= mode
== QFmode
? 24 : 32;
5996 emdnorm (xi
, 0, 0, exp
, 64);
5998 toc4x (xi
, d
, mode
);
6003 unsigned EMUSHORT
*x
, *y
;
6004 enum machine_mode mode
;
6011 /* Short-circuit the zero case */
6012 if ((x
[0] == 0) /* Zero exponent and sign */
6014 && (x
[M
] == 0) /* The rest is for zero mantissa */
6016 /* Only check for double if necessary */
6017 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6019 /* We have a zero. Put it into the output and return. */
6032 /* Negative number require a two's complement conversion of the
6038 i
= ((int) x
[1]) - 0x7f;
6040 /* Now add 1 to the inverted data to do the two's complement. */
6050 x
[v
] = carry
? 0x0000 : 0xffff;
6054 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6060 /* The following is a special case. The C4X negative float requires
6061 a zero in the high bit (because the format is (2 - x) x 2^m), so
6062 if a one is in that bit, we have to shift left one to get rid
6063 of it. This only occurs if the number is -1 x 2^m. */
6064 if (x
[M
+1] & 0x8000)
6066 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6067 high sign bit and shift the exponent. */
6074 i
= ((int) x
[1]) - 0x7f;
6077 if ((i
< -128) || (i
> 127))
6092 y
[0] |= ((i
& 0xff) << 8);
6096 y
[0] |= x
[M
] & 0x7f;
6106 /* Output a binary NaN bit pattern in the target machine's format. */
6108 /* If special NaN bit patterns are required, define them in tm.h
6109 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6115 unsigned EMUSHORT TFbignan
[8] =
6116 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6117 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6125 unsigned EMUSHORT XFbignan
[6] =
6126 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6127 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6135 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6136 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6144 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6145 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6151 make_nan (nan
, sign
, mode
)
6152 unsigned EMUSHORT
*nan
;
6154 enum machine_mode mode
;
6157 unsigned EMUSHORT
*p
;
6161 /* Possibly the `reserved operand' patterns on a VAX can be
6162 used like NaN's, but probably not in the same way as IEEE. */
6163 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6166 if (REAL_WORDS_BIG_ENDIAN
)
6174 if (REAL_WORDS_BIG_ENDIAN
)
6182 if (REAL_WORDS_BIG_ENDIAN
)
6191 if (REAL_WORDS_BIG_ENDIAN
)
6201 if (REAL_WORDS_BIG_ENDIAN
)
6202 *nan
++ = (sign
<< 15) | *p
++;
6205 if (! REAL_WORDS_BIG_ENDIAN
)
6206 *nan
= (sign
<< 15) | *p
;
6209 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6210 This is the inverse of the function `etarsingle' invoked by
6211 REAL_VALUE_TO_TARGET_SINGLE. */
6214 ereal_from_float (f
)
6218 unsigned EMUSHORT s
[2];
6219 unsigned EMUSHORT e
[NE
];
6221 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6222 This is the inverse operation to what the function `endian' does. */
6223 if (REAL_WORDS_BIG_ENDIAN
)
6225 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6226 s
[1] = (unsigned EMUSHORT
) f
;
6230 s
[0] = (unsigned EMUSHORT
) f
;
6231 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6233 /* Convert and promote the target float to E-type. */
6235 /* Output E-type to REAL_VALUE_TYPE. */
6241 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6242 This is the inverse of the function `etardouble' invoked by
6243 REAL_VALUE_TO_TARGET_DOUBLE.
6245 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6246 data format, with no holes in the bit packing. The first element
6247 of the input array holds the bits that would come first in the
6248 target computer's memory. */
6251 ereal_from_double (d
)
6255 unsigned EMUSHORT s
[4];
6256 unsigned EMUSHORT e
[NE
];
6258 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6259 if (REAL_WORDS_BIG_ENDIAN
)
6261 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6262 s
[1] = (unsigned EMUSHORT
) d
[0];
6263 #if HOST_BITS_PER_WIDE_INT == 32
6264 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6265 s
[3] = (unsigned EMUSHORT
) d
[1];
6267 /* In this case the entire target double is contained in the
6268 first array element. The second element of the input is
6270 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6271 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6276 /* Target float words are little-endian. */
6277 s
[0] = (unsigned EMUSHORT
) d
[0];
6278 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6279 #if HOST_BITS_PER_WIDE_INT == 32
6280 s
[2] = (unsigned EMUSHORT
) d
[1];
6281 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6283 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6284 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6287 /* Convert target double to E-type. */
6289 /* Output E-type to REAL_VALUE_TYPE. */
6295 /* Convert target computer unsigned 64-bit integer to e-type.
6296 The endian-ness of DImode follows the convention for integers,
6297 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6301 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6302 unsigned EMUSHORT
*e
;
6304 unsigned EMUSHORT yi
[NI
];
6308 if (WORDS_BIG_ENDIAN
)
6310 for (k
= M
; k
< M
+ 4; k
++)
6315 for (k
= M
+ 3; k
>= M
; k
--)
6318 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6319 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6320 ecleaz (yi
); /* it was zero */
6322 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6326 /* Convert target computer signed 64-bit integer to e-type. */
6330 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6331 unsigned EMUSHORT
*e
;
6333 unsigned EMULONG acc
;
6334 unsigned EMUSHORT yi
[NI
];
6335 unsigned EMUSHORT carry
;
6339 if (WORDS_BIG_ENDIAN
)
6341 for (k
= M
; k
< M
+ 4; k
++)
6346 for (k
= M
+ 3; k
>= M
; k
--)
6349 /* Take absolute value */
6355 for (k
= M
+ 3; k
>= M
; k
--)
6357 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6364 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6365 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6366 ecleaz (yi
); /* it was zero */
6368 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6375 /* Convert e-type to unsigned 64-bit int. */
6379 unsigned EMUSHORT
*x
;
6380 unsigned EMUSHORT
*i
;
6382 unsigned EMUSHORT xi
[NI
];
6391 k
= (int) xi
[E
] - (EXONE
- 1);
6394 for (j
= 0; j
< 4; j
++)
6400 for (j
= 0; j
< 4; j
++)
6403 warning ("overflow on truncation to integer");
6408 /* Shift more than 16 bits: first shift up k-16 mod 16,
6409 then shift up by 16's. */
6410 j
= k
- ((k
>> 4) << 4);
6414 if (WORDS_BIG_ENDIAN
)
6425 if (WORDS_BIG_ENDIAN
)
6430 while ((k
-= 16) > 0);
6434 /* shift not more than 16 bits */
6439 if (WORDS_BIG_ENDIAN
)
6458 /* Convert e-type to signed 64-bit int. */
6462 unsigned EMUSHORT
*x
;
6463 unsigned EMUSHORT
*i
;
6465 unsigned EMULONG acc
;
6466 unsigned EMUSHORT xi
[NI
];
6467 unsigned EMUSHORT carry
;
6468 unsigned EMUSHORT
*isave
;
6472 k
= (int) xi
[E
] - (EXONE
- 1);
6475 for (j
= 0; j
< 4; j
++)
6481 for (j
= 0; j
< 4; j
++)
6484 warning ("overflow on truncation to integer");
6490 /* Shift more than 16 bits: first shift up k-16 mod 16,
6491 then shift up by 16's. */
6492 j
= k
- ((k
>> 4) << 4);
6496 if (WORDS_BIG_ENDIAN
)
6507 if (WORDS_BIG_ENDIAN
)
6512 while ((k
-= 16) > 0);
6516 /* shift not more than 16 bits */
6519 if (WORDS_BIG_ENDIAN
)
6535 /* Negate if negative */
6539 if (WORDS_BIG_ENDIAN
)
6541 for (k
= 0; k
< 4; k
++)
6543 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6544 if (WORDS_BIG_ENDIAN
)
6556 /* Longhand square root routine. */
6559 static int esqinited
= 0;
6560 static unsigned short sqrndbit
[NI
];
6564 unsigned EMUSHORT
*x
, *y
;
6566 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6568 int i
, j
, k
, n
, nlups
;
6573 sqrndbit
[NI
- 2] = 1;
6576 /* Check for arg <= 0 */
6577 i
= ecmp (x
, ezero
);
6582 mtherr ("esqrt", DOMAIN
);
6598 /* Bring in the arg and renormalize if it is denormal. */
6600 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6604 /* Divide exponent by 2 */
6606 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6608 /* Adjust if exponent odd */
6618 n
= 8; /* get 8 bits of result per inner loop */
6624 /* bring in next word of arg */
6626 num
[NI
- 1] = xx
[j
+ 3];
6627 /* Do additional bit on last outer loop, for roundoff. */
6630 for (i
= 0; i
< n
; i
++)
6632 /* Next 2 bits of arg */
6635 /* Shift up answer */
6637 /* Make trial divisor */
6638 for (k
= 0; k
< NI
; k
++)
6641 eaddm (sqrndbit
, temp
);
6642 /* Subtract and insert answer bit if it goes in */
6643 if (ecmpm (temp
, num
) <= 0)
6653 /* Adjust for extra, roundoff loop done. */
6654 exp
+= (NBITS
- 1) - rndprc
;
6656 /* Sticky bit = 1 if the remainder is nonzero. */
6658 for (i
= 3; i
< NI
; i
++)
6661 /* Renormalize and round off. */
6662 emdnorm (sq
, k
, 0, exp
, 64);
6665 #endif /* EMU_NON_COMPILE not defined */
6667 /* Return the binary precision of the significand for a given
6668 floating point mode. The mode can hold an integer value
6669 that many bits wide, without losing any bits. */
6672 significand_size (mode
)
6673 enum machine_mode mode
;
6676 /* Don't test the modes, but their sizes, lest this
6677 code won't work for BITS_PER_UNIT != 8 . */
6679 switch (GET_MODE_BITSIZE (mode
))
6683 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6690 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6693 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6696 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6699 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT