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) \
253 if (2*NE < sizeof(*r)) \
254 bzero((char *)r, sizeof(*r)); \
255 bcopy ((char *) e, (char *) r, 2*NE); \
257 #else /* no XFmode */
258 #if LONG_DOUBLE_TYPE_SIZE == 128
260 #define MAXDECEXP 4932
261 #define MINDECEXP -4977
262 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
263 #define PUT_REAL(e,r) \
265 if (2*NE < sizeof(*r)) \
266 bzero((char *)r, sizeof(*r)); \
267 bcopy ((char *) e, (char *) r, 2*NE); \
271 #define MAXDECEXP 4932
272 #define MINDECEXP -4956
273 #ifdef REAL_ARITHMETIC
274 /* Emulator uses target format internally
275 but host stores it in host endian-ness. */
277 #define GET_REAL(r,e) \
279 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
280 e53toe ((unsigned EMUSHORT *) (r), (e)); \
283 unsigned EMUSHORT w[4]; \
284 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
285 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
286 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
287 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
292 #define PUT_REAL(e,r) \
294 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
295 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
298 unsigned EMUSHORT w[4]; \
300 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
301 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
302 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
303 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
307 #else /* not REAL_ARITHMETIC */
309 /* emulator uses host format */
310 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
311 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
313 #endif /* not REAL_ARITHMETIC */
314 #endif /* not TFmode */
315 #endif /* not XFmode */
318 /* Number of 16 bit words in internal format */
321 /* Array offset to exponent */
324 /* Array offset to high guard word */
327 /* Number of bits of precision */
328 #define NBITS ((NI-4)*16)
330 /* Maximum number of decimal digits in ASCII conversion
333 #define NDEC (NBITS*8/27)
335 /* The exponent of 1.0 */
336 #define EXONE (0x3fff)
338 extern int extra_warnings
;
339 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
340 extern unsigned EMUSHORT elog2
[], esqrt2
[];
342 static void endian
PROTO((unsigned EMUSHORT
*, long *,
344 static void eclear
PROTO((unsigned EMUSHORT
*));
345 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
347 static void eabs
PROTO((unsigned EMUSHORT
*));
349 static void eneg
PROTO((unsigned EMUSHORT
*));
350 static int eisneg
PROTO((unsigned EMUSHORT
*));
351 static int eisinf
PROTO((unsigned EMUSHORT
*));
352 static int eisnan
PROTO((unsigned EMUSHORT
*));
353 static void einfin
PROTO((unsigned EMUSHORT
*));
354 static void enan
PROTO((unsigned EMUSHORT
*, int));
355 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
356 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
357 static void ecleaz
PROTO((unsigned EMUSHORT
*));
358 static void ecleazs
PROTO((unsigned EMUSHORT
*));
359 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
360 static void einan
PROTO((unsigned EMUSHORT
*));
361 static int eiisnan
PROTO((unsigned EMUSHORT
*));
362 static int eiisneg
PROTO((unsigned EMUSHORT
*));
364 static void eiinfin
PROTO((unsigned EMUSHORT
*));
366 static int eiisinf
PROTO((unsigned EMUSHORT
*));
367 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
368 static void eshdn1
PROTO((unsigned EMUSHORT
*));
369 static void eshup1
PROTO((unsigned EMUSHORT
*));
370 static void eshdn8
PROTO((unsigned EMUSHORT
*));
371 static void eshup8
PROTO((unsigned EMUSHORT
*));
372 static void eshup6
PROTO((unsigned EMUSHORT
*));
373 static void eshdn6
PROTO((unsigned EMUSHORT
*));
374 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
375 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void m16m
PROTO((unsigned int, unsigned short *,
378 static int edivm
PROTO((unsigned short *, unsigned short *));
379 static int emulm
PROTO((unsigned short *, unsigned short *));
380 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
381 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
382 unsigned EMUSHORT
*));
383 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
384 unsigned EMUSHORT
*));
385 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
386 unsigned EMUSHORT
*));
387 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
388 unsigned EMUSHORT
*));
389 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
390 unsigned EMUSHORT
*));
391 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
392 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
394 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
395 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
396 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
397 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
398 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
399 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
400 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
401 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
402 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
403 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
405 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
407 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
408 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
409 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
410 unsigned EMUSHORT
*));
411 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
412 unsigned EMUSHORT
*));
413 static int eshift
PROTO((unsigned EMUSHORT
*, int));
414 static int enormlz
PROTO((unsigned EMUSHORT
*));
416 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
417 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
418 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
419 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
421 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
422 static void asctoe24
PROTO((const char *, unsigned EMUSHORT
*));
423 static void asctoe53
PROTO((const char *, unsigned EMUSHORT
*));
424 static void asctoe64
PROTO((const char *, unsigned EMUSHORT
*));
425 static void asctoe113
PROTO((const char *, unsigned EMUSHORT
*));
426 static void asctoe
PROTO((const char *, unsigned EMUSHORT
*));
427 static void asctoeg
PROTO((const char *, unsigned EMUSHORT
*, int));
428 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
430 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
431 unsigned EMUSHORT
*));
433 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
435 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
436 unsigned EMUSHORT
*));
438 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
439 static void mtherr
PROTO((const char *, int));
441 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
442 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
443 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
446 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
448 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
450 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
454 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
456 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
458 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
461 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
463 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
464 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
465 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
466 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
467 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
470 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
471 swapping ends if required, into output array of longs. The
472 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
476 unsigned EMUSHORT e
[];
478 enum machine_mode mode
;
482 if (REAL_WORDS_BIG_ENDIAN
)
487 /* Swap halfwords in the fourth long. */
488 th
= (unsigned long) e
[6] & 0xffff;
489 t
= (unsigned long) e
[7] & 0xffff;
494 /* Swap halfwords in the third long. */
495 th
= (unsigned long) e
[4] & 0xffff;
496 t
= (unsigned long) e
[5] & 0xffff;
499 /* fall into the double case */
502 /* Swap halfwords in the second word. */
503 th
= (unsigned long) e
[2] & 0xffff;
504 t
= (unsigned long) e
[3] & 0xffff;
507 /* fall into the float case */
511 /* Swap halfwords in the first word. */
512 th
= (unsigned long) e
[0] & 0xffff;
513 t
= (unsigned long) e
[1] & 0xffff;
524 /* Pack the output array without swapping. */
529 /* Pack the fourth long. */
530 th
= (unsigned long) e
[7] & 0xffff;
531 t
= (unsigned long) e
[6] & 0xffff;
536 /* Pack the third long.
537 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
539 th
= (unsigned long) e
[5] & 0xffff;
540 t
= (unsigned long) e
[4] & 0xffff;
543 /* fall into the double case */
546 /* Pack the second long */
547 th
= (unsigned long) e
[3] & 0xffff;
548 t
= (unsigned long) e
[2] & 0xffff;
551 /* fall into the float case */
555 /* Pack the first long */
556 th
= (unsigned long) e
[1] & 0xffff;
557 t
= (unsigned long) e
[0] & 0xffff;
569 /* This is the implementation of the REAL_ARITHMETIC macro. */
572 earith (value
, icode
, r1
, r2
)
573 REAL_VALUE_TYPE
*value
;
578 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
584 /* Return NaN input back to the caller. */
587 PUT_REAL (d1
, value
);
592 PUT_REAL (d2
, value
);
596 code
= (enum tree_code
) icode
;
604 esub (d2
, d1
, v
); /* d1 - d2 */
612 #ifndef REAL_INFINITY
613 if (ecmp (d2
, ezero
) == 0)
616 enan (v
, eisneg (d1
) ^ eisneg (d2
));
623 ediv (d2
, d1
, v
); /* d1/d2 */
626 case MIN_EXPR
: /* min (d1,d2) */
627 if (ecmp (d1
, d2
) < 0)
633 case MAX_EXPR
: /* max (d1,d2) */
634 if (ecmp (d1
, d2
) > 0)
647 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
648 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
654 unsigned EMUSHORT f
[NE
], g
[NE
];
670 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
671 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
677 unsigned EMUSHORT f
[NE
], g
[NE
];
679 unsigned HOST_WIDE_INT l
;
693 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
694 string to binary, rounding off as indicated by the machine_mode argument.
695 Then it promotes the rounded value to REAL_VALUE_TYPE. */
702 unsigned EMUSHORT tem
[NE
], e
[NE
];
745 /* Expansion of REAL_NEGATE. */
751 unsigned EMUSHORT e
[NE
];
761 /* Round real toward zero to HOST_WIDE_INT;
762 implements REAL_VALUE_FIX (x). */
768 unsigned EMUSHORT f
[NE
], g
[NE
];
775 warning ("conversion from NaN to int");
783 /* Round real toward zero to unsigned HOST_WIDE_INT
784 implements REAL_VALUE_UNSIGNED_FIX (x).
785 Negative input returns zero. */
787 unsigned HOST_WIDE_INT
791 unsigned EMUSHORT f
[NE
], g
[NE
];
792 unsigned HOST_WIDE_INT l
;
798 warning ("conversion from NaN to unsigned int");
807 /* REAL_VALUE_FROM_INT macro. */
810 ereal_from_int (d
, i
, j
, mode
)
813 enum machine_mode mode
;
815 unsigned EMUSHORT df
[NE
], dg
[NE
];
816 HOST_WIDE_INT low
, high
;
819 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
826 /* complement and add 1 */
833 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
834 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
836 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
841 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
842 Avoid double-rounding errors later by rounding off now from the
843 extra-wide internal format to the requested precision. */
844 switch (GET_MODE_BITSIZE (mode
))
874 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
877 ereal_from_uint (d
, i
, j
, mode
)
879 unsigned HOST_WIDE_INT i
, j
;
880 enum machine_mode mode
;
882 unsigned EMUSHORT df
[NE
], dg
[NE
];
883 unsigned HOST_WIDE_INT low
, high
;
885 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
889 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
895 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
896 Avoid double-rounding errors later by rounding off now from the
897 extra-wide internal format to the requested precision. */
898 switch (GET_MODE_BITSIZE (mode
))
928 /* REAL_VALUE_TO_INT macro. */
931 ereal_to_int (low
, high
, rr
)
932 HOST_WIDE_INT
*low
, *high
;
935 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
942 warning ("conversion from NaN to int");
948 /* convert positive value */
955 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
956 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
957 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
958 emul (df
, dh
, dg
); /* fractional part is the low word */
959 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
962 /* complement and add 1 */
972 /* REAL_VALUE_LDEXP macro. */
979 unsigned EMUSHORT e
[NE
], y
[NE
];
992 /* These routines are conditionally compiled because functions
993 of the same names may be defined in fold-const.c. */
995 #ifdef REAL_ARITHMETIC
997 /* Check for infinity in a REAL_VALUE_TYPE. */
1003 unsigned EMUSHORT e
[NE
];
1007 return (eisinf (e
));
1013 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1019 unsigned EMUSHORT e
[NE
];
1023 return (eisnan (e
));
1030 /* Check for a negative REAL_VALUE_TYPE number.
1031 This just checks the sign bit, so that -0 counts as negative. */
1037 return ereal_isneg (x
);
1040 /* Expansion of REAL_VALUE_TRUNCATE.
1041 The result is in floating point, rounded to nearest or even. */
1044 real_value_truncate (mode
, arg
)
1045 enum machine_mode mode
;
1046 REAL_VALUE_TYPE arg
;
1048 unsigned EMUSHORT e
[NE
], t
[NE
];
1094 /* If an unsupported type was requested, presume that
1095 the machine files know something useful to do with
1096 the unmodified value. */
1105 /* Try to change R into its exact multiplicative inverse in machine mode
1106 MODE. Return nonzero function value if successful. */
1109 exact_real_inverse (mode
, r
)
1110 enum machine_mode mode
;
1113 unsigned EMUSHORT e
[NE
], einv
[NE
];
1114 REAL_VALUE_TYPE rinv
;
1119 /* Test for input in range. Don't transform IEEE special values. */
1120 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1123 /* Test for a power of 2: all significand bits zero except the MSB.
1124 We are assuming the target has binary (or hex) arithmetic. */
1125 if (e
[NE
- 2] != 0x8000)
1128 for (i
= 0; i
< NE
- 2; i
++)
1134 /* Compute the inverse and truncate it to the required mode. */
1135 ediv (e
, eone
, einv
);
1136 PUT_REAL (einv
, &rinv
);
1137 rinv
= real_value_truncate (mode
, rinv
);
1139 #ifdef CHECK_FLOAT_VALUE
1140 /* This check is not redundant. It may, for example, flush
1141 a supposedly IEEE denormal value to zero. */
1143 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1146 GET_REAL (&rinv
, einv
);
1148 /* Check the bits again, because the truncation might have
1149 generated an arbitrary saturation value on overflow. */
1150 if (einv
[NE
- 2] != 0x8000)
1153 for (i
= 0; i
< NE
- 2; i
++)
1159 /* Fail if the computed inverse is out of range. */
1160 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1163 /* Output the reciprocal and return success flag. */
1167 #endif /* REAL_ARITHMETIC defined */
1169 /* Used for debugging--print the value of R in human-readable format
1178 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1179 fprintf (stderr
, "%s", dstr
);
1183 /* The following routines convert REAL_VALUE_TYPE to the various floating
1184 point formats that are meaningful to supported computers.
1186 The results are returned in 32-bit pieces, each piece stored in a `long'.
1187 This is so they can be printed by statements like
1189 fprintf (file, "%lx, %lx", L[0], L[1]);
1191 that will work on both narrow- and wide-word host computers. */
1193 /* Convert R to a 128-bit long double precision value. The output array L
1194 contains four 32-bit pieces of the result, in the order they would appear
1202 unsigned EMUSHORT e
[NE
];
1206 endian (e
, l
, TFmode
);
1209 /* Convert R to a double extended precision value. The output array L
1210 contains three 32-bit pieces of the result, in the order they would
1211 appear in memory. */
1218 unsigned EMUSHORT e
[NE
];
1222 endian (e
, l
, XFmode
);
1225 /* Convert R to a double precision value. The output array L contains two
1226 32-bit pieces of the result, in the order they would appear in memory. */
1233 unsigned EMUSHORT e
[NE
];
1237 endian (e
, l
, DFmode
);
1240 /* Convert R to a single precision float value stored in the least-significant
1241 bits of a `long'. */
1247 unsigned EMUSHORT e
[NE
];
1252 endian (e
, &l
, SFmode
);
1256 /* Convert X to a decimal ASCII string S for output to an assembly
1257 language file. Note, there is no standard way to spell infinity or
1258 a NaN, so these values may require special treatment in the tm.h
1262 ereal_to_decimal (x
, s
)
1266 unsigned EMUSHORT e
[NE
];
1272 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1273 or -2 if either is a NaN. */
1277 REAL_VALUE_TYPE x
, y
;
1279 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1283 return (ecmp (ex
, ey
));
1286 /* Return 1 if the sign bit of X is set, else return 0. */
1292 unsigned EMUSHORT ex
[NE
];
1295 return (eisneg (ex
));
1298 /* End of REAL_ARITHMETIC interface */
1301 Extended precision IEEE binary floating point arithmetic routines
1303 Numbers are stored in C language as arrays of 16-bit unsigned
1304 short integers. The arguments of the routines are pointers to
1307 External e type data structure, similar to Intel 8087 chip
1308 temporary real format but possibly with a larger significand:
1310 NE-1 significand words (least significant word first,
1311 most significant bit is normally set)
1312 exponent (value = EXONE for 1.0,
1313 top bit is the sign)
1316 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1318 ei[0] sign word (0 for positive, 0xffff for negative)
1319 ei[1] biased exponent (value = EXONE for the number 1.0)
1320 ei[2] high guard word (always zero after normalization)
1322 to ei[NI-2] significand (NI-4 significand words,
1323 most significant word first,
1324 most significant bit is set)
1325 ei[NI-1] low guard word (0x8000 bit is rounding place)
1329 Routines for external format e-type numbers
1331 asctoe (string, e) ASCII string to extended double e type
1332 asctoe64 (string, &d) ASCII string to long double
1333 asctoe53 (string, &d) ASCII string to double
1334 asctoe24 (string, &f) ASCII string to single
1335 asctoeg (string, e, prec) ASCII string to specified precision
1336 e24toe (&f, e) IEEE single precision to e type
1337 e53toe (&d, e) IEEE double precision to e type
1338 e64toe (&d, e) IEEE long double precision to e type
1339 e113toe (&d, e) 128-bit long double precision to e type
1341 eabs (e) absolute value
1343 eadd (a, b, c) c = b + a
1345 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1346 -1 if a < b, -2 if either a or b is a NaN.
1347 ediv (a, b, c) c = b / a
1348 efloor (a, b) truncate to integer, toward -infinity
1349 efrexp (a, exp, s) extract exponent and significand
1350 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1351 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1352 einfin (e) set e to infinity, leaving its sign alone
1353 eldexp (a, n, b) multiply by 2**n
1355 emul (a, b, c) c = b * a
1358 eround (a, b) b = nearest integer value to a
1360 esub (a, b, c) c = b - a
1362 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1363 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1364 e64toasc (&d, str, n) 80-bit long double to ASCII string
1365 e113toasc (&d, str, n) 128-bit long double to ASCII string
1367 etoasc (e, str, n) e to ASCII string, n digits after decimal
1368 etoe24 (e, &f) convert e type to IEEE single precision
1369 etoe53 (e, &d) convert e type to IEEE double precision
1370 etoe64 (e, &d) convert e type to IEEE long double precision
1371 ltoe (&l, e) HOST_WIDE_INT to e type
1372 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1373 eisneg (e) 1 if sign bit of e != 0, else 0
1374 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1375 or is infinite (IEEE)
1376 eisnan (e) 1 if e is a NaN
1379 Routines for internal format exploded e-type numbers
1381 eaddm (ai, bi) add significands, bi = bi + ai
1383 ecleazs (ei) set ei = 0 but leave its sign alone
1384 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1385 edivm (ai, bi) divide significands, bi = bi / ai
1386 emdnorm (ai,l,s,exp) normalize and round off
1387 emovi (a, ai) convert external a to internal ai
1388 emovo (ai, a) convert internal ai to external a
1389 emovz (ai, bi) bi = ai, low guard word of bi = 0
1390 emulm (ai, bi) multiply significands, bi = bi * ai
1391 enormlz (ei) left-justify the significand
1392 eshdn1 (ai) shift significand and guards down 1 bit
1393 eshdn8 (ai) shift down 8 bits
1394 eshdn6 (ai) shift down 16 bits
1395 eshift (ai, n) shift ai n bits up (or down if n < 0)
1396 eshup1 (ai) shift significand and guards up 1 bit
1397 eshup8 (ai) shift up 8 bits
1398 eshup6 (ai) shift up 16 bits
1399 esubm (ai, bi) subtract significands, bi = bi - ai
1400 eiisinf (ai) 1 if infinite
1401 eiisnan (ai) 1 if a NaN
1402 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1403 einan (ai) set ai = NaN
1405 eiinfin (ai) set ai = infinity
1408 The result is always normalized and rounded to NI-4 word precision
1409 after each arithmetic operation.
1411 Exception flags are NOT fully supported.
1413 Signaling NaN's are NOT supported; they are treated the same
1416 Define INFINITY for support of infinity; otherwise a
1417 saturation arithmetic is implemented.
1419 Define NANS for support of Not-a-Number items; otherwise the
1420 arithmetic will never produce a NaN output, and might be confused
1422 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1423 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1424 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1427 Denormals are always supported here where appropriate (e.g., not
1428 for conversion to DEC numbers). */
1430 /* Definitions for error codes that are passed to the common error handling
1433 For Digital Equipment PDP-11 and VAX computers, certain
1434 IBM systems, and others that use numbers with a 56-bit
1435 significand, the symbol DEC should be defined. In this
1436 mode, most floating point constants are given as arrays
1437 of octal integers to eliminate decimal to binary conversion
1438 errors that might be introduced by the compiler.
1440 For computers, such as IBM PC, that follow the IEEE
1441 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1442 Std 754-1985), the symbol IEEE should be defined.
1443 These numbers have 53-bit significands. In this mode, constants
1444 are provided as arrays of hexadecimal 16 bit integers.
1445 The endian-ness of generated values is controlled by
1446 REAL_WORDS_BIG_ENDIAN.
1448 To accommodate other types of computer arithmetic, all
1449 constants are also provided in a normal decimal radix
1450 which one can hope are correctly converted to a suitable
1451 format by the available C language compiler. To invoke
1452 this mode, the symbol UNK is defined.
1454 An important difference among these modes is a predefined
1455 set of machine arithmetic constants for each. The numbers
1456 MACHEP (the machine roundoff error), MAXNUM (largest number
1457 represented), and several other parameters are preset by
1458 the configuration symbol. Check the file const.c to
1459 ensure that these values are correct for your computer.
1461 For ANSI C compatibility, define ANSIC equal to 1. Currently
1462 this affects only the atan2 function and others that use it. */
1464 /* Constant definitions for math error conditions. */
1466 #define DOMAIN 1 /* argument domain error */
1467 #define SING 2 /* argument singularity */
1468 #define OVERFLOW 3 /* overflow range error */
1469 #define UNDERFLOW 4 /* underflow range error */
1470 #define TLOSS 5 /* total loss of precision */
1471 #define PLOSS 6 /* partial loss of precision */
1472 #define INVALID 7 /* NaN-producing operation */
1474 /* e type constants used by high precision check routines */
1476 #if LONG_DOUBLE_TYPE_SIZE == 128
1478 unsigned EMUSHORT ezero
[NE
] =
1479 {0x0000, 0x0000, 0x0000, 0x0000,
1480 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1481 extern unsigned EMUSHORT ezero
[];
1484 unsigned EMUSHORT ehalf
[NE
] =
1485 {0x0000, 0x0000, 0x0000, 0x0000,
1486 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1487 extern unsigned EMUSHORT ehalf
[];
1490 unsigned EMUSHORT eone
[NE
] =
1491 {0x0000, 0x0000, 0x0000, 0x0000,
1492 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1493 extern unsigned EMUSHORT eone
[];
1496 unsigned EMUSHORT etwo
[NE
] =
1497 {0x0000, 0x0000, 0x0000, 0x0000,
1498 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1499 extern unsigned EMUSHORT etwo
[];
1502 unsigned EMUSHORT e32
[NE
] =
1503 {0x0000, 0x0000, 0x0000, 0x0000,
1504 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1505 extern unsigned EMUSHORT e32
[];
1507 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1508 unsigned EMUSHORT elog2
[NE
] =
1509 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1510 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1511 extern unsigned EMUSHORT elog2
[];
1513 /* 1.41421356237309504880168872420969807856967187537695E0 */
1514 unsigned EMUSHORT esqrt2
[NE
] =
1515 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1516 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1517 extern unsigned EMUSHORT esqrt2
[];
1519 /* 3.14159265358979323846264338327950288419716939937511E0 */
1520 unsigned EMUSHORT epi
[NE
] =
1521 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1522 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1523 extern unsigned EMUSHORT epi
[];
1526 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1527 unsigned EMUSHORT ezero
[NE
] =
1528 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1529 unsigned EMUSHORT ehalf
[NE
] =
1530 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1531 unsigned EMUSHORT eone
[NE
] =
1532 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1533 unsigned EMUSHORT etwo
[NE
] =
1534 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1535 unsigned EMUSHORT e32
[NE
] =
1536 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1537 unsigned EMUSHORT elog2
[NE
] =
1538 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1539 unsigned EMUSHORT esqrt2
[NE
] =
1540 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1541 unsigned EMUSHORT epi
[NE
] =
1542 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1545 /* Control register for rounding precision.
1546 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1551 /* Clear out entire e-type number X. */
1555 register unsigned EMUSHORT
*x
;
1559 for (i
= 0; i
< NE
; i
++)
1563 /* Move e-type number from A to B. */
1567 register unsigned EMUSHORT
*a
, *b
;
1571 for (i
= 0; i
< NE
; i
++)
1577 /* Absolute value of e-type X. */
1581 unsigned EMUSHORT x
[];
1583 /* sign is top bit of last word of external format */
1584 x
[NE
- 1] &= 0x7fff;
1588 /* Negate the e-type number X. */
1592 unsigned EMUSHORT x
[];
1595 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1598 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1602 unsigned EMUSHORT x
[];
1605 if (x
[NE
- 1] & 0x8000)
1611 /* Return 1 if e-type number X is infinity, else return zero. */
1615 unsigned EMUSHORT x
[];
1622 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1628 /* Check if e-type number is not a number. The bit pattern is one that we
1629 defined, so we know for sure how to detect it. */
1633 unsigned EMUSHORT x
[];
1638 /* NaN has maximum exponent */
1639 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1641 /* ... and non-zero significand field. */
1642 for (i
= 0; i
< NE
- 1; i
++)
1652 /* Fill e-type number X with infinity pattern (IEEE)
1653 or largest possible number (non-IEEE). */
1657 register unsigned EMUSHORT
*x
;
1662 for (i
= 0; i
< NE
- 1; i
++)
1666 for (i
= 0; i
< NE
- 1; i
++)
1694 /* Output an e-type NaN.
1695 This generates Intel's quiet NaN pattern for extended real.
1696 The exponent is 7fff, the leading mantissa word is c000. */
1700 register unsigned EMUSHORT
*x
;
1705 for (i
= 0; i
< NE
- 2; i
++)
1708 *x
= (sign
<< 15) | 0x7fff;
1711 /* Move in an e-type number A, converting it to exploded e-type B. */
1715 unsigned EMUSHORT
*a
, *b
;
1717 register unsigned EMUSHORT
*p
, *q
;
1721 p
= a
+ (NE
- 1); /* point to last word of external number */
1722 /* get the sign bit */
1727 /* get the exponent */
1729 *q
++ &= 0x7fff; /* delete the sign bit */
1731 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1737 for (i
= 3; i
< NI
; i
++)
1743 for (i
= 2; i
< NI
; i
++)
1749 /* clear high guard word */
1751 /* move in the significand */
1752 for (i
= 0; i
< NE
- 1; i
++)
1754 /* clear low guard word */
1758 /* Move out exploded e-type number A, converting it to e type B. */
1762 unsigned EMUSHORT
*a
, *b
;
1764 register unsigned EMUSHORT
*p
, *q
;
1765 unsigned EMUSHORT i
;
1769 q
= b
+ (NE
- 1); /* point to output exponent */
1770 /* combine sign and exponent */
1773 *q
-- = *p
++ | 0x8000;
1777 if (*(p
- 1) == 0x7fff)
1782 enan (b
, eiisneg (a
));
1790 /* skip over guard word */
1792 /* move the significand */
1793 for (j
= 0; j
< NE
- 1; j
++)
1797 /* Clear out exploded e-type number XI. */
1801 register unsigned EMUSHORT
*xi
;
1805 for (i
= 0; i
< NI
; i
++)
1809 /* Clear out exploded e-type XI, but don't touch the sign. */
1813 register unsigned EMUSHORT
*xi
;
1818 for (i
= 0; i
< NI
- 1; i
++)
1822 /* Move exploded e-type number from A to B. */
1826 register unsigned EMUSHORT
*a
, *b
;
1830 for (i
= 0; i
< NI
- 1; i
++)
1832 /* clear low guard word */
1836 /* Generate exploded e-type NaN.
1837 The explicit pattern for this is maximum exponent and
1838 top two significant bits set. */
1842 unsigned EMUSHORT x
[];
1850 /* Return nonzero if exploded e-type X is a NaN. */
1854 unsigned EMUSHORT x
[];
1858 if ((x
[E
] & 0x7fff) == 0x7fff)
1860 for (i
= M
+ 1; i
< NI
; i
++)
1869 /* Return nonzero if sign of exploded e-type X is nonzero. */
1873 unsigned EMUSHORT x
[];
1880 /* Fill exploded e-type X with infinity pattern.
1881 This has maximum exponent and significand all zeros. */
1885 unsigned EMUSHORT x
[];
1893 /* Return nonzero if exploded e-type X is infinite. */
1897 unsigned EMUSHORT x
[];
1904 if ((x
[E
] & 0x7fff) == 0x7fff)
1910 /* Compare significands of numbers in internal exploded e-type format.
1911 Guard words are included in the comparison.
1919 register unsigned EMUSHORT
*a
, *b
;
1923 a
+= M
; /* skip up to significand area */
1925 for (i
= M
; i
< NI
; i
++)
1933 if (*(--a
) > *(--b
))
1939 /* Shift significand of exploded e-type X down by 1 bit. */
1943 register unsigned EMUSHORT
*x
;
1945 register unsigned EMUSHORT bits
;
1948 x
+= M
; /* point to significand area */
1951 for (i
= M
; i
< NI
; i
++)
1963 /* Shift significand of exploded e-type X up by 1 bit. */
1967 register unsigned EMUSHORT
*x
;
1969 register unsigned EMUSHORT bits
;
1975 for (i
= M
; i
< NI
; i
++)
1988 /* Shift significand of exploded e-type X down by 8 bits. */
1992 register unsigned EMUSHORT
*x
;
1994 register unsigned EMUSHORT newbyt
, oldbyt
;
1999 for (i
= M
; i
< NI
; i
++)
2009 /* Shift significand of exploded e-type X up by 8 bits. */
2013 register unsigned EMUSHORT
*x
;
2016 register unsigned EMUSHORT newbyt
, oldbyt
;
2021 for (i
= M
; i
< NI
; i
++)
2031 /* Shift significand of exploded e-type X up by 16 bits. */
2035 register unsigned EMUSHORT
*x
;
2038 register unsigned EMUSHORT
*p
;
2043 for (i
= M
; i
< NI
- 1; i
++)
2049 /* Shift significand of exploded e-type X down by 16 bits. */
2053 register unsigned EMUSHORT
*x
;
2056 register unsigned EMUSHORT
*p
;
2061 for (i
= M
; i
< NI
- 1; i
++)
2067 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2071 unsigned EMUSHORT
*x
, *y
;
2073 register unsigned EMULONG a
;
2080 for (i
= M
; i
< NI
; i
++)
2082 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2087 *y
= (unsigned EMUSHORT
) a
;
2093 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2097 unsigned EMUSHORT
*x
, *y
;
2106 for (i
= M
; i
< NI
; i
++)
2108 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2113 *y
= (unsigned EMUSHORT
) a
;
2120 static unsigned EMUSHORT equot
[NI
];
2124 /* Radix 2 shift-and-add versions of multiply and divide */
2127 /* Divide significands */
2131 unsigned EMUSHORT den
[], num
[];
2134 register unsigned EMUSHORT
*p
, *q
;
2135 unsigned EMUSHORT j
;
2141 for (i
= M
; i
< NI
; i
++)
2146 /* Use faster compare and subtraction if denominator has only 15 bits of
2152 for (i
= M
+ 3; i
< NI
; i
++)
2157 if ((den
[M
+ 1] & 1) != 0)
2165 for (i
= 0; i
< NBITS
+ 2; i
++)
2183 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2184 bit + 1 roundoff bit. */
2189 for (i
= 0; i
< NBITS
+ 2; i
++)
2191 if (ecmpm (den
, num
) <= 0)
2194 j
= 1; /* quotient bit = 1 */
2208 /* test for nonzero remainder after roundoff bit */
2211 for (i
= M
; i
< NI
; i
++)
2219 for (i
= 0; i
< NI
; i
++)
2225 /* Multiply significands */
2229 unsigned EMUSHORT a
[], b
[];
2231 unsigned EMUSHORT
*p
, *q
;
2236 for (i
= M
; i
< NI
; i
++)
2241 while (*p
== 0) /* significand is not supposed to be zero */
2246 if ((*p
& 0xff) == 0)
2254 for (i
= 0; i
< k
; i
++)
2258 /* remember if there were any nonzero bits shifted out */
2265 for (i
= 0; i
< NI
; i
++)
2268 /* return flag for lost nonzero bits */
2274 /* Radix 65536 versions of multiply and divide. */
2276 /* Multiply significand of e-type number B
2277 by 16-bit quantity A, return e-type result to C. */
2282 unsigned EMUSHORT b
[], c
[];
2284 register unsigned EMUSHORT
*pp
;
2285 register unsigned EMULONG carry
;
2286 unsigned EMUSHORT
*ps
;
2287 unsigned EMUSHORT p
[NI
];
2288 unsigned EMULONG aa
, m
;
2297 for (i
=M
+1; i
<NI
; i
++)
2307 m
= (unsigned EMULONG
) aa
* *ps
--;
2308 carry
= (m
& 0xffff) + *pp
;
2309 *pp
-- = (unsigned EMUSHORT
)carry
;
2310 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2311 *pp
= (unsigned EMUSHORT
)carry
;
2312 *(pp
-1) = carry
>> 16;
2315 for (i
=M
; i
<NI
; i
++)
2319 /* Divide significands of exploded e-types NUM / DEN. Neither the
2320 numerator NUM nor the denominator DEN is permitted to have its high guard
2325 unsigned EMUSHORT den
[], num
[];
2328 register unsigned EMUSHORT
*p
;
2329 unsigned EMULONG tnum
;
2330 unsigned EMUSHORT j
, tdenm
, tquot
;
2331 unsigned EMUSHORT tprod
[NI
+1];
2337 for (i
=M
; i
<NI
; i
++)
2343 for (i
=M
; i
<NI
; i
++)
2345 /* Find trial quotient digit (the radix is 65536). */
2346 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2348 /* Do not execute the divide instruction if it will overflow. */
2349 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2352 tquot
= tnum
/ tdenm
;
2353 /* Multiply denominator by trial quotient digit. */
2354 m16m ((unsigned int)tquot
, den
, tprod
);
2355 /* The quotient digit may have been overestimated. */
2356 if (ecmpm (tprod
, num
) > 0)
2360 if (ecmpm (tprod
, num
) > 0)
2370 /* test for nonzero remainder after roundoff bit */
2373 for (i
=M
; i
<NI
; i
++)
2380 for (i
=0; i
<NI
; i
++)
2386 /* Multiply significands of exploded e-type A and B, result in B. */
2390 unsigned EMUSHORT a
[], b
[];
2392 unsigned EMUSHORT
*p
, *q
;
2393 unsigned EMUSHORT pprod
[NI
];
2394 unsigned EMUSHORT j
;
2399 for (i
=M
; i
<NI
; i
++)
2405 for (i
=M
+1; i
<NI
; i
++)
2413 m16m ((unsigned int) *p
--, b
, pprod
);
2414 eaddm(pprod
, equot
);
2420 for (i
=0; i
<NI
; i
++)
2423 /* return flag for lost nonzero bits */
2429 /* Normalize and round off.
2431 The internal format number to be rounded is S.
2432 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2434 Input SUBFLG indicates whether the number was obtained
2435 by a subtraction operation. In that case if LOST is nonzero
2436 then the number is slightly smaller than indicated.
2438 Input EXP is the biased exponent, which may be negative.
2439 the exponent field of S is ignored but is replaced by
2440 EXP as adjusted by normalization and rounding.
2442 Input RCNTRL is the rounding control. If it is nonzero, the
2443 returned value will be rounded to RNDPRC bits.
2445 For future reference: In order for emdnorm to round off denormal
2446 significands at the right point, the input exponent must be
2447 adjusted to be the actual value it would have after conversion to
2448 the final floating point type. This adjustment has been
2449 implemented for all type conversions (etoe53, etc.) and decimal
2450 conversions, but not for the arithmetic functions (eadd, etc.).
2451 Data types having standard 15-bit exponents are not affected by
2452 this, but SFmode and DFmode are affected. For example, ediv with
2453 rndprc = 24 will not round correctly to 24-bit precision if the
2454 result is denormal. */
2456 static int rlast
= -1;
2458 static unsigned EMUSHORT rmsk
= 0;
2459 static unsigned EMUSHORT rmbit
= 0;
2460 static unsigned EMUSHORT rebit
= 0;
2462 static unsigned EMUSHORT rbit
[NI
];
2465 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2466 unsigned EMUSHORT s
[];
2473 unsigned EMUSHORT r
;
2478 /* a blank significand could mean either zero or infinity. */
2491 if ((j
> NBITS
) && (exp
< 32767))
2499 if (exp
> (EMULONG
) (-NBITS
- 1))
2512 /* Round off, unless told not to by rcntrl. */
2515 /* Set up rounding parameters if the control register changed. */
2516 if (rndprc
!= rlast
)
2523 rw
= NI
- 1; /* low guard word */
2546 /* For DEC or IBM arithmetic */
2563 /* For C4x arithmetic */
2584 /* Shift down 1 temporarily if the data structure has an implied
2585 most significant bit and the number is denormal.
2586 Intel long double denormals also lose one bit of precision. */
2587 if ((exp
<= 0) && (rndprc
!= NBITS
)
2588 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2590 lost
|= s
[NI
- 1] & 1;
2593 /* Clear out all bits below the rounding bit,
2594 remembering in r if any were nonzero. */
2608 if ((r
& rmbit
) != 0)
2614 { /* round to even */
2615 if ((s
[re
] & rebit
) == 0)
2628 /* Undo the temporary shift for denormal values. */
2629 if ((exp
<= 0) && (rndprc
!= NBITS
)
2630 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2635 { /* overflow on roundoff */
2648 for (i
= 2; i
< NI
- 1; i
++)
2651 warning ("floating point overflow");
2655 for (i
= M
+ 1; i
< NI
- 1; i
++)
2658 if ((rndprc
< 64) || (rndprc
== 113))
2673 s
[1] = (unsigned EMUSHORT
) exp
;
2676 /* Subtract. C = B - A, all e type numbers. */
2678 static int subflg
= 0;
2682 unsigned EMUSHORT
*a
, *b
, *c
;
2696 /* Infinity minus infinity is a NaN.
2697 Test for subtracting infinities of the same sign. */
2698 if (eisinf (a
) && eisinf (b
)
2699 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2701 mtherr ("esub", INVALID
);
2710 /* Add. C = A + B, all e type. */
2714 unsigned EMUSHORT
*a
, *b
, *c
;
2718 /* NaN plus anything is a NaN. */
2729 /* Infinity minus infinity is a NaN.
2730 Test for adding infinities of opposite signs. */
2731 if (eisinf (a
) && eisinf (b
)
2732 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2734 mtherr ("esub", INVALID
);
2743 /* Arithmetic common to both addition and subtraction. */
2747 unsigned EMUSHORT
*a
, *b
, *c
;
2749 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2751 EMULONG lt
, lta
, ltb
;
2772 /* compare exponents */
2777 { /* put the larger number in bi */
2787 if (lt
< (EMULONG
) (-NBITS
- 1))
2788 goto done
; /* answer same as larger addend */
2790 lost
= eshift (ai
, k
); /* shift the smaller number down */
2794 /* exponents were the same, so must compare significands */
2797 { /* the numbers are identical in magnitude */
2798 /* if different signs, result is zero */
2804 /* if same sign, result is double */
2805 /* double denormalized tiny number */
2806 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2811 /* add 1 to exponent unless both are zero! */
2812 for (j
= 1; j
< NI
- 1; j
++)
2828 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2832 { /* put the larger number in bi */
2848 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2854 /* Divide: C = B/A, all e type. */
2858 unsigned EMUSHORT
*a
, *b
, *c
;
2860 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2862 EMULONG lt
, lta
, ltb
;
2864 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2865 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2866 sign
= eisneg(a
) ^ eisneg(b
);
2869 /* Return any NaN input. */
2880 /* Zero over zero, or infinity over infinity, is a NaN. */
2881 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2882 || (eisinf (a
) && eisinf (b
)))
2884 mtherr ("ediv", INVALID
);
2889 /* Infinity over anything else is infinity. */
2896 /* Anything else over infinity is zero. */
2908 { /* See if numerator is zero. */
2909 for (i
= 1; i
< NI
- 1; i
++)
2913 ltb
-= enormlz (bi
);
2923 { /* possible divide by zero */
2924 for (i
= 1; i
< NI
- 1; i
++)
2928 lta
-= enormlz (ai
);
2932 /* Divide by zero is not an invalid operation.
2933 It is a divide-by-zero operation! */
2935 mtherr ("ediv", SING
);
2941 /* calculate exponent */
2942 lt
= ltb
- lta
+ EXONE
;
2943 emdnorm (bi
, i
, 0, lt
, 64);
2950 && (ecmp (c
, ezero
) != 0)
2953 *(c
+(NE
-1)) |= 0x8000;
2955 *(c
+(NE
-1)) &= ~0x8000;
2958 /* Multiply e-types A and B, return e-type product C. */
2962 unsigned EMUSHORT
*a
, *b
, *c
;
2964 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2966 EMULONG lt
, lta
, ltb
;
2968 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2969 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2970 sign
= eisneg(a
) ^ eisneg(b
);
2973 /* NaN times anything is the same NaN. */
2984 /* Zero times infinity is a NaN. */
2985 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2986 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2988 mtherr ("emul", INVALID
);
2993 /* Infinity times anything else is infinity. */
2995 if (eisinf (a
) || eisinf (b
))
3007 for (i
= 1; i
< NI
- 1; i
++)
3011 lta
-= enormlz (ai
);
3022 for (i
= 1; i
< NI
- 1; i
++)
3026 ltb
-= enormlz (bi
);
3035 /* Multiply significands */
3037 /* calculate exponent */
3038 lt
= lta
+ ltb
- (EXONE
- 1);
3039 emdnorm (bi
, j
, 0, lt
, 64);
3046 && (ecmp (c
, ezero
) != 0)
3049 *(c
+(NE
-1)) |= 0x8000;
3051 *(c
+(NE
-1)) &= ~0x8000;
3054 /* Convert double precision PE to e-type Y. */
3058 unsigned EMUSHORT
*pe
, *y
;
3067 ibmtoe (pe
, y
, DFmode
);
3072 c4xtoe (pe
, y
, HFmode
);
3075 register unsigned EMUSHORT r
;
3076 register unsigned EMUSHORT
*e
, *p
;
3077 unsigned EMUSHORT yy
[NI
];
3081 denorm
= 0; /* flag if denormalized number */
3083 if (! REAL_WORDS_BIG_ENDIAN
)
3089 yy
[M
] = (r
& 0x0f) | 0x10;
3090 r
&= ~0x800f; /* strip sign and 4 significand bits */
3095 if (! REAL_WORDS_BIG_ENDIAN
)
3097 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3098 || (pe
[1] != 0) || (pe
[0] != 0))
3100 enan (y
, yy
[0] != 0);
3106 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3107 || (pe
[2] != 0) || (pe
[3] != 0))
3109 enan (y
, yy
[0] != 0);
3120 #endif /* INFINITY */
3122 /* If zero exponent, then the significand is denormalized.
3123 So take back the understood high significand bit. */
3134 if (! REAL_WORDS_BIG_ENDIAN
)
3151 /* If zero exponent, then normalize the significand. */
3152 if ((k
= enormlz (yy
)) > NBITS
)
3155 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3158 #endif /* not C4X */
3159 #endif /* not IBM */
3160 #endif /* not DEC */
3163 /* Convert double extended precision float PE to e type Y. */
3167 unsigned EMUSHORT
*pe
, *y
;
3169 unsigned EMUSHORT yy
[NI
];
3170 unsigned EMUSHORT
*e
, *p
, *q
;
3175 for (i
= 0; i
< NE
- 5; i
++)
3177 /* This precision is not ordinarily supported on DEC or IBM. */
3179 for (i
= 0; i
< 5; i
++)
3183 p
= &yy
[0] + (NE
- 1);
3186 for (i
= 0; i
< 5; i
++)
3190 if (! REAL_WORDS_BIG_ENDIAN
)
3192 for (i
= 0; i
< 5; i
++)
3195 /* For denormal long double Intel format, shift significand up one
3196 -- but only if the top significand bit is zero. A top bit of 1
3197 is "pseudodenormal" when the exponent is zero. */
3198 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3200 unsigned EMUSHORT temp
[NI
];
3210 p
= &yy
[0] + (NE
- 1);
3211 #ifdef ARM_EXTENDED_IEEE_FORMAT
3212 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3213 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3219 for (i
= 0; i
< 4; i
++)
3224 /* Point to the exponent field and check max exponent cases. */
3226 if ((*p
& 0x7fff) == 0x7fff)
3229 if (! REAL_WORDS_BIG_ENDIAN
)
3231 for (i
= 0; i
< 4; i
++)
3233 if ((i
!= 3 && pe
[i
] != 0)
3234 /* Anything but 0x8000 here, including 0, is a NaN. */
3235 || (i
== 3 && pe
[i
] != 0x8000))
3237 enan (y
, (*p
& 0x8000) != 0);
3244 #ifdef ARM_EXTENDED_IEEE_FORMAT
3245 for (i
= 2; i
<= 5; i
++)
3249 enan (y
, (*p
& 0x8000) != 0);
3254 /* In Motorola extended precision format, the most significant
3255 bit of an infinity mantissa could be either 1 or 0. It is
3256 the lower order bits that tell whether the value is a NaN. */
3257 if ((pe
[2] & 0x7fff) != 0)
3260 for (i
= 3; i
<= 5; i
++)
3265 enan (y
, (*p
& 0x8000) != 0);
3269 #endif /* not ARM */
3278 #endif /* INFINITY */
3281 for (i
= 0; i
< NE
; i
++)
3285 /* Convert 128-bit long double precision float PE to e type Y. */
3289 unsigned EMUSHORT
*pe
, *y
;
3291 register unsigned EMUSHORT r
;
3292 unsigned EMUSHORT
*e
, *p
;
3293 unsigned EMUSHORT yy
[NI
];
3300 if (! REAL_WORDS_BIG_ENDIAN
)
3312 if (! REAL_WORDS_BIG_ENDIAN
)
3314 for (i
= 0; i
< 7; i
++)
3318 enan (y
, yy
[0] != 0);
3325 for (i
= 1; i
< 8; i
++)
3329 enan (y
, yy
[0] != 0);
3341 #endif /* INFINITY */
3345 if (! REAL_WORDS_BIG_ENDIAN
)
3347 for (i
= 0; i
< 7; i
++)
3353 for (i
= 0; i
< 7; i
++)
3357 /* If denormal, remove the implied bit; else shift down 1. */
3370 /* Convert single precision float PE to e type Y. */
3374 unsigned EMUSHORT
*pe
, *y
;
3378 ibmtoe (pe
, y
, SFmode
);
3384 c4xtoe (pe
, y
, QFmode
);
3388 register unsigned EMUSHORT r
;
3389 register unsigned EMUSHORT
*e
, *p
;
3390 unsigned EMUSHORT yy
[NI
];
3394 denorm
= 0; /* flag if denormalized number */
3397 if (! REAL_WORDS_BIG_ENDIAN
)
3407 yy
[M
] = (r
& 0x7f) | 0200;
3408 r
&= ~0x807f; /* strip sign and 7 significand bits */
3413 if (REAL_WORDS_BIG_ENDIAN
)
3415 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3417 enan (y
, yy
[0] != 0);
3423 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3425 enan (y
, yy
[0] != 0);
3436 #endif /* INFINITY */
3438 /* If zero exponent, then the significand is denormalized.
3439 So take back the understood high significand bit. */
3452 if (! REAL_WORDS_BIG_ENDIAN
)
3462 { /* if zero exponent, then normalize the significand */
3463 if ((k
= enormlz (yy
)) > NBITS
)
3466 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3469 #endif /* not C4X */
3470 #endif /* not IBM */
3473 /* Convert e-type X to IEEE 128-bit long double format E. */
3477 unsigned EMUSHORT
*x
, *e
;
3479 unsigned EMUSHORT xi
[NI
];
3486 make_nan (e
, eisneg (x
), TFmode
);
3491 exp
= (EMULONG
) xi
[E
];
3496 /* round off to nearest or even */
3499 emdnorm (xi
, 0, 0, exp
, 64);
3505 /* Convert exploded e-type X, that has already been rounded to
3506 113-bit precision, to IEEE 128-bit long double format Y. */
3510 unsigned EMUSHORT
*a
, *b
;
3512 register unsigned EMUSHORT
*p
, *q
;
3513 unsigned EMUSHORT i
;
3518 make_nan (b
, eiisneg (a
), TFmode
);
3523 if (REAL_WORDS_BIG_ENDIAN
)
3526 q
= b
+ 7; /* point to output exponent */
3528 /* If not denormal, delete the implied bit. */
3533 /* combine sign and exponent */
3535 if (REAL_WORDS_BIG_ENDIAN
)
3538 *q
++ = *p
++ | 0x8000;
3545 *q
-- = *p
++ | 0x8000;
3549 /* skip over guard word */
3551 /* move the significand */
3552 if (REAL_WORDS_BIG_ENDIAN
)
3554 for (i
= 0; i
< 7; i
++)
3559 for (i
= 0; i
< 7; i
++)
3564 /* Convert e-type X to IEEE double extended format E. */
3568 unsigned EMUSHORT
*x
, *e
;
3570 unsigned EMUSHORT xi
[NI
];
3577 make_nan (e
, eisneg (x
), XFmode
);
3582 /* adjust exponent for offset */
3583 exp
= (EMULONG
) xi
[E
];
3588 /* round off to nearest or even */
3591 emdnorm (xi
, 0, 0, exp
, 64);
3597 /* Convert exploded e-type X, that has already been rounded to
3598 64-bit precision, to IEEE double extended format Y. */
3602 unsigned EMUSHORT
*a
, *b
;
3604 register unsigned EMUSHORT
*p
, *q
;
3605 unsigned EMUSHORT i
;
3610 make_nan (b
, eiisneg (a
), XFmode
);
3614 /* Shift denormal long double Intel format significand down one bit. */
3615 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3625 if (REAL_WORDS_BIG_ENDIAN
)
3629 q
= b
+ 4; /* point to output exponent */
3630 #if LONG_DOUBLE_TYPE_SIZE == 96
3631 /* Clear the last two bytes of 12-byte Intel format */
3637 /* combine sign and exponent */
3641 *q
++ = *p
++ | 0x8000;
3648 *q
-- = *p
++ | 0x8000;
3653 if (REAL_WORDS_BIG_ENDIAN
)
3655 #ifdef ARM_EXTENDED_IEEE_FORMAT
3656 /* The exponent is in the lowest 15 bits of the first word. */
3657 *q
++ = i
? 0x8000 : 0;
3661 *q
++ = *p
++ | 0x8000;
3670 *q
-- = *p
++ | 0x8000;
3675 /* skip over guard word */
3677 /* move the significand */
3679 for (i
= 0; i
< 4; i
++)
3683 for (i
= 0; i
< 4; i
++)
3687 if (REAL_WORDS_BIG_ENDIAN
)
3689 for (i
= 0; i
< 4; i
++)
3697 /* Intel long double infinity significand. */
3705 for (i
= 0; i
< 4; i
++)
3711 /* e type to double precision. */
3714 /* Convert e-type X to DEC-format double E. */
3718 unsigned EMUSHORT
*x
, *e
;
3720 etodec (x
, e
); /* see etodec.c */
3723 /* Convert exploded e-type X, that has already been rounded to
3724 56-bit double precision, to DEC double Y. */
3728 unsigned EMUSHORT
*x
, *y
;
3735 /* Convert e-type X to IBM 370-format double E. */
3739 unsigned EMUSHORT
*x
, *e
;
3741 etoibm (x
, e
, DFmode
);
3744 /* Convert exploded e-type X, that has already been rounded to
3745 56-bit precision, to IBM 370 double Y. */
3749 unsigned EMUSHORT
*x
, *y
;
3751 toibm (x
, y
, DFmode
);
3754 #else /* it's neither DEC nor IBM */
3756 /* Convert e-type X to C4X-format long double E. */
3760 unsigned EMUSHORT
*x
, *e
;
3762 etoc4x (x
, e
, HFmode
);
3765 /* Convert exploded e-type X, that has already been rounded to
3766 56-bit precision, to IBM 370 double Y. */
3770 unsigned EMUSHORT
*x
, *y
;
3772 toc4x (x
, y
, HFmode
);
3775 #else /* it's neither DEC nor IBM nor C4X */
3777 /* Convert e-type X to IEEE double E. */
3781 unsigned EMUSHORT
*x
, *e
;
3783 unsigned EMUSHORT xi
[NI
];
3790 make_nan (e
, eisneg (x
), DFmode
);
3795 /* adjust exponent for offsets */
3796 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3801 /* round off to nearest or even */
3804 emdnorm (xi
, 0, 0, exp
, 64);
3810 /* Convert exploded e-type X, that has already been rounded to
3811 53-bit precision, to IEEE double Y. */
3815 unsigned EMUSHORT
*x
, *y
;
3817 unsigned EMUSHORT i
;
3818 unsigned EMUSHORT
*p
;
3823 make_nan (y
, eiisneg (x
), DFmode
);
3829 if (! REAL_WORDS_BIG_ENDIAN
)
3832 *y
= 0; /* output high order */
3834 *y
= 0x8000; /* output sign bit */
3837 if (i
>= (unsigned int) 2047)
3839 /* Saturate at largest number less than infinity. */
3842 if (! REAL_WORDS_BIG_ENDIAN
)
3856 *y
|= (unsigned EMUSHORT
) 0x7fef;
3857 if (! REAL_WORDS_BIG_ENDIAN
)
3882 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3883 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3884 if (! REAL_WORDS_BIG_ENDIAN
)
3899 #endif /* not C4X */
3900 #endif /* not IBM */
3901 #endif /* not DEC */
3905 /* e type to single precision. */
3908 /* Convert e-type X to IBM 370 float E. */
3912 unsigned EMUSHORT
*x
, *e
;
3914 etoibm (x
, e
, SFmode
);
3917 /* Convert exploded e-type X, that has already been rounded to
3918 float precision, to IBM 370 float Y. */
3922 unsigned EMUSHORT
*x
, *y
;
3924 toibm (x
, y
, SFmode
);
3930 /* Convert e-type X to C4X float E. */
3934 unsigned EMUSHORT
*x
, *e
;
3936 etoc4x (x
, e
, QFmode
);
3939 /* Convert exploded e-type X, that has already been rounded to
3940 float precision, to IBM 370 float Y. */
3944 unsigned EMUSHORT
*x
, *y
;
3946 toc4x (x
, y
, QFmode
);
3951 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3955 unsigned EMUSHORT
*x
, *e
;
3958 unsigned EMUSHORT xi
[NI
];
3964 make_nan (e
, eisneg (x
), SFmode
);
3969 /* adjust exponent for offsets */
3970 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3975 /* round off to nearest or even */
3978 emdnorm (xi
, 0, 0, exp
, 64);
3984 /* Convert exploded e-type X, that has already been rounded to
3985 float precision, to IEEE float Y. */
3989 unsigned EMUSHORT
*x
, *y
;
3991 unsigned EMUSHORT i
;
3992 unsigned EMUSHORT
*p
;
3997 make_nan (y
, eiisneg (x
), SFmode
);
4003 if (! REAL_WORDS_BIG_ENDIAN
)
4009 *y
= 0; /* output high order */
4011 *y
= 0x8000; /* output sign bit */
4014 /* Handle overflow cases. */
4018 *y
|= (unsigned EMUSHORT
) 0x7f80;
4023 if (! REAL_WORDS_BIG_ENDIAN
)
4031 #else /* no INFINITY */
4032 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4037 if (! REAL_WORDS_BIG_ENDIAN
)
4048 #endif /* no INFINITY */
4060 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4061 /* High order output already has sign bit set. */
4067 if (! REAL_WORDS_BIG_ENDIAN
)
4076 #endif /* not C4X */
4077 #endif /* not IBM */
4079 /* Compare two e type numbers.
4083 -2 if either a or b is a NaN. */
4087 unsigned EMUSHORT
*a
, *b
;
4089 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4090 register unsigned EMUSHORT
*p
, *q
;
4095 if (eisnan (a
) || eisnan (b
))
4104 { /* the signs are different */
4106 for (i
= 1; i
< NI
- 1; i
++)
4120 /* both are the same sign */
4135 return (0); /* equality */
4139 if (*(--p
) > *(--q
))
4140 return (msign
); /* p is bigger */
4142 return (-msign
); /* p is littler */
4146 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4150 unsigned EMUSHORT
*x
, *y
;
4157 /* Convert HOST_WIDE_INT LP to e type Y. */
4162 unsigned EMUSHORT
*y
;
4164 unsigned EMUSHORT yi
[NI
];
4165 unsigned HOST_WIDE_INT ll
;
4171 /* make it positive */
4172 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4173 yi
[0] = 0xffff; /* put correct sign in the e type number */
4177 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4179 /* move the long integer to yi significand area */
4180 #if HOST_BITS_PER_WIDE_INT == 64
4181 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4182 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4183 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4184 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4185 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4187 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4188 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4189 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4192 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4193 ecleaz (yi
); /* it was zero */
4195 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4196 emovo (yi
, y
); /* output the answer */
4199 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4203 unsigned HOST_WIDE_INT
*lp
;
4204 unsigned EMUSHORT
*y
;
4206 unsigned EMUSHORT yi
[NI
];
4207 unsigned HOST_WIDE_INT ll
;
4213 /* move the long integer to ayi significand area */
4214 #if HOST_BITS_PER_WIDE_INT == 64
4215 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4216 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4217 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4218 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4219 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4221 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4222 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4223 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4226 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4227 ecleaz (yi
); /* it was zero */
4229 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4230 emovo (yi
, y
); /* output the answer */
4234 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4235 part FRAC of e-type (packed internal format) floating point input X.
4236 The integer output I has the sign of the input, except that
4237 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4238 The output e-type fraction FRAC is the positive fractional
4243 unsigned EMUSHORT
*x
;
4245 unsigned EMUSHORT
*frac
;
4247 unsigned EMUSHORT xi
[NI
];
4249 unsigned HOST_WIDE_INT ll
;
4252 k
= (int) xi
[E
] - (EXONE
- 1);
4255 /* if exponent <= 0, integer = 0 and real output is fraction */
4260 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4262 /* long integer overflow: output large integer
4263 and correct fraction */
4265 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4268 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4269 /* In this case, let it overflow and convert as if unsigned. */
4270 euifrac (x
, &ll
, frac
);
4271 *i
= (HOST_WIDE_INT
) ll
;
4274 /* In other cases, return the largest positive integer. */
4275 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4280 warning ("overflow on truncation to integer");
4284 /* Shift more than 16 bits: first shift up k-16 mod 16,
4285 then shift up by 16's. */
4286 j
= k
- ((k
>> 4) << 4);
4293 ll
= (ll
<< 16) | xi
[M
];
4295 while ((k
-= 16) > 0);
4302 /* shift not more than 16 bits */
4304 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4311 if ((k
= enormlz (xi
)) > NBITS
)
4314 xi
[E
] -= (unsigned EMUSHORT
) k
;
4320 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4321 FRAC of e-type X. A negative input yields integer output = 0 but
4322 correct fraction. */
4325 euifrac (x
, i
, frac
)
4326 unsigned EMUSHORT
*x
;
4327 unsigned HOST_WIDE_INT
*i
;
4328 unsigned EMUSHORT
*frac
;
4330 unsigned HOST_WIDE_INT ll
;
4331 unsigned EMUSHORT xi
[NI
];
4335 k
= (int) xi
[E
] - (EXONE
- 1);
4338 /* if exponent <= 0, integer = 0 and argument is fraction */
4343 if (k
> HOST_BITS_PER_WIDE_INT
)
4345 /* Long integer overflow: output large integer
4346 and correct fraction.
4347 Note, the BSD microvax compiler says that ~(0UL)
4348 is a syntax error. */
4352 warning ("overflow on truncation to unsigned integer");
4356 /* Shift more than 16 bits: first shift up k-16 mod 16,
4357 then shift up by 16's. */
4358 j
= k
- ((k
>> 4) << 4);
4365 ll
= (ll
<< 16) | xi
[M
];
4367 while ((k
-= 16) > 0);
4372 /* shift not more than 16 bits */
4374 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4377 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4383 if ((k
= enormlz (xi
)) > NBITS
)
4386 xi
[E
] -= (unsigned EMUSHORT
) k
;
4391 /* Shift the significand of exploded e-type X up or down by SC bits. */
4395 unsigned EMUSHORT
*x
;
4398 unsigned EMUSHORT lost
;
4399 unsigned EMUSHORT
*p
;
4412 lost
|= *p
; /* remember lost bits */
4453 return ((int) lost
);
4456 /* Shift normalize the significand area of exploded e-type X.
4457 Return the shift count (up = positive). */
4461 unsigned EMUSHORT x
[];
4463 register unsigned EMUSHORT
*p
;
4472 return (0); /* already normalized */
4478 /* With guard word, there are NBITS+16 bits available.
4479 Return true if all are zero. */
4483 /* see if high byte is zero */
4484 while ((*p
& 0xff00) == 0)
4489 /* now shift 1 bit at a time */
4490 while ((*p
& 0x8000) == 0)
4496 mtherr ("enormlz", UNDERFLOW
);
4502 /* Normalize by shifting down out of the high guard word
4503 of the significand */
4518 mtherr ("enormlz", OVERFLOW
);
4525 /* Powers of ten used in decimal <-> binary conversions. */
4530 #if LONG_DOUBLE_TYPE_SIZE == 128
4531 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4533 {0x6576, 0x4a92, 0x804a, 0x153f,
4534 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4535 {0x6a32, 0xce52, 0x329a, 0x28ce,
4536 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4537 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4538 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4539 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4540 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4541 {0x851e, 0xeab7, 0x98fe, 0x901b,
4542 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4543 {0x0235, 0x0137, 0x36b1, 0x336c,
4544 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4545 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4546 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4547 {0x0000, 0x0000, 0x0000, 0x0000,
4548 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4549 {0x0000, 0x0000, 0x0000, 0x0000,
4550 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4551 {0x0000, 0x0000, 0x0000, 0x0000,
4552 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4553 {0x0000, 0x0000, 0x0000, 0x0000,
4554 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4555 {0x0000, 0x0000, 0x0000, 0x0000,
4556 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4557 {0x0000, 0x0000, 0x0000, 0x0000,
4558 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4561 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4563 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4564 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4565 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4566 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4567 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4568 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4569 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4570 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4571 {0xa23e, 0x5308, 0xfefb, 0x1155,
4572 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4573 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4574 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4575 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4576 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4577 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4578 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4579 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4580 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4581 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4582 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4583 {0xc155, 0xa4a8, 0x404e, 0x6113,
4584 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4585 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4586 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4587 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4588 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4591 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4592 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4594 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4595 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4596 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4597 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4598 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4599 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4600 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4601 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4602 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4603 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4604 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4605 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4606 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4609 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4611 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4612 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4613 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4614 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4615 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4616 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4617 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4618 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4619 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4620 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4621 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4622 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4623 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4628 /* Convert float value X to ASCII string STRING with NDIG digits after
4629 the decimal point. */
4632 e24toasc (x
, string
, ndigs
)
4633 unsigned EMUSHORT x
[];
4637 unsigned EMUSHORT w
[NI
];
4640 etoasc (w
, string
, ndigs
);
4643 /* Convert double value X to ASCII string STRING with NDIG digits after
4644 the decimal point. */
4647 e53toasc (x
, string
, ndigs
)
4648 unsigned EMUSHORT x
[];
4652 unsigned EMUSHORT w
[NI
];
4655 etoasc (w
, string
, ndigs
);
4658 /* Convert double extended value X to ASCII string STRING with NDIG digits
4659 after the decimal point. */
4662 e64toasc (x
, string
, ndigs
)
4663 unsigned EMUSHORT x
[];
4667 unsigned EMUSHORT w
[NI
];
4670 etoasc (w
, string
, ndigs
);
4673 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4674 after the decimal point. */
4677 e113toasc (x
, string
, ndigs
)
4678 unsigned EMUSHORT x
[];
4682 unsigned EMUSHORT w
[NI
];
4685 etoasc (w
, string
, ndigs
);
4689 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4690 the decimal point. */
4692 static char wstring
[80]; /* working storage for ASCII output */
4695 etoasc (x
, string
, ndigs
)
4696 unsigned EMUSHORT x
[];
4701 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4702 unsigned EMUSHORT
*p
, *r
, *ten
;
4703 unsigned EMUSHORT sign
;
4704 int i
, j
, k
, expon
, rndsav
;
4706 unsigned EMUSHORT m
;
4717 sprintf (wstring
, " NaN ");
4721 rndprc
= NBITS
; /* set to full precision */
4722 emov (x
, y
); /* retain external format */
4723 if (y
[NE
- 1] & 0x8000)
4726 y
[NE
- 1] &= 0x7fff;
4733 ten
= &etens
[NTEN
][0];
4735 /* Test for zero exponent */
4738 for (k
= 0; k
< NE
- 1; k
++)
4741 goto tnzro
; /* denormalized number */
4743 goto isone
; /* valid all zeros */
4747 /* Test for infinity. */
4748 if (y
[NE
- 1] == 0x7fff)
4751 sprintf (wstring
, " -Infinity ");
4753 sprintf (wstring
, " Infinity ");
4757 /* Test for exponent nonzero but significand denormalized.
4758 * This is an error condition.
4760 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4762 mtherr ("etoasc", DOMAIN
);
4763 sprintf (wstring
, "NaN");
4767 /* Compare to 1.0 */
4776 { /* Number is greater than 1 */
4777 /* Convert significand to an integer and strip trailing decimal zeros. */
4779 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4781 p
= &etens
[NTEN
- 4][0];
4787 for (j
= 0; j
< NE
- 1; j
++)
4800 /* Rescale from integer significand */
4801 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4803 /* Find power of 10 */
4807 /* An unordered compare result shouldn't happen here. */
4808 while (ecmp (ten
, u
) <= 0)
4810 if (ecmp (p
, u
) <= 0)
4823 { /* Number is less than 1.0 */
4824 /* Pad significand with trailing decimal zeros. */
4827 while ((y
[NE
- 2] & 0x8000) == 0)
4836 for (i
= 0; i
< NDEC
+ 1; i
++)
4838 if ((w
[NI
- 1] & 0x7) != 0)
4840 /* multiply by 10 */
4853 if (eone
[NE
- 1] <= u
[1])
4865 while (ecmp (eone
, w
) > 0)
4867 if (ecmp (p
, w
) >= 0)
4882 /* Find the first (leading) digit. */
4888 digit
= equot
[NI
- 1];
4889 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4897 digit
= equot
[NI
- 1];
4905 /* Examine number of digits requested by caller. */
4923 *s
++ = (char)digit
+ '0';
4926 /* Generate digits after the decimal point. */
4927 for (k
= 0; k
<= ndigs
; k
++)
4929 /* multiply current number by 10, without normalizing */
4936 *s
++ = (char) equot
[NI
- 1] + '0';
4938 digit
= equot
[NI
- 1];
4941 /* round off the ASCII string */
4944 /* Test for critical rounding case in ASCII output. */
4948 if (ecmp (t
, ezero
) != 0)
4949 goto roun
; /* round to nearest */
4951 if ((*(s
- 1) & 1) == 0)
4952 goto doexp
; /* round to even */
4955 /* Round up and propagate carry-outs */
4959 /* Carry out to most significant digit? */
4966 /* Most significant digit carries to 10? */
4974 /* Round up and carry out from less significant digits */
4986 sprintf (ss, "e+%d", expon);
4988 sprintf (ss, "e%d", expon);
4990 sprintf (ss
, "e%d", expon
);
4993 /* copy out the working string */
4996 while (*ss
== ' ') /* strip possible leading space */
4998 while ((*s
++ = *ss
++) != '\0')
5003 /* Convert ASCII string to floating point.
5005 Numeric input is a free format decimal number of any length, with
5006 or without decimal point. Entering E after the number followed by an
5007 integer number causes the second number to be interpreted as a power of
5008 10 to be multiplied by the first number (i.e., "scientific" notation). */
5010 /* Convert ASCII string S to single precision float value Y. */
5015 unsigned EMUSHORT
*y
;
5021 /* Convert ASCII string S to double precision value Y. */
5026 unsigned EMUSHORT
*y
;
5028 #if defined(DEC) || defined(IBM)
5040 /* Convert ASCII string S to double extended value Y. */
5045 unsigned EMUSHORT
*y
;
5050 /* Convert ASCII string S to 128-bit long double Y. */
5055 unsigned EMUSHORT
*y
;
5057 asctoeg (s
, y
, 113);
5060 /* Convert ASCII string S to e type Y. */
5065 unsigned EMUSHORT
*y
;
5067 asctoeg (s
, y
, NBITS
);
5070 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5071 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5074 asctoeg (ss
, y
, oprec
)
5076 unsigned EMUSHORT
*y
;
5079 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5080 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5081 int k
, trail
, c
, rndsav
;
5083 unsigned EMUSHORT nsign
, *p
;
5084 char *sp
, *s
, *lstr
;
5087 /* Copy the input string. */
5088 lstr
= (char *) alloca (strlen (ss
) + 1);
5090 while (*ss
== ' ') /* skip leading spaces */
5094 while ((*sp
++ = *ss
++) != '\0')
5098 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5105 rndprc
= NBITS
; /* Set to full precision */
5117 if (*s
>= '0' && *s
<= '9')
5123 if ((k
>= 0) && (k
< base
))
5125 /* Ignore leading zeros */
5126 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5128 /* Identify and strip trailing zeros after the decimal point. */
5129 if ((trail
== 0) && (decflg
!= 0))
5132 while ((*sp
>= '0' && *sp
<= '9')
5133 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5134 || (*sp
>= 'A' && *sp
<= 'F'))))
5136 /* Check for syntax error */
5138 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5139 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5141 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5152 /* If enough digits were given to more than fill up the yy register,
5153 continuing until overflow into the high guard word yy[2]
5154 guarantees that there will be a roundoff bit at the top
5155 of the low guard word after normalization. */
5162 nexp
+= 4; /* count digits after decimal point */
5164 eshup1 (yy
); /* multiply current number by 16 */
5172 nexp
+= 1; /* count digits after decimal point */
5174 eshup1 (yy
); /* multiply current number by 10 */
5180 /* Insert the current digit. */
5182 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5187 /* Mark any lost non-zero digit. */
5189 /* Count lost digits before the decimal point. */
5211 case '.': /* decimal point */
5241 mtherr ("asctoe", DOMAIN
);
5250 /* Exponent interpretation */
5252 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5253 for (k
= 0; k
< NI
; k
++)
5264 /* check for + or - */
5272 while ((*s
>= '0') && (*s
<= '9'))
5281 if ((exp
> MAXDECEXP
) && (base
== 10))
5285 yy
[E
] = 0x7fff; /* infinity */
5288 if ((exp
< MINDECEXP
) && (base
== 10))
5298 /* Base 16 hexadecimal floating constant. */
5299 if ((k
= enormlz (yy
)) > NBITS
)
5304 /* Adjust the exponent. NEXP is the number of hex digits,
5305 EXP is a power of 2. */
5306 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5316 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5317 while ((nexp
> 0) && (yy
[2] == 0))
5329 if ((k
= enormlz (yy
)) > NBITS
)
5334 lexp
= (EXONE
- 1 + NBITS
) - k
;
5335 emdnorm (yy
, lost
, 0, lexp
, 64);
5338 /* Convert to external format:
5340 Multiply by 10**nexp. If precision is 64 bits,
5341 the maximum relative error incurred in forming 10**n
5342 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5343 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5344 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5359 /* Punt. Can't handle this without 2 divides. */
5360 emovi (etens
[0], tt
);
5367 p
= &etens
[NTEN
][0];
5377 while (exp
<= MAXP
);
5396 /* Round and convert directly to the destination type */
5398 lexp
-= EXONE
- 0x3ff;
5400 else if (oprec
== 24 || oprec
== 32)
5401 lexp
-= (EXONE
- 0x7f);
5404 else if (oprec
== 24 || oprec
== 56)
5405 lexp
-= EXONE
- (0x41 << 2);
5407 else if (oprec
== 24)
5408 lexp
-= EXONE
- 0177;
5412 else if (oprec
== 56)
5413 lexp
-= EXONE
- 0201;
5416 emdnorm (yy
, lost
, 0, lexp
, 64);
5426 todec (yy
, y
); /* see etodec.c */
5431 toibm (yy
, y
, DFmode
);
5436 toc4x (yy
, y
, HFmode
);
5460 /* Return Y = largest integer not greater than X (truncated toward minus
5463 static unsigned EMUSHORT bmask
[] =
5486 unsigned EMUSHORT x
[], y
[];
5488 register unsigned EMUSHORT
*p
;
5490 unsigned EMUSHORT f
[NE
];
5492 emov (x
, f
); /* leave in external format */
5493 expon
= (int) f
[NE
- 1];
5494 e
= (expon
& 0x7fff) - (EXONE
- 1);
5500 /* number of bits to clear out */
5512 /* clear the remaining bits */
5514 /* truncate negatives toward minus infinity */
5517 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5519 for (i
= 0; i
< NE
- 1; i
++)
5532 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5533 For example, 1.1 = 0.55 * 2^1. */
5537 unsigned EMUSHORT x
[];
5539 unsigned EMUSHORT s
[];
5541 unsigned EMUSHORT xi
[NI
];
5545 /* Handle denormalized numbers properly using long integer exponent. */
5546 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5554 *exp
= (int) (li
- 0x3ffe);
5558 /* Return e type Y = X * 2^PWR2. */
5562 unsigned EMUSHORT x
[];
5564 unsigned EMUSHORT y
[];
5566 unsigned EMUSHORT xi
[NI
];
5574 emdnorm (xi
, i
, i
, li
, 64);
5580 /* C = remainder after dividing B by A, all e type values.
5581 Least significant integer quotient bits left in EQUOT. */
5585 unsigned EMUSHORT a
[], b
[], c
[];
5587 unsigned EMUSHORT den
[NI
], num
[NI
];
5591 || (ecmp (a
, ezero
) == 0)
5599 if (ecmp (a
, ezero
) == 0)
5601 mtherr ("eremain", SING
);
5607 eiremain (den
, num
);
5608 /* Sign of remainder = sign of quotient */
5617 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5618 remainder in NUM. */
5622 unsigned EMUSHORT den
[], num
[];
5625 unsigned EMUSHORT j
;
5628 ld
-= enormlz (den
);
5630 ln
-= enormlz (num
);
5634 if (ecmpm (den
, num
) <= 0)
5646 emdnorm (num
, 0, 0, ln
, 0);
5649 /* Report an error condition CODE encountered in function NAME.
5651 Mnemonic Value Significance
5653 DOMAIN 1 argument domain error
5654 SING 2 function singularity
5655 OVERFLOW 3 overflow range error
5656 UNDERFLOW 4 underflow range error
5657 TLOSS 5 total loss of precision
5658 PLOSS 6 partial loss of precision
5659 INVALID 7 NaN - producing operation
5660 EDOM 33 Unix domain error code
5661 ERANGE 34 Unix range error code
5663 The order of appearance of the following messages is bound to the
5664 error codes defined above. */
5674 /* The string passed by the calling program is supposed to be the
5675 name of the function in which the error occurred.
5676 The code argument selects which error message string will be printed. */
5678 if (strcmp (name
, "esub") == 0)
5679 name
= "subtraction";
5680 else if (strcmp (name
, "ediv") == 0)
5682 else if (strcmp (name
, "emul") == 0)
5683 name
= "multiplication";
5684 else if (strcmp (name
, "enormlz") == 0)
5685 name
= "normalization";
5686 else if (strcmp (name
, "etoasc") == 0)
5687 name
= "conversion to text";
5688 else if (strcmp (name
, "asctoe") == 0)
5690 else if (strcmp (name
, "eremain") == 0)
5692 else if (strcmp (name
, "esqrt") == 0)
5693 name
= "square root";
5698 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5699 case SING
: warning ("%s: function singularity" , name
); break;
5700 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5701 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5702 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5703 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5704 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5709 /* Set global error message word */
5714 /* Convert DEC double precision D to e type E. */
5718 unsigned EMUSHORT
*d
;
5719 unsigned EMUSHORT
*e
;
5721 unsigned EMUSHORT y
[NI
];
5722 register unsigned EMUSHORT r
, *p
;
5724 ecleaz (y
); /* start with a zero */
5725 p
= y
; /* point to our number */
5726 r
= *d
; /* get DEC exponent word */
5727 if (*d
& (unsigned int) 0x8000)
5728 *p
= 0xffff; /* fill in our sign */
5729 ++p
; /* bump pointer to our exponent word */
5730 r
&= 0x7fff; /* strip the sign bit */
5731 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5735 r
>>= 7; /* shift exponent word down 7 bits */
5736 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5737 /* add our e type exponent offset */
5738 *p
++ = r
; /* to form our exponent */
5740 r
= *d
++; /* now do the high order mantissa */
5741 r
&= 0177; /* strip off the DEC exponent and sign bits */
5742 r
|= 0200; /* the DEC understood high order mantissa bit */
5743 *p
++ = r
; /* put result in our high guard word */
5745 *p
++ = *d
++; /* fill in the rest of our mantissa */
5749 eshdn8 (y
); /* shift our mantissa down 8 bits */
5754 /* Convert e type X to DEC double precision D. */
5758 unsigned EMUSHORT
*x
, *d
;
5760 unsigned EMUSHORT xi
[NI
];
5765 /* Adjust exponent for offsets. */
5766 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5767 /* Round off to nearest or even. */
5770 emdnorm (xi
, 0, 0, exp
, 64);
5775 /* Convert exploded e-type X, that has already been rounded to
5776 56-bit precision, to DEC format double Y. */
5780 unsigned EMUSHORT
*x
, *y
;
5782 unsigned EMUSHORT i
;
5783 unsigned EMUSHORT
*p
;
5822 /* Convert IBM single/double precision to e type. */
5826 unsigned EMUSHORT
*d
;
5827 unsigned EMUSHORT
*e
;
5828 enum machine_mode mode
;
5830 unsigned EMUSHORT y
[NI
];
5831 register unsigned EMUSHORT r
, *p
;
5834 ecleaz (y
); /* start with a zero */
5835 p
= y
; /* point to our number */
5836 r
= *d
; /* get IBM exponent word */
5837 if (*d
& (unsigned int) 0x8000)
5838 *p
= 0xffff; /* fill in our sign */
5839 ++p
; /* bump pointer to our exponent word */
5840 r
&= 0x7f00; /* strip the sign bit */
5841 r
>>= 6; /* shift exponent word down 6 bits */
5842 /* in fact shift by 8 right and 2 left */
5843 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5844 /* add our e type exponent offset */
5845 *p
++ = r
; /* to form our exponent */
5847 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5848 /* strip off the IBM exponent and sign bits */
5849 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5851 *p
++ = *d
++; /* fill in the rest of our mantissa */
5856 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5859 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5860 /* handle change in RADIX */
5866 /* Convert e type to IBM single/double precision. */
5870 unsigned EMUSHORT
*x
, *d
;
5871 enum machine_mode mode
;
5873 unsigned EMUSHORT xi
[NI
];
5878 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5879 /* round off to nearest or even */
5882 emdnorm (xi
, 0, 0, exp
, 64);
5884 toibm (xi
, d
, mode
);
5889 unsigned EMUSHORT
*x
, *y
;
5890 enum machine_mode mode
;
5892 unsigned EMUSHORT i
;
5893 unsigned EMUSHORT
*p
;
5943 /* Convert C4X single/double precision to e type. */
5947 unsigned EMUSHORT
*d
;
5948 unsigned EMUSHORT
*e
;
5949 enum machine_mode mode
;
5951 unsigned EMUSHORT y
[NI
];
5958 /* Short-circuit the zero case. */
5959 if ((d
[0] == 0x8000)
5961 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5972 ecleaz (y
); /* start with a zero */
5973 r
= d
[0]; /* get sign/exponent part */
5974 if (r
& (unsigned int) 0x0080)
5976 y
[0] = 0xffff; /* fill in our sign */
5984 r
>>= 8; /* Shift exponent word down 8 bits. */
5985 if (r
& 0x80) /* Make the exponent negative if it is. */
5987 r
= r
| (~0 & ~0xff);
5992 /* Now do the high order mantissa. We don't "or" on the high bit
5993 because it is 2 (not 1) and is handled a little differently
5998 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6000 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6010 /* Now do the two's complement on the data. */
6012 carry
= 1; /* Initially add 1 for the two's complement. */
6013 for (i
=size
+ M
; i
> M
; i
--)
6015 if (carry
&& (y
[i
] == 0x0000))
6017 /* We overflowed into the next word, carry is the same. */
6018 y
[i
] = carry
? 0x0000 : 0xffff;
6022 /* No overflow, just invert and add carry. */
6023 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6038 /* Add our e type exponent offset to form our exponent. */
6042 /* Now do the high order mantissa strip off the exponent and sign
6043 bits and add the high 1 bit. */
6044 y
[M
] = (d
[0] & 0x7f) | 0x80;
6047 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6049 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6059 /* Convert e type to C4X single/double precision. */
6063 unsigned EMUSHORT
*x
, *d
;
6064 enum machine_mode mode
;
6066 unsigned EMUSHORT xi
[NI
];
6072 /* Adjust exponent for offsets. */
6073 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6075 /* Round off to nearest or even. */
6077 rndprc
= mode
== QFmode
? 24 : 32;
6078 emdnorm (xi
, 0, 0, exp
, 64);
6080 toc4x (xi
, d
, mode
);
6085 unsigned EMUSHORT
*x
, *y
;
6086 enum machine_mode mode
;
6092 /* Short-circuit the zero case */
6093 if ((x
[0] == 0) /* Zero exponent and sign */
6095 && (x
[M
] == 0) /* The rest is for zero mantissa */
6097 /* Only check for double if necessary */
6098 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6100 /* We have a zero. Put it into the output and return. */
6113 /* Negative number require a two's complement conversion of the
6119 i
= ((int) x
[1]) - 0x7f;
6121 /* Now add 1 to the inverted data to do the two's complement. */
6131 x
[v
] = carry
? 0x0000 : 0xffff;
6135 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6141 /* The following is a special case. The C4X negative float requires
6142 a zero in the high bit (because the format is (2 - x) x 2^m), so
6143 if a one is in that bit, we have to shift left one to get rid
6144 of it. This only occurs if the number is -1 x 2^m. */
6145 if (x
[M
+1] & 0x8000)
6147 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6148 high sign bit and shift the exponent. */
6155 i
= ((int) x
[1]) - 0x7f;
6158 if ((i
< -128) || (i
> 127))
6173 y
[0] |= ((i
& 0xff) << 8);
6177 y
[0] |= x
[M
] & 0x7f;
6187 /* Output a binary NaN bit pattern in the target machine's format. */
6189 /* If special NaN bit patterns are required, define them in tm.h
6190 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6196 unsigned EMUSHORT TFbignan
[8] =
6197 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6198 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6206 unsigned EMUSHORT XFbignan
[6] =
6207 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6208 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6216 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6217 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6225 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6226 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6232 make_nan (nan
, sign
, mode
)
6233 unsigned EMUSHORT
*nan
;
6235 enum machine_mode mode
;
6238 unsigned EMUSHORT
*p
;
6242 /* Possibly the `reserved operand' patterns on a VAX can be
6243 used like NaN's, but probably not in the same way as IEEE. */
6244 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6247 if (REAL_WORDS_BIG_ENDIAN
)
6255 if (REAL_WORDS_BIG_ENDIAN
)
6263 if (REAL_WORDS_BIG_ENDIAN
)
6272 if (REAL_WORDS_BIG_ENDIAN
)
6282 if (REAL_WORDS_BIG_ENDIAN
)
6283 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6286 if (! REAL_WORDS_BIG_ENDIAN
)
6287 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6290 /* This is the inverse of the function `etarsingle' invoked by
6291 REAL_VALUE_TO_TARGET_SINGLE. */
6294 ereal_unto_float (f
)
6298 unsigned EMUSHORT s
[2];
6299 unsigned EMUSHORT e
[NE
];
6301 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6302 This is the inverse operation to what the function `endian' does. */
6303 if (REAL_WORDS_BIG_ENDIAN
)
6305 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6306 s
[1] = (unsigned EMUSHORT
) f
;
6310 s
[0] = (unsigned EMUSHORT
) f
;
6311 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6313 /* Convert and promote the target float to E-type. */
6315 /* Output E-type to REAL_VALUE_TYPE. */
6321 /* This is the inverse of the function `etardouble' invoked by
6322 REAL_VALUE_TO_TARGET_DOUBLE. */
6325 ereal_unto_double (d
)
6329 unsigned EMUSHORT s
[4];
6330 unsigned EMUSHORT e
[NE
];
6332 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6333 if (REAL_WORDS_BIG_ENDIAN
)
6335 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6336 s
[1] = (unsigned EMUSHORT
) d
[0];
6337 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6338 s
[3] = (unsigned EMUSHORT
) d
[1];
6342 /* Target float words are little-endian. */
6343 s
[0] = (unsigned EMUSHORT
) d
[0];
6344 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6345 s
[2] = (unsigned EMUSHORT
) d
[1];
6346 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6348 /* Convert target double to E-type. */
6350 /* Output E-type to REAL_VALUE_TYPE. */
6356 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6357 This is somewhat like ereal_unto_float, but the input types
6358 for these are different. */
6361 ereal_from_float (f
)
6365 unsigned EMUSHORT s
[2];
6366 unsigned EMUSHORT e
[NE
];
6368 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6369 This is the inverse operation to what the function `endian' does. */
6370 if (REAL_WORDS_BIG_ENDIAN
)
6372 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6373 s
[1] = (unsigned EMUSHORT
) f
;
6377 s
[0] = (unsigned EMUSHORT
) f
;
6378 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6380 /* Convert and promote the target float to E-type. */
6382 /* Output E-type to REAL_VALUE_TYPE. */
6388 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6389 This is somewhat like ereal_unto_double, but the input types
6390 for these are different.
6392 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6393 data format, with no holes in the bit packing. The first element
6394 of the input array holds the bits that would come first in the
6395 target computer's memory. */
6398 ereal_from_double (d
)
6402 unsigned EMUSHORT s
[4];
6403 unsigned EMUSHORT e
[NE
];
6405 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6406 if (REAL_WORDS_BIG_ENDIAN
)
6408 #if HOST_BITS_PER_WIDE_INT == 32
6409 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6410 s
[1] = (unsigned EMUSHORT
) d
[0];
6411 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6412 s
[3] = (unsigned EMUSHORT
) d
[1];
6414 /* In this case the entire target double is contained in the
6415 first array element. The second element of the input is
6417 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6418 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6419 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6420 s
[3] = (unsigned EMUSHORT
) d
[0];
6425 /* Target float words are little-endian. */
6426 s
[0] = (unsigned EMUSHORT
) d
[0];
6427 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6428 #if HOST_BITS_PER_WIDE_INT == 32
6429 s
[2] = (unsigned EMUSHORT
) d
[1];
6430 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6432 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6433 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6436 /* Convert target double to E-type. */
6438 /* Output E-type to REAL_VALUE_TYPE. */
6445 /* Convert target computer unsigned 64-bit integer to e-type.
6446 The endian-ness of DImode follows the convention for integers,
6447 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6451 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6452 unsigned EMUSHORT
*e
;
6454 unsigned EMUSHORT yi
[NI
];
6458 if (WORDS_BIG_ENDIAN
)
6460 for (k
= M
; k
< M
+ 4; k
++)
6465 for (k
= M
+ 3; k
>= M
; k
--)
6468 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6469 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6470 ecleaz (yi
); /* it was zero */
6472 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6476 /* Convert target computer signed 64-bit integer to e-type. */
6480 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6481 unsigned EMUSHORT
*e
;
6483 unsigned EMULONG acc
;
6484 unsigned EMUSHORT yi
[NI
];
6485 unsigned EMUSHORT carry
;
6489 if (WORDS_BIG_ENDIAN
)
6491 for (k
= M
; k
< M
+ 4; k
++)
6496 for (k
= M
+ 3; k
>= M
; k
--)
6499 /* Take absolute value */
6505 for (k
= M
+ 3; k
>= M
; k
--)
6507 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6514 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6515 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6516 ecleaz (yi
); /* it was zero */
6518 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6525 /* Convert e-type to unsigned 64-bit int. */
6529 unsigned EMUSHORT
*x
;
6530 unsigned EMUSHORT
*i
;
6532 unsigned EMUSHORT xi
[NI
];
6541 k
= (int) xi
[E
] - (EXONE
- 1);
6544 for (j
= 0; j
< 4; j
++)
6550 for (j
= 0; j
< 4; j
++)
6553 warning ("overflow on truncation to integer");
6558 /* Shift more than 16 bits: first shift up k-16 mod 16,
6559 then shift up by 16's. */
6560 j
= k
- ((k
>> 4) << 4);
6564 if (WORDS_BIG_ENDIAN
)
6575 if (WORDS_BIG_ENDIAN
)
6580 while ((k
-= 16) > 0);
6584 /* shift not more than 16 bits */
6589 if (WORDS_BIG_ENDIAN
)
6608 /* Convert e-type to signed 64-bit int. */
6612 unsigned EMUSHORT
*x
;
6613 unsigned EMUSHORT
*i
;
6615 unsigned EMULONG acc
;
6616 unsigned EMUSHORT xi
[NI
];
6617 unsigned EMUSHORT carry
;
6618 unsigned EMUSHORT
*isave
;
6622 k
= (int) xi
[E
] - (EXONE
- 1);
6625 for (j
= 0; j
< 4; j
++)
6631 for (j
= 0; j
< 4; j
++)
6634 warning ("overflow on truncation to integer");
6640 /* Shift more than 16 bits: first shift up k-16 mod 16,
6641 then shift up by 16's. */
6642 j
= k
- ((k
>> 4) << 4);
6646 if (WORDS_BIG_ENDIAN
)
6657 if (WORDS_BIG_ENDIAN
)
6662 while ((k
-= 16) > 0);
6666 /* shift not more than 16 bits */
6669 if (WORDS_BIG_ENDIAN
)
6685 /* Negate if negative */
6689 if (WORDS_BIG_ENDIAN
)
6691 for (k
= 0; k
< 4; k
++)
6693 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6694 if (WORDS_BIG_ENDIAN
)
6706 /* Longhand square root routine. */
6709 static int esqinited
= 0;
6710 static unsigned short sqrndbit
[NI
];
6714 unsigned EMUSHORT
*x
, *y
;
6716 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6718 int i
, j
, k
, n
, nlups
;
6723 sqrndbit
[NI
- 2] = 1;
6726 /* Check for arg <= 0 */
6727 i
= ecmp (x
, ezero
);
6732 mtherr ("esqrt", DOMAIN
);
6748 /* Bring in the arg and renormalize if it is denormal. */
6750 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6754 /* Divide exponent by 2 */
6756 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6758 /* Adjust if exponent odd */
6768 n
= 8; /* get 8 bits of result per inner loop */
6774 /* bring in next word of arg */
6776 num
[NI
- 1] = xx
[j
+ 3];
6777 /* Do additional bit on last outer loop, for roundoff. */
6780 for (i
= 0; i
< n
; i
++)
6782 /* Next 2 bits of arg */
6785 /* Shift up answer */
6787 /* Make trial divisor */
6788 for (k
= 0; k
< NI
; k
++)
6791 eaddm (sqrndbit
, temp
);
6792 /* Subtract and insert answer bit if it goes in */
6793 if (ecmpm (temp
, num
) <= 0)
6803 /* Adjust for extra, roundoff loop done. */
6804 exp
+= (NBITS
- 1) - rndprc
;
6806 /* Sticky bit = 1 if the remainder is nonzero. */
6808 for (i
= 3; i
< NI
; i
++)
6811 /* Renormalize and round off. */
6812 emdnorm (sq
, k
, 0, exp
, 64);
6816 #endif /* EMU_NON_COMPILE not defined */
6818 /* Return the binary precision of the significand for a given
6819 floating point mode. The mode can hold an integer value
6820 that many bits wide, without losing any bits. */
6823 significand_size (mode
)
6824 enum machine_mode mode
;
6827 /* Don't test the modes, but their sizes, lest this
6828 code won't work for BITS_PER_UNIT != 8 . */
6830 switch (GET_MODE_BITSIZE (mode
))
6834 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6841 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6844 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6847 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6850 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT