]>
gcc.gnu.org Git - gcc.git/blob - gcc/real.c
1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 94, 95, 96, 97, 1998 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
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, 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 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
80 then `long double' and `double' are both implemented, but they
81 both mean DFmode. In this case, the software floating-point
82 support available here is activated by writing
83 #define REAL_ARITHMETIC
86 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
87 and may deactivate XFmode since `long double' is used to refer
90 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
91 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
92 separate the floating point unit's endian-ness from that of
93 the integer addressing. This permits one to define a big-endian
94 FPU on a little-endian machine (e.g., ARM). An extension to
95 BYTES_BIG_ENDIAN may be required for some machines in the future.
96 These optional macros may be defined in tm.h. In real.h, they
97 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
98 them for any normal host or target machine on which the floats
99 and the integers have the same endian-ness. */
102 /* The following converts gcc macros into the ones used by this file. */
104 /* REAL_ARITHMETIC defined means that macros in real.h are
105 defined to call emulator functions. */
106 #ifdef REAL_ARITHMETIC
108 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
109 /* PDP-11, Pro350, VAX: */
111 #else /* it's not VAX */
112 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
113 /* IBM System/370 style */
115 #else /* it's also not an IBM */
116 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
117 /* TMS320C3x/C4x style */
119 #else /* it's also not a C4X */
120 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
122 #else /* it's not IEEE either */
123 /* UNKnown arithmetic. We don't support this and can't go on. */
124 unknown arithmetic type
126 #endif /* not IEEE */
131 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
134 /* REAL_ARITHMETIC not defined means that the *host's* data
135 structure will be used. It may differ by endian-ness from the
136 target machine's structure and will get its ends swapped
137 accordingly (but not here). Probably only the decimal <-> binary
138 functions in this file will actually be used in this case. */
140 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
142 #else /* it's not VAX */
143 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
144 /* IBM System/370 style */
146 #else /* it's also not an IBM */
147 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
149 #else /* it's not IEEE either */
150 unknown arithmetic type
152 #endif /* not IEEE */
156 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
158 #endif /* REAL_ARITHMETIC not defined */
160 /* Define INFINITY for support of infinity.
161 Define NANS for support of Not-a-Number's (NaN's). */
162 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
167 /* Support of NaNs requires support of infinity. */
174 /* Find a host integer type that is at least 16 bits wide,
175 and another type at least twice whatever that size is. */
177 #if HOST_BITS_PER_CHAR >= 16
178 #define EMUSHORT char
179 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
180 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
182 #if HOST_BITS_PER_SHORT >= 16
183 #define EMUSHORT short
184 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
185 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
187 #if HOST_BITS_PER_INT >= 16
189 #define EMUSHORT_SIZE HOST_BITS_PER_INT
190 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
192 #if HOST_BITS_PER_LONG >= 16
193 #define EMUSHORT long
194 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
195 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
197 /* You will have to modify this program to have a smaller unit size. */
198 #define EMU_NON_COMPILE
204 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
205 #define EMULONG short
207 #if HOST_BITS_PER_INT >= EMULONG_SIZE
210 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
213 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
214 #define EMULONG long long int
216 /* You will have to modify this program to have a smaller unit size. */
217 #define EMU_NON_COMPILE
224 /* The host interface doesn't work if no 16-bit size exists. */
225 #if EMUSHORT_SIZE != 16
226 #define EMU_NON_COMPILE
229 /* OK to continue compilation. */
230 #ifndef EMU_NON_COMPILE
232 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
233 In GET_REAL and PUT_REAL, r and e are pointers.
234 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
235 in memory, with no holes. */
237 #if LONG_DOUBLE_TYPE_SIZE == 96
238 /* Number of 16 bit words in external e type format */
240 #define MAXDECEXP 4932
241 #define MINDECEXP -4956
242 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
243 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
244 #else /* no XFmode */
245 #if LONG_DOUBLE_TYPE_SIZE == 128
247 #define MAXDECEXP 4932
248 #define MINDECEXP -4977
249 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
250 #define PUT_REAL(e,r) bcopy ((char *) e, (char *) r, 2*NE)
253 #define MAXDECEXP 4932
254 #define MINDECEXP -4956
255 #ifdef REAL_ARITHMETIC
256 /* Emulator uses target format internally
257 but host stores it in host endian-ness. */
259 #define GET_REAL(r,e) \
261 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
262 e53toe ((unsigned EMUSHORT *) (r), (e)); \
265 unsigned EMUSHORT w[4]; \
266 w[3] = ((EMUSHORT *) r)[0]; \
267 w[2] = ((EMUSHORT *) r)[1]; \
268 w[1] = ((EMUSHORT *) r)[2]; \
269 w[0] = ((EMUSHORT *) r)[3]; \
274 #define PUT_REAL(e,r) \
276 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
277 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
280 unsigned EMUSHORT w[4]; \
282 *((EMUSHORT *) r) = w[3]; \
283 *((EMUSHORT *) r + 1) = w[2]; \
284 *((EMUSHORT *) r + 2) = w[1]; \
285 *((EMUSHORT *) r + 3) = w[0]; \
289 #else /* not REAL_ARITHMETIC */
291 /* emulator uses host format */
292 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
293 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
295 #endif /* not REAL_ARITHMETIC */
296 #endif /* not TFmode */
297 #endif /* not XFmode */
300 /* Number of 16 bit words in internal format */
303 /* Array offset to exponent */
306 /* Array offset to high guard word */
309 /* Number of bits of precision */
310 #define NBITS ((NI-4)*16)
312 /* Maximum number of decimal digits in ASCII conversion
315 #define NDEC (NBITS*8/27)
317 /* The exponent of 1.0 */
318 #define EXONE (0x3fff)
320 extern int extra_warnings
;
321 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
322 extern unsigned EMUSHORT elog2
[], esqrt2
[];
324 static void endian
PROTO((unsigned EMUSHORT
*, long *,
326 static void eclear
PROTO((unsigned EMUSHORT
*));
327 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
328 static void eabs
PROTO((unsigned EMUSHORT
*));
329 static void eneg
PROTO((unsigned EMUSHORT
*));
330 static int eisneg
PROTO((unsigned EMUSHORT
*));
331 static int eisinf
PROTO((unsigned EMUSHORT
*));
332 static int eisnan
PROTO((unsigned EMUSHORT
*));
333 static void einfin
PROTO((unsigned EMUSHORT
*));
334 static void enan
PROTO((unsigned EMUSHORT
*, int));
335 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
336 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
337 static void ecleaz
PROTO((unsigned EMUSHORT
*));
338 static void ecleazs
PROTO((unsigned EMUSHORT
*));
339 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
340 static void einan
PROTO((unsigned EMUSHORT
*));
341 static int eiisnan
PROTO((unsigned EMUSHORT
*));
342 static int eiisneg
PROTO((unsigned EMUSHORT
*));
343 static void eiinfin
PROTO((unsigned EMUSHORT
*));
344 static int eiisinf
PROTO((unsigned EMUSHORT
*));
345 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
346 static void eshdn1
PROTO((unsigned EMUSHORT
*));
347 static void eshup1
PROTO((unsigned EMUSHORT
*));
348 static void eshdn8
PROTO((unsigned EMUSHORT
*));
349 static void eshup8
PROTO((unsigned EMUSHORT
*));
350 static void eshup6
PROTO((unsigned EMUSHORT
*));
351 static void eshdn6
PROTO((unsigned EMUSHORT
*));
352 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
353 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
354 static void m16m
PROTO((unsigned int, unsigned short *,
356 static int edivm
PROTO((unsigned short *, unsigned short *));
357 static int emulm
PROTO((unsigned short *, unsigned short *));
358 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
359 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
360 unsigned EMUSHORT
*));
361 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
362 unsigned EMUSHORT
*));
363 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
364 unsigned EMUSHORT
*));
365 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
366 unsigned EMUSHORT
*));
367 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
368 unsigned EMUSHORT
*));
369 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
370 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
371 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
372 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
373 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
374 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
375 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
376 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
378 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
379 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
380 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
381 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
382 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
383 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
384 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
385 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
386 unsigned EMUSHORT
*));
387 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
388 unsigned EMUSHORT
*));
389 static int eshift
PROTO((unsigned EMUSHORT
*, int));
390 static int enormlz
PROTO((unsigned EMUSHORT
*));
391 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
392 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
393 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
394 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
395 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
396 static void asctoe24
PROTO((char *, unsigned EMUSHORT
*));
397 static void asctoe53
PROTO((char *, unsigned EMUSHORT
*));
398 static void asctoe64
PROTO((char *, unsigned EMUSHORT
*));
399 static void asctoe113
PROTO((char *, unsigned EMUSHORT
*));
400 static void asctoe
PROTO((char *, unsigned EMUSHORT
*));
401 static void asctoeg
PROTO((char *, unsigned EMUSHORT
*, int));
402 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
404 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
405 unsigned EMUSHORT
*));
407 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
409 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
410 unsigned EMUSHORT
*));
412 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
413 static void mtherr
PROTO((char *, int));
415 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
416 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
417 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
420 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
422 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
424 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
428 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
430 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
432 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
435 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
437 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
438 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
439 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
440 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
441 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
444 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
445 swapping ends if required, into output array of longs. The
446 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
450 unsigned EMUSHORT e
[];
452 enum machine_mode mode
;
456 if (REAL_WORDS_BIG_ENDIAN
)
461 /* Swap halfwords in the fourth long. */
462 th
= (unsigned long) e
[6] & 0xffff;
463 t
= (unsigned long) e
[7] & 0xffff;
468 /* Swap halfwords in the third long. */
469 th
= (unsigned long) e
[4] & 0xffff;
470 t
= (unsigned long) e
[5] & 0xffff;
473 /* fall into the double case */
476 /* Swap halfwords in the second word. */
477 th
= (unsigned long) e
[2] & 0xffff;
478 t
= (unsigned long) e
[3] & 0xffff;
481 /* fall into the float case */
485 /* Swap halfwords in the first word. */
486 th
= (unsigned long) e
[0] & 0xffff;
487 t
= (unsigned long) e
[1] & 0xffff;
498 /* Pack the output array without swapping. */
503 /* Pack the fourth long. */
504 th
= (unsigned long) e
[7] & 0xffff;
505 t
= (unsigned long) e
[6] & 0xffff;
510 /* Pack the third long.
511 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
513 th
= (unsigned long) e
[5] & 0xffff;
514 t
= (unsigned long) e
[4] & 0xffff;
517 /* fall into the double case */
520 /* Pack the second long */
521 th
= (unsigned long) e
[3] & 0xffff;
522 t
= (unsigned long) e
[2] & 0xffff;
525 /* fall into the float case */
529 /* Pack the first long */
530 th
= (unsigned long) e
[1] & 0xffff;
531 t
= (unsigned long) e
[0] & 0xffff;
543 /* This is the implementation of the REAL_ARITHMETIC macro. */
546 earith (value
, icode
, r1
, r2
)
547 REAL_VALUE_TYPE
*value
;
552 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
558 /* Return NaN input back to the caller. */
561 PUT_REAL (d1
, value
);
566 PUT_REAL (d2
, value
);
570 code
= (enum tree_code
) icode
;
578 esub (d2
, d1
, v
); /* d1 - d2 */
586 #ifndef REAL_INFINITY
587 if (ecmp (d2
, ezero
) == 0)
590 enan (v
, eisneg (d1
) ^ eisneg (d2
));
597 ediv (d2
, d1
, v
); /* d1/d2 */
600 case MIN_EXPR
: /* min (d1,d2) */
601 if (ecmp (d1
, d2
) < 0)
607 case MAX_EXPR
: /* max (d1,d2) */
608 if (ecmp (d1
, d2
) > 0)
621 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
622 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
628 unsigned EMUSHORT f
[NE
], g
[NE
];
644 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
645 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
651 unsigned EMUSHORT f
[NE
], g
[NE
];
653 unsigned HOST_WIDE_INT l
;
667 /* This is the REAL_VALUE_ATOF function. It converts a decimal string to
668 binary, rounding off as indicated by the machine_mode argument. Then it
669 promotes the rounded value to REAL_VALUE_TYPE. */
676 unsigned EMUSHORT tem
[NE
], e
[NE
];
710 /* Expansion of REAL_NEGATE. */
716 unsigned EMUSHORT e
[NE
];
726 /* Round real toward zero to HOST_WIDE_INT;
727 implements REAL_VALUE_FIX (x). */
733 unsigned EMUSHORT f
[NE
], g
[NE
];
740 warning ("conversion from NaN to int");
748 /* Round real toward zero to unsigned HOST_WIDE_INT
749 implements REAL_VALUE_UNSIGNED_FIX (x).
750 Negative input returns zero. */
752 unsigned HOST_WIDE_INT
756 unsigned EMUSHORT f
[NE
], g
[NE
];
757 unsigned HOST_WIDE_INT l
;
763 warning ("conversion from NaN to unsigned int");
772 /* REAL_VALUE_FROM_INT macro. */
775 ereal_from_int (d
, i
, j
, mode
)
778 enum machine_mode mode
;
780 unsigned EMUSHORT df
[NE
], dg
[NE
];
781 HOST_WIDE_INT low
, high
;
784 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
791 /* complement and add 1 */
798 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
799 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
801 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
806 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
807 Avoid double-rounding errors later by rounding off now from the
808 extra-wide internal format to the requested precision. */
809 switch (GET_MODE_BITSIZE (mode
))
839 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
842 ereal_from_uint (d
, i
, j
, mode
)
844 unsigned HOST_WIDE_INT i
, j
;
845 enum machine_mode mode
;
847 unsigned EMUSHORT df
[NE
], dg
[NE
];
848 unsigned HOST_WIDE_INT low
, high
;
850 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
854 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
860 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
861 Avoid double-rounding errors later by rounding off now from the
862 extra-wide internal format to the requested precision. */
863 switch (GET_MODE_BITSIZE (mode
))
893 /* REAL_VALUE_TO_INT macro. */
896 ereal_to_int (low
, high
, rr
)
897 HOST_WIDE_INT
*low
, *high
;
900 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
907 warning ("conversion from NaN to int");
913 /* convert positive value */
920 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
921 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
922 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
923 emul (df
, dh
, dg
); /* fractional part is the low word */
924 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
927 /* complement and add 1 */
937 /* REAL_VALUE_LDEXP macro. */
944 unsigned EMUSHORT e
[NE
], y
[NE
];
957 /* These routines are conditionally compiled because functions
958 of the same names may be defined in fold-const.c. */
960 #ifdef REAL_ARITHMETIC
962 /* Check for infinity in a REAL_VALUE_TYPE. */
968 unsigned EMUSHORT e
[NE
];
978 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
984 unsigned EMUSHORT e
[NE
];
995 /* Check for a negative REAL_VALUE_TYPE number.
996 This just checks the sign bit, so that -0 counts as negative. */
1002 return ereal_isneg (x
);
1005 /* Expansion of REAL_VALUE_TRUNCATE.
1006 The result is in floating point, rounded to nearest or even. */
1009 real_value_truncate (mode
, arg
)
1010 enum machine_mode mode
;
1011 REAL_VALUE_TYPE arg
;
1013 unsigned EMUSHORT e
[NE
], t
[NE
];
1049 /* If an unsupported type was requested, presume that
1050 the machine files know something useful to do with
1051 the unmodified value. */
1060 /* Try to change R into its exact multiplicative inverse in machine mode
1061 MODE. Return nonzero function value if successful. */
1064 exact_real_inverse (mode
, r
)
1065 enum machine_mode mode
;
1068 unsigned EMUSHORT e
[NE
], einv
[NE
];
1069 REAL_VALUE_TYPE rinv
;
1074 /* Test for input in range. Don't transform IEEE special values. */
1075 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1078 /* Test for a power of 2: all significand bits zero except the MSB.
1079 We are assuming the target has binary (or hex) arithmetic. */
1080 if (e
[NE
- 2] != 0x8000)
1083 for (i
= 0; i
< NE
- 2; i
++)
1089 /* Compute the inverse and truncate it to the required mode. */
1090 ediv (e
, eone
, einv
);
1091 PUT_REAL (einv
, &rinv
);
1092 rinv
= real_value_truncate (mode
, rinv
);
1094 #ifdef CHECK_FLOAT_VALUE
1095 /* This check is not redundant. It may, for example, flush
1096 a supposedly IEEE denormal value to zero. */
1098 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1101 GET_REAL (&rinv
, einv
);
1103 /* Check the bits again, because the truncation might have
1104 generated an arbitrary saturation value on overflow. */
1105 if (einv
[NE
- 2] != 0x8000)
1108 for (i
= 0; i
< NE
- 2; i
++)
1114 /* Fail if the computed inverse is out of range. */
1115 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1118 /* Output the reciprocal and return success flag. */
1122 #endif /* REAL_ARITHMETIC defined */
1124 /* Used for debugging--print the value of R in human-readable format
1133 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1134 fprintf (stderr
, "%s", dstr
);
1138 /* The following routines convert REAL_VALUE_TYPE to the various floating
1139 point formats that are meaningful to supported computers.
1141 The results are returned in 32-bit pieces, each piece stored in a `long'.
1142 This is so they can be printed by statements like
1144 fprintf (file, "%lx, %lx", L[0], L[1]);
1146 that will work on both narrow- and wide-word host computers. */
1148 /* Convert R to a 128-bit long double precision value. The output array L
1149 contains four 32-bit pieces of the result, in the order they would appear
1157 unsigned EMUSHORT e
[NE
];
1161 endian (e
, l
, TFmode
);
1164 /* Convert R to a double extended precision value. The output array L
1165 contains three 32-bit pieces of the result, in the order they would
1166 appear in memory. */
1173 unsigned EMUSHORT e
[NE
];
1177 endian (e
, l
, XFmode
);
1180 /* Convert R to a double precision value. The output array L contains two
1181 32-bit pieces of the result, in the order they would appear in memory. */
1188 unsigned EMUSHORT e
[NE
];
1192 endian (e
, l
, DFmode
);
1195 /* Convert R to a single precision float value stored in the least-significant
1196 bits of a `long'. */
1202 unsigned EMUSHORT e
[NE
];
1207 endian (e
, &l
, SFmode
);
1211 /* Convert X to a decimal ASCII string S for output to an assembly
1212 language file. Note, there is no standard way to spell infinity or
1213 a NaN, so these values may require special treatment in the tm.h
1217 ereal_to_decimal (x
, s
)
1221 unsigned EMUSHORT e
[NE
];
1227 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1228 or -2 if either is a NaN. */
1232 REAL_VALUE_TYPE x
, y
;
1234 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1238 return (ecmp (ex
, ey
));
1241 /* Return 1 if the sign bit of X is set, else return 0. */
1247 unsigned EMUSHORT ex
[NE
];
1250 return (eisneg (ex
));
1253 /* End of REAL_ARITHMETIC interface */
1256 Extended precision IEEE binary floating point arithmetic routines
1258 Numbers are stored in C language as arrays of 16-bit unsigned
1259 short integers. The arguments of the routines are pointers to
1262 External e type data structure, similar to Intel 8087 chip
1263 temporary real format but possibly with a larger significand:
1265 NE-1 significand words (least significant word first,
1266 most significant bit is normally set)
1267 exponent (value = EXONE for 1.0,
1268 top bit is the sign)
1271 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1273 ei[0] sign word (0 for positive, 0xffff for negative)
1274 ei[1] biased exponent (value = EXONE for the number 1.0)
1275 ei[2] high guard word (always zero after normalization)
1277 to ei[NI-2] significand (NI-4 significand words,
1278 most significant word first,
1279 most significant bit is set)
1280 ei[NI-1] low guard word (0x8000 bit is rounding place)
1284 Routines for external format e-type numbers
1286 asctoe (string, e) ASCII string to extended double e type
1287 asctoe64 (string, &d) ASCII string to long double
1288 asctoe53 (string, &d) ASCII string to double
1289 asctoe24 (string, &f) ASCII string to single
1290 asctoeg (string, e, prec) ASCII string to specified precision
1291 e24toe (&f, e) IEEE single precision to e type
1292 e53toe (&d, e) IEEE double precision to e type
1293 e64toe (&d, e) IEEE long double precision to e type
1294 e113toe (&d, e) 128-bit long double precision to e type
1295 eabs (e) absolute value
1296 eadd (a, b, c) c = b + a
1298 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1299 -1 if a < b, -2 if either a or b is a NaN.
1300 ediv (a, b, c) c = b / a
1301 efloor (a, b) truncate to integer, toward -infinity
1302 efrexp (a, exp, s) extract exponent and significand
1303 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1304 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1305 einfin (e) set e to infinity, leaving its sign alone
1306 eldexp (a, n, b) multiply by 2**n
1308 emul (a, b, c) c = b * a
1310 eround (a, b) b = nearest integer value to a
1311 esub (a, b, c) c = b - a
1312 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1313 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1314 e64toasc (&d, str, n) 80-bit long double to ASCII string
1315 e113toasc (&d, str, n) 128-bit long double to ASCII string
1316 etoasc (e, str, n) e to ASCII string, n digits after decimal
1317 etoe24 (e, &f) convert e type to IEEE single precision
1318 etoe53 (e, &d) convert e type to IEEE double precision
1319 etoe64 (e, &d) convert e type to IEEE long double precision
1320 ltoe (&l, e) HOST_WIDE_INT to e type
1321 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1322 eisneg (e) 1 if sign bit of e != 0, else 0
1323 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1324 or is infinite (IEEE)
1325 eisnan (e) 1 if e is a NaN
1328 Routines for internal format exploded e-type numbers
1330 eaddm (ai, bi) add significands, bi = bi + ai
1332 ecleazs (ei) set ei = 0 but leave its sign alone
1333 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1334 edivm (ai, bi) divide significands, bi = bi / ai
1335 emdnorm (ai,l,s,exp) normalize and round off
1336 emovi (a, ai) convert external a to internal ai
1337 emovo (ai, a) convert internal ai to external a
1338 emovz (ai, bi) bi = ai, low guard word of bi = 0
1339 emulm (ai, bi) multiply significands, bi = bi * ai
1340 enormlz (ei) left-justify the significand
1341 eshdn1 (ai) shift significand and guards down 1 bit
1342 eshdn8 (ai) shift down 8 bits
1343 eshdn6 (ai) shift down 16 bits
1344 eshift (ai, n) shift ai n bits up (or down if n < 0)
1345 eshup1 (ai) shift significand and guards up 1 bit
1346 eshup8 (ai) shift up 8 bits
1347 eshup6 (ai) shift up 16 bits
1348 esubm (ai, bi) subtract significands, bi = bi - ai
1349 eiisinf (ai) 1 if infinite
1350 eiisnan (ai) 1 if a NaN
1351 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1352 einan (ai) set ai = NaN
1353 eiinfin (ai) set ai = infinity
1355 The result is always normalized and rounded to NI-4 word precision
1356 after each arithmetic operation.
1358 Exception flags are NOT fully supported.
1360 Signaling NaN's are NOT supported; they are treated the same
1363 Define INFINITY for support of infinity; otherwise a
1364 saturation arithmetic is implemented.
1366 Define NANS for support of Not-a-Number items; otherwise the
1367 arithmetic will never produce a NaN output, and might be confused
1369 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1370 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1371 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1374 Denormals are always supported here where appropriate (e.g., not
1375 for conversion to DEC numbers). */
1377 /* Definitions for error codes that are passed to the common error handling
1380 For Digital Equipment PDP-11 and VAX computers, certain
1381 IBM systems, and others that use numbers with a 56-bit
1382 significand, the symbol DEC should be defined. In this
1383 mode, most floating point constants are given as arrays
1384 of octal integers to eliminate decimal to binary conversion
1385 errors that might be introduced by the compiler.
1387 For computers, such as IBM PC, that follow the IEEE
1388 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1389 Std 754-1985), the symbol IEEE should be defined.
1390 These numbers have 53-bit significands. In this mode, constants
1391 are provided as arrays of hexadecimal 16 bit integers.
1392 The endian-ness of generated values is controlled by
1393 REAL_WORDS_BIG_ENDIAN.
1395 To accommodate other types of computer arithmetic, all
1396 constants are also provided in a normal decimal radix
1397 which one can hope are correctly converted to a suitable
1398 format by the available C language compiler. To invoke
1399 this mode, the symbol UNK is defined.
1401 An important difference among these modes is a predefined
1402 set of machine arithmetic constants for each. The numbers
1403 MACHEP (the machine roundoff error), MAXNUM (largest number
1404 represented), and several other parameters are preset by
1405 the configuration symbol. Check the file const.c to
1406 ensure that these values are correct for your computer.
1408 For ANSI C compatibility, define ANSIC equal to 1. Currently
1409 this affects only the atan2 function and others that use it. */
1411 /* Constant definitions for math error conditions. */
1413 #define DOMAIN 1 /* argument domain error */
1414 #define SING 2 /* argument singularity */
1415 #define OVERFLOW 3 /* overflow range error */
1416 #define UNDERFLOW 4 /* underflow range error */
1417 #define TLOSS 5 /* total loss of precision */
1418 #define PLOSS 6 /* partial loss of precision */
1419 #define INVALID 7 /* NaN-producing operation */
1421 /* e type constants used by high precision check routines */
1423 #if LONG_DOUBLE_TYPE_SIZE == 128
1425 unsigned EMUSHORT ezero
[NE
] =
1426 {0x0000, 0x0000, 0x0000, 0x0000,
1427 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1428 extern unsigned EMUSHORT ezero
[];
1431 unsigned EMUSHORT ehalf
[NE
] =
1432 {0x0000, 0x0000, 0x0000, 0x0000,
1433 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1434 extern unsigned EMUSHORT ehalf
[];
1437 unsigned EMUSHORT eone
[NE
] =
1438 {0x0000, 0x0000, 0x0000, 0x0000,
1439 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1440 extern unsigned EMUSHORT eone
[];
1443 unsigned EMUSHORT etwo
[NE
] =
1444 {0x0000, 0x0000, 0x0000, 0x0000,
1445 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1446 extern unsigned EMUSHORT etwo
[];
1449 unsigned EMUSHORT e32
[NE
] =
1450 {0x0000, 0x0000, 0x0000, 0x0000,
1451 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1452 extern unsigned EMUSHORT e32
[];
1454 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1455 unsigned EMUSHORT elog2
[NE
] =
1456 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1457 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1458 extern unsigned EMUSHORT elog2
[];
1460 /* 1.41421356237309504880168872420969807856967187537695E0 */
1461 unsigned EMUSHORT esqrt2
[NE
] =
1462 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1463 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1464 extern unsigned EMUSHORT esqrt2
[];
1466 /* 3.14159265358979323846264338327950288419716939937511E0 */
1467 unsigned EMUSHORT epi
[NE
] =
1468 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1469 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1470 extern unsigned EMUSHORT epi
[];
1473 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1474 unsigned EMUSHORT ezero
[NE
] =
1475 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1476 unsigned EMUSHORT ehalf
[NE
] =
1477 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1478 unsigned EMUSHORT eone
[NE
] =
1479 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1480 unsigned EMUSHORT etwo
[NE
] =
1481 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1482 unsigned EMUSHORT e32
[NE
] =
1483 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1484 unsigned EMUSHORT elog2
[NE
] =
1485 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1486 unsigned EMUSHORT esqrt2
[NE
] =
1487 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1488 unsigned EMUSHORT epi
[NE
] =
1489 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1492 /* Control register for rounding precision.
1493 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1498 /* Clear out entire e-type number X. */
1502 register unsigned EMUSHORT
*x
;
1506 for (i
= 0; i
< NE
; i
++)
1510 /* Move e-type number from A to B. */
1514 register unsigned EMUSHORT
*a
, *b
;
1518 for (i
= 0; i
< NE
; i
++)
1523 /* Absolute value of e-type X. */
1527 unsigned EMUSHORT x
[];
1529 /* sign is top bit of last word of external format */
1530 x
[NE
- 1] &= 0x7fff;
1533 /* Negate the e-type number X. */
1537 unsigned EMUSHORT x
[];
1540 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1543 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1547 unsigned EMUSHORT x
[];
1550 if (x
[NE
- 1] & 0x8000)
1556 /* Return 1 if e-type number X is infinity, else return zero. */
1560 unsigned EMUSHORT x
[];
1567 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1573 /* Check if e-type number is not a number. The bit pattern is one that we
1574 defined, so we know for sure how to detect it. */
1578 unsigned EMUSHORT x
[];
1583 /* NaN has maximum exponent */
1584 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1586 /* ... and non-zero significand field. */
1587 for (i
= 0; i
< NE
- 1; i
++)
1597 /* Fill e-type number X with infinity pattern (IEEE)
1598 or largest possible number (non-IEEE). */
1602 register unsigned EMUSHORT
*x
;
1607 for (i
= 0; i
< NE
- 1; i
++)
1611 for (i
= 0; i
< NE
- 1; i
++)
1639 /* Output an e-type NaN.
1640 This generates Intel's quiet NaN pattern for extended real.
1641 The exponent is 7fff, the leading mantissa word is c000. */
1645 register unsigned EMUSHORT
*x
;
1650 for (i
= 0; i
< NE
- 2; i
++)
1653 *x
= (sign
<< 15) | 0x7fff;
1656 /* Move in an e-type number A, converting it to exploded e-type B. */
1660 unsigned EMUSHORT
*a
, *b
;
1662 register unsigned EMUSHORT
*p
, *q
;
1666 p
= a
+ (NE
- 1); /* point to last word of external number */
1667 /* get the sign bit */
1672 /* get the exponent */
1674 *q
++ &= 0x7fff; /* delete the sign bit */
1676 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1682 for (i
= 3; i
< NI
; i
++)
1688 for (i
= 2; i
< NI
; i
++)
1694 /* clear high guard word */
1696 /* move in the significand */
1697 for (i
= 0; i
< NE
- 1; i
++)
1699 /* clear low guard word */
1703 /* Move out exploded e-type number A, converting it to e type B. */
1707 unsigned EMUSHORT
*a
, *b
;
1709 register unsigned EMUSHORT
*p
, *q
;
1710 unsigned EMUSHORT i
;
1714 q
= b
+ (NE
- 1); /* point to output exponent */
1715 /* combine sign and exponent */
1718 *q
-- = *p
++ | 0x8000;
1722 if (*(p
- 1) == 0x7fff)
1727 enan (b
, eiisneg (a
));
1735 /* skip over guard word */
1737 /* move the significand */
1738 for (j
= 0; j
< NE
- 1; j
++)
1742 /* Clear out exploded e-type number XI. */
1746 register unsigned EMUSHORT
*xi
;
1750 for (i
= 0; i
< NI
; i
++)
1754 /* Clear out exploded e-type XI, but don't touch the sign. */
1758 register unsigned EMUSHORT
*xi
;
1763 for (i
= 0; i
< NI
- 1; i
++)
1767 /* Move exploded e-type number from A to B. */
1771 register unsigned EMUSHORT
*a
, *b
;
1775 for (i
= 0; i
< NI
- 1; i
++)
1777 /* clear low guard word */
1781 /* Generate exploded e-type NaN.
1782 The explicit pattern for this is maximum exponent and
1783 top two significant bits set. */
1787 unsigned EMUSHORT x
[];
1795 /* Return nonzero if exploded e-type X is a NaN. */
1799 unsigned EMUSHORT x
[];
1803 if ((x
[E
] & 0x7fff) == 0x7fff)
1805 for (i
= M
+ 1; i
< NI
; i
++)
1814 /* Return nonzero if sign of exploded e-type X is nonzero. */
1818 unsigned EMUSHORT x
[];
1824 /* Fill exploded e-type X with infinity pattern.
1825 This has maximum exponent and significand all zeros. */
1829 unsigned EMUSHORT x
[];
1836 /* Return nonzero if exploded e-type X is infinite. */
1840 unsigned EMUSHORT x
[];
1847 if ((x
[E
] & 0x7fff) == 0x7fff)
1853 /* Compare significands of numbers in internal exploded e-type format.
1854 Guard words are included in the comparison.
1862 register unsigned EMUSHORT
*a
, *b
;
1866 a
+= M
; /* skip up to significand area */
1868 for (i
= M
; i
< NI
; i
++)
1876 if (*(--a
) > *(--b
))
1882 /* Shift significand of exploded e-type X down by 1 bit. */
1886 register unsigned EMUSHORT
*x
;
1888 register unsigned EMUSHORT bits
;
1891 x
+= M
; /* point to significand area */
1894 for (i
= M
; i
< NI
; i
++)
1906 /* Shift significand of exploded e-type X up by 1 bit. */
1910 register unsigned EMUSHORT
*x
;
1912 register unsigned EMUSHORT bits
;
1918 for (i
= M
; i
< NI
; i
++)
1931 /* Shift significand of exploded e-type X down by 8 bits. */
1935 register unsigned EMUSHORT
*x
;
1937 register unsigned EMUSHORT newbyt
, oldbyt
;
1942 for (i
= M
; i
< NI
; i
++)
1952 /* Shift significand of exploded e-type X up by 8 bits. */
1956 register unsigned EMUSHORT
*x
;
1959 register unsigned EMUSHORT newbyt
, oldbyt
;
1964 for (i
= M
; i
< NI
; i
++)
1974 /* Shift significand of exploded e-type X up by 16 bits. */
1978 register unsigned EMUSHORT
*x
;
1981 register unsigned EMUSHORT
*p
;
1986 for (i
= M
; i
< NI
- 1; i
++)
1992 /* Shift significand of exploded e-type X down by 16 bits. */
1996 register unsigned EMUSHORT
*x
;
1999 register unsigned EMUSHORT
*p
;
2004 for (i
= M
; i
< NI
- 1; i
++)
2010 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2014 unsigned EMUSHORT
*x
, *y
;
2016 register unsigned EMULONG a
;
2023 for (i
= M
; i
< NI
; i
++)
2025 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2030 *y
= (unsigned EMUSHORT
) a
;
2036 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2040 unsigned EMUSHORT
*x
, *y
;
2049 for (i
= M
; i
< NI
; i
++)
2051 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2056 *y
= (unsigned EMUSHORT
) a
;
2063 static unsigned EMUSHORT equot
[NI
];
2067 /* Radix 2 shift-and-add versions of multiply and divide */
2070 /* Divide significands */
2074 unsigned EMUSHORT den
[], num
[];
2077 register unsigned EMUSHORT
*p
, *q
;
2078 unsigned EMUSHORT j
;
2084 for (i
= M
; i
< NI
; i
++)
2089 /* Use faster compare and subtraction if denominator has only 15 bits of
2095 for (i
= M
+ 3; i
< NI
; i
++)
2100 if ((den
[M
+ 1] & 1) != 0)
2108 for (i
= 0; i
< NBITS
+ 2; i
++)
2126 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2127 bit + 1 roundoff bit. */
2132 for (i
= 0; i
< NBITS
+ 2; i
++)
2134 if (ecmpm (den
, num
) <= 0)
2137 j
= 1; /* quotient bit = 1 */
2151 /* test for nonzero remainder after roundoff bit */
2154 for (i
= M
; i
< NI
; i
++)
2162 for (i
= 0; i
< NI
; i
++)
2168 /* Multiply significands */
2172 unsigned EMUSHORT a
[], b
[];
2174 unsigned EMUSHORT
*p
, *q
;
2179 for (i
= M
; i
< NI
; i
++)
2184 while (*p
== 0) /* significand is not supposed to be zero */
2189 if ((*p
& 0xff) == 0)
2197 for (i
= 0; i
< k
; i
++)
2201 /* remember if there were any nonzero bits shifted out */
2208 for (i
= 0; i
< NI
; i
++)
2211 /* return flag for lost nonzero bits */
2217 /* Radix 65536 versions of multiply and divide. */
2219 /* Multiply significand of e-type number B
2220 by 16-bit quantity A, return e-type result to C. */
2225 unsigned EMUSHORT b
[], c
[];
2227 register unsigned EMUSHORT
*pp
;
2228 register unsigned EMULONG carry
;
2229 unsigned EMUSHORT
*ps
;
2230 unsigned EMUSHORT p
[NI
];
2231 unsigned EMULONG aa
, m
;
2240 for (i
=M
+1; i
<NI
; i
++)
2250 m
= (unsigned EMULONG
) aa
* *ps
--;
2251 carry
= (m
& 0xffff) + *pp
;
2252 *pp
-- = (unsigned EMUSHORT
)carry
;
2253 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2254 *pp
= (unsigned EMUSHORT
)carry
;
2255 *(pp
-1) = carry
>> 16;
2258 for (i
=M
; i
<NI
; i
++)
2262 /* Divide significands of exploded e-types NUM / DEN. Neither the
2263 numerator NUM nor the denominator DEN is permitted to have its high guard
2268 unsigned EMUSHORT den
[], num
[];
2271 register unsigned EMUSHORT
*p
;
2272 unsigned EMULONG tnum
;
2273 unsigned EMUSHORT j
, tdenm
, tquot
;
2274 unsigned EMUSHORT tprod
[NI
+1];
2280 for (i
=M
; i
<NI
; i
++)
2286 for (i
=M
; i
<NI
; i
++)
2288 /* Find trial quotient digit (the radix is 65536). */
2289 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2291 /* Do not execute the divide instruction if it will overflow. */
2292 if ((tdenm
* 0xffffL
) < tnum
)
2295 tquot
= tnum
/ tdenm
;
2296 /* Multiply denominator by trial quotient digit. */
2297 m16m ((unsigned int)tquot
, den
, tprod
);
2298 /* The quotient digit may have been overestimated. */
2299 if (ecmpm (tprod
, num
) > 0)
2303 if (ecmpm (tprod
, num
) > 0)
2313 /* test for nonzero remainder after roundoff bit */
2316 for (i
=M
; i
<NI
; i
++)
2323 for (i
=0; i
<NI
; i
++)
2329 /* Multiply significands of exploded e-type A and B, result in B. */
2333 unsigned EMUSHORT a
[], b
[];
2335 unsigned EMUSHORT
*p
, *q
;
2336 unsigned EMUSHORT pprod
[NI
];
2337 unsigned EMUSHORT j
;
2342 for (i
=M
; i
<NI
; i
++)
2348 for (i
=M
+1; i
<NI
; i
++)
2356 m16m ((unsigned int) *p
--, b
, pprod
);
2357 eaddm(pprod
, equot
);
2363 for (i
=0; i
<NI
; i
++)
2366 /* return flag for lost nonzero bits */
2372 /* Normalize and round off.
2374 The internal format number to be rounded is S.
2375 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2377 Input SUBFLG indicates whether the number was obtained
2378 by a subtraction operation. In that case if LOST is nonzero
2379 then the number is slightly smaller than indicated.
2381 Input EXP is the biased exponent, which may be negative.
2382 the exponent field of S is ignored but is replaced by
2383 EXP as adjusted by normalization and rounding.
2385 Input RCNTRL is the rounding control. If it is nonzero, the
2386 returned value will be rounded to RNDPRC bits.
2388 For future reference: In order for emdnorm to round off denormal
2389 significands at the right point, the input exponent must be
2390 adjusted to be the actual value it would have after conversion to
2391 the final floating point type. This adjustment has been
2392 implemented for all type conversions (etoe53, etc.) and decimal
2393 conversions, but not for the arithmetic functions (eadd, etc.).
2394 Data types having standard 15-bit exponents are not affected by
2395 this, but SFmode and DFmode are affected. For example, ediv with
2396 rndprc = 24 will not round correctly to 24-bit precision if the
2397 result is denormal. */
2399 static int rlast
= -1;
2401 static unsigned EMUSHORT rmsk
= 0;
2402 static unsigned EMUSHORT rmbit
= 0;
2403 static unsigned EMUSHORT rebit
= 0;
2405 static unsigned EMUSHORT rbit
[NI
];
2408 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2409 unsigned EMUSHORT s
[];
2416 unsigned EMUSHORT r
;
2421 /* a blank significand could mean either zero or infinity. */
2434 if ((j
> NBITS
) && (exp
< 32767))
2442 if (exp
> (EMULONG
) (-NBITS
- 1))
2455 /* Round off, unless told not to by rcntrl. */
2458 /* Set up rounding parameters if the control register changed. */
2459 if (rndprc
!= rlast
)
2466 rw
= NI
- 1; /* low guard word */
2489 /* For DEC or IBM arithmetic */
2506 /* For C4x arithmetic */
2527 /* Shift down 1 temporarily if the data structure has an implied
2528 most significant bit and the number is denormal.
2529 Intel long double denormals also lose one bit of precision. */
2530 if ((exp
<= 0) && (rndprc
!= NBITS
)
2531 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2533 lost
|= s
[NI
- 1] & 1;
2536 /* Clear out all bits below the rounding bit,
2537 remembering in r if any were nonzero. */
2551 if ((r
& rmbit
) != 0)
2556 { /* round to even */
2557 if ((s
[re
] & rebit
) == 0)
2569 /* Undo the temporary shift for denormal values. */
2570 if ((exp
<= 0) && (rndprc
!= NBITS
)
2571 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2576 { /* overflow on roundoff */
2589 for (i
= 2; i
< NI
- 1; i
++)
2592 warning ("floating point overflow");
2596 for (i
= M
+ 1; i
< NI
- 1; i
++)
2599 if ((rndprc
< 64) || (rndprc
== 113))
2614 s
[1] = (unsigned EMUSHORT
) exp
;
2617 /* Subtract. C = B - A, all e type numbers. */
2619 static int subflg
= 0;
2623 unsigned EMUSHORT
*a
, *b
, *c
;
2637 /* Infinity minus infinity is a NaN.
2638 Test for subtracting infinities of the same sign. */
2639 if (eisinf (a
) && eisinf (b
)
2640 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2642 mtherr ("esub", INVALID
);
2651 /* Add. C = A + B, all e type. */
2655 unsigned EMUSHORT
*a
, *b
, *c
;
2659 /* NaN plus anything is a NaN. */
2670 /* Infinity minus infinity is a NaN.
2671 Test for adding infinities of opposite signs. */
2672 if (eisinf (a
) && eisinf (b
)
2673 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2675 mtherr ("esub", INVALID
);
2684 /* Arithmetic common to both addition and subtraction. */
2688 unsigned EMUSHORT
*a
, *b
, *c
;
2690 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2692 EMULONG lt
, lta
, ltb
;
2713 /* compare exponents */
2718 { /* put the larger number in bi */
2728 if (lt
< (EMULONG
) (-NBITS
- 1))
2729 goto done
; /* answer same as larger addend */
2731 lost
= eshift (ai
, k
); /* shift the smaller number down */
2735 /* exponents were the same, so must compare significands */
2738 { /* the numbers are identical in magnitude */
2739 /* if different signs, result is zero */
2745 /* if same sign, result is double */
2746 /* double denormalized tiny number */
2747 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2752 /* add 1 to exponent unless both are zero! */
2753 for (j
= 1; j
< NI
- 1; j
++)
2769 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2773 { /* put the larger number in bi */
2789 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2795 /* Divide: C = B/A, all e type. */
2799 unsigned EMUSHORT
*a
, *b
, *c
;
2801 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2803 EMULONG lt
, lta
, ltb
;
2805 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2806 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2807 sign
= eisneg(a
) ^ eisneg(b
);
2810 /* Return any NaN input. */
2821 /* Zero over zero, or infinity over infinity, is a NaN. */
2822 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2823 || (eisinf (a
) && eisinf (b
)))
2825 mtherr ("ediv", INVALID
);
2830 /* Infinity over anything else is infinity. */
2837 /* Anything else over infinity is zero. */
2849 { /* See if numerator is zero. */
2850 for (i
= 1; i
< NI
- 1; i
++)
2854 ltb
-= enormlz (bi
);
2864 { /* possible divide by zero */
2865 for (i
= 1; i
< NI
- 1; i
++)
2869 lta
-= enormlz (ai
);
2873 /* Divide by zero is not an invalid operation.
2874 It is a divide-by-zero operation! */
2876 mtherr ("ediv", SING
);
2882 /* calculate exponent */
2883 lt
= ltb
- lta
+ EXONE
;
2884 emdnorm (bi
, i
, 0, lt
, 64);
2891 && (ecmp (c
, ezero
) != 0)
2894 *(c
+(NE
-1)) |= 0x8000;
2896 *(c
+(NE
-1)) &= ~0x8000;
2899 /* Multiply e-types A and B, return e-type product C. */
2903 unsigned EMUSHORT
*a
, *b
, *c
;
2905 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2907 EMULONG lt
, lta
, ltb
;
2909 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2910 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2911 sign
= eisneg(a
) ^ eisneg(b
);
2914 /* NaN times anything is the same NaN. */
2925 /* Zero times infinity is a NaN. */
2926 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2927 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2929 mtherr ("emul", INVALID
);
2934 /* Infinity times anything else is infinity. */
2936 if (eisinf (a
) || eisinf (b
))
2948 for (i
= 1; i
< NI
- 1; i
++)
2952 lta
-= enormlz (ai
);
2963 for (i
= 1; i
< NI
- 1; i
++)
2967 ltb
-= enormlz (bi
);
2976 /* Multiply significands */
2978 /* calculate exponent */
2979 lt
= lta
+ ltb
- (EXONE
- 1);
2980 emdnorm (bi
, j
, 0, lt
, 64);
2987 && (ecmp (c
, ezero
) != 0)
2990 *(c
+(NE
-1)) |= 0x8000;
2992 *(c
+(NE
-1)) &= ~0x8000;
2995 /* Convert double precision PE to e-type Y. */
2999 unsigned EMUSHORT
*pe
, *y
;
3008 ibmtoe (pe
, y
, DFmode
);
3013 c4xtoe (pe
, y
, HFmode
);
3016 register unsigned EMUSHORT r
;
3017 register unsigned EMUSHORT
*e
, *p
;
3018 unsigned EMUSHORT yy
[NI
];
3022 denorm
= 0; /* flag if denormalized number */
3024 if (! REAL_WORDS_BIG_ENDIAN
)
3030 yy
[M
] = (r
& 0x0f) | 0x10;
3031 r
&= ~0x800f; /* strip sign and 4 significand bits */
3036 if (! REAL_WORDS_BIG_ENDIAN
)
3038 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3039 || (pe
[1] != 0) || (pe
[0] != 0))
3041 enan (y
, yy
[0] != 0);
3047 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3048 || (pe
[2] != 0) || (pe
[3] != 0))
3050 enan (y
, yy
[0] != 0);
3061 #endif /* INFINITY */
3063 /* If zero exponent, then the significand is denormalized.
3064 So take back the understood high significand bit. */
3075 if (! REAL_WORDS_BIG_ENDIAN
)
3092 /* If zero exponent, then normalize the significand. */
3093 if ((k
= enormlz (yy
)) > NBITS
)
3096 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3099 #endif /* not C4X */
3100 #endif /* not IBM */
3101 #endif /* not DEC */
3104 /* Convert double extended precision float PE to e type Y. */
3108 unsigned EMUSHORT
*pe
, *y
;
3110 unsigned EMUSHORT yy
[NI
];
3111 unsigned EMUSHORT
*e
, *p
, *q
;
3116 for (i
= 0; i
< NE
- 5; i
++)
3118 /* This precision is not ordinarily supported on DEC or IBM. */
3120 for (i
= 0; i
< 5; i
++)
3124 p
= &yy
[0] + (NE
- 1);
3127 for (i
= 0; i
< 5; i
++)
3131 if (! REAL_WORDS_BIG_ENDIAN
)
3133 for (i
= 0; i
< 5; i
++)
3136 /* For denormal long double Intel format, shift significand up one
3137 -- but only if the top significand bit is zero. A top bit of 1
3138 is "pseudodenormal" when the exponent is zero. */
3139 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3141 unsigned EMUSHORT temp
[NI
];
3151 p
= &yy
[0] + (NE
- 1);
3152 #ifdef ARM_EXTENDED_IEEE_FORMAT
3153 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3154 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3160 for (i
= 0; i
< 4; i
++)
3165 /* Point to the exponent field and check max exponent cases. */
3167 if ((*p
& 0x7fff) == 0x7fff)
3170 if (! REAL_WORDS_BIG_ENDIAN
)
3172 for (i
= 0; i
< 4; i
++)
3174 if ((i
!= 3 && pe
[i
] != 0)
3175 /* Anything but 0x8000 here, including 0, is a NaN. */
3176 || (i
== 3 && pe
[i
] != 0x8000))
3178 enan (y
, (*p
& 0x8000) != 0);
3185 #ifdef ARM_EXTENDED_IEEE_FORMAT
3186 for (i
= 2; i
<= 5; i
++)
3190 enan (y
, (*p
& 0x8000) != 0);
3195 /* In Motorola extended precision format, the most significant
3196 bit of an infinity mantissa could be either 1 or 0. It is
3197 the lower order bits that tell whether the value is a NaN. */
3198 if ((pe
[2] & 0x7fff) != 0)
3201 for (i
= 3; i
<= 5; i
++)
3206 enan (y
, (*p
& 0x8000) != 0);
3210 #endif /* not ARM */
3219 #endif /* INFINITY */
3222 for (i
= 0; i
< NE
; i
++)
3226 /* Convert 128-bit long double precision float PE to e type Y. */
3230 unsigned EMUSHORT
*pe
, *y
;
3232 register unsigned EMUSHORT r
;
3233 unsigned EMUSHORT
*e
, *p
;
3234 unsigned EMUSHORT yy
[NI
];
3241 if (! REAL_WORDS_BIG_ENDIAN
)
3253 if (! REAL_WORDS_BIG_ENDIAN
)
3255 for (i
= 0; i
< 7; i
++)
3259 enan (y
, yy
[0] != 0);
3266 for (i
= 1; i
< 8; i
++)
3270 enan (y
, yy
[0] != 0);
3282 #endif /* INFINITY */
3286 if (! REAL_WORDS_BIG_ENDIAN
)
3288 for (i
= 0; i
< 7; i
++)
3294 for (i
= 0; i
< 7; i
++)
3298 /* If denormal, remove the implied bit; else shift down 1. */
3311 /* Convert single precision float PE to e type Y. */
3315 unsigned EMUSHORT
*pe
, *y
;
3319 ibmtoe (pe
, y
, SFmode
);
3325 c4xtoe (pe
, y
, QFmode
);
3329 register unsigned EMUSHORT r
;
3330 register unsigned EMUSHORT
*e
, *p
;
3331 unsigned EMUSHORT yy
[NI
];
3335 denorm
= 0; /* flag if denormalized number */
3338 if (! REAL_WORDS_BIG_ENDIAN
)
3348 yy
[M
] = (r
& 0x7f) | 0200;
3349 r
&= ~0x807f; /* strip sign and 7 significand bits */
3354 if (REAL_WORDS_BIG_ENDIAN
)
3356 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3358 enan (y
, yy
[0] != 0);
3364 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3366 enan (y
, yy
[0] != 0);
3377 #endif /* INFINITY */
3379 /* If zero exponent, then the significand is denormalized.
3380 So take back the understood high significand bit. */
3393 if (! REAL_WORDS_BIG_ENDIAN
)
3403 { /* if zero exponent, then normalize the significand */
3404 if ((k
= enormlz (yy
)) > NBITS
)
3407 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3410 #endif /* not C4X */
3411 #endif /* not IBM */
3414 /* Convert e-type X to IEEE 128-bit long double format E. */
3418 unsigned EMUSHORT
*x
, *e
;
3420 unsigned EMUSHORT xi
[NI
];
3427 make_nan (e
, eisneg (x
), TFmode
);
3432 exp
= (EMULONG
) xi
[E
];
3437 /* round off to nearest or even */
3440 emdnorm (xi
, 0, 0, exp
, 64);
3446 /* Convert exploded e-type X, that has already been rounded to
3447 113-bit precision, to IEEE 128-bit long double format Y. */
3451 unsigned EMUSHORT
*a
, *b
;
3453 register unsigned EMUSHORT
*p
, *q
;
3454 unsigned EMUSHORT i
;
3459 make_nan (b
, eiisneg (a
), TFmode
);
3464 if (REAL_WORDS_BIG_ENDIAN
)
3467 q
= b
+ 7; /* point to output exponent */
3469 /* If not denormal, delete the implied bit. */
3474 /* combine sign and exponent */
3476 if (REAL_WORDS_BIG_ENDIAN
)
3479 *q
++ = *p
++ | 0x8000;
3486 *q
-- = *p
++ | 0x8000;
3490 /* skip over guard word */
3492 /* move the significand */
3493 if (REAL_WORDS_BIG_ENDIAN
)
3495 for (i
= 0; i
< 7; i
++)
3500 for (i
= 0; i
< 7; i
++)
3505 /* Convert e-type X to IEEE double extended format E. */
3509 unsigned EMUSHORT
*x
, *e
;
3511 unsigned EMUSHORT xi
[NI
];
3518 make_nan (e
, eisneg (x
), XFmode
);
3523 /* adjust exponent for offset */
3524 exp
= (EMULONG
) xi
[E
];
3529 /* round off to nearest or even */
3532 emdnorm (xi
, 0, 0, exp
, 64);
3538 /* Convert exploded e-type X, that has already been rounded to
3539 64-bit precision, to IEEE double extended format Y. */
3543 unsigned EMUSHORT
*a
, *b
;
3545 register unsigned EMUSHORT
*p
, *q
;
3546 unsigned EMUSHORT i
;
3551 make_nan (b
, eiisneg (a
), XFmode
);
3555 /* Shift denormal long double Intel format significand down one bit. */
3556 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3566 if (REAL_WORDS_BIG_ENDIAN
)
3570 q
= b
+ 4; /* point to output exponent */
3571 #if LONG_DOUBLE_TYPE_SIZE == 96
3572 /* Clear the last two bytes of 12-byte Intel format */
3578 /* combine sign and exponent */
3582 *q
++ = *p
++ | 0x8000;
3589 *q
-- = *p
++ | 0x8000;
3594 if (REAL_WORDS_BIG_ENDIAN
)
3596 #ifdef ARM_EXTENDED_IEEE_FORMAT
3597 /* The exponent is in the lowest 15 bits of the first word. */
3598 *q
++ = i
? 0x8000 : 0;
3602 *q
++ = *p
++ | 0x8000;
3611 *q
-- = *p
++ | 0x8000;
3616 /* skip over guard word */
3618 /* move the significand */
3620 for (i
= 0; i
< 4; i
++)
3624 for (i
= 0; i
< 4; i
++)
3628 if (REAL_WORDS_BIG_ENDIAN
)
3630 for (i
= 0; i
< 4; i
++)
3638 /* Intel long double infinity significand. */
3646 for (i
= 0; i
< 4; i
++)
3652 /* e type to double precision. */
3655 /* Convert e-type X to DEC-format double E. */
3659 unsigned EMUSHORT
*x
, *e
;
3661 etodec (x
, e
); /* see etodec.c */
3664 /* Convert exploded e-type X, that has already been rounded to
3665 56-bit double precision, to DEC double Y. */
3669 unsigned EMUSHORT
*x
, *y
;
3676 /* Convert e-type X to IBM 370-format double E. */
3680 unsigned EMUSHORT
*x
, *e
;
3682 etoibm (x
, e
, DFmode
);
3685 /* Convert exploded e-type X, that has already been rounded to
3686 56-bit precision, to IBM 370 double Y. */
3690 unsigned EMUSHORT
*x
, *y
;
3692 toibm (x
, y
, DFmode
);
3695 #else /* it's neither DEC nor IBM */
3697 /* Convert e-type X to C4X-format double E. */
3701 unsigned EMUSHORT
*x
, *e
;
3703 etoc4x (x
, e
, HFmode
);
3706 /* Convert exploded e-type X, that has already been rounded to
3707 56-bit precision, to IBM 370 double Y. */
3711 unsigned EMUSHORT
*x
, *y
;
3713 toc4x (x
, y
, HFmode
);
3716 #else /* it's neither DEC nor IBM nor C4X */
3718 /* Convert e-type X to IEEE double E. */
3722 unsigned EMUSHORT
*x
, *e
;
3724 unsigned EMUSHORT xi
[NI
];
3731 make_nan (e
, eisneg (x
), DFmode
);
3736 /* adjust exponent for offsets */
3737 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3742 /* round off to nearest or even */
3745 emdnorm (xi
, 0, 0, exp
, 64);
3751 /* Convert exploded e-type X, that has already been rounded to
3752 53-bit precision, to IEEE double Y. */
3756 unsigned EMUSHORT
*x
, *y
;
3758 unsigned EMUSHORT i
;
3759 unsigned EMUSHORT
*p
;
3764 make_nan (y
, eiisneg (x
), DFmode
);
3770 if (! REAL_WORDS_BIG_ENDIAN
)
3773 *y
= 0; /* output high order */
3775 *y
= 0x8000; /* output sign bit */
3778 if (i
>= (unsigned int) 2047)
3780 /* Saturate at largest number less than infinity. */
3783 if (! REAL_WORDS_BIG_ENDIAN
)
3797 *y
|= (unsigned EMUSHORT
) 0x7fef;
3798 if (! REAL_WORDS_BIG_ENDIAN
)
3823 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3824 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3825 if (! REAL_WORDS_BIG_ENDIAN
)
3840 #endif /* not C4X */
3841 #endif /* not IBM */
3842 #endif /* not DEC */
3846 /* e type to single precision. */
3849 /* Convert e-type X to IBM 370 float E. */
3853 unsigned EMUSHORT
*x
, *e
;
3855 etoibm (x
, e
, SFmode
);
3858 /* Convert exploded e-type X, that has already been rounded to
3859 float precision, to IBM 370 float Y. */
3863 unsigned EMUSHORT
*x
, *y
;
3865 toibm (x
, y
, SFmode
);
3871 /* Convert e-type X to C4X float E. */
3875 unsigned EMUSHORT
*x
, *e
;
3877 etoc4x (x
, e
, QFmode
);
3880 /* Convert exploded e-type X, that has already been rounded to
3881 float precision, to IBM 370 float Y. */
3885 unsigned EMUSHORT
*x
, *y
;
3887 toc4x (x
, y
, QFmode
);
3892 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3896 unsigned EMUSHORT
*x
, *e
;
3899 unsigned EMUSHORT xi
[NI
];
3905 make_nan (e
, eisneg (x
), SFmode
);
3910 /* adjust exponent for offsets */
3911 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3916 /* round off to nearest or even */
3919 emdnorm (xi
, 0, 0, exp
, 64);
3925 /* Convert exploded e-type X, that has already been rounded to
3926 float precision, to IEEE float Y. */
3930 unsigned EMUSHORT
*x
, *y
;
3932 unsigned EMUSHORT i
;
3933 unsigned EMUSHORT
*p
;
3938 make_nan (y
, eiisneg (x
), SFmode
);
3944 if (! REAL_WORDS_BIG_ENDIAN
)
3950 *y
= 0; /* output high order */
3952 *y
= 0x8000; /* output sign bit */
3955 /* Handle overflow cases. */
3959 *y
|= (unsigned EMUSHORT
) 0x7f80;
3964 if (! REAL_WORDS_BIG_ENDIAN
)
3972 #else /* no INFINITY */
3973 *y
|= (unsigned EMUSHORT
) 0x7f7f;
3978 if (! REAL_WORDS_BIG_ENDIAN
)
3989 #endif /* no INFINITY */
4001 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4002 /* High order output already has sign bit set. */
4008 if (! REAL_WORDS_BIG_ENDIAN
)
4017 #endif /* not C4X */
4018 #endif /* not IBM */
4020 /* Compare two e type numbers.
4024 -2 if either a or b is a NaN. */
4028 unsigned EMUSHORT
*a
, *b
;
4030 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4031 register unsigned EMUSHORT
*p
, *q
;
4036 if (eisnan (a
) || eisnan (b
))
4045 { /* the signs are different */
4047 for (i
= 1; i
< NI
- 1; i
++)
4061 /* both are the same sign */
4076 return (0); /* equality */
4080 if (*(--p
) > *(--q
))
4081 return (msign
); /* p is bigger */
4083 return (-msign
); /* p is littler */
4086 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4090 unsigned EMUSHORT
*x
, *y
;
4096 /* Convert HOST_WIDE_INT LP to e type Y. */
4101 unsigned EMUSHORT
*y
;
4103 unsigned EMUSHORT yi
[NI
];
4104 unsigned HOST_WIDE_INT ll
;
4110 /* make it positive */
4111 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4112 yi
[0] = 0xffff; /* put correct sign in the e type number */
4116 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4118 /* move the long integer to yi significand area */
4119 #if HOST_BITS_PER_WIDE_INT == 64
4120 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4121 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4122 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4123 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4124 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4126 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4127 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4128 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4131 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4132 ecleaz (yi
); /* it was zero */
4134 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4135 emovo (yi
, y
); /* output the answer */
4138 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4142 unsigned HOST_WIDE_INT
*lp
;
4143 unsigned EMUSHORT
*y
;
4145 unsigned EMUSHORT yi
[NI
];
4146 unsigned HOST_WIDE_INT ll
;
4152 /* move the long integer to ayi significand area */
4153 #if HOST_BITS_PER_WIDE_INT == 64
4154 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4155 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4156 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4157 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4158 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4160 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4161 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4162 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4165 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4166 ecleaz (yi
); /* it was zero */
4168 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4169 emovo (yi
, y
); /* output the answer */
4173 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4174 part FRAC of e-type (packed internal format) floating point input X.
4175 The integer output I has the sign of the input, except that
4176 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4177 The output e-type fraction FRAC is the positive fractional
4182 unsigned EMUSHORT
*x
;
4184 unsigned EMUSHORT
*frac
;
4186 unsigned EMUSHORT xi
[NI
];
4188 unsigned HOST_WIDE_INT ll
;
4191 k
= (int) xi
[E
] - (EXONE
- 1);
4194 /* if exponent <= 0, integer = 0 and real output is fraction */
4199 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4201 /* long integer overflow: output large integer
4202 and correct fraction */
4204 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4207 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4208 /* In this case, let it overflow and convert as if unsigned. */
4209 euifrac (x
, &ll
, frac
);
4210 *i
= (HOST_WIDE_INT
) ll
;
4213 /* In other cases, return the largest positive integer. */
4214 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4219 warning ("overflow on truncation to integer");
4223 /* Shift more than 16 bits: first shift up k-16 mod 16,
4224 then shift up by 16's. */
4225 j
= k
- ((k
>> 4) << 4);
4232 ll
= (ll
<< 16) | xi
[M
];
4234 while ((k
-= 16) > 0);
4241 /* shift not more than 16 bits */
4243 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4250 if ((k
= enormlz (xi
)) > NBITS
)
4253 xi
[E
] -= (unsigned EMUSHORT
) k
;
4259 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4260 FRAC of e-type X. A negative input yields integer output = 0 but
4261 correct fraction. */
4264 euifrac (x
, i
, frac
)
4265 unsigned EMUSHORT
*x
;
4266 unsigned HOST_WIDE_INT
*i
;
4267 unsigned EMUSHORT
*frac
;
4269 unsigned HOST_WIDE_INT ll
;
4270 unsigned EMUSHORT xi
[NI
];
4274 k
= (int) xi
[E
] - (EXONE
- 1);
4277 /* if exponent <= 0, integer = 0 and argument is fraction */
4282 if (k
> HOST_BITS_PER_WIDE_INT
)
4284 /* Long integer overflow: output large integer
4285 and correct fraction.
4286 Note, the BSD microvax compiler says that ~(0UL)
4287 is a syntax error. */
4291 warning ("overflow on truncation to unsigned integer");
4295 /* Shift more than 16 bits: first shift up k-16 mod 16,
4296 then shift up by 16's. */
4297 j
= k
- ((k
>> 4) << 4);
4304 ll
= (ll
<< 16) | xi
[M
];
4306 while ((k
-= 16) > 0);
4311 /* shift not more than 16 bits */
4313 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4316 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4322 if ((k
= enormlz (xi
)) > NBITS
)
4325 xi
[E
] -= (unsigned EMUSHORT
) k
;
4330 /* Shift the significand of exploded e-type X up or down by SC bits. */
4334 unsigned EMUSHORT
*x
;
4337 unsigned EMUSHORT lost
;
4338 unsigned EMUSHORT
*p
;
4351 lost
|= *p
; /* remember lost bits */
4392 return ((int) lost
);
4395 /* Shift normalize the significand area of exploded e-type X.
4396 Return the shift count (up = positive). */
4400 unsigned EMUSHORT x
[];
4402 register unsigned EMUSHORT
*p
;
4411 return (0); /* already normalized */
4417 /* With guard word, there are NBITS+16 bits available.
4418 Return true if all are zero. */
4422 /* see if high byte is zero */
4423 while ((*p
& 0xff00) == 0)
4428 /* now shift 1 bit at a time */
4429 while ((*p
& 0x8000) == 0)
4435 mtherr ("enormlz", UNDERFLOW
);
4441 /* Normalize by shifting down out of the high guard word
4442 of the significand */
4457 mtherr ("enormlz", OVERFLOW
);
4464 /* Powers of ten used in decimal <-> binary conversions. */
4469 #if LONG_DOUBLE_TYPE_SIZE == 128
4470 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4472 {0x6576, 0x4a92, 0x804a, 0x153f,
4473 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4474 {0x6a32, 0xce52, 0x329a, 0x28ce,
4475 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4476 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4477 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4478 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4479 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4480 {0x851e, 0xeab7, 0x98fe, 0x901b,
4481 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4482 {0x0235, 0x0137, 0x36b1, 0x336c,
4483 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4484 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4485 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4486 {0x0000, 0x0000, 0x0000, 0x0000,
4487 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4488 {0x0000, 0x0000, 0x0000, 0x0000,
4489 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4490 {0x0000, 0x0000, 0x0000, 0x0000,
4491 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4492 {0x0000, 0x0000, 0x0000, 0x0000,
4493 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4494 {0x0000, 0x0000, 0x0000, 0x0000,
4495 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4496 {0x0000, 0x0000, 0x0000, 0x0000,
4497 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4500 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4502 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4503 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4504 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4505 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4506 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4507 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4508 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4509 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4510 {0xa23e, 0x5308, 0xfefb, 0x1155,
4511 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4512 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4513 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4514 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4515 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4516 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4517 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4518 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4519 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4520 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4521 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4522 {0xc155, 0xa4a8, 0x404e, 0x6113,
4523 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4524 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4525 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4526 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4527 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4530 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4531 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4533 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4534 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4535 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4536 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4537 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4538 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4539 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4540 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4541 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4542 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4543 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4544 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4545 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4548 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4550 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4551 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4552 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4553 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4554 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4555 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4556 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4557 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4558 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4559 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4560 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4561 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4562 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4566 /* Convert float value X to ASCII string STRING with NDIG digits after
4567 the decimal point. */
4570 e24toasc (x
, string
, ndigs
)
4571 unsigned EMUSHORT x
[];
4575 unsigned EMUSHORT w
[NI
];
4578 etoasc (w
, string
, ndigs
);
4581 /* Convert double value X to ASCII string STRING with NDIG digits after
4582 the decimal point. */
4585 e53toasc (x
, string
, ndigs
)
4586 unsigned EMUSHORT x
[];
4590 unsigned EMUSHORT w
[NI
];
4593 etoasc (w
, string
, ndigs
);
4596 /* Convert double extended value X to ASCII string STRING with NDIG digits
4597 after the decimal point. */
4600 e64toasc (x
, string
, ndigs
)
4601 unsigned EMUSHORT x
[];
4605 unsigned EMUSHORT w
[NI
];
4608 etoasc (w
, string
, ndigs
);
4611 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4612 after the decimal point. */
4615 e113toasc (x
, string
, ndigs
)
4616 unsigned EMUSHORT x
[];
4620 unsigned EMUSHORT w
[NI
];
4623 etoasc (w
, string
, ndigs
);
4626 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4627 the decimal point. */
4629 static char wstring
[80]; /* working storage for ASCII output */
4632 etoasc (x
, string
, ndigs
)
4633 unsigned EMUSHORT x
[];
4638 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4639 unsigned EMUSHORT
*p
, *r
, *ten
;
4640 unsigned EMUSHORT sign
;
4641 int i
, j
, k
, expon
, rndsav
;
4643 unsigned EMUSHORT m
;
4654 sprintf (wstring
, " NaN ");
4658 rndprc
= NBITS
; /* set to full precision */
4659 emov (x
, y
); /* retain external format */
4660 if (y
[NE
- 1] & 0x8000)
4663 y
[NE
- 1] &= 0x7fff;
4670 ten
= &etens
[NTEN
][0];
4672 /* Test for zero exponent */
4675 for (k
= 0; k
< NE
- 1; k
++)
4678 goto tnzro
; /* denormalized number */
4680 goto isone
; /* valid all zeros */
4684 /* Test for infinity. */
4685 if (y
[NE
- 1] == 0x7fff)
4688 sprintf (wstring
, " -Infinity ");
4690 sprintf (wstring
, " Infinity ");
4694 /* Test for exponent nonzero but significand denormalized.
4695 * This is an error condition.
4697 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4699 mtherr ("etoasc", DOMAIN
);
4700 sprintf (wstring
, "NaN");
4704 /* Compare to 1.0 */
4713 { /* Number is greater than 1 */
4714 /* Convert significand to an integer and strip trailing decimal zeros. */
4716 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4718 p
= &etens
[NTEN
- 4][0];
4724 for (j
= 0; j
< NE
- 1; j
++)
4737 /* Rescale from integer significand */
4738 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4740 /* Find power of 10 */
4744 /* An unordered compare result shouldn't happen here. */
4745 while (ecmp (ten
, u
) <= 0)
4747 if (ecmp (p
, u
) <= 0)
4760 { /* Number is less than 1.0 */
4761 /* Pad significand with trailing decimal zeros. */
4764 while ((y
[NE
- 2] & 0x8000) == 0)
4773 for (i
= 0; i
< NDEC
+ 1; i
++)
4775 if ((w
[NI
- 1] & 0x7) != 0)
4777 /* multiply by 10 */
4790 if (eone
[NE
- 1] <= u
[1])
4802 while (ecmp (eone
, w
) > 0)
4804 if (ecmp (p
, w
) >= 0)
4819 /* Find the first (leading) digit. */
4825 digit
= equot
[NI
- 1];
4826 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4834 digit
= equot
[NI
- 1];
4842 /* Examine number of digits requested by caller. */
4860 *s
++ = (char)digit
+ '0';
4863 /* Generate digits after the decimal point. */
4864 for (k
= 0; k
<= ndigs
; k
++)
4866 /* multiply current number by 10, without normalizing */
4873 *s
++ = (char) equot
[NI
- 1] + '0';
4875 digit
= equot
[NI
- 1];
4878 /* round off the ASCII string */
4881 /* Test for critical rounding case in ASCII output. */
4885 if (ecmp (t
, ezero
) != 0)
4886 goto roun
; /* round to nearest */
4887 if ((*(s
- 1) & 1) == 0)
4888 goto doexp
; /* round to even */
4890 /* Round up and propagate carry-outs */
4894 /* Carry out to most significant digit? */
4901 /* Most significant digit carries to 10? */
4909 /* Round up and carry out from less significant digits */
4921 sprintf (ss, "e+%d", expon);
4923 sprintf (ss, "e%d", expon);
4925 sprintf (ss
, "e%d", expon
);
4928 /* copy out the working string */
4931 while (*ss
== ' ') /* strip possible leading space */
4933 while ((*s
++ = *ss
++) != '\0')
4938 /* Convert ASCII string to floating point.
4940 Numeric input is a free format decimal number of any length, with
4941 or without decimal point. Entering E after the number followed by an
4942 integer number causes the second number to be interpreted as a power of
4943 10 to be multiplied by the first number (i.e., "scientific" notation). */
4945 /* Convert ASCII string S to single precision float value Y. */
4950 unsigned EMUSHORT
*y
;
4956 /* Convert ASCII string S to double precision value Y. */
4961 unsigned EMUSHORT
*y
;
4963 #if defined(DEC) || defined(IBM)
4975 /* Convert ASCII string S to double extended value Y. */
4980 unsigned EMUSHORT
*y
;
4985 /* Convert ASCII string S to 128-bit long double Y. */
4990 unsigned EMUSHORT
*y
;
4992 asctoeg (s
, y
, 113);
4995 /* Convert ASCII string S to e type Y. */
5000 unsigned EMUSHORT
*y
;
5002 asctoeg (s
, y
, NBITS
);
5005 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5009 asctoeg (ss
, y
, oprec
)
5011 unsigned EMUSHORT
*y
;
5014 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5015 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5016 int k
, trail
, c
, rndsav
;
5018 unsigned EMUSHORT nsign
, *p
;
5019 char *sp
, *s
, *lstr
;
5021 /* Copy the input string. */
5022 lstr
= (char *) alloca (strlen (ss
) + 1);
5024 while (*s
== ' ') /* skip leading spaces */
5027 while ((*sp
++ = *s
++) != '\0')
5032 rndprc
= NBITS
; /* Set to full precision */
5045 if ((k
>= 0) && (k
<= 9))
5047 /* Ignore leading zeros */
5048 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5050 /* Identify and strip trailing zeros after the decimal point. */
5051 if ((trail
== 0) && (decflg
!= 0))
5054 while ((*sp
>= '0') && (*sp
<= '9'))
5056 /* Check for syntax error */
5058 if ((c
!= 'e') && (c
!= 'E') && (c
!= '\0')
5059 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5070 /* If enough digits were given to more than fill up the yy register,
5071 continuing until overflow into the high guard word yy[2]
5072 guarantees that there will be a roundoff bit at the top
5073 of the low guard word after normalization. */
5078 nexp
+= 1; /* count digits after decimal point */
5079 eshup1 (yy
); /* multiply current number by 10 */
5085 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5090 /* Mark any lost non-zero digit. */
5092 /* Count lost digits before the decimal point. */
5107 case '.': /* decimal point */
5137 mtherr ("asctoe", DOMAIN
);
5146 /* Exponent interpretation */
5148 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5149 for (k
= 0; k
< NI
; k
++)
5160 /* check for + or - */
5168 while ((*s
>= '0') && (*s
<= '9'))
5172 if (exp
> -(MINDECEXP
))
5182 if (exp
> MAXDECEXP
)
5186 yy
[E
] = 0x7fff; /* infinity */
5189 if (exp
< MINDECEXP
)
5198 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5199 while ((nexp
> 0) && (yy
[2] == 0))
5211 if ((k
= enormlz (yy
)) > NBITS
)
5216 lexp
= (EXONE
- 1 + NBITS
) - k
;
5217 emdnorm (yy
, lost
, 0, lexp
, 64);
5219 /* Convert to external format:
5221 Multiply by 10**nexp. If precision is 64 bits,
5222 the maximum relative error incurred in forming 10**n
5223 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5224 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5225 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5240 /* Punt. Can't handle this without 2 divides. */
5241 emovi (etens
[0], tt
);
5248 p
= &etens
[NTEN
][0];
5258 while (exp
<= MAXP
);
5276 /* Round and convert directly to the destination type */
5278 lexp
-= EXONE
- 0x3ff;
5280 else if (oprec
== 24 || oprec
== 32)
5281 lexp
-= (EXONE
- 0x7f);
5284 else if (oprec
== 24 || oprec
== 56)
5285 lexp
-= EXONE
- (0x41 << 2);
5287 else if (oprec
== 24)
5288 lexp
-= EXONE
- 0177;
5292 else if (oprec
== 56)
5293 lexp
-= EXONE
- 0201;
5296 emdnorm (yy
, k
, 0, lexp
, 64);
5306 todec (yy
, y
); /* see etodec.c */
5311 toibm (yy
, y
, DFmode
);
5316 toc4x (yy
, y
, HFmode
);
5340 /* Return Y = largest integer not greater than X (truncated toward minus
5343 static unsigned EMUSHORT bmask
[] =
5366 unsigned EMUSHORT x
[], y
[];
5368 register unsigned EMUSHORT
*p
;
5370 unsigned EMUSHORT f
[NE
];
5372 emov (x
, f
); /* leave in external format */
5373 expon
= (int) f
[NE
- 1];
5374 e
= (expon
& 0x7fff) - (EXONE
- 1);
5380 /* number of bits to clear out */
5392 /* clear the remaining bits */
5394 /* truncate negatives toward minus infinity */
5397 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5399 for (i
= 0; i
< NE
- 1; i
++)
5412 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5413 For example, 1.1 = 0.55 * 2^1. */
5417 unsigned EMUSHORT x
[];
5419 unsigned EMUSHORT s
[];
5421 unsigned EMUSHORT xi
[NI
];
5425 /* Handle denormalized numbers properly using long integer exponent. */
5426 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5434 *exp
= (int) (li
- 0x3ffe);
5438 /* Return e type Y = X * 2^PWR2. */
5442 unsigned EMUSHORT x
[];
5444 unsigned EMUSHORT y
[];
5446 unsigned EMUSHORT xi
[NI
];
5454 emdnorm (xi
, i
, i
, li
, 64);
5460 /* C = remainder after dividing B by A, all e type values.
5461 Least significant integer quotient bits left in EQUOT. */
5465 unsigned EMUSHORT a
[], b
[], c
[];
5467 unsigned EMUSHORT den
[NI
], num
[NI
];
5471 || (ecmp (a
, ezero
) == 0)
5479 if (ecmp (a
, ezero
) == 0)
5481 mtherr ("eremain", SING
);
5487 eiremain (den
, num
);
5488 /* Sign of remainder = sign of quotient */
5497 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5498 remainder in NUM. */
5502 unsigned EMUSHORT den
[], num
[];
5505 unsigned EMUSHORT j
;
5508 ld
-= enormlz (den
);
5510 ln
-= enormlz (num
);
5514 if (ecmpm (den
, num
) <= 0)
5526 emdnorm (num
, 0, 0, ln
, 0);
5529 /* Report an error condition CODE encountered in function NAME.
5530 CODE is one of the following:
5532 Mnemonic Value Significance
5534 DOMAIN 1 argument domain error
5535 SING 2 function singularity
5536 OVERFLOW 3 overflow range error
5537 UNDERFLOW 4 underflow range error
5538 TLOSS 5 total loss of precision
5539 PLOSS 6 partial loss of precision
5540 INVALID 7 NaN - producing operation
5541 EDOM 33 Unix domain error code
5542 ERANGE 34 Unix range error code
5544 The order of appearance of the following messages is bound to the
5545 error codes defined above. */
5548 static char *ermsg
[NMSGS
] =
5550 "unknown", /* error code 0 */
5551 "domain", /* error code 1 */
5552 "singularity", /* et seq. */
5555 "total loss of precision",
5556 "partial loss of precision",
5570 /* The string passed by the calling program is supposed to be the
5571 name of the function in which the error occurred.
5572 The code argument selects which error message string will be printed. */
5574 if ((code
<= 0) || (code
>= NMSGS
))
5576 sprintf (errstr
, " %s %s error", name
, ermsg
[code
]);
5579 /* Set global error message word */
5584 /* Convert DEC double precision D to e type E. */
5588 unsigned EMUSHORT
*d
;
5589 unsigned EMUSHORT
*e
;
5591 unsigned EMUSHORT y
[NI
];
5592 register unsigned EMUSHORT r
, *p
;
5594 ecleaz (y
); /* start with a zero */
5595 p
= y
; /* point to our number */
5596 r
= *d
; /* get DEC exponent word */
5597 if (*d
& (unsigned int) 0x8000)
5598 *p
= 0xffff; /* fill in our sign */
5599 ++p
; /* bump pointer to our exponent word */
5600 r
&= 0x7fff; /* strip the sign bit */
5601 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5605 r
>>= 7; /* shift exponent word down 7 bits */
5606 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5607 /* add our e type exponent offset */
5608 *p
++ = r
; /* to form our exponent */
5610 r
= *d
++; /* now do the high order mantissa */
5611 r
&= 0177; /* strip off the DEC exponent and sign bits */
5612 r
|= 0200; /* the DEC understood high order mantissa bit */
5613 *p
++ = r
; /* put result in our high guard word */
5615 *p
++ = *d
++; /* fill in the rest of our mantissa */
5619 eshdn8 (y
); /* shift our mantissa down 8 bits */
5624 /* Convert e type X to DEC double precision D. */
5628 unsigned EMUSHORT
*x
, *d
;
5630 unsigned EMUSHORT xi
[NI
];
5635 /* Adjust exponent for offsets. */
5636 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5637 /* Round off to nearest or even. */
5640 emdnorm (xi
, 0, 0, exp
, 64);
5645 /* Convert exploded e-type X, that has already been rounded to
5646 56-bit precision, to DEC format double Y. */
5650 unsigned EMUSHORT
*x
, *y
;
5652 unsigned EMUSHORT i
;
5653 unsigned EMUSHORT
*p
;
5692 /* Convert IBM single/double precision to e type. */
5696 unsigned EMUSHORT
*d
;
5697 unsigned EMUSHORT
*e
;
5698 enum machine_mode mode
;
5700 unsigned EMUSHORT y
[NI
];
5701 register unsigned EMUSHORT r
, *p
;
5704 ecleaz (y
); /* start with a zero */
5705 p
= y
; /* point to our number */
5706 r
= *d
; /* get IBM exponent word */
5707 if (*d
& (unsigned int) 0x8000)
5708 *p
= 0xffff; /* fill in our sign */
5709 ++p
; /* bump pointer to our exponent word */
5710 r
&= 0x7f00; /* strip the sign bit */
5711 r
>>= 6; /* shift exponent word down 6 bits */
5712 /* in fact shift by 8 right and 2 left */
5713 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5714 /* add our e type exponent offset */
5715 *p
++ = r
; /* to form our exponent */
5717 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5718 /* strip off the IBM exponent and sign bits */
5719 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5721 *p
++ = *d
++; /* fill in the rest of our mantissa */
5726 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5729 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5730 /* handle change in RADIX */
5736 /* Convert e type to IBM single/double precision. */
5740 unsigned EMUSHORT
*x
, *d
;
5741 enum machine_mode mode
;
5743 unsigned EMUSHORT xi
[NI
];
5748 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5749 /* round off to nearest or even */
5752 emdnorm (xi
, 0, 0, exp
, 64);
5754 toibm (xi
, d
, mode
);
5759 unsigned EMUSHORT
*x
, *y
;
5760 enum machine_mode mode
;
5762 unsigned EMUSHORT i
;
5763 unsigned EMUSHORT
*p
;
5813 /* Convert C4X single/double precision to e type. */
5817 unsigned EMUSHORT
*d
;
5818 unsigned EMUSHORT
*e
;
5819 enum machine_mode mode
;
5821 unsigned EMUSHORT y
[NI
];
5829 /* Short-circuit the zero case. */
5830 if ((d
[0] == 0x8000)
5832 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5843 ecleaz (y
); /* start with a zero */
5844 r
= d
[0]; /* get sign/exponent part */
5845 if (r
& (unsigned int) 0x0080)
5847 y
[0] = 0xffff; /* fill in our sign */
5855 r
>>= 8; /* Shift exponent word down 8 bits. */
5856 if (r
& 0x80) /* Make the exponent negative if it is. */
5858 r
= r
| (~0 & ~0xff);
5863 /* Now do the high order mantissa. We don't "or" on the high bit
5864 because it is 2 (not 1) and is handled a little differently
5869 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5871 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5881 /* Now do the two's complement on the data. */
5883 carry
= 1; /* Initially add 1 for the two's complement. */
5884 for (i
=size
+ M
; i
> M
; i
--)
5886 if (carry
&& (y
[i
] == 0x0000))
5888 /* We overflowed into the next word, carry is the same. */
5889 y
[i
] = carry
? 0x0000 : 0xffff;
5893 /* No overflow, just invert and add carry. */
5894 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
5909 /* Add our e type exponent offset to form our exponent. */
5913 /* Now do the high order mantissa strip off the exponent and sign
5914 bits and add the high 1 bit. */
5915 y
[M
] = d
[0] & 0x7f | 0x80;
5918 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
5920 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
5930 /* Convert e type to C4X single/double precision. */
5934 unsigned EMUSHORT
*x
, *d
;
5935 enum machine_mode mode
;
5937 unsigned EMUSHORT xi
[NI
];
5943 /* Adjust exponent for offsets. */
5944 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
5946 /* Round off to nearest or even. */
5948 rndprc
= mode
== QFmode
? 24 : 32;
5949 emdnorm (xi
, 0, 0, exp
, 64);
5951 toc4x (xi
, d
, mode
);
5956 unsigned EMUSHORT
*x
, *y
;
5957 enum machine_mode mode
;
5964 /* Short-circuit the zero case */
5965 if ((x
[0] == 0) /* Zero exponent and sign */
5967 && (x
[M
] == 0) /* The rest is for zero mantissa */
5969 /* Only check for double if necessary */
5970 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
5972 /* We have a zero. Put it into the output and return. */
5985 /* Negative number require a two's complement conversion of the
5991 i
= ((int) x
[1]) - 0x7f;
5993 /* Now add 1 to the inverted data to do the two's complement. */
6003 x
[v
] = carry
? 0x0000 : 0xffff;
6007 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6013 /* The following is a special case. The C4X negative float requires
6014 a zero in the high bit (because the format is (2 - x) x 2^m), so
6015 if a one is in that bit, we have to shift left one to get rid
6016 of it. This only occurs if the number is -1 x 2^m. */
6017 if (x
[M
+1] & 0x8000)
6019 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6020 high sign bit and shift the exponent. */
6027 i
= ((int) x
[1]) - 0x7f;
6030 if ((i
< -128) || (i
> 127))
6045 y
[0] |= ((i
& 0xff) << 8);
6049 y
[0] |= x
[M
] & 0x7f;
6059 /* Output a binary NaN bit pattern in the target machine's format. */
6061 /* If special NaN bit patterns are required, define them in tm.h
6062 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6068 unsigned EMUSHORT TFbignan
[8] =
6069 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6070 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6078 unsigned EMUSHORT XFbignan
[6] =
6079 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6080 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6088 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6089 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6097 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6098 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6104 make_nan (nan
, sign
, mode
)
6105 unsigned EMUSHORT
*nan
;
6107 enum machine_mode mode
;
6110 unsigned EMUSHORT
*p
;
6114 /* Possibly the `reserved operand' patterns on a VAX can be
6115 used like NaN's, but probably not in the same way as IEEE. */
6116 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6119 if (REAL_WORDS_BIG_ENDIAN
)
6127 if (REAL_WORDS_BIG_ENDIAN
)
6135 if (REAL_WORDS_BIG_ENDIAN
)
6144 if (REAL_WORDS_BIG_ENDIAN
)
6154 if (REAL_WORDS_BIG_ENDIAN
)
6155 *nan
++ = (sign
<< 15) | *p
++;
6158 if (! REAL_WORDS_BIG_ENDIAN
)
6159 *nan
= (sign
<< 15) | *p
;
6162 /* This is the inverse of the function `etarsingle' invoked by
6163 REAL_VALUE_TO_TARGET_SINGLE. */
6166 ereal_unto_float (f
)
6170 unsigned EMUSHORT s
[2];
6171 unsigned EMUSHORT e
[NE
];
6173 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6174 This is the inverse operation to what the function `endian' does. */
6175 if (REAL_WORDS_BIG_ENDIAN
)
6177 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6178 s
[1] = (unsigned EMUSHORT
) f
;
6182 s
[0] = (unsigned EMUSHORT
) f
;
6183 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6185 /* Convert and promote the target float to E-type. */
6187 /* Output E-type to REAL_VALUE_TYPE. */
6193 /* This is the inverse of the function `etardouble' invoked by
6194 REAL_VALUE_TO_TARGET_DOUBLE. */
6197 ereal_unto_double (d
)
6201 unsigned EMUSHORT s
[4];
6202 unsigned EMUSHORT e
[NE
];
6204 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6205 if (REAL_WORDS_BIG_ENDIAN
)
6207 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6208 s
[1] = (unsigned EMUSHORT
) d
[0];
6209 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6210 s
[3] = (unsigned EMUSHORT
) d
[1];
6214 /* Target float words are little-endian. */
6215 s
[0] = (unsigned EMUSHORT
) d
[0];
6216 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6217 s
[2] = (unsigned EMUSHORT
) d
[1];
6218 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6220 /* Convert target double to E-type. */
6222 /* Output E-type to REAL_VALUE_TYPE. */
6228 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6229 This is somewhat like ereal_unto_float, but the input types
6230 for these are different. */
6233 ereal_from_float (f
)
6237 unsigned EMUSHORT s
[2];
6238 unsigned EMUSHORT e
[NE
];
6240 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6241 This is the inverse operation to what the function `endian' does. */
6242 if (REAL_WORDS_BIG_ENDIAN
)
6244 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6245 s
[1] = (unsigned EMUSHORT
) f
;
6249 s
[0] = (unsigned EMUSHORT
) f
;
6250 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6252 /* Convert and promote the target float to E-type. */
6254 /* Output E-type to REAL_VALUE_TYPE. */
6260 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6261 This is somewhat like ereal_unto_double, but the input types
6262 for these are different.
6264 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6265 data format, with no holes in the bit packing. The first element
6266 of the input array holds the bits that would come first in the
6267 target computer's memory. */
6270 ereal_from_double (d
)
6274 unsigned EMUSHORT s
[4];
6275 unsigned EMUSHORT e
[NE
];
6277 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6278 if (REAL_WORDS_BIG_ENDIAN
)
6280 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6281 s
[1] = (unsigned EMUSHORT
) d
[0];
6282 #if HOST_BITS_PER_WIDE_INT == 32
6283 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6284 s
[3] = (unsigned EMUSHORT
) d
[1];
6286 /* In this case the entire target double is contained in the
6287 first array element. The second element of the input is
6289 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 48);
6290 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 32);
6295 /* Target float words are little-endian. */
6296 s
[0] = (unsigned EMUSHORT
) d
[0];
6297 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6298 #if HOST_BITS_PER_WIDE_INT == 32
6299 s
[2] = (unsigned EMUSHORT
) d
[1];
6300 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6302 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6303 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6306 /* Convert target double to E-type. */
6308 /* Output E-type to REAL_VALUE_TYPE. */
6315 /* Convert target computer unsigned 64-bit integer to e-type.
6316 The endian-ness of DImode follows the convention for integers,
6317 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6321 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6322 unsigned EMUSHORT
*e
;
6324 unsigned EMUSHORT yi
[NI
];
6328 if (WORDS_BIG_ENDIAN
)
6330 for (k
= M
; k
< M
+ 4; k
++)
6335 for (k
= M
+ 3; k
>= M
; k
--)
6338 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6339 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6340 ecleaz (yi
); /* it was zero */
6342 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6346 /* Convert target computer signed 64-bit integer to e-type. */
6350 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6351 unsigned EMUSHORT
*e
;
6353 unsigned EMULONG acc
;
6354 unsigned EMUSHORT yi
[NI
];
6355 unsigned EMUSHORT carry
;
6359 if (WORDS_BIG_ENDIAN
)
6361 for (k
= M
; k
< M
+ 4; k
++)
6366 for (k
= M
+ 3; k
>= M
; k
--)
6369 /* Take absolute value */
6375 for (k
= M
+ 3; k
>= M
; k
--)
6377 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6384 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6385 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6386 ecleaz (yi
); /* it was zero */
6388 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6395 /* Convert e-type to unsigned 64-bit int. */
6399 unsigned EMUSHORT
*x
;
6400 unsigned EMUSHORT
*i
;
6402 unsigned EMUSHORT xi
[NI
];
6411 k
= (int) xi
[E
] - (EXONE
- 1);
6414 for (j
= 0; j
< 4; j
++)
6420 for (j
= 0; j
< 4; j
++)
6423 warning ("overflow on truncation to integer");
6428 /* Shift more than 16 bits: first shift up k-16 mod 16,
6429 then shift up by 16's. */
6430 j
= k
- ((k
>> 4) << 4);
6434 if (WORDS_BIG_ENDIAN
)
6445 if (WORDS_BIG_ENDIAN
)
6450 while ((k
-= 16) > 0);
6454 /* shift not more than 16 bits */
6459 if (WORDS_BIG_ENDIAN
)
6478 /* Convert e-type to signed 64-bit int. */
6482 unsigned EMUSHORT
*x
;
6483 unsigned EMUSHORT
*i
;
6485 unsigned EMULONG acc
;
6486 unsigned EMUSHORT xi
[NI
];
6487 unsigned EMUSHORT carry
;
6488 unsigned EMUSHORT
*isave
;
6492 k
= (int) xi
[E
] - (EXONE
- 1);
6495 for (j
= 0; j
< 4; j
++)
6501 for (j
= 0; j
< 4; j
++)
6504 warning ("overflow on truncation to integer");
6510 /* Shift more than 16 bits: first shift up k-16 mod 16,
6511 then shift up by 16's. */
6512 j
= k
- ((k
>> 4) << 4);
6516 if (WORDS_BIG_ENDIAN
)
6527 if (WORDS_BIG_ENDIAN
)
6532 while ((k
-= 16) > 0);
6536 /* shift not more than 16 bits */
6539 if (WORDS_BIG_ENDIAN
)
6555 /* Negate if negative */
6559 if (WORDS_BIG_ENDIAN
)
6561 for (k
= 0; k
< 4; k
++)
6563 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6564 if (WORDS_BIG_ENDIAN
)
6576 /* Longhand square root routine. */
6579 static int esqinited
= 0;
6580 static unsigned short sqrndbit
[NI
];
6584 unsigned EMUSHORT
*x
, *y
;
6586 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6588 int i
, j
, k
, n
, nlups
;
6593 sqrndbit
[NI
- 2] = 1;
6596 /* Check for arg <= 0 */
6597 i
= ecmp (x
, ezero
);
6602 mtherr ("esqrt", DOMAIN
);
6618 /* Bring in the arg and renormalize if it is denormal. */
6620 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6624 /* Divide exponent by 2 */
6626 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6628 /* Adjust if exponent odd */
6638 n
= 8; /* get 8 bits of result per inner loop */
6644 /* bring in next word of arg */
6646 num
[NI
- 1] = xx
[j
+ 3];
6647 /* Do additional bit on last outer loop, for roundoff. */
6650 for (i
= 0; i
< n
; i
++)
6652 /* Next 2 bits of arg */
6655 /* Shift up answer */
6657 /* Make trial divisor */
6658 for (k
= 0; k
< NI
; k
++)
6661 eaddm (sqrndbit
, temp
);
6662 /* Subtract and insert answer bit if it goes in */
6663 if (ecmpm (temp
, num
) <= 0)
6673 /* Adjust for extra, roundoff loop done. */
6674 exp
+= (NBITS
- 1) - rndprc
;
6676 /* Sticky bit = 1 if the remainder is nonzero. */
6678 for (i
= 3; i
< NI
; i
++)
6681 /* Renormalize and round off. */
6682 emdnorm (sq
, k
, 0, exp
, 64);
6686 #endif /* EMU_NON_COMPILE not defined */
6688 /* Return the binary precision of the significand for a given
6689 floating point mode. The mode can hold an integer value
6690 that many bits wide, without losing any bits. */
6693 significand_size (mode
)
6694 enum machine_mode mode
;
6697 /* Don't test the modes, but their sizes, lest this
6698 code won't work for BITS_PER_UNIT != 8 . */
6700 switch (GET_MODE_BITSIZE (mode
))
6704 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6711 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6714 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6717 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6720 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
This page took 0.353465 seconds and 5 git commands to generate.