This is the mail archive of the libc-alpha@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Enable


>>>>> David H Munro writes:



>> I'd much rather just [add] extra calls, `feenableexcept',
>> `fedisableexcept' which do this:
>> 
>> int feenableexcept(int excepts);
>> 
>> Returns a bitmap containing those exceptions in 'excepts' which were
>> enabled.  Will not enable _more_ exceptions that 'excepts' specifies;
>> returns 0 if 'excepts' is not FE_ALL_EXCEPT and cannot enable or
>> disable exceptions individually.
>> 
>> Note that on PPC, at least, you can test whether exceptions have
>> occurred at a finer level than you can enable or disable them.  So if
>> you ask to have just FE_INVALID_SQRT enabled, it'll fail because you can
>> only enable all the FE_INVALID exceptions at once.

David> This straightforward extension to fenv.h sounds better to me also.
David> The fact that macros FE_DIVBYZERO, FE_INVALID, etc. exist fools many
David> people into thinking that they can be used as arguments to fesetenv to
David> effect the exception mask bits (as opposed to the status bits).

Here comes a patch for the feenableexcpt and fedisableexcpt functions.
Please note that I changed the semantics of the return value slightly
from Geoff's proposal.

I'll look at the "fast underflow" issue separatly, after we've agreed
on these functions.

Andreas

1999-10-27  Andreas Jaeger  <aj@suse.de>

	* math/fenv.h: Add prototypes for feenableexcept and
	fedisableexcept.

	* sysdeps/generic/feenablxcpt.c: Stub file.

	* sysdeps/generic/fedisblxcpt.c: Stub file.

	* sysdeps/i386/fpu/fedisblxcpt.c: New file.

	* sysdeps/i386/fpu/feenablxcpt.c: New file.

	* math/Makefile (libm-support): Add new files.

	* math/Versions: Add new functions.


============================================================
Index: math/Makefile
--- math/Makefile	1999/10/19 06:28:01	1.89
+++ math/Makefile	1999/10/27 10:32:45
@@ -39,7 +39,7 @@
 libm-support = k_standard s_lib_version s_matherr s_signgam		\
 	       fclrexcpt fgetexcptflg fraiseexcpt fsetexcptflg		\
 	       ftestexcept fegetround fesetround fegetenv feholdexcpt	\
-	       fesetenv feupdateenv t_exp
+	       fesetenv feupdateenv fedisblxcpt feenablxcpt t_exp
 libm-calls = e_acos e_acosh e_asin e_atan2 e_atanh e_cosh e_exp e_fmod	\
 	     e_hypot e_j0 e_j1 e_jn e_lgamma_r e_log e_log10 e_pow	\
 	     e_rem_pio2 e_remainder e_scalb e_sinh e_sqrt e_gamma_r	\
============================================================
Index: math/fenv.h
--- math/fenv.h	1999/10/19 03:04:54	1.5
+++ math/fenv.h	1999/10/27 10:32:46
@@ -109,6 +109,20 @@
    according to saved exceptions.  */
 extern void feupdateenv (__const fenv_t *__envp) __THROW;
 
+#ifdef __USE_GNU
+/* Enable individual exceptions.  Returns all enabled exceptions.
+   Will not enable more exceptions than EXCEPTS specifies.  Returns 0
+   if EXCEPTS is not FE_ALL_EXCEPT and cannot enable or disable
+   exceptions individually.  */
+extern int feenableexcept (int excepts) __THROW;
+
+/* Disable individual exceptions.  Returns all enabled exceptions.
+   Will not disable more exceptions than EXCEPTS specifies.  Returns 0
+   if EXCEPTS is not FE_ALL_EXCEPT and cannot enable or disable
+   exceptions individually.  */
+extern int fedisableexcept (int excepts) __THROW;
+#endif
+
 __END_DECLS
 
 #endif /* fenv.h */
============================================================
Index: sysdeps/generic/feenablxcpt.c
--- sysdeps/generic/feenablxcpt.c	created
+++ sysdeps/generic/feenablxcpt.c	Wed Oct 27 12:11:16 1999	1.1
@@ -0,0 +1,29 @@
+/* Enable floating-point exceptions.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1999.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+feenableexcept (int excepts)
+{
+  return 0;		/* Signal failure.  */
+}
+stub_warning (feenableexcept)
+#include <stub-tag.h>
============================================================
Index: sysdeps/generic/fedisblxcpt.c
--- sysdeps/generic/fedisblxcpt.c	created
+++ sysdeps/generic/fedisblxcpt.c	Wed Oct 27 12:11:45 1999	1.1
@@ -0,0 +1,29 @@
+/* Disable floating-point exceptions.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1999.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+fedisableexcept (int excepts)
+{
+  return 0;		/* Signal failure.  */
+}
+stub_warning (fedisableexcept)
+#include <stub-tag.h>
============================================================
Index: sysdeps/i386/fpu/fedisblxcpt.c
--- sysdeps/i386/fpu/fedisblxcpt.c	created
+++ sysdeps/i386/fpu/fedisblxcpt.c	Wed Oct 27 12:31:09 1999	1.1
@@ -0,0 +1,37 @@
+/* Disable floating-point exceptions.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1999.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+fedisableexcept (int excepts)
+{
+  unsigned short int new_exc;
+  
+  /* Get the current control word.  */
+  __asm__ ("fstcw %0" : "=m" (*&new_exc));
+
+  excepts &= FE_ALL_EXCEPT;
+  
+  new_exc &= ~excepts;
+  __asm__ ("fldcw %0" : : "m" (*&new_exc));
+
+  return new_exc & FE_ALL_EXCEPT;
+}
============================================================
Index: sysdeps/i386/fpu/feenablxcpt.c
--- sysdeps/i386/fpu/feenablxcpt.c	created
+++ sysdeps/i386/fpu/feenablxcpt.c	Wed Oct 27 12:31:14 1999	1.1
@@ -0,0 +1,36 @@
+/* Enable floating-point exceptions.
+   Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@suse.de>, 1999.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <fenv.h>
+
+int
+feenableexcept (int excepts)
+{
+  unsigned short int new_exc;
+  
+  /* Get the current control word.  */
+  __asm__ ("fstcw %0" : "=m" (*&new_exc));
+
+  excepts &= FE_ALL_EXCEPT;
+  new_exc |= excepts;
+  __asm__ ("fldcw %0" : : "m" (*&new_exc));
+
+  return new_exc & FE_ALL_EXCEPT;
+}

============================================================
Index: math/Versions
--- math/Versions	1999/01/19 10:01:03	1.5
+++ math/Versions	1999/10/27 10:48:12
@@ -153,4 +153,9 @@
     __fpclassify; __fpclassifyf; __fpclassifyl;
     __signbit; __signbitf; __signbitl;
   }
+
+  GLIBC_2.2 {
+    # fp environment function
+    feenableexcept; fedisableexcept;
+  }
 }

-- 
 Andreas Jaeger   
  SuSE Labs aj@suse.de	
   private aj@arthur.rhein-neckar.de

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]