OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [machine/] [powerpc/] [strtoufix32.c] - Blame information for rev 252

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
#ifdef __SPE__ 
2
 
3
#include <_ansi.h>
4
#include <limits.h>
5
#include <errno.h>
6
#include <stdlib.h>
7
#include <reent.h>
8
#include "vfieeefp.h"
9
 
10
/*
11
 * Convert a string to a fixed-point 32-bit value.
12
 *
13
 * Ignores `locale' stuff.
14
 */
15
__uint32_t
16
_DEFUN (_strtoufix32_r, (rptr, nptr, endptr),
17
        struct _reent *rptr _AND
18
        _CONST char *nptr _AND
19
        char **endptr)
20
{
21
  union double_union dbl;
22
  int exp, negexp;
23
  __uint32_t tmp, tmp2, result = 0;
24
 
25
  dbl.d = _strtod_r (rptr, nptr, endptr);
26
 
27
  /* treat NAN as domain error, +/- infinity as saturation */
28
  if (!finite(dbl.d))
29
    {
30
      if (isnan (dbl.d))
31
        {
32
          rptr->_errno = EDOM;
33
          return 0;
34
        }
35
      rptr->_errno = ERANGE;
36
      if (word0(dbl) & Sign_bit)
37
        return 0;
38
      return ULONG_MAX;
39
    }
40
 
41
  /* check for normal saturation */
42
  if (dbl.d >= 1.0)
43
    {
44
      rptr->_errno = ERANGE;
45
      return ULONG_MAX;
46
    }
47
  else if (dbl.d < 0)
48
    {
49
      rptr->_errno = ERANGE;
50
      return 0;
51
    }
52
 
53
  /* otherwise we have normal positive number in range */
54
 
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)
68
    {
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);
74
    }
75
  else
76
    {
77
      result = tmp + ((word1(dbl) & (1 << (32 - Ebits - 1))) != 0);
78
      /* if rounding causes carry, then saturation has occurred */
79
      if (result < tmp)
80
        {
81
          rptr->_errno = ERANGE;
82
          return ULONG_MAX;
83
        }
84
    }
85
 
86
  return result;
87
}
88
 
89
#ifndef _REENT_ONLY
90
 
91
__uint32_t
92
_DEFUN (strtoufix32, (s, ptr, base),
93
        _CONST char *s _AND
94
        char **ptr)
95
{
96
  return _strtoufix32_r (_REENT, s, ptr);
97
}
98
 
99
#endif
100
 
101
#endif /* __SPE__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.