From 56b1f57c43964a5a1ade12ae958d28b0b358723a Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Mon, 22 Apr 2013 21:28:53 -0400 Subject: Implement IEEE-versions of isnan etc. that are not optimized away --- mathfuncs_base.h | 4 ++++ mathfuncs_fabs.h | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/mathfuncs_base.h b/mathfuncs_base.h index e8f24a8..22df222 100644 --- a/mathfuncs_base.h +++ b/mathfuncs_base.h @@ -66,6 +66,10 @@ namespace vecmathlib { static realvec_t vml_fmax(realvec_t x, realvec_t y); static realvec_t vml_fmin(realvec_t x, realvec_t y); static intvec_t vml_ilogb(realvec_t x); + static boolvec_t vml_ieee_isfinite(realvec_t x); + static boolvec_t vml_ieee_isinf(realvec_t x); + static boolvec_t vml_ieee_isnan(realvec_t x); + static boolvec_t vml_ieee_isnormal(realvec_t x); static boolvec_t vml_isfinite(realvec_t x); static boolvec_t vml_isinf(realvec_t x); static boolvec_t vml_isnan(realvec_t x); diff --git a/mathfuncs_fabs.h b/mathfuncs_fabs.h index 170a827..4f7aa60 100644 --- a/mathfuncs_fabs.h +++ b/mathfuncs_fabs.h @@ -66,10 +66,38 @@ namespace vecmathlib { } template + auto mathfuncs::vml_ieee_isfinite(realvec_t x) -> boolvec_t + { + return (as_int(x) & IV(FP::exponent_mask)) != IV(FP::exponent_mask); + } + + template + auto mathfuncs::vml_ieee_isinf(realvec_t x) -> boolvec_t + { + return (as_int(x) & IV(~FP::signbit_mask)) == IV(FP::exponent_mask); + } + + template + auto mathfuncs::vml_ieee_isnan(realvec_t x) -> boolvec_t + { + return + (as_int(x) & IV(FP::exponent_mask)) == IV(FP::exponent_mask) && + (as_int(x) & IV(FP::mantissa_mask)) != IV(I(0)); + } + + template + auto mathfuncs::vml_ieee_isnormal(realvec_t x) -> boolvec_t + { + return + (as_int(x) & IV(FP::exponent_mask)) != IV(FP::exponent_mask) && + (as_int(x) & IV(FP::exponent_mask)) != IV(I(0)); + } + + template auto mathfuncs::vml_isfinite(realvec_t x) -> boolvec_t { #if defined VML_HAVE_INF || defined VML_HAVE_NAN - return (as_int(x) & IV(FP::exponent_mask)) != IV(FP::exponent_mask); + return vml_ieee_isfinite(x); #else return BV(true); #endif @@ -79,7 +107,7 @@ namespace vecmathlib { auto mathfuncs::vml_isinf(realvec_t x) -> boolvec_t { #if defined VML_HAVE_INF - return (as_int(x) & IV(~FP::signbit_mask)) == IV(FP::exponent_mask); + return vml_ieee_isinf(x); #else return BV(false); #endif @@ -89,9 +117,7 @@ namespace vecmathlib { auto mathfuncs::vml_isnan(realvec_t x) -> boolvec_t { #if defined VML_HAVE_NAN - return - (as_int(x) & IV(FP::exponent_mask)) == IV(FP::exponent_mask) && - (as_int(x) & IV(FP::mantissa_mask)) != IV(I(0)); + return vml_ieee_isnan(x); #else return BV(false); #endif @@ -101,9 +127,7 @@ namespace vecmathlib { auto mathfuncs::vml_isnormal(realvec_t x) -> boolvec_t { #if defined VML_HAVE_DENORMALS || defined VML_HAVE_INF || defined VML_HAVE_NAN - return - (as_int(x) & IV(FP::exponent_mask)) != IV(FP::exponent_mask) && - (as_int(x) & IV(FP::exponent_mask)) != IV(I(0)); + return vml_ieee_isnormal(x); #else return BV(true); #endif -- cgit v1.1