mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 14:53:40 +00:00
[CRT/ARM] Integer to float conversion implementation (#3866)
CORE-17713 CORE-17706 CORE-17604
This commit is contained in:
parent
6ec6233e9c
commit
9c4e3234ba
11 changed files with 160 additions and 104 deletions
98
sdk/lib/crt/math/arm/__64tof.h
Normal file
98
sdk/lib/crt/math/arm/__64tof.h
Normal file
|
@ -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;
|
||||||
|
}
|
14
sdk/lib/crt/math/arm/__i64tod.c
Normal file
14
sdk/lib/crt/math/arm/__i64tod.c
Normal file
|
@ -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 */
|
|
@ -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 */
|
|
13
sdk/lib/crt/math/arm/__i64tos.c
Normal file
13
sdk/lib/crt/math/arm/__i64tos.c
Normal file
|
@ -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 */
|
|
@ -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 */
|
|
13
sdk/lib/crt/math/arm/__u64tod.c
Normal file
13
sdk/lib/crt/math/arm/__u64tod.c
Normal file
|
@ -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 */
|
|
@ -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 */
|
|
12
sdk/lib/crt/math/arm/__u64tos.c
Normal file
12
sdk/lib/crt/math/arm/__u64tos.c
Normal file
|
@ -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 */
|
|
@ -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 */
|
|
|
@ -86,6 +86,11 @@ elseif(ARCH STREQUAL "arm")
|
||||||
math/arm/__stoi64.c
|
math/arm/__stoi64.c
|
||||||
math/arm/__stou64.c
|
math/arm/__stou64.c
|
||||||
math/arm/__fto64.h
|
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
|
list(APPEND CRT_MATH_SOURCE
|
||||||
math/fabsf.c
|
math/fabsf.c
|
||||||
|
@ -103,10 +108,6 @@ elseif(ARCH STREQUAL "arm")
|
||||||
math/arm/log10.s
|
math/arm/log10.s
|
||||||
math/arm/pow.s
|
math/arm/pow.s
|
||||||
math/arm/tan.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_sdiv64.s
|
||||||
math/arm/__rt_srsh.s
|
math/arm/__rt_srsh.s
|
||||||
math/arm/__rt_udiv64.s
|
math/arm/__rt_udiv64.s
|
||||||
|
|
|
@ -48,13 +48,14 @@ elseif(ARCH STREQUAL "arm")
|
||||||
math/arm/__stoi64.c
|
math/arm/__stoi64.c
|
||||||
math/arm/__stou64.c
|
math/arm/__stou64.c
|
||||||
math/arm/__fto64.h
|
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
|
list(APPEND MSVCRTEX_ASM_SOURCE
|
||||||
except/arm/chkstk_asm.s
|
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_sdiv64.s
|
||||||
math/arm/__rt_srsh.s
|
math/arm/__rt_srsh.s
|
||||||
math/arm/__rt_udiv64.s
|
math/arm/__rt_udiv64.s
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue