1 /* real.c - implementation of REAL_ARITHMETIC, REAL_VALUE_ATOF,
2 and support for XFmode IEEE extended real floating point arithmetic.
3 Copyright (C) 1993, 94-98, 1999 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
6 This file is part of GNU CC.
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
29 /* To enable support of XFmode extended real floating point, define
30 LONG_DOUBLE_TYPE_SIZE 96 in the tm.h file (m68k.h or i386.h).
32 To support cross compilation between IEEE, VAX and IBM floating
33 point formats, define REAL_ARITHMETIC in the tm.h file.
35 In either case the machine files (tm.h) must not contain any code
36 that tries to use host floating point arithmetic to convert
37 REAL_VALUE_TYPEs from `double' to `float', pass them to fprintf,
38 etc. In cross-compile situations a REAL_VALUE_TYPE may not
39 be intelligible to the host computer's native arithmetic.
41 The emulator defaults to the host's floating point format so that
42 its decimal conversion functions can be used if desired (see
45 The first part of this file interfaces gcc to a floating point
46 arithmetic suite that was not written with gcc in mind. Avoid
47 changing the low-level arithmetic routines unless you have suitable
48 test programs available. A special version of the PARANOIA floating
49 point arithmetic tester, modified for this purpose, can be found on
50 usc.edu: /pub/C-numanal/ieeetest.zoo. Other tests, and libraries of
51 XFmode and TFmode transcendental functions, can be obtained by ftp from
52 netlib.att.com: netlib/cephes. */
54 /* Type of computer arithmetic.
55 Only one of DEC, IBM, IEEE, C4X, or UNK should get defined.
57 `IEEE', when REAL_WORDS_BIG_ENDIAN is non-zero, refers generically
58 to big-endian IEEE floating-point data structure. This definition
59 should work in SFmode `float' type and DFmode `double' type on
60 virtually all big-endian IEEE machines. If LONG_DOUBLE_TYPE_SIZE
61 has been defined to be 96, then IEEE also invokes the particular
62 XFmode (`long double' type) data structure used by the Motorola
63 680x0 series processors.
65 `IEEE', when REAL_WORDS_BIG_ENDIAN is zero, refers generally to
66 little-endian IEEE machines. In this case, if LONG_DOUBLE_TYPE_SIZE
67 has been defined to be 96, then IEEE also invokes the particular
68 XFmode `long double' data structure used by the Intel 80x86 series
71 `DEC' refers specifically to the Digital Equipment Corp PDP-11
72 and VAX floating point data structure. This model currently
73 supports no type wider than DFmode.
75 `IBM' refers specifically to the IBM System/370 and compatible
76 floating point data structure. This model currently supports
77 no type wider than DFmode. The IBM conversions were contributed by
78 frank@atom.ansto.gov.au (Frank Crawford).
80 `C4X' refers specifically to the floating point format used on
81 Texas Instruments TMS320C3x and TMS320C4x digital signal
82 processors. This supports QFmode (32-bit float, double) and HFmode
83 (40-bit long double) where BITS_PER_BYTE is 32. Unlike IEEE
84 floats, C4x floats are not rounded to be even. The C4x conversions
85 were contributed by m.hayes@elec.canterbury.ac.nz (Michael Hayes) and
86 Haj.Ten.Brugge@net.HCC.nl (Herman ten Brugge).
88 If LONG_DOUBLE_TYPE_SIZE = 64 (the default, unless tm.h defines it)
89 then `long double' and `double' are both implemented, but they
90 both mean DFmode. In this case, the software floating-point
91 support available here is activated by writing
92 #define REAL_ARITHMETIC
95 The case LONG_DOUBLE_TYPE_SIZE = 128 activates TFmode support
96 and may deactivate XFmode since `long double' is used to refer
99 The macros FLOAT_WORDS_BIG_ENDIAN, HOST_FLOAT_WORDS_BIG_ENDIAN,
100 contributed by Richard Earnshaw <Richard.Earnshaw@cl.cam.ac.uk>,
101 separate the floating point unit's endian-ness from that of
102 the integer addressing. This permits one to define a big-endian
103 FPU on a little-endian machine (e.g., ARM). An extension to
104 BYTES_BIG_ENDIAN may be required for some machines in the future.
105 These optional macros may be defined in tm.h. In real.h, they
106 default to WORDS_BIG_ENDIAN, etc., so there is no need to define
107 them for any normal host or target machine on which the floats
108 and the integers have the same endian-ness. */
111 /* The following converts gcc macros into the ones used by this file. */
113 /* REAL_ARITHMETIC defined means that macros in real.h are
114 defined to call emulator functions. */
115 #ifdef REAL_ARITHMETIC
117 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
118 /* PDP-11, Pro350, VAX: */
120 #else /* it's not VAX */
121 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
122 /* IBM System/370 style */
124 #else /* it's also not an IBM */
125 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
126 /* TMS320C3x/C4x style */
128 #else /* it's also not a C4X */
129 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
131 #else /* it's not IEEE either */
132 /* UNKnown arithmetic. We don't support this and can't go on. */
133 unknown arithmetic type
135 #endif /* not IEEE */
140 #define REAL_WORDS_BIG_ENDIAN FLOAT_WORDS_BIG_ENDIAN
143 /* REAL_ARITHMETIC not defined means that the *host's* data
144 structure will be used. It may differ by endian-ness from the
145 target machine's structure and will get its ends swapped
146 accordingly (but not here). Probably only the decimal <-> binary
147 functions in this file will actually be used in this case. */
149 #if HOST_FLOAT_FORMAT == VAX_FLOAT_FORMAT
151 #else /* it's not VAX */
152 #if HOST_FLOAT_FORMAT == IBM_FLOAT_FORMAT
153 /* IBM System/370 style */
155 #else /* it's also not an IBM */
156 #if HOST_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
158 #else /* it's not IEEE either */
159 unknown arithmetic type
161 #endif /* not IEEE */
165 #define REAL_WORDS_BIG_ENDIAN HOST_FLOAT_WORDS_BIG_ENDIAN
167 #endif /* REAL_ARITHMETIC not defined */
169 /* Define INFINITY for support of infinity.
170 Define NANS for support of Not-a-Number's (NaN's). */
171 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
176 /* Support of NaNs requires support of infinity. */
183 /* Find a host integer type that is at least 16 bits wide,
184 and another type at least twice whatever that size is. */
186 #if HOST_BITS_PER_CHAR >= 16
187 #define EMUSHORT char
188 #define EMUSHORT_SIZE HOST_BITS_PER_CHAR
189 #define EMULONG_SIZE (2 * HOST_BITS_PER_CHAR)
191 #if HOST_BITS_PER_SHORT >= 16
192 #define EMUSHORT short
193 #define EMUSHORT_SIZE HOST_BITS_PER_SHORT
194 #define EMULONG_SIZE (2 * HOST_BITS_PER_SHORT)
196 #if HOST_BITS_PER_INT >= 16
198 #define EMUSHORT_SIZE HOST_BITS_PER_INT
199 #define EMULONG_SIZE (2 * HOST_BITS_PER_INT)
201 #if HOST_BITS_PER_LONG >= 16
202 #define EMUSHORT long
203 #define EMUSHORT_SIZE HOST_BITS_PER_LONG
204 #define EMULONG_SIZE (2 * HOST_BITS_PER_LONG)
206 /* You will have to modify this program to have a smaller unit size. */
207 #define EMU_NON_COMPILE
213 #if HOST_BITS_PER_SHORT >= EMULONG_SIZE
214 #define EMULONG short
216 #if HOST_BITS_PER_INT >= EMULONG_SIZE
219 #if HOST_BITS_PER_LONG >= EMULONG_SIZE
222 #if HOST_BITS_PER_LONGLONG >= EMULONG_SIZE
223 #define EMULONG long long int
225 /* You will have to modify this program to have a smaller unit size. */
226 #define EMU_NON_COMPILE
233 /* The host interface doesn't work if no 16-bit size exists. */
234 #if EMUSHORT_SIZE != 16
235 #define EMU_NON_COMPILE
238 /* OK to continue compilation. */
239 #ifndef EMU_NON_COMPILE
241 /* Construct macros to translate between REAL_VALUE_TYPE and e type.
242 In GET_REAL and PUT_REAL, r and e are pointers.
243 A REAL_VALUE_TYPE is guaranteed to occupy contiguous locations
244 in memory, with no holes. */
246 #if LONG_DOUBLE_TYPE_SIZE == 96
247 /* Number of 16 bit words in external e type format */
249 #define MAXDECEXP 4932
250 #define MINDECEXP -4956
251 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
252 #define PUT_REAL(e,r) \
254 if (2*NE < sizeof(*r)) \
255 bzero((char *)r, sizeof(*r)); \
256 bcopy ((char *) e, (char *) r, 2*NE); \
258 #else /* no XFmode */
259 #if LONG_DOUBLE_TYPE_SIZE == 128
261 #define MAXDECEXP 4932
262 #define MINDECEXP -4977
263 #define GET_REAL(r,e) bcopy ((char *) r, (char *) e, 2*NE)
264 #define PUT_REAL(e,r) \
266 if (2*NE < sizeof(*r)) \
267 bzero((char *)r, sizeof(*r)); \
268 bcopy ((char *) e, (char *) r, 2*NE); \
272 #define MAXDECEXP 4932
273 #define MINDECEXP -4956
274 #ifdef REAL_ARITHMETIC
275 /* Emulator uses target format internally
276 but host stores it in host endian-ness. */
278 #define GET_REAL(r,e) \
280 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
281 e53toe ((unsigned EMUSHORT *) (r), (e)); \
284 unsigned EMUSHORT w[4]; \
285 memcpy (&w[3], ((EMUSHORT *) r), sizeof (EMUSHORT)); \
286 memcpy (&w[2], ((EMUSHORT *) r) + 1, sizeof (EMUSHORT)); \
287 memcpy (&w[1], ((EMUSHORT *) r) + 2, sizeof (EMUSHORT)); \
288 memcpy (&w[0], ((EMUSHORT *) r) + 3, sizeof (EMUSHORT)); \
293 #define PUT_REAL(e,r) \
295 if (HOST_FLOAT_WORDS_BIG_ENDIAN == REAL_WORDS_BIG_ENDIAN) \
296 etoe53 ((e), (unsigned EMUSHORT *) (r)); \
299 unsigned EMUSHORT w[4]; \
301 memcpy (((EMUSHORT *) r), &w[3], sizeof (EMUSHORT)); \
302 memcpy (((EMUSHORT *) r) + 1, &w[2], sizeof (EMUSHORT)); \
303 memcpy (((EMUSHORT *) r) + 2, &w[1], sizeof (EMUSHORT)); \
304 memcpy (((EMUSHORT *) r) + 3, &w[0], sizeof (EMUSHORT)); \
308 #else /* not REAL_ARITHMETIC */
310 /* emulator uses host format */
311 #define GET_REAL(r,e) e53toe ((unsigned EMUSHORT *) (r), (e))
312 #define PUT_REAL(e,r) etoe53 ((e), (unsigned EMUSHORT *) (r))
314 #endif /* not REAL_ARITHMETIC */
315 #endif /* not TFmode */
316 #endif /* not XFmode */
319 /* Number of 16 bit words in internal format */
322 /* Array offset to exponent */
325 /* Array offset to high guard word */
328 /* Number of bits of precision */
329 #define NBITS ((NI-4)*16)
331 /* Maximum number of decimal digits in ASCII conversion
334 #define NDEC (NBITS*8/27)
336 /* The exponent of 1.0 */
337 #define EXONE (0x3fff)
339 extern int extra_warnings
;
340 extern unsigned EMUSHORT ezero
[], ehalf
[], eone
[], etwo
[];
341 extern unsigned EMUSHORT elog2
[], esqrt2
[];
343 static void endian
PROTO((unsigned EMUSHORT
*, long *,
345 static void eclear
PROTO((unsigned EMUSHORT
*));
346 static void emov
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
348 static void eabs
PROTO((unsigned EMUSHORT
*));
350 static void eneg
PROTO((unsigned EMUSHORT
*));
351 static int eisneg
PROTO((unsigned EMUSHORT
*));
352 static int eisinf
PROTO((unsigned EMUSHORT
*));
353 static int eisnan
PROTO((unsigned EMUSHORT
*));
354 static void einfin
PROTO((unsigned EMUSHORT
*));
355 static void enan
PROTO((unsigned EMUSHORT
*, int));
356 static void emovi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
357 static void emovo
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
358 static void ecleaz
PROTO((unsigned EMUSHORT
*));
359 static void ecleazs
PROTO((unsigned EMUSHORT
*));
360 static void emovz
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
361 static void einan
PROTO((unsigned EMUSHORT
*));
362 static int eiisnan
PROTO((unsigned EMUSHORT
*));
363 static int eiisneg
PROTO((unsigned EMUSHORT
*));
365 static void eiinfin
PROTO((unsigned EMUSHORT
*));
367 static int eiisinf
PROTO((unsigned EMUSHORT
*));
368 static int ecmpm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
369 static void eshdn1
PROTO((unsigned EMUSHORT
*));
370 static void eshup1
PROTO((unsigned EMUSHORT
*));
371 static void eshdn8
PROTO((unsigned EMUSHORT
*));
372 static void eshup8
PROTO((unsigned EMUSHORT
*));
373 static void eshup6
PROTO((unsigned EMUSHORT
*));
374 static void eshdn6
PROTO((unsigned EMUSHORT
*));
375 static void eaddm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));\f
376 static void esubm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
377 static void m16m
PROTO((unsigned int, unsigned short *,
379 static int edivm
PROTO((unsigned short *, unsigned short *));
380 static int emulm
PROTO((unsigned short *, unsigned short *));
381 static void emdnorm
PROTO((unsigned EMUSHORT
*, int, int, EMULONG
, int));
382 static void esub
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
383 unsigned EMUSHORT
*));
384 static void eadd
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
385 unsigned EMUSHORT
*));
386 static void eadd1
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
387 unsigned EMUSHORT
*));
388 static void ediv
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
389 unsigned EMUSHORT
*));
390 static void emul
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
391 unsigned EMUSHORT
*));
392 static void e53toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
393 static void e64toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
394 static void e113toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
395 static void e24toe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
396 static void etoe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
397 static void toe113
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
398 static void etoe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
399 static void toe64
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
400 static void etoe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
401 static void toe53
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
402 static void etoe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
403 static void toe24
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
404 static int ecmp
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
406 static void eround
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
408 static void ltoe
PROTO((HOST_WIDE_INT
*, unsigned EMUSHORT
*));
409 static void ultoe
PROTO((unsigned HOST_WIDE_INT
*, unsigned EMUSHORT
*));
410 static void eifrac
PROTO((unsigned EMUSHORT
*, HOST_WIDE_INT
*,
411 unsigned EMUSHORT
*));
412 static void euifrac
PROTO((unsigned EMUSHORT
*, unsigned HOST_WIDE_INT
*,
413 unsigned EMUSHORT
*));
414 static int eshift
PROTO((unsigned EMUSHORT
*, int));
415 static int enormlz
PROTO((unsigned EMUSHORT
*));
417 static void e24toasc
PROTO((unsigned EMUSHORT
*, char *, int));
418 static void e53toasc
PROTO((unsigned EMUSHORT
*, char *, int));
419 static void e64toasc
PROTO((unsigned EMUSHORT
*, char *, int));
420 static void e113toasc
PROTO((unsigned EMUSHORT
*, char *, int));
422 static void etoasc
PROTO((unsigned EMUSHORT
*, char *, int));
423 static void asctoe24
PROTO((const char *, unsigned EMUSHORT
*));
424 static void asctoe53
PROTO((const char *, unsigned EMUSHORT
*));
425 static void asctoe64
PROTO((const char *, unsigned EMUSHORT
*));
426 static void asctoe113
PROTO((const char *, unsigned EMUSHORT
*));
427 static void asctoe
PROTO((const char *, unsigned EMUSHORT
*));
428 static void asctoeg
PROTO((const char *, unsigned EMUSHORT
*, int));
429 static void efloor
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
431 static void efrexp
PROTO((unsigned EMUSHORT
*, int *,
432 unsigned EMUSHORT
*));
434 static void eldexp
PROTO((unsigned EMUSHORT
*, int, unsigned EMUSHORT
*));
436 static void eremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
437 unsigned EMUSHORT
*));
439 static void eiremain
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
440 static void mtherr
PROTO((const char *, int));
442 static void dectoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
443 static void etodec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
444 static void todec
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
447 static void ibmtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
449 static void etoibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
451 static void toibm
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
455 static void c4xtoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
457 static void etoc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
459 static void toc4x
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*,
462 static void make_nan
PROTO((unsigned EMUSHORT
*, int, enum machine_mode
));
464 static void uditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
465 static void ditoe
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
466 static void etoudi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
467 static void etodi
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
468 static void esqrt
PROTO((unsigned EMUSHORT
*, unsigned EMUSHORT
*));
471 /* Copy 32-bit numbers obtained from array containing 16-bit numbers,
472 swapping ends if required, into output array of longs. The
473 result is normally passed to fprintf by the ASM_OUTPUT_ macros. */
477 unsigned EMUSHORT e
[];
479 enum machine_mode mode
;
483 if (REAL_WORDS_BIG_ENDIAN
)
488 /* Swap halfwords in the fourth long. */
489 th
= (unsigned long) e
[6] & 0xffff;
490 t
= (unsigned long) e
[7] & 0xffff;
495 /* Swap halfwords in the third long. */
496 th
= (unsigned long) e
[4] & 0xffff;
497 t
= (unsigned long) e
[5] & 0xffff;
500 /* fall into the double case */
503 /* Swap halfwords in the second word. */
504 th
= (unsigned long) e
[2] & 0xffff;
505 t
= (unsigned long) e
[3] & 0xffff;
508 /* fall into the float case */
512 /* Swap halfwords in the first word. */
513 th
= (unsigned long) e
[0] & 0xffff;
514 t
= (unsigned long) e
[1] & 0xffff;
525 /* Pack the output array without swapping. */
530 /* Pack the fourth long. */
531 th
= (unsigned long) e
[7] & 0xffff;
532 t
= (unsigned long) e
[6] & 0xffff;
537 /* Pack the third long.
538 Each element of the input REAL_VALUE_TYPE array has 16 useful bits
540 th
= (unsigned long) e
[5] & 0xffff;
541 t
= (unsigned long) e
[4] & 0xffff;
544 /* fall into the double case */
547 /* Pack the second long */
548 th
= (unsigned long) e
[3] & 0xffff;
549 t
= (unsigned long) e
[2] & 0xffff;
552 /* fall into the float case */
556 /* Pack the first long */
557 th
= (unsigned long) e
[1] & 0xffff;
558 t
= (unsigned long) e
[0] & 0xffff;
570 /* This is the implementation of the REAL_ARITHMETIC macro. */
573 earith (value
, icode
, r1
, r2
)
574 REAL_VALUE_TYPE
*value
;
579 unsigned EMUSHORT d1
[NE
], d2
[NE
], v
[NE
];
585 /* Return NaN input back to the caller. */
588 PUT_REAL (d1
, value
);
593 PUT_REAL (d2
, value
);
597 code
= (enum tree_code
) icode
;
605 esub (d2
, d1
, v
); /* d1 - d2 */
613 #ifndef REAL_INFINITY
614 if (ecmp (d2
, ezero
) == 0)
617 enan (v
, eisneg (d1
) ^ eisneg (d2
));
624 ediv (d2
, d1
, v
); /* d1/d2 */
627 case MIN_EXPR
: /* min (d1,d2) */
628 if (ecmp (d1
, d2
) < 0)
634 case MAX_EXPR
: /* max (d1,d2) */
635 if (ecmp (d1
, d2
) > 0)
648 /* Truncate REAL_VALUE_TYPE toward zero to signed HOST_WIDE_INT.
649 implements REAL_VALUE_RNDZINT (x) (etrunci (x)). */
655 unsigned EMUSHORT f
[NE
], g
[NE
];
671 /* Truncate REAL_VALUE_TYPE toward zero to unsigned HOST_WIDE_INT;
672 implements REAL_VALUE_UNSIGNED_RNDZINT (x) (etruncui (x)). */
678 unsigned EMUSHORT f
[NE
], g
[NE
];
680 unsigned HOST_WIDE_INT l
;
694 /* This is the REAL_VALUE_ATOF function. It converts a decimal or hexadecimal
695 string to binary, rounding off as indicated by the machine_mode argument.
696 Then it promotes the rounded value to REAL_VALUE_TYPE. */
703 unsigned EMUSHORT tem
[NE
], e
[NE
];
746 /* Expansion of REAL_NEGATE. */
752 unsigned EMUSHORT e
[NE
];
762 /* Round real toward zero to HOST_WIDE_INT;
763 implements REAL_VALUE_FIX (x). */
769 unsigned EMUSHORT f
[NE
], g
[NE
];
776 warning ("conversion from NaN to int");
784 /* Round real toward zero to unsigned HOST_WIDE_INT
785 implements REAL_VALUE_UNSIGNED_FIX (x).
786 Negative input returns zero. */
788 unsigned HOST_WIDE_INT
792 unsigned EMUSHORT f
[NE
], g
[NE
];
793 unsigned HOST_WIDE_INT l
;
799 warning ("conversion from NaN to unsigned int");
808 /* REAL_VALUE_FROM_INT macro. */
811 ereal_from_int (d
, i
, j
, mode
)
814 enum machine_mode mode
;
816 unsigned EMUSHORT df
[NE
], dg
[NE
];
817 HOST_WIDE_INT low
, high
;
820 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
827 /* complement and add 1 */
834 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
835 ultoe ((unsigned HOST_WIDE_INT
*) &high
, dg
);
837 ultoe ((unsigned HOST_WIDE_INT
*) &low
, df
);
842 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
843 Avoid double-rounding errors later by rounding off now from the
844 extra-wide internal format to the requested precision. */
845 switch (GET_MODE_BITSIZE (mode
))
875 /* REAL_VALUE_FROM_UNSIGNED_INT macro. */
878 ereal_from_uint (d
, i
, j
, mode
)
880 unsigned HOST_WIDE_INT i
, j
;
881 enum machine_mode mode
;
883 unsigned EMUSHORT df
[NE
], dg
[NE
];
884 unsigned HOST_WIDE_INT low
, high
;
886 if (GET_MODE_CLASS (mode
) != MODE_FLOAT
)
890 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
896 /* A REAL_VALUE_TYPE may not be wide enough to hold the two HOST_WIDE_INTS.
897 Avoid double-rounding errors later by rounding off now from the
898 extra-wide internal format to the requested precision. */
899 switch (GET_MODE_BITSIZE (mode
))
929 /* REAL_VALUE_TO_INT macro. */
932 ereal_to_int (low
, high
, rr
)
933 HOST_WIDE_INT
*low
, *high
;
936 unsigned EMUSHORT d
[NE
], df
[NE
], dg
[NE
], dh
[NE
];
943 warning ("conversion from NaN to int");
949 /* convert positive value */
956 eldexp (eone
, HOST_BITS_PER_WIDE_INT
, df
);
957 ediv (df
, d
, dg
); /* dg = d / 2^32 is the high word */
958 euifrac (dg
, (unsigned HOST_WIDE_INT
*) high
, dh
);
959 emul (df
, dh
, dg
); /* fractional part is the low word */
960 euifrac (dg
, (unsigned HOST_WIDE_INT
*)low
, dh
);
963 /* complement and add 1 */
973 /* REAL_VALUE_LDEXP macro. */
980 unsigned EMUSHORT e
[NE
], y
[NE
];
993 /* These routines are conditionally compiled because functions
994 of the same names may be defined in fold-const.c. */
996 #ifdef REAL_ARITHMETIC
998 /* Check for infinity in a REAL_VALUE_TYPE. */
1004 unsigned EMUSHORT e
[NE
];
1008 return (eisinf (e
));
1014 /* Check whether a REAL_VALUE_TYPE item is a NaN. */
1020 unsigned EMUSHORT e
[NE
];
1024 return (eisnan (e
));
1031 /* Check for a negative REAL_VALUE_TYPE number.
1032 This just checks the sign bit, so that -0 counts as negative. */
1038 return ereal_isneg (x
);
1041 /* Expansion of REAL_VALUE_TRUNCATE.
1042 The result is in floating point, rounded to nearest or even. */
1045 real_value_truncate (mode
, arg
)
1046 enum machine_mode mode
;
1047 REAL_VALUE_TYPE arg
;
1049 unsigned EMUSHORT e
[NE
], t
[NE
];
1095 /* If an unsupported type was requested, presume that
1096 the machine files know something useful to do with
1097 the unmodified value. */
1106 /* Try to change R into its exact multiplicative inverse in machine mode
1107 MODE. Return nonzero function value if successful. */
1110 exact_real_inverse (mode
, r
)
1111 enum machine_mode mode
;
1114 unsigned EMUSHORT e
[NE
], einv
[NE
];
1115 REAL_VALUE_TYPE rinv
;
1120 /* Test for input in range. Don't transform IEEE special values. */
1121 if (eisinf (e
) || eisnan (e
) || (ecmp (e
, ezero
) == 0))
1124 /* Test for a power of 2: all significand bits zero except the MSB.
1125 We are assuming the target has binary (or hex) arithmetic. */
1126 if (e
[NE
- 2] != 0x8000)
1129 for (i
= 0; i
< NE
- 2; i
++)
1135 /* Compute the inverse and truncate it to the required mode. */
1136 ediv (e
, eone
, einv
);
1137 PUT_REAL (einv
, &rinv
);
1138 rinv
= real_value_truncate (mode
, rinv
);
1140 #ifdef CHECK_FLOAT_VALUE
1141 /* This check is not redundant. It may, for example, flush
1142 a supposedly IEEE denormal value to zero. */
1144 if (CHECK_FLOAT_VALUE (mode
, rinv
, i
))
1147 GET_REAL (&rinv
, einv
);
1149 /* Check the bits again, because the truncation might have
1150 generated an arbitrary saturation value on overflow. */
1151 if (einv
[NE
- 2] != 0x8000)
1154 for (i
= 0; i
< NE
- 2; i
++)
1160 /* Fail if the computed inverse is out of range. */
1161 if (eisinf (einv
) || eisnan (einv
) || (ecmp (einv
, ezero
) == 0))
1164 /* Output the reciprocal and return success flag. */
1168 #endif /* REAL_ARITHMETIC defined */
1170 /* Used for debugging--print the value of R in human-readable format
1179 REAL_VALUE_TO_DECIMAL (r
, "%.20g", dstr
);
1180 fprintf (stderr
, "%s", dstr
);
1184 /* The following routines convert REAL_VALUE_TYPE to the various floating
1185 point formats that are meaningful to supported computers.
1187 The results are returned in 32-bit pieces, each piece stored in a `long'.
1188 This is so they can be printed by statements like
1190 fprintf (file, "%lx, %lx", L[0], L[1]);
1192 that will work on both narrow- and wide-word host computers. */
1194 /* Convert R to a 128-bit long double precision value. The output array L
1195 contains four 32-bit pieces of the result, in the order they would appear
1203 unsigned EMUSHORT e
[NE
];
1207 endian (e
, l
, TFmode
);
1210 /* Convert R to a double extended precision value. The output array L
1211 contains three 32-bit pieces of the result, in the order they would
1212 appear in memory. */
1219 unsigned EMUSHORT e
[NE
];
1223 endian (e
, l
, XFmode
);
1226 /* Convert R to a double precision value. The output array L contains two
1227 32-bit pieces of the result, in the order they would appear in memory. */
1234 unsigned EMUSHORT e
[NE
];
1238 endian (e
, l
, DFmode
);
1241 /* Convert R to a single precision float value stored in the least-significant
1242 bits of a `long'. */
1248 unsigned EMUSHORT e
[NE
];
1253 endian (e
, &l
, SFmode
);
1257 /* Convert X to a decimal ASCII string S for output to an assembly
1258 language file. Note, there is no standard way to spell infinity or
1259 a NaN, so these values may require special treatment in the tm.h
1263 ereal_to_decimal (x
, s
)
1267 unsigned EMUSHORT e
[NE
];
1273 /* Compare X and Y. Return 1 if X > Y, 0 if X == Y, -1 if X < Y,
1274 or -2 if either is a NaN. */
1278 REAL_VALUE_TYPE x
, y
;
1280 unsigned EMUSHORT ex
[NE
], ey
[NE
];
1284 return (ecmp (ex
, ey
));
1287 /* Return 1 if the sign bit of X is set, else return 0. */
1293 unsigned EMUSHORT ex
[NE
];
1296 return (eisneg (ex
));
1299 /* End of REAL_ARITHMETIC interface */
1302 Extended precision IEEE binary floating point arithmetic routines
1304 Numbers are stored in C language as arrays of 16-bit unsigned
1305 short integers. The arguments of the routines are pointers to
1308 External e type data structure, similar to Intel 8087 chip
1309 temporary real format but possibly with a larger significand:
1311 NE-1 significand words (least significant word first,
1312 most significant bit is normally set)
1313 exponent (value = EXONE for 1.0,
1314 top bit is the sign)
1317 Internal exploded e-type data structure of a number (a "word" is 16 bits):
1319 ei[0] sign word (0 for positive, 0xffff for negative)
1320 ei[1] biased exponent (value = EXONE for the number 1.0)
1321 ei[2] high guard word (always zero after normalization)
1323 to ei[NI-2] significand (NI-4 significand words,
1324 most significant word first,
1325 most significant bit is set)
1326 ei[NI-1] low guard word (0x8000 bit is rounding place)
1330 Routines for external format e-type numbers
1332 asctoe (string, e) ASCII string to extended double e type
1333 asctoe64 (string, &d) ASCII string to long double
1334 asctoe53 (string, &d) ASCII string to double
1335 asctoe24 (string, &f) ASCII string to single
1336 asctoeg (string, e, prec) ASCII string to specified precision
1337 e24toe (&f, e) IEEE single precision to e type
1338 e53toe (&d, e) IEEE double precision to e type
1339 e64toe (&d, e) IEEE long double precision to e type
1340 e113toe (&d, e) 128-bit long double precision to e type
1342 eabs (e) absolute value
1344 eadd (a, b, c) c = b + a
1346 ecmp (a, b) Returns 1 if a > b, 0 if a == b,
1347 -1 if a < b, -2 if either a or b is a NaN.
1348 ediv (a, b, c) c = b / a
1349 efloor (a, b) truncate to integer, toward -infinity
1350 efrexp (a, exp, s) extract exponent and significand
1351 eifrac (e, &l, frac) e to HOST_WIDE_INT and e type fraction
1352 euifrac (e, &l, frac) e to unsigned HOST_WIDE_INT and e type fraction
1353 einfin (e) set e to infinity, leaving its sign alone
1354 eldexp (a, n, b) multiply by 2**n
1356 emul (a, b, c) c = b * a
1359 eround (a, b) b = nearest integer value to a
1361 esub (a, b, c) c = b - a
1363 e24toasc (&f, str, n) single to ASCII string, n digits after decimal
1364 e53toasc (&d, str, n) double to ASCII string, n digits after decimal
1365 e64toasc (&d, str, n) 80-bit long double to ASCII string
1366 e113toasc (&d, str, n) 128-bit long double to ASCII string
1368 etoasc (e, str, n) e to ASCII string, n digits after decimal
1369 etoe24 (e, &f) convert e type to IEEE single precision
1370 etoe53 (e, &d) convert e type to IEEE double precision
1371 etoe64 (e, &d) convert e type to IEEE long double precision
1372 ltoe (&l, e) HOST_WIDE_INT to e type
1373 ultoe (&l, e) unsigned HOST_WIDE_INT to e type
1374 eisneg (e) 1 if sign bit of e != 0, else 0
1375 eisinf (e) 1 if e has maximum exponent (non-IEEE)
1376 or is infinite (IEEE)
1377 eisnan (e) 1 if e is a NaN
1380 Routines for internal format exploded e-type numbers
1382 eaddm (ai, bi) add significands, bi = bi + ai
1384 ecleazs (ei) set ei = 0 but leave its sign alone
1385 ecmpm (ai, bi) compare significands, return 1, 0, or -1
1386 edivm (ai, bi) divide significands, bi = bi / ai
1387 emdnorm (ai,l,s,exp) normalize and round off
1388 emovi (a, ai) convert external a to internal ai
1389 emovo (ai, a) convert internal ai to external a
1390 emovz (ai, bi) bi = ai, low guard word of bi = 0
1391 emulm (ai, bi) multiply significands, bi = bi * ai
1392 enormlz (ei) left-justify the significand
1393 eshdn1 (ai) shift significand and guards down 1 bit
1394 eshdn8 (ai) shift down 8 bits
1395 eshdn6 (ai) shift down 16 bits
1396 eshift (ai, n) shift ai n bits up (or down if n < 0)
1397 eshup1 (ai) shift significand and guards up 1 bit
1398 eshup8 (ai) shift up 8 bits
1399 eshup6 (ai) shift up 16 bits
1400 esubm (ai, bi) subtract significands, bi = bi - ai
1401 eiisinf (ai) 1 if infinite
1402 eiisnan (ai) 1 if a NaN
1403 eiisneg (ai) 1 if sign bit of ai != 0, else 0
1404 einan (ai) set ai = NaN
1406 eiinfin (ai) set ai = infinity
1409 The result is always normalized and rounded to NI-4 word precision
1410 after each arithmetic operation.
1412 Exception flags are NOT fully supported.
1414 Signaling NaN's are NOT supported; they are treated the same
1417 Define INFINITY for support of infinity; otherwise a
1418 saturation arithmetic is implemented.
1420 Define NANS for support of Not-a-Number items; otherwise the
1421 arithmetic will never produce a NaN output, and might be confused
1423 If NaN's are supported, the output of `ecmp (a,b)' is -2 if
1424 either a or b is a NaN. This means asking `if (ecmp (a,b) < 0)'
1425 may not be legitimate. Use `if (ecmp (a,b) == -1)' for `less than'
1428 Denormals are always supported here where appropriate (e.g., not
1429 for conversion to DEC numbers). */
1431 /* Definitions for error codes that are passed to the common error handling
1434 For Digital Equipment PDP-11 and VAX computers, certain
1435 IBM systems, and others that use numbers with a 56-bit
1436 significand, the symbol DEC should be defined. In this
1437 mode, most floating point constants are given as arrays
1438 of octal integers to eliminate decimal to binary conversion
1439 errors that might be introduced by the compiler.
1441 For computers, such as IBM PC, that follow the IEEE
1442 Standard for Binary Floating Point Arithmetic (ANSI/IEEE
1443 Std 754-1985), the symbol IEEE should be defined.
1444 These numbers have 53-bit significands. In this mode, constants
1445 are provided as arrays of hexadecimal 16 bit integers.
1446 The endian-ness of generated values is controlled by
1447 REAL_WORDS_BIG_ENDIAN.
1449 To accommodate other types of computer arithmetic, all
1450 constants are also provided in a normal decimal radix
1451 which one can hope are correctly converted to a suitable
1452 format by the available C language compiler. To invoke
1453 this mode, the symbol UNK is defined.
1455 An important difference among these modes is a predefined
1456 set of machine arithmetic constants for each. The numbers
1457 MACHEP (the machine roundoff error), MAXNUM (largest number
1458 represented), and several other parameters are preset by
1459 the configuration symbol. Check the file const.c to
1460 ensure that these values are correct for your computer.
1462 For ANSI C compatibility, define ANSIC equal to 1. Currently
1463 this affects only the atan2 function and others that use it. */
1465 /* Constant definitions for math error conditions. */
1467 #define DOMAIN 1 /* argument domain error */
1468 #define SING 2 /* argument singularity */
1469 #define OVERFLOW 3 /* overflow range error */
1470 #define UNDERFLOW 4 /* underflow range error */
1471 #define TLOSS 5 /* total loss of precision */
1472 #define PLOSS 6 /* partial loss of precision */
1473 #define INVALID 7 /* NaN-producing operation */
1475 /* e type constants used by high precision check routines */
1477 #if LONG_DOUBLE_TYPE_SIZE == 128
1479 unsigned EMUSHORT ezero
[NE
] =
1480 {0x0000, 0x0000, 0x0000, 0x0000,
1481 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,};
1482 extern unsigned EMUSHORT ezero
[];
1485 unsigned EMUSHORT ehalf
[NE
] =
1486 {0x0000, 0x0000, 0x0000, 0x0000,
1487 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3ffe,};
1488 extern unsigned EMUSHORT ehalf
[];
1491 unsigned EMUSHORT eone
[NE
] =
1492 {0x0000, 0x0000, 0x0000, 0x0000,
1493 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x3fff,};
1494 extern unsigned EMUSHORT eone
[];
1497 unsigned EMUSHORT etwo
[NE
] =
1498 {0x0000, 0x0000, 0x0000, 0x0000,
1499 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4000,};
1500 extern unsigned EMUSHORT etwo
[];
1503 unsigned EMUSHORT e32
[NE
] =
1504 {0x0000, 0x0000, 0x0000, 0x0000,
1505 0x0000, 0x0000, 0x0000, 0x0000, 0x8000, 0x4004,};
1506 extern unsigned EMUSHORT e32
[];
1508 /* 6.93147180559945309417232121458176568075500134360255E-1 */
1509 unsigned EMUSHORT elog2
[NE
] =
1510 {0x40f3, 0xf6af, 0x03f2, 0xb398,
1511 0xc9e3, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1512 extern unsigned EMUSHORT elog2
[];
1514 /* 1.41421356237309504880168872420969807856967187537695E0 */
1515 unsigned EMUSHORT esqrt2
[NE
] =
1516 {0x1d6f, 0xbe9f, 0x754a, 0x89b3,
1517 0x597d, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1518 extern unsigned EMUSHORT esqrt2
[];
1520 /* 3.14159265358979323846264338327950288419716939937511E0 */
1521 unsigned EMUSHORT epi
[NE
] =
1522 {0x2902, 0x1cd1, 0x80dc, 0x628b,
1523 0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1524 extern unsigned EMUSHORT epi
[];
1527 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
1528 unsigned EMUSHORT ezero
[NE
] =
1529 {0, 0000000, 0000000, 0000000, 0000000, 0000000,};
1530 unsigned EMUSHORT ehalf
[NE
] =
1531 {0, 0000000, 0000000, 0000000, 0100000, 0x3ffe,};
1532 unsigned EMUSHORT eone
[NE
] =
1533 {0, 0000000, 0000000, 0000000, 0100000, 0x3fff,};
1534 unsigned EMUSHORT etwo
[NE
] =
1535 {0, 0000000, 0000000, 0000000, 0100000, 0040000,};
1536 unsigned EMUSHORT e32
[NE
] =
1537 {0, 0000000, 0000000, 0000000, 0100000, 0040004,};
1538 unsigned EMUSHORT elog2
[NE
] =
1539 {0xc9e4, 0x79ab, 0150717, 0013767, 0130562, 0x3ffe,};
1540 unsigned EMUSHORT esqrt2
[NE
] =
1541 {0x597e, 0x6484, 0174736, 0171463, 0132404, 0x3fff,};
1542 unsigned EMUSHORT epi
[NE
] =
1543 {0xc4c6, 0xc234, 0020550, 0155242, 0144417, 0040000,};
1546 /* Control register for rounding precision.
1547 This can be set to 113 (if NE=10), 80 (if NE=6), 64, 56, 53, or 24 bits. */
1552 /* Clear out entire e-type number X. */
1556 register unsigned EMUSHORT
*x
;
1560 for (i
= 0; i
< NE
; i
++)
1564 /* Move e-type number from A to B. */
1568 register unsigned EMUSHORT
*a
, *b
;
1572 for (i
= 0; i
< NE
; i
++)
1578 /* Absolute value of e-type X. */
1582 unsigned EMUSHORT x
[];
1584 /* sign is top bit of last word of external format */
1585 x
[NE
- 1] &= 0x7fff;
1589 /* Negate the e-type number X. */
1593 unsigned EMUSHORT x
[];
1596 x
[NE
- 1] ^= 0x8000; /* Toggle the sign bit */
1599 /* Return 1 if sign bit of e-type number X is nonzero, else zero. */
1603 unsigned EMUSHORT x
[];
1606 if (x
[NE
- 1] & 0x8000)
1612 /* Return 1 if e-type number X is infinity, else return zero. */
1616 unsigned EMUSHORT x
[];
1623 if ((x
[NE
- 1] & 0x7fff) == 0x7fff)
1629 /* Check if e-type number is not a number. The bit pattern is one that we
1630 defined, so we know for sure how to detect it. */
1634 unsigned EMUSHORT x
[];
1639 /* NaN has maximum exponent */
1640 if ((x
[NE
- 1] & 0x7fff) != 0x7fff)
1642 /* ... and non-zero significand field. */
1643 for (i
= 0; i
< NE
- 1; i
++)
1653 /* Fill e-type number X with infinity pattern (IEEE)
1654 or largest possible number (non-IEEE). */
1658 register unsigned EMUSHORT
*x
;
1663 for (i
= 0; i
< NE
- 1; i
++)
1667 for (i
= 0; i
< NE
- 1; i
++)
1695 /* Output an e-type NaN.
1696 This generates Intel's quiet NaN pattern for extended real.
1697 The exponent is 7fff, the leading mantissa word is c000. */
1701 register unsigned EMUSHORT
*x
;
1706 for (i
= 0; i
< NE
- 2; i
++)
1709 *x
= (sign
<< 15) | 0x7fff;
1712 /* Move in an e-type number A, converting it to exploded e-type B. */
1716 unsigned EMUSHORT
*a
, *b
;
1718 register unsigned EMUSHORT
*p
, *q
;
1722 p
= a
+ (NE
- 1); /* point to last word of external number */
1723 /* get the sign bit */
1728 /* get the exponent */
1730 *q
++ &= 0x7fff; /* delete the sign bit */
1732 if ((*(q
- 1) & 0x7fff) == 0x7fff)
1738 for (i
= 3; i
< NI
; i
++)
1744 for (i
= 2; i
< NI
; i
++)
1750 /* clear high guard word */
1752 /* move in the significand */
1753 for (i
= 0; i
< NE
- 1; i
++)
1755 /* clear low guard word */
1759 /* Move out exploded e-type number A, converting it to e type B. */
1763 unsigned EMUSHORT
*a
, *b
;
1765 register unsigned EMUSHORT
*p
, *q
;
1766 unsigned EMUSHORT i
;
1770 q
= b
+ (NE
- 1); /* point to output exponent */
1771 /* combine sign and exponent */
1774 *q
-- = *p
++ | 0x8000;
1778 if (*(p
- 1) == 0x7fff)
1783 enan (b
, eiisneg (a
));
1791 /* skip over guard word */
1793 /* move the significand */
1794 for (j
= 0; j
< NE
- 1; j
++)
1798 /* Clear out exploded e-type number XI. */
1802 register unsigned EMUSHORT
*xi
;
1806 for (i
= 0; i
< NI
; i
++)
1810 /* Clear out exploded e-type XI, but don't touch the sign. */
1814 register unsigned EMUSHORT
*xi
;
1819 for (i
= 0; i
< NI
- 1; i
++)
1823 /* Move exploded e-type number from A to B. */
1827 register unsigned EMUSHORT
*a
, *b
;
1831 for (i
= 0; i
< NI
- 1; i
++)
1833 /* clear low guard word */
1837 /* Generate exploded e-type NaN.
1838 The explicit pattern for this is maximum exponent and
1839 top two significant bits set. */
1843 unsigned EMUSHORT x
[];
1851 /* Return nonzero if exploded e-type X is a NaN. */
1855 unsigned EMUSHORT x
[];
1859 if ((x
[E
] & 0x7fff) == 0x7fff)
1861 for (i
= M
+ 1; i
< NI
; i
++)
1870 /* Return nonzero if sign of exploded e-type X is nonzero. */
1874 unsigned EMUSHORT x
[];
1881 /* Fill exploded e-type X with infinity pattern.
1882 This has maximum exponent and significand all zeros. */
1886 unsigned EMUSHORT x
[];
1894 /* Return nonzero if exploded e-type X is infinite. */
1898 unsigned EMUSHORT x
[];
1905 if ((x
[E
] & 0x7fff) == 0x7fff)
1911 /* Compare significands of numbers in internal exploded e-type format.
1912 Guard words are included in the comparison.
1920 register unsigned EMUSHORT
*a
, *b
;
1924 a
+= M
; /* skip up to significand area */
1926 for (i
= M
; i
< NI
; i
++)
1934 if (*(--a
) > *(--b
))
1940 /* Shift significand of exploded e-type X down by 1 bit. */
1944 register unsigned EMUSHORT
*x
;
1946 register unsigned EMUSHORT bits
;
1949 x
+= M
; /* point to significand area */
1952 for (i
= M
; i
< NI
; i
++)
1964 /* Shift significand of exploded e-type X up by 1 bit. */
1968 register unsigned EMUSHORT
*x
;
1970 register unsigned EMUSHORT bits
;
1976 for (i
= M
; i
< NI
; i
++)
1989 /* Shift significand of exploded e-type X down by 8 bits. */
1993 register unsigned EMUSHORT
*x
;
1995 register unsigned EMUSHORT newbyt
, oldbyt
;
2000 for (i
= M
; i
< NI
; i
++)
2010 /* Shift significand of exploded e-type X up by 8 bits. */
2014 register unsigned EMUSHORT
*x
;
2017 register unsigned EMUSHORT newbyt
, oldbyt
;
2022 for (i
= M
; i
< NI
; i
++)
2032 /* Shift significand of exploded e-type X up by 16 bits. */
2036 register unsigned EMUSHORT
*x
;
2039 register unsigned EMUSHORT
*p
;
2044 for (i
= M
; i
< NI
- 1; i
++)
2050 /* Shift significand of exploded e-type X down by 16 bits. */
2054 register unsigned EMUSHORT
*x
;
2057 register unsigned EMUSHORT
*p
;
2062 for (i
= M
; i
< NI
- 1; i
++)
2068 /* Add significands of exploded e-type X and Y. X + Y replaces Y. */
2072 unsigned EMUSHORT
*x
, *y
;
2074 register unsigned EMULONG a
;
2081 for (i
= M
; i
< NI
; i
++)
2083 a
= (unsigned EMULONG
) (*x
) + (unsigned EMULONG
) (*y
) + carry
;
2088 *y
= (unsigned EMUSHORT
) a
;
2094 /* Subtract significands of exploded e-type X and Y. Y - X replaces Y. */
2098 unsigned EMUSHORT
*x
, *y
;
2107 for (i
= M
; i
< NI
; i
++)
2109 a
= (unsigned EMULONG
) (*y
) - (unsigned EMULONG
) (*x
) - carry
;
2114 *y
= (unsigned EMUSHORT
) a
;
2121 static unsigned EMUSHORT equot
[NI
];
2125 /* Radix 2 shift-and-add versions of multiply and divide */
2128 /* Divide significands */
2132 unsigned EMUSHORT den
[], num
[];
2135 register unsigned EMUSHORT
*p
, *q
;
2136 unsigned EMUSHORT j
;
2142 for (i
= M
; i
< NI
; i
++)
2147 /* Use faster compare and subtraction if denominator has only 15 bits of
2153 for (i
= M
+ 3; i
< NI
; i
++)
2158 if ((den
[M
+ 1] & 1) != 0)
2166 for (i
= 0; i
< NBITS
+ 2; i
++)
2184 /* The number of quotient bits to calculate is NBITS + 1 scaling guard
2185 bit + 1 roundoff bit. */
2190 for (i
= 0; i
< NBITS
+ 2; i
++)
2192 if (ecmpm (den
, num
) <= 0)
2195 j
= 1; /* quotient bit = 1 */
2209 /* test for nonzero remainder after roundoff bit */
2212 for (i
= M
; i
< NI
; i
++)
2220 for (i
= 0; i
< NI
; i
++)
2226 /* Multiply significands */
2230 unsigned EMUSHORT a
[], b
[];
2232 unsigned EMUSHORT
*p
, *q
;
2237 for (i
= M
; i
< NI
; i
++)
2242 while (*p
== 0) /* significand is not supposed to be zero */
2247 if ((*p
& 0xff) == 0)
2255 for (i
= 0; i
< k
; i
++)
2259 /* remember if there were any nonzero bits shifted out */
2266 for (i
= 0; i
< NI
; i
++)
2269 /* return flag for lost nonzero bits */
2275 /* Radix 65536 versions of multiply and divide. */
2277 /* Multiply significand of e-type number B
2278 by 16-bit quantity A, return e-type result to C. */
2283 unsigned EMUSHORT b
[], c
[];
2285 register unsigned EMUSHORT
*pp
;
2286 register unsigned EMULONG carry
;
2287 unsigned EMUSHORT
*ps
;
2288 unsigned EMUSHORT p
[NI
];
2289 unsigned EMULONG aa
, m
;
2298 for (i
=M
+1; i
<NI
; i
++)
2308 m
= (unsigned EMULONG
) aa
* *ps
--;
2309 carry
= (m
& 0xffff) + *pp
;
2310 *pp
-- = (unsigned EMUSHORT
)carry
;
2311 carry
= (carry
>> 16) + (m
>> 16) + *pp
;
2312 *pp
= (unsigned EMUSHORT
)carry
;
2313 *(pp
-1) = carry
>> 16;
2316 for (i
=M
; i
<NI
; i
++)
2320 /* Divide significands of exploded e-types NUM / DEN. Neither the
2321 numerator NUM nor the denominator DEN is permitted to have its high guard
2326 unsigned EMUSHORT den
[], num
[];
2329 register unsigned EMUSHORT
*p
;
2330 unsigned EMULONG tnum
;
2331 unsigned EMUSHORT j
, tdenm
, tquot
;
2332 unsigned EMUSHORT tprod
[NI
+1];
2338 for (i
=M
; i
<NI
; i
++)
2344 for (i
=M
; i
<NI
; i
++)
2346 /* Find trial quotient digit (the radix is 65536). */
2347 tnum
= (((unsigned EMULONG
) num
[M
]) << 16) + num
[M
+1];
2349 /* Do not execute the divide instruction if it will overflow. */
2350 if ((tdenm
* (unsigned long)0xffff) < tnum
)
2353 tquot
= tnum
/ tdenm
;
2354 /* Multiply denominator by trial quotient digit. */
2355 m16m ((unsigned int)tquot
, den
, tprod
);
2356 /* The quotient digit may have been overestimated. */
2357 if (ecmpm (tprod
, num
) > 0)
2361 if (ecmpm (tprod
, num
) > 0)
2371 /* test for nonzero remainder after roundoff bit */
2374 for (i
=M
; i
<NI
; i
++)
2381 for (i
=0; i
<NI
; i
++)
2387 /* Multiply significands of exploded e-type A and B, result in B. */
2391 unsigned EMUSHORT a
[], b
[];
2393 unsigned EMUSHORT
*p
, *q
;
2394 unsigned EMUSHORT pprod
[NI
];
2395 unsigned EMUSHORT j
;
2400 for (i
=M
; i
<NI
; i
++)
2406 for (i
=M
+1; i
<NI
; i
++)
2414 m16m ((unsigned int) *p
--, b
, pprod
);
2415 eaddm(pprod
, equot
);
2421 for (i
=0; i
<NI
; i
++)
2424 /* return flag for lost nonzero bits */
2430 /* Normalize and round off.
2432 The internal format number to be rounded is S.
2433 Input LOST is 0 if the value is exact. This is the so-called sticky bit.
2435 Input SUBFLG indicates whether the number was obtained
2436 by a subtraction operation. In that case if LOST is nonzero
2437 then the number is slightly smaller than indicated.
2439 Input EXP is the biased exponent, which may be negative.
2440 the exponent field of S is ignored but is replaced by
2441 EXP as adjusted by normalization and rounding.
2443 Input RCNTRL is the rounding control. If it is nonzero, the
2444 returned value will be rounded to RNDPRC bits.
2446 For future reference: In order for emdnorm to round off denormal
2447 significands at the right point, the input exponent must be
2448 adjusted to be the actual value it would have after conversion to
2449 the final floating point type. This adjustment has been
2450 implemented for all type conversions (etoe53, etc.) and decimal
2451 conversions, but not for the arithmetic functions (eadd, etc.).
2452 Data types having standard 15-bit exponents are not affected by
2453 this, but SFmode and DFmode are affected. For example, ediv with
2454 rndprc = 24 will not round correctly to 24-bit precision if the
2455 result is denormal. */
2457 static int rlast
= -1;
2459 static unsigned EMUSHORT rmsk
= 0;
2460 static unsigned EMUSHORT rmbit
= 0;
2461 static unsigned EMUSHORT rebit
= 0;
2463 static unsigned EMUSHORT rbit
[NI
];
2466 emdnorm (s
, lost
, subflg
, exp
, rcntrl
)
2467 unsigned EMUSHORT s
[];
2474 unsigned EMUSHORT r
;
2479 /* a blank significand could mean either zero or infinity. */
2492 if ((j
> NBITS
) && (exp
< 32767))
2500 if (exp
> (EMULONG
) (-NBITS
- 1))
2513 /* Round off, unless told not to by rcntrl. */
2516 /* Set up rounding parameters if the control register changed. */
2517 if (rndprc
!= rlast
)
2524 rw
= NI
- 1; /* low guard word */
2547 /* For DEC or IBM arithmetic */
2564 /* For C4x arithmetic */
2585 /* Shift down 1 temporarily if the data structure has an implied
2586 most significant bit and the number is denormal.
2587 Intel long double denormals also lose one bit of precision. */
2588 if ((exp
<= 0) && (rndprc
!= NBITS
)
2589 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2591 lost
|= s
[NI
- 1] & 1;
2594 /* Clear out all bits below the rounding bit,
2595 remembering in r if any were nonzero. */
2609 if ((r
& rmbit
) != 0)
2615 { /* round to even */
2616 if ((s
[re
] & rebit
) == 0)
2629 /* Undo the temporary shift for denormal values. */
2630 if ((exp
<= 0) && (rndprc
!= NBITS
)
2631 && ((rndprc
!= 64) || ((rndprc
== 64) && ! REAL_WORDS_BIG_ENDIAN
)))
2636 { /* overflow on roundoff */
2649 for (i
= 2; i
< NI
- 1; i
++)
2652 warning ("floating point overflow");
2656 for (i
= M
+ 1; i
< NI
- 1; i
++)
2659 if ((rndprc
< 64) || (rndprc
== 113))
2674 s
[1] = (unsigned EMUSHORT
) exp
;
2677 /* Subtract. C = B - A, all e type numbers. */
2679 static int subflg
= 0;
2683 unsigned EMUSHORT
*a
, *b
, *c
;
2697 /* Infinity minus infinity is a NaN.
2698 Test for subtracting infinities of the same sign. */
2699 if (eisinf (a
) && eisinf (b
)
2700 && ((eisneg (a
) ^ eisneg (b
)) == 0))
2702 mtherr ("esub", INVALID
);
2711 /* Add. C = A + B, all e type. */
2715 unsigned EMUSHORT
*a
, *b
, *c
;
2719 /* NaN plus anything is a NaN. */
2730 /* Infinity minus infinity is a NaN.
2731 Test for adding infinities of opposite signs. */
2732 if (eisinf (a
) && eisinf (b
)
2733 && ((eisneg (a
) ^ eisneg (b
)) != 0))
2735 mtherr ("esub", INVALID
);
2744 /* Arithmetic common to both addition and subtraction. */
2748 unsigned EMUSHORT
*a
, *b
, *c
;
2750 unsigned EMUSHORT ai
[NI
], bi
[NI
], ci
[NI
];
2752 EMULONG lt
, lta
, ltb
;
2773 /* compare exponents */
2778 { /* put the larger number in bi */
2788 if (lt
< (EMULONG
) (-NBITS
- 1))
2789 goto done
; /* answer same as larger addend */
2791 lost
= eshift (ai
, k
); /* shift the smaller number down */
2795 /* exponents were the same, so must compare significands */
2798 { /* the numbers are identical in magnitude */
2799 /* if different signs, result is zero */
2805 /* if same sign, result is double */
2806 /* double denormalized tiny number */
2807 if ((bi
[E
] == 0) && ((bi
[3] & 0x8000) == 0))
2812 /* add 1 to exponent unless both are zero! */
2813 for (j
= 1; j
< NI
- 1; j
++)
2829 bi
[E
] = (unsigned EMUSHORT
) ltb
;
2833 { /* put the larger number in bi */
2849 emdnorm (bi
, lost
, subflg
, ltb
, 64);
2855 /* Divide: C = B/A, all e type. */
2859 unsigned EMUSHORT
*a
, *b
, *c
;
2861 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2863 EMULONG lt
, lta
, ltb
;
2865 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2866 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2867 sign
= eisneg(a
) ^ eisneg(b
);
2870 /* Return any NaN input. */
2881 /* Zero over zero, or infinity over infinity, is a NaN. */
2882 if (((ecmp (a
, ezero
) == 0) && (ecmp (b
, ezero
) == 0))
2883 || (eisinf (a
) && eisinf (b
)))
2885 mtherr ("ediv", INVALID
);
2890 /* Infinity over anything else is infinity. */
2897 /* Anything else over infinity is zero. */
2909 { /* See if numerator is zero. */
2910 for (i
= 1; i
< NI
- 1; i
++)
2914 ltb
-= enormlz (bi
);
2924 { /* possible divide by zero */
2925 for (i
= 1; i
< NI
- 1; i
++)
2929 lta
-= enormlz (ai
);
2933 /* Divide by zero is not an invalid operation.
2934 It is a divide-by-zero operation! */
2936 mtherr ("ediv", SING
);
2942 /* calculate exponent */
2943 lt
= ltb
- lta
+ EXONE
;
2944 emdnorm (bi
, i
, 0, lt
, 64);
2951 && (ecmp (c
, ezero
) != 0)
2954 *(c
+(NE
-1)) |= 0x8000;
2956 *(c
+(NE
-1)) &= ~0x8000;
2959 /* Multiply e-types A and B, return e-type product C. */
2963 unsigned EMUSHORT
*a
, *b
, *c
;
2965 unsigned EMUSHORT ai
[NI
], bi
[NI
];
2967 EMULONG lt
, lta
, ltb
;
2969 /* IEEE says if result is not a NaN, the sign is "-" if and only if
2970 operands have opposite signs -- but flush -0 to 0 later if not IEEE. */
2971 sign
= eisneg(a
) ^ eisneg(b
);
2974 /* NaN times anything is the same NaN. */
2985 /* Zero times infinity is a NaN. */
2986 if ((eisinf (a
) && (ecmp (b
, ezero
) == 0))
2987 || (eisinf (b
) && (ecmp (a
, ezero
) == 0)))
2989 mtherr ("emul", INVALID
);
2994 /* Infinity times anything else is infinity. */
2996 if (eisinf (a
) || eisinf (b
))
3008 for (i
= 1; i
< NI
- 1; i
++)
3012 lta
-= enormlz (ai
);
3023 for (i
= 1; i
< NI
- 1; i
++)
3027 ltb
-= enormlz (bi
);
3036 /* Multiply significands */
3038 /* calculate exponent */
3039 lt
= lta
+ ltb
- (EXONE
- 1);
3040 emdnorm (bi
, j
, 0, lt
, 64);
3047 && (ecmp (c
, ezero
) != 0)
3050 *(c
+(NE
-1)) |= 0x8000;
3052 *(c
+(NE
-1)) &= ~0x8000;
3055 /* Convert double precision PE to e-type Y. */
3059 unsigned EMUSHORT
*pe
, *y
;
3068 ibmtoe (pe
, y
, DFmode
);
3073 c4xtoe (pe
, y
, HFmode
);
3076 register unsigned EMUSHORT r
;
3077 register unsigned EMUSHORT
*e
, *p
;
3078 unsigned EMUSHORT yy
[NI
];
3082 denorm
= 0; /* flag if denormalized number */
3084 if (! REAL_WORDS_BIG_ENDIAN
)
3090 yy
[M
] = (r
& 0x0f) | 0x10;
3091 r
&= ~0x800f; /* strip sign and 4 significand bits */
3096 if (! REAL_WORDS_BIG_ENDIAN
)
3098 if (((pe
[3] & 0xf) != 0) || (pe
[2] != 0)
3099 || (pe
[1] != 0) || (pe
[0] != 0))
3101 enan (y
, yy
[0] != 0);
3107 if (((pe
[0] & 0xf) != 0) || (pe
[1] != 0)
3108 || (pe
[2] != 0) || (pe
[3] != 0))
3110 enan (y
, yy
[0] != 0);
3121 #endif /* INFINITY */
3123 /* If zero exponent, then the significand is denormalized.
3124 So take back the understood high significand bit. */
3135 if (! REAL_WORDS_BIG_ENDIAN
)
3152 /* If zero exponent, then normalize the significand. */
3153 if ((k
= enormlz (yy
)) > NBITS
)
3156 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3159 #endif /* not C4X */
3160 #endif /* not IBM */
3161 #endif /* not DEC */
3164 /* Convert double extended precision float PE to e type Y. */
3168 unsigned EMUSHORT
*pe
, *y
;
3170 unsigned EMUSHORT yy
[NI
];
3171 unsigned EMUSHORT
*e
, *p
, *q
;
3176 for (i
= 0; i
< NE
- 5; i
++)
3178 /* This precision is not ordinarily supported on DEC or IBM. */
3180 for (i
= 0; i
< 5; i
++)
3184 p
= &yy
[0] + (NE
- 1);
3187 for (i
= 0; i
< 5; i
++)
3191 if (! REAL_WORDS_BIG_ENDIAN
)
3193 for (i
= 0; i
< 5; i
++)
3196 /* For denormal long double Intel format, shift significand up one
3197 -- but only if the top significand bit is zero. A top bit of 1
3198 is "pseudodenormal" when the exponent is zero. */
3199 if((yy
[NE
-1] & 0x7fff) == 0 && (yy
[NE
-2] & 0x8000) == 0)
3201 unsigned EMUSHORT temp
[NI
];
3211 p
= &yy
[0] + (NE
- 1);
3212 #ifdef ARM_EXTENDED_IEEE_FORMAT
3213 /* For ARMs, the exponent is in the lowest 15 bits of the word. */
3214 *p
-- = (e
[0] & 0x8000) | (e
[1] & 0x7ffff);
3220 for (i
= 0; i
< 4; i
++)
3225 /* Point to the exponent field and check max exponent cases. */
3227 if ((*p
& 0x7fff) == 0x7fff)
3230 if (! REAL_WORDS_BIG_ENDIAN
)
3232 for (i
= 0; i
< 4; i
++)
3234 if ((i
!= 3 && pe
[i
] != 0)
3235 /* Anything but 0x8000 here, including 0, is a NaN. */
3236 || (i
== 3 && pe
[i
] != 0x8000))
3238 enan (y
, (*p
& 0x8000) != 0);
3245 #ifdef ARM_EXTENDED_IEEE_FORMAT
3246 for (i
= 2; i
<= 5; i
++)
3250 enan (y
, (*p
& 0x8000) != 0);
3255 /* In Motorola extended precision format, the most significant
3256 bit of an infinity mantissa could be either 1 or 0. It is
3257 the lower order bits that tell whether the value is a NaN. */
3258 if ((pe
[2] & 0x7fff) != 0)
3261 for (i
= 3; i
<= 5; i
++)
3266 enan (y
, (*p
& 0x8000) != 0);
3270 #endif /* not ARM */
3279 #endif /* INFINITY */
3282 for (i
= 0; i
< NE
; i
++)
3286 /* Convert 128-bit long double precision float PE to e type Y. */
3290 unsigned EMUSHORT
*pe
, *y
;
3292 register unsigned EMUSHORT r
;
3293 unsigned EMUSHORT
*e
, *p
;
3294 unsigned EMUSHORT yy
[NI
];
3301 if (! REAL_WORDS_BIG_ENDIAN
)
3313 if (! REAL_WORDS_BIG_ENDIAN
)
3315 for (i
= 0; i
< 7; i
++)
3319 enan (y
, yy
[0] != 0);
3326 for (i
= 1; i
< 8; i
++)
3330 enan (y
, yy
[0] != 0);
3342 #endif /* INFINITY */
3346 if (! REAL_WORDS_BIG_ENDIAN
)
3348 for (i
= 0; i
< 7; i
++)
3354 for (i
= 0; i
< 7; i
++)
3358 /* If denormal, remove the implied bit; else shift down 1. */
3371 /* Convert single precision float PE to e type Y. */
3375 unsigned EMUSHORT
*pe
, *y
;
3379 ibmtoe (pe
, y
, SFmode
);
3385 c4xtoe (pe
, y
, QFmode
);
3389 register unsigned EMUSHORT r
;
3390 register unsigned EMUSHORT
*e
, *p
;
3391 unsigned EMUSHORT yy
[NI
];
3395 denorm
= 0; /* flag if denormalized number */
3398 if (! REAL_WORDS_BIG_ENDIAN
)
3408 yy
[M
] = (r
& 0x7f) | 0200;
3409 r
&= ~0x807f; /* strip sign and 7 significand bits */
3414 if (REAL_WORDS_BIG_ENDIAN
)
3416 if (((pe
[0] & 0x7f) != 0) || (pe
[1] != 0))
3418 enan (y
, yy
[0] != 0);
3424 if (((pe
[1] & 0x7f) != 0) || (pe
[0] != 0))
3426 enan (y
, yy
[0] != 0);
3437 #endif /* INFINITY */
3439 /* If zero exponent, then the significand is denormalized.
3440 So take back the understood high significand bit. */
3453 if (! REAL_WORDS_BIG_ENDIAN
)
3463 { /* if zero exponent, then normalize the significand */
3464 if ((k
= enormlz (yy
)) > NBITS
)
3467 yy
[E
] -= (unsigned EMUSHORT
) (k
- 1);
3470 #endif /* not C4X */
3471 #endif /* not IBM */
3474 /* Convert e-type X to IEEE 128-bit long double format E. */
3478 unsigned EMUSHORT
*x
, *e
;
3480 unsigned EMUSHORT xi
[NI
];
3487 make_nan (e
, eisneg (x
), TFmode
);
3492 exp
= (EMULONG
) xi
[E
];
3497 /* round off to nearest or even */
3500 emdnorm (xi
, 0, 0, exp
, 64);
3506 /* Convert exploded e-type X, that has already been rounded to
3507 113-bit precision, to IEEE 128-bit long double format Y. */
3511 unsigned EMUSHORT
*a
, *b
;
3513 register unsigned EMUSHORT
*p
, *q
;
3514 unsigned EMUSHORT i
;
3519 make_nan (b
, eiisneg (a
), TFmode
);
3524 if (REAL_WORDS_BIG_ENDIAN
)
3527 q
= b
+ 7; /* point to output exponent */
3529 /* If not denormal, delete the implied bit. */
3534 /* combine sign and exponent */
3536 if (REAL_WORDS_BIG_ENDIAN
)
3539 *q
++ = *p
++ | 0x8000;
3546 *q
-- = *p
++ | 0x8000;
3550 /* skip over guard word */
3552 /* move the significand */
3553 if (REAL_WORDS_BIG_ENDIAN
)
3555 for (i
= 0; i
< 7; i
++)
3560 for (i
= 0; i
< 7; i
++)
3565 /* Convert e-type X to IEEE double extended format E. */
3569 unsigned EMUSHORT
*x
, *e
;
3571 unsigned EMUSHORT xi
[NI
];
3578 make_nan (e
, eisneg (x
), XFmode
);
3583 /* adjust exponent for offset */
3584 exp
= (EMULONG
) xi
[E
];
3589 /* round off to nearest or even */
3592 emdnorm (xi
, 0, 0, exp
, 64);
3598 /* Convert exploded e-type X, that has already been rounded to
3599 64-bit precision, to IEEE double extended format Y. */
3603 unsigned EMUSHORT
*a
, *b
;
3605 register unsigned EMUSHORT
*p
, *q
;
3606 unsigned EMUSHORT i
;
3611 make_nan (b
, eiisneg (a
), XFmode
);
3615 /* Shift denormal long double Intel format significand down one bit. */
3616 if ((a
[E
] == 0) && ! REAL_WORDS_BIG_ENDIAN
)
3626 if (REAL_WORDS_BIG_ENDIAN
)
3630 q
= b
+ 4; /* point to output exponent */
3631 #if LONG_DOUBLE_TYPE_SIZE == 96
3632 /* Clear the last two bytes of 12-byte Intel format */
3638 /* combine sign and exponent */
3642 *q
++ = *p
++ | 0x8000;
3649 *q
-- = *p
++ | 0x8000;
3654 if (REAL_WORDS_BIG_ENDIAN
)
3656 #ifdef ARM_EXTENDED_IEEE_FORMAT
3657 /* The exponent is in the lowest 15 bits of the first word. */
3658 *q
++ = i
? 0x8000 : 0;
3662 *q
++ = *p
++ | 0x8000;
3671 *q
-- = *p
++ | 0x8000;
3676 /* skip over guard word */
3678 /* move the significand */
3680 for (i
= 0; i
< 4; i
++)
3684 for (i
= 0; i
< 4; i
++)
3688 if (REAL_WORDS_BIG_ENDIAN
)
3690 for (i
= 0; i
< 4; i
++)
3698 /* Intel long double infinity significand. */
3706 for (i
= 0; i
< 4; i
++)
3712 /* e type to double precision. */
3715 /* Convert e-type X to DEC-format double E. */
3719 unsigned EMUSHORT
*x
, *e
;
3721 etodec (x
, e
); /* see etodec.c */
3724 /* Convert exploded e-type X, that has already been rounded to
3725 56-bit double precision, to DEC double Y. */
3729 unsigned EMUSHORT
*x
, *y
;
3736 /* Convert e-type X to IBM 370-format double E. */
3740 unsigned EMUSHORT
*x
, *e
;
3742 etoibm (x
, e
, DFmode
);
3745 /* Convert exploded e-type X, that has already been rounded to
3746 56-bit precision, to IBM 370 double Y. */
3750 unsigned EMUSHORT
*x
, *y
;
3752 toibm (x
, y
, DFmode
);
3755 #else /* it's neither DEC nor IBM */
3757 /* Convert e-type X to C4X-format long double E. */
3761 unsigned EMUSHORT
*x
, *e
;
3763 etoc4x (x
, e
, HFmode
);
3766 /* Convert exploded e-type X, that has already been rounded to
3767 56-bit precision, to IBM 370 double Y. */
3771 unsigned EMUSHORT
*x
, *y
;
3773 toc4x (x
, y
, HFmode
);
3776 #else /* it's neither DEC nor IBM nor C4X */
3778 /* Convert e-type X to IEEE double E. */
3782 unsigned EMUSHORT
*x
, *e
;
3784 unsigned EMUSHORT xi
[NI
];
3791 make_nan (e
, eisneg (x
), DFmode
);
3796 /* adjust exponent for offsets */
3797 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x3ff);
3802 /* round off to nearest or even */
3805 emdnorm (xi
, 0, 0, exp
, 64);
3811 /* Convert exploded e-type X, that has already been rounded to
3812 53-bit precision, to IEEE double Y. */
3816 unsigned EMUSHORT
*x
, *y
;
3818 unsigned EMUSHORT i
;
3819 unsigned EMUSHORT
*p
;
3824 make_nan (y
, eiisneg (x
), DFmode
);
3830 if (! REAL_WORDS_BIG_ENDIAN
)
3833 *y
= 0; /* output high order */
3835 *y
= 0x8000; /* output sign bit */
3838 if (i
>= (unsigned int) 2047)
3840 /* Saturate at largest number less than infinity. */
3843 if (! REAL_WORDS_BIG_ENDIAN
)
3857 *y
|= (unsigned EMUSHORT
) 0x7fef;
3858 if (! REAL_WORDS_BIG_ENDIAN
)
3883 i
|= *p
++ & (unsigned EMUSHORT
) 0x0f; /* *p = xi[M] */
3884 *y
|= (unsigned EMUSHORT
) i
; /* high order output already has sign bit set */
3885 if (! REAL_WORDS_BIG_ENDIAN
)
3900 #endif /* not C4X */
3901 #endif /* not IBM */
3902 #endif /* not DEC */
3906 /* e type to single precision. */
3909 /* Convert e-type X to IBM 370 float E. */
3913 unsigned EMUSHORT
*x
, *e
;
3915 etoibm (x
, e
, SFmode
);
3918 /* Convert exploded e-type X, that has already been rounded to
3919 float precision, to IBM 370 float Y. */
3923 unsigned EMUSHORT
*x
, *y
;
3925 toibm (x
, y
, SFmode
);
3931 /* Convert e-type X to C4X float E. */
3935 unsigned EMUSHORT
*x
, *e
;
3937 etoc4x (x
, e
, QFmode
);
3940 /* Convert exploded e-type X, that has already been rounded to
3941 float precision, to IBM 370 float Y. */
3945 unsigned EMUSHORT
*x
, *y
;
3947 toc4x (x
, y
, QFmode
);
3952 /* Convert e-type X to IEEE float E. DEC float is the same as IEEE float. */
3956 unsigned EMUSHORT
*x
, *e
;
3959 unsigned EMUSHORT xi
[NI
];
3965 make_nan (e
, eisneg (x
), SFmode
);
3970 /* adjust exponent for offsets */
3971 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0177);
3976 /* round off to nearest or even */
3979 emdnorm (xi
, 0, 0, exp
, 64);
3985 /* Convert exploded e-type X, that has already been rounded to
3986 float precision, to IEEE float Y. */
3990 unsigned EMUSHORT
*x
, *y
;
3992 unsigned EMUSHORT i
;
3993 unsigned EMUSHORT
*p
;
3998 make_nan (y
, eiisneg (x
), SFmode
);
4004 if (! REAL_WORDS_BIG_ENDIAN
)
4010 *y
= 0; /* output high order */
4012 *y
= 0x8000; /* output sign bit */
4015 /* Handle overflow cases. */
4019 *y
|= (unsigned EMUSHORT
) 0x7f80;
4024 if (! REAL_WORDS_BIG_ENDIAN
)
4032 #else /* no INFINITY */
4033 *y
|= (unsigned EMUSHORT
) 0x7f7f;
4038 if (! REAL_WORDS_BIG_ENDIAN
)
4049 #endif /* no INFINITY */
4061 i
|= *p
++ & (unsigned EMUSHORT
) 0x7f; /* *p = xi[M] */
4062 /* High order output already has sign bit set. */
4068 if (! REAL_WORDS_BIG_ENDIAN
)
4077 #endif /* not C4X */
4078 #endif /* not IBM */
4080 /* Compare two e type numbers.
4084 -2 if either a or b is a NaN. */
4088 unsigned EMUSHORT
*a
, *b
;
4090 unsigned EMUSHORT ai
[NI
], bi
[NI
];
4091 register unsigned EMUSHORT
*p
, *q
;
4096 if (eisnan (a
) || eisnan (b
))
4105 { /* the signs are different */
4107 for (i
= 1; i
< NI
- 1; i
++)
4121 /* both are the same sign */
4136 return (0); /* equality */
4140 if (*(--p
) > *(--q
))
4141 return (msign
); /* p is bigger */
4143 return (-msign
); /* p is littler */
4147 /* Find e-type nearest integer to X, as floor (X + 0.5). */
4151 unsigned EMUSHORT
*x
, *y
;
4158 /* Convert HOST_WIDE_INT LP to e type Y. */
4163 unsigned EMUSHORT
*y
;
4165 unsigned EMUSHORT yi
[NI
];
4166 unsigned HOST_WIDE_INT ll
;
4172 /* make it positive */
4173 ll
= (unsigned HOST_WIDE_INT
) (-(*lp
));
4174 yi
[0] = 0xffff; /* put correct sign in the e type number */
4178 ll
= (unsigned HOST_WIDE_INT
) (*lp
);
4180 /* move the long integer to yi significand area */
4181 #if HOST_BITS_PER_WIDE_INT == 64
4182 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4183 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4184 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4185 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4186 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4188 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4189 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4190 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4193 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4194 ecleaz (yi
); /* it was zero */
4196 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
4197 emovo (yi
, y
); /* output the answer */
4200 /* Convert unsigned HOST_WIDE_INT LP to e type Y. */
4204 unsigned HOST_WIDE_INT
*lp
;
4205 unsigned EMUSHORT
*y
;
4207 unsigned EMUSHORT yi
[NI
];
4208 unsigned HOST_WIDE_INT ll
;
4214 /* move the long integer to ayi significand area */
4215 #if HOST_BITS_PER_WIDE_INT == 64
4216 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 48);
4217 yi
[M
+ 1] = (unsigned EMUSHORT
) (ll
>> 32);
4218 yi
[M
+ 2] = (unsigned EMUSHORT
) (ll
>> 16);
4219 yi
[M
+ 3] = (unsigned EMUSHORT
) ll
;
4220 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
4222 yi
[M
] = (unsigned EMUSHORT
) (ll
>> 16);
4223 yi
[M
+ 1] = (unsigned EMUSHORT
) ll
;
4224 yi
[E
] = EXONE
+ 15; /* exponent if normalize shift count were 0 */
4227 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
4228 ecleaz (yi
); /* it was zero */
4230 yi
[E
] -= (unsigned EMUSHORT
) k
; /* subtract shift count from exponent */
4231 emovo (yi
, y
); /* output the answer */
4235 /* Find signed HOST_WIDE_INT integer I and floating point fractional
4236 part FRAC of e-type (packed internal format) floating point input X.
4237 The integer output I has the sign of the input, except that
4238 positive overflow is permitted if FIXUNS_TRUNC_LIKE_FIX_TRUNC.
4239 The output e-type fraction FRAC is the positive fractional
4244 unsigned EMUSHORT
*x
;
4246 unsigned EMUSHORT
*frac
;
4248 unsigned EMUSHORT xi
[NI
];
4250 unsigned HOST_WIDE_INT ll
;
4253 k
= (int) xi
[E
] - (EXONE
- 1);
4256 /* if exponent <= 0, integer = 0 and real output is fraction */
4261 if (k
> (HOST_BITS_PER_WIDE_INT
- 1))
4263 /* long integer overflow: output large integer
4264 and correct fraction */
4266 *i
= ((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1);
4269 #ifdef FIXUNS_TRUNC_LIKE_FIX_TRUNC
4270 /* In this case, let it overflow and convert as if unsigned. */
4271 euifrac (x
, &ll
, frac
);
4272 *i
= (HOST_WIDE_INT
) ll
;
4275 /* In other cases, return the largest positive integer. */
4276 *i
= (((unsigned HOST_WIDE_INT
) 1) << (HOST_BITS_PER_WIDE_INT
- 1)) - 1;
4281 warning ("overflow on truncation to integer");
4285 /* Shift more than 16 bits: first shift up k-16 mod 16,
4286 then shift up by 16's. */
4287 j
= k
- ((k
>> 4) << 4);
4294 ll
= (ll
<< 16) | xi
[M
];
4296 while ((k
-= 16) > 0);
4303 /* shift not more than 16 bits */
4305 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4312 if ((k
= enormlz (xi
)) > NBITS
)
4315 xi
[E
] -= (unsigned EMUSHORT
) k
;
4321 /* Find unsigned HOST_WIDE_INT integer I and floating point fractional part
4322 FRAC of e-type X. A negative input yields integer output = 0 but
4323 correct fraction. */
4326 euifrac (x
, i
, frac
)
4327 unsigned EMUSHORT
*x
;
4328 unsigned HOST_WIDE_INT
*i
;
4329 unsigned EMUSHORT
*frac
;
4331 unsigned HOST_WIDE_INT ll
;
4332 unsigned EMUSHORT xi
[NI
];
4336 k
= (int) xi
[E
] - (EXONE
- 1);
4339 /* if exponent <= 0, integer = 0 and argument is fraction */
4344 if (k
> HOST_BITS_PER_WIDE_INT
)
4346 /* Long integer overflow: output large integer
4347 and correct fraction.
4348 Note, the BSD microvax compiler says that ~(0UL)
4349 is a syntax error. */
4353 warning ("overflow on truncation to unsigned integer");
4357 /* Shift more than 16 bits: first shift up k-16 mod 16,
4358 then shift up by 16's. */
4359 j
= k
- ((k
>> 4) << 4);
4366 ll
= (ll
<< 16) | xi
[M
];
4368 while ((k
-= 16) > 0);
4373 /* shift not more than 16 bits */
4375 *i
= (HOST_WIDE_INT
) xi
[M
] & 0xffff;
4378 if (xi
[0]) /* A negative value yields unsigned integer 0. */
4384 if ((k
= enormlz (xi
)) > NBITS
)
4387 xi
[E
] -= (unsigned EMUSHORT
) k
;
4392 /* Shift the significand of exploded e-type X up or down by SC bits. */
4396 unsigned EMUSHORT
*x
;
4399 unsigned EMUSHORT lost
;
4400 unsigned EMUSHORT
*p
;
4413 lost
|= *p
; /* remember lost bits */
4454 return ((int) lost
);
4457 /* Shift normalize the significand area of exploded e-type X.
4458 Return the shift count (up = positive). */
4462 unsigned EMUSHORT x
[];
4464 register unsigned EMUSHORT
*p
;
4473 return (0); /* already normalized */
4479 /* With guard word, there are NBITS+16 bits available.
4480 Return true if all are zero. */
4484 /* see if high byte is zero */
4485 while ((*p
& 0xff00) == 0)
4490 /* now shift 1 bit at a time */
4491 while ((*p
& 0x8000) == 0)
4497 mtherr ("enormlz", UNDERFLOW
);
4503 /* Normalize by shifting down out of the high guard word
4504 of the significand */
4519 mtherr ("enormlz", OVERFLOW
);
4526 /* Powers of ten used in decimal <-> binary conversions. */
4531 #if LONG_DOUBLE_TYPE_SIZE == 128
4532 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4534 {0x6576, 0x4a92, 0x804a, 0x153f,
4535 0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4536 {0x6a32, 0xce52, 0x329a, 0x28ce,
4537 0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4538 {0x526c, 0x50ce, 0xf18b, 0x3d28,
4539 0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4540 {0x9c66, 0x58f8, 0xbc50, 0x5c54,
4541 0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4542 {0x851e, 0xeab7, 0x98fe, 0x901b,
4543 0xddbb, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4544 {0x0235, 0x0137, 0x36b1, 0x336c,
4545 0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4546 {0x50f8, 0x25fb, 0xc76b, 0x6b71,
4547 0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4548 {0x0000, 0x0000, 0x0000, 0x0000,
4549 0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4550 {0x0000, 0x0000, 0x0000, 0x0000,
4551 0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4552 {0x0000, 0x0000, 0x0000, 0x0000,
4553 0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4554 {0x0000, 0x0000, 0x0000, 0x0000,
4555 0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4556 {0x0000, 0x0000, 0x0000, 0x0000,
4557 0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4558 {0x0000, 0x0000, 0x0000, 0x0000,
4559 0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4562 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4564 {0x2030, 0xcffc, 0xa1c3, 0x8123,
4565 0x2de3, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4566 {0x8264, 0xd2cb, 0xf2ea, 0x12d4,
4567 0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4568 {0xf53f, 0xf698, 0x6bd3, 0x0158,
4569 0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4570 {0xe731, 0x04d4, 0xe3f2, 0xd332,
4571 0x7132, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4572 {0xa23e, 0x5308, 0xfefb, 0x1155,
4573 0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4574 {0xe26d, 0xdbde, 0xd05d, 0xb3f6,
4575 0xac7c, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4576 {0x2a20, 0x6224, 0x47b3, 0x98d7,
4577 0x3f23, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4578 {0x0b5b, 0x4af2, 0xa581, 0x18ed,
4579 0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4580 {0xbf71, 0xa9b3, 0x7989, 0xbe68,
4581 0x4c2e, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4582 {0x3d4d, 0x7c3d, 0x36ba, 0x0d2b,
4583 0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4584 {0xc155, 0xa4a8, 0x404e, 0x6113,
4585 0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4586 {0xd70a, 0x70a3, 0x0a3d, 0xa3d7,
4587 0x3d70, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4588 {0xcccd, 0xcccc, 0xcccc, 0xcccc,
4589 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4592 /* LONG_DOUBLE_TYPE_SIZE is other than 128 */
4593 static unsigned EMUSHORT etens
[NTEN
+ 1][NE
] =
4595 {0xc94c, 0x979a, 0x8a20, 0x5202, 0xc460, 0x7525,}, /* 10**4096 */
4596 {0xa74d, 0x5de4, 0xc53d, 0x3b5d, 0x9e8b, 0x5a92,}, /* 10**2048 */
4597 {0x650d, 0x0c17, 0x8175, 0x7586, 0xc976, 0x4d48,},
4598 {0xcc65, 0x91c6, 0xa60e, 0xa0ae, 0xe319, 0x46a3,},
4599 {0xddbc, 0xde8d, 0x9df9, 0xebfb, 0xaa7e, 0x4351,},
4600 {0xc66f, 0x8cdf, 0x80e9, 0x47c9, 0x93ba, 0x41a8,},
4601 {0x3cbf, 0xa6d5, 0xffcf, 0x1f49, 0xc278, 0x40d3,},
4602 {0xf020, 0xb59d, 0x2b70, 0xada8, 0x9dc5, 0x4069,},
4603 {0x0000, 0x0000, 0x0400, 0xc9bf, 0x8e1b, 0x4034,},
4604 {0x0000, 0x0000, 0x0000, 0x2000, 0xbebc, 0x4019,},
4605 {0x0000, 0x0000, 0x0000, 0x0000, 0x9c40, 0x400c,},
4606 {0x0000, 0x0000, 0x0000, 0x0000, 0xc800, 0x4005,},
4607 {0x0000, 0x0000, 0x0000, 0x0000, 0xa000, 0x4002,}, /* 10**1 */
4610 static unsigned EMUSHORT emtens
[NTEN
+ 1][NE
] =
4612 {0x2de4, 0x9fde, 0xd2ce, 0x04c8, 0xa6dd, 0x0ad8,}, /* 10**-4096 */
4613 {0x4925, 0x2de4, 0x3436, 0x534f, 0xceae, 0x256b,}, /* 10**-2048 */
4614 {0x87a6, 0xc0bd, 0xda57, 0x82a5, 0xa2a6, 0x32b5,},
4615 {0x7133, 0xd21c, 0xdb23, 0xee32, 0x9049, 0x395a,},
4616 {0xfa91, 0x1939, 0x637a, 0x4325, 0xc031, 0x3cac,},
4617 {0xac7d, 0xe4a0, 0x64bc, 0x467c, 0xddd0, 0x3e55,},
4618 {0x3f24, 0xe9a5, 0xa539, 0xea27, 0xa87f, 0x3f2a,},
4619 {0x67de, 0x94ba, 0x4539, 0x1ead, 0xcfb1, 0x3f94,},
4620 {0x4c2f, 0xe15b, 0xc44d, 0x94be, 0xe695, 0x3fc9,},
4621 {0xfdc2, 0xcefc, 0x8461, 0x7711, 0xabcc, 0x3fe4,},
4622 {0xd3c3, 0x652b, 0xe219, 0x1758, 0xd1b7, 0x3ff1,},
4623 {0x3d71, 0xd70a, 0x70a3, 0x0a3d, 0xa3d7, 0x3ff8,},
4624 {0xcccd, 0xcccc, 0xcccc, 0xcccc, 0xcccc, 0x3ffb,}, /* 10**-1 */
4629 /* Convert float value X to ASCII string STRING with NDIG digits after
4630 the decimal point. */
4633 e24toasc (x
, string
, ndigs
)
4634 unsigned EMUSHORT x
[];
4638 unsigned EMUSHORT w
[NI
];
4641 etoasc (w
, string
, ndigs
);
4644 /* Convert double value X to ASCII string STRING with NDIG digits after
4645 the decimal point. */
4648 e53toasc (x
, string
, ndigs
)
4649 unsigned EMUSHORT x
[];
4653 unsigned EMUSHORT w
[NI
];
4656 etoasc (w
, string
, ndigs
);
4659 /* Convert double extended value X to ASCII string STRING with NDIG digits
4660 after the decimal point. */
4663 e64toasc (x
, string
, ndigs
)
4664 unsigned EMUSHORT x
[];
4668 unsigned EMUSHORT w
[NI
];
4671 etoasc (w
, string
, ndigs
);
4674 /* Convert 128-bit long double value X to ASCII string STRING with NDIG digits
4675 after the decimal point. */
4678 e113toasc (x
, string
, ndigs
)
4679 unsigned EMUSHORT x
[];
4683 unsigned EMUSHORT w
[NI
];
4686 etoasc (w
, string
, ndigs
);
4690 /* Convert e-type X to ASCII string STRING with NDIGS digits after
4691 the decimal point. */
4693 static char wstring
[80]; /* working storage for ASCII output */
4696 etoasc (x
, string
, ndigs
)
4697 unsigned EMUSHORT x
[];
4702 unsigned EMUSHORT y
[NI
], t
[NI
], u
[NI
], w
[NI
];
4703 unsigned EMUSHORT
*p
, *r
, *ten
;
4704 unsigned EMUSHORT sign
;
4705 int i
, j
, k
, expon
, rndsav
;
4707 unsigned EMUSHORT m
;
4718 sprintf (wstring
, " NaN ");
4722 rndprc
= NBITS
; /* set to full precision */
4723 emov (x
, y
); /* retain external format */
4724 if (y
[NE
- 1] & 0x8000)
4727 y
[NE
- 1] &= 0x7fff;
4734 ten
= &etens
[NTEN
][0];
4736 /* Test for zero exponent */
4739 for (k
= 0; k
< NE
- 1; k
++)
4742 goto tnzro
; /* denormalized number */
4744 goto isone
; /* valid all zeros */
4748 /* Test for infinity. */
4749 if (y
[NE
- 1] == 0x7fff)
4752 sprintf (wstring
, " -Infinity ");
4754 sprintf (wstring
, " Infinity ");
4758 /* Test for exponent nonzero but significand denormalized.
4759 * This is an error condition.
4761 if ((y
[NE
- 1] != 0) && ((y
[NE
- 2] & 0x8000) == 0))
4763 mtherr ("etoasc", DOMAIN
);
4764 sprintf (wstring
, "NaN");
4768 /* Compare to 1.0 */
4777 { /* Number is greater than 1 */
4778 /* Convert significand to an integer and strip trailing decimal zeros. */
4780 u
[NE
- 1] = EXONE
+ NBITS
- 1;
4782 p
= &etens
[NTEN
- 4][0];
4788 for (j
= 0; j
< NE
- 1; j
++)
4801 /* Rescale from integer significand */
4802 u
[NE
- 1] += y
[NE
- 1] - (unsigned int) (EXONE
+ NBITS
- 1);
4804 /* Find power of 10 */
4808 /* An unordered compare result shouldn't happen here. */
4809 while (ecmp (ten
, u
) <= 0)
4811 if (ecmp (p
, u
) <= 0)
4824 { /* Number is less than 1.0 */
4825 /* Pad significand with trailing decimal zeros. */
4828 while ((y
[NE
- 2] & 0x8000) == 0)
4837 for (i
= 0; i
< NDEC
+ 1; i
++)
4839 if ((w
[NI
- 1] & 0x7) != 0)
4841 /* multiply by 10 */
4854 if (eone
[NE
- 1] <= u
[1])
4866 while (ecmp (eone
, w
) > 0)
4868 if (ecmp (p
, w
) >= 0)
4883 /* Find the first (leading) digit. */
4889 digit
= equot
[NI
- 1];
4890 while ((digit
== 0) && (ecmp (y
, ezero
) != 0))
4898 digit
= equot
[NI
- 1];
4906 /* Examine number of digits requested by caller. */
4924 *s
++ = (char)digit
+ '0';
4927 /* Generate digits after the decimal point. */
4928 for (k
= 0; k
<= ndigs
; k
++)
4930 /* multiply current number by 10, without normalizing */
4937 *s
++ = (char) equot
[NI
- 1] + '0';
4939 digit
= equot
[NI
- 1];
4942 /* round off the ASCII string */
4945 /* Test for critical rounding case in ASCII output. */
4949 if (ecmp (t
, ezero
) != 0)
4950 goto roun
; /* round to nearest */
4952 if ((*(s
- 1) & 1) == 0)
4953 goto doexp
; /* round to even */
4956 /* Round up and propagate carry-outs */
4960 /* Carry out to most significant digit? */
4967 /* Most significant digit carries to 10? */
4975 /* Round up and carry out from less significant digits */
4987 sprintf (ss, "e+%d", expon);
4989 sprintf (ss, "e%d", expon);
4991 sprintf (ss
, "e%d", expon
);
4994 /* copy out the working string */
4997 while (*ss
== ' ') /* strip possible leading space */
4999 while ((*s
++ = *ss
++) != '\0')
5004 /* Convert ASCII string to floating point.
5006 Numeric input is a free format decimal number of any length, with
5007 or without decimal point. Entering E after the number followed by an
5008 integer number causes the second number to be interpreted as a power of
5009 10 to be multiplied by the first number (i.e., "scientific" notation). */
5011 /* Convert ASCII string S to single precision float value Y. */
5016 unsigned EMUSHORT
*y
;
5022 /* Convert ASCII string S to double precision value Y. */
5027 unsigned EMUSHORT
*y
;
5029 #if defined(DEC) || defined(IBM)
5041 /* Convert ASCII string S to double extended value Y. */
5046 unsigned EMUSHORT
*y
;
5051 /* Convert ASCII string S to 128-bit long double Y. */
5056 unsigned EMUSHORT
*y
;
5058 asctoeg (s
, y
, 113);
5061 /* Convert ASCII string S to e type Y. */
5066 unsigned EMUSHORT
*y
;
5068 asctoeg (s
, y
, NBITS
);
5071 /* Convert ASCII string SS to e type Y, with a specified rounding precision
5072 of OPREC bits. BASE is 16 for C9X hexadecimal floating constants. */
5075 asctoeg (ss
, y
, oprec
)
5077 unsigned EMUSHORT
*y
;
5080 unsigned EMUSHORT yy
[NI
], xt
[NI
], tt
[NI
];
5081 int esign
, decflg
, sgnflg
, nexp
, exp
, prec
, lost
;
5082 int k
, trail
, c
, rndsav
;
5084 unsigned EMUSHORT nsign
, *p
;
5085 char *sp
, *s
, *lstr
;
5088 /* Copy the input string. */
5089 lstr
= (char *) alloca (strlen (ss
) + 1);
5091 while (*ss
== ' ') /* skip leading spaces */
5095 while ((*sp
++ = *ss
++) != '\0')
5099 if (s
[0] == '0' && (s
[1] == 'x' || s
[1] == 'X'))
5106 rndprc
= NBITS
; /* Set to full precision */
5118 if (*s
>= '0' && *s
<= '9')
5124 if ((k
>= 0) && (k
< base
))
5126 /* Ignore leading zeros */
5127 if ((prec
== 0) && (decflg
== 0) && (k
== 0))
5129 /* Identify and strip trailing zeros after the decimal point. */
5130 if ((trail
== 0) && (decflg
!= 0))
5133 while ((*sp
>= '0' && *sp
<= '9')
5134 || (base
== 16 && ((*sp
>= 'a' && *sp
<= 'f')
5135 || (*sp
>= 'A' && *sp
<= 'F'))))
5137 /* Check for syntax error */
5139 if ((base
!= 10 || ((c
!= 'e') && (c
!= 'E')))
5140 && (base
!= 16 || ((c
!= 'p') && (c
!= 'P')))
5142 && (c
!= '\n') && (c
!= '\r') && (c
!= ' ')
5153 /* If enough digits were given to more than fill up the yy register,
5154 continuing until overflow into the high guard word yy[2]
5155 guarantees that there will be a roundoff bit at the top
5156 of the low guard word after normalization. */
5163 nexp
+= 4; /* count digits after decimal point */
5165 eshup1 (yy
); /* multiply current number by 16 */
5173 nexp
+= 1; /* count digits after decimal point */
5175 eshup1 (yy
); /* multiply current number by 10 */
5181 /* Insert the current digit. */
5183 xt
[NI
- 2] = (unsigned EMUSHORT
) k
;
5188 /* Mark any lost non-zero digit. */
5190 /* Count lost digits before the decimal point. */
5212 case '.': /* decimal point */
5242 mtherr ("asctoe", DOMAIN
);
5251 /* Exponent interpretation */
5253 /* 0.0eXXX is zero, regardless of XXX. Check for the 0.0. */
5254 for (k
= 0; k
< NI
; k
++)
5265 /* check for + or - */
5273 while ((*s
>= '0') && (*s
<= '9'))
5282 if ((exp
> MAXDECEXP
) && (base
== 10))
5286 yy
[E
] = 0x7fff; /* infinity */
5289 if ((exp
< MINDECEXP
) && (base
== 10))
5299 /* Base 16 hexadecimal floating constant. */
5300 if ((k
= enormlz (yy
)) > NBITS
)
5305 /* Adjust the exponent. NEXP is the number of hex digits,
5306 EXP is a power of 2. */
5307 lexp
= (EXONE
- 1 + NBITS
) - k
+ yy
[E
] + exp
- nexp
;
5317 /* Pad trailing zeros to minimize power of 10, per IEEE spec. */
5318 while ((nexp
> 0) && (yy
[2] == 0))
5330 if ((k
= enormlz (yy
)) > NBITS
)
5335 lexp
= (EXONE
- 1 + NBITS
) - k
;
5336 emdnorm (yy
, lost
, 0, lexp
, 64);
5339 /* Convert to external format:
5341 Multiply by 10**nexp. If precision is 64 bits,
5342 the maximum relative error incurred in forming 10**n
5343 for 0 <= n <= 324 is 8.2e-20, at 10**180.
5344 For 0 <= n <= 999, the peak relative error is 1.4e-19 at 10**947.
5345 For 0 >= n >= -999, it is -1.55e-19 at 10**-435. */
5360 /* Punt. Can't handle this without 2 divides. */
5361 emovi (etens
[0], tt
);
5368 p
= &etens
[NTEN
][0];
5378 while (exp
<= MAXP
);
5397 /* Round and convert directly to the destination type */
5399 lexp
-= EXONE
- 0x3ff;
5401 else if (oprec
== 24 || oprec
== 32)
5402 lexp
-= (EXONE
- 0x7f);
5405 else if (oprec
== 24 || oprec
== 56)
5406 lexp
-= EXONE
- (0x41 << 2);
5408 else if (oprec
== 24)
5409 lexp
-= EXONE
- 0177;
5413 else if (oprec
== 56)
5414 lexp
-= EXONE
- 0201;
5417 emdnorm (yy
, lost
, 0, lexp
, 64);
5427 todec (yy
, y
); /* see etodec.c */
5432 toibm (yy
, y
, DFmode
);
5437 toc4x (yy
, y
, HFmode
);
5461 /* Return Y = largest integer not greater than X (truncated toward minus
5464 static unsigned EMUSHORT bmask
[] =
5487 unsigned EMUSHORT x
[], y
[];
5489 register unsigned EMUSHORT
*p
;
5491 unsigned EMUSHORT f
[NE
];
5493 emov (x
, f
); /* leave in external format */
5494 expon
= (int) f
[NE
- 1];
5495 e
= (expon
& 0x7fff) - (EXONE
- 1);
5501 /* number of bits to clear out */
5513 /* clear the remaining bits */
5515 /* truncate negatives toward minus infinity */
5518 if ((unsigned EMUSHORT
) expon
& (unsigned EMUSHORT
) 0x8000)
5520 for (i
= 0; i
< NE
- 1; i
++)
5533 /* Return S and EXP such that S * 2^EXP = X and .5 <= S < 1.
5534 For example, 1.1 = 0.55 * 2^1. */
5538 unsigned EMUSHORT x
[];
5540 unsigned EMUSHORT s
[];
5542 unsigned EMUSHORT xi
[NI
];
5546 /* Handle denormalized numbers properly using long integer exponent. */
5547 li
= (EMULONG
) ((EMUSHORT
) xi
[1]);
5555 *exp
= (int) (li
- 0x3ffe);
5559 /* Return e type Y = X * 2^PWR2. */
5563 unsigned EMUSHORT x
[];
5565 unsigned EMUSHORT y
[];
5567 unsigned EMUSHORT xi
[NI
];
5575 emdnorm (xi
, i
, i
, li
, 64);
5581 /* C = remainder after dividing B by A, all e type values.
5582 Least significant integer quotient bits left in EQUOT. */
5586 unsigned EMUSHORT a
[], b
[], c
[];
5588 unsigned EMUSHORT den
[NI
], num
[NI
];
5592 || (ecmp (a
, ezero
) == 0)
5600 if (ecmp (a
, ezero
) == 0)
5602 mtherr ("eremain", SING
);
5608 eiremain (den
, num
);
5609 /* Sign of remainder = sign of quotient */
5618 /* Return quotient of exploded e-types NUM / DEN in EQUOT,
5619 remainder in NUM. */
5623 unsigned EMUSHORT den
[], num
[];
5626 unsigned EMUSHORT j
;
5629 ld
-= enormlz (den
);
5631 ln
-= enormlz (num
);
5635 if (ecmpm (den
, num
) <= 0)
5647 emdnorm (num
, 0, 0, ln
, 0);
5650 /* Report an error condition CODE encountered in function NAME.
5652 Mnemonic Value Significance
5654 DOMAIN 1 argument domain error
5655 SING 2 function singularity
5656 OVERFLOW 3 overflow range error
5657 UNDERFLOW 4 underflow range error
5658 TLOSS 5 total loss of precision
5659 PLOSS 6 partial loss of precision
5660 INVALID 7 NaN - producing operation
5661 EDOM 33 Unix domain error code
5662 ERANGE 34 Unix range error code
5664 The order of appearance of the following messages is bound to the
5665 error codes defined above. */
5675 /* The string passed by the calling program is supposed to be the
5676 name of the function in which the error occurred.
5677 The code argument selects which error message string will be printed. */
5679 if (strcmp (name
, "esub") == 0)
5680 name
= "subtraction";
5681 else if (strcmp (name
, "ediv") == 0)
5683 else if (strcmp (name
, "emul") == 0)
5684 name
= "multiplication";
5685 else if (strcmp (name
, "enormlz") == 0)
5686 name
= "normalization";
5687 else if (strcmp (name
, "etoasc") == 0)
5688 name
= "conversion to text";
5689 else if (strcmp (name
, "asctoe") == 0)
5691 else if (strcmp (name
, "eremain") == 0)
5693 else if (strcmp (name
, "esqrt") == 0)
5694 name
= "square root";
5699 case DOMAIN
: warning ("%s: argument domain error" , name
); break;
5700 case SING
: warning ("%s: function singularity" , name
); break;
5701 case OVERFLOW
: warning ("%s: overflow range error" , name
); break;
5702 case UNDERFLOW
: warning ("%s: underflow range error" , name
); break;
5703 case TLOSS
: warning ("%s: total loss of precision" , name
); break;
5704 case PLOSS
: warning ("%s: partial loss of precision", name
); break;
5705 case INVALID
: warning ("%s: NaN - producing operation", name
); break;
5710 /* Set global error message word */
5715 /* Convert DEC double precision D to e type E. */
5719 unsigned EMUSHORT
*d
;
5720 unsigned EMUSHORT
*e
;
5722 unsigned EMUSHORT y
[NI
];
5723 register unsigned EMUSHORT r
, *p
;
5725 ecleaz (y
); /* start with a zero */
5726 p
= y
; /* point to our number */
5727 r
= *d
; /* get DEC exponent word */
5728 if (*d
& (unsigned int) 0x8000)
5729 *p
= 0xffff; /* fill in our sign */
5730 ++p
; /* bump pointer to our exponent word */
5731 r
&= 0x7fff; /* strip the sign bit */
5732 if (r
== 0) /* answer = 0 if high order DEC word = 0 */
5736 r
>>= 7; /* shift exponent word down 7 bits */
5737 r
+= EXONE
- 0201; /* subtract DEC exponent offset */
5738 /* add our e type exponent offset */
5739 *p
++ = r
; /* to form our exponent */
5741 r
= *d
++; /* now do the high order mantissa */
5742 r
&= 0177; /* strip off the DEC exponent and sign bits */
5743 r
|= 0200; /* the DEC understood high order mantissa bit */
5744 *p
++ = r
; /* put result in our high guard word */
5746 *p
++ = *d
++; /* fill in the rest of our mantissa */
5750 eshdn8 (y
); /* shift our mantissa down 8 bits */
5755 /* Convert e type X to DEC double precision D. */
5759 unsigned EMUSHORT
*x
, *d
;
5761 unsigned EMUSHORT xi
[NI
];
5766 /* Adjust exponent for offsets. */
5767 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0201);
5768 /* Round off to nearest or even. */
5771 emdnorm (xi
, 0, 0, exp
, 64);
5776 /* Convert exploded e-type X, that has already been rounded to
5777 56-bit precision, to DEC format double Y. */
5781 unsigned EMUSHORT
*x
, *y
;
5783 unsigned EMUSHORT i
;
5784 unsigned EMUSHORT
*p
;
5823 /* Convert IBM single/double precision to e type. */
5827 unsigned EMUSHORT
*d
;
5828 unsigned EMUSHORT
*e
;
5829 enum machine_mode mode
;
5831 unsigned EMUSHORT y
[NI
];
5832 register unsigned EMUSHORT r
, *p
;
5835 ecleaz (y
); /* start with a zero */
5836 p
= y
; /* point to our number */
5837 r
= *d
; /* get IBM exponent word */
5838 if (*d
& (unsigned int) 0x8000)
5839 *p
= 0xffff; /* fill in our sign */
5840 ++p
; /* bump pointer to our exponent word */
5841 r
&= 0x7f00; /* strip the sign bit */
5842 r
>>= 6; /* shift exponent word down 6 bits */
5843 /* in fact shift by 8 right and 2 left */
5844 r
+= EXONE
- (0x41 << 2); /* subtract IBM exponent offset */
5845 /* add our e type exponent offset */
5846 *p
++ = r
; /* to form our exponent */
5848 *p
++ = *d
++ & 0xff; /* now do the high order mantissa */
5849 /* strip off the IBM exponent and sign bits */
5850 if (mode
!= SFmode
) /* there are only 2 words in SFmode */
5852 *p
++ = *d
++; /* fill in the rest of our mantissa */
5857 if (y
[M
] == 0 && y
[M
+1] == 0 && y
[M
+2] == 0 && y
[M
+3] == 0)
5860 y
[E
] -= 5 + enormlz (y
); /* now normalise the mantissa */
5861 /* handle change in RADIX */
5867 /* Convert e type to IBM single/double precision. */
5871 unsigned EMUSHORT
*x
, *d
;
5872 enum machine_mode mode
;
5874 unsigned EMUSHORT xi
[NI
];
5879 exp
= (EMULONG
) xi
[E
] - (EXONE
- (0x41 << 2)); /* adjust exponent for offsets */
5880 /* round off to nearest or even */
5883 emdnorm (xi
, 0, 0, exp
, 64);
5885 toibm (xi
, d
, mode
);
5890 unsigned EMUSHORT
*x
, *y
;
5891 enum machine_mode mode
;
5893 unsigned EMUSHORT i
;
5894 unsigned EMUSHORT
*p
;
5944 /* Convert C4X single/double precision to e type. */
5948 unsigned EMUSHORT
*d
;
5949 unsigned EMUSHORT
*e
;
5950 enum machine_mode mode
;
5952 unsigned EMUSHORT y
[NI
];
5959 /* Short-circuit the zero case. */
5960 if ((d
[0] == 0x8000)
5962 && ((mode
== QFmode
) || ((d
[2] == 0x0000) && (d
[3] == 0x0000))))
5973 ecleaz (y
); /* start with a zero */
5974 r
= d
[0]; /* get sign/exponent part */
5975 if (r
& (unsigned int) 0x0080)
5977 y
[0] = 0xffff; /* fill in our sign */
5985 r
>>= 8; /* Shift exponent word down 8 bits. */
5986 if (r
& 0x80) /* Make the exponent negative if it is. */
5988 r
= r
| (~0 & ~0xff);
5993 /* Now do the high order mantissa. We don't "or" on the high bit
5994 because it is 2 (not 1) and is handled a little differently
5999 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6001 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6011 /* Now do the two's complement on the data. */
6013 carry
= 1; /* Initially add 1 for the two's complement. */
6014 for (i
=size
+ M
; i
> M
; i
--)
6016 if (carry
&& (y
[i
] == 0x0000))
6018 /* We overflowed into the next word, carry is the same. */
6019 y
[i
] = carry
? 0x0000 : 0xffff;
6023 /* No overflow, just invert and add carry. */
6024 y
[i
] = ((~y
[i
]) + carry
) & 0xffff;
6039 /* Add our e type exponent offset to form our exponent. */
6043 /* Now do the high order mantissa strip off the exponent and sign
6044 bits and add the high 1 bit. */
6045 y
[M
] = (d
[0] & 0x7f) | 0x80;
6048 if (mode
!= QFmode
) /* There are only 2 words in QFmode. */
6050 y
[M
+2] = d
[2]; /* Fill in the rest of our mantissa. */
6060 /* Convert e type to C4X single/double precision. */
6064 unsigned EMUSHORT
*x
, *d
;
6065 enum machine_mode mode
;
6067 unsigned EMUSHORT xi
[NI
];
6073 /* Adjust exponent for offsets. */
6074 exp
= (EMULONG
) xi
[E
] - (EXONE
- 0x7f);
6076 /* Round off to nearest or even. */
6078 rndprc
= mode
== QFmode
? 24 : 32;
6079 emdnorm (xi
, 0, 0, exp
, 64);
6081 toc4x (xi
, d
, mode
);
6086 unsigned EMUSHORT
*x
, *y
;
6087 enum machine_mode mode
;
6093 /* Short-circuit the zero case */
6094 if ((x
[0] == 0) /* Zero exponent and sign */
6096 && (x
[M
] == 0) /* The rest is for zero mantissa */
6098 /* Only check for double if necessary */
6099 && ((mode
== QFmode
) || ((x
[M
+2] == 0) && (x
[M
+3] == 0))))
6101 /* We have a zero. Put it into the output and return. */
6114 /* Negative number require a two's complement conversion of the
6120 i
= ((int) x
[1]) - 0x7f;
6122 /* Now add 1 to the inverted data to do the two's complement. */
6132 x
[v
] = carry
? 0x0000 : 0xffff;
6136 x
[v
] = ((~x
[v
]) + carry
) & 0xffff;
6142 /* The following is a special case. The C4X negative float requires
6143 a zero in the high bit (because the format is (2 - x) x 2^m), so
6144 if a one is in that bit, we have to shift left one to get rid
6145 of it. This only occurs if the number is -1 x 2^m. */
6146 if (x
[M
+1] & 0x8000)
6148 /* This is the case of -1 x 2^m, we have to rid ourselves of the
6149 high sign bit and shift the exponent. */
6156 i
= ((int) x
[1]) - 0x7f;
6159 if ((i
< -128) || (i
> 127))
6174 y
[0] |= ((i
& 0xff) << 8);
6178 y
[0] |= x
[M
] & 0x7f;
6188 /* Output a binary NaN bit pattern in the target machine's format. */
6190 /* If special NaN bit patterns are required, define them in tm.h
6191 as arrays of unsigned 16-bit shorts. Otherwise, use the default
6197 unsigned EMUSHORT TFbignan
[8] =
6198 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6199 unsigned EMUSHORT TFlittlenan
[8] = {0, 0, 0, 0, 0, 0, 0x8000, 0xffff};
6207 unsigned EMUSHORT XFbignan
[6] =
6208 {0x7fff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
6209 unsigned EMUSHORT XFlittlenan
[6] = {0, 0, 0, 0xc000, 0xffff, 0};
6217 unsigned EMUSHORT DFbignan
[4] = {0x7fff, 0xffff, 0xffff, 0xffff};
6218 unsigned EMUSHORT DFlittlenan
[4] = {0, 0, 0, 0xfff8};
6226 unsigned EMUSHORT SFbignan
[2] = {0x7fff, 0xffff};
6227 unsigned EMUSHORT SFlittlenan
[2] = {0, 0xffc0};
6233 make_nan (nan
, sign
, mode
)
6234 unsigned EMUSHORT
*nan
;
6236 enum machine_mode mode
;
6239 unsigned EMUSHORT
*p
;
6243 /* Possibly the `reserved operand' patterns on a VAX can be
6244 used like NaN's, but probably not in the same way as IEEE. */
6245 #if !defined(DEC) && !defined(IBM) && !defined(C4X)
6248 if (REAL_WORDS_BIG_ENDIAN
)
6256 if (REAL_WORDS_BIG_ENDIAN
)
6264 if (REAL_WORDS_BIG_ENDIAN
)
6273 if (REAL_WORDS_BIG_ENDIAN
)
6283 if (REAL_WORDS_BIG_ENDIAN
)
6284 *nan
++ = (sign
<< 15) | (*p
++ & 0x7fff);
6287 if (! REAL_WORDS_BIG_ENDIAN
)
6288 *nan
= (sign
<< 15) | (*p
& 0x7fff);
6291 /* This is the inverse of the function `etarsingle' invoked by
6292 REAL_VALUE_TO_TARGET_SINGLE. */
6295 ereal_unto_float (f
)
6299 unsigned EMUSHORT s
[2];
6300 unsigned EMUSHORT e
[NE
];
6302 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6303 This is the inverse operation to what the function `endian' does. */
6304 if (REAL_WORDS_BIG_ENDIAN
)
6306 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6307 s
[1] = (unsigned EMUSHORT
) f
;
6311 s
[0] = (unsigned EMUSHORT
) f
;
6312 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6314 /* Convert and promote the target float to E-type. */
6316 /* Output E-type to REAL_VALUE_TYPE. */
6322 /* This is the inverse of the function `etardouble' invoked by
6323 REAL_VALUE_TO_TARGET_DOUBLE. */
6326 ereal_unto_double (d
)
6330 unsigned EMUSHORT s
[4];
6331 unsigned EMUSHORT e
[NE
];
6333 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6334 if (REAL_WORDS_BIG_ENDIAN
)
6336 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6337 s
[1] = (unsigned EMUSHORT
) d
[0];
6338 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6339 s
[3] = (unsigned EMUSHORT
) d
[1];
6343 /* Target float words are little-endian. */
6344 s
[0] = (unsigned EMUSHORT
) d
[0];
6345 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6346 s
[2] = (unsigned EMUSHORT
) d
[1];
6347 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6349 /* Convert target double to E-type. */
6351 /* Output E-type to REAL_VALUE_TYPE. */
6357 /* Convert an SFmode target `float' value to a REAL_VALUE_TYPE.
6358 This is somewhat like ereal_unto_float, but the input types
6359 for these are different. */
6362 ereal_from_float (f
)
6366 unsigned EMUSHORT s
[2];
6367 unsigned EMUSHORT e
[NE
];
6369 /* Convert 32 bit integer to array of 16 bit pieces in target machine order.
6370 This is the inverse operation to what the function `endian' does. */
6371 if (REAL_WORDS_BIG_ENDIAN
)
6373 s
[0] = (unsigned EMUSHORT
) (f
>> 16);
6374 s
[1] = (unsigned EMUSHORT
) f
;
6378 s
[0] = (unsigned EMUSHORT
) f
;
6379 s
[1] = (unsigned EMUSHORT
) (f
>> 16);
6381 /* Convert and promote the target float to E-type. */
6383 /* Output E-type to REAL_VALUE_TYPE. */
6389 /* Convert a DFmode target `double' value to a REAL_VALUE_TYPE.
6390 This is somewhat like ereal_unto_double, but the input types
6391 for these are different.
6393 The DFmode is stored as an array of HOST_WIDE_INT in the target's
6394 data format, with no holes in the bit packing. The first element
6395 of the input array holds the bits that would come first in the
6396 target computer's memory. */
6399 ereal_from_double (d
)
6403 unsigned EMUSHORT s
[4];
6404 unsigned EMUSHORT e
[NE
];
6406 /* Convert array of HOST_WIDE_INT to equivalent array of 16-bit pieces. */
6407 if (REAL_WORDS_BIG_ENDIAN
)
6409 #if HOST_BITS_PER_WIDE_INT == 32
6410 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 16);
6411 s
[1] = (unsigned EMUSHORT
) d
[0];
6412 s
[2] = (unsigned EMUSHORT
) (d
[1] >> 16);
6413 s
[3] = (unsigned EMUSHORT
) d
[1];
6415 /* In this case the entire target double is contained in the
6416 first array element. The second element of the input is
6418 s
[0] = (unsigned EMUSHORT
) (d
[0] >> 48);
6419 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 32);
6420 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 16);
6421 s
[3] = (unsigned EMUSHORT
) d
[0];
6426 /* Target float words are little-endian. */
6427 s
[0] = (unsigned EMUSHORT
) d
[0];
6428 s
[1] = (unsigned EMUSHORT
) (d
[0] >> 16);
6429 #if HOST_BITS_PER_WIDE_INT == 32
6430 s
[2] = (unsigned EMUSHORT
) d
[1];
6431 s
[3] = (unsigned EMUSHORT
) (d
[1] >> 16);
6433 s
[2] = (unsigned EMUSHORT
) (d
[0] >> 32);
6434 s
[3] = (unsigned EMUSHORT
) (d
[0] >> 48);
6437 /* Convert target double to E-type. */
6439 /* Output E-type to REAL_VALUE_TYPE. */
6446 /* Convert target computer unsigned 64-bit integer to e-type.
6447 The endian-ness of DImode follows the convention for integers,
6448 so we use WORDS_BIG_ENDIAN here, not REAL_WORDS_BIG_ENDIAN. */
6452 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6453 unsigned EMUSHORT
*e
;
6455 unsigned EMUSHORT yi
[NI
];
6459 if (WORDS_BIG_ENDIAN
)
6461 for (k
= M
; k
< M
+ 4; k
++)
6466 for (k
= M
+ 3; k
>= M
; k
--)
6469 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6470 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6471 ecleaz (yi
); /* it was zero */
6473 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6477 /* Convert target computer signed 64-bit integer to e-type. */
6481 unsigned EMUSHORT
*di
; /* Address of the 64-bit int. */
6482 unsigned EMUSHORT
*e
;
6484 unsigned EMULONG acc
;
6485 unsigned EMUSHORT yi
[NI
];
6486 unsigned EMUSHORT carry
;
6490 if (WORDS_BIG_ENDIAN
)
6492 for (k
= M
; k
< M
+ 4; k
++)
6497 for (k
= M
+ 3; k
>= M
; k
--)
6500 /* Take absolute value */
6506 for (k
= M
+ 3; k
>= M
; k
--)
6508 acc
= (unsigned EMULONG
) (~yi
[k
] & 0xffff) + carry
;
6515 yi
[E
] = EXONE
+ 47; /* exponent if normalize shift count were 0 */
6516 if ((k
= enormlz (yi
)) > NBITS
)/* normalize the significand */
6517 ecleaz (yi
); /* it was zero */
6519 yi
[E
] -= (unsigned EMUSHORT
) k
;/* subtract shift count from exponent */
6526 /* Convert e-type to unsigned 64-bit int. */
6530 unsigned EMUSHORT
*x
;
6531 unsigned EMUSHORT
*i
;
6533 unsigned EMUSHORT xi
[NI
];
6542 k
= (int) xi
[E
] - (EXONE
- 1);
6545 for (j
= 0; j
< 4; j
++)
6551 for (j
= 0; j
< 4; j
++)
6554 warning ("overflow on truncation to integer");
6559 /* Shift more than 16 bits: first shift up k-16 mod 16,
6560 then shift up by 16's. */
6561 j
= k
- ((k
>> 4) << 4);
6565 if (WORDS_BIG_ENDIAN
)
6576 if (WORDS_BIG_ENDIAN
)
6581 while ((k
-= 16) > 0);
6585 /* shift not more than 16 bits */
6590 if (WORDS_BIG_ENDIAN
)
6609 /* Convert e-type to signed 64-bit int. */
6613 unsigned EMUSHORT
*x
;
6614 unsigned EMUSHORT
*i
;
6616 unsigned EMULONG acc
;
6617 unsigned EMUSHORT xi
[NI
];
6618 unsigned EMUSHORT carry
;
6619 unsigned EMUSHORT
*isave
;
6623 k
= (int) xi
[E
] - (EXONE
- 1);
6626 for (j
= 0; j
< 4; j
++)
6632 for (j
= 0; j
< 4; j
++)
6635 warning ("overflow on truncation to integer");
6641 /* Shift more than 16 bits: first shift up k-16 mod 16,
6642 then shift up by 16's. */
6643 j
= k
- ((k
>> 4) << 4);
6647 if (WORDS_BIG_ENDIAN
)
6658 if (WORDS_BIG_ENDIAN
)
6663 while ((k
-= 16) > 0);
6667 /* shift not more than 16 bits */
6670 if (WORDS_BIG_ENDIAN
)
6686 /* Negate if negative */
6690 if (WORDS_BIG_ENDIAN
)
6692 for (k
= 0; k
< 4; k
++)
6694 acc
= (unsigned EMULONG
) (~(*isave
) & 0xffff) + carry
;
6695 if (WORDS_BIG_ENDIAN
)
6707 /* Longhand square root routine. */
6710 static int esqinited
= 0;
6711 static unsigned short sqrndbit
[NI
];
6715 unsigned EMUSHORT
*x
, *y
;
6717 unsigned EMUSHORT temp
[NI
], num
[NI
], sq
[NI
], xx
[NI
];
6719 int i
, j
, k
, n
, nlups
;
6724 sqrndbit
[NI
- 2] = 1;
6727 /* Check for arg <= 0 */
6728 i
= ecmp (x
, ezero
);
6733 mtherr ("esqrt", DOMAIN
);
6749 /* Bring in the arg and renormalize if it is denormal. */
6751 m
= (EMULONG
) xx
[1]; /* local long word exponent */
6755 /* Divide exponent by 2 */
6757 exp
= (unsigned short) ((m
/ 2) + 0x3ffe);
6759 /* Adjust if exponent odd */
6769 n
= 8; /* get 8 bits of result per inner loop */
6775 /* bring in next word of arg */
6777 num
[NI
- 1] = xx
[j
+ 3];
6778 /* Do additional bit on last outer loop, for roundoff. */
6781 for (i
= 0; i
< n
; i
++)
6783 /* Next 2 bits of arg */
6786 /* Shift up answer */
6788 /* Make trial divisor */
6789 for (k
= 0; k
< NI
; k
++)
6792 eaddm (sqrndbit
, temp
);
6793 /* Subtract and insert answer bit if it goes in */
6794 if (ecmpm (temp
, num
) <= 0)
6804 /* Adjust for extra, roundoff loop done. */
6805 exp
+= (NBITS
- 1) - rndprc
;
6807 /* Sticky bit = 1 if the remainder is nonzero. */
6809 for (i
= 3; i
< NI
; i
++)
6812 /* Renormalize and round off. */
6813 emdnorm (sq
, k
, 0, exp
, 64);
6817 #endif /* EMU_NON_COMPILE not defined */
6819 /* Return the binary precision of the significand for a given
6820 floating point mode. The mode can hold an integer value
6821 that many bits wide, without losing any bits. */
6824 significand_size (mode
)
6825 enum machine_mode mode
;
6828 /* Don't test the modes, but their sizes, lest this
6829 code won't work for BITS_PER_UNIT != 8 . */
6831 switch (GET_MODE_BITSIZE (mode
))
6835 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT
6842 #if TARGET_FLOAT_FORMAT == IEEE_FLOAT_FORMAT
6845 #if TARGET_FLOAT_FORMAT == IBM_FLOAT_FORMAT
6848 #if TARGET_FLOAT_FORMAT == VAX_FLOAT_FORMAT
6851 #if TARGET_FLOAT_FORMAT == C4X_FLOAT_FORMAT