beifg: Factorise code to count interference components.
[libfirm] / ir / tv / fltcalc.h
index a66aa7b..867262d 100644 (file)
@@ -1,20 +1,6 @@
 /*
- * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
- *
  * This file is part of libFirm.
- *
- * This file may be distributed and/or modified under the terms of the
- * GNU General Public License version 2 as published by the Free Software
- * Foundation and appearing in the file LICENSE.GPL included in the
- * packaging of this file.
- *
- * Licensees holding valid libFirm Professional Edition licenses may use
- * this file in accordance with the libFirm Commercial License.
- * Agreement provided with the Software.
- *
- * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
- * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE.
+ * Copyright (C) 2012 University of Karlsruhe.
  */
 
 /**
  * @brief    tarval floating point calculations
  * @date     2003
  * @author   Mathias Heil
- * @version  $Id$
  */
 #ifndef FIRM_TV_FLTCALC_H
 #define FIRM_TV_FLTCALC_H
 
-#include "firm_config.h"
+#include <stdlib.h>
 #include "firm_types.h"
-
-#ifdef HAVE_LONG_DOUBLE
-/* XXX Set this via autoconf */
-#define HAVE_EXPLICIT_ONE
-typedef long double LLDBL;
-#else
-typedef double LLDBL;
-#endif
+#include "irtypes.h"
 
 enum {
        FC_DEC,
@@ -59,25 +37,15 @@ typedef enum {
  * possible float states
  */
 typedef enum {
-       NORMAL,       /**< normal representation, implicit 1 */
-       ZERO,         /**< +/-0 */
-       SUBNORMAL,    /**< denormals, implicit 0 */
-       INF,          /**< +/-oo */
-       NAN,          /**< Not A Number */
+       FC_NORMAL,       /**< normal representation, implicit 1 */
+       FC_ZERO,         /**< +/-0 */
+       FC_SUBNORMAL,    /**< denormals, implicit 0 */
+       FC_INF,          /**< +/-oo */
+       FC_NAN,          /**< Not A Number */
 } value_class_t;
 
-/**
- * A descriptor for an IEEE float value.
- */
-typedef struct ieee_descriptor_t {
-       unsigned char exponent_size;    /**< size of exponent in bits */
-       unsigned char mantissa_size;    /**< size of mantissa in bits */
-       unsigned char explicit_one;     /**< set if the leading one is explicit */
-       unsigned char clss;             /**< state of this float */
-} ieee_descriptor_t;
-
-struct _fp_value;
-typedef struct _fp_value fp_value;
+struct fp_value;
+typedef struct fp_value fp_value;
 
 /*@{*/
 /** internal buffer access
@@ -90,14 +58,14 @@ const void *fc_get_buffer(void);
 int fc_get_buffer_length(void);
 /*}@*/
 
-void *fc_val_from_str(const char *str, unsigned int len, const ieee_descriptor_t *desc, void *result);
+void *fc_val_from_str(const char *str, size_t len, const float_descriptor_t *desc, void *result);
 
 /** get the representation of a floating point value
  * This function tries to builds a representation having the same value as the
  * float number passed.
- * If the wished precision is less than the precision of LLDBL the value built
- * will be rounded. Therefore only an approximation of the passed float can be
- * expected in this case.
+ * If the wished precision is less than the precision of long double the value
+ * built will be rounded. Therefore only an approximation of the passed float
+ * can be expected in this case.
  *
  * @param l       The floating point number to build a representation for
  * @param desc    The floating point descriptor
@@ -109,12 +77,13 @@ void *fc_val_from_str(const char *str, unsigned int len, const ieee_descriptor_t
  * @return  The result pointer passed to the function. If this was NULL this returns
  *          a pointer to the internal accumulator buffer
  */
-fp_value *fc_val_from_ieee754(LLDBL l, const ieee_descriptor_t *desc, fp_value *result);
+fp_value *fc_val_from_ieee754(long double l, const float_descriptor_t *desc,
+                              fp_value *result);
 
 /** retrieve the float value of an internal value
- * This function casts the internal value to LLDBL and returns a LLDBL with
- * that value.
- * This implies that values of higher precision than LLDBL are subject to
+ * This function casts the internal value to long double and returns a
+ * long double with that value.
+ * This implies that values of higher precision than long double are subject to
  * rounding, so the returned value might not the same than the actually
  * represented value.
  *
@@ -122,7 +91,7 @@ fp_value *fc_val_from_ieee754(LLDBL l, const ieee_descriptor_t *desc, fp_value *
  *
  * @return a float value approximating the represented value
  */
-LLDBL fc_val_to_ieee754(const fp_value *val);
+long double fc_val_to_ieee754(const fp_value *val);
 
 /** cast a value to another precision
  * This function changes the precision of a float representation.
@@ -138,7 +107,7 @@ LLDBL fc_val_to_ieee754(const fp_value *val);
  * @return  The result pointer passed to the function. If this was NULL this returns
  *          a pointer to the internal accumulator buffer
  */
-fp_value *fc_cast(const fp_value *val, const ieee_descriptor_t *desc, fp_value *result);
+fp_value *fc_cast(const fp_value *val, const float_descriptor_t *desc, fp_value *result);
 
 /*@{*/
 /** build a special float value
@@ -153,12 +122,12 @@ fp_value *fc_cast(const fp_value *val, const ieee_descriptor_t *desc, fp_value *
  * @return  The result pointer passed to the function. If this was NULL this returns
  *          a pointer to the internal accumulator buffer
  */
-fp_value *fc_get_min(const ieee_descriptor_t *desc, fp_value *result);
-fp_value *fc_get_max(const ieee_descriptor_t *desc, fp_value *result);
-fp_value *fc_get_snan(const ieee_descriptor_t *desc, fp_value *result);
-fp_value *fc_get_qnan(const ieee_descriptor_t *desc, fp_value *result);
-fp_value *fc_get_plusinf(const ieee_descriptor_t *desc, fp_value *result);
-fp_value *fc_get_minusinf(const ieee_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_min(const float_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_max(const float_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_snan(const float_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_qnan(const float_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_plusinf(const float_descriptor_t *desc, fp_value *result);
+fp_value *fc_get_minusinf(const float_descriptor_t *desc, fp_value *result);
 /*@}*/
 
 int fc_is_zero(const fp_value *a);
@@ -182,13 +151,10 @@ char *fc_print(const fp_value *a, char *buf, int buflen, unsigned base);
  *
  * @param a Value No. 1
  * @param b Value No. 2
- * @result The returned value will be one of
- *          -1  if a < b
- *           0  if a == b
- *           1  if a > b
- *           2  if either value is NaN
+ * @result The relation between a and b; either less, equal, greater or
+ *         unordered.
  */
-int fc_comp(const fp_value *a, const fp_value *b);
+ir_relation fc_comp(const fp_value *a, const fp_value *b);
 
 /**
  * Converts an floating point value into an integer value.
@@ -208,7 +174,7 @@ int fc_get_exponent(const fp_value *value);
 /**
  * Return non-zero if a given value can be converted lossless into another precision.
  */
-int fc_can_lossless_conv_to(const fp_value *value, char exp_size, char mant_size);
+int fc_can_lossless_conv_to(const fp_value *value, const float_descriptor_t *desc);
 
 /** Set new rounding mode
  * This function sets the rounding mode to one of the following, returning
@@ -277,15 +243,6 @@ fc_rounding_mode_t fc_get_rounding_mode(void);
  */
 unsigned char fc_sub_bits(const fp_value *val, unsigned num_bit, unsigned byte_ofs);
 
-/**
- * Set the immediate precision for IEEE-754 results. Set this to
- * 0 to get the same precision as the operands.
- * For x87 compatibility, set this to 80.
- *
- * @return the old setting
- */
-unsigned fc_set_immediate_precision(unsigned bits);
-
 /**
  * Returns non-zero if the result of the last operation was exact.
  */