Patchwork real_zerop for vectors

login
register
mail settings
Submitter Paolo Carlini
Date Oct. 28, 2012, 4:58 p.m.
Message ID <508D6452.3020203@oracle.com>
Download mbox | patch
Permalink /patch/194724/
State New
Headers show

Comments

Paolo Carlini - Oct. 28, 2012, 4:58 p.m.
Hi,

On 10/28/2012 05:51 PM, Marc Glisse wrote:
> On Sun, 28 Oct 2012, Marc Glisse wrote:
>
> [there are 4 real_*p that only differ by 1 character]
>
>> It is true that we could have a single function in tree.c:
>> bool real_intcstp (const_tree, int);
>
> The helper function could even take a REAL_VALUE_TYPE as second 
> argument, so the non-inline part doesn't have more work than currently.
I was writing something like the below.

Paolo.

/////////////////
Marc Glisse - Oct. 28, 2012, 5:06 p.m.
On Sun, 28 Oct 2012, Paolo Carlini wrote:

> I was writing something like the below.

I would move the one-liners (real_zerop, etc) to tree.h, but that looks 
good, yes.
Paolo Carlini - Oct. 28, 2012, 5:52 p.m.
On 10/28/2012 06:06 PM, Marc Glisse wrote:
> On Sun, 28 Oct 2012, Paolo Carlini wrote:
>
>> I was writing something like the below.
>
> I would move the one-liners (real_zerop, etc) to tree.h, but that 
> looks good, yes.
Ah great. But please, don't wait on me, I'm in the middle of too many 
other things, if you like the idea just integrate it with your other 
work in this area and go ahead!

Cheers,
Paolo.

Patch

Index: tree.c
===================================================================
--- tree.c	(revision 192887)
+++ tree.c	(working copy)
@@ -1984,20 +1984,39 @@  tree_floor_log2 (const_tree expr)
 	  : floor_log2 (low));
 }
 
+static int
+real_somep (const_tree expr, REAL_VALUE_TYPE dcst)
+{
+  STRIP_NOPS (expr);
+
+  switch (TREE_CODE (expr))
+    {
+    case REAL_CST:
+      return REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dcst)
+	     && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr))));
+    case COMPLEX_CST:
+      return real_somep (TREE_REALPART (expr), dcst)
+	     && real_somep (TREE_IMAGPART (expr), dconst0);
+    case VECTOR_CST:
+      {
+	unsigned i;
+	for (i = 0; i < VECTOR_CST_NELTS (expr); ++i)
+	  if (!real_somep (VECTOR_CST_ELT (expr, i), dcst))
+	    return false;
+	return true;
+      }
+    default:
+      return false;
+    }
+}
+
 /* Return 1 if EXPR is the real constant zero.  Trailing zeroes matter for
    decimal float constants, so don't return 1 for them.  */
 
 int
 real_zerop (const_tree expr)
 {
-  STRIP_NOPS (expr);
-
-  return ((TREE_CODE (expr) == REAL_CST
-	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst0)
-	   && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && real_zerop (TREE_REALPART (expr))
-	      && real_zerop (TREE_IMAGPART (expr))));
+  return real_somep (expr, dconst0);
 }
 
 /* Return 1 if EXPR is the real constant one in real or complex form.
@@ -2007,14 +2026,7 @@  real_zerop (const_tree expr)
 int
 real_onep (const_tree expr)
 {
-  STRIP_NOPS (expr);
-
-  return ((TREE_CODE (expr) == REAL_CST
-	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst1)
-	   && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && real_onep (TREE_REALPART (expr))
-	      && real_zerop (TREE_IMAGPART (expr))));
+  return real_somep (expr, dconst1);
 }
 
 /* Return 1 if EXPR is the real constant two.  Trailing zeroes matter
@@ -2023,14 +2035,7 @@  real_onep (const_tree expr)
 int
 real_twop (const_tree expr)
 {
-  STRIP_NOPS (expr);
-
-  return ((TREE_CODE (expr) == REAL_CST
-	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconst2)
-	   && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && real_twop (TREE_REALPART (expr))
-	      && real_zerop (TREE_IMAGPART (expr))));
+  return real_somep (expr, dconst2);
 }
 
 /* Return 1 if EXPR is the real constant minus one.  Trailing zeroes
@@ -2039,14 +2044,7 @@  real_twop (const_tree expr)
 int
 real_minus_onep (const_tree expr)
 {
-  STRIP_NOPS (expr);
-
-  return ((TREE_CODE (expr) == REAL_CST
-	   && REAL_VALUES_EQUAL (TREE_REAL_CST (expr), dconstm1)
-	   && !(DECIMAL_FLOAT_MODE_P (TYPE_MODE (TREE_TYPE (expr)))))
-	  || (TREE_CODE (expr) == COMPLEX_CST
-	      && real_minus_onep (TREE_REALPART (expr))
-	      && real_zerop (TREE_IMAGPART (expr))));
+  return real_somep (expr, dconstm1);
 }
 
 /* Nonzero if EXP is a constant or a cast of a constant.  */