ldiv: Work around missing struct return feature.
* lib/mes/div.c (__mesabi_ldiv): Remove return type. (__mesabi_imod): Adapt call site. (__aeabi_idiv): Adapt call site and move it to conditional compilation. (__aeabi_idivmod): Adapt call site.
This commit is contained in:
parent
40aa190459
commit
3f03574050
|
@ -67,9 +67,9 @@ __mesabi_uldiv (unsigned long a, unsigned long b, unsigned long* remainder)
|
||||||
/* Note: Rounds towards zero.
|
/* Note: Rounds towards zero.
|
||||||
Maintainer: Be careful to satisfy quot * b + rem == a.
|
Maintainer: Be careful to satisfy quot * b + rem == a.
|
||||||
That means that rem can be negative. */
|
That means that rem can be negative. */
|
||||||
ldiv_t __mesabi_ldiv(long a, long b)
|
void
|
||||||
|
__mesabi_ldiv(long a, long b, ldiv_t* result)
|
||||||
{
|
{
|
||||||
ldiv_t result;
|
|
||||||
int negate_result = (a < 0) ^ (b < 0);
|
int negate_result = (a < 0) ^ (b < 0);
|
||||||
if (b == LONG_MIN)
|
if (b == LONG_MIN)
|
||||||
__mesabi_div0();
|
__mesabi_div0();
|
||||||
|
@ -80,22 +80,21 @@ ldiv_t __mesabi_ldiv(long a, long b)
|
||||||
a = -a;
|
a = -a;
|
||||||
if (b < 0)
|
if (b < 0)
|
||||||
b = -b;
|
b = -b;
|
||||||
result.quot = __mesabi_uldiv(a, b, &result.rem);
|
result->quot = __mesabi_uldiv(a, b, &result->rem);
|
||||||
if (negate_result)
|
if (negate_result)
|
||||||
result.quot = -result.quot;
|
result->quot = -result->quot;
|
||||||
if (negative_a)
|
if (negative_a)
|
||||||
result.rem = -result.rem;
|
result->rem = -result->rem;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result.rem = 0;
|
result->rem = 0;
|
||||||
if (b < 0)
|
if (b < 0)
|
||||||
b = -b;
|
b = -b;
|
||||||
if (b == 1)
|
if (b == 1)
|
||||||
{
|
{
|
||||||
result.quot = a;
|
result->quot = a;
|
||||||
/* Since result.quot is already negative, don't negate it again. */
|
/* Since result->quot is already negative, don't negate it again. */
|
||||||
negate_result = !negate_result;
|
negate_result = !negate_result;
|
||||||
}
|
}
|
||||||
else if (b == 0)
|
else if (b == 0)
|
||||||
|
@ -105,15 +104,32 @@ ldiv_t __mesabi_ldiv(long a, long b)
|
||||||
long x;
|
long x;
|
||||||
for (x = 0; a <= -b; a += b)
|
for (x = 0; a <= -b; a += b)
|
||||||
++x;
|
++x;
|
||||||
result.rem = a; /* negative */
|
result->rem = a; /* negative */
|
||||||
result.quot = x;
|
result->quot = x;
|
||||||
}
|
}
|
||||||
if (negate_result)
|
if (negate_result)
|
||||||
result.quot = -result.quot;
|
result->quot = -result->quot;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
__mesabi_imod (long a, long b)
|
||||||
|
{
|
||||||
|
ldiv_t result;
|
||||||
|
__mesabi_ldiv(a, b, &result);
|
||||||
|
return result.rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if !SYSTEM_LIBC && __arm__
|
||||||
|
long
|
||||||
|
__aeabi_idiv (long a, long b)
|
||||||
|
{
|
||||||
|
ldiv_t result;
|
||||||
|
__mesabi_ldiv(a, b, &result);
|
||||||
|
return result.quot;
|
||||||
|
}
|
||||||
|
#endif // !SYSTEM_LIBC && __arm__
|
||||||
|
|
||||||
#if __GNUC__ && !SYSTEM_LIBC && __arm__
|
#if __GNUC__ && !SYSTEM_LIBC && __arm__
|
||||||
// ...-binutils-2.31.1/bin/ld: hash.o: in function `hash_cstring':
|
// ...-binutils-2.31.1/bin/ld: hash.o: in function `hash_cstring':
|
||||||
// hash.c:(.text+0x56): undefined reference to `__aeabi_idivmod'
|
// hash.c:(.text+0x56): undefined reference to `__aeabi_idivmod'
|
||||||
|
@ -129,19 +145,13 @@ ldiv_t __mesabi_ldiv(long a, long b)
|
||||||
long
|
long
|
||||||
__aeabi_idivmod (long a, long b)
|
__aeabi_idivmod (long a, long b)
|
||||||
{
|
{
|
||||||
ldiv_t result = __mesabi_ldiv(a, b);
|
ldiv_t result;
|
||||||
|
__mesabi_ldiv(a, b, &result);
|
||||||
register long rem_result asm("r1");
|
register long rem_result asm("r1");
|
||||||
rem_result = result.rem;
|
rem_result = result.rem;
|
||||||
return result.quot;
|
return result.quot;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
|
||||||
__aeabi_idiv (long a, long b)
|
|
||||||
{
|
|
||||||
ldiv_t result = __mesabi_ldiv(a, b);
|
|
||||||
return result.quot;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Result: r0: quotient; r1: remainder */
|
/* Result: r0: quotient; r1: remainder */
|
||||||
unsigned long
|
unsigned long
|
||||||
__aeabi_uidivmod (unsigned long a, unsigned long b)
|
__aeabi_uidivmod (unsigned long a, unsigned long b)
|
||||||
|
|
Loading…
Reference in a new issue