OSDN Git Service

test: get out of the endless while loop, when bind failed
[uclinux-h8/uClibc.git] / libm / math_private.h
index f85db12..be8031e 100644 (file)
@@ -9,11 +9,6 @@
  * ====================================================
  */
 
-/*
- * from: @(#)fdlibm.h 5.1 93/09/24
- * $Id: math_private.h,v 1.3 2004/02/09 07:10:38 andersen Exp $
- */
-
 #ifndef _MATH_PRIVATE_H_
 #define _MATH_PRIVATE_H_
 
@@ -167,9 +162,9 @@ extern double __ieee754_cosh (double) attribute_hidden;
 extern double __ieee754_fmod (double,double) attribute_hidden;
 extern double __ieee754_pow (double,double) attribute_hidden;
 extern double __ieee754_lgamma_r (double,int *) attribute_hidden;
-extern double __ieee754_gamma_r (double,int *) attribute_hidden;
+/*extern double __ieee754_gamma_r (double,int *) attribute_hidden;*/
 extern double __ieee754_lgamma (double) attribute_hidden;
-extern double __ieee754_gamma (double) attribute_hidden;
+/*extern double __ieee754_gamma (double) attribute_hidden;*/
 extern double __ieee754_log10 (double) attribute_hidden;
 extern double __ieee754_sinh (double) attribute_hidden;
 extern double __ieee754_hypot (double,double) attribute_hidden;
@@ -181,11 +176,7 @@ extern double __ieee754_jn (int,double) attribute_hidden;
 extern double __ieee754_yn (int,double) attribute_hidden;
 extern double __ieee754_remainder (double,double) attribute_hidden;
 extern int    __ieee754_rem_pio2 (double,double*) attribute_hidden;
-#if defined(_SCALB_INT)
-extern double __ieee754_scalb (double,int) attribute_hidden;
-#else
 extern double __ieee754_scalb (double,double) attribute_hidden;
-#endif
 
 /* fdlibm kernel function */
 #ifndef _IEEE_LIBM
@@ -196,4 +187,73 @@ extern double __kernel_cos (double,double) attribute_hidden;
 extern double __kernel_tan (double,double,int) attribute_hidden;
 extern int    __kernel_rem_pio2 (double*,double*,int,int,int,const int*) attribute_hidden;
 
+/*
+ * math_opt_barrier(x): safely load x, even if it was manipulated
+ * by non-floationg point operations. This macro returns the value of x.
+ * This ensures compiler does not (ab)use its knowledge about x value
+ * and don't optimize future operations. Example:
+ * float x;
+ * SET_FLOAT_WORD(x, 0x80000001); // sets a bit pattern
+ * y = math_opt_barrier(x); // "compiler, do not cheat!"
+ * y = y * y; // compiler can't optimize, must use real multiply insn
+ *
+ * math_force_eval(x): force expression x to be evaluated.
+ * Useful if otherwise compiler may eliminate the expression
+ * as unused. This macro returns no value.
+ * Example: "void fn(float f) { f = f * f; }"
+ *   versus "void fn(float f) { f = f * f; math_force_eval(f); }"
+ *
+ * Currently, math_force_eval(x) stores x into
+ * a floating point register or memory *of the appropriate size*.
+ * There is no guarantee this will not change.
+ */
+#if defined(__i386__)
+#define math_opt_barrier(x) ({ \
+       __typeof(x) __x = (x); \
+       /* "t": load x into top-of-stack fpreg */ \
+       __asm__ ("" : "=t" (__x) : "0" (__x)); \
+       __x; \
+})
+#define math_force_eval(x) do {        \
+       __typeof(x) __x = (x); \
+       if (sizeof(__x) <= sizeof(double)) \
+               /* "m": store x into a memory location */ \
+               __asm__ __volatile__ ("" : : "m" (__x)); \
+       else /* long double */ \
+               /* "f": load x into (any) fpreg */ \
+               __asm__ __volatile__ ("" : : "f" (__x)); \
+} while (0)
+#endif
+
+#if defined(__x86_64__)
+#define math_opt_barrier(x) ({ \
+       __typeof(x) __x = (x); \
+       if (sizeof(__x) <= sizeof(double)) \
+               /* "x": load into XMM SSE register */ \
+               __asm__ ("" : "=x" (__x) : "0" (__x)); \
+       else /* long double */ \
+               /* "t": load x into top-of-stack fpreg */ \
+               __asm__ ("" : "=t" (__x) : "0" (__x)); \
+       __x; \
+})
+#define math_force_eval(x) do { \
+       __typeof(x) __x = (x); \
+       if (sizeof(__x) <= sizeof(double)) \
+               /* "x": load into XMM SSE register */ \
+               __asm__ __volatile__ ("" : : "x" (__x)); \
+       else /* long double */ \
+               /* "f": load x into (any) fpreg */ \
+               __asm__ __volatile__ ("" : : "f" (__x)); \
+} while (0)
+#endif
+
+/* Default implementations force store to a memory location */
+#ifndef math_opt_barrier
+#define math_opt_barrier(x) ({ __typeof(x) __x = (x); __asm__ ("" : "+m" (__x)); __x; })
+#endif
+#ifndef math_force_eval
+#define math_force_eval(x)  do { __typeof(x) __x = (x); __asm__ __volatile__ ("" : : "m" (__x)); } while (0)
+#endif
+
+
 #endif /* _MATH_PRIVATE_H_ */