summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Schnetter <schnetter@gmail.com>2013-04-22 21:28:53 -0400
committerErik Schnetter <schnetter@gmail.com>2013-04-22 21:28:53 -0400
commit56b1f57c43964a5a1ade12ae958d28b0b358723a (patch)
treeed2cac8b192442eec9e8ce2b820f0f4729d41647
parent6bf4819267f22dbf6fd82cb8dd81e14c4b065739 (diff)
downloadvecmathlib-56b1f57c43964a5a1ade12ae958d28b0b358723a.zip
vecmathlib-56b1f57c43964a5a1ade12ae958d28b0b358723a.tar.gz
Implement IEEE-versions of isnan etc. that are not optimized away
-rw-r--r--mathfuncs_base.h4
-rw-r--r--mathfuncs_fabs.h40
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<typename realvec_t>
+ auto mathfuncs<realvec_t>::vml_ieee_isfinite(realvec_t x) -> boolvec_t
+ {
+ return (as_int(x) & IV(FP::exponent_mask)) != IV(FP::exponent_mask);
+ }
+
+ template<typename realvec_t>
+ auto mathfuncs<realvec_t>::vml_ieee_isinf(realvec_t x) -> boolvec_t
+ {
+ return (as_int(x) & IV(~FP::signbit_mask)) == IV(FP::exponent_mask);
+ }
+
+ template<typename realvec_t>
+ auto mathfuncs<realvec_t>::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<typename realvec_t>
+ auto mathfuncs<realvec_t>::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<typename realvec_t>
auto mathfuncs<realvec_t>::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<realvec_t>::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<realvec_t>::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<realvec_t>::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
OpenPOWER on IntegriCloud