public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/meissner/heads/work093)] Rework setting 128-bit complex multiply and divide.
@ 2022-07-08 20:24 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2022-07-08 20:24 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:7931bc2fc3446603bec638e180def10959184659

commit 7931bc2fc3446603bec638e180def10959184659
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jul 8 16:23:51 2022 -0400

    Rework setting 128-bit complex multiply and divide.
    
    2022-07-08   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs600.cc (create_complex_muldiv_inner): New
            function.
            (create_complex_muldiv): Rewrite function to handle both multiply
            and divide.  Set the decl assembler name to change the name to the
            external function.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/mulkc3-2.c: Revert patch #7.
            * gcc.target/powerpc/divkc3-2.c: Likewise.
    
    libgcc/
    
            * config/rs6000/float128-ifunc.c: Revert patch #7.
            * config/rs6000/quad-float128.h: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.cc                 | 160 +++++++++++++++++++---------
 gcc/testsuite/gcc.target/powerpc/divkc3-2.c |   2 +-
 gcc/testsuite/gcc.target/powerpc/mulkc3-2.c |   2 +-
 libgcc/config/rs6000/float128-ifunc.c       |   6 --
 libgcc/config/rs6000/quad-float128.h        |   5 -
 5 files changed, 114 insertions(+), 61 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 541b4679907..94cd4bb464e 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -11031,26 +11031,6 @@ init_float128_ibm (machine_mode mode)
     }
 }
 
-/* Create a decl for either complex long double multiply or complex long double
-   divide when long double is IEEE 128-bit floating point.  We can't use
-   __multc3 and __divtc3 because the original long double using IBM extended
-   double used those names.  The complex multiply/divide functions are encoded
-   as builtin functions with a complex result and 4 scalar inputs.  */
-
-static void
-create_complex_muldiv (const char *name, built_in_function fncode, tree fntype)
-{
-  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
-				      name, NULL_TREE);
-
-  set_builtin_decl (fncode, fndecl, true);
-
-  if (TARGET_DEBUG_BUILTIN)
-    fprintf (stderr, "create complex %s, fncode: %d\n", name, (int) fncode);
-
-  return;
-}
-
 /* Set up IEEE 128-bit floating point routines.  Use different names if the
    arguments can be passed in a vector register.  The historical PowerPC
    implementation of IEEE 128-bit floating point used _q_<op> for the names, so
@@ -11146,6 +11126,107 @@ init_float128_ieee (machine_mode mode)
     }
 }
 
+/* Create a decls for complex long double multiply and complex long double
+   divide for the 128-bit floating point types.
+
+   When long double is IEEE 128-bit floating point, we can't use __multc3 and
+   __divtc3 because the original long double using IBM extended double used
+   those names.
+
+   Similarly for __ibm128, we want to use __multc3 and __divtc3.
+
+   For these cases, we create a decl with a different name, and then set the
+   ASM name so that we don't have to change libgcc to provide these extra
+   names.  We can't just use the same name because we will get an abort if a
+   built-in function uses the same name.
+
+   The complex multiply/divide functions are encoded as builtin functions with
+   a complex result and 4 scalar inputs.  */
+
+/* Inner function to create a single complex multiply or complex divide
+   function with MUL_OR_DIV, LIB_MODE_NAME, ASM_MODE_NAME, FNCODE, and FNTYPE.
+
+   MUL_OR_DIV is either "mul" or "div" depending on whether we are creating
+   multiply or divide.
+
+   LIB_MODE_NAME is "ic", "kc", or "tc" (i.e. the 2 letter lower case spelling
+   for the complex type being created).
+
+   ASM_MODE_NAME is "kc" or "tc" (i.e. the 2 letter lower case spelling that
+   gives the function to be called).
+
+   FNCODE is the function code of the multiply/divide built-in function.
+
+   FNTYPE is the tree type node of the function.  */
+
+static void
+create_complex_muldiv_inner (const char *mul_or_div,
+			     const char *lib_mode_name,
+			     const char *asm_mode_name,
+			     built_in_function fncode,
+			     tree fntype)
+{
+  char *asm_name = ACONCAT (("__", mul_or_div, asm_mode_name, "3", NULL));
+  char *name = ACONCAT (("__", mul_or_div, lib_mode_name, "3_", asm_mode_name,
+			 NULL));
+
+  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
+				      asm_name, NULL_TREE);
+
+  set_builtin_decl (fncode, fndecl, true);
+
+  if (TARGET_DEBUG_BUILTIN)
+    fprintf (stderr, "create complex %s (%s), fncode: %d\n", name, asm_name,
+	     (int) fncode);
+
+  return;
+}
+
+/* Create both complex multiply and complex divide for a given 128-bit floating
+   point type with LIB_MODE_NAME, ASM_MODE_NAME, COMPLEX_MODE, and ARG_TYPE.
+
+   LIB_MODE_NAME is "ic", "kc", or "tc" (i.e. the 2 letter lower case spelling
+   for the complex type being created).
+
+   ASM_MODE_NAME is "kc" or "tc" (i.e. the 2 letter lower case spelling that
+   gives the function to be called).
+
+   COMPLEX_MODE is the mode of the complex type (i.e. KCmode, ICmode, or
+   TCmode).
+
+   ARG_TYPE is the type of scalar 128-bit floating point type (i.e. the
+   _Float128, __ibm128, or long double type nodes).  */
+
+static void
+create_complex_muldiv (const char *lib_mode_name,
+		       const char *asm_mode_name,
+		       machine_mode complex_mode,
+		       tree arg_type)
+{
+  tree complex_type = (arg_type == long_double_type_node
+		       ? complex_long_double_type_node
+		       : build_complex_type (arg_type));
+  tree fntype = build_function_type_list (complex_type, arg_type, arg_type,
+					  arg_type, arg_type, NULL_TREE);
+
+  /* Build complex multiply.  */
+  built_in_function mul_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("mul", lib_mode_name, asm_mode_name, mul_fncode,
+			       fntype);
+
+  /* Build complex divide.  */
+  built_in_function div_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("div", lib_mode_name, asm_mode_name, div_fncode,
+			       fntype);
+  return;
+}
+
 static void
 rs6000_init_libfuncs (void)
 {
@@ -11168,44 +11249,27 @@ rs6000_init_libfuncs (void)
 	init_float128_ieee (TFmode);
     }
 
