xref: /reactos/sdk/lib/crt/math/amd64/fabs.S (revision d82185f1)
1/*
2 * PROJECT:     ReactOS CRT library
3 * LICENSE:     MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE:     x64 asm implementation of fabs
5 * COPYRIGHT:   Copyright 2021 Timo Kreuzer <timo.kreuzer@reactos.org>
6 */
7
8/* INCLUDES ******************************************************************/
9
10#include <asm.inc>
11
12/* CODE **********************************************************************/
13.code64
14
15#ifdef _USE_ML
16/* fabs is not allowed as label name, so create _fabs instead and alias fabs to it */
17ALIAS <fabs> = <_fabs>
18PUBLIC _fabs
19_fabs:
20#else
21PUBLIC fabs
22fabs:
23#endif
24    /* Copy parameter into rcx */
25#if !defined(_MSC_VER) || (_MSC_VER >= 1916)
26    movq rcx, xmm0
27#else
28    /* Old ML64 version does not understand this form of movq and uses movd instead */
29    movd rcx, xmm0
30#endif
31
32    /* Copy into rax */
33    mov rax, rcx
34
35    /* Clear sign bit in rax */
36    btr rax, 63
37
38    /* Check for NAN */
39    mov r8, HEX(7FF0000000000000)
40    cmp rax, r8
41
42    /* If it is NAN, copy original value back to rax */
43    cmova rax, rcx
44
45#if !defined(_MSC_VER) || (_MSC_VER >= 1916)
46    movq xmm0, rax
47#else
48    /* Old ML64 version does not understand this form of movq and uses movd instead */
49    movd xmm0, rax
50#endif
51
52    ret
53
54END
55