1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
4 1999, 2000 Free Software Foundation, Inc.
5 Contributed by Stephen L. Moshier (moshier@world.std.com).
7 This file is part of GNU CC.
9 GNU CC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GNU CC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU CC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
30 /* To enable support of XFmode extended real floating point, define
31 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
33 To support cross compilation between IEEE, VAX and IBM floating
34 point formats, define REAL_ARITHMETIC in the tm.h file.
36 In either case the machine files (tm.h) must not contain any code
37 that tries to use host floating point arithmetic to convert
38 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
39 etc. In cross-compile situations a REAL_VALUE_TYPE may not
40 be intelligible to the host computer's native arithmetic.
42 The emulator defaults to the host's floating point format so that
43 its decimal conversion functions can be used if desired (see
46 The first part of this file interfaces gcc to a floating point
47 arithmetic suite that was not written with gcc in mind. Avoid
48 changing the low-level arithmetic routines unless you have suitable
49 test programs available. A special version of the PARANOIA floating
50 point arithmetic tester, modified for this purpose, can be found on
51 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
52 XFmode and TFmode transcendental functions, can be obtained by ftp from
53 netlib.att.com: netlib/cephes. */
55 /* Type of computer arithmetic.
56 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
58 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
59 to big-endian IEEE floating-point data structure. This definition
60 should work in SFmode `float' type and DFmode `double' type on
61 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
62 has been defined to be 96, then IEEE also invokes the particular
63 XFmode (`long double' type) data structure used by the Motorola
64 680x0 series processors.
66 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
67 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
68 has been defined to be 96, then IEEE also invokes the particular
69 XFmode `long double' data structure used by the Intel 80x86 series
72 `DEC' refers specifically to the Digital Equipment Corp PDP-11
73 and VAX floating point data structure. This model currently
74 supports no type wider than DFmode.
76 `IBM' refers specifically to the IBM System/370 and compatible
77 floating point data structure. This model currently supports
78 no type wider than DFmode. The IBM conversions were contributed by
79 frank@atom.ansto.gov.au (Frank Crawford).
81 `C4X' refers specifically to the floating point format used on
82 Texas Instruments TMS320C3x and TMS320C4x digital signal
83 processors. This supports QFmode (32-bit float, double) and HFmode
84 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
85 floats, C4x floats are not rounded to be even. The C4x conversions
86 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
87 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
89 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
90 then `long double' and `double' are both implemented, but they
91 both mean DFmode. In this case, the software floating-point
92 support available here is activated by writing
93 #define REAL_ARITHMETIC
96 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
97 and may deactivate XFmode since `long double' is used to refer
98 to both modes. Defining INTEL_EXTENDED_IEEE_FORMAT at the same
99 time enables 80387-style 80-bit floats in a 128-bit padded
100 image, as seen on IA-64.
102 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
103 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
104 separate the floating point unit's endian-ness from that of
105 the integer addressing. This permits one to define a big-endian
106 FPU on a little-endian machine (e.g., ARM). An extension to
107 BYTES_BIG_ENDIAN may be required for some machines in the future.
108 These optional macros may be defined in tm.h. In real.h, they
109 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
110 them for any normal host or target machine on which the floats
111 and the integers have the same endian-ness. */
114 /* The following converts gcc macros into the ones used by this file. */
116 /* REAL_ARITHMETIC defined means that macros in real.h are
117 defined to call emulator functions. */
118 #ifdef REAL_ARITHMETIC
120 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
121 /* PDP-11, Pro350, VAX: */
123 #else /* it's not VAX */
124 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
125 /* IBM System/370 style */
127 #else /* it's also not an IBM */
128 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
129 /* TMS320C3x/C4x style */
131 #else /* it's also not a C4X */
132 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
134 #else /* it's not IEEE either */
135 /* UNKnown arithmetic. We don't support this and can't go on. */
136 unknown arithmetic type
138 #endif /* not IEEE */
143 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
146 /* REAL_ARITHMETIC not defined means that the *host's* data
147 structure will be used. It may differ by endian-ness from the
148 target machine's structure and will get its ends swapped
149 accordingly (but not here). Probably only the decimal <-> binary
150 functions in this file will actually be used in this case. */
152 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
154 #else /* it's not VAX */
155 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
156 /* IBM System/370 style */
158 #else /* it's also not an IBM */
159 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
161 #else /* it's not IEEE either */
162 unknown arithmetic type
164 #endif /* not IEEE */
168 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
170 #endif /* REAL_ARITHMETIC not defined */
172 /* Define INFINITY for support of infinity.
173 Define NANS for support of Not-a-Number's (NaN's). */
174 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
179 /* Support of NaNs requires support of infinity. */
186 /* Find a host integer type that is at least 16 bits wide,
187 and another type at least twice whatever that size is. */
189 #if HOST_BITS_PER_CHAR >= 16
190 #define EMUSHORT char
191 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
194 #if HOST_BITS_PER_SHORT >= 16
195 #define EMUSHORT short
196 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
197 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
199 #if HOST_BITS_PER_INT >= 16
201 #define EMUSHORT_SIZE HOST_BITS_PER_INT
202 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
204 #if HOST_BITS_PER_LONG >= 16
205 #define EMUSHORT long
206 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
207 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
209 /* You will have to modify this program to have a smaller unit size. */
210 #define EMU_NON_COMPILE
216 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
217 #define EMULONG short
219 #if HOST_BITS_PER_INT >= EMULONG_SIZE
222 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
225 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
226 #define EMULONG long long int
228 /* You will have to modify this program to have a smaller unit size. */
229 #define EMU_NON_COMPILE
236 /* The host interface doesn't work if no 16-bit size exists. */
237 #if EMUSHORT_SIZE != 16
238 #define EMU_NON_COMPILE
241 /* OK to continue compilation. */
242 #ifndef EMU_NON_COMPILE
244 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
245 In GET_REAL and PUT_REAL, r and e are pointers.
246 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
247 in memory, with no holes. */
249 #if MAX_LONG_DOUBLE_TYPE_SIZE == 96 || \
250 (defined(INTEL_EXTENDED_IEEE_FORMAT) && MAX_LONG_DOUBLE_TYPE_SIZE == 128)
251 /* Number of 16 bit words in external e type format */
253 # define MAXDECEXP 4932
254 # define MINDECEXP -4956
255 # define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
256 # define PUT_REAL(e,r) \
258 memcpy ((char *)(r), (char *)(e), 2*NE); \
259 if (2*NE < sizeof(*r)) \
260 memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
262 # else /* no XFmode */
263 # if MAX_LONG_DOUBLE_TYPE_SIZE == 128
265 # define MAXDECEXP 4932
266 # define MINDECEXP -4977
267 # define GET_REAL(r,e) memcpy ((char *)(e), (char *)(r), 2*NE)
268 # define PUT_REAL(e,r) \
270 memcpy ((char *)(r), (char *)(e), 2*NE); \
271 if (2*NE < sizeof(*r)) \
272 memset ((char *)(r) + 2*NE, 0, sizeof(*r) - 2*NE); \
276 #define MAXDECEXP 4932
277 #define MINDECEXP -4956
278 #ifdef REAL_ARITHMETIC
279 /* Emulator uses target format internally
280 but host stores it in host endian-ness. */
282 #define GET_REAL(r,e) \
284 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
285 e53toe ((unsigned EMUSHORT *) (r), (e)); \
288 unsigned EMUSHORT w[4]; \
289 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
290 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
291 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
292 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
297 #define PUT_REAL(e,r) \
299 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
300 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
303 unsigned EMUSHORT w[4]; \
305 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
306 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
307 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
308 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
312 #else /* not REAL_ARITHMETIC */
314 /* emulator uses host format */
315 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
316 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
318 #endif /* not REAL_ARITHMETIC */
319 #endif /* not TFmode */
320 #endif /* not XFmode */
323 /* Number of 16 bit words in internal format */
326 /* Array offset to exponent */
329 /* Array offset to high guard word */
332 /* Number of bits of precision */
333 #define NBITS ((NI-4)*16)
335 /* Maximum number of decimal digits in ASCII conversion
338 #define NDEC (NBITS*8/27)
340 /* The exponent of 1.0 */
341 #define EXONE (0x3fff)
343 #if defined(HOST_EBCDIC)
344 /* bit 8 is significant in EBCDIC */
345 #define CHARMASK 0xff
347 #define CHARMASK 0x7f
350 extern int extra_warnings
;
351 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
352 extern unsigned EMUSHORT elog2
[], esqrt2
[];
354 static void endian
PARAMS ((unsigned EMUSHORT
*, long *,
356 static void eclear
PARAMS ((unsigned EMUSHORT
*));
357 static void emov
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
359 static void eabs
PARAMS ((unsigned EMUSHORT
*));
361 static void eneg
PARAMS ((unsigned EMUSHORT
*));
362 static int eisneg
PARAMS ((unsigned EMUSHORT
*));
363 static int eisinf
PARAMS ((unsigned EMUSHORT
*));
364 static int eisnan
PARAMS ((unsigned EMUSHORT
*));
365 static void einfin
PARAMS ((unsigned EMUSHORT
*));
367 static void enan
PARAMS ((unsigned EMUSHORT
*, int));
368 static void einan
PARAMS ((unsigned EMUSHORT
*));
369 static int eiisnan
PARAMS ((unsigned EMUSHORT
*));
370 static int eiisneg
PARAMS ((unsigned EMUSHORT
*));
371 static void make_nan
PARAMS ((unsigned EMUSHORT
*, int, enum machine_mode
));
373 static void emovi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void emovo
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void ecleaz
PARAMS ((unsigned EMUSHORT
*));
376 static void ecleazs
PARAMS ((unsigned EMUSHORT
*));
377 static void emovz
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void eiinfin
PARAMS ((unsigned EMUSHORT
*));
382 static int eiisinf
PARAMS ((unsigned EMUSHORT
*));
384 static int ecmpm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static void eshdn1
PARAMS ((unsigned EMUSHORT
*));
386 static void eshup1
PARAMS ((unsigned EMUSHORT
*));
387 static void eshdn8
PARAMS ((unsigned EMUSHORT
*));
388 static void eshup8
PARAMS ((unsigned EMUSHORT
*));
389 static void eshup6
PARAMS ((unsigned EMUSHORT
*));
390 static void eshdn6
PARAMS ((unsigned EMUSHORT
*));
391 static void eaddm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
392 static void esubm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static void m16m
PARAMS ((unsigned int, unsigned short *,
395 static int edivm
PARAMS ((unsigned short *, unsigned short *));
396 static int emulm
PARAMS ((unsigned short *, unsigned short *));
397 static void emdnorm
PARAMS ((unsigned EMUSHORT
*, int, int, EMULONG
, int));
398 static void esub
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
399 unsigned EMUSHORT
*));
400 static void eadd
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
401 unsigned EMUSHORT
*));
402 static void eadd1
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
403 unsigned EMUSHORT
*));
404 static void ediv
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
405 unsigned EMUSHORT
*));
406 static void emul
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
407 unsigned EMUSHORT
*));
408 static void e53toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
409 static void e64toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
410 #ifndef INTEL_EXTENDED_IEEE_FORMAT
411 static void e113toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void e24toe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
414 static void etoe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
415 static void toe113
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void etoe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
417 static void toe64
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
418 static void etoe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
419 static void toe53
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static void etoe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
421 static void toe24
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
422 static int ecmp
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
424 static void eround
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
426 static void ltoe
PARAMS ((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
427 static void ultoe
PARAMS ((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
428 static void eifrac
PARAMS ((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
429 unsigned EMUSHORT
*));
430 static void euifrac
PARAMS ((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
431 unsigned EMUSHORT
*));
432 static int eshift
PARAMS ((unsigned EMUSHORT
*, int));
433 static int enormlz
PARAMS ((unsigned EMUSHORT
*));
435 static void e24toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
436 static void e53toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
437 static void e64toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
438 static void e113toasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
440 static void etoasc
PARAMS ((unsigned EMUSHORT
*, char *, int));
441 static void asctoe24
PARAMS ((const char *, unsigned EMUSHORT
*));
442 static void asctoe53
PARAMS ((const char *, unsigned EMUSHORT
*));
443 static void asctoe64
PARAMS ((const char *, unsigned EMUSHORT
*));
444 #ifndef INTEL_EXTENDED_IEEE_FORMAT
445 static void asctoe113
PARAMS ((const char *, unsigned EMUSHORT
*));
447 static void asctoe
PARAMS ((const char *, unsigned EMUSHORT
*));
448 static void asctoeg
PARAMS ((const char *, unsigned EMUSHORT
*, int));
449 static void efloor
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
451 static void efrexp
PARAMS ((unsigned EMUSHORT
*, int *,
452 unsigned EMUSHORT
*));
454 static void eldexp
PARAMS ((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
456 static void eremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
457 unsigned EMUSHORT
*));
459 static void eiremain
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
460 static void mtherr
PARAMS ((const char *, int));
462 static void dectoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
463 static void etodec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
464 static void todec
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
467 static void ibmtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
469 static void etoibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
471 static void toibm
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
475 static void c4xtoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
477 static void etoc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
479 static void toc4x
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
483 static void uditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
484 static void ditoe
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
485 static void etoudi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
486 static void etodi
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
487 static void esqrt
PARAMS ((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
490 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
491 swapping ends if required, into output array of longs. The
492 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
496 unsigned EMUSHORT e
[];
498 enum machine_mode mode
;
502 if (REAL_WORDS_BIG_ENDIAN
)
507 #ifndef INTEL_EXTENDED_IEEE_FORMAT
508 /* Swap halfwords in the fourth long. */
509 th
= (unsigned long) e
[6] & 0xffff;
510 t
= (unsigned long) e
[7] & 0xffff;
516 /* Swap halfwords in the third long. */
517 th
= (unsigned long) e
[4] & 0xffff;
518 t
= (unsigned long) e
[5] & 0xffff;
521 /* fall into the double case */
524 /* Swap halfwords in the second word. */
525 th
= (unsigned long) e
[2] & 0xffff;
526 t
= (unsigned long) e
[3] & 0xffff;
529 /* fall into the float case */
533 /* Swap halfwords in the first word. */
534 th
= (unsigned long) e
[0] & 0xffff;
535 t
= (unsigned long) e
[1] & 0xffff;
546 /* Pack the output array without swapping. */
551 #ifndef INTEL_EXTENDED_IEEE_FORMAT
552 /* Pack the fourth long. */
553 th
= (unsigned long) e
[7] & 0xffff;
554 t
= (unsigned long) e
[6] & 0xffff;
560 /* Pack the third long.
561 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
563 th
= (unsigned long) e
[5] & 0xffff;
564 t
= (unsigned long) e
[4] & 0xffff;
567 /* fall into the double case */
570 /* Pack the second long */
571 th
= (unsigned long) e
[3] & 0xffff;
572 t
= (unsigned long) e
[2] & 0xffff;
575 /* fall into the float case */
579 /* Pack the first long */
580 th
= (unsigned long) e
[1] & 0xffff;
581 t
= (unsigned long) e
[0] & 0xffff;
593 /* This is the implementation of the REAL_ARITHMETIC macro. */
596 earith (value
, icode
, r1
, r2
)
597 REAL_VALUE_TYPE
*value
;
602 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
608 /* Return NaN input back to the caller. */
611 PUT_REAL (d1
, value
);
616 PUT_REAL (d2
, value
);
620 code
= (enum tree_code
) icode
;
628 esub (d2
, d1
, v
); /* d1 - d2 */
636 #ifndef REAL_INFINITY
637 if (ecmp (d2
, ezero
) == 0)
640 enan (v
, eisneg (d1
) ^ eisneg (d2
));
647 ediv (d2
, d1
, v
); /* d1/d2 */
650 case MIN_EXPR
: /* min (d1,d2) */
651 if (ecmp (d1
, d2
) < 0)
657 case MAX_EXPR
: /* max (d1,d2) */
658 if (ecmp (d1
, d2
) > 0)
671 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
672 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
678 unsigned EMUSHORT f
[NE
], g
[NE
];
694 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
695 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
701 unsigned EMUSHORT f
[NE
], g
[NE
];
703 unsigned HOST_WIDE_INT l
;
717 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
718 string to binary, rounding off as indicated by the machine_mode argument.
719 Then it promotes the rounded value to REAL_VALUE_TYPE. */
726 unsigned EMUSHORT tem
[NE
], e
[NE
];
752 #ifndef INTEL_EXTENDED_IEEE_FORMAT
772 /* Expansion of REAL_NEGATE. */
778 unsigned EMUSHORT e
[NE
];
788 /* Round real toward zero to HOST_WIDE_INT;
789 implements REAL_VALUE_FIX (x). */
795 unsigned EMUSHORT f
[NE
], g
[NE
];
802 warning ("conversion from NaN to int");
810 /* Round real toward zero to unsigned HOST_WIDE_INT
811 implements REAL_VALUE_UNSIGNED_FIX (x).
812 Negative input returns zero. */
814 unsigned HOST_WIDE_INT
818 unsigned EMUSHORT f
[NE
], g
[NE
];
819 unsigned HOST_WIDE_INT l
;
825 warning ("conversion from NaN to unsigned int");
834 /* REAL_VALUE_FROM_INT macro. */
837 ereal_from_int (d
, i
, j
, mode
)
840 enum machine_mode mode
;
842 unsigned EMUSHORT df
[NE
], dg
[NE
];
843 HOST_WIDE_INT low
, high
;
846 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
853 /* complement and add 1 */
860 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
861 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
863 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
868 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
869 Avoid double-rounding errors later by rounding off now from the
870 extra-wide internal format to the requested precision. */
871 switch (GET_MODE_BITSIZE (mode
))
889 #ifndef INTEL_EXTENDED_IEEE_FORMAT
906 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
909 ereal_from_uint (d
, i
, j
, mode
)
911 unsigned HOST_WIDE_INT i
, j
;
912 enum machine_mode mode
;
914 unsigned EMUSHORT df
[NE
], dg
[NE
];
915 unsigned HOST_WIDE_INT low
, high
;
917 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
921 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
927 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
928 Avoid double-rounding errors later by rounding off now from the
929 extra-wide internal format to the requested precision. */
930 switch (GET_MODE_BITSIZE (mode
))
948 #ifndef INTEL_EXTENDED_IEEE_FORMAT
965 /* REAL_VALUE_TO_INT macro. */
968 ereal_to_int (low
, high
, rr
)
969 HOST_WIDE_INT
*low
, *high
;
972 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
979 warning ("conversion from NaN to int");
985 /* convert positive value */
992 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
993 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
994 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
995 emul (df
, dh
, dg
); /* fractional part is the low word */
996 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
999 /* complement and add 1 */
1009 /* REAL_VALUE_LDEXP macro. */
1016 unsigned EMUSHORT e
[NE
], y
[NE
];
1029 /* These routines are conditionally compiled because functions
1030 of the same names may be defined in fold-const.c. */
1032 #ifdef REAL_ARITHMETIC
1034 /* Check for infinity in a REAL_VALUE_TYPE. */
1038 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1041 unsigned EMUSHORT e
[NE
];
1044 return (eisinf (e
));
1050 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1054 REAL_VALUE_TYPE x ATTRIBUTE_UNUSED
;
1057 unsigned EMUSHORT e
[NE
];
1060 return (eisnan (e
));
1067 /* Check for a negative REAL_VALUE_TYPE number.
1068 This just checks the sign bit, so that -0 counts as negative. */
1074 return ereal_isneg (x
);
1077 /* Expansion of REAL_VALUE_TRUNCATE.
1078 The result is in floating point, rounded to nearest or even. */
1081 real_value_truncate (mode
, arg
)
1082 enum machine_mode mode
;
1083 REAL_VALUE_TYPE arg
;
1085 unsigned EMUSHORT e
[NE
], t
[NE
];
1097 #ifndef INTEL_EXTENDED_IEEE_FORMAT
1134 /* If an unsupported type was requested, presume that
1135 the machine files know something useful to do with
1136 the unmodified value. */
1145 /* Try to change R into its exact multiplicative inverse in machine mode
1146 MODE. Return nonzero function value if successful. */
1149 exact_real_inverse (mode
, r
)
1150 enum machine_mode mode
;
1153 unsigned EMUSHORT e
[NE
], einv
[NE
];
1154 REAL_VALUE_TYPE rinv
;
1159 /* Test for input in range. Don't transform IEEE special values. */
1160 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1163 /* Test for a power of 2: all significand bits zero except the MSB.
1164 We are assuming the target has binary (or hex) arithmetic. */
1165 if (e
[NE
- 2] != 0x8000)
1168 for (i
= 0; i
< NE
- 2; i
++)
1174 /* Compute the inverse and truncate it to the required mode. */
1175 ediv (e
, eone
, einv
);
1176 PUT_REAL (einv
, &rinv
);
1177 rinv
= real_value_truncate (mode
, rinv
);
1179 #ifdef CHECK_FLOAT_VALUE
1180 /* This check is not redundant. It may, for example, flush
1181 a supposedly IEEE denormal value to zero. */
1183 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1186 GET_REAL (&rinv
, einv
);
1188 /* Check the bits again, because the truncation might have
1189 generated an arbitrary saturation value on overflow. */
1190 if (einv
[NE
- 2] != 0x8000)
1193 for (i
= 0; i
< NE
- 2; i
++)
1199 /* Fail if the computed inverse is out of range. */
1200 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1203 /* Output the reciprocal and return success flag. */
1207 #endif /* REAL_ARITHMETIC defined */
1209 /* Used for debugging--print the value of R in human-readable format
1218 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1219 fprintf (stderr
, "%s", dstr
);
1223 /* The following routines convert REAL_VALUE_TYPE to the various floating
1224 point formats that are meaningful to supported computers.
1226 The results are returned in 32-bit pieces, each piece stored in a `long'.
1227 This is so they can be printed by statements like
1229 fprintf (file, "%lx, %lx", L[0], L[1]);
1231 that will work on both narrow- and wide-word host computers. */
1233 /* Convert R to a 128-bit long double precision value. The output array L
1234 contains four 32-bit pieces of the result, in the order they would appear
1242 unsigned EMUSHORT e
[NE
];
1246 endian (e
, l
, TFmode
);
1249 /* Convert R to a double extended precision value. The output array L
1250 contains three 32-bit pieces of the result, in the order they would
1251 appear in memory. */
1258 unsigned EMUSHORT e
[NE
];
1262 endian (e
, l
, XFmode
);
1265 /* Convert R to a double precision value. The output array L contains two
1266 32-bit pieces of the result, in the order they would appear in memory. */
1273 unsigned EMUSHORT e
[NE
];
1277 endian (e
, l
, DFmode
);
1280 /* Convert R to a single precision float value stored in the least-significant
1281 bits of a `long'. */
1287 unsigned EMUSHORT e
[NE
];
1292 endian (e
, &l
, SFmode
);
1296 /* Convert X to a decimal ASCII string S for output to an assembly
1297 language file. Note, there is no standard way to spell infinity or
1298 a NaN, so these values may require special treatment in the tm.h
1302 ereal_to_decimal (x
, s
)
1306 unsigned EMUSHORT e
[NE
];
1312 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1313 or -2 if either is a NaN. */
1317 REAL_VALUE_TYPE x
, y
;
1319 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1323 return (ecmp (ex
, ey
));
1326 /* Return 1 if the sign bit of X is set, else return 0. */
1332 unsigned EMUSHORT ex
[NE
];
1335 return (eisneg (ex
));
1338 /* End of REAL_ARITHMETIC interface */
1341 Extended precision IEEE binary floating point arithmetic routines
1343 Numbers are stored in C language as arrays of 16-bit unsigned
1344 short integers. The arguments of the routines are pointers to
1347 External e type data structure, similar to Intel 8087 chip
1348 temporary real format but possibly with a larger significand:
1350 NE-1 significand words (least significant word first,
1351 most significant bit is normally set)
1352 exponent (value = EXONE for 1.0,
1353 top bit is the sign)
1356 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1358 ei[0] sign word (0 for positive, 0xffff for negative)
1359 ei[1] biased exponent (value = EXONE for the number 1.0)
1360 ei[2] high guard word (always zero after normalization)
1362 to ei[NI-2] significand (NI-4 significand words,
1363 most significant word first,
1364 most significant bit is set)
1365 ei[NI-1] low guard word (0x8000 bit is rounding place)
1369 Routines for external format e-type numbers
1371 asctoe (string, e) ASCII string to extended double e type
1372 asctoe64 (string, &d) ASCII string to long double
1373 asctoe53 (string, &d) ASCII string to double
1374 asctoe24 (string, &f) ASCII string to single
1375 asctoeg (string, e, prec) ASCII string to specified precision
1376 e24toe (&f, e) IEEE single precision to e type
1377 e53toe (&d, e) IEEE double precision to e type
1378 e64toe (&d, e) IEEE long double precision to e type
1379 e113toe (&d, e) 128-bit long double precision to e type
1381 eabs (e) absolute value
1383 eadd (a, b, c) c = b + a
1385 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1386 -1 if a < b, -2 if either a or b is a NaN.
1387 ediv (a, b, c) c = b / a
1388 efloor (a, b) truncate to integer, toward -infinity
1389 efrexp (a, exp, s) extract exponent and significand
1390 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1391 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1392 einfin (e) set e to infinity, leaving its sign alone
1393 eldexp (a, n, b) multiply by 2**n
1395 emul (a, b, c) c = b * a
1398 eround (a, b) b = nearest integer value to a
1400 esub (a, b, c) c = b - a
1402 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1403 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1404 e64toasc (&d, str, n) 80-bit long double to ASCII string
1405 e113toasc (&d, str, n) 128-bit long double to ASCII string
1407 etoasc (e, str, n) e to ASCII string, n digits after decimal
1408 etoe24 (e, &f) convert e type to IEEE single precision
1409 etoe53 (e, &d) convert e type to IEEE double precision
1410 etoe64 (e, &d) convert e type to IEEE long double precision
1411 ltoe (&l, e) HOST_WIDE_INT to e type
1412 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1413 eisneg (e) 1 if sign bit of e != 0, else 0
1414 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1415 or is infinite (IEEE)
1416 eisnan (e) 1 if e is a NaN
1419 Routines for internal format exploded e-type numbers
1421 eaddm (ai, bi) add significands, bi = bi + ai
1423 ecleazs (ei) set ei = 0 but leave its sign alone
1424 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1425 edivm (ai, bi) divide significands, bi = bi / ai
1426 emdnorm (ai,l,s,exp) normalize and round off
1427 emovi (a, ai) convert external a to internal ai
1428 emovo (ai, a) convert internal ai to external a
1429 emovz (ai, bi) bi = ai, low guard word of bi = 0
1430 emulm (ai, bi) multiply significands, bi = bi * ai
1431 enormlz (ei) left-justify the significand
1432 eshdn1 (ai) shift significand and guards down 1 bit
1433 eshdn8 (ai) shift down 8 bits
1434 eshdn6 (ai) shift down 16 bits
1435 eshift (ai, n) shift ai n bits up (or down if n < 0)
1436 eshup1 (ai) shift significand and guards up 1 bit
1437 eshup8 (ai) shift up 8 bits
1438 eshup6 (ai) shift up 16 bits
1439 esubm (ai, bi) subtract significands, bi = bi - ai
1440 eiisinf (ai) 1 if infinite
1441 eiisnan (ai) 1 if a NaN
1442 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1443 einan (ai) set ai = NaN
1445 eiinfin (ai) set ai = infinity
1448 The result is always normalized and rounded to NI-4 word precision
1449 after each arithmetic operation.
1451 Exception flags are NOT fully supported.
1453 Signaling NaN's are NOT supported; they are treated the same
1456 Define INFINITY for support of infinity; otherwise a
1457 saturation arithmetic is implemented.
1459 Define NANS for support of Not-a-Number items; otherwise the
1460 arithmetic will never produce a NaN output, and might be confused
1462 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1463 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1464 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1467 Denormals are always supported here where appropriate (e.g., not
1468 for conversion to DEC numbers). */
1470 /* Definitions for error codes that are passed to the common error handling
1473 For Digital Equipment PDP-11 and VAX computers, certain
1474 IBM systems, and others that use numbers with a 56-bit
1475 significand, the symbol DEC should be defined. In this
1476 mode, most floating point constants are given as arrays
1477 of octal integers to eliminate decimal to binary conversion
1478 errors that might be introduced by the compiler.
1480 For computers, such as IBM PC, that follow the IEEE
1481 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1482 Std 754-1985), the symbol IEEE should be defined.
1483 These numbers have 53-bit significands. In this mode, constants
1484 are provided as arrays of hexadecimal 16 bit integers.
1485 The endian-ness of generated values is controlled by
1486 REAL_WORDS_BIG_ENDIAN.
1488 To accommodate other types of computer arithmetic, all
1489 constants are also provided in a normal decimal radix
1490 which one can hope are correctly converted to a suitable
1491 format by the available C language compiler. To invoke
1492 this mode, the symbol UNK is defined.
1494 An important difference among these modes is a predefined
1495 set of machine arithmetic constants for each. The numbers
1496 MACHEP (the machine roundoff error), MAXNUM (largest number
1497 represented), and several other parameters are preset by
1498 the configuration symbol. Check the file const.c to
1499 ensure that these values are correct for your computer.
1501 For ANSI C compatibility, define ANSIC equal to 1. Currently
1502 this affects only the atan2 function and others that use it. */
1504 /* Constant definitions for math error conditions. */
1506 #define DOMAIN 1 /* argument domain error */
1507 #define SING 2 /* argument singularity */
1508 #define OVERFLOW 3 /* overflow range error */
1509 #define UNDERFLOW 4 /* underflow range error */
1510 #define TLOSS 5 /* total loss of precision */
1511 #define PLOSS 6 /* partial loss of precision */
1512 #define INVALID 7 /* NaN-producing operation */
1514 /* e type constants used by high precision check routines */
1516 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !defined(INTEL_EXTENDED_IEEE_FORMAT)
1518 unsigned EMUSHORT ezero
[NE
] =
1519 {0x0000, 0x0000, 0x0000, 0x0000,
1520 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1521 extern unsigned EMUSHORT ezero
[];
1524 unsigned EMUSHORT ehalf
[NE
] =
1525 {0x0000, 0x0000, 0x0000, 0x0000,
1526 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1527 extern unsigned EMUSHORT ehalf
[];
1530 unsigned EMUSHORT eone
[NE
] =
1531 {0x0000, 0x0000, 0x0000, 0x0000,
1532 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1533 extern unsigned EMUSHORT eone
[];
1536 unsigned EMUSHORT etwo
[NE
] =
1537 {0x0000, 0x0000, 0x0000, 0x0000,
1538 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1539 extern unsigned EMUSHORT etwo
[];
1542 unsigned EMUSHORT e32
[NE
] =
1543 {0x0000, 0x0000, 0x0000, 0x0000,
1544 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1545 extern unsigned EMUSHORT e32
[];
1547 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1548 unsigned EMUSHORT elog2
[NE
] =
1549 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1550 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1551 extern unsigned EMUSHORT elog2
[];
1553 /* 1.41421356237309504880168872420969807856967187537695E0 */
1554 unsigned EMUSHORT esqrt2
[NE
] =
1555 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1556 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1557 extern unsigned EMUSHORT esqrt2
[];
1559 /* 3.14159265358979323846264338327950288419716939937511E0 */
1560 unsigned EMUSHORT epi
[NE
] =
1561 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1562 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1563 extern unsigned EMUSHORT epi
[];
1566 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1567 unsigned EMUSHORT ezero
[NE
] =
1568 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1569 unsigned EMUSHORT ehalf
[NE
] =
1570 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1571 unsigned EMUSHORT eone
[NE
] =
1572 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1573 unsigned EMUSHORT etwo
[NE
] =
1574 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1575 unsigned EMUSHORT e32
[NE
] =
1576 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1577 unsigned EMUSHORT elog2
[NE
] =
1578 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1579 unsigned EMUSHORT esqrt2
[NE
] =
1580 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1581 unsigned EMUSHORT epi
[NE
] =
1582 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1585 /* Control register for rounding precision.
1586 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1591 /* Clear out entire e-type number X. */
1595 register unsigned EMUSHORT
*x
;
1599 for (i
= 0; i
< NE
; i
++)
1603 /* Move e-type number from A to B. */
1607 register unsigned EMUSHORT
*a
, *b
;
1611 for (i
= 0; i
< NE
; i
++)
1617 /* Absolute value of e-type X. */
1621 unsigned EMUSHORT x
[];
1623 /* sign is top bit of last word of external format */
1624 x
[NE
- 1] &= 0x7fff;
1628 /* Negate the e-type number X. */
1632 unsigned EMUSHORT x
[];
1635 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1638 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1642 unsigned EMUSHORT x
[];
1645 if (x
[NE
- 1] & 0x8000)
1651 /* Return 1 if e-type number X is infinity, else return zero. */
1655 unsigned EMUSHORT x
[];
1662 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1668 /* Check if e-type number is not a number. The bit pattern is one that we
1669 defined, so we know for sure how to detect it. */
1673 unsigned EMUSHORT x
[] ATTRIBUTE_UNUSED
;
1678 /* NaN has maximum exponent */
1679 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1681 /* ... and non-zero significand field. */
1682 for (i
= 0; i
< NE
- 1; i
++)
1692 /* Fill e-type number X with infinity pattern (IEEE)
1693 or largest possible number (non-IEEE). */
1697 register unsigned EMUSHORT
*x
;
1702 for (i
= 0; i
< NE
- 1; i
++)
1706 for (i
= 0; i
< NE
- 1; i
++)
1734 /* Output an e-type NaN.
1735 This generates Intel's quiet NaN pattern for extended real.
1736 The exponent is 7fff, the leading mantissa word is c000. */
1741 register unsigned EMUSHORT
*x
;
1746 for (i
= 0; i
< NE
- 2; i
++)
1749 *x
= (sign
<< 15) | 0x7fff;
1753 /* Move in an e-type number A, converting it to exploded e-type B. */
1757 unsigned EMUSHORT
*a
, *b
;
1759 register unsigned EMUSHORT
*p
, *q
;
1763 p
= a
+ (NE
- 1); /* point to last word of external number */
1764 /* get the sign bit */
1769 /* get the exponent */
1771 *q
++ &= 0x7fff; /* delete the sign bit */
1773 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1779 for (i
= 3; i
< NI
; i
++)
1785 for (i
= 2; i
< NI
; i
++)
1791 /* clear high guard word */
1793 /* move in the significand */
1794 for (i
= 0; i
< NE
- 1; i
++)
1796 /* clear low guard word */
1800 /* Move out exploded e-type number A, converting it to e type B. */
1804 unsigned EMUSHORT
*a
, *b
;
1806 register unsigned EMUSHORT
*p
, *q
;
1807 unsigned EMUSHORT i
;
1811 q
= b
+ (NE
- 1); /* point to output exponent */
1812 /* combine sign and exponent */
1815 *q
-- = *p
++ | 0x8000;
1819 if (*(p
- 1) == 0x7fff)
1824 enan (b
, eiisneg (a
));
1832 /* skip over guard word */
1834 /* move the significand */
1835 for (j
= 0; j
< NE
- 1; j
++)
1839 /* Clear out exploded e-type number XI. */
1843 register unsigned EMUSHORT
*xi
;
1847 for (i
= 0; i
< NI
; i
++)
1851 /* Clear out exploded e-type XI, but don't touch the sign. */
1855 register unsigned EMUSHORT
*xi
;
1860 for (i
= 0; i
< NI
- 1; i
++)
1864 /* Move exploded e-type number from A to B. */
1868 register unsigned EMUSHORT
*a
, *b
;
1872 for (i
= 0; i
< NI
- 1; i
++)
1874 /* clear low guard word */
1878 /* Generate exploded e-type NaN.
1879 The explicit pattern for this is maximum exponent and
1880 top two significant bits set. */
1885 unsigned EMUSHORT x
[];
1894 /* Return nonzero if exploded e-type X is a NaN. */
1899 unsigned EMUSHORT x
[];
1903 if ((x
[E
] & 0x7fff) == 0x7fff)
1905 for (i
= M
+ 1; i
< NI
; i
++)
1915 /* Return nonzero if sign of exploded e-type X is nonzero. */
1920 unsigned EMUSHORT x
[];
1928 /* Fill exploded e-type X with infinity pattern.
1929 This has maximum exponent and significand all zeros. */
1933 unsigned EMUSHORT x
[];
1941 /* Return nonzero if exploded e-type X is infinite. */
1946 unsigned EMUSHORT x
[];
1953 if ((x
[E
] & 0x7fff) == 0x7fff)
1957 #endif /* INFINITY */
1959 /* Compare significands of numbers in internal exploded e-type format.
1960 Guard words are included in the comparison.
1968 register unsigned EMUSHORT
*a
, *b
;
1972 a
+= M
; /* skip up to significand area */
1974 for (i
= M
; i
< NI
; i
++)
1982 if (*(--a
) > *(--b
))
1988 /* Shift significand of exploded e-type X down by 1 bit. */
1992 register unsigned EMUSHORT
*x
;
1994 register unsigned EMUSHORT bits
;
1997 x
+= M
; /* point to significand area */
2000 for (i
= M
; i
< NI
; i
++)
2012 /* Shift significand of exploded e-type X up by 1 bit. */
2016 register unsigned EMUSHORT
*x
;
2018 register unsigned EMUSHORT bits
;
2024 for (i
= M
; i
< NI
; i
++)
2037 /* Shift significand of exploded e-type X down by 8 bits. */
2041 register unsigned EMUSHORT
*x
;
2043 register unsigned EMUSHORT newbyt
, oldbyt
;
2048 for (i
= M
; i
< NI
; i
++)
2058 /* Shift significand of exploded e-type X up by 8 bits. */
2062 register unsigned EMUSHORT
*x
;
2065 register unsigned EMUSHORT newbyt
, oldbyt
;
2070 for (i
= M
; i
< NI
; i
++)
2080 /* Shift significand of exploded e-type X up by 16 bits. */
2084 register unsigned EMUSHORT
*x
;
2087 register unsigned EMUSHORT
*p
;
2092 for (i
= M
; i
< NI
- 1; i
++)
2098 /* Shift significand of exploded e-type X down by 16 bits. */
2102 register unsigned EMUSHORT
*x
;
2105 register unsigned EMUSHORT
*p
;
2110 for (i
= M
; i
< NI
- 1; i
++)
2116 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2120 unsigned EMUSHORT
*x
, *y
;
2122 register unsigned EMULONG a
;
2129 for (i
= M
; i
< NI
; i
++)
2131 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2136 *y
= (unsigned EMUSHORT
) a
;
2142 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2146 unsigned EMUSHORT
*x
, *y
;
2155 for (i
= M
; i
< NI
; i
++)
2157 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2162 *y
= (unsigned EMUSHORT
) a
;
2169 static unsigned EMUSHORT equot
[NI
];
2173 /* Radix 2 shift-and-add versions of multiply and divide */
2176 /* Divide significands */
2180 unsigned EMUSHORT den
[], num
[];
2183 register unsigned EMUSHORT
*p
, *q
;
2184 unsigned EMUSHORT j
;
2190 for (i
= M
; i
< NI
; i
++)
2195 /* Use faster compare and subtraction if denominator has only 15 bits of
2201 for (i
= M
+ 3; i
< NI
; i
++)
2206 if ((den
[M
+ 1] & 1) != 0)
2214 for (i
= 0; i
< NBITS
+ 2; i
++)
2232 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2233 bit + 1 roundoff bit. */
2238 for (i
= 0; i
< NBITS
+ 2; i
++)
2240 if (ecmpm (den
, num
) <= 0)
2243 j
= 1; /* quotient bit = 1 */
2257 /* test for nonzero remainder after roundoff bit */
2260 for (i
= M
; i
< NI
; i
++)
2268 for (i
= 0; i
< NI
; i
++)
2274 /* Multiply significands */
2278 unsigned EMUSHORT a
[], b
[];
2280 unsigned EMUSHORT
*p
, *q
;
2285 for (i
= M
; i
< NI
; i
++)
2290 while (*p
== 0) /* significand is not supposed to be zero */
2295 if ((*p
& 0xff) == 0)
2303 for (i
= 0; i
< k
; i
++)
2307 /* remember if there were any nonzero bits shifted out */
2314 for (i
= 0; i
< NI
; i
++)
2317 /* return flag for lost nonzero bits */
2323 /* Radix 65536 versions of multiply and divide. */
2325 /* Multiply significand of e-type number B
2326 by 16-bit quantity A, return e-type result to C. */
2331 unsigned EMUSHORT b
[], c
[];
2333 register unsigned EMUSHORT
*pp
;
2334 register unsigned EMULONG carry
;
2335 unsigned EMUSHORT
*ps
;
2336 unsigned EMUSHORT p
[NI
];
2337 unsigned EMULONG aa
, m
;
2346 for (i
=M
+1; i
<NI
; i
++)
2356 m
= (unsigned EMULONG
) aa
* *ps
--;
2357 carry
= (m
& 0xffff) + *pp
;
2358 *pp
-- = (unsigned EMUSHORT
)carry
;
2359 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2360 *pp
= (unsigned EMUSHORT
)carry
;
2361 *(pp
-1) = carry
>> 16;
2364 for (i
=M
; i
<NI
; i
++)
2368 /* Divide significands of exploded e-types NUM / DEN. Neither the
2369 numerator NUM nor the denominator DEN is permitted to have its high guard
2374 unsigned EMUSHORT den
[], num
[];
2377 register unsigned EMUSHORT
*p
;
2378 unsigned EMULONG tnum
;
2379 unsigned EMUSHORT j
, tdenm
, tquot
;
2380 unsigned EMUSHORT tprod
[NI
+1];
2386 for (i
=M
; i
<NI
; i
++)
2392 for (i
=M
; i
<NI
; i
++)
2394 /* Find trial quotient digit (the radix is 65536). */
2395 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2397 /* Do not execute the divide instruction if it will overflow. */
2398 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2401 tquot
= tnum
/ tdenm
;
2402 /* Multiply denominator by trial quotient digit. */
2403 m16m ((unsigned int)tquot
, den
, tprod
);
2404 /* The quotient digit may have been overestimated. */
2405 if (ecmpm (tprod
, num
) > 0)
2409 if (ecmpm (tprod
, num
) > 0)
2419 /* test for nonzero remainder after roundoff bit */
2422 for (i
=M
; i
<NI
; i
++)
2429 for (i
=0; i
<NI
; i
++)
2435 /* Multiply significands of exploded e-type A and B, result in B. */
2439 unsigned EMUSHORT a
[], b
[];
2441 unsigned EMUSHORT
*p
, *q
;
2442 unsigned EMUSHORT pprod
[NI
];
2443 unsigned EMUSHORT j
;
2448 for (i
=M
; i
<NI
; i
++)
2454 for (i
=M
+1; i
<NI
; i
++)
2462 m16m ((unsigned int) *p
--, b
, pprod
);
2463 eaddm(pprod
, equot
);
2469 for (i
=0; i
<NI
; i
++)
2472 /* return flag for lost nonzero bits */
2478 /* Normalize and round off.
2480 The internal format number to be rounded is S.
2481 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2483 Input SUBFLG indicates whether the number was obtained
2484 by a subtraction operation. In that case if LOST is nonzero
2485 then the number is slightly smaller than indicated.
2487 Input EXP is the biased exponent, which may be negative.
2488 the exponent field of S is ignored but is replaced by
2489 EXP as adjusted by normalization and rounding.
2491 Input RCNTRL is the rounding control. If it is nonzero, the
2492 returned value will be rounded to RNDPRC bits.
2494 For future reference: In order for emdnorm to round off denormal
2495 significands at the right point, the input exponent must be
2496 adjusted to be the actual value it would have after conversion to
2497 the final floating point type. This adjustment has been
2498 implemented for all type conversions (etoe53, etc.) and decimal
2499 conversions, but not for the arithmetic functions (eadd, etc.).
2500 Data types having standard 15-bit exponents are not affected by
2501 this, but SFmode and DFmode are affected. For example, ediv with
2502 rndprc = 24 will not round correctly to 24-bit precision if the
2503 result is denormal. */
2505 static int rlast
= -1;
2507 static unsigned EMUSHORT rmsk
= 0;
2508 static unsigned EMUSHORT rmbit
= 0;
2509 static unsigned EMUSHORT rebit
= 0;
2511 static unsigned EMUSHORT rbit
[NI
];
2514 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2515 unsigned EMUSHORT s
[];
2522 unsigned EMUSHORT r
;
2527 /* a blank significand could mean either zero or infinity. */
2540 if ((j
> NBITS
) && (exp
< 32767))
2548 if (exp
> (EMULONG
) (-NBITS
- 1))
2561 /* Round off, unless told not to by rcntrl. */
2564 /* Set up rounding parameters if the control register changed. */
2565 if (rndprc
!= rlast
)
2572 rw
= NI
- 1; /* low guard word */
2595 /* For DEC or IBM arithmetic */
2612 /* For C4x arithmetic */
2633 /* Shift down 1 temporarily if the data structure has an implied
2634 most significant bit and the number is denormal.
2635 Intel long double denormals also lose one bit of precision. */
2636 if ((exp
<= 0) && (rndprc
!= NBITS
)
2637 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2639 lost
|= s
[NI
- 1] & 1;
2642 /* Clear out all bits below the rounding bit,
2643 remembering in r if any were nonzero. */
2657 if ((r
& rmbit
) != 0)
2663 { /* round to even */
2664 if ((s
[re
] & rebit
) == 0)
2677 /* Undo the temporary shift for denormal values. */
2678 if ((exp
<= 0) && (rndprc
!= NBITS
)
2679 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2684 { /* overflow on roundoff */
2697 for (i
= 2; i
< NI
- 1; i
++)
2700 warning ("floating point overflow");
2704 for (i
= M
+ 1; i
< NI
- 1; i
++)
2707 if ((rndprc
< 64) || (rndprc
== 113))
2722 s
[1] = (unsigned EMUSHORT
) exp
;
2725 /* Subtract. C = B - A, all e type numbers. */
2727 static int subflg
= 0;
2731 unsigned EMUSHORT
*a
, *b
, *c
;
2745 /* Infinity minus infinity is a NaN.
2746 Test for subtracting infinities of the same sign. */
2747 if (eisinf (a
) && eisinf (b
)
2748 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2750 mtherr ("esub", INVALID
);
2759 /* Add. C = A + B, all e type. */
2763 unsigned EMUSHORT
*a
, *b
, *c
;
2767 /* NaN plus anything is a NaN. */
2778 /* Infinity minus infinity is a NaN.
2779 Test for adding infinities of opposite signs. */
2780 if (eisinf (a
) && eisinf (b
)
2781 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2783 mtherr ("esub", INVALID
);
2792 /* Arithmetic common to both addition and subtraction. */
2796 unsigned EMUSHORT
*a
, *b
, *c
;
2798 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2800 EMULONG lt
, lta
, ltb
;
2821 /* compare exponents */
2826 { /* put the larger number in bi */
2836 if (lt
< (EMULONG
) (-NBITS
- 1))
2837 goto done
; /* answer same as larger addend */
2839 lost
= eshift (ai
, k
); /* shift the smaller number down */
2843 /* exponents were the same, so must compare significands */
2846 { /* the numbers are identical in magnitude */
2847 /* if different signs, result is zero */
2853 /* if same sign, result is double */
2854 /* double denormalized tiny number */
2855 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2860 /* add 1 to exponent unless both are zero! */
2861 for (j
= 1; j
< NI
- 1; j
++)
2877 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2881 { /* put the larger number in bi */
2897 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2903 /* Divide: C = B/A, all e type. */
2907 unsigned EMUSHORT
*a
, *b
, *c
;
2909 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2911 EMULONG lt
, lta
, ltb
;
2913 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2914 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2915 sign
= eisneg(a
) ^ eisneg(b
);
2918 /* Return any NaN input. */
2929 /* Zero over zero, or infinity over infinity, is a NaN. */
2930 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2931 || (eisinf (a
) && eisinf (b
)))
2933 mtherr ("ediv", INVALID
);
2938 /* Infinity over anything else is infinity. */
2945 /* Anything else over infinity is zero. */
2957 { /* See if numerator is zero. */
2958 for (i
= 1; i
< NI
- 1; i
++)
2962 ltb
-= enormlz (bi
);
2972 { /* possible divide by zero */
2973 for (i
= 1; i
< NI
- 1; i
++)
2977 lta
-= enormlz (ai
);
2981 /* Divide by zero is not an invalid operation.
2982 It is a divide-by-zero operation! */
2984 mtherr ("ediv", SING
);
2990 /* calculate exponent */
2991 lt
= ltb
- lta
+ EXONE
;
2992 emdnorm (bi
, i
, 0, lt
, 64);
2999 && (ecmp (c
, ezero
) != 0)
3002 *(c
+(NE
-1)) |= 0x8000;
3004 *(c
+(NE
-1)) &= ~0x8000;
3007 /* Multiply e-types A and B, return e-type product C. */
3011 unsigned EMUSHORT
*a
, *b
, *c
;
3013 unsigned EMUSHORT ai
[NI
], bi
[NI
];
3015 EMULONG lt
, lta
, ltb
;
3017 /* IEEE says if result is not a NaN, the sign is "-" if and only if
3018 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
3019 sign
= eisneg(a
) ^ eisneg(b
);
3022 /* NaN times anything is the same NaN. */
3033 /* Zero times infinity is a NaN. */
3034 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
3035 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
3037 mtherr ("emul", INVALID
);
3042 /* Infinity times anything else is infinity. */
3044 if (eisinf (a
) || eisinf (b
))
3056 for (i
= 1; i
< NI
- 1; i
++)
3060 lta
-= enormlz (ai
);
3071 for (i
= 1; i
< NI
- 1; i
++)
3075 ltb
-= enormlz (bi
);
3084 /* Multiply significands */
3086 /* calculate exponent */
3087 lt
= lta
+ ltb
- (EXONE
- 1);
3088 emdnorm (bi
, j
, 0, lt
, 64);
3095 && (ecmp (c
, ezero
) != 0)
3098 *(c
+(NE
-1)) |= 0x8000;
3100 *(c
+(NE
-1)) &= ~0x8000;
3103 /* Convert double precision PE to e-type Y. */
3107 unsigned EMUSHORT
*pe
, *y
;
3116 ibmtoe (pe
, y
, DFmode
);
3121 c4xtoe (pe
, y
, HFmode
);
3124 register unsigned EMUSHORT r
;
3125 register unsigned EMUSHORT
*e
, *p
;
3126 unsigned EMUSHORT yy
[NI
];
3130 denorm
= 0; /* flag if denormalized number */
3132 if (! REAL_WORDS_BIG_ENDIAN
)
3138 yy
[M
] = (r
& 0x0f) | 0x10;
3139 r
&= ~0x800f; /* strip sign and 4 significand bits */
3144 if (! REAL_WORDS_BIG_ENDIAN
)
3146 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3147 || (pe
[1] != 0) || (pe
[0] != 0))
3149 enan (y
, yy
[0] != 0);
3155 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3156 || (pe
[2] != 0) || (pe
[3] != 0))
3158 enan (y
, yy
[0] != 0);
3169 #endif /* INFINITY */
3171 /* If zero exponent, then the significand is denormalized.
3172 So take back the understood high significand bit. */
3183 if (! REAL_WORDS_BIG_ENDIAN
)
3200 /* If zero exponent, then normalize the significand. */
3201 if ((k
= enormlz (yy
)) > NBITS
)
3204 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3207 #endif /* not C4X */
3208 #endif /* not IBM */
3209 #endif /* not DEC */
3212 /* Convert double extended precision float PE to e type Y. */
3216 unsigned EMUSHORT
*pe
, *y
;
3218 unsigned EMUSHORT yy
[NI
];
3219 unsigned EMUSHORT
*e
, *p
, *q
;
3224 for (i
= 0; i
< NE
- 5; i
++)
3226 /* This precision is not ordinarily supported on DEC or IBM. */
3228 for (i
= 0; i
< 5; i
++)
3232 p
= &yy
[0] + (NE
- 1);
3235 for (i
= 0; i
< 5; i
++)
3239 if (! REAL_WORDS_BIG_ENDIAN
)
3241 for (i
= 0; i
< 5; i
++)
3244 /* For denormal long double Intel format, shift significand up one
3245 -- but only if the top significand bit is zero. A top bit of 1
3246 is "pseudodenormal" when the exponent is zero. */
3247 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3249 unsigned EMUSHORT temp
[NI
];
3259 p
= &yy
[0] + (NE
- 1);
3260 #ifdef ARM_EXTENDED_IEEE_FORMAT
3261 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3262 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3268 for (i
= 0; i
< 4; i
++)
3273 /* Point to the exponent field and check max exponent cases. */
3275 if ((*p
& 0x7fff) == 0x7fff)
3278 if (! REAL_WORDS_BIG_ENDIAN
)
3280 for (i
= 0; i
< 4; i
++)
3282 if ((i
!= 3 && pe
[i
] != 0)
3283 /* Anything but 0x8000 here, including 0, is a NaN. */
3284 || (i
== 3 && pe
[i
] != 0x8000))
3286 enan (y
, (*p
& 0x8000) != 0);
3293 #ifdef ARM_EXTENDED_IEEE_FORMAT
3294 for (i
= 2; i
<= 5; i
++)
3298 enan (y
, (*p
& 0x8000) != 0);
3303 /* In Motorola extended precision format, the most significant
3304 bit of an infinity mantissa could be either 1 or 0. It is
3305 the lower order bits that tell whether the value is a NaN. */
3306 if ((pe
[2] & 0x7fff) != 0)
3309 for (i
= 3; i
<= 5; i
++)
3314 enan (y
, (*p
& 0x8000) != 0);
3318 #endif /* not ARM */
3327 #endif /* INFINITY */
3330 for (i
= 0; i
< NE
; i
++)
3334 #ifndef INTEL_EXTENDED_IEEE_FORMAT
3335 /* Convert 128-bit long double precision float PE to e type Y. */
3339 unsigned EMUSHORT
*pe
, *y
;
3341 register unsigned EMUSHORT r
;
3342 unsigned EMUSHORT
*e
, *p
;
3343 unsigned EMUSHORT yy
[NI
];
3350 if (! REAL_WORDS_BIG_ENDIAN
)
3362 if (! REAL_WORDS_BIG_ENDIAN
)
3364 for (i
= 0; i
< 7; i
++)
3368 enan (y
, yy
[0] != 0);
3375 for (i
= 1; i
< 8; i
++)
3379 enan (y
, yy
[0] != 0);
3391 #endif /* INFINITY */
3395 if (! REAL_WORDS_BIG_ENDIAN
)
3397 for (i
= 0; i
< 7; i
++)
3403 for (i
= 0; i
< 7; i
++)
3407 /* If denormal, remove the implied bit; else shift down 1. */
3421 /* Convert single precision float PE to e type Y. */
3425 unsigned EMUSHORT
*pe
, *y
;
3429 ibmtoe (pe
, y
, SFmode
);
3435 c4xtoe (pe
, y
, QFmode
);
3439 register unsigned EMUSHORT r
;
3440 register unsigned EMUSHORT
*e
, *p
;
3441 unsigned EMUSHORT yy
[NI
];
3445 denorm
= 0; /* flag if denormalized number */
3448 if (! REAL_WORDS_BIG_ENDIAN
)
3458 yy
[M
] = (r
& 0x7f) | 0200;
3459 r
&= ~0x807f; /* strip sign and 7 significand bits */
3464 if (REAL_WORDS_BIG_ENDIAN
)
3466 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3468 enan (y
, yy
[0] != 0);
3474 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3476 enan (y
, yy
[0] != 0);
3487 #endif /* INFINITY */
3489 /* If zero exponent, then the significand is denormalized.
3490 So take back the understood high significand bit. */
3503 if (! REAL_WORDS_BIG_ENDIAN
)
3513 { /* if zero exponent, then normalize the significand */
3514 if ((k
= enormlz (yy
)) > NBITS
)
3517 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3520 #endif /* not C4X */
3521 #endif /* not IBM */
3524 /* Convert e-type X to IEEE 128-bit long double format E. */
3528 unsigned EMUSHORT
*x
, *e
;
3530 unsigned EMUSHORT xi
[NI
];
3537 make_nan (e
, eisneg (x
), TFmode
);
3542 exp
= (EMULONG
) xi
[E
];
3547 /* round off to nearest or even */
3550 emdnorm (xi
, 0, 0, exp
, 64);
3558 /* Convert exploded e-type X, that has already been rounded to
3559 113-bit precision, to IEEE 128-bit long double format Y. */
3563 unsigned EMUSHORT
*a
, *b
;
3565 register unsigned EMUSHORT
*p
, *q
;
3566 unsigned EMUSHORT i
;
3571 make_nan (b
, eiisneg (a
), TFmode
);
3576 if (REAL_WORDS_BIG_ENDIAN
)
3579 q
= b
+ 7; /* point to output exponent */
3581 /* If not denormal, delete the implied bit. */
3586 /* combine sign and exponent */
3588 if (REAL_WORDS_BIG_ENDIAN
)
3591 *q
++ = *p
++ | 0x8000;
3598 *q
-- = *p
++ | 0x8000;
3602 /* skip over guard word */
3604 /* move the significand */
3605 if (REAL_WORDS_BIG_ENDIAN
)
3607 for (i
= 0; i
< 7; i
++)
3612 for (i
= 0; i
< 7; i
++)
3617 /* Convert e-type X to IEEE double extended format E. */
3621 unsigned EMUSHORT
*x
, *e
;
3623 unsigned EMUSHORT xi
[NI
];
3630 make_nan (e
, eisneg (x
), XFmode
);
3635 /* adjust exponent for offset */
3636 exp
= (EMULONG
) xi
[E
];
3641 /* round off to nearest or even */
3644 emdnorm (xi
, 0, 0, exp
, 64);
3652 /* Convert exploded e-type X, that has already been rounded to
3653 64-bit precision, to IEEE double extended format Y. */
3657 unsigned EMUSHORT
*a
, *b
;
3659 register unsigned EMUSHORT
*p
, *q
;
3660 unsigned EMUSHORT i
;
3665 make_nan (b
, eiisneg (a
), XFmode
);
3669 /* Shift denormal long double Intel format significand down one bit. */
3670 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3680 if (REAL_WORDS_BIG_ENDIAN
)
3684 q
= b
+ 4; /* point to output exponent */
3685 /* Clear the last two bytes of 12-byte Intel format. q is pointing
3686 into an array of size 6 (e.g. x[NE]), so the last two bytes are
3687 always there, and there are never more bytes, even when we are using
3688 INTEL_EXTENDED_IEEE_FORMAT. */
3693 /* combine sign and exponent */
3697 *q
++ = *p
++ | 0x8000;
3704 *q
-- = *p
++ | 0x8000;
3709 if (REAL_WORDS_BIG_ENDIAN
)
3711 #ifdef ARM_EXTENDED_IEEE_FORMAT
3712 /* The exponent is in the lowest 15 bits of the first word. */
3713 *q
++ = i
? 0x8000 : 0;
3717 *q
++ = *p
++ | 0x8000;
3726 *q
-- = *p
++ | 0x8000;
3731 /* skip over guard word */
3733 /* move the significand */
3735 for (i
= 0; i
< 4; i
++)
3739 for (i
= 0; i
< 4; i
++)
3743 if (REAL_WORDS_BIG_ENDIAN
)
3745 for (i
= 0; i
< 4; i
++)
3753 /* Intel long double infinity significand. */
3761 for (i
= 0; i
< 4; i
++)
3767 /* e type to double precision. */
3770 /* Convert e-type X to DEC-format double E. */
3774 unsigned EMUSHORT
*x
, *e
;
3776 etodec (x
, e
); /* see etodec.c */
3779 /* Convert exploded e-type X, that has already been rounded to
3780 56-bit double precision, to DEC double Y. */
3784 unsigned EMUSHORT
*x
, *y
;
3791 /* Convert e-type X to IBM 370-format double E. */
3795 unsigned EMUSHORT
*x
, *e
;
3797 etoibm (x
, e
, DFmode
);
3800 /* Convert exploded e-type X, that has already been rounded to
3801 56-bit precision, to IBM 370 double Y. */
3805 unsigned EMUSHORT
*x
, *y
;
3807 toibm (x
, y
, DFmode
);
3810 #else /* it's neither DEC nor IBM */
3812 /* Convert e-type X to C4X-format long double E. */
3816 unsigned EMUSHORT
*x
, *e
;
3818 etoc4x (x
, e
, HFmode
);
3821 /* Convert exploded e-type X, that has already been rounded to
3822 56-bit precision, to IBM 370 double Y. */
3826 unsigned EMUSHORT
*x
, *y
;
3828 toc4x (x
, y
, HFmode
);
3831 #else /* it's neither DEC nor IBM nor C4X */
3833 /* Convert e-type X to IEEE double E. */
3837 unsigned EMUSHORT
*x
, *e
;
3839 unsigned EMUSHORT xi
[NI
];
3846 make_nan (e
, eisneg (x
), DFmode
);
3851 /* adjust exponent for offsets */
3852 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3857 /* round off to nearest or even */
3860 emdnorm (xi
, 0, 0, exp
, 64);
3868 /* Convert exploded e-type X, that has already been rounded to
3869 53-bit precision, to IEEE double Y. */
3873 unsigned EMUSHORT
*x
, *y
;
3875 unsigned EMUSHORT i
;
3876 unsigned EMUSHORT
*p
;
3881 make_nan (y
, eiisneg (x
), DFmode
);
3887 if (! REAL_WORDS_BIG_ENDIAN
)
3890 *y
= 0; /* output high order */
3892 *y
= 0x8000; /* output sign bit */
3895 if (i
>= (unsigned int) 2047)
3897 /* Saturate at largest number less than infinity. */
3900 if (! REAL_WORDS_BIG_ENDIAN
)
3914 *y
|= (unsigned EMUSHORT
) 0x7fef;
3915 if (! REAL_WORDS_BIG_ENDIAN
)
3940 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3941 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3942 if (! REAL_WORDS_BIG_ENDIAN
)
3957 #endif /* not C4X */
3958 #endif /* not IBM */
3959 #endif /* not DEC */
3963 /* e type to single precision. */
3966 /* Convert e-type X to IBM 370 float E. */
3970 unsigned EMUSHORT
*x
, *e
;
3972 etoibm (x
, e
, SFmode
);
3975 /* Convert exploded e-type X, that has already been rounded to
3976 float precision, to IBM 370 float Y. */
3980 unsigned EMUSHORT
*x
, *y
;
3982 toibm (x
, y
, SFmode
);
3988 /* Convert e-type X to C4X float E. */
3992 unsigned EMUSHORT
*x
, *e
;
3994 etoc4x (x
, e
, QFmode
);
3997 /* Convert exploded e-type X, that has already been rounded to
3998 float precision, to IBM 370 float Y. */
4002 unsigned EMUSHORT
*x
, *y
;
4004 toc4x (x
, y
, QFmode
);
4009 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
4013 unsigned EMUSHORT
*x
, *e
;
4016 unsigned EMUSHORT xi
[NI
];
4022 make_nan (e
, eisneg (x
), SFmode
);
4027 /* adjust exponent for offsets */
4028 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
4033 /* round off to nearest or even */
4036 emdnorm (xi
, 0, 0, exp
, 64);
4044 /* Convert exploded e-type X, that has already been rounded to
4045 float precision, to IEEE float Y. */
4049 unsigned EMUSHORT
*x
, *y
;
4051 unsigned EMUSHORT i
;
4052 unsigned EMUSHORT
*p
;
4057 make_nan (y
, eiisneg (x
), SFmode
);
4063 if (! REAL_WORDS_BIG_ENDIAN
)
4069 *y
= 0; /* output high order */
4071 *y
= 0x8000; /* output sign bit */
4074 /* Handle overflow cases. */
4078 *y
|= (unsigned EMUSHORT
) 0x7f80;
4083 if (! REAL_WORDS_BIG_ENDIAN
)
4091 #else /* no INFINITY */
4092 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4097 if (! REAL_WORDS_BIG_ENDIAN
)
4108 #endif /* no INFINITY */
4120 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4121 /* High order output already has sign bit set. */
4127 if (! REAL_WORDS_BIG_ENDIAN
)
4136 #endif /* not C4X */
4137 #endif /* not IBM */
4139 /* Compare two e type numbers.
4143 -2 if either a or b is a NaN. */
4147 unsigned EMUSHORT
*a
, *b
;
4149 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4150 register unsigned EMUSHORT
*p
, *q
;
4155 if (eisnan (a
) || eisnan (b
))
4164 { /* the signs are different */
4166 for (i
= 1; i
< NI
- 1; i
++)
4180 /* both are the same sign */
4195 return (0); /* equality */
4199 if (*(--p
) > *(--q
))
4200 return (msign
); /* p is bigger */
4202 return (-msign
); /* p is littler */
4206 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4210 unsigned EMUSHORT
*x
, *y
;
4217 /* Convert HOST_WIDE_INT LP to e type Y. */
4222 unsigned EMUSHORT
*y
;
4224 unsigned EMUSHORT yi
[NI
];
4225 unsigned HOST_WIDE_INT ll
;
4231 /* make it positive */
4232 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4233 yi
[0] = 0xffff; /* put correct sign in the e type number */
4237 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4239 /* move the long integer to yi significand area */
4240 #if HOST_BITS_PER_WIDE_INT == 64
4241 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4242 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4243 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4244 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4245 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4247 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4248 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4249 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4252 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4253 ecleaz (yi
); /* it was zero */
4255 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4256 emovo (yi
, y
); /* output the answer */
4259 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4263 unsigned HOST_WIDE_INT
*lp
;
4264 unsigned EMUSHORT
*y
;
4266 unsigned EMUSHORT yi
[NI
];
4267 unsigned HOST_WIDE_INT ll
;
4273 /* move the long integer to ayi significand area */
4274 #if HOST_BITS_PER_WIDE_INT == 64
4275 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4276 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4277 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4278 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4279 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4281 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4282 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4283 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4286 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4287 ecleaz (yi
); /* it was zero */
4289 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4290 emovo (yi
, y
); /* output the answer */
4294 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4295 part FRAC of e-type (packed internal format) floating point input X.
4296 The integer output I has the sign of the input, except that
4297 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4298 The output e-type fraction FRAC is the positive fractional
4303 unsigned EMUSHORT
*x
;
4305 unsigned EMUSHORT
*frac
;
4307 unsigned EMUSHORT xi
[NI
];
4309 unsigned HOST_WIDE_INT ll
;
4312 k
= (int) xi
[E
] - (EXONE
- 1);
4315 /* if exponent <= 0, integer = 0 and real output is fraction */
4320 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4322 /* long integer overflow: output large integer
4323 and correct fraction */
4325 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4328 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4329 /* In this case, let it overflow and convert as if unsigned. */
4330 euifrac (x
, &ll
, frac
);
4331 *i
= (HOST_WIDE_INT
) ll
;
4334 /* In other cases, return the largest positive integer. */
4335 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4340 warning ("overflow on truncation to integer");
4344 /* Shift more than 16 bits: first shift up k-16 mod 16,
4345 then shift up by 16's. */
4346 j
= k
- ((k
>> 4) << 4);
4353 ll
= (ll
<< 16) | xi
[M
];
4355 while ((k
-= 16) > 0);
4362 /* shift not more than 16 bits */
4364 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4371 if ((k
= enormlz (xi
)) > NBITS
)
4374 xi
[E
] -= (unsigned EMUSHORT
) k
;
4380 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4381 FRAC of e-type X. A negative input yields integer output = 0 but
4382 correct fraction. */
4385 euifrac (x
, i
, frac
)
4386 unsigned EMUSHORT
*x
;
4387 unsigned HOST_WIDE_INT
*i
;
4388 unsigned EMUSHORT
*frac
;
4390 unsigned HOST_WIDE_INT ll
;
4391 unsigned EMUSHORT xi
[NI
];
4395 k
= (int) xi
[E
] - (EXONE
- 1);
4398 /* if exponent <= 0, integer = 0 and argument is fraction */
4403 if (k
> HOST_BITS_PER_WIDE_INT
)
4405 /* Long integer overflow: output large integer
4406 and correct fraction.
4407 Note, the BSD microvax compiler says that ~(0UL)
4408 is a syntax error. */
4412 warning ("overflow on truncation to unsigned integer");
4416 /* Shift more than 16 bits: first shift up k-16 mod 16,
4417 then shift up by 16's. */
4418 j
= k
- ((k
>> 4) << 4);
4425 ll
= (ll
<< 16) | xi
[M
];
4427 while ((k
-= 16) > 0);
4432 /* shift not more than 16 bits */
4434 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4437 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4443 if ((k
= enormlz (xi
)) > NBITS
)
4446 xi
[E
] -= (unsigned EMUSHORT
) k
;
4451 /* Shift the significand of exploded e-type X up or down by SC bits. */
4455 unsigned EMUSHORT
*x
;
4458 unsigned EMUSHORT lost
;
4459 unsigned EMUSHORT
*p
;
4472 lost
|= *p
; /* remember lost bits */
4513 return ((int) lost
);
4516 /* Shift normalize the significand area of exploded e-type X.
4517 Return the shift count (up = positive). */
4521 unsigned EMUSHORT x
[];
4523 register unsigned EMUSHORT
*p
;
4532 return (0); /* already normalized */
4538 /* With guard word, there are NBITS+16 bits available.
4539 Return true if all are zero. */
4543 /* see if high byte is zero */
4544 while ((*p
& 0xff00) == 0)
4549 /* now shift 1 bit at a time */
4550 while ((*p
& 0x8000) == 0)
4556 mtherr ("enormlz", UNDERFLOW
);
4562 /* Normalize by shifting down out of the high guard word
4563 of the significand */
4578 mtherr ("enormlz", OVERFLOW
);
4585 /* Powers of ten used in decimal <-> binary conversions. */
4590 #if MAX_LONG_DOUBLE_TYPE_SIZE == 128 && !defined(INTEL_EXTENDED_IEEE_FORMAT)
4591 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4593 {0x6576, 0x4a92, 0x804a, 0x153f,
4594 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4595 {0x6a32, 0xce52, 0x329a, 0x28ce,
4596 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4597 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4598 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4599 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4600 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4601 {0x851e, 0xeab7, 0x98fe, 0x901b,
4602 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4603 {0x0235, 0x0137, 0x36b1, 0x336c,
4604 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4605 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4606 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4607 {0x0000, 0x0000, 0x0000, 0x0000,
4608 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4609 {0x0000, 0x0000, 0x0000, 0x0000,
4610 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4611 {0x0000, 0x0000, 0x0000, 0x0000,
4612 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4613 {0x0000, 0x0000, 0x0000, 0x0000,
4614 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4615 {0x0000, 0x0000, 0x0000, 0x0000,
4616 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4617 {0x0000, 0x0000, 0x0000, 0x0000,
4618 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4621 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4623 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4624 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4625 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4626 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4627 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4628 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4629 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4630 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4631 {0xa23e, 0x5308, 0xfefb, 0x1155,
4632 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4633 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4634 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4635 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4636 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4637 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4638 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4639 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4640 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4641 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4642 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4643 {0xc155, 0xa4a8, 0x404e, 0x6113,
4644 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4645 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4646 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4647 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4648 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4651 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4652 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4654 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4655 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4656 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4657 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4658 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4659 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4660 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4661 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4662 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4663 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4664 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4665 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4666 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4669 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4671 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4672 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4673 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4674 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4675 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4676 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4677 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4678 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4679 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4680 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4681 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4682 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4683 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4688 /* Convert float value X to ASCII string STRING with NDIG digits after
4689 the decimal point. */
4692 e24toasc (x
, string
, ndigs
)
4693 unsigned EMUSHORT x
[];
4697 unsigned EMUSHORT w
[NI
];
4700 etoasc (w
, string
, ndigs
);
4703 /* Convert double value X to ASCII string STRING with NDIG digits after
4704 the decimal point. */
4707 e53toasc (x
, string
, ndigs
)
4708 unsigned EMUSHORT x
[];
4712 unsigned EMUSHORT w
[NI
];
4715 etoasc (w
, string
, ndigs
);
4718 /* Convert double extended value X to ASCII string STRING with NDIG digits
4719 after the decimal point. */
4722 e64toasc (x
, string
, ndigs
)
4723 unsigned EMUSHORT x
[];
4727 unsigned EMUSHORT w
[NI
];
4730 etoasc (w
, string
, ndigs
);
4733 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4734 after the decimal point. */
4737 e113toasc (x
, string
, ndigs
)
4738 unsigned EMUSHORT x
[];
4742 unsigned EMUSHORT w
[NI
];
4745 etoasc (w
, string
, ndigs
);
4749 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4750 the decimal point. */
4752 static char wstring
[80]; /* working storage for ASCII output */
4755 etoasc (x
, string
, ndigs
)
4756 unsigned EMUSHORT x
[];
4761 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4762 unsigned EMUSHORT
*p
, *r
, *ten
;
4763 unsigned EMUSHORT sign
;
4764 int i
, j
, k
, expon
, rndsav
;
4766 unsigned EMUSHORT m
;
4777 sprintf (wstring
, " NaN ");
4781 rndprc
= NBITS
; /* set to full precision */
4782 emov (x
, y
); /* retain external format */
4783 if (y
[NE
- 1] & 0x8000)
4786 y
[NE
- 1] &= 0x7fff;
4793 ten
= &etens
[NTEN
][0];
4795 /* Test for zero exponent */
4798 for (k
= 0; k
< NE
- 1; k
++)
4801 goto tnzro
; /* denormalized number */
4803 goto isone
; /* valid all zeros */
4807 /* Test for infinity. */
4808 if (y
[NE
- 1] == 0x7fff)
4811 sprintf (wstring
, " -Infinity ");
4813 sprintf (wstring
, " Infinity ");
4817 /* Test for exponent nonzero but significand denormalized.
4818 * This is an error condition.
4820 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4822 mtherr ("etoasc", DOMAIN
);
4823 sprintf (wstring
, "NaN");
4827 /* Compare to 1.0 */
4836 { /* Number is greater than 1 */
4837 /* Convert significand to an integer and strip trailing decimal zeros. */
4839 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4841 p
= &etens
[NTEN
- 4][0];
4847 for (j
= 0; j
< NE
- 1; j
++)
4860 /* Rescale from integer significand */
4861 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4863 /* Find power of 10 */
4867 /* An unordered compare result shouldn't happen here. */
4868 while (ecmp (ten
, u
) <= 0)
4870 if (ecmp (p
, u
) <= 0)
4883 { /* Number is less than 1.0 */
4884 /* Pad significand with trailing decimal zeros. */
4887 while ((y
[NE
- 2] & 0x8000) == 0)
4896 for (i
= 0; i
< NDEC
+ 1; i
++)
4898 if ((w
[NI
- 1] & 0x7) != 0)
4900 /* multiply by 10 */
4913 if (eone
[NE
- 1] <= u
[1])
4925 while (ecmp (eone
, w
) > 0)
4927 if (ecmp (p
, w
) >= 0)
4942 /* Find the first (leading) digit. */
4948 digit
= equot
[NI
- 1];
4949 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4957 digit
= equot
[NI
- 1];
4965 /* Examine number of digits requested by caller. */
4983 *s
++ = (char)digit
+ '0';
4986 /* Generate digits after the decimal point. */
4987 for (k
= 0; k
<= ndigs
; k
++)
4989 /* multiply current number by 10, without normalizing */
4996 *s
++ = (char) equot
[NI
- 1] + '0';
4998 digit
= equot
[NI
- 1];
5001 /* round off the ASCII string */
5004 /* Test for critical rounding case in ASCII output. */
5008 if (ecmp (t
, ezero
) != 0)
5009 goto roun
; /* round to nearest */
5011 if ((*(s
- 1) & 1) == 0)
5012 goto doexp
; /* round to even */
5015 /* Round up and propagate carry-outs */
5019 /* Carry out to most significant digit? */
5026 /* Most significant digit carries to 10? */
5034 /* Round up and carry out from less significant digits */
5046 sprintf (ss, "e+%d", expon);
5048 sprintf (ss, "e%d", expon);
5050 sprintf (ss
, "e%d", expon
);
5053 /* copy out the working string */
5056 while (*ss
== ' ') /* strip possible leading space */
5058 while ((*s
++ = *ss
++) != '\0')
5063 /* Convert ASCII string to floating point.
5065 Numeric input is a free format decimal number of any length, with
5066 or without decimal point. Entering E after the number followed by an
5067 integer number causes the second number to be interpreted as a power of
5068 10 to be multiplied by the first number (i.e., "scientific" notation). */
5070 /* Convert ASCII string S to single precision float value Y. */
5075 unsigned EMUSHORT
*y
;
5081 /* Convert ASCII string S to double precision value Y. */
5086 unsigned EMUSHORT
*y
;
5088 #if defined(DEC) || defined(IBM)
5100 /* Convert ASCII string S to double extended value Y. */
5105 unsigned EMUSHORT
*y
;
5110 #ifndef INTEL_EXTENDED_IEEE_FORMAT
5111 /* Convert ASCII string S to 128-bit long double Y. */
5116 unsigned EMUSHORT
*y
;
5118 asctoeg (s
, y
, 113);
5122 /* Convert ASCII string S to e type Y. */
5127 unsigned EMUSHORT
*y
;
5129 asctoeg (s
, y
, NBITS
);
5132 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5133 of OPREC bits. BASE is 16 for C99 hexadecimal floating constants. */
5136 asctoeg (ss
, y
, oprec
)
5138 unsigned EMUSHORT
*y
;
5141 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5142 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5143 int i
, k
, trail
, c
, rndsav
;
5145 unsigned EMUSHORT nsign
;
5146 char *sp
, *s
, *lstr
;
5149 /* Copy the input string. */
5150 lstr
= (char *) alloca (strlen (ss
) + 1);
5152 while (*ss
== ' ') /* skip leading spaces */
5156 while ((*sp
++ = *ss
++) != '\0')
5160 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5167 rndprc
= NBITS
; /* Set to full precision */
5179 if (*s
>= '0' && *s
<= '9')
5181 else if (*s
>= 'a' && *s
<= 'f')
5185 if ((k
>= 0) && (k
< base
))
5187 /* Ignore leading zeros */
5188 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5190 /* Identify and strip trailing zeros after the decimal point. */
5191 if ((trail
== 0) && (decflg
!= 0))
5194 while ((*sp
>= '0' && *sp
<= '9')
5195 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5196 || (*sp
>= 'A' && *sp
<= 'F'))))
5198 /* Check for syntax error */
5200 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5201 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5203 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5205 goto unexpected_char_error
;
5214 /* If enough digits were given to more than fill up the yy register,
5215 continuing until overflow into the high guard word yy[2]
5216 guarantees that there will be a roundoff bit at the top
5217 of the low guard word after normalization. */
5224 nexp
+= 4; /* count digits after decimal point */
5226 eshup1 (yy
); /* multiply current number by 16 */
5234 nexp
+= 1; /* count digits after decimal point */
5236 eshup1 (yy
); /* multiply current number by 10 */
5242 /* Insert the current digit. */
5244 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5249 /* Mark any lost non-zero digit. */
5251 /* Count lost digits before the decimal point. */
5273 case '.': /* decimal point */
5275 goto unexpected_char_error
;
5281 goto unexpected_char_error
;
5286 goto unexpected_char_error
;
5299 unexpected_char_error
:
5303 mtherr ("asctoe", DOMAIN
);
5312 /* Exponent interpretation */
5314 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5315 for (k
= 0; k
< NI
; k
++)
5326 /* check for + or - */
5334 while ((*s
>= '0') && (*s
<= '9'))
5343 if ((exp
> MAXDECEXP
) && (base
== 10))
5347 yy
[E
] = 0x7fff; /* infinity */
5350 if ((exp
< MINDECEXP
) && (base
== 10))
5360 /* Base 16 hexadecimal floating constant. */
5361 if ((k
= enormlz (yy
)) > NBITS
)
5366 /* Adjust the exponent. NEXP is the number of hex digits,
5367 EXP is a power of 2. */
5368 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5378 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5379 while ((nexp
> 0) && (yy
[2] == 0))
5391 if ((k
= enormlz (yy
)) > NBITS
)
5396 lexp
= (EXONE
- 1 + NBITS
) - k
;
5397 emdnorm (yy
, lost
, 0, lexp
, 64);
5400 /* Convert to external format:
5402 Multiply by 10**nexp. If precision is 64 bits,
5403 the maximum relative error incurred in forming 10**n
5404 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5405 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5406 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5421 /* Punt. Can't handle this without 2 divides. */
5422 emovi (etens
[0], tt
);
5435 emul (etens
[i
], xt
, xt
);
5439 while (exp
<= MAXP
);
5458 /* Round and convert directly to the destination type */
5460 lexp
-= EXONE
- 0x3ff;
5462 else if (oprec
== 24 || oprec
== 32)
5463 lexp
-= (EXONE
- 0x7f);
5466 else if (oprec
== 24 || oprec
== 56)
5467 lexp
-= EXONE
- (0x41 << 2);
5469 else if (oprec
== 24)
5470 lexp
-= EXONE
- 0177;
5474 else if (oprec
== 56)
5475 lexp
-= EXONE
- 0201;
5478 emdnorm (yy
, lost
, 0, lexp
, 64);
5488 todec (yy
, y
); /* see etodec.c */
5493 toibm (yy
, y
, DFmode
);
5498 toc4x (yy
, y
, HFmode
);
5522 /* Return Y = largest integer not greater than X (truncated toward minus
5525 static unsigned EMUSHORT bmask
[] =
5548 unsigned EMUSHORT x
[], y
[];
5550 register unsigned EMUSHORT
*p
;
5552 unsigned EMUSHORT f
[NE
];
5554 emov (x
, f
); /* leave in external format */
5555 expon
= (int) f
[NE
- 1];
5556 e
= (expon
& 0x7fff) - (EXONE
- 1);
5562 /* number of bits to clear out */
5574 /* clear the remaining bits */
5576 /* truncate negatives toward minus infinity */
5579 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5581 for (i
= 0; i
< NE
- 1; i
++)
5594 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5595 For example, 1.1 = 0.55 * 2^1. */
5599 unsigned EMUSHORT x
[];
5601 unsigned EMUSHORT s
[];
5603 unsigned EMUSHORT xi
[NI
];
5607 /* Handle denormalized numbers properly using long integer exponent. */
5608 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5616 *exp
= (int) (li
- 0x3ffe);
5620 /* Return e type Y = X * 2^PWR2. */
5624 unsigned EMUSHORT x
[];
5626 unsigned EMUSHORT y
[];
5628 unsigned EMUSHORT xi
[NI
];
5636 emdnorm (xi
, i
, i
, li
, 64);
5642 /* C = remainder after dividing B by A, all e type values.
5643 Least significant integer quotient bits left in EQUOT. */
5647 unsigned EMUSHORT a
[], b
[], c
[];
5649 unsigned EMUSHORT den
[NI
], num
[NI
];
5653 || (ecmp (a
, ezero
) == 0)
5661 if (ecmp (a
, ezero
) == 0)
5663 mtherr ("eremain", SING
);
5669 eiremain (den
, num
);
5670 /* Sign of remainder = sign of quotient */
5679 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5680 remainder in NUM. */
5684 unsigned EMUSHORT den
[], num
[];
5687 unsigned EMUSHORT j
;
5690 ld
-= enormlz (den
);
5692 ln
-= enormlz (num
);
5696 if (ecmpm (den
, num
) <= 0)
5708 emdnorm (num
, 0, 0, ln
, 0);
5711 /* Report an error condition CODE encountered in function NAME.
5713 Mnemonic Value Significance
5715 DOMAIN 1 argument domain error
5716 SING 2 function singularity
5717 OVERFLOW 3 overflow range error
5718 UNDERFLOW 4 underflow range error
5719 TLOSS 5 total loss of precision
5720 PLOSS 6 partial loss of precision
5721 INVALID 7 NaN - producing operation
5722 EDOM 33 Unix domain error code
5723 ERANGE 34 Unix range error code
5725 The order of appearance of the following messages is bound to the
5726 error codes defined above. */
5736 /* The string passed by the calling program is supposed to be the
5737 name of the function in which the error occurred.
5738 The code argument selects which error message string will be printed. */
5740 if (strcmp (name
, "esub") == 0)
5741 name
= "subtraction";
5742 else if (strcmp (name
, "ediv") == 0)
5744 else if (strcmp (name
, "emul") == 0)
5745 name
= "multiplication";
5746 else if (strcmp (name
, "enormlz") == 0)
5747 name
= "normalization";
5748 else if (strcmp (name
, "etoasc") == 0)
5749 name
= "conversion to text";
5750 else if (strcmp (name
, "asctoe") == 0)
5752 else if (strcmp (name
, "eremain") == 0)
5754 else if (strcmp (name
, "esqrt") == 0)
5755 name
= "square root";
5760 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5761 case SING
: warning ("%s: function singularity" , name
); break;
5762 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5763 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5764 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5765 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5766 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5771 /* Set global error message word */
5776 /* Convert DEC double precision D to e type E. */
5780 unsigned EMUSHORT
*d
;
5781 unsigned EMUSHORT
*e
;
5783 unsigned EMUSHORT y
[NI
];
5784 register unsigned EMUSHORT r
, *p
;
5786 ecleaz (y
); /* start with a zero */
5787 p
= y
; /* point to our number */
5788 r
= *d
; /* get DEC exponent word */
5789 if (*d
& (unsigned int) 0x8000)
5790 *p
= 0xffff; /* fill in our sign */
5791 ++p
; /* bump pointer to our exponent word */
5792 r
&= 0x7fff; /* strip the sign bit */
5793 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5797 r
>>= 7; /* shift exponent word down 7 bits */
5798 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5799 /* add our e type exponent offset */
5800 *p
++ = r
; /* to form our exponent */
5802 r
= *d
++; /* now do the high order mantissa */
5803 r
&= 0177; /* strip off the DEC exponent and sign bits */
5804 r
|= 0200; /* the DEC understood high order mantissa bit */
5805 *p
++ = r
; /* put result in our high guard word */
5807 *p
++ = *d
++; /* fill in the rest of our mantissa */
5811 eshdn8 (y
); /* shift our mantissa down 8 bits */
5816 /* Convert e type X to DEC double precision D. */
5820 unsigned EMUSHORT
*x
, *d
;
5822 unsigned EMUSHORT xi
[NI
];
5827 /* Adjust exponent for offsets. */
5828 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5829 /* Round off to nearest or even. */
5832 emdnorm (xi
, 0, 0, exp
, 64);
5837 /* Convert exploded e-type X, that has already been rounded to
5838 56-bit precision, to DEC format double Y. */
5842 unsigned EMUSHORT
*x
, *y
;
5844 unsigned EMUSHORT i
;
5845 unsigned EMUSHORT
*p
;
5884 /* Convert IBM single/double precision to e type. */
5888 unsigned EMUSHORT
*d
;
5889 unsigned EMUSHORT
*e
;
5890 enum machine_mode mode
;
5892 unsigned EMUSHORT y
[NI
];
5893 register unsigned EMUSHORT r
, *p
;
5895 ecleaz (y
); /* start with a zero */
5896 p
= y
; /* point to our number */
5897 r
= *d
; /* get IBM exponent word */
5898 if (*d
& (unsigned int) 0x8000)
5899 *p
= 0xffff; /* fill in our sign */
5900 ++p
; /* bump pointer to our exponent word */
5901 r
&= 0x7f00; /* strip the sign bit */
5902 r
>>= 6; /* shift exponent word down 6 bits */
5903 /* in fact shift by 8 right and 2 left */
5904 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5905 /* add our e type exponent offset */
5906 *p
++ = r
; /* to form our exponent */
5908 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5909 /* strip off the IBM exponent and sign bits */
5910 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5912 *p
++ = *d
++; /* fill in the rest of our mantissa */
5917 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5920 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5921 /* handle change in RADIX */
5927 /* Convert e type to IBM single/double precision. */
5931 unsigned EMUSHORT
*x
, *d
;
5932 enum machine_mode mode
;
5934 unsigned EMUSHORT xi
[NI
];
5939 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5940 /* round off to nearest or even */
5943 emdnorm (xi
, 0, 0, exp
, 64);
5945 toibm (xi
, d
, mode
);
5950 unsigned EMUSHORT
*x
, *y
;
5951 enum machine_mode mode
;
5953 unsigned EMUSHORT i
;
5954 unsigned EMUSHORT
*p
;
6004 /* Convert C4X single/double precision to e type. */
6008 unsigned EMUSHORT
*d
;
6009 unsigned EMUSHORT
*e
;
6010 enum machine_mode mode
;
6012 unsigned EMUSHORT y
[NI
];
6019 /* Short-circuit the zero case. */
6020 if ((d
[0] == 0x8000)
6022 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
6033 ecleaz (y
); /* start with a zero */
6034 r
= d
[0]; /* get sign/exponent part */
6035 if (r
& (unsigned int) 0x0080)
6037 y
[0] = 0xffff; /* fill in our sign */
6045 r
>>= 8; /* Shift exponent word down 8 bits. */
6046 if (r
& 0x80) /* Make the exponent negative if it is. */
6048 r
= r
| (~0 & ~0xff);
6053 /* Now do the high order mantissa. We don't "or" on the high bit
6054 because it is 2 (not 1) and is handled a little differently
6059 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6061 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6071 /* Now do the two's complement on the data. */
6073 carry
= 1; /* Initially add 1 for the two's complement. */
6074 for (i
=size
+ M
; i
> M
; i
--)
6076 if (carry
&& (y
[i
] == 0x0000))
6078 /* We overflowed into the next word, carry is the same. */
6079 y
[i
] = carry
? 0x0000 : 0xffff;
6083 /* No overflow, just invert and add carry. */
6084 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6099 /* Add our e type exponent offset to form our exponent. */
6103 /* Now do the high order mantissa strip off the exponent and sign
6104 bits and add the high 1 bit. */
6105 y
[M
] = (d
[0] & 0x7f) | 0x80;
6108 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6110 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6120 /* Convert e type to C4X single/double precision. */
6124 unsigned EMUSHORT
*x
, *d
;
6125 enum machine_mode mode
;
6127 unsigned EMUSHORT xi
[NI
];
6133 /* Adjust exponent for offsets. */
6134 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6136 /* Round off to nearest or even. */
6138 rndprc
= mode
== QFmode
? 24 : 32;
6139 emdnorm (xi
, 0, 0, exp
, 64);
6141 toc4x (xi
, d
, mode
);
6146 unsigned EMUSHORT
*x
, *y
;
6147 enum machine_mode mode
;
6153 /* Short-circuit the zero case */
6154 if ((x
[0] == 0) /* Zero exponent and sign */
6156 && (x
[M
] == 0) /* The rest is for zero mantissa */
6158 /* Only check for double if necessary */
6159 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6161 /* We have a zero. Put it into the output and return. */
6174 /* Negative number require a two's complement conversion of the
6180 i
= ((int) x
[1]) - 0x7f;
6182 /* Now add 1 to the inverted data to do the two's complement. */
6192 x
[v
] = carry
? 0x0000 : 0xffff;
6196 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6202 /* The following is a special case. The C4X negative float requires
6203 a zero in the high bit (because the format is (2 - x) x 2^m), so
6204 if a one is in that bit, we have to shift left one to get rid
6205 of it. This only occurs if the number is -1 x 2^m. */
6206 if (x
[M
+1] & 0x8000)
6208 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6209 high sign bit and shift the exponent. */
6216 i
= ((int) x
[1]) - 0x7f;
6219 if ((i
< -128) || (i
> 127))
6234 y
[0] |= ((i
& 0xff) << 8);
6238 y
[0] |= x
[M
] & 0x7f;
6248 /* Output a binary NaN bit pattern in the target machine's format. */
6250 /* If special NaN bit patterns are required, define them in tm.h
6251 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6257 unsigned EMUSHORT TFbignan
[8] =
6258 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6259 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6267 unsigned EMUSHORT XFbignan
[6] =
6268 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6269 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6277 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6278 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6286 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6287 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6294 make_nan (nan
, sign
, mode
)
6295 unsigned EMUSHORT
*nan
;
6297 enum machine_mode mode
;
6300 unsigned EMUSHORT
*p
;
6304 /* Possibly the `reserved operand' patterns on a VAX can be
6305 used like NaN's, but probably not in the same way as IEEE. */
6306 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6308 #ifndef INTEL_EXTENDED_IEEE_FORMAT
6310 if (REAL_WORDS_BIG_ENDIAN
)
6320 if (REAL_WORDS_BIG_ENDIAN
)
6328 if (REAL_WORDS_BIG_ENDIAN
)
6337 if (REAL_WORDS_BIG_ENDIAN
)
6347 if (REAL_WORDS_BIG_ENDIAN
)
6348 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6351 if (! REAL_WORDS_BIG_ENDIAN
)
6352 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6356 /* This is the inverse of the function `etarsingle' invoked by
6357 REAL_VALUE_TO_TARGET_SINGLE. */
6360 ereal_unto_float (f
)
6364 unsigned EMUSHORT s
[2];
6365 unsigned EMUSHORT e
[NE
];
6367 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6368 This is the inverse operation to what the function `endian' does. */
6369 if (REAL_WORDS_BIG_ENDIAN
)
6371 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6372 s
[1] = (unsigned EMUSHORT
) f
;
6376 s
[0] = (unsigned EMUSHORT
) f
;
6377 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6379 /* Convert and promote the target float to E-type. */
6381 /* Output E-type to REAL_VALUE_TYPE. */
6387 /* This is the inverse of the function `etardouble' invoked by
6388 REAL_VALUE_TO_TARGET_DOUBLE. */
6391 ereal_unto_double (d
)
6395 unsigned EMUSHORT s
[4];
6396 unsigned EMUSHORT e
[NE
];
6398 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6399 if (REAL_WORDS_BIG_ENDIAN
)
6401 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6402 s
[1] = (unsigned EMUSHORT
) d
[0];
6403 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6404 s
[3] = (unsigned EMUSHORT
) d
[1];
6408 /* Target float words are little-endian. */
6409 s
[0] = (unsigned EMUSHORT
) d
[0];
6410 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6411 s
[2] = (unsigned EMUSHORT
) d
[1];
6412 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6414 /* Convert target double to E-type. */
6416 /* Output E-type to REAL_VALUE_TYPE. */
6422 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6423 This is somewhat like ereal_unto_float, but the input types
6424 for these are different. */
6427 ereal_from_float (f
)
6431 unsigned EMUSHORT s
[2];
6432 unsigned EMUSHORT e
[NE
];
6434 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6435 This is the inverse operation to what the function `endian' does. */
6436 if (REAL_WORDS_BIG_ENDIAN
)
6438 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6439 s
[1] = (unsigned EMUSHORT
) f
;
6443 s
[0] = (unsigned EMUSHORT
) f
;
6444 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6446 /* Convert and promote the target float to E-type. */
6448 /* Output E-type to REAL_VALUE_TYPE. */
6454 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6455 This is somewhat like ereal_unto_double, but the input types
6456 for these are different.
6458 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6459 data format, with no holes in the bit packing. The first element
6460 of the input array holds the bits that would come first in the
6461 target computer's memory. */
6464 ereal_from_double (d
)
6468 unsigned EMUSHORT s
[4];
6469 unsigned EMUSHORT e
[NE
];
6471 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6472 if (REAL_WORDS_BIG_ENDIAN
)
6474 #if HOST_BITS_PER_WIDE_INT == 32
6475 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6476 s
[1] = (unsigned EMUSHORT
) d
[0];
6477 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6478 s
[3] = (unsigned EMUSHORT
) d
[1];
6480 /* In this case the entire target double is contained in the
6481 first array element. The second element of the input is
6483 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6484 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6485 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6486 s
[3] = (unsigned EMUSHORT
) d
[0];
6491 /* Target float words are little-endian. */
6492 s
[0] = (unsigned EMUSHORT
) d
[0];
6493 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6494 #if HOST_BITS_PER_WIDE_INT == 32
6495 s
[2] = (unsigned EMUSHORT
) d
[1];
6496 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6498 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6499 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6502 /* Convert target double to E-type. */
6504 /* Output E-type to REAL_VALUE_TYPE. */
6511 /* Convert target computer unsigned 64-bit integer to e-type.
6512 The endian-ness of DImode follows the convention for integers,
6513 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6517 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6518 unsigned EMUSHORT
*e
;
6520 unsigned EMUSHORT yi
[NI
];
6524 if (WORDS_BIG_ENDIAN
)
6526 for (k
= M
; k
< M
+ 4; k
++)
6531 for (k
= M
+ 3; k
>= M
; k
--)
6534 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6535 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6536 ecleaz (yi
); /* it was zero */
6538 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6542 /* Convert target computer signed 64-bit integer to e-type. */
6546 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6547 unsigned EMUSHORT
*e
;
6549 unsigned EMULONG acc
;
6550 unsigned EMUSHORT yi
[NI
];
6551 unsigned EMUSHORT carry
;
6555 if (WORDS_BIG_ENDIAN
)
6557 for (k
= M
; k
< M
+ 4; k
++)
6562 for (k
= M
+ 3; k
>= M
; k
--)
6565 /* Take absolute value */
6571 for (k
= M
+ 3; k
>= M
; k
--)
6573 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6580 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6581 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6582 ecleaz (yi
); /* it was zero */
6584 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6591 /* Convert e-type to unsigned 64-bit int. */
6595 unsigned EMUSHORT
*x
;
6596 unsigned EMUSHORT
*i
;
6598 unsigned EMUSHORT xi
[NI
];
6607 k
= (int) xi
[E
] - (EXONE
- 1);
6610 for (j
= 0; j
< 4; j
++)
6616 for (j
= 0; j
< 4; j
++)
6619 warning ("overflow on truncation to integer");
6624 /* Shift more than 16 bits: first shift up k-16 mod 16,
6625 then shift up by 16's. */
6626 j
= k
- ((k
>> 4) << 4);
6630 if (WORDS_BIG_ENDIAN
)
6641 if (WORDS_BIG_ENDIAN
)
6646 while ((k
-= 16) > 0);
6650 /* shift not more than 16 bits */
6655 if (WORDS_BIG_ENDIAN
)
6674 /* Convert e-type to signed 64-bit int. */
6678 unsigned EMUSHORT
*x
;
6679 unsigned EMUSHORT
*i
;
6681 unsigned EMULONG acc
;
6682 unsigned EMUSHORT xi
[NI
];
6683 unsigned EMUSHORT carry
;
6684 unsigned EMUSHORT
*isave
;
6688 k
= (int) xi
[E
] - (EXONE
- 1);
6691 for (j
= 0; j
< 4; j
++)
6697 for (j
= 0; j
< 4; j
++)
6700 warning ("overflow on truncation to integer");
6706 /* Shift more than 16 bits: first shift up k-16 mod 16,
6707 then shift up by 16's. */
6708 j
= k
- ((k
>> 4) << 4);
6712 if (WORDS_BIG_ENDIAN
)
6723 if (WORDS_BIG_ENDIAN
)
6728 while ((k
-= 16) > 0);
6732 /* shift not more than 16 bits */
6735 if (WORDS_BIG_ENDIAN
)
6751 /* Negate if negative */
6755 if (WORDS_BIG_ENDIAN
)
6757 for (k
= 0; k
< 4; k
++)
6759 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6760 if (WORDS_BIG_ENDIAN
)
6772 /* Longhand square root routine. */
6775 static int esqinited
= 0;
6776 static unsigned short sqrndbit
[NI
];
6780 unsigned EMUSHORT
*x
, *y
;
6782 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6784 int i
, j
, k
, n
, nlups
;
6789 sqrndbit
[NI
- 2] = 1;
6792 /* Check for arg <= 0 */
6793 i
= ecmp (x
, ezero
);
6798 mtherr ("esqrt", DOMAIN
);
6814 /* Bring in the arg and renormalize if it is denormal. */
6816 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6820 /* Divide exponent by 2 */
6822 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6824 /* Adjust if exponent odd */
6834 n
= 8; /* get 8 bits of result per inner loop */
6840 /* bring in next word of arg */
6842 num
[NI
- 1] = xx
[j
+ 3];
6843 /* Do additional bit on last outer loop, for roundoff. */
6846 for (i
= 0; i
< n
; i
++)
6848 /* Next 2 bits of arg */
6851 /* Shift up answer */
6853 /* Make trial divisor */
6854 for (k
= 0; k
< NI
; k
++)
6857 eaddm (sqrndbit
, temp
);
6858 /* Subtract and insert answer bit if it goes in */
6859 if (ecmpm (temp
, num
) <= 0)
6869 /* Adjust for extra, roundoff loop done. */
6870 exp
+= (NBITS
- 1) - rndprc
;
6872 /* Sticky bit = 1 if the remainder is nonzero. */
6874 for (i
= 3; i
< NI
; i
++)
6877 /* Renormalize and round off. */
6878 emdnorm (sq
, k
, 0, exp
, 64);
6882 #endif /* EMU_NON_COMPILE not defined */
6884 /* Return the binary precision of the significand for a given
6885 floating point mode. The mode can hold an integer value
6886 that many bits wide, without losing any bits. */
6889 significand_size (mode
)
6890 enum machine_mode mode
;
6893 /* Don't test the modes, but their sizes, lest this
6894 code won't work for BITS_PER_UNIT != 8 . */
6896 switch (GET_MODE_BITSIZE (mode
))
6900 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6907 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6910 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6913 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6916 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6929 #ifndef INTEL_EXTENDED_IEEE_FORMAT