-  /* Set up to call __mulkc3 and __divkc3 when long double uses the IEEE
-     128-bit encoding.  We cannot use the same name (__mulkc3 or __divkc3 for
-     both IEEE long double and for explicit _Float128/__float128) because
-     c_builtin_function will complain if we create two built-in functions with
-     the same name.  Instead we use an alias name for the case when long double
-     uses the IEEE 128-bit encoding.  Libgcc will create a weak alias reference
-     for this name.
+  /* Set up to call the appropriate __mul{kc,tc}3 and __div{kc,tc}3 for the
+     128-bit floating point types, using kc3 for IEEE 128-bit and tc3 for IBM
+     128-bit.  We only call this for the functions that don't use the default
+     names.
 
      We need to only execute this once.  If we have clone or target attributes,
      this will be called a second time.  We need to create the built-in
      function only once.  */
   static bool complex_muldiv_init_p = false;
 
-  if (TARGET_FLOAT128_TYPE && TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128
-      && !complex_muldiv_init_p)
+  if (!complex_muldiv_init_p
+      && (TARGET_FLOAT128_TYPE || TARGET_LONG_DOUBLE_128))
     {
       complex_muldiv_init_p = true;
 
-      tree fntype = build_function_type_list (complex_long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      NULL_TREE);
-
-      /* Create complex multiply.  */
-      built_in_function mul_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
-
-      create_complex_muldiv ("__multc3_ieee128", mul_fncode, fntype);
-
-      /* Create complex divide.  */
-      built_in_function div_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
+      /* Create __ibm128 complex multiply divide.  */
+      create_complex_muldiv ("ic", "tc", ICmode, ibm128_float_type_node);
 
-      create_complex_muldiv ("__divtc3_ieee128", div_fncode, fntype);
+      if (TARGET_LONG_DOUBLE_128 && TARGET_IEEEQUAD)
+	/* Create long double (IEEE 128-bit) complex multiply/divide.  */
+	create_complex_muldiv ("tc", "kc", TCmode, long_double_type_node);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
index 0cfcea837ed..e34ed40bac2 100644
--- a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
@@ -14,4 +14,4 @@ divide (cld_t *p, cld_t *q, cld_t *r)
   *p = *q / *r;
 }
 
