1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 94-98, 1999 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
28 /* To enable support of XFmode extended real floating point, define
29 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
31 To support cross compilation between IEEE, VAX and IBM floating
32 point formats, define REAL_ARITHMETIC in the tm.h file.
34 In either case the machine files (tm.h) must not contain any code
35 that tries to use host floating point arithmetic to convert
36 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
37 etc. In cross-compile situations a REAL_VALUE_TYPE may not
38 be intelligible to the host computer's native arithmetic.
40 The emulator defaults to the host's floating point format so that
41 its decimal conversion functions can be used if desired (see
44 The first part of this file interfaces gcc to a floating point
45 arithmetic suite that was not written with gcc in mind. Avoid
46 changing the low-level arithmetic routines unless you have suitable
47 test programs available. A special version of the PARANOIA floating
48 point arithmetic tester, modified for this purpose, can be found on
49 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
50 XFmode and TFmode transcendental functions, can be obtained by ftp from
51 netlib.att.com: netlib/cephes. */
53 /* Type of computer arithmetic.
54 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
56 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
57 to big-endian IEEE floating-point data structure. This definition
58 should work in SFmode `float' type and DFmode `double' type on
59 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
60 has been defined to be 96, then IEEE also invokes the particular
61 XFmode (`long double' type) data structure used by the Motorola
62 680x0 series processors.
64 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
65 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
66 has been defined to be 96, then IEEE also invokes the particular
67 XFmode `long double' data structure used by the Intel 80x86 series
70 `DEC' refers specifically to the Digital Equipment Corp PDP-11
71 and VAX floating point data structure. This model currently
72 supports no type wider than DFmode.
74 `IBM' refers specifically to the IBM System/370 and compatible
75 floating point data structure. This model currently supports
76 no type wider than DFmode. The IBM conversions were contributed by
77 frank@atom.ansto.gov.au (Frank Crawford).
79 `C4X' refers specifically to the floating point format used on
80 Texas Instruments TMS320C3x and TMS320C4x digital signal
81 processors. This supports QFmode (32-bit float, double) and HFmode
82 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
83 floats, C4x floats are not rounded to be even. The C4x conversions
84 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
85 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
87 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
88 then `long double' and `double' are both implemented, but they
89 both mean DFmode. In this case, the software floating-point
90 support available here is activated by writing
91 #define REAL_ARITHMETIC
94 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
95 and may deactivate XFmode since `long double' is used to refer
98 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
99 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
100 separate the floating point unit's endian-ness from that of
101 the integer addressing. This permits one to define a big-endian
102 FPU on a little-endian machine (e.g., ARM). An extension to
103 BYTES_BIG_ENDIAN may be required for some machines in the future.
104 These optional macros may be defined in tm.h. In real.h, they
105 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
106 them for any normal host or target machine on which the floats
107 and the integers have the same endian-ness. */
110 /* The following converts gcc macros into the ones used by this file. */
112 /* REAL_ARITHMETIC defined means that macros in real.h are
113 defined to call emulator functions. */
114 #ifdef REAL_ARITHMETIC
116 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
117 /* PDP-11, Pro350, VAX: */
119 #else /* it's not VAX */
120 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
121 /* IBM System/370 style */
123 #else /* it's also not an IBM */
124 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
125 /* TMS320C3x/C4x style */
127 #else /* it's also not a C4X */
128 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
130 #else /* it's not IEEE either */
131 /* UNKnown arithmetic. We don't support this and can't go on. */
132 unknown arithmetic type
134 #endif /* not IEEE */
139 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
142 /* REAL_ARITHMETIC not defined means that the *host's* data
143 structure will be used. It may differ by endian-ness from the
144 target machine's structure and will get its ends swapped
145 accordingly (but not here). Probably only the decimal <-> binary
146 functions in this file will actually be used in this case. */
148 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
150 #else /* it's not VAX */
151 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
152 /* IBM System/370 style */
154 #else /* it's also not an IBM */
155 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
157 #else /* it's not IEEE either */
158 unknown arithmetic type
160 #endif /* not IEEE */
164 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
166 #endif /* REAL_ARITHMETIC not defined */
168 /* Define INFINITY for support of infinity.
169 Define NANS for support of Not-a-Number's (NaN's). */
170 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
175 /* Support of NaNs requires support of infinity. */
182 /* Find a host integer type that is at least 16 bits wide,
183 and another type at least twice whatever that size is. */
185 #if HOST_BITS_PER_CHAR >= 16
186 #define EMUSHORT char
187 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
188 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
190 #if HOST_BITS_PER_SHORT >= 16
191 #define EMUSHORT short
192 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
193 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
195 #if HOST_BITS_PER_INT >= 16
197 #define EMUSHORT_SIZE HOST_BITS_PER_INT
198 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
200 #if HOST_BITS_PER_LONG >= 16
201 #define EMUSHORT long
202 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
203 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
205 /* You will have to modify this program to have a smaller unit size. */
206 #define EMU_NON_COMPILE
212 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
213 #define EMULONG short
215 #if HOST_BITS_PER_INT >= EMULONG_SIZE
218 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
221 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
222 #define EMULONG long long int
224 /* You will have to modify this program to have a smaller unit size. */
225 #define EMU_NON_COMPILE
232 /* The host interface doesn't work if no 16-bit size exists. */
233 #if EMUSHORT_SIZE != 16
234 #define EMU_NON_COMPILE
237 /* OK to continue compilation. */
238 #ifndef EMU_NON_COMPILE
240 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
241 In GET_REAL and PUT_REAL, r and e are pointers.
242 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
243 in memory, with no holes. */
245 #if LONG_DOUBLE_TYPE_SIZE == 96
246 /* Number of 16 bit words in external e type format */
248 #define MAXDECEXP 4932
249 #define MINDECEXP -4956
250 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
251 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
252 #else /* no XFmode */
253 #if LONG_DOUBLE_TYPE_SIZE == 128
255 #define MAXDECEXP 4932
256 #define MINDECEXP -4977
257 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
258 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
261 #define MAXDECEXP 4932
262 #define MINDECEXP -4956
263 #ifdef REAL_ARITHMETIC
264 /* Emulator uses target format internally
265 but host stores it in host endian-ness. */
267 #define GET_REAL(r,e) \
269 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
270 e53toe ((unsigned EMUSHORT *) (r), (e)); \
273 unsigned EMUSHORT w[4]; \
274 w[3] = ((EMUSHORT *) r)[0]; \
275 w[2] = ((EMUSHORT *) r)[1]; \
276 w[1] = ((EMUSHORT *) r)[2]; \
277 w[0] = ((EMUSHORT *) r)[3]; \
282 #define PUT_REAL(e,r) \
284 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
285 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
288 unsigned EMUSHORT w[4]; \
290 *((EMUSHORT *) r) = w[3]; \
291 *((EMUSHORT *) r + 1) = w[2]; \
292 *((EMUSHORT *) r + 2) = w[1]; \
293 *((EMUSHORT *) r + 3) = w[0]; \
297 #else /* not REAL_ARITHMETIC */
299 /* emulator uses host format */
300 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
301 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
303 #endif /* not REAL_ARITHMETIC */
304 #endif /* not TFmode */
305 #endif /* not XFmode */
308 /* Number of 16 bit words in internal format */
311 /* Array offset to exponent */
314 /* Array offset to high guard word */
317 /* Number of bits of precision */
318 #define NBITS ((NI-4)*16)
320 /* Maximum number of decimal digits in ASCII conversion
323 #define NDEC (NBITS*8/27)
325 /* The exponent of 1.0 */
326 #define EXONE (0x3fff)
328 extern int extra_warnings
;
329 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
330 extern unsigned EMUSHORT elog2
[], esqrt2
[];
332 static void endian
PROTO((unsigned EMUSHORT
*, long *,
334 static void eclear
PROTO((unsigned EMUSHORT
*));
335 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
337 static void eabs
PROTO((unsigned EMUSHORT
*));
339 static void eneg
PROTO((unsigned EMUSHORT
*));
340 static int eisneg
PROTO((unsigned EMUSHORT
*));
341 static int eisinf
PROTO((unsigned EMUSHORT
*));
342 static int eisnan
PROTO((unsigned EMUSHORT
*));
343 static void einfin
PROTO((unsigned EMUSHORT
*));
344 static void enan
PROTO((unsigned EMUSHORT
*, int));
345 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
346 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
347 static void ecleaz
PROTO((unsigned EMUSHORT
*));
348 static void ecleazs
PROTO((unsigned EMUSHORT
*));
349 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
350 static void einan
PROTO((unsigned EMUSHORT
*));
351 static int eiisnan
PROTO((unsigned EMUSHORT
*));
352 static int eiisneg
PROTO((unsigned EMUSHORT
*));
354 static void eiinfin
PROTO((unsigned EMUSHORT
*));
356 static int eiisinf
PROTO((unsigned EMUSHORT
*));
357 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
358 static void eshdn1
PROTO((unsigned EMUSHORT
*));
359 static void eshup1
PROTO((unsigned EMUSHORT
*));
360 static void eshdn8
PROTO((unsigned EMUSHORT
*));
361 static void eshup8
PROTO((unsigned EMUSHORT
*));
362 static void eshup6
PROTO((unsigned EMUSHORT
*));
363 static void eshdn6
PROTO((unsigned EMUSHORT
*));
364 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
365 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
366 static void m16m
PROTO((unsigned int, unsigned short *,
368 static int edivm
PROTO((unsigned short *, unsigned short *));
369 static int emulm
PROTO((unsigned short *, unsigned short *));
370 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
371 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
372 unsigned EMUSHORT
*));
373 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
374 unsigned EMUSHORT
*));
375 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
376 unsigned EMUSHORT
*));
377 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
378 unsigned EMUSHORT
*));
379 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
380 unsigned EMUSHORT
*));
381 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
384 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
385 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
386 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
387 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
388 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
389 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
390 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
391 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
392 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
395 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
397 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
398 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
399 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
400 unsigned EMUSHORT
*));
401 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
402 unsigned EMUSHORT
*));
403 static int eshift
PROTO((unsigned EMUSHORT
*, int));
404 static int enormlz
PROTO((unsigned EMUSHORT
*));
406 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
407 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
408 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
409 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
411 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
412 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
413 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
414 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
415 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
416 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
417 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
418 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
421 unsigned EMUSHORT
*));
423 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
425 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
426 unsigned EMUSHORT
*));
428 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
429 static void mtherr
PROTO((char *, int));
431 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
432 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
433 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
436 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
438 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
440 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
444 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
446 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
448 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
451 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
453 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
454 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
455 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
456 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
457 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
460 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
461 swapping ends if required, into output array of longs. The
462 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
466 unsigned EMUSHORT e
[];
468 enum machine_mode mode
;
472 if (REAL_WORDS_BIG_ENDIAN
)
477 /* Swap halfwords in the fourth long. */
478 th
= (unsigned long) e
[6] & 0xffff;
479 t
= (unsigned long) e
[7] & 0xffff;
484 /* Swap halfwords in the third long. */
485 th
= (unsigned long) e
[4] & 0xffff;
486 t
= (unsigned long) e
[5] & 0xffff;
489 /* fall into the double case */
492 /* Swap halfwords in the second word. */
493 th
= (unsigned long) e
[2] & 0xffff;
494 t
= (unsigned long) e
[3] & 0xffff;
497 /* fall into the float case */
501 /* Swap halfwords in the first word. */
502 th
= (unsigned long) e
[0] & 0xffff;
503 t
= (unsigned long) e
[1] & 0xffff;
514 /* Pack the output array without swapping. */
519 /* Pack the fourth long. */
520 th
= (unsigned long) e
[7] & 0xffff;
521 t
= (unsigned long) e
[6] & 0xffff;
526 /* Pack the third long.
527 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
529 th
= (unsigned long) e
[5] & 0xffff;
530 t
= (unsigned long) e
[4] & 0xffff;
533 /* fall into the double case */
536 /* Pack the second long */
537 th
= (unsigned long) e
[3] & 0xffff;
538 t
= (unsigned long) e
[2] & 0xffff;
541 /* fall into the float case */
545 /* Pack the first long */
546 th
= (unsigned long) e
[1] & 0xffff;
547 t
= (unsigned long) e
[0] & 0xffff;
557 /* If 32 bits is an entire word for the target, but not for the host,
558 then sign-extend on the host so that the number will look the same
559 way on the host that it would on the target. See for instance
560 simplify_unary_operation. The #if is needed to avoid compiler
563 #if HOST_BITS_PER_WIDE_INT > 32
564 if (BITS_PER_WORD
< HOST_BITS_PER_WIDE_INT
&& BITS_PER_WORD
== 32)
566 if (x
[0] & ((HOST_WIDE_INT
) 1 << 31))
567 x
[0] |= ((HOST_WIDE_INT
) (-1) << 32);
569 if (x
[1] & ((HOST_WIDE_INT
) 1 << 31))
570 x
[1] |= ((HOST_WIDE_INT
) (-1) << 32);
576 /* This is the implementation of the REAL_ARITHMETIC macro. */
579 earith (value
, icode
, r1
, r2
)
580 REAL_VALUE_TYPE
*value
;
585 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
591 /* Return NaN input back to the caller. */
594 PUT_REAL (d1
, value
);
599 PUT_REAL (d2
, value
);
603 code
= (enum tree_code
) icode
;
611 esub (d2
, d1
, v
); /* d1 - d2 */
619 #ifndef REAL_INFINITY
620 if (ecmp (d2
, ezero
) == 0)
623 enan (v
, eisneg (d1
) ^ eisneg (d2
));
630 ediv (d2
, d1
, v
); /* d1/d2 */
633 case MIN_EXPR
: /* min (d1,d2) */
634 if (ecmp (d1
, d2
) < 0)
640 case MAX_EXPR
: /* max (d1,d2) */
641 if (ecmp (d1
, d2
) > 0)
654 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
655 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
661 unsigned EMUSHORT f
[NE
], g
[NE
];
677 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
678 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
684 unsigned EMUSHORT f
[NE
], g
[NE
];
686 unsigned HOST_WIDE_INT l
;
700 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
701 string to binary, rounding off as indicated by the machine_mode argument.
702 Then it promotes the rounded value to REAL_VALUE_TYPE. */
709 unsigned EMUSHORT tem
[NE
], e
[NE
];
752 /* Expansion of REAL_NEGATE. */
758 unsigned EMUSHORT e
[NE
];
768 /* Round real toward zero to HOST_WIDE_INT;
769 implements REAL_VALUE_FIX (x). */
775 unsigned EMUSHORT f
[NE
], g
[NE
];
782 warning ("conversion from NaN to int");
790 /* Round real toward zero to unsigned HOST_WIDE_INT
791 implements REAL_VALUE_UNSIGNED_FIX (x).
792 Negative input returns zero. */
794 unsigned HOST_WIDE_INT
798 unsigned EMUSHORT f
[NE
], g
[NE
];
799 unsigned HOST_WIDE_INT l
;
805 warning ("conversion from NaN to unsigned int");
814 /* REAL_VALUE_FROM_INT macro. */
817 ereal_from_int (d
, i
, j
, mode
)
820 enum machine_mode mode
;
822 unsigned EMUSHORT df
[NE
], dg
[NE
];
823 HOST_WIDE_INT low
, high
;
826 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
833 /* complement and add 1 */
840 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
841 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
843 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
848 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
849 Avoid double-rounding errors later by rounding off now from the
850 extra-wide internal format to the requested precision. */
851 switch (GET_MODE_BITSIZE (mode
))
881 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
884 ereal_from_uint (d
, i
, j
, mode
)
886 unsigned HOST_WIDE_INT i
, j
;
887 enum machine_mode mode
;
889 unsigned EMUSHORT df
[NE
], dg
[NE
];
890 unsigned HOST_WIDE_INT low
, high
;
892 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
896 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
902 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
903 Avoid double-rounding errors later by rounding off now from the
904 extra-wide internal format to the requested precision. */
905 switch (GET_MODE_BITSIZE (mode
))
935 /* REAL_VALUE_TO_INT macro. */
938 ereal_to_int (low
, high
, rr
)
939 HOST_WIDE_INT
*low
, *high
;
942 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
949 warning ("conversion from NaN to int");
955 /* convert positive value */
962 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
963 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
964 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
965 emul (df
, dh
, dg
); /* fractional part is the low word */
966 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
969 /* complement and add 1 */
979 /* REAL_VALUE_LDEXP macro. */
986 unsigned EMUSHORT e
[NE
], y
[NE
];
999 /* These routines are conditionally compiled because functions
1000 of the same names may be defined in fold-const.c. */
1002 #ifdef REAL_ARITHMETIC
1004 /* Check for infinity in a REAL_VALUE_TYPE. */
1010 unsigned EMUSHORT e
[NE
];
1014 return (eisinf (e
));
1020 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1026 unsigned EMUSHORT e
[NE
];
1030 return (eisnan (e
));
1037 /* Check for a negative REAL_VALUE_TYPE number.
1038 This just checks the sign bit, so that -0 counts as negative. */
1044 return ereal_isneg (x
);
1047 /* Expansion of REAL_VALUE_TRUNCATE.
1048 The result is in floating point, rounded to nearest or even. */
1051 real_value_truncate (mode
, arg
)
1052 enum machine_mode mode
;
1053 REAL_VALUE_TYPE arg
;
1055 unsigned EMUSHORT e
[NE
], t
[NE
];
1101 /* If an unsupported type was requested, presume that
1102 the machine files know something useful to do with
1103 the unmodified value. */
1112 /* Try to change R into its exact multiplicative inverse in machine mode
1113 MODE. Return nonzero function value if successful. */
1116 exact_real_inverse (mode
, r
)
1117 enum machine_mode mode
;
1120 unsigned EMUSHORT e
[NE
], einv
[NE
];
1121 REAL_VALUE_TYPE rinv
;
1126 /* Test for input in range. Don't transform IEEE special values. */
1127 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1130 /* Test for a power of 2: all significand bits zero except the MSB.
1131 We are assuming the target has binary (or hex) arithmetic. */
1132 if (e
[NE
- 2] != 0x8000)
1135 for (i
= 0; i
< NE
- 2; i
++)
1141 /* Compute the inverse and truncate it to the required mode. */
1142 ediv (e
, eone
, einv
);
1143 PUT_REAL (einv
, &rinv
);
1144 rinv
= real_value_truncate (mode
, rinv
);
1146 #ifdef CHECK_FLOAT_VALUE
1147 /* This check is not redundant. It may, for example, flush
1148 a supposedly IEEE denormal value to zero. */
1150 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1153 GET_REAL (&rinv
, einv
);
1155 /* Check the bits again, because the truncation might have
1156 generated an arbitrary saturation value on overflow. */
1157 if (einv
[NE
- 2] != 0x8000)
1160 for (i
= 0; i
< NE
- 2; i
++)
1166 /* Fail if the computed inverse is out of range. */
1167 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1170 /* Output the reciprocal and return success flag. */
1174 #endif /* REAL_ARITHMETIC defined */
1176 /* Used for debugging--print the value of R in human-readable format
1185 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1186 fprintf (stderr
, "%s", dstr
);
1190 /* The following routines convert REAL_VALUE_TYPE to the various floating
1191 point formats that are meaningful to supported computers.
1193 The results are returned in 32-bit pieces, each piece stored in a `long'.
1194 This is so they can be printed by statements like
1196 fprintf (file, "%lx, %lx", L[0], L[1]);
1198 that will work on both narrow- and wide-word host computers. */
1200 /* Convert R to a 128-bit long double precision value. The output array L
1201 contains four 32-bit pieces of the result, in the order they would appear
1209 unsigned EMUSHORT e
[NE
];
1213 endian (e
, l
, TFmode
);
1216 /* Convert R to a double extended precision value. The output array L
1217 contains three 32-bit pieces of the result, in the order they would
1218 appear in memory. */
1225 unsigned EMUSHORT e
[NE
];
1229 endian (e
, l
, XFmode
);
1232 /* Convert R to a double precision value. The output array L contains two
1233 32-bit pieces of the result, in the order they would appear in memory. */
1240 unsigned EMUSHORT e
[NE
];
1244 endian (e
, l
, DFmode
);
1247 /* Convert R to a single precision float value stored in the least-significant
1248 bits of a `long'. */
1254 unsigned EMUSHORT e
[NE
];
1259 endian (e
, &l
, SFmode
);
1263 /* Convert X to a decimal ASCII string S for output to an assembly
1264 language file. Note, there is no standard way to spell infinity or
1265 a NaN, so these values may require special treatment in the tm.h
1269 ereal_to_decimal (x
, s
)
1273 unsigned EMUSHORT e
[NE
];
1279 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1280 or -2 if either is a NaN. */
1284 REAL_VALUE_TYPE x
, y
;
1286 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1290 return (ecmp (ex
, ey
));
1293 /* Return 1 if the sign bit of X is set, else return 0. */
1299 unsigned EMUSHORT ex
[NE
];
1302 return (eisneg (ex
));
1305 /* End of REAL_ARITHMETIC interface */
1308 Extended precision IEEE binary floating point arithmetic routines
1310 Numbers are stored in C language as arrays of 16-bit unsigned
1311 short integers. The arguments of the routines are pointers to
1314 External e type data structure, similar to Intel 8087 chip
1315 temporary real format but possibly with a larger significand:
1317 NE-1 significand words (least significant word first,
1318 most significant bit is normally set)
1319 exponent (value = EXONE for 1.0,
1320 top bit is the sign)
1323 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1325 ei[0] sign word (0 for positive, 0xffff for negative)
1326 ei[1] biased exponent (value = EXONE for the number 1.0)
1327 ei[2] high guard word (always zero after normalization)
1329 to ei[NI-2] significand (NI-4 significand words,
1330 most significant word first,
1331 most significant bit is set)
1332 ei[NI-1] low guard word (0x8000 bit is rounding place)
1336 Routines for external format e-type numbers
1338 asctoe (string, e) ASCII string to extended double e type
1339 asctoe64 (string, &d) ASCII string to long double
1340 asctoe53 (string, &d) ASCII string to double
1341 asctoe24 (string, &f) ASCII string to single
1342 asctoeg (string, e, prec) ASCII string to specified precision
1343 e24toe (&f, e) IEEE single precision to e type
1344 e53toe (&d, e) IEEE double precision to e type
1345 e64toe (&d, e) IEEE long double precision to e type
1346 e113toe (&d, e) 128-bit long double precision to e type
1348 eabs (e) absolute value
1350 eadd (a, b, c) c = b + a
1352 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1353 -1 if a < b, -2 if either a or b is a NaN.
1354 ediv (a, b, c) c = b / a
1355 efloor (a, b) truncate to integer, toward -infinity
1356 efrexp (a, exp, s) extract exponent and significand
1357 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1358 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1359 einfin (e) set e to infinity, leaving its sign alone
1360 eldexp (a, n, b) multiply by 2**n
1362 emul (a, b, c) c = b * a
1365 eround (a, b) b = nearest integer value to a
1367 esub (a, b, c) c = b - a
1369 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1370 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1371 e64toasc (&d, str, n) 80-bit long double to ASCII string
1372 e113toasc (&d, str, n) 128-bit long double to ASCII string
1374 etoasc (e, str, n) e to ASCII string, n digits after decimal
1375 etoe24 (e, &f) convert e type to IEEE single precision
1376 etoe53 (e, &d) convert e type to IEEE double precision
1377 etoe64 (e, &d) convert e type to IEEE long double precision
1378 ltoe (&l, e) HOST_WIDE_INT to e type
1379 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1380 eisneg (e) 1 if sign bit of e != 0, else 0
1381 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1382 or is infinite (IEEE)
1383 eisnan (e) 1 if e is a NaN
1386 Routines for internal format exploded e-type numbers
1388 eaddm (ai, bi) add significands, bi = bi + ai
1390 ecleazs (ei) set ei = 0 but leave its sign alone
1391 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1392 edivm (ai, bi) divide significands, bi = bi / ai
1393 emdnorm (ai,l,s,exp) normalize and round off
1394 emovi (a, ai) convert external a to internal ai
1395 emovo (ai, a) convert internal ai to external a
1396 emovz (ai, bi) bi = ai, low guard word of bi = 0
1397 emulm (ai, bi) multiply significands, bi = bi * ai
1398 enormlz (ei) left-justify the significand
1399 eshdn1 (ai) shift significand and guards down 1 bit
1400 eshdn8 (ai) shift down 8 bits
1401 eshdn6 (ai) shift down 16 bits
1402 eshift (ai, n) shift ai n bits up (or down if n < 0)
1403 eshup1 (ai) shift significand and guards up 1 bit
1404 eshup8 (ai) shift up 8 bits
1405 eshup6 (ai) shift up 16 bits
1406 esubm (ai, bi) subtract significands, bi = bi - ai
1407 eiisinf (ai) 1 if infinite
1408 eiisnan (ai) 1 if a NaN
1409 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1410 einan (ai) set ai = NaN
1412 eiinfin (ai) set ai = infinity
1415 The result is always normalized and rounded to NI-4 word precision
1416 after each arithmetic operation.
1418 Exception flags are NOT fully supported.
1420 Signaling NaN's are NOT supported; they are treated the same
1423 Define INFINITY for support of infinity; otherwise a
1424 saturation arithmetic is implemented.
1426 Define NANS for support of Not-a-Number items; otherwise the
1427 arithmetic will never produce a NaN output, and might be confused
1429 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1430 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1431 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1434 Denormals are always supported here where appropriate (e.g., not
1435 for conversion to DEC numbers). */
1437 /* Definitions for error codes that are passed to the common error handling
1440 For Digital Equipment PDP-11 and VAX computers, certain
1441 IBM systems, and others that use numbers with a 56-bit
1442 significand, the symbol DEC should be defined. In this
1443 mode, most floating point constants are given as arrays
1444 of octal integers to eliminate decimal to binary conversion
1445 errors that might be introduced by the compiler.
1447 For computers, such as IBM PC, that follow the IEEE
1448 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1449 Std 754-1985), the symbol IEEE should be defined.
1450 These numbers have 53-bit significands. In this mode, constants
1451 are provided as arrays of hexadecimal 16 bit integers.
1452 The endian-ness of generated values is controlled by
1453 REAL_WORDS_BIG_ENDIAN.
1455 To accommodate other types of computer arithmetic, all
1456 constants are also provided in a normal decimal radix
1457 which one can hope are correctly converted to a suitable
1458 format by the available C language compiler. To invoke
1459 this mode, the symbol UNK is defined.
1461 An important difference among these modes is a predefined
1462 set of machine arithmetic constants for each. The numbers
1463 MACHEP (the machine roundoff error), MAXNUM (largest number
1464 represented), and several other parameters are preset by
1465 the configuration symbol. Check the file const.c to
1466 ensure that these values are correct for your computer.
1468 For ANSI C compatibility, define ANSIC equal to 1. Currently
1469 this affects only the atan2 function and others that use it. */
1471 /* Constant definitions for math error conditions. */
1473 #define DOMAIN 1 /* argument domain error */
1474 #define SING 2 /* argument singularity */
1475 #define OVERFLOW 3 /* overflow range error */
1476 #define UNDERFLOW 4 /* underflow range error */
1477 #define TLOSS 5 /* total loss of precision */
1478 #define PLOSS 6 /* partial loss of precision */
1479 #define INVALID 7 /* NaN-producing operation */
1481 /* e type constants used by high precision check routines */
1483 #if LONG_DOUBLE_TYPE_SIZE == 128
1485 unsigned EMUSHORT ezero
[NE
] =
1486 {0x0000, 0x0000, 0x0000, 0x0000,
1487 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1488 extern unsigned EMUSHORT ezero
[];
1491 unsigned EMUSHORT ehalf
[NE
] =
1492 {0x0000, 0x0000, 0x0000, 0x0000,
1493 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1494 extern unsigned EMUSHORT ehalf
[];
1497 unsigned EMUSHORT eone
[NE
] =
1498 {0x0000, 0x0000, 0x0000, 0x0000,
1499 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1500 extern unsigned EMUSHORT eone
[];
1503 unsigned EMUSHORT etwo
[NE
] =
1504 {0x0000, 0x0000, 0x0000, 0x0000,
1505 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1506 extern unsigned EMUSHORT etwo
[];
1509 unsigned EMUSHORT e32
[NE
] =
1510 {0x0000, 0x0000, 0x0000, 0x0000,
1511 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1512 extern unsigned EMUSHORT e32
[];
1514 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1515 unsigned EMUSHORT elog2
[NE
] =
1516 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1517 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1518 extern unsigned EMUSHORT elog2
[];
1520 /* 1.41421356237309504880168872420969807856967187537695E0 */
1521 unsigned EMUSHORT esqrt2
[NE
] =
1522 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1523 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1524 extern unsigned EMUSHORT esqrt2
[];
1526 /* 3.14159265358979323846264338327950288419716939937511E0 */
1527 unsigned EMUSHORT epi
[NE
] =
1528 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1529 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1530 extern unsigned EMUSHORT epi
[];
1533 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1534 unsigned EMUSHORT ezero
[NE
] =
1535 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1536 unsigned EMUSHORT ehalf
[NE
] =
1537 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1538 unsigned EMUSHORT eone
[NE
] =
1539 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1540 unsigned EMUSHORT etwo
[NE
] =
1541 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1542 unsigned EMUSHORT e32
[NE
] =
1543 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1544 unsigned EMUSHORT elog2
[NE
] =
1545 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1546 unsigned EMUSHORT esqrt2
[NE
] =
1547 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1548 unsigned EMUSHORT epi
[NE
] =
1549 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1552 /* Control register for rounding precision.
1553 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1558 /* Clear out entire e-type number X. */
1562 register unsigned EMUSHORT
*x
;
1566 for (i
= 0; i
< NE
; i
++)
1570 /* Move e-type number from A to B. */
1574 register unsigned EMUSHORT
*a
, *b
;
1578 for (i
= 0; i
< NE
; i
++)
1584 /* Absolute value of e-type X. */
1588 unsigned EMUSHORT x
[];
1590 /* sign is top bit of last word of external format */
1591 x
[NE
- 1] &= 0x7fff;
1595 /* Negate the e-type number X. */
1599 unsigned EMUSHORT x
[];
1602 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1605 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1609 unsigned EMUSHORT x
[];
1612 if (x
[NE
- 1] & 0x8000)
1618 /* Return 1 if e-type number X is infinity, else return zero. */
1622 unsigned EMUSHORT x
[];
1629 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1635 /* Check if e-type number is not a number. The bit pattern is one that we
1636 defined, so we know for sure how to detect it. */
1640 unsigned EMUSHORT x
[];
1645 /* NaN has maximum exponent */
1646 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1648 /* ... and non-zero significand field. */
1649 for (i
= 0; i
< NE
- 1; i
++)
1659 /* Fill e-type number X with infinity pattern (IEEE)
1660 or largest possible number (non-IEEE). */
1664 register unsigned EMUSHORT
*x
;
1669 for (i
= 0; i
< NE
- 1; i
++)
1673 for (i
= 0; i
< NE
- 1; i
++)
1701 /* Output an e-type NaN.
1702 This generates Intel's quiet NaN pattern for extended real.
1703 The exponent is 7fff, the leading mantissa word is c000. */
1707 register unsigned EMUSHORT
*x
;
1712 for (i
= 0; i
< NE
- 2; i
++)
1715 *x
= (sign
<< 15) | 0x7fff;
1718 /* Move in an e-type number A, converting it to exploded e-type B. */
1722 unsigned EMUSHORT
*a
, *b
;
1724 register unsigned EMUSHORT
*p
, *q
;
1728 p
= a
+ (NE
- 1); /* point to last word of external number */
1729 /* get the sign bit */
1734 /* get the exponent */
1736 *q
++ &= 0x7fff; /* delete the sign bit */
1738 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1744 for (i
= 3; i
< NI
; i
++)
1750 for (i
= 2; i
< NI
; i
++)
1756 /* clear high guard word */
1758 /* move in the significand */
1759 for (i
= 0; i
< NE
- 1; i
++)
1761 /* clear low guard word */
1765 /* Move out exploded e-type number A, converting it to e type B. */
1769 unsigned EMUSHORT
*a
, *b
;
1771 register unsigned EMUSHORT
*p
, *q
;
1772 unsigned EMUSHORT i
;
1776 q
= b
+ (NE
- 1); /* point to output exponent */
1777 /* combine sign and exponent */
1780 *q
-- = *p
++ | 0x8000;
1784 if (*(p
- 1) == 0x7fff)
1789 enan (b
, eiisneg (a
));
1797 /* skip over guard word */
1799 /* move the significand */
1800 for (j
= 0; j
< NE
- 1; j
++)
1804 /* Clear out exploded e-type number XI. */
1808 register unsigned EMUSHORT
*xi
;
1812 for (i
= 0; i
< NI
; i
++)
1816 /* Clear out exploded e-type XI, but don't touch the sign. */
1820 register unsigned EMUSHORT
*xi
;
1825 for (i
= 0; i
< NI
- 1; i
++)
1829 /* Move exploded e-type number from A to B. */
1833 register unsigned EMUSHORT
*a
, *b
;
1837 for (i
= 0; i
< NI
- 1; i
++)
1839 /* clear low guard word */
1843 /* Generate exploded e-type NaN.
1844 The explicit pattern for this is maximum exponent and
1845 top two significant bits set. */
1849 unsigned EMUSHORT x
[];
1857 /* Return nonzero if exploded e-type X is a NaN. */
1861 unsigned EMUSHORT x
[];
1865 if ((x
[E
] & 0x7fff) == 0x7fff)
1867 for (i
= M
+ 1; i
< NI
; i
++)
1876 /* Return nonzero if sign of exploded e-type X is nonzero. */
1880 unsigned EMUSHORT x
[];
1887 /* Fill exploded e-type X with infinity pattern.
1888 This has maximum exponent and significand all zeros. */
1892 unsigned EMUSHORT x
[];
1900 /* Return nonzero if exploded e-type X is infinite. */
1904 unsigned EMUSHORT x
[];
1911 if ((x
[E
] & 0x7fff) == 0x7fff)
1917 /* Compare significands of numbers in internal exploded e-type format.
1918 Guard words are included in the comparison.
1926 register unsigned EMUSHORT
*a
, *b
;
1930 a
+= M
; /* skip up to significand area */
1932 for (i
= M
; i
< NI
; i
++)
1940 if (*(--a
) > *(--b
))
1946 /* Shift significand of exploded e-type X down by 1 bit. */
1950 register unsigned EMUSHORT
*x
;
1952 register unsigned EMUSHORT bits
;
1955 x
+= M
; /* point to significand area */
1958 for (i
= M
; i
< NI
; i
++)
1970 /* Shift significand of exploded e-type X up by 1 bit. */
1974 register unsigned EMUSHORT
*x
;
1976 register unsigned EMUSHORT bits
;
1982 for (i
= M
; i
< NI
; i
++)
1995 /* Shift significand of exploded e-type X down by 8 bits. */
1999 register unsigned EMUSHORT
*x
;
2001 register unsigned EMUSHORT newbyt
, oldbyt
;
2006 for (i
= M
; i
< NI
; i
++)
2016 /* Shift significand of exploded e-type X up by 8 bits. */
2020 register unsigned EMUSHORT
*x
;
2023 register unsigned EMUSHORT newbyt
, oldbyt
;
2028 for (i
= M
; i
< NI
; i
++)
2038 /* Shift significand of exploded e-type X up by 16 bits. */
2042 register unsigned EMUSHORT
*x
;
2045 register unsigned EMUSHORT
*p
;
2050 for (i
= M
; i
< NI
- 1; i
++)
2056 /* Shift significand of exploded e-type X down by 16 bits. */
2060 register unsigned EMUSHORT
*x
;
2063 register unsigned EMUSHORT
*p
;
2068 for (i
= M
; i
< NI
- 1; i
++)
2074 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2078 unsigned EMUSHORT
*x
, *y
;
2080 register unsigned EMULONG a
;
2087 for (i
= M
; i
< NI
; i
++)
2089 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2094 *y
= (unsigned EMUSHORT
) a
;
2100 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2104 unsigned EMUSHORT
*x
, *y
;
2113 for (i
= M
; i
< NI
; i
++)
2115 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2120 *y
= (unsigned EMUSHORT
) a
;
2127 static unsigned EMUSHORT equot
[NI
];
2131 /* Radix 2 shift-and-add versions of multiply and divide */
2134 /* Divide significands */
2138 unsigned EMUSHORT den
[], num
[];
2141 register unsigned EMUSHORT
*p
, *q
;
2142 unsigned EMUSHORT j
;
2148 for (i
= M
; i
< NI
; i
++)
2153 /* Use faster compare and subtraction if denominator has only 15 bits of
2159 for (i
= M
+ 3; i
< NI
; i
++)
2164 if ((den
[M
+ 1] & 1) != 0)
2172 for (i
= 0; i
< NBITS
+ 2; i
++)
2190 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2191 bit + 1 roundoff bit. */
2196 for (i
= 0; i
< NBITS
+ 2; i
++)
2198 if (ecmpm (den
, num
) <= 0)
2201 j
= 1; /* quotient bit = 1 */
2215 /* test for nonzero remainder after roundoff bit */
2218 for (i
= M
; i
< NI
; i
++)
2226 for (i
= 0; i
< NI
; i
++)
2232 /* Multiply significands */
2236 unsigned EMUSHORT a
[], b
[];
2238 unsigned EMUSHORT
*p
, *q
;
2243 for (i
= M
; i
< NI
; i
++)
2248 while (*p
== 0) /* significand is not supposed to be zero */
2253 if ((*p
& 0xff) == 0)
2261 for (i
= 0; i
< k
; i
++)
2265 /* remember if there were any nonzero bits shifted out */
2272 for (i
= 0; i
< NI
; i
++)
2275 /* return flag for lost nonzero bits */
2281 /* Radix 65536 versions of multiply and divide. */
2283 /* Multiply significand of e-type number B
2284 by 16-bit quantity A, return e-type result to C. */
2289 unsigned EMUSHORT b
[], c
[];
2291 register unsigned EMUSHORT
*pp
;
2292 register unsigned EMULONG carry
;
2293 unsigned EMUSHORT
*ps
;
2294 unsigned EMUSHORT p
[NI
];
2295 unsigned EMULONG aa
, m
;
2304 for (i
=M
+1; i
<NI
; i
++)
2314 m
= (unsigned EMULONG
) aa
* *ps
--;
2315 carry
= (m
& 0xffff) + *pp
;
2316 *pp
-- = (unsigned EMUSHORT
)carry
;
2317 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2318 *pp
= (unsigned EMUSHORT
)carry
;
2319 *(pp
-1) = carry
>> 16;
2322 for (i
=M
; i
<NI
; i
++)
2326 /* Divide significands of exploded e-types NUM / DEN. Neither the
2327 numerator NUM nor the denominator DEN is permitted to have its high guard
2332 unsigned EMUSHORT den
[], num
[];
2335 register unsigned EMUSHORT
*p
;
2336 unsigned EMULONG tnum
;
2337 unsigned EMUSHORT j
, tdenm
, tquot
;
2338 unsigned EMUSHORT tprod
[NI
+1];
2344 for (i
=M
; i
<NI
; i
++)
2350 for (i
=M
; i
<NI
; i
++)
2352 /* Find trial quotient digit (the radix is 65536). */
2353 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2355 /* Do not execute the divide instruction if it will overflow. */
2356 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2359 tquot
= tnum
/ tdenm
;
2360 /* Multiply denominator by trial quotient digit. */
2361 m16m ((unsigned int)tquot
, den
, tprod
);
2362 /* The quotient digit may have been overestimated. */
2363 if (ecmpm (tprod
, num
) > 0)
2367 if (ecmpm (tprod
, num
) > 0)
2377 /* test for nonzero remainder after roundoff bit */
2380 for (i
=M
; i
<NI
; i
++)
2387 for (i
=0; i
<NI
; i
++)
2393 /* Multiply significands of exploded e-type A and B, result in B. */
2397 unsigned EMUSHORT a
[], b
[];
2399 unsigned EMUSHORT
*p
, *q
;
2400 unsigned EMUSHORT pprod
[NI
];
2401 unsigned EMUSHORT j
;
2406 for (i
=M
; i
<NI
; i
++)
2412 for (i
=M
+1; i
<NI
; i
++)
2420 m16m ((unsigned int) *p
--, b
, pprod
);
2421 eaddm(pprod
, equot
);
2427 for (i
=0; i
<NI
; i
++)
2430 /* return flag for lost nonzero bits */
2436 /* Normalize and round off.
2438 The internal format number to be rounded is S.
2439 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2441 Input SUBFLG indicates whether the number was obtained
2442 by a subtraction operation. In that case if LOST is nonzero
2443 then the number is slightly smaller than indicated.
2445 Input EXP is the biased exponent, which may be negative.
2446 the exponent field of S is ignored but is replaced by
2447 EXP as adjusted by normalization and rounding.
2449 Input RCNTRL is the rounding control. If it is nonzero, the
2450 returned value will be rounded to RNDPRC bits.
2452 For future reference: In order for emdnorm to round off denormal
2453 significands at the right point, the input exponent must be
2454 adjusted to be the actual value it would have after conversion to
2455 the final floating point type. This adjustment has been
2456 implemented for all type conversions (etoe53, etc.) and decimal
2457 conversions, but not for the arithmetic functions (eadd, etc.).
2458 Data types having standard 15-bit exponents are not affected by
2459 this, but SFmode and DFmode are affected. For example, ediv with
2460 rndprc = 24 will not round correctly to 24-bit precision if the
2461 result is denormal. */
2463 static int rlast
= -1;
2465 static unsigned EMUSHORT rmsk
= 0;
2466 static unsigned EMUSHORT rmbit
= 0;
2467 static unsigned EMUSHORT rebit
= 0;
2469 static unsigned EMUSHORT rbit
[NI
];
2472 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2473 unsigned EMUSHORT s
[];
2480 unsigned EMUSHORT r
;
2485 /* a blank significand could mean either zero or infinity. */
2498 if ((j
> NBITS
) && (exp
< 32767))
2506 if (exp
> (EMULONG
) (-NBITS
- 1))
2519 /* Round off, unless told not to by rcntrl. */
2522 /* Set up rounding parameters if the control register changed. */
2523 if (rndprc
!= rlast
)
2530 rw
= NI
- 1; /* low guard word */
2553 /* For DEC or IBM arithmetic */
2570 /* For C4x arithmetic */
2591 /* Shift down 1 temporarily if the data structure has an implied
2592 most significant bit and the number is denormal.
2593 Intel long double denormals also lose one bit of precision. */
2594 if ((exp
<= 0) && (rndprc
!= NBITS
)
2595 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2597 lost
|= s
[NI
- 1] & 1;
2600 /* Clear out all bits below the rounding bit,
2601 remembering in r if any were nonzero. */
2615 if ((r
& rmbit
) != 0)
2621 { /* round to even */
2622 if ((s
[re
] & rebit
) == 0)
2635 /* Undo the temporary shift for denormal values. */
2636 if ((exp
<= 0) && (rndprc
!= NBITS
)
2637 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2642 { /* overflow on roundoff */
2655 for (i
= 2; i
< NI
- 1; i
++)
2658 warning ("floating point overflow");
2662 for (i
= M
+ 1; i
< NI
- 1; i
++)
2665 if ((rndprc
< 64) || (rndprc
== 113))
2680 s
[1] = (unsigned EMUSHORT
) exp
;
2683 /* Subtract. C = B - A, all e type numbers. */
2685 static int subflg
= 0;
2689 unsigned EMUSHORT
*a
, *b
, *c
;
2703 /* Infinity minus infinity is a NaN.
2704 Test for subtracting infinities of the same sign. */
2705 if (eisinf (a
) && eisinf (b
)
2706 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2708 mtherr ("esub", INVALID
);
2717 /* Add. C = A + B, all e type. */
2721 unsigned EMUSHORT
*a
, *b
, *c
;
2725 /* NaN plus anything is a NaN. */
2736 /* Infinity minus infinity is a NaN.
2737 Test for adding infinities of opposite signs. */
2738 if (eisinf (a
) && eisinf (b
)
2739 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2741 mtherr ("esub", INVALID
);
2750 /* Arithmetic common to both addition and subtraction. */
2754 unsigned EMUSHORT
*a
, *b
, *c
;
2756 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2758 EMULONG lt
, lta
, ltb
;
2779 /* compare exponents */
2784 { /* put the larger number in bi */
2794 if (lt
< (EMULONG
) (-NBITS
- 1))
2795 goto done
; /* answer same as larger addend */
2797 lost
= eshift (ai
, k
); /* shift the smaller number down */
2801 /* exponents were the same, so must compare significands */
2804 { /* the numbers are identical in magnitude */
2805 /* if different signs, result is zero */
2811 /* if same sign, result is double */
2812 /* double denormalized tiny number */
2813 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2818 /* add 1 to exponent unless both are zero! */
2819 for (j
= 1; j
< NI
- 1; j
++)
2835 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2839 { /* put the larger number in bi */
2855 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2861 /* Divide: C = B/A, all e type. */
2865 unsigned EMUSHORT
*a
, *b
, *c
;
2867 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2869 EMULONG lt
, lta
, ltb
;
2871 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2872 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2873 sign
= eisneg(a
) ^ eisneg(b
);
2876 /* Return any NaN input. */
2887 /* Zero over zero, or infinity over infinity, is a NaN. */
2888 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2889 || (eisinf (a
) && eisinf (b
)))
2891 mtherr ("ediv", INVALID
);
2896 /* Infinity over anything else is infinity. */
2903 /* Anything else over infinity is zero. */
2915 { /* See if numerator is zero. */
2916 for (i
= 1; i
< NI
- 1; i
++)
2920 ltb
-= enormlz (bi
);
2930 { /* possible divide by zero */
2931 for (i
= 1; i
< NI
- 1; i
++)
2935 lta
-= enormlz (ai
);
2939 /* Divide by zero is not an invalid operation.
2940 It is a divide-by-zero operation! */
2942 mtherr ("ediv", SING
);
2948 /* calculate exponent */
2949 lt
= ltb
- lta
+ EXONE
;
2950 emdnorm (bi
, i
, 0, lt
, 64);
2957 && (ecmp (c
, ezero
) != 0)
2960 *(c
+(NE
-1)) |= 0x8000;
2962 *(c
+(NE
-1)) &= ~0x8000;
2965 /* Multiply e-types A and B, return e-type product C. */
2969 unsigned EMUSHORT
*a
, *b
, *c
;
2971 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2973 EMULONG lt
, lta
, ltb
;
2975 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2976 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2977 sign
= eisneg(a
) ^ eisneg(b
);
2980 /* NaN times anything is the same NaN. */
2991 /* Zero times infinity is a NaN. */
2992 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2993 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2995 mtherr ("emul", INVALID
);
3000 /* Infinity times anything else is infinity. */
3002 if (eisinf (a
) || eisinf (b
))
3014 for (i
= 1; i
< NI
- 1; i
++)
3018 lta
-= enormlz (ai
);
3029 for (i
= 1; i
< NI
- 1; i
++)
3033 ltb
-= enormlz (bi
);
3042 /* Multiply significands */
3044 /* calculate exponent */
3045 lt
= lta
+ ltb
- (EXONE
- 1);
3046 emdnorm (bi
, j
, 0, lt
, 64);
3053 && (ecmp (c
, ezero
) != 0)
3056 *(c
+(NE
-1)) |= 0x8000;
3058 *(c
+(NE
-1)) &= ~0x8000;
3061 /* Convert double precision PE to e-type Y. */
3065 unsigned EMUSHORT
*pe
, *y
;
3074 ibmtoe (pe
, y
, DFmode
);
3079 c4xtoe (pe
, y
, HFmode
);
3082 register unsigned EMUSHORT r
;
3083 register unsigned EMUSHORT
*e
, *p
;
3084 unsigned EMUSHORT yy
[NI
];
3088 denorm
= 0; /* flag if denormalized number */
3090 if (! REAL_WORDS_BIG_ENDIAN
)
3096 yy
[M
] = (r
& 0x0f) | 0x10;
3097 r
&= ~0x800f; /* strip sign and 4 significand bits */
3102 if (! REAL_WORDS_BIG_ENDIAN
)
3104 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3105 || (pe
[1] != 0) || (pe
[0] != 0))
3107 enan (y
, yy
[0] != 0);
3113 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3114 || (pe
[2] != 0) || (pe
[3] != 0))
3116 enan (y
, yy
[0] != 0);
3127 #endif /* INFINITY */
3129 /* If zero exponent, then the significand is denormalized.
3130 So take back the understood high significand bit. */
3141 if (! REAL_WORDS_BIG_ENDIAN
)
3158 /* If zero exponent, then normalize the significand. */
3159 if ((k
= enormlz (yy
)) > NBITS
)
3162 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3165 #endif /* not C4X */
3166 #endif /* not IBM */
3167 #endif /* not DEC */
3170 /* Convert double extended precision float PE to e type Y. */
3174 unsigned EMUSHORT
*pe
, *y
;
3176 unsigned EMUSHORT yy
[NI
];
3177 unsigned EMUSHORT
*e
, *p
, *q
;
3182 for (i
= 0; i
< NE
- 5; i
++)
3184 /* This precision is not ordinarily supported on DEC or IBM. */
3186 for (i
= 0; i
< 5; i
++)
3190 p
= &yy
[0] + (NE
- 1);
3193 for (i
= 0; i
< 5; i
++)
3197 if (! REAL_WORDS_BIG_ENDIAN
)
3199 for (i
= 0; i
< 5; i
++)
3202 /* For denormal long double Intel format, shift significand up one
3203 -- but only if the top significand bit is zero. A top bit of 1
3204 is "pseudodenormal" when the exponent is zero. */
3205 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3207 unsigned EMUSHORT temp
[NI
];
3217 p
= &yy
[0] + (NE
- 1);
3218 #ifdef ARM_EXTENDED_IEEE_FORMAT
3219 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3220 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3226 for (i
= 0; i
< 4; i
++)
3231 /* Point to the exponent field and check max exponent cases. */
3233 if ((*p
& 0x7fff) == 0x7fff)
3236 if (! REAL_WORDS_BIG_ENDIAN
)
3238 for (i
= 0; i
< 4; i
++)
3240 if ((i
!= 3 && pe
[i
] != 0)
3241 /* Anything but 0x8000 here, including 0, is a NaN. */
3242 || (i
== 3 && pe
[i
] != 0x8000))
3244 enan (y
, (*p
& 0x8000) != 0);
3251 #ifdef ARM_EXTENDED_IEEE_FORMAT
3252 for (i
= 2; i
<= 5; i
++)
3256 enan (y
, (*p
& 0x8000) != 0);
3261 /* In Motorola extended precision format, the most significant
3262 bit of an infinity mantissa could be either 1 or 0. It is
3263 the lower order bits that tell whether the value is a NaN. */
3264 if ((pe
[2] & 0x7fff) != 0)
3267 for (i
= 3; i
<= 5; i
++)
3272 enan (y
, (*p
& 0x8000) != 0);
3276 #endif /* not ARM */
3285 #endif /* INFINITY */
3288 for (i
= 0; i
< NE
; i
++)
3292 /* Convert 128-bit long double precision float PE to e type Y. */
3296 unsigned EMUSHORT
*pe
, *y
;
3298 register unsigned EMUSHORT r
;
3299 unsigned EMUSHORT
*e
, *p
;
3300 unsigned EMUSHORT yy
[NI
];
3307 if (! REAL_WORDS_BIG_ENDIAN
)
3319 if (! REAL_WORDS_BIG_ENDIAN
)
3321 for (i
= 0; i
< 7; i
++)
3325 enan (y
, yy
[0] != 0);
3332 for (i
= 1; i
< 8; i
++)
3336 enan (y
, yy
[0] != 0);
3348 #endif /* INFINITY */
3352 if (! REAL_WORDS_BIG_ENDIAN
)
3354 for (i
= 0; i
< 7; i
++)
3360 for (i
= 0; i
< 7; i
++)
3364 /* If denormal, remove the implied bit; else shift down 1. */
3377 /* Convert single precision float PE to e type Y. */
3381 unsigned EMUSHORT
*pe
, *y
;
3385 ibmtoe (pe
, y
, SFmode
);
3391 c4xtoe (pe
, y
, QFmode
);
3395 register unsigned EMUSHORT r
;
3396 register unsigned EMUSHORT
*e
, *p
;
3397 unsigned EMUSHORT yy
[NI
];
3401 denorm
= 0; /* flag if denormalized number */
3404 if (! REAL_WORDS_BIG_ENDIAN
)
3414 yy
[M
] = (r
& 0x7f) | 0200;
3415 r
&= ~0x807f; /* strip sign and 7 significand bits */
3420 if (REAL_WORDS_BIG_ENDIAN
)
3422 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3424 enan (y
, yy
[0] != 0);
3430 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3432 enan (y
, yy
[0] != 0);
3443 #endif /* INFINITY */
3445 /* If zero exponent, then the significand is denormalized.
3446 So take back the understood high significand bit. */
3459 if (! REAL_WORDS_BIG_ENDIAN
)
3469 { /* if zero exponent, then normalize the significand */
3470 if ((k
= enormlz (yy
)) > NBITS
)
3473 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3476 #endif /* not C4X */
3477 #endif /* not IBM */
3480 /* Convert e-type X to IEEE 128-bit long double format E. */
3484 unsigned EMUSHORT
*x
, *e
;
3486 unsigned EMUSHORT xi
[NI
];
3493 make_nan (e
, eisneg (x
), TFmode
);
3498 exp
= (EMULONG
) xi
[E
];
3503 /* round off to nearest or even */
3506 emdnorm (xi
, 0, 0, exp
, 64);
3512 /* Convert exploded e-type X, that has already been rounded to
3513 113-bit precision, to IEEE 128-bit long double format Y. */
3517 unsigned EMUSHORT
*a
, *b
;
3519 register unsigned EMUSHORT
*p
, *q
;
3520 unsigned EMUSHORT i
;
3525 make_nan (b
, eiisneg (a
), TFmode
);
3530 if (REAL_WORDS_BIG_ENDIAN
)
3533 q
= b
+ 7; /* point to output exponent */
3535 /* If not denormal, delete the implied bit. */
3540 /* combine sign and exponent */
3542 if (REAL_WORDS_BIG_ENDIAN
)
3545 *q
++ = *p
++ | 0x8000;
3552 *q
-- = *p
++ | 0x8000;
3556 /* skip over guard word */
3558 /* move the significand */
3559 if (REAL_WORDS_BIG_ENDIAN
)
3561 for (i
= 0; i
< 7; i
++)
3566 for (i
= 0; i
< 7; i
++)
3571 /* Convert e-type X to IEEE double extended format E. */
3575 unsigned EMUSHORT
*x
, *e
;
3577 unsigned EMUSHORT xi
[NI
];
3584 make_nan (e
, eisneg (x
), XFmode
);
3589 /* adjust exponent for offset */
3590 exp
= (EMULONG
) xi
[E
];
3595 /* round off to nearest or even */
3598 emdnorm (xi
, 0, 0, exp
, 64);
3604 /* Convert exploded e-type X, that has already been rounded to
3605 64-bit precision, to IEEE double extended format Y. */
3609 unsigned EMUSHORT
*a
, *b
;
3611 register unsigned EMUSHORT
*p
, *q
;
3612 unsigned EMUSHORT i
;
3617 make_nan (b
, eiisneg (a
), XFmode
);
3621 /* Shift denormal long double Intel format significand down one bit. */
3622 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3632 if (REAL_WORDS_BIG_ENDIAN
)
3636 q
= b
+ 4; /* point to output exponent */
3637 #if LONG_DOUBLE_TYPE_SIZE == 96
3638 /* Clear the last two bytes of 12-byte Intel format */
3644 /* combine sign and exponent */
3648 *q
++ = *p
++ | 0x8000;
3655 *q
-- = *p
++ | 0x8000;
3660 if (REAL_WORDS_BIG_ENDIAN
)
3662 #ifdef ARM_EXTENDED_IEEE_FORMAT
3663 /* The exponent is in the lowest 15 bits of the first word. */
3664 *q
++ = i
? 0x8000 : 0;
3668 *q
++ = *p
++ | 0x8000;
3677 *q
-- = *p
++ | 0x8000;
3682 /* skip over guard word */
3684 /* move the significand */
3686 for (i
= 0; i
< 4; i
++)
3690 for (i
= 0; i
< 4; i
++)
3694 if (REAL_WORDS_BIG_ENDIAN
)
3696 for (i
= 0; i
< 4; i
++)
3704 /* Intel long double infinity significand. */
3712 for (i
= 0; i
< 4; i
++)
3718 /* e type to double precision. */
3721 /* Convert e-type X to DEC-format double E. */
3725 unsigned EMUSHORT
*x
, *e
;
3727 etodec (x
, e
); /* see etodec.c */
3730 /* Convert exploded e-type X, that has already been rounded to
3731 56-bit double precision, to DEC double Y. */
3735 unsigned EMUSHORT
*x
, *y
;
3742 /* Convert e-type X to IBM 370-format double E. */
3746 unsigned EMUSHORT
*x
, *e
;
3748 etoibm (x
, e
, DFmode
);
3751 /* Convert exploded e-type X, that has already been rounded to
3752 56-bit precision, to IBM 370 double Y. */
3756 unsigned EMUSHORT
*x
, *y
;
3758 toibm (x
, y
, DFmode
);
3761 #else /* it's neither DEC nor IBM */
3763 /* Convert e-type X to C4X-format long double E. */
3767 unsigned EMUSHORT
*x
, *e
;
3769 etoc4x (x
, e
, HFmode
);
3772 /* Convert exploded e-type X, that has already been rounded to
3773 56-bit precision, to IBM 370 double Y. */
3777 unsigned EMUSHORT
*x
, *y
;
3779 toc4x (x
, y
, HFmode
);
3782 #else /* it's neither DEC nor IBM nor C4X */
3784 /* Convert e-type X to IEEE double E. */
3788 unsigned EMUSHORT
*x
, *e
;
3790 unsigned EMUSHORT xi
[NI
];
3797 make_nan (e
, eisneg (x
), DFmode
);
3802 /* adjust exponent for offsets */
3803 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3808 /* round off to nearest or even */
3811 emdnorm (xi
, 0, 0, exp
, 64);
3817 /* Convert exploded e-type X, that has already been rounded to
3818 53-bit precision, to IEEE double Y. */
3822 unsigned EMUSHORT
*x
, *y
;
3824 unsigned EMUSHORT i
;
3825 unsigned EMUSHORT
*p
;
3830 make_nan (y
, eiisneg (x
), DFmode
);
3836 if (! REAL_WORDS_BIG_ENDIAN
)
3839 *y
= 0; /* output high order */
3841 *y
= 0x8000; /* output sign bit */
3844 if (i
>= (unsigned int) 2047)
3846 /* Saturate at largest number less than infinity. */
3849 if (! REAL_WORDS_BIG_ENDIAN
)
3863 *y
|= (unsigned EMUSHORT
) 0x7fef;
3864 if (! REAL_WORDS_BIG_ENDIAN
)
3889 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3890 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3891 if (! REAL_WORDS_BIG_ENDIAN
)
3906 #endif /* not C4X */
3907 #endif /* not IBM */
3908 #endif /* not DEC */
3912 /* e type to single precision. */
3915 /* Convert e-type X to IBM 370 float E. */
3919 unsigned EMUSHORT
*x
, *e
;
3921 etoibm (x
, e
, SFmode
);
3924 /* Convert exploded e-type X, that has already been rounded to
3925 float precision, to IBM 370 float Y. */
3929 unsigned EMUSHORT
*x
, *y
;
3931 toibm (x
, y
, SFmode
);
3937 /* Convert e-type X to C4X float E. */
3941 unsigned EMUSHORT
*x
, *e
;
3943 etoc4x (x
, e
, QFmode
);
3946 /* Convert exploded e-type X, that has already been rounded to
3947 float precision, to IBM 370 float Y. */
3951 unsigned EMUSHORT
*x
, *y
;
3953 toc4x (x
, y
, QFmode
);
3958 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3962 unsigned EMUSHORT
*x
, *e
;
3965 unsigned EMUSHORT xi
[NI
];
3971 make_nan (e
, eisneg (x
), SFmode
);
3976 /* adjust exponent for offsets */
3977 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3982 /* round off to nearest or even */
3985 emdnorm (xi
, 0, 0, exp
, 64);
3991 /* Convert exploded e-type X, that has already been rounded to
3992 float precision, to IEEE float Y. */
3996 unsigned EMUSHORT
*x
, *y
;
3998 unsigned EMUSHORT i
;
3999 unsigned EMUSHORT
*p
;
4004 make_nan (y
, eiisneg (x
), SFmode
);
4010 if (! REAL_WORDS_BIG_ENDIAN
)
4016 *y
= 0; /* output high order */
4018 *y
= 0x8000; /* output sign bit */
4021 /* Handle overflow cases. */
4025 *y
|= (unsigned EMUSHORT
) 0x7f80;
4030 if (! REAL_WORDS_BIG_ENDIAN
)
4038 #else /* no INFINITY */
4039 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4044 if (! REAL_WORDS_BIG_ENDIAN
)
4055 #endif /* no INFINITY */
4067 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4068 /* High order output already has sign bit set. */
4074 if (! REAL_WORDS_BIG_ENDIAN
)
4083 #endif /* not C4X */
4084 #endif /* not IBM */
4086 /* Compare two e type numbers.
4090 -2 if either a or b is a NaN. */
4094 unsigned EMUSHORT
*a
, *b
;
4096 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4097 register unsigned EMUSHORT
*p
, *q
;
4102 if (eisnan (a
) || eisnan (b
))
4111 { /* the signs are different */
4113 for (i
= 1; i
< NI
- 1; i
++)
4127 /* both are the same sign */
4142 return (0); /* equality */
4146 if (*(--p
) > *(--q
))
4147 return (msign
); /* p is bigger */
4149 return (-msign
); /* p is littler */
4153 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4157 unsigned EMUSHORT
*x
, *y
;
4164 /* Convert HOST_WIDE_INT LP to e type Y. */
4169 unsigned EMUSHORT
*y
;
4171 unsigned EMUSHORT yi
[NI
];
4172 unsigned HOST_WIDE_INT ll
;
4178 /* make it positive */
4179 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4180 yi
[0] = 0xffff; /* put correct sign in the e type number */
4184 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4186 /* move the long integer to yi significand area */
4187 #if HOST_BITS_PER_WIDE_INT == 64
4188 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4189 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4190 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4191 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4192 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4194 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4195 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4196 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4199 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4200 ecleaz (yi
); /* it was zero */
4202 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4203 emovo (yi
, y
); /* output the answer */
4206 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4210 unsigned HOST_WIDE_INT
*lp
;
4211 unsigned EMUSHORT
*y
;
4213 unsigned EMUSHORT yi
[NI
];
4214 unsigned HOST_WIDE_INT ll
;
4220 /* move the long integer to ayi significand area */
4221 #if HOST_BITS_PER_WIDE_INT == 64
4222 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4223 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4224 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4225 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4226 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4228 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4229 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4230 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4233 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4234 ecleaz (yi
); /* it was zero */
4236 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4237 emovo (yi
, y
); /* output the answer */
4241 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4242 part FRAC of e-type (packed internal format) floating point input X.
4243 The integer output I has the sign of the input, except that
4244 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4245 The output e-type fraction FRAC is the positive fractional
4250 unsigned EMUSHORT
*x
;
4252 unsigned EMUSHORT
*frac
;
4254 unsigned EMUSHORT xi
[NI
];
4256 unsigned HOST_WIDE_INT ll
;
4259 k
= (int) xi
[E
] - (EXONE
- 1);
4262 /* if exponent <= 0, integer = 0 and real output is fraction */
4267 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4269 /* long integer overflow: output large integer
4270 and correct fraction */
4272 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4275 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4276 /* In this case, let it overflow and convert as if unsigned. */
4277 euifrac (x
, &ll
, frac
);
4278 *i
= (HOST_WIDE_INT
) ll
;
4281 /* In other cases, return the largest positive integer. */
4282 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4287 warning ("overflow on truncation to integer");
4291 /* Shift more than 16 bits: first shift up k-16 mod 16,
4292 then shift up by 16's. */
4293 j
= k
- ((k
>> 4) << 4);
4300 ll
= (ll
<< 16) | xi
[M
];
4302 while ((k
-= 16) > 0);
4309 /* shift not more than 16 bits */
4311 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4318 if ((k
= enormlz (xi
)) > NBITS
)
4321 xi
[E
] -= (unsigned EMUSHORT
) k
;
4327 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4328 FRAC of e-type X. A negative input yields integer output = 0 but
4329 correct fraction. */
4332 euifrac (x
, i
, frac
)
4333 unsigned EMUSHORT
*x
;
4334 unsigned HOST_WIDE_INT
*i
;
4335 unsigned EMUSHORT
*frac
;
4337 unsigned HOST_WIDE_INT ll
;
4338 unsigned EMUSHORT xi
[NI
];
4342 k
= (int) xi
[E
] - (EXONE
- 1);
4345 /* if exponent <= 0, integer = 0 and argument is fraction */
4350 if (k
> HOST_BITS_PER_WIDE_INT
)
4352 /* Long integer overflow: output large integer
4353 and correct fraction.
4354 Note, the BSD microvax compiler says that ~(0UL)
4355 is a syntax error. */
4359 warning ("overflow on truncation to unsigned integer");
4363 /* Shift more than 16 bits: first shift up k-16 mod 16,
4364 then shift up by 16's. */
4365 j
= k
- ((k
>> 4) << 4);
4372 ll
= (ll
<< 16) | xi
[M
];
4374 while ((k
-= 16) > 0);
4379 /* shift not more than 16 bits */
4381 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4384 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4390 if ((k
= enormlz (xi
)) > NBITS
)
4393 xi
[E
] -= (unsigned EMUSHORT
) k
;
4398 /* Shift the significand of exploded e-type X up or down by SC bits. */
4402 unsigned EMUSHORT
*x
;
4405 unsigned EMUSHORT lost
;
4406 unsigned EMUSHORT
*p
;
4419 lost
|= *p
; /* remember lost bits */
4460 return ((int) lost
);
4463 /* Shift normalize the significand area of exploded e-type X.
4464 Return the shift count (up = positive). */
4468 unsigned EMUSHORT x
[];
4470 register unsigned EMUSHORT
*p
;
4479 return (0); /* already normalized */
4485 /* With guard word, there are NBITS+16 bits available.
4486 Return true if all are zero. */
4490 /* see if high byte is zero */
4491 while ((*p
& 0xff00) == 0)
4496 /* now shift 1 bit at a time */
4497 while ((*p
& 0x8000) == 0)
4503 mtherr ("enormlz", UNDERFLOW
);
4509 /* Normalize by shifting down out of the high guard word
4510 of the significand */
4525 mtherr ("enormlz", OVERFLOW
);
4532 /* Powers of ten used in decimal <-> binary conversions. */
4537 #if LONG_DOUBLE_TYPE_SIZE == 128
4538 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4540 {0x6576, 0x4a92, 0x804a, 0x153f,
4541 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4542 {0x6a32, 0xce52, 0x329a, 0x28ce,
4543 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4544 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4545 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4546 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4547 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4548 {0x851e, 0xeab7, 0x98fe, 0x901b,
4549 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4550 {0x0235, 0x0137, 0x36b1, 0x336c,
4551 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4552 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4553 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4554 {0x0000, 0x0000, 0x0000, 0x0000,
4555 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4556 {0x0000, 0x0000, 0x0000, 0x0000,
4557 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4558 {0x0000, 0x0000, 0x0000, 0x0000,
4559 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4560 {0x0000, 0x0000, 0x0000, 0x0000,
4561 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4562 {0x0000, 0x0000, 0x0000, 0x0000,
4563 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4564 {0x0000, 0x0000, 0x0000, 0x0000,
4565 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4568 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4570 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4571 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4572 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4573 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4574 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4575 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4576 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4577 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4578 {0xa23e, 0x5308, 0xfefb, 0x1155,
4579 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4580 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4581 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4582 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4583 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4584 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4585 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4586 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4587 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4588 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4589 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4590 {0xc155, 0xa4a8, 0x404e, 0x6113,
4591 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4592 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4593 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4594 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4595 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4598 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4599 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4601 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4602 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4603 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4604 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4605 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4606 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4607 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4608 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4609 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4610 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4611 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4612 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4613 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4616 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4618 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4619 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4620 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4621 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4622 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4623 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4624 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4625 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4626 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4627 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4628 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4629 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4630 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4635 /* Convert float value X to ASCII string STRING with NDIG digits after
4636 the decimal point. */
4639 e24toasc (x
, string
, ndigs
)
4640 unsigned EMUSHORT x
[];
4644 unsigned EMUSHORT w
[NI
];
4647 etoasc (w
, string
, ndigs
);
4650 /* Convert double value X to ASCII string STRING with NDIG digits after
4651 the decimal point. */
4654 e53toasc (x
, string
, ndigs
)
4655 unsigned EMUSHORT x
[];
4659 unsigned EMUSHORT w
[NI
];
4662 etoasc (w
, string
, ndigs
);
4665 /* Convert double extended value X to ASCII string STRING with NDIG digits
4666 after the decimal point. */
4669 e64toasc (x
, string
, ndigs
)
4670 unsigned EMUSHORT x
[];
4674 unsigned EMUSHORT w
[NI
];
4677 etoasc (w
, string
, ndigs
);
4680 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4681 after the decimal point. */
4684 e113toasc (x
, string
, ndigs
)
4685 unsigned EMUSHORT x
[];
4689 unsigned EMUSHORT w
[NI
];
4692 etoasc (w
, string
, ndigs
);
4696 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4697 the decimal point. */
4699 static char wstring
[80]; /* working storage for ASCII output */
4702 etoasc (x
, string
, ndigs
)
4703 unsigned EMUSHORT x
[];
4708 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4709 unsigned EMUSHORT
*p
, *r
, *ten
;
4710 unsigned EMUSHORT sign
;
4711 int i
, j
, k
, expon
, rndsav
;
4713 unsigned EMUSHORT m
;
4724 sprintf (wstring
, " NaN ");
4728 rndprc
= NBITS
; /* set to full precision */
4729 emov (x
, y
); /* retain external format */
4730 if (y
[NE
- 1] & 0x8000)
4733 y
[NE
- 1] &= 0x7fff;
4740 ten
= &etens
[NTEN
][0];
4742 /* Test for zero exponent */
4745 for (k
= 0; k
< NE
- 1; k
++)
4748 goto tnzro
; /* denormalized number */
4750 goto isone
; /* valid all zeros */
4754 /* Test for infinity. */
4755 if (y
[NE
- 1] == 0x7fff)
4758 sprintf (wstring
, " -Infinity ");
4760 sprintf (wstring
, " Infinity ");
4764 /* Test for exponent nonzero but significand denormalized.
4765 * This is an error condition.
4767 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4769 mtherr ("etoasc", DOMAIN
);
4770 sprintf (wstring
, "NaN");
4774 /* Compare to 1.0 */
4783 { /* Number is greater than 1 */
4784 /* Convert significand to an integer and strip trailing decimal zeros. */
4786 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4788 p
= &etens
[NTEN
- 4][0];
4794 for (j
= 0; j
< NE
- 1; j
++)
4807 /* Rescale from integer significand */
4808 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4810 /* Find power of 10 */
4814 /* An unordered compare result shouldn't happen here. */
4815 while (ecmp (ten
, u
) <= 0)
4817 if (ecmp (p
, u
) <= 0)
4830 { /* Number is less than 1.0 */
4831 /* Pad significand with trailing decimal zeros. */
4834 while ((y
[NE
- 2] & 0x8000) == 0)
4843 for (i
= 0; i
< NDEC
+ 1; i
++)
4845 if ((w
[NI
- 1] & 0x7) != 0)
4847 /* multiply by 10 */
4860 if (eone
[NE
- 1] <= u
[1])
4872 while (ecmp (eone
, w
) > 0)
4874 if (ecmp (p
, w
) >= 0)
4889 /* Find the first (leading) digit. */
4895 digit
= equot
[NI
- 1];
4896 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4904 digit
= equot
[NI
- 1];
4912 /* Examine number of digits requested by caller. */
4930 *s
++ = (char)digit
+ '0';
4933 /* Generate digits after the decimal point. */
4934 for (k
= 0; k
<= ndigs
; k
++)
4936 /* multiply current number by 10, without normalizing */
4943 *s
++ = (char) equot
[NI
- 1] + '0';
4945 digit
= equot
[NI
- 1];
4948 /* round off the ASCII string */
4951 /* Test for critical rounding case in ASCII output. */
4955 if (ecmp (t
, ezero
) != 0)
4956 goto roun
; /* round to nearest */
4958 if ((*(s
- 1) & 1) == 0)
4959 goto doexp
; /* round to even */
4962 /* Round up and propagate carry-outs */
4966 /* Carry out to most significant digit? */
4973 /* Most significant digit carries to 10? */
4981 /* Round up and carry out from less significant digits */
4993 sprintf (ss, "e+%d", expon);
4995 sprintf (ss, "e%d", expon);
4997 sprintf (ss
, "e%d", expon
);
5000 /* copy out the working string */
5003 while (*ss
== ' ') /* strip possible leading space */
5005 while ((*s
++ = *ss
++) != '\0')
5010 /* Convert ASCII string to floating point.
5012 Numeric input is a free format decimal number of any length, with
5013 or without decimal point. Entering E after the number followed by an
5014 integer number causes the second number to be interpreted as a power of
5015 10 to be multiplied by the first number (i.e., "scientific" notation). */
5017 /* Convert ASCII string S to single precision float value Y. */
5022 unsigned EMUSHORT
*y
;
5028 /* Convert ASCII string S to double precision value Y. */
5033 unsigned EMUSHORT
*y
;
5035 #if defined(DEC) || defined(IBM)
5047 /* Convert ASCII string S to double extended value Y. */
5052 unsigned EMUSHORT
*y
;
5057 /* Convert ASCII string S to 128-bit long double Y. */
5062 unsigned EMUSHORT
*y
;
5064 asctoeg (s
, y
, 113);
5067 /* Convert ASCII string S to e type Y. */
5072 unsigned EMUSHORT
*y
;
5074 asctoeg (s
, y
, NBITS
);
5077 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5078 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5081 asctoeg (ss
, y
, oprec
)
5083 unsigned EMUSHORT
*y
;
5086 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5087 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5088 int k
, trail
, c
, rndsav
;
5090 unsigned EMUSHORT nsign
, *p
;
5091 char *sp
, *s
, *lstr
;
5094 /* Copy the input string. */
5095 lstr
= (char *) alloca (strlen (ss
) + 1);
5098 while (*s
== ' ') /* skip leading spaces */
5102 while ((*sp
++ = *s
++) != '\0')
5106 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5113 rndprc
= NBITS
; /* Set to full precision */
5125 if (*s
>= '0' && *s
<= '9')
5131 if ((k
>= 0) && (k
< base
))
5133 /* Ignore leading zeros */
5134 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5136 /* Identify and strip trailing zeros after the decimal point. */
5137 if ((trail
== 0) && (decflg
!= 0))
5140 while ((*sp
>= '0' && *sp
<= '9')
5141 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5142 || (*sp
>= 'A' && *sp
<= 'F'))))
5144 /* Check for syntax error */
5146 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5147 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5149 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5160 /* If enough digits were given to more than fill up the yy register,
5161 continuing until overflow into the high guard word yy[2]
5162 guarantees that there will be a roundoff bit at the top
5163 of the low guard word after normalization. */
5170 nexp
+= 4; /* count digits after decimal point */
5172 eshup1 (yy
); /* multiply current number by 16 */
5180 nexp
+= 1; /* count digits after decimal point */
5182 eshup1 (yy
); /* multiply current number by 10 */
5188 /* Insert the current digit. */
5190 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5195 /* Mark any lost non-zero digit. */
5197 /* Count lost digits before the decimal point. */
5219 case '.': /* decimal point */
5249 mtherr ("asctoe", DOMAIN
);
5258 /* Exponent interpretation */
5260 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5261 for (k
= 0; k
< NI
; k
++)
5272 /* check for + or - */
5280 while ((*s
>= '0') && (*s
<= '9'))
5289 if ((exp
> MAXDECEXP
) && (base
== 10))
5293 yy
[E
] = 0x7fff; /* infinity */
5296 if ((exp
< MINDECEXP
) && (base
== 10))
5306 /* Base 16 hexadecimal floating constant. */
5307 if ((k
= enormlz (yy
)) > NBITS
)
5312 /* Adjust the exponent. NEXP is the number of hex digits,
5313 EXP is a power of 2. */
5314 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5324 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5325 while ((nexp
> 0) && (yy
[2] == 0))
5337 if ((k
= enormlz (yy
)) > NBITS
)
5342 lexp
= (EXONE
- 1 + NBITS
) - k
;
5343 emdnorm (yy
, lost
, 0, lexp
, 64);
5346 /* Convert to external format:
5348 Multiply by 10**nexp. If precision is 64 bits,
5349 the maximum relative error incurred in forming 10**n
5350 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5351 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5352 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5367 /* Punt. Can't handle this without 2 divides. */
5368 emovi (etens
[0], tt
);
5375 p
= &etens
[NTEN
][0];
5385 while (exp
<= MAXP
);
5404 /* Round and convert directly to the destination type */
5406 lexp
-= EXONE
- 0x3ff;
5408 else if (oprec
== 24 || oprec
== 32)
5409 lexp
-= (EXONE
- 0x7f);
5412 else if (oprec
== 24 || oprec
== 56)
5413 lexp
-= EXONE
- (0x41 << 2);
5415 else if (oprec
== 24)
5416 lexp
-= EXONE
- 0177;
5420 else if (oprec
== 56)
5421 lexp
-= EXONE
- 0201;
5424 emdnorm (yy
, lost
, 0, lexp
, 64);
5434 todec (yy
, y
); /* see etodec.c */
5439 toibm (yy
, y
, DFmode
);
5444 toc4x (yy
, y
, HFmode
);
5468 /* Return Y = largest integer not greater than X (truncated toward minus
5471 static unsigned EMUSHORT bmask
[] =
5494 unsigned EMUSHORT x
[], y
[];
5496 register unsigned EMUSHORT
*p
;
5498 unsigned EMUSHORT f
[NE
];
5500 emov (x
, f
); /* leave in external format */
5501 expon
= (int) f
[NE
- 1];
5502 e
= (expon
& 0x7fff) - (EXONE
- 1);
5508 /* number of bits to clear out */
5520 /* clear the remaining bits */
5522 /* truncate negatives toward minus infinity */
5525 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5527 for (i
= 0; i
< NE
- 1; i
++)
5540 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5541 For example, 1.1 = 0.55 * 2^1. */
5545 unsigned EMUSHORT x
[];
5547 unsigned EMUSHORT s
[];
5549 unsigned EMUSHORT xi
[NI
];
5553 /* Handle denormalized numbers properly using long integer exponent. */
5554 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5562 *exp
= (int) (li
- 0x3ffe);
5566 /* Return e type Y = X * 2^PWR2. */
5570 unsigned EMUSHORT x
[];
5572 unsigned EMUSHORT y
[];
5574 unsigned EMUSHORT xi
[NI
];
5582 emdnorm (xi
, i
, i
, li
, 64);
5588 /* C = remainder after dividing B by A, all e type values.
5589 Least significant integer quotient bits left in EQUOT. */
5593 unsigned EMUSHORT a
[], b
[], c
[];
5595 unsigned EMUSHORT den
[NI
], num
[NI
];
5599 || (ecmp (a
, ezero
) == 0)
5607 if (ecmp (a
, ezero
) == 0)
5609 mtherr ("eremain", SING
);
5615 eiremain (den
, num
);
5616 /* Sign of remainder = sign of quotient */
5625 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5626 remainder in NUM. */
5630 unsigned EMUSHORT den
[], num
[];
5633 unsigned EMUSHORT j
;
5636 ld
-= enormlz (den
);
5638 ln
-= enormlz (num
);
5642 if (ecmpm (den
, num
) <= 0)
5654 emdnorm (num
, 0, 0, ln
, 0);
5657 /* Report an error condition CODE encountered in function NAME.
5658 CODE is one of the following:
5660 Mnemonic Value Significance
5662 DOMAIN 1 argument domain error
5663 SING 2 function singularity
5664 OVERFLOW 3 overflow range error
5665 UNDERFLOW 4 underflow range error
5666 TLOSS 5 total loss of precision
5667 PLOSS 6 partial loss of precision
5668 INVALID 7 NaN - producing operation
5669 EDOM 33 Unix domain error code
5670 ERANGE 34 Unix range error code
5672 The order of appearance of the following messages is bound to the
5673 error codes defined above. */
5676 static char *ermsg
[NMSGS
] =
5678 "unknown", /* error code 0 */
5679 "domain error", /* error code 1 */
5680 "singularity", /* et seq. */
5683 "total loss of precision",
5684 "partial loss of precision",
5685 "`not-a-number' produced"
5698 /* The string passed by the calling program is supposed to be the
5699 name of the function in which the error occurred.
5700 The code argument selects which error message string will be printed. */
5702 if ((code
<= 0) || (code
>= NMSGS
))
5704 if (strcmp (name
, "esub") == 0)
5705 name
= "subtraction";
5706 else if (strcmp (name
, "ediv") == 0)
5708 else if (strcmp (name
, "emul") == 0)
5709 name
= "multiplication";
5710 else if (strcmp (name
, "enormlz") == 0)
5711 name
= "normalization";
5712 else if (strcmp (name
, "etoasc") == 0)
5713 name
= "conversion to text";
5714 else if (strcmp (name
, "asctoe") == 0)
5716 else if (strcmp (name
, "eremain") == 0)
5718 else if (strcmp (name
, "esqrt") == 0)
5719 name
= "square root";
5720 sprintf (errstr
, "%s during real %s", ermsg
[code
], name
);
5723 /* Set global error message word */
5728 /* Convert DEC double precision D to e type E. */
5732 unsigned EMUSHORT
*d
;
5733 unsigned EMUSHORT
*e
;
5735 unsigned EMUSHORT y
[NI
];
5736 register unsigned EMUSHORT r
, *p
;
5738 ecleaz (y
); /* start with a zero */
5739 p
= y
; /* point to our number */
5740 r
= *d
; /* get DEC exponent word */
5741 if (*d
& (unsigned int) 0x8000)
5742 *p
= 0xffff; /* fill in our sign */
5743 ++p
; /* bump pointer to our exponent word */
5744 r
&= 0x7fff; /* strip the sign bit */
5745 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5749 r
>>= 7; /* shift exponent word down 7 bits */
5750 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5751 /* add our e type exponent offset */
5752 *p
++ = r
; /* to form our exponent */
5754 r
= *d
++; /* now do the high order mantissa */
5755 r
&= 0177; /* strip off the DEC exponent and sign bits */
5756 r
|= 0200; /* the DEC understood high order mantissa bit */
5757 *p
++ = r
; /* put result in our high guard word */
5759 *p
++ = *d
++; /* fill in the rest of our mantissa */
5763 eshdn8 (y
); /* shift our mantissa down 8 bits */
5768 /* Convert e type X to DEC double precision D. */
5772 unsigned EMUSHORT
*x
, *d
;
5774 unsigned EMUSHORT xi
[NI
];
5779 /* Adjust exponent for offsets. */
5780 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5781 /* Round off to nearest or even. */
5784 emdnorm (xi
, 0, 0, exp
, 64);
5789 /* Convert exploded e-type X, that has already been rounded to
5790 56-bit precision, to DEC format double Y. */
5794 unsigned EMUSHORT
*x
, *y
;
5796 unsigned EMUSHORT i
;
5797 unsigned EMUSHORT
*p
;
5836 /* Convert IBM single/double precision to e type. */
5840 unsigned EMUSHORT
*d
;
5841 unsigned EMUSHORT
*e
;
5842 enum machine_mode mode
;
5844 unsigned EMUSHORT y
[NI
];
5845 register unsigned EMUSHORT r
, *p
;
5848 ecleaz (y
); /* start with a zero */
5849 p
= y
; /* point to our number */
5850 r
= *d
; /* get IBM exponent word */
5851 if (*d
& (unsigned int) 0x8000)
5852 *p
= 0xffff; /* fill in our sign */
5853 ++p
; /* bump pointer to our exponent word */
5854 r
&= 0x7f00; /* strip the sign bit */
5855 r
>>= 6; /* shift exponent word down 6 bits */
5856 /* in fact shift by 8 right and 2 left */
5857 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5858 /* add our e type exponent offset */
5859 *p
++ = r
; /* to form our exponent */
5861 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5862 /* strip off the IBM exponent and sign bits */
5863 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5865 *p
++ = *d
++; /* fill in the rest of our mantissa */
5870 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5873 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5874 /* handle change in RADIX */
5880 /* Convert e type to IBM single/double precision. */
5884 unsigned EMUSHORT
*x
, *d
;
5885 enum machine_mode mode
;
5887 unsigned EMUSHORT xi
[NI
];
5892 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5893 /* round off to nearest or even */
5896 emdnorm (xi
, 0, 0, exp
, 64);
5898 toibm (xi
, d
, mode
);
5903 unsigned EMUSHORT
*x
, *y
;
5904 enum machine_mode mode
;
5906 unsigned EMUSHORT i
;
5907 unsigned EMUSHORT
*p
;
5957 /* Convert C4X single/double precision to e type. */
5961 unsigned EMUSHORT
*d
;
5962 unsigned EMUSHORT
*e
;
5963 enum machine_mode mode
;
5965 unsigned EMUSHORT y
[NI
];
5972 /* Short-circuit the zero case. */
5973 if ((d
[0] == 0x8000)
5975 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5986 ecleaz (y
); /* start with a zero */
5987 r
= d
[0]; /* get sign/exponent part */
5988 if (r
& (unsigned int) 0x0080)
5990 y
[0] = 0xffff; /* fill in our sign */
5998 r
>>= 8; /* Shift exponent word down 8 bits. */
5999 if (r
& 0x80) /* Make the exponent negative if it is. */
6001 r
= r
| (~0 & ~0xff);
6006 /* Now do the high order mantissa. We don't "or" on the high bit
6007 because it is 2 (not 1) and is handled a little differently
6012 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6014 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6024 /* Now do the two's complement on the data. */
6026 carry
= 1; /* Initially add 1 for the two's complement. */
6027 for (i
=size
+ M
; i
> M
; i
--)
6029 if (carry
&& (y
[i
] == 0x0000))
6031 /* We overflowed into the next word, carry is the same. */
6032 y
[i
] = carry
? 0x0000 : 0xffff;
6036 /* No overflow, just invert and add carry. */
6037 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6052 /* Add our e type exponent offset to form our exponent. */
6056 /* Now do the high order mantissa strip off the exponent and sign
6057 bits and add the high 1 bit. */
6058 y
[M
] = (d
[0] & 0x7f) | 0x80;
6061 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6063 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6073 /* Convert e type to C4X single/double precision. */
6077 unsigned EMUSHORT
*x
, *d
;
6078 enum machine_mode mode
;
6080 unsigned EMUSHORT xi
[NI
];
6086 /* Adjust exponent for offsets. */
6087 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6089 /* Round off to nearest or even. */
6091 rndprc
= mode
== QFmode
? 24 : 32;
6092 emdnorm (xi
, 0, 0, exp
, 64);
6094 toc4x (xi
, d
, mode
);
6099 unsigned EMUSHORT
*x
, *y
;
6100 enum machine_mode mode
;
6106 /* Short-circuit the zero case */
6107 if ((x
[0] == 0) /* Zero exponent and sign */
6109 && (x
[M
] == 0) /* The rest is for zero mantissa */
6111 /* Only check for double if necessary */
6112 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6114 /* We have a zero. Put it into the output and return. */
6127 /* Negative number require a two's complement conversion of the
6133 i
= ((int) x
[1]) - 0x7f;
6135 /* Now add 1 to the inverted data to do the two's complement. */
6145 x
[v
] = carry
? 0x0000 : 0xffff;
6149 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6155 /* The following is a special case. The C4X negative float requires
6156 a zero in the high bit (because the format is (2 - x) x 2^m), so
6157 if a one is in that bit, we have to shift left one to get rid
6158 of it. This only occurs if the number is -1 x 2^m. */
6159 if (x
[M
+1] & 0x8000)
6161 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6162 high sign bit and shift the exponent. */
6169 i
= ((int) x
[1]) - 0x7f;
6172 if ((i
< -128) || (i
> 127))
6187 y
[0] |= ((i
& 0xff) << 8);
6191 y
[0] |= x
[M
] & 0x7f;
6201 /* Output a binary NaN bit pattern in the target machine's format. */
6203 /* If special NaN bit patterns are required, define them in tm.h
6204 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6210 unsigned EMUSHORT TFbignan
[8] =
6211 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6212 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6220 unsigned EMUSHORT XFbignan
[6] =
6221 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6222 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6230 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6231 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6239 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6240 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6246 make_nan (nan
, sign
, mode
)
6247 unsigned EMUSHORT
*nan
;
6249 enum machine_mode mode
;
6252 unsigned EMUSHORT
*p
;
6256 /* Possibly the `reserved operand' patterns on a VAX can be
6257 used like NaN's, but probably not in the same way as IEEE. */
6258 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6261 if (REAL_WORDS_BIG_ENDIAN
)
6269 if (REAL_WORDS_BIG_ENDIAN
)
6277 if (REAL_WORDS_BIG_ENDIAN
)
6286 if (REAL_WORDS_BIG_ENDIAN
)
6296 if (REAL_WORDS_BIG_ENDIAN
)
6297 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6300 if (! REAL_WORDS_BIG_ENDIAN
)
6301 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6304 /* This is the inverse of the function `etarsingle' invoked by
6305 REAL_VALUE_TO_TARGET_SINGLE. */
6308 ereal_unto_float (f
)
6312 unsigned EMUSHORT s
[2];
6313 unsigned EMUSHORT e
[NE
];
6315 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6316 This is the inverse operation to what the function `endian' does. */
6317 if (REAL_WORDS_BIG_ENDIAN
)
6319 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6320 s
[1] = (unsigned EMUSHORT
) f
;
6324 s
[0] = (unsigned EMUSHORT
) f
;
6325 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6327 /* Convert and promote the target float to E-type. */
6329 /* Output E-type to REAL_VALUE_TYPE. */
6335 /* This is the inverse of the function `etardouble' invoked by
6336 REAL_VALUE_TO_TARGET_DOUBLE. */
6339 ereal_unto_double (d
)
6343 unsigned EMUSHORT s
[4];
6344 unsigned EMUSHORT e
[NE
];
6346 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6347 if (REAL_WORDS_BIG_ENDIAN
)
6349 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6350 s
[1] = (unsigned EMUSHORT
) d
[0];
6351 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6352 s
[3] = (unsigned EMUSHORT
) d
[1];
6356 /* Target float words are little-endian. */
6357 s
[0] = (unsigned EMUSHORT
) d
[0];
6358 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6359 s
[2] = (unsigned EMUSHORT
) d
[1];
6360 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6362 /* Convert target double to E-type. */
6364 /* Output E-type to REAL_VALUE_TYPE. */
6370 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6371 This is somewhat like ereal_unto_float, but the input types
6372 for these are different. */
6375 ereal_from_float (f
)
6379 unsigned EMUSHORT s
[2];
6380 unsigned EMUSHORT e
[NE
];
6382 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6383 This is the inverse operation to what the function `endian' does. */
6384 if (REAL_WORDS_BIG_ENDIAN
)
6386 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6387 s
[1] = (unsigned EMUSHORT
) f
;
6391 s
[0] = (unsigned EMUSHORT
) f
;
6392 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6394 /* Convert and promote the target float to E-type. */
6396 /* Output E-type to REAL_VALUE_TYPE. */
6402 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6403 This is somewhat like ereal_unto_double, but the input types
6404 for these are different.
6406 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6407 data format, with no holes in the bit packing. The first element
6408 of the input array holds the bits that would come first in the
6409 target computer's memory. */
6412 ereal_from_double (d
)
6416 unsigned EMUSHORT s
[4];
6417 unsigned EMUSHORT e
[NE
];
6419 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6420 if (REAL_WORDS_BIG_ENDIAN
)
6422 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6423 s
[1] = (unsigned EMUSHORT
) d
[0];
6424 #if HOST_BITS_PER_WIDE_INT == 32
6425 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6426 s
[3] = (unsigned EMUSHORT
) d
[1];
6428 /* In this case the entire target double is contained in the
6429 first array element. The second element of the input is
6431 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6432 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6437 /* Target float words are little-endian. */
6438 s
[0] = (unsigned EMUSHORT
) d
[0];
6439 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6440 #if HOST_BITS_PER_WIDE_INT == 32
6441 s
[2] = (unsigned EMUSHORT
) d
[1];
6442 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6444 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6445 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6448 /* Convert target double to E-type. */
6450 /* Output E-type to REAL_VALUE_TYPE. */
6457 /* Convert target computer unsigned 64-bit integer to e-type.
6458 The endian-ness of DImode follows the convention for integers,
6459 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6463 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6464 unsigned EMUSHORT
*e
;
6466 unsigned EMUSHORT yi
[NI
];
6470 if (WORDS_BIG_ENDIAN
)
6472 for (k
= M
; k
< M
+ 4; k
++)
6477 for (k
= M
+ 3; k
>= M
; k
--)
6480 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6481 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6482 ecleaz (yi
); /* it was zero */
6484 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6488 /* Convert target computer signed 64-bit integer to e-type. */
6492 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6493 unsigned EMUSHORT
*e
;
6495 unsigned EMULONG acc
;
6496 unsigned EMUSHORT yi
[NI
];
6497 unsigned EMUSHORT carry
;
6501 if (WORDS_BIG_ENDIAN
)
6503 for (k
= M
; k
< M
+ 4; k
++)
6508 for (k
= M
+ 3; k
>= M
; k
--)
6511 /* Take absolute value */
6517 for (k
= M
+ 3; k
>= M
; k
--)
6519 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6526 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6527 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6528 ecleaz (yi
); /* it was zero */
6530 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6537 /* Convert e-type to unsigned 64-bit int. */
6541 unsigned EMUSHORT
*x
;
6542 unsigned EMUSHORT
*i
;
6544 unsigned EMUSHORT xi
[NI
];
6553 k
= (int) xi
[E
] - (EXONE
- 1);
6556 for (j
= 0; j
< 4; j
++)
6562 for (j
= 0; j
< 4; j
++)
6565 warning ("overflow on truncation to integer");
6570 /* Shift more than 16 bits: first shift up k-16 mod 16,
6571 then shift up by 16's. */
6572 j
= k
- ((k
>> 4) << 4);
6576 if (WORDS_BIG_ENDIAN
)
6587 if (WORDS_BIG_ENDIAN
)
6592 while ((k
-= 16) > 0);
6596 /* shift not more than 16 bits */
6601 if (WORDS_BIG_ENDIAN
)
6620 /* Convert e-type to signed 64-bit int. */
6624 unsigned EMUSHORT
*x
;
6625 unsigned EMUSHORT
*i
;
6627 unsigned EMULONG acc
;
6628 unsigned EMUSHORT xi
[NI
];
6629 unsigned EMUSHORT carry
;
6630 unsigned EMUSHORT
*isave
;
6634 k
= (int) xi
[E
] - (EXONE
- 1);
6637 for (j
= 0; j
< 4; j
++)
6643 for (j
= 0; j
< 4; j
++)
6646 warning ("overflow on truncation to integer");
6652 /* Shift more than 16 bits: first shift up k-16 mod 16,
6653 then shift up by 16's. */
6654 j
= k
- ((k
>> 4) << 4);
6658 if (WORDS_BIG_ENDIAN
)
6669 if (WORDS_BIG_ENDIAN
)
6674 while ((k
-= 16) > 0);
6678 /* shift not more than 16 bits */
6681 if (WORDS_BIG_ENDIAN
)
6697 /* Negate if negative */
6701 if (WORDS_BIG_ENDIAN
)
6703 for (k
= 0; k
< 4; k
++)
6705 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6706 if (WORDS_BIG_ENDIAN
)
6718 /* Longhand square root routine. */
6721 static int esqinited
= 0;
6722 static unsigned short sqrndbit
[NI
];
6726 unsigned EMUSHORT
*x
, *y
;
6728 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6730 int i
, j
, k
, n
, nlups
;
6735 sqrndbit
[NI
- 2] = 1;
6738 /* Check for arg <= 0 */
6739 i
= ecmp (x
, ezero
);
6744 mtherr ("esqrt", DOMAIN
);
6760 /* Bring in the arg and renormalize if it is denormal. */
6762 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6766 /* Divide exponent by 2 */
6768 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6770 /* Adjust if exponent odd */
6780 n
= 8; /* get 8 bits of result per inner loop */
6786 /* bring in next word of arg */
6788 num
[NI
- 1] = xx
[j
+ 3];
6789 /* Do additional bit on last outer loop, for roundoff. */
6792 for (i
= 0; i
< n
; i
++)
6794 /* Next 2 bits of arg */
6797 /* Shift up answer */
6799 /* Make trial divisor */
6800 for (k
= 0; k
< NI
; k
++)
6803 eaddm (sqrndbit
, temp
);
6804 /* Subtract and insert answer bit if it goes in */
6805 if (ecmpm (temp
, num
) <= 0)
6815 /* Adjust for extra, roundoff loop done. */
6816 exp
+= (NBITS
- 1) - rndprc
;
6818 /* Sticky bit = 1 if the remainder is nonzero. */
6820 for (i
= 3; i
< NI
; i
++)
6823 /* Renormalize and round off. */
6824 emdnorm (sq
, k
, 0, exp
, 64);
6828 #endif /* EMU_NON_COMPILE not defined */
6830 /* Return the binary precision of the significand for a given
6831 floating point mode. The mode can hold an integer value
6832 that many bits wide, without losing any bits. */
6835 significand_size (mode
)
6836 enum machine_mode mode
;
6839 /* Don't test the modes, but their sizes, lest this
6840 code won't work for BITS_PER_UNIT != 8 . */
6842 switch (GET_MODE_BITSIZE (mode
))
6846 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6853 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6856 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6859 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6862 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT