Home | History | Annotate | Line # | Download | only in ppc
      1  1.1  joerg /* This file is distributed under the University of Illinois Open Source
      2  1.1  joerg  * License. See LICENSE.TXT for details.
      3  1.1  joerg  */
      4  1.1  joerg 
      5  1.1  joerg /* long double __floatditf(long long x); */
      6  1.1  joerg /* This file implements the PowerPC long long -> long double conversion */
      7  1.1  joerg 
      8  1.1  joerg #include "DD.h"
      9  1.1  joerg 
     10  1.1  joerg long double __floatditf(int64_t a) {
     11  1.1  joerg 
     12  1.1  joerg 	static const double twop32 = 0x1.0p32;
     13  1.1  joerg 	static const double twop52 = 0x1.0p52;
     14  1.1  joerg 
     15  1.1  joerg 	doublebits low  = { .d = twop52 };
     16  1.1  joerg 	low.x |= a & UINT64_C(0x00000000ffffffff);	/* 0x1.0p52 + low 32 bits of a. */
     17  1.1  joerg 
     18  1.1  joerg 	const double high_addend = (double)((int32_t)(a >> 32))*twop32 - twop52;
     19  1.1  joerg 
     20  1.1  joerg 	/* At this point, we have two double precision numbers
     21  1.1  joerg 	 * high_addend and low.d, and we wish to return their sum
     22  1.1  joerg 	 * as a canonicalized long double:
     23  1.1  joerg 	 */
     24  1.1  joerg 
     25  1.1  joerg 	/* This implementation sets the inexact flag spuriously.
     26  1.1  joerg 	 * This could be avoided, but at some substantial cost.
     27  1.1  joerg 	*/
     28  1.1  joerg 
     29  1.1  joerg 	DD result;
     30  1.1  joerg 
     31  1.1  joerg 	result.s.hi = high_addend + low.d;
     32  1.1  joerg 	result.s.lo = (high_addend - result.s.hi) + low.d;
     33  1.1  joerg 
     34  1.1  joerg 	return result.ld;
     35  1.1  joerg 
     36  1.1  joerg }
     37