-/* { dg-final { scan-assembler "bl __divtc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __divkc3" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
index 78ef1dc00f0..eee6de9e2a5 100644
--- a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
@@ -14,4 +14,4 @@ multiply (cld_t *p, cld_t *q, cld_t *r)
   *p = *q * *r;
 }
 
-/* { dg-final { scan-assembler "bl __multc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __mulkc3" } } */
diff --git a/libgcc/config/rs6000/float128-ifunc.c b/libgcc/config/rs6000/float128-ifunc.c
index 30d46bcb233..73cbca2fc9a 100644
--- a/libgcc/config/rs6000/float128-ifunc.c
+++ b/libgcc/config/rs6000/float128-ifunc.c
@@ -359,9 +359,3 @@ TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
 
 TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
   __attribute__ ((__ifunc__ ("__divkc3_resolve")));
-
-TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
-
-TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__divkc3_resolve")));
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index a684d0e1bcf..ae0622c744c 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -191,11 +191,6 @@ extern TFtype __trunctfkf2 (IBM128_TYPE);
 extern TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype);
 extern TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype);
 
-/* Complex long double multiply/divide if long double uses the IEEE 128-bit
-   encoding.  */
-extern TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-
 /* Convert IEEE 128-bit floating point to/from string.  We explicitly use
    _Float128 instead of TFmode because _strtokf and _strfromkf must be compiled
    with long double being IBM 128.  */


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

* [gcc(refs/users/meissner/heads/work093)] Rework setting 128-bit complex multiply and divide.
@ 2022-07-08 20:10 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2022-07-08 20:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5e59c98a91e04ac5991c80db899b6470e24ade37

commit 5e59c98a91e04ac5991c80db899b6470e24ade37
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jul 8 16:10:41 2022 -0400

    Rework setting 128-bit complex multiply and divide.
    
    2022-07-08   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs600.cc (create_complex_muldiv_inner): New
            function.
            (create_complex_muldiv): Rewrite function to handle both multiply
            and divide.  Set the decl assembler name to change the name to the
            external function.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/mulkc3-2.c: Revert patch #7.
            * gcc.target/powerpc/divkc3-2.c: Likewise.
    
    libgcc/
    
            * config/rs6000/float128-ifunc.c: Revert patch #7.
            * config/rs6000/quad-float128.h: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.cc                 | 160 +++++++++++++++++++---------
 gcc/testsuite/gcc.target/powerpc/divkc3-2.c |   2 +-
 gcc/testsuite/gcc.target/powerpc/mulkc3-2.c |   2 +-
 libgcc/config/rs6000/float128-ifunc.c       |   6 --
 libgcc/config/rs6000/quad-float128.h        |   5 -
 5 files changed, 114 insertions(+), 61 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 541b4679907..b482f5eee99 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -11031,26 +11031,6 @@ init_float128_ibm (machine_mode mode)
     }
 }
 
