aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts/SkFloatingPoint_opts.h
blob: 8b6536ad7f18dab0e72c7472803fe63deab9d777 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkFloatingPoint_opts_DEFINED
#define SkFloatingPoint_opts_DEFINED

#include "SkFloatingPoint.h"

namespace SK_OPTS_NS {

#if defined(SK_ARM_HAS_NEON)
    static float rsqrt(float x) {
        return sk_float_rsqrt(x);  // This sk_float_rsqrt copy will take the NEON compile-time path.
    }
#else
    static float rsqrt(float x) {
        // Get initial estimate.
        int i = *SkTCast<int*>(&x);
        i = 0x5F1FFFF9 - (i>>1);
        float estimate = *SkTCast<float*>(&i);

        // One step of Newton's method to refine.
        const float estimate_sq = estimate*estimate;
        estimate *= 0.703952253f*(2.38924456f-x*estimate_sq);
        return estimate;
    }
#endif

}  // namespace SK_OPTS_NS

#endif//SkFloatingPoint_opts_DEFINED