ReactOS 0.4.15-dev-8145-ga541a46
cntrlfp.c File Reference
#include <precomp.h>
#include <float.h>
Include dependency graph for cntrlfp.c:

Go to the source code of this file.

Macros

#define X87_CW_IM   (1<<0) /* Invalid operation mask */
 
#define X87_CW_DM   (1<<1) /* Denormal operand mask */
 
#define X87_CW_ZM   (1<<2) /* Zero divide mask */
 
#define X87_CW_OM   (1<<3) /* Overflow mask */
 
#define X87_CW_UM   (1<<4) /* Underflow mask */
 
#define X87_CW_PM   (1<<5) /* Precision mask */
 
#define X87_CW_PC_MASK   (3<<8) /* precision control mask */
 
#define X87_CW_PC24   (0<<8) /* 24 bit precision */
 
#define X87_CW_PC53   (2<<8) /* 53 bit precision */
 
#define X87_CW_PC64   (3<<8) /* 64 bit precision */
 
#define X87_CW_RC_MASK   (3<<10) /* rounding control mask */
 
#define X87_CW_RC_NEAREST   (0<<10) /* round to nearest */
 
#define X87_CW_RC_DOWN   (1<<10) /* round down */
 
#define X87_CW_RC_UP   (2<<10) /* round up */
 
#define X87_CW_RC_ZERO   (3<<10) /* round toward zero (chop) */
 
#define X87_CW_IC   (1<<12) /* infinity control flag */
 

Functions

unsigned int CDECL _controlfp (unsigned int newval, unsigned int mask)
 
unsigned int CDECL _control87 (unsigned int newval, unsigned int mask)
 

Macro Definition Documentation

◆ X87_CW_DM

#define X87_CW_DM   (1<<1) /* Denormal operand mask */

Definition at line 7 of file cntrlfp.c.

◆ X87_CW_IC

#define X87_CW_IC   (1<<12) /* infinity control flag */

Definition at line 24 of file cntrlfp.c.

◆ X87_CW_IM

#define X87_CW_IM   (1<<0) /* Invalid operation mask */

Definition at line 6 of file cntrlfp.c.

◆ X87_CW_OM

#define X87_CW_OM   (1<<3) /* Overflow mask */

Definition at line 9 of file cntrlfp.c.

◆ X87_CW_PC24

#define X87_CW_PC24   (0<<8) /* 24 bit precision */

Definition at line 14 of file cntrlfp.c.

◆ X87_CW_PC53

#define X87_CW_PC53   (2<<8) /* 53 bit precision */

Definition at line 15 of file cntrlfp.c.

◆ X87_CW_PC64

#define X87_CW_PC64   (3<<8) /* 64 bit precision */

Definition at line 16 of file cntrlfp.c.

◆ X87_CW_PC_MASK

#define X87_CW_PC_MASK   (3<<8) /* precision control mask */

Definition at line 13 of file cntrlfp.c.

◆ X87_CW_PM

#define X87_CW_PM   (1<<5) /* Precision mask */

Definition at line 11 of file cntrlfp.c.

◆ X87_CW_RC_DOWN

#define X87_CW_RC_DOWN   (1<<10) /* round down */

Definition at line 20 of file cntrlfp.c.

◆ X87_CW_RC_MASK

#define X87_CW_RC_MASK   (3<<10) /* rounding control mask */

Definition at line 18 of file cntrlfp.c.

◆ X87_CW_RC_NEAREST

#define X87_CW_RC_NEAREST   (0<<10) /* round to nearest */

Definition at line 19 of file cntrlfp.c.

◆ X87_CW_RC_UP

#define X87_CW_RC_UP   (2<<10) /* round up */

Definition at line 21 of file cntrlfp.c.

◆ X87_CW_RC_ZERO

#define X87_CW_RC_ZERO   (3<<10) /* round toward zero (chop) */

Definition at line 22 of file cntrlfp.c.

◆ X87_CW_UM

#define X87_CW_UM   (1<<4) /* Underflow mask */

Definition at line 10 of file cntrlfp.c.

◆ X87_CW_ZM

#define X87_CW_ZM   (1<<2) /* Zero divide mask */

Definition at line 8 of file cntrlfp.c.

Function Documentation

◆ _control87()

unsigned int CDECL _control87 ( unsigned int  newval,
unsigned int  mask 
)

Definition at line 43 of file cntrlfp.c.