-/* Create a decl for either complex long double multiply or complex long double
-   divide when long double is IEEE 128-bit floating point.  We can't use
-   __multc3 and __divtc3 because the original long double using IBM extended
-   double used those names.  The complex multiply/divide functions are encoded
-   as builtin functions with a complex result and 4 scalar inputs.  */
-
-static void
-create_complex_muldiv (const char *name, built_in_function fncode, tree fntype)
-{
-  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
-				      name, NULL_TREE);
-
-  set_builtin_decl (fncode, fndecl, true);
-
-  if (TARGET_DEBUG_BUILTIN)
-    fprintf (stderr, "create complex %s, fncode: %d\n", name, (int) fncode);
-
-  return;
-}
-
 /* Set up IEEE 128-bit floating point routines.  Use different names if the
    arguments can be passed in a vector register.  The historical PowerPC
    implementation of IEEE 128-bit floating point used _q_<op> for the names, so
@@ -11146,6 +11126,107 @@ init_float128_ieee (machine_mode mode)
     }
 }
 
+/* Create a decls for complex long double multiply and complex long double
+   divide for the 128-bit floating point types.
+
+   When long double is IEEE 128-bit floating point, we can't use __multc3 and
+   __divtc3 because the original long double using IBM extended double used
+   those names.
+
+   Similarly for __ibm128, we want to use __multc3 and __divtc3.
+
+   For these cases, we create a decl with a different name, and then set the
+   ASM name so that we don't have to change libgcc to provide these extra
+   names.  We can't just use the same name because we will get an abort if a
+   built-in function uses the same name.
+
+   The complex multiply/divide functions are encoded as builtin functions with
+   a complex result and 4 scalar inputs.  */
+
+/* Inner function to create a single complex multiply or complex divide
+   function.
+
+   Mul_or_div is either "mul" or "div" depending on whether we are creating
+   multiply or divide.
+
+   Lib_mode_name is "ic", "kc", or "tc" (i.e. the 2 letter mode for the complex
+   type being created).
+
+   Asm_mode_name is "kc" or "tc" (i.e. the 2 letter mode for the function that
+   will be called).
+
+   Fncode is the function code of the multiply/divide built-in function.
+
+   Fntype is the tree type node of the function.  */
+
+static void
+create_complex_muldiv_inner (const char *mul_or_div,
+			     const char *lib_mode_name,
+			     const char *asm_mode_name,
+			     built_in_function fncode,
+			     tree fntype)
+{
+  char *asm_name = ACONCAT (("__", mul_or_div, asm_mode_name, "3", NULL));
+  char *name = ACONCAT (("__", mul_or_div, lib_mode_name, "3_", asm_mode_name,
+			 NULL));
+
+  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
+				      asm_name, NULL_TREE);
+
+  set_builtin_decl (fncode, fndecl, true);
+
+  if (TARGET_DEBUG_BUILTIN)
+    fprintf (stderr, "create complex %s (%s), fncode: %d\n", name, asm_name,
+	     (int) fncode);
+
+  return;
+}
+
+/* Create both complex multiply and complex divide for a given 128-bit floating
+   point type.
+
+   Lib_mode_name is "ic", "kc", or "tc" (i.e. the 2 letter mode for the complex
+   type being created).
+
+   Asm_mode_name is "kc" or "tc" (i.e. the 2 letter mode for the function that
+   will be called).
+
+   Complex_mode is the mode of the complex type (i.e. KCmode, ICmode, or
+   TCmode).
+
+   Arg_type is the type of scalar 128-bit floating point type (i.e. the
+   _Float128, __ibm128, or long double type nodes).  */
+
+static void
+create_complex_muldiv (const char *lib_mode_name,
+		       const char *asm_mode_name,
+		       machine_mode complex_mode,
+		       tree arg_type)
+{
+  tree complex_type = (arg_type == long_double_type_node
+		       ? complex_long_double_type_node
+		       : build_complex_type (arg_type));
+  tree fntype = build_function_type_list (complex_type, arg_type, arg_type,
+					  arg_type, arg_type, NULL_TREE);
+
+  /* Build complex multiply.  */
+  built_in_function mul_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("mul", lib_mode_name, asm_mode_name, mul_fncode,
+			       fntype);
+
+  /* Build complex divide.  */
+  built_in_function div_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("div", lib_mode_name, asm_mode_name, div_fncode,
+			       fntype);
+  return;
+}
+
 static void
 rs6000_init_libfuncs (void)
 {
@@ -11168,44 +11249,27 @@ rs6000_init_libfuncs (void)
 	init_float128_ieee (TFmode);
     }
 
