X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Ftv%2Ffltcalc.h;h=1f5891644bc84576fd66b3e885853e053665b292;hb=4e93e1cb7409412d405d9c4d06a54f5098021092;hp=8079a6748ff0c9fbdc63e4a69c5b338088e9315e;hpb=4a727972596f9f33381c207d3eec92482ddb8b94;p=libfirm diff --git a/ir/tv/fltcalc.h b/ir/tv/fltcalc.h index 8079a6748..1f5891644 100644 --- a/ir/tv/fltcalc.h +++ b/ir/tv/fltcalc.h @@ -1,19 +1,33 @@ /* - * Project: libFIRM - * File name: ir/tv/fltcalc.h - * 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. + * Copyright (C) 1995-2007 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. */ -#ifndef _FLTCALC_H_ -#define _FLTCALC_H_ +/** + * @file + * @brief tarval floating point calculations + * @date 2003 + * @author Mathias Heil + * @version $Id$ + */ +#ifndef FIRM_TV_FLTCALC_H +#define FIRM_TV_FLTCALC_H -#include "config.h" +#include "firm_config.h" #ifdef HAVE_LONG_DOUBLE /* XXX Set this via autoconf */ @@ -30,29 +44,26 @@ typedef enum { FC_div, /**< divide */ FC_neg, /**< negate */ FC_int, /**< truncate to integer */ - FC_rnd, /**< round to integer */ + FC_rnd /**< round to integer */ } fc_op_t; enum { FC_DEC, FC_HEX, FC_BIN, - FC_PACKED, + FC_PACKED }; -/* rounding modes */ +/** IEEE-754 Rounding modes. */ typedef enum { - FC_TONEAREST, - FC_TOPOSITIVE, - FC_TONEGATIVE, - FC_TOZERO, + 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) - /*@{*/ /** internal buffer access * All functions that accept NULL as return buffer put their result into an @@ -61,15 +72,15 @@ typedef enum { * returns the size of this buffer */ const void *fc_get_buffer(void); -const int fc_get_buffer_length(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); +char *fc_val_from_str(const char *str, unsigned int len, char exp_size, char mant_size, char *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 precicion of LLDBL the value built + * 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. * @@ -83,7 +94,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); +char *fc_val_from_float(LLDBL l, char exp_size, char mant_size, char *result); /** retrieve the float value of an internal value * This function casts the internal value to LLDBL and returns a LLDBL with @@ -112,7 +123,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); +char *fc_cast(const void *val, char exp_size, char mant_size, char *result); /*@{*/ /** build a special float value @@ -130,13 +141,13 @@ 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); -/*}@*/ +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); +/*@}*/ int fc_is_zero(const void *a); int fc_is_negative(const void *a); @@ -144,13 +155,13 @@ int fc_is_inf(const void *a); int fc_is_nan(const void *a); int fc_is_subnormal(const void *a); -FC_DECLARE2(add); -FC_DECLARE2(sub); -FC_DECLARE2(mul); -FC_DECLARE2(div); -FC_DECLARE1(neg); -FC_DECLARE1(int); -FC_DECLARE1(rnd); +char *fc_add(const void *a, const void *b, void *result); +char *fc_sub(const void *a, const void *b, void *result); +char *fc_mul(const void *a, const void *b, void *result); +char *fc_div(const void *a, const void *b, void *result); +char *fc_neg(const void *a, void *result); +char *fc_int(const void *a, void *result); +char *fc_rnd(const void *a, void *result); char *fc_print(const void *a, char *buf, int buflen, unsigned base); @@ -173,8 +184,8 @@ int fc_comp(const void *a, const void *b); * FC_TONEAREST (default): * Any unrepresentable value is rounded to the nearest representable * value. If it lies in the middle the value with the least significant - * bit of zero is chosen. - * Values too big to represent will round to +-infinity. + * bit of zero is chosen (the even one). + * Values too big to represent will round to +/-infinity. * FC_TONEGATIVE * Any unrepresentable value is rounded towards negative infinity. * Positive values too big to represent will round to the biggest @@ -191,7 +202,7 @@ int fc_comp(const void *a, const void *b); * Values too big to represent will round to the biggest/smallest * representable value. * - * These modes correspond to the modes required by the ieee standard. + * These modes correspond to the modes required by the IEEE-754 standard. * * @param mode The new rounding mode. Any value other than the four * defined values will have no effect. @@ -211,21 +222,21 @@ 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. - * The value will be packed corresponding to the way used by the ieee + * 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 * exp_size bits exponent + bias * mant_size bits mantissa, without leading 1 * - * As in ieee, an exponent of 0 indicates a denormalized number, which + * As in IEEE, an exponent of 0 indicates a denormalized number, which * implies a most significant bit of zero instead of one; an exponent * of all ones (2**exp_size - 1) encodes infinity if the mantissa is - * all zeroes, else Not A Number. + * all zeros, else Not A Number. * * @param val A pointer to the value. If NULL is passed a copy of the * most recent value passed to this function is used, saving the - * packing step. This behaviour may be changed in the future. + * packing step. This behavior may be changed in the future. * @param num_bit The maximum number of bits to return. Any bit beyond * num_bit will be returned as zero. * @param byte_ofs The byte index to read, 0 is the least significant @@ -235,4 +246,6 @@ fc_rounding_mode_t fc_get_rounding_mode(void); unsigned char fc_sub_bits(const void *val, unsigned num_bit, unsigned byte_ofs); void init_fltcalc(int precision); -#endif /* _FLTCALC_H_ */ +void finish_fltcalc(void); + +#endif /* FIRM_TV_FLTCALC_H */