rint: Determine RINT_LIBM correctly on AIX 7.
authorBruno Haible <bruno@clisp.org>
Mon, 10 Oct 2011 00:29:53 +0000 (02:29 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 10 Oct 2011 00:29:53 +0000 (02:29 +0200)
* m4/mathfunc.m4 (gl_MATHFUNC): Try to invoke the function also
directly, not only through a function pointer. Also accept an optional
4th argument with extra code.
* m4/rint.m4 (gl_FUNC_RINT): Pass an extra code that gets turned into a
rintf() call by gcc when optimizing.

ChangeLog
m4/mathfunc.m4
m4/rint.m4

index d9419d2..44f1e18 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-10-09  Bruno Haible  <bruno@clisp.org>
 
+       rint: Determine RINT_LIBM correctly on AIX 7.
+       * m4/mathfunc.m4 (gl_MATHFUNC): Try to invoke the function also
+       directly, not only through a function pointer. Also accept an optional
+       4th argument with extra code.
+       * m4/rint.m4 (gl_FUNC_RINT): Pass an extra code that gets turned into a
+       rintf() call by gcc when optimizing.
+
        mathfunc.m4: Refactor.
        * m4/mathfunc.m4 (gl_MATHFUNC): Assign the argument list to a temporary
        m4 variable.
index 698e188..b7a1239 100644 (file)
@@ -1,11 +1,11 @@
-# mathfunc.m4 serial 8
+# mathfunc.m4 serial 9
 dnl Copyright (C) 2010-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
 
-# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES)
-# --------------------------------------------------
+# gl_MATHFUNC(FUNC, RETTYPE, PARAMTYPES [, EXTRA-CODE])
+# -----------------------------------------------------
 # tests whether the function FUNC is available in libc or libm.
 # RETTYPE is the return type. PARAMTYPES is a parameter list, with parentheses.
 # It sets FUNC_LIBM to empty or "-lm" accordingly.
@@ -13,9 +13,20 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_MATHFUNC],
 [
   dnl We need the RETTYPE and PARAMTYPES in order to force linking with the
-  dnl function. With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function
-  dnl are inlined by the compiler, therefore linking of these calls does not
-  dnl require -lm, but taking the function pointer of 'fabs' does.
+  dnl function.
+  dnl 1) With gcc >= 4.3 on glibc/x86_64, calls to the 'fabs' function
+  dnl    are inlined by the compiler, therefore linking of these calls does
+  dnl    not require -lm, but taking the function pointer of 'fabs' does.
+  dnl 2) On MSVC 9, many math functions exist only as macros with arguments,
+  dnl    whereas the function pointer is undefined.
+  dnl On the other hand, taking just the function pointer is not enough.
+  dnl 1) On AIX 7.1, when 'long double' is 128 bit large ("xlc -qldbl128" or
+  dnl    "xlc -qlongdouble" or "gcc -mlong-double-128") many math functions
+  dnl    exist as macros with arguments, that may reference libm or even
+  dnl    completely undefined functions such as __rint128.
+  dnl 2) In AIX 7.1 with gcc 4.2, when optimization is turned on, calls to
+  dnl    rint() with simple arguments are turned into rintf() calls by the
+  dnl    compiler. But while rint() is resides in libc, rintf() is in libm.
   m4_pushdef([func], [$1])
   m4_pushdef([FUNC], [m4_translit([$1],[abcdefghijklmnopqrstuvwxyz],
                                        [ABCDEFGHIJKLMNOPQRSTUVWXYZ])])
@@ -51,7 +62,8 @@ AC_DEFUN([gl_MATHFUNC],
              float f_ret;
              double d_ret;
              long double l_ret;]],
-           [[$2 y = funcptr ]ARGS[;
+           [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[;
+             $4
              return y < 0.3 || y > 1.7;
            ]])],
         [gl_cv_func_]func[_no_libm=yes],
@@ -74,7 +86,8 @@ AC_DEFUN([gl_MATHFUNC],
                float f_ret;
                double d_ret;
                long double l_ret;]],
-             [[$2 y = funcptr ]ARGS[;
+             [[$2 y = funcptr ]ARGS[ + ]func[ ]ARGS[;
+               $4
                return y < 0.3 || y > 1.7;
              ]])],
           [gl_cv_func_]func[_in_libm=yes],
index 5d9e832..2a09136 100644 (file)
@@ -1,4 +1,4 @@
-# rint.m4 serial 2
+# rint.m4 serial 3
 dnl Copyright (C) 2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -9,7 +9,11 @@ AC_DEFUN([gl_FUNC_RINT],
   AC_REQUIRE([gl_MATH_H_DEFAULTS])
 
   dnl Determine RINT_LIBM.
-  gl_MATHFUNC([rint], [double], [(double)])
+  dnl The reason for the extra code is:
+  dnl In AIX 7.1 with gcc 4.2, when optimization is turned on, calls to
+  dnl rint() with simple arguments are turned into rintf() calls by the
+  dnl compiler. But while rint() is resides in libc, rintf() is in libm.
+  gl_MATHFUNC([rint], [double], [(double)], [y += rint (2.0);])
   if test $gl_cv_func_rint_no_libm = no \
      && test $gl_cv_func_rint_in_libm = no; then
     HAVE_RINT=0