OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [machine/] [powerpc/] [ufix64toa.c] - Blame information for rev 158

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
/* _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 _PARAMS((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
_DEFUN (_ufix64toa_r, (rptr, value, mode, ndigits, decpt, sign, rve),
29
        struct _reent *rptr _AND
30
        __uint64_t value _AND
31
        int mode _AND
32
        int ndigits _AND
33
        int *decpt _AND
34
        int *sign _AND
35
        char **rve)
36
{
37
  union long_double_union ldbl;
38
  union fix64_union fix64;
39
  unsigned long tmp;
40
  int exp, negexp;
41
 
42
  /* if input is 0, no additional work is needed */
43
  if (value == 0)
44
    {
45
      ldbl.i[0] = ldbl.i[1] = ldbl.i[2] = ldbl.i[3] = 0;
46
    }
47
  else /* otherwise, we calculate long double equivalent of value */
48
    {
49
      /* find exponent by locating most-significant one-bit */
50
      fix64.ll = value;
51
      negexp = 1;
52
      if (hiword(fix64) == 0)
53
        {
54
          tmp = loword(fix64);
55
          negexp = 33;
56
        }
57
      else
58
        {
59
          tmp = hiword(fix64);
60
          negexp = 1;
61
        }
62
 
63
      while (negexp < 65)
64
        {
65
          if (tmp & 0x80000000)
66
            break;
67
          ++negexp;
68
          tmp <<= 1;
69
        }
70
 
71
      /* shift input appropriately */
72
      fix64.ll = value << (negexp - 1 + (Exp_msk1 != 0));
73
 
74
      /* build long double */
75
      exp = -negexp + Bias;
76
      word0(ldbl) = (exp << Exp_shift);
77
      word1(ldbl) = hiword(fix64) << (32-Ebits-1);
78
      word2(ldbl) = loword(fix64) << (32-Ebits-1);
79
      word3(ldbl) = 0;
80
      if (Ebits+1 < 32)
81
        {
82
          word0(ldbl) |= hiword(fix64) >> (Ebits + 1);
83
          word1(ldbl) |= loword(fix64) >> (Ebits + 1);
84
        }
85
    }
86
 
87
  /* convert long double to character */
88
  return _simdldtoa_r (rptr, &ldbl, mode, ndigits, decpt, sign, rve);
89
}
90
 
91
#endif /* __SPE__ */

powered by: WebSVN 2.1.0

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