master
 1/**
 2 * This file has no copyright assigned and is placed in the Public Domain.
 3 * This file is part of the mingw-w64 runtime package.
 4 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 5 */
 6
 7#include "internal.h"
 8
 9#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
10/* Internal MinGW version of _control87_2 */
11int __mingw_control87_2( unsigned int newval, unsigned int mask,
12                         unsigned int *x86_cw, unsigned int *sse2_cw )
13{
14    if (x86_cw)
15    {
16        *x86_cw = newval;
17        __mingw_setfp(x86_cw, mask, NULL, 0);
18    }
19
20    if (!sse2_cw) return 1;
21
22    if (__mingw_has_sse())
23    {
24        *sse2_cw = newval;
25        __mingw_setfp_sse(sse2_cw, mask, NULL, 0);
26    }
27    else *sse2_cw = 0;
28
29    return 1;
30}
31#endif
32
33/* Internal MinGW version of _control87 */
34unsigned int __mingw_controlfp(unsigned int newval, unsigned int mask)
35{
36    unsigned int flags = 0;
37#if defined(__i386__) || (defined(__x86_64__) && !defined(__arm64ec__))
38    unsigned int sse2_cw;
39
40    __mingw_control87_2( newval, mask, &flags, &sse2_cw );
41
42    if (__mingw_has_sse())
43    {
44        if ((flags ^ sse2_cw) & (_MCW_EM | _MCW_RC)) flags |= _EM_AMBIGUOUS;
45        flags |= sse2_cw;
46    }
47#else
48    flags = newval;
49    __mingw_setfp(&flags, mask, NULL, 0);
50#endif
51    return flags;
52}
53