From: Christoph Mallon Date: Tue, 11 Sep 2007 11:53:49 +0000 (+0000) Subject: Handle left shift (when magnitude > mantissa) when converting float constants to... X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=117f69473fd6a80923a26aff2772341ebf9403dd;p=libfirm Handle left shift (when magnitude > mantissa) when converting float constants to int. [r15744] --- diff --git a/ir/tv/fltcalc.c b/ir/tv/fltcalc.c index ca16d7f3a..bed4dac97 100644 --- a/ir/tv/fltcalc.c +++ b/ir/tv/fltcalc.c @@ -1651,9 +1651,13 @@ 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 = a->desc.mantissa_size - exp_val + 2; + shift = exp_val - a->desc.mantissa_size - 2; - sc_shrI(_mant(a), shift, 64, 0, result); + if (shift > 0) { + sc_shlI(_mant(a), shift, 64, 0, result); + } else { + sc_shrI(_mant(a), -shift, 64, 0, result); + } /* check for overflow */ highest = sc_get_highest_set_bit(result); diff --git a/ir/tv/strcalc.c b/ir/tv/strcalc.c index 3fb6ab37d..dc6879645 100644 --- a/ir/tv/strcalc.c +++ b/ir/tv/strcalc.c @@ -1646,9 +1646,7 @@ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *m } -void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buffer) { - long offset = sc_val_to_long(val2); - +void sc_shlI(const void *val1, long offset, int radius, int sign, void *buffer) { carry_flag = 0; DEBUGPRINTF_COMPUTATION(("%s << %ld ", sc_print_hex(value1), offset)); @@ -1661,6 +1659,12 @@ void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buff } } +void sc_shl(const void *val1, const void *val2, int radius, int sign, void *buffer) { + long offset = sc_val_to_long(val2); + + sc_shlI(val1, offset, radius, sign, buffer); +} + void sc_shrI(const void *val1, long offset, int radius, int sign, void *buffer) { carry_flag = 0; diff --git a/ir/tv/strcalc.h b/ir/tv/strcalc.h index 1b6261911..ec666bc9b 100644 --- a/ir/tv/strcalc.h +++ b/ir/tv/strcalc.h @@ -143,6 +143,11 @@ void sc_mod(const void *value1, const void *value2, void *buffer); */ void sc_divmod(const void *value1, const void *value2, void *div_buffer, void *mod_buffer); +/** + * buffer = value1 << offset + */ +void sc_shlI(const void *val1, long offset, int radius, int sign, void *buffer); + /** * buffer = value1 << value2 */