This is the mail archive of the libc-alpha@sourceware.org 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]
Other format: [Raw text]

[PATCH 6/8] Convert libc_feholdexcept et al from macros to inline functions.


	* math/math_private.h (default_libc_feholdexcept): New.
	(default_libc_feholdexcept_setround): New.
	(default_libc_fesetenv, default_libc_feupdateenv): New.
	(libc_feholdexcept, libc_feholdexceptf, libc_feholdexceptl,
	libc_feholdexcept_setround, libc_feholdexcept_setroundf,
	libc_feholdexcept_setroundl, libc_fetestexcept, libc_fetestexceptf,
	libc_fetestexceptl, libc_fesetenv, libc_fesetenvf, libc_fesetenvl,
	libc_feupdateenv, libc_feupdateenvf, libc_feupdateenvl): Define only
	if not already defined; use the default_libc_foo inlines.
	* sysdeps/x86_64/fpu/math_private.h (libc_feholdexcept,
	libc_feholdexcept_setround, libc_fetestexcept, libc_fesetenv,
	libc_feupdateenv): Convert from macros to inlines.

---
 math/math_private.h               |   98 ++++++++++++++++++++++++++--------
 sysdeps/x86_64/fpu/math_private.h |  109 +++++++++++++++++++------------------
 2 files changed, 131 insertions(+), 76 deletions(-)

diff --git a/math/math_private.h b/math/math_private.h
index 645baa3..20b4b5a 100644
--- a/math/math_private.h
+++ b/math/math_private.h
@@ -19,6 +19,7 @@
 #include <endian.h>
 #include <stdint.h>
 #include <sys/types.h>
+#include <fenv.h>
 
 /* The original fdlibm code used statements like:
 	n0 = ((*(int*)&one)>>29)^1;		* index of high word *
@@ -372,28 +373,81 @@ extern void __docos (double __x, double __dx, double __v[]);
    know what operations are going to be performed.  Therefore we
    define additional interfaces.  By default they refer to the normal
    interfaces.  */
-#define libc_feholdexcept(e) (void) feholdexcept (e)
-#define libc_feholdexceptf(e) (void) feholdexcept (e)
-#define libc_feholdexceptl(e) (void) feholdexcept (e)
-
-#define libc_feholdexcept_setround(e, r) \
-  do { feholdexcept (e); fesetround (r); } while (0)
-#define libc_feholdexcept_setroundf(e, r) \
-  do { feholdexcept (e); fesetround (r); } while (0)
-#define libc_feholdexcept_setroundl(e, r) \
-  do { feholdexcept (e); fesetround (r); } while (0)
-
-#define libc_fetestexcept(e) fetestexcept (e)
-#define libc_fetestexceptf(e) fetestexcept (e)
-#define libc_fetestexceptl(e) fetestexcept (e)
-
-#define libc_fesetenv(e) (void) fesetenv (e)
-#define libc_fesetenvf(e) (void) fesetenv (e)
-#define libc_fesetenvl(e) (void) fesetenv (e)
-
-#define libc_feupdateenv(e) (void) feupdateenv (e)
-#define libc_feupdateenvf(e) (void) feupdateenv (e)
-#define libc_feupdateenvl(e) (void) feupdateenv (e)
+
+static inline void __attribute__((always_inline))
+default_libc_feholdexcept (fenv_t *e)
+{
+  (void) feholdexcept (e);
+}
+
+#ifndef libc_feholdexcept
+# define libc_feholdexcept  default_libc_feholdexcept
+#endif
+#ifndef libc_feholdexceptf
+# define libc_feholdexceptf default_libc_feholdexcept
+#endif
+#ifndef libc_feholdexceptl
+# define libc_feholdexceptl default_libc_feholdexcept
+#endif
+
+static inline void __attribute__((always_inline))
+default_libc_feholdexcept_setround (fenv_t *e, int r)
+{
+  feholdexcept (e);
+  fesetround (r);
+}
+
+#ifndef libc_feholdexcept_setround
+# define libc_feholdexcept_setround  default_libc_feholdexcept_setround
+#endif
+#ifndef libc_feholdexcept_setroundf
+# define libc_feholdexcept_setroundf default_libc_feholdexcept_setround
+#endif
+#ifndef libc_feholdexcept_setroundl
+# define libc_feholdexcept_setroundl default_libc_feholdexcept_setround
+#endif
+
+#ifndef libc_fetestexcept
+# define libc_fetestexcept  fetestexcept
+#endif
+#ifndef libc_fetestexceptf
+# define libc_fetestexceptf fetestexcept
+#endif
+#ifndef libc_fetestexceptl
+# define libc_fetestexceptl fetestexcept
+#endif
+
+static inline void __attribute__((always_inline))
+default_libc_fesetenv (fenv_t *e)
+{
+  (void) fesetenv (e);
+}
+
+#ifndef libc_fesetenv
+# define libc_fesetenv  default_libc_fesetenv
+#endif
+#ifndef libc_fesetenvf
+# define libc_fesetenvf default_libc_fesetenv
+#endif
+#ifndef libc_fesetenvl
+# define libc_fesetenvl default_libc_fesetenv
+#endif
+
+static inline void __attribute__((always_inline))
+default_libc_feupdateenv (fenv_t *e)
+{
+  (void) feupdateenv (e);
+}
+
+#ifndef libc_feupdateenv
+# define libc_feupdateenv  default_libc_feupdateenv
+#endif
+#ifndef libc_feupdateenvf
+# define libc_feupdateenvf default_libc_feupdateenv
+#endif
+#ifndef libc_feupdateenvl
+# define libc_feupdateenvl default_libc_feupdateenv
+#endif
 
 #define __nan(str) \
   (__builtin_constant_p (str) && str[0] == '\0' ? NAN : __nan (str))
