-/* fltcalc.c
- * Authors: Matthias Heil
+/*
+ * Project: libFIRM
+ * File name: ir/tv/fltcalc.c
+ * Purpose:
+ * Author:
+ * Modified by:
+ * Created: 2003
+ * CVS-ID: $Id$
+ * Copyright: (c) 2003 Universität Karlsruhe
+ * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+
#include "fltcalc.h"
#include "strcalc.h"
# undef NAN
#endif
+#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
-#include <alloca.h>
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
typedef uint32_t UINT32;
* value is represented as a pseudo-struct char array, addressed
* by macros
* struct {
- * char sign; // 0 for positive, 1 for negative
+ * char sign; // 0 for positive, 1 for negative
* char exp[VALUE_SIZE];
* char mant[VALUE_SIZE];
* descriptor_t desc;
_fail_char(old_str, len, str - old_str);
}
}
- } // switch(state)
+ } /* switch(state) */
done:
sc_val_from_str(mant_str, strlen(mant_str), _mant(result));
char *temp;
int bias_res, bias_val, mant_val;
value_t srcval;
+ UINT32 sign, exponent, mantissa0, mantissa1;
srcval.d = l;
bias_res = ((1<<exp_size)/2-1);
#ifdef HAVE_LONG_DOUBLE
- mant_val = 64;
- bias_val = 0x3fff;
- UINT32 sign = (srcval.val.high & 0x00008000) != 0;
- UINT32 exponent = (srcval.val.high & 0x00007FFF) ;
- UINT32 mantissa0 = srcval.val.mid;
- UINT32 mantissa1 = srcval.val.low;
+ mant_val = 64;
+ bias_val = 0x3fff;
+ sign = (srcval.val.high & 0x00008000) != 0;
+ exponent = (srcval.val.high & 0x00007FFF) ;
+ mantissa0 = srcval.val.mid;
+ mantissa1 = srcval.val.low;
#else /* no long double */
- mant_val = 52;
- bias_val = 0x3ff;
- UINT32 sign = (srcval.val.high & 0x80000000) != 0;
- UINT32 exponent = (srcval.val.high & 0x7FF00000) >> 20;
- UINT32 mantissa0 = srcval.val.high & 0x000FFFFF;
- UINT32 mantissa1 = srcval.val.low;
+ mant_val = 52;
+ bias_val = 0x3ff;
+ sign = (srcval.val.high & 0x80000000) != 0;
+ exponent = (srcval.val.high & 0x7FF00000) >> 20;
+ mantissa0 = srcval.val.high & 0x000FFFFF;
+ mantissa1 = srcval.val.low;
#endif
#ifdef HAVE_LONG_DOUBLE
- TRACEPRINTF(("val_from_float(%.8X%.8X%.8X)\n", ((int*)&l)[2], ((int*)&l)[1], ((int*)&l)[0]));//srcval.val.high, srcval.val.mid, srcval.val.low));
+ TRACEPRINTF(("val_from_float(%.8X%.8X%.8X)\n", ((int*)&l)[2], ((int*)&l)[1], ((int*)&l)[0]));/* srcval.val.high, srcval.val.mid, srcval.val.low)); */
DEBUGPRINTF(("(%d-%.4X-%.8X%.8X)\n", sign, exponent, mantissa0, mantissa1));
#else
TRACEPRINTF(("val_from_float(%.8X%.8X)\n", srcval.val.high, srcval.val.low));
for (; (byte_offset<<3) < result_mantissa; byte_offset++)
mantissa0 |= sc_sub_bits(_mant(value), result_mantissa, byte_offset) << ((byte_offset-4)<<3);
-#ifndef HAVE_LONG_DOUBLE
- mantissa0 &= 0x000FFFFF; /* get rid of garbage */
-#endif
-
#ifdef HAVE_LONG_DOUBLE
buildval.val.high = sign << 15;
buildval.val.high |= exponent;
buildval.val.mid = mantissa0;
buildval.val.low = mantissa1;
#else /* no long double */
+ mantissa0 &= 0x000FFFFF; /* get rid of garbage */
buildval.val.high = sign << 31;
buildval.val.high |= exponent << 20;
buildval.val.high |= mantissa0;
}
}
+void finish_fltcalc (void) {
+ free(calc_buffer); calc_buffer = NULL;
+}
+
/* definition of interface functions */
FC_DEFINE2(add)
FC_DEFINE2(sub)