public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Michael Meissner <meissner@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/meissner/heads/work092)] Iterate on getting long double complex multiply and divide working.
Date: Thu, 23 Jun 2022 18:35:11 +0000 (GMT)	[thread overview]
Message-ID: <20220623183511.DBA0A3856268@sourceware.org> (raw)

https://gcc.gnu.org/g:b9e7eb58e577057fb288bfe202bb7a2563289083

commit b9e7eb58e577057fb288bfe202bb7a2563289083
Author: Michael Meissner <meissner@linux.ibm.com>
Date:   Thu Jun 23 14:34:49 2022 -0400

    Iterate on getting long double complex multiply and divide working.
    
    2022-06-23   Michael Meissner  <meissner@linux.ibm.com>
    
    gcc/
            * config/rs6000/rs6000-builtin.cc (rs6000_type_string): The type
            for __float128 is __float128, not __ieee128.
            * config/rs6000/rs6000.cc (create_complex_muldiv): Add function
            back in.
            (rs6000_init_libfuncs): Move the IEEE 128-bit complex long double
            multiply and divide support here.  Use the names __multc3_ieee128
            and __divtc3_ieee128.
    
    libgcc/
            * config/rs6000/float128-ifunc.c (__multc3_ieee128): Add
            ifunc support.
            (__divtc3_ieee128): Likewise.
            * config/rs6000/quad-float128.h (__multc3_ieee128): Add
            Declaration.
            (__divtc3_ieee128): Likewise.

Diff:
---
 gcc/config/rs6000/rs6000-builtin.cc   |  2 +-
 gcc/config/rs6000/rs6000.cc           | 60 +++++++++++++++++++++++++++++++++++
 libgcc/config/rs6000/float128-ifunc.c |  6 ++++
 libgcc/config/rs6000/quad-float128.h  |  5 +++
 4 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000-builtin.cc b/gcc/config/rs6000/rs6000-builtin.cc
index b43a8039ad6..70cbca98e57 100644
--- a/gcc/config/rs6000/rs6000-builtin.cc
+++ b/gcc/config/rs6000/rs6000-builtin.cc
@@ -435,7 +435,7 @@ const char *rs6000_type_string (tree type_node)
   else if (type_node == ibm128_float_type_node)
     return "__ibm128";
   else if (type_node == ieee128_float_type_node)
-    return "__ieee128";
+    return "__float128";
   else if (type_node == opaque_V4SI_type_node)
     return "opaque";
   else if (POINTER_TYPE_P (type_node))
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index c036b05a077..17cb9bf7729 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -11034,6 +11034,26 @@ 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
@@ -11149,6 +11169,46 @@ rs6000_init_libfuncs (void)
       else
 	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.
+
+     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)
+    {
+      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_complex_muldiv ("__divtc3_ieee128", div_fncode, fntype);
+    }
 }
 
 /* Emit a potentially record-form instruction, setting DST from SRC.
diff --git a/libgcc/config/rs6000/float128-ifunc.c b/libgcc/config/rs6000/float128-ifunc.c
index 73cbca2fc9a..30d46bcb233 100644
--- a/libgcc/config/rs6000/float128-ifunc.c
+++ b/libgcc/config/rs6000/float128-ifunc.c
@@ -359,3 +359,9 @@ 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 ae0622c744c..a684d0e1bcf 100644
--- a/libgcc/config/rs6000/quad-float128.h
+++ b/libgcc/config/rs6000/quad-float128.h
@@ -191,6 +191,11 @@ 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.  */


             reply	other threads:[~2022-06-23 18:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23 18:35 Michael Meissner [this message]
2022-06-23 18:36 Michael Meissner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220623183511.DBA0A3856268@sourceware.org \
    --to=meissner@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).