newlib/winsup/mingw/mingwex/feholdexcept.c
Danny Smith f34428eb35 Support SSE float environment in fenv.h functions.
* cpu_features.c: New file.
	* cpu_features.h: New file.
	* crt1.c: Include "cpu_features.h".
	(__mingw_CRTStartup): Call cpu_features_init().
	* Makefile.in (MING_OBJS): Add cpu_features.c.
	(SRCDIST_FILES): Add cpu_features.c, cpu_features.h.
	* include/fenv,h ( fenv_t;): Append  __mxcsr field.
	(__MXCSR_EXCEPT_FLAG_SHIFT): New define.
	(__MXCSR_EXCEPT_MASK_SHIFT): New define.
	(__MXCSR_ROUND_FLAG_SHIFT): New define.
	* mingwex/feclearexcept.c: Include "cpu_features.h".
	Handle SSE environment.
	* mingwex/fegetenv.c: Likewise.
	* mingwex/feholdexcept.c: Likewise.
	* mingwex/fesetenv.c: Likewise.
	* mingwex/fesetexceptflag.c: Likewise.
	* mingwex/fesetround.c: Likewise.
	* mingwex/fetestexcept.c: Likewise.
	* mingwex/feupdateenv.c: Likewise.
	* mingwex/fegetround.c: Add comment.
2006-07-03 10:32:58 +00:00

31 lines
983 B
C

#include <fenv.h>
#include "cpu_features.h"
/* 7.6.4.2
The feholdexcept function saves the current floating-point
environment in the object pointed to by envp, clears the exception
flags, and then installs a non-stop (continue on exceptions) mode,
if available, for all exceptions. */
int feholdexcept (fenv_t * envp)
{
__asm__ ("fnstenv %0;" : "=m" (* envp)); /* save current into envp */
/* fnstenv sets control word to non-stop for all exceptions, so all we
need to do is clear the exception flags. */
__asm__ ("fnclex");
if (__HAS_SSE)
{
unsigned int _csr;
/* Save the SSE MXCSR register. */
__asm__ ("stmxcsr %0" : "=m" (envp->__mxcsr));
/* Clear the exception flags. */
_csr = envp->__mxcsr & ~FE_ALL_EXCEPT;
/* Set exception mask to non-stop */
_csr |= (FE_ALL_EXCEPT << __MXCSR_EXCEPT_MASK_SHIFT) /*= 0x1f80 */;
__asm__ volatile ("ldmxcsr %0" : : "m" (_csr));
}
return 0;
}