From 2fc3fe45a4abc32707b1028203317f423e17e8fb Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Tue, 9 Sep 2008 10:06:17 +0000 Subject: [PATCH] tarval_ieee754_get_mantissa_size() implemented [r21772] --- include/libfirm/tv.h | 6 ++++++ ir/ir/iropt.c | 10 ++-------- ir/tv/tv.c | 23 +++++++++++++++++------ 3 files changed, 25 insertions(+), 14 deletions(-) diff --git a/include/libfirm/tv.h b/include/libfirm/tv.h index a5ff79150..e7186490f 100644 --- a/include/libfirm/tv.h +++ b/include/libfirm/tv.h @@ -788,6 +788,12 @@ unsigned tarval_ieee754_set_immediate_precision(unsigned bits); */ unsigned tarval_ieee754_get_exact(void); +/** + * Return the size of the mantissa in bits (including possible + * implicit bits) for the given mode. + */ +unsigned tarval_ieee754_get_mantissa_size(const ir_mode *mode); + /** * Enable/Disable floating point constant folding. */ diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index 513908d77..d6f6d3b8c 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -1262,14 +1262,8 @@ restart: if (mode_is_int(n_mode) && mode_is_float(a_mode)) { /* ConvI(ConvF(I)) -> I, iff float mantissa >= int mode */ size_t int_mantissa = get_mode_size_bits(n_mode) - (mode_is_signed(n_mode) ? 1 : 0); - size_t float_mantissa; - /* FIXME There is no way to get the mantissa size of a mode */ - switch (get_mode_size_bits(a_mode)) { - case 32: float_mantissa = 23 + 1; break; // + 1 for implicit 1 - case 64: float_mantissa = 52 + 1; break; - case 80: float_mantissa = 64; break; - default: float_mantissa = 0; break; - } + size_t float_mantissa = tarval_ieee754_get_mantissa_size(a_mode); + if (float_mantissa >= int_mantissa) { n = b; DBG_OPT_ALGSIM1(oldn, a, b, n, FS_OPT_CONV); diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 0ebef2373..b6f4b6677 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -176,17 +176,17 @@ static int cmp_tv(const void *p1, const void *p2, size_t n) { assert(tv1->kind == k_tarval); assert(tv2->kind == k_tarval); - if(tv1->mode < tv2->mode) + if (tv1->mode < tv2->mode) return -1; - if(tv1->mode > tv2->mode) + if (tv1->mode > tv2->mode) return 1; - if(tv1->length < tv2->length) + if (tv1->length < tv2->length) return -1; - if(tv1->length > tv2->length) + if (tv1->length > tv2->length) return 1; - if(tv1->value < tv2->value) + if (tv1->value < tv2->value) return -1; - if(tv1->value > tv2->value) + if (tv1->value > tv2->value) return 1; return 0; @@ -1696,6 +1696,17 @@ unsigned tarval_ieee754_get_exact(void) { return fc_is_exact(); } +/* Return the size of the mantissa in bits (including possible + implicit bits) for the given mode. */ +unsigned tarval_ieee754_get_mantissa_size(const ir_mode *mode) { + const ieee_descriptor_t *desc; + + assert(get_mode_arithmetic(mode) == irma_ieee754); + desc = get_descriptor(mode); + + return desc->mantissa_size + desc->explicit_one; +} + /* check if its the a floating point NaN */ int tarval_is_NaN(tarval *tv) { if (! mode_is_float(tv->mode)) -- 2.20.1