diff options
author | Lawrence Crowl <crowl@google.com> | 2012-09-24 18:22:31 +0000 |
---|---|---|
committer | Lawrence Crowl <crowl@gcc.gnu.org> | 2012-09-24 18:22:31 +0000 |
commit | 9be0ac8c9e638bc1b52b83d34a98e8176af645e1 (patch) | |
tree | 023b0bf502c0f425e346dd501e463d522b3de28e /gcc/expmed.c | |
parent | ee38ecd4066dc3af0b893f2f4cda42d7938fa951 (diff) | |
download | gcc-9be0ac8c9e638bc1b52b83d34a98e8176af645e1.zip gcc-9be0ac8c9e638bc1b52b83d34a98e8176af645e1.tar.gz gcc-9be0ac8c9e638bc1b52b83d34a98e8176af645e1.tar.bz2 |
Finish conversion of uses of double_int to the new API.
Some old functionality required new interfaces, and these have been added to
double-int.[hc]:
double_int::from_pair - static constructor function
wide_mul_with_sign - double-wide multiply instruction
sub_with_overflow - subtraction with overlow testing
neg_with_overflow - negation with overlow testing
divmod_with_overflow - div and mod with overlow testing
This patch corrects the bootstrap problem on HPPA, via the addition of
sub_with_overflow. (The overflow properties of negation and addition are
different from subtraction.)
The prior two generations of the interface have been removed.
Some of these old interfaces are still used as static implementation in
double-int.c.
The changed compiler appears 0.321% faster with 80% confidence of being faster.
Tested on x86_64, HPPA, and SPARC. However, there are changes to the avr
config files, and I have not tested those.
Index: gcc/java/ChangeLog
2012-09-24 Lawrence Crowl <crowl@google.com>
* decl.c (java_init_decl_processing): Change to new double_int API.
* jcf-parse.c (get_constant): Likewise.
* boehm.c (mark_reference_fields): Likewise.
(get_boehm_type_descriptor): Likewise.
Index: gcc/ChangeLog
2012-09-24 Lawrence Crowl <crowl@google.com>
* double-int.h (double_int::from_pair): New.
(double_int::wide_mul_with_sign): New.
(double_int::sub_with_overflow): New.
(double_int::neg_with_overflow): New.
(double_int::divmod_with_overflow): New.
(shwi_to_double_int): Remove.
(uhwi_to_double_int): Remove.
(double_int_to_shwi): Remove.
(double_int_to_uhwi): Remove.
(double_int_fits_in_uhwi_p): Remove.
(double_int_fits_in_shwi_p): Remove.
(double_int_fits_in_hwi_p): Remove.
(double_int_mul): Remove.
(double_int_mul_with_sign): Remove.
(double_int_add): Remove.
(double_int_sub): Remove.
(double_int_neg): Remove.
(double_int_div): Remove.
(double_int_sdiv): Remove.
(double_int_udiv): Remove.
(double_int_mod): Remove.
(double_int_smod): Remove.
(double_int_umod): Remove.
(double_int_divmod): Remove.
(double_int_sdivmod): Remove.
(double_int_udivmod): Remove.
(double_int_multiple_of): Remove.
(double_int_setbit): Remove.
(double_int_ctz): Remove.
(double_int_not): Remove.
(double_int_ior): Remove.
(double_int_and): Remove.
(double_int_and_not): Remove.
(double_int_xor): Remove.
(double_int_lshift): Remove.
(double_int_rshift): Remove.
(double_int_lrotate): Remove.
(double_int_rrotate): Remove.
(double_int_negative_p): Remove.
(double_int_cmp): Remove.
(double_int_scmp): Remove.
(double_int_ucmp): Remove.
(double_int_max): Remove.
(double_int_smax): Remove.
(double_int_umax): Remove.
(double_int_min): Remove.
(double_int_smin): Remove.
(double_int_umin): Remove.
(double_int_ext): Remove.
(double_int_sext): Remove.
(double_int_zext): Remove.
(double_int_mask): Remove.
(double_int_max_value): Remove.
(double_int_min_value): Remove.
(double_int_zero_p): Remove.
(double_int_one_p): Remove.
(double_int_minus_one_p): Remove.
(double_int_equal_p): Remove.
(double_int_popcount): Remove.
(extern add_double_with_sign): Remove.
(#define add_double): Remove.
(extern neg_double): Remove.
(extern mul_double_with_sign): Remove.
(extern mul_double_wide_with_sign): Remove.
(#define mul_double): Remove.
(extern lshift_double): Remove.
(extern div_and_round_double): Remove.
* double-int.c (add_double_with_sign): Make static.
(#defined add_double): Localized from header.
(neg_double): Make static.
(mul_double_with_sign): Make static.
(mul_double_wide_with_sign): Make static.
(#defined mul_double): Localized from header.
(lshift_double): Make static.
(div_and_round_double): Make static.
(double_int::wide_mul_with_sign): New.
(double_int::sub_with_overflow): New.
(double_int::neg_with_overflow): New.
(double_int::divmod_with_overflow): New.
* emit-rtl.c (init_emit_once): Change to new double_int API.
* explow.c (plus_constant): Likewise.
* expmed.c (choose_multiplier): Likewise.
* fold-const.c (#define OVERFLOW_SUM_SIGN): Remove.
(int_const_binop_1): Change to new double_int API.
(fold_div_compare): Likewise.
(maybe_canonicalize_comparison): Likewise.
(pointer_may_wrap_p): Likewise.
(fold_negate_const): Likewise.
(fold_abs_const): Likewise.
* simplify-rtx.c (simplify_const_unary_operation): Likewise.
(simplify_const_binary_operation): Likewise.
* tree-chrec.c (tree_fold_binomial): Likewise.
* tree-vrp.c (extract_range_from_binary_expr_1): Likewise.
* config/sparc/sparc.c (sparc_fold_builtin): Likewise.
* config/avr/avr.c (avr_double_int_push_digit): Likewise.
(avr_map): Likewise.
(avr_map_decompose): Likewise.
(avr_out_insert_bits): Likewise.
Index: gcc/cp/ChangeLog
2012-09-24 Lawrence Crowl <crowl@google.com>
* init.c (build_new_1): Change to new double_int API.
* decl.c (build_enumerator): Likewise.
* typeck2.c (process_init_constructor_array): Likewise.
* mangle.c (write_array_type): Likewise.
Index: gcc/fortran/ChangeLog
2012-09-24 Lawrence Crowl <crowl@google.com>
* trans-expr.c (gfc_conv_cst_int_power): Change to new double_int API.
* target-memory.c (gfc_interpret_logical): Likewise.
From-SVN: r191675
Diffstat (limited to 'gcc/expmed.c')
-rw-r--r-- | gcc/expmed.c | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/gcc/expmed.c b/gcc/expmed.c index cde9246..767834e 100644 --- a/gcc/expmed.c +++ b/gcc/expmed.c @@ -3392,12 +3392,9 @@ choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision, unsigned HOST_WIDE_INT *multiplier_ptr, int *post_shift_ptr, int *lgup_ptr) { - HOST_WIDE_INT mhigh_hi, mlow_hi; - unsigned HOST_WIDE_INT mhigh_lo, mlow_lo; + double_int mhigh, mlow; int lgup, post_shift; int pow, pow2; - unsigned HOST_WIDE_INT nl, dummy1; - HOST_WIDE_INT nh, dummy2; /* lgup = ceil(log2(divisor)); */ lgup = ceil_log2 (d); @@ -3413,32 +3410,17 @@ choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision, gcc_assert (pow != HOST_BITS_PER_DOUBLE_INT); /* mlow = 2^(N + lgup)/d */ - if (pow >= HOST_BITS_PER_WIDE_INT) - { - nh = (HOST_WIDE_INT) 1 << (pow - HOST_BITS_PER_WIDE_INT); - nl = 0; - } - else - { - nh = 0; - nl = (unsigned HOST_WIDE_INT) 1 << pow; - } - div_and_round_double (TRUNC_DIV_EXPR, 1, nl, nh, d, (HOST_WIDE_INT) 0, - &mlow_lo, &mlow_hi, &dummy1, &dummy2); + double_int val = double_int_zero.set_bit (pow); + mlow = val.div (double_int::from_uhwi (d), true, TRUNC_DIV_EXPR); - /* mhigh = (2^(N + lgup) + 2^N + lgup - precision)/d */ - if (pow2 >= HOST_BITS_PER_WIDE_INT) - nh |= (HOST_WIDE_INT) 1 << (pow2 - HOST_BITS_PER_WIDE_INT); - else - nl |= (unsigned HOST_WIDE_INT) 1 << pow2; - div_and_round_double (TRUNC_DIV_EXPR, 1, nl, nh, d, (HOST_WIDE_INT) 0, - &mhigh_lo, &mhigh_hi, &dummy1, &dummy2); + /* mhigh = (2^(N + lgup) + 2^(N + lgup - precision))/d */ + val |= double_int_zero.set_bit (pow2); + mhigh = val.div (double_int::from_uhwi (d), true, TRUNC_DIV_EXPR); - gcc_assert (!mhigh_hi || nh - d < d); - gcc_assert (mhigh_hi <= 1 && mlow_hi <= 1); + gcc_assert (!mhigh.high || val.high - d < d); + gcc_assert (mhigh.high <= 1 && mlow.high <= 1); /* Assert that mlow < mhigh. */ - gcc_assert (mlow_hi < mhigh_hi - || (mlow_hi == mhigh_hi && mlow_lo < mhigh_lo)); + gcc_assert (mlow.ult (mhigh)); /* If precision == N, then mlow, mhigh exceed 2^N (but they do not exceed 2^(N+1)). */ @@ -3446,15 +3428,14 @@ choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision, /* Reduce to lowest terms. */ for (post_shift = lgup; post_shift > 0; post_shift--) { - unsigned HOST_WIDE_INT ml_lo = (mlow_hi << (HOST_BITS_PER_WIDE_INT - 1)) | (mlow_lo >> 1); - unsigned HOST_WIDE_INT mh_lo = (mhigh_hi << (HOST_BITS_PER_WIDE_INT - 1)) | (mhigh_lo >> 1); + int shft = HOST_BITS_PER_WIDE_INT - 1; + unsigned HOST_WIDE_INT ml_lo = (mlow.high << shft) | (mlow.low >> 1); + unsigned HOST_WIDE_INT mh_lo = (mhigh.high << shft) | (mhigh.low >> 1); if (ml_lo >= mh_lo) break; - mlow_hi = 0; - mlow_lo = ml_lo; - mhigh_hi = 0; - mhigh_lo = mh_lo; + mlow = double_int::from_uhwi (ml_lo); + mhigh = double_int::from_uhwi (mh_lo); } *post_shift_ptr = post_shift; @@ -3462,13 +3443,13 @@ choose_multiplier (unsigned HOST_WIDE_INT d, int n, int precision, if (n < HOST_BITS_PER_WIDE_INT) { unsigned HOST_WIDE_INT mask = ((unsigned HOST_WIDE_INT) 1 << n) - 1; - *multiplier_ptr = mhigh_lo & mask; - return mhigh_lo >= mask; + *multiplier_ptr = mhigh.low & mask; + return mhigh.low >= mask; } else { - *multiplier_ptr = mhigh_lo; - return mhigh_hi; + *multiplier_ptr = mhigh.low; + return mhigh.high; } } |