diff --git a/sysdeps/x86_64/fpu/math_private.h b/sysdeps/x86_64/fpu/math_private.h
index fcf448e..44b72d8 100644
--- a/sysdeps/x86_64/fpu/math_private.h
+++ b/sysdeps/x86_64/fpu/math_private.h
@@ -1,6 +1,8 @@
 #ifndef X86_64_MATH_PRIVATE_H
 #define X86_64_MATH_PRIVATE_H 1
 
+#include <fenv.h>
+
 #define math_opt_barrier(x) \
   ({ __typeof(x) __x;							      \
      if (sizeof (x) <= sizeof (double))					      \
@@ -62,8 +64,6 @@
     f = f__;								      \
   } while (0)
 
-#include <math/math_private.h>
-
 extern inline double
 __ieee754_sqrt (double d)
 {
@@ -149,58 +149,59 @@ __floorf (float d)
 
 /* Specialized variants of the <fenv.h> interfaces which only handle
    either the FPU or the SSE unit.  */
-#undef libc_feholdexcept
-#define libc_feholdexcept(e) \
-  do {									      \
-     unsigned int mxcsr;						      \
-     asm (STMXCSR " %0" : "=m" (*&mxcsr));				      \
-     (e)->__mxcsr = mxcsr;						      \
-     mxcsr = (mxcsr | 0x1f80) & ~0x3f;					      \
-     asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr));			      \
-  } while (0)
-#undef libc_feholdexceptf
-#define libc_feholdexceptf(e) libc_feholdexcept (e)
-// #define libc_feholdexceptl(e) (void) feholdexcept (e)
+static inline void __attribute__((always_inline))
+libc_feholdexcept (fenv_t *e)
+{
+  unsigned int mxcsr;
+  asm (STMXCSR " %0" : "=m" (*&mxcsr));
+  e->__mxcsr = mxcsr;
+  mxcsr = (mxcsr | 0x1f80) & ~0x3f;
+  asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr));
+}
+#define libc_feholdexcept  libc_feholdexcept
+#define libc_feholdexceptf libc_feholdexcept
 
