OSDN Git Service

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