From 69eb2dc7a32de8cefa7a18d2e257c8ff59e782f5 Mon Sep 17 00:00:00 2001 From: Michael Beck Date: Wed, 14 Nov 2007 14:41:08 +0000 Subject: [PATCH] - added more classification functions for floating point tarvals - speed up some functions - more comments added [r16531] --- include/libfirm/tv.h | 20 ++++++++++++++++++++ ir/tv/tv.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 5 deletions(-) diff --git a/include/libfirm/tv.h b/include/libfirm/tv.h index 0d7fe9007..a92175d20 100644 --- a/include/libfirm/tv.h +++ b/include/libfirm/tv.h @@ -615,4 +615,24 @@ unsigned tarval_ieee754_get_exact(void); */ int tarval_enable_fp_ops(int enable); +/** + * Check if its the a floating point NaN. + */ +int tarval_is_NaN(tarval *tv); + +/** + * Check if its the a floating point +inf. + */ +int tarval_is_plus_inf(tarval *tv); + +/** + * Check if its the a floating point -inf. + */ +int tarval_is_minus_inf(tarval *tv); + +/** + * Check if the tarval represents a finite value, ie neither NaN nor inf. + */ +int tarval_is_finite(tarval *tv); + #endif /* FIRM_TV_TV_H */ diff --git a/ir/tv/tv.c b/ir/tv/tv.c index 1aa0deaea..b8858d9cf 100644 --- a/ir/tv/tv.c +++ b/ir/tv/tv.c @@ -237,10 +237,12 @@ static tarval *get_tarval_overflow(const void *value, int length, ir_mode *mode) case irms_float_number: if (SWITCH_NOINFINITY && fc_is_inf(value)) { - return fc_is_negative(value)?get_mode_min(mode):get_mode_max(mode); + /* clip infinity to maximum value */ + return fc_is_negative(value) ? get_mode_min(mode) : get_mode_max(mode); } if (SWITCH_NODENORMALS && fc_is_subnormal(value)) { + /* clip denormals to zero */ return get_mode_null(mode); } break; @@ -729,7 +731,7 @@ int tarval_is_negative(tarval *a) { return sc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0; case irms_float_number: - return fc_comp(a->value, get_mode_null(a->mode)->value) == -1 ? 1 : 0; + return fc_is_negative(a->value); default: assert(0 && "not implemented"); @@ -743,7 +745,7 @@ int tarval_is_negative(tarval *a) { int tarval_is_null(tarval *a) { return a != tarval_bad && - a == get_tarval_null(get_tarval_mode(a)); + a == get_mode_null(get_tarval_mode(a)); } /* @@ -752,7 +754,7 @@ int tarval_is_null(tarval *a) { int tarval_is_one(tarval *a) { return a != tarval_bad && - a == get_tarval_one(get_tarval_mode(a)); + a == get_mode_one(get_tarval_mode(a)); } int tarval_is_all_one(tarval *tv) { @@ -767,7 +769,7 @@ int tarval_is_all_one(tarval *tv) { int tarval_is_minus_one(tarval *a) { return a != tarval_bad && - a == get_tarval_minus_one(get_tarval_mode(a)); + a == get_mode_minus_one(get_tarval_mode(a)); } /* @@ -1638,6 +1640,34 @@ unsigned tarval_ieee754_get_exact(void) { return fc_is_exact(); } +/* check if its the a floating point NaN */ +int tarval_is_NaN(tarval *tv) { + if (! mode_is_float(tv->mode)) + return 0; + return fc_is_nan(tv->value); +} + +/* check if its the a floating point +inf */ +int tarval_is_plus_inf(tarval *tv) { + if (! mode_is_float(tv->mode)) + return 0; + return fc_is_inf(tv->value) && !fc_is_negative(tv->value); +} + +/* check if its the a floating point -inf */ +int tarval_is_minus_inf(tarval *tv) { + if (! mode_is_float(tv->mode)) + return 0; + return fc_is_inf(tv->value) && fc_is_negative(tv->value); +} + +/* check if the tarval represents a finite value */ +int tarval_is_finite(tarval *tv) { + if (mode_is_float(tv->mode)) + return !fc_is_nan(tv->value) && !fc_is_inf(tv->value); + return 1; +} + /* * Sets the overflow mode for integer operations. */ -- 2.20.1