Subversion Repositories HelenOS-historic

Rev

Rev 811 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 811 Rev 1196
Line 63... Line 63...
63
 
63
 
64
    return result;
64
    return result;
65
}
65
}
66
 
66
 
67
 
67
 
68
static unsigned long divandmod64(unsigned long a, unsigned long b, unsigned long *remainder)
68
static unsigned long long divandmod64(unsigned long long a, unsigned long long b, unsigned long long *remainder)
69
{
69
{
70
    unsigned long result;
70
    unsigned long long result;
71
    int steps = sizeof(unsigned long) * 8;
71
    int steps = sizeof(unsigned long long) * 8;
72
   
72
   
73
    *remainder = 0;
73
    *remainder = 0;
74
    result = 0;
74
    result = 0;
75
   
75
   
76
    if (b == 0) {
76
    if (b == 0) {
Line 109... Line 109...
109
    if ( SGN(a) == SGN(b)) return result;
109
    if ( SGN(a) == SGN(b)) return result;
110
    return -result;
110
    return -result;
111
}
111
}
112
 
112
 
113
/* 64bit integer division */
113
/* 64bit integer division */
114
long __divdi3(long a, long b)
114
long long __divdi3(long long a, long long b)
115
{
115
{
116
    unsigned long rem;
116
    unsigned long long rem;
117
    long result;
117
    long long result;
118
   
118
   
119
    result = (long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);
119
    result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);
120
 
120
 
121
    if ( SGN(a) == SGN(b)) return result;
121
    if ( SGN(a) == SGN(b)) return result;
122
    return -result;
122
    return -result;
123
}
123
}
124
 
124
 
Line 128... Line 128...
128
    unsigned int rem;
128
    unsigned int rem;
129
    return divandmod32(a, b, &rem);
129
    return divandmod32(a, b, &rem);
130
}
130
}
131
 
131
 
132
/* 64bit unsigned integer division */
132
/* 64bit unsigned integer division */
133
unsigned long __udivdi3(unsigned long a, unsigned long b)
133
unsigned long long __udivdi3(unsigned long long a, unsigned long long b)
134
{
134
{
135
    unsigned long rem;
135
    unsigned long long  rem;
136
    return divandmod64(a, b, &rem);
136
    return divandmod64(a, b, &rem);
137
}
137
}
138
 
138
 
139
/* 32bit remainder of the signed division */
139
/* 32bit remainder of the signed division */
140
int __modsi3(int a, int b)
140
int __modsi3(int a, int b)
Line 149... Line 149...
149
   
149
   
150
    return (int)rem;
150
    return (int)rem;
151
}
151
}
152
 
152
 
153
/* 64bit remainder of the signed division */
153
/* 64bit remainder of the signed division */
154
long __moddi3(long a, long b)
154
long long __moddi3(long long a,long  long b)
155
{
155
{
156
    unsigned long rem;
156
    unsigned long long rem;
157
    divandmod64(a, b, &rem);
157
    divandmod64(a, b, &rem);
158
   
158
   
159
    /* if divident is negative, remainder must be too */
159
    /* if divident is negative, remainder must be too */
160
    if (!(SGN(a))) {
160
    if (!(SGN(a))) {
161
        return -((long)rem);
161
        return -((long long)rem);
162
    }
162
    }
163
   
163
   
164
    return (long)rem;
164
    return (long long)rem;
165
}
165
}
166
 
166
 
167
/* 32bit remainder of the unsigned division */
167
/* 32bit remainder of the unsigned division */
168
unsigned int __umodsi3(unsigned int a, unsigned int b)
168
unsigned int __umodsi3(unsigned int a, unsigned int b)
169
{
169
{
Line 171... Line 171...
171
    divandmod32(a, b, &rem);
171
    divandmod32(a, b, &rem);
172
    return rem;
172
    return rem;
173
}
173
}
174
 
174
 
175
/* 64bit remainder of the unsigned division */
175
/* 64bit remainder of the unsigned division */
176
unsigned long __umoddi3(unsigned long a, unsigned long b)
176
unsigned long long __umoddi3(unsigned long long a, unsigned long long b)
177
{
177
{
178
    unsigned long rem;
178
    unsigned long long rem;
179
    divandmod64(a, b, &rem);
179
    divandmod64(a, b, &rem);
180
    return rem;
180
    return rem;
181
}
181
}
182
 
182
 
183
unsigned long __udivmoddi3(unsigned long a, unsigned long b, unsigned long *c)
183
unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c)
184
{
184
{
185
    return divandmod64(a, b, c);
185
    return divandmod64(a, b, c);
186
}
186
}
187
 
187
 
188
 
188