From 1d41674dc1fdb0798729b4bd3beac2c44d189442 Mon Sep 17 00:00:00 2001 From: Myles Busig Date: Thu, 4 Apr 2024 04:18:36 -0600 Subject: [PATCH] Fix udiv100000 and udiv1000000000 ASM macros changing the source register --- include/{mtl/armv4t => armv4t/mtl}/asm/math.s | 15 ++++++++------- src/armv4t/math.s | 2 +- src/armv4t/to.s | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) rename include/{mtl/armv4t => armv4t/mtl}/asm/math.s (86%) diff --git a/include/mtl/armv4t/asm/math.s b/include/armv4t/mtl/asm/math.s similarity index 86% rename from include/mtl/armv4t/asm/math.s rename to include/armv4t/mtl/asm/math.s index a3f38b2..e3a5c30 100644 --- a/include/mtl/armv4t/asm/math.s +++ b/include/armv4t/mtl/asm/math.s @@ -41,12 +41,13 @@ * k = 17 * * This division uses the output produces by clang for a division by 100000. - * I don't understand why it works, but it does. + * I don't understand why it works, but it does. It also needs one extra + * temporary register to preserve the value of rx. */ -.macro udiv100000 rd, rx, rt - lsr \rx, $5 +.macro udiv100000 rd, rx, rt, rtt + lsr \rtt, \rx, $5 ldr \rt, =0xA7C5AC5 - umull \rt, \rd, \rx, \rt + umull \rt, \rd, \rtt, \rt lsrs \rd, $7 .endm @@ -71,10 +72,10 @@ /* * Same situation as udiv100000 */ -.macro udiv1000000000 rd, rx, rt - lsr \rx, $9 +.macro udiv1000000000 rd, rx, rt, rtt + lsr \rtt, \rx, $9 ldr \rt, =0x44B83 - umull \rt, \rd, \rx, \rt + umull \rt, \rd, \rtt, \rt lsrs \rd, $7 .endm diff --git a/src/armv4t/math.s b/src/armv4t/math.s index b7d33d9..6b21bae 100644 --- a/src/armv4t/math.s +++ b/src/armv4t/math.s @@ -1,6 +1,6 @@ .syntax unified -.include "mtl/armv4t/asm/math.s" +.include "mtl/asm/math.s" .section .iwram, "ax", %progbits .arm diff --git a/src/armv4t/to.s b/src/armv4t/to.s index 1546a23..98fb6e1 100644 --- a/src/armv4t/to.s +++ b/src/armv4t/to.s @@ -1,6 +1,6 @@ .syntax unified -.include "mtl/armv4t/asm/math.s" +.include "mtl/asm/math.s" .section .iwram, "ax", %progbits .arm @@ -133,7 +133,7 @@ push {r4-r6} add r3, $1 .Ldigits_10: // Divide by 10^9 to get the most significant digit - udiv1000000000 r5, r0, r12 + udiv1000000000 r5, r0, r12, r6 // Write the digit to the string add r6, r5, '0' strb r6, [r1], $1 @@ -164,7 +164,7 @@ push {r4-r6} mul r6, r5 sub r0, r6 .Ldigits_6: - udiv100000 r5, r0, r12 + udiv100000 r5, r0, r12, r6 add r6, r5, '0' strb r6, [r1], $1 ldr r6, =100000