[CRT] Implement portable + amd64 asm version of fabs/fabsf

Note: older versions of ML64 are broken and don't understand the register form of movq.
See https://stackoverflow.com/questions/24789339/move-quadword-between-xmm-and-general-purpose-register-in-ml64
This commit is contained in:
Timo Kreuzer 2021-05-29 19:40:30 +02:00
parent 8a67170616
commit b85afdfd25
7 changed files with 149 additions and 48 deletions

38
sdk/lib/crt/math/fabs.c Normal file
View file

@ -0,0 +1,38 @@
/*
* PROJECT: ReactOS CRT library
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Portable implementation of fabs
* COPYRIGHT: Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <math.h>
#ifdef _MSC_VER
#pragma function(fabs)
#endif
_Check_return_
double
__cdecl
fabs(
_In_ double x)
{
/* Load the value as uint64 */
unsigned long long u64 = *(unsigned long long*)&x;
/* Clear the sign bit */
u64 &= ~(1ULL << 63);
/* Check for NAN */
if (u64 > 0x7FF0000000000000ull)
{
#ifdef _M_IX86
/* Set error bit */
*(unsigned long long*)&x |= 0x0008000000000000ull;
#endif
return x;
}
/* Convert back to double */
return *(double*)&u64;
}