Re: [wide-int 4/8] Tweak uses of new API
On Tue, Apr 22, 2014 at 9:55 PM, Richard Sandiford wrote: > 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? Ok. Thanks, Richard. > 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.c2014-04-22 20:31:10.680896299 +0100 > +++ gcc/expmed.c2014-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.c2014-04-22 20:31:10.680896299 +0100 > +++ gcc/fold-const.c2014-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 - b
[wide-int 4/8] Tweak uses of new API
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.c2014-04-22 20:31:10.680896299 +0100 +++ gcc/expmed.c2014-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.c2014-04-22 20:31:10.680896299 +0100 +++ gcc/fold-const.c2014-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 =