https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f2bc1f0e11187e84230fb3...
commit f2bc1f0e11187e84230fb3319f7b6a281b8d2ffa Author: Roman Masanin 52833910+theR4K@users.noreply.github.com AuthorDate: Sat Jul 24 21:23:58 2021 +0300 Commit: GitHub noreply@github.com CommitDate: Sat Jul 24 20:23:58 2021 +0200
__rt_div fixes for arm (#3843)
[CRT/arm] Fix __rt_udiv and __rt_sdiv --- sdk/lib/crt/math/arm/__rt_div_worker.h | 27 +++++++++++++++++---------- sdk/lib/crt/math/arm/__rt_sdiv.c | 7 ++++--- sdk/lib/crt/math/arm/__rt_sdiv64.s | 15 +++++++-------- sdk/lib/crt/math/arm/__rt_udiv.c | 7 ++++--- sdk/lib/crt/math/arm/__rt_udiv64.s | 15 +++++++-------- 5 files changed, 39 insertions(+), 32 deletions(-)
diff --git a/sdk/lib/crt/math/arm/__rt_div_worker.h b/sdk/lib/crt/math/arm/__rt_div_worker.h index 2aef926d0d9..035b3abd045 100644 --- a/sdk/lib/crt/math/arm/__rt_div_worker.h +++ b/sdk/lib/crt/math/arm/__rt_div_worker.h @@ -25,10 +25,18 @@ __brkdiv0(void) __emit(0xDEF9); }
-typedef struct _ARM_DIVRESULT +typedef union _ARM_DIVRESULT { - UINT3264 quotient; /* to be returned in R0 */ - UINT3264 modulus; /* to be returned in R1 */ +#ifdef _USE_64_BITS_ + unsigned int raw_data[4]; +#else + unsigned long long raw_data; +#endif + struct + { + UINT3264 quotient; /* to be returned in R0(R0,R1) */ + UINT3264 modulus; /* to be returned in R1(R2,R3) */ + } data; } ARM_DIVRESULT;
#ifndef _USE_64_BITS_ @@ -36,9 +44,9 @@ __forceinline #endif void __rt_div_worker( - ARM_DIVRESULT *result, UINT3264 divisor, - UINT3264 dividend) + UINT3264 dividend, + ARM_DIVRESULT* result) { UINT3264 shift; UINT3264 mask; @@ -70,8 +78,8 @@ __rt_div_worker(
if (divisor > dividend) { - result->quotient = 0; - result->modulus = divisor; + result->data.quotient = 0; + result->data.modulus = divisor; return; }
@@ -110,7 +118,6 @@ __rt_div_worker( } #endif // _SIGNED_DIV_
- result->quotient = quotient; - result->modulus = dividend; - return; + result->data.quotient = quotient; + result->data.modulus = dividend; } diff --git a/sdk/lib/crt/math/arm/__rt_sdiv.c b/sdk/lib/crt/math/arm/__rt_sdiv.c index dea2b30e326..302cec422a4 100644 --- a/sdk/lib/crt/math/arm/__rt_sdiv.c +++ b/sdk/lib/crt/math/arm/__rt_sdiv.c @@ -13,14 +13,15 @@
#include "__rt_div_worker.h"
-ARM_DIVRESULT +unsigned long long __rt_sdiv( int divisor, int dividend) { ARM_DIVRESULT result;
- __rt_sdiv_worker(&result, divisor, dividend); - return result; + __rt_sdiv_worker(divisor, dividend, &result); + + return result.raw_data; }
diff --git a/sdk/lib/crt/math/arm/__rt_sdiv64.s b/sdk/lib/crt/math/arm/__rt_sdiv64.s index c5ea8bb15ed..d3515a79729 100644 --- a/sdk/lib/crt/math/arm/__rt_sdiv64.s +++ b/sdk/lib/crt/math/arm/__rt_sdiv64.s @@ -18,19 +18,18 @@ NESTED_ENTRY __rt_sdiv64
/* Allocate stack space and store parameters there */ - stmdb sp!,{r0,r1,r2,r3,lr} + push {lr} + sub sp,sp,0x10 + mov r12,sp + push {r12} PROLOG_END
- /* Load pointer to stack structure into R0 */ - mov r0, sp - /* Call the C worker function */ - adr lr, Return - b __rt_sdiv64_worker + bl __rt_sdiv64_worker + add sp,sp,0x04
-Return /* Move result data into the appropriate registers and return */ - ldmia sp!,{r0,r1,r2,r3,pc} + pop {r0,r1,r2,r3,pc} NESTED_END __rt_sdiv64
END diff --git a/sdk/lib/crt/math/arm/__rt_udiv.c b/sdk/lib/crt/math/arm/__rt_udiv.c index 0d047e3c66a..2f47697d8ff 100644 --- a/sdk/lib/crt/math/arm/__rt_udiv.c +++ b/sdk/lib/crt/math/arm/__rt_udiv.c @@ -11,14 +11,15 @@
#include "__rt_div_worker.h"
-ARM_DIVRESULT +unsigned long long __rt_udiv( unsigned int divisor, unsigned int dividend) { ARM_DIVRESULT result;
- __rt_udiv_worker(&result, divisor, dividend); - return result; + __rt_udiv_worker(divisor, dividend, &result); + + return result.raw_data; }
diff --git a/sdk/lib/crt/math/arm/__rt_udiv64.s b/sdk/lib/crt/math/arm/__rt_udiv64.s index 07c90bce81c..d08a02fc463 100644 --- a/sdk/lib/crt/math/arm/__rt_udiv64.s +++ b/sdk/lib/crt/math/arm/__rt_udiv64.s @@ -18,19 +18,18 @@ NESTED_ENTRY __rt_udiv64
/* Allocate stack space and store parameters there */ - stmdb sp!,{r0,r1,r2,r3,lr} + push {lr} + sub sp,sp,0x10 + mov r12,sp + push {r12} PROLOG_END
- /* Load pointer to stack structure into R0 */ - mov r0, sp - /* Call the C worker function */ - adr lr, Return - b __rt_udiv64_worker + bl __rt_udiv64_worker + add sp,sp,0x04
-Return /* Move result data into the appropriate registers and return */ - ldmia sp!,{r0,r1,r2,r3,pc} + pop {r0,r1,r2,r3,pc} NESTED_END __rt_udiv64
END