-  /* Set up to call __mulkc3 and __divkc3 when long double uses the IEEE
-     128-bit encoding.  We cannot use the same name (__mulkc3 or __divkc3 for
-     both IEEE long double and for explicit _Float128/__float128) because
-     c_builtin_function will complain if we create two built-in functions with
-     the same name.  Instead we use an alias name for the case when long double
-     uses the IEEE 128-bit encoding.  Libgcc will create a weak alias reference
-     for this name.
+  /* Set up to call the appropriate __mul{kc,tc}3 and __div{kc,tc}3 for the
+     128-bit floating point types, using kc3 for IEEE 128-bit and tc3 for IBM
+     128-bit.  We only call this for the functions that don't use the default
+     names.
 
      We need to only execute this once.  If we have clone or target attributes,
      this will be called a second time.  We need to create the built-in
      function only once.  */
   static bool complex_muldiv_init_p = false;
 
-  if (TARGET_FLOAT128_TYPE && TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128
-      && !complex_muldiv_init_p)
+  if (!complex_muldiv_init_p
+      && (TARGET_FLOAT128_TYPE || TARGET_LONG_DOUBLE_128))
     {
       complex_muldiv_init_p = true;
 
-      tree fntype = build_function_type_list (complex_long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      NULL_TREE);
-
-      /* Create complex multiply.  */
-      built_in_function mul_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
-
-      create_complex_muldiv ("__multc3_ieee128", mul_fncode, fntype);
-
-      /* Create complex divide.  */
-      built_in_function div_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
+      /* Create __ibm128 complex multiply divide.  */
+      create_complex_muldiv ("ic", "tc", ICmode, ibm128_float_type_node);
 
-      create_complex_muldiv ("__divtc3_ieee128", div_fncode, fntype);
+      if (TARGET_LONG_DOUBLE_128 && TARGET_IEEEQUAD)
+	/* Create long double (IEEE 128-bit) complex multiply/divide.  */
+	create_complex_muldiv ("tc", "kc", TCmode, long_double_type_node);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
index 0cfcea837ed..e34ed40bac2 100644
--- a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
@@ -14,4 +14,4 @@ divide (cld_t *p, cld_t *q, cld_t *r)
   *p = *q / *r;
 }
 
-/* { dg-final { scan-assembler "bl __divtc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __divkc3" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
index 78ef1dc00f0..eee6de9e2a5 100644
--- a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
@@ -14,4 +14,4 @@ multiply (cld_t *p, cld_t *q, cld_t *r)
   *p = *q * *r;
 }
 
-/* { dg-final { scan-assembler "bl __multc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __mulkc3" } } */
diff --git a/libgcc/config/rs6000/float128-ifunc.c b/libgcc/config/rs6000/float128-ifunc.c
index 30d46bcb233..73cbca2fc9a 100644
--- a/libgcc/config/rs6000/float128-ifunc.c
+++ b/libgcc/config/rs6000/float128-ifunc.c
@@ -359,9 +359,3 @@ TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
 
 TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
   __attribute__ ((__ifunc__ ("__divkc3_resolve")));
-
-TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
-
-TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__divkc3_resolve")));
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index a684d0e1bcf..ae0622c744c 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -191,11 +191,6 @@ extern TFtype __trunctfkf2 (IBM128_TYPE);
 extern TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype);
 extern TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype);
 