44{
45 unsigned short fpword = 0;
46 unsigned int flags = 0;
47
48 TRACE("(%08x, %08x): Called\n", newval, mask);
49
50 /* Get fp control word */
51#ifdef _M_AMD64
52 fpword = __getfpcw87();
53#elif defined(__GNUC__)
54 __asm__ __volatile__( "fstcw %0" : "=m" (fpword) : );
55#else
56 __asm fstcw [fpword];
57#endif
58
59 TRACE("Control word before : %08x\n", fpword);
60
61 /* Convert into mask constants */
62 if (fpword & 0x1) flags |= _EM_INVALID;
63 if (fpword & 0x2) flags |= _EM_DENORMAL;
64 if (fpword & 0x4) flags |= _EM_ZERODIVIDE;
65 if (fpword & 0x8) flags |= _EM_OVERFLOW;
66 if (fpword & 0x10) flags |= _EM_UNDERFLOW;
67 if (fpword & 0x20) flags |= _EM_INEXACT;
68 switch(fpword & 0xC00) {
69 case 0xC00: flags |= _RC_UP|_RC_DOWN; break;
70 case 0x800: flags |= _RC_UP; break;
71 case 0x400: flags |= _RC_DOWN; break;
72 }
73 switch(fpword & 0x300) {
74 case 0x0: flags |= _PC_24; break;
75 case 0x200: flags |= _PC_53; break;
76 case 0x300: flags |= _PC_64; break;
77 }
78 if (fpword & 0x1000) flags |= _IC_AFFINE;
79
80 /* Mask with parameters */
81 flags = (flags & ~mask) | (newval & mask);
82
83 /* Convert (masked) value back to fp word */
84 fpword = 0;
85 if (flags & _EM_INVALID) fpword |= 0x1;
86 if (flags & _EM_DENORMAL) fpword |= 0x2;
87 if (flags & _EM_ZERODIVIDE) fpword |= 0x4;
88 if (flags & _EM_OVERFLOW) fpword |= 0x8;
89 if (flags & _EM_UNDERFLOW) fpword |= 0x10;
90 if (flags & _EM_INEXACT) fpword |= 0x20;
91 switch(flags & (_RC_UP | _RC_DOWN)) {
92 case _RC_UP|_RC_DOWN: fpword |= 0xC00; break;
93 case _RC_UP: fpword |= 0x800; break;
94 case _RC_DOWN: fpword |= 0x400; break;
95 }
96 switch (flags & (_PC_24 | _PC_53)) {
97 case _PC_64: fpword |= 0x300; break;
98 case _PC_53: fpword |= 0x200; break;
99 case _PC_24: fpword |= 0x0; break;
100 }
101 if (flags & _IC_AFFINE) fpword |= 0x1000;
102
103 TRACE("Control word after : %08x\n", fpword);
104
105 /* Put fp control word */
106#ifdef _M_AMD64
107 __setfpcw87(fpword);
108#elif defined(__GNUC__)
109 __asm__ __volatile__( "fldcw %0" : : "m" (fpword) );
110#else
111 __asm fldcw [fpword];
112#endif
113
114 return flags;
115}
GLenum GLint GLuint mask
Definition: glext.h:6028
GLbitfield flags
Definition: glext.h:7161
#define _IC_AFFINE
Definition: float.h:53
#define _RC_UP
Definition: float.h:56
#define _PC_64
Definition: float.h:61
#define _EM_UNDERFLOW
Definition: float.h:51
#define _EM_ZERODIVIDE
Definition: float.h:49
#define _EM_INEXACT
Definition: float.h:52
#define _EM_OVERFLOW
Definition: float.h:50
#define _EM_INVALID
Definition: float.h:47
#define _PC_24
Definition: float.h:59
#define _EM_DENORMAL
Definition: float.h:48
#define _RC_DOWN
Definition: float.h:57
#define _PC_53
Definition: float.h:60
__asm__(".p2align 4, 0x90\n" ".seh_proc __seh2_global_filter_func\n" "__seh2_global_filter_func:\n" "\tsub %rbp, %rax\n" "\tpush %rbp\n" "\t.seh_pushreg %rbp\n" "\tsub $32, %rsp\n" "\t.seh_stackalloc 32\n" "\t.seh_endprologue\n" "\tsub %rax, %rdx\n" "\tmov %rdx, %rbp\n" "\tjmp *%r8\n" "__seh2_global_filter_func_exit:\n" "\t.p2align 4\n" "\tadd $32, %rsp\n" "\tpop %rbp\n" "\tret\n" "\t.seh_endproc")
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by __declspec(), _controlfp(), LocaleTest::_num_put_get(), main(), and Test_exceptions().

◆ _controlfp()

unsigned int CDECL _controlfp ( unsigned int  newval,
unsigned int  mask 
)

Definition at line 35 of file cntrlfp.c.

36{
37 return _control87( newval, mask & ~_EM_DENORMAL );
38}
unsigned int CDECL _control87(unsigned int newval, unsigned int mask)
Definition: cntrlfp.c:43