xref: /reactos/sdk/lib/crt/float/amd64/_control87.c (revision 426598c6)
1 /*
2  * PROJECT:     ReactOS CRT
3  * LICENSE:     MIT (https://spdx.org/licenses/MIT)
4  * PURPOSE:     Implementation of _control87
5  * COPYRIGHT:   Copyright 2022 Timo Kreuzer <timo.kreuzer@reactos.org>
6  */
7 
8 #include <xmmintrin.h>
9 #include <float.h>
10 
11 unsigned int _get_native_fpcw(void);
12 void _set_native_fpcw(unsigned int value);
13 unsigned int _fpcw_native_to_abstract(unsigned int native);
14 unsigned int _fpcw_abstract_to_native(unsigned int abstract);
15 
16 unsigned int __cdecl _control87(unsigned int newval, unsigned int mask)
17 {
18     unsigned int native, oldval, updated;
19 
20     /* Sanatize the mask */
21     mask &= _MCW_DN | _MCW_EM | _MCW_RC;
22 
23     /* Get native control word */
24     native = _get_native_fpcw();
25 
26     /* Convert to abstract */
27     oldval = _fpcw_native_to_abstract(native);
28 
29     /* Update it according to the given parameters */
30     updated = (oldval & ~mask) | (newval & mask);
31 
32     /* Convert back to native */
33     native = _fpcw_abstract_to_native(updated);
34 
35     /* Set the native value */
36     _set_native_fpcw(native);
37 
38     return updated;
39 }
40