Repair converting long double to integer and hopefully do not break something else.
authorChristoph Mallon <christoph.mallon@gmx.de>
Mon, 8 Dec 2008 19:03:01 +0000 (19:03 +0000)
committerChristoph Mallon <christoph.mallon@gmx.de>
Mon, 8 Dec 2008 19:03:01 +0000 (19:03 +0000)
[r24406]

ir/tv/fltcalc.c
ir/tv/strcalc.c

index eedee4d..040b5bc 100644 (file)
@@ -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 */
index 82fe3aa..1bc6eee 100644 (file)
@@ -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 */