OSDN Git Service

795e67ad36a91ec0de2e2bc861a9bd1f1aff3af8
[pf3gnuchains/gcc-fork.git] / gcc / config / fp-bit.c
1 /* This is a software floating point library which can be used
2    for targets without hardware floating point. 
3    Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003,
4    2004, 2005 Free Software Foundation, Inc.
5
6 This file is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file with other programs, and to distribute
14 those programs without any restriction coming from the use of this
15 file.  (The General Public License restrictions do apply in other
16 respects; for example, they cover modification of the file, and
17 distribution when not linked into another program.)
18
19 This file is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; see the file COPYING.  If not, write to
26 the Free Software Foundation, 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.  */
28
29 /* As a special exception, if you link this library with other files,
30    some of which are compiled with GCC, to produce an executable,
31    this library does not by itself cause the resulting executable
32    to be covered by the GNU General Public License.
33    This exception does not however invalidate any other reasons why
34    the executable file might be covered by the GNU General Public License.  */
35
36 /* This implements IEEE 754 format arithmetic, but does not provide a
37    mechanism for setting the rounding mode, or for generating or handling
38    exceptions.
39
40    The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
41    Wilson, all of Cygnus Support.  */
42
43 /* The intended way to use this file is to make two copies, add `#define FLOAT'
44    to one copy, then compile both copies and add them to libgcc.a.  */
45
46 #include "tconfig.h"
47 #include "coretypes.h"
48 #include "tm.h"
49 #include "config/fp-bit.h"
50
51 /* The following macros can be defined to change the behavior of this file:
52    FLOAT: Implement a `float', aka SFmode, fp library.  If this is not
53      defined, then this file implements a `double', aka DFmode, fp library.
54    FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
55      don't include float->double conversion which requires the double library.
56      This is useful only for machines which can't support doubles, e.g. some
57      8-bit processors.
58    CMPtype: Specify the type that floating point compares should return.
59      This defaults to SItype, aka int.
60    US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
61      US Software goFast library.
62    _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
63      two integers to the FLO_union_type.
64    NO_DENORMALS: Disable handling of denormals.
65    NO_NANS: Disable nan and infinity handling
66    SMALL_MACHINE: Useful when operations on QIs and HIs are faster
67      than on an SI */
68
69 /* We don't currently support extended floats (long doubles) on machines
70    without hardware to deal with them.
71
72    These stubs are just to keep the linker from complaining about unresolved
73    references which can be pulled in from libio & libstdc++, even if the
74    user isn't using long doubles.  However, they may generate an unresolved
75    external to abort if abort is not used by the function, and the stubs
76    are referenced from within libc, since libgcc goes before and after the
77    system library.  */
78
79 #ifdef DECLARE_LIBRARY_RENAMES
80   DECLARE_LIBRARY_RENAMES
81 #endif
82
83 #ifdef EXTENDED_FLOAT_STUBS
84 extern void abort (void);
85 void __extendsfxf2 (void) { abort(); }
86 void __extenddfxf2 (void) { abort(); }
87 void __truncxfdf2 (void) { abort(); }
88 void __truncxfsf2 (void) { abort(); }
89 void __fixxfsi (void) { abort(); }
90 void __floatsixf (void) { abort(); }
91 void __addxf3 (void) { abort(); }
92 void __subxf3 (void) { abort(); }
93 void __mulxf3 (void) { abort(); }
94 void __divxf3 (void) { abort(); }
95 void __negxf2 (void) { abort(); }
96 void __eqxf2 (void) { abort(); }
97 void __nexf2 (void) { abort(); }
98 void __gtxf2 (void) { abort(); }
99 void __gexf2 (void) { abort(); }
100 void __lexf2 (void) { abort(); }
101 void __ltxf2 (void) { abort(); }
102
103 void __extendsftf2 (void) { abort(); }
104 void __extenddftf2 (void) { abort(); }
105 void __trunctfdf2 (void) { abort(); }
106 void __trunctfsf2 (void) { abort(); }
107 void __fixtfsi (void) { abort(); }
108 void __floatsitf (void) { abort(); }
109 void __addtf3 (void) { abort(); }
110 void __subtf3 (void) { abort(); }
111 void __multf3 (void) { abort(); }
112 void __divtf3 (void) { abort(); }
113 void __negtf2 (void) { abort(); }
114 void __eqtf2 (void) { abort(); }
115 void __netf2 (void) { abort(); }
116 void __gttf2 (void) { abort(); }
117 void __getf2 (void) { abort(); }
118 void __letf2 (void) { abort(); }
119 void __lttf2 (void) { abort(); }
120 #else   /* !EXTENDED_FLOAT_STUBS, rest of file */
121
122 /* IEEE "special" number predicates */
123
124 #ifdef NO_NANS
125
126 #define nan() 0
127 #define isnan(x) 0
128 #define isinf(x) 0
129 #else
130
131 #if   defined L_thenan_sf
132 const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
133 #elif defined L_thenan_df
134 const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
135 #elif defined L_thenan_tf
136 const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
137 #elif defined TFLOAT
138 extern const fp_number_type __thenan_tf;
139 #elif defined FLOAT
140 extern const fp_number_type __thenan_sf;
141 #else
142 extern const fp_number_type __thenan_df;
143 #endif
144
145 INLINE
146 static fp_number_type *
147 nan (void)
148 {
149   /* Discard the const qualifier...  */
150 #ifdef TFLOAT
151   return (fp_number_type *) (& __thenan_tf);
152 #elif defined FLOAT  
153   return (fp_number_type *) (& __thenan_sf);
154 #else
155   return (fp_number_type *) (& __thenan_df);
156 #endif
157 }
158
159 INLINE
160 static int
161 isnan ( fp_number_type *  x)
162 {
163   return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
164 }
165
166 INLINE
167 static int
168 isinf ( fp_number_type *  x)
169 {
170   return x->class == CLASS_INFINITY;
171 }
172
173 #endif /* NO_NANS */
174
175 INLINE
176 static int
177 iszero ( fp_number_type *  x)
178 {
179   return x->class == CLASS_ZERO;
180 }
181
182 INLINE 
183 static void
184 flip_sign ( fp_number_type *  x)
185 {
186   x->sign = !x->sign;
187 }
188
189 extern FLO_type pack_d ( fp_number_type * );
190
191 #if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
192 FLO_type
193 pack_d ( fp_number_type *  src)
194 {
195   FLO_union_type dst;
196   fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
197   int sign = src->sign;
198   int exp = 0;
199
200   if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
201     {
202       /* We can't represent these values accurately.  By using the
203          largest possible magnitude, we guarantee that the conversion
204          of infinity is at least as big as any finite number.  */
205       exp = EXPMAX;
206       fraction = ((fractype) 1 << FRACBITS) - 1;
207     }
208   else if (isnan (src))
209     {
210       exp = EXPMAX;
211       if (src->class == CLASS_QNAN || 1)
212         {
213 #ifdef QUIET_NAN_NEGATED
214           fraction |= QUIET_NAN - 1;
215 #else
216           fraction |= QUIET_NAN;
217 #endif
218         }
219     }
220   else if (isinf (src))
221     {
222       exp = EXPMAX;
223       fraction = 0;
224     }
225   else if (iszero (src))
226     {
227       exp = 0;
228       fraction = 0;
229     }
230   else if (fraction == 0)
231     {
232       exp = 0;
233     }
234   else
235     {
236       if (src->normal_exp < NORMAL_EXPMIN)
237         {
238 #ifdef NO_DENORMALS
239           /* Go straight to a zero representation if denormals are not
240              supported.  The denormal handling would be harmless but
241              isn't unnecessary.  */
242           exp = 0;
243           fraction = 0;
244 #else /* NO_DENORMALS */
245           /* This number's exponent is too low to fit into the bits
246              available in the number, so we'll store 0 in the exponent and
247              shift the fraction to the right to make up for it.  */
248
249           int shift = NORMAL_EXPMIN - src->normal_exp;
250
251           exp = 0;
252
253           if (shift > FRAC_NBITS - NGARDS)
254             {
255               /* No point shifting, since it's more that 64 out.  */
256               fraction = 0;
257             }
258           else
259             {
260               int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
261               fraction = (fraction >> shift) | lowbit;
262             }
263           if ((fraction & GARDMASK) == GARDMSB)
264             {
265               if ((fraction & (1 << NGARDS)))
266                 fraction += GARDROUND + 1;
267             }
268           else
269             {
270               /* Add to the guards to round up.  */
271               fraction += GARDROUND;
272             }
273           /* Perhaps the rounding means we now need to change the
274              exponent, because the fraction is no longer denormal.  */
275           if (fraction >= IMPLICIT_1)
276             {
277               exp += 1;
278             }
279           fraction >>= NGARDS;
280 #endif /* NO_DENORMALS */
281         }
282       else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
283                && src->normal_exp > EXPBIAS)
284         {
285           exp = EXPMAX;
286           fraction = 0;
287         }
288       else
289         {
290           exp = src->normal_exp + EXPBIAS;
291           if (!ROUND_TOWARDS_ZERO)
292             {
293               /* IF the gard bits are the all zero, but the first, then we're
294                  half way between two numbers, choose the one which makes the
295                  lsb of the answer 0.  */
296               if ((fraction & GARDMASK) == GARDMSB)
297                 {
298                   if (fraction & (1 << NGARDS))
299                     fraction += GARDROUND + 1;
300                 }
301               else
302                 {
303                   /* Add a one to the guards to round up */
304                   fraction += GARDROUND;
305                 }
306               if (fraction >= IMPLICIT_2)
307                 {
308                   fraction >>= 1;
309                   exp += 1;
310                 }
311             }
312           fraction >>= NGARDS;
313
314           if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
315             {
316               /* Saturate on overflow.  */
317               exp = EXPMAX;
318               fraction = ((fractype) 1 << FRACBITS) - 1;
319             }
320         }
321     }
322
323   /* We previously used bitfields to store the number, but this doesn't
324      handle little/big endian systems conveniently, so use shifts and
325      masks */
326 #ifdef FLOAT_BIT_ORDER_MISMATCH
327   dst.bits.fraction = fraction;
328   dst.bits.exp = exp;
329   dst.bits.sign = sign;
330 #else
331 # if defined TFLOAT && defined HALFFRACBITS
332  {
333    halffractype high, low, unity;
334    int lowsign, lowexp;
335
336    unity = (halffractype) 1 << HALFFRACBITS;
337
338    /* Set HIGH to the high double's significand, masking out the implicit 1.
339       Set LOW to the low double's full significand.  */
340    high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
341    low = fraction & (unity * 2 - 1);
342
343    /* Get the initial sign and exponent of the low double.  */
344    lowexp = exp - HALFFRACBITS - 1;
345    lowsign = sign;
346
347    /* HIGH should be rounded like a normal double, making |LOW| <=
348       0.5 ULP of HIGH.  Assume round-to-nearest.  */
349    if (exp < EXPMAX)
350      if (low > unity || (low == unity && (high & 1) == 1))
351        {
352          /* Round HIGH up and adjust LOW to match.  */
353          high++;
354          if (high == unity)
355            {
356              /* May make it infinite, but that's OK.  */
357              high = 0;
358              exp++;
359            }
360          low = unity * 2 - low;
361          lowsign ^= 1;
362        }
363
364    high |= (halffractype) exp << HALFFRACBITS;
365    high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
366
367    if (exp == EXPMAX || exp == 0 || low == 0)
368      low = 0;
369    else
370      {
371        while (lowexp > 0 && low < unity)
372          {
373            low <<= 1;
374            lowexp--;
375          }
376
377        if (lowexp <= 0)
378          {
379            halffractype roundmsb, round;
380            int shift;
381
382            shift = 1 - lowexp;
383            roundmsb = (1 << (shift - 1));
384            round = low & ((roundmsb << 1) - 1);
385
386            low >>= shift;
387            lowexp = 0;
388
389            if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
390              {
391                low++;
392                if (low == unity)
393                  /* LOW rounds up to the smallest normal number.  */
394                  lowexp++;
395              }
396          }
397
398        low &= unity - 1;
399        low |= (halffractype) lowexp << HALFFRACBITS;
400        low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
401      }
402    dst.value_raw = ((fractype) high << HALFSHIFT) | low;
403  }
404 # else
405   dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
406   dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
407   dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
408 # endif
409 #endif
410
411 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
412 #ifdef TFLOAT
413   {
414     qrtrfractype tmp1 = dst.words[0];
415     qrtrfractype tmp2 = dst.words[1];
416     dst.words[0] = dst.words[3];
417     dst.words[1] = dst.words[2];
418     dst.words[2] = tmp2;
419     dst.words[3] = tmp1;
420   }
421 #else
422   {
423     halffractype tmp = dst.words[0];
424     dst.words[0] = dst.words[1];
425     dst.words[1] = tmp;
426   }
427 #endif
428 #endif
429
430   return dst.value;
431 }
432 #endif
433
434 #if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
435 void
436 unpack_d (FLO_union_type * src, fp_number_type * dst)
437 {
438   /* We previously used bitfields to store the number, but this doesn't
439      handle little/big endian systems conveniently, so use shifts and
440      masks */
441   fractype fraction;
442   int exp;
443   int sign;
444
445 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
446   FLO_union_type swapped;
447
448 #ifdef TFLOAT
449   swapped.words[0] = src->words[3];
450   swapped.words[1] = src->words[2];
451   swapped.words[2] = src->words[1];
452   swapped.words[3] = src->words[0];
453 #else
454   swapped.words[0] = src->words[1];
455   swapped.words[1] = src->words[0];
456 #endif
457   src = &swapped;
458 #endif
459   
460 #ifdef FLOAT_BIT_ORDER_MISMATCH
461   fraction = src->bits.fraction;
462   exp = src->bits.exp;
463   sign = src->bits.sign;
464 #else
465 # if defined TFLOAT && defined HALFFRACBITS
466  {
467    halffractype high, low;
468    
469    high = src->value_raw >> HALFSHIFT;
470    low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
471
472    fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
473    fraction <<= FRACBITS - HALFFRACBITS;
474    exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
475    sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
476
477    if (exp != EXPMAX && exp != 0 && low != 0)
478      {
479        int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
480        int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
481        int shift;
482        fractype xlow;
483
484        xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
485        if (lowexp)
486          xlow |= (((halffractype)1) << HALFFRACBITS);
487        else
488          lowexp = 1;
489        shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
490        if (shift > 0)
491          xlow <<= shift;
492        else if (shift < 0)
493          xlow >>= -shift;
494        if (sign == lowsign)
495          fraction += xlow;
496        else if (fraction >= xlow)
497          fraction -= xlow;
498        else
499          {
500            /* The high part is a power of two but the full number is lower.
501               This code will leave the implicit 1 in FRACTION, but we'd
502               have added that below anyway.  */
503            fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
504            exp--;
505          }
506      }
507  }
508 # else
509   fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
510   exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
511   sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
512 # endif
513 #endif
514
515   dst->sign = sign;
516   if (exp == 0)
517     {
518       /* Hmm.  Looks like 0 */
519       if (fraction == 0
520 #ifdef NO_DENORMALS
521           || 1
522 #endif
523           )
524         {
525           /* tastes like zero */
526           dst->class = CLASS_ZERO;
527         }
528       else
529         {
530           /* Zero exponent with nonzero fraction - it's denormalized,
531              so there isn't a leading implicit one - we'll shift it so
532              it gets one.  */
533           dst->normal_exp = exp - EXPBIAS + 1;
534           fraction <<= NGARDS;
535
536           dst->class = CLASS_NUMBER;
537 #if 1
538           while (fraction < IMPLICIT_1)
539             {
540               fraction <<= 1;
541               dst->normal_exp--;
542             }
543 #endif
544           dst->fraction.ll = fraction;
545         }
546     }
547   else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
548     {
549       /* Huge exponent*/
550       if (fraction == 0)
551         {
552           /* Attached to a zero fraction - means infinity */
553           dst->class = CLASS_INFINITY;
554         }
555       else
556         {
557           /* Nonzero fraction, means nan */
558 #ifdef QUIET_NAN_NEGATED
559           if ((fraction & QUIET_NAN) == 0)
560 #else
561           if (fraction & QUIET_NAN)
562 #endif
563             {
564               dst->class = CLASS_QNAN;
565             }
566           else
567             {
568               dst->class = CLASS_SNAN;
569             }
570           /* Keep the fraction part as the nan number */
571           dst->fraction.ll = fraction;
572         }
573     }
574   else
575     {
576       /* Nothing strange about this number */
577       dst->normal_exp = exp - EXPBIAS;
578       dst->class = CLASS_NUMBER;
579       dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
580     }
581 }
582 #endif /* L_unpack_df || L_unpack_sf */
583
584 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
585 static fp_number_type *
586 _fpadd_parts (fp_number_type * a,
587               fp_number_type * b,
588               fp_number_type * tmp)
589 {
590   intfrac tfraction;
591
592   /* Put commonly used fields in local variables.  */
593   int a_normal_exp;
594   int b_normal_exp;
595   fractype a_fraction;
596   fractype b_fraction;
597
598   if (isnan (a))
599     {
600       return a;
601     }
602   if (isnan (b))
603     {
604       return b;
605     }
606   if (isinf (a))
607     {
608       /* Adding infinities with opposite signs yields a NaN.  */
609       if (isinf (b) && a->sign != b->sign)
610         return nan ();
611       return a;
612     }
613   if (isinf (b))
614     {
615       return b;
616     }
617   if (iszero (b))
618     {
619       if (iszero (a))
620         {
621           *tmp = *a;
622           tmp->sign = a->sign & b->sign;
623           return tmp;
624         }
625       return a;
626     }
627   if (iszero (a))
628     {
629       return b;
630     }
631
632   /* Got two numbers. shift the smaller and increment the exponent till
633      they're the same */
634   {
635     int diff;
636
637     a_normal_exp = a->normal_exp;
638     b_normal_exp = b->normal_exp;
639     a_fraction = a->fraction.ll;
640     b_fraction = b->fraction.ll;
641
642     diff = a_normal_exp - b_normal_exp;
643
644     if (diff < 0)
645       diff = -diff;
646     if (diff < FRAC_NBITS)
647       {
648         /* ??? This does shifts one bit at a time.  Optimize.  */
649         while (a_normal_exp > b_normal_exp)
650           {
651             b_normal_exp++;
652             LSHIFT (b_fraction);
653           }
654         while (b_normal_exp > a_normal_exp)
655           {
656             a_normal_exp++;
657             LSHIFT (a_fraction);
658           }
659       }
660     else
661       {
662         /* Somethings's up.. choose the biggest */
663         if (a_normal_exp > b_normal_exp)
664           {
665             b_normal_exp = a_normal_exp;
666             b_fraction = 0;
667           }
668         else
669           {
670             a_normal_exp = b_normal_exp;
671             a_fraction = 0;
672           }
673       }
674   }
675
676   if (a->sign != b->sign)
677     {
678       if (a->sign)
679         {
680           tfraction = -a_fraction + b_fraction;
681         }
682       else
683         {
684           tfraction = a_fraction - b_fraction;
685         }
686       if (tfraction >= 0)
687         {
688           tmp->sign = 0;
689           tmp->normal_exp = a_normal_exp;
690           tmp->fraction.ll = tfraction;
691         }
692       else
693         {
694           tmp->sign = 1;
695           tmp->normal_exp = a_normal_exp;
696           tmp->fraction.ll = -tfraction;
697         }
698       /* and renormalize it */
699
700       while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
701         {
702           tmp->fraction.ll <<= 1;
703           tmp->normal_exp--;
704         }
705     }
706   else
707     {
708       tmp->sign = a->sign;
709       tmp->normal_exp = a_normal_exp;
710       tmp->fraction.ll = a_fraction + b_fraction;
711     }
712   tmp->class = CLASS_NUMBER;
713   /* Now the fraction is added, we have to shift down to renormalize the
714      number */
715
716   if (tmp->fraction.ll >= IMPLICIT_2)
717     {
718       LSHIFT (tmp->fraction.ll);
719       tmp->normal_exp++;
720     }
721   return tmp;
722
723 }
724
725 FLO_type
726 add (FLO_type arg_a, FLO_type arg_b)
727 {
728   fp_number_type a;
729   fp_number_type b;
730   fp_number_type tmp;
731   fp_number_type *res;
732   FLO_union_type au, bu;
733
734   au.value = arg_a;
735   bu.value = arg_b;
736
737   unpack_d (&au, &a);
738   unpack_d (&bu, &b);
739
740   res = _fpadd_parts (&a, &b, &tmp);
741
742   return pack_d (res);
743 }
744
745 FLO_type
746 sub (FLO_type arg_a, FLO_type arg_b)
747 {
748   fp_number_type a;
749   fp_number_type b;
750   fp_number_type tmp;
751   fp_number_type *res;
752   FLO_union_type au, bu;
753
754   au.value = arg_a;
755   bu.value = arg_b;
756
757   unpack_d (&au, &a);
758   unpack_d (&bu, &b);
759
760   b.sign ^= 1;
761
762   res = _fpadd_parts (&a, &b, &tmp);
763
764   return pack_d (res);
765 }
766 #endif /* L_addsub_sf || L_addsub_df */
767
768 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
769 static inline __attribute__ ((__always_inline__)) fp_number_type *
770 _fpmul_parts ( fp_number_type *  a,
771                fp_number_type *  b,
772                fp_number_type * tmp)
773 {
774   fractype low = 0;
775   fractype high = 0;
776
777   if (isnan (a))
778     {
779       a->sign = a->sign != b->sign;
780       return a;
781     }
782   if (isnan (b))
783     {
784       b->sign = a->sign != b->sign;
785       return b;
786     }
787   if (isinf (a))
788     {
789       if (iszero (b))
790         return nan ();
791       a->sign = a->sign != b->sign;
792       return a;
793     }
794   if (isinf (b))
795     {
796       if (iszero (a))
797         {
798           return nan ();
799         }
800       b->sign = a->sign != b->sign;
801       return b;
802     }
803   if (iszero (a))
804     {
805       a->sign = a->sign != b->sign;
806       return a;
807     }
808   if (iszero (b))
809     {
810       b->sign = a->sign != b->sign;
811       return b;
812     }
813
814   /* Calculate the mantissa by multiplying both numbers to get a
815      twice-as-wide number.  */
816   {
817 #if defined(NO_DI_MODE) || defined(TFLOAT)
818     {
819       fractype x = a->fraction.ll;
820       fractype ylow = b->fraction.ll;
821       fractype yhigh = 0;
822       int bit;
823
824       /* ??? This does multiplies one bit at a time.  Optimize.  */
825       for (bit = 0; bit < FRAC_NBITS; bit++)
826         {
827           int carry;
828
829           if (x & 1)
830             {
831               carry = (low += ylow) < ylow;
832               high += yhigh + carry;
833             }
834           yhigh <<= 1;
835           if (ylow & FRACHIGH)
836             {
837               yhigh |= 1;
838             }
839           ylow <<= 1;
840           x >>= 1;
841         }
842     }
843 #elif defined(FLOAT) 
844     /* Multiplying two USIs to get a UDI, we're safe.  */
845     {
846       UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
847       
848       high = answer >> BITS_PER_SI;
849       low = answer;
850     }
851 #else
852     /* fractype is DImode, but we need the result to be twice as wide.
853        Assuming a widening multiply from DImode to TImode is not
854        available, build one by hand.  */
855     {
856       USItype nl = a->fraction.ll;
857       USItype nh = a->fraction.ll >> BITS_PER_SI;
858       USItype ml = b->fraction.ll;
859       USItype mh = b->fraction.ll >> BITS_PER_SI;
860       UDItype pp_ll = (UDItype) ml * nl;
861       UDItype pp_hl = (UDItype) mh * nl;
862       UDItype pp_lh = (UDItype) ml * nh;
863       UDItype pp_hh = (UDItype) mh * nh;
864       UDItype res2 = 0;
865       UDItype res0 = 0;
866       UDItype ps_hh__ = pp_hl + pp_lh;
867       if (ps_hh__ < pp_hl)
868         res2 += (UDItype)1 << BITS_PER_SI;
869       pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
870       res0 = pp_ll + pp_hl;
871       if (res0 < pp_ll)
872         res2++;
873       res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
874       high = res2;
875       low = res0;
876     }
877 #endif
878   }
879
880   tmp->normal_exp = a->normal_exp + b->normal_exp
881     + FRAC_NBITS - (FRACBITS + NGARDS);
882   tmp->sign = a->sign != b->sign;
883   while (high >= IMPLICIT_2)
884     {
885       tmp->normal_exp++;
886       if (high & 1)
887         {
888           low >>= 1;
889           low |= FRACHIGH;
890         }
891       high >>= 1;
892     }
893   while (high < IMPLICIT_1)
894     {
895       tmp->normal_exp--;
896
897       high <<= 1;
898       if (low & FRACHIGH)
899         high |= 1;
900       low <<= 1;
901     }
902
903   if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
904     {
905       if (high & (1 << NGARDS))
906         {
907           /* Because we're half way, we would round to even by adding
908              GARDROUND + 1, except that's also done in the packing
909              function, and rounding twice will lose precision and cause
910              the result to be too far off.  Example: 32-bit floats with
911              bit patterns 0xfff * 0x3f800400 ~= 0xfff (less than 0.5ulp
912              off), not 0x1000 (more than 0.5ulp off).  */
913         }
914       else if (low)
915         {
916           /* We're a further than half way by a small amount corresponding
917              to the bits set in "low".  Knowing that, we round here and
918              not in pack_d, because there we don't have "low" available
919              anymore.  */
920           high += GARDROUND + 1;
921
922           /* Avoid further rounding in pack_d.  */
923           high &= ~(fractype) GARDMASK;
924         }
925     }
926   tmp->fraction.ll = high;
927   tmp->class = CLASS_NUMBER;
928   return tmp;
929 }
930
931 FLO_type
932 multiply (FLO_type arg_a, FLO_type arg_b)
933 {
934   fp_number_type a;
935   fp_number_type b;
936   fp_number_type tmp;
937   fp_number_type *res;
938   FLO_union_type au, bu;
939
940   au.value = arg_a;
941   bu.value = arg_b;
942
943   unpack_d (&au, &a);
944   unpack_d (&bu, &b);
945
946   res = _fpmul_parts (&a, &b, &tmp);
947
948   return pack_d (res);
949 }
950 #endif /* L_mul_sf || L_mul_df || L_mul_tf */
951
952 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
953 static inline __attribute__ ((__always_inline__)) fp_number_type *
954 _fpdiv_parts (fp_number_type * a,
955               fp_number_type * b)
956 {
957   fractype bit;
958   fractype numerator;
959   fractype denominator;
960   fractype quotient;
961
962   if (isnan (a))
963     {
964       return a;
965     }
966   if (isnan (b))
967     {
968       return b;
969     }
970
971   a->sign = a->sign ^ b->sign;
972
973   if (isinf (a) || iszero (a))
974     {
975       if (a->class == b->class)
976         return nan ();
977       return a;
978     }
979
980   if (isinf (b))
981     {
982       a->fraction.ll = 0;
983       a->normal_exp = 0;
984       return a;
985     }
986   if (iszero (b))
987     {
988       a->class = CLASS_INFINITY;
989       return a;
990     }
991
992   /* Calculate the mantissa by multiplying both 64bit numbers to get a
993      128 bit number */
994   {
995     /* quotient =
996        ( numerator / denominator) * 2^(numerator exponent -  denominator exponent)
997      */
998
999     a->normal_exp = a->normal_exp - b->normal_exp;
1000     numerator = a->fraction.ll;
1001     denominator = b->fraction.ll;
1002
1003     if (numerator < denominator)
1004       {
1005         /* Fraction will be less than 1.0 */
1006         numerator *= 2;
1007         a->normal_exp--;
1008       }
1009     bit = IMPLICIT_1;
1010     quotient = 0;
1011     /* ??? Does divide one bit at a time.  Optimize.  */
1012     while (bit)
1013       {
1014         if (numerator >= denominator)
1015           {
1016             quotient |= bit;
1017             numerator -= denominator;
1018           }
1019         bit >>= 1;
1020         numerator *= 2;
1021       }
1022
1023     if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
1024       {
1025         if (quotient & (1 << NGARDS))
1026           {
1027             /* Because we're half way, we would round to even by adding
1028                GARDROUND + 1, except that's also done in the packing
1029                function, and rounding twice will lose precision and cause
1030                the result to be too far off.  */
1031           }
1032         else if (numerator)
1033           {
1034             /* We're a further than half way by the small amount
1035                corresponding to the bits set in "numerator".  Knowing
1036                that, we round here and not in pack_d, because there we
1037                don't have "numerator" available anymore.  */
1038             quotient += GARDROUND + 1;
1039
1040             /* Avoid further rounding in pack_d.  */
1041             quotient &= ~(fractype) GARDMASK;
1042           }
1043       }
1044
1045     a->fraction.ll = quotient;
1046     return (a);
1047   }
1048 }
1049
1050 FLO_type
1051 divide (FLO_type arg_a, FLO_type arg_b)
1052 {
1053   fp_number_type a;
1054   fp_number_type b;
1055   fp_number_type *res;
1056   FLO_union_type au, bu;
1057
1058   au.value = arg_a;
1059   bu.value = arg_b;
1060
1061   unpack_d (&au, &a);
1062   unpack_d (&bu, &b);
1063
1064   res = _fpdiv_parts (&a, &b);
1065
1066   return pack_d (res);
1067 }
1068 #endif /* L_div_sf || L_div_df */
1069
1070 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
1071     || defined(L_fpcmp_parts_tf)
1072 /* according to the demo, fpcmp returns a comparison with 0... thus
1073    a<b -> -1
1074    a==b -> 0
1075    a>b -> +1
1076  */
1077
1078 int
1079 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1080 {
1081 #if 0
1082   /* either nan -> unordered. Must be checked outside of this routine.  */
1083   if (isnan (a) && isnan (b))
1084     {
1085       return 1;                 /* still unordered! */
1086     }
1087 #endif
1088
1089   if (isnan (a) || isnan (b))
1090     {
1091       return 1;                 /* how to indicate unordered compare? */
1092     }
1093   if (isinf (a) && isinf (b))
1094     {
1095       /* +inf > -inf, but +inf != +inf */
1096       /* b    \a| +inf(0)| -inf(1)
1097        ______\+--------+--------
1098        +inf(0)| a==b(0)| a<b(-1)
1099        -------+--------+--------
1100        -inf(1)| a>b(1) | a==b(0)
1101        -------+--------+--------
1102        So since unordered must be nonzero, just line up the columns...
1103        */
1104       return b->sign - a->sign;
1105     }
1106   /* but not both...  */
1107   if (isinf (a))
1108     {
1109       return a->sign ? -1 : 1;
1110     }
1111   if (isinf (b))
1112     {
1113       return b->sign ? 1 : -1;
1114     }
1115   if (iszero (a) && iszero (b))
1116     {
1117       return 0;
1118     }
1119   if (iszero (a))
1120     {
1121       return b->sign ? 1 : -1;
1122     }
1123   if (iszero (b))
1124     {
1125       return a->sign ? -1 : 1;
1126     }
1127   /* now both are "normal".  */
1128   if (a->sign != b->sign)
1129     {
1130       /* opposite signs */
1131       return a->sign ? -1 : 1;
1132     }
1133   /* same sign; exponents? */
1134   if (a->normal_exp > b->normal_exp)
1135     {
1136       return a->sign ? -1 : 1;
1137     }
1138   if (a->normal_exp < b->normal_exp)
1139     {
1140       return a->sign ? 1 : -1;
1141     }
1142   /* same exponents; check size.  */
1143   if (a->fraction.ll > b->fraction.ll)
1144     {
1145       return a->sign ? -1 : 1;
1146     }
1147   if (a->fraction.ll < b->fraction.ll)
1148     {
1149       return a->sign ? 1 : -1;
1150     }
1151   /* after all that, they're equal.  */
1152   return 0;
1153 }
1154 #endif
1155
1156 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
1157 CMPtype
1158 compare (FLO_type arg_a, FLO_type arg_b)
1159 {
1160   fp_number_type a;
1161   fp_number_type b;
1162   FLO_union_type au, bu;
1163
1164   au.value = arg_a;
1165   bu.value = arg_b;
1166
1167   unpack_d (&au, &a);
1168   unpack_d (&bu, &b);
1169
1170   return __fpcmp_parts (&a, &b);
1171 }
1172 #endif /* L_compare_sf || L_compare_df */
1173
1174 #ifndef US_SOFTWARE_GOFAST
1175
1176 /* These should be optimized for their specific tasks someday.  */
1177
1178 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
1179 CMPtype
1180 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1181 {
1182   fp_number_type a;
1183   fp_number_type b;
1184   FLO_union_type au, bu;
1185
1186   au.value = arg_a;
1187   bu.value = arg_b;
1188
1189   unpack_d (&au, &a);
1190   unpack_d (&bu, &b);
1191
1192   if (isnan (&a) || isnan (&b))
1193     return 1;                   /* false, truth == 0 */
1194
1195   return __fpcmp_parts (&a, &b) ;
1196 }
1197 #endif /* L_eq_sf || L_eq_df */
1198
1199 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
1200 CMPtype
1201 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1202 {
1203   fp_number_type a;
1204   fp_number_type b;
1205   FLO_union_type au, bu;
1206
1207   au.value = arg_a;
1208   bu.value = arg_b;
1209
1210   unpack_d (&au, &a);
1211   unpack_d (&bu, &b);
1212
1213   if (isnan (&a) || isnan (&b))
1214     return 1;                   /* true, truth != 0 */
1215
1216   return  __fpcmp_parts (&a, &b) ;
1217 }
1218 #endif /* L_ne_sf || L_ne_df */
1219
1220 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
1221 CMPtype
1222 _gt_f2 (FLO_type arg_a, FLO_type arg_b)
1223 {
1224   fp_number_type a;
1225   fp_number_type b;
1226   FLO_union_type au, bu;
1227
1228   au.value = arg_a;
1229   bu.value = arg_b;
1230
1231   unpack_d (&au, &a);
1232   unpack_d (&bu, &b);
1233
1234   if (isnan (&a) || isnan (&b))
1235     return -1;                  /* false, truth > 0 */
1236
1237   return __fpcmp_parts (&a, &b);
1238 }
1239 #endif /* L_gt_sf || L_gt_df */
1240
1241 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
1242 CMPtype
1243 _ge_f2 (FLO_type arg_a, FLO_type arg_b)
1244 {
1245   fp_number_type a;
1246   fp_number_type b;
1247   FLO_union_type au, bu;
1248
1249   au.value = arg_a;
1250   bu.value = arg_b;
1251
1252   unpack_d (&au, &a);
1253   unpack_d (&bu, &b);
1254
1255   if (isnan (&a) || isnan (&b))
1256     return -1;                  /* false, truth >= 0 */
1257   return __fpcmp_parts (&a, &b) ;
1258 }
1259 #endif /* L_ge_sf || L_ge_df */
1260
1261 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
1262 CMPtype
1263 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1264 {
1265   fp_number_type a;
1266   fp_number_type b;
1267   FLO_union_type au, bu;
1268
1269   au.value = arg_a;
1270   bu.value = arg_b;
1271
1272   unpack_d (&au, &a);
1273   unpack_d (&bu, &b);
1274
1275   if (isnan (&a) || isnan (&b))
1276     return 1;                   /* false, truth < 0 */
1277
1278   return __fpcmp_parts (&a, &b);
1279 }
1280 #endif /* L_lt_sf || L_lt_df */
1281
1282 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
1283 CMPtype
1284 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1285 {
1286   fp_number_type a;
1287   fp_number_type b;
1288   FLO_union_type au, bu;
1289
1290   au.value = arg_a;
1291   bu.value = arg_b;
1292
1293   unpack_d (&au, &a);
1294   unpack_d (&bu, &b);
1295
1296   if (isnan (&a) || isnan (&b))
1297     return 1;                   /* false, truth <= 0 */
1298
1299   return __fpcmp_parts (&a, &b) ;
1300 }
1301 #endif /* L_le_sf || L_le_df */
1302
1303 #endif /* ! US_SOFTWARE_GOFAST */
1304
1305 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
1306 CMPtype
1307 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1308 {
1309   fp_number_type a;
1310   fp_number_type b;
1311   FLO_union_type au, bu;
1312
1313   au.value = arg_a;
1314   bu.value = arg_b;
1315
1316   unpack_d (&au, &a);
1317   unpack_d (&bu, &b);
1318
1319   return (isnan (&a) || isnan (&b));
1320 }
1321 #endif /* L_unord_sf || L_unord_df */
1322
1323 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
1324 FLO_type
1325 si_to_float (SItype arg_a)
1326 {
1327   fp_number_type in;
1328
1329   in.class = CLASS_NUMBER;
1330   in.sign = arg_a < 0;
1331   if (!arg_a)
1332     {
1333       in.class = CLASS_ZERO;
1334     }
1335   else
1336     {
1337       in.normal_exp = FRACBITS + NGARDS;
1338       if (in.sign) 
1339         {
1340           /* Special case for minint, since there is no +ve integer
1341              representation for it */
1342           if (arg_a == (- MAX_SI_INT - 1))
1343             {
1344               return (FLO_type)(- MAX_SI_INT - 1);
1345             }
1346           in.fraction.ll = (-arg_a);
1347         }
1348       else
1349         in.fraction.ll = arg_a;
1350
1351       while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1352         {
1353           in.fraction.ll <<= 1;
1354           in.normal_exp -= 1;
1355         }
1356     }
1357   return pack_d (&in);
1358 }
1359 #endif /* L_si_to_sf || L_si_to_df */
1360
1361 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
1362 FLO_type
1363 usi_to_float (USItype arg_a)
1364 {
1365   fp_number_type in;
1366
1367   in.sign = 0;
1368   if (!arg_a)
1369     {
1370       in.class = CLASS_ZERO;
1371     }
1372   else
1373     {
1374       in.class = CLASS_NUMBER;
1375       in.normal_exp = FRACBITS + NGARDS;
1376       in.fraction.ll = arg_a;
1377
1378       while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
1379         {
1380           in.fraction.ll >>= 1;
1381           in.normal_exp += 1;
1382         }
1383       while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1384         {
1385           in.fraction.ll <<= 1;
1386           in.normal_exp -= 1;
1387         }
1388     }
1389   return pack_d (&in);
1390 }
1391 #endif
1392
1393 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
1394 SItype
1395 float_to_si (FLO_type arg_a)
1396 {
1397   fp_number_type a;
1398   SItype tmp;
1399   FLO_union_type au;
1400
1401   au.value = arg_a;
1402   unpack_d (&au, &a);
1403
1404   if (iszero (&a))
1405     return 0;
1406   if (isnan (&a))
1407     return 0;
1408   /* get reasonable MAX_SI_INT...  */
1409   if (isinf (&a))
1410     return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1411   /* it is a number, but a small one */
1412   if (a.normal_exp < 0)
1413     return 0;
1414   if (a.normal_exp > BITS_PER_SI - 2)
1415     return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1416   tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1417   return a.sign ? (-tmp) : (tmp);
1418 }
1419 #endif /* L_sf_to_si || L_df_to_si */
1420
1421 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
1422 #if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
1423 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1424    we also define them for GOFAST because the ones in libgcc2.c have the
1425    wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1426    out of libgcc2.c.  We can't define these here if not GOFAST because then
1427    there'd be duplicate copies.  */
1428
1429 USItype
1430 float_to_usi (FLO_type arg_a)
1431 {
1432   fp_number_type a;
1433   FLO_union_type au;
1434
1435   au.value = arg_a;
1436   unpack_d (&au, &a);
1437
1438   if (iszero (&a))
1439     return 0;
1440   if (isnan (&a))
1441     return 0;
1442   /* it is a negative number */
1443   if (a.sign)
1444     return 0;
1445   /* get reasonable MAX_USI_INT...  */
1446   if (isinf (&a))
1447     return MAX_USI_INT;
1448   /* it is a number, but a small one */
1449   if (a.normal_exp < 0)
1450     return 0;
1451   if (a.normal_exp > BITS_PER_SI - 1)
1452     return MAX_USI_INT;
1453   else if (a.normal_exp > (FRACBITS + NGARDS))
1454     return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1455   else
1456     return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1457 }
1458 #endif /* US_SOFTWARE_GOFAST */
1459 #endif /* L_sf_to_usi || L_df_to_usi */
1460
1461 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
1462 FLO_type
1463 negate (FLO_type arg_a)
1464 {
1465   fp_number_type a;
1466   FLO_union_type au;
1467
1468   au.value = arg_a;
1469   unpack_d (&au, &a);
1470
1471   flip_sign (&a);
1472   return pack_d (&a);
1473 }
1474 #endif /* L_negate_sf || L_negate_df */
1475
1476 #ifdef FLOAT
1477
1478 #if defined(L_make_sf)
1479 SFtype
1480 __make_fp(fp_class_type class,
1481              unsigned int sign,
1482              int exp, 
1483              USItype frac)
1484 {
1485   fp_number_type in;
1486
1487   in.class = class;
1488   in.sign = sign;
1489   in.normal_exp = exp;
1490   in.fraction.ll = frac;
1491   return pack_d (&in);
1492 }
1493 #endif /* L_make_sf */
1494
1495 #ifndef FLOAT_ONLY
1496
1497 /* This enables one to build an fp library that supports float but not double.
1498    Otherwise, we would get an undefined reference to __make_dp.
1499    This is needed for some 8-bit ports that can't handle well values that
1500    are 8-bytes in size, so we just don't support double for them at all.  */
1501
1502 #if defined(L_sf_to_df)
1503 DFtype
1504 sf_to_df (SFtype arg_a)
1505 {
1506   fp_number_type in;
1507   FLO_union_type au;
1508
1509   au.value = arg_a;
1510   unpack_d (&au, &in);
1511
1512   return __make_dp (in.class, in.sign, in.normal_exp,
1513                     ((UDItype) in.fraction.ll) << F_D_BITOFF);
1514 }
1515 #endif /* L_sf_to_df */
1516
1517 #if defined(L_sf_to_tf) && defined(TMODES)
1518 TFtype
1519 sf_to_tf (SFtype arg_a)
1520 {
1521   fp_number_type in;
1522   FLO_union_type au;
1523
1524   au.value = arg_a;
1525   unpack_d (&au, &in);
1526
1527   return __make_tp (in.class, in.sign, in.normal_exp,
1528                     ((UTItype) in.fraction.ll) << F_T_BITOFF);
1529 }
1530 #endif /* L_sf_to_df */
1531
1532 #endif /* ! FLOAT_ONLY */
1533 #endif /* FLOAT */
1534
1535 #ifndef FLOAT
1536
1537 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1538
1539 #if defined(L_make_df)
1540 DFtype
1541 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1542 {
1543   fp_number_type in;
1544
1545   in.class = class;
1546   in.sign = sign;
1547   in.normal_exp = exp;
1548   in.fraction.ll = frac;
1549   return pack_d (&in);
1550 }
1551 #endif /* L_make_df */
1552
1553 #if defined(L_df_to_sf)
1554 SFtype
1555 df_to_sf (DFtype arg_a)
1556 {
1557   fp_number_type in;
1558   USItype sffrac;
1559   FLO_union_type au;
1560
1561   au.value = arg_a;
1562   unpack_d (&au, &in);
1563
1564   sffrac = in.fraction.ll >> F_D_BITOFF;
1565
1566   /* We set the lowest guard bit in SFFRAC if we discarded any non
1567      zero bits.  */
1568   if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1569     sffrac |= 1;
1570
1571   return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1572 }
1573 #endif /* L_df_to_sf */
1574
1575 #if defined(L_df_to_tf) && defined(TMODES) \
1576     && !defined(FLOAT) && !defined(TFLOAT)
1577 TFtype
1578 df_to_tf (DFtype arg_a)
1579 {
1580   fp_number_type in;
1581   FLO_union_type au;
1582
1583   au.value = arg_a;
1584   unpack_d (&au, &in);
1585
1586   return __make_tp (in.class, in.sign, in.normal_exp,
1587                     ((UTItype) in.fraction.ll) << D_T_BITOFF);
1588 }
1589 #endif /* L_sf_to_df */
1590
1591 #ifdef TFLOAT
1592 #if defined(L_make_tf)
1593 TFtype
1594 __make_tp(fp_class_type class,
1595              unsigned int sign,
1596              int exp, 
1597              UTItype frac)
1598 {
1599   fp_number_type in;
1600
1601   in.class = class;
1602   in.sign = sign;
1603   in.normal_exp = exp;
1604   in.fraction.ll = frac;
1605   return pack_d (&in);
1606 }
1607 #endif /* L_make_tf */
1608
1609 #if defined(L_tf_to_df)
1610 DFtype
1611 tf_to_df (TFtype arg_a)
1612 {
1613   fp_number_type in;
1614   UDItype sffrac;
1615   FLO_union_type au;
1616
1617   au.value = arg_a;
1618   unpack_d (&au, &in);
1619
1620   sffrac = in.fraction.ll >> D_T_BITOFF;
1621
1622   /* We set the lowest guard bit in SFFRAC if we discarded any non
1623      zero bits.  */
1624   if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
1625     sffrac |= 1;
1626
1627   return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
1628 }
1629 #endif /* L_tf_to_df */
1630
1631 #if defined(L_tf_to_sf)
1632 SFtype
1633 tf_to_sf (TFtype arg_a)
1634 {
1635   fp_number_type in;
1636   USItype sffrac;
1637   FLO_union_type au;
1638
1639   au.value = arg_a;
1640   unpack_d (&au, &in);
1641
1642   sffrac = in.fraction.ll >> F_T_BITOFF;
1643
1644   /* We set the lowest guard bit in SFFRAC if we discarded any non
1645      zero bits.  */
1646   if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
1647     sffrac |= 1;
1648
1649   return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1650 }
1651 #endif /* L_tf_to_sf */
1652 #endif /* TFLOAT */
1653
1654 #endif /* ! FLOAT */
1655 #endif /* !EXTENDED_FLOAT_STUBS */