fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / machine / powerpc / ufix64toa.c
blob450e0a352357f02113abe6a3bfc7fef99a8d1da5
1 /* _ufix64toa_r: convert unsigned 64-bit fixed point to ASCII string.
3 * This routine converts an unsigned fixed-point number to long double format and
4 * then calls _ldtoa_r to do the conversion.
6 * Written by Jeff Johnston.
7 */
9 #ifdef __SPE__
11 #include <_ansi.h>
12 #include <limits.h>
13 #include <errno.h>
14 #include <stdlib.h>
15 #include <reent.h>
16 #include "fix64.h"
18 extern char *_simdldtoa_r _PARAMS((struct _reent *, LONG_DOUBLE_UNION *, int,
19 int, int *, int *, char **));
22 * Convert an unsigned fixed-point 64-bit value to string.
24 * Ignores `locale' stuff.
27 char *
28 _DEFUN (_ufix64toa_r, (rptr, value, mode, ndigits, decpt, sign, rve),
29 struct _reent *rptr _AND
30 __uint64_t value _AND
31 int mode _AND
32 int ndigits _AND
33 int *decpt _AND
34 int *sign _AND
35 char **rve)
37 union long_double_union ldbl;
38 union fix64_union fix64;
39 unsigned long tmp;
40 int exp, negexp;
42 /* if input is 0, no additional work is needed */
43 if (value == 0)
45 ldbl.i[0] = ldbl.i[1] = ldbl.i[2] = ldbl.i[3] = 0;
47 else /* otherwise, we calculate long double equivalent of value */
49 /* find exponent by locating most-significant one-bit */
50 fix64.ll = value;
51 negexp = 1;
52 if (hiword(fix64) == 0)
54 tmp = loword(fix64);
55 negexp = 33;
57 else
59 tmp = hiword(fix64);
60 negexp = 1;
63 while (negexp < 65)
65 if (tmp & 0x80000000)
66 break;
67 ++negexp;
68 tmp <<= 1;
71 /* shift input appropriately */
72 fix64.ll = value << (negexp - 1 + (Exp_msk1 != 0));
74 /* build long double */
75 exp = -negexp + Bias;
76 word0(ldbl) = (exp << Exp_shift);
77 word1(ldbl) = hiword(fix64) << (32-Ebits-1);
78 word2(ldbl) = loword(fix64) << (32-Ebits-1);
79 word3(ldbl) = 0;
80 if (Ebits+1 < 32)
82 word0(ldbl) |= hiword(fix64) >> (Ebits + 1);
83 word1(ldbl) |= loword(fix64) >> (Ebits + 1);
87 /* convert long double to character */
88 return _simdldtoa_r (rptr, &ldbl, mode, ndigits, decpt, sign, rve);
91 #endif /* __SPE__ */