mirror of
https://github.com/reactos/reactos.git
synced 2025-02-20 15:35:04 +00:00
[ARM/CRT] Refactor several functions (#3865)
- Make __fto64 function more readable - Call worker function directly for __rt_sdiv/udiv - Adapt __rt_sdiv64/udiv64 asm shims accordingly - Add header files to CMake source list CORE-17607 CORE-17614 CORE-17703 CORE-17604 Addendum tof2bc1f0e
,e448094e
and54406bf4
.
This commit is contained in:
parent
d7f13aa696
commit
be3c532bf4
12 changed files with 70 additions and 76 deletions
|
@ -2,8 +2,7 @@
|
|||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __dtoi64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
* COPYRIGHT: Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __fto64 __dtoi64
|
||||
|
@ -11,3 +10,5 @@
|
|||
#define _USE_SIGNED_
|
||||
|
||||
#include "__fto64.h"
|
||||
|
||||
/* __dtoi64 is implemented in __fto64.h */
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __dtou64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
* COPYRIGHT: Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __fto64 __dtou64
|
||||
#define _USE_64_BITS_
|
||||
|
||||
#include "__fto64.h"
|
||||
|
||||
/* __dtou64 is implemented in __fto64.h */
|
||||
|
|
|
@ -23,6 +23,12 @@ unsigned
|
|||
#endif
|
||||
long long FTO64_RESULT;
|
||||
|
||||
typedef union _FTO64_UNION
|
||||
{
|
||||
FLOAT_TYPE value;
|
||||
FINT_TYPE raw;
|
||||
} FTO64_UNION;
|
||||
|
||||
#define SIGN_MASK (((FINT_TYPE)1) << (FRACTION_LEN + EXPONENT_LEN))
|
||||
|
||||
#define FRACTION_ONE (((FINT_TYPE)1) << FRACTION_LEN)
|
||||
|
@ -44,18 +50,14 @@ long long FTO64_RESULT;
|
|||
#define NEGATE(x) (~(x) + 1)
|
||||
|
||||
FTO64_RESULT
|
||||
__fto64(FLOAT_TYPE value)
|
||||
__fto64(FLOAT_TYPE fvalue)
|
||||
{
|
||||
union {
|
||||
FLOAT_TYPE val_float;
|
||||
FINT_TYPE val_int;
|
||||
} u;
|
||||
FTO64_UNION u = { .value = fvalue };
|
||||
FINT_TYPE value = u.raw;
|
||||
int exponent;
|
||||
FTO64_RESULT fraction;
|
||||
|
||||
u.val_float = value;
|
||||
|
||||
exponent = (int)(u.val_int >> FRACTION_LEN);
|
||||
exponent = (int)(value >> FRACTION_LEN);
|
||||
exponent &= EXPONENT_MASK;
|
||||
|
||||
/* infinity and other NaNs */
|
||||
|
@ -77,11 +79,11 @@ __fto64(FLOAT_TYPE value)
|
|||
return INTNAN;
|
||||
|
||||
#ifndef _USE_SIGNED_
|
||||
if (u.val_int & SIGN_MASK)
|
||||
if (value & SIGN_MASK)
|
||||
return INTNAN;
|
||||
#endif
|
||||
|
||||
fraction = u.val_int & FRACTION_MASK;
|
||||
fraction = value & FRACTION_MASK;
|
||||
fraction |= FRACTION_ONE;
|
||||
|
||||
exponent -= FRACTION_LEN;
|
||||
|
@ -94,7 +96,7 @@ __fto64(FLOAT_TYPE value)
|
|||
}
|
||||
|
||||
#ifdef _USE_SIGNED_
|
||||
if (u.val_int & SIGN_MASK)
|
||||
if (value & SIGN_MASK)
|
||||
fraction = NEGATE(fraction);
|
||||
#endif
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __rt_div_worker
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -20,10 +20,16 @@
|
|||
#ifdef _USE_64_BITS_
|
||||
typedef unsigned long long UINT3264;
|
||||
typedef long long INT3264;
|
||||
typedef struct
|
||||
{
|
||||
unsigned long long quotient; /* to be returned in R0,R1 */
|
||||
unsigned long long modulus; /* to be returned in R2,R3 */
|
||||
} RETURN_TYPE;
|
||||
#define _CountLeadingZeros _CountLeadingZeros64
|
||||
#else
|
||||
typedef unsigned int UINT3264;
|
||||
typedef int INT3264;
|
||||
typedef unsigned long long RETURN_TYPE; /* to be returned in R0,R1 */
|
||||
#endif
|
||||
|
||||
__forceinline
|
||||
|
@ -35,27 +41,20 @@ __brkdiv0(void)
|
|||
|
||||
typedef union _ARM_DIVRESULT
|
||||
{
|
||||
#ifdef _USE_64_BITS_
|
||||
unsigned int raw_data[4];
|
||||
#else
|
||||
unsigned long long raw_data;
|
||||
#endif
|
||||
RETURN_TYPE raw_data;
|
||||
struct
|
||||
{
|
||||
UINT3264 quotient; /* to be returned in R0(R0,R1) */
|
||||
UINT3264 modulus; /* to be returned in R1(R2,R3) */
|
||||
UINT3264 quotient;
|
||||
UINT3264 modulus;
|
||||
} data;
|
||||
} ARM_DIVRESULT;
|
||||
|
||||
#ifndef _USE_64_BITS_
|
||||
__forceinline
|
||||
#endif
|
||||
void
|
||||
RETURN_TYPE
|
||||
__rt_div_worker(
|
||||
UINT3264 divisor,
|
||||
UINT3264 dividend,
|
||||
ARM_DIVRESULT* result)
|
||||
UINT3264 dividend)
|
||||
{
|
||||
ARM_DIVRESULT result;
|
||||
UINT3264 shift;
|
||||
UINT3264 mask;
|
||||
UINT3264 quotient;
|
||||
|
@ -86,13 +85,13 @@ __rt_div_worker(
|
|||
|
||||
if (divisor > dividend)
|
||||
{
|
||||
result->data.quotient = 0;
|
||||
result.data.quotient = 0;
|
||||
#ifdef _SIGNED_DIV_
|
||||
if (dividend_sign)
|
||||
dividend = -(INT3264)dividend;
|
||||
#endif // _SIGNED_DIV_
|
||||
result->data.modulus = dividend;
|
||||
return;
|
||||
result.data.modulus = dividend;
|
||||
return result.raw_data;
|
||||
}
|
||||
|
||||
/* Get the difference in count of leading zeros between dividend and divisor */
|
||||
|
@ -130,6 +129,7 @@ __rt_div_worker(
|
|||
}
|
||||
#endif // _SIGNED_DIV_
|
||||
|
||||
result->data.quotient = quotient;
|
||||
result->data.modulus = dividend;
|
||||
result.data.quotient = quotient;
|
||||
result.data.modulus = dividend;
|
||||
return result.raw_data;
|
||||
}
|
||||
|
|
|
@ -3,25 +3,12 @@
|
|||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __rt_sdiv
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __rt_div_worker __rt_sdiv_worker
|
||||
#define __rt_div_worker __rt_sdiv
|
||||
#define _SIGNED_DIV_
|
||||
|
||||
#include "__rt_div_worker.h"
|
||||
|
||||
/*
|
||||
* Returns quotient in R0, remainder in R1
|
||||
*/
|
||||
long long
|
||||
__rt_sdiv(
|
||||
int divisor,
|
||||
int dividend)
|
||||
{
|
||||
ARM_DIVRESULT result;
|
||||
|
||||
__rt_sdiv_worker(divisor, dividend, &result);
|
||||
|
||||
return result.raw_data;
|
||||
}
|
||||
/* __rt_sdiv is implemented in __rt_div_worker.h */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __rt_sdiv64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
@ -28,12 +28,17 @@
|
|||
push {lr}
|
||||
sub sp,sp,0x10
|
||||
mov r12,sp
|
||||
push {r12}
|
||||
push {r2,r3}
|
||||
PROLOG_END
|
||||
|
||||
/* r0 = ret*, r2:r3 = divisor, [sp] = dividend */
|
||||
mov r3,r1
|
||||
mov r2,r0
|
||||
mov r0,r12
|
||||
|
||||
/* Call the C worker function */
|
||||
bl __rt_sdiv64_worker
|
||||
add sp,sp,0x04
|
||||
add sp,sp,0x08
|
||||
|
||||
/* Move result data into the appropriate registers and return */
|
||||
pop {r0,r1,r2,r3,pc}
|
||||
|
|
|
@ -3,24 +3,11 @@
|
|||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __rt_udiv
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __rt_div_worker __rt_udiv_worker
|
||||
#define __rt_div_worker __rt_udiv
|
||||
|
||||
#include "__rt_div_worker.h"
|
||||
|
||||
/*
|
||||
* Returns quotient in R0, remainder in R1
|
||||
*/
|
||||
unsigned long long
|
||||
__rt_udiv(
|
||||
unsigned int divisor,
|
||||
unsigned int dividend)
|
||||
{
|
||||
ARM_DIVRESULT result;
|
||||
|
||||
__rt_udiv_worker(divisor, dividend, &result);
|
||||
|
||||
return result.raw_data;
|
||||
}
|
||||
/* __rt_udiv is implemented in __rt_div_worker.h */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __rt_udiv64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Raman Masanin <36927roma@gmail.com>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
/* INCLUDES ******************************************************************/
|
||||
|
@ -28,12 +28,17 @@
|
|||
push {lr}
|
||||
sub sp,sp,0x10
|
||||
mov r12,sp
|
||||
push {r12}
|
||||
push {r2,r3}
|
||||
PROLOG_END
|
||||
|
||||
/* r0 = ret*, r2:r3 = divisor, [sp] = dividend */
|
||||
mov r3,r1
|
||||
mov r2,r0
|
||||
mov r0,r12
|
||||
|
||||
/* Call the C worker function */
|
||||
bl __rt_udiv64_worker
|
||||
add sp,sp,0x04
|
||||
add sp,sp,0x08
|
||||
|
||||
/* Move result data into the appropriate registers and return */
|
||||
pop {r0,r1,r2,r3,pc}
|
||||
|
|
|
@ -2,11 +2,12 @@
|
|||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __stoi64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
* COPYRIGHT: Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __fto64 __stoi64
|
||||
#define _USE_SIGNED_
|
||||
|
||||
#include "__fto64.h"
|
||||
|
||||
/* __stoi64 is implemented in __fto64.h */
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
* PROJECT: ReactOS CRT library
|
||||
* LICENSE: MIT (https://spdx.org/licenses/MIT)
|
||||
* PURPOSE: Implementation of __stou64
|
||||
* COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer@reactos.org>
|
||||
* Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
* COPYRIGHT: Copyright 2021 Roman Masanin <36927roma@gmail.com>
|
||||
*/
|
||||
|
||||
#define __fto64 __stou64
|
||||
|
||||
#include "__fto64.h"
|
||||
|
||||
/* __stou64 is implemented in __fto64.h */
|
||||
|
|
|
@ -79,10 +79,12 @@ elseif(ARCH STREQUAL "arm")
|
|||
math/arm/__rt_sdiv64_worker.c
|
||||
math/arm/__rt_udiv.c
|
||||
math/arm/__rt_udiv64_worker.c
|
||||
math/arm/__rt_div_worker.h
|
||||
math/arm/__dtoi64.c
|
||||
math/arm/__dtou64.c
|
||||
math/arm/__stoi64.c
|
||||
math/arm/__stou64.c
|
||||
math/arm/__fto64.h
|
||||
)
|
||||
list(APPEND CRT_MATH_SOURCE
|
||||
math/fabsf.c
|
||||
|
|
|
@ -72,10 +72,12 @@ elseif(ARCH STREQUAL "arm")
|
|||
math/arm/__rt_sdiv64_worker.c
|
||||
math/arm/__rt_udiv.c
|
||||
math/arm/__rt_udiv64_worker.c
|
||||
math/arm/__rt_div_worker.h
|
||||
math/arm/__dtoi64.c
|
||||
math/arm/__dtou64.c
|
||||
math/arm/__stoi64.c
|
||||
math/arm/__stou64.c
|
||||
math/arm/__fto64.h
|
||||
)
|
||||
list(APPEND MSVCRTEX_ASM_SOURCE
|
||||
except/arm/chkstk_asm.s
|
||||
|
|
Loading…
Reference in a new issue