1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 1994 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
31 /* To enable support of XFmode extended real floating point, define
32 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
34 To support cross compilation between IEEE, VAX and IBM floating
35 point formats, define REAL_ARITHMETIC in the tm.h file.
37 In either case the machine files (tm.h) must not contain any code
38 that tries to use host floating point arithmetic to convert
39 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
40 etc. In cross-compile situations a REAL_VALUE_TYPE may not
41 be intelligible to the host computer's native arithmetic.
43 The emulator defaults to the host's floating point format so that
44 its decimal conversion functions can be used if desired (see
47 The first part of this file interfaces gcc to ieee.c, which is a
48 floating point arithmetic suite that was not written with gcc in
49 mind. The interface is followed by ieee.c itself and related
50 items. Avoid changing ieee.c unless you have suitable test
51 programs available. A special version of the PARANOIA floating
52 point arithmetic tester, modified for this purpose, can be found
53 on usc.edu : /pub/C-numanal/ieeetest.zoo. Some tutorial
54 information on ieee.c is given in my book: S. L. Moshier,
55 _Methods and Programs for Mathematical Functions_, Prentice-Hall
56 or Simon & Schuster Int'l, 1989. A library of XFmode elementary
57 transcendental functions can be obtained by ftp from
58 research.att.com: netlib/cephes/ldouble.shar.Z */
60 /* Type of computer arithmetic.
61 Only one of DEC, IBM, MIEEE, IBMPC, or UNK should get defined.
63 `MIEEE' refers generically to big-endian IEEE floating-point data
64 structure. This definition should work in SFmode `float' type and
65 DFmode `double' type on virtually all big-endian IEEE machines.
66 If LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then MIEEE
67 also invokes the particular XFmode (`long double' type) data
68 structure used by the Motorola 680x0 series processors.
70 `IBMPC' refers generally to little-endian IEEE machines. In this
71 case, if LONG_DOUBLE_TYPE_SIZE has been defined to be 96, then
72 IBMPC also invokes the particular XFmode `long double' data
73 structure used by the Intel 80x86 series processors.
75 `DEC' refers specifically to the Digital Equipment Corp PDP-11
76 and VAX floating point data structure. This model currently
77 supports no type wider than DFmode.
79 `IBM' refers specifically to the IBM System/370 and compatible
80 floating point data structure. This model currently supports
81 no type wider than DFmode. The IBM conversions were contributed by
82 frank@atom.ansto.gov.au (Frank Crawford).
84 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
85 then `long double' and `double' are both implemented, but they
86 both mean DFmode. In this case, the software floating-point
87 support available here is activated by writing
88 #define REAL_ARITHMETIC
91 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
92 and may deactivate XFmode since `long double' is used to refer
95 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
96 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
97 separate the floating point unit's endian-ness from that of
98 the integer addressing. This permits one to define a big-endian
99 FPU on a little-endian machine (e.g., ARM). An extension to
100 BYTES_BIG_ENDIAN may be required for some machines in the future.
101 These optional macros may be defined in tm.h. In real.h, they
102 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
103 them for any normal host or target machine on which the floats
104 and the integers have the same endian-ness. */
107 /* The following converts gcc macros into the ones used by this file. */
109 /* REAL_ARITHMETIC defined means that macros in real.h are
110 defined to call emulator functions. */
111 #ifdef REAL_ARITHMETIC
113 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
114 /* PDP-11, Pro350, VAX: */
116 #else /* it's not VAX */
117 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
118 /* IBM System/370 style */
120 #else /* it's also not an IBM */
121 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
122 #if FLOAT_WORDS_BIG_ENDIAN
123 /* Motorola IEEE, high order words come first (Sun workstation): */
125 #else /* not big-endian */
126 /* Intel IEEE, low order words come first:
129 #endif /* big-endian */
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 /* REAL_ARITHMETIC not defined means that the *host's* data
140 structure will be used. It may differ by endian-ness from the
141 target machine's structure and will get its ends swapped
142 accordingly (but not here). Probably only the decimal <-> binary
143 functions in this file will actually be used in this case. */
145 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
147 #else /* it's not VAX */
148 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
149 /* IBM System/370 style */
151 #else /* it's also not an IBM */
152 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
153 #if HOST_FLOAT_WORDS_BIG_ENDIAN
155 #else /* not big-endian */
157 #endif /* big-endian */
158 #else /* it's not IEEE either */
159 unknown arithmetic type
161 #endif /* not IEEE */
165 #endif /* REAL_ARITHMETIC not defined */
167 /* Define INFINITY for support of infinity.
168 Define NANS for support of Not-a-Number's (NaN's). */
169 #if !defined(DEC) && !defined(IBM)
174 /* Support of NaNs requires support of infinity. */
181 /* Find a host integer type that is at least 16 bits wide,
182 and another type at least twice whatever that size is. */
184 #if HOST_BITS_PER_CHAR >= 16
185 #define EMUSHORT char
186 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
187 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
189 #if HOST_BITS_PER_SHORT >= 16
190 #define EMUSHORT short
191 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
192 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
194 #if HOST_BITS_PER_INT >= 16
196 #define EMUSHORT_SIZE HOST_BITS_PER_INT
197 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
199 #if HOST_BITS_PER_LONG >= 16
200 #define EMUSHORT long
201 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
202 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
204 /* You will have to modify this program to have a smaller unit size. */
205 #define EMU_NON_COMPILE
211 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
212 #define EMULONG short
214 #if HOST_BITS_PER_INT >= EMULONG_SIZE
217 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
220 #if HOST_BITS_PER_LONG_LONG >= EMULONG_SIZE
221 #define EMULONG long long int
223 /* You will have to modify this program to have a smaller unit size. */
224 #define EMU_NON_COMPILE
231 /* The host interface doesn't work if no 16-bit size exists. */
232 #if EMUSHORT_SIZE != 16
233 #define EMU_NON_COMPILE
236 /* OK to continue compilation. */
237 #ifndef EMU_NON_COMPILE
239 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
240 In GET_REAL and PUT_REAL, r and e are pointers.
241 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
242 in memory, with no holes. */
244 #if LONG_DOUBLE_TYPE_SIZE == 96
245 /* Number of 16 bit words in external e type format */
247 #define MAXDECEXP 4932
248 #define MINDECEXP -4956
249 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
250 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
251 #else /* no XFmode */
252 #if LONG_DOUBLE_TYPE_SIZE == 128
254 #define MAXDECEXP 4932
255 #define MINDECEXP -4977
256 #define GET_REAL(r,e) bcopy (r, e, 2*NE)
257 #define PUT_REAL(e,r) bcopy (e, r, 2*NE)
260 #define MAXDECEXP 4932
261 #define MINDECEXP -4956
262 #ifdef REAL_ARITHMETIC
263 /* Emulator uses target format internally
264 but host stores it in host endian-ness. */
266 #if HOST_FLOAT_WORDS_BIG_ENDIAN == FLOAT_WORDS_BIG_ENDIAN
267 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT*) (r), (e))
268 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
270 #else /* endian-ness differs */
271 /* emulator uses target endian-ness internally */
272 #define GET_REAL(r,e) \
273 do { unsigned EMUSHORT w[4]; \
274 w[3] = ((EMUSHORT *) r)[0]; \
275 w[2] = ((EMUSHORT *) r)[1]; \
276 w[1] = ((EMUSHORT *) r)[2]; \
277 w[0] = ((EMUSHORT *) r)[3]; \
278 e53toe (w, (e)); } while (0)
280 #define PUT_REAL(e,r) \
281 do { unsigned EMUSHORT w[4]; \
283 *((EMUSHORT *) r) = w[3]; \
284 *((EMUSHORT *) r + 1) = w[2]; \
285 *((EMUSHORT *) r + 2) = w[1]; \
286 *((EMUSHORT *) r + 3) = w[0]; } while (0)
288 #endif /* endian-ness differs */
290 #else /* not REAL_ARITHMETIC */
292 /* emulator uses host format */
293 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
294 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
296 #endif /* not REAL_ARITHMETIC */
297 #endif /* not TFmode */
298 #endif /* no XFmode */
301 /* Number of 16 bit words in internal format */
304 /* Array offset to exponent */
307 /* Array offset to high guard word */
310 /* Number of bits of precision */
311 #define NBITS ((NI-4)*16)
313 /* Maximum number of decimal digits in ASCII conversion
316 #define NDEC (NBITS*8/27)
318 /* The exponent of 1.0 */
319 #define EXONE (0x3fff)
321 extern int extra_warnings
;
322 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
323 extern unsigned EMUSHORT elog2
[], esqrt2
[];
325 static void endian
PROTO((unsigned EMUSHORT
*, long *,
327 static void eclear
PROTO((unsigned EMUSHORT
*));
328 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
329 static void eabs
PROTO((unsigned EMUSHORT
*));
330 static void eneg
PROTO((unsigned EMUSHORT
*));
331 static int eisneg
PROTO((unsigned EMUSHORT
*));
332 static int eisinf
PROTO((unsigned EMUSHORT
*));
333 static int eisnan
PROTO((unsigned EMUSHORT
*));
334 static void einfin
PROTO((unsigned EMUSHORT
*));
335 static void enan
PROTO((unsigned EMUSHORT
*, int));
336 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
337 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
338 static void ecleaz
PROTO((unsigned EMUSHORT
*));
339 static void ecleazs
PROTO((unsigned EMUSHORT
*));
340 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
341 static void einan
PROTO((unsigned EMUSHORT
*));
342 static int eiisnan
PROTO((unsigned EMUSHORT
*));
343 static int eiisneg
PROTO((unsigned EMUSHORT
*));
344 static void eiinfin
PROTO((unsigned EMUSHORT
*));
345 static int eiisinf
PROTO((unsigned EMUSHORT
*));
346 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
347 static void eshdn1
PROTO((unsigned EMUSHORT
*));
348 static void eshup1
PROTO((unsigned EMUSHORT
*));
349 static void eshdn8
PROTO((unsigned EMUSHORT
*));
350 static void eshup8
PROTO((unsigned EMUSHORT
*));
351 static void eshup6
PROTO((unsigned EMUSHORT
*));
352 static void eshdn6
PROTO((unsigned EMUSHORT
*));
353 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
354 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
355 static void m16m
PROTO((unsigned int, unsigned short *,
357 static int edivm
PROTO((unsigned short *, unsigned short *));
358 static int emulm
PROTO((unsigned short *, unsigned short *));
359 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
360 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
361 unsigned EMUSHORT
*));
362 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
363 unsigned EMUSHORT
*));
364 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
365 unsigned EMUSHORT
*));
366 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
367 unsigned EMUSHORT
*));
368 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
369 unsigned EMUSHORT
*));
370 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
371 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
372 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
373 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
378 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
380 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
381 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
384 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
385 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
386 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
387 unsigned EMUSHORT
*));
388 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
389 unsigned EMUSHORT
*));
390 static int eshift
PROTO((unsigned EMUSHORT
*, int));
391 static int enormlz
PROTO((unsigned EMUSHORT
*));
392 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
393 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
394 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
395 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
396 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
397 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
398 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
399 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
400 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
401 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
402 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
403 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
404 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
405 unsigned EMUSHORT
*));
406 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
407 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
408 unsigned EMUSHORT
*));
409 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
410 static void mtherr
PROTO((char *, int));
411 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
412 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
414 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
416 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
418 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
420 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
421 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
422 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
423 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
424 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
425 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
427 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
428 swapping ends if required, into output array of longs. The
429 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
433 unsigned EMUSHORT e
[];
435 enum machine_mode mode
;
439 #if FLOAT_WORDS_BIG_ENDIAN
444 /* Swap halfwords in the fourth long. */
445 th
= (unsigned long) e
[6] & 0xffff;
446 t
= (unsigned long) e
[7] & 0xffff;
452 /* Swap halfwords in the third long. */
453 th
= (unsigned long) e
[4] & 0xffff;
454 t
= (unsigned long) e
[5] & 0xffff;
457 /* fall into the double case */
461 /* swap halfwords in the second word */
462 th
= (unsigned long) e
[2] & 0xffff;
463 t
= (unsigned long) e
[3] & 0xffff;
466 /* fall into the float case */
470 /* swap halfwords in the first word */
471 th
= (unsigned long) e
[0] & 0xffff;
472 t
= (unsigned long) e
[1] & 0xffff;
483 /* Pack the output array without swapping. */
490 /* Pack the fourth long. */
491 th
= (unsigned long) e
[7] & 0xffff;
492 t
= (unsigned long) e
[6] & 0xffff;
498 /* Pack the third long.
499 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
501 th
= (unsigned long) e
[5] & 0xffff;
502 t
= (unsigned long) e
[4] & 0xffff;
505 /* fall into the double case */
509 /* pack the second long */
510 th
= (unsigned long) e
[3] & 0xffff;
511 t
= (unsigned long) e
[2] & 0xffff;
514 /* fall into the float case */
518 /* pack the first long */
519 th
= (unsigned long) e
[1] & 0xffff;
520 t
= (unsigned long) e
[0] & 0xffff;
533 /* This is the implementation of the REAL_ARITHMETIC macro. */
536 earith (value
, icode
, r1
, r2
)
537 REAL_VALUE_TYPE
*value
;
542 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
548 /* Return NaN input back to the caller. */
551 PUT_REAL (d1
, value
);
556 PUT_REAL (d2
, value
);
560 code
= (enum tree_code
) icode
;
568 esub (d2
, d1
, v
); /* d1 - d2 */
576 #ifndef REAL_INFINITY
577 if (ecmp (d2
, ezero
) == 0)
580 enan (v
, eisneg (d1
) ^ eisneg (d2
));
587 ediv (d2
, d1
, v
); /* d1/d2 */
590 case MIN_EXPR
: /* min (d1,d2) */
591 if (ecmp (d1
, d2
) < 0)
597 case MAX_EXPR
: /* max (d1,d2) */
598 if (ecmp (d1
, d2
) > 0)
611 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
612 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
618 unsigned EMUSHORT f
[NE
], g
[NE
];
634 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
635 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
641 unsigned EMUSHORT f
[NE
], g
[NE
];
643 unsigned HOST_WIDE_INT l
;
657 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
658 binary, rounding off as indicated by the machine_mode argument. Then it
659 promotes the rounded value to REAL_VALUE_TYPE. */
666 unsigned EMUSHORT tem
[NE
], e
[NE
];
695 /* Expansion of REAL_NEGATE. */
701 unsigned EMUSHORT e
[NE
];
711 /* Round real toward zero to HOST_WIDE_INT;
712 implements REAL_VALUE_FIX (x). */
718 unsigned EMUSHORT f
[NE
], g
[NE
];
725 warning ("conversion from NaN to int");
733 /* Round real toward zero to unsigned HOST_WIDE_INT
734 implements REAL_VALUE_UNSIGNED_FIX (x).
735 Negative input returns zero. */
737 unsigned HOST_WIDE_INT
741 unsigned EMUSHORT f
[NE
], g
[NE
];
742 unsigned HOST_WIDE_INT l
;
748 warning ("conversion from NaN to unsigned int");
757 /* REAL_VALUE_FROM_INT macro. */
760 ereal_from_int (d
, i
, j
)
764 unsigned EMUSHORT df
[NE
], dg
[NE
];
765 HOST_WIDE_INT low
, high
;
773 /* complement and add 1 */
780 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
781 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
783 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
791 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
794 ereal_from_uint (d
, i
, j
)
796 unsigned HOST_WIDE_INT i
, j
;
798 unsigned EMUSHORT df
[NE
], dg
[NE
];
799 unsigned HOST_WIDE_INT low
, high
;
803 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
812 /* REAL_VALUE_TO_INT macro. */
815 ereal_to_int (low
, high
, rr
)
816 HOST_WIDE_INT
*low
, *high
;
819 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
826 warning ("conversion from NaN to int");
832 /* convert positive value */
839 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
840 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
841 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
842 emul (df
, dh
, dg
); /* fractional part is the low word */
843 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
846 /* complement and add 1 */
856 /* REAL_VALUE_LDEXP macro. */
863 unsigned EMUSHORT e
[NE
], y
[NE
];
876 /* These routines are conditionally compiled because functions
877 of the same names may be defined in fold-const.c. */
879 #ifdef REAL_ARITHMETIC
881 /* Check for infinity in a REAL_VALUE_TYPE. */
887 unsigned EMUSHORT e
[NE
];
898 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
904 unsigned EMUSHORT e
[NE
];
915 /* Check for a negative REAL_VALUE_TYPE number.
916 This just checks the sign bit, so that -0 counts as negative. */
922 return ereal_isneg (x
);
925 /* Expansion of REAL_VALUE_TRUNCATE.
926 The result is in floating point, rounded to nearest or even. */
929 real_value_truncate (mode
, arg
)
930 enum machine_mode mode
;
933 unsigned EMUSHORT e
[NE
], t
[NE
];
968 /* If an unsupported type was requested, presume that
969 the machine files know something useful to do with
970 the unmodified value. */
979 #endif /* REAL_ARITHMETIC defined */
981 /* Used for debugging--print the value of R in human-readable format
990 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
991 fprintf (stderr
, "%s", dstr
);
995 /* Target values are arrays of host longs. A long is guaranteed
996 to be at least 32 bits wide. */
998 /* 128-bit long double */
1005 unsigned EMUSHORT e
[NE
];
1009 endian (e
, l
, TFmode
);
1012 /* 80-bit long double */
1019 unsigned EMUSHORT e
[NE
];
1023 endian (e
, l
, XFmode
);
1031 unsigned EMUSHORT e
[NE
];
1035 endian (e
, l
, DFmode
);
1042 unsigned EMUSHORT e
[NE
];
1047 endian (e
, &l
, SFmode
);
1052 ereal_to_decimal (x
, s
)
1056 unsigned EMUSHORT e
[NE
];
1064 REAL_VALUE_TYPE x
, y
;
1066 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1070 return (ecmp (ex
, ey
));
1077 unsigned EMUSHORT ex
[NE
];
1080 return (eisneg (ex
));
1083 /* End of REAL_ARITHMETIC interface */
1086 Extended precision IEEE binary floating point arithmetic routines
1088 Numbers are stored in C language as arrays of 16-bit unsigned
1089 short integers. The arguments of the routines are pointers to
1092 External e type data structure, simulates Intel 8087 chip
1093 temporary real format but possibly with a larger significand:
1095 NE-1 significand words (least significant word first,
1096 most significant bit is normally set)
1097 exponent (value = EXONE for 1.0,
1098 top bit is the sign)
1101 Internal data structure of a number (a "word" is 16 bits):
1103 ei[0] sign word (0 for positive, 0xffff for negative)
1104 ei[1] biased exponent (value = EXONE for the number 1.0)
1105 ei[2] high guard word (always zero after normalization)
1107 to ei[NI-2] significand (NI-4 significand words,
1108 most significant word first,
1109 most significant bit is set)
1110 ei[NI-1] low guard word (0x8000 bit is rounding place)
1114 Routines for external format numbers
1116 asctoe (string, e) ASCII string to extended double e type
1117 asctoe64 (string, &d) ASCII string to long double
1118 asctoe53 (string, &d) ASCII string to double
1119 asctoe24 (string, &f) ASCII string to single
1120 asctoeg (string, e, prec) ASCII string to specified precision
1121 e24toe (&f, e) IEEE single precision to e type
1122 e53toe (&d, e) IEEE double precision to e type
1123 e64toe (&d, e) IEEE long double precision to e type
1124 e113toe (&d, e) 128-bit long double precision to e type
1125 eabs (e) absolute value
1126 eadd (a, b, c) c = b + a
1128 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1129 -1 if a < b, -2 if either a or b is a NaN.
1130 ediv (a, b, c) c = b / a
1131 efloor (a, b) truncate to integer, toward -infinity
1132 efrexp (a, exp, s) extract exponent and significand
1133 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1134 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1135 einfin (e) set e to infinity, leaving its sign alone
1136 eldexp (a, n, b) multiply by 2**n
1138 emul (a, b, c) c = b * a
1140 eround (a, b) b = nearest integer value to a
1141 esub (a, b, c) c = b - a
1142 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1143 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1144 e64toasc (&d, str, n) 80-bit long double to ASCII string
1145 e113toasc (&d, str, n) 128-bit long double to ASCII string
1146 etoasc (e, str, n) e to ASCII string, n digits after decimal
1147 etoe24 (e, &f) convert e type to IEEE single precision
1148 etoe53 (e, &d) convert e type to IEEE double precision
1149 etoe64 (e, &d) convert e type to IEEE long double precision
1150 ltoe (&l, e) HOST_WIDE_INT to e type
1151 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1152 eisneg (e) 1 if sign bit of e != 0, else 0
1153 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1154 or is infinite (IEEE)
1155 eisnan (e) 1 if e is a NaN
1158 Routines for internal format numbers
1160 eaddm (ai, bi) add significands, bi = bi + ai
1162 ecleazs (ei) set ei = 0 but leave its sign alone
1163 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1164 edivm (ai, bi) divide significands, bi = bi / ai
1165 emdnorm (ai,l,s,exp) normalize and round off
1166 emovi (a, ai) convert external a to internal ai
1167 emovo (ai, a) convert internal ai to external a
1168 emovz (ai, bi) bi = ai, low guard word of bi = 0
1169 emulm (ai, bi) multiply significands, bi = bi * ai
1170 enormlz (ei) left-justify the significand
1171 eshdn1 (ai) shift significand and guards down 1 bit
1172 eshdn8 (ai) shift down 8 bits
1173 eshdn6 (ai) shift down 16 bits
1174 eshift (ai, n) shift ai n bits up (or down if n < 0)
1175 eshup1 (ai) shift significand and guards up 1 bit
1176 eshup8 (ai) shift up 8 bits
1177 eshup6 (ai) shift up 16 bits
1178 esubm (ai, bi) subtract significands, bi = bi - ai
1179 eiisinf (ai) 1 if infinite
1180 eiisnan (ai) 1 if a NaN
1181 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1182 einan (ai) set ai = NaN
1183 eiinfin (ai) set ai = infinity
1185 The result is always normalized and rounded to NI-4 word precision
1186 after each arithmetic operation.
1188 Exception flags are NOT fully supported.
1190 Signaling NaN's are NOT supported; they are treated the same
1193 Define INFINITY for support of infinity; otherwise a
1194 saturation arithmetic is implemented.
1196 Define NANS for support of Not-a-Number items; otherwise the
1197 arithmetic will never produce a NaN output, and might be confused
1199 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1200 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1201 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1204 Denormals are always supported here where appropriate (e.g., not
1205 for conversion to DEC numbers). */
1207 /* Definitions for error codes that are passed to the common error handling
1210 For Digital Equipment PDP-11 and VAX computers, certain
1211 IBM systems, and others that use numbers with a 56-bit
1212 significand, the symbol DEC should be defined. In this
1213 mode, most floating point constants are given as arrays
1214 of octal integers to eliminate decimal to binary conversion
1215 errors that might be introduced by the compiler.
1217 For computers, such as IBM PC, that follow the IEEE
1218 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1219 Std 754-1985), the symbol IBMPC or MIEEE should be defined.
1220 These numbers have 53-bit significands. In this mode, constants
1221 are provided as arrays of hexadecimal 16 bit integers.
1223 To accommodate other types of computer arithmetic, all
1224 constants are also provided in a normal decimal radix
1225 which one can hope are correctly converted to a suitable
1226 format by the available C language compiler. To invoke
1227 this mode, the symbol UNK is defined.
1229 An important difference among these modes is a predefined
1230 set of machine arithmetic constants for each. The numbers
1231 MACHEP (the machine roundoff error), MAXNUM (largest number
1232 represented), and several other parameters are preset by
1233 the configuration symbol. Check the file const.c to
1234 ensure that these values are correct for your computer.
1236 For ANSI C compatibility, define ANSIC equal to 1. Currently
1237 this affects only the atan2 function and others that use it. */
1239 /* Constant definitions for math error conditions. */
1241 #define DOMAIN 1 /* argument domain error */
1242 #define SING 2 /* argument singularity */
1243 #define OVERFLOW 3 /* overflow range error */
1244 #define UNDERFLOW 4 /* underflow range error */
1245 #define TLOSS 5 /* total loss of precision */
1246 #define PLOSS 6 /* partial loss of precision */
1247 #define INVALID 7 /* NaN-producing operation */
1249 /* e type constants used by high precision check routines */
1251 #if LONG_DOUBLE_TYPE_SIZE == 128
1253 unsigned EMUSHORT ezero
[NE
] =
1254 {0x0000, 0x0000, 0x0000, 0x0000,
1255 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1256 extern unsigned EMUSHORT ezero
[];
1259 unsigned EMUSHORT ehalf
[NE
] =
1260 {0x0000, 0x0000, 0x0000, 0x0000,
1261 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1262 extern unsigned EMUSHORT ehalf
[];
1265 unsigned EMUSHORT eone
[NE
] =
1266 {0x0000, 0x0000, 0x0000, 0x0000,
1267 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1268 extern unsigned EMUSHORT eone
[];
1271 unsigned EMUSHORT etwo
[NE
] =
1272 {0x0000, 0x0000, 0x0000, 0x0000,
1273 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1274 extern unsigned EMUSHORT etwo
[];
1277 unsigned EMUSHORT e32
[NE
] =
1278 {0x0000, 0x0000, 0x0000, 0x0000,
1279 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1280 extern unsigned EMUSHORT e32
[];
1282 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1283 unsigned EMUSHORT elog2
[NE
] =
1284 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1285 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1286 extern unsigned EMUSHORT elog2
[];
1288 /* 1.41421356237309504880168872420969807856967187537695E0 */
1289 unsigned EMUSHORT esqrt2
[NE
] =
1290 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1291 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1292 extern unsigned EMUSHORT esqrt2
[];
1294 /* 3.14159265358979323846264338327950288419716939937511E0 */
1295 unsigned EMUSHORT epi
[NE
] =
1296 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1297 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1298 extern unsigned EMUSHORT epi
[];
1301 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1302 unsigned EMUSHORT ezero
[NE
] =
1303 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1304 unsigned EMUSHORT ehalf
[NE
] =
1305 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1306 unsigned EMUSHORT eone
[NE
] =
1307 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1308 unsigned EMUSHORT etwo
[NE
] =
1309 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1310 unsigned EMUSHORT e32
[NE
] =
1311 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1312 unsigned EMUSHORT elog2
[NE
] =
1313 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1314 unsigned EMUSHORT esqrt2
[NE
] =
1315 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1316 unsigned EMUSHORT epi
[NE
] =
1317 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1322 /* Control register for rounding precision.
1323 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1328 /* Clear out entire external format number. */
1332 register unsigned EMUSHORT
*x
;
1336 for (i
= 0; i
< NE
; i
++)
1342 /* Move external format number from a to b. */
1346 register unsigned EMUSHORT
*a
, *b
;
1350 for (i
= 0; i
< NE
; i
++)
1355 /* Absolute value of external format number. */
1359 unsigned EMUSHORT x
[];
1361 /* sign is top bit of last word of external format */
1362 x
[NE
- 1] &= 0x7fff;
1365 /* Negate external format number. */
1369 unsigned EMUSHORT x
[];
1372 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1377 /* Return 1 if sign bit of external format number is nonzero, else zero. */
1381 unsigned EMUSHORT x
[];
1384 if (x
[NE
- 1] & 0x8000)
1391 /* Return 1 if external format number is infinity, else return zero. */
1395 unsigned EMUSHORT x
[];
1402 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1409 /* Check if e-type number is not a number. The bit pattern is one that we
1410 defined, so we know for sure how to detect it. */
1414 unsigned EMUSHORT x
[];
1419 /* NaN has maximum exponent */
1420 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1422 /* ... and non-zero significand field. */
1423 for (i
= 0; i
< NE
- 1; i
++)
1433 /* Fill external format number with infinity pattern (IEEE)
1434 or largest possible number (non-IEEE). */
1438 register unsigned EMUSHORT
*x
;
1443 for (i
= 0; i
< NE
- 1; i
++)
1447 for (i
= 0; i
< NE
- 1; i
++)
1476 /* Output an e-type NaN.
1477 This generates Intel's quiet NaN pattern for extended real.
1478 The exponent is 7fff, the leading mantissa word is c000. */
1482 register unsigned EMUSHORT
*x
;
1487 for (i
= 0; i
< NE
- 2; i
++)
1490 *x
= (sign
<< 15) | 0x7fff;
1494 /* Move in external format number, converting it to internal format. */
1498 unsigned EMUSHORT
*a
, *b
;
1500 register unsigned EMUSHORT
*p
, *q
;
1504 p
= a
+ (NE
- 1); /* point to last word of external number */
1505 /* get the sign bit */
1510 /* get the exponent */
1512 *q
++ &= 0x7fff; /* delete the sign bit */
1514 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1520 for (i
= 3; i
< NI
; i
++)
1526 for (i
= 2; i
< NI
; i
++)
1532 /* clear high guard word */
1534 /* move in the significand */
1535 for (i
= 0; i
< NE
- 1; i
++)
1537 /* clear low guard word */
1542 /* Move internal format number out, converting it to external format. */
1546 unsigned EMUSHORT
*a
, *b
;
1548 register unsigned EMUSHORT
*p
, *q
;
1549 unsigned EMUSHORT i
;
1553 q
= b
+ (NE
- 1); /* point to output exponent */
1554 /* combine sign and exponent */
1557 *q
-- = *p
++ | 0x8000;
1561 if (*(p
- 1) == 0x7fff)
1566 enan (b
, eiisneg (a
));
1574 /* skip over guard word */
1576 /* move the significand */
1577 for (j
= 0; j
< NE
- 1; j
++)
1581 /* Clear out internal format number. */
1585 register unsigned EMUSHORT
*xi
;
1589 for (i
= 0; i
< NI
; i
++)
1594 /* Same, but don't touch the sign. */
1598 register unsigned EMUSHORT
*xi
;
1603 for (i
= 0; i
< NI
- 1; i
++)
1609 /* Move internal format number from a to b. */
1613 register unsigned EMUSHORT
*a
, *b
;
1617 for (i
= 0; i
< NI
- 1; i
++)
1619 /* clear low guard word */
1623 /* Generate internal format NaN.
1624 The explicit pattern for this is maximum exponent and
1625 top two significant bits set. */
1629 unsigned EMUSHORT x
[];
1637 /* Return nonzero if internal format number is a NaN. */
1641 unsigned EMUSHORT x
[];
1645 if ((x
[E
] & 0x7fff) == 0x7fff)
1647 for (i
= M
+ 1; i
< NI
; i
++)
1656 /* Return nonzero if sign of internal format number is nonzero. */
1660 unsigned EMUSHORT x
[];
1666 /* Fill internal format number with infinity pattern.
1667 This has maximum exponent and significand all zeros. */
1671 unsigned EMUSHORT x
[];
1678 /* Return nonzero if internal format number is infinite. */
1682 unsigned EMUSHORT x
[];
1689 if ((x
[E
] & 0x7fff) == 0x7fff)
1695 /* Compare significands of numbers in internal format.
1696 Guard words are included in the comparison.
1704 register unsigned EMUSHORT
*a
, *b
;
1708 a
+= M
; /* skip up to significand area */
1710 for (i
= M
; i
< NI
; i
++)
1718 if (*(--a
) > *(--b
))
1725 /* Shift significand down by 1 bit. */
1729 register unsigned EMUSHORT
*x
;
1731 register unsigned EMUSHORT bits
;
1734 x
+= M
; /* point to significand area */
1737 for (i
= M
; i
< NI
; i
++)
1751 /* Shift significand up by 1 bit. */
1755 register unsigned EMUSHORT
*x
;
1757 register unsigned EMUSHORT bits
;
1763 for (i
= M
; i
< NI
; i
++)
1776 /* Shift significand down by 8 bits. */
1780 register unsigned EMUSHORT
*x
;
1782 register unsigned EMUSHORT newbyt
, oldbyt
;
1787 for (i
= M
; i
< NI
; i
++)
1797 /* Shift significand up by 8 bits. */
1801 register unsigned EMUSHORT
*x
;
1804 register unsigned EMUSHORT newbyt
, oldbyt
;
1809 for (i
= M
; i
< NI
; i
++)
1819 /* Shift significand up by 16 bits. */
1823 register unsigned EMUSHORT
*x
;
1826 register unsigned EMUSHORT
*p
;
1831 for (i
= M
; i
< NI
- 1; i
++)
1837 /* Shift significand down by 16 bits. */
1841 register unsigned EMUSHORT
*x
;
1844 register unsigned EMUSHORT
*p
;
1849 for (i
= M
; i
< NI
- 1; i
++)
1855 /* Add significands. x + y replaces y. */
1859 unsigned EMUSHORT
*x
, *y
;
1861 register unsigned EMULONG a
;
1868 for (i
= M
; i
< NI
; i
++)
1870 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
1875 *y
= (unsigned EMUSHORT
) a
;
1881 /* Subtract significands. y - x replaces y. */
1885 unsigned EMUSHORT
*x
, *y
;
1894 for (i
= M
; i
< NI
; i
++)
1896 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
1901 *y
= (unsigned EMUSHORT
) a
;
1908 static unsigned EMUSHORT equot
[NI
];
1912 /* Radix 2 shift-and-add versions of multiply and divide */
1915 /* Divide significands */
1919 unsigned EMUSHORT den
[], num
[];
1922 register unsigned EMUSHORT
*p
, *q
;
1923 unsigned EMUSHORT j
;
1929 for (i
= M
; i
< NI
; i
++)
1934 /* Use faster compare and subtraction if denominator has only 15 bits of
1940 for (i
= M
+ 3; i
< NI
; i
++)
1945 if ((den
[M
+ 1] & 1) != 0)
1953 for (i
= 0; i
< NBITS
+ 2; i
++)
1971 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
1972 bit + 1 roundoff bit. */
1977 for (i
= 0; i
< NBITS
+ 2; i
++)
1979 if (ecmpm (den
, num
) <= 0)
1982 j
= 1; /* quotient bit = 1 */
1996 /* test for nonzero remainder after roundoff bit */
1999 for (i
= M
; i
< NI
; i
++)
2007 for (i
= 0; i
< NI
; i
++)
2013 /* Multiply significands */
2016 unsigned EMUSHORT a
[], b
[];
2018 unsigned EMUSHORT
*p
, *q
;
2023 for (i
= M
; i
< NI
; i
++)
2028 while (*p
== 0) /* significand is not supposed to be zero */
2033 if ((*p
& 0xff) == 0)
2041 for (i
= 0; i
< k
; i
++)
2045 /* remember if there were any nonzero bits shifted out */
2052 for (i
= 0; i
< NI
; i
++)
2055 /* return flag for lost nonzero bits */
2061 /* Radix 65536 versions of multiply and divide */
2064 /* Multiply significand of e-type number b
2065 by 16-bit quantity a, e-type result to c. */
2070 unsigned short b
[], c
[];
2072 register unsigned short *pp
;
2073 register unsigned long carry
;
2075 unsigned short p
[NI
];
2076 unsigned long aa
, m
;
2085 for (i
=M
+1; i
<NI
; i
++)
2095 m
= (unsigned long) aa
* *ps
--;
2096 carry
= (m
& 0xffff) + *pp
;
2097 *pp
-- = (unsigned short)carry
;
2098 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2099 *pp
= (unsigned short)carry
;
2100 *(pp
-1) = carry
>> 16;
2103 for (i
=M
; i
<NI
; i
++)
2108 /* Divide significands. Neither the numerator nor the denominator
2109 is permitted to have its high guard word nonzero. */
2113 unsigned short den
[], num
[];
2116 register unsigned short *p
;
2118 unsigned short j
, tdenm
, tquot
;
2119 unsigned short tprod
[NI
+1];
2125 for (i
=M
; i
<NI
; i
++)
2131 for (i
=M
; i
<NI
; i
++)
2133 /* Find trial quotient digit (the radix is 65536). */
2134 tnum
= (((unsigned long) num
[M
]) << 16) + num
[M
+1];
2136 /* Do not execute the divide instruction if it will overflow. */
2137 if ((tdenm
* 0xffffL
) < tnum
)
2140 tquot
= tnum
/ tdenm
;
2141 /* Multiply denominator by trial quotient digit. */
2142 m16m ((unsigned int)tquot
, den
, tprod
);
2143 /* The quotient digit may have been overestimated. */
2144 if (ecmpm (tprod
, num
) > 0)
2148 if (ecmpm (tprod
, num
) > 0)
2158 /* test for nonzero remainder after roundoff bit */
2161 for (i
=M
; i
<NI
; i
++)
2168 for (i
=0; i
<NI
; i
++)
2176 /* Multiply significands */
2179 unsigned short a
[], b
[];
2181 unsigned short *p
, *q
;
2182 unsigned short pprod
[NI
];
2188 for (i
=M
; i
<NI
; i
++)
2194 for (i
=M
+1; i
<NI
; i
++)
2202 m16m ((unsigned int) *p
--, b
, pprod
);
2203 eaddm(pprod
, equot
);
2209 for (i
=0; i
<NI
; i
++)
2212 /* return flag for lost nonzero bits */
2218 /* Normalize and round off.
2220 The internal format number to be rounded is "s".
2221 Input "lost" indicates whether or not the number is exact.
2222 This is the so-called sticky bit.
2224 Input "subflg" indicates whether the number was obtained
2225 by a subtraction operation. In that case if lost is nonzero
2226 then the number is slightly smaller than indicated.
2228 Input "exp" is the biased exponent, which may be negative.
2229 the exponent field of "s" is ignored but is replaced by
2230 "exp" as adjusted by normalization and rounding.
2232 Input "rcntrl" is the rounding control.
2234 For future reference: In order for emdnorm to round off denormal
2235 significands at the right point, the input exponent must be
2236 adjusted to be the actual value it would have after conversion to
2237 the final floating point type. This adjustment has been
2238 implemented for all type conversions (etoe53, etc.) and decimal
2239 conversions, but not for the arithmetic functions (eadd, etc.).
2240 Data types having standard 15-bit exponents are not affected by
2241 this, but SFmode and DFmode are affected. For example, ediv with
2242 rndprc = 24 will not round correctly to 24-bit precision if the
2243 result is denormal. */
2245 static int rlast
= -1;
2247 static unsigned EMUSHORT rmsk
= 0;
2248 static unsigned EMUSHORT rmbit
= 0;
2249 static unsigned EMUSHORT rebit
= 0;
2251 static unsigned EMUSHORT rbit
[NI
];
2254 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2255 unsigned EMUSHORT s
[];
2262 unsigned EMUSHORT r
;
2267 /* a blank significand could mean either zero or infinity. */
2280 if ((j
> NBITS
) && (exp
< 32767))
2288 if (exp
> (EMULONG
) (-NBITS
- 1))
2301 /* Round off, unless told not to by rcntrl. */
2304 /* Set up rounding parameters if the control register changed. */
2305 if (rndprc
!= rlast
)
2312 rw
= NI
- 1; /* low guard word */
2332 /* For DEC or IBM arithmetic */
2359 /* Shift down 1 temporarily if the data structure has an implied
2360 most significant bit and the number is denormal. */
2361 if ((exp
<= 0) && (rndprc
!= 64) && (rndprc
!= NBITS
))
2363 lost
|= s
[NI
- 1] & 1;
2366 /* Clear out all bits below the rounding bit,
2367 remembering in r if any were nonzero. */
2381 if ((r
& rmbit
) != 0)
2386 { /* round to even */
2387 if ((s
[re
] & rebit
) == 0)
2399 if ((exp
<= 0) && (rndprc
!= 64) && (rndprc
!= NBITS
))
2404 { /* overflow on roundoff */
2417 for (i
= 2; i
< NI
- 1; i
++)
2420 warning ("floating point overflow");
2424 for (i
= M
+ 1; i
< NI
- 1; i
++)
2427 if ((rndprc
< 64) || (rndprc
== 113))
2442 s
[1] = (unsigned EMUSHORT
) exp
;
2447 /* Subtract external format numbers. */
2449 static int subflg
= 0;
2453 unsigned EMUSHORT
*a
, *b
, *c
;
2467 /* Infinity minus infinity is a NaN.
2468 Test for subtracting infinities of the same sign. */
2469 if (eisinf (a
) && eisinf (b
)
2470 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2472 mtherr ("esub", INVALID
);
2486 unsigned EMUSHORT
*a
, *b
, *c
;
2490 /* NaN plus anything is a NaN. */
2501 /* Infinity minus infinity is a NaN.
2502 Test for adding infinities of opposite signs. */
2503 if (eisinf (a
) && eisinf (b
)
2504 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2506 mtherr ("esub", INVALID
);
2517 unsigned EMUSHORT
*a
, *b
, *c
;
2519 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2521 EMULONG lt
, lta
, ltb
;
2542 /* compare exponents */
2547 { /* put the larger number in bi */
2557 if (lt
< (EMULONG
) (-NBITS
- 1))
2558 goto done
; /* answer same as larger addend */
2560 lost
= eshift (ai
, k
); /* shift the smaller number down */
2564 /* exponents were the same, so must compare significands */
2567 { /* the numbers are identical in magnitude */
2568 /* if different signs, result is zero */
2574 /* if same sign, result is double */
2575 /* double denomalized tiny number */
2576 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2581 /* add 1 to exponent unless both are zero! */
2582 for (j
= 1; j
< NI
- 1; j
++)
2586 /* This could overflow, but let emovo take care of that. */
2591 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2595 { /* put the larger number in bi */
2611 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2623 unsigned EMUSHORT
*a
, *b
, *c
;
2625 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2627 EMULONG lt
, lta
, ltb
;
2630 /* Return any NaN input. */
2641 /* Zero over zero, or infinity over infinity, is a NaN. */
2642 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2643 || (eisinf (a
) && eisinf (b
)))
2645 mtherr ("ediv", INVALID
);
2646 enan (c
, eisneg (a
) ^ eisneg (b
));
2650 /* Infinity over anything else is infinity. */
2654 if (eisneg (a
) ^ eisneg (b
))
2655 *(c
+ (NE
- 1)) = 0x8000;
2657 *(c
+ (NE
- 1)) = 0;
2661 /* Anything else over infinity is zero. */
2673 { /* See if numerator is zero. */
2674 for (i
= 1; i
< NI
- 1; i
++)
2678 ltb
-= enormlz (bi
);
2688 { /* possible divide by zero */
2689 for (i
= 1; i
< NI
- 1; i
++)
2693 lta
-= enormlz (ai
);
2698 *(c
+ (NE
- 1)) = 0;
2700 *(c
+ (NE
- 1)) = 0x8000;
2701 /* Divide by zero is not an invalid operation.
2702 It is a divide-by-zero operation! */
2704 mtherr ("ediv", SING
);
2710 /* calculate exponent */
2711 lt
= ltb
- lta
+ EXONE
;
2712 emdnorm (bi
, i
, 0, lt
, 64);
2727 unsigned EMUSHORT
*a
, *b
, *c
;
2729 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2731 EMULONG lt
, lta
, ltb
;
2734 /* NaN times anything is the same NaN. */
2745 /* Zero times infinity is a NaN. */
2746 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2747 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2749 mtherr ("emul", INVALID
);
2750 enan (c
, eisneg (a
) ^ eisneg (b
));
2754 /* Infinity times anything else is infinity. */
2756 if (eisinf (a
) || eisinf (b
))
2758 if (eisneg (a
) ^ eisneg (b
))
2759 *(c
+ (NE
- 1)) = 0x8000;
2761 *(c
+ (NE
- 1)) = 0;
2772 for (i
= 1; i
< NI
- 1; i
++)
2776 lta
-= enormlz (ai
);
2787 for (i
= 1; i
< NI
- 1; i
++)
2791 ltb
-= enormlz (bi
);
2800 /* Multiply significands */
2802 /* calculate exponent */
2803 lt
= lta
+ ltb
- (EXONE
- 1);
2804 emdnorm (bi
, j
, 0, lt
, 64);
2805 /* calculate sign of product */
2816 /* Convert IEEE double precision to e type. */
2820 unsigned EMUSHORT
*pe
, *y
;
2824 dectoe (pe
, y
); /* see etodec.c */
2829 ibmtoe (pe
, y
, DFmode
);
2832 register unsigned EMUSHORT r
;
2833 register unsigned EMUSHORT
*e
, *p
;
2834 unsigned EMUSHORT yy
[NI
];
2838 denorm
= 0; /* flag if denormalized number */
2847 yy
[M
] = (r
& 0x0f) | 0x10;
2848 r
&= ~0x800f; /* strip sign and 4 significand bits */
2854 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
2855 || (pe
[1] != 0) || (pe
[0] != 0))
2857 enan (y
, yy
[0] != 0);
2861 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
2862 || (pe
[2] != 0) || (pe
[3] != 0))
2864 enan (y
, yy
[0] != 0);
2875 #endif /* INFINITY */
2877 /* If zero exponent, then the significand is denormalized.
2878 So take back the understood high significand bit. */
2901 { /* if zero exponent, then normalize the significand */
2902 if ((k
= enormlz (yy
)) > NBITS
)
2905 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
2908 #endif /* not IBM */
2909 #endif /* not DEC */
2914 unsigned EMUSHORT
*pe
, *y
;
2916 unsigned EMUSHORT yy
[NI
];
2917 unsigned EMUSHORT
*e
, *p
, *q
;
2922 for (i
= 0; i
< NE
- 5; i
++)
2925 for (i
= 0; i
< 5; i
++)
2928 /* This precision is not ordinarily supported on DEC or IBM. */
2930 for (i
= 0; i
< 5; i
++)
2934 p
= &yy
[0] + (NE
- 1);
2937 for (i
= 0; i
< 5; i
++)
2941 p
= &yy
[0] + (NE
- 1);
2944 for (i
= 0; i
< 4; i
++)
2954 for (i
= 0; i
< 4; i
++)
2958 enan (y
, (*p
& 0x8000) != 0);
2963 for (i
= 1; i
<= 4; i
++)
2967 enan (y
, (*p
& 0x8000) != 0);
2979 #endif /* INFINITY */
2980 for (i
= 0; i
< NE
; i
++)
2987 unsigned EMUSHORT
*pe
, *y
;
2989 register unsigned EMUSHORT r
;
2990 unsigned EMUSHORT
*e
, *p
;
2991 unsigned EMUSHORT yy
[NI
];
3010 for (i
= 0; i
< 7; i
++)
3014 enan (y
, yy
[0] != 0);
3019 for (i
= 1; i
< 8; i
++)
3023 enan (y
, yy
[0] != 0);
3035 #endif /* INFINITY */
3039 for (i
= 0; i
< 7; i
++)
3044 for (i
= 0; i
< 7; i
++)
3047 /* If denormal, remove the implied bit; else shift down 1. */
3061 /* Convert IEEE single precision to e type. */
3065 unsigned EMUSHORT
*pe
, *y
;
3069 ibmtoe (pe
, y
, SFmode
);
3072 register unsigned EMUSHORT r
;
3073 register unsigned EMUSHORT
*e
, *p
;
3074 unsigned EMUSHORT yy
[NI
];
3078 denorm
= 0; /* flag if denormalized number */
3090 yy
[M
] = (r
& 0x7f) | 0200;
3091 r
&= ~0x807f; /* strip sign and 7 significand bits */
3097 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3099 enan (y
, yy
[0] != 0);
3103 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3105 enan (y
, yy
[0] != 0);
3116 #endif /* INFINITY */
3118 /* If zero exponent, then the significand is denormalized.
3119 So take back the understood high significand bit. */
3140 { /* if zero exponent, then normalize the significand */
3141 if ((k
= enormlz (yy
)) > NBITS
)
3144 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3147 #endif /* not IBM */
3153 unsigned EMUSHORT
*x
, *e
;
3155 unsigned EMUSHORT xi
[NI
];
3162 make_nan (e
, eisneg (x
), TFmode
);
3167 exp
= (EMULONG
) xi
[E
];
3172 /* round off to nearest or even */
3175 emdnorm (xi
, 0, 0, exp
, 64);
3181 /* Move out internal format to ieee long double */
3185 unsigned EMUSHORT
*a
, *b
;
3187 register unsigned EMUSHORT
*p
, *q
;
3188 unsigned EMUSHORT i
;
3193 make_nan (b
, eiisneg (a
), TFmode
);
3201 q
= b
+ 7; /* point to output exponent */
3204 /* If not denormal, delete the implied bit. */
3209 /* combine sign and exponent */
3213 *q
++ = *p
++ | 0x8000;
3218 *q
-- = *p
++ | 0x8000;
3222 /* skip over guard word */
3224 /* move the significand */
3226 for (i
= 0; i
< 7; i
++)
3229 for (i
= 0; i
< 7; i
++)
3236 unsigned EMUSHORT
*x
, *e
;
3238 unsigned EMUSHORT xi
[NI
];
3245 make_nan (e
, eisneg (x
), XFmode
);
3250 /* adjust exponent for offset */
3251 exp
= (EMULONG
) xi
[E
];
3256 /* round off to nearest or even */
3259 emdnorm (xi
, 0, 0, exp
, 64);
3266 /* Move out internal format to ieee long double. */
3270 unsigned EMUSHORT
*a
, *b
;
3272 register unsigned EMUSHORT
*p
, *q
;
3273 unsigned EMUSHORT i
;
3278 make_nan (b
, eiisneg (a
), XFmode
);
3283 #if defined(MIEEE) || defined(IBM)
3286 q
= b
+ 4; /* point to output exponent */
3287 #if LONG_DOUBLE_TYPE_SIZE == 96
3288 /* Clear the last two bytes of 12-byte Intel format */
3293 /* combine sign and exponent */
3295 #if defined(MIEEE) || defined(IBM)
3297 *q
++ = *p
++ | 0x8000;
3303 *q
-- = *p
++ | 0x8000;
3307 /* skip over guard word */
3309 /* move the significand */
3310 #if defined(MIEEE) || defined(IBM)
3311 for (i
= 0; i
< 4; i
++)
3314 for (i
= 0; i
< 4; i
++)
3320 /* e type to IEEE double precision. */
3326 unsigned EMUSHORT
*x
, *e
;
3328 etodec (x
, e
); /* see etodec.c */
3333 unsigned EMUSHORT
*x
, *y
;
3343 unsigned EMUSHORT
*x
, *e
;
3345 etoibm (x
, e
, DFmode
);
3350 unsigned EMUSHORT
*x
, *y
;
3352 toibm (x
, y
, DFmode
);
3355 #else /* it's neither DEC nor IBM */
3359 unsigned EMUSHORT
*x
, *e
;
3361 unsigned EMUSHORT xi
[NI
];
3368 make_nan (e
, eisneg (x
), DFmode
);
3373 /* adjust exponent for offsets */
3374 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3379 /* round off to nearest or even */
3382 emdnorm (xi
, 0, 0, exp
, 64);
3391 unsigned EMUSHORT
*x
, *y
;
3393 unsigned EMUSHORT i
;
3394 unsigned EMUSHORT
*p
;
3399 make_nan (y
, eiisneg (x
), DFmode
);
3407 *y
= 0; /* output high order */
3409 *y
= 0x8000; /* output sign bit */
3412 if (i
>= (unsigned int) 2047)
3413 { /* Saturate at largest number less than infinity. */
3428 *y
|= (unsigned EMUSHORT
) 0x7fef;
3452 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3453 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3467 #endif /* not IBM */
3468 #endif /* not DEC */
3472 /* e type to IEEE single precision. */
3478 unsigned EMUSHORT
*x
, *e
;
3480 etoibm (x
, e
, SFmode
);
3485 unsigned EMUSHORT
*x
, *y
;
3487 toibm (x
, y
, SFmode
);
3494 unsigned EMUSHORT
*x
, *e
;
3497 unsigned EMUSHORT xi
[NI
];
3503 make_nan (e
, eisneg (x
), SFmode
);
3508 /* adjust exponent for offsets */
3509 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3514 /* round off to nearest or even */
3517 emdnorm (xi
, 0, 0, exp
, 64);
3525 unsigned EMUSHORT
*x
, *y
;
3527 unsigned EMUSHORT i
;
3528 unsigned EMUSHORT
*p
;
3533 make_nan (y
, eiisneg (x
), SFmode
);
3544 *y
= 0; /* output high order */
3546 *y
= 0x8000; /* output sign bit */
3549 /* Handle overflow cases. */
3553 *y
|= (unsigned EMUSHORT
) 0x7f80;
3564 #else /* no INFINITY */
3565 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3579 #endif /* no INFINITY */
3591 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
3592 *y
|= i
; /* high order output already has sign bit set */
3604 #endif /* not IBM */
3606 /* Compare two e type numbers.
3610 -2 if either a or b is a NaN. */
3614 unsigned EMUSHORT
*a
, *b
;
3616 unsigned EMUSHORT ai
[NI
], bi
[NI
];
3617 register unsigned EMUSHORT
*p
, *q
;
3622 if (eisnan (a
) || eisnan (b
))
3631 { /* the signs are different */
3633 for (i
= 1; i
< NI
- 1; i
++)
3647 /* both are the same sign */
3662 return (0); /* equality */
3668 if (*(--p
) > *(--q
))
3669 return (msign
); /* p is bigger */
3671 return (-msign
); /* p is littler */
3677 /* Find nearest integer to x = floor (x + 0.5). */
3681 unsigned EMUSHORT
*x
, *y
;
3690 /* Convert HOST_WIDE_INT to e type. */
3695 unsigned EMUSHORT
*y
;
3697 unsigned EMUSHORT yi
[NI
];
3698 unsigned HOST_WIDE_INT ll
;
3704 /* make it positive */
3705 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
3706 yi
[0] = 0xffff; /* put correct sign in the e type number */
3710 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
3712 /* move the long integer to yi significand area */
3713 #if HOST_BITS_PER_WIDE_INT == 64
3714 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
3715 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
3716 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
3717 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
3718 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
3720 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
3721 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
3722 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
3725 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
3726 ecleaz (yi
); /* it was zero */
3728 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
3729 emovo (yi
, y
); /* output the answer */
3732 /* Convert unsigned HOST_WIDE_INT to e type. */
3736 unsigned HOST_WIDE_INT
*lp
;
3737 unsigned EMUSHORT
*y
;
3739 unsigned EMUSHORT yi
[NI
];
3740 unsigned HOST_WIDE_INT ll
;
3746 /* move the long integer to ayi significand area */
3747 #if HOST_BITS_PER_WIDE_INT == 64
3748 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
3749 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
3750 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
3751 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
3752 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
3754 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
3755 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
3756 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
3759 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
3760 ecleaz (yi
); /* it was zero */
3762 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
3763 emovo (yi
, y
); /* output the answer */
3767 /* Find signed HOST_WIDE_INT integer and floating point fractional
3768 parts of e-type (packed internal format) floating point input X.
3769 The integer output I has the sign of the input, except that
3770 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
3771 The output e-type fraction FRAC is the positive fractional
3776 unsigned EMUSHORT
*x
;
3778 unsigned EMUSHORT
*frac
;
3780 unsigned EMUSHORT xi
[NI
];
3782 unsigned HOST_WIDE_INT ll
;
3785 k
= (int) xi
[E
] - (EXONE
- 1);
3788 /* if exponent <= 0, integer = 0 and real output is fraction */
3793 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
3795 /* long integer overflow: output large integer
3796 and correct fraction */
3798 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
3801 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
3802 /* In this case, let it overflow and convert as if unsigned. */
3803 euifrac (x
, &ll
, frac
);
3804 *i
= (HOST_WIDE_INT
) ll
;
3807 /* In other cases, return the largest positive integer. */
3808 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
3813 warning ("overflow on truncation to integer");
3817 /* Shift more than 16 bits: first shift up k-16 mod 16,
3818 then shift up by 16's. */
3819 j
= k
- ((k
>> 4) << 4);
3826 ll
= (ll
<< 16) | xi
[M
];
3828 while ((k
-= 16) > 0);
3835 /* shift not more than 16 bits */
3837 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
3844 if ((k
= enormlz (xi
)) > NBITS
)
3847 xi
[E
] -= (unsigned EMUSHORT
) k
;
3853 /* Find unsigned HOST_WIDE_INT integer and floating point fractional parts.
3854 A negative e type input yields integer output = 0
3855 but correct fraction. */
3858 euifrac (x
, i
, frac
)
3859 unsigned EMUSHORT
*x
;
3860 unsigned HOST_WIDE_INT
*i
;
3861 unsigned EMUSHORT
*frac
;
3863 unsigned HOST_WIDE_INT ll
;
3864 unsigned EMUSHORT xi
[NI
];
3868 k
= (int) xi
[E
] - (EXONE
- 1);
3871 /* if exponent <= 0, integer = 0 and argument is fraction */
3876 if (k
> HOST_BITS_PER_WIDE_INT
)
3878 /* Long integer overflow: output large integer
3879 and correct fraction.
3880 Note, the BSD microvax compiler says that ~(0UL)
3881 is a syntax error. */
3885 warning ("overflow on truncation to unsigned integer");
3889 /* Shift more than 16 bits: first shift up k-16 mod 16,
3890 then shift up by 16's. */
3891 j
= k
- ((k
>> 4) << 4);
3898 ll
= (ll
<< 16) | xi
[M
];
3900 while ((k
-= 16) > 0);
3905 /* shift not more than 16 bits */
3907 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
3910 if (xi
[0]) /* A negative value yields unsigned integer 0. */
3916 if ((k
= enormlz (xi
)) > NBITS
)
3919 xi
[E
] -= (unsigned EMUSHORT
) k
;
3926 /* Shift significand area up or down by the number of bits given by SC. */
3930 unsigned EMUSHORT
*x
;
3933 unsigned EMUSHORT lost
;
3934 unsigned EMUSHORT
*p
;
3947 lost
|= *p
; /* remember lost bits */
3988 return ((int) lost
);
3993 /* Shift normalize the significand area pointed to by argument.
3994 Shift count (up = positive) is returned. */
3998 unsigned EMUSHORT x
[];
4000 register unsigned EMUSHORT
*p
;
4009 return (0); /* already normalized */
4015 /* With guard word, there are NBITS+16 bits available.
4016 Return true if all are zero. */
4020 /* see if high byte is zero */
4021 while ((*p
& 0xff00) == 0)
4026 /* now shift 1 bit at a time */
4027 while ((*p
& 0x8000) == 0)
4033 mtherr ("enormlz", UNDERFLOW
);
4039 /* Normalize by shifting down out of the high guard word
4040 of the significand */
4055 mtherr ("enormlz", OVERFLOW
);
4065 /* Convert e type number to decimal format ASCII string.
4066 The constants are for 64 bit precision. */
4071 #if LONG_DOUBLE_TYPE_SIZE == 128
4072 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4074 {0x6576, 0x4a92, 0x804a, 0x153f,
4075 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4076 {0x6a32, 0xce52, 0x329a, 0x28ce,
4077 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4078 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4079 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4080 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4081 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4082 {0x851e, 0xeab7, 0x98fe, 0x901b,
4083 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4084 {0x0235, 0x0137, 0x36b1, 0x336c,
4085 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4086 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4087 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4088 {0x0000, 0x0000, 0x0000, 0x0000,
4089 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4090 {0x0000, 0x0000, 0x0000, 0x0000,
4091 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4092 {0x0000, 0x0000, 0x0000, 0x0000,
4093 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4094 {0x0000, 0x0000, 0x0000, 0x0000,
4095 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4096 {0x0000, 0x0000, 0x0000, 0x0000,
4097 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4098 {0x0000, 0x0000, 0x0000, 0x0000,
4099 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4102 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4104 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4105 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4106 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4107 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4108 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4109 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4110 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4111 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4112 {0xa23e, 0x5308, 0xfefb, 0x1155,
4113 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4114 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4115 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4116 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4117 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4118 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4119 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4120 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4121 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4122 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4123 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4124 {0xc155, 0xa4a8, 0x404e, 0x6113,
4125 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4126 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4127 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4128 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4129 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4132 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4133 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4135 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4136 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4137 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4138 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4139 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4140 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4141 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4142 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4143 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4144 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4145 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4146 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4147 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4150 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4152 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4153 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4154 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4155 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4156 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4157 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4158 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4159 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4160 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4161 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4162 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4163 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4164 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4169 e24toasc (x
, string
, ndigs
)
4170 unsigned EMUSHORT x
[];
4174 unsigned EMUSHORT w
[NI
];
4177 etoasc (w
, string
, ndigs
);
4182 e53toasc (x
, string
, ndigs
)
4183 unsigned EMUSHORT x
[];
4187 unsigned EMUSHORT w
[NI
];
4190 etoasc (w
, string
, ndigs
);
4195 e64toasc (x
, string
, ndigs
)
4196 unsigned EMUSHORT x
[];
4200 unsigned EMUSHORT w
[NI
];
4203 etoasc (w
, string
, ndigs
);
4207 e113toasc (x
, string
, ndigs
)
4208 unsigned EMUSHORT x
[];
4212 unsigned EMUSHORT w
[NI
];
4215 etoasc (w
, string
, ndigs
);
4219 static char wstring
[80]; /* working storage for ASCII output */
4222 etoasc (x
, string
, ndigs
)
4223 unsigned EMUSHORT x
[];
4228 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4229 unsigned EMUSHORT
*p
, *r
, *ten
;
4230 unsigned EMUSHORT sign
;
4231 int i
, j
, k
, expon
, rndsav
;
4233 unsigned EMUSHORT m
;
4244 sprintf (wstring
, " NaN ");
4248 rndprc
= NBITS
; /* set to full precision */
4249 emov (x
, y
); /* retain external format */
4250 if (y
[NE
- 1] & 0x8000)
4253 y
[NE
- 1] &= 0x7fff;
4260 ten
= &etens
[NTEN
][0];
4262 /* Test for zero exponent */
4265 for (k
= 0; k
< NE
- 1; k
++)
4268 goto tnzro
; /* denormalized number */
4270 goto isone
; /* legal all zeros */
4274 /* Test for infinity. */
4275 if (y
[NE
- 1] == 0x7fff)
4278 sprintf (wstring
, " -Infinity ");
4280 sprintf (wstring
, " Infinity ");
4284 /* Test for exponent nonzero but significand denormalized.
4285 * This is an error condition.
4287 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4289 mtherr ("etoasc", DOMAIN
);
4290 sprintf (wstring
, "NaN");
4294 /* Compare to 1.0 */
4303 { /* Number is greater than 1 */
4304 /* Convert significand to an integer and strip trailing decimal zeros. */
4306 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4308 p
= &etens
[NTEN
- 4][0];
4314 for (j
= 0; j
< NE
- 1; j
++)
4327 /* Rescale from integer significand */
4328 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4330 /* Find power of 10 */
4334 /* An unordered compare result shouldn't happen here. */
4335 while (ecmp (ten
, u
) <= 0)
4337 if (ecmp (p
, u
) <= 0)
4350 { /* Number is less than 1.0 */
4351 /* Pad significand with trailing decimal zeros. */
4354 while ((y
[NE
- 2] & 0x8000) == 0)
4363 for (i
= 0; i
< NDEC
+ 1; i
++)
4365 if ((w
[NI
- 1] & 0x7) != 0)
4367 /* multiply by 10 */
4380 if (eone
[NE
- 1] <= u
[1])
4392 while (ecmp (eone
, w
) > 0)
4394 if (ecmp (p
, w
) >= 0)
4409 /* Find the first (leading) digit. */
4415 digit
= equot
[NI
- 1];
4416 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4424 digit
= equot
[NI
- 1];
4432 /* Examine number of digits requested by caller. */
4450 *s
++ = (char)digit
+ '0';
4453 /* Generate digits after the decimal point. */
4454 for (k
= 0; k
<= ndigs
; k
++)
4456 /* multiply current number by 10, without normalizing */
4463 *s
++ = (char) equot
[NI
- 1] + '0';
4465 digit
= equot
[NI
- 1];
4468 /* round off the ASCII string */
4471 /* Test for critical rounding case in ASCII output. */
4475 if (ecmp (t
, ezero
) != 0)
4476 goto roun
; /* round to nearest */
4477 if ((*(s
- 1) & 1) == 0)
4478 goto doexp
; /* round to even */
4480 /* Round up and propagate carry-outs */
4484 /* Carry out to most significant digit? */
4491 /* Most significant digit carries to 10? */
4499 /* Round up and carry out from less significant digits */
4511 sprintf (ss, "e+%d", expon);
4513 sprintf (ss, "e%d", expon);
4515 sprintf (ss
, "e%d", expon
);
4518 /* copy out the working string */
4521 while (*ss
== ' ') /* strip possible leading space */
4523 while ((*s
++ = *ss
++) != '\0')
4528 /* Convert ASCII string to quadruple precision floating point
4530 Numeric input is free field decimal number with max of 15 digits with or
4531 without decimal point entered as ASCII from teletype. Entering E after
4532 the number followed by a second number causes the second number to be
4533 interpreted as a power of 10 to be multiplied by the first number
4534 (i.e., "scientific" notation). */
4536 /* ASCII to single */
4541 unsigned EMUSHORT
*y
;
4547 /* ASCII to double */
4552 unsigned EMUSHORT
*y
;
4554 #if defined(DEC) || defined(IBM)
4562 /* ASCII to long double */
4567 unsigned EMUSHORT
*y
;
4572 /* ASCII to 128-bit long double */
4577 unsigned EMUSHORT
*y
;
4579 asctoeg (s
, y
, 113);
4582 /* ASCII to super double */
4587 unsigned EMUSHORT
*y
;
4589 asctoeg (s
, y
, NBITS
);
4593 /* ASCII to e type, with specified rounding precision = oprec. */
4596 asctoeg (ss
, y
, oprec
)
4598 unsigned EMUSHORT
*y
;
4601 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
4602 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
4603 int k
, trail
, c
, rndsav
;
4605 unsigned EMUSHORT nsign
, *p
;
4606 char *sp
, *s
, *lstr
;
4608 /* Copy the input string. */
4609 lstr
= (char *) alloca (strlen (ss
) + 1);
4611 while (*s
== ' ') /* skip leading spaces */
4614 while ((*sp
++ = *s
++) != '\0')
4619 rndprc
= NBITS
; /* Set to full precision */
4632 if ((k
>= 0) && (k
<= 9))
4634 /* Ignore leading zeros */
4635 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
4637 /* Identify and strip trailing zeros after the decimal point. */
4638 if ((trail
== 0) && (decflg
!= 0))
4641 while ((*sp
>= '0') && (*sp
<= '9'))
4643 /* Check for syntax error */
4645 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
4646 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
4657 /* If enough digits were given to more than fill up the yy register,
4658 continuing until overflow into the high guard word yy[2]
4659 guarantees that there will be a roundoff bit at the top
4660 of the low guard word after normalization. */
4665 nexp
+= 1; /* count digits after decimal point */
4666 eshup1 (yy
); /* multiply current number by 10 */
4672 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
4677 /* Mark any lost non-zero digit. */
4679 /* Count lost digits before the decimal point. */
4694 case '.': /* decimal point */
4724 mtherr ("asctoe", DOMAIN
);
4733 /* Exponent interpretation */
4739 /* check for + or - */
4747 while ((*s
>= '0') && (*s
<= '9'))
4751 if (exp
> -(MINDECEXP
))
4761 if (exp
> MAXDECEXP
)
4765 yy
[E
] = 0x7fff; /* infinity */
4768 if (exp
< MINDECEXP
)
4777 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
4778 while ((nexp
> 0) && (yy
[2] == 0))
4790 if ((k
= enormlz (yy
)) > NBITS
)
4795 lexp
= (EXONE
- 1 + NBITS
) - k
;
4796 emdnorm (yy
, lost
, 0, lexp
, 64);
4798 /* Convert to external format:
4800 Multiply by 10**nexp. If precision is 64 bits,
4801 the maximum relative error incurred in forming 10**n
4802 for 0 <= n <= 324 is 8.2e-20, at 10**180.
4803 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
4804 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
4819 /* Punt. Can't handle this without 2 divides. */
4820 emovi (etens
[0], tt
);
4827 p
= &etens
[NTEN
][0];
4837 while (exp
<= MAXP
);
4855 /* Round and convert directly to the destination type */
4857 lexp
-= EXONE
- 0x3ff;
4859 else if (oprec
== 24 || oprec
== 56)
4860 lexp
-= EXONE
- (0x41 << 2);
4862 else if (oprec
== 24)
4863 lexp
-= EXONE
- 0177;
4866 else if (oprec
== 56)
4867 lexp
-= EXONE
- 0201;
4870 emdnorm (yy
, k
, 0, lexp
, 64);
4880 todec (yy
, y
); /* see etodec.c */
4885 toibm (yy
, y
, DFmode
);
4908 /* y = largest integer not greater than x (truncated toward minus infinity) */
4910 static unsigned EMUSHORT bmask
[] =
4933 unsigned EMUSHORT x
[], y
[];
4935 register unsigned EMUSHORT
*p
;
4937 unsigned EMUSHORT f
[NE
];
4939 emov (x
, f
); /* leave in external format */
4940 expon
= (int) f
[NE
- 1];
4941 e
= (expon
& 0x7fff) - (EXONE
- 1);
4947 /* number of bits to clear out */
4959 /* clear the remaining bits */
4961 /* truncate negatives toward minus infinity */
4964 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
4966 for (i
= 0; i
< NE
- 1; i
++)
4978 /* Returns s and exp such that s * 2**exp = x and .5 <= s < 1.
4979 For example, 1.1 = 0.55 * 2**1
4980 Handles denormalized numbers properly using long integer exp. */
4984 unsigned EMUSHORT x
[];
4986 unsigned EMUSHORT s
[];
4988 unsigned EMUSHORT xi
[NI
];
4992 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5000 *exp
= (int) (li
- 0x3ffe);
5005 /* Return y = x * 2**pwr2. */
5009 unsigned EMUSHORT x
[];
5011 unsigned EMUSHORT y
[];
5013 unsigned EMUSHORT xi
[NI
];
5021 emdnorm (xi
, i
, i
, li
, 64);
5026 /* c = remainder after dividing b by a
5027 Least significant integer quotient bits left in equot[]. */
5031 unsigned EMUSHORT a
[], b
[], c
[];
5033 unsigned EMUSHORT den
[NI
], num
[NI
];
5037 || (ecmp (a
, ezero
) == 0)
5045 if (ecmp (a
, ezero
) == 0)
5047 mtherr ("eremain", SING
);
5053 eiremain (den
, num
);
5054 /* Sign of remainder = sign of quotient */
5064 unsigned EMUSHORT den
[], num
[];
5067 unsigned EMUSHORT j
;
5070 ld
-= enormlz (den
);
5072 ln
-= enormlz (num
);
5076 if (ecmpm (den
, num
) <= 0)
5090 emdnorm (num
, 0, 0, ln
, 0);
5093 /* This routine may be called to report one of the following
5094 error conditions (in the include file mconf.h).
5096 Mnemonic Value Significance
5098 DOMAIN 1 argument domain error
5099 SING 2 function singularity
5100 OVERFLOW 3 overflow range error
5101 UNDERFLOW 4 underflow range error
5102 TLOSS 5 total loss of precision
5103 PLOSS 6 partial loss of precision
5104 INVALID 7 NaN - producing operation
5105 EDOM 33 Unix domain error code
5106 ERANGE 34 Unix range error code
5108 The default version of the file prints the function name,
5109 passed to it by the pointer fctnam, followed by the
5110 error condition. The display is directed to the standard
5111 output device. The routine then returns to the calling
5112 program. Users may wish to modify the program to abort by
5113 calling exit under severe error conditions such as domain
5116 Since all error conditions pass control to this function,
5117 the display may be easily changed, eliminated, or directed
5118 to an error logging device. */
5120 /* Note: the order of appearance of the following messages is bound to the
5121 error codes defined above. */
5124 static char *ermsg
[NMSGS
] =
5126 "unknown", /* error code 0 */
5127 "domain", /* error code 1 */
5128 "singularity", /* et seq. */
5131 "total loss of precision",
5132 "partial loss of precision",
5146 /* Display string passed by calling program, which is supposed to be the
5147 name of the function in which the error occurred.
5149 Display error message defined by the code argument. */
5151 if ((code
<= 0) || (code
>= NMSGS
))
5153 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5156 /* Set global error message word */
5161 /* Convert DEC double precision to e type. */
5165 unsigned EMUSHORT
*d
;
5166 unsigned EMUSHORT
*e
;
5168 unsigned EMUSHORT y
[NI
];
5169 register unsigned EMUSHORT r
, *p
;
5171 ecleaz (y
); /* start with a zero */
5172 p
= y
; /* point to our number */
5173 r
= *d
; /* get DEC exponent word */
5174 if (*d
& (unsigned int) 0x8000)
5175 *p
= 0xffff; /* fill in our sign */
5176 ++p
; /* bump pointer to our exponent word */
5177 r
&= 0x7fff; /* strip the sign bit */
5178 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5182 r
>>= 7; /* shift exponent word down 7 bits */
5183 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5184 /* add our e type exponent offset */
5185 *p
++ = r
; /* to form our exponent */
5187 r
= *d
++; /* now do the high order mantissa */
5188 r
&= 0177; /* strip off the DEC exponent and sign bits */
5189 r
|= 0200; /* the DEC understood high order mantissa bit */
5190 *p
++ = r
; /* put result in our high guard word */
5192 *p
++ = *d
++; /* fill in the rest of our mantissa */
5196 eshdn8 (y
); /* shift our mantissa down 8 bits */
5204 ; convert e type to DEC double precision
5212 unsigned EMUSHORT
*x
, *d
;
5214 unsigned EMUSHORT xi
[NI
];
5219 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201); /* adjust exponent for offsets */
5220 /* round off to nearest or even */
5223 emdnorm (xi
, 0, 0, exp
, 64);
5230 unsigned EMUSHORT
*x
, *y
;
5232 unsigned EMUSHORT i
;
5233 unsigned EMUSHORT
*p
;
5272 /* Convert IBM single/double precision to e type. */
5276 unsigned EMUSHORT
*d
;
5277 unsigned EMUSHORT
*e
;
5278 enum machine_mode mode
;
5280 unsigned EMUSHORT y
[NI
];
5281 register unsigned EMUSHORT r
, *p
;
5284 ecleaz (y
); /* start with a zero */
5285 p
= y
; /* point to our number */
5286 r
= *d
; /* get IBM exponent word */
5287 if (*d
& (unsigned int) 0x8000)
5288 *p
= 0xffff; /* fill in our sign */
5289 ++p
; /* bump pointer to our exponent word */
5290 r
&= 0x7f00; /* strip the sign bit */
5291 r
>>= 6; /* shift exponent word down 6 bits */
5292 /* in fact shift by 8 right and 2 left */
5293 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5294 /* add our e type exponent offset */
5295 *p
++ = r
; /* to form our exponent */
5297 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5298 /* strip off the IBM exponent and sign bits */
5299 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5301 *p
++ = *d
++; /* fill in the rest of our mantissa */
5306 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5309 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5310 /* handle change in RADIX */
5316 /* Convert e type to IBM single/double precision. */
5320 unsigned EMUSHORT
*x
, *d
;
5321 enum machine_mode mode
;
5323 unsigned EMUSHORT xi
[NI
];
5328 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5329 /* round off to nearest or even */
5332 emdnorm (xi
, 0, 0, exp
, 64);
5334 toibm (xi
, d
, mode
);
5339 unsigned EMUSHORT
*x
, *y
;
5340 enum machine_mode mode
;
5342 unsigned EMUSHORT i
;
5343 unsigned EMUSHORT
*p
;
5391 /* Output a binary NaN bit pattern in the target machine's format. */
5393 /* If special NaN bit patterns are required, define them in tm.h
5394 as arrays of unsigned 16-bit shorts. Otherwise, use the default
5400 unsigned EMUSHORT TFnan
[8] =
5401 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5404 unsigned EMUSHORT TFnan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
5412 unsigned EMUSHORT XFnan
[6] = {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
5415 unsigned EMUSHORT XFnan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
5423 unsigned EMUSHORT DFnan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
5426 unsigned EMUSHORT DFnan
[4] = {0, 0, 0, 0xfff8};
5434 unsigned EMUSHORT SFnan
[2] = {0x7fff, 0xffff};
5437 unsigned EMUSHORT SFnan
[2] = {0, 0xffc0};
5443 make_nan (nan
, sign
, mode
)
5444 unsigned EMUSHORT
*nan
;
5446 enum machine_mode mode
;
5449 unsigned EMUSHORT
*p
;
5453 /* Possibly the `reserved operand' patterns on a VAX can be
5454 used like NaN's, but probably not in the same way as IEEE. */
5455 #if !defined(DEC) && !defined(IBM)
5477 *nan
++ = (sign
<< 15) | *p
++;
5482 *nan
= (sign
<< 15) | *p
;
5486 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
5487 This is the inverse of the function `etarsingle' invoked by
5488 REAL_VALUE_TO_TARGET_SINGLE. */
5491 ereal_from_float (f
)
5495 unsigned EMUSHORT s
[2];
5496 unsigned EMUSHORT e
[NE
];
5498 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
5499 This is the inverse operation to what the function `endian' does. */
5500 #if FLOAT_WORDS_BIG_ENDIAN
5501 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
5502 s
[1] = (unsigned EMUSHORT
) f
;
5504 s
[0] = (unsigned EMUSHORT
) f
;
5505 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
5507 /* Convert and promote the target float to E-type. */
5509 /* Output E-type to REAL_VALUE_TYPE. */
5515 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
5516 This is the inverse of the function `etardouble' invoked by
5517 REAL_VALUE_TO_TARGET_DOUBLE.
5519 The DFmode is stored as an array of HOST_WIDE_INT in the target's
5520 data format, with no holes in the bit packing. The first element
5521 of the input array holds the bits that would come first in the
5522 target computer's memory. */
5525 ereal_from_double (d
)
5529 unsigned EMUSHORT s
[4];
5530 unsigned EMUSHORT e
[NE
];
5532 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
5533 #if FLOAT_WORDS_BIG_ENDIAN
5534 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
5535 s
[1] = (unsigned EMUSHORT
) d
[0];
5536 #if HOST_BITS_PER_WIDE_INT == 32
5537 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
5538 s
[3] = (unsigned EMUSHORT
) d
[1];
5540 /* In this case the entire target double is contained in the
5541 first array element. The second element of the input is ignored. */
5542 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
5543 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
5546 /* Target float words are little-endian. */
5547 s
[0] = (unsigned EMUSHORT
) d
[0];
5548 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
5549 #if HOST_BITS_PER_WIDE_INT == 32
5550 s
[2] = (unsigned EMUSHORT
) d
[1];
5551 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
5553 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
5554 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
5557 /* Convert target double to E-type. */
5559 /* Output E-type to REAL_VALUE_TYPE. */
5565 /* Convert target computer unsigned 64-bit integer to e-type.
5566 The endian-ness of DImode follows the convention for integers,
5567 so we use WORDS_BIG_ENDIAN here, not FLOAT_WORDS_BIG_ENDIAN. */
5571 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
5572 unsigned EMUSHORT
*e
;
5574 unsigned EMUSHORT yi
[NI
];
5578 #if WORDS_BIG_ENDIAN
5579 for (k
= M
; k
< M
+ 4; k
++)
5582 for (k
= M
+ 3; k
>= M
; k
--)
5585 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
5586 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
5587 ecleaz (yi
); /* it was zero */
5589 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
5593 /* Convert target computer signed 64-bit integer to e-type. */
5597 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
5598 unsigned EMUSHORT
*e
;
5600 unsigned EMULONG acc
;
5601 unsigned EMUSHORT yi
[NI
];
5602 unsigned EMUSHORT carry
;
5606 #if WORDS_BIG_ENDIAN
5607 for (k
= M
; k
< M
+ 4; k
++)
5610 for (k
= M
+ 3; k
>= M
; k
--)
5613 /* Take absolute value */
5619 for (k
= M
+ 3; k
>= M
; k
--)
5621 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
5628 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
5629 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
5630 ecleaz (yi
); /* it was zero */
5632 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
5639 /* Convert e-type to unsigned 64-bit int. */
5643 unsigned EMUSHORT
*x
;
5644 unsigned EMUSHORT
*i
;
5646 unsigned EMUSHORT xi
[NI
];
5655 k
= (int) xi
[E
] - (EXONE
- 1);
5658 for (j
= 0; j
< 4; j
++)
5664 for (j
= 0; j
< 4; j
++)
5667 warning ("overflow on truncation to integer");
5672 /* Shift more than 16 bits: first shift up k-16 mod 16,
5673 then shift up by 16's. */
5674 j
= k
- ((k
>> 4) << 4);
5678 #if WORDS_BIG_ENDIAN
5688 #if WORDS_BIG_ENDIAN
5694 while ((k
-= 16) > 0);
5698 /* shift not more than 16 bits */
5703 #if WORDS_BIG_ENDIAN
5719 /* Convert e-type to signed 64-bit int. */
5723 unsigned EMUSHORT
*x
;
5724 unsigned EMUSHORT
*i
;
5726 unsigned EMULONG acc
;
5727 unsigned EMUSHORT xi
[NI
];
5728 unsigned EMUSHORT carry
;
5729 unsigned EMUSHORT
*isave
;
5733 k
= (int) xi
[E
] - (EXONE
- 1);
5736 for (j
= 0; j
< 4; j
++)
5742 for (j
= 0; j
< 4; j
++)
5745 warning ("overflow on truncation to integer");
5751 /* Shift more than 16 bits: first shift up k-16 mod 16,
5752 then shift up by 16's. */
5753 j
= k
- ((k
>> 4) << 4);
5757 #if WORDS_BIG_ENDIAN
5767 #if WORDS_BIG_ENDIAN
5773 while ((k
-= 16) > 0);
5777 /* shift not more than 16 bits */
5780 #if WORDS_BIG_ENDIAN
5793 /* Negate if negative */
5797 #if WORDS_BIG_ENDIAN
5800 for (k
= 0; k
< 4; k
++)
5802 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
5803 #if WORDS_BIG_ENDIAN
5816 /* Longhand square root routine. */
5819 static int esqinited
= 0;
5820 static unsigned short sqrndbit
[NI
];
5824 unsigned EMUSHORT
*x
, *y
;
5826 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
5828 int i
, j
, k
, n
, nlups
;
5833 sqrndbit
[NI
- 2] = 1;
5836 /* Check for arg <= 0 */
5837 i
= ecmp (x
, ezero
);
5842 mtherr ("esqrt", DOMAIN
);
5858 /* Bring in the arg and renormalize if it is denormal. */
5860 m
= (EMULONG
) xx
[1]; /* local long word exponent */
5864 /* Divide exponent by 2 */
5866 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
5868 /* Adjust if exponent odd */
5878 n
= 8; /* get 8 bits of result per inner loop */
5884 /* bring in next word of arg */
5886 num
[NI
- 1] = xx
[j
+ 3];
5887 /* Do additional bit on last outer loop, for roundoff. */
5890 for (i
= 0; i
< n
; i
++)
5892 /* Next 2 bits of arg */
5895 /* Shift up answer */
5897 /* Make trial divisor */
5898 for (k
= 0; k
< NI
; k
++)
5901 eaddm (sqrndbit
, temp
);
5902 /* Subtract and insert answer bit if it goes in */
5903 if (ecmpm (temp
, num
) <= 0)
5913 /* Adjust for extra, roundoff loop done. */
5914 exp
+= (NBITS
- 1) - rndprc
;
5916 /* Sticky bit = 1 if the remainder is nonzero. */
5918 for (i
= 3; i
< NI
; i
++)
5921 /* Renormalize and round off. */
5922 emdnorm (sq
, k
, 0, exp
, 64);
5925 #endif /* EMU_NON_COMPILE not defined */
5927 /* Return the binary precision of the significand for a given
5928 floating point mode. The mode can hold an integer value
5929 that many bits wide, without losing any bits. */
5932 significand_size (mode
)
5933 enum machine_mode mode
;
5942 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
5945 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
5948 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT