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 */
}
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 */
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 */