https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9c4e3234ba34927c14ec1f...
commit 9c4e3234ba34927c14ec1fd8c75952c37ba0fa87 Author: Roman Masanin 36927roma@gmail.com AuthorDate: Wed Jul 28 21:16:04 2021 +0300 Commit: Stanislav Motylkov x86corez@gmail.com CommitDate: Thu Sep 9 16:02:03 2021 +0300
[CRT/ARM] Integer to float conversion implementation (#3866)
CORE-17713 CORE-17706 CORE-17604 --- sdk/lib/crt/math/arm/__64tof.h | 98 +++++++++++++++++++++++++++++++++++++++++ sdk/lib/crt/math/arm/__i64tod.c | 14 ++++++ sdk/lib/crt/math/arm/__i64tod.s | 24 ---------- sdk/lib/crt/math/arm/__i64tos.c | 13 ++++++ sdk/lib/crt/math/arm/__i64tos.s | 24 ---------- sdk/lib/crt/math/arm/__u64tod.c | 13 ++++++ sdk/lib/crt/math/arm/__u64tod.s | 24 ---------- sdk/lib/crt/math/arm/__u64tos.c | 12 +++++ sdk/lib/crt/math/arm/__u64tos.s | 24 ---------- sdk/lib/crt/math/math.cmake | 9 ++-- sdk/lib/crt/msvcrtex.cmake | 9 ++-- 11 files changed, 160 insertions(+), 104 deletions(-)
diff --git a/sdk/lib/crt/math/arm/__64tof.h b/sdk/lib/crt/math/arm/__64tof.h new file mode 100644 index 00000000000..7aecb6f4e6e --- /dev/null +++ b/sdk/lib/crt/math/arm/__64tof.h @@ -0,0 +1,98 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Integer to float conversion (__i64tod/u64tod/i64tos/u64tos) + * COPYRIGHT: Copyright 2021 Roman Masanin 36927roma@gmail.com + */ + +#ifdef _USE_64_BITS_ +typedef double FLOAT_TYPE; +typedef unsigned long long FINT_TYPE; +#define FRACTION_LEN 52 +#define EXPONENT_LEN 11 +#define SHIFT_OFFSET EXPONENT_LEN +#else +typedef float FLOAT_TYPE; +typedef unsigned int FINT_TYPE; +#define FRACTION_LEN 23 +#define EXPONENT_LEN 8 +#define SHIFT_OFFSET (EXPONENT_LEN + 32) +#endif + +#ifdef _USE_SIGNED_ +typedef long long INT64SU; +#else +typedef unsigned long long INT64SU; +#endif + +typedef union _FLOAT_RESULT +{ + FLOAT_TYPE value; + FINT_TYPE raw; +} FLOAT_RESULT; + +#define SIGN_MASK 0x8000000000000000ULL + +#define EXPONENT_ZERO ((1 << (EXPONENT_LEN - 1)) - 1) + +#define NEGATE(x) (~(x) + 1) + +FLOAT_TYPE +__64tof(INT64SU value) +{ + FLOAT_RESULT result; + FINT_TYPE exponent = EXPONENT_ZERO + FRACTION_LEN; + int count = 0; + unsigned long long mask = SIGN_MASK; + + if (value == 0) + return (FLOAT_TYPE)0; + +#ifdef _USE_SIGNED_ + if (value & SIGN_MASK) + { + value = NEGATE(value); + /* set Sign bit using exponent */ + exponent |= 1 << EXPONENT_LEN; + } +#endif + + for (; count < 64; count++) + { + if (value & mask) + break; + mask = mask >> 1; + } + + count -= SHIFT_OFFSET; + /* exponent is FRACTION_LEN - count */ + exponent -= count; + result.raw = exponent << FRACTION_LEN; + + mask--; + value = value & mask; + if (value == 0) + return result.value; + + if (count == 0) + { + result.raw |= value; + } + else if (count < 0) + { + count = NEGATE(count) - 1; + value = value >> count; + mask = value & 1; + result.raw |= value >> 1; + + /* round up if left most bit of lost data is 1 */ + if (mask) + result.raw++; + } + else + { + result.raw |= value << count; + } + + return result.value; +} diff --git a/sdk/lib/crt/math/arm/__i64tod.c b/sdk/lib/crt/math/arm/__i64tod.c new file mode 100644 index 00000000000..789c4ff30f2 --- /dev/null +++ b/sdk/lib/crt/math/arm/__i64tod.c @@ -0,0 +1,14 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __i64tod + * COPYRIGHT: Copyright 2021 Roman Masanin 36927roma@gmail.com + */ + +#define __64tof __i64tod +#define _USE_64_BITS_ +#define _USE_SIGNED_ + +#include "__64tof.h" + +/* __i64tod is implemented in __64tof.h */ diff --git a/sdk/lib/crt/math/arm/__i64tod.s b/sdk/lib/crt/math/arm/__i64tod.s deleted file mode 100644 index 88b0b0574cd..00000000000 --- a/sdk/lib/crt/math/arm/__i64tod.s +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __i64tod - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) - */ - -/* INCLUDES ******************************************************************/ - -#include <kxarm.h> - -/* CODE **********************************************************************/ - - TEXTAREA - - LEAF_ENTRY __i64tod - - __assertfail - bx lr - - LEAF_END __i64tod - - END -/* EOF */ diff --git a/sdk/lib/crt/math/arm/__i64tos.c b/sdk/lib/crt/math/arm/__i64tos.c new file mode 100644 index 00000000000..58e8ba28d8b --- /dev/null +++ b/sdk/lib/crt/math/arm/__i64tos.c @@ -0,0 +1,13 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __i64tos + * COPYRIGHT: Copyright 2021 Roman Masanin 36927roma@gmail.com + */ + +#define __64tof __i64tos +#define _USE_SIGNED_ + +#include "__64tof.h" + +/* __i64tos is implemented in __64tof.h */ diff --git a/sdk/lib/crt/math/arm/__i64tos.s b/sdk/lib/crt/math/arm/__i64tos.s deleted file mode 100644 index 6f6c730bd00..00000000000 --- a/sdk/lib/crt/math/arm/__i64tos.s +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __i64tos - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) - */ - -/* INCLUDES ******************************************************************/ - -#include <kxarm.h> - -/* CODE **********************************************************************/ - - TEXTAREA - - LEAF_ENTRY __i64tos - - __assertfail - bx lr - - LEAF_END __i64tos - - END -/* EOF */ diff --git a/sdk/lib/crt/math/arm/__u64tod.c b/sdk/lib/crt/math/arm/__u64tod.c new file mode 100644 index 00000000000..f9c7ad3db6a --- /dev/null +++ b/sdk/lib/crt/math/arm/__u64tod.c @@ -0,0 +1,13 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __u64tod + * COPYRIGHT: Copyright 2021 Roman Masanin 36927roma@gmail.com + */ + +#define __64tof __u64tod +#define _USE_64_BITS_ + +#include "__64tof.h" + +/* __u64tod is implemented in __64tof.h */ diff --git a/sdk/lib/crt/math/arm/__u64tod.s b/sdk/lib/crt/math/arm/__u64tod.s deleted file mode 100644 index cf56f96fc80..00000000000 --- a/sdk/lib/crt/math/arm/__u64tod.s +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __u64tod - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) - */ - -/* INCLUDES ******************************************************************/ - -#include <kxarm.h> - -/* CODE **********************************************************************/ - - TEXTAREA - - LEAF_ENTRY __u64tod - - __assertfail - bx lr - - LEAF_END __u64tod - - END -/* EOF */ diff --git a/sdk/lib/crt/math/arm/__u64tos.c b/sdk/lib/crt/math/arm/__u64tos.c new file mode 100644 index 00000000000..c50fff1937a --- /dev/null +++ b/sdk/lib/crt/math/arm/__u64tos.c @@ -0,0 +1,12 @@ +/* + * PROJECT: ReactOS CRT library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of __u64tos + * COPYRIGHT: Copyright 2021 Roman Masanin 36927roma@gmail.com + */ + +#define __64tof __u64tos + +#include "__64tof.h" + +/* __u64tos is implemented in __64tof.h */ diff --git a/sdk/lib/crt/math/arm/__u64tos.s b/sdk/lib/crt/math/arm/__u64tos.s deleted file mode 100644 index 828bc7fe55c..00000000000 --- a/sdk/lib/crt/math/arm/__u64tos.s +++ /dev/null @@ -1,24 +0,0 @@ -/* - * COPYRIGHT: BSD - See COPYING.ARM in the top level directory - * PROJECT: ReactOS CRT library - * PURPOSE: Implementation of __u64tos - * PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org) - */ - -/* INCLUDES ******************************************************************/ - -#include <kxarm.h> - -/* CODE **********************************************************************/ - - TEXTAREA - - LEAF_ENTRY __u64tos - - __assertfail - bx lr - - LEAF_END __u64tos - - END -/* EOF */ diff --git a/sdk/lib/crt/math/math.cmake b/sdk/lib/crt/math/math.cmake index 7e04dcc503b..a534fc8832e 100644 --- a/sdk/lib/crt/math/math.cmake +++ b/sdk/lib/crt/math/math.cmake @@ -86,6 +86,11 @@ elseif(ARCH STREQUAL "arm") math/arm/__stoi64.c math/arm/__stou64.c math/arm/__fto64.h + math/arm/__i64tod.c + math/arm/__u64tod.c + math/arm/__i64tos.c + math/arm/__u64tos.c + math/arm/__64tof.h ) list(APPEND CRT_MATH_SOURCE math/fabsf.c @@ -103,10 +108,6 @@ elseif(ARCH STREQUAL "arm") math/arm/log10.s math/arm/pow.s math/arm/tan.s - math/arm/__i64tod.s - math/arm/__i64tos.s - math/arm/__u64tod.s - math/arm/__u64tos.s math/arm/__rt_sdiv64.s math/arm/__rt_srsh.s math/arm/__rt_udiv64.s diff --git a/sdk/lib/crt/msvcrtex.cmake b/sdk/lib/crt/msvcrtex.cmake index 0ba3ee2aa7e..511473788e6 100644 --- a/sdk/lib/crt/msvcrtex.cmake +++ b/sdk/lib/crt/msvcrtex.cmake @@ -48,13 +48,14 @@ elseif(ARCH STREQUAL "arm") math/arm/__stoi64.c math/arm/__stou64.c math/arm/__fto64.h + math/arm/__i64tod.c + math/arm/__u64tod.c + math/arm/__i64tos.c + math/arm/__u64tos.c + math/arm/__64tof.h ) list(APPEND MSVCRTEX_ASM_SOURCE except/arm/chkstk_asm.s - math/arm/__i64tod.s - math/arm/__i64tos.s - math/arm/__u64tod.s - math/arm/__u64tos.s math/arm/__rt_sdiv64.s math/arm/__rt_srsh.s math/arm/__rt_udiv64.s