Prevent beuses from choking on basic blocks without control flow successors.
[libfirm] / ir / tv / fltcalc.c
index 8938cdc..5e2fc0a 100644 (file)
@@ -52,7 +52,7 @@
 
 #include "xmalloc.h"
 
-/** The number of extra precesion rounding bits */
+/** The number of extra precision rounding bits */
 #define ROUNDING_BITS 2
 
 typedef uint32_t UINT32;
@@ -1140,6 +1140,7 @@ LLDBL fc_val_to_ieee754(const fp_value *val) {
 
        value_t           buildval;
        ieee_descriptor_t desc;
+       unsigned          mantissa_size;
 
 #ifdef HAVE_LONG_DOUBLE
        desc.exponent_size = 15;
@@ -1152,6 +1153,7 @@ LLDBL fc_val_to_ieee754(const fp_value *val) {
        desc.explicit_one  = 0;
        desc.clss          = NORMAL;
 #endif
+       mantissa_size = desc.mantissa_size + desc.explicit_one;
 
        temp = alloca(calc_buffer_size);
        value = fc_cast(val, &desc, temp);
@@ -1169,10 +1171,10 @@ LLDBL fc_val_to_ieee754(const fp_value *val) {
        mantissa1 = 0;
 
        for (byte_offset = 0; byte_offset < 4; byte_offset++)
-               mantissa1 |= sc_sub_bits(_mant(value), desc.mantissa_size, byte_offset) << (byte_offset<<3);
+               mantissa1 |= sc_sub_bits(_mant(value), mantissa_size, byte_offset) << (byte_offset << 3);
 
        for (; (byte_offset<<3) < desc.mantissa_size; byte_offset++)
-               mantissa0 |= sc_sub_bits(_mant(value), desc.mantissa_size, byte_offset) << ((byte_offset-4)<<3);
+               mantissa0 |= sc_sub_bits(_mant(value), mantissa_size, byte_offset) << ((byte_offset - 4) << 3);
 
 #ifdef HAVE_LONG_DOUBLE
        buildval.val.high = sign << 15;
@@ -1408,6 +1410,7 @@ int fc_is_subnormal(const fp_value *a) {
 
 char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base) {
        char *mul_1;
+       LLDBL flt_val;
 
        mul_1 = alloca(calc_buffer_size);
 
@@ -1425,12 +1428,12 @@ char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base) {
                        snprintf(buf, buflen, "0.0");
                        break;
                default:
-                       /* XXX to be implemented */
+                       flt_val = fc_val_to_ieee754(val);
 #ifdef HAVE_LONG_DOUBLE
                        /* XXX 30 is arbitrary */
-                       snprintf(buf, buflen, "%.30LE", fc_val_to_ieee754(val));
+                       snprintf(buf, buflen, "%.30LE", flt_val);
 #else
-                       snprintf(buf, buflen, "%.18E", fc_val_to_ieee754(val));
+                       snprintf(buf, buflen, "%.18E", flt_val);
 #endif
                }
                break;
@@ -1448,10 +1451,11 @@ char *fc_print(const fp_value *val, char *buf, int buflen, unsigned base) {
                        snprintf(buf, buflen, "0.0");
                        break;
                default:
+                       flt_val = fc_val_to_ieee754(val);
 #ifdef HAVE_LONG_DOUBLE
-                       snprintf(buf, buflen, "%LA", fc_val_to_ieee754(val));
+                       snprintf(buf, buflen, "%LA", flt_val);
 #else
-                       snprintf(buf, buflen, "%A", fc_val_to_ieee754(val));
+                       snprintf(buf, buflen, "%A", flt_val);
 #endif
                }
                break;
@@ -1531,11 +1535,11 @@ void init_fltcalc(int precision) {
                /* does nothing if already init */
                if (precision == 0) precision = FC_DEFAULT_PRECISION;
 
-               init_strcalc(precision + 4);
+               init_strcalc(precision + 2 + ROUNDING_BITS);
 
-               /* needs additionally two bits to round, a bit as explicit 1., and one for
+               /* needs additionally rounding bits, one bit as explicit 1., and one for
                 * addition overflow */
-               max_precision = sc_get_precision() - 4;
+               max_precision = sc_get_precision() - (2 + ROUNDING_BITS);
                if (max_precision < precision)
                        printf("WARNING: not enough precision available, using %d\n", max_precision);