1208737Sjmallett/* Public domain.  */
2208737Sjmalletttypedef int DItype __attribute__ ((mode (DI)));
3208737Sjmalletttypedef unsigned int UDItype __attribute__ ((mode (DI)));
4208737Sjmalletttypedef unsigned int USItype __attribute__ ((mode (SI)));
5208737Sjmalletttypedef float SFtype __attribute__ ((mode (SF)));
6208737Sjmalletttypedef float DFtype __attribute__ ((mode (DF)));
7208737Sjmallett
8208737SjmallettSFtype __floatundisf (UDItype);
9208737Sjmallett
10208737SjmallettSFtype
11208737Sjmallett__floatundisf (UDItype u)
12208737Sjmallett{
13208737Sjmallett  /* Protect against double-rounding error.
14208737Sjmallett     Represent any low-order bits, that might be truncated by a bit that
15208737Sjmallett     won't be lost.  The bit can go in anywhere below the rounding position
16208737Sjmallett     of SFTYPE.  A fixed mask and bit position handles all usual
17208737Sjmallett     configurations.  */
18208737Sjmallett  if (53 < (sizeof (DItype) * 8)
19208737Sjmallett      && 53 > ((sizeof (DItype) * 8) - 53 + 24))
20208737Sjmallett    {
21208737Sjmallett      if (u >= ((UDItype) 1 << 53))
22208737Sjmallett	{
23208737Sjmallett	  if ((UDItype) u & (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1))
24208737Sjmallett	    {
25208737Sjmallett	      u &= ~ (((UDItype) 1 << (sizeof (DItype) * 8 - 53)) - 1);
26208737Sjmallett	      u |= (UDItype) 1 << (sizeof (DItype) * 8 - 53);
27208737Sjmallett	    }
28208737Sjmallett	}
29208737Sjmallett    }
30208737Sjmallett  /* Do the calculation in a wider type so that we don't lose any of
31208737Sjmallett     the precision of the high word while multiplying it.  */
32208737Sjmallett  DFtype f = (USItype) (u >> (sizeof (USItype) * 8));
33208737Sjmallett  f *= 0x1p32f;
34208737Sjmallett  f += (USItype) u;
35208737Sjmallett  return (SFtype) f;
36208737Sjmallett}
37