real.c (real_hash): New.
[gcc.git] / gcc / real.c
1 /* real.c - software floating point emulation.
2 Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2002 Free Software Foundation, Inc.
4 Contributed by Stephen L. Moshier (moshier@world.std.com).
5 Re-written by Richard Henderson <rth@redhat.com>
6
7 This file is part of GCC.
8
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
13
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 02111-1307, USA. */
23
24 #include "config.h"
25 #include "system.h"
26 #include "tree.h"
27 #include "toplev.h"
28 #include "real.h"
29 #include "tm_p.h"
30
31 /* The floating point model used internally is not exactly IEEE 754
32 compliant, and close to the description in the ISO C standard,
33 section 5.2.4.2.2 Characteristics of floating types.
34
35 Specifically
36
37 x = s * b^e * \sum_{k=1}^p f_k * b^{-k}
38
39 where
40 s = sign (+- 1)
41 b = base or radix, here always 2
42 e = exponent
43 p = precision (the number of base-b digits in the significand)
44 f_k = the digits of the significand.
45
46 We differ from typical IEEE 754 encodings in that the entire
47 significand is fractional. Normalized significands are in the
48 range [0.5, 1.0).
49
50 A requirement of the model is that P be larger than than the
51 largest supported target floating-point type by at least 2 bits.
52 This gives us proper rounding when we truncate to the target type.
53 In addition, E must be large enough to hold the smallest supported
54 denormal number in a normalized form.
55
56 Both of these requirements are easily satisfied. The largest
57 target significand is 113 bits; we store 128. The smallest
58 denormal number fits in 17 exponent bits; we store 29.
59
60 Target floating point models that use base 16 instead of base 2
61 (i.e. IBM 370), are handled during round_for_format, in which we
62 canonicalize the exponent to be a multiple of 4 (log2(16)), and
63 adjust the significand to match. */
64
65
66 /* Used to classify two numbers simultaneously. */
67 #define CLASS2(A, B) ((A) << 2 | (B))
68
69 #if HOST_BITS_PER_LONG != 64 && HOST_BITS_PER_LONG != 32
70 #error "Some constant folding done by hand to avoid shift count warnings"
71 #endif
72
73 /* Describes the properties of the specific target format in use. */
74 struct real_format
75 {
76 /* Move to and from the target bytes. */
77 void (*encode) (const struct real_format *, long *,
78 const REAL_VALUE_TYPE *);
79 void (*decode) (const struct real_format *, REAL_VALUE_TYPE *,
80 const long *);
81
82 /* The radix of the exponent and digits of the significand. */
83 int b;
84
85 /* log2(b). */
86 int log2_b;
87
88 /* Size of the significand in digits of radix B. */
89 int p;
90
91 /* The minimum negative integer, x, such that b**(x-1) is normalized. */
92 int emin;
93
94 /* The maximum integer, x, such that b**(x-1) is representable. */
95 int emax;
96
97 /* Properties of the format. */
98 bool has_nans;
99 bool has_inf;
100 bool has_denorm;
101 bool has_signed_zero;
102 bool qnan_msb_set;
103 };
104
105
106 static const struct real_format *fmt_for_mode[TFmode - QFmode + 1];
107
108
109 static void get_zero PARAMS ((REAL_VALUE_TYPE *, int));
110 static void get_canonical_qnan PARAMS ((REAL_VALUE_TYPE *, int));
111 static void get_canonical_snan PARAMS ((REAL_VALUE_TYPE *, int));
112 static void get_inf PARAMS ((REAL_VALUE_TYPE *, int));
113 static void sticky_rshift_significand PARAMS ((REAL_VALUE_TYPE *,
114 const REAL_VALUE_TYPE *,
115 unsigned int));
116 static void rshift_significand PARAMS ((REAL_VALUE_TYPE *,
117 const REAL_VALUE_TYPE *,
118 unsigned int));
119 static void lshift_significand PARAMS ((REAL_VALUE_TYPE *,
120 const REAL_VALUE_TYPE *,
121 unsigned int));
122 static void lshift_significand_1 PARAMS ((REAL_VALUE_TYPE *,
123 const REAL_VALUE_TYPE *));
124 static bool add_significands PARAMS ((REAL_VALUE_TYPE *r,
125 const REAL_VALUE_TYPE *,
126 const REAL_VALUE_TYPE *));
127 static bool sub_significands PARAMS ((REAL_VALUE_TYPE *,
128 const REAL_VALUE_TYPE *,
129 const REAL_VALUE_TYPE *));
130 static void neg_significand PARAMS ((REAL_VALUE_TYPE *,
131 const REAL_VALUE_TYPE *));
132 static int cmp_significands PARAMS ((const REAL_VALUE_TYPE *,
133 const REAL_VALUE_TYPE *));
134 static void set_significand_bit PARAMS ((REAL_VALUE_TYPE *, unsigned int));
135 static void clear_significand_bit PARAMS ((REAL_VALUE_TYPE *, unsigned int));
136 static bool test_significand_bit PARAMS ((REAL_VALUE_TYPE *, unsigned int));
137 static void clear_significand_below PARAMS ((REAL_VALUE_TYPE *,
138 unsigned int));
139 static bool div_significands PARAMS ((REAL_VALUE_TYPE *,
140 const REAL_VALUE_TYPE *,
141 const REAL_VALUE_TYPE *));
142 static void normalize PARAMS ((REAL_VALUE_TYPE *));
143
144 static void do_add PARAMS ((REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
145 const REAL_VALUE_TYPE *, int));
146 static void do_multiply PARAMS ((REAL_VALUE_TYPE *,
147 const REAL_VALUE_TYPE *,
148 const REAL_VALUE_TYPE *));
149 static void do_divide PARAMS ((REAL_VALUE_TYPE *, const REAL_VALUE_TYPE *,
150 const REAL_VALUE_TYPE *));
151 static int do_compare PARAMS ((const REAL_VALUE_TYPE *,
152 const REAL_VALUE_TYPE *, int));
153 static void do_fix_trunc PARAMS ((REAL_VALUE_TYPE *,
154 const REAL_VALUE_TYPE *));
155
156 static const REAL_VALUE_TYPE * ten_to_ptwo PARAMS ((int));
157 static const REAL_VALUE_TYPE * real_digit PARAMS ((int));
158
159 static void round_for_format PARAMS ((const struct real_format *,
160 REAL_VALUE_TYPE *));
161 \f
162 /* Initialize R with a positive zero. */
163
164 static inline void
165 get_zero (r, sign)
166 REAL_VALUE_TYPE *r;
167 int sign;
168 {
169 memset (r, 0, sizeof (*r));
170 r->sign = sign;
171 }
172
173 /* Initialize R with the canonical quiet NaN. */
174
175 static inline void
176 get_canonical_qnan (r, sign)
177 REAL_VALUE_TYPE *r;
178 int sign;
179 {
180 memset (r, 0, sizeof (*r));
181 r->class = rvc_nan;
182 r->sign = sign;
183 r->sig[SIGSZ-1] = SIG_MSB >> 1;
184 }
185
186 static inline void
187 get_canonical_snan (r, sign)
188 REAL_VALUE_TYPE *r;
189 int sign;
190 {
191 memset (r, 0, sizeof (*r));
192 r->class = rvc_nan;
193 r->sign = sign;
194 r->sig[SIGSZ-1] = SIG_MSB >> 2;
195 }
196
197 static inline void
198 get_inf (r, sign)
199 REAL_VALUE_TYPE *r;
200 int sign;
201 {
202 memset (r, 0, sizeof (*r));
203 r->class = rvc_inf;
204 r->sign = sign;
205 }
206
207 \f
208 /* Right-shift the significand of A by N bits; put the result in the
209 significand of R. If any one bits are shifted out, set the least
210 significant bit of R. */
211
212 static void
213 sticky_rshift_significand (r, a, n)
214 REAL_VALUE_TYPE *r;
215 const REAL_VALUE_TYPE *a;
216 unsigned int n;
217 {
218 unsigned long sticky = 0;
219 unsigned int i, ofs = 0;
220
221 if (n >= HOST_BITS_PER_LONG)
222 {
223 for (i = 0, ofs = n / HOST_BITS_PER_LONG; i < ofs; ++i)
224 sticky |= a->sig[i];
225 n -= ofs * HOST_BITS_PER_LONG;
226 }
227
228 if (n != 0)
229 {
230 sticky |= a->sig[ofs] & (((unsigned long)1 << n) - 1);
231 for (i = 0; i < SIGSZ; ++i)
232 {
233 r->sig[i]
234 = (((ofs + i >= SIGSZ ? 0 : a->sig[ofs + i]) >> n)
235 | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[ofs + i + 1])
236 << (HOST_BITS_PER_LONG - n)));
237 }
238 }
239 else
240 {
241 for (i = 0; ofs + i < SIGSZ; ++i)
242 r->sig[i] = a->sig[ofs + i];
243 for (; i < SIGSZ; ++i)
244 r->sig[i] = 0;
245 }
246
247 r->sig[0] |= (sticky != 0);
248 }
249
250 /* Right-shift the significand of A by N bits; put the result in the
251 significand of R. */
252
253 static void
254 rshift_significand (r, a, n)
255 REAL_VALUE_TYPE *r;
256 const REAL_VALUE_TYPE *a;
257 unsigned int n;
258 {
259 unsigned int i, ofs = n / HOST_BITS_PER_LONG;
260
261 n -= ofs * HOST_BITS_PER_LONG;
262 if (n != 0)
263 {
264 for (i = 0; i < SIGSZ; ++i)
265 {
266 r->sig[i]
267 = (((ofs + i >= SIGSZ ? 0 : a->sig[ofs + i]) >> n)
268 | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[ofs + i + 1])
269 << (HOST_BITS_PER_LONG - n)));
270 }
271 }
272 else
273 {
274 for (i = 0; ofs + i < SIGSZ; ++i)
275 r->sig[i] = a->sig[ofs + i];
276 for (; i < SIGSZ; ++i)
277 r->sig[i] = 0;
278 }
279 }
280
281 /* Left-shift the significand of A by N bits; put the result in the
282 significand of R. */
283
284 static void
285 lshift_significand (r, a, n)
286 REAL_VALUE_TYPE *r;
287 const REAL_VALUE_TYPE *a;
288 unsigned int n;
289 {
290 unsigned int i, ofs = n / HOST_BITS_PER_LONG;
291
292 n -= ofs * HOST_BITS_PER_LONG;
293 if (n == 0)
294 {
295 for (i = 0; ofs + i < SIGSZ; ++i)
296 r->sig[SIGSZ-1-i] = a->sig[SIGSZ-1-i-ofs];
297 for (; i < SIGSZ; ++i)
298 r->sig[SIGSZ-1-i] = 0;
299 }
300 else
301 for (i = 0; i < SIGSZ; ++i)
302 {
303 r->sig[SIGSZ-1-i]
304 = (((ofs + i >= SIGSZ ? 0 : a->sig[SIGSZ-1-i-ofs]) << n)
305 | ((ofs + i + 1 >= SIGSZ ? 0 : a->sig[SIGSZ-1-i-ofs-1])
306 >> (HOST_BITS_PER_LONG - n)));
307 }
308 }
309
310 /* Likewise, but N is specialized to 1. */
311
312 static inline void
313 lshift_significand_1 (r, a)
314 REAL_VALUE_TYPE *r;
315 const REAL_VALUE_TYPE *a;
316 {
317 unsigned int i;
318
319 for (i = SIGSZ - 1; i > 0; --i)
320 r->sig[i] = (a->sig[i] << 1) | (a->sig[i-1] >> (HOST_BITS_PER_LONG - 1));
321 r->sig[0] = a->sig[0] << 1;
322 }
323
324 /* Add the significands of A and B, placing the result in R. Return
325 true if there was carry out of the most significant word. */
326
327 static inline bool
328 add_significands (r, a, b)
329 REAL_VALUE_TYPE *r;
330 const REAL_VALUE_TYPE *a, *b;
331 {
332 bool carry = false;
333 int i;
334
335 for (i = 0; i < SIGSZ; ++i)
336 {
337 unsigned long ai = a->sig[i];
338 unsigned long ri = ai + b->sig[i];
339
340 if (carry)
341 {
342 carry = ri < ai;
343 carry |= ++ri == 0;
344 }
345 else
346 carry = ri < ai;
347
348 r->sig[i] = ri;
349 }
350
351 return carry;
352 }
353
354 /* Subtract the significands of A and B, placing the result in R.
355 Return true if there was carry out of the most significant word. */
356
357 static inline bool
358 sub_significands (r, a, b)
359 REAL_VALUE_TYPE *r;
360 const REAL_VALUE_TYPE *a, *b;
361 {
362 bool carry = false;
363 int i;
364
365 for (i = 0; i < SIGSZ; ++i)
366 {
367 unsigned long ai = a->sig[i];
368 unsigned long ri = ai - b->sig[i];
369
370 if (carry)
371 {
372 carry = ri > ai;
373 carry |= ~--ri == 0;
374 }
375 else
376 carry = ri > ai;
377
378 r->sig[i] = ri;
379 }
380
381 return carry;
382 }
383
384 /* Negate the significand A, placing the result in R. */
385
386 static inline void
387 neg_significand (r, a)
388 REAL_VALUE_TYPE *r;
389 const REAL_VALUE_TYPE *a;
390 {
391 bool carry = true;
392 int i;
393
394 for (i = 0; i < SIGSZ; ++i)
395 {
396 unsigned long ri, ai = a->sig[i];
397
398 if (carry)
399 {
400 if (ai)
401 {
402 ri = -ai;
403 carry = false;
404 }
405 else
406 ri = ai;
407 }
408 else
409 ri = ~ai;
410
411 r->sig[i] = ri;
412 }
413 }
414
415 /* Compare significands. Return tri-state vs zero. */
416
417 static inline int
418 cmp_significands (a, b)
419 const REAL_VALUE_TYPE *a, *b;
420 {
421 int i;
422
423 for (i = SIGSZ - 1; i >= 0; --i)
424 {
425 unsigned long ai = a->sig[i];
426 unsigned long bi = b->sig[i];
427
428 if (ai > bi)
429 return 1;
430 if (ai < bi)
431 return -1;
432 }
433
434 return 0;
435 }
436
437 /* Set bit N of the significand of R. */
438
439 static inline void
440 set_significand_bit (r, n)
441 REAL_VALUE_TYPE *r;
442 unsigned int n;
443 {
444 r->sig[n / HOST_BITS_PER_LONG]
445 |= (unsigned long)1 << (n % HOST_BITS_PER_LONG);
446 }
447
448 /* Clear bit N of the significand of R. */
449
450 static inline void
451 clear_significand_bit (r, n)
452 REAL_VALUE_TYPE *r;
453 unsigned int n;
454 {
455 r->sig[n / HOST_BITS_PER_LONG]
456 &= ~((unsigned long)1 << (n % HOST_BITS_PER_LONG));
457 }
458
459 /* Test bit N of the significand of R. */
460
461 static inline bool
462 test_significand_bit (r, n)
463 REAL_VALUE_TYPE *r;
464 unsigned int n;
465 {
466 /* ??? Compiler bug here if we return this expression directly.
467 The conversion to bool strips the "&1" and we wind up testing
468 e.g. 2 != 0 -> true. Seen in gcc version 3.2 20020520. */
469 int t = (r->sig[n / HOST_BITS_PER_LONG] >> (n % HOST_BITS_PER_LONG)) & 1;
470 return t;
471 }
472
473 /* Clear bits 0..N-1 of the significand of R. */
474
475 static void
476 clear_significand_below (r, n)
477 REAL_VALUE_TYPE *r;
478 unsigned int n;
479 {
480 int i, w = n / HOST_BITS_PER_LONG;
481
482 for (i = 0; i < w; ++i)
483 r->sig[i] = 0;
484
485 r->sig[w] &= ~(((unsigned long)1 << (n % HOST_BITS_PER_LONG)) - 1);
486 }
487
488 /* Divide the significands of A and B, placing the result in R. Return
489 true if the division was inexact. */
490
491 static inline bool
492 div_significands (r, a, b)
493 REAL_VALUE_TYPE *r;
494 const REAL_VALUE_TYPE *a, *b;
495 {
496 REAL_VALUE_TYPE u;
497 int bit = SIGNIFICAND_BITS - 1;
498 int i;
499 long inexact;
500
501 u = *a;
502 memset (r->sig, 0, sizeof (r->sig));
503
504 goto start;
505 do
506 {
507 if ((u.sig[SIGSZ-1] & SIG_MSB) == 0)
508 {
509 lshift_significand_1 (&u, &u);
510 start:
511 if (cmp_significands (&u, b) >= 0)
512 {
513 sub_significands (&u, &u, b);
514 set_significand_bit (r, bit);
515 }
516 }
517 else
518 {
519 /* We lose a bit here, and thus know the next quotient bit
520 will be one. */
521 lshift_significand_1 (&u, &u);
522 sub_significands (&u, &u, b);
523 set_significand_bit (r, bit);
524 }
525 }
526 while (--bit >= 0);
527
528 for (i = 0, inexact = 0; i < SIGSZ; i++)
529 inexact |= u.sig[i];
530
531 return inexact != 0;
532 }
533
534 /* Adjust the exponent and significand of R such that the most
535 significant bit is set. We underflow to zero and overflow to
536 infinity here, without denormals. (The intermediate representation
537 exponent is large enough to handle target denormals normalized.) */
538
539 static void
540 normalize (r)
541 REAL_VALUE_TYPE *r;
542 {
543 int shift = 0, exp;
544 int i, j;
545
546 /* Find the first word that is non-zero. */
547 for (i = SIGSZ - 1; i >= 0; i--)
548 if (r->sig[i] == 0)
549 shift += HOST_BITS_PER_LONG;
550 else
551 break;
552
553 /* Zero significand flushes to zero. */
554 if (i < 0)
555 {
556 r->class = rvc_zero;
557 r->exp = 0;
558 return;
559 }
560
561 /* Find the first bit that is non-zero. */
562 for (j = 0; ; j++)
563 if (r->sig[i] & ((unsigned long)1 << (HOST_BITS_PER_LONG - 1 - j)))
564 break;
565 shift += j;
566
567 if (shift > 0)
568 {
569 exp = r->exp - shift;
570 if (exp > MAX_EXP)
571 get_inf (r, r->sign);
572 else if (exp < -MAX_EXP)
573 get_zero (r, r->sign);
574 else
575 {
576 r->exp = exp;
577 lshift_significand (r, r, shift);
578 }
579 }
580 }
581 \f
582 /* Return R = A + (SUBTRACT_P ? -B : B). */
583
584 static void
585 do_add (r, a, b, subtract_p)
586 REAL_VALUE_TYPE *r;
587 const REAL_VALUE_TYPE *a, *b;
588 int subtract_p;
589 {
590 int dexp, sign, exp;
591 REAL_VALUE_TYPE t;
592
593 /* Determine if we need to add or subtract. */
594 sign = a->sign;
595 subtract_p = (sign ^ b->sign) ^ subtract_p;
596
597 switch (CLASS2 (a->class, b->class))
598 {
599 case CLASS2 (rvc_zero, rvc_zero):
600 /* +-0 +/- +-0 = +0. */
601 get_zero (r, 0);
602 return;
603
604 case CLASS2 (rvc_zero, rvc_normal):
605 case CLASS2 (rvc_zero, rvc_inf):
606 case CLASS2 (rvc_zero, rvc_nan):
607 /* 0 + ANY = ANY. */
608 case CLASS2 (rvc_normal, rvc_nan):
609 case CLASS2 (rvc_inf, rvc_nan):
610 case CLASS2 (rvc_nan, rvc_nan):
611 /* ANY + NaN = NaN. */
612 case CLASS2 (rvc_normal, rvc_inf):
613 /* R + Inf = Inf. */
614 *r = *b;
615 r->sign = sign ^ subtract_p;
616 return;
617
618 case CLASS2 (rvc_normal, rvc_zero):
619 case CLASS2 (rvc_inf, rvc_zero):
620 case CLASS2 (rvc_nan, rvc_zero):
621 /* ANY + 0 = ANY. */
622 case CLASS2 (rvc_nan, rvc_normal):
623 case CLASS2 (rvc_nan, rvc_inf):
624 /* NaN + ANY = NaN. */
625 case CLASS2 (rvc_inf, rvc_normal):
626 /* Inf + R = Inf. */
627 *r = *a;
628 return;
629
630 case CLASS2 (rvc_inf, rvc_inf):
631 if (subtract_p)
632 /* Inf - Inf = NaN. */
633 get_canonical_qnan (r, 0);
634 else
635 /* Inf + Inf = Inf. */
636 *r = *a;
637 return;
638
639 case CLASS2 (rvc_normal, rvc_normal):
640 break;
641
642 default:
643 abort ();
644 }
645
646 /* Swap the arguments such that A has the larger exponent. */
647 dexp = a->exp - b->exp;
648 if (dexp < 0)
649 {
650 const REAL_VALUE_TYPE *t;
651 t = a, a = b, b = t;
652 dexp = -dexp;
653 sign ^= subtract_p;
654 }
655 exp = a->exp;
656
657 /* If the exponents are not identical, we need to shift the
658 significand of B down. */
659 if (dexp > 0)
660 {
661 /* If the exponents are too far apart, the significands
662 do not overlap, which makes the subtraction a noop. */
663 if (dexp >= SIGNIFICAND_BITS)
664 {
665 *r = *a;
666 r->sign = sign;
667 return;
668 }
669
670 sticky_rshift_significand (&t, b, dexp);
671 b = &t;
672 }
673
674 if (subtract_p)
675 {
676 if (sub_significands (r, a, b))
677 {
678 /* We got a borrow out of the subtraction. That means that
679 A and B had the same exponent, and B had the larger
680 significand. We need to swap the sign and negate the
681 significand. */
682 sign ^= 1;
683 neg_significand (r, r);
684 }
685 }
686 else
687 {
688 if (add_significands (r, a, b))
689 {
690 /* We got carry out of the addition. This means we need to
691 shift the significand back down one bit and increase the
692 exponent. */
693 sticky_rshift_significand (r, r, 1);
694 r->sig[SIGSZ-1] |= SIG_MSB;
695 if (++exp > MAX_EXP)
696 {
697 get_inf (r, sign);
698 return;
699 }
700 }
701 }
702
703 r->class = rvc_normal;
704 r->sign = sign;
705 r->exp = exp;
706
707 /* Re-normalize the result. */
708 normalize (r);
709
710 /* Special case: if the subtraction results in zero, the result
711 is positive. */
712 if (r->class == rvc_zero)
713 r->sign = 0;
714 }
715
716 /* Return R = A * B. */
717
718 static void
719 do_multiply (r, a, b)
720 REAL_VALUE_TYPE *r;
721 const REAL_VALUE_TYPE *a, *b;
722 {
723 REAL_VALUE_TYPE u, t, *rr;
724 unsigned int i, j, k;
725 int sign = a->sign ^ b->sign;
726
727 switch (CLASS2 (a->class, b->class))
728 {
729 case CLASS2 (rvc_zero, rvc_zero):
730 case CLASS2 (rvc_zero, rvc_normal):
731 case CLASS2 (rvc_normal, rvc_zero):
732 /* +-0 * ANY = 0 with appropriate sign. */
733 get_zero (r, sign);
734 return;
735
736 case CLASS2 (rvc_zero, rvc_nan):
737 case CLASS2 (rvc_normal, rvc_nan):
738 case CLASS2 (rvc_inf, rvc_nan):
739 case CLASS2 (rvc_nan, rvc_nan):
740 /* ANY * NaN = NaN. */
741 *r = *b;
742 r->sign = sign;
743 return;
744
745 case CLASS2 (rvc_nan, rvc_zero):
746 case CLASS2 (rvc_nan, rvc_normal):
747 case CLASS2 (rvc_nan, rvc_inf):
748 /* NaN * ANY = NaN. */
749 *r = *a;
750 r->sign = sign;
751 return;
752
753 case CLASS2 (rvc_zero, rvc_inf):
754 case CLASS2 (rvc_inf, rvc_zero):
755 /* 0 * Inf = NaN */
756 get_canonical_qnan (r, sign);
757 return;
758
759 case CLASS2 (rvc_inf, rvc_inf):
760 case CLASS2 (rvc_normal, rvc_inf):
761 case CLASS2 (rvc_inf, rvc_normal):
762 /* Inf * Inf = Inf, R * Inf = Inf */
763 overflow:
764 get_inf (r, sign);
765 return;
766
767 case CLASS2 (rvc_normal, rvc_normal):
768 break;
769
770 default:
771 abort ();
772 }
773
774 if (r == a || r == b)
775 rr = &t;
776 else
777 rr = r;
778 get_zero (rr, 0);
779
780 u.class = rvc_normal;
781 u.sign = 0;
782
783 /* Collect all the partial products. Since we don't have sure access
784 to a widening multiply, we split each long into two half-words.
785
786 Consider the long-hand form of a four half-word multiplication:
787
788 A B C D
789 * E F G H
790 --------------
791 DE DF DG DH
792 CE CF CG CH
793 BE BF BG BH
794 AE AF AG AH
795
796 We construct partial products of the widened half-word products
797 that are known to not overlap, e.g. DF+DH. Each such partial
798 product is given its proper exponent, which allows us to sum them
799 and obtain the finished product. */
800
801 for (i = 0; i < SIGSZ * 2; ++i)
802 {
803 unsigned long ai = a->sig[i / 2];
804 if (i & 1)
805 ai >>= HOST_BITS_PER_LONG / 2;
806 else
807 ai &= ((unsigned long)1 << (HOST_BITS_PER_LONG / 2)) - 1;
808
809 if (ai == 0)
810 continue;
811
812 for (j = 0; j < 2; ++j)
813 {
814 int exp = (a->exp - (2*SIGSZ-1-i)*(HOST_BITS_PER_LONG/2)
815 + (b->exp - (1-j)*(HOST_BITS_PER_LONG/2)));
816
817 if (exp > MAX_EXP)
818 goto overflow;
819 if (exp < -MAX_EXP)
820 /* Would underflow to zero, which we shouldn't bother adding. */
821 continue;
822
823 u.exp = exp;
824
825 for (k = j; k < SIGSZ * 2; k += 2)
826 {
827 unsigned long bi = b->sig[k / 2];
828 if (k & 1)
829 bi >>= HOST_BITS_PER_LONG / 2;
830 else
831 bi &= ((unsigned long)1 << (HOST_BITS_PER_LONG / 2)) - 1;
832
833 u.sig[k / 2] = ai * bi;
834 }
835
836 do_add (rr, rr, &u, 0);
837 }
838 }
839
840 rr->sign = sign;
841 if (rr != r)
842 *r = t;
843 }
844
845 /* Return R = A / B. */
846
847 static void
848 do_divide (r, a, b)
849 REAL_VALUE_TYPE *r;
850 const REAL_VALUE_TYPE *a, *b;
851 {
852 int exp, sign = a->sign ^ b->sign;
853 REAL_VALUE_TYPE t, *rr;
854 bool inexact;
855
856 switch (CLASS2 (a->class, b->class))
857 {
858 case CLASS2 (rvc_zero, rvc_zero):
859 /* 0 / 0 = NaN. */
860 case CLASS2 (rvc_inf, rvc_zero):
861 /* Inf / 0 = NaN. */
862 case CLASS2 (rvc_inf, rvc_inf):
863 /* Inf / Inf = NaN. */
864 get_canonical_qnan (r, sign);
865 return;
866
867 case CLASS2 (rvc_zero, rvc_normal):
868 case CLASS2 (rvc_zero, rvc_inf):
869 /* 0 / ANY = 0. */
870 case CLASS2 (rvc_normal, rvc_inf):
871 /* R / Inf = 0. */
872 underflow:
873 get_zero (r, sign);
874 return;
875
876 case CLASS2 (rvc_normal, rvc_zero):
877 /* R / 0 = Inf. */
878 get_inf (r, sign);
879 return;
880
881 case CLASS2 (rvc_zero, rvc_nan):
882 case CLASS2 (rvc_normal, rvc_nan):
883 case CLASS2 (rvc_inf, rvc_nan):
884 case CLASS2 (rvc_nan, rvc_nan):
885 /* ANY / NaN = NaN. */
886 *r = *b;
887 r->sign = sign;
888 return;
889
890 case CLASS2 (rvc_nan, rvc_zero):
891 case CLASS2 (rvc_nan, rvc_normal):
892 case CLASS2 (rvc_nan, rvc_inf):
893 /* NaN / ANY = NaN. */
894 *r = *a;
895 r->sign = sign;
896 return;
897
898 case CLASS2 (rvc_inf, rvc_normal):
899 /* Inf / R = Inf. */
900 overflow:
901 get_inf (r, sign);
902 return;
903
904 case CLASS2 (rvc_normal, rvc_normal):
905 break;
906
907 default:
908 abort ();
909 }
910
911 if (r == a || r == b)
912 rr = &t;
913 else
914 rr = r;
915
916 rr->class = rvc_normal;
917 rr->sign = sign;
918
919 exp = a->exp - b->exp + 1;
920 if (exp > MAX_EXP)
921 goto overflow;
922 if (exp < -MAX_EXP)
923 goto underflow;
924 rr->exp = exp;
925
926 inexact = div_significands (rr, a, b);
927 rr->sig[0] |= inexact;
928
929 /* Re-normalize the result. */
930 normalize (rr);
931
932 if (rr != r)
933 *r = t;
934 }
935
936 /* Return a tri-state comparison of A vs B. Return NAN_RESULT if
937 one of the two operands is a NaN. */
938
939 static int
940 do_compare (a, b, nan_result)
941 const REAL_VALUE_TYPE *a, *b;
942 int nan_result;
943 {
944 int ret;
945
946 switch (CLASS2 (a->class, b->class))
947 {
948 case CLASS2 (rvc_zero, rvc_zero):
949 /* Sign of zero doesn't matter for compares. */
950 return 0;
951
952 case CLASS2 (rvc_inf, rvc_zero):
953 case CLASS2 (rvc_inf, rvc_normal):
954 case CLASS2 (rvc_normal, rvc_zero):
955 return (a->sign ? -1 : 1);
956
957 case CLASS2 (rvc_inf, rvc_inf):
958 return -a->sign - -b->sign;
959
960 case CLASS2 (rvc_zero, rvc_normal):
961 case CLASS2 (rvc_zero, rvc_inf):
962 case CLASS2 (rvc_normal, rvc_inf):
963 return (b->sign ? 1 : -1);
964
965 case CLASS2 (rvc_zero, rvc_nan):
966 case CLASS2 (rvc_normal, rvc_nan):
967 case CLASS2 (rvc_inf, rvc_nan):
968 case CLASS2 (rvc_nan, rvc_nan):
969 case CLASS2 (rvc_nan, rvc_zero):
970 case CLASS2 (rvc_nan, rvc_normal):
971 case CLASS2 (rvc_nan, rvc_inf):
972 return nan_result;
973
974 case CLASS2 (rvc_normal, rvc_normal):
975 break;
976
977 default:
978 abort ();
979 }
980
981 if (a->sign != b->sign)
982 return -a->sign - -b->sign;
983
984 if (a->exp > b->exp)
985 ret = 1;
986 else if (a->exp < b->exp)
987 ret = -1;
988 else
989 ret = cmp_significands (a, b);
990
991 return (a->sign ? -ret : ret);
992 }
993
994 /* Return A truncated to an integral value toward zero. */
995
996 static void
997 do_fix_trunc (r, a)
998 REAL_VALUE_TYPE *r;
999 const REAL_VALUE_TYPE *a;
1000 {
1001 *r = *a;
1002
1003 switch (a->class)
1004 {
1005 case rvc_zero:
1006 case rvc_inf:
1007 case rvc_nan:
1008 break;
1009
1010 case rvc_normal:
1011 if (r->exp <= 0)
1012 get_zero (r, r->sign);
1013 else if (r->exp < SIGNIFICAND_BITS)
1014 clear_significand_below (r, SIGNIFICAND_BITS - r->exp);
1015 break;
1016
1017 default:
1018 abort ();
1019 }
1020 }
1021
1022 /* Perform the binary or unary operation described by CODE.
1023 For a unary operation, leave OP1 NULL. */
1024
1025 void
1026 real_arithmetic (r, icode, op0, op1)
1027 REAL_VALUE_TYPE *r;
1028 int icode;
1029 const REAL_VALUE_TYPE *op0, *op1;
1030 {
1031 enum tree_code code = icode;
1032
1033 switch (code)
1034 {
1035 case PLUS_EXPR:
1036 do_add (r, op0, op1, 0);
1037 break;
1038
1039 case MINUS_EXPR:
1040 do_add (r, op0, op1, 1);
1041 break;
1042
1043 case MULT_EXPR:
1044 do_multiply (r, op0, op1);
1045 break;
1046
1047 case RDIV_EXPR:
1048 do_divide (r, op0, op1);
1049 break;
1050
1051 case MIN_EXPR:
1052 if (op1->class == rvc_nan)
1053 *r = *op1;
1054 else if (do_compare (op0, op1, -1) < 0)
1055 *r = *op0;
1056 else
1057 *r = *op1;
1058 break;
1059
1060 case MAX_EXPR:
1061 if (op1->class == rvc_nan)
1062 *r = *op1;
1063 else if (do_compare (op0, op1, 1) < 0)
1064 *r = *op1;
1065 else
1066 *r = *op0;
1067 break;
1068
1069 case NEGATE_EXPR:
1070 *r = *op0;
1071 r->sign ^= 1;
1072 break;
1073
1074 case ABS_EXPR:
1075 *r = *op0;
1076 r->sign = 0;
1077 break;
1078
1079 case FIX_TRUNC_EXPR:
1080 do_fix_trunc (r, op0);
1081 break;
1082
1083 default:
1084 abort ();
1085 }
1086 }
1087
1088 /* Legacy. Similar, but return the result directly. */
1089
1090 REAL_VALUE_TYPE
1091 real_arithmetic2 (icode, op0, op1)
1092 int icode;
1093 const REAL_VALUE_TYPE *op0, *op1;
1094 {
1095 REAL_VALUE_TYPE r;
1096 real_arithmetic (&r, icode, op0, op1);
1097 return r;
1098 }
1099
1100 bool
1101 real_compare (icode, op0, op1)
1102 int icode;
1103 const REAL_VALUE_TYPE *op0, *op1;
1104 {
1105 enum tree_code code = icode;
1106
1107 switch (code)
1108 {
1109 case LT_EXPR:
1110 return do_compare (op0, op1, 1) < 0;
1111 case LE_EXPR:
1112 return do_compare (op0, op1, 1) <= 0;
1113 case GT_EXPR:
1114 return do_compare (op0, op1, -1) > 0;
1115 case GE_EXPR:
1116 return do_compare (op0, op1, -1) >= 0;
1117 case EQ_EXPR:
1118 return do_compare (op0, op1, -1) == 0;
1119 case NE_EXPR:
1120 return do_compare (op0, op1, -1) != 0;
1121 case UNORDERED_EXPR:
1122 return op0->class == rvc_nan || op1->class == rvc_nan;
1123 case ORDERED_EXPR:
1124 return op0->class != rvc_nan && op1->class != rvc_nan;
1125 case UNLT_EXPR:
1126 return do_compare (op0, op1, -1) < 0;
1127 case UNLE_EXPR:
1128 return do_compare (op0, op1, -1) <= 0;
1129 case UNGT_EXPR:
1130 return do_compare (op0, op1, 1) > 0;
1131 case UNGE_EXPR:
1132 return do_compare (op0, op1, 1) >= 0;
1133 case UNEQ_EXPR:
1134 return do_compare (op0, op1, 0) == 0;
1135
1136 default:
1137 abort ();
1138 }
1139 }
1140
1141 /* Return floor log2(R). */
1142
1143 int
1144 real_exponent (r)
1145 const REAL_VALUE_TYPE *r;
1146 {
1147 switch (r->class)
1148 {
1149 case rvc_zero:
1150 return 0;
1151 case rvc_inf:
1152 case rvc_nan:
1153 return (unsigned int)-1 >> 1;
1154 case rvc_normal:
1155 return r->exp;
1156 default:
1157 abort ();
1158 }
1159 }
1160
1161 /* R = OP0 * 2**EXP. */
1162
1163 void
1164 real_ldexp (r, op0, exp)
1165 REAL_VALUE_TYPE *r;
1166 const REAL_VALUE_TYPE *op0;
1167 int exp;
1168 {
1169 *r = *op0;
1170 switch (r->class)
1171 {
1172 case rvc_zero:
1173 case rvc_inf:
1174 case rvc_nan:
1175 break;
1176
1177 case rvc_normal:
1178 exp += op0->exp;
1179 if (exp > MAX_EXP)
1180 get_inf (r, r->sign);
1181 else if (exp < -MAX_EXP)
1182 get_zero (r, r->sign);
1183 else
1184 r->exp = exp;
1185 break;
1186
1187 default:
1188 abort ();
1189 }
1190 }
1191
1192 /* Determine whether a floating-point value X is infinite. */
1193
1194 bool
1195 real_isinf (r)
1196 const REAL_VALUE_TYPE *r;
1197 {
1198 return (r->class == rvc_inf);
1199 }
1200
1201 /* Determine whether a floating-point value X is a NaN. */
1202
1203 bool
1204 real_isnan (r)
1205 const REAL_VALUE_TYPE *r;
1206 {
1207 return (r->class == rvc_nan);
1208 }
1209
1210 /* Determine whether a floating-point value X is negative. */
1211
1212 bool
1213 real_isneg (r)
1214 const REAL_VALUE_TYPE *r;
1215 {
1216 return r->sign;
1217 }
1218
1219 /* Determine whether a floating-point value X is minus zero. */
1220
1221 bool
1222 real_isnegzero (r)
1223 const REAL_VALUE_TYPE *r;
1224 {
1225 return r->sign && r->class == rvc_zero;
1226 }
1227
1228 /* Compare two floating-point objects for bitwise identity. */
1229
1230 extern bool
1231 real_identical (a, b)
1232 const REAL_VALUE_TYPE *a, *b;
1233 {
1234 int i;
1235
1236 if (a->class != b->class)
1237 return false;
1238 if (a->sign != b->sign)
1239 return false;
1240
1241 switch (a->class)
1242 {
1243 case rvc_zero:
1244 case rvc_inf:
1245 break;
1246
1247 case rvc_normal:
1248 if (a->exp != b->exp)
1249 return false;
1250 /* FALLTHRU */
1251 case rvc_nan:
1252 for (i = 0; i < SIGSZ; ++i)
1253 if (a->sig[i] != b->sig[i])
1254 return false;
1255 break;
1256
1257 default:
1258 abort ();
1259 }
1260
1261 return true;
1262 }
1263
1264 /* Try to change R into its exact multiplicative inverse in machine
1265 mode MODE. Return true if successful. */
1266
1267 bool
1268 exact_real_inverse (mode, r)
1269 enum machine_mode mode;
1270 REAL_VALUE_TYPE *r;
1271 {
1272 const REAL_VALUE_TYPE *one = real_digit (1);
1273 REAL_VALUE_TYPE u;
1274 int i;
1275
1276 if (r->class != rvc_normal)
1277 return false;
1278
1279 /* Check for a power of two: all significand bits zero except the MSB. */
1280 for (i = 0; i < SIGSZ-1; ++i)
1281 if (r->sig[i] != 0)
1282 return false;
1283 if (r->sig[SIGSZ-1] != SIG_MSB)
1284 return false;
1285
1286 /* Find the inverse and truncate to the required mode. */
1287 do_divide (&u, one, r);
1288 real_convert (&u, mode, &u);
1289
1290 /* The rounding may have overflowed. */
1291 if (u.class != rvc_normal)
1292 return false;
1293 for (i = 0; i < SIGSZ-1; ++i)
1294 if (u.sig[i] != 0)
1295 return false;
1296 if (u.sig[SIGSZ-1] != SIG_MSB)
1297 return false;
1298
1299 *r = u;
1300 return true;
1301 }
1302 \f
1303 /* Render R as an integer. */
1304
1305 HOST_WIDE_INT
1306 real_to_integer (r)
1307 const REAL_VALUE_TYPE *r;
1308 {
1309 unsigned HOST_WIDE_INT i;
1310
1311 switch (r->class)
1312 {
1313 case rvc_zero:
1314 underflow:
1315 return 0;
1316
1317 case rvc_inf:
1318 case rvc_nan:
1319 overflow:
1320 i = (unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1);
1321 if (!r->sign)
1322 i--;
1323 return i;
1324
1325 case rvc_normal:
1326 if (r->exp <= 0)
1327 goto underflow;
1328 if (r->exp > HOST_BITS_PER_WIDE_INT)
1329 goto overflow;
1330
1331 if (HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG)
1332 i = r->sig[SIGSZ-1];
1333 else if (HOST_BITS_PER_WIDE_INT == 2*HOST_BITS_PER_LONG)
1334 {
1335 i = r->sig[SIGSZ-1];
1336 i = i << (HOST_BITS_PER_LONG - 1) << 1;
1337 i |= r->sig[SIGSZ-2];
1338 }
1339 else
1340 abort ();
1341
1342 i >>= HOST_BITS_PER_WIDE_INT - r->exp;
1343
1344 if (r->sign)
1345 i = -i;
1346 return i;
1347
1348 default:
1349 abort ();
1350 }
1351 }
1352
1353 /* Likewise, but to an integer pair, HI+LOW. */
1354
1355 void
1356 real_to_integer2 (plow, phigh, r)
1357 HOST_WIDE_INT *plow, *phigh;
1358 const REAL_VALUE_TYPE *r;
1359 {
1360 REAL_VALUE_TYPE t;
1361 HOST_WIDE_INT low, high;
1362 int exp;
1363
1364 switch (r->class)
1365 {
1366 case rvc_zero:
1367 underflow:
1368 low = high = 0;
1369 break;
1370
1371 case rvc_inf:
1372 case rvc_nan:
1373 overflow:
1374 high = (unsigned HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT - 1);
1375 if (r->sign)
1376 low = 0;
1377 else
1378 {
1379 high--;
1380 low = -1;
1381 }
1382 break;
1383
1384 case rvc_normal:
1385 exp = r->exp;
1386 if (exp <= 0)
1387 goto underflow;
1388 if (exp >= 2*HOST_BITS_PER_WIDE_INT)
1389 goto overflow;
1390
1391 rshift_significand (&t, r, 2*HOST_BITS_PER_WIDE_INT - exp);
1392 if (HOST_BITS_PER_WIDE_INT == HOST_BITS_PER_LONG)
1393 {
1394 high = t.sig[SIGSZ-1];
1395 low = t.sig[SIGSZ-2];
1396 }
1397 else if (HOST_BITS_PER_WIDE_INT == 2*HOST_BITS_PER_LONG)
1398 {
1399 high = t.sig[SIGSZ-1];
1400 high = high << (HOST_BITS_PER_LONG - 1) << 1;
1401 high |= t.sig[SIGSZ-2];
1402
1403 low = t.sig[SIGSZ-3];
1404 low = low << (HOST_BITS_PER_LONG - 1) << 1;
1405 low |= t.sig[SIGSZ-4];
1406 }
1407 else
1408 abort ();
1409
1410 if (r->sign)
1411 {
1412 if (low == 0)
1413 high = -high;
1414 else
1415 low = -low, high = ~high;
1416 }
1417 break;
1418
1419 default:
1420 abort ();
1421 }
1422
1423 *plow = low;
1424 *phigh = high;
1425 }
1426
1427 /* Render R as a decimal floating point constant. Emit DIGITS
1428 significant digits in the result. If DIGITS <= 0, choose the
1429 maximum for the representation. */
1430
1431 #define M_LOG10_2 0.30102999566398119521
1432
1433 void
1434 real_to_decimal (str, r_orig, digits)
1435 char *str;
1436 const REAL_VALUE_TYPE *r_orig;
1437 int digits;
1438 {
1439 REAL_VALUE_TYPE r;
1440 const REAL_VALUE_TYPE *one, *ten;
1441 int dec_exp, max_digits, d, cmp_half;
1442 char *p, *first, *last;
1443 bool sign;
1444
1445 r = *r_orig;
1446 switch (r.class)
1447 {
1448 case rvc_zero:
1449 strcpy (str, (r.sign ? "-0.0" : "0.0"));
1450 return;
1451 case rvc_normal:
1452 break;
1453 case rvc_inf:
1454 strcpy (str, (r.sign ? "+Inf" : "-Inf"));
1455 return;
1456 case rvc_nan:
1457 /* ??? Print the significand as well, if not canonical? */
1458 strcpy (str, (r.sign ? "+NaN" : "-NaN"));
1459 return;
1460 default:
1461 abort ();
1462 }
1463
1464 max_digits = SIGNIFICAND_BITS * M_LOG10_2;
1465 if (digits <= 0 || digits > max_digits)
1466 digits = max_digits;
1467
1468 one = real_digit (1);
1469 ten = ten_to_ptwo (0);
1470
1471 sign = r.sign;
1472 r.sign = 0;
1473
1474 /* Estimate the decimal exponent. */
1475 dec_exp = r.exp * M_LOG10_2;
1476
1477 /* Scale the number such that it is in [1, 10). */
1478 if (dec_exp > 0)
1479 {
1480 int i;
1481 for (i = EXP_BITS - 1; i >= 0; --i)
1482 if (dec_exp & (1 << i))
1483 do_divide (&r, &r, ten_to_ptwo (i));
1484 }
1485 else if (dec_exp < 0)
1486 {
1487 int i, pos_exp = -(--dec_exp);
1488
1489 for (i = EXP_BITS - 1; i >= 0; --i)
1490 if (pos_exp & (1 << i))
1491 do_multiply (&r, &r, ten_to_ptwo (i));
1492 }
1493
1494 /* Assert that the number is in the proper range. Round-off can
1495 prevent the above from working exactly. */
1496 if (do_compare (&r, one, -1) < 0)
1497 {
1498 do_multiply (&r, &r, ten);
1499 dec_exp--;
1500 }
1501 else if (do_compare (&r, ten, 1) >= 0)
1502 {
1503 do_divide (&r, &r, ten);
1504 dec_exp++;
1505 }
1506
1507 p = str;
1508 if (sign)
1509 *p++ = '-';
1510 first = p++;
1511 while (1)
1512 {
1513 d = real_to_integer ((const REAL_VALUE_TYPE *) &r);
1514 do_add (&r, &r, real_digit (d), 1);
1515
1516 *p++ = d + '0';
1517 if (--digits == 0)
1518 break;
1519 do_multiply (&r, &r, ten);
1520 }
1521 last = p;
1522
1523 /* Round the result. Compare R vs 0.5 by doing R*2 vs 1.0. */
1524 r.exp += 1;
1525 cmp_half = do_compare (&r, one, -1);
1526 if (cmp_half == 0)
1527 /* Round to even. */
1528 cmp_half += d & 1;
1529 if (cmp_half > 0)
1530 {
1531 while (p > first)
1532 {
1533 d = *--p;
1534 if (d == '9')
1535 *p = '0';
1536 else
1537 {
1538 *p = d + 1;
1539 break;
1540 }
1541 }
1542
1543 if (p == first)
1544 {
1545 first[1] = '1';
1546 dec_exp++;
1547 }
1548 }
1549
1550 first[0] = first[1];
1551 first[1] = '.';
1552
1553 sprintf (last, "e%+d", dec_exp);
1554 }
1555
1556 /* Render R as a hexadecimal floating point constant. Emit DIGITS
1557 significant digits in the result. If DIGITS <= 0, choose the maximum
1558 for the representation. */
1559
1560 void
1561 real_to_hexadecimal (str, r, digits)
1562 char *str;
1563 const REAL_VALUE_TYPE *r;
1564 int digits;
1565 {
1566 int i, j, exp = r->exp;
1567 char *p;
1568
1569 switch (r->class)
1570 {
1571 case rvc_zero:
1572 exp = 0;
1573 break;
1574 case rvc_normal:
1575 break;
1576 case rvc_inf:
1577 strcpy (str, (r->sign ? "+Inf" : "-Inf"));
1578 return;
1579 case rvc_nan:
1580 /* ??? Print the significand as well, if not canonical? */
1581 strcpy (str, (r->sign ? "+NaN" : "-NaN"));
1582 return;
1583 default:
1584 abort ();
1585 }
1586
1587 if (digits <= 0)
1588 digits = SIGNIFICAND_BITS / 4;
1589
1590 p = str;
1591 if (r->sign)
1592 *p++ = '-';
1593 *p++ = '0';
1594 *p++ = 'x';
1595 *p++ = '0';
1596 *p++ = '.';
1597
1598 for (i = SIGSZ - 1; i >= 0; --i)
1599 for (j = HOST_BITS_PER_LONG - 4; j >= 0; j -= 4)
1600 {
1601 *p++ = "0123456789abcdef"[(r->sig[i] >> j) & 15];
1602 if (--digits == 0)
1603 goto out;
1604 }
1605 out:
1606 sprintf (p, "p%+d", exp);
1607 }
1608
1609 /* Initialize R from a decimal or hexadecimal string. The string is
1610 assumed to have been syntax checked already. */
1611
1612 void
1613 real_from_string (r, str)
1614 REAL_VALUE_TYPE *r;
1615 const char *str;
1616 {
1617 int exp = 0;
1618
1619 get_zero (r, 0);
1620
1621 if (*str == '-')
1622 {
1623 r->sign = 1;
1624 str++;
1625 }
1626 else if (*str == '+')
1627 str++;
1628
1629 if (str[0] == '0' && str[1] == 'x')
1630 {
1631 /* Hexadecimal floating point. */
1632 int pos = SIGNIFICAND_BITS - 4, d;
1633
1634 str += 2;
1635
1636 while (*str == '0')
1637 str++;
1638 while (1)
1639 {
1640 d = hex_value (*str);
1641 if (d == _hex_bad)
1642 break;
1643 if (pos >= 0)
1644 {
1645 r->sig[pos / HOST_BITS_PER_LONG]
1646 |= (unsigned long) d << (pos % HOST_BITS_PER_LONG);
1647 pos -= 4;
1648 }
1649 exp += 4;
1650 str++;
1651 }
1652 if (*str == '.')
1653 {
1654 str++;
1655 while (1)
1656 {
1657 d = hex_value (*str);
1658 if (d == _hex_bad)
1659 break;
1660 if (pos >= 0)
1661 {
1662 r->sig[pos / HOST_BITS_PER_LONG]
1663 |= (unsigned long) d << (pos % HOST_BITS_PER_LONG);
1664 pos -= 4;
1665 }
1666 str++;
1667 }
1668 }
1669 if (*str == 'p' || *str == 'P')
1670 {
1671 int exp_neg = 0;
1672
1673 str++;
1674 if (*str == '-')
1675 {
1676 exp_neg = 1;
1677 str++;
1678 }
1679 else if (*str == '+')
1680 str++;
1681
1682 d = 0;
1683 while (ISDIGIT (*str))
1684 {
1685 int t = d;
1686 d *= 10;
1687 d += *str - '0';
1688 if (d < t)
1689 {
1690 /* Overflowed the exponent. */
1691 if (exp_neg)
1692 goto underflow;
1693 else
1694 goto overflow;
1695 }
1696 str++;
1697 }
1698 if (exp_neg)
1699 d = -d;
1700
1701 exp += d;
1702 }
1703
1704 r->class = rvc_normal;
1705 r->exp = exp;
1706 if (r->exp != exp)
1707 {
1708 if (exp < 0)
1709 goto underflow;
1710 else
1711 goto overflow;
1712 }
1713
1714 normalize (r);
1715 }
1716 else
1717 {
1718 /* Decimal floating point. */
1719 const REAL_VALUE_TYPE *ten = ten_to_ptwo (0);
1720 int d;
1721
1722 while (*str == '0')
1723 str++;
1724 while (ISDIGIT (*str))
1725 {
1726 d = *str++ - '0';
1727 do_multiply (r, r, ten);
1728 if (d)
1729 do_add (r, r, real_digit (d), 0);
1730 }
1731 if (*str == '.')
1732 {
1733 str++;
1734 while (ISDIGIT (*str))
1735 {
1736 d = *str++ - '0';
1737 do_multiply (r, r, ten);
1738 if (d)
1739 do_add (r, r, real_digit (d), 0);
1740 exp--;
1741 }
1742 }
1743
1744 if (*str == 'e' || *str == 'E')
1745 {
1746 int exp_neg = 0;
1747
1748 str++;
1749 if (*str == '-')
1750 {
1751 exp_neg = 1;
1752 str++;
1753 }
1754 else if (*str == '+')
1755 str++;
1756
1757 d = 0;
1758 while (ISDIGIT (*str))
1759 {
1760 int t = d;
1761 d *= 10;
1762 d += *str - '0';
1763 if (d < t)
1764 {
1765 /* Overflowed the exponent. */
1766 if (exp_neg)
1767 goto underflow;
1768 else
1769 goto overflow;
1770 }
1771 str++;
1772 }
1773 if (exp_neg)
1774 d = -d;
1775 exp += d;
1776 }
1777
1778 if (exp < 0)
1779 {
1780 exp = -exp;
1781 for (d = 0; d < EXP_BITS; ++d)
1782 if (exp & (1 << d))
1783 do_divide (r, r, ten_to_ptwo (d));
1784 }
1785 else if (exp > 0)
1786 {
1787 for (d = 0; d < EXP_BITS; ++d)
1788 if (exp & (1 << d))
1789 do_multiply (r, r, ten_to_ptwo (d));
1790 }
1791 }
1792
1793 return;
1794
1795 underflow:
1796 get_zero (r, r->sign);
1797 return;
1798
1799 overflow:
1800 get_inf (r, r->sign);
1801 return;
1802 }
1803
1804 /* Legacy. Similar, but return the result directly. */
1805
1806 REAL_VALUE_TYPE
1807 real_from_string2 (s, mode)
1808 const char *s;
1809 enum machine_mode mode;
1810 {
1811 REAL_VALUE_TYPE r;
1812
1813 real_from_string (&r, s);
1814 if (mode != VOIDmode)
1815 real_convert (&r, mode, &r);
1816
1817 return r;
1818 }
1819
1820 /* Initialize R from the integer pair HIGH+LOW. */
1821
1822 void
1823 real_from_integer (r, mode, low, high, unsigned_p)
1824 REAL_VALUE_TYPE *r;
1825 enum machine_mode mode;
1826 unsigned HOST_WIDE_INT low;
1827 HOST_WIDE_INT high;
1828 int unsigned_p;
1829 {
1830 if (low == 0 && high == 0)
1831 get_zero (r, 0);
1832 else
1833 {
1834 r->class = rvc_normal;
1835 r->sign = high < 0 && !unsigned_p;
1836 r->exp = 2 * HOST_BITS_PER_WIDE_INT;
1837
1838 if (r->sign)
1839 {
1840 high = ~high;
1841 if (low == 0)
1842 high += 1;
1843 else
1844 low = -low;
1845 }
1846
1847 if (HOST_BITS_PER_LONG == HOST_BITS_PER_WIDE_INT)
1848 {
1849 r->sig[SIGSZ-1] = high;
1850 r->sig[SIGSZ-2] = low;
1851 memset (r->sig, 0, sizeof(long)*(SIGSZ-2));
1852 }
1853 else if (HOST_BITS_PER_LONG*2 == HOST_BITS_PER_WIDE_INT)
1854 {
1855 r->sig[SIGSZ-1] = high >> (HOST_BITS_PER_LONG - 1) >> 1;
1856 r->sig[SIGSZ-2] = high;
1857 r->sig[SIGSZ-3] = low >> (HOST_BITS_PER_LONG - 1) >> 1;
1858 r->sig[SIGSZ-4] = low;
1859 if (SIGSZ > 4)
1860 memset (r->sig, 0, sizeof(long)*(SIGSZ-4));
1861 }
1862 else
1863 abort ();
1864
1865 normalize (r);
1866 }
1867
1868 if (mode != VOIDmode)
1869 real_convert (r, mode, r);
1870 }
1871
1872 /* Returns 10**2**n. */
1873
1874 static const REAL_VALUE_TYPE *
1875 ten_to_ptwo (n)
1876 int n;
1877 {
1878 static REAL_VALUE_TYPE tens[EXP_BITS];
1879
1880 if (n < 0 || n >= EXP_BITS)
1881 abort ();
1882
1883 if (tens[n].class == rvc_zero)
1884 {
1885 if (n < (HOST_BITS_PER_WIDE_INT == 64 ? 5 : 4))
1886 {
1887 HOST_WIDE_INT t = 10;
1888 int i;
1889
1890 for (i = 0; i < n; ++i)
1891 t *= t;
1892
1893 real_from_integer (&tens[n], VOIDmode, t, 0, 1);
1894 }
1895 else
1896 {
1897 const REAL_VALUE_TYPE *t = ten_to_ptwo (n - 1);
1898 do_multiply (&tens[n], t, t);
1899 }
1900 }
1901
1902 return &tens[n];
1903 }
1904
1905 /* Returns N. */
1906
1907 static const REAL_VALUE_TYPE *
1908 real_digit (n)
1909 int n;
1910 {
1911 static REAL_VALUE_TYPE num[10];
1912
1913 if (n < 0 || n > 9)
1914 abort ();
1915
1916 if (n > 0 && num[n].class == rvc_zero)
1917 real_from_integer (&num[n], VOIDmode, n, 0, 1);
1918
1919 return &num[n];
1920 }
1921
1922 /* Fills R with +Inf. */
1923
1924 void
1925 real_inf (r)
1926 REAL_VALUE_TYPE *r;
1927 {
1928 get_inf (r, 0);
1929 }
1930
1931 /* Fills R with a NaN whose significand is described by STR. If QUIET,
1932 we force a QNaN, else we force an SNaN. The string, if not empty,
1933 is parsed as a number and placed in the significand. Return true
1934 if the string was successfully parsed. */
1935
1936 bool
1937 real_nan (r, str, quiet, mode)
1938 REAL_VALUE_TYPE *r;
1939 const char *str;
1940 int quiet;
1941 enum machine_mode mode;
1942 {
1943 const struct real_format *fmt;
1944
1945 fmt = fmt_for_mode[mode - QFmode];
1946 if (fmt == NULL)
1947 abort ();
1948
1949 if (*str == 0)
1950 {
1951 if (quiet)
1952 get_canonical_qnan (r, 0);
1953 else
1954 get_canonical_snan (r, 0);
1955 }
1956 else
1957 {
1958 int base = 10, d;
1959 bool neg = false;
1960
1961 memset (r, 0, sizeof (*r));
1962 r->class = rvc_nan;
1963
1964 /* Parse akin to strtol into the significand of R. */
1965
1966 while (ISSPACE (*str))
1967 str++;
1968 if (*str == '-')
1969 str++, neg = true;
1970 else if (*str == '+')
1971 str++;
1972 if (*str == '0')
1973 {
1974 if (*++str == 'x')
1975 str++, base = 16;
1976 else
1977 base = 8;
1978 }
1979
1980 while ((d = hex_value (*str)) < base)
1981 {
1982 REAL_VALUE_TYPE u;
1983
1984 switch (base)
1985 {
1986 case 8:
1987 lshift_significand (r, r, 3);
1988 break;
1989 case 16:
1990 lshift_significand (r, r, 4);
1991 break;
1992 case 10:
1993 lshift_significand_1 (&u, r);
1994 lshift_significand (r, r, 3);
1995 add_significands (r, r, &u);
1996 break;
1997 default:
1998 abort ();
1999 }
2000
2001 get_zero (&u, 0);
2002 u.sig[0] = d;
2003 add_significands (r, r, &u);
2004
2005 str++;
2006 }
2007
2008 /* Must have consumed the entire string for success. */
2009 if (*str != 0)
2010 return false;
2011
2012 /* Shift the significand into place such that the bits
2013 are in the most significant bits for the format. */
2014 lshift_significand (r, r, SIGNIFICAND_BITS - fmt->p);
2015
2016 /* Our MSB is always unset for NaNs. */
2017 r->sig[SIGSZ-1] &= ~SIG_MSB;
2018
2019 /* Force quiet or signalling NaN. */
2020 if (quiet)
2021 r->sig[SIGSZ-1] |= SIG_MSB >> 1;
2022 else
2023 r->sig[SIGSZ-1] &= ~(SIG_MSB >> 1);
2024
2025 /* Force at least one bit of the significand set. */
2026 for (d = 0; d < SIGSZ; ++d)
2027 if (r->sig[d])
2028 break;
2029 if (d == SIGSZ)
2030 r->sig[SIGSZ-1] |= SIG_MSB >> 2;
2031
2032 /* Our intermediate format forces QNaNs to have MSB-1 set.
2033 If the target format has QNaNs with the top bit unset,
2034 mirror the output routines and invert the top two bits. */
2035 if (!fmt->qnan_msb_set)
2036 r->sig[SIGSZ-1] ^= (SIG_MSB >> 1) | (SIG_MSB >> 2);
2037 }
2038
2039 return true;
2040 }
2041
2042 /* Fills R with 2**N. */
2043
2044 void
2045 real_2expN (r, n)
2046 REAL_VALUE_TYPE *r;
2047 int n;
2048 {
2049 memset (r, 0, sizeof (*r));
2050
2051 n++;
2052 if (n > MAX_EXP)
2053 r->class = rvc_inf;
2054 else if (n < -MAX_EXP)
2055 ;
2056 else
2057 {
2058 r->class = rvc_normal;
2059 r->exp = n;
2060 r->sig[SIGSZ-1] = SIG_MSB;
2061 }
2062 }
2063
2064 \f
2065 static void
2066 round_for_format (fmt, r)
2067 const struct real_format *fmt;
2068 REAL_VALUE_TYPE *r;
2069 {
2070 int p2, np2, i, w;
2071 unsigned long sticky;
2072 bool guard, lsb;
2073 int emin2m1, emax2;
2074
2075 p2 = fmt->p * fmt->log2_b;
2076 emin2m1 = (fmt->emin - 1) * fmt->log2_b;
2077 emax2 = fmt->emax * fmt->log2_b;
2078
2079 np2 = SIGNIFICAND_BITS - p2;
2080 switch (r->class)
2081 {
2082 underflow:
2083 get_zero (r, r->sign);
2084 case rvc_zero:
2085 if (!fmt->has_signed_zero)
2086 r->sign = 0;
2087 return;
2088
2089 overflow:
2090 get_inf (r, r->sign);
2091 case rvc_inf:
2092 return;
2093
2094 case rvc_nan:
2095 clear_significand_below (r, np2);
2096
2097 /* If we've cleared the entire significand, we need one bit
2098 set for this to continue to be a NaN. */
2099 for (i = 0; i < SIGSZ; ++i)
2100 if (r->sig[i])
2101 break;
2102 if (i == SIGSZ)
2103 r->sig[SIGSZ-1] = SIG_MSB >> 2;
2104 return;
2105
2106 case rvc_normal:
2107 break;
2108
2109 default:
2110 abort ();
2111 }
2112
2113 /* If we're not base2, normalize the exponent to a multiple of
2114 the true base. */
2115 if (fmt->log2_b != 1)
2116 {
2117 int shift = r->exp & (fmt->log2_b - 1);
2118 if (shift)
2119 {
2120 shift = fmt->log2_b - shift;
2121 sticky_rshift_significand (r, r, shift);
2122 r->exp += shift;
2123 }
2124 }
2125
2126 /* Check the range of the exponent. If we're out of range,
2127 either underflow or overflow. */
2128 if (r->exp > emax2)
2129 goto overflow;
2130 else if (r->exp <= emin2m1)
2131 {
2132 int diff;
2133
2134 if (!fmt->has_denorm)
2135 {
2136 /* Don't underflow completely until we've had a chance to round. */
2137 if (r->exp < emin2m1)
2138 goto underflow;
2139 }
2140 else
2141 {
2142 diff = emin2m1 - r->exp + 1;
2143 if (diff > p2)
2144 goto underflow;
2145
2146 /* De-normalize the significand. */
2147 sticky_rshift_significand (r, r, diff);
2148 r->exp += diff;
2149 }
2150 }
2151
2152 /* There are P2 true significand bits, followed by one guard bit,
2153 followed by one sticky bit, followed by stuff. Fold non-zero
2154 stuff into the sticky bit. */
2155
2156 sticky = 0;
2157 for (i = 0, w = (np2 - 1) / HOST_BITS_PER_LONG; i < w; ++i)
2158 sticky |= r->sig[i];
2159 sticky |=
2160 r->sig[w] & (((unsigned long)1 << ((np2 - 1) % HOST_BITS_PER_LONG)) - 1);
2161
2162 guard = test_significand_bit (r, np2 - 1);
2163 lsb = test_significand_bit (r, np2);
2164
2165 /* Round to even. */
2166 if (guard && (sticky || lsb))
2167 {
2168 REAL_VALUE_TYPE u;
2169 get_zero (&u, 0);
2170 set_significand_bit (&u, np2);
2171
2172 if (add_significands (r, r, &u))
2173 {
2174 /* Overflow. Means the significand had been all ones, and
2175 is now all zeros. Need to increase the exponent, and
2176 possibly re-normalize it. */
2177 if (++r->exp > emax2)
2178 goto overflow;
2179 r->sig[SIGSZ-1] = SIG_MSB;
2180
2181 if (fmt->log2_b != 1)
2182 {
2183 int shift = r->exp & (fmt->log2_b - 1);
2184 if (shift)
2185 {
2186 shift = fmt->log2_b - shift;
2187 sticky_rshift_significand (r, r, shift);
2188 r->exp += shift;
2189 if (r->exp > emax2)
2190 goto overflow;
2191 }
2192 }
2193 }
2194 }
2195
2196 /* Catch underflow that we deferred until after rounding. */
2197 if (r->exp <= emin2m1)
2198 goto underflow;
2199
2200 /* Clear out trailing garbage. */
2201 clear_significand_below (r, np2);
2202 }
2203
2204 /* Extend or truncate to a new mode. */
2205
2206 void
2207 real_convert (r, mode, a)
2208 REAL_VALUE_TYPE *r;
2209 enum machine_mode mode;
2210 const REAL_VALUE_TYPE *a;
2211 {
2212 const struct real_format *fmt;
2213
2214 fmt = fmt_for_mode[mode - QFmode];
2215 if (fmt == NULL)
2216 abort ();
2217
2218 *r = *a;
2219 round_for_format (fmt, r);
2220
2221 /* round_for_format de-normalizes denormals. Undo just that part. */
2222 if (r->class == rvc_normal)
2223 normalize (r);
2224 }
2225
2226 /* Legacy. Likewise, except return the struct directly. */
2227
2228 REAL_VALUE_TYPE
2229 real_value_truncate (mode, a)
2230 enum machine_mode mode;
2231 REAL_VALUE_TYPE a;
2232 {
2233 REAL_VALUE_TYPE r;
2234 real_convert (&r, mode, &a);
2235 return r;
2236 }
2237
2238 /* Return true if truncating to MODE is exact. */
2239
2240 bool
2241 exact_real_truncate (mode, a)
2242 enum machine_mode mode;
2243 const REAL_VALUE_TYPE *a;
2244 {
2245 REAL_VALUE_TYPE t;
2246 real_convert (&t, mode, a);
2247 return real_identical (&t, a);
2248 }
2249
2250 /* Write R to the target format of MODE. Place the words of the
2251 result in target word order in BUF. There are always 32 bits
2252 in each long, no matter the size of the host long.
2253
2254 Legacy: return word 0 for implementing REAL_VALUE_TO_TARGET_SINGLE. */
2255
2256 long
2257 real_to_target (buf, r_orig, mode)
2258 long *buf;
2259 const REAL_VALUE_TYPE *r_orig;
2260 enum machine_mode mode;
2261 {
2262 REAL_VALUE_TYPE r;
2263 const struct real_format *fmt;
2264 long buf1;
2265
2266 fmt = fmt_for_mode[mode - QFmode];
2267 if (fmt == NULL)
2268 abort ();
2269
2270 r = *r_orig;
2271 round_for_format (fmt, &r);
2272
2273 if (!buf)
2274 buf = &buf1;
2275 (*fmt->encode) (fmt, buf, &r);
2276
2277 return *buf;
2278 }
2279
2280 /* Read R from the target format of MODE. Read the words of the
2281 result in target word order in BUF. There are always 32 bits
2282 in each long, no matter the size of the host long. */
2283
2284 void
2285 real_from_target (r, buf, mode)
2286 REAL_VALUE_TYPE *r;
2287 const long *buf;
2288 enum machine_mode mode;
2289 {
2290 const struct real_format *fmt;
2291
2292 fmt = fmt_for_mode[mode - QFmode];
2293 if (fmt == NULL)
2294 abort ();
2295
2296 (*fmt->decode) (fmt, r, buf);
2297 }
2298
2299 /* Return the number of bits in the significand for MODE. */
2300 /* ??? Legacy. Should get access to real_format directly. */
2301
2302 int
2303 significand_size (mode)
2304 enum machine_mode mode;
2305 {
2306 const struct real_format *fmt;
2307
2308 fmt = fmt_for_mode[mode - QFmode];
2309 if (fmt == NULL)
2310 return 0;
2311
2312 return fmt->p * fmt->log2_b;
2313 }
2314
2315 /* Return a hash value for the given real value. */
2316 /* ??? The "unsigned int" return value is intended to be hashval_t,
2317 but I didn't want to pull hashtab.h into real.h. */
2318
2319 unsigned int
2320 real_hash (r)
2321 const REAL_VALUE_TYPE *r;
2322 {
2323 unsigned int h;
2324 size_t i;
2325
2326 h = r->class | (r->sign << 2);
2327 switch (r->class)
2328 {
2329 case rvc_zero:
2330 case rvc_inf:
2331 break;
2332
2333 case rvc_normal:
2334 h |= r->exp << 3;
2335 /* FALLTHRU */
2336
2337 case rvc_nan:
2338 if (sizeof(unsigned long) > sizeof(unsigned int))
2339 for (i = 0; i < SIGSZ; ++i)
2340 {
2341 unsigned long s = r->sig[i];
2342 h ^= s ^ (s >> (HOST_BITS_PER_LONG / 2));
2343 }
2344 else
2345 for (i = 0; i < SIGSZ; ++i)
2346 h ^= r->sig[i];
2347 break;
2348
2349 default:
2350 abort ();
2351 }
2352
2353 return h;
2354 }
2355 \f
2356 /* IEEE single-precision format. */
2357
2358 static void encode_ieee_single PARAMS ((const struct real_format *fmt,
2359 long *, const REAL_VALUE_TYPE *));
2360 static void decode_ieee_single PARAMS ((const struct real_format *,
2361 REAL_VALUE_TYPE *, const long *));
2362
2363 static void
2364 encode_ieee_single (fmt, buf, r)
2365 const struct real_format *fmt;
2366 long *buf;
2367 const REAL_VALUE_TYPE *r;
2368 {
2369 unsigned long image, sig, exp;
2370 bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0;
2371
2372 image = r->sign << 31;
2373 sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff;
2374
2375 switch (r->class)
2376 {
2377 case rvc_zero:
2378 break;
2379
2380 case rvc_inf:
2381 if (fmt->has_inf)
2382 image |= 255 << 23;
2383 else
2384 image |= 0x7fffffff;
2385 break;
2386
2387 case rvc_nan:
2388 if (fmt->has_nans)
2389 {
2390 image |= 255 << 23;
2391 image |= sig;
2392 if (!fmt->qnan_msb_set)
2393 image ^= 1 << 23 | 1 << 22;
2394 }
2395 else
2396 image |= 0x7fffffff;
2397 break;
2398
2399 case rvc_normal:
2400 /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
2401 whereas the intermediate representation is 0.F x 2**exp.
2402 Which means we're off by one. */
2403 if (denormal)
2404 exp = 0;
2405 else
2406 exp = r->exp + 127 - 1;
2407 image |= exp << 23;
2408 image |= sig;
2409 break;
2410
2411 default:
2412 abort ();
2413 }
2414
2415 buf[0] = image;
2416 }
2417
2418 static void
2419 decode_ieee_single (fmt, r, buf)
2420 const struct real_format *fmt;
2421 REAL_VALUE_TYPE *r;
2422 const long *buf;
2423 {
2424 unsigned long image = buf[0] & 0xffffffff;
2425 bool sign = (image >> 31) & 1;
2426 int exp = (image >> 23) & 0xff;
2427
2428 memset (r, 0, sizeof (*r));
2429 image <<= HOST_BITS_PER_LONG - 24;
2430 image &= ~SIG_MSB;
2431
2432 if (exp == 0)
2433 {
2434 if (image && fmt->has_denorm)
2435 {
2436 r->class = rvc_normal;
2437 r->sign = sign;
2438 r->exp = -126;
2439 r->sig[SIGSZ-1] = image << 1;
2440 normalize (r);
2441 }
2442 else if (fmt->has_signed_zero)
2443 r->sign = sign;
2444 }
2445 else if (exp == 255 && (fmt->has_nans || fmt->has_inf))
2446 {
2447 if (image)
2448 {
2449 r->class = rvc_nan;
2450 r->sign = sign;
2451 if (!fmt->qnan_msb_set)
2452 image ^= (SIG_MSB >> 1 | SIG_MSB >> 2);
2453 r->sig[SIGSZ-1] = image;
2454 }
2455 else
2456 {
2457 r->class = rvc_inf;
2458 r->sign = sign;
2459 }
2460 }
2461 else
2462 {
2463 r->class = rvc_normal;
2464 r->sign = sign;
2465 r->exp = exp - 127 + 1;
2466 r->sig[SIGSZ-1] = image | SIG_MSB;
2467 }
2468 }
2469
2470 const struct real_format ieee_single =
2471 {
2472 encode_ieee_single,
2473 decode_ieee_single,
2474 2,
2475 1,
2476 24,
2477 -125,
2478 128,
2479 true,
2480 true,
2481 true,
2482 true,
2483 true
2484 };
2485
2486 \f
2487 /* IEEE double-precision format. */
2488
2489 static void encode_ieee_double PARAMS ((const struct real_format *fmt,
2490 long *, const REAL_VALUE_TYPE *));
2491 static void decode_ieee_double PARAMS ((const struct real_format *,
2492 REAL_VALUE_TYPE *, const long *));
2493
2494 static void
2495 encode_ieee_double (fmt, buf, r)
2496 const struct real_format *fmt;
2497 long *buf;
2498 const REAL_VALUE_TYPE *r;
2499 {
2500 unsigned long image_lo, image_hi, sig_lo, sig_hi, exp;
2501 bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0;
2502
2503 image_hi = r->sign << 31;
2504 image_lo = 0;
2505
2506 if (HOST_BITS_PER_LONG == 64)
2507 {
2508 sig_hi = r->sig[SIGSZ-1];
2509 sig_lo = (sig_hi >> (64 - 53)) & 0xffffffff;
2510 sig_hi = (sig_hi >> (64 - 53 + 1) >> 31) & 0xfffff;
2511 }
2512 else
2513 {
2514 sig_hi = r->sig[SIGSZ-1];
2515 sig_lo = r->sig[SIGSZ-2];
2516 sig_lo = (sig_hi << 21) | (sig_lo >> 11);
2517 sig_hi = (sig_hi >> 11) & 0xfffff;
2518 }
2519
2520 switch (r->class)
2521 {
2522 case rvc_zero:
2523 break;
2524
2525 case rvc_inf:
2526 if (fmt->has_inf)
2527 image_hi |= 2047 << 20;
2528 else
2529 {
2530 image_hi |= 0x7fffffff;
2531 image_lo = 0xffffffff;
2532 }
2533 break;
2534
2535 case rvc_nan:
2536 if (fmt->has_nans)
2537 {
2538 image_hi |= 2047 << 20;
2539 image_hi |= sig_hi;
2540 if (!fmt->qnan_msb_set)
2541 image_hi ^= 1 << 19 | 1 << 18;
2542 image_lo = sig_lo;
2543 }
2544 else
2545 {
2546 image_hi |= 0x7fffffff;
2547 image_lo = 0xffffffff;
2548 }
2549 break;
2550
2551 case rvc_normal:
2552 /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
2553 whereas the intermediate representation is 0.F x 2**exp.
2554 Which means we're off by one. */
2555 if (denormal)
2556 exp = 0;
2557 else
2558 exp = r->exp + 1023 - 1;
2559 image_hi |= exp << 20;
2560 image_hi |= sig_hi;
2561 image_lo = sig_lo;
2562 break;
2563
2564 default:
2565 abort ();
2566 }
2567
2568 if (FLOAT_WORDS_BIG_ENDIAN)
2569 buf[0] = image_hi, buf[1] = image_lo;
2570 else
2571 buf[0] = image_lo, buf[1] = image_hi;
2572 }
2573
2574 static void
2575 decode_ieee_double (fmt, r, buf)
2576 const struct real_format *fmt;
2577 REAL_VALUE_TYPE *r;
2578 const long *buf;
2579 {
2580 unsigned long image_hi, image_lo;
2581 bool sign;
2582 int exp;
2583
2584 if (FLOAT_WORDS_BIG_ENDIAN)
2585 image_hi = buf[0], image_lo = buf[1];
2586 else
2587 image_lo = buf[0], image_hi = buf[1];
2588 image_lo &= 0xffffffff;
2589 image_hi &= 0xffffffff;
2590
2591 sign = (image_hi >> 31) & 1;
2592 exp = (image_hi >> 20) & 0x7ff;
2593
2594 memset (r, 0, sizeof (*r));
2595
2596 image_hi <<= 32 - 21;
2597 image_hi |= image_lo >> 21;
2598 image_hi &= 0x7fffffff;
2599 image_lo <<= 32 - 21;
2600
2601 if (exp == 0)
2602 {
2603 if ((image_hi || image_lo) && fmt->has_denorm)
2604 {
2605 r->class = rvc_normal;
2606 r->sign = sign;
2607 r->exp = -1022;
2608 if (HOST_BITS_PER_LONG == 32)
2609 {
2610 image_hi = (image_hi << 1) | (image_lo >> 31);
2611 image_lo <<= 1;
2612 r->sig[SIGSZ-1] = image_hi;
2613 r->sig[SIGSZ-2] = image_lo;
2614 }
2615 else
2616 {
2617 image_hi = (image_hi << 31 << 2) | (image_lo << 1);
2618 r->sig[SIGSZ-1] = image_hi;
2619 }
2620 normalize (r);
2621 }
2622 else if (fmt->has_signed_zero)
2623 r->sign = sign;
2624 }
2625 else if (exp == 2047 && (fmt->has_nans || fmt->has_inf))
2626 {
2627 if (image_hi || image_lo)
2628 {
2629 r->class = rvc_nan;
2630 r->sign = sign;
2631 if (HOST_BITS_PER_LONG == 32)
2632 {
2633 r->sig[SIGSZ-1] = image_hi;
2634 r->sig[SIGSZ-2] = image_lo;
2635 }
2636 else
2637 r->sig[SIGSZ-1] = (image_hi << 31 << 1) | image_lo;
2638
2639 if (!fmt->qnan_msb_set)
2640 r->sig[SIGSZ-1] ^= (SIG_MSB >> 1 | SIG_MSB >> 2);
2641 }
2642 else
2643 {
2644 r->class = rvc_inf;
2645 r->sign = sign;
2646 }
2647 }
2648 else
2649 {
2650 r->class = rvc_normal;
2651 r->sign = sign;
2652 r->exp = exp - 1023 + 1;
2653 if (HOST_BITS_PER_LONG == 32)
2654 {
2655 r->sig[SIGSZ-1] = image_hi | SIG_MSB;
2656 r->sig[SIGSZ-2] = image_lo;
2657 }
2658 else
2659 r->sig[SIGSZ-1] = (image_hi << 31 << 1) | image_lo | SIG_MSB;
2660 }
2661 }
2662
2663 const struct real_format ieee_double =
2664 {
2665 encode_ieee_double,
2666 decode_ieee_double,
2667 2,
2668 1,
2669 53,
2670 -1021,
2671 1024,
2672 true,
2673 true,
2674 true,
2675 true,
2676 true
2677 };
2678
2679 \f
2680 /* IEEE extended double precision format. This comes in three
2681 flavours: Intel's as a 12 byte image, Intel's as a 16 byte image,
2682 and Motorola's. */
2683
2684 static void encode_ieee_extended PARAMS ((const struct real_format *fmt,
2685 long *, const REAL_VALUE_TYPE *));
2686 static void decode_ieee_extended PARAMS ((const struct real_format *,
2687 REAL_VALUE_TYPE *, const long *));
2688
2689 static void encode_ieee_extended_128 PARAMS ((const struct real_format *fmt,
2690 long *,
2691 const REAL_VALUE_TYPE *));
2692 static void decode_ieee_extended_128 PARAMS ((const struct real_format *,
2693 REAL_VALUE_TYPE *,
2694 const long *));
2695
2696 static void
2697 encode_ieee_extended (fmt, buf, r)
2698 const struct real_format *fmt;
2699 long *buf;
2700 const REAL_VALUE_TYPE *r;
2701 {
2702 unsigned long image_hi, sig_hi, sig_lo;
2703 bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0;
2704
2705 image_hi = r->sign << 15;
2706 sig_hi = sig_lo = 0;
2707
2708 switch (r->class)
2709 {
2710 case rvc_zero:
2711 break;
2712
2713 case rvc_inf:
2714 if (fmt->has_inf)
2715 {
2716 image_hi |= 32767;
2717
2718 /* Intel requires the explicit integer bit to be set, otherwise
2719 it considers the value a "pseudo-infinity". Motorola docs
2720 say it doesn't care. */
2721 sig_hi = 0x80000000;
2722 }
2723 else
2724 {
2725 image_hi |= 32767;
2726 sig_lo = sig_hi = 0xffffffff;
2727 }
2728 break;
2729
2730 case rvc_nan:
2731 if (fmt->has_nans)
2732 {
2733 image_hi |= 32767;
2734 if (HOST_BITS_PER_LONG == 32)
2735 {
2736 sig_hi = r->sig[SIGSZ-1];
2737 sig_lo = r->sig[SIGSZ-2];
2738 }
2739 else
2740 {
2741 sig_lo = r->sig[SIGSZ-1];
2742 sig_hi = sig_lo >> 31 >> 1;
2743 sig_lo &= 0xffffffff;
2744 }
2745 if (!fmt->qnan_msb_set)
2746 sig_hi ^= 1 << 30 | 1 << 29;
2747
2748 /* Intel requires the explicit integer bit to be set, otherwise
2749 it considers the value a "pseudo-nan". Motorola docs say it
2750 doesn't care. */
2751 sig_hi |= 0x80000000;
2752 }
2753 else
2754 {
2755 image_hi |= 32767;
2756 sig_lo = sig_hi = 0xffffffff;
2757 }
2758 break;
2759
2760 case rvc_normal:
2761 {
2762 int exp = r->exp;
2763
2764 /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
2765 whereas the intermediate representation is 0.F x 2**exp.
2766 Which means we're off by one.
2767
2768 Except for Motorola, which consider exp=0 and explicit
2769 integer bit set to continue to be normalized. In theory
2770 this descrepency has been taken care of by the difference
2771 in fmt->emin in round_for_format. */
2772
2773 if (denormal)
2774 exp = 0;
2775 else
2776 {
2777 exp += 16383 - 1;
2778 if (exp < 0)
2779 abort ();
2780 }
2781 image_hi |= exp;
2782
2783 if (HOST_BITS_PER_LONG == 32)
2784 {
2785 sig_hi = r->sig[SIGSZ-1];
2786 sig_lo = r->sig[SIGSZ-2];
2787 }
2788 else
2789 {
2790 sig_lo = r->sig[SIGSZ-1];
2791 sig_hi = sig_lo >> 31 >> 1;
2792 sig_lo &= 0xffffffff;
2793 }
2794 }
2795 break;
2796
2797 default:
2798 abort ();
2799 }
2800
2801 if (FLOAT_WORDS_BIG_ENDIAN)
2802 buf[0] = image_hi << 16, buf[1] = sig_hi, buf[2] = sig_lo;
2803 else
2804 buf[0] = sig_lo, buf[1] = sig_hi, buf[2] = image_hi;
2805 }
2806
2807 static void
2808 encode_ieee_extended_128 (fmt, buf, r)
2809 const struct real_format *fmt;
2810 long *buf;
2811 const REAL_VALUE_TYPE *r;
2812 {
2813 buf[3 * !FLOAT_WORDS_BIG_ENDIAN] = 0;
2814 encode_ieee_extended (fmt, buf+!!FLOAT_WORDS_BIG_ENDIAN, r);
2815 }
2816
2817 static void
2818 decode_ieee_extended (fmt, r, buf)
2819 const struct real_format *fmt;
2820 REAL_VALUE_TYPE *r;
2821 const long *buf;
2822 {
2823 unsigned long image_hi, sig_hi, sig_lo;
2824 bool sign;
2825 int exp;
2826
2827 if (FLOAT_WORDS_BIG_ENDIAN)
2828 image_hi = buf[0] >> 16, sig_hi = buf[1], sig_lo = buf[2];
2829 else
2830 sig_lo = buf[0], sig_hi = buf[1], image_hi = buf[2];
2831 sig_lo &= 0xffffffff;
2832 sig_hi &= 0xffffffff;
2833 image_hi &= 0xffffffff;
2834
2835 sign = (image_hi >> 15) & 1;
2836 exp = image_hi & 0x7fff;
2837
2838 memset (r, 0, sizeof (*r));
2839
2840 if (exp == 0)
2841 {
2842 if ((sig_hi || sig_lo) && fmt->has_denorm)
2843 {
2844 r->class = rvc_normal;
2845 r->sign = sign;
2846
2847 /* When the IEEE format contains a hidden bit, we know that
2848 it's zero at this point, and so shift up the significand
2849 and decrease the exponent to match. In this case, Motorola
2850 defines the explicit integer bit to be valid, so we don't
2851 know whether the msb is set or not. */
2852 r->exp = fmt->emin;
2853 if (HOST_BITS_PER_LONG == 32)
2854 {
2855 r->sig[SIGSZ-1] = sig_hi;
2856 r->sig[SIGSZ-2] = sig_lo;
2857 }
2858 else
2859 r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
2860
2861 normalize (r);
2862 }
2863 else if (fmt->has_signed_zero)
2864 r->sign = sign;
2865 }
2866 else if (exp == 32767 && (fmt->has_nans || fmt->has_inf))
2867 {
2868 /* See above re "pseudo-infinities" and "pseudo-nans".
2869 Short summary is that the MSB will likely always be
2870 set, and that we don't care about it. */
2871 sig_hi &= 0x7fffffff;
2872
2873 if (sig_hi || sig_lo)
2874 {
2875 r->class = rvc_nan;
2876 r->sign = sign;
2877 if (HOST_BITS_PER_LONG == 32)
2878 {
2879 r->sig[SIGSZ-1] = sig_hi;
2880 r->sig[SIGSZ-2] = sig_lo;
2881 }
2882 else
2883 r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
2884
2885 if (!fmt->qnan_msb_set)
2886 r->sig[SIGSZ-1] ^= (SIG_MSB >> 1 | SIG_MSB >> 2);
2887 }
2888 else
2889 {
2890 r->class = rvc_inf;
2891 r->sign = sign;
2892 }
2893 }
2894 else
2895 {
2896 r->class = rvc_normal;
2897 r->sign = sign;
2898 r->exp = exp - 16383 + 1;
2899 if (HOST_BITS_PER_LONG == 32)
2900 {
2901 r->sig[SIGSZ-1] = sig_hi;
2902 r->sig[SIGSZ-2] = sig_lo;
2903 }
2904 else
2905 r->sig[SIGSZ-1] = (sig_hi << 31 << 1) | sig_lo;
2906 }
2907 }
2908
2909 static void
2910 decode_ieee_extended_128 (fmt, r, buf)
2911 const struct real_format *fmt;
2912 REAL_VALUE_TYPE *r;
2913 const long *buf;
2914 {
2915 decode_ieee_extended (fmt, r, buf+!!FLOAT_WORDS_BIG_ENDIAN);
2916 }
2917
2918 const struct real_format ieee_extended_motorola =
2919 {
2920 encode_ieee_extended,
2921 decode_ieee_extended,
2922 2,
2923 1,
2924 64,
2925 -16382,
2926 16384,
2927 true,
2928 true,
2929 true,
2930 true,
2931 true
2932 };
2933
2934 const struct real_format ieee_extended_intel_96 =
2935 {
2936 encode_ieee_extended,
2937 decode_ieee_extended,
2938 2,
2939 1,
2940 64,
2941 -16381,
2942 16384,
2943 true,
2944 true,
2945 true,
2946 true,
2947 true
2948 };
2949
2950 const struct real_format ieee_extended_intel_128 =
2951 {
2952 encode_ieee_extended_128,
2953 decode_ieee_extended_128,
2954 2,
2955 1,
2956 64,
2957 -16381,
2958 16384,
2959 true,
2960 true,
2961 true,
2962 true,
2963 true
2964 };
2965
2966 \f
2967 /* IEEE quad precision format. */
2968
2969 static void encode_ieee_quad PARAMS ((const struct real_format *fmt,
2970 long *, const REAL_VALUE_TYPE *));
2971 static void decode_ieee_quad PARAMS ((const struct real_format *,
2972 REAL_VALUE_TYPE *, const long *));
2973
2974 static void
2975 encode_ieee_quad (fmt, buf, r)
2976 const struct real_format *fmt;
2977 long *buf;
2978 const REAL_VALUE_TYPE *r;
2979 {
2980 unsigned long image3, image2, image1, image0, exp;
2981 bool denormal = (r->sig[SIGSZ-1] & SIG_MSB) == 0;
2982 REAL_VALUE_TYPE u;
2983
2984 image3 = r->sign << 31;
2985 image2 = 0;
2986 image1 = 0;
2987 image0 = 0;
2988
2989 rshift_significand (&u, r, SIGNIFICAND_BITS - 113);
2990
2991 switch (r->class)
2992 {
2993 case rvc_zero:
2994 break;
2995
2996 case rvc_inf:
2997 if (fmt->has_inf)
2998 image3 |= 32767 << 16;
2999 else
3000 {
3001 image3 |= 0x7fffffff;
3002 image2 = 0xffffffff;
3003 image1 = 0xffffffff;
3004 image0 = 0xffffffff;
3005 }
3006 break;
3007
3008 case rvc_nan:
3009 if (fmt->has_nans)
3010 {
3011 image3 |= 32767 << 16;
3012
3013 if (HOST_BITS_PER_LONG == 32)
3014 {
3015 image0 = u.sig[0];
3016 image1 = u.sig[1];
3017 image2 = u.sig[2];
3018 image3 |= u.sig[3] & 0xffff;
3019 }
3020 else
3021 {
3022 image0 = u.sig[0];
3023 image1 = image0 >> 31 >> 1;
3024 image2 = u.sig[1];
3025 image3 |= (image2 >> 31 >> 1) & 0xffff;
3026 image0 &= 0xffffffff;
3027 image2 &= 0xffffffff;
3028 }
3029
3030 if (!fmt->qnan_msb_set)
3031 image3 ^= 1 << 15 | 1 << 14;
3032 }
3033 else
3034 {
3035 image3 |= 0x7fffffff;
3036 image2 = 0xffffffff;
3037 image1 = 0xffffffff;
3038 image0 = 0xffffffff;
3039 }
3040 break;
3041
3042 case rvc_normal:
3043 /* Recall that IEEE numbers are interpreted as 1.F x 2**exp,
3044 whereas the intermediate representation is 0.F x 2**exp.
3045 Which means we're off by one. */
3046 if (denormal)
3047 exp = 0;
3048 else
3049 exp = r->exp + 16383 - 1;
3050 image3 |= exp << 16;
3051
3052 if (HOST_BITS_PER_LONG == 32)
3053 {
3054 image0 = u.sig[0];
3055 image1 = u.sig[1];
3056 image2 = u.sig[2];
3057 image3 |= u.sig[3] & 0xffff;
3058 }
3059 else
3060 {
3061 image0 = u.sig[0];
3062 image1 = image0 >> 31 >> 1;
3063 image2 = u.sig[1];
3064 image3 |= (image2 >> 31 >> 1) & 0xffff;
3065 image0 &= 0xffffffff;
3066 image2 &= 0xffffffff;
3067 }
3068 break;
3069
3070 default:
3071 abort ();
3072 }
3073
3074 if (FLOAT_WORDS_BIG_ENDIAN)
3075 {
3076 buf[0] = image3;
3077 buf[1] = image2;
3078 buf[2] = image1;
3079 buf[3] = image0;
3080 }
3081 else
3082 {
3083 buf[0] = image0;
3084 buf[1] = image1;
3085 buf[2] = image2;
3086 buf[3] = image3;
3087 }
3088 }
3089
3090 static void
3091 decode_ieee_quad (fmt, r, buf)
3092 const struct real_format *fmt;
3093 REAL_VALUE_TYPE *r;
3094 const long *buf;
3095 {
3096 unsigned long image3, image2, image1, image0;
3097 bool sign;
3098 int exp;
3099
3100 if (FLOAT_WORDS_BIG_ENDIAN)
3101 {
3102 image3 = buf[0];
3103 image2 = buf[1];
3104 image1 = buf[2];
3105 image0 = buf[3];
3106 }
3107 else
3108 {
3109 image0 = buf[0];
3110 image1 = buf[1];
3111 image2 = buf[2];
3112 image3 = buf[3];
3113 }
3114 image0 &= 0xffffffff;
3115 image1 &= 0xffffffff;
3116 image2 &= 0xffffffff;
3117
3118 sign = (image3 >> 31) & 1;
3119 exp = (image3 >> 16) & 0x7fff;
3120 image3 &= 0xffff;
3121
3122 memset (r, 0, sizeof (*r));
3123
3124 if (exp == 0)
3125 {
3126 if ((image3 | image2 | image1 | image0) && fmt->has_denorm)
3127 {
3128 r->class = rvc_normal;
3129 r->sign = sign;
3130
3131 r->exp = -16382 + (SIGNIFICAND_BITS - 112);
3132 if (HOST_BITS_PER_LONG == 32)
3133 {
3134 r->sig[0] = image0;
3135 r->sig[1] = image1;
3136 r->sig[2] = image2;
3137 r->sig[3] = image3;
3138 }
3139 else
3140 {
3141 r->sig[0] = (image1 << 31 << 1) | image0;
3142 r->sig[1] = (image3 << 31 << 1) | image2;
3143 }
3144
3145 normalize (r);
3146 }
3147 else if (fmt->has_signed_zero)
3148 r->sign = sign;
3149 }
3150 else if (exp == 32767 && (fmt->has_nans || fmt->has_inf))
3151 {
3152 if (image3 | image2 | image1 | image0)
3153 {
3154 r->class = rvc_nan;
3155 r->sign = sign;
3156
3157 if (HOST_BITS_PER_LONG == 32)
3158 {
3159 r->sig[0] = image0;
3160 r->sig[1] = image1;
3161 r->sig[2] = image2;
3162 r->sig[3] = image3;
3163 }
3164 else
3165 {
3166 r->sig[0] = (image1 << 31 << 1) | image0;
3167 r->sig[1] = (image3 << 31 << 1) | image2;
3168 }
3169 lshift_significand (r, r, SIGNIFICAND_BITS - 113);
3170
3171 if (!fmt->qnan_msb_set)
3172 r->sig[SIGSZ-1] ^= (SIG_MSB >> 1 | SIG_MSB >> 2);
3173 }
3174 else
3175 {
3176 r->class = rvc_inf;
3177 r->sign = sign;
3178 }
3179 }
3180 else
3181 {
3182 r->class = rvc_normal;
3183 r->sign = sign;
3184 r->exp = exp - 16383 + 1;
3185
3186 if (HOST_BITS_PER_LONG == 32)
3187 {
3188 r->sig[0] = image0;
3189 r->sig[1] = image1;
3190 r->sig[2] = image2;
3191 r->sig[3] = image3;
3192 }
3193 else
3194 {
3195 r->sig[0] = (image1 << 31 << 1) | image0;
3196 r->sig[1] = (image3 << 31 << 1) | image2;
3197 }
3198 lshift_significand (r, r, SIGNIFICAND_BITS - 113);
3199 r->sig[SIGSZ-1] |= SIG_MSB;
3200 }
3201 }
3202
3203 const struct real_format ieee_quad =
3204 {
3205 encode_ieee_quad,
3206 decode_ieee_quad,
3207 2,
3208 1,
3209 113,
3210 -16382,
3211 16384,
3212 true,
3213 true,
3214 true,
3215 true,
3216 true
3217 };
3218
3219 \f
3220 /* The VAX floating point formats. */
3221
3222 static void encode_vax_f PARAMS ((const struct real_format *fmt,
3223 long *, const REAL_VALUE_TYPE *));
3224 static void decode_vax_f PARAMS ((const struct real_format *,
3225 REAL_VALUE_TYPE *, const long *));
3226 static void encode_vax_d PARAMS ((const struct real_format *fmt,
3227 long *, const REAL_VALUE_TYPE *));
3228 static void decode_vax_d PARAMS ((const struct real_format *,
3229 REAL_VALUE_TYPE *, const long *));
3230 static void encode_vax_g PARAMS ((const struct real_format *fmt,
3231 long *, const REAL_VALUE_TYPE *));
3232 static void decode_vax_g PARAMS ((const struct real_format *,
3233 REAL_VALUE_TYPE *, const long *));
3234
3235 static void
3236 encode_vax_f (fmt, buf, r)
3237 const struct real_format *fmt ATTRIBUTE_UNUSED;
3238 long *buf;
3239 const REAL_VALUE_TYPE *r;
3240 {
3241 unsigned long sign, exp, sig, image;
3242
3243 sign = r->sign << 15;
3244
3245 switch (r->class)
3246 {
3247 case rvc_zero:
3248 image = 0;
3249 break;
3250
3251 case rvc_inf:
3252 case rvc_nan:
3253 image = 0xffff7fff | sign;
3254 break;
3255
3256 case rvc_normal:
3257 sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff;
3258 exp = r->exp + 128;
3259
3260 image = (sig << 16) & 0xffff0000;
3261 image |= sign;
3262 image |= exp << 7;
3263 image |= sig >> 16;
3264 break;
3265
3266 default:
3267 abort ();
3268 }
3269
3270 buf[0] = image;
3271 }
3272
3273 static void
3274 decode_vax_f (fmt, r, buf)
3275 const struct real_format *fmt ATTRIBUTE_UNUSED;
3276 REAL_VALUE_TYPE *r;
3277 const long *buf;
3278 {
3279 unsigned long image = buf[0] & 0xffffffff;
3280 int exp = (image >> 7) & 0xff;
3281
3282 memset (r, 0, sizeof (*r));
3283
3284 if (exp != 0)
3285 {
3286 r->class = rvc_normal;
3287 r->sign = (image >> 15) & 1;
3288 r->exp = exp - 128;
3289
3290 image = ((image & 0x7f) << 16) | ((image >> 16) & 0xffff);
3291 r->sig[SIGSZ-1] = (image << (HOST_BITS_PER_LONG - 24)) | SIG_MSB;
3292 }
3293 }
3294
3295 static void
3296 encode_vax_d (fmt, buf, r)
3297 const struct real_format *fmt ATTRIBUTE_UNUSED;
3298 long *buf;
3299 const REAL_VALUE_TYPE *r;
3300 {
3301 unsigned long image0, image1, sign = r->sign << 15;
3302
3303 switch (r->class)
3304 {
3305 case rvc_zero:
3306 image0 = image1 = 0;
3307 break;
3308
3309 case rvc_inf:
3310 case rvc_nan:
3311 image0 = 0xffff7fff | sign;
3312 image1 = 0xffffffff;
3313 break;
3314
3315 case rvc_normal:
3316 /* Extract the significand into straight hi:lo. */
3317 if (HOST_BITS_PER_LONG == 64)
3318 {
3319 image0 = r->sig[SIGSZ-1];
3320 image1 = (image0 >> (64 - 56)) & 0xffffffff;
3321 image0 = (image0 >> (64 - 56 + 1) >> 31) & 0x7fffff;
3322 }
3323 else
3324 {
3325 image0 = r->sig[SIGSZ-1];
3326 image1 = r->sig[SIGSZ-2];
3327 image1 = (image0 << 24) | (image1 >> 8);
3328 image0 = (image0 >> 8) & 0xffffff;
3329 }
3330
3331 /* Rearrange the half-words of the significand to match the
3332 external format. */
3333 image0 = ((image0 << 16) | (image0 >> 16)) & 0xffff007f;
3334 image1 = ((image1 << 16) | (image1 >> 16)) & 0xffffffff;
3335
3336 /* Add the sign and exponent. */
3337 image0 |= sign;
3338 image0 |= (r->exp + 128) << 7;
3339 break;
3340
3341 default:
3342 abort ();
3343 }
3344
3345 if (FLOAT_WORDS_BIG_ENDIAN)
3346 buf[0] = image1, buf[1] = image0;
3347 else
3348 buf[0] = image0, buf[1] = image1;
3349 }
3350
3351 static void
3352 decode_vax_d (fmt, r, buf)
3353 const struct real_format *fmt ATTRIBUTE_UNUSED;
3354 REAL_VALUE_TYPE *r;
3355 const long *buf;
3356 {
3357 unsigned long image0, image1;
3358 int exp;
3359
3360 if (FLOAT_WORDS_BIG_ENDIAN)
3361 image1 = buf[0], image0 = buf[1];
3362 else
3363 image0 = buf[0], image1 = buf[1];
3364 image0 &= 0xffffffff;
3365 image1 &= 0xffffffff;
3366
3367 exp = (image0 >> 7) & 0x7f;
3368
3369 memset (r, 0, sizeof (*r));
3370
3371 if (exp != 0)
3372 {
3373 r->class = rvc_normal;
3374 r->sign = (image0 >> 15) & 1;
3375 r->exp = exp - 128;
3376
3377 /* Rearrange the half-words of the external format into
3378 proper ascending order. */
3379 image0 = ((image0 & 0x7f) << 16) | ((image0 >> 16) & 0xffff);
3380 image1 = ((image1 & 0xffff) << 16) | ((image1 >> 16) & 0xffff);
3381
3382 if (HOST_BITS_PER_LONG == 64)
3383 {
3384 image0 = (image0 << 31 << 1) | image1;
3385 image0 <<= 64 - 56;
3386 image0 |= SIG_MSB;
3387 r->sig[SIGSZ-1] = image0;
3388 }
3389 else
3390 {
3391 r->sig[SIGSZ-1] = image0;
3392 r->sig[SIGSZ-2] = image1;
3393 lshift_significand (r, r, 2*HOST_BITS_PER_LONG - 56);
3394 r->sig[SIGSZ-1] |= SIG_MSB;
3395 }
3396 }
3397 }
3398
3399 static void
3400 encode_vax_g (fmt, buf, r)
3401 const struct real_format *fmt ATTRIBUTE_UNUSED;
3402 long *buf;
3403 const REAL_VALUE_TYPE *r;
3404 {
3405 unsigned long image0, image1, sign = r->sign << 15;
3406
3407 switch (r->class)
3408 {
3409 case rvc_zero:
3410 image0 = image1 = 0;
3411 break;
3412
3413 case rvc_inf:
3414 case rvc_nan:
3415 image0 = 0xffff7fff | sign;
3416 image1 = 0xffffffff;
3417 break;
3418
3419 case rvc_normal:
3420 /* Extract the significand into straight hi:lo. */
3421 if (HOST_BITS_PER_LONG == 64)
3422 {
3423 image0 = r->sig[SIGSZ-1];
3424 image1 = (image0 >> (64 - 53)) & 0xffffffff;
3425 image0 = (image0 >> (64 - 53 + 1) >> 31) & 0xfffff;
3426 }
3427 else
3428 {
3429 image0 = r->sig[SIGSZ-1];
3430 image1 = r->sig[SIGSZ-2];
3431 image1 = (image0 << 21) | (image1 >> 11);
3432 image0 = (image0 >> 11) & 0xfffff;
3433 }
3434
3435 /* Rearrange the half-words of the significand to match the
3436 external format. */
3437 image0 = ((image0 << 16) | (image0 >> 16)) & 0xffff000f;
3438 image1 = ((image1 << 16) | (image1 >> 16)) & 0xffffffff;
3439
3440 /* Add the sign and exponent. */
3441 image0 |= sign;
3442 image0 |= (r->exp + 1024) << 4;
3443 break;
3444
3445 default:
3446 abort ();
3447 }
3448
3449 if (FLOAT_WORDS_BIG_ENDIAN)
3450 buf[0] = image1, buf[1] = image0;
3451 else
3452 buf[0] = image0, buf[1] = image1;
3453 }
3454
3455 static void
3456 decode_vax_g (fmt, r, buf)
3457 const struct real_format *fmt ATTRIBUTE_UNUSED;
3458 REAL_VALUE_TYPE *r;
3459 const long *buf;
3460 {
3461 unsigned long image0, image1;
3462 int exp;
3463
3464 if (FLOAT_WORDS_BIG_ENDIAN)
3465 image1 = buf[0], image0 = buf[1];
3466 else
3467 image0 = buf[0], image1 = buf[1];
3468 image0 &= 0xffffffff;
3469 image1 &= 0xffffffff;
3470
3471 exp = (image0 >> 4) & 0x7ff;
3472
3473 memset (r, 0, sizeof (*r));
3474
3475 if (exp != 0)
3476 {
3477 r->class = rvc_normal;
3478 r->sign = (image0 >> 15) & 1;
3479 r->exp = exp - 1024;
3480
3481 /* Rearrange the half-words of the external format into
3482 proper ascending order. */
3483 image0 = ((image0 & 0xf) << 16) | ((image0 >> 16) & 0xffff);
3484 image1 = ((image1 & 0xffff) << 16) | ((image1 >> 16) & 0xffff);
3485
3486 if (HOST_BITS_PER_LONG == 64)
3487 {
3488 image0 = (image0 << 31 << 1) | image1;
3489 image0 <<= 64 - 53;
3490 image0 |= SIG_MSB;
3491 r->sig[SIGSZ-1] = image0;
3492 }
3493 else
3494 {
3495 r->sig[SIGSZ-1] = image0;
3496 r->sig[SIGSZ-2] = image1;
3497 lshift_significand (r, r, 64 - 53);
3498 r->sig[SIGSZ-1] |= SIG_MSB;
3499 }
3500 }
3501 }
3502
3503 const struct real_format vax_f_format =
3504 {
3505 encode_vax_f,
3506 decode_vax_f,
3507 2,
3508 1,
3509 24,
3510 -127,
3511 127,
3512 false,
3513 false,
3514 false,
3515 false,
3516 false
3517 };
3518
3519 const struct real_format vax_d_format =
3520 {
3521 encode_vax_d,
3522 decode_vax_d,
3523 2,
3524 1,
3525 56,
3526 -127,
3527 127,
3528 false,
3529 false,
3530 false,
3531 false,
3532 false
3533 };
3534
3535 const struct real_format vax_g_format =
3536 {
3537 encode_vax_g,
3538 decode_vax_g,
3539 2,
3540 1,
3541 53,
3542 -1023,
3543 1023,
3544 false,
3545 false,
3546 false,
3547 false,
3548 false
3549 };
3550
3551 \f
3552 /* The IBM S/390 floating point formats. A good reference for these can
3553 be found in chapter 9 of "ESA/390 Principles of Operation", IBM document
3554 number SA22-7201-01. An on-line version can be found here:
3555
3556 http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/DZ9AR001/9.1?DT=19930923083613
3557 */
3558
3559 static void encode_i370_single PARAMS ((const struct real_format *fmt,
3560 long *, const REAL_VALUE_TYPE *));
3561 static void decode_i370_single PARAMS ((const struct real_format *,
3562 REAL_VALUE_TYPE *, const long *));
3563 static void encode_i370_double PARAMS ((const struct real_format *fmt,
3564 long *, const REAL_VALUE_TYPE *));
3565 static void decode_i370_double PARAMS ((const struct real_format *,
3566 REAL_VALUE_TYPE *, const long *));
3567
3568 static void
3569 encode_i370_single (fmt, buf, r)
3570 const struct real_format *fmt ATTRIBUTE_UNUSED;
3571 long *buf;
3572 const REAL_VALUE_TYPE *r;
3573 {
3574 unsigned long sign, exp, sig, image;
3575
3576 sign = r->sign << 31;
3577
3578 switch (r->class)
3579 {
3580 case rvc_zero:
3581 image = 0;
3582 break;
3583
3584 case rvc_inf:
3585 case rvc_nan:
3586 image = 0x7fffffff | sign;
3587 break;
3588
3589 case rvc_normal:
3590 sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0xffffff;
3591 exp = ((r->exp / 4) + 64) << 24;
3592 image = sign | exp | sig;
3593 break;
3594
3595 default:
3596 abort ();
3597 }
3598
3599 buf[0] = image;
3600 }
3601
3602 static void
3603 decode_i370_single (fmt, r, buf)
3604 const struct real_format *fmt ATTRIBUTE_UNUSED;
3605 REAL_VALUE_TYPE *r;
3606 const long *buf;
3607 {
3608 unsigned long sign, sig, image = buf[0];
3609 int exp;
3610
3611 sign = (image >> 31) & 1;
3612 exp = (image >> 24) & 0x7f;
3613 sig = image & 0xffffff;
3614
3615 memset (r, 0, sizeof (*r));
3616
3617 if (exp || sig)
3618 {
3619 r->class = rvc_normal;
3620 r->sign = sign;
3621 r->exp = (exp - 64) * 4;
3622 r->sig[SIGSZ-1] = sig << (HOST_BITS_PER_LONG - 24);
3623 normalize (r);
3624 }
3625 }
3626
3627 static void
3628 encode_i370_double (fmt, buf, r)
3629 const struct real_format *fmt ATTRIBUTE_UNUSED;
3630 long *buf;
3631 const REAL_VALUE_TYPE *r;
3632 {
3633 unsigned long sign, exp, image_hi, image_lo;
3634
3635 sign = r->sign << 31;
3636
3637 switch (r->class)
3638 {
3639 case rvc_zero:
3640 image_hi = image_lo = 0;
3641 break;
3642
3643 case rvc_inf:
3644 case rvc_nan:
3645 image_hi = 0x7fffffff | sign;
3646 image_lo = 0xffffffff;
3647 break;
3648
3649 case rvc_normal:
3650 if (HOST_BITS_PER_LONG == 64)
3651 {
3652 image_hi = r->sig[SIGSZ-1];
3653 image_lo = (image_hi >> (64 - 56)) & 0xffffffff;
3654 image_hi = (image_hi >> (64 - 56 + 1) >> 31) & 0xffffff;
3655 }
3656 else
3657 {
3658 image_hi = r->sig[SIGSZ-1];
3659 image_lo = r->sig[SIGSZ-2];
3660 image_lo = (image_lo >> 8) | (image_hi << 24);
3661 image_hi >>= 8;
3662 }
3663
3664 exp = ((r->exp / 4) + 64) << 24;
3665 image_hi |= sign | exp;
3666 break;
3667
3668 default:
3669 abort ();
3670 }
3671
3672 if (FLOAT_WORDS_BIG_ENDIAN)
3673 buf[0] = image_hi, buf[1] = image_lo;
3674 else
3675 buf[0] = image_lo, buf[1] = image_hi;
3676 }
3677
3678 static void
3679 decode_i370_double (fmt, r, buf)
3680 const struct real_format *fmt ATTRIBUTE_UNUSED;
3681 REAL_VALUE_TYPE *r;
3682 const long *buf;
3683 {
3684 unsigned long sign, image_hi, image_lo;
3685 int exp;
3686
3687 if (FLOAT_WORDS_BIG_ENDIAN)
3688 image_hi = buf[0], image_lo = buf[1];
3689 else
3690 image_lo = buf[0], image_hi = buf[1];
3691
3692 sign = (image_hi >> 31) & 1;
3693 exp = (image_hi >> 24) & 0x7f;
3694 image_hi &= 0xffffff;
3695 image_lo &= 0xffffffff;
3696
3697 memset (r, 0, sizeof (*r));
3698
3699 if (exp || image_hi || image_lo)
3700 {
3701 r->class = rvc_normal;
3702 r->sign = sign;
3703 r->exp = (exp - 64) * 4 + (SIGNIFICAND_BITS - 56);
3704
3705 if (HOST_BITS_PER_LONG == 32)
3706 {
3707 r->sig[0] = image_lo;
3708 r->sig[1] = image_hi;
3709 }
3710 else
3711 r->sig[0] = image_lo | (image_hi << 31 << 1);
3712
3713 normalize (r);
3714 }
3715 }
3716
3717 const struct real_format i370_single =
3718 {
3719 encode_i370_single,
3720 decode_i370_single,
3721 16,
3722 4,
3723 6,
3724 -64,
3725 63,
3726 false,
3727 false,
3728 false, /* ??? The encoding does allow for "unnormals". */
3729 false, /* ??? The encoding does allow for "unnormals". */
3730 false
3731 };
3732
3733 const struct real_format i370_double =
3734 {
3735 encode_i370_double,
3736 decode_i370_double,
3737 16,
3738 4,
3739 14,
3740 -64,
3741 63,
3742 false,
3743 false,
3744 false, /* ??? The encoding does allow for "unnormals". */
3745 false, /* ??? The encoding does allow for "unnormals". */
3746 false
3747 };
3748
3749 \f
3750 /* TMS320C[34]x twos complement floating point format. */
3751
3752 static void encode_c4x_single PARAMS ((const struct real_format *fmt,
3753 long *, const REAL_VALUE_TYPE *));
3754 static void decode_c4x_single PARAMS ((const struct real_format *,
3755 REAL_VALUE_TYPE *, const long *));
3756 static void encode_c4x_extended PARAMS ((const struct real_format *fmt,
3757 long *, const REAL_VALUE_TYPE *));
3758 static void decode_c4x_extended PARAMS ((const struct real_format *,
3759 REAL_VALUE_TYPE *, const long *));
3760
3761 static void
3762 encode_c4x_single (fmt, buf, r)
3763 const struct real_format *fmt ATTRIBUTE_UNUSED;
3764 long *buf;
3765 const REAL_VALUE_TYPE *r;
3766 {
3767 unsigned long image, exp, sig;
3768
3769 switch (r->class)
3770 {
3771 case rvc_zero:
3772 exp = -128;
3773 sig = 0;
3774 break;
3775
3776 case rvc_inf:
3777 case rvc_nan:
3778 exp = 127;
3779 sig = 0x800000 - r->sign;
3780 break;
3781
3782 case rvc_normal:
3783 exp = r->exp - 1;
3784 sig = (r->sig[SIGSZ-1] >> (HOST_BITS_PER_LONG - 24)) & 0x7fffff;
3785 if (r->sign)
3786 {
3787 if (sig)
3788 sig = -sig;
3789 else
3790 exp--;
3791 sig |= 0x800000;
3792 }
3793 break;
3794
3795 default:
3796 abort ();
3797 }
3798
3799 image = ((exp & 0xff) << 24) | (sig & 0xffffff);
3800 buf[0] = image;
3801 }
3802
3803 static void
3804 decode_c4x_single (fmt, r, buf)
3805 const struct real_format *fmt ATTRIBUTE_UNUSED;
3806 REAL_VALUE_TYPE *r;
3807 const long *buf;
3808 {
3809 unsigned long image = buf[0];
3810 unsigned long sig;
3811 int exp, sf;
3812
3813 exp = (((image >> 24) & 0xff) ^ 0x80) - 0x80;
3814 sf = ((image & 0xffffff) ^ 0x800000) - 0x800000;
3815
3816 memset (r, 0, sizeof (*r));
3817
3818 if (exp != -128)
3819 {
3820 r->class = rvc_normal;
3821
3822 sig = sf & 0x7fffff;
3823 if (sf < 0)
3824 {
3825 r->sign = 1;
3826 if (sig)
3827 sig = -sig;
3828 else
3829 exp++;
3830 }
3831 sig = (sig << (HOST_BITS_PER_LONG - 24)) | SIG_MSB;
3832
3833 r->exp = exp + 1;
3834 r->sig[SIGSZ-1] = sig;
3835 }
3836 }
3837
3838 static void
3839 encode_c4x_extended (fmt, buf, r)
3840 const struct real_format *fmt ATTRIBUTE_UNUSED;
3841 long *buf;
3842 const REAL_VALUE_TYPE *r;
3843 {
3844 unsigned long exp, sig;
3845
3846 switch (r->class)
3847 {
3848 case rvc_zero:
3849 exp = -128;
3850 sig = 0;
3851 break;
3852
3853 case rvc_inf:
3854 case rvc_nan:
3855 exp = 127;
3856 sig = 0x80000000 - r->sign;
3857 break;
3858
3859 case rvc_normal:
3860 exp = r->exp - 1;
3861
3862 sig = r->sig[SIGSZ-1];
3863 if (HOST_BITS_PER_LONG == 64)
3864 sig = sig >> 1 >> 31;
3865 sig &= 0x7fffffff;
3866
3867 if (r->sign)
3868 {
3869 if (sig)
3870 sig = -sig;
3871 else
3872 exp--;
3873 sig |= 0x80000000;
3874 }
3875 break;
3876
3877 default:
3878 abort ();
3879 }
3880
3881 exp = (exp & 0xff) << 24;
3882 sig &= 0xffffffff;
3883
3884 if (FLOAT_WORDS_BIG_ENDIAN)
3885 buf[0] = exp, buf[1] = sig;
3886 else
3887 buf[0] = sig, buf[0] = exp;
3888 }
3889
3890 static void
3891 decode_c4x_extended (fmt, r, buf)
3892 const struct real_format *fmt ATTRIBUTE_UNUSED;
3893 REAL_VALUE_TYPE *r;
3894 const long *buf;
3895 {
3896 unsigned long sig;
3897 int exp, sf;
3898
3899 if (FLOAT_WORDS_BIG_ENDIAN)
3900 exp = buf[0], sf = buf[1];
3901 else
3902 sf = buf[0], exp = buf[1];
3903
3904 exp = (((exp >> 24) & 0xff) & 0x80) - 0x80;
3905 sf = ((sf & 0xffffffff) ^ 0x80000000) - 0x80000000;
3906
3907 memset (r, 0, sizeof (*r));
3908
3909 if (exp != -128)
3910 {
3911 r->class = rvc_normal;
3912
3913 sig = sf & 0x7fffffff;
3914 if (sf < 0)
3915 {
3916 r->sign = 1;
3917 if (sig)
3918 sig = -sig;
3919 else
3920 exp++;
3921 }
3922 if (HOST_BITS_PER_LONG == 64)
3923 sig = sig << 1 << 31;
3924 sig |= SIG_MSB;
3925
3926 r->exp = exp + 1;
3927 r->sig[SIGSZ-1] = sig;
3928 }
3929 }
3930
3931 const struct real_format c4x_single =
3932 {
3933 encode_c4x_single,
3934 decode_c4x_single,
3935 2,
3936 1,
3937 24,
3938 -126,
3939 128,
3940 false,
3941 false,
3942 false,
3943 false,
3944 false
3945 };
3946
3947 const struct real_format c4x_extended =
3948 {
3949 encode_c4x_extended,
3950 decode_c4x_extended,
3951 2,
3952 1,
3953 32,
3954 -126,
3955 128,
3956 false,
3957 false,
3958 false,
3959 false,
3960 false
3961 };
3962
3963 \f
3964 /* Initialize things at start of compilation. */
3965
3966 static const struct real_format * format_for_size PARAMS ((int));
3967
3968 static const struct real_format *
3969 format_for_size (size)
3970 int size;
3971 {
3972 #ifndef TARGET_G_FORMAT
3973 #define TARGET_G_FORMAT 0
3974 #endif
3975
3976 switch (TARGET_FLOAT_FORMAT)
3977 {
3978 case IEEE_FLOAT_FORMAT:
3979 switch (size)
3980 {
3981 case 32:
3982 return &ieee_single;
3983
3984 case 64:
3985 return &ieee_double;
3986
3987 case 96:
3988 if (!INTEL_EXTENDED_IEEE_FORMAT)
3989 return &ieee_extended_motorola;
3990 else
3991 return &ieee_extended_intel_96;
3992
3993 case 128:
3994 if (!INTEL_EXTENDED_IEEE_FORMAT)
3995 return &ieee_quad;
3996 else
3997 return &ieee_extended_intel_128;
3998 }
3999 break;
4000
4001 case VAX_FLOAT_FORMAT:
4002 switch (size)
4003 {
4004 case 32:
4005 return &vax_f_format;
4006
4007 case 64:
4008 if (TARGET_G_FORMAT)
4009 return &vax_g_format;
4010 else
4011 return &vax_d_format;
4012 }
4013 break;
4014
4015 case IBM_FLOAT_FORMAT:
4016 switch (size)
4017 {
4018 case 32:
4019 return &i370_single;
4020 case 64:
4021 return &i370_double;
4022 }
4023 break;
4024
4025 case C4X_FLOAT_FORMAT:
4026 switch (size)
4027 {
4028 case 32:
4029 return &c4x_single;
4030 case 64:
4031 return &c4x_extended;
4032 }
4033 break;
4034 }
4035
4036 abort ();
4037 }
4038
4039 void
4040 init_real_once ()
4041 {
4042 int i;
4043
4044 /* Set up the mode->format table. */
4045 for (i = 0; i < 3; ++i)
4046 {
4047 enum machine_mode mode;
4048 int size;
4049
4050 if (i == 0)
4051 size = FLOAT_TYPE_SIZE;
4052 else if (i == 1)
4053 size = DOUBLE_TYPE_SIZE;
4054 else
4055 size = LONG_DOUBLE_TYPE_SIZE;
4056
4057 mode = mode_for_size (size, MODE_FLOAT, 0);
4058 if (mode == BLKmode)
4059 abort ();
4060
4061 fmt_for_mode[mode - QFmode] = format_for_size (size);
4062 }
4063 }