-/* Complex long double multiply/divide if long double uses the IEEE 128-bit
-   encoding.  */
-extern TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-
 /* Convert IEEE 128-bit floating point to/from string.  We explicitly use
    _Float128 instead of TFmode because _strtokf and _strfromkf must be compiled
    with long double being IBM 128.  */


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

* [gcc(refs/users/meissner/heads/work093)] Rework setting 128-bit complex multiply and divide.
@ 2022-07-08 20:01 Michael Meissner
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Meissner @ 2022-07-08 20:01 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:08e4667eb33a05fc0ddb2eb1a6d94ac238c16e92

commit 08e4667eb33a05fc0ddb2eb1a6d94ac238c16e92
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Fri Jul 8 16:01:19 2022 -0400

    Rework setting 128-bit complex multiply and divide.
    
    2022-07-08   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
    
            * config/rs6000/rs600.cc (create_complex_muldiv_inner): New
            function.
            (create_complex_muldiv): Rewrite function to handle both multiply
            and divide.  Set the decl assembler name to change the name to the
            external function.
    
    gcc/testsuite/
    
            * gcc.target/powerpc/mulkc3-2.c: Revert patch #7.
            * gcc.target/powerpc/divkc3-2.c: Likewise.
    
    libgcc/
    
            * config/rs6000/float128-ifunc.c: Revert patch #7.
            * config/rs6000/quad-float128.h: Likewise.

Diff:
---
 gcc/config/rs6000/rs6000.cc                 | 160 +++++++++++++++++++---------
 gcc/testsuite/gcc.target/powerpc/divkc3-2.c |   2 +-
 gcc/testsuite/gcc.target/powerpc/mulkc3-2.c |   2 +-
 libgcc/config/rs6000/float128-ifunc.c       |   6 --
 libgcc/config/rs6000/quad-float128.h        |   5 -
 5 files changed, 114 insertions(+), 61 deletions(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 541b4679907..9017f9c4876 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -11031,26 +11031,6 @@ init_float128_ibm (machine_mode mode)
     }
 }
 
