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] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
#ifdef __SPE__
#ifdef __SPE__
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <limits.h>
#include <limits.h>
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdlib.h>
#include <reent.h>
#include <reent.h>
#include "fix64.h"
#include "fix64.h"
 
 
/*
/*
 * Convert a string to a fixed-point 64-bit unsigned value.
 * Convert a string to a fixed-point 64-bit unsigned value.
 *
 *
 * Ignores `locale' stuff.
 * Ignores `locale' stuff.
 */
 */
__uint64_t
__uint64_t
_DEFUN (_strtoufix64_r, (rptr, nptr, endptr),
_DEFUN (_strtoufix64_r, (rptr, nptr, endptr),
        struct _reent *rptr _AND
        struct _reent *rptr _AND
        _CONST char *nptr _AND
        _CONST char *nptr _AND
        char **endptr)
        char **endptr)
{
{
  union long_double_union ldbl;
  union long_double_union ldbl;
  int exp, sign, negexp, ld_type;
  int exp, sign, negexp, ld_type;
  __uint64_t tmp, tmp2, result = 0;
  __uint64_t tmp, tmp2, result = 0;
 
 
  init(ldbl);
  init(ldbl);
 
 
  _simdstrtold ((char *)nptr, endptr, &ldbl);
  _simdstrtold ((char *)nptr, endptr, &ldbl);
 
 
  /* treat NAN as domain error, +/- infinity as saturation */
  /* treat NAN as domain error, +/- infinity as saturation */
  ld_type = _simdldcheck (&ldbl);
  ld_type = _simdldcheck (&ldbl);
  if (ld_type != 0)
  if (ld_type != 0)
    {
    {
      if (ld_type == 1)
      if (ld_type == 1)
        {
        {
          rptr->_errno = EDOM;
          rptr->_errno = EDOM;
          return 0;
          return 0;
        }
        }
      rptr->_errno = ERANGE;
      rptr->_errno = ERANGE;
      if (word0(ldbl) & Sign_bit)
      if (word0(ldbl) & Sign_bit)
        return 0;
        return 0;
      return ULONG_LONG_MAX;
      return ULONG_LONG_MAX;
    }
    }
 
 
  /* strip off sign and exponent */
  /* strip off sign and exponent */
  sign = word0(ldbl) & Sign_bit;
  sign = word0(ldbl) & Sign_bit;
  exp = ((word0(ldbl) & Exp_mask) >> Exp_shift) - Bias;
  exp = ((word0(ldbl) & Exp_mask) >> Exp_shift) - Bias;
  negexp = -exp;
  negexp = -exp;
  if (negexp > 63)
  if (negexp > 63)
    return 0;
    return 0;
  word0(ldbl) &= ~(Exp_mask | Sign_bit);
  word0(ldbl) &= ~(Exp_mask | Sign_bit);
  /* add in implicit normalized bit */
  /* add in implicit normalized bit */
  word0(ldbl) |= Exp_msk1;
  word0(ldbl) |= Exp_msk1;
  /* shift so result is contained in single word */
  /* shift so result is contained in single word */
  tmp = word0(ldbl) << Ebits;
  tmp = word0(ldbl) << Ebits;
  tmp |= ((unsigned long)word1(ldbl) >> (32 - Ebits));
  tmp |= ((unsigned long)word1(ldbl) >> (32 - Ebits));
  tmp <<= 32;
  tmp <<= 32;
  if (Ebits < 32)
  if (Ebits < 32)
    tmp |= ((unsigned long)word1(ldbl) << Ebits);
    tmp |= ((unsigned long)word1(ldbl) << Ebits);
  tmp |= ((unsigned long)word2(ldbl) >> (32 - Ebits));
  tmp |= ((unsigned long)word2(ldbl) >> (32 - Ebits));
 
 
  /* check for saturation */
  /* check for saturation */
  if (sign)
  if (sign)
    {
    {
      rptr->_errno = ERANGE;
      rptr->_errno = ERANGE;
      return 0;
      return 0;
    }
    }
  else
  else
    {
    {
      if (exp > 0 || (exp == 0 && tmp >= 0x8000000000000000LL))
      if (exp > 0 || (exp == 0 && tmp >= 0x8000000000000000LL))
        {
        {
          rptr->_errno = ERANGE;
          rptr->_errno = ERANGE;
          return ULONG_LONG_MAX;
          return ULONG_LONG_MAX;
        }
        }
    }
    }
 
 
  /* otherwise we have normal number in range */
  /* otherwise we have normal number in range */
  if (negexp > 1)
  if (negexp > 1)
    {
    {
      tmp2 = tmp + (1 << (negexp - 2));
      tmp2 = tmp + (1 << (negexp - 2));
      result = (tmp2 >> (negexp - 1));
      result = (tmp2 >> (negexp - 1));
      /* if rounding causes carry, add carry bit in */
      /* if rounding causes carry, add carry bit in */
      if (tmp2 < tmp)
      if (tmp2 < tmp)
        result += 1 << (64 - negexp);
        result += 1 << (64 - negexp);
    }
    }
  else
  else
    {
    {
      if (Ebits < 32)
      if (Ebits < 32)
        {
        {
          result = tmp + ((word2(ldbl) & (1 << (32 - Ebits - 1))) != 0);
          result = tmp + ((word2(ldbl) & (1 << (32 - Ebits - 1))) != 0);
          /* if rounding causes carry, then saturation has occurred */
          /* if rounding causes carry, then saturation has occurred */
          if (result < tmp)
          if (result < tmp)
            {
            {
              rptr->_errno = ERANGE;
              rptr->_errno = ERANGE;
              return ULONG_LONG_MAX;
              return ULONG_LONG_MAX;
            }
            }
        }
        }
      else
      else
        result = tmp;
        result = tmp;
    }
    }
 
 
  return result;
  return result;
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
__uint64_t
__uint64_t
_DEFUN (strtoufix64, (s, ptr, base),
_DEFUN (strtoufix64, (s, ptr, base),
        _CONST char *s _AND
        _CONST char *s _AND
        char **ptr)
        char **ptr)
{
{
  return _strtoufix64_r (_REENT, s, ptr);
  return _strtoufix64_r (_REENT, s, ptr);
}
}
 
 
#endif
#endif
 
 
#endif /* __SPE__ */
#endif /* __SPE__ */
 
 

powered by: WebSVN 2.1.0

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