OSDN Git Service

* config/s390/s390.c (s390_optimize_prolog): Do not save/restore
[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    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 "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           fraction |= QUIET_NAN;
214         }
215     }
216   else if (isinf (src))
217     {
218       exp = EXPMAX;
219       fraction = 0;
220     }
221   else if (iszero (src))
222     {
223       exp = 0;
224       fraction = 0;
225     }
226   else if (fraction == 0)
227     {
228       exp = 0;
229     }
230   else
231     {
232       if (src->normal_exp < NORMAL_EXPMIN)
233         {
234 #ifdef NO_DENORMALS
235           /* Go straight to a zero representation if denormals are not
236              supported.  The denormal handling would be harmless but
237              isn't unnecessary.  */
238           exp = 0;
239           fraction = 0;
240 #else /* NO_DENORMALS */
241           /* This number's exponent is too low to fit into the bits
242              available in the number, so we'll store 0 in the exponent and
243              shift the fraction to the right to make up for it.  */
244
245           int shift = NORMAL_EXPMIN - src->normal_exp;
246
247           exp = 0;
248
249           if (shift > FRAC_NBITS - NGARDS)
250             {
251               /* No point shifting, since it's more that 64 out.  */
252               fraction = 0;
253             }
254           else
255             {
256               int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
257               fraction = (fraction >> shift) | lowbit;
258             }
259           if ((fraction & GARDMASK) == GARDMSB)
260             {
261               if ((fraction & (1 << NGARDS)))
262                 fraction += GARDROUND + 1;
263             }
264           else
265             {
266               /* Add to the guards to round up.  */
267               fraction += GARDROUND;
268             }
269           /* Perhaps the rounding means we now need to change the
270              exponent, because the fraction is no longer denormal.  */
271           if (fraction >= IMPLICIT_1)
272             {
273               exp += 1;
274             }
275           fraction >>= NGARDS;
276 #endif /* NO_DENORMALS */
277         }
278       else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
279                && src->normal_exp > EXPBIAS)
280         {
281           exp = EXPMAX;
282           fraction = 0;
283         }
284       else
285         {
286           exp = src->normal_exp + EXPBIAS;
287           if (!ROUND_TOWARDS_ZERO)
288             {
289               /* IF the gard bits are the all zero, but the first, then we're
290                  half way between two numbers, choose the one which makes the
291                  lsb of the answer 0.  */
292               if ((fraction & GARDMASK) == GARDMSB)
293                 {
294                   if (fraction & (1 << NGARDS))
295                     fraction += GARDROUND + 1;
296                 }
297               else
298                 {
299                   /* Add a one to the guards to round up */
300                   fraction += GARDROUND;
301                 }
302               if (fraction >= IMPLICIT_2)
303                 {
304                   fraction >>= 1;
305                   exp += 1;
306                 }
307             }
308           fraction >>= NGARDS;
309
310           if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
311             {
312               /* Saturate on overflow.  */
313               exp = EXPMAX;
314               fraction = ((fractype) 1 << FRACBITS) - 1;
315             }
316         }
317     }
318
319   /* We previously used bitfields to store the number, but this doesn't
320      handle little/big endian systems conveniently, so use shifts and
321      masks */
322 #ifdef FLOAT_BIT_ORDER_MISMATCH
323   dst.bits.fraction = fraction;
324   dst.bits.exp = exp;
325   dst.bits.sign = sign;
326 #else
327 # if defined TFLOAT && defined HALFFRACBITS
328  {
329    halffractype high, low;
330
331    high = (fraction >> (FRACBITS - HALFFRACBITS));
332    high &= (((fractype)1) << HALFFRACBITS) - 1;
333    high |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << HALFFRACBITS;
334    high |= ((fractype) (sign & 1)) << (HALFFRACBITS | EXPBITS);
335
336    low = (halffractype)fraction &
337      ((((halffractype)1) << (FRACBITS - HALFFRACBITS)) - 1);
338
339    if (exp == EXPMAX || exp == 0 || low == 0)
340      low = 0;
341    else
342      {
343        exp -= HALFFRACBITS + 1;
344
345        while (exp > 0
346               && low < ((halffractype)1 << HALFFRACBITS))
347          {
348            low <<= 1;
349            exp--;
350          }
351
352        if (exp <= 0)
353          {
354            halffractype roundmsb, round;
355
356            exp = -exp + 1;
357
358            roundmsb = (1 << (exp - 1));
359            round = low & ((roundmsb << 1) - 1);
360
361            low >>= exp;
362            exp = 0;
363
364            if (round > roundmsb || (round == roundmsb && (low & 1)))
365              {
366                low++;
367                if (low >= ((halffractype)1 << HALFFRACBITS))
368                  /* We don't shift left, since it has just become the
369                     smallest normal number, whose implicit 1 bit is
370                     now indicated by the non-zero exponent.  */
371                  exp++;
372              }
373          }
374
375        low &= ((halffractype)1 << HALFFRACBITS) - 1;
376        low |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << HALFFRACBITS;
377        low |= ((fractype) (sign & 1)) << (HALFFRACBITS | EXPBITS);
378      }
379
380    dst.value_raw = (((fractype) high) << HALFSHIFT) | low;
381  }
382 # else
383   dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
384   dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
385   dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
386 # endif
387 #endif
388
389 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
390 #ifdef TFLOAT
391   {
392     qrtrfractype tmp1 = dst.words[0];
393     qrtrfractype tmp2 = dst.words[1];
394     dst.words[0] = dst.words[3];
395     dst.words[1] = dst.words[2];
396     dst.words[2] = tmp2;
397     dst.words[3] = tmp1;
398   }
399 #else
400   {
401     halffractype tmp = dst.words[0];
402     dst.words[0] = dst.words[1];
403     dst.words[1] = tmp;
404   }
405 #endif
406 #endif
407
408   return dst.value;
409 }
410 #endif
411
412 #if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
413 void
414 unpack_d (FLO_union_type * src, fp_number_type * dst)
415 {
416   /* We previously used bitfields to store the number, but this doesn't
417      handle little/big endian systems conveniently, so use shifts and
418      masks */
419   fractype fraction;
420   int exp;
421   int sign;
422
423 #if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
424   FLO_union_type swapped;
425
426 #ifdef TFLOAT
427   swapped.words[0] = src->words[3];
428   swapped.words[1] = src->words[2];
429   swapped.words[2] = src->words[1];
430   swapped.words[3] = src->words[0];
431 #else
432   swapped.words[0] = src->words[1];
433   swapped.words[1] = src->words[0];
434 #endif
435   src = &swapped;
436 #endif
437   
438 #ifdef FLOAT_BIT_ORDER_MISMATCH
439   fraction = src->bits.fraction;
440   exp = src->bits.exp;
441   sign = src->bits.sign;
442 #else
443 # if defined TFLOAT && defined HALFFRACBITS
444  {
445    halffractype high, low;
446    
447    high = src->value_raw >> HALFSHIFT;
448    low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
449
450    fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
451    fraction <<= FRACBITS - HALFFRACBITS;
452    exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
453    sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
454
455    if (exp != EXPMAX && exp != 0 && low != 0)
456      {
457        int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
458        int shift;
459        fractype xlow;
460
461        xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
462        if (lowexp)
463          xlow |= (((halffractype)1) << HALFFRACBITS);
464        else
465          lowexp = 1;
466        shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
467        if (shift > 0)
468          xlow <<= shift;
469        else if (shift < 0)
470          xlow >>= -shift;
471        fraction += xlow;
472      }
473  }
474 # else
475   fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
476   exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
477   sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
478 # endif
479 #endif
480
481   dst->sign = sign;
482   if (exp == 0)
483     {
484       /* Hmm.  Looks like 0 */
485       if (fraction == 0
486 #ifdef NO_DENORMALS
487           || 1
488 #endif
489           )
490         {
491           /* tastes like zero */
492           dst->class = CLASS_ZERO;
493         }
494       else
495         {
496           /* Zero exponent with nonzero fraction - it's denormalized,
497              so there isn't a leading implicit one - we'll shift it so
498              it gets one.  */
499           dst->normal_exp = exp - EXPBIAS + 1;
500           fraction <<= NGARDS;
501
502           dst->class = CLASS_NUMBER;
503 #if 1
504           while (fraction < IMPLICIT_1)
505             {
506               fraction <<= 1;
507               dst->normal_exp--;
508             }
509 #endif
510           dst->fraction.ll = fraction;
511         }
512     }
513   else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
514     {
515       /* Huge exponent*/
516       if (fraction == 0)
517         {
518           /* Attached to a zero fraction - means infinity */
519           dst->class = CLASS_INFINITY;
520         }
521       else
522         {
523           /* Nonzero fraction, means nan */
524           if (fraction & QUIET_NAN)
525             {
526               dst->class = CLASS_QNAN;
527             }
528           else
529             {
530               dst->class = CLASS_SNAN;
531             }
532           /* Keep the fraction part as the nan number */
533           dst->fraction.ll = fraction;
534         }
535     }
536   else
537     {
538       /* Nothing strange about this number */
539       dst->normal_exp = exp - EXPBIAS;
540       dst->class = CLASS_NUMBER;
541       dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
542     }
543 }
544 #endif /* L_unpack_df || L_unpack_sf */
545
546 #if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
547 static fp_number_type *
548 _fpadd_parts (fp_number_type * a,
549               fp_number_type * b,
550               fp_number_type * tmp)
551 {
552   intfrac tfraction;
553
554   /* Put commonly used fields in local variables.  */
555   int a_normal_exp;
556   int b_normal_exp;
557   fractype a_fraction;
558   fractype b_fraction;
559
560   if (isnan (a))
561     {
562       return a;
563     }
564   if (isnan (b))
565     {
566       return b;
567     }
568   if (isinf (a))
569     {
570       /* Adding infinities with opposite signs yields a NaN.  */
571       if (isinf (b) && a->sign != b->sign)
572         return nan ();
573       return a;
574     }
575   if (isinf (b))
576     {
577       return b;
578     }
579   if (iszero (b))
580     {
581       if (iszero (a))
582         {
583           *tmp = *a;
584           tmp->sign = a->sign & b->sign;
585           return tmp;
586         }
587       return a;
588     }
589   if (iszero (a))
590     {
591       return b;
592     }
593
594   /* Got two numbers. shift the smaller and increment the exponent till
595      they're the same */
596   {
597     int diff;
598
599     a_normal_exp = a->normal_exp;
600     b_normal_exp = b->normal_exp;
601     a_fraction = a->fraction.ll;
602     b_fraction = b->fraction.ll;
603
604     diff = a_normal_exp - b_normal_exp;
605
606     if (diff < 0)
607       diff = -diff;
608     if (diff < FRAC_NBITS)
609       {
610         /* ??? This does shifts one bit at a time.  Optimize.  */
611         while (a_normal_exp > b_normal_exp)
612           {
613             b_normal_exp++;
614             LSHIFT (b_fraction);
615           }
616         while (b_normal_exp > a_normal_exp)
617           {
618             a_normal_exp++;
619             LSHIFT (a_fraction);
620           }
621       }
622     else
623       {
624         /* Somethings's up.. choose the biggest */
625         if (a_normal_exp > b_normal_exp)
626           {
627             b_normal_exp = a_normal_exp;
628             b_fraction = 0;
629           }
630         else
631           {
632             a_normal_exp = b_normal_exp;
633             a_fraction = 0;
634           }
635       }
636   }
637
638   if (a->sign != b->sign)
639     {
640       if (a->sign)
641         {
642           tfraction = -a_fraction + b_fraction;
643         }
644       else
645         {
646           tfraction = a_fraction - b_fraction;
647         }
648       if (tfraction >= 0)
649         {
650           tmp->sign = 0;
651           tmp->normal_exp = a_normal_exp;
652           tmp->fraction.ll = tfraction;
653         }
654       else
655         {
656           tmp->sign = 1;
657           tmp->normal_exp = a_normal_exp;
658           tmp->fraction.ll = -tfraction;
659         }
660       /* and renormalize it */
661
662       while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
663         {
664           tmp->fraction.ll <<= 1;
665           tmp->normal_exp--;
666         }
667     }
668   else
669     {
670       tmp->sign = a->sign;
671       tmp->normal_exp = a_normal_exp;
672       tmp->fraction.ll = a_fraction + b_fraction;
673     }
674   tmp->class = CLASS_NUMBER;
675   /* Now the fraction is added, we have to shift down to renormalize the
676      number */
677
678   if (tmp->fraction.ll >= IMPLICIT_2)
679     {
680       LSHIFT (tmp->fraction.ll);
681       tmp->normal_exp++;
682     }
683   return tmp;
684
685 }
686
687 FLO_type
688 add (FLO_type arg_a, FLO_type arg_b)
689 {
690   fp_number_type a;
691   fp_number_type b;
692   fp_number_type tmp;
693   fp_number_type *res;
694   FLO_union_type au, bu;
695
696   au.value = arg_a;
697   bu.value = arg_b;
698
699   unpack_d (&au, &a);
700   unpack_d (&bu, &b);
701
702   res = _fpadd_parts (&a, &b, &tmp);
703
704   return pack_d (res);
705 }
706
707 FLO_type
708 sub (FLO_type arg_a, FLO_type arg_b)
709 {
710   fp_number_type a;
711   fp_number_type b;
712   fp_number_type tmp;
713   fp_number_type *res;
714   FLO_union_type au, bu;
715
716   au.value = arg_a;
717   bu.value = arg_b;
718
719   unpack_d (&au, &a);
720   unpack_d (&bu, &b);
721
722   b.sign ^= 1;
723
724   res = _fpadd_parts (&a, &b, &tmp);
725
726   return pack_d (res);
727 }
728 #endif /* L_addsub_sf || L_addsub_df */
729
730 #if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
731 static inline __attribute__ ((__always_inline__)) fp_number_type *
732 _fpmul_parts ( fp_number_type *  a,
733                fp_number_type *  b,
734                fp_number_type * tmp)
735 {
736   fractype low = 0;
737   fractype high = 0;
738
739   if (isnan (a))
740     {
741       a->sign = a->sign != b->sign;
742       return a;
743     }
744   if (isnan (b))
745     {
746       b->sign = a->sign != b->sign;
747       return b;
748     }
749   if (isinf (a))
750     {
751       if (iszero (b))
752         return nan ();
753       a->sign = a->sign != b->sign;
754       return a;
755     }
756   if (isinf (b))
757     {
758       if (iszero (a))
759         {
760           return nan ();
761         }
762       b->sign = a->sign != b->sign;
763       return b;
764     }
765   if (iszero (a))
766     {
767       a->sign = a->sign != b->sign;
768       return a;
769     }
770   if (iszero (b))
771     {
772       b->sign = a->sign != b->sign;
773       return b;
774     }
775
776   /* Calculate the mantissa by multiplying both numbers to get a
777      twice-as-wide number.  */
778   {
779 #if defined(NO_DI_MODE) || defined(TFLOAT)
780     {
781       fractype x = a->fraction.ll;
782       fractype ylow = b->fraction.ll;
783       fractype yhigh = 0;
784       int bit;
785
786       /* ??? This does multiplies one bit at a time.  Optimize.  */
787       for (bit = 0; bit < FRAC_NBITS; bit++)
788         {
789           int carry;
790
791           if (x & 1)
792             {
793               carry = (low += ylow) < ylow;
794               high += yhigh + carry;
795             }
796           yhigh <<= 1;
797           if (ylow & FRACHIGH)
798             {
799               yhigh |= 1;
800             }
801           ylow <<= 1;
802           x >>= 1;
803         }
804     }
805 #elif defined(FLOAT) 
806     /* Multiplying two USIs to get a UDI, we're safe.  */
807     {
808       UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
809       
810       high = answer >> BITS_PER_SI;
811       low = answer;
812     }
813 #else
814     /* fractype is DImode, but we need the result to be twice as wide.
815        Assuming a widening multiply from DImode to TImode is not
816        available, build one by hand.  */
817     {
818       USItype nl = a->fraction.ll;
819       USItype nh = a->fraction.ll >> BITS_PER_SI;
820       USItype ml = b->fraction.ll;
821       USItype mh = b->fraction.ll >> BITS_PER_SI;
822       UDItype pp_ll = (UDItype) ml * nl;
823       UDItype pp_hl = (UDItype) mh * nl;
824       UDItype pp_lh = (UDItype) ml * nh;
825       UDItype pp_hh = (UDItype) mh * nh;
826       UDItype res2 = 0;
827       UDItype res0 = 0;
828       UDItype ps_hh__ = pp_hl + pp_lh;
829       if (ps_hh__ < pp_hl)
830         res2 += (UDItype)1 << BITS_PER_SI;
831       pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
832       res0 = pp_ll + pp_hl;
833       if (res0 < pp_ll)
834         res2++;
835       res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
836       high = res2;
837       low = res0;
838     }
839 #endif
840   }
841
842   tmp->normal_exp = a->normal_exp + b->normal_exp
843     + FRAC_NBITS - (FRACBITS + NGARDS);
844   tmp->sign = a->sign != b->sign;
845   while (high >= IMPLICIT_2)
846     {
847       tmp->normal_exp++;
848       if (high & 1)
849         {
850           low >>= 1;
851           low |= FRACHIGH;
852         }
853       high >>= 1;
854     }
855   while (high < IMPLICIT_1)
856     {
857       tmp->normal_exp--;
858
859       high <<= 1;
860       if (low & FRACHIGH)
861         high |= 1;
862       low <<= 1;
863     }
864   /* rounding is tricky. if we only round if it won't make us round later.  */
865 #if 0
866   if (low & FRACHIGH2)
867     {
868       if (((high & GARDMASK) != GARDMSB)
869           && (((high + 1) & GARDMASK) == GARDMSB))
870         {
871           /* don't round, it gets done again later.  */
872         }
873       else
874         {
875           high++;
876         }
877     }
878 #endif
879   if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
880     {
881       if (high & (1 << NGARDS))
882         {
883           /* half way, so round to even */
884           high += GARDROUND + 1;
885         }
886       else if (low)
887         {
888           /* but we really weren't half way */
889           high += GARDROUND + 1;
890         }
891     }
892   tmp->fraction.ll = high;
893   tmp->class = CLASS_NUMBER;
894   return tmp;
895 }
896
897 FLO_type
898 multiply (FLO_type arg_a, FLO_type arg_b)
899 {
900   fp_number_type a;
901   fp_number_type b;
902   fp_number_type tmp;
903   fp_number_type *res;
904   FLO_union_type au, bu;
905
906   au.value = arg_a;
907   bu.value = arg_b;
908
909   unpack_d (&au, &a);
910   unpack_d (&bu, &b);
911
912   res = _fpmul_parts (&a, &b, &tmp);
913
914   return pack_d (res);
915 }
916 #endif /* L_mul_sf || L_mul_df */
917
918 #if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
919 static inline __attribute__ ((__always_inline__)) fp_number_type *
920 _fpdiv_parts (fp_number_type * a,
921               fp_number_type * b)
922 {
923   fractype bit;
924   fractype numerator;
925   fractype denominator;
926   fractype quotient;
927
928   if (isnan (a))
929     {
930       return a;
931     }
932   if (isnan (b))
933     {
934       return b;
935     }
936
937   a->sign = a->sign ^ b->sign;
938
939   if (isinf (a) || iszero (a))
940     {
941       if (a->class == b->class)
942         return nan ();
943       return a;
944     }
945
946   if (isinf (b))
947     {
948       a->fraction.ll = 0;
949       a->normal_exp = 0;
950       return a;
951     }
952   if (iszero (b))
953     {
954       a->class = CLASS_INFINITY;
955       return a;
956     }
957
958   /* Calculate the mantissa by multiplying both 64bit numbers to get a
959      128 bit number */
960   {
961     /* quotient =
962        ( numerator / denominator) * 2^(numerator exponent -  denominator exponent)
963      */
964
965     a->normal_exp = a->normal_exp - b->normal_exp;
966     numerator = a->fraction.ll;
967     denominator = b->fraction.ll;
968
969     if (numerator < denominator)
970       {
971         /* Fraction will be less than 1.0 */
972         numerator *= 2;
973         a->normal_exp--;
974       }
975     bit = IMPLICIT_1;
976     quotient = 0;
977     /* ??? Does divide one bit at a time.  Optimize.  */
978     while (bit)
979       {
980         if (numerator >= denominator)
981           {
982             quotient |= bit;
983             numerator -= denominator;
984           }
985         bit >>= 1;
986         numerator *= 2;
987       }
988
989     if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
990       {
991         if (quotient & (1 << NGARDS))
992           {
993             /* half way, so round to even */
994             quotient += GARDROUND + 1;
995           }
996         else if (numerator)
997           {
998             /* but we really weren't half way, more bits exist */
999             quotient += GARDROUND + 1;
1000           }
1001       }
1002
1003     a->fraction.ll = quotient;
1004     return (a);
1005   }
1006 }
1007
1008 FLO_type
1009 divide (FLO_type arg_a, FLO_type arg_b)
1010 {
1011   fp_number_type a;
1012   fp_number_type b;
1013   fp_number_type *res;
1014   FLO_union_type au, bu;
1015
1016   au.value = arg_a;
1017   bu.value = arg_b;
1018
1019   unpack_d (&au, &a);
1020   unpack_d (&bu, &b);
1021
1022   res = _fpdiv_parts (&a, &b);
1023
1024   return pack_d (res);
1025 }
1026 #endif /* L_div_sf || L_div_df */
1027
1028 #if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
1029     || defined(L_fpcmp_parts_tf)
1030 /* according to the demo, fpcmp returns a comparison with 0... thus
1031    a<b -> -1
1032    a==b -> 0
1033    a>b -> +1
1034  */
1035
1036 int
1037 __fpcmp_parts (fp_number_type * a, fp_number_type * b)
1038 {
1039 #if 0
1040   /* either nan -> unordered. Must be checked outside of this routine.  */
1041   if (isnan (a) && isnan (b))
1042     {
1043       return 1;                 /* still unordered! */
1044     }
1045 #endif
1046
1047   if (isnan (a) || isnan (b))
1048     {
1049       return 1;                 /* how to indicate unordered compare? */
1050     }
1051   if (isinf (a) && isinf (b))
1052     {
1053       /* +inf > -inf, but +inf != +inf */
1054       /* b    \a| +inf(0)| -inf(1)
1055        ______\+--------+--------
1056        +inf(0)| a==b(0)| a<b(-1)
1057        -------+--------+--------
1058        -inf(1)| a>b(1) | a==b(0)
1059        -------+--------+--------
1060        So since unordered must be nonzero, just line up the columns...
1061        */
1062       return b->sign - a->sign;
1063     }
1064   /* but not both...  */
1065   if (isinf (a))
1066     {
1067       return a->sign ? -1 : 1;
1068     }
1069   if (isinf (b))
1070     {
1071       return b->sign ? 1 : -1;
1072     }
1073   if (iszero (a) && iszero (b))
1074     {
1075       return 0;
1076     }
1077   if (iszero (a))
1078     {
1079       return b->sign ? 1 : -1;
1080     }
1081   if (iszero (b))
1082     {
1083       return a->sign ? -1 : 1;
1084     }
1085   /* now both are "normal".  */
1086   if (a->sign != b->sign)
1087     {
1088       /* opposite signs */
1089       return a->sign ? -1 : 1;
1090     }
1091   /* same sign; exponents? */
1092   if (a->normal_exp > b->normal_exp)
1093     {
1094       return a->sign ? -1 : 1;
1095     }
1096   if (a->normal_exp < b->normal_exp)
1097     {
1098       return a->sign ? 1 : -1;
1099     }
1100   /* same exponents; check size.  */
1101   if (a->fraction.ll > b->fraction.ll)
1102     {
1103       return a->sign ? -1 : 1;
1104     }
1105   if (a->fraction.ll < b->fraction.ll)
1106     {
1107       return a->sign ? 1 : -1;
1108     }
1109   /* after all that, they're equal.  */
1110   return 0;
1111 }
1112 #endif
1113
1114 #if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
1115 CMPtype
1116 compare (FLO_type arg_a, FLO_type arg_b)
1117 {
1118   fp_number_type a;
1119   fp_number_type b;
1120   FLO_union_type au, bu;
1121
1122   au.value = arg_a;
1123   bu.value = arg_b;
1124
1125   unpack_d (&au, &a);
1126   unpack_d (&bu, &b);
1127
1128   return __fpcmp_parts (&a, &b);
1129 }
1130 #endif /* L_compare_sf || L_compare_df */
1131
1132 #ifndef US_SOFTWARE_GOFAST
1133
1134 /* These should be optimized for their specific tasks someday.  */
1135
1136 #if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
1137 CMPtype
1138 _eq_f2 (FLO_type arg_a, FLO_type arg_b)
1139 {
1140   fp_number_type a;
1141   fp_number_type b;
1142   FLO_union_type au, bu;
1143
1144   au.value = arg_a;
1145   bu.value = arg_b;
1146
1147   unpack_d (&au, &a);
1148   unpack_d (&bu, &b);
1149
1150   if (isnan (&a) || isnan (&b))
1151     return 1;                   /* false, truth == 0 */
1152
1153   return __fpcmp_parts (&a, &b) ;
1154 }
1155 #endif /* L_eq_sf || L_eq_df */
1156
1157 #if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
1158 CMPtype
1159 _ne_f2 (FLO_type arg_a, FLO_type arg_b)
1160 {
1161   fp_number_type a;
1162   fp_number_type b;
1163   FLO_union_type au, bu;
1164
1165   au.value = arg_a;
1166   bu.value = arg_b;
1167
1168   unpack_d (&au, &a);
1169   unpack_d (&bu, &b);
1170
1171   if (isnan (&a) || isnan (&b))
1172     return 1;                   /* true, truth != 0 */
1173
1174   return  __fpcmp_parts (&a, &b) ;
1175 }
1176 #endif /* L_ne_sf || L_ne_df */
1177
1178 #if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
1179 CMPtype
1180 _gt_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_gt_sf || L_gt_df */
1198
1199 #if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
1200 CMPtype
1201 _ge_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;                  /* false, truth >= 0 */
1215   return __fpcmp_parts (&a, &b) ;
1216 }
1217 #endif /* L_ge_sf || L_ge_df */
1218
1219 #if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
1220 CMPtype
1221 _lt_f2 (FLO_type arg_a, FLO_type arg_b)
1222 {
1223   fp_number_type a;
1224   fp_number_type b;
1225   FLO_union_type au, bu;
1226
1227   au.value = arg_a;
1228   bu.value = arg_b;
1229
1230   unpack_d (&au, &a);
1231   unpack_d (&bu, &b);
1232
1233   if (isnan (&a) || isnan (&b))
1234     return 1;                   /* false, truth < 0 */
1235
1236   return __fpcmp_parts (&a, &b);
1237 }
1238 #endif /* L_lt_sf || L_lt_df */
1239
1240 #if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
1241 CMPtype
1242 _le_f2 (FLO_type arg_a, FLO_type arg_b)
1243 {
1244   fp_number_type a;
1245   fp_number_type b;
1246   FLO_union_type au, bu;
1247
1248   au.value = arg_a;
1249   bu.value = arg_b;
1250
1251   unpack_d (&au, &a);
1252   unpack_d (&bu, &b);
1253
1254   if (isnan (&a) || isnan (&b))
1255     return 1;                   /* false, truth <= 0 */
1256
1257   return __fpcmp_parts (&a, &b) ;
1258 }
1259 #endif /* L_le_sf || L_le_df */
1260
1261 #endif /* ! US_SOFTWARE_GOFAST */
1262
1263 #if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
1264 CMPtype
1265 _unord_f2 (FLO_type arg_a, FLO_type arg_b)
1266 {
1267   fp_number_type a;
1268   fp_number_type b;
1269   FLO_union_type au, bu;
1270
1271   au.value = arg_a;
1272   bu.value = arg_b;
1273
1274   unpack_d (&au, &a);
1275   unpack_d (&bu, &b);
1276
1277   return (isnan (&a) || isnan (&b));
1278 }
1279 #endif /* L_unord_sf || L_unord_df */
1280
1281 #if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
1282 FLO_type
1283 si_to_float (SItype arg_a)
1284 {
1285   fp_number_type in;
1286
1287   in.class = CLASS_NUMBER;
1288   in.sign = arg_a < 0;
1289   if (!arg_a)
1290     {
1291       in.class = CLASS_ZERO;
1292     }
1293   else
1294     {
1295       in.normal_exp = FRACBITS + NGARDS;
1296       if (in.sign) 
1297         {
1298           /* Special case for minint, since there is no +ve integer
1299              representation for it */
1300           if (arg_a == (- MAX_SI_INT - 1))
1301             {
1302               return (FLO_type)(- MAX_SI_INT - 1);
1303             }
1304           in.fraction.ll = (-arg_a);
1305         }
1306       else
1307         in.fraction.ll = arg_a;
1308
1309       while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1310         {
1311           in.fraction.ll <<= 1;
1312           in.normal_exp -= 1;
1313         }
1314     }
1315   return pack_d (&in);
1316 }
1317 #endif /* L_si_to_sf || L_si_to_df */
1318
1319 #if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
1320 FLO_type
1321 usi_to_float (USItype arg_a)
1322 {
1323   fp_number_type in;
1324
1325   in.sign = 0;
1326   if (!arg_a)
1327     {
1328       in.class = CLASS_ZERO;
1329     }
1330   else
1331     {
1332       in.class = CLASS_NUMBER;
1333       in.normal_exp = FRACBITS + NGARDS;
1334       in.fraction.ll = arg_a;
1335
1336       while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
1337         {
1338           in.fraction.ll >>= 1;
1339           in.normal_exp += 1;
1340         }
1341       while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1342         {
1343           in.fraction.ll <<= 1;
1344           in.normal_exp -= 1;
1345         }
1346     }
1347   return pack_d (&in);
1348 }
1349 #endif
1350
1351 #if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
1352 SItype
1353 float_to_si (FLO_type arg_a)
1354 {
1355   fp_number_type a;
1356   SItype tmp;
1357   FLO_union_type au;
1358
1359   au.value = arg_a;
1360   unpack_d (&au, &a);
1361
1362   if (iszero (&a))
1363     return 0;
1364   if (isnan (&a))
1365     return 0;
1366   /* get reasonable MAX_SI_INT...  */
1367   if (isinf (&a))
1368     return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1369   /* it is a number, but a small one */
1370   if (a.normal_exp < 0)
1371     return 0;
1372   if (a.normal_exp > BITS_PER_SI - 2)
1373     return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1374   tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1375   return a.sign ? (-tmp) : (tmp);
1376 }
1377 #endif /* L_sf_to_si || L_df_to_si */
1378
1379 #if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
1380 #if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
1381 /* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
1382    we also define them for GOFAST because the ones in libgcc2.c have the
1383    wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
1384    out of libgcc2.c.  We can't define these here if not GOFAST because then
1385    there'd be duplicate copies.  */
1386
1387 USItype
1388 float_to_usi (FLO_type arg_a)
1389 {
1390   fp_number_type a;
1391   FLO_union_type au;
1392
1393   au.value = arg_a;
1394   unpack_d (&au, &a);
1395
1396   if (iszero (&a))
1397     return 0;
1398   if (isnan (&a))
1399     return 0;
1400   /* it is a negative number */
1401   if (a.sign)
1402     return 0;
1403   /* get reasonable MAX_USI_INT...  */
1404   if (isinf (&a))
1405     return MAX_USI_INT;
1406   /* it is a number, but a small one */
1407   if (a.normal_exp < 0)
1408     return 0;
1409   if (a.normal_exp > BITS_PER_SI - 1)
1410     return MAX_USI_INT;
1411   else if (a.normal_exp > (FRACBITS + NGARDS))
1412     return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
1413   else
1414     return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1415 }
1416 #endif /* US_SOFTWARE_GOFAST */
1417 #endif /* L_sf_to_usi || L_df_to_usi */
1418
1419 #if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
1420 FLO_type
1421 negate (FLO_type arg_a)
1422 {
1423   fp_number_type a;
1424   FLO_union_type au;
1425
1426   au.value = arg_a;
1427   unpack_d (&au, &a);
1428
1429   flip_sign (&a);
1430   return pack_d (&a);
1431 }
1432 #endif /* L_negate_sf || L_negate_df */
1433
1434 #ifdef FLOAT
1435
1436 #if defined(L_make_sf)
1437 SFtype
1438 __make_fp(fp_class_type class,
1439              unsigned int sign,
1440              int exp, 
1441              USItype frac)
1442 {
1443   fp_number_type in;
1444
1445   in.class = class;
1446   in.sign = sign;
1447   in.normal_exp = exp;
1448   in.fraction.ll = frac;
1449   return pack_d (&in);
1450 }
1451 #endif /* L_make_sf */
1452
1453 #ifndef FLOAT_ONLY
1454
1455 /* This enables one to build an fp library that supports float but not double.
1456    Otherwise, we would get an undefined reference to __make_dp.
1457    This is needed for some 8-bit ports that can't handle well values that
1458    are 8-bytes in size, so we just don't support double for them at all.  */
1459
1460 #if defined(L_sf_to_df)
1461 DFtype
1462 sf_to_df (SFtype arg_a)
1463 {
1464   fp_number_type in;
1465   FLO_union_type au;
1466
1467   au.value = arg_a;
1468   unpack_d (&au, &in);
1469
1470   return __make_dp (in.class, in.sign, in.normal_exp,
1471                     ((UDItype) in.fraction.ll) << F_D_BITOFF);
1472 }
1473 #endif /* L_sf_to_df */
1474
1475 #if defined(L_sf_to_tf) && defined(TMODES)
1476 TFtype
1477 sf_to_tf (SFtype arg_a)
1478 {
1479   fp_number_type in;
1480   FLO_union_type au;
1481
1482   au.value = arg_a;
1483   unpack_d (&au, &in);
1484
1485   return __make_tp (in.class, in.sign, in.normal_exp,
1486                     ((UTItype) in.fraction.ll) << F_T_BITOFF);
1487 }
1488 #endif /* L_sf_to_df */
1489
1490 #endif /* ! FLOAT_ONLY */
1491 #endif /* FLOAT */
1492
1493 #ifndef FLOAT
1494
1495 extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
1496
1497 #if defined(L_make_df)
1498 DFtype
1499 __make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
1500 {
1501   fp_number_type in;
1502
1503   in.class = class;
1504   in.sign = sign;
1505   in.normal_exp = exp;
1506   in.fraction.ll = frac;
1507   return pack_d (&in);
1508 }
1509 #endif /* L_make_df */
1510
1511 #if defined(L_df_to_sf)
1512 SFtype
1513 df_to_sf (DFtype arg_a)
1514 {
1515   fp_number_type in;
1516   USItype sffrac;
1517   FLO_union_type au;
1518
1519   au.value = arg_a;
1520   unpack_d (&au, &in);
1521
1522   sffrac = in.fraction.ll >> F_D_BITOFF;
1523
1524   /* We set the lowest guard bit in SFFRAC if we discarded any non
1525      zero bits.  */
1526   if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
1527     sffrac |= 1;
1528
1529   return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1530 }
1531 #endif /* L_df_to_sf */
1532
1533 #if defined(L_df_to_tf) && defined(TMODES) \
1534     && !defined(FLOAT) && !defined(TFLOAT)
1535 TFtype
1536 df_to_tf (DFtype arg_a)
1537 {
1538   fp_number_type in;
1539   FLO_union_type au;
1540
1541   au.value = arg_a;
1542   unpack_d (&au, &in);
1543
1544   return __make_tp (in.class, in.sign, in.normal_exp,
1545                     ((UTItype) in.fraction.ll) << D_T_BITOFF);
1546 }
1547 #endif /* L_sf_to_df */
1548
1549 #ifdef TFLOAT
1550 #if defined(L_make_tf)
1551 TFtype
1552 __make_tp(fp_class_type class,
1553              unsigned int sign,
1554              int exp, 
1555              UTItype frac)
1556 {
1557   fp_number_type in;
1558
1559   in.class = class;
1560   in.sign = sign;
1561   in.normal_exp = exp;
1562   in.fraction.ll = frac;
1563   return pack_d (&in);
1564 }
1565 #endif /* L_make_tf */
1566
1567 #if defined(L_tf_to_df)
1568 DFtype
1569 tf_to_df (TFtype arg_a)
1570 {
1571   fp_number_type in;
1572   UDItype sffrac;
1573   FLO_union_type au;
1574
1575   au.value = arg_a;
1576   unpack_d (&au, &in);
1577
1578   sffrac = in.fraction.ll >> D_T_BITOFF;
1579
1580   /* We set the lowest guard bit in SFFRAC if we discarded any non
1581      zero bits.  */
1582   if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
1583     sffrac |= 1;
1584
1585   return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
1586 }
1587 #endif /* L_tf_to_df */
1588
1589 #if defined(L_tf_to_sf)
1590 SFtype
1591 tf_to_sf (TFtype arg_a)
1592 {
1593   fp_number_type in;
1594   USItype sffrac;
1595   FLO_union_type au;
1596
1597   au.value = arg_a;
1598   unpack_d (&au, &in);
1599
1600   sffrac = in.fraction.ll >> F_T_BITOFF;
1601
1602   /* We set the lowest guard bit in SFFRAC if we discarded any non
1603      zero bits.  */
1604   if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
1605     sffrac |= 1;
1606
1607   return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
1608 }
1609 #endif /* L_tf_to_sf */
1610 #endif /* TFLOAT */
1611
1612 #endif /* ! FLOAT */
1613 #endif /* !EXTENDED_FLOAT_STUBS */