Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2505 → Rev 2504

/trunk/kernel/genarch/src/softint/division.c
34,11 → 34,10
 
#include <genarch/softint/division.h>
 
#define ABSVAL(x) ((x) > 0 ? (x) : -(x))
#define SGN(x) ((x) >= 0 ? 1 : 0)
#define ABSVAL(x) ( (x) > 0 ? (x) : -(x))
#define SGN(x) ( (x) >= 0 ? 1 : 0 )
static unsigned int divandmod32(unsigned int a, unsigned int b,
unsigned int *remainder)
static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder)
{
unsigned int result;
int steps = sizeof(unsigned int) * 8;
51,19 → 50,19
return 0;
}
if (a < b) {
if ( a < b) {
*remainder = a;
return 0;
}
 
for (; steps > 0; steps--) {
for ( ; steps > 0; steps--) {
/* shift one bit to remainder */
*remainder = ((*remainder) << 1) | (( a >> 31) & 0x1);
*remainder = ( (*remainder) << 1) | (( a >> 31) & 0x1);
result <<= 1;
if (*remainder >= b) {
*remainder -= b;
result |= 0x1;
*remainder -= b;
result |= 0x1;
}
a <<= 1;
}
72,8 → 71,7
}
 
 
static unsigned long long divandmod64(unsigned long long a,
unsigned long long b, unsigned long long *remainder)
static unsigned long long divandmod64(unsigned long long a, unsigned long long b, unsigned long long *remainder)
{
unsigned long long result;
int steps = sizeof(unsigned long long) * 8;
86,19 → 84,19
return 0;
}
if (a < b) {
if ( a < b) {
*remainder = a;
return 0;
}
 
for (; steps > 0; steps--) {
for ( ; steps > 0; steps--) {
/* shift one bit to remainder */
*remainder = ((*remainder) << 1) | ((a >> 63) & 0x1);
*remainder = ( (*remainder) << 1) | ((a >> 63) & 0x1);
result <<= 1;
if (*remainder >= b) {
*remainder -= b;
result |= 0x1;
*remainder -= b;
result |= 0x1;
}
a <<= 1;
}
112,10 → 110,9
unsigned int rem;
int result;
result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem);
result = (int)divandmod32(ABSVAL(a), ABSVAL(b), &rem);
 
if (SGN(a) == SGN(b))
return result;
if ( SGN(a) == SGN(b)) return result;
return -result;
}
 
125,10 → 122,9
unsigned long long rem;
long long result;
result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem);
result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);
 
if (SGN(a) == SGN(b))
return result;
if ( SGN(a) == SGN(b)) return result;
return -result;
}
 
154,10 → 150,10
/* if divident is negative, remainder must be too */
if (!(SGN(a))) {
return -((int) rem);
return -((int)rem);
}
return (int) rem;
return (int)rem;
}
 
/* 64bit remainder of the signed division */
168,10 → 164,10
/* if divident is negative, remainder must be too */
if (!(SGN(a))) {
return -((long long) rem);
return -((long long)rem);
}
return (long long) rem;
return (long long)rem;
}
 
/* 32bit remainder of the unsigned division */
190,8 → 186,7
return rem;
}
 
unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b,
unsigned long long *c)
unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c)
{
return divandmod64(a, b, c);
}