public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sylvain Noiry <snoiry@kalrayinc.com>
To: gcc-patches@gcc.gnu.org
Cc: Sylvain Noiry <snoiry@kalrayinc.com>
Subject: [PATCH 8/9] Native complex operations: Add explicit vector of complex
Date: Mon, 17 Jul 2023 11:02:49 +0200	[thread overview]
Message-ID: <20230717090250.4645-9-snoiry@kalrayinc.com> (raw)
In-Reply-To: <20230717090250.4645-1-snoiry@kalrayinc.com>

Allow the creation and usage of builtins vectors of complex
in C, using __attribute__ ((vector_size ()))

gcc/c-family/ChangeLog:

	* c-attribs.cc (vector_mode_valid_p): Add cases for
	vectors of complex
	(handle_mode_attribute): Likewise
	(type_valid_for_vector_size): Likewise
	* c-common.cc (c_common_type_for_mode): Likewise
	(vector_types_compatible_elements_p): Likewise

gcc/ChangeLog:

	* fold-const.cc (fold_binary_loc): Likewise

gcc/c/ChangeLog:

	* c-typeck.cc (build_unary_op): Likewise
---
 gcc/c-family/c-attribs.cc | 12 ++++++++++--
 gcc/c-family/c-common.cc  | 20 +++++++++++++++++++-
 gcc/c/c-typeck.cc         |  8 ++++++--
 gcc/fold-const.cc         |  1 +
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index e2792ca6898..d4de85160c1 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -2019,6 +2019,8 @@ vector_mode_valid_p (machine_mode mode)
   /* Doh!  What's going on?  */
   if (mclass != MODE_VECTOR_INT
       && mclass != MODE_VECTOR_FLOAT
+      && mclass != MODE_VECTOR_COMPLEX_INT
+      && mclass != MODE_VECTOR_COMPLEX_FLOAT
       && mclass != MODE_VECTOR_FRACT
       && mclass != MODE_VECTOR_UFRACT
       && mclass != MODE_VECTOR_ACCUM
@@ -2125,6 +2127,8 @@ handle_mode_attribute (tree *node, tree name, tree args,
 
 	case MODE_VECTOR_INT:
 	case MODE_VECTOR_FLOAT:
+	case MODE_VECTOR_COMPLEX_INT:
+	case MODE_VECTOR_COMPLEX_FLOAT:
 	case MODE_VECTOR_FRACT:
 	case MODE_VECTOR_UFRACT:
 	case MODE_VECTOR_ACCUM:
@@ -4361,9 +4365,13 @@ type_valid_for_vector_size (tree type, tree atname, tree args,
 
   if ((!INTEGRAL_TYPE_P (type)
        && !SCALAR_FLOAT_TYPE_P (type)
+       && !COMPLEX_INTEGER_TYPE_P (type)
+       && !COMPLEX_FLOAT_TYPE_P (type)
        && !FIXED_POINT_TYPE_P (type))
-      || (!SCALAR_FLOAT_MODE_P (orig_mode)
-	  && GET_MODE_CLASS (orig_mode) != MODE_INT
+      || ((!SCALAR_FLOAT_MODE_P (orig_mode)
+	   && GET_MODE_CLASS (orig_mode) != MODE_INT)
+	  && (!COMPLEX_FLOAT_MODE_P (orig_mode)
+	      && GET_MODE_CLASS (orig_mode) != MODE_COMPLEX_INT)
 	  && !ALL_SCALAR_FIXED_POINT_MODE_P (orig_mode))
       || !tree_fits_uhwi_p (TYPE_SIZE_UNIT (type))
       || TREE_CODE (type) == BOOLEAN_TYPE)
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 6ab63dae997..9574c074d26 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -2430,7 +2430,23 @@ c_common_type_for_mode (machine_mode mode, int unsignedp)
 	      : make_signed_type (precision));
     }
 
-  if (COMPLEX_MODE_P (mode))
+  if (GET_MODE_CLASS (mode) == MODE_VECTOR_BOOL
+	   && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
+    {
+      unsigned int elem_bits = vector_element_size (GET_MODE_BITSIZE (mode),
+						    GET_MODE_NUNITS (mode));
+      tree bool_type = build_nonstandard_boolean_type (elem_bits);
+      return build_vector_type_for_mode (bool_type, mode);
+    }
+  else if (VECTOR_MODE_P (mode)
+	   && valid_vector_subparts_p (GET_MODE_NUNITS (mode)))
+    {
+      machine_mode inner_mode = GET_MODE_INNER (mode);
+      tree inner_type = c_common_type_for_mode (inner_mode, unsignedp);
+      if (inner_type != NULL_TREE)
+	return build_vector_type_for_mode (inner_type, mode);
+    }
+  else if (COMPLEX_MODE_P (mode))
     {
       machine_mode inner_mode;
       tree inner_type;
@@ -8104,9 +8120,11 @@ vector_types_compatible_elements_p (tree t1, tree t2)
 
   gcc_assert ((INTEGRAL_TYPE_P (t1)
 	       || c1 == REAL_TYPE
+	       || c1 == COMPLEX_TYPE
 	       || c1 == FIXED_POINT_TYPE)
 	      && (INTEGRAL_TYPE_P (t2)
 		  || c2 == REAL_TYPE
+		  || c2 == COMPLEX_TYPE
 		  || c2 == FIXED_POINT_TYPE));
 
   t1 = c_common_signed_type (t1);
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index 7cf411155c6..68a9646cf5b 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -4584,7 +4584,9 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
       /* ~ works on integer types and non float vectors. */
       if (typecode == INTEGER_TYPE
 	  || (gnu_vector_type_p (TREE_TYPE (arg))
-	      && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))))
+	      && !VECTOR_FLOAT_TYPE_P (TREE_TYPE (arg))
+	      && !COMPLEX_INTEGER_TYPE_P (TREE_TYPE (TREE_TYPE (arg)))
+	      && !COMPLEX_FLOAT_TYPE_P (TREE_TYPE (TREE_TYPE (arg)))))
 	{
 	  tree e = arg;
 
@@ -4607,7 +4609,9 @@ build_unary_op (location_t location, enum tree_code code, tree xarg,
 	  if (!noconvert)
 	    arg = default_conversion (arg);
 	}
-      else if (typecode == COMPLEX_TYPE)
+      else if (typecode == COMPLEX_TYPE
+	  || COMPLEX_INTEGER_TYPE_P (TREE_TYPE (TREE_TYPE (arg)))
+	  || COMPLEX_FLOAT_TYPE_P (TREE_TYPE (TREE_TYPE (arg))))
 	{
 	  code = CONJ_EXPR;
 	  pedwarn (location, OPT_Wpedantic,
diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc
index f1224b6a548..9e9f711e82d 100644
--- a/gcc/fold-const.cc
+++ b/gcc/fold-const.cc
@@ -11109,6 +11109,7 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type,
 	     to __complex__ ( x, y ).  This is not the same for SNaNs or
 	     if signed zeros are involved.  */
 	  if (!HONOR_SNANS (arg0)
+	      && !(VECTOR_TYPE_P (TREE_TYPE (arg0)))
 	      && !HONOR_SIGNED_ZEROS (arg0)
 	      && COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0)))
 	    {
-- 
2.17.1






  parent reply	other threads:[~2023-07-17  9:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-17  9:02 [PATCH 0/9] Native complex operations Sylvain Noiry
2023-07-17  9:02 ` [PATCH 1/9] Native complex operations: Conditional lowering Sylvain Noiry
2023-07-17  9:02 ` [PATCH 2/9] Native complex operations: Move functions to hooks Sylvain Noiry
2023-07-17  9:02 ` [PATCH 3/9] Native complex operations: Add gen_rtx_complex hook Sylvain Noiry
2023-07-17  9:02 ` [PATCH 4/9] Native complex operations: Allow native complex regs and ops in rtl Sylvain Noiry
2023-07-17  9:02 ` [PATCH 5/9] Native complex operations: Add the conjugate op in optabs Sylvain Noiry
2023-07-17  9:02 ` [PATCH 6/9] Native complex operations: Update how complex rotations are handled Sylvain Noiry
2023-07-17  9:02 ` [PATCH 7/9] Native complex operations: Vectorization of native complex operations Sylvain Noiry
2023-07-17  9:02 ` Sylvain Noiry [this message]
2023-07-17  9:02 ` [PATCH 9/9] Native complex operation: Experimental support in x86 backend Sylvain Noiry
2023-09-12 10:07   ` [PATCH v2 0/11] Native complex operations Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 01/11] Native complex ops : Conditional lowering Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 02/11] Native complex ops: Move functions to hooks Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 03/11] Native complex ops: Add gen_rtx_complex hook Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 04/11] Native complex ops: Allow native complex regs and ops in rtl Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 05/11] Native complex ops: Add the conjugate op in optabs Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 06/11] Native complex ops: Update how complex rotations are handled Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 07/11] Native complex ops: Vectorization of native complex operations Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 08/11] Native complex ops: Add explicit vector of complex Sylvain Noiry
2023-09-12 17:25       ` Joseph Myers
2023-09-13  6:48         ` Richard Biener
2023-09-12 10:07     ` [PATCH v2 09/11] Native complex ops: remove useless special cases Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 10/11] Native complex ops: Add a fast complex multiplication pattern Sylvain Noiry
2023-09-12 10:07     ` [PATCH v2 11/11] Native complex ops: Experimental support in x86 backend Sylvain Noiry

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=20230717090250.4645-9-snoiry@kalrayinc.com \
    --to=snoiry@kalrayinc.com \
    --cc=gcc-patches@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).