fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / machine / powerpc / strtoufix32.c
blob6a8e0812f81a60f588696ad65a59407a7640ffe4
1 #ifdef __SPE__
3 #include <_ansi.h>
4 #include <limits.h>
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <reent.h>
8 #include "vfieeefp.h"
11 * Convert a string to a fixed-point 32-bit value.
13 * Ignores `locale' stuff.
15 __uint32_t
16 _DEFUN (_strtoufix32_r, (rptr, nptr, endptr),
17 struct _reent *rptr _AND
18 _CONST char *nptr _AND
19 char **endptr)
21 union double_union dbl;
22 int exp, negexp;
23 __uint32_t tmp, tmp2, result = 0;
25 dbl.d = _strtod_r (rptr, nptr, endptr);
27 /* treat NAN as domain error, +/- infinity as saturation */
28 if (!finite(dbl.d))
30 if (isnan (dbl.d))
32 rptr->_errno = EDOM;
33 return 0;
35 rptr->_errno = ERANGE;
36 if (word0(dbl) & Sign_bit)
37 return 0;
38 return ULONG_MAX;
41 /* check for normal saturation */
42 if (dbl.d >= 1.0)
44 rptr->_errno = ERANGE;
45 return ULONG_MAX;
47 else if (dbl.d < 0)
49 rptr->_errno = ERANGE;
50 return 0;
53 /* otherwise we have normal positive number in range */
55 /* strip off exponent */
56 exp = ((word0(dbl) & Exp_mask) >> Exp_shift) - Bias;
57 negexp = -exp;
58 if (negexp > 32)
59 return 0;
60 word0(dbl) &= ~(Exp_mask | Sign_bit);
61 /* add in implicit normalized bit */
62 word0(dbl) |= Exp_msk1;
63 /* shift so result is contained left-justified in word */
64 tmp = word0(dbl) << Ebits;
65 tmp |= ((unsigned long)word1(dbl) >> (32 - Ebits));
66 /* perform rounding */
67 if (negexp > 1)
69 tmp2 = tmp + (1 << (negexp - 2));
70 result = (tmp2 >> (negexp - 1));
71 /* if rounding causes carry, add carry bit in */
72 if (tmp2 < tmp)
73 result += 1 << (32 - negexp);
75 else
77 result = tmp + ((word1(dbl) & (1 << (32 - Ebits - 1))) != 0);
78 /* if rounding causes carry, then saturation has occurred */
79 if (result < tmp)
81 rptr->_errno = ERANGE;
82 return ULONG_MAX;
86 return result;
89 #ifndef _REENT_ONLY
91 __uint32_t
92 _DEFUN (strtoufix32, (s, ptr, base),
93 _CONST char *s _AND
94 char **ptr)
96 return _strtoufix32_r (_REENT, s, ptr);
99 #endif
101 #endif /* __SPE__ */