From patchwork Tue Aug 27 20:25:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenneth Zadeck X-Patchwork-Id: 270227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A0C032C007B for ; Wed, 28 Aug 2013 06:25:11 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; q= dns; s=default; b=xPmQpMl5vPp9Y2KInEpd16oRZ9LABnvu6q3eS7stNv7ep+ ZVaCKWn72b2vh7wLJ3YzTc2TEx4UclpFOfMrFvnIokbEJeryDJGBge7cuSPgmkv5 Xy0JKE3NAuHXNd4xSRq4wEfxQrbaGFVKfYXMFmkV+CKbKpQqA1u0+1K2osyWA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:mime-version:to:subject:content-type; s= default; bh=m2+MiWXvm46QVXqTk76uWuYO2Go=; b=w+3BoQQLqjv0QJmYPQ7R M6wwNVwr+t0LuZVPHBGBor689hIbUVD/WnrB8xGMisc0Ea3gxSG0Isl19itQtEN2 8DMnQTKf7AbOPt9sm6jX2CY0GycJ9G++BV/1hCIOOpEYdV6lG4ceF2VlPAuX07z4 kv6l+4oZVA3J1id5S6mpJTY= Received: (qmail 25245 invoked by alias); 27 Aug 2013 20:25:04 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 25236 invoked by uid 89); 27 Aug 2013 20:25:04 -0000 Received: from mail-ob0-f182.google.com (HELO mail-ob0-f182.google.com) (209.85.214.182) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 27 Aug 2013 20:25:04 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00 autolearn=ham version=3.3.2 X-HELO: mail-ob0-f182.google.com Received: by mail-ob0-f182.google.com with SMTP id wo10so5542343obc.41 for ; Tue, 27 Aug 2013 13:25:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:content-type; bh=sY0qPYqCl8DcPuMbIlPt2ufuU5WzrHSmgJ9GjbUpKhQ=; b=R8sOhcNqXZsRxFsPPpwzXqyOG/xAy52IJd0bO6RQI1gvaqgv4Su/57iS+8cF8XPEBx w3JwrS/DZdsTuHDtgs+vzCQQTxDseoIppAYzP5dabOAZ/sk1HggAPxxqTnUCYgadzFB1 a6VBU1JjwPGQ7k3f/RdWwZbDH7zBO+EmOPJvhzHQ+x8y7O1LwqPr/2bW2oDMsQCD3Nnl bLzyAu7y3JUn3VcNBMorIItIstZJb/BH0gNKmhBLmKpUeS1IJn+PZjZ6aR5biSCGVM14 qC+GoTSitPklWbfQioYxvXIlUORcthsrPYVawCYTyh42ipboxEcR38VmAObfvmv8JSr1 7Bsw== X-Gm-Message-State: ALoCoQnOMjFC840aupuEf/VW/yI6yRuSuRU626AdEMQWV94I1wSIrlAaOsR0aLeGLfFhT6y9M8zl X-Received: by 10.50.47.20 with SMTP id z20mr10695744igm.34.1377635101705; Tue, 27 Aug 2013 13:25:01 -0700 (PDT) Received: from moria.site (pool-98-113-157-218.nycmny.fios.verizon.net. [98.113.157.218]) by mx.google.com with ESMTPSA id m1sm1217igj.10.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 27 Aug 2013 13:25:01 -0700 (PDT) Message-ID: <521D0B1C.7060602@naturalbridge.com> Date: Tue, 27 Aug 2013 16:25:00 -0400 From: Kenneth Zadeck User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130801 Thunderbird/17.0.8 MIME-Version: 1.0 To: rguenther@suse.de, gcc-patches , Richard Sandiford , Mike Stump Subject: wide-int branch: cleaned up comparison functions. Removed the redundant implementations of several comparison function by just forwarding the oo version to the static version. Added static versions of cmp, cmpu and cmps. kenny Index: gcc/wide-int.h =================================================================== --- gcc/wide-int.h (revision 202033) +++ gcc/wide-int.h (working copy) @@ -443,12 +443,18 @@ public: template int cmp (const T &, signop) const; + template + static int cmp (const T1 &, const T2 &, signop); template int cmps (const T &) const; + template + static int cmps (const T1 &, const T2 &); template int cmpu (const T &) const; + template + static int cmpu (const T1 &, const T2 &); bool only_sign_bit_p (unsigned int) const; bool only_sign_bit_p () const; @@ -1137,38 +1143,7 @@ template inline bool wide_int_ro::operator == (const T &c) const { - bool result; - HOST_WIDE_INT ws[WIDE_INT_MAX_ELTS]; - const HOST_WIDE_INT *s; - unsigned int cl; - unsigned int p1, p2; - - p1 = precision; - - s = to_shwi1 (ws, &cl, &p2, c); - check_precision (&p1, &p2, true, false); - - if (p1 == 0) - /* There are prec 0 types and we need to do this to check their - min and max values. */ - result = (len == cl) && (val[0] == s[0]); - else if (p1 < HOST_BITS_PER_WIDE_INT) - { - unsigned HOST_WIDE_INT mask = ((HOST_WIDE_INT)1 << p1) - 1; - result = (val[0] & mask) == (s[0] & mask); - } - else if (p1 == HOST_BITS_PER_WIDE_INT) - result = val[0] == s[0]; - else - result = eq_p_large (val, len, p1, s, cl); - - if (result) - gcc_assert (len == cl); - -#ifdef DEBUG_WIDE_INT - debug_vwa ("wide_int_ro:: %d = (%s == %s)\n", result, *this, s, cl, p2); -#endif - return result; + return wide_int_ro::eq_p (*this, c); } /* Return true if C1 == C2. If both parameters have nonzero precisions, @@ -1219,31 +1194,7 @@ template inline bool wide_int_ro::lts_p (const T &c) const { - bool result; - HOST_WIDE_INT ws[WIDE_INT_MAX_ELTS]; - const HOST_WIDE_INT *s; - unsigned int cl; - unsigned int p1, p2; - - p1 = precision; - s = to_shwi1 (ws, &cl, &p2, c); - check_precision (&p1, &p2, false, true); - - if (p1 <= HOST_BITS_PER_WIDE_INT - && p2 <= HOST_BITS_PER_WIDE_INT) - { - gcc_assert (cl != 0); - HOST_WIDE_INT x0 = sext_hwi (val[0], p1); - HOST_WIDE_INT x1 = sext_hwi (s[0], p2); - result = x0 < x1; - } - else - result = lts_p_large (val, len, p1, s, cl, p2); - -#ifdef DEBUG_WIDE_INT - debug_vwa ("wide_int_ro:: %d = (%s lts_p %s\n", result, *this, s, cl, p2); -#endif - return result; + return wide_int_ro::lts_p (*this, c); } /* Return true if C1 < C2 using signed comparisons. */ @@ -1283,30 +1234,7 @@ template inline bool wide_int_ro::ltu_p (const T &c) const { - bool result; - HOST_WIDE_INT ws[WIDE_INT_MAX_ELTS]; - const HOST_WIDE_INT *s; - unsigned int cl; - unsigned int p1, p2; - - p1 = precision; - s = to_shwi1 (ws, &cl, &p2, c); - check_precision (&p1, &p2, false, true); - - if (p1 <= HOST_BITS_PER_WIDE_INT - && p2 <= HOST_BITS_PER_WIDE_INT) - { - unsigned HOST_WIDE_INT x0 = zext_hwi (val[0], p1); - unsigned HOST_WIDE_INT x1 = zext_hwi (s[0], p2); - result = x0 < x1; - } - else - result = ltu_p_large (val, len, p1, s, cl, p2); - -#ifdef DEBUG_WIDE_INT - debug_vwa ("wide_int_ro:: %d = (%s ltu_p %s)\n", result, *this, s, cl, p2); -#endif - return result; + return wide_int_ro::ltu_p (*this, c); } /* Return true if C1 < C2 using unsigned comparisons. */ @@ -1524,27 +1452,37 @@ wide_int_ro::ge_p (const T1 &c1, const T return geu_p (c1, c2); } -/* Returns -1 if THIS < C, 0 if THIS == C and 1 if A > C using +/* Returns -1 if THIS < C, 0 if THIS == C and 1 if THIS > C using signed compares. */ template inline int wide_int_ro::cmps (const T &c) const { + return wide_int_ro::cmps (*this, c); +} + +/* Returns -1 if C1 < C2, 0 if C1 == C2 and 1 if C1 > C2 using + signed compares. */ +template +inline int +wide_int_ro::cmps (const T1 &c1, const T2 &c2) +{ int result; - HOST_WIDE_INT ws[WIDE_INT_MAX_ELTS]; - const HOST_WIDE_INT *s; - unsigned int cl; - unsigned int prec; + HOST_WIDE_INT ws1[WIDE_INT_MAX_ELTS]; + HOST_WIDE_INT ws2[WIDE_INT_MAX_ELTS]; + const HOST_WIDE_INT *s1, *s2; /* Returned data */ + unsigned int cl1, cl2; /* array lengths */ + unsigned int p1, p2; /* precisions */ - s = to_shwi1 (ws, &cl, &prec, c); - if (prec == 0) - prec = precision; + s1 = to_shwi1 (ws1, &cl1, &p1, c1); + s2 = to_shwi1 (ws2, &cl2, &p2, c2); + check_precision (&p1, &p2, false, true); - if (precision <= HOST_BITS_PER_WIDE_INT - && prec <= HOST_BITS_PER_WIDE_INT) + if (p1 <= HOST_BITS_PER_WIDE_INT + && p2 <= HOST_BITS_PER_WIDE_INT) { - HOST_WIDE_INT x0 = sext_hwi (val[0], precision); - HOST_WIDE_INT x1 = sext_hwi (s[0], prec); + HOST_WIDE_INT x0 = sext_hwi (s1[0], p1); + HOST_WIDE_INT x1 = sext_hwi (s2[0], p2); if (x0 < x1) result = -1; @@ -1554,35 +1492,45 @@ wide_int_ro::cmps (const T &c) const result = 0; } else - result = cmps_large (val, len, precision, s, cl, prec); + result = cmps_large (s1, cl1, p1, s2, cl2, p2); #ifdef DEBUG_WIDE_INT - debug_vwa ("wide_int_ro:: %d = (%s cmps %s)\n", result, *this, s, cl, prec); + debug_vaa ("wide_int_ro:: %d = (%s cmps %s)\n", result, s1, cl1, p1, s2, cl2, p2); #endif return result; } -/* Returns -1 if THIS < C, 0 if THIS == C and 1 if A > C using +/* Returns -1 if THIS < C, 0 if THIS == C and 1 if THIS > C using unsigned compares. */ template int wide_int_ro::cmpu (const T &c) const { + return wide_int_ro::cmpu (*this, c); +} + +/* Returns -1 if C1 < C2, 0 if C1 == C2 and 1 if C1 > C2 using + unsigned compares. */ +template +int +wide_int_ro::cmpu (const T1 &c1, const T2 &c2) +{ int result; - HOST_WIDE_INT ws[WIDE_INT_MAX_ELTS]; - const HOST_WIDE_INT *s; - unsigned int cl; - unsigned int prec; + HOST_WIDE_INT ws1[WIDE_INT_MAX_ELTS]; + HOST_WIDE_INT ws2[WIDE_INT_MAX_ELTS]; + const HOST_WIDE_INT *s1, *s2; /* Returned data */ + unsigned int cl1, cl2; /* array lengths */ + unsigned int p1, p2; /* precisions */ - s = to_shwi1 (ws, &cl, &prec, c); - if (prec == 0) - prec = precision; + s1 = to_shwi1 (ws1, &cl1, &p1, c1); + s2 = to_shwi1 (ws2, &cl2, &p2, c2); + check_precision (&p1, &p2, false, true); - if (precision <= HOST_BITS_PER_WIDE_INT - && prec <= HOST_BITS_PER_WIDE_INT) + if (p1 <= HOST_BITS_PER_WIDE_INT + && p2 <= HOST_BITS_PER_WIDE_INT) { - unsigned HOST_WIDE_INT x0 = zext_hwi (val[0], precision); - unsigned HOST_WIDE_INT x1 = zext_hwi (s[0], prec); + unsigned HOST_WIDE_INT x0 = zext_hwi (s1[0], p1); + unsigned HOST_WIDE_INT x1 = zext_hwi (s2[0], p2); if (x0 < x1) result = -1; @@ -1592,10 +1540,10 @@ wide_int_ro::cmpu (const T &c) const result = 1; } else - result = cmpu_large (val, len, precision, s, cl, prec); + result = cmpu_large (s1, cl1, p1, s2, cl2, p2); #ifdef DEBUG_WIDE_INT - debug_vwa ("wide_int_ro:: %d = (%s cmpu %s)\n", result, *this, s, cl, prec); + debug_vaa ("wide_int_ro:: %d = (%s cmpu %s)\n", result, s1, cl1, p1, s2, cl2, p2); #endif return result; @@ -1613,6 +1561,18 @@ wide_int_ro::cmp (const T &c, signop sgn return cmpu (c); } +/* Return -1, 0 or 1 depending on how C1 compares with C2. + Signedness is indicated by SGN. */ +template +inline int +wide_int_ro::cmp (const T1 &c1, const T2 &c2, signop sgn) +{ + if (sgn == SIGNED) + return wide_int_ro::cmps (c1, c2); + else + return wide_int_ro::cmpu (c1, c2); +} + /* Return true if THIS has the sign bit set to 1 and all other bits are zero. */ inline bool Index: gcc/tree.c =================================================================== --- gcc/tree.c (revision 202033) +++ gcc/tree.c (working copy) @@ -8565,7 +8565,7 @@ retry: if ((c_neg || !t_neg) && wc.ltu_p (wd)) return false; } - else if (wc.cmp (wd, TYPE_SIGN (TREE_TYPE (type_low_bound))) < 0) + else if (wc.lt_p (wd, TYPE_SIGN (TREE_TYPE (type_low_bound)))) return false; ok_for_low_bound = true; } @@ -8586,7 +8586,7 @@ retry: if ((t_neg || !c_neg) && wc.gtu_p (wd)) return false; } - else if (wc.cmp (wd, TYPE_SIGN (TREE_TYPE (type_high_bound))) > 0) + else if (wc.gt_p (wd, TYPE_SIGN (TREE_TYPE (type_high_bound)))) return false; ok_for_high_bound = true; }