From 00cc326989907fc4a865a4cd4ad121423ca22806 Mon Sep 17 00:00:00 2001 From: Christoph Mallon Date: Mon, 8 Dec 2008 19:03:01 +0000 Subject: [PATCH] Repair converting long double to integer and hopefully do not break something else. [r24406] --- ir/tv/fltcalc.c | 9 ++++++--- ir/tv/strcalc.c | 10 ++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c index eedee4d16..040b5bc2b 100644 --- a/ir/tv/fltcalc.c +++ b/ir/tv/fltcalc.c @@ -1690,6 +1690,7 @@ int fc_flt2int(const fp_value *a, void *result, ir_mode *dst_mode) { int exp_bias = (1 << (a->desc.exponent_size - 1)) - 1; int exp_val = sc_val_to_long(_exp(a)) - exp_bias; int shift, highest; + int mantissa_size; if (a->sign && !mode_is_signed(dst_mode)) { /* FIXME: for now we cannot convert this */ @@ -1697,12 +1698,14 @@ int fc_flt2int(const fp_value *a, void *result, ir_mode *dst_mode) { } assert(exp_val >= 0 && "floating point value not integral before fc_flt2int() call"); - shift = exp_val - (a->desc.mantissa_size + ROUNDING_BITS); + mantissa_size = a->desc.mantissa_size + ROUNDING_BITS; + shift = exp_val - mantissa_size; + mantissa_size += a->desc.explicit_one; if (shift > 0) { - sc_shlI(_mant(a), shift, 64, 0, result); + sc_shlI(_mant(a), shift, mantissa_size, 0, result); } else { - sc_shrI(_mant(a), -shift, 64, 0, result); + sc_shrI(_mant(a), -shift, mantissa_size, 0, result); } /* check for overflow */ diff --git a/ir/tv/strcalc.c b/ir/tv/strcalc.c index 82fe3aa13..1bc6eee94 100644 --- a/ir/tv/strcalc.c +++ b/ir/tv/strcalc.c @@ -847,15 +847,13 @@ static void do_shr(const char *val1, char *buffer, long shift_cnt, int bitsize, carry_flag = 1; /* shift digits to the right with offset, carry and all */ - counter = 0; if ((bitsize >> 2) > shift_nib) { - buffer[counter] = shrs_table[_val(val1[shift_nib])][shift_mod][0]; - counter = 1; + buffer[0] = shrs_table[_val(val1[shift_nib])][shift_mod][0]; } - for (; counter < bitsize/4 - shift_nib; counter++) { + for (counter = 1; counter < ((bitsize + 3) >> 2) - shift_nib; counter++) { shrs = shrs_table[_val(val1[counter + shift_nib])][shift_mod]; - buffer[counter] = shrs[0]; - buffer[counter-1] = or_table[_val(buffer[counter-1])][_val(shrs[1])]; + buffer[counter] = shrs[0]; + buffer[counter - 1] = or_table[_val(buffer[counter-1])][_val(shrs[1])]; } /* the last digit is special in regard of signed/unsigned shift */ -- 2.20.1