00001 // This file is part of ff3d - http://www.freefem.org/ff3d 00002 // Copyright (C) 2002, 2003 Pascal Have 00003 00004 // This program is free software; you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation; either version 2, or (at your option) 00007 // any later version. 00008 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 00014 // You should have received a copy of the GNU General Public License 00015 // along with this program; if not, write to the Free Software Foundation, 00016 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 00018 // $Id: trapFPE.c,v 1.7 2007/03/04 03:16:53 delpinux Exp $ 00019 00029 #include <config.h> 00030 00031 #if !defined(NDEBUG) && defined (__i386__) && !defined(HAVE_GUI_LIBS) && !defined(__CYGWIN__) 00032 00033 #define MY_FLAGS FE_INVALID 00034 //( FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) 00035 00036 /* definition of glibc version */ 00037 #include <features.h> 00038 00039 /* file containing constants */ 00040 #if __GLIBC_MINOR__ > 0 00041 #include <fenv.h> 00042 int feenableexcept (int excepts); 00043 int fedisableexcept (int excepts); 00044 int fegetexcept (void); 00045 #else 00046 #include <fpu_control.h> 00047 #endif 00048 00049 static void __attribute__ ((constructor)) trapfpe () 00050 { 00051 #if __GLIBC_MINOR__ > 0 00052 /* glibc version > 2.0 */ 00053 /* On intel 00054 * unsigned short cw; 00055 * asm volatile ("fnstcw %0":"=m" (cw)); // Get flags 00056 * cw &= ~traps; // Enable new flags 00057 * asm volatile ("fldcw %0"::"m" (cw)); // Set flags 00058 */ 00059 feenableexcept(MY_FLAGS); 00060 #else 00061 /* glibc 2.0 Version */ 00062 __setfpucw (_FPU_DEFAULT & ~(_FPU_MASK_IM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM)); 00063 #endif 00064 } 00065 00066 #endif // not defined( NDEBUG) and defined (__i386__) and not defined (HAVE_GUI_LIBS)
1.5.6