From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23477 invoked by alias); 22 Apr 2014 19:55:56 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 23468 invoked by uid 89); 22 Apr 2014 19:55:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wg0-f42.google.com Received: from mail-wg0-f42.google.com (HELO mail-wg0-f42.google.com) (74.125.82.42) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 22 Apr 2014 19:55:54 +0000 Received: by mail-wg0-f42.google.com with SMTP id y10so4331823wgg.13 for ; Tue, 22 Apr 2014 12:55:51 -0700 (PDT) X-Received: by 10.194.174.42 with SMTP id bp10mr4488783wjc.57.1398196551673; Tue, 22 Apr 2014 12:55:51 -0700 (PDT) Received: from localhost ([2.26.169.52]) by mx.google.com with ESMTPSA id u8sm63262226wjq.1.2014.04.22.12.55.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Apr 2014 12:55:51 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org,zadeck@naturalbridge.com, mikestump@comcast.net, rdsandiford@googlemail.com Cc: zadeck@naturalbridge.com, mikestump@comcast.net Subject: [wide-int 4/8] Tweak uses of new API Date: Tue, 22 Apr 2014 20:02:00 -0000 Message-ID: <87wqehdtq2.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2014-04/txt/msg01348.txt.bz2 This is an assorted bunch of API tweaks: - use neg_p instead of lts_p (..., 0) - use STATIC_ASSERT for things that are known at compile time - avoid unnecessary wide(st)_int temporaries and arithmetic - remove an unnecessary template parameter - use to_short_addr for an offset_int->HOST_WIDE_INT offset change Tested on x86_64-linux-gnu. OK to install? Thanks, Richard Index: gcc/ada/gcc-interface/cuintp.c =================================================================== --- gcc/ada/gcc-interface/cuintp.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/ada/gcc-interface/cuintp.c 2014-04-22 20:31:24.526996049 +0100 @@ -160,7 +160,7 @@ UI_From_gnu (tree Input) in a signed 64-bit integer. */ if (tree_fits_shwi_p (Input)) return UI_From_Int (tree_to_shwi (Input)); - else if (wi::lts_p (Input, 0) && TYPE_UNSIGNED (gnu_type)) + else if (wi::neg_p (Input) && TYPE_UNSIGNED (gnu_type)) return No_Uint; #endif Index: gcc/expmed.c =================================================================== --- gcc/expmed.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/expmed.c 2014-04-22 20:31:24.527996056 +0100 @@ -4971,7 +4971,7 @@ make_tree (tree type, rtx x) return t; case CONST_DOUBLE: - gcc_assert (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT); + STATIC_ASSERT (HOST_BITS_PER_WIDE_INT * 2 <= MAX_BITSIZE_MODE_ANY_INT); if (TARGET_SUPPORTS_WIDE_INT == 0 && GET_MODE (x) == VOIDmode) t = wide_int_to_tree (type, wide_int::from_array (&CONST_DOUBLE_LOW (x), 2, Index: gcc/fold-const.c =================================================================== --- gcc/fold-const.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/fold-const.c 2014-04-22 20:31:24.530996079 +0100 @@ -4274,9 +4274,8 @@ build_range_check (location_t loc, tree if (integer_onep (low) && TREE_CODE (high) == INTEGER_CST) { int prec = TYPE_PRECISION (etype); - wide_int osb = wi::set_bit_in_zero (prec - 1, prec) - 1; - if (osb == high) + if (wi::mask (prec - 1, false, prec) == high) { if (TYPE_UNSIGNED (etype)) { @@ -12950,7 +12949,7 @@ fold_binary_loc (location_t loc, && operand_equal_p (tree_strip_nop_conversions (TREE_OPERAND (arg0, 1)), arg1, 0) - && wi::bit_and (TREE_OPERAND (arg0, 0), 1) == 1) + && wi::extract_uhwi (TREE_OPERAND (arg0, 0), 0, 1) == 1) { return omit_two_operands_loc (loc, type, code == NE_EXPR Index: gcc/predict.c =================================================================== --- gcc/predict.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/predict.c 2014-04-22 20:31:24.531996086 +0100 @@ -1309,33 +1309,34 @@ predict_iv_comparison (struct loop *loop bool overflow, overall_overflow = false; widest_int compare_count, tem; - widest_int loop_bound = wi::to_widest (loop_bound_var); - widest_int compare_bound = wi::to_widest (compare_var); - widest_int base = wi::to_widest (compare_base); - widest_int compare_step = wi::to_widest (compare_step_var); - /* (loop_bound - base) / compare_step */ - tem = wi::sub (loop_bound, base, SIGNED, &overflow); + tem = wi::sub (wi::to_widest (loop_bound_var), + wi::to_widest (compare_base), SIGNED, &overflow); overall_overflow |= overflow; - widest_int loop_count = wi::div_trunc (tem, compare_step, SIGNED, - &overflow); + widest_int loop_count = wi::div_trunc (tem, + wi::to_widest (compare_step_var), + SIGNED, &overflow); overall_overflow |= overflow; - if (!wi::neg_p (compare_step) + if (!wi::neg_p (wi::to_widest (compare_step_var)) ^ (compare_code == LT_EXPR || compare_code == LE_EXPR)) { /* (loop_bound - compare_bound) / compare_step */ - tem = wi::sub (loop_bound, compare_bound, SIGNED, &overflow); + tem = wi::sub (wi::to_widest (loop_bound_var), + wi::to_widest (compare_var), SIGNED, &overflow); overall_overflow |= overflow; - compare_count = wi::div_trunc (tem, compare_step, SIGNED, &overflow); + compare_count = wi::div_trunc (tem, wi::to_widest (compare_step_var), + SIGNED, &overflow); overall_overflow |= overflow; } else { /* (compare_bound - base) / compare_step */ - tem = wi::sub (compare_bound, base, SIGNED, &overflow); + tem = wi::sub (wi::to_widest (compare_var), + wi::to_widest (compare_base), SIGNED, &overflow); overall_overflow |= overflow; - compare_count = wi::div_trunc (tem, compare_step, SIGNED, &overflow); + compare_count = wi::div_trunc (tem, wi::to_widest (compare_step_var), + SIGNED, &overflow); overall_overflow |= overflow; } if (compare_code == LE_EXPR || compare_code == GE_EXPR) Index: gcc/real.c =================================================================== --- gcc/real.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/real.c 2014-04-22 20:31:24.528996063 +0100 @@ -1446,7 +1446,7 @@ real_to_integer (const REAL_VALUE_TYPE * w = SIGSZ * HOST_BITS_PER_LONG + words * HOST_BITS_PER_WIDE_INT; tmp = real_int::from_array (val, (w + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT, w); - tmp = wi::lrshift (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp); + tmp = wi::lrshift (tmp, (words * HOST_BITS_PER_WIDE_INT) - exp); result = wide_int::from (tmp, precision, UNSIGNED); if (r->sign) Index: gcc/tree-chrec.c =================================================================== --- gcc/tree-chrec.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/tree-chrec.c 2014-04-22 20:31:24.531996086 +0100 @@ -490,21 +490,18 @@ tree_fold_binomial (tree type, tree n, u if (k == 1) return fold_convert (type, n); - /* Numerator = n. */ - wide_int num = n; - /* Check that k <= n. */ - if (wi::ltu_p (num, k)) + if (wi::ltu_p (n, k)) return NULL_TREE; /* Denominator = 2. */ wide_int denom = wi::two (TYPE_PRECISION (TREE_TYPE (n))); /* Index = Numerator-1. */ - wide_int idx = num - 1; + wide_int idx = wi::sub (n, 1); /* Numerator = Numerator*Index = n*(n-1). */ - num = wi::smul (num, idx, &overflow); + wide_int num = wi::smul (n, idx, &overflow); if (overflow) return NULL_TREE; Index: gcc/varasm.c =================================================================== --- gcc/varasm.c 2014-04-22 20:31:10.680896299 +0100 +++ gcc/varasm.c 2014-04-22 20:31:24.532996093 +0100 @@ -4898,7 +4898,7 @@ output_constructor_regular_field (oc_loc offset_int idx = wi::sext (wi::to_offset (local->index) - wi::to_offset (local->min_index), prec); fieldpos = (idx * wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (local->val)))) - .to_shwi (); + .to_short_addr (); } else if (local->field != NULL_TREE) fieldpos = int_byte_position (local->field);