mirror of
https://github.com/reactos/reactos.git
synced 2025-07-31 21:11:54 +00:00
[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:
parent
8a67170616
commit
b85afdfd25
7 changed files with 149 additions and 48 deletions
38
sdk/lib/crt/math/fabs.c
Normal file
38
sdk/lib/crt/math/fabs.c
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue