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