aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/MathBench.cpp12
-rw-r--r--include/private/SkFloatingPoint.h6
2 files changed, 5 insertions, 13 deletions
diff --git a/bench/MathBench.cpp b/bench/MathBench.cpp
index 05a5f8a2d5..541a1052dc 100644
--- a/bench/MathBench.cpp
+++ b/bench/MathBench.cpp
@@ -126,23 +126,13 @@ private:
typedef MathBench INHERITED;
};
-static inline float SkFastInvSqrt(float x) {
- float xhalf = 0.5f*x;
- uint32_t i = *SkTCast<uint32_t*>(&x);
- i = 0x5f3759df - (i>>1);
- x = *SkTCast<float*>(&i);
- x = x*(1.5f-xhalf*x*x);
-// x = x*(1.5f-xhalf*x*x); // this line takes err from 10^-3 to 10^-6
- return x;
-}
-
class FastISqrtMathBench : public MathBench {
public:
FastISqrtMathBench() : INHERITED("fastIsqrt") {}
protected:
void performTest(float* SK_RESTRICT dst, const float* SK_RESTRICT src, int count) override {
for (int i = 0; i < count; ++i) {
- dst[i] = SkFastInvSqrt(src[i]);
+ dst[i] = sk_float_rsqrt(src[i]);
}
}
private:
diff --git a/include/private/SkFloatingPoint.h b/include/private/SkFloatingPoint.h
index 8d8843eb58..6a6edf3651 100644
--- a/include/private/SkFloatingPoint.h
+++ b/include/private/SkFloatingPoint.h
@@ -107,9 +107,11 @@ static const uint32_t kIEEENotANumber = 0x7fffffff;
static inline float sk_float_rsqrt_portable(float x) {
// Get initial estimate.
- int i = *SkTCast<int*>(&x);
+ int i;
+ memcpy(&i, &x, 4);
i = 0x5F1FFFF9 - (i>>1);
- float estimate = *SkTCast<float*>(&i);
+ float estimate;
+ memcpy(&estimate, &i, 4);
// One step of Newton's method to refine.
const float estimate_sq = estimate*estimate;