X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ffltcalc.h;h=c41257ea0c6a4a4327095c49163d0d947f9a41ff;hb=bd019d8cd785c1a433c19dee44bf3f9e82397286;hp=a4745c1c3ba779868c2cdf3cb275d919334d8d8a;hpb=b93f313acd50acf50e1f1d7ab042bdc3cfff1d04;p=libfirm diff --git a/ir/tv/fltcalc.h b/ir/tv/fltcalc.h index a4745c1c3..c41257ea0 100644 --- a/ir/tv/fltcalc.h +++ b/ir/tv/fltcalc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -22,21 +22,13 @@ * @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 #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, @@ -55,7 +47,19 @@ typedef enum { #define FC_DEFAULT_PRECISION 64 -typedef struct _fp_value fp_value; +/** + * possible float states + */ +typedef enum { + 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; + +struct fp_value; +typedef struct fp_value fp_value; /*@{*/ /** internal buffer access @@ -68,78 +72,76 @@ const void *fc_get_buffer(void); int fc_get_buffer_length(void); /*}@*/ -void *fc_val_from_str(const char *str, unsigned int len, char exp_size, char mant_size, 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 + * @param result A buffer to hold the value built. If this is NULL, the internal + * accumulator buffer is used. Note that the buffer must be big + * enough to hold the value. Use fc_get_buffer_length() to find out + * the size needed * - * @param l The floating point number to build a representation for - * @param exp_size The number of bits of the new exponent - * @param mant_size The number of bits of the new mantissa - * @param result A buffer to hold the value built. If this is NULL, the internal - * accumulator buffer is used. Note that the buffer must be big - * enough to hold the value. Use fc_get_buffer_length() to find out - * the size needed - * @return The result pointer passed to the function. If this was NULL this returns - * a pointer to the internal accumulator buffer + * @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, char exp_size, char mant_size, 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. * - * @param val The representation of a float value + * @param val The representation of a float 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. * If the new precision is less than the original precision the returned * value might not be the same as the original value. * - * @param val The value to be casted - * @param exp_size The number of bits of the new exponent - * @param mant_size The number of bits of the new mantissa - * @param result A buffer to hold the value built. If this is NULL, the internal - * accumulator buffer is used. Note that the buffer must be big - * enough to hold the value. Use fc_get_buffer_length() to find out - * the size needed - * @return The result pointer passed to the function. If this was NULL this returns - * a pointer to the internal accumulator buffer + * @param val The value to be casted + * @param desc The floating point descriptor + * @param result A buffer to hold the value built. If this is NULL, the internal + * accumulator buffer is used. Note that the buffer must be big + * enough to hold the value. Use fc_get_buffer_length() to find out + * the size needed + * @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, char exp_size, char mant_size, fp_value *result); +fp_value *fc_cast(const fp_value *val, const float_descriptor_t *desc, fp_value *result); /*@{*/ /** build a special float value * This function builds a representation for a special float value, as indicated by the * function's suffix. * - * @param exponent_size The number of bits of exponent of the float type the value - * is created for - * @param mantissa_size The number of bits of mantissa of the float type the value - * is created for - * @param result A buffer to hold the value built. If this is NULL, the internal - * accumulator buffer is used. Note that the buffer must be big - * enough to hold the value. Use fc_get_buffer_length() to find out - * the size needed - * @return The result pointer passed to the function. If this was NULL this returns - * a pointer to the internal accumulator buffer + * @param desc The floating point descriptor + * @param result A buffer to hold the value built. If this is NULL, the internal + * accumulator buffer is used. Note that the buffer must be big + * enough to hold the value. Use fc_get_buffer_length() to find out + * the size needed + * @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(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); +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); @@ -186,6 +188,11 @@ int fc_zero_mantissa(const fp_value *value); */ 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, const float_descriptor_t *desc); + /** Set new rounding mode * This function sets the rounding mode to one of the following, returning * the previously set rounding mode. @@ -253,15 +260,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. */