-/* Create a decl for either complex long double multiply or complex long double
-   divide when long double is IEEE 128-bit floating point.  We can't use
-   __multc3 and __divtc3 because the original long double using IBM extended
-   double used those names.  The complex multiply/divide functions are encoded
-   as builtin functions with a complex result and 4 scalar inputs.  */
-
-static void
-create_complex_muldiv (const char *name, built_in_function fncode, tree fntype)
-{
-  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
-				      name, NULL_TREE);
-
-  set_builtin_decl (fncode, fndecl, true);
-
-  if (TARGET_DEBUG_BUILTIN)
-    fprintf (stderr, "create complex %s, fncode: %d\n", name, (int) fncode);
-
-  return;
-}
-
 /* Set up IEEE 128-bit floating point routines.  Use different names if the
    arguments can be passed in a vector register.  The historical PowerPC
    implementation of IEEE 128-bit floating point used _q_<op> for the names, so
@@ -11146,6 +11126,107 @@ init_float128_ieee (machine_mode mode)
     }
 }
 
+/* Create a decls for complex long double multiply and complex long double
+   divide for the 128-bit floating point types.
+
+   When long double is IEEE 128-bit floating point, we can't use __multc3 and
+   __divtc3 because the original long double using IBM extended double used
+   those names.
+
+   Similarly for __ibm128, we want to use __multc3 and __divtc3.
+
+   For these cases, we create a decl with a different name, and then set the
+   ASM name so that we don't have to change libgcc to provide these extra
+   names.  We can't just use the same name because we will get an abort if a
+   built-in function uses the same name.
+
+   The complex multiply/divide functions are encoded as builtin functions with
+   a complex result and 4 scalar inputs.  */
+
+/* Inner function to create a single complex multiply or complex divide
+   function.
+
+   Mul_or_div is either "mul" or "div" depending on whether we are creating
+   multiply or divide.
+
+   Lib_mode_name is "ic", "kc", or "tc" (i.e. the 2 letter mode for the complex
+   type being created).
+
+   Asm_mode_name is "kc" or "tc" (i.e. the 2 letter mode for the function that
+   will be called).
+
+   Fncode is the function code of the multiply/divide built-in function.
+
+   Fntype is the tree type node of the function.  */
+
+static void
+create_complex_muldiv_inner (const char *mul_or_div,
+			     const char *lib_mode_name,
+			     const char *asm_mode_name,
+			     built_in_function fncode,
+			     tree fntype)
+{
+  char *asm_name = ACONCAT (("__", mul_or_div, asm_mode_name, "3", NULL));
+  char *name = ACONCAT (("__", mul_or_div, lib_mode_name, "3_", asm_mode_name,
+			 NULL));
+
+  tree fndecl = add_builtin_function (name, fntype, fncode, BUILT_IN_NORMAL,
+				      asm_name, NULL_TREE);
+
+  set_builtin_decl (fncode, fndecl, true);
+
+  if (1 || TARGET_DEBUG_BUILTIN)
+    fprintf (stderr, "create complex %s (%s), fncode: %d\n", name, asm_name,
+	     (int) fncode);
+
+  return;
+}
+
+/* Create both complex multiply and complex divide for a given 128-bit floating
+   point type.
+
+   Lib_mode_name is "ic", "kc", or "tc" (i.e. the 2 letter mode for the complex
+   type being created).
+
+   Asm_mode_name is "kc" or "tc" (i.e. the 2 letter mode for the function that
+   will be called).
+
+   Complex_mode is the mode of the complex type (i.e. KCmode, ICmode, or
+   TCmode).
+
+   Arg_type is the type of scalar 128-bit floating point type (i.e. the
+   _Float128, __ibm128, or long double type nodes).  */
+
+static void
+create_complex_muldiv (const char *lib_mode_name,
+		       const char *asm_mode_name,
+		       machine_mode complex_mode,
+		       tree arg_type)
+{
+  tree complex_type = (arg_type == long_double_type_node
+		       ? complex_long_double_type_node
+		       : build_complex_type (arg_type));
+  tree fntype = build_function_type_list (complex_type, arg_type, arg_type,
+					  arg_type, arg_type, NULL_TREE);
+
+  /* Build complex multiply.  */
+  built_in_function mul_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("mul", lib_mode_name, asm_mode_name, mul_fncode,
+			       fntype);
+
+  /* Build complex divide.  */
+  built_in_function div_fncode =
+    (built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + complex_mode
+			 - MIN_MODE_COMPLEX_FLOAT);
+
+  create_complex_muldiv_inner ("div", lib_mode_name, asm_mode_name, div_fncode,
+			       fntype);
+  return;
+}
+
 static void
 rs6000_init_libfuncs (void)
 {
@@ -11168,44 +11249,27 @@ rs6000_init_libfuncs (void)
 	init_float128_ieee (TFmode);
     }
 
-  /* Set up to call __mulkc3 and __divkc3 when long double uses the IEEE
-     128-bit encoding.  We cannot use the same name (__mulkc3 or __divkc3 for
-     both IEEE long double and for explicit _Float128/__float128) because
-     c_builtin_function will complain if we create two built-in functions with
-     the same name.  Instead we use an alias name for the case when long double
-     uses the IEEE 128-bit encoding.  Libgcc will create a weak alias reference
-     for this name.
+  /* Set up to call the appropriate __mul{kc,tc}3 and __div{kc,tc}3 for the
+     128-bit floating point types, using kc3 for IEEE 128-bit and tc3 for IBM
+     128-bit.  We only call this for the functions that don't use the default
+     names.
 
      We need to only execute this once.  If we have clone or target attributes,
      this will be called a second time.  We need to create the built-in
      function only once.  */
   static bool complex_muldiv_init_p = false;
 
