* 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
#define _USE_SIGNED_
#include "__fto64.h"
+
+/* __dtoi64 is implemented in __fto64.h */
* 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 */
#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)
#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 */
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;
}
#ifdef _USE_SIGNED_
- if (u.val_int & SIGN_MASK)
+ if (value & SIGN_MASK)
fraction = NEGATE(fraction);
#endif
* 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>
*/
/*
#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
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;
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 */
}
#endif // _SIGNED_DIV_
- result->data.quotient = quotient;
- result->data.modulus = dividend;
+ result.data.quotient = quotient;
+ result.data.modulus = dividend;
+ return result.raw_data;
}
* 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 */
* 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 ******************************************************************/
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}
* 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 */
* 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 ******************************************************************/
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}
* 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 */
* 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 */
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
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