aboutsummaryrefslogtreecommitdiff
path: root/libgfortran
diff options
context:
space:
mode:
authorFrancois-Xavier Coudert <coudert@clipper.ens.fr>2005-10-12 20:21:31 +0000
committerFrancois-Xavier Coudert <coudert@clipper.ens.fr>2005-10-12 20:21:31 +0000
commit84ffc9f01792079a296ea0f2c13bfd01f16ef888 (patch)
treeaf4f5409e807606750191918d192516dcd170012 /libgfortran
parent6f5a4e10d0a86518f6ff31245a4467f56d8062cf (diff)
* gfortran.h: Add bitmasks for different FPE traps. Add fpe
member to options_t. * invoke.texi: Document the new -ffpe-trap option. * lang.opt: Add -ffpe-trap option. * options.c (gfc_init_options): Initialize the FPE option. (gfc_handle_fpe_trap_option): New function to parse the argument of the -ffpe-trap option. (gfc_handle_option): Add case for -ffpe-trap. * trans-decl.c: Declare a tree for the set_fpe library function. (gfc_build_builtin_function_decls): Build this tree. (gfc_generate_function_code): Generate a call to set_fpe at the beginning of the main program. * trans.h: New tree for the set_fpe library function. * Makefile.am: Add fpu.c to the build process, and target-dependent code as fpu-target.h. * Makefile.in: Regenerate. * configure.ac: Add call to configure.host to set FPU_HOST_HEADER. * configure: Regenerate. * config.h.in: Regenerate. * aclocal.m4: Regenerate. * configure.host: New script to determine which host-dependent code should go in. * libgfortran.h: Add fpe option, remove previous fpu_ options. Add bitmasks for different FPE traps. Add prototype for set_fpu. * runtime/environ.c: Remove environment variables to control fpu behaviour. * runtime/fpu.c (set_fpe): New function for the front-end. * runtime/main.c (init): Set FPU state. * config: New directory to store host-dependent code. * config/fpu-387.h: New file with code handling the i387 FPU. * config/fpu-glibc.h: New file with code for glibc systems. * config/fpu-generic.h: Fallback for the most generic host. Issue warnings. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@105328 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgfortran')
-rw-r--r--libgfortran/ChangeLog22
-rw-r--r--libgfortran/Makefile.am8
-rw-r--r--libgfortran/Makefile.in13
-rw-r--r--libgfortran/config.h.in6
-rw-r--r--libgfortran/config/fpu-387.h103
-rw-r--r--libgfortran/config/fpu-generic.h57
-rw-r--r--libgfortran/config/fpu-glibc.h93
-rwxr-xr-xlibgfortran/configure94
-rw-r--r--libgfortran/configure.ac13
-rw-r--r--libgfortran/configure.host32
-rw-r--r--libgfortran/libgfortran.h16
-rw-r--r--libgfortran/runtime/environ.c24
-rw-r--r--libgfortran/runtime/fpu.c16
-rw-r--r--libgfortran/runtime/main.c1
14 files changed, 463 insertions, 35 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog
index 34072892ff3..9433fda08b9 100644
--- a/libgfortran/ChangeLog
+++ b/libgfortran/ChangeLog
@@ -1,3 +1,25 @@
+2005-10-12 Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+ * Makefile.am: Add fpu.c to the build process, and
+ target-dependent code as fpu-target.h.
+ * Makefile.in: Regenerate.
+ * configure.ac: Add call to configure.host to set
+ FPU_HOST_HEADER.
+ * configure: Regenerate.
+ * configure.host: New script to determine which host-dependent
+ code should go in.
+ * libgfortran.h: Add fpe option, remove previous fpu_ options.
+ Add bitmasks for different FPE traps. Add prototype for set_fpu.
+ * runtime/environ.c: Remove environment variables to control
+ fpu behaviour.
+ * runtime/fpu.c (set_fpe): New function for the front-end.
+ * runtime/main.c (init): Set FPU state.
+ * config: New directory to store host-dependent code.
+ * config/fpu-387.h: New file with code handling the i387 FPU.
+ * config/fpu-glibc.h: New file with code for glibc systems.
+ * config/fpu-generic.h: Fallback for the most generic host. Issue
+ warnings.
+
2005-10-12 Janne Blomqvist <jblomqvi@cc.hut.fi>
* io/unix.c: Remove parts of patch of 2005/10/07 that cause
diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am
index cac343b1da6..f5a1869baa3 100644
--- a/libgfortran/Makefile.am
+++ b/libgfortran/Makefile.am
@@ -18,8 +18,6 @@ libgfortranbegin_la_LDFLAGS = -static
## use -iquote
AM_CPPFLAGS = -iquote$(srcdir)/io
-libgfortranincludedir = $(includedir)/gforio
-
gfor_io_src= \
io/close.c \
io/file_pos.c \
@@ -97,6 +95,7 @@ gfor_src= \
runtime/compile_options.c \
runtime/environ.c \
runtime/error.c \
+runtime/fpu.c \
runtime/main.c \
runtime/memory.c \
runtime/pause.c \
@@ -433,7 +432,7 @@ gfor_built_src= $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
$(i_exponent_c) $(i_fraction_c) $(i_nearest_c) $(i_set_exponent_c) \
$(i_pow_c) \
selected_int_kind.inc selected_real_kind.inc kinds.h \
- kinds.inc c99_protos.inc
+ kinds.inc c99_protos.inc fpu-target.h
# Machine generated specifics
gfor_built_specific_src= \
@@ -592,6 +591,9 @@ selected_int_kind.inc: $(srcdir)/mk-sik-inc.sh
selected_real_kind.inc: $(srcdir)/mk-srk-inc.sh
$(SHELL) $(srcdir)/mk-srk-inc.sh '$(FCCOMPILE)' > $@
+fpu-target.h: $(srcdir)/$(FPU_HOST_HEADER)
+ cp $(srcdir)/$(FPU_HOST_HEADER) $@
+
## A 'normal' build shouldn't need to regenerate these
## so we only include them in maintainer mode
diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in
index c4d3be6ef11..5ed436f41ae 100644
--- a/libgfortran/Makefile.in
+++ b/libgfortran/Makefile.in
@@ -66,7 +66,7 @@ am__installdirs = "$(DESTDIR)$(toolexeclibdir)"
toolexeclibLTLIBRARIES_INSTALL = $(INSTALL)
LTLIBRARIES = $(toolexeclib_LTLIBRARIES)
libgfortran_la_LIBADD =
-am__objects_1 = compile_options.lo environ.lo error.lo main.lo \
+am__objects_1 = compile_options.lo environ.lo error.lo fpu.lo main.lo \
memory.lo pause.lo stop.lo string.lo select.lo
am__objects_2 = all_l4.lo all_l8.lo all_l16.lo
am__objects_3 = any_l4.lo any_l8.lo any_l16.lo
@@ -276,6 +276,7 @@ EGREP = @EGREP@
EXEEXT = @EXEEXT@
FC = @FC@
FCFLAGS = @FCFLAGS@
+FPU_HOST_HEADER = @FPU_HOST_HEADER@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_SCRIPT = @INSTALL_SCRIPT@
@@ -357,7 +358,6 @@ libgfortran_la_LDFLAGS = -version-info `grep -v '^\#' $(srcdir)/libtool-version`
libgfortranbegin_la_SOURCES = fmain.c
libgfortranbegin_la_LDFLAGS = -static
AM_CPPFLAGS = -iquote$(srcdir)/io
-libgfortranincludedir = $(includedir)/gforio
gfor_io_src = \
io/close.c \
io/file_pos.c \
@@ -435,6 +435,7 @@ gfor_src = \
runtime/compile_options.c \
runtime/environ.c \
runtime/error.c \
+runtime/fpu.c \
runtime/main.c \
runtime/memory.c \
runtime/pause.c \
@@ -771,7 +772,7 @@ gfor_built_src = $(i_all_c) $(i_any_c) $(i_count_c) $(i_maxloc0_c) \
$(i_exponent_c) $(i_fraction_c) $(i_nearest_c) $(i_set_exponent_c) \
$(i_pow_c) \
selected_int_kind.inc selected_real_kind.inc kinds.h \
- kinds.inc c99_protos.inc
+ kinds.inc c99_protos.inc fpu-target.h
# Machine generated specifics
@@ -1394,6 +1395,9 @@ environ.lo: runtime/environ.c
error.lo: runtime/error.c
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o error.lo `test -f 'runtime/error.c' || echo '$(srcdir)/'`runtime/error.c
+fpu.lo: runtime/fpu.c
+ $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o fpu.lo `test -f 'runtime/fpu.c' || echo '$(srcdir)/'`runtime/fpu.c
+
main.lo: runtime/main.c
$(LIBTOOL) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o main.lo `test -f 'runtime/main.c' || echo '$(srcdir)/'`runtime/main.c
@@ -2699,6 +2703,9 @@ selected_int_kind.inc: $(srcdir)/mk-sik-inc.sh
selected_real_kind.inc: $(srcdir)/mk-srk-inc.sh
$(SHELL) $(srcdir)/mk-srk-inc.sh '$(FCCOMPILE)' > $@
+fpu-target.h: $(srcdir)/$(FPU_HOST_HEADER)
+ cp $(srcdir)/$(FPU_HOST_HEADER) $@
+
@MAINTAINER_MODE_TRUE@$(i_all_c): m4/all.m4 $(I_M4_DEPS1)
@MAINTAINER_MODE_TRUE@ m4 -Dfile=$@ -I$(srcdir)/m4 all.m4 > $(srcdir)/$@
diff --git a/libgfortran/config.h.in b/libgfortran/config.h.in
index 44c45c7767b..669bc153166 100644
--- a/libgfortran/config.h.in
+++ b/libgfortran/config.h.in
@@ -285,6 +285,12 @@
/* libm includes fabsl */
#undef HAVE_FABSL
+/* libm includes feenableexcept */
+#undef HAVE_FEENABLEEXCEPT
+
+/* Define to 1 if you have the <fenv.h> header file. */
+#undef HAVE_FENV_H
+
/* libm includes finite */
#undef HAVE_FINITE
diff --git a/libgfortran/config/fpu-387.h b/libgfortran/config/fpu-387.h
new file mode 100644
index 00000000000..06c02eaf853
--- /dev/null
+++ b/libgfortran/config/fpu-387.h
@@ -0,0 +1,103 @@
+/* FPU-related code for x86 and x86_64 processors.
+ Copyright 2005 Free Software Foundation, Inc.
+ Contributed by Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+
+static int
+has_sse (void)
+{
+#ifdef __x86_64__
+ return 1;
+#else
+ unsigned int eax, ebx, ecx, edx;
+
+ /* See if we can use cpuid. */
+ asm volatile ("pushfl; pushfl; popl %0; movl %0,%1; xorl %2,%0;"
+ "pushl %0; popfl; pushfl; popl %0; popfl"
+ : "=&r" (eax), "=&r" (ebx)
+ : "i" (0x00200000));
+
+ if (((eax ^ ebx) & 0x00200000) == 0)
+ return 0;
+
+ /* Check the highest input value for eax. */
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (0));
+
+ if (eax == 0)
+ return 0;
+
+ asm volatile ("xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
+ : "=a" (eax), "=r" (ebx), "=c" (ecx), "=d" (edx)
+ : "0" (1));
+
+ if (edx & (1 << 25))
+ return 1;
+
+ return 0;
+#endif
+}
+
+void set_fpu (void)
+{
+ short cw;
+ int cw_sse;
+
+ /* i387 -- see linux <fpu_control.h> header file for details. */
+#define _FPU_MASK_IM 0x01
+#define _FPU_MASK_DM 0x02
+#define _FPU_MASK_ZM 0x04
+#define _FPU_MASK_OM 0x08
+#define _FPU_MASK_UM 0x10
+#define _FPU_MASK_PM 0x20
+ asm volatile ("fnstcw %0" : "=m" (cw));
+ cw |= _FPU_MASK_IM | _FPU_MASK_DM | _FPU_MASK_ZM | _FPU_MASK_OM | _FPU_MASK_UM | _FPU_MASK_PM;
+ if (options.fpe & GFC_FPE_INVALID) cw &= ~_FPU_MASK_IM;
+ if (options.fpe & GFC_FPE_DENORMAL) cw &= ~_FPU_MASK_DM;
+ if (options.fpe & GFC_FPE_ZERO) cw &= ~_FPU_MASK_ZM;
+ if (options.fpe & GFC_FPE_OVERFLOW) cw &= ~_FPU_MASK_OM;
+ if (options.fpe & GFC_FPE_UNDERFLOW) cw &= ~_FPU_MASK_UM;
+ if (options.fpe & GFC_FPE_PRECISION) cw &= ~_FPU_MASK_PM;
+ asm volatile ("fldcw %0" : : "m" (cw));
+
+ if (has_sse())
+ {
+ /* SSE */
+ asm volatile ("stmxcsr %0" : : "m" (cw_sse));
+ cw_sse &= 0xFFFF0000;
+ if (options.fpe & GFC_FPE_INVALID) cw_sse |= 1 << 7;
+ if (options.fpe & GFC_FPE_DENORMAL) cw_sse |= 1 << 8;
+ if (options.fpe & GFC_FPE_ZERO) cw_sse |= 1 << 9;
+ if (options.fpe & GFC_FPE_OVERFLOW) cw_sse |= 1 << 10;
+ if (options.fpe & GFC_FPE_UNDERFLOW) cw_sse |= 1 << 11;
+ if (options.fpe & GFC_FPE_PRECISION) cw_sse |= 1 << 12;
+ asm volatile ("ldmxcsr %0" : : "m" (cw_sse));
+ }
+}
diff --git a/libgfortran/config/fpu-generic.h b/libgfortran/config/fpu-generic.h
new file mode 100644
index 00000000000..9e043d74895
--- /dev/null
+++ b/libgfortran/config/fpu-generic.h
@@ -0,0 +1,57 @@
+/* Fallback FPU-related code (for systems not otherwise supported).
+ Copyright 2005 Free Software Foundation, Inc.
+ Contributed by Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+
+/* Fallback FPU-related code for systems not otherwise supported. This
+ is mainly telling the user that we will not be able to do what he
+ requested. */
+
+void
+set_fpu (void)
+{
+ if (options.fpe & GFC_FPE_INVALID)
+ st_printf ("Fortran runtime warning: IEEE 'invalid operation' "
+ "exception not supported.\n");
+ if (options.fpe & GFC_FPE_DENORMAL)
+ st_printf ("Fortran runtime warning: IEEE 'denormal number' "
+ "exception not supported.\n");
+ if (options.fpe & GFC_FPE_ZERO)
+ st_printf ("Fortran runtime warning: IEEE 'division by zero' "
+ "exception not supported.\n");
+ if (options.fpe & GFC_FPE_OVERFLOW)
+ st_printf ("Fortran runtime warning: IEEE 'overflow' "
+ "exception not supported.\n");
+ if (options.fpe & GFC_FPE_UNDERFLOW)
+ st_printf ("Fortran runtime warning: IEEE 'underflow' "
+ "exception not supported.\n");
+ if (options.fpe & GFC_FPE_PRECISION)
+ st_printf ("Fortran runtime warning: IEEE 'loss of precision' "
+ "exception not supported.\n");
+}
diff --git a/libgfortran/config/fpu-glibc.h b/libgfortran/config/fpu-glibc.h
new file mode 100644
index 00000000000..0a6c9df1cc1
--- /dev/null
+++ b/libgfortran/config/fpu-glibc.h
@@ -0,0 +1,93 @@
+/* FPU-related code for systems with GNU libc.
+ Copyright 2005 Free Software Foundation, Inc.
+ Contributed by Francois-Xavier Coudert <coudert@clipper.ens.fr>
+
+This file is part of the GNU Fortran 95 runtime library (libgfortran).
+
+Libgfortran is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+Libgfortran is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with libgfortran; see the file COPYING. If not,
+write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
+
+
+/* FPU-related code for systems with the GNU libc, providing the
+ feenableexcept function in fenv.h to set individual exceptions
+ (there's nothing to do that in C99). */
+
+#define __USE_GNU
+#ifdef HAVE_FENV_H
+#include <fenv.h>
+#endif
+
+void set_fpu (void)
+{
+ fedisableexcept (FE_ALL_EXCEPT);
+
+ if (options.fpe & GFC_FPE_INVALID)
+#ifdef FE_INVALID
+ feenableexcept (FE_INVALID);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'invalid operation' "
+ "exception not supported.\n");
+#endif
+
+/* glibc does never have a FE_DENORMAL. */
+ if (options.fpe & GFC_FPE_DENORMAL)
+#ifdef FE_DENORMAL
+ feenableexcept (FE_DENORMAL);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'denormal number' "
+ "exception not supported.\n");
+#endif
+
+ if (options.fpe & GFC_FPE_ZERO)
+#ifdef FE_DIVBYZERO
+ feenableexcept (FE_DIVBYZERO);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'division by zero' "
+ "exception not supported.\n");
+#endif
+
+ if (options.fpe & GFC_FPE_OVERFLOW)
+#ifdef FE_OVERFLOW
+ feenableexcept (FE_OVERFLOW);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'overflow' "
+ "exception not supported.\n");
+#endif
+
+ if (options.fpe & GFC_FPE_UNDERFLOW)
+#ifdef FE_UNDERFLOW
+ feenableexcept (FE_UNDERFLOW);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'underflow' "
+ "exception not supported.\n");
+#endif
+
+ if (options.fpe & GFC_FPE_PRECISION)
+#ifdef FE_INEXACT
+ feenableexcept (FE_INEXACT);
+#else
+ st_printf ("Fortran runtime warning: IEEE 'loss of precision' "
+ "exception not supported.\n");
+#endif
+}
diff --git a/libgfortran/configure b/libgfortran/configure
index 5b31d51a647..69ca7b75bc4 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -308,7 +308,7 @@ ac_includes_default="\
# include <unistd.h>
#endif"
-ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT multi_basedir toolexecdir toolexeclibdir CC ac_ct_CC EXEEXT OBJEXT AM_FCFLAGS AM_CFLAGS AS ac_ct_AS AR ac_ct_AR RANLIB ac_ct_RANLIB LN_S LIBTOOL enable_shared enable_static FC FCFLAGS LDFLAGS ac_ct_FC extra_ldflags_libgfortran CPP CPPFLAGS EGREP LIBOBJS LTLIBOBJS'
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRAM INSTALL_SCRIPT INSTALL_DATA CYGPATH_W PACKAGE VERSION ACLOCAL AUTOCONF AUTOMAKE AUTOHEADER MAKEINFO install_sh STRIP ac_ct_STRIP INSTALL_STRIP_PROGRAM mkdir_p AWK SET_MAKE am__leading_dot AMTAR am__tar am__untar MAINTAINER_MODE_TRUE MAINTAINER_MODE_FALSE MAINT multi_basedir toolexecdir toolexeclibdir CC ac_ct_CC EXEEXT OBJEXT AM_FCFLAGS AM_CFLAGS AS ac_ct_AS AR ac_ct_AR RANLIB ac_ct_RANLIB LN_S LIBTOOL enable_shared enable_static FC FCFLAGS LDFLAGS ac_ct_FC extra_ldflags_libgfortran CPP CPPFLAGS EGREP FPU_HOST_HEADER LIBOBJS LTLIBOBJS'
ac_subst_files=''
# Initialize some variables set by options.
@@ -6507,7 +6507,8 @@ done
-for ac_header in sys/mman.h sys/types.h sys/stat.h ieeefp.h
+
+for ac_header in sys/mman.h sys/types.h sys/stat.h ieeefp.h fenv.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
if eval "test \"\${$as_ac_Header+set}\" = set"; then
@@ -19431,6 +19432,94 @@ _ACEOF
fi
+# Check for GNU libc feenableexcept
+echo "$as_me:$LINENO: checking for feenableexcept in -lm" >&5
+echo $ECHO_N "checking for feenableexcept in -lm... $ECHO_C" >&6
+if test "${ac_cv_lib_m_feenableexcept+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_check_lib_save_LIBS=$LIBS
+LIBS="-lm $LIBS"
+if test x$gcc_no_link = xyes; then
+ { { echo "$as_me:$LINENO: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&5
+echo "$as_me: error: Link tests are not allowed after GCC_NO_EXECUTABLES." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char feenableexcept ();
+int
+main ()
+{
+feenableexcept ();
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_lib_m_feenableexcept=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_m_feenableexcept=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_m_feenableexcept" >&5
+echo "${ECHO_T}$ac_cv_lib_m_feenableexcept" >&6
+if test $ac_cv_lib_m_feenableexcept = yes; then
+ have_feenableexcept=yes
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_FEENABLEEXCEPT 1
+_ACEOF
+
+fi
+
+
+# Runs configure.host to set up necessary host-dependent shell variables.
+# We then display a message about it, and propagate them through the
+# build chain.
+. ${srcdir}/configure.host
+{ echo "$as_me:$LINENO: FPU dependent file will be ${fpu_host}.h" >&5
+echo "$as_me: FPU dependent file will be ${fpu_host}.h" >&6;}
+FPU_HOST_HEADER=config/${fpu_host}.h
+
+
# The standard autoconf HAVE_STRUCT_TIMEZONE doesn't actually check
# for struct timezone, as you might think. We also need to check how
# to call gettimeofday if we have it.
@@ -21031,6 +21120,7 @@ s,@extra_ldflags_libgfortran@,$extra_ldflags_libgfortran,;t t
s,@CPP@,$CPP,;t t
s,@CPPFLAGS@,$CPPFLAGS,;t t
s,@EGREP@,$EGREP,;t t
+s,@FPU_HOST_HEADER@,$FPU_HOST_HEADER,;t t
s,@LIBOBJS@,$LIBOBJS,;t t
s,@LTLIBOBJS@,$LTLIBOBJS,;t t
CEOF
diff --git a/libgfortran/configure.ac b/libgfortran/configure.ac
index 65f62416374..396deb5fe6a 100644
--- a/libgfortran/configure.ac
+++ b/libgfortran/configure.ac
@@ -158,7 +158,7 @@ AC_TYPE_OFF_T
AC_STDC_HEADERS
AC_HAVE_HEADERS(stdlib.h stdio.h string.h stddef.h math.h unistd.h signal.h)
AC_CHECK_HEADERS(time.h sys/params.h sys/time.h sys/times.h sys/resource.h)
-AC_CHECK_HEADERS(sys/mman.h sys/types.h sys/stat.h ieeefp.h)
+AC_CHECK_HEADERS(sys/mman.h sys/types.h sys/stat.h ieeefp.h fenv.h)
AC_CHECK_HEADER([complex.h],[AC_DEFINE([HAVE_COMPLEX_H], [1], [complex.h exists])])
AC_CHECK_MEMBERS([struct stat.st_blksize])
@@ -340,6 +340,17 @@ LIBGFOR_CHECK_FOR_BROKEN_FPCLASSIFY
# Fallback in case isfinite is not available.
AC_CHECK_LIB([m],[finite],[AC_DEFINE([HAVE_FINITE],[1],[libm includes finite])])
+# Check for GNU libc feenableexcept
+AC_CHECK_LIB([m],[feenableexcept],[have_feenableexcept=yes AC_DEFINE([HAVE_FEENABLEEXCEPT],[1],[libm includes feenableexcept])])
+
+# Runs configure.host to set up necessary host-dependent shell variables.
+# We then display a message about it, and propagate them through the
+# build chain.
+. ${srcdir}/configure.host
+AC_MSG_NOTICE([FPU dependent file will be ${fpu_host}.h])
+FPU_HOST_HEADER=config/${fpu_host}.h
+AC_SUBST(FPU_HOST_HEADER)
+
# The standard autoconf HAVE_STRUCT_TIMEZONE doesn't actually check
# for struct timezone, as you might think. We also need to check how
# to call gettimeofday if we have it.
diff --git a/libgfortran/configure.host b/libgfortran/configure.host
new file mode 100644
index 00000000000..c7cc16e17d2
--- /dev/null
+++ b/libgfortran/configure.host
@@ -0,0 +1,32 @@
+# configure.host
+#
+# This shell script handles all host based configuration for libgfortran.
+# It sets various shell variables based on the the host triplet.
+# You can modify this shell script without rerunning autoconf/aclocal/etc.
+# This file is "sourced", not executed.
+#
+#
+# It uses the following shell variables as set by config.guess:
+# host The configuration host (full CPU-vendor-OS triplet)
+# host_cpu The configuration host CPU
+# host_os The configuration host OS
+#
+#
+# It sets the following shell variables:
+#
+# fpu_host FPU-specific code file, defaults to fpu-generic.
+
+
+# DEFAULTS
+fpu_host=fpu-generic
+
+# HOST-SPECIFIC OVERRIDES
+case "${host_cpu}" in
+ i?86 | x86_64)
+ fpu_host='fpu-387' ;;
+esac
+
+# CONFIGURATION-SPECIFIC OVERRIDES
+if test "x${have_feenableexcept}" = "xyes"; then
+ fpu_host='fpu-glibc'
+fi
diff --git a/libgfortran/libgfortran.h b/libgfortran/libgfortran.h
index 174873b67a3..bc23789f7d6 100644
--- a/libgfortran/libgfortran.h
+++ b/libgfortran/libgfortran.h
@@ -337,8 +337,7 @@ typedef struct
int mem_check;
int use_stderr, all_unbuffered, default_recl;
- int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
- fpu_overflow, fpu_underflow, fpu_precision_loss;
+ int fpu_round, fpu_precision, fpe;
int sighup, sigint;
}
@@ -410,6 +409,14 @@ error_codes;
#define GFC_STD_F95_OBS (1<<1) /* Obsoleted in F95. */
#define GFC_STD_F77 (1<<0) /* Up to and including F77. */
+/* Bitmasks for the various FPE that can be enabled.
+ Keep them in sync with their counterparts in gcc/fortran/gfortran.h. */
+#define GFC_FPE_INVALID (1<<0)
+#define GFC_FPE_DENORMAL (1<<1)
+#define GFC_FPE_ZERO (1<<2)
+#define GFC_FPE_OVERFLOW (1<<3)
+#define GFC_FPE_UNDERFLOW (1<<4)
+#define GFC_FPE_PRECISION (1<<5)
/* The filename and line number don't go inside the globals structure.
They are set by the rest of the program and must be linked to. */
@@ -485,6 +492,11 @@ internal_proto(translate_error);
extern void generate_error (int, const char *);
internal_proto(generate_error);
+/* fpu.c */
+
+extern void set_fpu (void);
+internal_proto(set_fpu);
+
/* memory.c */
extern void *get_mem (size_t) __attribute__ ((malloc));
diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c
index fb5da2012ad..09743a0eb95 100644
--- a/libgfortran/runtime/environ.c
+++ b/libgfortran/runtime/environ.c
@@ -533,30 +533,6 @@ static variable variable_table[] = {
show_precision,
"Precision of intermediate results. Values are 24, 53 and 64.", 0},
- {"GFORTRAN_FPU_INVALID", 1, &options.fpu_invalid, init_boolean,
- show_boolean,
- "Raise a floating point exception on invalid FP operation.", 0},
-
- {"GFORTRAN_FPU_DENORMAL", 1, &options.fpu_denormal, init_boolean,
- show_boolean,
- "Raise a floating point exception when denormal numbers are encountered.",
- 0},
-
- {"GFORTRAN_FPU_ZERO", 0, &options.fpu_zerodiv, init_boolean, show_boolean,
- "Raise a floating point exception when dividing by zero.", 0},
-
- {"GFORTRAN_FPU_OVERFLOW", 0, &options.fpu_overflow, init_boolean,
- show_boolean,
- "Raise a floating point exception on overflow.", 0},
-
- {"GFORTRAN_FPU_UNDERFLOW", 0, &options.fpu_underflow, init_boolean,
- show_boolean,
- "Raise a floating point exception on underflow.", 0},
-
- {"GFORTRAN_FPU_PRECISION", 0, &options.fpu_precision_loss, init_boolean,
- show_boolean,
- "Raise a floating point exception on precision loss.", 0},
-
{NULL, 0, NULL, NULL, NULL, NULL, 0}
};
diff --git a/libgfortran/runtime/fpu.c b/libgfortran/runtime/fpu.c
new file mode 100644
index 00000000000..f81a3b05a42
--- /dev/null
+++ b/libgfortran/runtime/fpu.c
@@ -0,0 +1,16 @@
+#include "libgfortran.h"
+
+/* We include the platform-dependent code. */
+#include "fpu-target.h"
+
+/* Function called by the front-end to tell us
+ when a FPE should be raised. */
+extern void set_fpe (int);
+export_proto(set_fpe);
+
+void
+set_fpe (int exceptions)
+{
+ options.fpe = exceptions;
+ set_fpu ();
+}
diff --git a/libgfortran/runtime/main.c b/libgfortran/runtime/main.c
index 77204309aae..1186a304930 100644
--- a/libgfortran/runtime/main.c
+++ b/libgfortran/runtime/main.c
@@ -96,6 +96,7 @@ init (void)
init_variables ();
init_units ();
+ set_fpu ();
init_compile_options ();
#ifdef DEBUG