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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [machine/] [w65/] [divsi3.c] - Blame information for rev 816

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
 
2
#define divnorm(num, den, sign)                 \
3
{                                               \
4
  if (num < 0)                                   \
5
    {                                           \
6
      num = -num;                               \
7
      sign = 1;                                 \
8
    }                                           \
9
  else                                          \
10
    {                                           \
11
      sign = 0;                                  \
12
    }                                           \
13
                                                \
14
  if (den < 0)                                   \
15
    {                                           \
16
      den = - den;                              \
17
      sign = 1 - sign;                          \
18
    }                                           \
19
}
20
 
21
 
22
 
23
 
24
 
25
static unsigned long
26
divmodsi4(int modwanted, unsigned long num, unsigned long den)
27
{
28
  long int bit = 1;
29
  long int res = 0;
30
  long prevden;
31
  while (den < num && bit && !(den & (1L<<31)))
32
    {
33
      den <<=1;
34
      bit <<=1;
35
    }
36
  while (bit)
37
    {
38
      if (num >= den)
39
        {
40
          num -= den;
41
          res |= bit;
42
        }
43
      bit >>=1;
44
      den >>=1;
45
    }
46
  if (modwanted) return num;
47
  return res;
48
}
49
 
50
 
51
#define exitdiv(sign, res) if (sign) { res = - res;} return res;
52
 
53
long
54
__modsi3 (long numerator, long denominator)
55
{
56
  int sign = 0;
57
  long dividend;
58
  long modul;
59
 
60
 
61
  if (numerator < 0)
62
    {
63
      numerator = -numerator;
64
      sign = 1;
65
    }
66
  if (denominator < 0)
67
    {
68
      denominator = -denominator;
69
    }
70
 
71
  modul =  divmodsi4 (1, numerator, denominator);
72
  if (sign)
73
    return - modul;
74
  return modul;
75
}
76
 
77
 
78
long
79
__divsi3 (long numerator, long denominator)
80
{
81
  int sign;
82
  long dividend;
83
  long modul;
84
  divnorm (numerator, denominator, sign);
85
 
86
  dividend = divmodsi4 (0,  numerator, denominator);
87
  exitdiv (sign, dividend);
88
}
89
 
90
long
91
__umodsi3 (unsigned long numerator, unsigned long denominator)
92
{
93
  long dividend;
94
  long modul;
95
 
96
modul= divmodsi4 (1,  numerator, denominator);
97
  return modul;
98
}
99
 
100
long
101
__udivsi3 (unsigned long numerator, unsigned long denominator)
102
{
103
  int sign;
104
  long dividend;
105
  long modul;
106
  dividend =   divmodsi4 (0, numerator, denominator);
107
  return dividend;
108
}
109
 
110
 
111
 
112
 
113
 
114
 
115
#ifdef TEST
116
 
117
 
118
 
119
main ()
120
{
121
  long int i, j, k, m;
122
  for (i = -10000; i < 10000; i += 8)
123
    {
124
      for (j = -10000; j < 10000; j += 11)
125
        {
126
          k = i / j;
127
          m = __divsi3 (i, j);
128
          if (k != m)
129
            printf ("fail %d %d %d %d\n", i, j, k, m);
130
        }
131
    }
132
}
133
 
134
#endif

powered by: WebSVN 2.1.0

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