X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ffltcalc.h;h=a4745c1c3ba779868c2cdf3cb275d919334d8d8a;hb=515a21403ca2fd3bd104cae901ff0239343adf69;hp=6849ee7541802398fef5f5d9d96462ed351ab66d;hpb=eb08138c6b80c169945568e4414f491a9bc20388;p=libfirm diff --git a/ir/tv/fltcalc.h b/ir/tv/fltcalc.h index 6849ee754..a4745c1c3 100644 --- a/ir/tv/fltcalc.h +++ b/ir/tv/fltcalc.h @@ -17,21 +17,18 @@ * PURPOSE. */ -/* - * Project: libFIRM - * File name: ir/tv/fltcalc.h - * Purpose: - * Author: - * Modified by: - * Created: 2003 - * CVS-ID: $Id$ - * Copyright: (c) 2003 Universität Karlsruhe +/** + * @file + * @brief tarval floating point calculations + * @date 2003 + * @author Mathias Heil + * @version $Id$ */ - -#ifndef _FLTCALC_H_ -#define _FLTCALC_H_ +#ifndef FIRM_TV_FLTCALC_H +#define FIRM_TV_FLTCALC_H #include "firm_config.h" +#include "firm_types.h" #ifdef HAVE_LONG_DOUBLE /* XXX Set this via autoconf */ @@ -41,35 +38,24 @@ typedef long double LLDBL; typedef double LLDBL; #endif -typedef enum { - FC_add, /**< addition */ - FC_sub, /**< subtraction */ - FC_mul, /**< multiplication */ - FC_div, /**< divide */ - FC_neg, /**< negate */ - FC_int, /**< truncate to integer */ - FC_rnd /**< round to integer */ -} fc_op_t; - enum { - FC_DEC, - FC_HEX, - FC_BIN, - FC_PACKED + FC_DEC, + FC_HEX, + FC_BIN, + FC_PACKED }; /** IEEE-754 Rounding modes. */ typedef enum { - FC_TONEAREST, /**< if unsure, to the nearest even */ - FC_TOPOSITIVE, /**< to +oo */ - FC_TONEGATIVE, /**< to -oo */ - FC_TOZERO /**< to 0 */ + FC_TONEAREST, /**< if unsure, to the nearest even */ + FC_TOPOSITIVE, /**< to +oo */ + FC_TONEGATIVE, /**< to -oo */ + FC_TOZERO /**< to 0 */ } fc_rounding_mode_t; #define FC_DEFAULT_PRECISION 64 -#define FC_DECLARE1(code) char* fc_##code(const void *a, void *result) -#define FC_DECLARE2(code) char* fc_##code(const void *a, const void *b, void *result) +typedef struct _fp_value fp_value; /*@{*/ /** internal buffer access @@ -82,7 +68,7 @@ const void *fc_get_buffer(void); int fc_get_buffer_length(void); /*}@*/ -char* fc_val_from_str(const char *str, unsigned int len, char exp_size, char mant_size, char *result); +void *fc_val_from_str(const char *str, unsigned int len, char exp_size, char mant_size, void *result); /** get the representation of a floating point value * This function tries to builds a representation having the same value as the @@ -101,7 +87,7 @@ char* fc_val_from_str(const char *str, unsigned int len, char exp_size, char man * @return The result pointer passed to the function. If this was NULL this returns * a pointer to the internal accumulator buffer */ -char* fc_val_from_float(LLDBL l, char exp_size, char mant_size, char *result); +fp_value *fc_val_from_ieee754(LLDBL l, char exp_size, char mant_size, fp_value *result); /** retrieve the float value of an internal value * This function casts the internal value to LLDBL and returns a LLDBL with @@ -113,7 +99,7 @@ char* fc_val_from_float(LLDBL l, char exp_size, char mant_size, char *result); * @param val The representation of a float value * @return a float value approximating the represented value */ -LLDBL fc_val_to_float(const void *val); +LLDBL fc_val_to_ieee754(const fp_value *val); /** cast a value to another precision * This function changes the precision of a float representation. @@ -130,7 +116,7 @@ LLDBL fc_val_to_float(const void *val); * @return The result pointer passed to the function. If this was NULL this returns * a pointer to the internal accumulator buffer */ -char* fc_cast(const void *val, char exp_size, char mant_size, char *result); +fp_value *fc_cast(const fp_value *val, char exp_size, char mant_size, fp_value *result); /*@{*/ /** build a special float value @@ -148,29 +134,29 @@ char* fc_cast(const void *val, char exp_size, char mant_size, char *result); * @return The result pointer passed to the function. If this was NULL this returns * a pointer to the internal accumulator buffer */ -char* fc_get_min(unsigned int exponent_size, unsigned int mantissa_size, char* result); -char* fc_get_max(unsigned int exponent_size, unsigned int mantissa_size, char* result); -char* fc_get_snan(unsigned int exponent_size, unsigned int mantissa_size, char* result); -char* fc_get_qnan(unsigned int exponent_size, unsigned int mantissa_size, char* result); -char* fc_get_plusinf(unsigned int exponent_size, unsigned int mantissa_size, char* result); -char* fc_get_minusinf(unsigned int exponent_size, unsigned int mantissa_size, char* result); +fp_value *fc_get_min(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); +fp_value *fc_get_max(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); +fp_value *fc_get_snan(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); +fp_value *fc_get_qnan(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); +fp_value *fc_get_plusinf(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); +fp_value *fc_get_minusinf(unsigned int exponent_size, unsigned int mantissa_size, fp_value *result); /*@}*/ -int fc_is_zero(const void *a); -int fc_is_negative(const void *a); -int fc_is_inf(const void *a); -int fc_is_nan(const void *a); -int fc_is_subnormal(const void *a); +int fc_is_zero(const fp_value *a); +int fc_is_negative(const fp_value *a); +int fc_is_inf(const fp_value *a); +int fc_is_nan(const fp_value *a); +int fc_is_subnormal(const fp_value *a); -FC_DECLARE2(add); -FC_DECLARE2(sub); -FC_DECLARE2(mul); -FC_DECLARE2(div); -FC_DECLARE1(neg); -FC_DECLARE1(int); -FC_DECLARE1(rnd); +fp_value *fc_add(const fp_value *a, const fp_value *b, fp_value *result); +fp_value *fc_sub(const fp_value *a, const fp_value *b, fp_value *result); +fp_value *fc_mul(const fp_value *a, const fp_value *b, fp_value *result); +fp_value *fc_div(const fp_value *a, const fp_value *b, fp_value *result); +fp_value *fc_neg(const fp_value *a, fp_value *result); +fp_value *fc_int(const fp_value *a, fp_value *result); +fp_value *fc_rnd(const fp_value *a, fp_value *result); -char *fc_print(const void *a, char *buf, int buflen, unsigned base); +char *fc_print(const fp_value *a, char *buf, int buflen, unsigned base); /** Compare two values * This function compares two values @@ -183,7 +169,22 @@ char *fc_print(const void *a, char *buf, int buflen, unsigned base); * 1 if a > b * 2 if either value is NaN */ -int fc_comp(const void *a, const void *b); +int fc_comp(const fp_value *a, const fp_value *b); + +/** + * Converts an floating point value into an integer value. + */ +int fc_flt2int(const fp_value *a, void *result, ir_mode *dst_mode); + +/** + * Returns non-zero if the mantissa is zero, i.e. 1.0Exxx + */ +int fc_zero_mantissa(const fp_value *value); + +/** + * Returns the exponent of a value. + */ +int fc_get_exponent(const fp_value *value); /** Set new rounding mode * This function sets the rounding mode to one of the following, returning @@ -229,7 +230,7 @@ fc_rounding_mode_t fc_set_rounding_mode(fc_rounding_mode_t mode); fc_rounding_mode_t fc_get_rounding_mode(void); /** Get bit representation of a value - * This function allows to read a value in encoded form, bytewise. + * This function allows to read a value in encoded form, byte wise. * The value will be packed corresponding to the way used by the IEEE * encoding formats, i.e. * One bit sign @@ -250,9 +251,23 @@ fc_rounding_mode_t fc_get_rounding_mode(void); * byte. * @return 8 bits of encoded data */ -unsigned char fc_sub_bits(const void *val, unsigned num_bit, unsigned byte_ofs); +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. + */ +int fc_is_exact(void); void init_fltcalc(int precision); -void finish_fltcalc (void); +void finish_fltcalc(void); -#endif /* _FLTCALC_H_ */ +#endif /* FIRM_TV_FLTCALC_H */