-  if (TARGET_FLOAT128_TYPE && TARGET_IEEEQUAD && TARGET_LONG_DOUBLE_128
-      && !complex_muldiv_init_p)
+  if (!complex_muldiv_init_p
+      && (TARGET_FLOAT128_TYPE || TARGET_LONG_DOUBLE_128))
     {
       complex_muldiv_init_p = true;
 
-      tree fntype = build_function_type_list (complex_long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      long_double_type_node,
-					      NULL_TREE);
-
-      /* Create complex multiply.  */
-      built_in_function mul_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_MUL_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
-
-      create_complex_muldiv ("__multc3_ieee128", mul_fncode, fntype);
-
-      /* Create complex divide.  */
-      built_in_function div_fncode =
-	(built_in_function) (BUILT_IN_COMPLEX_DIV_MIN + TCmode
-			     - MIN_MODE_COMPLEX_FLOAT);
+      /* Create __ibm128 complex multiply divide.  */
+      create_complex_muldiv ("ic", "tc", ICmode, ibm128_float_type_node);
 
-      create_complex_muldiv ("__divtc3_ieee128", div_fncode, fntype);
+      if (TARGET_LONG_DOUBLE_128 && TARGET_IEEEQUAD)
+	/* Create long double (IEEE 128-bit) complex multiply/divide.  */
+	create_complex_muldiv ("tc", "kc", TCmode, long_double_type_node);
     }
 }
 
diff --git a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
index 0cfcea837ed..e34ed40bac2 100644
--- a/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/divkc3-2.c
@@ -14,4 +14,4 @@ divide (cld_t *p, cld_t *q, cld_t *r)
   *p = *q / *r;
 }
 
-/* { dg-final { scan-assembler "bl __divtc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __divkc3" } } */
diff --git a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
index 78ef1dc00f0..eee6de9e2a5 100644
--- a/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
+++ b/gcc/testsuite/gcc.target/powerpc/mulkc3-2.c
@@ -14,4 +14,4 @@ multiply (cld_t *p, cld_t *q, cld_t *r)
   *p = *q * *r;
 }
 
-/* { dg-final { scan-assembler "bl __multc3_ieee128" } } */
+/* { dg-final { scan-assembler "bl __mulkc3" } } */
diff --git a/libgcc/config/rs6000/float128-ifunc.c b/libgcc/config/rs6000/float128-ifunc.c
index 30d46bcb233..73cbca2fc9a 100644
--- a/libgcc/config/rs6000/float128-ifunc.c
+++ b/libgcc/config/rs6000/float128-ifunc.c
@@ -359,9 +359,3 @@ TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype)
 
 TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype)
   __attribute__ ((__ifunc__ ("__divkc3_resolve")));
-
-TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__mulkc3_resolve")));
-
-TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype)
-  __attribute__ ((__ifunc__ ("__divkc3_resolve")));
diff --git a/libgcc/config/rs6000/quad-float128.h b/libgcc/config/rs6000/quad-float128.h
index a684d0e1bcf..ae0622c744c 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -191,11 +191,6 @@ extern TFtype __trunctfkf2 (IBM128_TYPE);
 extern TCtype __mulkc3 (TFtype, TFtype, TFtype, TFtype);
 extern TCtype __divkc3 (TFtype, TFtype, TFtype, TFtype);
 
-/* Complex long double multiply/divide if long double uses the IEEE 128-bit
-   encoding.  */
-extern TCtype __multc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-extern TCtype __divtc3_ieee128 (TFtype, TFtype, TFtype, TFtype);
-
 /* Convert IEEE 128-bit floating point to/from string.  We explicitly use
    _Float128 instead of TFmode because _strtokf and _strfromkf must be compiled
    with long double being IBM 128.  */


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

end of thread, other threads:[~2022-07-08 20:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 20:24 [gcc(refs/users/meissner/heads/work093)] Rework setting 128-bit complex multiply and divide Michael Meissner
  -- strict thread matches above, loose matches on Subject: below --
2022-07-08 20:10 Michael Meissner
2022-07-08 20:01 Michael Meissner

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).