From 9a84e94a0a2d909cf5e87ba8ff49de8066d589ee Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Mon, 11 Mar 2019 19:33:53 +0100 Subject: [PATCH] ARM: Return both the quotient and the remainder. * lib/mes/div.c (__aeabi_idivmod): Use ldiv. Return both quotient and remainder. (__aeabi_uidivmod): Use __mesabi_uldiv. Return both quotient and remainder. --- lib/mes/div.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/mes/div.c b/lib/mes/div.c index 154ffb45..0712ac9b 100644 --- a/lib/mes/div.c +++ b/lib/mes/div.c @@ -119,11 +119,14 @@ ldiv_t ldiv(long a, long b) // /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: gcc-lib/libc.a(ntoab.o): in function `ntoab': // ntoab.c:(.text+0x54): undefined reference to `__aeabi_uidivmod' // /gnu/store/7sfr3vhxq7l4mai8m0fr1cd8w9xcj9dh-binutils-2.31.1/bin/ld: ntoab.c:(.text+0x62): undefined reference to `__aeabi_uidiv' +/* Result: r0: quotient; r1: remainder */ long __aeabi_idivmod (long a, long b) { ldiv_t result = ldiv(a, b); - return result.rem; + register long rem_result asm("r1"); + rem_result = result.rem; + return result.quot; } long @@ -133,12 +136,22 @@ __aeabi_idiv (long a, long b) return result.quot; } +typedef struct +{ + unsigned long quot; + unsigned long rem; +} uidiv_t; + +/* Result: r0: quotient; r1: remainder */ unsigned long __aeabi_uidivmod (unsigned long a, unsigned long b) { - unsigned long remainder; - __mesabi_uldiv (a, b, &remainder); - return remainder; + unsigned long quot; + unsigned long rem; + register unsigned long rem_result asm("r1"); + quot = __mesabi_uldiv (a, b, &rem); + rem_result = rem; + return quot; } unsigned long