public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [4.3 backport]: Fix PR target/25477
@ 2008-02-26 19:02 Jack Howarth
  2008-02-26 21:52 ` Mark Mitchell
  0 siblings, 1 reply; 2+ messages in thread
From: Jack Howarth @ 2008-02-26 19:02 UTC (permalink / raw)
  To: gcc-patches

Currently gcc 4.3 generates wrong code on powerpc*-apple-darwin* by calling
the wrong version of libc calls for long doubles. A target specific fix has
been applied to gcc trunk and the backport for gcc 4.3 is attached. With
these changes, this issue is resolved on powerpc-apple-darwin9 without
regressions.

Okay for gcc 4.3 branch?
                      Jack
ps This patch covers...

http://gcc.gnu.org/ml/gcc-cvs/2008-02/msg00591.html
http://gcc.gnu.org/ml/gcc-cvs/2008-02/msg00592.html
http://gcc.gnu.org/ml/gcc-cvs/2008-02/msg00636.html
http://gcc.gnu.org/ml/gcc-patches/2008-02/msg01297.html

The BUILT_IN_NANL definition from Uro's patch
is omitted from darwin-ppc-ldouble-patch.def since
the NANL patch to support it is not in gcc 4.3.

gcc/ChangeLog:

2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
	    Uros Bizjak <ubizjak@gmail.com>

	PR target/25477
	* gcc/config/darwin-protos.h: Add darwin_patch_builtins prototype.
	* gcc/config/darwin-ppc-ldouble-patch.def: New file.
	* gcc/config/rs6000/darwin.h (SUBTARGET_INIT_BUILTINS): New macro.
	* gcc/config/rs6000/rs6000.c (rs6000_init_builtins): Call
	SUBTARGET_INIT_BUILTINS if defined.
	* gcc/config/darwin.c (darwin_patch_builtin,
	darwin_patch_builtins): New functions. 


gcc/fortran/ChangeLog:

2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR target/25477
	* trans-expr.c (gfc_conv_power_op): Use BUILT_IN_CPOW{F,,L}.
	* f95-lang.c (gfc_init_builtin_functions): Define BUILT_IN_CPOW{F,,L}.
	* trans.h (gfor_fndecl_math_cpow, gfor_fndecl_math_cpowf,
	gfor_fndecl_math_cpowl10, gfor_fndecl_math_cpowl16): Remove.
	* trans-decl.c: Likewise.


gcc/testsuite/ChangeLog:

2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>

	PR libfortran/24685
	* gfortran.dg/large_real_kind_form_io_2.f90: XFAIL on
	powerpc*-apple-darwin*.
	* gfortran.dg/large_real_kind_2.F90: Split testing of ERF and
	ERFC into gfortran.dg/large_real_kind_3.F90.
	* gfortran.dg/large_real_kind_3.F90: New test.


Index: gcc/testsuite/gfortran.dg/large_real_kind_form_io_2.f90
===================================================================
--- gcc/testsuite/gfortran.dg/large_real_kind_form_io_2.f90	(revision 132649)
+++ gcc/testsuite/gfortran.dg/large_real_kind_form_io_2.f90	(working copy)
@@ -1,4 +1,4 @@
-! { dg-do run { xfail powerpc*-*-linux* } }
+! { dg-do run { xfail powerpc*-apple-darwin* powerpc*-*-linux* } }
 ! Test XFAILed on these platforms because the system's printf() lacks
 ! proper support for denormalized long doubles. See PR24685
 ! { dg-require-effective-target fortran_large_real }
Index: gcc/testsuite/gfortran.dg/large_real_kind_2.F90
===================================================================
--- gcc/testsuite/gfortran.dg/large_real_kind_2.F90	(revision 132649)
+++ gcc/testsuite/gfortran.dg/large_real_kind_2.F90	(working copy)
@@ -43,8 +43,6 @@
  TEST_FUNCTION(log,0.00178914)
  TEST_FUNCTION(log10,123789.123)
  TEST_FUNCTION(sqrt,789.1356)
- TEST_FUNCTION(erf,1.45123231)
- TEST_FUNCTION(erfc,-0.123789)
 
  CTEST_FUNCTION(cos,(17.456,-1.123))
  CTEST_FUNCTION(sin,(17.456,-7.6))
Index: gcc/testsuite/gfortran.dg/large_real_kind_3.F90
===================================================================
--- gcc/testsuite/gfortran.dg/large_real_kind_3.F90	(revision 0)
+++ gcc/testsuite/gfortran.dg/large_real_kind_3.F90	(revision 0)
@@ -0,0 +1,24 @@
+! { dg-do run }
+! { dg-require-effective-target fortran_large_real }
+! { dg-xfail-if "" { "powerpc*-apple-darwin*" } { "*" }  { "" } }
+
+! Testing erf and erfc library calls on large real kinds (larger than kind=8)
+  implicit none
+
+  integer,parameter :: k = selected_real_kind (precision (0.0_8) + 1)
+  real(8),parameter :: eps = 1e-8
+
+  real(kind=k) :: x
+  real(8) :: y
+
+#define TEST_FUNCTION(func,val) \
+ x = val ;\
+ y = x ;\
+ x = func (x) ;\
+ y = func (y) ;\
+ if (abs((y - x) / y) > eps) call abort
+  
+ TEST_FUNCTION(erf,1.45123231)
+ TEST_FUNCTION(erfc,-0.123789)
+ 
+end
Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c	(revision 132649)
+++ gcc/fortran/trans-expr.c	(working copy)
@@ -935,16 +935,14 @@
       switch (kind)
 	{
 	case 4:
-	  fndecl = gfor_fndecl_math_cpowf;
+	  fndecl = built_in_decls[BUILT_IN_CPOWF];
 	  break;
 	case 8:
-	  fndecl = gfor_fndecl_math_cpow;
+	  fndecl = built_in_decls[BUILT_IN_CPOW];
 	  break;
 	case 10:
-	  fndecl = gfor_fndecl_math_cpowl10;
-	  break;
 	case 16:
-	  fndecl = gfor_fndecl_math_cpowl16;
+	  fndecl = built_in_decls[BUILT_IN_CPOWL];
 	  break;
 	default:
 	  gcc_unreachable ();
Index: gcc/fortran/trans.h
===================================================================
--- gcc/fortran/trans.h	(revision 132649)
+++ gcc/fortran/trans.h	(working copy)
@@ -526,10 +526,6 @@
 gfc_powdecl_list;
 
 extern GTY(()) gfc_powdecl_list gfor_fndecl_math_powi[4][3];
-extern GTY(()) tree gfor_fndecl_math_cpowf;
-extern GTY(()) tree gfor_fndecl_math_cpow;
-extern GTY(()) tree gfor_fndecl_math_cpowl10;
-extern GTY(()) tree gfor_fndecl_math_cpowl16;
 extern GTY(()) tree gfor_fndecl_math_ishftc4;
 extern GTY(()) tree gfor_fndecl_math_ishftc8;
 extern GTY(()) tree gfor_fndecl_math_ishftc16;
Index: gcc/fortran/f95-lang.c
===================================================================
--- gcc/fortran/f95-lang.c	(revision 132649)
+++ gcc/fortran/f95-lang.c	(working copy)
@@ -942,6 +942,12 @@
 		      BUILT_IN_POW, "pow", true);
   gfc_define_builtin ("__builtin_powf", mfunc_float[1], 
 		      BUILT_IN_POWF, "powf", true);
+  gfc_define_builtin ("__builtin_cpowl", mfunc_clongdouble[1], 
+		      BUILT_IN_CPOWL, "cpowl", true);
+  gfc_define_builtin ("__builtin_cpow", mfunc_cdouble[1], 
+		      BUILT_IN_CPOW, "cpow", true);
+  gfc_define_builtin ("__builtin_cpowf", mfunc_cfloat[1], 
+		      BUILT_IN_CPOWF, "cpowf", true);
   gfc_define_builtin ("__builtin_powil", mfunc_longdouble[2], 
 		      BUILT_IN_POWIL, "powil", true);
   gfc_define_builtin ("__builtin_powi", mfunc_double[2], 
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(revision 132649)
+++ gcc/fortran/trans-decl.c	(working copy)
@@ -99,10 +99,6 @@
    trans-intrinsic.c.  */
 
 gfc_powdecl_list gfor_fndecl_math_powi[4][3];
-tree gfor_fndecl_math_cpowf;
-tree gfor_fndecl_math_cpow;
-tree gfor_fndecl_math_cpowl10;
-tree gfor_fndecl_math_cpowl16;
 tree gfor_fndecl_math_ishftc4;
 tree gfor_fndecl_math_ishftc8;
 tree gfor_fndecl_math_ishftc16;
@@ -2024,10 +2020,6 @@
   tree gfc_real8_type_node = gfc_get_real_type (8);
   tree gfc_real10_type_node = gfc_get_real_type (10);
   tree gfc_real16_type_node = gfc_get_real_type (16);
-  tree gfc_complex4_type_node = gfc_get_complex_type (4);
-  tree gfc_complex8_type_node = gfc_get_complex_type (8);
-  tree gfc_complex10_type_node = gfc_get_complex_type (10);
-  tree gfc_complex16_type_node = gfc_get_complex_type (16);
 
   /* String functions.  */
   gfor_fndecl_compare_string =
@@ -2195,25 +2187,6 @@
 #undef NRKINDS
   }
 
-  gfor_fndecl_math_cpowf =
-    gfc_build_library_function_decl (get_identifier ("cpowf"),
-				     gfc_complex4_type_node,
-				     1, gfc_complex4_type_node);
-  gfor_fndecl_math_cpow =
-    gfc_build_library_function_decl (get_identifier ("cpow"),
-				     gfc_complex8_type_node,
-				     1, gfc_complex8_type_node);
-  if (gfc_complex10_type_node)
-    gfor_fndecl_math_cpowl10 =
-      gfc_build_library_function_decl (get_identifier ("cpowl"),
-				       gfc_complex10_type_node, 1,
-				       gfc_complex10_type_node);
-  if (gfc_complex16_type_node)
-    gfor_fndecl_math_cpowl16 =
-      gfc_build_library_function_decl (get_identifier ("cpowl"),
-				       gfc_complex16_type_node, 1,
-				       gfc_complex16_type_node);
-
   gfor_fndecl_math_ishftc4 =
     gfc_build_library_function_decl (get_identifier (PREFIX("ishftc4")),
 				     gfc_int4_type_node,
Index: gcc/config/darwin-protos.h
===================================================================
--- gcc/config/darwin-protos.h	(revision 132649)
+++ gcc/config/darwin-protos.h	(working copy)
@@ -89,3 +89,4 @@
 extern void darwin_asm_output_anchor (rtx symbol);
 extern bool darwin_kextabi_p (void);
 extern void darwin_override_options (void);
+extern void darwin_patch_builtins (void);
Index: gcc/config/rs6000/darwin.h
===================================================================
--- gcc/config/rs6000/darwin.h	(revision 132649)
+++ gcc/config/rs6000/darwin.h	(working copy)
@@ -432,3 +432,6 @@
 /* When generating kernel code or kexts, we don't use Altivec by
    default, as kernel code doesn't save/restore those registers.  */
 #define OS_MISSING_ALTIVEC (flag_mkernel || flag_apple_kext)
+
+/* Darwin has to rename some of the long double builtins.  */
+#define SUBTARGET_INIT_BUILTINS darwin_patch_builtins ()
Index: gcc/config/rs6000/rs6000.c
===================================================================
--- gcc/config/rs6000/rs6000.c	(revision 132649)
+++ gcc/config/rs6000/rs6000.c	(working copy)
@@ -9177,6 +9177,10 @@
   if (built_in_decls [BUILT_IN_CLOG])
     set_user_assembler_name (built_in_decls [BUILT_IN_CLOG], "__clog");
 #endif
+
+#ifdef SUBTARGET_INIT_BUILTINS
+  SUBTARGET_INIT_BUILTINS;
+#endif
 }
 
 /* Search through a set of builtins and enable the mask bits.
Index: gcc/config/darwin.c
===================================================================
--- gcc/config/darwin.c	(revision 132649)
+++ gcc/config/darwin.c	(working copy)
@@ -1735,4 +1735,57 @@
     flag_var_tracking_uninit = 1;
 }
 
+/* Add $LDBL128 suffix to long double builtins.  */
+
+static void
+darwin_patch_builtin (int fncode)
+{
+  tree fn = built_in_decls[fncode];
+  tree sym;
+  char *newname;
+
+  if (!fn)
+    return;
+
+  sym = DECL_ASSEMBLER_NAME (fn);
+  newname = ACONCAT (("_", IDENTIFIER_POINTER (sym), "$LDBL128", NULL));
+
+#if 1
+  set_user_assembler_name (fn, newname);
+#else
+  sym = get_identifier (newname);
+  SET_DECL_ASSEMBLER_NAME (fn, sym);
+#endif
+
+  fn = implicit_built_in_decls[fncode];
+
+  if (fn)
+#if 1
+    set_user_assembler_name (fn, newname);
+#else
+    SET_DECL_ASSEMBLER_NAME (fn, sym);
+#endif
+}
+
+void
+darwin_patch_builtins (void)
+{
+  if (LONG_DOUBLE_TYPE_SIZE != 128)
+    return;
+
+#define PATCH_BUILTIN(fncode) darwin_patch_builtin (fncode);
+#define PATCH_BUILTIN_NO64(fncode) \
+  if (!TARGET_64BIT) \
+    darwin_patch_builtin (fncode);
+#define PATCH_BUILTIN_VARIADIC(fncode) \
+  if (!TARGET_64BIT \
+      && (strverscmp (darwin_macosx_version_min, "10.3.9") >= 0)) \
+    darwin_patch_builtin (fncode);
+#include "darwin-ppc-ldouble-patch.def"
+#undef PATCH_BUILTIN
+#undef PATCH_BUILTIN_NO64
+#undef PATCH_BUILTIN_VARIADIC
+}
+
+
 #include "gt-darwin.h"
Index: gcc/config/darwin-ppc-ldouble-patch.def
===================================================================
--- gcc/config/darwin-ppc-ldouble-patch.def	(revision 0)
+++ gcc/config/darwin-ppc-ldouble-patch.def	(revision 0)
@@ -0,0 +1,94 @@
+PATCH_BUILTIN (BUILT_IN_ACOSHL)
+PATCH_BUILTIN (BUILT_IN_ACOSL)
+PATCH_BUILTIN (BUILT_IN_ASINHL)
+PATCH_BUILTIN (BUILT_IN_ASINL)
+PATCH_BUILTIN (BUILT_IN_ATAN2L)
+PATCH_BUILTIN (BUILT_IN_ATANHL)
+PATCH_BUILTIN (BUILT_IN_ATANL)
+PATCH_BUILTIN (BUILT_IN_CABSL)
+PATCH_BUILTIN (BUILT_IN_CACOSHL)
+PATCH_BUILTIN (BUILT_IN_CACOSL)
+PATCH_BUILTIN (BUILT_IN_CARGL)
+PATCH_BUILTIN (BUILT_IN_CASINHL)
+PATCH_BUILTIN (BUILT_IN_CASINL)
+PATCH_BUILTIN (BUILT_IN_CATANHL)
+PATCH_BUILTIN (BUILT_IN_CATANL)
+PATCH_BUILTIN (BUILT_IN_CBRTL)
+PATCH_BUILTIN (BUILT_IN_CCOSHL)
+PATCH_BUILTIN (BUILT_IN_CCOSL)
+PATCH_BUILTIN (BUILT_IN_CEILL)
+PATCH_BUILTIN (BUILT_IN_CEXPL)
+PATCH_BUILTIN (BUILT_IN_CIMAGL)
+PATCH_BUILTIN (BUILT_IN_CLOGL)
+PATCH_BUILTIN (BUILT_IN_CONJL)
+PATCH_BUILTIN (BUILT_IN_COPYSIGNL)
+PATCH_BUILTIN (BUILT_IN_COSHL)
+PATCH_BUILTIN (BUILT_IN_COSL)
+PATCH_BUILTIN (BUILT_IN_CPOWL)
+PATCH_BUILTIN (BUILT_IN_CPROJL)
+PATCH_BUILTIN (BUILT_IN_CREALL)
+PATCH_BUILTIN (BUILT_IN_CSINHL)
+PATCH_BUILTIN (BUILT_IN_CSINL)
+PATCH_BUILTIN (BUILT_IN_CSQRTL)
+PATCH_BUILTIN (BUILT_IN_CTANHL)
+PATCH_BUILTIN (BUILT_IN_CTANL)
+PATCH_BUILTIN (BUILT_IN_ERFCL)
+PATCH_BUILTIN (BUILT_IN_ERFL)
+PATCH_BUILTIN (BUILT_IN_EXP2L)
+PATCH_BUILTIN (BUILT_IN_EXPL)
+PATCH_BUILTIN (BUILT_IN_EXPM1L)
+PATCH_BUILTIN (BUILT_IN_FABSL)
+PATCH_BUILTIN (BUILT_IN_FDIML)
+PATCH_BUILTIN (BUILT_IN_FLOORL)
+PATCH_BUILTIN (BUILT_IN_FMAL)
+PATCH_BUILTIN (BUILT_IN_FMAXL)
+PATCH_BUILTIN (BUILT_IN_FMINL)
+PATCH_BUILTIN (BUILT_IN_FMODL)
+PATCH_BUILTIN (BUILT_IN_FREXPL)
+PATCH_BUILTIN (BUILT_IN_HYPOTL)
+PATCH_BUILTIN (BUILT_IN_ILOGBL)
+PATCH_BUILTIN (BUILT_IN_LDEXPL)
+PATCH_BUILTIN (BUILT_IN_LGAMMAL)
+PATCH_BUILTIN (BUILT_IN_LLRINTL)
+PATCH_BUILTIN (BUILT_IN_LLROUNDL)
+PATCH_BUILTIN (BUILT_IN_LOG10L)
+PATCH_BUILTIN (BUILT_IN_LOG1PL)
+PATCH_BUILTIN (BUILT_IN_LOG2L)
+PATCH_BUILTIN (BUILT_IN_LOGBL)
+PATCH_BUILTIN (BUILT_IN_LOGL)
+PATCH_BUILTIN (BUILT_IN_LRINTL)
+PATCH_BUILTIN (BUILT_IN_LROUNDL)
+PATCH_BUILTIN (BUILT_IN_MODFL)
+PATCH_BUILTIN (BUILT_IN_NEARBYINTL)
+PATCH_BUILTIN (BUILT_IN_NEXTAFTERL)
+PATCH_BUILTIN (BUILT_IN_NEXTTOWARDL)
+PATCH_BUILTIN (BUILT_IN_POWL)
+PATCH_BUILTIN (BUILT_IN_REMAINDERL)
+PATCH_BUILTIN (BUILT_IN_REMQUOL)
+PATCH_BUILTIN (BUILT_IN_RINTL)
+PATCH_BUILTIN (BUILT_IN_ROUNDL)
+PATCH_BUILTIN (BUILT_IN_SCALBLNL)
+PATCH_BUILTIN (BUILT_IN_SCALBNL)
+PATCH_BUILTIN (BUILT_IN_SINHL)
+PATCH_BUILTIN (BUILT_IN_SINL)
+PATCH_BUILTIN (BUILT_IN_SQRTL)
+PATCH_BUILTIN (BUILT_IN_TANHL)
+PATCH_BUILTIN (BUILT_IN_TANL)
+PATCH_BUILTIN (BUILT_IN_TGAMMAL)
+PATCH_BUILTIN (BUILT_IN_TRUNCL)
+
+PATCH_BUILTIN_NO64 (BUILT_IN_VFPRINTF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VFSCANF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VPRINTF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VSCANF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VSNPRINTF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VSPRINTF)
+PATCH_BUILTIN_NO64 (BUILT_IN_VSSCANF)
+
+PATCH_BUILTIN_VARIADIC (BUILT_IN_FPRINTF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_FSCANF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_PRINTF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_SCANF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_SNPRINTF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_SPRINTF)
+PATCH_BUILTIN_VARIADIC (BUILT_IN_SSCANF)

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [4.3 backport]: Fix PR target/25477
  2008-02-26 19:02 [4.3 backport]: Fix PR target/25477 Jack Howarth
@ 2008-02-26 21:52 ` Mark Mitchell
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Mitchell @ 2008-02-26 21:52 UTC (permalink / raw)
  To: Jack Howarth; +Cc: gcc-patches

