https://git.reactos.org/?p=reactos.git;a=commitdiff;h=e448094e741708bb65005…
commit e448094e741708bb65005549d76bf15f952ea6db
Author: Roman Masanin <36927roma(a)gmail.com>
AuthorDate: Sun Jul 25 17:50:48 2021 +0300
Commit: Stanislav Motylkov <x86corez(a)gmail.com>
CommitDate: Fri Jul 30 14:20:23 2021 +0300
[CRT/ARM] Implement __dtoi64/dtou64/stoi64/stou64 functions (#3848)
CORE-17703 CORE-17604
---
sdk/lib/crt/math/arm/__dtoi64.s | 26 +++++++--
sdk/lib/crt/math/arm/__dtoi64_worker.c | 14 +++++
sdk/lib/crt/math/arm/__dtou64.s | 26 +++++++--
sdk/lib/crt/math/arm/__dtou64_worker.c | 13 +++++
sdk/lib/crt/math/arm/__fto64_worker.h | 102 +++++++++++++++++++++++++++++++++
sdk/lib/crt/math/arm/__stoi64.s | 25 ++++++--
sdk/lib/crt/math/arm/__stoi64_worker.c | 13 +++++
sdk/lib/crt/math/arm/__stou64.s | 25 ++++++--
sdk/lib/crt/math/arm/__stou64_worker.c | 12 ++++
sdk/lib/crt/math/math.cmake | 4 ++
sdk/lib/crt/msvcrtex.cmake | 4 ++
11 files changed, 240 insertions(+), 24 deletions(-)
diff --git a/sdk/lib/crt/math/arm/__dtoi64.s b/sdk/lib/crt/math/arm/__dtoi64.s
index 172d60f9f17..9e7e4cb7d74 100644
--- a/sdk/lib/crt/math/arm/__dtoi64.s
+++ b/sdk/lib/crt/math/arm/__dtoi64.s
@@ -1,23 +1,37 @@
/*
- * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
- * PROJECT: ReactOS CRT library
- * PURPOSE: Implementation of __dtoi64
- * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __dtoi64
+ * COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ * Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
*/
/* INCLUDES ******************************************************************/
#include <kxarm.h>
+ IMPORT __dtoi64_worker
+
/* CODE **********************************************************************/
TEXTAREA
+ /*
+ IN: d0 = double value
+ OUT: r1:r0 = int64 value
+ */
LEAF_ENTRY __dtoi64
+ /* Allocate stack space and store parameters there */
+ push {lr}
+ PROLOG_END
- __assertfail
- bx lr
+ /* Call the C worker function */
+ VMOV r0,d0[0]
+ VMOV r1,d0[1]
+ bl __dtoi64_worker
+ /* Move result data into the appropriate registers and return */
+ pop {pc}
LEAF_END __dtoi64
END
diff --git a/sdk/lib/crt/math/arm/__dtoi64_worker.c
b/sdk/lib/crt/math/arm/__dtoi64_worker.c
new file mode 100644
index 00000000000..beb247b24f5
--- /dev/null
+++ b/sdk/lib/crt/math/arm/__dtoi64_worker.c
@@ -0,0 +1,14 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __dtoi64_worker
+ * COPYRIGHT: Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
+ */
+
+#define __fto64_worker __dtoi64_worker
+#define _USE_64_BITS_
+#define _USE_SIGNED_
+
+#include "__fto64_worker.h"
+
+/* __dtoi64 is implemented in __dtoi64.s */
diff --git a/sdk/lib/crt/math/arm/__dtou64.s b/sdk/lib/crt/math/arm/__dtou64.s
index 03fd67b6b04..d204525a130 100644
--- a/sdk/lib/crt/math/arm/__dtou64.s
+++ b/sdk/lib/crt/math/arm/__dtou64.s
@@ -1,23 +1,37 @@
/*
- * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
- * PROJECT: ReactOS CRT library
- * PURPOSE: Implementation of __dtou64
- * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __dtou64
+ * COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ * Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
*/
/* INCLUDES ******************************************************************/
#include <kxarm.h>
+ IMPORT __dtou64_worker
+
/* CODE **********************************************************************/
TEXTAREA
+ /*
+ IN: d0 = double value
+ OUT: r1:r0 = uint64 value
+ */
LEAF_ENTRY __dtou64
+ /* Allocate stack space and store parameters there */
+ push {lr}
+ PROLOG_END
- __assertfail
- bx lr
+ /* Call the C worker function */
+ VMOV r0,d0[0]
+ VMOV r1,d0[1]
+ bl __dtou64_worker
+ /* Move result data into the appropriate registers and return */
+ pop {pc}
LEAF_END __dtou64
END
diff --git a/sdk/lib/crt/math/arm/__dtou64_worker.c
b/sdk/lib/crt/math/arm/__dtou64_worker.c
new file mode 100644
index 00000000000..432bd5df7f0
--- /dev/null
+++ b/sdk/lib/crt/math/arm/__dtou64_worker.c
@@ -0,0 +1,13 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __dtou64_worker
+ * COPYRIGHT: Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
+ */
+
+#define __fto64_worker __dtou64_worker
+#define _USE_64_BITS_
+
+#include "__fto64_worker.h"
+
+/* __dtou64 is implemented in __dtou64.s */
diff --git a/sdk/lib/crt/math/arm/__fto64_worker.h
b/sdk/lib/crt/math/arm/__fto64_worker.h
new file mode 100644
index 00000000000..e5e77b1665b
--- /dev/null
+++ b/sdk/lib/crt/math/arm/__fto64_worker.h
@@ -0,0 +1,102 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __dtoi64
+ * COPYRIGHT: Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
+ */
+
+#ifdef _USE_64_BITS_
+typedef double FLOAT_TYPE;
+typedef unsigned long long FINT_TYPE;
+#define FRACTION_LEN 52
+#define EXPONENT_LEN 11
+#else
+typedef float FLOAT_TYPE;
+typedef unsigned int FINT_TYPE;
+#define FRACTION_LEN 23
+#define EXPONENT_LEN 8
+#endif
+
+typedef
+#ifndef _USE_SIGNED_
+unsigned
+#endif
+long long FTO64_RESULT;
+
+#define SIGN_MASK (((FINT_TYPE)1) << (FRACTION_LEN + EXPONENT_LEN))
+
+#define FRACTION_ONE (((FINT_TYPE)1) << FRACTION_LEN)
+#define FRACTION_MASK ((FRACTION_ONE) - 1)
+
+#define EXPONENT_MASK ((1 << EXPONENT_LEN) - 1)
+#define EXPONENT_ZERO ((1 << (EXPONENT_LEN - 1)) - 1)
+
+#ifdef _USE_SIGNED_
+#define EXPONENT_MAX 62
+#define INTNAN 0x8000000000000000ULL
+#else
+#define EXPONENT_MAX 63
+#define INTNAN 0xFFFFFFFFFFFFFFFFULL
+#endif
+
+#define EXPONENT_INFINITY EXPONENT_MASK
+
+#define NEGATE(x) (~(x) + 1)
+
+FTO64_RESULT
+__fto64_worker(FLOAT_TYPE value)
+{
+ union {
+ FLOAT_TYPE val_float;
+ FINT_TYPE val_int;
+ } u;
+ int exponent;
+ FTO64_RESULT fraction;
+
+ u.val_float = value;
+
+ exponent = (int)(u.val_int >> FRACTION_LEN);
+ exponent &= EXPONENT_MASK;
+
+ /* infinity and other NaNs */
+ if (exponent == EXPONENT_INFINITY)
+ return INTNAN;
+
+ /* subnormals and signed zeros */
+ if (exponent == 0)
+ return 0;
+
+ exponent -= EXPONENT_ZERO;
+
+ /* number is less then one */
+ if (exponent < 0)
+ return 0;
+
+ /* number is too big */
+ if (exponent > EXPONENT_MAX)
+ return INTNAN;
+
+#ifndef _USE_SIGNED_
+ if (u.val_int & SIGN_MASK)
+ return INTNAN;
+#endif
+
+ fraction = u.val_int & FRACTION_MASK;
+ fraction |= FRACTION_ONE;
+
+ exponent -= FRACTION_LEN;
+ if (exponent != 0)
+ {
+ if (exponent < 0)
+ fraction = fraction >> NEGATE(exponent);
+ else
+ fraction = fraction << exponent;
+ }
+
+#ifdef _USE_SIGNED_
+ if (u.val_int & SIGN_MASK)
+ fraction = NEGATE(fraction);
+#endif
+
+ return fraction;
+}
diff --git a/sdk/lib/crt/math/arm/__stoi64.s b/sdk/lib/crt/math/arm/__stoi64.s
index ab03260319e..636d35c9d9b 100644
--- a/sdk/lib/crt/math/arm/__stoi64.s
+++ b/sdk/lib/crt/math/arm/__stoi64.s
@@ -1,23 +1,36 @@
/*
- * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
- * PROJECT: ReactOS CRT library
- * PURPOSE: Implementation of __stoi64
- * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __stoi64
+ * COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ * Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
*/
/* INCLUDES ******************************************************************/
#include <kxarm.h>
+ IMPORT __stoi64_worker
+
/* CODE **********************************************************************/
TEXTAREA
+ /*
+ IN: s0 = single (float) value
+ OUT: r1:r0 = int64 value
+ */
LEAF_ENTRY __stoi64
+ /* Allocate stack space and store parameters there */
+ push {lr}
+ PROLOG_END
- __assertfail
- bx lr
+ /* Call the C worker function */
+ VMOV r0,s0
+ bl __stoi64_worker
+ /* Move result data into the appropriate registers and return */
+ pop {pc}
LEAF_END __stoi64
END
diff --git a/sdk/lib/crt/math/arm/__stoi64_worker.c
b/sdk/lib/crt/math/arm/__stoi64_worker.c
new file mode 100644
index 00000000000..d7beeb8d26b
--- /dev/null
+++ b/sdk/lib/crt/math/arm/__stoi64_worker.c
@@ -0,0 +1,13 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __stoi64_worker
+ * COPYRIGHT: Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
+ */
+
+#define __fto64_worker __stoi64_worker
+#define _USE_SIGNED_
+
+#include "__fto64_worker.h"
+
+/* __stoi64 is implemented in __stoi64.s */
diff --git a/sdk/lib/crt/math/arm/__stou64.s b/sdk/lib/crt/math/arm/__stou64.s
index 204be052167..eac8c64c9fc 100644
--- a/sdk/lib/crt/math/arm/__stou64.s
+++ b/sdk/lib/crt/math/arm/__stou64.s
@@ -1,23 +1,36 @@
/*
- * COPYRIGHT: BSD - See COPYING.ARM in the top level directory
- * PROJECT: ReactOS CRT library
- * PURPOSE: Implementation of __stou64
- * PROGRAMMER: Timo Kreuzer (timo.kreuzer(a)reactos.org)
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __stou64
+ * COPYRIGHT: Copyright 2015 Timo Kreuzer <timo.kreuzer(a)reactos.org>
+ * Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
*/
/* INCLUDES ******************************************************************/
#include <kxarm.h>
+ IMPORT __stou64_worker
+
/* CODE **********************************************************************/
TEXTAREA
+ /*
+ IN: s0 = single (float) value
+ OUT: r1:r0 = uint64 value
+ */
LEAF_ENTRY __stou64
+ /* Allocate stack space and store parameters there */
+ push {lr}
+ PROLOG_END
- __assertfail
- bx lr
+ /* Call the C worker function */
+ VMOV r0,s0
+ bl __stou64_worker
+ /* Move result data into the appropriate registers and return */
+ pop {pc}
LEAF_END __stou64
END
diff --git a/sdk/lib/crt/math/arm/__stou64_worker.c
b/sdk/lib/crt/math/arm/__stou64_worker.c
new file mode 100644
index 00000000000..b373da1ad84
--- /dev/null
+++ b/sdk/lib/crt/math/arm/__stou64_worker.c
@@ -0,0 +1,12 @@
+/*
+ * PROJECT: ReactOS CRT library
+ * LICENSE: MIT (
https://spdx.org/licenses/MIT)
+ * PURPOSE: Implementation of __stou64_worker
+ * COPYRIGHT: Copyright 2021 Roman Masanin <36927roma(a)gmail.com>
+ */
+
+#define __fto64_worker __stou64_worker
+
+#include "__fto64_worker.h"
+
+/* __stou64 is implemented in __stou64.s */
diff --git a/sdk/lib/crt/math/math.cmake b/sdk/lib/crt/math/math.cmake
index e647201f53b..16cfdd10fd2 100644
--- a/sdk/lib/crt/math/math.cmake
+++ b/sdk/lib/crt/math/math.cmake
@@ -79,6 +79,10 @@ elseif(ARCH STREQUAL "arm")
math/arm/__rt_sdiv64_worker.c
math/arm/__rt_udiv.c
math/arm/__rt_udiv64_worker.c
+ math/arm/__dtoi64_worker.c
+ math/arm/__dtou64_worker.c
+ math/arm/__stoi64_worker.c
+ math/arm/__stou64_worker.c
)
list(APPEND CRT_MATH_SOURCE
math/fabsf.c
diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake
index 38ad8b04712..8034116c8c1 100644
--- a/sdk/lib/crt/msvcrtex.cmake
+++ b/sdk/lib/crt/msvcrtex.cmake
@@ -72,6 +72,10 @@ elseif(ARCH STREQUAL "arm")
math/arm/__rt_sdiv64_worker.c
math/arm/__rt_udiv.c
math/arm/__rt_udiv64_worker.c
+ math/arm/__dtoi64_worker.c
+ math/arm/__dtou64_worker.c
+ math/arm/__stoi64_worker.c
+ math/arm/__stou64_worker.c
)
list(APPEND MSVCRTEX_ASM_SOURCE
except/arm/chkstk_asm.s