Revert "implement SkScalar versions in terms of float versions"
This reverts commit 4c3cb3767f5af3860998b932702dc18619ab3e1e.
Reason for revert: investigate asan failures
Original change's description:
> implement SkScalar versions in terms of float versions
>
> Bug: skia:
> Change-Id: I44ce228290f7fda5b7e3553c8543dcf581b1ca3b
> Reviewed-on: https://skia-review.googlesource.com/127128
> Reviewed-by: Cary Clark <caryclark@google.com>
> Commit-Queue: Mike Reed <reed@google.com>
TBR=caryclark@google.com,reed@google.com
Change-Id: Ic790b15130a67f46a0a99fdf991c5c08d682be5e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/128060
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h
index f44d036..9c015e5 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -68,10 +68,22 @@
/** Returns true if x is not NaN and not infinite
*/
-static inline bool SkScalarIsFinite(SkScalar x) { return sk_float_isfinite(x); }
+static inline bool SkScalarIsFinite(SkScalar x) {
+ // We rely on the following behavior of infinities and nans
+ // 0 * finite --> 0
+ // 0 * infinity --> NaN
+ // 0 * NaN --> NaN
+ SkScalar prod = x * 0;
+ // At this point, prod will either be NaN or 0
+ return !SkScalarIsNaN(prod);
+}
static inline bool SkScalarsAreFinite(SkScalar a, SkScalar b) {
- return sk_float_isfinite(a) && sk_float_isfinite(b);
+ SkScalar prod = 0;
+ prod *= a;
+ prod *= b;
+ // At this point, prod will either be NaN or 0
+ return !SkScalarIsNaN(prod);
}
static inline bool SkScalarsAreFinite(const SkScalar array[], int count) {
@@ -80,7 +92,7 @@
prod *= array[i];
}
// At this point, prod will either be NaN or 0
- return prod == 0; // if prod is NaN, this check will return false
+ return !SkScalarIsNaN(prod);
}
/**
diff --git a/include/private/SkFloatBits.h b/include/private/SkFloatBits.h
index bae1542..2740a25 100644
--- a/include/private/SkFloatBits.h
+++ b/include/private/SkFloatBits.h
@@ -56,18 +56,6 @@
return data.fFloat;
}
-constexpr int32_t gFloatBits_exponent_mask = 0x7F800000;
-constexpr int32_t gFloatBits_matissa_mask = 0x007FFFFF;
-
-static inline bool SkFloatBits_IsFinite(int32_t bits) {
- return (bits & gFloatBits_exponent_mask) != gFloatBits_exponent_mask;
-}
-
-static inline bool SkFloatBits_IsInf(int32_t bits) {
- return ((bits & gFloatBits_exponent_mask) == gFloatBits_exponent_mask) &&
- (bits & gFloatBits_matissa_mask) == 0;
-}
-
/** Return the float as a 2s compliment int. Just to be used to compare floats
to each other or against positive float-bit-constants (like 0). This does
not return the int equivalent of the float, just something cheaper for
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h
index e2f2133..a2e6ee5 100644
--- a/include/private/SkFloatingPoint.h
+++ b/include/private/SkFloatingPoint.h
@@ -12,7 +12,6 @@
#include "SkTypes.h"
#include "SkSafe_math.h"
#include <float.h>
-#include <math.h>
#if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
#include <xmmintrin.h>
@@ -65,17 +64,17 @@
#define sk_float_log2(x) log2f(x)
#endif
-static inline bool sk_float_isfinite(float x) {
- return SkFloatBits_IsFinite(SkFloat2Bits(x));
-}
-
-static inline bool sk_float_isinf(float x) {
- return SkFloatBits_IsInf(SkFloat2Bits(x));
-}
-
-static inline bool sk_float_isnan(float x) {
- return !(x == x);
-}
+#ifdef SK_BUILD_FOR_WIN
+ #define sk_float_isfinite(x) _finite(x)
+ #define sk_float_isnan(x) _isnan(x)
+ static inline int sk_float_isinf(float x) {
+ return x && (x + x == x);
+ }
+#else
+ #define sk_float_isfinite(x) isfinite(x)
+ #define sk_float_isnan(x) isnan(x)
+ #define sk_float_isinf(x) isinf(x)
+#endif
#define sk_double_isnan(a) sk_float_isnan(a)