~mingw-w64/mingw-w64/experimental

« back to all changes in this revision

Viewing changes to ros-privexp/mingw-w64-crt/misc/fesetenv.c

  • Committer: NightStrike
  • Date: 2010-08-11 22:20:57 UTC
  • Revision ID: svn-v4:4407c894-4637-0410-b4f5-ada5f102cad1:experimental:3266
Branch for adding option for supporting ros

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * This file has no copyright assigned and is placed in the Public Domain.
 
3
 * This file is part of the w64 mingw-runtime package.
 
4
 * No warranty is given; refer to the file DISCLAIMER.PD within this package.
 
5
 */
 
6
#include <_mingw.h>
 
7
#include <fenv.h>
 
8
#include <float.h>
 
9
 
 
10
extern int __mingw_has_sse (void);
 
11
 
 
12
/* 7.6.4.3
 
13
   The fesetenv function establishes the floating-point environment
 
14
   represented by the object pointed to by envp. The argument envp
 
15
   points to an object set by a call to fegetenv or feholdexcept, or
 
16
   equal the macro FE_DFL_ENV or an implementation-defined environment
 
17
   macro. Note that fesetenv merely installs the state of the exception
 
18
   flags represented through its argument, and does not raise these
 
19
   exceptions.
 
20
 */
 
21
 
 
22
extern void (* __MINGW_IMP_SYMBOL(_fpreset))(void);
 
23
extern void _fpreset(void);
 
24
 
 
25
int fesetenv (const fenv_t * envp)
 
26
{
 
27
  if (envp == FE_PC64_ENV)
 
28
   /*
 
29
    *  fninit initializes the control register to 0x37f,
 
30
    *  the status register to zero and the tag word to 0FFFFh.
 
31
    *  The other registers are unaffected.
 
32
    */
 
33
    __asm__ __volatile__ ("fninit");
 
34
 
 
35
  else if (envp == FE_PC53_ENV)
 
36
   /*
 
37
    * MS _fpreset() does same *except* it sets control word
 
38
    * to 0x27f (53-bit precison).
 
39
    * We force calling _fpreset in msvcrt.dll
 
40
    */
 
41
 
 
42
   (* __MINGW_IMP_SYMBOL(_fpreset))();
 
43
 
 
44
  else if (envp == FE_DFL_ENV)
 
45
    /* Use the choice made at app startup */ 
 
46
    _fpreset();
 
47
 
 
48
  else
 
49
    {
 
50
      fenv_t env = *envp;
 
51
      int _mxcsr;
 
52
      _mxcsr = (env.__unused0 << 16) | env.__unused1; /* mxcsr low and high */
 
53
      env.__unused0 = 0xffff;
 
54
      env.__unused1 = 0xffff;
 
55
      __asm__ volatile ("fldenv %0" : : "m" (env)
 
56
                        : "st", "st(1)", "st(2)", "st(3)", "st(4)",
 
57
                        "st(5)", "st(6)", "st(7)");
 
58
      if (__mingw_has_sse ())
 
59
        __asm__ volatile ("ldmxcsr %0" : : "m" (_mxcsr));
 
60
    }
 
61
 
 
62
  return 0;
 
63
}