Jack Howarth wrote:

> 2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
> 	    Uros Bizjak <ubizjak@gmail.com>
> 
> 	PR target/25477
> 	* gcc/config/darwin-protos.h: Add darwin_patch_builtins prototype.
> 	* gcc/config/darwin-ppc-ldouble-patch.def: New file.
> 	* gcc/config/rs6000/darwin.h (SUBTARGET_INIT_BUILTINS): New macro.
> 	* gcc/config/rs6000/rs6000.c (rs6000_init_builtins): Call
> 	SUBTARGET_INIT_BUILTINS if defined.
> 	* gcc/config/darwin.c (darwin_patch_builtin,
> 	darwin_patch_builtins): New functions. 
> 
> 
> gcc/fortran/ChangeLog:
> 
> 2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
> 
> 	PR target/25477
> 	* trans-expr.c (gfc_conv_power_op): Use BUILT_IN_CPOW{F,,L}.
> 	* f95-lang.c (gfc_init_builtin_functions): Define BUILT_IN_CPOW{F,,L}.
> 	* trans.h (gfor_fndecl_math_cpow, gfor_fndecl_math_cpowf,
> 	gfor_fndecl_math_cpowl10, gfor_fndecl_math_cpowl16): Remove.
> 	* trans-decl.c: Likewise.
> 
> 
> gcc/testsuite/ChangeLog:
> 
> 2008-02-25  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
> 
> 	PR libfortran/24685
> 	* gfortran.dg/large_real_kind_form_io_2.f90: XFAIL on
> 	powerpc*-apple-darwin*.
> 	* gfortran.dg/large_real_kind_2.F90: Split testing of ERF and
> 	ERFC into gfortran.dg/large_real_kind_3.F90.
> 	* gfortran.dg/large_real_kind_3.F90: New test.

OK.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-02-26 21:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-26 19:02 [4.3 backport]: Fix PR target/25477 Jack Howarth
2008-02-26 21:52 ` Mark Mitchell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).