-#undef libc_feholdexcept_setround
-#define libc_feholdexcept_setround(e, r) \
-  do {									      \
-     unsigned int mxcsr;						      \
-     asm (STMXCSR " %0" : "=m" (*&mxcsr));				      \
-     (e)->__mxcsr = mxcsr;						      \
-     mxcsr = ((mxcsr | 0x1f80) & ~0x603f) | ((r) << 3);			      \
-     asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr));			      \
-  } while (0)
-#undef libc_feholdexcept_setroundf
-#define libc_feholdexcept_setroundf(e, r) libc_feholdexcept_setround (e, r)
-// #define libc_feholdexcept_setroundl(e, r) ...
-
-#undef libc_fetestexcept
-#define libc_fetestexcept(e) \
-  ({ unsigned int mxcsr;						      \
-     asm volatile (STMXCSR " %0" : "=m" (*&mxcsr));			      \
-     mxcsr & (e) & FE_ALL_EXCEPT; })
-#undef libc_fetestexceptf
-#define libc_fetestexceptf(e) libc_fetestexcept (e)
-// #define libc_fetestexceptl(e) fetestexcept (e)
-
-#undef libc_fesetenv
-#define libc_fesetenv(e) \
-  asm volatile (LDMXCSR " %0" : : "m" ((e)->__mxcsr))
-#undef libc_fesetenvf
-#define libc_fesetenvf(e) libc_fesetenv (e)
-// #define libc_fesetenvl(e) (void) fesetenv (e)
-
-#undef libc_feupdateenv
-#define libc_feupdateenv(e) \
-  do {									      \
-    unsigned int mxcsr;							      \
-    asm volatile (STMXCSR " %0" : "=m" (*&mxcsr));			      \
-    asm volatile (LDMXCSR " %0" : : "m" ((e)->__mxcsr));		      \
-    __feraiseexcept (mxcsr & FE_ALL_EXCEPT);				      \
-  } while (0)
-#undef libc_feupdateenvf
-#define libc_feupdateenvf(e) libc_feupdateenv (e)
-// #define libc_feupdateenvl(e) (void) feupdateenv (e)
+static inline void __attribute__((always_inline))
+libc_feholdexcept_setround (fenv_t *e, int r)
+{
+  unsigned int mxcsr;
+  asm (STMXCSR " %0" : "=m" (*&mxcsr));
+  e->__mxcsr = mxcsr;
+  mxcsr = ((mxcsr | 0x1f80) & ~0x603f) | (r << 3);
+  asm volatile (LDMXCSR " %0" : : "m" (*&mxcsr));
+}
+#define libc_feholdexcept_setround  libc_feholdexcept_setround
+#define libc_feholdexcept_setroundf libc_feholdexcept_setround
+
+static inline int __attribute__((always_inline))
+libc_fetestexcept (int e)
+{
+  unsigned int mxcsr;
+  asm volatile (STMXCSR " %0" : "=m" (*&mxcsr));
+  return mxcsr & e & FE_ALL_EXCEPT;
+}
+#define libc_fetestexcept  libc_fetestexcept
+#define libc_fetestexceptf libc_fetestexcept
+
+static inline void __attribute__((always_inline))
+libc_fesetenv (fenv_t *e)
+{
+  asm volatile (LDMXCSR " %0" : : "m" (e->__mxcsr));
+}
+#define libc_fesetenv  libc_fesetenv
+#define libc_fesetenvf libc_fesetenv
+
+static inline void __attribute__((always_inline))
+libc_feupdateenv (fenv_t *e)
+{
+  unsigned int mxcsr;
+  asm volatile (STMXCSR " %0" : "=m" (*&mxcsr));
+  asm volatile (LDMXCSR " %0" : : "m" ((e)->__mxcsr));
+  __feraiseexcept (mxcsr & FE_ALL_EXCEPT);
+}
+#define libc_feupdateenv  libc_feupdateenv
+#define libc_feupdateenvf libc_feupdateenv
+
+#include <math/math_private.h>
 
 #endif /* X86_64_MATH_PRIVATE_H */
-- 
1.7.7.6


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