1 | /* _ufix64toa_r: convert unsigned 64-bit fixed point to ASCII string. |
---|
2 | * |
---|
3 | * This routine converts an unsigned fixed-point number to long double format and |
---|
4 | * then calls _ldtoa_r to do the conversion. |
---|
5 | * |
---|
6 | * Written by Jeff Johnston. |
---|
7 | */ |
---|
8 | |
---|
9 | #ifdef __SPE__ |
---|
10 | |
---|
11 | #include <_ansi.h> |
---|
12 | #include <limits.h> |
---|
13 | #include <errno.h> |
---|
14 | #include <stdlib.h> |
---|
15 | #include <reent.h> |
---|
16 | #include "fix64.h" |
---|
17 | |
---|
18 | extern char *_simdldtoa_r (struct _reent *, LONG_DOUBLE_UNION *, int, |
---|
19 | int, int *, int *, char **); |
---|
20 | |
---|
21 | /* |
---|
22 | * Convert an unsigned fixed-point 64-bit value to string. |
---|
23 | * |
---|
24 | * Ignores `locale' stuff. |
---|
25 | */ |
---|
26 | |
---|
27 | char * |
---|
28 | _ufix64toa_r (struct _reent *rptr, |
---|
29 | __uint64_t value, |
---|
30 | int mode, |
---|
31 | int ndigits, |
---|
32 | int *decpt, |
---|
33 | int *sign, |
---|
34 | char **rve) |
---|
35 | { |
---|
36 | union long_double_union ldbl; |
---|
37 | union fix64_union fix64; |
---|
38 | unsigned long tmp; |
---|
39 | int exp, negexp; |
---|
40 | |
---|
41 | /* if input is 0, no additional work is needed */ |
---|
42 | if (value == 0) |
---|
43 | { |
---|
44 | ldbl.i[0] = ldbl.i[1] = ldbl.i[2] = ldbl.i[3] = 0; |
---|
45 | } |
---|
46 | else /* otherwise, we calculate long double equivalent of value */ |
---|
47 | { |
---|
48 | /* find exponent by locating most-significant one-bit */ |
---|
49 | fix64.ll = value; |
---|
50 | negexp = 1; |
---|
51 | if (hiword(fix64) == 0) |
---|
52 | { |
---|
53 | tmp = loword(fix64); |
---|
54 | negexp = 33; |
---|
55 | } |
---|
56 | else |
---|
57 | { |
---|
58 | tmp = hiword(fix64); |
---|
59 | negexp = 1; |
---|
60 | } |
---|
61 | |
---|
62 | while (negexp < 65) |
---|
63 | { |
---|
64 | if (tmp & 0x80000000) |
---|
65 | break; |
---|
66 | ++negexp; |
---|
67 | tmp <<= 1; |
---|
68 | } |
---|
69 | |
---|
70 | /* shift input appropriately */ |
---|
71 | fix64.ll = value << (negexp - 1 + (Exp_msk1 != 0)); |
---|
72 | |
---|
73 | /* build long double */ |
---|
74 | exp = -negexp + Bias; |
---|
75 | word0(ldbl) = (exp << Exp_shift); |
---|
76 | word1(ldbl) = hiword(fix64) << (32-Ebits-1); |
---|
77 | word2(ldbl) = loword(fix64) << (32-Ebits-1); |
---|
78 | word3(ldbl) = 0; |
---|
79 | if (Ebits+1 < 32) |
---|
80 | { |
---|
81 | word0(ldbl) |= hiword(fix64) >> (Ebits + 1); |
---|
82 | word1(ldbl) |= loword(fix64) >> (Ebits + 1); |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | /* convert long double to character */ |
---|
87 | return _simdldtoa_r (rptr, &ldbl, mode, ndigits, decpt, sign, rve); |
---|
88 | } |
---|
89 | |
---|
90 | #endif /* __SPE__ */ |
---|