This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH]: Resolve mainline builtin sqrt issues (take 2)
- From: Roger Sayle <roger at eyesopen dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 19 Nov 2001 18:06:32 -0700 (MST)
- Subject: [PATCH]: Resolve mainline builtin sqrt issues (take 2)
My apologies to Joseph Myers for taking so long with this. This
patch renames "__builtin_fsqrt" to "__builtin_sqrt". This brings
mainline in step with the 3.0 releases, fixes link problems with
using "__builtin_fsqrt", treats "sqrt" as a builtin function and
even simplifies the documentation (i.e. solves PRs c/3120 and
libstdc++/3070). For more details see the original posting
http://gcc.gnu.org/ml/gcc-patches/2001-11/msg00952.html and its
follow ups.
Whilst making this change I also noticed that the FORTRAN front-end
was using the same enumeration to specify the different flavours of
sqrt, cos and sin. Whilst not a problem at the moment, this may
cause a problem in future, so its fixed with this patch.
Tested by "make bootstrap", "make check" and "make check-gcc" on
i686-pc-linux-gnu with no regressions. No new testcase this time.
2001-11-19 Roger Sayle <roger@eyesopen.com>
* builtins.def: Rename BUILT_IN_FSQRT to BUILT_IN_SQRT and
__builtin_fsqrt to __builtin_sqrt.
* builtins.c (expand_builtin_mathfn,expand_builtin): Same.
* extend.texi: Simplify documentation to match patch.
* f/com-rt.def: Use __builtin_sqrt instead of __builtin_fsqrt.
* f/com.c (ffecom_init_0): Same, and fixed enumeration usage.
* libstdc++-v3/acconfig.h: Test for __builtin_sqrt instead of
__builtin_fsqrt.
* libstdc++-v3/acinclude.m4: Same.
* libstdc++-v3/include/c_shadow/bits/std_cmath.h: Same.
diff -c3pr gcc/gcc/builtins.c patch1/gcc/builtins.c
*** gcc/gcc/builtins.c Sun Nov 18 10:33:50 2001
--- patch1/gcc/builtins.c Mon Nov 19 11:59:21 2001
*************** expand_builtin_mathfn (exp, target, subt
*** 1423,1429 ****
case BUILT_IN_COSF:
case BUILT_IN_COSL:
builtin_optab = cos_optab; break;
! case BUILT_IN_FSQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
builtin_optab = sqrt_optab; break;
--- 1423,1429 ----
case BUILT_IN_COSF:
case BUILT_IN_COSL:
builtin_optab = cos_optab; break;
! case BUILT_IN_SQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
builtin_optab = sqrt_optab; break;
*************** expand_builtin (exp, target, subtarget,
*** 3465,3471 ****
set of builtins. */
if (! optimize && ! CALLED_AS_BUILT_IN (fndecl)
&& (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
! || fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_SQRTF
|| fcode == BUILT_IN_SQRTL || fcode == BUILT_IN_MEMSET
|| fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
|| fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
--- 3465,3471 ----
set of builtins. */
if (! optimize && ! CALLED_AS_BUILT_IN (fndecl)
&& (fcode == BUILT_IN_SIN || fcode == BUILT_IN_COS
! || fcode == BUILT_IN_SQRT || fcode == BUILT_IN_SQRTF
|| fcode == BUILT_IN_SQRTL || fcode == BUILT_IN_MEMSET
|| fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
|| fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
*************** expand_builtin (exp, target, subtarget,
*** 3517,3523 ****
because of possible accuracy problems. */
if (! flag_unsafe_math_optimizations)
break;
! case BUILT_IN_FSQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
target = expand_builtin_mathfn (exp, target, subtarget);
--- 3517,3523 ----
because of possible accuracy problems. */
if (! flag_unsafe_math_optimizations)
break;
! case BUILT_IN_SQRT:
case BUILT_IN_SQRTF:
case BUILT_IN_SQRTL:
target = expand_builtin_mathfn (exp, target, subtarget);
diff -c3pr gcc/gcc/builtins.def patch1/gcc/builtins.def
*** gcc/gcc/builtins.def Sun Nov 18 10:37:38 2001
--- patch1/gcc/builtins.def Mon Nov 19 12:00:24 2001
*************** DEF_LIB_BUILTIN(BUILT_IN_STRRCHR,
*** 263,270 ****
"__builtin_strrchr",
BT_FN_STRING_CONST_STRING_INT)
! DEF_LIB_BUILTIN(BUILT_IN_FSQRT,
! "__builtin_fsqrt",
BT_FN_DOUBLE_DOUBLE)
DEF_LIB_BUILTIN(BUILT_IN_SIN,
"__builtin_sin",
--- 263,270 ----
"__builtin_strrchr",
BT_FN_STRING_CONST_STRING_INT)
! DEF_LIB_BUILTIN(BUILT_IN_SQRT,
! "__builtin_sqrt",
BT_FN_DOUBLE_DOUBLE)
DEF_LIB_BUILTIN(BUILT_IN_SIN,
"__builtin_sin",
diff -c3pr gcc/gcc/doc/extend.texi patch1/gcc/doc/extend.texi
*** gcc/gcc/doc/extend.texi Sun Nov 18 10:37:41 2001
--- patch1/gcc/doc/extend.texi Mon Nov 19 12:02:18 2001
*************** The ISO C89 functions @code{abs}, @code{
*** 4377,4386 ****
@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all
recognized as built-in functions unless @option{-fno-builtin} is
specified (or @option{-fno-builtin-@var{function}} is specified for an
! individual function). All of these functions have
! corresponding versions prefixed
! with @code{__builtin_}, except that the version for @code{sqrt} is
! called @code{__builtin_fsqrt}.
GCC provides built-in versions of the ISO C99 floating point comparison
macros that avoid raising exceptions for unordered operands. They have
--- 4377,4384 ----
@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all
recognized as built-in functions unless @option{-fno-builtin} is
specified (or @option{-fno-builtin-@var{function}} is specified for an
! individual function). All of these functions have corresponding
! versions prefixed with @code{__builtin_}.
GCC provides built-in versions of the ISO C99 floating point comparison
macros that avoid raising exceptions for unordered operands. They have
diff -c3pr gcc/gcc/f/com-rt.def patch1/gcc/f/com-rt.def
*** gcc/gcc/f/com-rt.def Wed Aug 23 15:16:19 2000
--- patch1/gcc/f/com-rt.def Mon Nov 19 12:03:36 2001
*************** DEFGFRT (FFECOM_gfrtL_LOG10, "log10", FF
*** 273,279 ****
DEFGFRT (FFECOM_gfrtL_POW, "pow", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_SIN, "__builtin_sin", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_SINH, "sinh", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
! DEFGFRT (FFECOM_gfrtL_SQRT, "__builtin_fsqrt", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_TAN, "tan", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_TANH, "tanh", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
--- 273,279 ----
DEFGFRT (FFECOM_gfrtL_POW, "pow", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_SIN, "__builtin_sin", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_SINH, "sinh", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
! DEFGFRT (FFECOM_gfrtL_SQRT, "__builtin_sqrt", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_TAN, "tan", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
DEFGFRT (FFECOM_gfrtL_TANH, "tanh", FFECOM_rttypeDOUBLE_, "d", FALSE, FALSE, TRUE)
diff -c3pr gcc/gcc/f/com.c patch1/gcc/f/com.c
*** gcc/gcc/f/com.c Sun Nov 18 10:34:34 2001
--- patch1/gcc/f/com.c Mon Nov 19 12:06:53 2001
*************** ffecom_init_0 ()
*** 11711,11733 ****
= build_function_type (void_type_node, NULL_TREE);
builtin_function ("__builtin_sqrtf", float_ftype_float,
! BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtf");
! builtin_function ("__builtin_fsqrt", double_ftype_double,
! BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrt");
builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
! BUILT_IN_FSQRT, BUILT_IN_NORMAL, "sqrtl");
builtin_function ("__builtin_sinf", float_ftype_float,
! BUILT_IN_SIN, BUILT_IN_NORMAL, "sinf");
builtin_function ("__builtin_sin", double_ftype_double,
BUILT_IN_SIN, BUILT_IN_NORMAL, "sin");
builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
! BUILT_IN_SIN, BUILT_IN_NORMAL, "sinl");
builtin_function ("__builtin_cosf", float_ftype_float,
! BUILT_IN_COS, BUILT_IN_NORMAL, "cosf");
builtin_function ("__builtin_cos", double_ftype_double,
BUILT_IN_COS, BUILT_IN_NORMAL, "cos");
builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
! BUILT_IN_COS, BUILT_IN_NORMAL, "cosl");
pedantic_lvalues = FALSE;
--- 11711,11733 ----
= build_function_type (void_type_node, NULL_TREE);
builtin_function ("__builtin_sqrtf", float_ftype_float,
! BUILT_IN_SQRTF, BUILT_IN_NORMAL, "sqrtf");
! builtin_function ("__builtin_sqrt", double_ftype_double,
! BUILT_IN_SQRT, BUILT_IN_NORMAL, "sqrt");
builtin_function ("__builtin_sqrtl", ldouble_ftype_ldouble,
! BUILT_IN_SQRTL, BUILT_IN_NORMAL, "sqrtl");
builtin_function ("__builtin_sinf", float_ftype_float,
! BUILT_IN_SINF, BUILT_IN_NORMAL, "sinf");
builtin_function ("__builtin_sin", double_ftype_double,
BUILT_IN_SIN, BUILT_IN_NORMAL, "sin");
builtin_function ("__builtin_sinl", ldouble_ftype_ldouble,
! BUILT_IN_SINL, BUILT_IN_NORMAL, "sinl");
builtin_function ("__builtin_cosf", float_ftype_float,
! BUILT_IN_COSF, BUILT_IN_NORMAL, "cosf");
builtin_function ("__builtin_cos", double_ftype_double,
BUILT_IN_COS, BUILT_IN_NORMAL, "cos");
builtin_function ("__builtin_cosl", ldouble_ftype_ldouble,
! BUILT_IN_COSL, BUILT_IN_NORMAL, "cosl");
pedantic_lvalues = FALSE;
diff -c3pr gcc/libstdc++-v3/acconfig.h patch1/libstdc++-v3/acconfig.h
*** gcc/libstdc++-v3/acconfig.h Fri Nov 2 15:30:57 2001
--- patch1/libstdc++-v3/acconfig.h Mon Nov 19 12:10:56 2001
***************
*** 100,107 ****
// Define if the compiler/host combination has __builtin_sinl
#undef HAVE___BUILTIN_SINL
! // Define if the compiler/host combination has __builtin_fsqrt
! #undef HAVE___BUILTIN_FSQRT
// Define if the compiler/host combination has __builtin_sqrtf
#undef HAVE___BUILTIN_SQRTF
--- 100,107 ----
// Define if the compiler/host combination has __builtin_sinl
#undef HAVE___BUILTIN_SINL
! // Define if the compiler/host combination has __builtin_sqrt
! #undef HAVE___BUILTIN_SQRT
// Define if the compiler/host combination has __builtin_sqrtf
#undef HAVE___BUILTIN_SQRTF
diff -c3pr gcc/libstdc++-v3/acinclude.m4 patch1/libstdc++-v3/acinclude.m4
*** gcc/libstdc++-v3/acinclude.m4 Tue Nov 6 15:50:49 2001
--- patch1/libstdc++-v3/acinclude.m4 Mon Nov 19 12:12:00 2001
*************** dnl check for __builtin_fabl
*** 587,593 ****
dnl check for __builtin_labs
dnl check for __builtin_sqrtf
dnl check for __builtin_sqrtl
! dnl check for __builtin_fsqrt
dnl check for __builtin_sinf
dnl check for __builtin_sin
dnl check for __builtin_sinl
--- 587,593 ----
dnl check for __builtin_labs
dnl check for __builtin_sqrtf
dnl check for __builtin_sqrtl
! dnl check for __builtin_sqrt
dnl check for __builtin_sinf
dnl check for __builtin_sin
dnl check for __builtin_sinl
*************** AC_DEFUN(GLIBCPP_CHECK_BUILTIN_MATH_SUPP
*** 606,612 ****
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_labs)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtf)
! GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_fsqrt)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtl)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sinf)
--- 606,612 ----
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_labs)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtf)
! GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrt)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sqrtl)
GLIBCPP_CHECK_BUILTIN_MATH_DECL_AND_LINKAGE_1(__builtin_sinf)
*************** AC_DEFUN(GLIBCPP_CHECK_BUILTIN_MATH_SUPP
*** 636,642 ****
AC_DEFINE(HAVE___BUILTIN_SIN)
AC_DEFINE(HAVE___BUILTIN_SINF)
AC_DEFINE(HAVE___BUILTIN_SINL)
! AC_DEFINE(HAVE___BUILTIN_FSQRT)
AC_DEFINE(HAVE___BUILTIN_SQRTF)
AC_DEFINE(HAVE___BUILTIN_SQRTL)
fi
--- 636,642 ----
AC_DEFINE(HAVE___BUILTIN_SIN)
AC_DEFINE(HAVE___BUILTIN_SINF)
AC_DEFINE(HAVE___BUILTIN_SINL)
! AC_DEFINE(HAVE___BUILTIN_SQRT)
AC_DEFINE(HAVE___BUILTIN_SQRTF)
AC_DEFINE(HAVE___BUILTIN_SQRTL)
fi
diff -c3pr gcc/libstdc++-v3/include/c_shadow/bits/std_cmath.h patch1/libstdc++-v3/include/c_shadow/bits/std_cmath.h
*** gcc/libstdc++-v3/include/c_shadow/bits/std_cmath.h Thu Dec 21 15:46:26 2000
--- patch1/libstdc++-v3/include/c_shadow/bits/std_cmath.h Mon Nov 19 12:20:41 2001
*************** namespace _C_legacy {
*** 318,324 ****
#if _GLIBCPP_HAVE___BUILTIN_SQRT
inline double
! _CPP_sqrt_capture(double __x) { return __builtin_fsqrt(__x); }
#else
inline double
_CPP_sqrt_capture(double __x) { return sqrt(__x); }
--- 318,324 ----
#if _GLIBCPP_HAVE___BUILTIN_SQRT
inline double
! _CPP_sqrt_capture(double __x) { return __builtin_sqrt(__x); }
#else
inline double
_CPP_sqrt_capture(double __x) { return sqrt(__x); }
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-438-3470