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

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [machine/] [powerpc/] [strtoufix64.c] - Blame information for rev 345

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 "fix64.h"
9
 
10
/*
11
 * Convert a string to a fixed-point 64-bit unsigned value.
12
 *
13
 * Ignores `locale' stuff.
14
 */
15
__uint64_t
16
_DEFUN (_strtoufix64_r, (rptr, nptr, endptr),
17
        struct _reent *rptr _AND
18
        _CONST char *nptr _AND
19
        char **endptr)
20
{
21
  union long_double_union ldbl;
22
  int exp, sign, negexp, ld_type;
23
  __uint64_t tmp, tmp2, result = 0;
24
 
25
  init(ldbl);
26
 
27
  _simdstrtold ((char *)nptr, endptr, &ldbl);
28
 
29
  /* treat NAN as domain error, +/- infinity as saturation */
30
  ld_type = _simdldcheck (&ldbl);
31
  if (ld_type != 0)
32
    {
33
      if (ld_type == 1)
34
        {
35
          rptr->_errno = EDOM;
36
          return 0;
37
        }
38
      rptr->_errno = ERANGE;
39
      if (word0(ldbl) & Sign_bit)
40
        return 0;
41
      return ULONG_LONG_MAX;
42
    }
43
 
44
  /* strip off sign and exponent */
45
  sign = word0(ldbl) & Sign_bit;
46
  exp = ((word0(ldbl) & Exp_mask) >> Exp_shift) - Bias;
47
  negexp = -exp;
48
  if (negexp > 63)
49
    return 0;
50
  word0(ldbl) &= ~(Exp_mask | Sign_bit);
51
  /* add in implicit normalized bit */
52
  word0(ldbl) |= Exp_msk1;
53
  /* shift so result is contained in single word */
54
  tmp = word0(ldbl) << Ebits;
55
  tmp |= ((unsigned long)word1(ldbl) >> (32 - Ebits));
56
  tmp <<= 32;
57
  if (Ebits < 32)
58
    tmp |= ((unsigned long)word1(ldbl) << Ebits);
59
  tmp |= ((unsigned long)word2(ldbl) >> (32 - Ebits));
60
 
61
  /* check for saturation */
62
  if (sign)
63
    {
64
      rptr->_errno = ERANGE;
65
      return 0;
66
    }
67
  else
68
    {
69
      if (exp > 0 || (exp == 0 && tmp >= 0x8000000000000000LL))
70
        {
71
          rptr->_errno = ERANGE;
72
          return ULONG_LONG_MAX;
73
        }
74
    }
75
 
76
  /* otherwise we have normal number in range */
77
  if (negexp > 1)
78
    {
79
      tmp2 = tmp + (1 << (negexp - 2));
80
      result = (tmp2 >> (negexp - 1));
81
      /* if rounding causes carry, add carry bit in */
82
      if (tmp2 < tmp)
83
        result += 1 << (64 - negexp);
84
    }
85
  else
86
    {
87
      if (Ebits < 32)
88
        {
89
          result = tmp + ((word2(ldbl) & (1 << (32 - Ebits - 1))) != 0);
90
          /* if rounding causes carry, then saturation has occurred */
91
          if (result < tmp)
92
            {
93
              rptr->_errno = ERANGE;
94
              return ULONG_LONG_MAX;
95
            }
96
        }
97
      else
98
        result = tmp;
99
    }
100
 
101
  return result;
102
}
103
 
104
#ifndef _REENT_ONLY
105
 
106
__uint64_t
107
_DEFUN (strtoufix64, (s, ptr, base),
108
        _CONST char *s _AND
109
        char **ptr)
110
{
111
  return _strtoufix64_r (_REENT, s, ptr);
112
}
113
 
114
#endif
115
 
116
#endif /* __SPE__ */

powered by: WebSVN 2.1.0

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