[CRT/ARM] Implement __dtoi64/dtou64/stoi64/stou64 functions (#3848)

CORE-17703 CORE-17604
This commit is contained in:
Roman Masanin 2021-07-25 17:50:48 +03:00 committed by Stanislav Motylkov
parent fd8baca9f2
commit e448094e74
No known key found for this signature in database
GPG key ID: AFE513258CBA9E92
11 changed files with 240 additions and 24 deletions

View file

@ -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@reactos.org)
* 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>
*/
/* 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

View file

@ -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@gmail.com>
*/
#define __fto64_worker __dtoi64_worker
#define _USE_64_BITS_
#define _USE_SIGNED_
#include "__fto64_worker.h"
/* __dtoi64 is implemented in __dtoi64.s */

View file

@ -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@reactos.org)
* 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>
*/
/* 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

View file

@ -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@gmail.com>
*/
#define __fto64_worker __dtou64_worker
#define _USE_64_BITS_
#include "__fto64_worker.h"
/* __dtou64 is implemented in __dtou64.s */

View file

@ -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@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;
}

View file

@ -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@reactos.org)
* 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>
*/
/* 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

View file

@ -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@gmail.com>
*/
#define __fto64_worker __stoi64_worker
#define _USE_SIGNED_
#include "__fto64_worker.h"
/* __stoi64 is implemented in __stoi64.s */

View file

@ -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@reactos.org)
* 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>
*/
/* 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

View file

@ -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@gmail.com>
*/
#define __fto64_worker __stou64_worker
#include "__fto64_worker.h"
/* __stou64 is implemented in __stou64.s */

View file

@ -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

View file

@ -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