From patchwork Sun Oct 28 16:58:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: real_zerop for vectors Date: Sun, 28 Oct 2012 06:58:58 -0000 From: Paolo Carlini X-Patchwork-Id: 194724 Message-Id: <508D6452.3020203@oracle.com> To: Marc Glisse Cc: gcc-patches@gcc.gnu.org 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. ///////////////// 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. */